Example #1
0
    def __init__(self, agent):
        """
        Initial route and client sets are empty. New routes are registered with add_route.
        New clients are registered/deregistered with register/deregister

        Messages are routed by packet type. All port agent endpoints will receive the Router.got_data
        callback on initialization. When data is received at an endpoint it will be used to generate a Packet
        which will be passed to got_data.

        All messages will be routed to all clients registered for a specific packet type. A special packet type
        of ALL will indicate that a client wishes to receive all messages.

        The data_format argument to add_route will determine the format of the message passed to the endpoint.
        A value of PACKET indicates the entire packet should be sent (packed), RAW indicates just the raw data
        will be passed and ASCII indicates the packet should be formatted in a method suitable for logging.
        """
        self.agent = agent
        self.routes = {}
        self.clients = {}
        self.producers = set()
        self.statistics = defaultdict(Counter)
        for packet_type in PacketType.values():
            self.routes[packet_type] = set()
        for endpoint_type in EndpointType.values():
            self.clients[endpoint_type] = set()

        self.stats_time = None

        stats_task = task.LoopingCall(self._log_stats)
        stats_task.start(interval=ROUTER_STATS_INTERVAL)
Example #2
0
 def logstring(self):
     if self._logstring is None:
         crc = 'CRC OK' if self.valid else 'CRC BAD'
         self._logstring = '%15.4f : %15s : %7s : %r' % (self.header.time,
                                                         PacketType.get_key(self.header.packet_type, 'UNKNOWN'),
                                                         crc,
                                                         self.payload)
     return self._logstring
Example #3
0
 def logstring(self):
     if self._logstring is None:
         crc = 'CRC OK' if self.valid else 'CRC BAD'
         self._logstring = '%15.4f : %15s : %7s : %r' % (
             self.header.time,
             PacketType.get_key(self.header.packet_type,
                                'UNKNOWN'), crc, self.payload)
     return self._logstring
Example #4
0
 def add_route(self, packet_type, endpoint_type, data_format=Format.RAW):
     """
     Route packets of packet_type to all endpoints of endpoint_type using data_format
     """
     self.statistics[RouterStat.ADD_ROUTE] += 1
     if packet_type == PacketType.ALL:
         for packet_type in PacketType.values():
             log.msg('ADD ROUTE: %s -> %s data_format: %s' % (packet_type, endpoint_type, data_format))
             self.routes[packet_type].add((endpoint_type, data_format))
     else:
         log.msg('ADD ROUTE: %s -> %s data_format: %s' % (packet_type, endpoint_type, data_format))
         self.routes[packet_type].add((endpoint_type, data_format))
Example #5
0
 def add_route(self, packet_type, endpoint_type, data_format=Format.RAW):
     """
     Route packets of packet_type to all endpoints of endpoint_type using data_format
     """
     self.statistics[endpoint_type][RouterStat.ADD_ROUTE] += 1
     if packet_type == PacketType.ALL:
         for packet_type in PacketType.values():
             log.msg('ADD ROUTE: %s -> %s data_format: %s' %
                     (packet_type, endpoint_type, data_format), logLevel=logging.DEBUG)
             self.routes[packet_type].add((endpoint_type, data_format))
     else:
         log.msg('ADD ROUTE: %s -> %s data_format: %s'
                 % (packet_type, endpoint_type, data_format), logLevel=logging.DEBUG)
         self.routes[packet_type].add((endpoint_type, data_format))