summaryrefslogtreecommitdiffstats
path: root/src/plugins/ikev2/test/vpp_ikev2.py
diff options
context:
space:
mode:
authorFilip Tehlar <ftehlar@cisco.com>2020-04-26 18:05:05 +0000
committerFilip Tehlar <ftehlar@cisco.com>2020-06-18 05:02:04 +0000
commit12b517b3ffe3ca4b447263548cfa2bcac857c836 (patch)
treeebe985afc769d04157c5f1cf327af86d2489b3c3 /src/plugins/ikev2/test/vpp_ikev2.py
parent99151bde6ef4a75d5eaa8211a9ab921e8f270678 (diff)
tests: add ikev2 test framework with basic test case
Ticket: VPP-1905 Type: test Change-Id: Ie66fbd8e37eb5e69bd61b701ed3449366bee8c84 Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
Diffstat (limited to 'src/plugins/ikev2/test/vpp_ikev2.py')
-rw-r--r--src/plugins/ikev2/test/vpp_ikev2.py101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/plugins/ikev2/test/vpp_ikev2.py b/src/plugins/ikev2/test/vpp_ikev2.py
new file mode 100644
index 00000000000..67df1d53b5e
--- /dev/null
+++ b/src/plugins/ikev2/test/vpp_ikev2.py
@@ -0,0 +1,101 @@
+from vpp_object import VppObject
+from vpp_papi import VppEnum
+
+
+class AuthMethod:
+ v = {'rsa-sig': 1,
+ 'shared-key': 2}
+
+ @staticmethod
+ def value(key): return AuthMethod.v[key]
+
+
+class IDType:
+ v = {'ip4-addr': 1,
+ 'fqdn': 2}
+
+ @staticmethod
+ def value(key): return IDType.v[key]
+
+
+class Profile(VppObject):
+ """ IKEv2 profile """
+ def __init__(self, test, profile_name):
+ self.test = test
+ self.vapi = test.vapi
+ self.profile_name = profile_name
+
+ def add_auth(self, method, data, is_hex=False):
+ if isinstance(method, int):
+ m = method
+ elif isinstance(method, str):
+ m = AuthMethod.value(method)
+ else:
+ raise Exception('unsupported type {}'.format(method))
+ self.auth = {'auth_method': m,
+ 'data': data,
+ 'is_hex': is_hex}
+
+ def add_local_id(self, id_type, data):
+ if isinstance(id_type, str):
+ t = IDType.value(id_type)
+ self.local_id = {'id_type': t,
+ 'data': data,
+ 'is_local': True}
+
+ def add_remote_id(self, id_type, data):
+ if isinstance(id_type, str):
+ t = IDType.value(id_type)
+ self.remote_id = {'id_type': t,
+ 'data': data,
+ 'is_local': False}
+
+ def add_local_ts(self, start_addr, end_addr, start_port=0, end_port=0xffff,
+ proto=0):
+ self.local_ts = {'is_local': True,
+ 'proto': proto,
+ 'start_port': start_port,
+ 'end_port': end_port,
+ 'start_addr': start_addr,
+ 'end_addr': end_addr}
+
+ def add_remote_ts(self, start_addr, end_addr, start_port=0,
+ end_port=0xffff, proto=0):
+ self.remote_ts = {'is_local': False,
+ 'proto': proto,
+ 'start_port': start_port,
+ 'end_port': end_port,
+ 'start_addr': start_addr,
+ 'end_addr': end_addr}
+
+ def object_id(self):
+ return 'ikev2-profile-%s' % self.profile_name
+
+ def remove_vpp_config(self):
+ self.vapi.ikev2_profile_add_del(name=self.profile_name, is_add=False)
+
+ def add_vpp_config(self):
+ self.vapi.ikev2_profile_add_del(name=self.profile_name, is_add=True)
+ if hasattr(self, 'auth'):
+ self.vapi.ikev2_profile_set_auth(name=self.profile_name,
+ data_len=len(self.auth['data']),
+ **self.auth)
+ if hasattr(self, 'local_id'):
+ self.vapi.ikev2_profile_set_id(name=self.profile_name,
+ data_len=len(self.local_id
+ ['data']),
+ **self.local_id)
+ if hasattr(self, 'remote_id'):
+ self.vapi.ikev2_profile_set_id(name=self.profile_name,
+ data_len=len(self.remote_id
+ ['data']),
+ **self.remote_id)
+ if hasattr(self, 'local_ts'):
+ self.vapi.ikev2_profile_set_ts(name=self.profile_name,
+ **self.local_ts)
+ if hasattr(self, 'remote_ts'):
+ self.vapi.ikev2_profile_set_ts(name=self.profile_name,
+ **self.remote_ts)
+
+ def query_vpp_config(self):
+ raise NotImplementedError()