blob: 97e8a90b392dd8d85ca518fbf648929dd634c094 [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 Rannscbcc84b2018-02-25 10:52:12 -08006@@ -0,0 +1,56 @@
Neale Rannsd792d9c2017-10-21 10:53:20 -07007+# http://trac.secdev.org/scapy/ticket/31
8+
Neale Rannsf0510722018-01-31 11:35:41 -08009+# scapy.contrib.description = BIER
Neale Rannsd792d9c2017-10-21 10:53:20 -070010+# 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+
Neale Rannsf0510722018-01-31 11:35:41 -080017+
Neale Rannsd792d9c2017-10-21 10:53:20 -070018+class BIERLength:
Neale Rannsf0510722018-01-31 11:35:41 -080019+ BIER_LEN_64 = 0
20+ BIER_LEN_128 = 1
21+ BIER_LEN_256 = 2
22+ BIER_LEN_512 = 3
23+ BIER_LEN_1024 = 4
Neale Rannsd792d9c2017-10-21 10:53:20 -070024+
25+
Neale Rannsf0510722018-01-31 11:35:41 -080026+BIERnhcls = {1: "MPLS",
27+ 2: "MPLS",
28+ 4: "IPv4",
29+ 5: "IPv6"}
Neale Rannsd792d9c2017-10-21 10:53:20 -070030+
Neale Ranns91286372017-12-05 13:24:04 -080031+
32+class BIFT(Packet):
Neale Rannsf0510722018-01-31 11:35:41 -080033+ name = "BIFT"
34+ fields_desc = [BitField("bsl", 0, 4),
35+ BitField("sd", 0, 8),
36+ BitField("set", 0, 8),
37+ BitField("cos", 0, 3),
38+ BitField("s", 1, 1),
39+ ByteField("ttl", 0)]
Neale Ranns91286372017-12-05 13:24:04 -080040+
Neale Ranns91286372017-12-05 13:24:04 -080041+
Neale Rannsd792d9c2017-10-21 10:53:20 -070042+class BIER(Packet):
Neale Rannsf0510722018-01-31 11:35:41 -080043+ name = "BIER"
44+ fields_desc = [BitField("id", 5, 4),
45+ BitField("version", 0, 4),
46+ BitFieldLenField("length", BIERLength.BIER_LEN_256, 4,
47+ length_of=lambda x:(x.BitString >> 8)),
48+ BitField("entropy", 0, 20),
49+ BitField("OAM", 0, 2),
50+ BitField("RSV", 0, 2),
51+ BitField("DSCP", 0, 6),
52+ BitEnumField("Proto", 2, 6, BIERnhcls),
53+ ShortField("BFRID", 0),
54+ StrLenField("BitString",
55+ "",
56+ length_from=lambda x:(8 << x.length))]
Neale Rannsd792d9c2017-10-21 10:53:20 -070057+
58+
59+bind_layers(BIER, IP, Proto=4)
60+bind_layers(BIER, IPv6, Proto=5)
Neale Ranns91286372017-12-05 13:24:04 -080061+bind_layers(UDP, BIFT, dport=8138)
Neale Rannscbcc84b2018-02-25 10:52:12 -080062+bind_layers(BIFT, BIER)