blob: c7ec0eed12754ad3ccea703832f5c27cba42e3e6 [file] [log] [blame]
Neale Rannsd792d9c2017-10-21 10:53:20 -07001#!/usr/bin/env python
2
3import unittest
4import socket
5
Neale Rannsf0510722018-01-31 11:35:41 -08006from framework import VppTestCase, VppTestRunner, running_extended_tests
Neale Rannsd792d9c2017-10-21 10:53:20 -07007from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsRoute, \
8 VppMplsTable, VppIpMRoute, VppMRoutePath, VppIpTable, \
Neale Ranns31ed7442018-02-23 05:29:09 -08009 MRouteEntryFlags, MRouteItfFlags, MPLS_LABEL_INVALID, DpoProto, \
10 VppMplsLabel
Neale Rannsd792d9c2017-10-21 10:53:20 -070011from vpp_bier import *
Neale Ranns91286372017-12-05 13:24:04 -080012from vpp_udp_encap import *
Neale Rannsd792d9c2017-10-21 10:53:20 -070013
14from scapy.packet import Raw
15from scapy.layers.l2 import Ether
16from scapy.layers.inet import IP, UDP, ICMP
17from scapy.layers.inet6 import IPv6
18from scapy.contrib.mpls import MPLS
19from scapy.contrib.bier import *
20
21
22class TestBFIB(VppTestCase):
23 """ BIER FIB Test Case """
24
25 def test_bfib(self):
26 """ BFIB Unit Tests """
27 error = self.vapi.cli("test bier")
28
29 if error:
30 self.logger.critical(error)
31 self.assertEqual(error.find("Failed"), -1)
32
33
34class TestBier(VppTestCase):
35 """ BIER Test Case """
36
37 def setUp(self):
38 super(TestBier, self).setUp()
39
40 # create 2 pg interfaces
41 self.create_pg_interfaces(range(3))
42
43 # create the default MPLS table
44 self.tables = []
45 tbl = VppMplsTable(self, 0)
46 tbl.add_vpp_config()
47 self.tables.append(tbl)
48
49 tbl = VppIpTable(self, 10)
50 tbl.add_vpp_config()
51 self.tables.append(tbl)
52
53 # setup both interfaces
54 for i in self.pg_interfaces:
55 if i == self.pg2:
56 i.set_table_ip4(10)
57 i.admin_up()
58 i.config_ip4()
59 i.resolve_arp()
60 i.enable_mpls()
61
62 def tearDown(self):
63 for i in self.pg_interfaces:
64 i.disable_mpls()
65 i.unconfig_ip4()
66 i.set_table_ip4(0)
67 i.admin_down()
68 super(TestBier, self).tearDown()
69
Neale Rannsf0510722018-01-31 11:35:41 -080070 def bier_midpoint(self, hdr_len_id, n_bytes, max_bp):
Neale Rannsd792d9c2017-10-21 10:53:20 -070071 """BIER midpoint"""
72
73 #
74 # Add a BIER table for sub-domain 0, set 0, and BSL 256
75 #
Neale Rannsf0510722018-01-31 11:35:41 -080076 bti = VppBierTableID(0, 0, hdr_len_id)
Neale Rannsd792d9c2017-10-21 10:53:20 -070077 bt = VppBierTable(self, bti, 77)
78 bt.add_vpp_config()
79
80 #
81 # A packet with no bits set gets dropped
82 #
83 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
84 MPLS(label=77, ttl=255) /
Neale Rannsf0510722018-01-31 11:35:41 -080085 BIER(length=hdr_len_id) /
Neale Rannsd792d9c2017-10-21 10:53:20 -070086 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) /
87 UDP(sport=1234, dport=1234) /
88 Raw())
89 pkts = [p]
90
91 self.send_and_assert_no_replies(self.pg0, pkts,
92 "Empty Bit-String")
93
94 #
95 # Add a BIER route for each bit-position in the table via a different
96 # next-hop. Testing whether the BIER walk and replicate forwarding
97 # function works for all bit posisitons.
98 #
99 nh_routes = []
100 bier_routes = []
Neale Rannsf0510722018-01-31 11:35:41 -0800101 for i in range(1, max_bp+1):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700102 nh = "10.0.%d.%d" % (i / 255, i % 255)
Neale Ranns31ed7442018-02-23 05:29:09 -0800103 nh_routes.append(
104 VppIpRoute(self, nh, 32,
105 [VppRoutePath(self.pg1.remote_ip4,
106 self.pg1.sw_if_index,
107 labels=[VppMplsLabel(2000+i)])]))
Neale Rannsd792d9c2017-10-21 10:53:20 -0700108 nh_routes[-1].add_vpp_config()
109
Neale Ranns31ed7442018-02-23 05:29:09 -0800110 bier_routes.append(
111 VppBierRoute(self, bti, i,
112 [VppRoutePath(nh, 0xffffffff,
113 labels=[VppMplsLabel(100+i)])]))
Neale Rannsd792d9c2017-10-21 10:53:20 -0700114 bier_routes[-1].add_vpp_config()
115
116 #
Neale Rannsf0510722018-01-31 11:35:41 -0800117 # A packet with all bits set gets replicated once for each bit
Neale Rannsd792d9c2017-10-21 10:53:20 -0700118 #
Neale Rannsf0510722018-01-31 11:35:41 -0800119 pkt_sizes = [64, 1400]
Neale Rannsd792d9c2017-10-21 10:53:20 -0700120
Neale Rannsf0510722018-01-31 11:35:41 -0800121 for pkt_size in pkt_sizes:
122 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
123 MPLS(label=77, ttl=255) /
124 BIER(length=hdr_len_id, BitString=chr(255)*n_bytes) /
125 IPv6(src=self.pg0.remote_ip6, dst=self.pg0.remote_ip6) /
126 UDP(sport=1234, dport=1234) /
127 Raw(chr(5) * pkt_size))
128 pkts = p
Neale Rannsd792d9c2017-10-21 10:53:20 -0700129
Neale Rannsf0510722018-01-31 11:35:41 -0800130 self.pg0.add_stream(pkts)
131 self.pg_enable_capture(self.pg_interfaces)
132 self.pg_start()
Neale Rannsd792d9c2017-10-21 10:53:20 -0700133
Neale Rannsf0510722018-01-31 11:35:41 -0800134 rx = self.pg1.get_capture(max_bp)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700135
Neale Rannsf0510722018-01-31 11:35:41 -0800136 for rxp in rx:
137 #
138 # The packets are not required to be sent in bit-position order
139 # when we setup the routes above we used the bit-position to
140 # construct the out-label. so use that here to determine the BP
141 #
142 olabel = rxp[MPLS]
143 bp = olabel.label - 2000
Neale Rannsd792d9c2017-10-21 10:53:20 -0700144
Neale Rannsf0510722018-01-31 11:35:41 -0800145 blabel = olabel[MPLS].payload
146 self.assertEqual(blabel.label, 100+bp)
147 self.assertEqual(blabel.ttl, 254)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700148
Neale Rannsf0510722018-01-31 11:35:41 -0800149 bier_hdr = blabel[MPLS].payload
Neale Rannsd792d9c2017-10-21 10:53:20 -0700150
Neale Rannsf0510722018-01-31 11:35:41 -0800151 self.assertEqual(bier_hdr.id, 5)
152 self.assertEqual(bier_hdr.version, 0)
153 self.assertEqual(bier_hdr.length, hdr_len_id)
154 self.assertEqual(bier_hdr.entropy, 0)
155 self.assertEqual(bier_hdr.OAM, 0)
156 self.assertEqual(bier_hdr.RSV, 0)
157 self.assertEqual(bier_hdr.DSCP, 0)
158 self.assertEqual(bier_hdr.Proto, 5)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700159
Neale Rannsf0510722018-01-31 11:35:41 -0800160 # The bit-string should consist only of the BP given by i.
161 byte_array = ['\0'] * (n_bytes)
162 byte_val = chr(1 << (bp - 1) % 8)
163 byte_pos = n_bytes - (((bp - 1) / 8) + 1)
164 byte_array[byte_pos] = byte_val
165 bitstring = ''.join(byte_array)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700166
Neale Rannsf0510722018-01-31 11:35:41 -0800167 self.assertEqual(len(bitstring), len(bier_hdr.BitString))
168 self.assertEqual(bitstring, bier_hdr.BitString)
169
170 #
171 # cleanup. not strictly necessary, but it's much quicker this way
172 # becuase the bier_fib_dump and ip_fib_dump will be empty when the
173 # auto-cleanup kicks in
174 #
175 for br in bier_routes:
176 br.remove_vpp_config()
177 for nhr in nh_routes:
178 nhr.remove_vpp_config()
179
180 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
181 def test_bier_midpoint_1024(self):
182 """BIER midpoint BSL:1024"""
183 self.bier_midpoint(BIERLength.BIER_LEN_1024, 128, 1024)
184
185 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
186 def test_bier_midpoint_512(self):
187 """BIER midpoint BSL:512"""
188 self.bier_midpoint(BIERLength.BIER_LEN_512, 64, 512)
189
190 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
191 def test_bier_midpoint_256(self):
192 """BIER midpoint BSL:256"""
193 self.bier_midpoint(BIERLength.BIER_LEN_256, 32, 256)
194
195 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
196 def test_bier_midpoint_128(self):
197 """BIER midpoint BSL:128"""
198 self.bier_midpoint(BIERLength.BIER_LEN_128, 16, 128)
199
200 def test_bier_midpoint_64(self):
Neale Rannsc819fc62018-02-16 02:44:05 -0800201 """BIER midpoint BSL:64"""
Neale Rannsf0510722018-01-31 11:35:41 -0800202 self.bier_midpoint(BIERLength.BIER_LEN_64, 8, 64)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700203
204 def test_bier_head(self):
205 """BIER head"""
206
207 #
208 # Add a BIER table for sub-domain 0, set 0, and BSL 256
209 #
210 bti = VppBierTableID(0, 0, BIERLength.BIER_LEN_256)
211 bt = VppBierTable(self, bti, 77)
212 bt.add_vpp_config()
213
214 #
215 # 2 bit positions via two next hops
216 #
217 nh1 = "10.0.0.1"
218 nh2 = "10.0.0.2"
219 ip_route_1 = VppIpRoute(self, nh1, 32,
220 [VppRoutePath(self.pg1.remote_ip4,
221 self.pg1.sw_if_index,
Neale Ranns31ed7442018-02-23 05:29:09 -0800222 labels=[VppMplsLabel(2001)])])
Neale Rannsd792d9c2017-10-21 10:53:20 -0700223 ip_route_2 = VppIpRoute(self, nh2, 32,
224 [VppRoutePath(self.pg1.remote_ip4,
225 self.pg1.sw_if_index,
Neale Ranns31ed7442018-02-23 05:29:09 -0800226 labels=[VppMplsLabel(2002)])])
Neale Rannsd792d9c2017-10-21 10:53:20 -0700227 ip_route_1.add_vpp_config()
228 ip_route_2.add_vpp_config()
229
Neale Ranns91286372017-12-05 13:24:04 -0800230 bier_route_1 = VppBierRoute(self, bti, 1,
231 [VppRoutePath(nh1, 0xffffffff,
Neale Ranns31ed7442018-02-23 05:29:09 -0800232 labels=[VppMplsLabel(101)])])
Neale Ranns91286372017-12-05 13:24:04 -0800233 bier_route_2 = VppBierRoute(self, bti, 2,
234 [VppRoutePath(nh2, 0xffffffff,
Neale Ranns31ed7442018-02-23 05:29:09 -0800235 labels=[VppMplsLabel(102)])])
Neale Rannsd792d9c2017-10-21 10:53:20 -0700236 bier_route_1.add_vpp_config()
237 bier_route_2.add_vpp_config()
238
239 #
240 # An imposition object with both bit-positions set
241 #
242 bi = VppBierImp(self, bti, 333, chr(0x3) * 32)
243 bi.add_vpp_config()
244
245 #
246 # Add a multicast route that will forward into the BIER doamin
247 #
248 route_ing_232_1_1_1 = VppIpMRoute(
249 self,
250 "0.0.0.0",
251 "232.1.1.1", 32,
252 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
253 paths=[VppMRoutePath(self.pg0.sw_if_index,
254 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
255 VppMRoutePath(0xffffffff,
256 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
257 proto=DpoProto.DPO_PROTO_BIER,
258 bier_imp=bi.bi_index)])
259 route_ing_232_1_1_1.add_vpp_config()
260
261 #
Neale Ranns91286372017-12-05 13:24:04 -0800262 # inject an IP packet. We expect it to be BIER encapped and
Neale Rannsd792d9c2017-10-21 10:53:20 -0700263 # replicated.
264 #
265 p = (Ether(dst=self.pg0.local_mac,
266 src=self.pg0.remote_mac) /
267 IP(src="1.1.1.1", dst="232.1.1.1") /
268 UDP(sport=1234, dport=1234))
269
270 self.pg0.add_stream([p])
271 self.pg_enable_capture(self.pg_interfaces)
272 self.pg_start()
273
274 rx = self.pg1.get_capture(2)
275
Neale Ranns91286372017-12-05 13:24:04 -0800276 #
277 # Encap Stack is; eth, MPLS, MPLS, BIER
278 #
279 igp_mpls = rx[0][MPLS]
280 self.assertEqual(igp_mpls.label, 2001)
281 self.assertEqual(igp_mpls.ttl, 64)
282 self.assertEqual(igp_mpls.s, 0)
283 bier_mpls = igp_mpls[MPLS].payload
284 self.assertEqual(bier_mpls.label, 101)
285 self.assertEqual(bier_mpls.ttl, 64)
286 self.assertEqual(bier_mpls.s, 1)
287 self.assertEqual(rx[0][BIER].length, 2)
288
289 igp_mpls = rx[1][MPLS]
290 self.assertEqual(igp_mpls.label, 2002)
291 self.assertEqual(igp_mpls.ttl, 64)
292 self.assertEqual(igp_mpls.s, 0)
293 bier_mpls = igp_mpls[MPLS].payload
294 self.assertEqual(bier_mpls.label, 102)
295 self.assertEqual(bier_mpls.ttl, 64)
296 self.assertEqual(bier_mpls.s, 1)
297 self.assertEqual(rx[0][BIER].length, 2)
298
Neale Rannsd792d9c2017-10-21 10:53:20 -0700299 def test_bier_tail(self):
300 """BIER Tail"""
301
302 #
303 # Add a BIER table for sub-domain 0, set 0, and BSL 256
304 #
305 bti = VppBierTableID(0, 0, BIERLength.BIER_LEN_256)
306 bt = VppBierTable(self, bti, 77)
307 bt.add_vpp_config()
308
309 #
310 # disposition table
311 #
312 bdt = VppBierDispTable(self, 8)
313 bdt.add_vpp_config()
314
315 #
316 # BIER route in table that's for-us
317 #
Neale Ranns91286372017-12-05 13:24:04 -0800318 bier_route_1 = VppBierRoute(self, bti, 1,
319 [VppRoutePath("0.0.0.0",
320 0xffffffff,
321 nh_table_id=8)])
Neale Rannsd792d9c2017-10-21 10:53:20 -0700322 bier_route_1.add_vpp_config()
323
324 #
325 # An entry in the disposition table
326 #
327 bier_de_1 = VppBierDispEntry(self, bdt.id, 99,
328 BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
Neale Rannsf0510722018-01-31 11:35:41 -0800329 DpoProto.DPO_PROTO_BIER,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700330 "0.0.0.0", 0, rpf_id=8192)
331 bier_de_1.add_vpp_config()
332
333 #
334 # A multicast route to forward post BIER disposition
335 #
336 route_eg_232_1_1_1 = VppIpMRoute(
337 self,
338 "0.0.0.0",
339 "232.1.1.1", 32,
340 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
341 paths=[VppMRoutePath(self.pg1.sw_if_index,
342 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
343 route_eg_232_1_1_1.add_vpp_config()
344 route_eg_232_1_1_1.update_rpf_id(8192)
345
346 #
347 # A packet with all bits set gets spat out to BP:1
348 #
349 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
350 MPLS(label=77, ttl=255) /
Neale Rannsf0510722018-01-31 11:35:41 -0800351 BIER(length=BIERLength.BIER_LEN_256,
352 BitString=chr(255)*32,
353 BFRID=99) /
Neale Rannsd792d9c2017-10-21 10:53:20 -0700354 IP(src="1.1.1.1", dst="232.1.1.1") /
355 UDP(sport=1234, dport=1234) /
356 Raw())
357
358 self.send_and_expect(self.pg0, [p], self.pg1)
359
Neale Rannsceb4d052017-12-13 09:13:41 -0800360 #
361 # A packet that does not match the Disposition entry gets dropped
362 #
363 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
364 MPLS(label=77, ttl=255) /
Neale Rannsf0510722018-01-31 11:35:41 -0800365 BIER(length=BIERLength.BIER_LEN_256,
366 BitString=chr(255)*32,
367 BFRID=77) /
Neale Rannsceb4d052017-12-13 09:13:41 -0800368 IP(src="1.1.1.1", dst="232.1.1.1") /
369 UDP(sport=1234, dport=1234) /
370 Raw())
371 self.send_and_assert_no_replies(self.pg0, p*2,
372 "no matching disposition entry")
373
374 #
375 # Add the default route to the disposition table
376 #
377 bier_de_2 = VppBierDispEntry(self, bdt.id, 0,
378 BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
Neale Rannsf0510722018-01-31 11:35:41 -0800379 DpoProto.DPO_PROTO_BIER,
Neale Rannsceb4d052017-12-13 09:13:41 -0800380 "0.0.0.0", 0, rpf_id=8192)
381 bier_de_2.add_vpp_config()
382
383 #
384 # now the previous packet is forwarded
385 #
386 self.send_and_expect(self.pg0, [p], self.pg1)
387
Neale Rannsf0510722018-01-31 11:35:41 -0800388 def bier_e2e(self, hdr_len_id, n_bytes, max_bp):
389 """ BIER end-to-end"""
Neale Rannsd792d9c2017-10-21 10:53:20 -0700390
391 #
392 # Add a BIER table for sub-domain 0, set 0, and BSL 256
393 #
Neale Rannsf0510722018-01-31 11:35:41 -0800394 bti = VppBierTableID(0, 0, hdr_len_id)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700395 bt = VppBierTable(self, bti, 77)
396 bt.add_vpp_config()
397
Neale Rannsf0510722018-01-31 11:35:41 -0800398 lowest = ['\0'] * (n_bytes)
399 lowest[-1] = chr(1)
400 highest = ['\0'] * (n_bytes)
401 highest[0] = chr(128)
402
Neale Rannsd792d9c2017-10-21 10:53:20 -0700403 #
Neale Rannsf0510722018-01-31 11:35:41 -0800404 # Impostion Sets bit strings
Neale Rannsd792d9c2017-10-21 10:53:20 -0700405 #
Neale Rannsf0510722018-01-31 11:35:41 -0800406 bi_low = VppBierImp(self, bti, 333, lowest)
407 bi_low.add_vpp_config()
408 bi_high = VppBierImp(self, bti, 334, highest)
409 bi_high.add_vpp_config()
Neale Rannsd792d9c2017-10-21 10:53:20 -0700410
411 #
412 # Add a multicast route that will forward into the BIER doamin
413 #
414 route_ing_232_1_1_1 = VppIpMRoute(
415 self,
416 "0.0.0.0",
417 "232.1.1.1", 32,
418 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
419 paths=[VppMRoutePath(self.pg0.sw_if_index,
420 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
421 VppMRoutePath(0xffffffff,
422 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
423 proto=DpoProto.DPO_PROTO_BIER,
Neale Rannsf0510722018-01-31 11:35:41 -0800424 bier_imp=bi_low.bi_index)])
Neale Rannsd792d9c2017-10-21 10:53:20 -0700425 route_ing_232_1_1_1.add_vpp_config()
Neale Rannsf0510722018-01-31 11:35:41 -0800426 route_ing_232_1_1_2 = VppIpMRoute(
427 self,
428 "0.0.0.0",
429 "232.1.1.2", 32,
430 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
431 paths=[VppMRoutePath(self.pg0.sw_if_index,
432 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
433 VppMRoutePath(0xffffffff,
434 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
435 proto=DpoProto.DPO_PROTO_BIER,
436 bier_imp=bi_high.bi_index)])
437 route_ing_232_1_1_2.add_vpp_config()
Neale Rannsd792d9c2017-10-21 10:53:20 -0700438
439 #
440 # disposition table 8
441 #
442 bdt = VppBierDispTable(self, 8)
443 bdt.add_vpp_config()
444
445 #
Neale Rannsf0510722018-01-31 11:35:41 -0800446 # BIER routes in table that are for-us, resolving through
Neale Rannsd792d9c2017-10-21 10:53:20 -0700447 # disp table 8.
448 #
Neale Ranns91286372017-12-05 13:24:04 -0800449 bier_route_1 = VppBierRoute(self, bti, 1,
450 [VppRoutePath("0.0.0.0",
451 0xffffffff,
452 nh_table_id=8)])
Neale Rannsd792d9c2017-10-21 10:53:20 -0700453 bier_route_1.add_vpp_config()
Neale Rannsf0510722018-01-31 11:35:41 -0800454 bier_route_max = VppBierRoute(self, bti, max_bp,
455 [VppRoutePath("0.0.0.0",
456 0xffffffff,
457 nh_table_id=8)])
458 bier_route_max.add_vpp_config()
Neale Rannsd792d9c2017-10-21 10:53:20 -0700459
460 #
461 # An entry in the disposition table for sender 333
462 # lookup in VRF 10
463 #
464 bier_de_1 = VppBierDispEntry(self, bdt.id, 333,
465 BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
Neale Rannsf0510722018-01-31 11:35:41 -0800466 DpoProto.DPO_PROTO_BIER,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700467 "0.0.0.0", 10, rpf_id=8192)
468 bier_de_1.add_vpp_config()
Neale Rannsf0510722018-01-31 11:35:41 -0800469 bier_de_1 = VppBierDispEntry(self, bdt.id, 334,
470 BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
471 DpoProto.DPO_PROTO_BIER,
472 "0.0.0.0", 10, rpf_id=8193)
473 bier_de_1.add_vpp_config()
Neale Rannsd792d9c2017-10-21 10:53:20 -0700474
475 #
Neale Rannsf0510722018-01-31 11:35:41 -0800476 # Add a multicast routes that will forward the traffic
Neale Rannsd792d9c2017-10-21 10:53:20 -0700477 # post-disposition
478 #
479 route_eg_232_1_1_1 = VppIpMRoute(
480 self,
481 "0.0.0.0",
482 "232.1.1.1", 32,
483 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
484 table_id=10,
485 paths=[VppMRoutePath(self.pg1.sw_if_index,
486 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
487 route_eg_232_1_1_1.add_vpp_config()
488 route_eg_232_1_1_1.update_rpf_id(8192)
Neale Rannsf0510722018-01-31 11:35:41 -0800489 route_eg_232_1_1_2 = VppIpMRoute(
490 self,
491 "0.0.0.0",
492 "232.1.1.2", 32,
493 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
494 table_id=10,
495 paths=[VppMRoutePath(self.pg1.sw_if_index,
496 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
497 route_eg_232_1_1_2.add_vpp_config()
498 route_eg_232_1_1_2.update_rpf_id(8193)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700499
500 #
501 # inject a packet in VRF-0. We expect it to be BIER encapped,
502 # replicated, then hit the disposition and be forwarded
503 # out of VRF 10, i.e. on pg1
504 #
505 p = (Ether(dst=self.pg0.local_mac,
506 src=self.pg0.remote_mac) /
507 IP(src="1.1.1.1", dst="232.1.1.1") /
Neale Rannsf0510722018-01-31 11:35:41 -0800508 UDP(sport=1234, dport=1234) /
509 Raw(chr(5) * 32))
Neale Rannsd792d9c2017-10-21 10:53:20 -0700510
Neale Ranns91286372017-12-05 13:24:04 -0800511 rx = self.send_and_expect(self.pg0, p*65, self.pg1)
512
Neale Ranns91286372017-12-05 13:24:04 -0800513 self.assertEqual(rx[0][IP].src, "1.1.1.1")
514 self.assertEqual(rx[0][IP].dst, "232.1.1.1")
515
Neale Rannsf0510722018-01-31 11:35:41 -0800516 p = (Ether(dst=self.pg0.local_mac,
517 src=self.pg0.remote_mac) /
518 IP(src="1.1.1.1", dst="232.1.1.2") /
519 UDP(sport=1234, dport=1234) /
520 Raw(chr(5) * 512))
521
522 rx = self.send_and_expect(self.pg0, p*65, self.pg1)
523 self.assertEqual(rx[0][IP].src, "1.1.1.1")
524 self.assertEqual(rx[0][IP].dst, "232.1.1.2")
525
526 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
527 def test_bier_e2e_1024(self):
528 """ BIER end-to-end BSL:1024"""
529 self.bier_e2e(BIERLength.BIER_LEN_1024, 128, 1024)
530
531 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
532 def test_bier_e2e_512(self):
533 """ BIER end-to-end BSL:512"""
534 self.bier_e2e(BIERLength.BIER_LEN_512, 64, 512)
535
536 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
537 def test_bier_e2e_256(self):
538 """ BIER end-to-end BSL:256"""
539 self.bier_e2e(BIERLength.BIER_LEN_256, 32, 256)
540
541 @unittest.skipUnless(running_extended_tests(), "part of extended tests")
542 def test_bier_e2e_128(self):
543 """ BIER end-to-end BSL:128"""
544 self.bier_e2e(BIERLength.BIER_LEN_128, 16, 128)
545
546 def test_bier_e2e_64(self):
547 """ BIER end-to-end BSL:64"""
548 self.bier_e2e(BIERLength.BIER_LEN_64, 8, 64)
549
Neale Ranns91286372017-12-05 13:24:04 -0800550 def test_bier_head_o_udp(self):
551 """BIER head over UDP"""
552
553 #
554 # Add a BIER table for sub-domain 1, set 0, and BSL 256
555 #
556 bti = VppBierTableID(1, 0, BIERLength.BIER_LEN_256)
557 bt = VppBierTable(self, bti, 77)
558 bt.add_vpp_config()
559
560 #
561 # 1 bit positions via 1 next hops
562 #
563 nh1 = "10.0.0.1"
564 ip_route = VppIpRoute(self, nh1, 32,
565 [VppRoutePath(self.pg1.remote_ip4,
566 self.pg1.sw_if_index,
Neale Ranns31ed7442018-02-23 05:29:09 -0800567 labels=[VppMplsLabel(2001)])])
Neale Ranns91286372017-12-05 13:24:04 -0800568 ip_route.add_vpp_config()
569
570 udp_encap = VppUdpEncap(self, 4,
571 self.pg0.local_ip4,
572 nh1,
573 330, 8138)
574 udp_encap.add_vpp_config()
575
576 bier_route = VppBierRoute(self, bti, 1,
577 [VppRoutePath("0.0.0.0",
578 0xFFFFFFFF,
579 is_udp_encap=1,
580 next_hop_id=4)])
581 bier_route.add_vpp_config()
582
583 #
Neale Rannseea537a2018-01-09 04:11:28 -0800584 # An 2 imposition objects with all bit-positions set
585 # only use the second, but creating 2 tests with a non-zero
586 # value index in the route add
Neale Ranns91286372017-12-05 13:24:04 -0800587 #
588 bi = VppBierImp(self, bti, 333, chr(0xff) * 32)
589 bi.add_vpp_config()
Neale Rannseea537a2018-01-09 04:11:28 -0800590 bi2 = VppBierImp(self, bti, 334, chr(0xff) * 32)
591 bi2.add_vpp_config()
Neale Ranns91286372017-12-05 13:24:04 -0800592
593 #
594 # Add a multicast route that will forward into the BIER doamin
595 #
596 route_ing_232_1_1_1 = VppIpMRoute(
597 self,
598 "0.0.0.0",
599 "232.1.1.1", 32,
600 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
601 paths=[VppMRoutePath(self.pg0.sw_if_index,
602 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
603 VppMRoutePath(0xffffffff,
604 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
605 proto=DpoProto.DPO_PROTO_BIER,
Neale Rannseea537a2018-01-09 04:11:28 -0800606 bier_imp=bi2.bi_index)])
Neale Ranns91286372017-12-05 13:24:04 -0800607 route_ing_232_1_1_1.add_vpp_config()
608
609 #
610 # inject a packet an IP. We expect it to be BIER and UDP encapped,
611 #
612 p = (Ether(dst=self.pg0.local_mac,
613 src=self.pg0.remote_mac) /
614 IP(src="1.1.1.1", dst="232.1.1.1") /
615 UDP(sport=1234, dport=1234))
616
617 self.pg0.add_stream([p])
618 self.pg_enable_capture(self.pg_interfaces)
619 self.pg_start()
620
621 rx = self.pg1.get_capture(1)
622
623 #
624 # Encap Stack is, eth, IP, UDP, BIFT, BIER
625 #
626 self.assertEqual(rx[0][IP].src, self.pg0.local_ip4)
627 self.assertEqual(rx[0][IP].dst, nh1)
628 self.assertEqual(rx[0][UDP].sport, 330)
629 self.assertEqual(rx[0][UDP].dport, 8138)
630 self.assertEqual(rx[0][BIFT].bsl, 2)
631 self.assertEqual(rx[0][BIFT].sd, 1)
632 self.assertEqual(rx[0][BIFT].set, 0)
633 self.assertEqual(rx[0][BIFT].ttl, 64)
634 self.assertEqual(rx[0][BIER].length, 2)
635
636 def test_bier_tail_o_udp(self):
637 """BIER Tail over UDP"""
638
639 #
640 # Add a BIER table for sub-domain 0, set 0, and BSL 256
641 #
642 bti = VppBierTableID(1, 0, BIERLength.BIER_LEN_256)
643 bt = VppBierTable(self, bti, MPLS_LABEL_INVALID)
644 bt.add_vpp_config()
645
646 #
647 # disposition table
648 #
649 bdt = VppBierDispTable(self, 8)
650 bdt.add_vpp_config()
651
652 #
653 # BIER route in table that's for-us
654 #
655 bier_route_1 = VppBierRoute(self, bti, 1,
656 [VppRoutePath("0.0.0.0",
657 0xffffffff,
658 nh_table_id=8)])
659 bier_route_1.add_vpp_config()
660
661 #
662 # An entry in the disposition table
663 #
664 bier_de_1 = VppBierDispEntry(self, bdt.id, 99,
665 BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
Neale Rannsf0510722018-01-31 11:35:41 -0800666 DpoProto.DPO_PROTO_BIER,
Neale Ranns91286372017-12-05 13:24:04 -0800667 "0.0.0.0", 0, rpf_id=8192)
668 bier_de_1.add_vpp_config()
669
670 #
671 # A multicast route to forward post BIER disposition
672 #
673 route_eg_232_1_1_1 = VppIpMRoute(
674 self,
675 "0.0.0.0",
676 "232.1.1.1", 32,
677 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
678 paths=[VppMRoutePath(self.pg1.sw_if_index,
679 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
680 route_eg_232_1_1_1.add_vpp_config()
681 route_eg_232_1_1_1.update_rpf_id(8192)
682
683 #
684 # A packet with all bits set gets spat out to BP:1
685 #
686 p = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
687 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
688 UDP(sport=333, dport=8138) /
689 BIFT(sd=1, set=0, bsl=2, ttl=255) /
Neale Rannsf0510722018-01-31 11:35:41 -0800690 BIER(length=BIERLength.BIER_LEN_256,
691 BitString=chr(255)*32,
692 BFRID=99) /
Neale Ranns91286372017-12-05 13:24:04 -0800693 IP(src="1.1.1.1", dst="232.1.1.1") /
694 UDP(sport=1234, dport=1234) /
695 Raw())
696
697 rx = self.send_and_expect(self.pg0, [p], self.pg1)
Neale Rannsd792d9c2017-10-21 10:53:20 -0700698
699
700if __name__ == '__main__':
701 unittest.main(testRunner=VppTestRunner)