Newer
Older
def END(self):
self.res += "s"
return self.res
a=ATMT9(debug=5, ll=lambda: None, recvsock=lambda: None)
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
a.run()
assert( _ == "VENUs" )
a.restart()
a.run()
assert( _ == "VENUs" )
a.restart()
a.BEGIN.intercepts()
while True:
try:
x = a.run()
except Automaton.InterceptionPoint,p:
a.accept_packet(Raw(p.packet.load.lower()), wait=False)
else:
break
x
assert( _ == "Venus" )
############
############
+ Test IP options
= IP options individual assembly
~ IP options
str(IPOption())
str(IPOption_LSRR(routers=["1.2.3.4","5.6.7.8"]))
assert(_ == b'\x83\x0b\x04\x01\x02\x03\x04\x05\x06\x07\x08')
= IP options individual dissection
~ IP options
assert(_.option == 0 and isinstance(_, IPOption_EOL))
assert(_.option == 1 and isinstance(_, IPOption_NOP))
p=IPOption_LSRR(lsrr)
p
q=IPOption(lsrr)
q
assert(p == q)
= IP assembly and dissection with options
~ IP options
p = IP(src="9.10.11.12",dst="13.14.15.16",options=IPOption_SDBM(addresses=["1.2.3.4","5.6.7.8"]))/TCP()
str(p)
assert(_ == b'H\x00\x004\x00\x01\x00\x00@\x06\xa2q\t\n\x0b\x0c\r\x0e\x0f\x10\x95\n\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00_K\x00\x00')
q=IP(_)
q
assert( isinstance(q.options[0],IPOption_SDBM) )
assert( q[IPOption_SDBM].addresses[1] == "5.6.7.8" )
p.options[0].addresses[0] = '5.6.7.8'
assert( IP(str(p)).options[0].addresses[0] == '5.6.7.8' )
IP(src="9.10.11.12", dst="13.14.15.16", options=[IPOption_NOP(),IPOption_LSRR(routers=["1.2.3.4","5.6.7.8"]),IPOption_Security(transmission_control_code="XYZ")])/TCP()
str(_)
assert(_ == b'K\x00\x00@\x00\x01\x00\x00@\x06\xf3\x83\t\n\x0b\x0c\r\x0e\x0f\x10\x01\x83\x0b\x04\x01\x02\x03\x04\x05\x06\x07\x08\x82\x0b\x00\x00\x00\x00\x00\x00XYZ\x00\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00_K\x00\x00')
IP(_)
q=_
assert(q[IPOption_LSRR].get_current_router() == "1.2.3.4")
assert(q[IPOption_Security].transmission_control_code == "XYZ")
assert(q[TCP].flags == 2)
############
############
+ Test PPP
= PPP/HDLC
~ ppp hdlc
HDLC()/PPP()/PPP_IPCP()
str(_)
s=_
PPP(s)
p=_
assert(HDLC in p)
assert(p[HDLC].control==3)
assert(p[PPP].proto==0x8021)
PPP(s[2:])
q=_
assert(HDLC not in q)
assert(q[PPP].proto==0x8021)
= PPP IPCP
~ ppp ipcp
PPP(b'\x80!\x01\x01\x00\x10\x03\x06\xc0\xa8\x01\x01\x02\x06\x00-\x0f\x01')
p=_
assert(p[PPP_IPCP].code == 1)
assert(p[PPP_IPCP_Option_IPAddress].data=="192.168.1.1")
p=PPP()/PPP_IPCP(options=[PPP_IPCP_Option_DNS1(data="1.2.3.4"),PPP_IPCP_Option_DNS2(data="5.6.7.8"),PPP_IPCP_Option_NBNS2(data="9.10.11.12")])
str(p)
assert(_ == b'\x80!\x01\x00\x00\x16\x81\x06\x01\x02\x03\x04\x83\x06\x05\x06\x07\x08\x84\x06\t\n\x0b\x0c')
PPP(_)
q=_
assert(str(p) == str(q))
assert(PPP(str(q))==q)
PPP()/PPP_IPCP(options=[PPP_IPCP_Option_DNS1(data="1.2.3.4"),PPP_IPCP_Option_DNS2(data="5.6.7.8"),PPP_IPCP_Option(type=123,data="ABCDEFG"),PPP_IPCP_Option_NBNS2(data="9.10.11.12")])
p=_
str(p)
assert(_ == b'\x80!\x01\x00\x00\x1f\x81\x06\x01\x02\x03\x04\x83\x06\x05\x06\x07\x08{\tABCDEFG\x84\x06\t\n\x0b\x0c')
PPP(_)
q=_
assert( q[PPP_IPCP_Option].type == 123 )
assert( q[PPP_IPCP_Option].data == 'ABCDEFG' )
assert( q[PPP_IPCP_Option_NBNS2].data == '9.10.11.12' )
= PPP ECP
~ ppp ecp
PPP()/PPP_ECP(options=[PPP_ECP_Option_OUI(oui="XYZ")])
p=_
str(p)
PPP(_)
q=_
assert( str(p)==str(q) )
PPP()/PPP_ECP(options=[PPP_ECP_Option_OUI(oui="XYZ"),PPP_ECP_Option(type=1,data="ABCDEFG")])
p=_
str(p)
assert(_ == b'\x80S\x01\x00\x00\x13\x00\x06XYZ\x00\x01\tABCDEFG')
PPP(_)
q=_
assert( str(p) == str(q) )
assert( q[PPP_ECP_Option].data == "ABCDEFG" )
############
############
+ Test IPv6 Class
= IPv6 Class basic Instantiation
a=IPv6()
= IPv6 Class basic build (default values)
str(IPv6()) == b'`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
= IPv6 Class basic dissection (default values)
a=IPv6(str(IPv6()))
a.version == 6 and a.tc == 0 and a.fl == 0 and a.plen == 0 and a.nh == 59 and a.hlim ==64 and a.src == "::1" and a.dst == "::1"
= IPv6 Class with basic TCP stacked - build
str(IPv6()/TCP()) == b'`\x00\x00\x00\x00\x14\x06@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x8f}\x00\x00'
= IPv6 Class with basic TCP stacked - dissection
a=IPv6(str(IPv6()/TCP()))
a.nh == 6 and a.plen == 20 and isinstance(a.payload, TCP) and a.payload.chksum == 0x8f7d
= IPv6 Class with TCP and TCP data - build
str(IPv6()/TCP()/Raw(load="somedata")) == b'`\x00\x00\x00\x00\x1c\x06@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\xd5\xdd\x00\x00somedata'
= IPv6 Class with TCP and TCP data - dissection
a=IPv6(str(IPv6()/TCP()/Raw(load="somedata")))
a.nh == 6 and a.plen == 28 and isinstance(a.payload, TCP) and a.payload.chksum == 0xd5dd and isinstance(a.payload.payload, Raw) and a[Raw].load == "somedata"
= IPv6 Class binding with Ethernet - build
str(Ether(src="00:00:00:00:00:00", dst="ff:ff:ff:ff:ff:ff")/IPv6()/TCP()) == b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x86\xdd`\x00\x00\x00\x00\x14\x06@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x8f}\x00\x00'
= IPv6 Class binding with Ethernet - dissection
a=Ether(str(Ether()/IPv6()/TCP()))
a.type == 0x86dd
= IPv6 Class binding with GRE - build
str(IP()/GRE()/Ether()/IP()/GRE()/IPv6()) == b'E\x00\x00f\x00\x01\x00\x00@/|f\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00eX\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00@\x00\x01\x00\x00@/|\x8c\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00\x86\xdd`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
= IPv6 Class binding with GRE - dissection
p = IP(str(IP()/GRE()/Ether()/IP()/GRE()/IPv6()))
GRE in p and p[GRE:1].proto == 0x6558 and p[GRE:2].proto == 0x86DD and IPv6 in p
########### IPv6ExtHdrRouting Class ###########################
= IPv6ExtHdrRouting Class - No address - build
str(IPv6(src="2048::deca", dst="2047::cafe")/IPv6ExtHdrRouting(addresses=[])/TCP(dport=80)) ==b'`\x00\x00\x00\x00\x1c+@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x06\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\xa5&\x00\x00'
str(IPv6(src="2048::deca", dst="2047::cafe")/IPv6ExtHdrRouting(addresses=["2022::deca"])/TCP(dport=80)) == b'`\x00\x00\x00\x00,+@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x06\x02\x00\x01\x00\x00\x00\x00 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x91\x7f\x00\x00'
= IPv6ExtHdrRouting Class - Multiple Addresses - build
str(IPv6(src="2048::deca", dst="2047::cafe")/IPv6ExtHdrRouting(addresses=["2001::deca", "2022::deca"])/TCP(dport=80)) == b'`\x00\x00\x00\x00<+@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x06\x04\x00\x02\x00\x00\x00\x00 \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x91\x7f\x00\x00'
= IPv6ExtHdrRouting Class - Specific segleft (2->1) - build
str(IPv6(src="2048::deca", dst="2047::cafe")/IPv6ExtHdrRouting(addresses=["2001::deca", "2022::deca"], segleft=1)/TCP(dport=80)) == b'`\x00\x00\x00\x00<+@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x06\x04\x00\x01\x00\x00\x00\x00 \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x91\x7f\x00\x00'
= IPv6ExtHdrRouting Class - Specific segleft (2->0) - build
str(IPv6(src="2048::deca", dst="2047::cafe")/IPv6ExtHdrRouting(addresses=["2001::deca", "2022::deca"], segleft=0)/TCP(dport=80)) == b'`\x00\x00\x00\x00<+@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x06\x04\x00\x00\x00\x00\x00\x00 \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\xa5&\x00\x00'
########### IPv6ExtHdrSegmentRouting Class ###########################
= IPv6ExtHdrSegmentRouting Class - default - build & dissect
s = str(IPv6()/IPv6ExtHdrSegmentRouting()/UDP())
assert(s == b'`\x00\x00\x00\x00 +@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x11\x02\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x005\x005\x00\x08\xffr')
p = IPv6(s)
assert(UDP in p and IPv6ExtHdrSegmentRouting in p)
assert(len(p[IPv6ExtHdrSegmentRouting].addresses) == 1 and len(p[IPv6ExtHdrSegmentRouting].tlv_objects) == 0)
= IPv6ExtHdrSegmentRouting Class - empty lists - build & dissect
s = str(IPv6()/IPv6ExtHdrSegmentRouting(addresses=[], tlv_objects=[])/UDP())
assert(s == b'`\x00\x00\x00\x00\x10+@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x11\x00\x04\x00\x00\x00\x00\x00\x005\x005\x00\x08\xffr')
p = IPv6(s)
assert(UDP in p and IPv6ExtHdrSegmentRouting in p)
assert(len(p[IPv6ExtHdrSegmentRouting].addresses) == 0 and len(p[IPv6ExtHdrSegmentRouting].tlv_objects) == 0)
= IPv6ExtHdrSegmentRouting Class - addresses list - build & dissect
s = str(IPv6()/IPv6ExtHdrSegmentRouting(addresses=["::1", "::2", "::3"])/UDP())
assert(s == b'`\x00\x00\x00\x00@+@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x11\x06\x04\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x005\x005\x00\x08\xffr')
p = IPv6(s)
assert(UDP in p and IPv6ExtHdrSegmentRouting in p)
assert(len(p[IPv6ExtHdrSegmentRouting].addresses) == 3 and len(p[IPv6ExtHdrSegmentRouting].tlv_objects) == 0)
= IPv6ExtHdrSegmentRouting Class - TLVs list - build & dissect
s = str(IPv6()/IPv6ExtHdrSegmentRouting(addresses=[], tlv_objects=[IPv6ExtHdrSegmentRoutingTLV()])/TCP())
assert(s == b'`\x00\x00\x00\x00$+@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x06\x01\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x02\x00\x00\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x8f}\x00\x00')
p = IPv6(s)
assert(TCP in p and IPv6ExtHdrSegmentRouting in p)
assert(len(p[IPv6ExtHdrSegmentRouting].addresses) == 0 and len(p[IPv6ExtHdrSegmentRouting].tlv_objects) == 2)
assert(isinstance(p[IPv6ExtHdrSegmentRouting].tlv_objects[1], IPv6ExtHdrSegmentRoutingTLVPadding))
= IPv6ExtHdrSegmentRouting Class - both lists - build & dissect
s = str(IPv6()/IPv6ExtHdrSegmentRouting(addresses=["::1", "::2", "::3"], tlv_objects=[IPv6ExtHdrSegmentRoutingTLVIngressNode(),IPv6ExtHdrSegmentRoutingTLVEgressNode()])/ICMPv6EchoRequest())
assert(s == b'`\x00\x00\x00\x00h+@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01:\x0b\x04\x02\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x01\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x80\x00\x7f\xbb\x00\x00\x00\x00')
p = IPv6(s)
assert(ICMPv6EchoRequest in p and IPv6ExtHdrSegmentRouting in p)
assert(len(p[IPv6ExtHdrSegmentRouting].addresses) == 3 and len(p[IPv6ExtHdrSegmentRouting].tlv_objects) == 2)
############
############
+ Test in6_get6to4Prefix()
= Test in6_get6to4Prefix() - 0.0.0.0 address
in6_get6to4Prefix("0.0.0.0") == "2002::"
= Test in6_get6to4Prefix() - 255.255.255.255 address
in6_get6to4Prefix("255.255.255.255") == "2002:ffff:ffff::"
= Test in6_get6to4Prefix() - 1.1.1.1 address
in6_get6to4Prefix("1.1.1.1") == "2002:101:101::"
= Test in6_get6to4Prefix() - invalid address
in6_get6to4Prefix("somebadstring") is None
############
############
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
+ Test in6_6to4ExtractAddr()
= Test in6_6to4ExtractAddr() - 2002:: address
in6_6to4ExtractAddr("2002::") == "0.0.0.0"
= Test in6_6to4ExtractAddr() - 255.255.255.255 address
in6_6to4ExtractAddr("2002:ffff:ffff::") == "255.255.255.255"
= Test in6_6to4ExtractAddr() - "2002:101:101::" address
in6_6to4ExtractAddr("2002:101:101::") == "1.1.1.1"
= Test in6_6to4ExtractAddr() - invalid address
in6_6to4ExtractAddr("somebadstring") is None
########### RFC 4489 - Link-Scoped IPv6 Multicast address ###########
= in6_getLinkScopedMcastAddr() : default generation
a = in6_getLinkScopedMcastAddr(addr="FE80::")
a == 'ff32:ff::'
= in6_getLinkScopedMcastAddr() : different valid scope values
a = in6_getLinkScopedMcastAddr(addr="FE80::", scope=0)
b = in6_getLinkScopedMcastAddr(addr="FE80::", scope=1)
c = in6_getLinkScopedMcastAddr(addr="FE80::", scope=2)
d = in6_getLinkScopedMcastAddr(addr="FE80::", scope=3)
a == 'ff30:ff::' and b == 'ff31:ff::' and c == 'ff32:ff::' and d is None
= in6_getLinkScopedMcastAddr() : grpid in different formats
a = in6_getLinkScopedMcastAddr(addr="FE80::A12:34FF:FE56:7890", grpid=b"\x12\x34\x56\x78")
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
b = in6_getLinkScopedMcastAddr(addr="FE80::A12:34FF:FE56:7890", grpid="12345678")
c = in6_getLinkScopedMcastAddr(addr="FE80::A12:34FF:FE56:7890", grpid=305419896)
a == b and b == c
########### ethernet address to iface ID conversion #################
= in6_mactoifaceid() conversion function (test 1)
in6_mactoifaceid("FD:00:00:00:00:00", ulbit=0) == 'FD00:00FF:FE00:0000'
= in6_mactoifaceid() conversion function (test 2)
in6_mactoifaceid("FD:00:00:00:00:00", ulbit=1) == 'FF00:00FF:FE00:0000'
= in6_mactoifaceid() conversion function (test 3)
in6_mactoifaceid("FD:00:00:00:00:00") == 'FF00:00FF:FE00:0000'
= in6_mactoifaceid() conversion function (test 4)
in6_mactoifaceid("FF:00:00:00:00:00") == 'FD00:00FF:FE00:0000'
= in6_mactoifaceid() conversion function (test 5)
in6_mactoifaceid("FF:00:00:00:00:00", ulbit=1) == 'FF00:00FF:FE00:0000'
= in6_mactoifaceid() conversion function (test 6)
in6_mactoifaceid("FF:00:00:00:00:00", ulbit=0) == 'FD00:00FF:FE00:0000'
########### iface ID conversion #################
= in6_mactoifaceid() conversion function (test 1)
in6_ifaceidtomac(in6_mactoifaceid("FD:00:00:00:00:00", ulbit=0)) == 'ff:00:00:00:00:00'
= in6_mactoifaceid() conversion function (test 2)
in6_ifaceidtomac(in6_mactoifaceid("FD:00:00:00:00:00", ulbit=1)) == 'fd:00:00:00:00:00'
= in6_mactoifaceid() conversion function (test 3)
in6_ifaceidtomac(in6_mactoifaceid("FD:00:00:00:00:00")) == 'fd:00:00:00:00:00'
= in6_mactoifaceid() conversion function (test 4)
in6_ifaceidtomac(in6_mactoifaceid("FF:00:00:00:00:00")) == 'ff:00:00:00:00:00'
= in6_mactoifaceid() conversion function (test 5)
in6_ifaceidtomac(in6_mactoifaceid("FF:00:00:00:00:00", ulbit=1)) == 'fd:00:00:00:00:00'
= in6_mactoifaceid() conversion function (test 6)
in6_ifaceidtomac(in6_mactoifaceid("FF:00:00:00:00:00", ulbit=0)) == 'ff:00:00:00:00:00'
= in6_addrtomac() conversion function (test 1)
in6_addrtomac("FE80::" + in6_mactoifaceid("FD:00:00:00:00:00", ulbit=0)) == 'ff:00:00:00:00:00'
= in6_addrtomac() conversion function (test 2)
in6_addrtomac("FE80::" + in6_mactoifaceid("FD:00:00:00:00:00", ulbit=1)) == 'fd:00:00:00:00:00'
= in6_addrtomac() conversion function (test 3)
in6_addrtomac("FE80::" + in6_mactoifaceid("FD:00:00:00:00:00")) == 'fd:00:00:00:00:00'
= in6_addrtomac() conversion function (test 4)
in6_addrtomac("FE80::" + in6_mactoifaceid("FF:00:00:00:00:00")) == 'ff:00:00:00:00:00'
= in6_addrtomac() conversion function (test 5)
in6_addrtomac("FE80::" + in6_mactoifaceid("FF:00:00:00:00:00", ulbit=1)) == 'fd:00:00:00:00:00'
= in6_addrtomac() conversion function (test 6)
in6_addrtomac("FE80::" + in6_mactoifaceid("FF:00:00:00:00:00", ulbit=0)) == 'ff:00:00:00:00:00'
########### RFC 3041 related function ###############################
= Test in6_getRandomizedIfaceId
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
s1,s2 = in6_getRandomizedIfaceId('20b:93ff:feeb:2d3')
inet_pton(socket.AF_INET6, '::'+s1)
tmp2 = inet_pton(socket.AF_INET6, '::'+s2)
res = res and ((ord(s1[0]) & 0x04) == 0x04)
s1,s2 = in6_getRandomizedIfaceId('20b:93ff:feeb:2d3', previous=tmp2)
tmp = inet_pton(socket.AF_INET6, '::'+s1)
inet_pton(socket.AF_INET6, '::'+s2)
res = res and ((ord(s1[0]) & 0x04) == 0x04)
########### RFC 1924 related function ###############################
= Test RFC 1924 function - in6_ctop() basic test
in6_ctop("4)+k&C#VzJ4br>0wv%Yp") == '1080::8:800:200c:417a'
= Test RFC 1924 function - in6_ctop() with character outside charset
in6_ctop("4)+k&C#VzJ4br>0wv%Y'") == None
= Test RFC 1924 function - in6_ctop() with bad length address
in6_ctop("4)+k&C#VzJ4br>0wv%Y") == None
= Test RFC 1924 function - in6_ptoc() basic test
in6_ptoc('1080::8:800:200c:417a') == '4)+k&C#VzJ4br>0wv%Yp'
= Test RFC 1924 function - in6_ptoc() basic test
in6_ptoc('1080::8:800:200c:417a') == '4)+k&C#VzJ4br>0wv%Yp'
= Test RFC 1924 function - in6_ptoc() with bad input
in6_ptoc('1080:::8:800:200c:417a') == None
########### in6_getAddrType #########################################
= in6_getAddrType - 6to4 addresses
in6_getAddrType("2002::1") == (IPV6_ADDR_UNICAST | IPV6_ADDR_GLOBAL | IPV6_ADDR_6TO4)
= in6_getAddrType - Assignable Unicast global address
in6_getAddrType("2001:db8::1") == (IPV6_ADDR_UNICAST | IPV6_ADDR_GLOBAL)
= in6_getAddrType - Multicast global address
in6_getAddrType("FF0E::1") == (IPV6_ADDR_GLOBAL | IPV6_ADDR_MULTICAST)
= in6_getAddrType - Multicast local address
in6_getAddrType("FF02::1") == (IPV6_ADDR_LINKLOCAL | IPV6_ADDR_MULTICAST)
= in6_getAddrType - Unicast Link-Local address
in6_getAddrType("FE80::") == (IPV6_ADDR_UNICAST | IPV6_ADDR_LINKLOCAL)
= in6_getAddrType - Loopback address
in6_getAddrType("::1") == IPV6_ADDR_LOOPBACK
= in6_getAddrType - Unspecified address
in6_getAddrType("::") == IPV6_ADDR_UNSPECIFIED
= in6_getAddrType - Unassigned Global Unicast address
in6_getAddrType("4000::") == (IPV6_ADDR_GLOBAL | IPV6_ADDR_UNICAST)
= in6_getAddrType - Weird address (FE::1)
in6_getAddrType("FE::") == (IPV6_ADDR_GLOBAL | IPV6_ADDR_UNICAST)
= in6_getAddrType - Weird address (FE8::1)
in6_getAddrType("FE8::1") == (IPV6_ADDR_GLOBAL | IPV6_ADDR_UNICAST)
= in6_getAddrType - Weird address (1::1)
in6_getAddrType("1::1") == (IPV6_ADDR_GLOBAL | IPV6_ADDR_UNICAST)
= in6_getAddrType - Weird address (1000::1)
in6_getAddrType("1000::1") == (IPV6_ADDR_GLOBAL | IPV6_ADDR_UNICAST)
########### ICMPv6DestUnreach Class #################################
= ICMPv6DestUnreach Class - Basic Build (no argument)
str(ICMPv6DestUnreach()) == b'\x01\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6DestUnreach Class - Basic Build over IPv6 (for cksum and overload)
str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6DestUnreach()) == b'`\x00\x00\x00\x00\x08:@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x01\x00\x14e\x00\x00\x00\x00'
= ICMPv6DestUnreach Class - Basic Build over IPv6 with some payload
str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6DestUnreach()/IPv6(src="2047::cafe", dst="2048::deca")) == b'`\x00\x00\x00\x000:@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x01\x00\x8e\xa3\x00\x00\x00\x00`\x00\x00\x00\x00\x00;@ G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca'
= ICMPv6DestUnreach Class - Dissection with default values and some payload
a = IPv6(str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6DestUnreach()/IPv6(src="2047::cafe", dst="2048::deca")))
a.plen == 48 and a.nh == 58 and ICMPv6DestUnreach in a and a[ICMPv6DestUnreach].type == 1 and a[ICMPv6DestUnreach].code == 0 and a[ICMPv6DestUnreach].cksum == 0x8ea3 and a[ICMPv6DestUnreach].unused == 0 and IPerror6 in a
= ICMPv6DestUnreach Class - Dissection with specific values
a=IPv6(str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6DestUnreach(code=1, cksum=0x6666, unused=0x7777)/IPv6(src="2047::cafe", dst="2048::deca")))
a.plen == 48 and a.nh == 58 and ICMPv6DestUnreach in a and a[ICMPv6DestUnreach].type == 1 and a[ICMPv6DestUnreach].cksum == 0x6666 and a[ICMPv6DestUnreach].unused == 0x7777 and IPerror6 in a[ICMPv6DestUnreach]
= ICMPv6DestUnreach Class - checksum computation related stuff
a=IPv6(str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6DestUnreach(code=1, cksum=0x6666, unused=0x7777)/IPv6(src="2047::cafe", dst="2048::deca")/TCP()))
b=IPv6(str(IPv6(src="2047::cafe", dst="2048::deca")/TCP()))
a[ICMPv6DestUnreach][TCPerror].chksum == b.chksum
########### ICMPv6PacketTooBig Class ################################
= ICMPv6PacketTooBig Class - Basic Build (no argument)
str(ICMPv6PacketTooBig()) == b'\x02\x00\x00\x00\x00\x00\x05\x00'
= ICMPv6PacketTooBig Class - Basic Build over IPv6 (for cksum and overload)
str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6PacketTooBig()) == b'`\x00\x00\x00\x00\x08:@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x02\x00\x0ee\x00\x00\x05\x00'
= ICMPv6PacketTooBig Class - Basic Build over IPv6 with some payload
str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6PacketTooBig()/IPv6(src="2047::cafe", dst="2048::deca")) == b'`\x00\x00\x00\x000:@ H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x02\x00\x88\xa3\x00\x00\x05\x00`\x00\x00\x00\x00\x00;@ G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe H\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca'
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
= ICMPv6PacketTooBig Class - Dissection with default values and some payload
a = IPv6(str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6PacketTooBig()/IPv6(src="2047::cafe", dst="2048::deca")))
a.plen == 48 and a.nh == 58 and ICMPv6PacketTooBig in a and a[ICMPv6PacketTooBig].type == 2 and a[ICMPv6PacketTooBig].code == 0 and a[ICMPv6PacketTooBig].cksum == 0x88a3 and a[ICMPv6PacketTooBig].mtu == 1280 and IPerror6 in a
True
= ICMPv6PacketTooBig Class - Dissection with specific values
a=IPv6(str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6PacketTooBig(code=2, cksum=0x6666, mtu=1460)/IPv6(src="2047::cafe", dst="2048::deca")))
a.plen == 48 and a.nh == 58 and ICMPv6PacketTooBig in a and a[ICMPv6PacketTooBig].type == 2 and a[ICMPv6PacketTooBig].code == 2 and a[ICMPv6PacketTooBig].cksum == 0x6666 and a[ICMPv6PacketTooBig].mtu == 1460 and IPerror6 in a
= ICMPv6PacketTooBig Class - checksum computation related stuff
a=IPv6(str(IPv6(src="2048::deca", dst="2047::cafe")/ICMPv6PacketTooBig(code=1, cksum=0x6666, mtu=0x7777)/IPv6(src="2047::cafe", dst="2048::deca")/TCP()))
b=IPv6(str(IPv6(src="2047::cafe", dst="2048::deca")/TCP()))
a[ICMPv6PacketTooBig][TCPerror].chksum == b.chksum
########### ICMPv6TimeExceeded Class ################################
# To be done but not critical. Same mechanisms and format as
# previous ones.
########### ICMPv6ParamProblem Class ################################
# See previous note
############
############
+ Test ICMPv6EchoRequest Class
= ICMPv6EchoRequest - Basic Instantiation
str(ICMPv6EchoRequest()) == b'\x80\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6EchoRequest - Instantiation with specific values
str(ICMPv6EchoRequest(code=0xff, cksum=0x1111, id=0x2222, seq=0x3333, data="thisissomestring")) == b'\x80\xff\x11\x11""33thisissomestring'
a=ICMPv6EchoRequest(b'\x80\x00\x00\x00\x00\x00\x00\x00')
a.type == 128 and a.code == 0 and a.cksum == 0 and a.id == 0 and a.seq == 0 and a.data == ""
= ICMPv6EchoRequest - Dissection with specific values
a=ICMPv6EchoRequest(b'\x80\xff\x11\x11""33thisissomestring')
a.type == 128 and a.code == 0xff and a.cksum == 0x1111 and a.id == 0x2222 and a.seq == 0x3333 and a.data == "thisissomestring"
= ICMPv6EchoRequest - Automatic checksum computation and field overloading (build)
str(IPv6(dst="2001::cafe", src="2001::deca", hlim=64)/ICMPv6EchoRequest()) == b'`\x00\x00\x00\x00\x08:@ \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x80\x00\x95\xf1\x00\x00\x00\x00'
= ICMPv6EchoRequest - Automatic checksum computation and field overloading (dissection)
a=IPv6(b'`\x00\x00\x00\x00\x08:@ \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x80\x00\x95\xf1\x00\x00\x00\x00')
isinstance(a, IPv6) and a.nh == 58 and isinstance(a.payload, ICMPv6EchoRequest) and a.payload.cksum == 0x95f1
############
############
+ Test ICMPv6EchoReply Class
= ICMPv6EchoReply - Basic Instantiation
str(ICMPv6EchoReply()) == b'\x81\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6EchoReply - Instantiation with specific values
str(ICMPv6EchoReply(code=0xff, cksum=0x1111, id=0x2222, seq=0x3333, data="thisissomestring")) == b'\x81\xff\x11\x11""33thisissomestring'
a.type == 128 and a.code == 0 and a.cksum == 0 and a.id == 0 and a.seq == 0 and a.data == ""
= ICMPv6EchoReply - Dissection with specific values
a=ICMPv6EchoReply(b'\x80\xff\x11\x11""33thisissomestring')
a.type == 128 and a.code == 0xff and a.cksum == 0x1111 and a.id == 0x2222 and a.seq == 0x3333 and a.data == "thisissomestring"
= ICMPv6EchoReply - Automatic checksum computation and field overloading (build)
str(IPv6(dst="2001::cafe", src="2001::deca", hlim=64)/ICMPv6EchoReply()) == b'`\x00\x00\x00\x00\x08:@ \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x81\x00\x94\xf1\x00\x00\x00\x00'
= ICMPv6EchoReply - Automatic checksum computation and field overloading (dissection)
a=IPv6(b'`\x00\x00\x00\x00\x08:@ \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xde\xca \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xfe\x80\x00\x95\xf1\x00\x00\x00\x00')
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
isinstance(a, IPv6) and a.nh == 58 and isinstance(a.payload, ICMPv6EchoRequest) and a.payload.cksum == 0x95f1
########### ICMPv6EchoReply/Request answers() and hashret() #########
= ICMPv6EchoRequest and ICMPv6EchoReply - hashret() test 1
b=IPv6(src="2047::deca", dst="2048::cafe")/ICMPv6EchoReply(data="somedata")
a=IPv6(src="2048::cafe", dst="2047::deca")/ICMPv6EchoRequest(data="somedata")
b.hashret() == a.hashret()
# data are not taken into account for hashret
= ICMPv6EchoRequest and ICMPv6EchoReply - hashret() test 2
b=IPv6(src="2047::deca", dst="2048::cafe")/ICMPv6EchoReply(data="somedata")
a=IPv6(src="2048::cafe", dst="2047::deca")/ICMPv6EchoRequest(data="otherdata")
b.hashret() == a.hashret()
= ICMPv6EchoRequest and ICMPv6EchoReply - hashret() test 3
b=IPv6(src="2047::deca", dst="2048::cafe")/ICMPv6EchoReply(id=0x6666, seq=0x7777,data="somedata")
a=IPv6(src="2048::cafe", dst="2047::deca")/ICMPv6EchoRequest(id=0x6666, seq=0x8888, data="somedata")
b.hashret() != a.hashret()
= ICMPv6EchoRequest and ICMPv6EchoReply - hashret() test 4
b=IPv6(src="2047::deca", dst="2048::cafe")/ICMPv6EchoReply(id=0x6666, seq=0x7777,data="somedata")
a=IPv6(src="2048::cafe", dst="2047::deca")/ICMPv6EchoRequest(id=0x8888, seq=0x7777, data="somedata")
b.hashret() != a.hashret()
= ICMPv6EchoRequest and ICMPv6EchoReply - answers() test 5
b=IPv6(src="2047::deca", dst="2048::cafe")/ICMPv6EchoReply(data="somedata")
a=IPv6(src="2048::cafe", dst="2047::deca")/ICMPv6EchoRequest(data="somedata")
(a > b) == True
= ICMPv6EchoRequest and ICMPv6EchoReply - answers() test 6
b=IPv6(src="2047::deca", dst="2048::cafe")/ICMPv6EchoReply(id=0x6666, seq=0x7777, data="somedata")
a=IPv6(src="2048::cafe", dst="2047::deca")/ICMPv6EchoRequest(id=0x6666, seq=0x7777, data="somedata")
(a > b) == True
########### ICMPv6MRD* Classes ######################################
= ICMPv6MRD_Advertisement - Basic instantiation
str(ICMPv6MRD_Advertisement()) == b'\x97\x14\x00\x00\x00\x00\x00\x00'
= ICMPv6MRD_Advertisement - Instantiation with specific values
str(ICMPv6MRD_Advertisement(advinter=0xdd, queryint=0xeeee, robustness=0xffff)) == b'\x97\xdd\x00\x00\xee\xee\xff\xff'
= ICMPv6MRD_Advertisement - Basic Dissection and overloading mechanisms
a=Ether(str(Ether()/IPv6()/ICMPv6MRD_Advertisement()))
a.dst == "33:33:00:00:00:02" and IPv6 in a and a[IPv6].plen == 8 and a[IPv6].nh == 58 and a[IPv6].hlim == 1 and a[IPv6].dst == "ff02::2" and ICMPv6MRD_Advertisement in a and a[ICMPv6MRD_Advertisement].type == 151 and a[ICMPv6MRD_Advertisement].advinter == 20 and a[ICMPv6MRD_Advertisement].queryint == 0 and a[ICMPv6MRD_Advertisement].robustness == 0
= ICMPv6MRD_Solicitation - Basic dissection
= ICMPv6MRD_Solicitation - Instantiation with specific values
str(ICMPv6MRD_Solicitation(res=0xbb)) == b'\x98\xbb\x00\x00'
= ICMPv6MRD_Solicitation - Basic Dissection and overloading mechanisms
a=Ether(str(Ether()/IPv6()/ICMPv6MRD_Solicitation()))
a.dst == "33:33:00:00:00:02" and IPv6 in a and a[IPv6].plen == 4 and a[IPv6].nh == 58 and a[IPv6].hlim == 1 and a[IPv6].dst == "ff02::2" and ICMPv6MRD_Solicitation in a and a[ICMPv6MRD_Solicitation].type == 152 and a[ICMPv6MRD_Solicitation].res == 0
= ICMPv6MRD_Termination Basic instantiation
= ICMPv6MRD_Termination - Instantiation with specific values
str(ICMPv6MRD_Termination(res=0xbb)) == b'\x99\xbb\x00\x00'
= ICMPv6MRD_Termination - Basic Dissection and overloading mechanisms
a=Ether(str(Ether()/IPv6()/ICMPv6MRD_Termination()))
a.dst == "33:33:00:00:00:6a" and IPv6 in a and a[IPv6].plen == 4 and a[IPv6].nh == 58 and a[IPv6].hlim == 1 and a[IPv6].dst == "ff02::6a" and ICMPv6MRD_Termination in a and a[ICMPv6MRD_Termination].type == 153 and a[ICMPv6MRD_Termination].res == 0
############
############
+ Test HBHOptUnknown Class
= HBHOptUnknown - Basic Instantiation
a.otype == 0x01 and a.optlen == 0 and a.optdata == ""
= HBHOptUnknown - Automatic optlen computation
str(HBHOptUnknown(optdata="B"*10)) == b'\x01\nBBBBBBBBBB'
= HBHOptUnknown - Instantiation with specific values
str(HBHOptUnknown(optlen=9, optdata="B"*10)) == b'\x01\tBBBBBBBBBB'
a.otype == 0x01 and a.optlen == 9 and a.optdata == "B"*9 and isinstance(a.payload, Raw) and a.payload.load == "B"
############
############
############
############
a.otype == 1 and a.optlen == 0 and a.optdata == ''
= PadN - Dissection with specific values
a.otype == 1 and a.optlen == 12 and a.optdata == 'BBBBBBBBBB'
= PadN - Instantiation with forced optlen
str(PadN(optdata="B"*10, optlen=9)) == b'\x01\x09BBBBBBBBBB'
############
############
+ Test RouterAlert Class (RFC 2711)
= RouterAlert - Basic Instantiation
a.otype == 0x05 and a.optlen == 2 and a.value == 00
= RouterAlert - Instantiation with specific values
str(RouterAlert(optlen=3, value=0xffff)) == b'\x05\x03\xff\xff'
a.otype == 0x05 and a.optlen == 3 and a.value == 0xffff
############
############
+ Test Jumbo Class (RFC 2675)
= Jumbo - Basic Instantiation
a.otype == 0xC2 and a.optlen == 4 and a.jumboplen == 0
= Jumbo - Instantiation with specific values
str(Jumbo(optlen=6, jumboplen=0xffffffff)) == b'\xc2\x06\xff\xff\xff\xff'
a.otype == 0xc2 and a.optlen == 6 and a.jumboplen == 0xffffffff
############
############
+ Test HAO Class (RFC 3775)
= HAO - Basic Instantiation
str(HAO()) == b'\xc9\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
a=HAO(b'\xc9\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
a.otype == 0xC9 and a.optlen == 16 and a.hoa == "::"
= HAO - Instantiation with specific values
str(HAO(optlen=9, hoa="2001::ffff")) == b'\xc9\t \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff'
a=HAO(b'\xc9\t \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff')
a.otype == 0xC9 and a.optlen == 9 and a.hoa == "2001::ffff"
= HAO - hashret
p = IPv6()/IPv6ExtHdrDestOpt(options=HAO(hoa="2001:db8::1"))/ICMPv6EchoRequest()
p.hashret() == b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00:\x00\x00\x00\x00"
############
############
+ Test IPv6ExtHdrHopByHop()
= IPv6ExtHdrHopByHop - Basic Instantiation
str(IPv6ExtHdrHopByHop()) == b';\x00\x01\x04\x00\x00\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with HAO option
str(IPv6ExtHdrHopByHop(options=[HAO()])) == b';\x02\x01\x02\x00\x00\xc9\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with RouterAlert option
str(IPv6ExtHdrHopByHop(options=[RouterAlert()])) == b';\x00\x05\x02\x00\x00\x01\x00'
= IPv6ExtHdrHopByHop - Instantiation with Jumbo option
str(IPv6ExtHdrHopByHop(options=[Jumbo()])) == b';\x00\xc2\x04\x00\x00\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with Pad1 option
str(IPv6ExtHdrHopByHop(options=[Pad1()])) == b';\x00\x00\x01\x03\x00\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with PadN option
str(IPv6ExtHdrHopByHop(options=[Pad1()])) == b';\x00\x00\x01\x03\x00\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with Jumbo, RouterAlert, HAO
str(IPv6ExtHdrHopByHop(options=[Jumbo(), RouterAlert(), HAO()])) == b';\x03\xc2\x04\x00\x00\x00\x00\x05\x02\x00\x00\x01\x00\xc9\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with HAO, Jumbo, RouterAlert
str(IPv6ExtHdrHopByHop(options=[HAO(), Jumbo(), RouterAlert()])) == b';\x04\x01\x02\x00\x00\xc9\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\xc2\x04\x00\x00\x00\x00\x05\x02\x00\x00\x01\x02\x00\x00'
= IPv6ExtHdrHopByHop - Instantiation with RouterAlert, HAO, Jumbo
str(IPv6ExtHdrHopByHop(options=[RouterAlert(), HAO(), Jumbo()])) == b';\x03\x05\x02\x00\x00\xc9\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\xc2\x04\x00\x00\x00\x00'
a=IPv6ExtHdrHopByHop(b';\x00\x01\x04\x00\x00\x00\x00')
a.nh == 59 and a.len == 0 and len(a.options) == 1 and isinstance(a.options[0], PadN) and a.options[0].otype == 1 and a.options[0].optlen == 4 and a.options[0].optdata == b'\x00'*4
#= IPv6ExtHdrHopByHop - Automatic length computation
#str(IPv6ExtHdrHopByHop(options=["toto"])) == b'\x00\x00toto'
#str(IPv6ExtHdrHopByHop(options=["toto"])) == b'\x00\x00tototo'
############
############
+ Test ICMPv6ND_RS() class - ICMPv6 Type 133 Code 0
= ICMPv6ND_RS - Basic instantiation
str(ICMPv6ND_RS()) == b'\x85\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6ND_RS - Basic instantiation with empty dst in IPv6 underlayer
str(IPv6(src="2001:db8::1")/ICMPv6ND_RS()) == b'`\x00\x00\x00\x00\x08:\xff \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x85\x00M\xfe\x00\x00\x00\x00'
a.type == 133 and a.code == 0 and a.cksum == 0 and a.res == 0
= ICMPv6ND_RS - Basic instantiation with empty dst in IPv6 underlayer
a=IPv6(b'`\x00\x00\x00\x00\x08:\xff \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x85\x00M\xfe\x00\x00\x00\x00')
isinstance(a, IPv6) and a.nh == 58 and a.hlim == 255 and isinstance(a.payload, ICMPv6ND_RS) and a.payload.type == 133 and a.payload.code == 0 and a.payload.cksum == 0x4dfe and a.payload.res == 0
############
############
+ Test ICMPv6ND_RA() class - ICMPv6 Type 134 Code 0
= ICMPv6ND_RA - Basic Instantiation
str(ICMPv6ND_RA()) == b'\x86\x00\x00\x00\x00\x08\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6ND_RA - Basic instantiation with empty dst in IPv6 underlayer
str(IPv6(src="2001:db8::1")/ICMPv6ND_RA()) == b'`\x00\x00\x00\x00\x10:\xff \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x86\x00E\xe7\x00\x08\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00'
a=ICMPv6ND_RA(b'\x86\x00\x00\x00\x00\x08\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00')
a.type == 134 and a.code == 0 and a.cksum == 0 and a.chlim == 0 and a.M == 0 and a.O == 0 and a.H == 0 and a.prf == 1 and a.res == 0 and a.routerlifetime == 1800 and a.reachabletime == 0 and a.retranstimer == 0
= ICMPv6ND_RA - Basic instantiation with empty dst in IPv6 underlayer
a=IPv6(b'`\x00\x00\x00\x00\x10:\xff \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x86\x00E\xe7\x00\x08\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00')
isinstance(a, IPv6) and a.nh == 58 and a.hlim == 255 and isinstance(a.payload, ICMPv6ND_RA) and a.payload.type == 134 and a.code == 0 and a.cksum == 0x45e7 and a.chlim == 0 and a.M == 0 and a.O == 0 and a.H == 0 and a.prf == 1 and a.res == 0 and a.routerlifetime == 1800 and a.reachabletime == 0 and a.retranstimer == 0
# TODO: Add answers()/Hashret() tests ( think about Cisco routers
# that reply with mcast RA to mcast rs )
############
############
+ ICMPv6ND_NS Class Test
= ICMPv6ND_NS - Basic Instantiation
str(ICMPv6ND_NS()) == b'\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
str(ICMPv6ND_NS(code=0x11, res=3758096385, tgt="ffff::1111")) == b'\x87\x11\x00\x00\xe0\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11'
a=ICMPv6ND_NS(b'\x87\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
a.code==0 and a.res==0 and a.tgt=="::"
a=ICMPv6ND_NS(b'\x87\x11\x00\x00\xe0\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11')
a.code==0x11 and a.res==3758096385 and a.tgt=="ffff::1111"
= ICMPv6ND_NS - IPv6 layer fields overloading
a=IPv6(str(IPv6()/ICMPv6ND_NS()))
a.nh == 58 and a.dst=="ff02::1" and a.hlim==255
############
############
+ ICMPv6ND_NA Class Test
= ICMPv6ND_NA - Basic Instantiation
str(ICMPv6ND_NA()) == b'\x88\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
str(ICMPv6ND_NA(code=0x11, R=0, S=1, O=0, res=1, tgt="ffff::1111")) == b'\x88\x11\x00\x00@\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11'
a=ICMPv6ND_NA(b'\x88\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
a.code==0 and a.R==0 and a.S==0 and a.O==0 and a.res==0 and a.tgt=="::"
= ICMPv6ND_NA - Dissection with specific values
a=ICMPv6ND_NA(b'\x88\x11\x00\x00@\x00\x00\x01\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11\x11')
a.code==0x11 and a.R==0 and a.S==1 and a.O==0 and a.res==1 and a.tgt=="ffff::1111"
= ICMPv6ND_NS - IPv6 layer fields overloading
a=IPv6(str(IPv6()/ICMPv6ND_NS()))
a.nh == 58 and a.dst=="ff02::1" and a.hlim==255
############
############
+ ICMPv6ND_ND/ICMPv6ND_ND matching test
= ICMPv6ND_ND/ICMPv6ND_ND matching - test 1
# Sent NS
a=IPv6(b'`\x00\x00\x00\x00\x18:\xff\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x0f\x1f\xff\xfe\xcaFP\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x87\x00UC\x00\x00\x00\x00\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x0f4\xff\xfe\x8a\x8a\xa1')
b=IPv6(b'n\x00\x00\x00\x00 :\xff\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x0f4\xff\xfe\x8a\x8a\xa1\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x0f\x1f\xff\xfe\xcaFP\x88\x00\xf3F\xe0\x00\x00\x00\xfe\x80\x00\x00\x00\x00\x00\x00\x02\x0f4\xff\xfe\x8a\x8a\xa1\x02\x01\x00\x0f4\x8a\x8a\xa1')
############
############
+ ICMPv6NDOptUnknown Class Test
= ICMPv6NDOptUnknown - Basic Instantiation
= ICMPv6NDOptUnknown - Instantiation with specific values
str(ICMPv6NDOptUnknown(len=4, data="somestring")) == b'\x00\x04somestring'
a.type == 0 and a.len == 2
= ICMPv6NDOptUnknown - Dissection with specific values
a.type == 0 and a.len==4 and a.data == "so" and isinstance(a.payload, Raw) and a.payload.load == "mestring"
############
############
+ ICMPv6NDOptSrcLLAddr Class Test
= ICMPv6NDOptSrcLLAddr - Basic Instantiation
str(ICMPv6NDOptSrcLLAddr()) == b'\x01\x01\x00\x00\x00\x00\x00\x00'
= ICMPv6NDOptSrcLLAddr - Instantiation with specific values
str(ICMPv6NDOptSrcLLAddr(len=2, lladdr="11:11:11:11:11:11")) == b'\x01\x02\x11\x11\x11\x11\x11\x11'
a=ICMPv6NDOptSrcLLAddr(b'\x01\x01\x00\x00\x00\x00\x00\x00')
a.type == 1 and a.len == 1 and a.lladdr == "00:00:00:00:00:00"
= ICMPv6NDOptSrcLLAddr - Instantiation with specific values
a=ICMPv6NDOptSrcLLAddr(b'\x01\x02\x11\x11\x11\x11\x11\x11')
a.type == 1 and a.len == 2 and a.lladdr == "11:11:11:11:11:11"
############
############
+ ICMPv6NDOptDstLLAddr Class Test
= ICMPv6NDOptDstLLAddr - Basic Instantiation
str(ICMPv6NDOptDstLLAddr()) == b'\x02\x01\x00\x00\x00\x00\x00\x00'
= ICMPv6NDOptDstLLAddr - Instantiation with specific values
str(ICMPv6NDOptDstLLAddr(len=2, lladdr="11:11:11:11:11:11")) == b'\x02\x02\x11\x11\x11\x11\x11\x11'
a=ICMPv6NDOptDstLLAddr(b'\x02\x01\x00\x00\x00\x00\x00\x00')
a.type == 2 and a.len == 1 and a.lladdr == "00:00:00:00:00:00"
= ICMPv6NDOptDstLLAddr - Instantiation with specific values
a=ICMPv6NDOptDstLLAddr(b'\x02\x02\x11\x11\x11\x11\x11\x11')
a.type == 2 and a.len == 2 and a.lladdr == "11:11:11:11:11:11"
############
############
+ ICMPv6NDOptPrefixInfo Class Test
= ICMPv6NDOptPrefixInfo - Basic Instantiation
str(ICMPv6NDOptPrefixInfo()) == b'\x03\x04\x00\xc0\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6NDOptPrefixInfo - Instantiation with specific values
str(ICMPv6NDOptPrefixInfo(len=5, prefixlen=64, L=0, A=0, R=1, res1=1, validlifetime=0x11111111, preferredlifetime=0x22222222, res2=0x33333333, prefix="2001:db8::1")) == b'\x03\x05@!\x11\x11\x11\x11""""3333 \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
a=ICMPv6NDOptPrefixInfo(b'\x03\x04\x00\xc0\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
a.type == 3 and a.len == 4 and a.prefixlen == 0 and a.L == 1 and a.A == 1 and a.R == 0 and a.res1 == 0 and a.validlifetime == 0xffffffff and a.preferredlifetime == 0xffffffff and a.res2 == 0 and a.prefix == "::"
= ICMPv6NDOptPrefixInfo - Instantiation with specific values
a=ICMPv6NDOptPrefixInfo(b'\x03\x05@!\x11\x11\x11\x11""""3333 \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
a.type == 3 and a.len == 5 and a.prefixlen == 64 and a.L == 0 and a.A == 0 and a.R == 1 and a.res1 == 1 and a.validlifetime == 0x11111111 and a.preferredlifetime == 0x22222222 and a.res2 == 0x33333333 and a.prefix == "2001:db8::1"
############
############
+ ICMPv6NDOptRedirectedHdr Class Test
= ICMPv6NDOptRedirectedHdr - Basic Instantiation
str(ICMPv6NDOptRedirectedHdr()) == b'\x04\x01\x00\x00\x00\x00\x00\x00'
= ICMPv6NDOptRedirectedHdr - Instantiation with specific values
str(ICMPv6NDOptRedirectedHdr(len=0xff, res=0x1111, pkt="somestringthatisnotanipv6packet")) == b'\x04\xff4369\x00\x00somestringthatisnotanipv'
= ICMPv6NDOptRedirectedHdr - Instantiation with simple IPv6 packet (no upper layer)
str(ICMPv6NDOptRedirectedHdr(pkt=IPv6())) == b'\x04\x06\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
assert(a.type == 4)
assert(a.len == 0)
= ICMPv6NDOptRedirectedHdr - Disssection with specific values
a=ICMPv6NDOptRedirectedHdr(b'\x04\xff\x11\x11\x00\x00\x00\x00somestringthatisnotanipv6pac')
a.type == 4 and a.len == 255 and a.res == b'\x11\x11\x00\x00\x00\x00' and isinstance(a.pkt, Raw) and a.pkt.load == "somestringthatisnotanipv6pac"
= ICMPv6NDOptRedirectedHdr - Dissection with cut IPv6 Header
a=ICMPv6NDOptRedirectedHdr(b'\x04\x06\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
a.type == 4 and a.len == 6 and a.res == b"\x00\x00\x00\x00\x00\x00" and isinstance(a.pkt, Raw) and a.pkt.load == b'`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
= ICMPv6NDOptRedirectedHdr - Complete dissection
~ ICMPv6NDOptRedirectedHdr
x=ICMPv6NDOptRedirectedHdr(b'\x04\x06\x00\x00\x00\x00\x00\x00`\x00\x00\x00\x00\x00;@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01')
y=x.copy()
del(y.len)
x == ICMPv6NDOptRedirectedHdr(str(y))
############
############
+ ICMPv6NDOptMTU Class Test
= ICMPv6NDOptMTU - Basic Instantiation
str(ICMPv6NDOptMTU()) == b'\x05\x01\x00\x00\x00\x00\x05\x00'
= ICMPv6NDOptMTU - Instantiation with specific values
str(ICMPv6NDOptMTU(len=2, res=0x1111, mtu=1500)) == b'\x05\x02\x11\x11\x00\x00\x05\xdc'