Esempio n. 1
0
 def test_mac_net_min(self, ):
     # Pack
     fmac = heymac.HeyMacFrame(fctl_type=heymac.HeyMacFrame.FCTL_TYPE_NET)
     fnet = heymac.APv6Frame()
     fmac.data = fnet
     b = bytes(fmac)
     self.assertEqual(b, b"\xe2\x80\xD7")
     # Unpack HeyMacFrame
     fmac = heymac.HeyMacFrame(b)
     self.assertEqual(fmac.pv_pid, fmac.PV_PID_HEYMAC)
     self.assertEqual(fmac.pv_ver, fmac.PV_VER_HEYMAC2)
     self.assertEqual(fmac.fctl_type, heymac.HeyMacFrame.FCTL_TYPE_NET)
     self.assertEqual(fmac.fctl_l, 0)
     self.assertEqual(fmac.fctl_p, 0)
     self.assertEqual(fmac.fctl_n, 0)
     self.assertEqual(fmac.fctl_d, 0)
     self.assertEqual(fmac.fctl_i, 0)
     self.assertEqual(fmac.fctl_s, 0)
     self.assertEqual(fmac.exttype, b"")
     self.assertEqual(fmac.netid, b"")
     self.assertEqual(fmac.daddr, b"")
     self.assertEqual(fmac.saddr, b"")
     self.assertTrue(len(fmac.data) > 0)
     # Unpack APv6Frame
     fnet = fmac.data
     self.assertEqual(type(fnet), heymac.APv6Frame)
     self.assertEqual(fnet.iphc_prefix, 6)
     self.assertEqual(fnet.iphc_nhc, 1)
     self.assertEqual(fnet.iphc_hlim, 1)
     self.assertEqual(fnet.iphc_sam, 1)
     self.assertEqual(fnet.iphc_dam, 1)
     self.assertEqual(fnet.hops, 0x01)
     self.assertEqual(fnet.src, b"")
     self.assertEqual(fnet.dst, b"")
Esempio n. 2
0
 def test_csma_ver(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.pid_protocol = heymac.HeyMacFrame.PID_PROTOCOL_HEYMAC
     f.pid_type = heymac.HeyMacFrame.PID_TYPE_CSMA
     f.pid_ver = 0 #heymac.HeyMacFrame.PID_VER_CSMA
     b = bytes(f)
     self.assertEqual(b, b"\xE4\x00")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.pid, 0xE4)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 0)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 0)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"")
     self.assertEqual(f.saddr, b"")
     self.assertEqual(f.data, b"")
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")
Esempio n. 3
0
 def test_mac_net_udp_to_google(self, ):
     # Pack
     fmac = heymac.HeyMacFrame(
         fctl_type=heymac.HeyMacFrame.FCTL_TYPE_NET,
         pend=0,
         saddr=b"\x35\x16",
     )
     google_ipv6_addr = b"\x20\x01\x48\x60\x48\x60\x00\x00\x00\x00\x00\x00\x00\x00\x88\x88"
     fnet = heymac.APv6Frame(dst=google_ipv6_addr, )
     fudp = heymac.APv6Udp(src_port=0xF0B0, dst_port=53, data=b"DnsRequest")
     fmac.data = fnet
     fnet.data = fudp
     b = bytes(fmac)
     self.assertEqual(
         b, b"\xe2\x81\x35\x16\xD6" + google_ipv6_addr +
         b"\xF6\xB0\x00\x35DnsRequest")
     # Unpack HeyMacFrame
     fmac = heymac.HeyMacFrame(b)
     self.assertEqual(fmac.pv_pid, fmac.PV_PID_HEYMAC)
     self.assertEqual(fmac.pv_ver, fmac.PV_VER_HEYMAC2)
     self.assertEqual(fmac.fctl_type, heymac.HeyMacFrame.FCTL_TYPE_NET)
     self.assertEqual(fmac.fctl_l, 0)
     self.assertEqual(fmac.fctl_p, 0)
     self.assertEqual(fmac.fctl_n, 0)
     self.assertEqual(fmac.fctl_d, 0)
     self.assertEqual(fmac.fctl_i, 0)
     self.assertEqual(fmac.fctl_s, 1)
     self.assertEqual(fmac.exttype, b"")
     self.assertEqual(fmac.netid, b"")
     self.assertEqual(fmac.daddr, b"")
     self.assertEqual(fmac.saddr, b"\x35\x16")
     self.assertTrue(len(fmac.data) > 0)
     # Unpack APv6Frame
     fnet = fmac.data
     self.assertEqual(type(fnet), heymac.APv6Frame)
     self.assertEqual(fnet.iphc_prefix, 6)
     self.assertEqual(fnet.iphc_nhc, 1)
     self.assertEqual(fnet.iphc_hlim, 1)
     self.assertEqual(fnet.iphc_sam, 1)
     self.assertEqual(fnet.iphc_dam, 0)
     self.assertEqual(fnet.hops, 1)
     self.assertEqual(fnet.src, b"")
     self.assertEqual(fnet.dst, google_ipv6_addr)
     # Unpack UDP
     fudp = fnet.data
     self.assertEqual(type(fudp), heymac.APv6Udp)
     self.assertEqual(fudp.hdr_type, 0b11110)
     self.assertEqual(fudp.hdr_co, 1)
     self.assertEqual(fudp.hdr_ports, 0b10)
     self.assertEqual(fudp.chksum, b"")
     self.assertEqual(fudp.src_port, 0xF0B0)
     self.assertEqual(fudp.dst_port, 53)
     self.assertEqual(fudp.data, b"DnsRequest")
