BD ARP entry use common API types
[vpp.git] / test / test_gbp.py
index 8e873f3..ef4bf70 100644 (file)
@@ -10,7 +10,6 @@ from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable
 from vpp_ip import *
 from vpp_mac import *
 from vpp_papi_provider import L2_PORT_TYPE
-from vpp_papi.vpp_format import VPPFormat
 
 from scapy.packet import Raw
 from scapy.layers.l2 import Ether, ARP
@@ -163,7 +162,7 @@ class VppGbpSubnet(VppObject):
                  sw_if_index=None, epg=None):
         self._test = test
         self.table_id = table_id
-        self.prefix = "{}/{}".format(address, address_len)
+        self.prefix = VppIpPrefix(address, address_len)
         self.is_internal = is_internal
         self.sw_if_index = sw_if_index
         self.epg = epg
@@ -173,7 +172,7 @@ class VppGbpSubnet(VppObject):
             1,
             self.table_id,
             self.is_internal,
-            self.prefix,
+            self.prefix.encode(),
             sw_if_index=self.sw_if_index if self.sw_if_index else 0xffffffff,
             epg_id=self.epg if self.epg else 0xffff)
         self._test.registry.register(self, self._test.logger)
@@ -183,7 +182,7 @@ class VppGbpSubnet(VppObject):
             0,
             self.table_id,
             self.is_internal,
-            self.prefix)
+            self.prefix.encode())
 
     def __str__(self):
         return self.object_id()
@@ -196,7 +195,7 @@ class VppGbpSubnet(VppObject):
         ss = self._test.vapi.gbp_subnet_dump()
         for s in ss:
             if s.subnet.table_id == self.table_id and \
-               VPPFormat.unformat(s.subnet.prefix) == self.prefix:
+               s.subnet.prefix == self.prefix:
                 return True
         return False
 
@@ -211,10 +210,8 @@ class VppGbpEndpointGroup(VppObject):
         self._test = test
         self.uplink = uplink
         self.bvi = bvi
-        self.bvi_ip4 = bvi_ip4
-        self.bvi_ip4_n = inet_pton(AF_INET, bvi_ip4)
-        self.bvi_ip6 = bvi_ip6
-        self.bvi_ip6_n = inet_pton(AF_INET6, bvi_ip6)
+        self.bvi_ip4 = VppIpAddress(bvi_ip4)
+        self.bvi_ip6 = VppIpAddress(bvi_ip6)
         self.epg = epg
         self.bd = bd
         self.rd = rd
@@ -359,7 +356,7 @@ class TestGBP(VppTestCase):
         self.create_pg_interfaces(range(9))
         self.create_loopback_interfaces(9)
 
-        self.router_mac = "00:11:22:33:44:55"
+        self.router_mac = VppMacAddress("00:11:22:33:44:55")
 
         for i in self.pg_interfaces:
             i.admin_up()
@@ -367,7 +364,7 @@ class TestGBP(VppTestCase):
             i.admin_up()
             self.vapi.sw_interface_set_mac_address(
                 i.sw_if_index,
-                mactobinary(self.router_mac))
+                self.router_mac.bytes)
 
     def tearDown(self):
         for i in self.pg_interfaces:
@@ -449,7 +446,7 @@ class TestGBP(VppTestCase):
         rx = self.send_and_expect(src, tx, dst)
 
         for r in rx:
-            self.assertEqual(r[Ether].src, self.router_mac)
+            self.assertEqual(r[Ether].src, self.router_mac.address)
             self.assertEqual(r[Ether].dst, dst.remote_mac)
             self.assertEqual(r[IP].dst, dst_ip)
             self.assertEqual(r[IP].src, src_ip)
@@ -459,7 +456,7 @@ class TestGBP(VppTestCase):
         rx = self.send_and_expect(src, tx, dst)
 
         for r in rx:
-            self.assertEqual(r[Ether].src, self.router_mac)
+            self.assertEqual(r[Ether].src, self.router_mac.address)
             self.assertEqual(r[Ether].dst, dst.remote_mac)
             self.assertEqual(r[IPv6].dst, dst_ip)
             self.assertEqual(r[IPv6].src, src_ip)
@@ -559,10 +556,10 @@ class TestGBP(VppTestCase):
                                                   is_add=1)
 
             self.vapi.sw_interface_add_del_address(epg.bvi.sw_if_index,
-                                                   epg.bvi_ip4_n,
+                                                   epg.bvi_ip4.bytes,
                                                    32)
             self.vapi.sw_interface_add_del_address(epg.bvi.sw_if_index,
-                                                   epg.bvi_ip6_n,
+                                                   epg.bvi_ip6.bytes,
                                                    128,
                                                    is_ipv6=True)
 
