コード例 #1
0
ファイル: router.py プロジェクト: steinermg/ooi_port_agent
    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)
コード例 #2
0
ファイル: packet.py プロジェクト: JeffRoy/ooi_port_agent
 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
コード例 #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
コード例 #4
0
ファイル: router.py プロジェクト: ronkyo/ooi_port_agent
 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))
コード例 #5
0
ファイル: router.py プロジェクト: steinermg/ooi_port_agent
 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))