Ejemplo n.º 1
0
 def query_na(self, eid):
     icn_packet = ICNPacket()
     icn_packet.setHeader("c11e70000000000000000000000c11e7",
                          "92500000000000000000000000000925", "00")
     cmd_type = binascii.a2b_hex("03")
     eid_hex = binascii.a2b_hex(eid)
     icn_packet.setPayload(cmd_type + eid_hex)
     icn_packet.fill_packet()
     reply = self.send(icn_packet)
     cmd_type = int(binascii.b2a_hex(reply.payload[:1]), 16)
     na = binascii.b2a_hex(reply.payload[17:21]).decode("utf-8")
     if cmd_type == 4:
         return na
     else:
         return None
Ejemplo n.º 2
0
 def request_handler(self, data, address):
     packet = ICNPacket()
     packet.byte2icn(data)
     packet.print_packet()
     payload = packet.payload
     cmd_type = int(binascii.b2a_hex(payload[:1]), 16)
     reply = ICNPacket()
     reply.setHeader("92500000000000000000000000000925",
                     "c11e70000000000000000000000c11e7", "00")
     if cmd_type == 1:
         reply.setPayload(self.register(payload))
     elif cmd_type == 3:
         reply.setPayload(self.query_na(payload))
     reply.fill_packet()
     reply.print_packet()
     self.send(reply, address)
Ejemplo n.º 3
0
 def query_hrn(self, eid):
     icn_packet = ICNPacket()
     icn_packet.setHeader("226cf119b78825f1720cf2ca485c2d85",
                          "00000000000000000000000000000000", "00")
     cmd_type = binascii.a2b_hex("05")
     hrn_hex = binascii.a2b_hex(eid)
     icn_packet.setPayload(cmd_type + hrn_hex)
     icn_packet.fill_packet()
     reply = self.send(icn_packet)
     cmd_type = int(binascii.b2a_hex(reply.payload[:1]), 16)
     ack = int(binascii.b2a_hex(reply.payload[1:2]), 16)
     if cmd_type == 6 and ack == 1:
         hrn_len = int(binascii.b2a_hex(reply.payload[2:3]), 16)
         hrn = reply.payload[3:3 + hrn_len].decode("utf-8")
         return hrn
     else:
         return None
Ejemplo n.º 4
0
 def register(self, eid, na):
     icn_packet = ICNPacket()
     icn_packet.setHeader("c11e70000000000000000000000c11e7",
                          "92500000000000000000000000000925", "00")
     cmd_type = binascii.a2b_hex("01")
     eid_hex = binascii.a2b_hex(eid)
     na_hex = binascii.a2b_hex(na)
     icn_packet.setPayload(cmd_type + eid_hex + na_hex)
     icn_packet.fill_packet()
     icn_packet.print_packet()
     reply = self.send(icn_packet)
     cmd_type = int(binascii.b2a_hex(reply.payload[:1]), 16)
     ack = int(binascii.b2a_hex(reply.payload[17:18]), 16)
     if cmd_type == 2 and ack == 1:
         return True
     else:
         return False
Ejemplo n.º 5
0
 def query_eid(self, hrn):
     icn_packet = ICNPacket()
     icn_packet.setHeader("226cf119b78825f1720cf2ca485c2d85",
                          "00000000000000000000000000000000", "00")
     cmd_type = binascii.a2b_hex("03")
     hrn_hex = hrn.encode("utf-8")
     hrn_len = len(hrn_hex)
     icn_packet.setPayload(cmd_type +
                           binascii.a2b_hex(int2byte(hrn_len, 8)) + hrn_hex)
     icn_packet.fill_packet()
     reply = self.send(icn_packet)
     cmd_type = int(binascii.b2a_hex(reply.payload[:1]), 16)
     ack = int(binascii.b2a_hex(reply.payload[1:2]), 16)
     if cmd_type == 4 and ack == 1:
         eid = binascii.b2a_hex(reply.payload[2:18])
         return eid.decode("utf-8")
     else:
         return None