@@ -574,13 +571,13 @@ class TestGBP(VppTestCase):
 
             # add the BD ARP termination entry for BVI IP
             self.vapi.bd_ip_mac_add_del(bd_id=epg.bd,
-                                        mac=mactobinary(self.router_mac),
-                                        ip=epg.bvi_ip4_n,
+                                        mac=self.router_mac.encode(),
+                                        ip=epg.bvi_ip4.encode(),
                                         is_ipv6=0,
                                         is_add=1)
             self.vapi.bd_ip_mac_add_del(bd_id=epg.bd,
-                                        mac=mactobinary(self.router_mac),
-                                        ip=epg.bvi_ip6_n,
+                                        mac=self.router_mac.encode(),
+                                        ip=epg.bvi_ip6.encode(),
                                         is_ipv6=1,
                                         is_add=1)
 
@@ -593,7 +590,7 @@ class TestGBP(VppTestCase):
                     port_type=L2_PORT_TYPE.BVI)
 
                 # BVI L2 FIB entry
-                self.vapi.l2fib_add_del(self.router_mac,
+                self.vapi.l2fib_add_del(self.router_mac.address,
                                         epg.bd,
                                         epg.bvi.sw_if_index,
                                         is_add=1, bvi_mac=1)
@@ -655,8 +652,8 @@ class TestGBP(VppTestCase):
 
                 # add the BD ARP termination entry
                 self.vapi.bd_ip_mac_add_del(bd_id=ep.epg.bd,
-                                            mac=ep.bin_mac,
-                                            ip=ip.bytes,
+                                            mac=ep.vmac.encode(),
+                                            ip=ip.encode(),
                                             is_ipv6=ip.is_ip6,
                                             is_add=1)
 
@@ -703,8 +700,8 @@ class TestGBP(VppTestCase):
             # add the BD ARP termination entry for floating IP
             for fip in ep.fips:
                 self.vapi.bd_ip_mac_add_del(bd_id=epg_nat.bd,
-                                            mac=ep.bin_mac,
-                                            ip=fip.bytes,
+                                            mac=ep.vmac.encode(),
+                                            ip=fip.encode(),
                                             is_ipv6=fip.is_ip6,
                                             is_add=1)
 
@@ -734,7 +731,7 @@ class TestGBP(VppTestCase):
                    ARP(op="who-has",
                        hwdst="ff:ff:ff:ff:ff:ff",
                        hwsrc=self.pg0.remote_mac,
-                       pdst=epgs[0].bvi_ip4,
+                       pdst=epgs[0].bvi_ip4.address,
                        psrc="10.0.0.88"))
 
         self.send_and_expect(self.pg0, [pkt_arp], self.pg0)
@@ -747,7 +744,7 @@ class TestGBP(VppTestCase):
                    ARP(op="who-has",
                        hwdst="ff:ff:ff:ff:ff:ff",
                        hwsrc=self.pg0.remote_mac,
-                       pdst=epgs[0].bvi_ip4,
+                       pdst=epgs[0].bvi_ip4.address,
                        psrc=eps[0].ip4.address))
 
         self.send_and_expect(self.pg0, [pkt_arp], self.pg0)
@@ -756,7 +753,7 @@ class TestGBP(VppTestCase):
         d = inet_ntop(AF_INET6, nsma)
         pkt_nd = (Ether(dst=in6_getnsmac(nsma)) /
                   IPv6(dst=d, src=eps[0].ip6.address) /
-                  ICMPv6ND_NS(tgt=epgs[0].bvi_ip6) /
+                  ICMPv6ND_NS(tgt=epgs[0].bvi_ip6.address) /
                   ICMPv6NDOptSrcLLAddr(lladdr=self.pg0.remote_mac))
         self.send_and_expect(self.pg0, [pkt_nd], self.pg0)
 
@@ -784,13 +781,13 @@ class TestGBP(VppTestCase):
         # packets to non-local L3 destinations dropped
         #
         pkt_intra_epg_220_ip4 = (Ether(src=self.pg0.remote_mac,
-                                       dst=self.router_mac) /
+                                       dst=self.router_mac.address) /
                                  IP(src=eps[0].ip4.address,
                                     dst="10.0.0.99") /
                                  UDP(sport=1234, dport=1234) /
                                  Raw('\xa5' * 100))
         pkt_inter_epg_222_ip4 = (Ether(src=self.pg0.remote_mac,
-                                       dst=self.router_mac) /
+                                       dst=self.router_mac.address) /
                                  IP(src=eps[0].ip4.address,
                                     dst="10.0.1.99") /
                                  UDP(sport=1234, dport=1234) /
