ipsec: IPSec protection for multi-point tunnel interfaces
[vpp.git] / test / test_bier.py
index 58ca3b0..1c58ee5 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import unittest
 
@@ -7,7 +7,7 @@ from vpp_ip import DpoProto
 from vpp_ip_route import VppIpRoute, VppRoutePath, \
     VppMplsTable, VppIpMRoute, VppMRoutePath, VppIpTable, \
     MRouteEntryFlags, MRouteItfFlags, MPLS_LABEL_INVALID, \
-    VppMplsLabel
+    VppMplsLabel, FibPathProto, FibPathType
 from vpp_bier import BIER_HDR_PAYLOAD, VppBierImp, VppBierDispEntry, \
     VppBierDispTable, VppBierTable, VppBierTableID, VppBierRoute
 from vpp_udp_encap import VppUdpEncap
@@ -20,6 +20,8 @@ from scapy.layers.inet6 import IPv6
 from scapy.contrib.mpls import MPLS
 from scapy.contrib.bier import BIER, BIERLength, BIFT
 
+NUM_PKTS = 67
+
 
 class TestBFIB(VppTestCase):
     """ BIER FIB Test Case """
@@ -165,7 +167,7 @@ class TestBier(VppTestCase):
                 byte_val = scapy.compat.chb(1 << (bp - 1) % 8)
                 byte_pos = n_bytes - (((bp - 1) // 8) + 1)
                 byte_array[byte_pos] = byte_val
-                bitstring = ''.join([scapy.compat.chb(x) for x in byte_array])
+                bitstring = b''.join(byte_array)
 
                 self.assertEqual(len(bitstring), len(bier_hdr.BitString))
                 self.assertEqual(bitstring, bier_hdr.BitString)
@@ -276,6 +278,7 @@ class TestBier(VppTestCase):
                           labels=[VppMplsLabel(101)])])
 
         rx = self.send_and_expect(self.pg0, pkts, self.pg1)
+
         for nh in nhs:
             self.assertTrue(sum(p[MPLS].label == nh['label'] for p in rx))
 
@@ -351,7 +354,8 @@ class TestBier(VppTestCase):
                                  MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
                    VppMRoutePath(0xffffffff,
                                  MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
-                                 proto=DpoProto.DPO_PROTO_BIER,
+                                 proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
+                                 type=FibPathType.FIB_PATH_TYPE_BIER_IMP,
                                  bier_imp=bi.bi_index)])
         route_ing_232_1_1_1.add_vpp_config()
 
@@ -416,7 +420,7 @@ class TestBier(VppTestCase):
             self, bti, 1,
             [VppRoutePath("0.0.0.0",
                           0xffffffff,
-                          proto=DpoProto.DPO_PROTO_BIER,
+                          proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
                           nh_table_id=8)])
         bier_route_1.add_vpp_config()
 
@@ -425,7 +429,7 @@ class TestBier(VppTestCase):
         #
         bier_de_1 = VppBierDispEntry(self, bdt.id, 99,
                                      BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
-                                     DpoProto.DPO_PROTO_BIER,
+                                     FibPathProto.FIB_PATH_NH_PROTO_BIER,
                                      "0.0.0.0", 0, rpf_id=8192)
         bier_de_1.add_vpp_config()
 
@@ -475,7 +479,7 @@ class TestBier(VppTestCase):
         #
         bier_de_2 = VppBierDispEntry(self, bdt.id, 0,
                                      BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
-                                     DpoProto.DPO_PROTO_BIER,
+                                     FibPathProto.FIB_PATH_NH_PROTO_BIER,
                                      "0.0.0.0", 0, rpf_id=8192)
         bier_de_2.add_vpp_config()
 
@@ -499,6 +503,7 @@ class TestBier(VppTestCase):
             paths=[VppMRoutePath(0xffffffff,
                                  MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
                                  proto=DpoProto.DPO_PROTO_BIER,
+                                 type=FibPathType.FIB_PATH_TYPE_BIER_IMP,
                                  bier_imp=bi.bi_index),
                    VppMRoutePath(self.pg1.sw_if_index,
                                  MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
@@ -550,7 +555,8 @@ class TestBier(VppTestCase):
                                  MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
                    VppMRoutePath(0xffffffff,
                                  MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
-                                 proto=DpoProto.DPO_PROTO_BIER,
+                                 proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
+                                 type=FibPathType.FIB_PATH_TYPE_BIER_IMP,
                                  bier_imp=bi_low.bi_index)])
         route_ing_232_1_1_1.add_vpp_config()
         route_ing_232_1_1_2 = VppIpMRoute(
@@ -562,7 +568,8 @@ class TestBier(VppTestCase):
                                  MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
                    VppMRoutePath(0xffffffff,
                                  MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
-                                 proto=DpoProto.DPO_PROTO_BIER,
+                                 proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
+                                 type=FibPathType.FIB_PATH_TYPE_BIER_IMP,
                                  bier_imp=bi_high.bi_index)])
         route_ing_232_1_1_2.add_vpp_config()
 