Esempio n. 4
0
 def test_mac_net_udp_to_node(self, ):
     # Pack
     fmac = heymac.HeyMacFrame(fctl_type=heymac.HeyMacFrame.FCTL_TYPE_NET,
                               pend=0,
                               saddr=b"\x35\x16",
                               daddr=b"\x83\x11")
     fnet = heymac.APv6Frame()
     fudp = heymac.APv6Udp(src_port=0xF0BA,
                           dst_port=0xF0BF,
                           data=b"nodedata")
     fmac.data = fnet
     fnet.data = fudp
     b = bytes(fmac)
     self.assertEqual(b, b"\xe2\x85\x83\x11\x35\x16\xD7\xF7\xAFnodedata")
     # Unpack HeyMacFrame
     fmac = heymac.HeyMacFrame(b)
     self.assertEqual(fmac.pv_pid, fmac.PV_PID_HEYMAC)
     self.assertEqual(fmac.pv_ver, fmac.PV_VER_HEYMAC2)
     self.assertEqual(fmac.fctl_type, heymac.HeyMacFrame.FCTL_TYPE_NET)
     self.assertEqual(fmac.fctl_l, 0)
     self.assertEqual(fmac.fctl_p, 0)
     self.assertEqual(fmac.fctl_n, 0)
     self.assertEqual(fmac.fctl_d, 1)
     self.assertEqual(fmac.fctl_i, 0)
     self.assertEqual(fmac.fctl_s, 1)
     self.assertEqual(fmac.exttype, b"")
     self.assertEqual(fmac.netid, b"")
     self.assertEqual(fmac.daddr, b"\x83\x11")
     self.assertEqual(fmac.saddr, b"\x35\x16")
     self.assertTrue(len(fmac.data) > 0)
     # Unpack APv6Frame
     fnet = fmac.data
     self.assertEqual(type(fnet), heymac.APv6Frame)
     self.assertEqual(fnet.iphc_prefix, 6)
     self.assertEqual(fnet.iphc_nhc, 1)
     self.assertEqual(fnet.iphc_hlim, 1)
     self.assertEqual(fnet.iphc_sam, 1)
     self.assertEqual(fnet.iphc_dam, 1)
     self.assertEqual(fnet.hops, 1)
     self.assertEqual(fnet.src, b"")
     self.assertEqual(fnet.dst, b"")
     # Unpack UDP
     fudp = fnet.data
     self.assertEqual(type(fudp), heymac.APv6Udp)
     self.assertEqual(fudp.hdr_type, 0b11110)
     self.assertEqual(fudp.hdr_co, 1)
     self.assertEqual(fudp.hdr_ports, 0b11)
     self.assertEqual(fudp.chksum, b"")
     self.assertEqual(fudp.src_port, 0xF0BA)
     self.assertEqual(fudp.dst_port, 0xF0BF)
     self.assertEqual(fudp.data, b"nodedata")