@@ -799,7 +796,7 @@ class TestGBP(VppTestCase):
         self.send_and_assert_no_replies(self.pg0, pkt_intra_epg_220_ip4 * 65)
 
         pkt_inter_epg_222_ip6 = (Ether(src=self.pg0.remote_mac,
-                                       dst=self.router_mac) /
+                                       dst=self.router_mac.address) /
                                  IPv6(src=eps[0].ip6.address,
                                       dst="2001:10::99") /
                                  UDP(sport=1234, dport=1234) /
@@ -914,7 +911,7 @@ class TestGBP(VppTestCase):
                                     UDP(sport=1234, dport=1234) /
                                     Raw('\xa5' * 100))
         pkt_inter_epg_220_to_222 = (Ether(src=self.pg0.remote_mac,
-                                          dst=self.router_mac) /
+                                          dst=self.router_mac.address) /
                                     IP(src=eps[0].ip4.address,
                                        dst=eps[3].ip4.address) /
                                     UDP(sport=1234, dport=1234) /
@@ -972,7 +969,7 @@ class TestGBP(VppTestCase):
         self.send_and_expect_routed(self.pg0,
                                     pkt_inter_epg_220_to_222 * 65,
                                     self.pg3,
-                                    self.router_mac)
+                                    self.router_mac.address)
 
         #
         # remove both contracts, traffic stops in both directions
@@ -1035,7 +1032,7 @@ class TestGBP(VppTestCase):
         # From an EP to an outside addess: IN2OUT
         #
         pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac,
-                                             dst=self.router_mac) /
+                                             dst=self.router_mac.address) /
                                        IP(src=eps[0].ip4.address,
                                           dst="1.1.1.1") /
                                        UDP(sport=1234, dport=1234) /
@@ -1062,7 +1059,7 @@ class TestGBP(VppTestCase):
                                     eps[0].fip4.address)
 
         pkt_inter_epg_220_to_global = (Ether(src=self.pg0.remote_mac,
-                                             dst=self.router_mac) /
+                                             dst=self.router_mac.address) /
                                        IPv6(src=eps[0].ip6.address,
                                             dst="6001::1") /
                                        UDP(sport=1234, dport=1234) /
@@ -1076,7 +1073,7 @@ class TestGBP(VppTestCase):
         #
         # From a global address to an EP: OUT2IN
         #
-        pkt_inter_epg_220_from_global = (Ether(src=self.router_mac,
+        pkt_inter_epg_220_from_global = (Ether(src=self.router_mac.address,
                                                dst=self.pg0.remote_mac) /
                                          IP(dst=eps[0].fip4.address,
                                             src="1.1.1.1") /
@@ -1094,7 +1091,7 @@ class TestGBP(VppTestCase):
                                       eps[0].itf,
                                       eps[0].ip4.address)
 
-        pkt_inter_epg_220_from_global = (Ether(src=self.router_mac,
+        pkt_inter_epg_220_from_global = (Ether(src=self.router_mac.address,
                                                dst=self.pg0.remote_mac) /
                                          IPv6(dst=eps[0].fip6.address,
                                               src="6001::1") /
@@ -1111,7 +1108,7 @@ class TestGBP(VppTestCase):
         #  IN2OUT2IN
         #
         pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac,
-                                          dst=self.router_mac) /
+                                          dst=self.router_mac.address) /
                                     IP(src=eps[0].ip4.address,
                                        dst=eps[1].fip4.address) /
                                     UDP(sport=1234, dport=1234) /
@@ -1124,7 +1121,7 @@ class TestGBP(VppTestCase):
                                            eps[1].ip4.address)
 
         pkt_intra_epg_220_global = (Ether(src=self.pg0.remote_mac,
-                                          dst=self.router_mac) /
+                                          dst=self.router_mac.address) /
                                     IPv6(src=eps[0].ip6.address,
                                          dst=eps[1].fip6.address) /
                                     UDP(sport=1234, dport=1234) /
@@ -1154,11 +1151,11 @@ class TestGBP(VppTestCase):
         for epg in epgs:
             # IP config on the BVI interfaces
             self.vapi.sw_interface_add_del_address(epg.bvi.sw_if_index,
-                                                   epg.bvi_ip4_n,
+                                                   epg.bvi_ip4.bytes,
                                                    32,
                                                    is_add=0)
             self.vapi.sw_interface_add_del_address(epg.bvi.sw_if_index,
-                                                   epg.bvi_ip6_n,
+                                                   epg.bvi_ip6.bytes,
                                                    128,
                                                    is_add=0,
                                                    is_ipv6=True)