API: Python and Unix domain socket improvement
[vpp.git] / test / vpp_papi_provider.py
index ed2eee1..8b637f0 100644 (file)
@@ -12,22 +12,9 @@ from collections import deque
 from six import moves, iteritems
 from vpp_papi import VPP, mac_pton
 from hook import Hook
-from vpp_l2 import L2_PORT_TYPE
 from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
 
 
-class L2_VTR_OP:
-    L2_DISABLED = 0
-    L2_PUSH_1 = 1
-    L2_PUSH_2 = 2
-    L2_POP_1 = 3
-    L2_POP_2 = 4
-    L2_TRANSLATE_1_1 = 5
-    L2_TRANSLATE_1_2 = 6
-    L2_TRANSLATE_2_1 = 7
-    L2_TRANSLATE_2_2 = 8
-
-
 class QOS_SOURCE:
     EXT = 0
     VLAN = 1
@@ -81,7 +68,7 @@ defaultmapping = {
     'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
     'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
                               'decap_next_index': 4294967295, },
-    'gre_add_del_tunnel': {'instance': 4294967295, 'is_add': 1, },
+    'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
     'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
                             'decap_next_index': 4294967295, },
     'input_acl_set_interface': {'ip4_table_index': 4294967295,
@@ -183,6 +170,7 @@ defaultmapping = {
     'svs_route_add_del': {'is_add': 1, },
     'svs_table_add_del': {'is_add': 1, },
     'sw_interface_add_del_address': {'is_add': 1, },
+    'sw_interface_dump': {'sw_if_index': 4294967295, },
     'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
                                      'pref_lifetime': 4294967295, },
     'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
@@ -238,8 +226,16 @@ class VppPapiProvider(object):
         if 'VPP_API_DIR' not in os.environ:
             os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
 
+        use_socket = False
+        try:
+            if os.environ['SOCKET'] == '1':
+                use_socket = True
+        except:
+            pass
         self.vpp = VPP(logger=test_class.logger,
-                       read_timeout=read_timeout)
+                       read_timeout=read_timeout,
+                       use_socket=use_socket,
+                       server_address=test_class.api_sock)
         self._events = deque()
 
     def __enter__(self):
@@ -616,15 +612,14 @@ class VppPapiProvider(object):
              }
         )
 
-    def gre_add_del_tunnel(self,
-                           src_address,
-                           dst_address,
+    def gre_tunnel_add_del(self,
+                           src,
+                           dst,
                            outer_fib_id=0,
                            tunnel_type=0,
                            instance=0xFFFFFFFF,
                            session_id=0,
-                           is_add=1,
-                           is_ip6=0):
+                           is_add=1):
         """ Add a GRE tunnel
 
         :param src_address:
@@ -638,15 +633,17 @@ class VppPapiProvider(object):
         """
 
         return self.api(
-            self.papi.gre_add_del_tunnel,
+            self.papi.gre_tunnel_add_del,
             {'is_add': is_add,
-             'is_ipv6': is_ip6,
-             'tunnel_type': tunnel_type,
-             'instance': instance,
-             'src_address': src_address,
-             'dst_address': dst_address,
-             'outer_fib_id': outer_fib_id,
-             'session_id': session_id}
+             'tunnel':
+             {
+                 'type': tunnel_type,
+                 'instance': instance,
+                 'src': src,
+                 'dst': dst,
+                 'outer_fib_id': outer_fib_id,
+                 'session_id': session_id}
+             }
         )
 
     def udp_encap_add(self,
@@ -2370,6 +2367,7 @@ class VppPapiProvider(object):
                                 tunnel_src_address='',
                                 tunnel_dst_address='',
                                 flags=0,
+                                salt=0,
                                 is_add=1):
         """ IPSEC SA add/del
         :param sad_id: security association ID
@@ -2408,6 +2406,7 @@ class VppPapiProvider(object):
                             'data': crypto_key,
                         },
                         'flags': flags,
+                        'salt': salt,
                     }
             })
 
@@ -2485,7 +2484,7 @@ class VppPapiProvider(object):
     def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
                                 remote_spi, crypto_alg, local_crypto_key,
                                 remote_crypto_key, integ_alg, local_integ_key,
-                                remote_integ_key, is_add=1, esn=0,
+                                remote_integ_key, is_add=1, esn=0, salt=0,
                                 anti_replay=1, renumber=0, show_instance=0):
         return self.api(
             self.papi.ipsec_tunnel_if_add_del,
@@ -2508,9 +2507,23 @@ class VppPapiProvider(object):
                 'esn': esn,
                 'anti_replay': anti_replay,
                 'renumber': renumber,
-                'show_instance': show_instance
+                'show_instance': show_instance,
+                'salt': salt
             })
 
+    def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
+                                 sa_out, sa_in, is_add=1):
+        return self.api(self.papi.ipsec_gre_tunnel_add_del,
+                        {
+                            'is_add': is_add,
+                            'tunnel': {
+                                'src': local_ip,
+                                'dst': remote_ip,
+                                'local_sa_id': sa_out,
+                                'remote_sa_id': sa_in
+                            }
+                        })
+
     def ipsec_select_backend(self, protocol, index):
         return self.api(self.papi.ipsec_select_backend,
                         {'protocol': protocol, 'index': index})