BIER: fix support for longer bit-string lengths
Change-Id: I2421197b76be58099e5f8ed5554410adff202109
Signed-off-by: Neale Ranns <neale.ranns@cisco.com>
diff --git a/test/Makefile b/test/Makefile
index 155325a..dbb2697 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -214,7 +214,7 @@
@echo " V=[0|1|2] - set test verbosity level"
@echo " CACHE_OUTPUT=[0|1] - cache VPP stdout/stderr and log as one block after test finishes (default: 1)"
@echo " FAILFAST=[0|1] - fail fast if 1, complete all tests if 0"
- @echo " TIMEOUT=<timeout> - fail test suite if any single test takes longer than <timeout> to finish"
+ @echo " TIMEOUT=<timeout> - fail test suite if any single test takes longer than <timeout> (in seconds) to finish"
@echo " RETRIES=<n> - retry failed tests <n> times"
@echo " DEBUG=<type> - set VPP debugging kind"
@echo " DEBUG=core - detect coredump and load it in gdb on crash"
diff --git a/test/patches/scapy-2.3.3/bier.patch b/test/patches/scapy-2.3.3/bier.patch
index 50814d4..82a881e 100644
--- a/test/patches/scapy-2.3.3/bier.patch
+++ b/test/patches/scapy-2.3.3/bier.patch
@@ -3,10 +3,10 @@
index 0000000..e173cdb
--- /dev/null
+++ b/scapy/contrib/bier.py
-@@ -0,0 +1,53 @@
+@@ -0,0 +1,58 @@
+# http://trac.secdev.org/scapy/ticket/31
+
-+# scapy.contrib.description = MPLS
++# scapy.contrib.description = BIER
+# scapy.contrib.status = loads
+
+from scapy.packet import *
@@ -14,44 +14,49 @@
+from scapy.layers.inet import IP, UDP
+from scapy.layers.inet6 import IPv6
+
++
+class BIERLength:
-+ BIER_LEN_64 = 0
-+ BIER_LEN_128 = 1
-+ BIER_LEN_256 = 2
++ BIER_LEN_64 = 0
++ BIER_LEN_128 = 1
++ BIER_LEN_256 = 2
++ BIER_LEN_512 = 3
++ BIER_LEN_1024 = 4
+
+
-+BIERnhcls = { 1: "MPLS",
-+ 2: "MPLS",
-+ 4: "IPv4",
-+ 5: "IPv6" }
++BIERnhcls = {1: "MPLS",
++ 2: "MPLS",
++ 4: "IPv4",
++ 5: "IPv6"}
+
+
+class BIFT(Packet):
-+ name = "BIFT"
-+ fields_desc = [ BitField("bsl", 0, 4),
-+ BitField("sd", 0, 8),
-+ BitField("set", 0, 8),
-+ BitField("cos", 0, 3),
-+ BitField("s", 1, 1),
-+ ByteField("ttl", 0) ]
++ name = "BIFT"
++ fields_desc = [BitField("bsl", 0, 4),
++ BitField("sd", 0, 8),
++ BitField("set", 0, 8),
++ BitField("cos", 0, 3),
++ BitField("s", 1, 1),
++ ByteField("ttl", 0)]
+
-+ def guess_payload_class(self, payload):
-+ return BIER
++ def guess_payload_class(self, payload):
++ return BIER
+
+
+class BIER(Packet):
-+ name = "BIER"
-+ fields_desc = [ BitField("id", 5, 4),
-+ BitField("version", 0, 4),
-+ BitField("length", 0, 4),
-+ BitField("entropy", 0, 20),
-+ BitField("OAM", 0, 2),
-+ BitField("RSV", 0, 2),
-+ BitField("DSCP", 0, 6),
-+ BitEnumField("Proto", 2, 6, BIERnhcls),
-+ ShortField("BFRID", 0),
-+ StrFixedLenField("BitString",
-+ chr(255)*32, 32) ]
++ name = "BIER"
++ fields_desc = [BitField("id", 5, 4),
++ BitField("version", 0, 4),
++ BitFieldLenField("length", BIERLength.BIER_LEN_256, 4,
++ length_of=lambda x:(x.BitString >> 8)),
++ BitField("entropy", 0, 20),
++ BitField("OAM", 0, 2),
++ BitField("RSV", 0, 2),
++ BitField("DSCP", 0, 6),
++ BitEnumField("Proto", 2, 6, BIERnhcls),
++ ShortField("BFRID", 0),
++ StrLenField("BitString",
++ "",
++ length_from=lambda x:(8 << x.length))]
+
+
+bind_layers(BIER, IP, Proto=4)
diff --git a/test/test_bier.py b/test/test_bier.py
index 03ae52a..a70dd09 100644
--- a/test/test_bier.py
+++ b/test/test_bier.py
@@ -3,7 +3,7 @@
import unittest
import socket
-from framework import VppTestCase, VppTestRunner
+from framework import VppTestCase, VppTestRunner, running_extended_tests
from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsRoute, \
VppMplsTable, VppIpMRoute, VppMRoutePath, VppIpTable, \
MRouteEntryFlags, MRouteItfFlags, MPLS_LABEL_INVALID, DpoProto
@@ -66,13 +66,13 @@
i.admin_down()
super(TestBier, self).tearDown()
- def test_bier_midpoint(self):
+ def bier_midpoint(self, hdr_len_id, n_bytes, max_bp):
"""BIER midpoint"""
#
# Add a BIER table for sub-domain 0, set 0, and BSL 256
#
- bti = VppBierTableID(0, 0, BIERLength.BIER_LEN_256)
+ bti = VppBierTableID(0, 0, hdr_len_id)
bt = VppBierTable(self, bti, 77)
bt.add_vpp_config()
@@ -81,8 +81,7 @@
#
p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
MPLS(label=77, ttl=255) /
- BIER(length=BIERLength.BIER_LEN_256,
- BitString=chr(0)*64) /
+ BIER(length=hdr_len_id) /
IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) /
UDP(sport=1234, dport=1234) /
Raw())
@@ -98,7 +97,7 @@
#
nh_routes = []
bier_routes = []
- for i in range(1, 256):
+ for i in range(1, max_bp+1):
nh = "10.0.%d.%d" % (i / 255, i % 255)
nh_routes.append(VppIpRoute(self, nh, 32,
[VppRoutePath(self.pg1.remote_ip4,
@@ -112,60 +111,92 @@
bier_routes[-1].add_vpp_config()
#
- # A packet with all bits set gets spat out to BP:1
+ # A packet with all bits set gets replicated once for each bit
#
- p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
- MPLS(label=77, ttl=255) /
- BIER(length=BIERLength.BIER_LEN_256) /
- IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) /
- UDP(sport=1234, dport=1234) /
- Raw())
- pkts = [p]
+ pkt_sizes = [64, 1400]
- self.pg0.add_stream(pkts)
- self.pg_enable_capture(self.pg_interfaces)
- self.pg_start()
+ for pkt_size in pkt_sizes:
+ p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
+ MPLS(label=77, ttl=255) /
+ BIER(length=hdr_len_id, BitString=chr(255)*n_bytes) /
+ IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) /
+ UDP(sport=1234, dport=1234) /
+ Raw(chr(5) * pkt_size))
+ pkts = p
- rx = self.pg1.get_capture(255)
+ self.pg0.add_stream(pkts)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
- for rxp in rx:
- #
- # The packets are not required to be sent in bit-position order
- # when we setup the routes above we used the bit-position to
- # construct the out-label. so use that here to determine the BP
- #
- olabel = rxp[MPLS]
- bp = olabel.label - 2000
+ rx = self.pg1.get_capture(max_bp)
- blabel = olabel[MPLS].payload
- self.assertEqual(blabel.label, 100+bp)
- self.assertEqual(blabel.ttl, 254)
+ for rxp in rx:
+ #
+ # The packets are not required to be sent in bit-position order
+ # when we setup the routes above we used the bit-position to
+ # construct the out-label. so use that here to determine the BP
+ #
+ olabel = rxp[MPLS]
+ bp = olabel.label - 2000
- bier_hdr = blabel[MPLS].payload
+ blabel = olabel[MPLS].payload
+ self.assertEqual(blabel.label, 100+bp)
+ self.assertEqual(blabel.ttl, 254)
- self.assertEqual(bier_hdr.id, 5)
- self.assertEqual(bier_hdr.version, 0)
- self.assertEqual(bier_hdr.length, BIERLength.BIER_LEN_256)
- self.assertEqual(bier_hdr.entropy, 0)
- self.assertEqual(bier_hdr.OAM, 0)
- self.assertEqual(bier_hdr.RSV, 0)
- self.assertEqual(bier_hdr.DSCP, 0)
- self.assertEqual(bier_hdr.Proto, 5)
+ bier_hdr = blabel[MPLS].payload
- # The bit-string should consist only of the BP given by i.
- i = 0
- bitstring = ""
- bpi = bp - 1
- while (i < bpi/8):
- bitstring = chr(0) + bitstring
- i += 1
- bitstring = chr(1 << bpi % 8) + bitstring
+ self.assertEqual(bier_hdr.id, 5)
+ self.assertEqual(bier_hdr.version, 0)
+ self.assertEqual(bier_hdr.length, hdr_len_id)
+ self.assertEqual(bier_hdr.entropy, 0)
+ self.assertEqual(bier_hdr.OAM, 0)
+ self.assertEqual(bier_hdr.RSV, 0)
+ self.assertEqual(bier_hdr.DSCP, 0)
+ self.assertEqual(bier_hdr.Proto, 5)
- while len(bitstring) < 32:
- bitstring = chr(0) + bitstring
+ # The bit-string should consist only of the BP given by i.
+ byte_array = ['\0'] * (n_bytes)
+ byte_val = chr(1 << (bp - 1) % 8)
+ byte_pos = n_bytes - (((bp - 1) / 8) + 1)
+ byte_array[byte_pos] = byte_val
+ bitstring = ''.join(byte_array)
- self.assertEqual(len(bitstring), len(bier_hdr.BitString))
- self.assertEqual(bitstring, bier_hdr.BitString)
+ self.assertEqual(len(bitstring), len(bier_hdr.BitString))
+ self.assertEqual(bitstring, bier_hdr.BitString)
+
+ #
+ # cleanup. not strictly necessary, but it's much quicker this way
+ # becuase the bier_fib_dump and ip_fib_dump will be empty when the
+ # auto-cleanup kicks in
+ #
+ for br in bier_routes:
+ br.remove_vpp_config()
+ for nhr in nh_routes:
+ nhr.remove_vpp_config()
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_midpoint_1024(self):
+ """BIER midpoint BSL:1024"""
+ self.bier_midpoint(BIERLength.BIER_LEN_1024, 128, 1024)
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_midpoint_512(self):
+ """BIER midpoint BSL:512"""
+ self.bier_midpoint(BIERLength.BIER_LEN_512, 64, 512)
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_midpoint_256(self):
+ """BIER midpoint BSL:256"""
+ self.bier_midpoint(BIERLength.BIER_LEN_256, 32, 256)
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_midpoint_128(self):
+ """BIER midpoint BSL:128"""
+ self.bier_midpoint(BIERLength.BIER_LEN_128, 16, 128)
+
+ def test_bier_midpoint_64(self):
+ """BIER midpoint BSL:256"""
+ self.bier_midpoint(BIERLength.BIER_LEN_64, 8, 64)
def test_bier_head(self):
"""BIER head"""
@@ -292,6 +323,7 @@
#
bier_de_1 = VppBierDispEntry(self, bdt.id, 99,
BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
+ DpoProto.DPO_PROTO_BIER,
"0.0.0.0", 0, rpf_id=8192)
bier_de_1.add_vpp_config()
@@ -313,7 +345,9 @@
#
p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
MPLS(label=77, ttl=255) /
- BIER(length=BIERLength.BIER_LEN_256, BFRID=99) /
+ BIER(length=BIERLength.BIER_LEN_256,
+ BitString=chr(255)*32,
+ BFRID=99) /
IP(src="1.1.1.1", dst="232.1.1.1") /
UDP(sport=1234, dport=1234) /
Raw())
@@ -325,7 +359,9 @@
#
p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
MPLS(label=77, ttl=255) /
- BIER(length=BIERLength.BIER_LEN_256, BFRID=77) /
+ BIER(length=BIERLength.BIER_LEN_256,
+ BitString=chr(255)*32,
+ BFRID=77) /
IP(src="1.1.1.1", dst="232.1.1.1") /
UDP(sport=1234, dport=1234) /
Raw())
@@ -337,6 +373,7 @@
#
bier_de_2 = VppBierDispEntry(self, bdt.id, 0,
BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
+ DpoProto.DPO_PROTO_BIER,
"0.0.0.0", 0, rpf_id=8192)
bier_de_2.add_vpp_config()
@@ -345,22 +382,28 @@
#
self.send_and_expect(self.pg0, [p], self.pg1)
- def test_bier_e2e(self):
- """ BIER end-to-end """
+ def bier_e2e(self, hdr_len_id, n_bytes, max_bp):
+ """ BIER end-to-end"""
#
# Add a BIER table for sub-domain 0, set 0, and BSL 256
#
- bti = VppBierTableID(0, 0, BIERLength.BIER_LEN_256)
+ bti = VppBierTableID(0, 0, hdr_len_id)
bt = VppBierTable(self, bti, 77)
bt.add_vpp_config()
+ lowest = ['\0'] * (n_bytes)
+ lowest[-1] = chr(1)
+ highest = ['\0'] * (n_bytes)
+ highest[0] = chr(128)
+
#
- # Impostion Sets bit string 101010101....
- # sender 333
+ # Impostion Sets bit strings
#
- bi = VppBierImp(self, bti, 333, chr(0x5) * 32)
- bi.add_vpp_config()
+ bi_low = VppBierImp(self, bti, 333, lowest)
+ bi_low.add_vpp_config()
+ bi_high = VppBierImp(self, bti, 334, highest)
+ bi_high.add_vpp_config()
#
# Add a multicast route that will forward into the BIER doamin
@@ -375,8 +418,20 @@
VppMRoutePath(0xffffffff,
MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
proto=DpoProto.DPO_PROTO_BIER,
- bier_imp=bi.bi_index)])
+ bier_imp=bi_low.bi_index)])
route_ing_232_1_1_1.add_vpp_config()
+ route_ing_232_1_1_2 = VppIpMRoute(
+ self,
+ "0.0.0.0",
+ "232.1.1.2", 32,
+ MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
+ paths=[VppMRoutePath(self.pg0.sw_if_index,
+ MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
+ VppMRoutePath(0xffffffff,
+ MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
+ proto=DpoProto.DPO_PROTO_BIER,
+ bier_imp=bi_high.bi_index)])
+ route_ing_232_1_1_2.add_vpp_config()
#
# disposition table 8
@@ -385,7 +440,7 @@
bdt.add_vpp_config()
#
- # BIER route in table that's for-us, resolving through
+ # BIER routes in table that are for-us, resolving through
# disp table 8.
#
bier_route_1 = VppBierRoute(self, bti, 1,
@@ -393,6 +448,11 @@
0xffffffff,
nh_table_id=8)])
bier_route_1.add_vpp_config()
+ bier_route_max = VppBierRoute(self, bti, max_bp,
+ [VppRoutePath("0.0.0.0",
+ 0xffffffff,
+ nh_table_id=8)])
+ bier_route_max.add_vpp_config()
#
# An entry in the disposition table for sender 333
@@ -400,11 +460,17 @@
#
bier_de_1 = VppBierDispEntry(self, bdt.id, 333,
BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
+ DpoProto.DPO_PROTO_BIER,
"0.0.0.0", 10, rpf_id=8192)
bier_de_1.add_vpp_config()
+ bier_de_1 = VppBierDispEntry(self, bdt.id, 334,
+ BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
+ DpoProto.DPO_PROTO_BIER,
+ "0.0.0.0", 10, rpf_id=8193)
+ bier_de_1.add_vpp_config()
#
- # Add a multicast route that will forward the traffic
+ # Add a multicast routes that will forward the traffic
# post-disposition
#
route_eg_232_1_1_1 = VppIpMRoute(
@@ -417,6 +483,16 @@
MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
route_eg_232_1_1_1.add_vpp_config()
route_eg_232_1_1_1.update_rpf_id(8192)
+ route_eg_232_1_1_2 = VppIpMRoute(
+ self,
+ "0.0.0.0",
+ "232.1.1.2", 32,
+ MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
+ table_id=10,
+ paths=[VppMRoutePath(self.pg1.sw_if_index,
+ MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
+ route_eg_232_1_1_2.add_vpp_config()
+ route_eg_232_1_1_2.update_rpf_id(8193)
#
# inject a packet in VRF-0. We expect it to be BIER encapped,
@@ -426,16 +502,48 @@
p = (Ether(dst=self.pg0.local_mac,
src=self.pg0.remote_mac) /
IP(src="1.1.1.1", dst="232.1.1.1") /
- UDP(sport=1234, dport=1234))
+ UDP(sport=1234, dport=1234) /
+ Raw(chr(5) * 32))
rx = self.send_and_expect(self.pg0, p*65, self.pg1)
- #
- # should be IP
- #
self.assertEqual(rx[0][IP].src, "1.1.1.1")
self.assertEqual(rx[0][IP].dst, "232.1.1.1")
+ p = (Ether(dst=self.pg0.local_mac,
+ src=self.pg0.remote_mac) /
+ IP(src="1.1.1.1", dst="232.1.1.2") /
+ UDP(sport=1234, dport=1234) /
+ Raw(chr(5) * 512))
+
+ rx = self.send_and_expect(self.pg0, p*65, self.pg1)
+ self.assertEqual(rx[0][IP].src, "1.1.1.1")
+ self.assertEqual(rx[0][IP].dst, "232.1.1.2")
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_e2e_1024(self):
+ """ BIER end-to-end BSL:1024"""
+ self.bier_e2e(BIERLength.BIER_LEN_1024, 128, 1024)
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_e2e_512(self):
+ """ BIER end-to-end BSL:512"""
+ self.bier_e2e(BIERLength.BIER_LEN_512, 64, 512)
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_e2e_256(self):
+ """ BIER end-to-end BSL:256"""
+ self.bier_e2e(BIERLength.BIER_LEN_256, 32, 256)
+
+ @unittest.skipUnless(running_extended_tests(), "part of extended tests")
+ def test_bier_e2e_128(self):
+ """ BIER end-to-end BSL:128"""
+ self.bier_e2e(BIERLength.BIER_LEN_128, 16, 128)
+
+ def test_bier_e2e_64(self):
+ """ BIER end-to-end BSL:64"""
+ self.bier_e2e(BIERLength.BIER_LEN_64, 8, 64)
+
def test_bier_head_o_udp(self):
"""BIER head over UDP"""
@@ -552,6 +660,7 @@
#
bier_de_1 = VppBierDispEntry(self, bdt.id, 99,
BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
+ DpoProto.DPO_PROTO_BIER,
"0.0.0.0", 0, rpf_id=8192)
bier_de_1.add_vpp_config()
@@ -575,7 +684,9 @@
IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
UDP(sport=333, dport=8138) /
BIFT(sd=1, set=0, bsl=2, ttl=255) /
- BIER(length=BIERLength.BIER_LEN_256, BFRID=99) /
+ BIER(length=BIERLength.BIER_LEN_256,
+ BitString=chr(255)*32,
+ BFRID=99) /
IP(src="1.1.1.1", dst="232.1.1.1") /
UDP(sport=1234, dport=1234) /
Raw())
diff --git a/test/vpp_bier.py b/test/vpp_bier.py
index 328d4f0..ef9a9ab 100644
--- a/test/vpp_bier.py
+++ b/test/vpp_bier.py
@@ -219,11 +219,12 @@
BIER Disposition Entry
"""
- def __init__(self, test, tbl_id, bp, payload_proto, nh, nh_tbl,
- rpf_id=~0):
+ def __init__(self, test, tbl_id, bp, payload_proto, nh_proto,
+ nh, nh_tbl, rpf_id=~0):
self._test = test
self.tbl_id = tbl_id
self.nh_tbl = nh_tbl
+ self.nh_proto = nh_proto
self.bp = bp
self.payload_proto = payload_proto
self.rpf_id = rpf_id
@@ -234,6 +235,7 @@
self.tbl_id,
self.bp,
self.payload_proto,
+ self.nh_proto,
self.nh,
self.nh_tbl,
self.rpf_id,
@@ -245,6 +247,7 @@
self.tbl_id,
self.bp,
self.payload_proto,
+ self.nh_proto,
self.nh,
self.nh_tbl,
self.rpf_id,
diff --git a/test/vpp_object.py b/test/vpp_object.py
index a1cf42f..088cc39 100644
--- a/test/vpp_object.py
+++ b/test/vpp_object.py
@@ -66,18 +66,17 @@
return
logger.info("REG: Removing VPP configuration for registered objects")
# remove the config in reverse order as there might be dependencies
+ failed = []
for obj in reversed(self._object_registry):
if obj.query_vpp_config():
logger.info("REG: Removing configuration for %s" % obj)
obj.remove_vpp_config()
+ if obj.query_vpp_config():
+ failed.append(obj)
else:
logger.info(
"REG: Skipping removal for %s, configuration not present" %
obj)
- failed = []
- for obj in self._object_registry:
- if obj.query_vpp_config():
- failed.append(obj)
self.unregister_all(logger)
if failed:
logger.error("REG: Couldn't remove configuration for object(s):")
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 087a14b..fd62405 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -2886,6 +2886,7 @@
bdti,
bp,
payload_proto,
+ next_hop_afi,
next_hop,
next_hop_tbl_id=0,
next_hop_rpf_id=~0,
@@ -2900,7 +2901,7 @@
'bde_n_paths': 1,
'bde_paths': [{'next_hop': next_hop,
'table_id': next_hop_tbl_id,
- 'afi': 0,
+ 'afi': next_hop_afi,
'rpf_id': next_hop_rpf_id,
'n_labels': 0,
'label_stack': [0]}],