Esempio n. 5
0
 def test_net_data(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.data = heymac.APv6Frame()
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x00\xD7")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 0)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 0)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"")
     self.assertEqual(f.saddr, b"")
     self.assertEqual(type(f.payld), heymac.APv6Frame)
Esempio n. 6
0
 def test_mac_min(self, ):
     # Pack
     fmac = heymac.HeyMacFrame(fctl_type=heymac.HeyMacFrame.FCTL_TYPE_MIN)
     b = bytes(fmac)
     self.assertEqual(b, b"\xe2\x00")
     # Unpack
     fmac = heymac.HeyMacFrame(b)
     self.assertEqual(fmac.pv_pid, fmac.PV_PID_HEYMAC)
     self.assertEqual(fmac.pv_ver, fmac.PV_VER_HEYMAC2)
     self.assertEqual(fmac.fctl_type, heymac.HeyMacFrame.FCTL_TYPE_MIN)
     self.assertEqual(fmac.fctl_l, 0)
     self.assertEqual(fmac.fctl_p, 0)
     self.assertEqual(fmac.fctl_n, 0)
     self.assertEqual(fmac.fctl_d, 0)
     self.assertEqual(fmac.fctl_i, 0)
     self.assertEqual(fmac.fctl_s, 0)
     self.assertEqual(fmac.exttype, b"")
     self.assertEqual(fmac.netid, b"")
     self.assertEqual(fmac.daddr, b"")
     self.assertEqual(fmac.saddr, b"")
     self.assertEqual(fmac.data, b"")
Esempio n. 7
0
 def test_min_payld(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.data = b"ABCD"
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x00ABCD")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 0)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 0)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"")
     self.assertEqual(f.saddr, b"")
     self.assertEqual(f.data, b"ABCD")
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")
Esempio n. 8
0
 def test_mac_len_saddr64b(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.saddr = b"\x01\x02\x03\x04\x05\x06\x07\x08"
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x44\x01\x02\x03\x04\x05\x06\x07\x08")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 1)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 0)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 1)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"")
     self.assertEqual(f.saddr, b"\x01\x02\x03\x04\x05\x06\x07\x08")
     self.assertEqual(f.data, b"")
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")
Esempio n. 9
0
 def test_mac_len_saddr16b_beacon(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.saddr = b"\x11\x12"
     bcn = heymac.mac_cmds.HeyMacCmdSbcn(
         bcn_en=1,
         sf_order=5,
         eb_order=7,
         dscpln=2,
         caps=3,
         status=4,
         asn=42,
     )
     f.data = bytes(bcn)
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x04\x11\x12\x81\xf5\x02\x03\x04\x00\x00\x00\x2a\x00\x00\x00\x00\x00\x00\x00\x00")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 0)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 1)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"")
     self.assertEqual(f.saddr, b"\x11\x12")
     self.assertEqual(type(f.payld), heymac.mac_cmds.HeyMacCmdSbcn)
     self.assertEqual(f.payld.bcn_en, 1)
     self.assertEqual(f.payld.sf_order, 5)
     self.assertEqual(f.payld.eb_order, 7)
     self.assertEqual(f.payld.dscpln, 2)
     self.assertEqual(f.payld.caps, 3)
     self.assertEqual(f.payld.status, 4)
     self.assertEqual(f.payld.asn, 42)
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")
Esempio n. 10
0
 def test_mac(self,):
     # Pack
     f = heymac.HeyMacFrame()
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x00")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertTrue(f.is_heymac())
     self.assertTrue(f.is_heymac_version_compatible())
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 0)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 0)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"")
     self.assertEqual(f.saddr, b"")
     self.assertEqual(f.data, b"")
     self.assertEqual(f.hops, b"") # FIXME
     self.assertEqual(f.txaddr, b"")
Esempio n. 11
0
 def test_netid_daddr(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.netid = 0x80A5
     f.daddr = 0xd1d2
     f.data = b"data"
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x30\x80\xa5\xd1\xd2data")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 1)
     self.assertEqual(f.fctl_d, 1)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 0)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"\x80\xA5")
     self.assertEqual(f.daddr, b"\xd1\xd2")
     self.assertEqual(f.saddr, b"")
     self.assertEqual(f.data, b"data")
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")
Esempio n. 12
0
 def test_mac_len_saddr16b_daddr16b(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.daddr = b"\xd1\xd2"
     f.saddr = b"\xc1\xc2"
     f.data = b"hello world"
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x14\xd1\xd2\xc1\xc2hello world")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 0)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 1)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 1)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"\xd1\xd2")
     self.assertEqual(f.saddr, b"\xc1\xc2")
     self.assertEqual(f.data, b"hello world")
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")
Esempio n. 13
0
 def test_mac_len_saddr64b_daddr64b(self,):
     # Pack
     f = heymac.HeyMacFrame()
     f.daddr = b"\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8"
     f.saddr = b"\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8"
     f.data = b"hi"
     b = bytes(f)
     self.assertEqual(b, b"\xE0\x54\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8hi")
     # Unpack
     f = heymac.HeyMacFrame(b)
     self.assertEqual(f.fctl_x, 0)
     self.assertEqual(f.fctl_l, 1)
     self.assertEqual(f.fctl_n, 0)
     self.assertEqual(f.fctl_d, 1)
     self.assertEqual(f.fctl_i, 0)
     self.assertEqual(f.fctl_s, 1)
     self.assertEqual(f.fctl_m, 0)
     self.assertEqual(f.fctl_p, 0)
     self.assertEqual(f.netid, b"")
     self.assertEqual(f.daddr, b"\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8")
     self.assertEqual(f.saddr, b"\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8")
     self.assertEqual(f.data, b"hi")
     self.assertEqual(f.hops, b"")
     self.assertEqual(f.txaddr, b"")