MPLS Unifom mode
[vpp.git] / test / test_bier.py
1 #!/usr/bin/env python
2
3 import unittest
4 import socket
5
6 from framework import VppTestCase, VppTestRunner, running_extended_tests
7 from vpp_ip_route import VppIpRoute, VppRoutePath, VppMplsRoute, \
8     VppMplsTable, VppIpMRoute, VppMRoutePath, VppIpTable, \
9     MRouteEntryFlags, MRouteItfFlags, MPLS_LABEL_INVALID, DpoProto, \
10     VppMplsLabel
11 from vpp_bier import *
12 from vpp_udp_encap import *
13
14 from scapy.packet import Raw
15 from scapy.layers.l2 import Ether
16 from scapy.layers.inet import IP, UDP, ICMP
17 from scapy.layers.inet6 import IPv6
18 from scapy.contrib.mpls import MPLS
19 from scapy.contrib.bier import *
20
21
22 class 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
34 class 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
70     def bier_midpoint(self, hdr_len_id, n_bytes, max_bp):
71         """BIER midpoint"""
72
73         #
74         # Add a BIER table for sub-domain 0, set 0, and BSL 256
75         #
76         bti = VppBierTableID(0, 0, hdr_len_id)
77         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) /
85              BIER(length=hdr_len_id) /
86              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 = []
101         for i in range(1, max_bp+1):
102             nh = "10.0.%d.%d" % (i / 255, i % 255)
103             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)])]))
108             nh_routes[-1].add_vpp_config()
109
110             bier_routes.append(
111                 VppBierRoute(self, bti, i,
112                              [VppRoutePath(nh, 0xffffffff,
113                                            labels=[VppMplsLabel(100+i)])]))
114             bier_routes[-1].add_vpp_config()
115
116         #
117         # A packet with all bits set gets replicated once for each bit
118         #
119         pkt_sizes = [64, 1400]
120
121         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
129
130             self.pg0.add_stream(pkts)
131             self.pg_enable_capture(self.pg_interfaces)
132             self.pg_start()
133
134             rx = self.pg1.get_capture(max_bp)
135
136             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
144
145                 blabel = olabel[MPLS].payload
146                 self.assertEqual(blabel.label, 100+bp)
147                 self.assertEqual(blabel.ttl, 254)
148
149                 bier_hdr = blabel[MPLS].payload
150
151                 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)
159
160                 # 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)
166
167                 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):
201         """BIER midpoint BSL:64"""
202         self.bier_midpoint(BIERLength.BIER_LEN_64, 8, 64)
203
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,
222                                               labels=[VppMplsLabel(2001)])])
223         ip_route_2 = VppIpRoute(self, nh2, 32,
224                                 [VppRoutePath(self.pg1.remote_ip4,
225                                               self.pg1.sw_if_index,
226                                               labels=[VppMplsLabel(2002)])])
227         ip_route_1.add_vpp_config()
228         ip_route_2.add_vpp_config()
229
230         bier_route_1 = VppBierRoute(self, bti, 1,
231                                     [VppRoutePath(nh1, 0xffffffff,
232                                                   labels=[VppMplsLabel(101)])])
233         bier_route_2 = VppBierRoute(self, bti, 2,
234                                     [VppRoutePath(nh2, 0xffffffff,
235                                                   labels=[VppMplsLabel(102)])])
236         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         #
262         # inject an IP packet. We expect it to be BIER encapped and
263         # 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
276         #
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
299     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         #
318         bier_route_1 = VppBierRoute(self, bti, 1,
319                                     [VppRoutePath("0.0.0.0",
320                                                   0xffffffff,
321                                                   nh_table_id=8)])
322         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,
329                                      DpoProto.DPO_PROTO_BIER,
330                                      "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) /
351              BIER(length=BIERLength.BIER_LEN_256,
352                   BitString=chr(255)*32,
353                   BFRID=99) /
354              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
360         #
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) /
365              BIER(length=BIERLength.BIER_LEN_256,
366                   BitString=chr(255)*32,
367                   BFRID=77) /
368              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,
379                                      DpoProto.DPO_PROTO_BIER,
380                                      "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
388     def bier_e2e(self, hdr_len_id, n_bytes, max_bp):
389         """ BIER end-to-end"""
390
391         #
392         # Add a BIER table for sub-domain 0, set 0, and BSL 256
393         #
394         bti = VppBierTableID(0, 0, hdr_len_id)
395         bt = VppBierTable(self, bti, 77)
396         bt.add_vpp_config()
397
398         lowest = ['\0'] * (n_bytes)
399         lowest[-1] = chr(1)
400         highest = ['\0'] * (n_bytes)
401         highest[0] = chr(128)
402
403         #
404         # Impostion Sets bit strings
405         #
406         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()
410
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,
424                                  bier_imp=bi_low.bi_index)])
425         route_ing_232_1_1_1.add_vpp_config()
426         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()
438
439         #
440         # disposition table 8
441         #
442         bdt = VppBierDispTable(self, 8)
443         bdt.add_vpp_config()
444
445         #
446         # BIER routes in table that are for-us, resolving through
447         # disp table 8.
448         #
449         bier_route_1 = VppBierRoute(self, bti, 1,
450                                     [VppRoutePath("0.0.0.0",
451                                                   0xffffffff,
452                                                   nh_table_id=8)])
453         bier_route_1.add_vpp_config()
454         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()
459
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,
466                                      DpoProto.DPO_PROTO_BIER,
467                                      "0.0.0.0", 10, rpf_id=8192)
468         bier_de_1.add_vpp_config()
469         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()
474
475         #
476         # Add a multicast routes that will forward the traffic
477         # 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)
489         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)
499
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") /
508              UDP(sport=1234, dport=1234) /
509              Raw(chr(5) * 32))
510
511         rx = self.send_and_expect(self.pg0, p*65, self.pg1)
512
513         self.assertEqual(rx[0][IP].src, "1.1.1.1")
514         self.assertEqual(rx[0][IP].dst, "232.1.1.1")
515
516         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
550     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,
567                                             labels=[VppMplsLabel(2001)])])
568         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         #
584         # 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
587         #
588         bi = VppBierImp(self, bti, 333, chr(0xff) * 32)
589         bi.add_vpp_config()
590         bi2 = VppBierImp(self, bti, 334, chr(0xff) * 32)
591         bi2.add_vpp_config()
592
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,
606                                  bier_imp=bi2.bi_index)])
607         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,
666                                      DpoProto.DPO_PROTO_BIER,
667                                      "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) /
690              BIER(length=BIERLength.BIER_LEN_256,
691                   BitString=chr(255)*32,
692                   BFRID=99) /
693              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)
698
699
700 if __name__ == '__main__':
701     unittest.main(testRunner=VppTestRunner)