• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# MPLS unit tests
2#
3# Type the following command to launch start the tests:
4# $ test/run_tests -P "load_contrib('mpls')" -t test/contrib/mpls.uts
5
6+ MPLS
7
8= Build & dissect - IPv4
9
10s = raw(Ether(src="00:01:02:04:05")/MPLS()/IP())
11assert s == b'\xff\xff\xff\xff\xff\xff\x00\x01\x02\x04\x05\x00\x88G\x00\x00\x01\x00E\x00\x00\x14\x00\x01\x00\x00@\x00|\xe7\x7f\x00\x00\x01\x7f\x00\x00\x01'
12
13p = Ether(s)
14assert MPLS in p and IP in p
15
16
17= Build & dissect - IPv6
18s = raw(Ether(src="00:01:02:04:05")/MPLS(s=0)/MPLS()/IPv6())
19assert s == b'\xff\xff\xff\xff\xff\xff\x00\x01\x02\x04\x05\x00\x88G\x00\x000\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'
20
21p = Ether(s)
22assert IPv6 in p and isinstance(p[MPLS].payload, MPLS)
23
24= Association on IP and IPv6
25p = IP()/MPLS()
26p = IP(raw(p))
27assert p[IP].proto == 137
28
29p2 = IPv6()/MPLS()
30p2 = IPv6(raw(p2))
31assert p2[IPv6].nh == 137
32