doxygen formatting fix: prevent stray examples appearing in the docs
[vpp.git] / test / vpp_papi_provider.py
index 4812cb6..087424c 100644 (file)
@@ -4,22 +4,10 @@ import time
 from collections import deque
 
 from six import moves
-from vpp_mac import mactobinary
+from vpp_papi import VPP, mac_pton
 from hook import Hook
 from vpp_l2 import L2_PORT_TYPE
 
-# Sphinx creates auto-generated documentation by importing the python source
-# files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
-# the vpp_papi_provider.py file to be importable without having to build
-# the whole vpp api if the user only wishes to generate the test documentation.
-
-try:
-    from vpp_papi import VPP
-except ImportError:
-    if not os.getenv("NO_VPP_PAPI") == 1:
-        raise
-    pass
-
 # from vnet/vnet/mpls/mpls_types.h
 MPLS_IETF_MAX_LABEL = 0xfffff
 MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
@@ -75,14 +63,14 @@ class VppPapiProvider(object):
         self.test_class = test_class
         self._expect_api_retval = self._zero
         self._expect_stack = []
-        jsonfiles = []
 
         install_dir = os.getenv('VPP_INSTALL_PATH')
-        for root, dirnames, filenames in os.walk(install_dir):
-            for filename in fnmatch.filter(filenames, '*.api.json'):
-                jsonfiles.append(os.path.join(root, filename))
 
-        self.vpp = VPP(jsonfiles, logger=test_class.logger,
+        # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
+        if 'VPP_API_DIR' not in os.environ:
+            os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
+
+        self.vpp = VPP(logger=test_class.logger,
                        read_timeout=read_timeout)
         self._events = deque()
 
@@ -223,9 +211,6 @@ class VppPapiProvider(object):
         """
         return cli + "\n" + str(self.cli(cli))
 
-    def _convert_mac(self, mac):
-        return mactobinary(mac)
-
     def show_version(self):
         """ """
         return self.api(self.papi.show_version, {})
@@ -643,7 +628,7 @@ class VppPapiProvider(object):
             interface. (Default value = 0)
         """
         return self.api(self.papi.l2fib_add_del,
-                        {'mac': self._convert_mac(mac),
+                        {'mac': mac,
                          'bd_id': bd_id,
                          'sw_if_index': sw_if_index,
                          'is_add': is_add,
@@ -1671,6 +1656,39 @@ class VppPapiProvider(object):
              'local_num': local_num,
              'locals': locals})
 
+    def nat44_lb_static_mapping_add_del_local(
+           self,
+           external_addr,
+           external_port,
+           local_addr,
+           local_port,
+           protocol,
+           probability,
+           vrf_id=0,
+           is_add=1):
+        """Add/delete NAT44 load-balancing static mapping rule backend
+
+        :param external_addr: external IPv4 address of the servic
+        :param external_port: external L4 port number of the service
+        :param local_addr: IPv4 address of the internal node
+        :param local_port: L4 port number of the internal node
+        :param protocol: IP protocol number
+        :param probability: probability of the internal node
+        :param vrf_id: VRF id of the internal node
+        :param is_add: 1 if add, 0 if delete
+        """
+        return self.api(
+            self.papi.nat44_lb_static_mapping_add_del_local,
+            {'is_add': is_add,
+             'external_addr': external_addr,
+             'external_port': external_port,
+             'local': {
+                 'addr': local_addr,
+                 'port': local_port,
+                 'probability': probability,
+                 'vrf_id': vrf_id},
+             'protocol': protocol})
+
     def nat44_lb_static_mapping_dump(self):
         """Dump NAT44 load balancing static mappings
 
@@ -2702,9 +2720,8 @@ class VppPapiProvider(object):
                        ea_bits_len=0,
                        psid_offset=0,
                        psid_length=0,
-                       is_translation=0,
-                       is_rfc6052=0,
                        mtu=1280):
+
         return self.api(
             self.papi.map_add_domain,
             {
@@ -2714,11 +2731,25 @@ class VppPapiProvider(object):
                 'ea_bits_len': ea_bits_len,
                 'psid_offset': psid_offset,
                 'psid_length': psid_length,
-                'is_translation': is_translation,
-                'is_rfc6052': is_rfc6052,
                 'mtu': mtu
             })
 
+    def map_if_enable_disable(self, is_enable, sw_if_index, is_translation):
+        return self.api(
+            self.papi.map_if_enable_disable,
+            {
+                'is_enable': is_enable,
+                'sw_if_index': sw_if_index,
+                'is_translation': is_translation,
+            })
+
+    def map_param_set_tcp(self, tcp_mss):
+        return self.api(
+            self.papi.map_param_set_tcp,
+            {
+                'tcp_mss': tcp_mss,
+            })
+
     def gtpu_add_del_tunnel(
             self,
             src_addr,
@@ -3536,7 +3567,6 @@ class VppPapiProvider(object):
         return self.api(self.papi.gbp_endpoint_add,
                         {'endpoint': {
                             'sw_if_index': sw_if_index,
-                            'flags': 0,
                             'ips': ips,
                             'n_ips': len(ips),
                             'mac': mac,
@@ -3670,7 +3700,8 @@ class VppPapiProvider(object):
         return self.api(self.papi.gbp_subnet_dump,
                         {'_no_type_conversion': True})
 
-    def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, rules):
+    def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index,
+                             rules, allowed_ethertypes):
         """ GBP contract Add/Del """
         return self.api(self.papi.gbp_contract_add_del,
                         {'is_add': is_add,
@@ -3679,7 +3710,9 @@ class VppPapiProvider(object):
                              'src_epg': src_epg,
                              'dst_epg': dst_epg,
                              'n_rules': len(rules),
-                             'rules': rules}})
+                             'rules': rules,
+                             'n_ether_types': len(allowed_ethertypes),
+                             'allowed_ethertypes': allowed_ethertypes}})
 
     def gbp_contract_dump(self):
         """ GBP contract Dump """
@@ -3839,19 +3872,22 @@ class VppPapiProvider(object):
             mode,
             lb,
             use_custom_mac,
-            mac_address=''):
+            mac_address='',
+            interface_id=0xFFFFFFFF):
         """
         :param mode: mode
         :param lb: load balance
         :param use_custom_mac: use custom mac
         :param mac_address: mac address
+        :param interface_id: custom interface ID
         """
         return self.api(
             self.papi.bond_create,
             {'mode': mode,
              'lb': lb,
              'use_custom_mac': use_custom_mac,
-             'mac_address': mac_address
+             'mac_address': mac_address,
+             'id': interface_id
              })
 
     def bond_delete(