Beispiel #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"])
Beispiel #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)
Beispiel #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())
    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)