Add test suites for crypto sw scheduler engine
[csit.git] / resources / libraries / python / IPsecUtil.py
index 3c3997a..2bc10d3 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2020 Cisco and/or its affiliates.
+# Copyright (c) 2021 Cisco and/or its affiliates.
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at:
@@ -320,6 +320,30 @@ class IPsecUtil:
         with PapiSocketExecutor(node) as papi_exec:
             papi_exec.add(cmd, **args).get_reply(err_msg)
 
+    @staticmethod
+    def vpp_ipsec_crypto_sw_scheduler_set_worker(
+            node, worker_index, crypto_enable=False):
+        """Enable or disable crypto on specific vpp worker threads.
+
+        :param node: VPP node to enable or disable crypto for worker threads.
+        :param worker_index: VPP worker thread index.
+        :param crypto_enable: Disable or enable crypto work.
+        :type node: dict
+        :type worker_index: int
+        :type crypto_enable: bool
+        :raises RuntimeError: If failed to enable or disable crypto for worker
+            thread or if no API reply received.
+        """
+        cmd = u"crypto_sw_scheduler_set_worker"
+        err_msg = f"Failed to disable/enable crypto for worker thread " \
+            f"on host {node[u'host']}"
+        args = dict(
+            worker_index=worker_index,
+            crypto_enable=crypto_enable
+        )
+        with PapiSocketExecutor(node) as papi_exec:
+            papi_exec.add(cmd, **args).get_reply(err_msg)
+
     @staticmethod
     def vpp_ipsec_add_sad_entry(
             node, sad_id, spi, crypto_alg, crypto_key, integ_alg=None,
@@ -372,7 +396,7 @@ class IPsecUtil:
             src_addr = u""
             dst_addr = u""
 
-        cmd = u"ipsec_sad_entry_add_del"
+        cmd = u"ipsec_sad_entry_add_del_v2"
         err_msg = f"Failed to add Security Association Database entry " \
             f"on host {node[u'host']}"
         sad_entry = dict(
@@ -385,6 +409,10 @@ class IPsecUtil:
             flags=flags,
             tunnel_src=str(src_addr),
             tunnel_dst=str(dst_addr),
+            tunnel_flags=int(
+                TunnelEncpaDecapFlags.TUNNEL_API_ENCAP_DECAP_FLAG_NONE
+            ),
+            dscp=int(IpDscp.IP_API_DSCP_CS0),
             protocol=int(IPsecProto.IPSEC_API_PROTO_ESP),
             udp_src_port=4500,  # default value in api
             udp_dst_port=4500  # default value in api
@@ -482,7 +510,7 @@ class IPsecUtil:
                     IPsecSadFlags.IPSEC_API_SAD_FLAG_IS_TUNNEL_V6
                 )
 
-        cmd = u"ipsec_sad_entry_add_del"
+        cmd = u"ipsec_sad_entry_add_del_v2"
         err_msg = f"Failed to add Security Association Database entry " \
             f"on host {node[u'host']}"
 
@@ -496,6 +524,10 @@ class IPsecUtil:
             flags=flags,
             tunnel_src=str(src_addr),
             tunnel_dst=str(dst_addr),
+            tunnel_flags=int(
+                TunnelEncpaDecapFlags.TUNNEL_API_ENCAP_DECAP_FLAG_NONE
+            ),
+            dscp=int(IpDscp.IP_API_DSCP_CS0),
             protocol=int(IPsecProto.IPSEC_API_PROTO_ESP),
             udp_src_port=4500,  # default value in api
             udp_dst_port=4500  # default value in api
@@ -1045,9 +1077,11 @@ class IPsecUtil:
         """
         with PapiSocketExecutor(nodes[u"DUT1"]) as papi_exec:
             # Create loopback interface on DUT1, set it to up state
-            cmd = u"create_loopback"
+            cmd = u"create_loopback_instance"
             args = dict(
-                mac_address=0
+                mac_address=0,
+                is_specified=False,
+                user_instance=0,
             )
             err_msg = f"Failed to create loopback interface " \
                 f"on host {nodes[u'DUT1'][u'host']}"