Commit 79ef7f60 authored by Federico Sismondi's avatar Federico Sismondi

big refact of project structure, cleaned up imports

parent 6ee5d4a1
from __future__ import absolute_import
from .agent_cli import Agent
......@@ -165,9 +165,8 @@ For more information: README.md
self.name_option = click.Option(
param_decls=["--name"],
default=str(uuid.uuid1()),
required=False,
help="Agent identity (default: random generated)")
required=True,
help="Agent identity, normally associated with the IUT role (coap_client, comi_server, etc)")
self.dump_option = click.Option(
param_decls=["--dump"],
......
from __future__ import absolute_import
from . import core
from . import serialconn
from . import tun
from . import base
\ No newline at end of file
......@@ -5,7 +5,7 @@ import json
import logging
from multiprocessing import Process
from utils.messages import Message as EventBusMessage
from ..utils.messages import Message as EventBusMessage
from amqp.exceptions import UnexpectedFrame
from kombu import Connection, Queue, Exchange, Consumer
......@@ -64,7 +64,7 @@ class BaseConsumer(ConsumerMixin):
def subscribe_to_topics(self, topic_list):
for t in topic_list:
queue = Queue(
name="consumer: {name}.{consumer_name}::RKey:{rkey}".format(
name="consumer: {name}.{consumer_name}?rkey={rkey}".format(
name=self.name,
consumer_name=self.consumer_name,
rkey=t
......@@ -88,7 +88,7 @@ class BaseConsumer(ConsumerMixin):
assert type(body) is dict # assert that kombu deserialized it already
json_body = json.dumps(body)
self.log.debug("DEFAULT on_message callback, got: {}".format(message.delivery_info.get('routing_key')))
self.log.debug("base on_message() callback, got: {}".format(message.delivery_info.get('routing_key')))
msg = EventBusMessage.load(json_body, message.delivery_info.get('routing_key'))
try:
self._on_message(msg)
......@@ -98,16 +98,13 @@ class BaseConsumer(ConsumerMixin):
)
def _on_message(self, message):
"Class to be overridden by children calss"
"Class to be overridden by children class"
return NotImplementedError()
def on_consume_ready(self, connection, channel, consumers, wakeup=True, **kwargs):
# control plane info
for q in self.queues:
self.log.info(
"Queue: {queue_name} bound to: {rkey} ".format(queue_name=q.name,
rkey=q.routing_key)
)
self.log.info("Queue: {queue_name} bound to: {rkey} ".format(queue_name=q.name, rkey=q.routing_key))
class BaseController(Process):
......
......@@ -3,10 +3,10 @@ Plugin to connect to the AMQP broker
"""
import json
import logging
from utils.messages import *
from kombu import Producer
from .base import BaseController, BaseConsumer
from ..utils.messages import MsgTestingToolComponentReady
__version__ = (0, 1, 0)
......
import json
__version__ = (0, 1, 0)
import logging
from requests import Request, Session
from .base import BaseController, BaseConsumer
log = logging.getLogger(__name__)
......
......@@ -6,10 +6,10 @@ import serial
import logging
import threading
from connectors.base import BaseController, BaseConsumer
from utils.serial_listener import SerialListener
from utils import arrow_down, arrow_up, finterop_banner
from utils.messages import *
from .base import BaseController, BaseConsumer
from ..utils import messages
from ..utils import arrow_down
from ..utils.serial_listener import SerialListener
__version__ = (0, 1, 0)
......@@ -26,11 +26,11 @@ class SerialConsumer(BaseConsumer):
def __init__(self, user, password, session, server, exchange, name, consumer_name):
self.dispatcher = {
MsgPacketInjectRaw: self.handle_data,
messages.MsgPacketInjectRaw: self.handle_data,
}
subscriptions = [
MsgPacketInjectRaw.routing_key.replace('*', name).replace('ip.tun', '802154.serial'),
messages.MsgPacketInjectRaw.routing_key.replace('*', name).replace('ip.tun', '802154.serial'),
]
super(SerialConsumer, self).__init__(user, password, session, server, exchange, name, consumer_name,
......
......@@ -7,15 +7,12 @@ import json
import logging
import sys
import datetime
from utils.opentun import OpenTunLinux, OpenTunMACOS
from utils import arrow_down, arrow_up, finterop_banner
from utils.messages import *
from kombu import Producer
from connectors.base import BaseController, BaseConsumer
__version__ = (0, 1, 0)
from .base import BaseController, BaseConsumer
from ..utils.opentun import OpenTunLinux, OpenTunMACOS
from ..utils import arrow_up
from ..utils import messages
class TunConsumer(BaseConsumer):
......@@ -29,22 +26,22 @@ class TunConsumer(BaseConsumer):
def __init__(self, user, password, session, server, exchange, name, consumer_name, force_bootstrap, ipv6_host,
ipv6_prefix):
self.dispatcher = {
MsgAgentTunStart: self.handle_start,
MsgPacketInjectRaw: self.handle_raw_packet_to_inject,
messages.MsgAgentTunStart: self.handle_start,
messages.MsgPacketInjectRaw: self.handle_raw_packet_to_inject,
}
self.tun = None
self.packet_count = 0
subscriptions = [
MsgAgentTunStart.routing_key.replace('*', name), # default rkey is "toAgent.*.ip.tun.start"
MsgPacketInjectRaw.routing_key.replace('*', name)
messages.MsgAgentTunStart.routing_key.replace('*', name), # default rkey is "toAgent.*.ip.tun.start"
messages.MsgPacketInjectRaw.routing_key.replace('*', name)
]
super(TunConsumer, self).__init__(user, password, session, server, exchange, name, consumer_name, subscriptions)
if force_bootstrap:
self.handle_start(
MsgAgentTunStart(
messages.MsgAgentTunStart(
name=name,
ipv6_host=ipv6_host,
ipv6_prefix=ipv6_prefix,
......@@ -75,7 +72,7 @@ class TunConsumer(BaseConsumer):
conf_params = self.tun.get_tun_configuration()
conf_params.update({'name': self.name})
# publish message in event bus
msg = MsgAgentTunStarted(**conf_params)
msg = messages.MsgAgentTunStarted(**conf_params)
logging.info('Publishing %s' % repr(msg))
producer = Producer(self.connection, serializer='json')
......@@ -146,17 +143,25 @@ class TunConsumer(BaseConsumer):
return
self.packet_count += 1
print(arrow_down)
self.log.debug('\n* * * * * * HANDLE INCOMING PACKET (%s) * * * * * * *' % self.packet_count)
self.log.debug("TIME: %s" % datetime.datetime.time(datetime.datetime.now()))
self.log.debug(" - - - ")
self.log.debug(("Interface", message.interface_name))
self.log.debug(("Data", message.data))
self.log.debug('\n* * * * * * * * * * * * * * * * * * * * * * *')
self.log.info("Message received from testing tool. Injecting in Tun. Message count (downlink): %s"
% self.packet_count)
print(arrow_up)
self.log.info('\n # # # # # # # # # # # # OPEN TUN # # # # # # # # # # # # ' +
'\n data packet EventBus -> TUN interface' +
'\n' + message.to_json() +
'\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'
)
# print(arrow_down)
# self.log.debug('\n* * * * * * HANDLE INCOMING PACKET (%s) * * * * * * *' % self.packet_count)
# self.log.debug("TIME: %s" % datetime.datetime.time(datetime.datetime.now()))
# self.log.debug(" - - - ")
# self.log.debug(("Interface", message.interface_name))
# self.log.debug(("Data", message.data))
# self.log.debug('\n* * * * * * * * * * * * * * * * * * * * * * *')
self.tun._eventBusToTun(
sender="Testing Tool",
signal="tun inject",
......
from __future__ import absolute_import
from . import messages
import logging
import os
......
......@@ -12,8 +12,8 @@ import sys
from kombu import Exchange
from utils import arrow_down, arrow_up, finterop_banner
from utils.messages import *
from . import arrow_down, arrow_up
from . import messages
DEFAULT_IPV6_PREFIX = 'bbbb'
......@@ -503,7 +503,7 @@ class OpenTunLinux(object):
This function forwards the data to the the EventBus.
"""
routing_key = MsgPacketSniffedRaw.routing_key.replace('*', self.name)
routing_key = messages.MsgPacketSniffedRaw.routing_key.replace('*', self.name)
log.debug("Pushing message to topic: %s" % routing_key)
self.packet_count += 1
......@@ -511,14 +511,14 @@ class OpenTunLinux(object):
% self.packet_count)
# dispatch to EventBus
m = MsgPacketSniffedRaw(
m = messages.MsgPacketSniffedRaw(
interface_name=self.ifname,
timestamp=time.time(),
data=data
)
print(arrow_up)
log.info('\n # # # # # # # # # # # # OPEN TUN # # # # # # # # # # # # ' +
'\n data packet TUN -> EventBus' +
'\n data packet TUN interface -> EventBus' +
'\n' + m.to_json() +
'\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'
)
......@@ -718,7 +718,7 @@ class OpenTunMACOS(object):
This function forwards the data to the the EventBus.
"""
routing_key = MsgPacketSniffedRaw.routing_key.replace('*', self.name)
routing_key = messages.MsgPacketSniffedRaw.routing_key.replace('*', self.name)
log.debug("Pushing message to topic: %s" % routing_key)
self.packet_count += 1
......@@ -726,14 +726,14 @@ class OpenTunMACOS(object):
% self.packet_count)
# dispatch to EventBus
m = MsgPacketSniffedRaw(
m = messages.MsgPacketSniffedRaw(
interface_name=self.ifname,
timestamp=time.time(),
data=data
)
print(arrow_up)
log.info('\n # # # # # # # # # # # # OPEN TUN # # # # # # # # # # # # ' +
'\n data packet TUN -> EventBus' +
'\n data packet TUN interface -> EventBus' +
'\n' + m.to_json() +
'\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # #'
)
......
......@@ -4,10 +4,12 @@ import json
import serial
import logging
import sys
from utils import messages
from kombu import Exchange
from collections import OrderedDict
from utils import arrow_down, arrow_up, finterop_banner
from . import messages
from . import arrow_down, arrow_up, finterop_banner
STATE_OK = 0
STATE_ESC = 1
......
# Author:
# Federico Sismondi <federico.sismondi@gmail.com>
#
# License: ???
# Federico Sismondi <federicosismondi@gmail.com>
from __future__ import absolute_import
import io
......@@ -51,7 +50,7 @@ setup(
'kombu',
'pika',
'pyserial',
'requests',
],
entry_points={'console_scripts': ['ioppytest-agent=agent.agent_cli:main']},
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment