Exemplo n.º 1
0
    def add_forward_action(self,
                           interface_type=InterfaceType.HOST,
                           interface_configuration=None):
        if interface_configuration is not None and interface_type == InterfaceType.HOST:
            raise ValueError(
                "interface_configuration is not supported for interface_type HOST"
            )

        if interface_type == InterfaceType.D7ASP:
            if interface_configuration is None:
                interface_configuration = Configuration()

            self.actions.append(
                RegularAction(operation=Forward(operand=InterfaceConfiguration(
                    interface_id=InterfaceType.D7ASP,
                    interface_configuration=interface_configuration))))
        elif interface_type == InterfaceType.SERIAL:
            self.actions.append(
                RegularAction(operation=Forward(operand=InterfaceConfiguration(
                    interface_id=InterfaceType.SERIAL))))
        elif interface_type == InterfaceType.LORAWAN_ABP:
            self.actions.append(
                RegularAction(operation=Forward(operand=InterfaceConfiguration(
                    interface_id=InterfaceType.LORAWAN_ABP,
                    interface_configuration=interface_configuration))))
        elif interface_type == InterfaceType.LORAWAN_OTAA:
            self.actions.append(
                RegularAction(operation=Forward(operand=InterfaceConfiguration(
                    interface_id=InterfaceType.LORAWAN_OTAA,
                    interface_configuration=interface_configuration))))
        elif interface_type == InterfaceType.HOST:
            pass
        else:
            raise ValueError(
                "interface_type {} is not supported".format(interface_type))
Exemplo n.º 2
0
  def parse_forward_action(self, b7, b6, s):
    if b7:
      raise ParseError("bit 7 is RFU")

    interface_id = InterfaceType(int(s.read("uint:8")))
    assert(interface_id == InterfaceType.D7ASP)
    interface_config = Configuration.parse(s)
    return ForwardAction(resp=b6, operation=Forward(operand=InterfaceConfiguration(interface_id=interface_id,
                                                                                   interface_configuration=interface_config)))
Exemplo n.º 3
0
    def test_byte_generation(self):
        d7asp_config = Configuration()
        forward_action = Forward(operand=InterfaceConfiguration(
            interface_id=InterfaceType.D7ASP,
            interface_configuration=d7asp_config))

        bytes = bytearray(forward_action)
        self.assertEqual(len(bytes), len(bytearray(d7asp_config)) + 1)
        self.assertEqual(bytes[0], 0xD7)
        self.assertEqual(bytes[1:], bytearray(d7asp_config))
Exemplo n.º 4
0
    def add_forward_action(self,
                           interface_type=InterfaceType.HOST,
                           interface_configuration=None):
        if interface_configuration is not None and interface_type == InterfaceType.HOST:
            raise ValueError(
                "interface_configuration is not supported for interface_type HOST"
            )

        if interface_type == InterfaceType.D7ASP:
            if interface_configuration is None:
                interface_configuration = Configuration()

            self.actions.append(
                RegularAction(operation=Forward(operand=InterfaceConfiguration(
                    interface_id=InterfaceType.D7ASP,
                    interface_configuration=interface_configuration))))
Exemplo n.º 5
0
    def parse_forward_action(self, b7, b6, s):
        if b7:
            raise ParseError("bit 7 is RFU")

        interface_id = InterfaceType(int(s.read("uint:8")))
        interface_config = None
        if (interface_id == InterfaceType.D7ASP):
            interface_config = Configuration.parse(s)
        elif (interface_id == InterfaceType.SERIAL):
            pass  # no interface config
        else:
            assert (False)

        return ForwardAction(resp=b6,
                             operation=Forward(operand=InterfaceConfiguration(
                                 interface_id=interface_id,
                                 interface_configuration=interface_config)))
Exemplo n.º 6
0
  def test_byte_generation_forward_LoRaWAN_OTAA_iface(self):
    lorawan_config = LoRaWANInterfaceConfigurationOTAA(
      adr_enabled=True,
      request_ack=False,
      app_port=0x01,
      data_rate=0,
      device_eui=[0xBE, 0X7A, 0X00, 0X00, 0X00, 0X00, 0X1B, 0X81],
      app_eui=[0xBE, 0X7A, 0X00, 0X00, 0X00, 0X00, 0X0D, 0X9F],
      app_key=[0X7E, 0XEF, 0X56, 0XEC, 0XDA, 0X1D, 0XD5, 0XA4, 0X70, 0X59, 0XFD, 0X35, 0X9C, 0XE6, 0X80, 0XCD]
    )

    forward_action = Forward(
      operand=InterfaceConfiguration(
        interface_id=InterfaceType.LORAWAN_OTAA,
        interface_configuration=lorawan_config
      )
    )

    bytes = bytearray(forward_action)
    self.assertEqual(len(bytes), len(bytearray(lorawan_config)) + 1)
    self.assertEqual(bytes[0], 0x03)
    self.assertEqual(bytes[1:], bytearray(lorawan_config))
Exemplo n.º 7
0
  def test_byte_generation_forward_LoRaWAN_ABP_iface(self):
    lorawan_config = LoRaWANInterfaceConfigurationABP(
      adr_enabled=True,
      request_ack=False,
      app_port=0x01,
      data_rate=0,
      netw_session_key=[0x53, 0X1b, 0Xd9, 0Xc5, 0Xec, 0X5d, 0X8b, 0Xa5, 0Xef, 0X3b, 0X26, 0X2c, 0Xeb, 0Xfb, 0X3e, 0X66],
      app_session_key=[0x53, 0X1b, 0Xd9, 0Xc5, 0Xec, 0X5d, 0X8b, 0Xa5, 0Xef, 0X3b, 0X26, 0X2c, 0Xeb, 0Xfb, 0X3e, 0X66],
      dev_addr=1,
      netw_id=2,
    )

    forward_action = Forward(
      operand=InterfaceConfiguration(
        interface_id=InterfaceType.LORAWAN_ABP,
        interface_configuration=lorawan_config
      )
    )

    bytes = bytearray(forward_action)
    self.assertEqual(len(bytes), len(bytearray(lorawan_config)) + 1)
    self.assertEqual(bytes[0], 0x02)
    self.assertEqual(bytes[1:], bytearray(lorawan_config))