• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# GENEVE unit tests
2#
3# Type the following command to launch start the tests:
4# $ test/run_tests -P "load_contrib('geneve')" -t test/contrib/geneve.uts
5
6+ GENEVE
7
8= Build & dissect - GENEVE encapsulates Ether
9
10s = raw(IP()/UDP(sport=10000)/GENEVE()/Ether(dst='00:01:00:11:11:11',src='00:02:00:22:22:22'))
11assert 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'
12
13p = IP(s)
14assert GENEVE in p and Ether in p[GENEVE].payload
15
16
17= Build & dissect - GENEVE with options encapsulates Ether
18
19s = 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'))
20assert 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'
21
22p = IP(s)
23assert GENEVE in p and Ether in p[GENEVE].payload and p[GENEVE].critical == 1 and p[GENEVE].optionlen == 2
24
25= Build & dissect - GENEVE with metadata options encapsulates Ether
26
27s = raw(Ether()/Dot1Q()/IP()/UDP(sport=57025,dport=6081)/GENEVE(proto=0x6558,options=GeneveOptions(classid=0x0102,type=0x80,data=b'\x00\x01\x00\x02'))/Ether()/IP()/ICMP(type=8))
28assert (s == b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x81\x00\x00\x01\x08\x00E\x00\x00V\x00\x01\x00\x00@\x11|\x94\x7f\x00\x00\x01\x7f\x00\x00\x01\xde\xc1\x17\xc1\x00B\x1a\x86\x02\x00eX\x00\x00\x00\x00\x01\x02\x80\x01\x00\x01\x00\x02\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00E\x00\x00\x1c\x00\x01\x00\x00@\x01|\xde\x7f\x00\x00\x01\x7f\x00\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00')
29
30p = Ether(s)
31assert GENEVE in p and Ether in p[GENEVE].payload and p[GENEVE].proto == 0x6558 and p[GeneveOptions].length == 1 and p[GeneveOptions].classid == 0x102 and p[GeneveOptions].type == 0x80
32
33= Build & dissect - GENEVE with multiple options
34
35s = raw(GENEVE(proto=0x0800,options=[GeneveOptions(classid=0x0102,type=0x1,data=b'\x00\x01\x00\x02'), GeneveOptions(classid=0x0102,type=0x2,data=b'\x00\x01\x00\x02')]))
36p = GENEVE(s)
37assert p.optionlen == 4
38assert len(p.options) == 2
39assert p.options[0].classid == 0x102 and p.options[0].type == 0x1
40assert p.options[1].classid == 0x102 and p.options[1].type == 0x2
41
42
43= Build & dissect - GENEVE encapsulates IPv4
44
45s = raw(IP()/UDP(sport=10000)/GENEVE()/IP())
46assert 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"
47
48p = IP(s)
49assert GENEVE in p and IP in p[GENEVE].payload
50
51
52= Build & dissect - GENEVE encapsulates IPv6
53s = raw(IP()/UDP(sport=10000)/GENEVE()/IPv6())
54assert 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"
55
56p = IP(s)
57assert GENEVE in p and IPv6 in p[GENEVE].payload
58
59= GENEVE - Answers
60
61a = 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'
62b = 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'
63c = Raw("data")
64
65a = GENEVE(raw(a))
66b = GENEVE(raw(b))
67
68assert b.answers(a)
69assert not a.answers(b)
70assert not b.answers(c)
71assert not a.answers(c)
72
73= GENEVE - Summary
74
75a = 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'
76a = GENEVE(raw(a))
77assert a.summary() == 'GENEVE / IP / ICMP 192.168.0.119 > 172.217.18.195 echo-request 0'
78assert a.mysummary() in ['GENEVE (vni=0x0,optionlen=0,proto=0x800)', 'GENEVE (vni=0x0,optionlen=0,proto=IPv4)']
79
80= GENEVE - Optionlen
81
82for size in range(0, 0x1f, 4):
83    p = GENEVE(bytes(GENEVE(options=GeneveOptions(data=RandString(size)))))
84    assert p[GENEVE].optionlen == (size // 4 + 1)
85    assert len(p[GENEVE].options[0].data) == size
86
87