64 lines
2.8 KiB
Text
64 lines
2.8 KiB
Text
|
# GENEVE unit tests
|
||
|
#
|
||
|
# Type the following command to launch start the tests:
|
||
|
# $ test/run_tests -P "load_contrib('geneve')" -t scapy/contrib/geneve.uts
|
||
|
|
||
|
+ GENEVE
|
||
|
|
||
|
= Build & dissect - GENEVE encapsulates Ether
|
||
|
if WINDOWS:
|
||
|
route_add_loopback()
|
||
|
|
||
|
s = raw(IP()/UDP(sport=10000)/GENEVE()/Ether(dst='00:01:00:11:11:11',src='00:02:00:22:22:22'))
|
||
|
assert(s == b'E\x00\x002\x00\x01\x00\x00@\x11|\xb8\x7f\x00\x00\x01\x7f\x00\x00\x01\'\x10\x17\xc1\x00\x1e\x9a\x1c\x00\x00eX\x00\x00\x00\x00\x00\x01\x00\x11\x11\x11\x00\x02\x00"""\x90\x00')
|
||
|
|
||
|
p = IP(s)
|
||
|
assert(GENEVE in p and Ether in p[GENEVE].payload)
|
||
|
|
||
|
|
||
|
= Build & dissect - GENEVE with options encapsulates Ether
|
||
|
|
||
|
s = raw(IP()/UDP(sport=10000)/GENEVE(critical=1, options=b'\x00\x01\x81\x02\x0a\x0a\x0b\x0b')/Ether(dst='00:01:00:11:11:11',src='00:02:00:22:22:22'))
|
||
|
assert(s == b'E\x00\x00:\x00\x01\x00\x00@\x11|\xb0\x7f\x00\x00\x01\x7f\x00\x00\x01\'\x10\x17\xc1\x00&\x01\xb4\x02@eX\x00\x00\x00\x00\x00\x01\x81\x02\n\n\x0b\x0b\x00\x01\x00\x11\x11\x11\x00\x02\x00"""\x90\x00')
|
||
|
|
||
|
p = IP(s)
|
||
|
assert(GENEVE in p and Ether in p[GENEVE].payload and p[GENEVE].critical == 1 and p[GENEVE].optionlen == 2)
|
||
|
|
||
|
|
||
|
= Build & dissect - GENEVE encapsulates IPv4
|
||
|
|
||
|
s = raw(IP()/UDP(sport=10000)/GENEVE()/IP())
|
||
|
assert(s == b"E\x00\x008\x00\x01\x00\x00@\x11|\xb2\x7f\x00\x00\x01\x7f\x00\x00\x01'\x10\x17\xc1\x00$\xba\xd2\x00\x00\x08\x00\x00\x00\x00\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01")
|
||
|
|
||
|
p = IP(s)
|
||
|
assert(GENEVE in p and IP in p[GENEVE].payload)
|
||
|
|
||
|
|
||
|
= Build & dissect - GENEVE encapsulates IPv6
|
||
|
s = raw(IP()/UDP(sport=10000)/GENEVE()/IPv6())
|
||
|
assert(s == b"E\x00\x00L\x00\x01\x00\x00@\x11|\x9e\x7f\x00\x00\x01\x7f\x00\x00\x01'\x10\x17\xc1\x008\xa0\x8a\x00\x00\x86\xdd\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")
|
||
|
|
||
|
p = IP(s)
|
||
|
assert(GENEVE in p and IPv6 in p[GENEVE].payload)
|
||
|
|
||
|
= GENEVE - Answers
|
||
|
|
||
|
a = GENEVE(proto=0x0800)/b'E\x00\x00\x1c\x00\x01\x00\x00@\x01\xfa$\xc0\xa8\x00w\xac\xd9\x12\xc3\x08\x00\xf7\xff\x00\x00\x00\x00'
|
||
|
b = GENEVE(proto=0x0800)/b'E\x00\x00\x1c\x00\x00\x00\x007\x01\x03&\xac\xd9\x12\xc3\xc0\xa8\x00w\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'
|
||
|
c = Raw("data")
|
||
|
|
||
|
a = GENEVE(raw(a))
|
||
|
b = GENEVE(raw(b))
|
||
|
|
||
|
assert b.answers(a)
|
||
|
assert not a.answers(b)
|
||
|
assert not b.answers(c)
|
||
|
assert not a.answers(c)
|
||
|
|
||
|
= GENEVE - Summary
|
||
|
|
||
|
a = GENEVE(proto=0x0800)/b'E\x00\x00\x1c\x00\x01\x00\x00@\x01\xfa$\xc0\xa8\x00w\xac\xd9\x12\xc3\x08\x00\xf7\xff\x00\x00\x00\x00'
|
||
|
a = GENEVE(raw(a))
|
||
|
assert a.summary() == 'GENEVE / IP / ICMP 192.168.0.119 > 172.217.18.195 echo-request 0'
|
||
|
assert a.mysummary() in ['GENEVE (vni=0x0,optionlen=0,proto=0x800)', 'GENEVE (vni=0x0,optionlen=0,proto=IPv4)']
|