@@ -580,13 +587,15 @@ class TestBier(VppTestCase):
             self, bti, 1,
             [VppRoutePath("0.0.0.0",
                           0xffffffff,
-                          proto=DpoProto.DPO_PROTO_BIER,
+                          proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
                           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 = VppBierRoute(
+            self, bti, max_bp,
+            [VppRoutePath("0.0.0.0",
+                          0xffffffff,
+                          proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
+                          nh_table_id=8)])
         bier_route_max.add_vpp_config()
 
         #
@@ -595,12 +604,12 @@ class TestBier(VppTestCase):
         #
         bier_de_1 = VppBierDispEntry(self, bdt.id, 333,
                                      BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
-                                     DpoProto.DPO_PROTO_BIER,
+                                     FibPathProto.FIB_PATH_NH_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,
+                                     FibPathProto.FIB_PATH_NH_PROTO_BIER,
                                      "0.0.0.0", 10, rpf_id=8193)
         bier_de_1.add_vpp_config()
 
@@ -640,7 +649,7 @@ class TestBier(VppTestCase):
              UDP(sport=1234, dport=1234) /
              Raw(scapy.compat.chb(5) * 32))
 
-        rx = self.send_and_expect(self.pg0, p*65, self.pg1)
+        rx = self.send_and_expect(self.pg0, p*NUM_PKTS, self.pg1)
 
         self.assertEqual(rx[0][IP].src, "1.1.1.1")
         self.assertEqual(rx[0][IP].dst, "232.1.1.1")
@@ -651,7 +660,7 @@ class TestBier(VppTestCase):
              UDP(sport=1234, dport=1234) /
              Raw(scapy.compat.chb(5) * 512))
 
-        rx = self.send_and_expect(self.pg0, p*65, self.pg1)
+        rx = self.send_and_expect(self.pg0, p*NUM_PKTS, self.pg1)
         self.assertEqual(rx[0][IP].src, "1.1.1.1")
         self.assertEqual(rx[0][IP].dst, "232.1.1.2")
 
@@ -709,7 +718,7 @@ class TestBier(VppTestCase):
             self, bti, 1,
             [VppRoutePath("0.0.0.0",
                           0xFFFFFFFF,
-                          is_udp_encap=1,
+                          type=FibPathType.FIB_PATH_TYPE_UDP_ENCAP,
                           next_hop_id=udp_encap.id)])
         bier_route.add_vpp_config()
 
@@ -735,7 +744,8 @@ class TestBier(VppTestCase):
                                  MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
                    VppMRoutePath(0xffffffff,
                                  MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
-                                 proto=DpoProto.DPO_PROTO_BIER,
+                                 proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
+                                 type=FibPathType.FIB_PATH_TYPE_BIER_IMP,
                                  bier_imp=bi2.bi_index)])
         route_ing_232_1_1_1.add_vpp_config()
 
@@ -789,7 +799,7 @@ class TestBier(VppTestCase):
             self, bti, 1,
             [VppRoutePath("0.0.0.0",
                           0xffffffff,
-                          proto=DpoProto.DPO_PROTO_BIER,
+                          proto=FibPathProto.FIB_PATH_NH_PROTO_BIER,
                           nh_table_id=8)])
         bier_route_1.add_vpp_config()
 
@@ -798,7 +808,7 @@ class TestBier(VppTestCase):
         #
         bier_de_1 = VppBierDispEntry(self, bdt.id, 99,
                                      BIER_HDR_PAYLOAD.BIER_HDR_PROTO_IPV4,
-                                     DpoProto.DPO_PROTO_BIER,
+                                     FibPathProto.FIB_PATH_NH_PROTO_BIER,
                                      "0.0.0.0", 0, rpf_id=8192)
         bier_de_1.add_vpp_config()