Example #1
0
 def notify(self, event: Event):
     from interface_listener import RootPacketForwardEvent
     from serial_connection import ResponseToPacketRequest
     if isinstance(event, RootPacketForwardEvent):
         self.add_packet(event.get_event())
     if isinstance(event, ResponseToPacketRequest):
         self.handle_packet(event.get_event()["question_id"],
                            event.get_event()["response"])
Example #2
0
 def notify(self, event: Event):
     from serial_connection import MoteGlobalAddressEvent
     if isinstance(event, MoteGlobalAddressEvent):
         self.set_wifi_ipv6_lobal_address(event.get_event())
     elif isinstance(event, ChangeModeEvent):
         mode = event.get_event()
         if mode == Data.MODE_NODE:
             self._unset_address(self._root_address)
             self._add_route(self._root_address)
         elif mode == Data.MODE_ROOT:
             self._set_address(self._root_address)
             self._remove_route(self._root_address)
Example #3
0
 def notify(self, event: Event):
     from interface_listener import PacketSendToSerialEvent, PacketForwardToSerialEvent
     from data import PacketBuffEvent
     if isinstance(event, ContikiBootEvent):
         self.send_config_to_contiki()
     elif isinstance(event, PacketSendToSerialEvent):
         self.send_packet_to_contiki(event.get_event())
     elif isinstance(event, PacketForwardToSerialEvent):
         self.forward_packet_to_contiki(event.get_event())
     elif isinstance(event, PacketBuffEvent):
         self.request_forward_packet_decision(event.get_event()["id"],
                                              event.get_event()["packet"])
     elif isinstance(event, HelloBridgeRequestEvent):
         self._send_hello_response()
 def notify(self, event: Event):
     from serial_connection import SerialPacketToSendEvent
     if isinstance(event, SerialPacketToSendEvent):
         self.send_packet(event.get_event())
Example #5
0

class Test:
    def __init__(self, order):
        self.order = order

    def callback_create_tx(self, event):
        print(f"{event}, order {self.order}")

    def callback_create_block(self, event):
        print(f"{event}, order {self.order}")


event_system = EventSystem()

test = Test(0)

event_system.subscribe(Event.CreateBlock, test.callback_create_block,
                       test.order)
event_system.subscribe(Event.CreateBlock, callback_create_block10, 10)

event_system.subscribe(Event.CreateTx, test.callback_create_tx, test.order)
event_system.subscribe(Event.CreateTx, callback_create_tx10, 10)
event_system.unsubscribe(Event.CreateTx, test.callback_create_tx)

e = Event.CreateBlock(block_hash="123")
event_system.publish(e)

e = Event.CreateTx(tx_hash="abc")
event_system.publish(e)
 def __init__(self, data: NodeAddress):
     Event.__init__(self, data)
     logging.info('BRIDGE:refreshed node address "{}"'.format(data))
    def notify(self, event: Event):
        from serial_connection import RequestRouteToMoteEvent
        if isinstance(event, NeighbourSolicitationEvent):
            self._sender.send_icmpv6_na(src_l2=event.get_event()["src_l2"], src_ip=event.get_event()["src_ip"],
                                        target_ip=event.get_event()["target_ip"])

        elif isinstance(event, NewNodeEvent):
            technology = event.get_event().get_tech_type()
            if technology != "wifi":
                new_ip = str(event.get_event().get_ip_address())
                self._pendings.add_pending(new_ip, self._sender.send_icmpv6_ns)
        elif isinstance(event, NodeRefreshEvent):
            technology = event.get_event().get_tech_type()
            if technology == "wifi":
                mote_ip = None
                next_node = event.get_event().get_node_addresses()
                for key in next_node:
                    if next_node[key].get_tech_type() == "rpl":
                        mote_ip = str(next_node[key].get_ip_address())
                if mote_ip:
                    self._pendings.remove_pending(mote_ip)
                    self._pendings.add_pending(mote_ip, self._sender.send_icmpv6_ns)
        elif isinstance(event, NeighbourAdvertisementEvent):
            src_ip = event.get_event()["src_ip"]
            target_ip = event.get_event()["target_ip"]
            src_l2_addr = event.get_event()["src_l2_addr"]

            if self._pendings.has_pending(target_ip):
                pending = self._pendings.get_pending(target_ip)
                if pending:
                    pending.set_status(PendingEntry.STATUS_SUCCESS)
                # response to NS for border router
                if self._data.get_configuration()['border-router']['ipv6'] == target_ip:
                    self._data.set_border_router_l2_address(src_l2_addr)
                else:
                    wifi_node_address = self._node_table.get_node_address(src_ip, 'wifi')
                    if not wifi_node_address:
                        wifi_node_address = NodeAddress(src_ip, 'wifi', src_l2_addr)
                    self._node_table.add_node_address(wifi_node_address)

                    mote_node_address = self._node_table.get_node_address(target_ip, 'rpl')
                    if mote_node_address:
                        mote_node_address.add_next_node_address(wifi_node_address)
        elif isinstance(event, RequestRouteToMoteEvent):
            node = self._node_table.get_node_address(event.get_event()["ip_addr"], 'rpl')
            if node and node.has_neighbor_with_tech('wifi'):
                response = 1
            else:
                response = 0
            self._slip_commands.send_route_request_response_to_contiki(event.get_event()["question_id"], response)
Example #8
0
 def __init__(self, data: dict):
     Event.__init__(self, data)
     logging.debug("BRIDGE: new packet in buffer")
Example #9
0
 def __init__(self, data: ContikiPacket):
     Event.__init__(self, data)
     logging.debug('BRIDGE:incoming packet to send')
 def __init__(self, data: ContikiPacket):
     Event.__init__(self, data)
     logging.debug(
         'BRIDGE:Asking for forward decision for packet "{}"'.format(
             data.get_contiki_format()))
Example #11
0
 def __init__(self):
     Event.__init__(self, None)
Example #12
0
 def __init__(self, data: dict):
     Event.__init__(self, data)
     logging.debug('CONTIKI: sending response "{}" to path id: "{}"'.format(
         data["response"], data['question_id']))
Example #13
0
 def __init__(self, data: dict):
     Event.__init__(self, data)
     logging.debug(
         'BRIDGE: contiki needs wants to use wifi for target host "{}"'.
         format(data['ip_addr']))
Example #14
0
 def __init__(self, data: str):
     Event.__init__(self, data)
     logging.info(
         'BRIDGE: contiki uses global IPv6 address "{}"'.format(data))
 def __init__(self, data: dict):
     Event.__init__(self, data)
     logging.debug(
         'BRIDGE:Sending response to ICMPv6 neighbour solicitation for address "{}"'
         .format(data['target_ip']))
 def __init__(self, data: dict):
     Event.__init__(self, data)
     logging.debug('BRIDGE:Received ICMPv6 NA for ip"{}"'.format(
         data['src_l2_addr']))
Example #17
0
 def __init__(self, data: int):
     Event.__init__(self, data)
     logging.info('CONTIKI: sets node mode to "{}"'.format(data))
 def __init__(self, data: ContikiPacket):
     Event.__init__(self, data)
     logging.debug('BRIDGE:Packet send to serial event')
Example #19
0
 def __init__(self, line: str):
     Event.__init__(self, line)
     logging.info('CONTIKI: contiki device is booting')