blob: 50814d41315fcad7ad71be5f13358a75715232a6 [file] [log] [blame]
Neale Rannsd792d9c2017-10-21 10:53:20 -07001diff --git a/scapy/contrib/bier.py b/scapy/contrib/bier.py
2new file mode 100644
3index 0000000..e173cdb
4--- /dev/null
5+++ b/scapy/contrib/bier.py
Neale Ranns91286372017-12-05 13:24:04 -08006@@ -0,0 +1,53 @@
Neale Rannsd792d9c2017-10-21 10:53:20 -07007+# http://trac.secdev.org/scapy/ticket/31
8+
9+# scapy.contrib.description = MPLS
10+# scapy.contrib.status = loads
11+
12+from scapy.packet import *
13+from scapy.fields import *
Neale Ranns91286372017-12-05 13:24:04 -080014+from scapy.layers.inet import IP, UDP
Neale Rannsd792d9c2017-10-21 10:53:20 -070015+from scapy.layers.inet6 import IPv6
16+
17+class BIERLength:
18+ BIER_LEN_64 = 0
19+ BIER_LEN_128 = 1
20+ BIER_LEN_256 = 2
21+
22+
Neale Rannsd792d9c2017-10-21 10:53:20 -070023+BIERnhcls = { 1: "MPLS",
24+ 2: "MPLS",
25+ 4: "IPv4",
26+ 5: "IPv6" }
27+
Neale Ranns91286372017-12-05 13:24:04 -080028+
29+class BIFT(Packet):
30+ name = "BIFT"
31+ fields_desc = [ BitField("bsl", 0, 4),
32+ BitField("sd", 0, 8),
33+ BitField("set", 0, 8),
34+ BitField("cos", 0, 3),
35+ BitField("s", 1, 1),
36+ ByteField("ttl", 0) ]
37+
38+ def guess_payload_class(self, payload):
39+ return BIER
40+
41+
Neale Rannsd792d9c2017-10-21 10:53:20 -070042+class BIER(Packet):
43+ name = "BIER"
44+ fields_desc = [ BitField("id", 5, 4),
45+ BitField("version", 0, 4),
46+ BitField("length", 0, 4),
47+ BitField("entropy", 0, 20),
48+ BitField("OAM", 0, 2),
49+ BitField("RSV", 0, 2),
50+ BitField("DSCP", 0, 6),
51+ BitEnumField("Proto", 2, 6, BIERnhcls),
52+ ShortField("BFRID", 0),
53+ StrFixedLenField("BitString",
54+ chr(255)*32, 32) ]
55+
56+
57+bind_layers(BIER, IP, Proto=4)
58+bind_layers(BIER, IPv6, Proto=5)
Neale Ranns91286372017-12-05 13:24:04 -080059+bind_layers(UDP, BIFT, dport=8138)