1 from vpp_object import VppObject
2 from vpp_papi import VppEnum
10 def value(key): return AuthMethod.v[key]
18 def value(key): return IDType.v[key]
21 class Profile(VppObject):
23 def __init__(self, test, profile_name):
26 self.profile_name = profile_name
28 def add_auth(self, method, data, is_hex=False):
29 if isinstance(method, int):
31 elif isinstance(method, str):
32 m = AuthMethod.value(method)
34 raise Exception('unsupported type {}'.format(method))
35 self.auth = {'auth_method': m,
39 def add_local_id(self, id_type, data):
40 if isinstance(id_type, str):
41 t = IDType.value(id_type)
42 self.local_id = {'id_type': t,
46 def add_remote_id(self, id_type, data):
47 if isinstance(id_type, str):
48 t = IDType.value(id_type)
49 self.remote_id = {'id_type': t,
53 def add_local_ts(self, start_addr, end_addr, start_port=0, end_port=0xffff,
55 self.local_ts = {'is_local': True,
57 'start_port': start_port,
59 'start_addr': start_addr,
62 def add_remote_ts(self, start_addr, end_addr, start_port=0,
63 end_port=0xffff, proto=0):
64 self.remote_ts = {'is_local': False,
66 'start_port': start_port,
68 'start_addr': start_addr,
72 return 'ikev2-profile-%s' % self.profile_name
74 def remove_vpp_config(self):
75 self.vapi.ikev2_profile_add_del(name=self.profile_name, is_add=False)
77 def add_vpp_config(self):
78 self.vapi.ikev2_profile_add_del(name=self.profile_name, is_add=True)
79 if hasattr(self, 'auth'):
80 self.vapi.ikev2_profile_set_auth(name=self.profile_name,
81 data_len=len(self.auth['data']),
83 if hasattr(self, 'local_id'):
84 self.vapi.ikev2_profile_set_id(name=self.profile_name,
85 data_len=len(self.local_id
88 if hasattr(self, 'remote_id'):
89 self.vapi.ikev2_profile_set_id(name=self.profile_name,
90 data_len=len(self.remote_id
93 if hasattr(self, 'local_ts'):
94 self.vapi.ikev2_profile_set_ts(name=self.profile_name,
96 if hasattr(self, 'remote_ts'):
97 self.vapi.ikev2_profile_set_ts(name=self.profile_name,
100 def query_vpp_config(self):
101 raise NotImplementedError()