blob: 6e5ebc25fb446548399a9fc8badd274356dc0612 [file] [log] [blame]
Ole Troan9a475372019-03-05 16:58:24 +01001# NB NB NB NB NB NB NB NB NB NB NB
2#
3# NOTE: The API binary wrappers in this file are in the process of being
4# deprecated. DO NOT ADD NEW WRAPPERS HERE. Call the functions using
5# named arguments directly instead.
6#
7
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02009import time
Klement Sekerae4504c62016-12-08 10:16:41 +010010from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +020011
Ole Troanf159f582019-02-28 20:20:47 +010012from six import moves, iteritems
Paul Vinciguerra19542292019-03-17 17:34:46 -070013from vpp_papi import VPPApiClient, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080014from hook import Hook
Paul Vinciguerrab5f15bd2019-03-17 08:42:58 -070015from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
Klement Sekeraf62ae122016-10-11 11:47:09 +020016
Klement Sekera0e3c0de2016-09-29 14:43:44 +020017
Ole Troanf159f582019-02-28 20:20:47 +010018#
19# Dictionary keyed on message name to override default values for
20# named parameters
21#
Ole Troan9a475372019-03-05 16:58:24 +010022defaultmapping = {
Paul Vinciguerrac0e94412020-04-28 01:12:04 -040023
Ole Troan9a475372019-03-05 16:58:24 +010024 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
Ole Troan9a475372019-03-05 16:58:24 +010025 'bd_ip_mac_add_del': {'is_add': 1, },
Jakub Grajciar4682feb2019-09-02 13:28:52 +020026 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None,
27 'conf_key_id': None},
28 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None,
29 'is_delayed': False},
Ole Troan9a475372019-03-05 16:58:24 +010030 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
31 'is_add': 1, },
32 'bier_disp_table_add_del': {'is_add': 1, },
33 'bier_imp_add': {'is_add': 1, },
34 'bier_route_add_del': {'is_add': 1, },
35 'bier_table_add_del': {'is_add': 1, },
36 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
37 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070038 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010039 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
40 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
41 'decap_next_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010042 'input_acl_set_interface': {'ip4_table_index': 4294967295,
43 'ip6_table_index': 4294967295,
44 'l2_table_index': 4294967295, },
45 'ip6_add_del_address_using_prefix': {'is_add': 1, },
46 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
47 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
48 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010049 'classify_table_index': 4294967295, 'is_add': 1, },
50 'ip_mroute_add_del': {'is_add': 1, },
51 'ip_neighbor_add_del': {'is_add': 1, },
52 'ip_punt_police': {'is_add': 1, },
53 'ip_punt_redirect': {'is_add': 1, },
Neale Ranns097fa662018-05-01 05:17:55 -070054 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010055 'ipsec_interface_add_del_spd': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010056 'ipsec_spd_add_del': {'is_add': 1, },
57 'ipsec_spd_dump': {'sa_id': 4294967295, },
58 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
59 'remote_port_stop': 65535, 'priority': 100,
60 'is_outbound': 1,
61 'is_add': 1, },
62 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
63 'l2_emulation': {'enable': 1, },
64 'l2fib_add_del': {'is_add': 1, },
65 'lisp_add_del_adjacency': {'is_add': 1, },
66 'lisp_add_del_local_eid': {'is_add': 1, },
67 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
68 'lisp_add_del_locator_set': {'is_add': 1, },
69 'lisp_add_del_remote_mapping': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010070 'macip_acl_interface_add_del': {'is_add': 1, },
71 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010072 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
73 'mr_next_hop_weight': 1,
74 'mr_next_hop_via_label': 1048576,
75 'mr_is_add': 1,
76 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010077 'mpls_table_add_del': {'is_add': 1, },
78 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
79 'next_hop_weight': 1,
80 'next_hop_via_label': 1048576,
81 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010082 'output_acl_set_interface': {'ip4_table_index': 4294967295,
83 'ip6_table_index': 4294967295,
84 'l2_table_index': 4294967295, },
85 'pppoe_add_del_session': {'is_add': 1, },
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010086 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, },
Ole Troan9a475372019-03-05 16:58:24 +010087 'proxy_arp_add_del': {'is_add': 1, },
88 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010089 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
90 'proto': 1, },
91 'set_ipfix_exporter': {'collector_port': 4739, },
Ole Troan9a475372019-03-05 16:58:24 +010092 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
93 'svs_enable_disable': {'is_enable': 1, },
94 'svs_route_add_del': {'is_add': 1, },
95 'svs_table_add_del': {'is_add': 1, },
96 'sw_interface_add_del_address': {'is_add': 1, },
97 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
98 'pref_lifetime': 4294967295, },
99 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
100 'sw_interface_set_l2_bridge': {'enable': 1, },
101 'sw_interface_set_mpls_enable': {'enable': 1, },
102 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
103 'sw_interface_set_unnumbered': {'is_add': 1, },
104 'sw_interface_span_enable_disable': {'state': 1, },
105 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
106 'decap_next_index': 4294967295,
107 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100108 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
109 'protocol': 3, },
110 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100111 'want_igmp_events': {'enable': 1, },
112 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +0200113 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100114}
Ole Troanf159f582019-02-28 20:20:47 +0100115
Matus Fabianb4515b42018-11-19 04:25:32 -0800116
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400117def as_fn_signature(d):
118 return ", ".join(f"{k}={v}" for k, v in d.items())
119
120
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400121class CliFailedCommandError(Exception):
122 """ cli command failed."""
123
124
125class CliSyntaxError(Exception):
126 """ cli command had a syntax error."""
127
128
Klement Sekera73884482017-02-23 09:26:30 +0100129class UnexpectedApiReturnValueError(Exception):
130 """ exception raised when the API return value is unexpected """
131 pass
132
133
Klement Sekeraf62ae122016-10-11 11:47:09 +0200134class VppPapiProvider(object):
135 """VPP-api provider using vpp-papi
136
137 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200138 """
139
Klement Sekerae0545ef2017-01-25 08:00:40 +0100140 _zero, _negative = range(2)
141
Klement Sekera611864f2018-09-26 11:19:00 +0200142 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800143 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200144 self.name = name
145 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100146 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100147 self._expect_api_retval = self._zero
148 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100149
Paul Vinciguerra19542292019-03-17 17:34:46 -0700150 # install_dir is a class attribute. We need to set it before
151 # calling the constructor.
152 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800153
Ole Troan4ff09ae2019-04-15 11:27:22 +0200154 use_socket = False
155 try:
156 if os.environ['SOCKET'] == '1':
157 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400158 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200159 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700160
161 self.vpp = VPPApiClient(logger=test_class.logger,
162 read_timeout=read_timeout,
163 use_socket=use_socket,
164 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100165 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166
Klement Sekerae0545ef2017-01-25 08:00:40 +0100167 def __enter__(self):
168 return self
169
Klement Sekera7d6afb32018-11-08 11:52:04 +0100170 def assert_negative_api_retval(self):
171 """ Expect API failure - used with with, e.g.:
172 with self.vapi.assert_negative_api_retval():
173 self.vapi.<api call expected to fail>
174 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100175 self._expect_stack.append(self._expect_api_retval)
176 self._expect_api_retval = self._negative
177 return self
178
Klement Sekera7d6afb32018-11-08 11:52:04 +0100179 def assert_zero_api_retval(self):
180 """ Expect API success - used with with, e.g.:
181 with self.vapi.assert_negative_api_retval():
182 self.vapi.<api call expected to succeed>
183
184 note: this is useful only inside another with block
185 as success is the default expected value
186 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100187 self._expect_stack.append(self._expect_api_retval)
188 self._expect_api_retval = self._zero
189 return self
190
191 def __exit__(self, exc_type, exc_value, traceback):
192 self._expect_api_retval = self._expect_stack.pop()
193
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194 def register_hook(self, hook):
195 """Replace hook registration with new hook
196
197 :param hook:
198
199 """
200 self.hook = hook
201
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200202 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100203 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200204 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100205 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200206 return e
207
208 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100209 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100210 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100211 self.test_class.logger.debug("Expecting event '%s' within %ss",
212 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300213 else:
214 self.test_class.logger.debug("Expecting event within %ss",
215 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100216 if self._events:
217 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200218 limit = time.time() + timeout
219 while time.time() < limit:
220 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100221 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200222 if name and type(e).__name__ != name:
223 raise Exception(
224 "Unexpected event received: %s, expected: %s" %
225 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100226 self.test_class.logger.debug("Returning event %s:%s" %
227 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200228 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700229 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200230 raise Exception("Event did not occur within timeout")
231
232 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100233 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 # FIXME use the name instead of relying on type(e).__name__ ?
235 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100236 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200237 self._events.append(event)
238
Ole Troanf159f582019-02-28 20:20:47 +0100239 def factory(self, name, apifn):
240 def f(*a, **ka):
241 fields = apifn._func.msg.fields
242
243 # add positional and kw arguments
244 d = ka
245 for i, o in enumerate(fields[3:]):
246 try:
247 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200248 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100249 break
250
251 # Default override
252 if name in defaultmapping:
253 for k, v in iteritems(defaultmapping[name]):
254 if k in d:
255 continue
256 d[k] = v
257 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100258
Ole Troanf159f582019-02-28 20:20:47 +0100259 return f
260
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800261 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100262 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800263 method = super(VppPapiProvider, self).__getattribute__(name)
264 except AttributeError:
265 method = self.factory(name, getattr(self.papi, name))
266 # lazily load the method so we don't need to call factory
267 # again for this name.
268 setattr(self, name, method)
269 return method
Ole Troanf159f582019-02-28 20:20:47 +0100270
Klement Sekeraf62ae122016-10-11 11:47:09 +0200271 def connect(self):
272 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100273 self.vpp.connect(self.name, self.shm_prefix)
274 self.papi = self.vpp.api
275 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200276
277 def disconnect(self):
278 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100279 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200280
281 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100282 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200283 Call the appropriate hooks before and after the API call
284
285 :param api_fn: API function to call
286 :param api_args: tuple of API function arguments
287 :param expected_retval: Expected return value (Default value = 0)
288 :returns: reply from the API
289
290 """
291 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100292 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100293 if self._expect_api_retval == self._negative:
294 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400295 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100296 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400297 (api_fn.__name__, as_fn_signature(api_args),
298 reply.retval,
299 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100300 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100301 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100302 elif self._expect_api_retval == self._zero:
303 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400304 msg = "%s(%s) failed, expected %d return value instead " \
305 "of %d in %s" % (api_fn.__name__,
306 as_fn_signature(api_args),
307 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400308 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100309 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100310 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100311 else:
312 raise Exception("Internal error, unexpected value for "
313 "self._expect_api_retval %s" %
314 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200315 self.hook.after_api(api_fn.__name__, api_args)
316 return reply
317
Dave Barach5932ce12019-10-09 17:28:04 -0400318 def cli_return_response(self, cli):
319 """ Execute a CLI, calling the before/after hooks appropriately.
320 Return the reply without examining it
321
322 :param cli: CLI to execute
323 :returns: response object
324
325 """
326 self.hook.before_cli(cli)
327 cli += '\n'
328 r = self.papi.cli_inband(cmd=cli)
329 self.hook.after_cli(cli)
330 return r
331
Klement Sekeraf62ae122016-10-11 11:47:09 +0200332 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100333 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200334
335 :param cli: CLI to execute
336 :returns: CLI output
337
338 """
Dave Barach5932ce12019-10-09 17:28:04 -0400339 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400340 if r.retval == -156:
341 raise CliSyntaxError(r.reply)
342 if r.retval != 0:
343 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200344 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100345 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200346
Jan49c0fca2016-10-26 15:44:27 +0200347 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100348 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200349
350 :param cli: CLI to execute
351 :returns: CLI output
352 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200353 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200354
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100355 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
356 mrc=0, mrd=0):
357 return self.api(self.papi.ip6nd_send_router_solicitation,
358 {'irt': irt,
359 'mrt': mrt,
360 'mrc': mrc,
361 'mrd': mrd,
362 'sw_if_index': sw_if_index})
363
Juraj Slobodab3f90502018-10-04 15:15:16 +0200364 def want_interface_events(self, enable_disable=1):
365 return self.api(self.papi.want_interface_events,
366 {'enable_disable': enable_disable,
367 'pid': os.getpid(), })
368
Neale Rannsc819fc62018-02-16 02:44:05 -0800369 def sw_interface_set_mac_address(self, sw_if_index, mac):
370 return self.api(self.papi.sw_interface_set_mac_address,
371 {'sw_if_index': sw_if_index,
372 'mac_address': mac})
373
Ole Troane1ade682019-03-04 23:55:43 +0100374 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200375 """Create p2p ethernet subinterface
376
377 :param sw_if_index: main (parent) interface
378 :param remote_mac: client (remote) mac address
379
380 """
381 return self.api(
382 self.papi.p2p_ethernet_add,
383 {'parent_if_index': sw_if_index,
384 'remote_mac': remote_mac,
385 'subif_id': subif_id})
386
Ole Troane1ade682019-03-04 23:55:43 +0100387 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200388 """Delete p2p ethernet subinterface
389
390 :param sw_if_index: main (parent) interface
391 :param remote_mac: client (remote) mac address
392
393 """
394 return self.api(
395 self.papi.p2p_ethernet_del,
396 {'parent_if_index': sw_if_index,
397 'remote_mac': remote_mac})
398
Klement Sekeraf62ae122016-10-11 11:47:09 +0200399 def create_vlan_subif(self, sw_if_index, vlan):
400 """
401
402 :param vlan:
403 :param sw_if_index:
404
405 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100406 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200407 {'sw_if_index': sw_if_index,
408 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200409
Matej Klotton0178d522016-11-04 11:11:44 +0100410 def create_loopback(self, mac=''):
411 """
412
413 :param mac: (Optional)
414 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100415 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200416 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100417
Neale Ranns097fa662018-05-01 05:17:55 -0700418 def ip_route_dump(self, table_id, is_ip6=False):
419 return self.api(self.papi.ip_route_dump,
420 {'table': {
421 'table_id': table_id,
422 'is_ip6': is_ip6
423 }})
424
Matej Klotton0178d522016-11-04 11:11:44 +0100425 def ip_neighbor_add_del(self,
426 sw_if_index,
427 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700428 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100429 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700430 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100431 """ Add neighbor MAC to IPv4 or IPv6 address.
432
433 :param sw_if_index:
434 :param mac_address:
435 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100436 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700437 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100438 """
Matej Klotton0178d522016-11-04 11:11:44 +0100439 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100440 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700441 {
442 'is_add': is_add,
443 'neighbor': {
444 'sw_if_index': sw_if_index,
445 'flags': flags,
446 'mac_address': mac_address,
447 'ip_address': ip_address
448 }
449 }
Matej Klotton0178d522016-11-04 11:11:44 +0100450 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100451
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800452 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700453 low,
454 hi,
455 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800456 is_add=1):
457 """ Config Proxy Arp Range.
458
459 :param low_address: Start address in the rnage to Proxy for
460 :param hi_address: End address in the rnage to Proxy for
461 :param vrf_id: The VRF/table in which to proxy
462 """
463
464 return self.api(
465 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700466 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100467 {
468 'table_id': table_id,
469 'low': low,
470 'hi': hi,
471 },
472 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800473
474 def proxy_arp_intfc_enable_disable(self,
475 sw_if_index,
476 is_enable=1):
477 """ Enable/Disable an interface for proxy ARP requests
478
479 :param sw_if_index: Interface
480 :param enable_disable: Enable/Disable
481 """
482
483 return self.api(
484 self.papi.proxy_arp_intfc_enable_disable,
485 {'sw_if_index': sw_if_index,
Neale Rannscbe25aa2019-09-30 10:53:31 +0000486 'enable': is_enable
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800487 }
488 )
489
Neale Rannsd0df49f2018-08-08 01:06:40 -0700490 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700491 src_ip,
492 dst_ip,
493 src_port,
494 dst_port,
495 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800496 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800497 :param src_ip:
498 :param dst_ip:
499 :param src_port:
500 :param dst_port:
501 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800502 """
503
504 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700505 self.papi.udp_encap_add,
506 {
507 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700508 'src_ip': src_ip,
509 'dst_ip': dst_ip,
510 'src_port': src_port,
511 'dst_port': dst_port,
512 'table_id': table_id
513 }
514 })
515
Neale Ranns097fa662018-05-01 05:17:55 -0700516 def udp_encap_del(self, id):
517 return self.api(self.papi.udp_encap_del, {'id': id})
518
519 def udp_encap_dump(self):
520 return self.api(self.papi.udp_encap_dump, {})
521
522 def want_udp_encap_stats(self, enable=1):
523 return self.api(self.papi.want_udp_encap_stats,
524 {'enable': enable,
525 'pid': os.getpid()})
526
527 def mpls_route_dump(self, table_id):
528 return self.api(self.papi.mpls_route_dump,
529 {'table': {
530 'mt_table_id': table_id
531 }})
532
533 def mpls_table_dump(self):
534 return self.api(self.papi.mpls_table_dump, {})
535
Neale Ranns15002542017-09-10 04:39:11 -0700536 def mpls_table_add_del(
537 self,
538 table_id,
539 is_add=1):
540 """
541
542 :param table_id
543 :param is_add: (Default value = 1)
544
545 """
546
547 return self.api(
548 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700549 {'mt_table':
550 {
551 'mt_table_id': table_id,
552 },
Neale Ranns15002542017-09-10 04:39:11 -0700553 'mt_is_add': is_add})
554
Neale Ranns097fa662018-05-01 05:17:55 -0700555 def mpls_route_add_del(self,
556 table_id,
557 label,
558 eos,
559 eos_proto,
560 is_multicast,
561 paths,
562 is_add,
563 is_multipath):
564 """ MPLS Route add/del """
565 return self.api(
566 self.papi.mpls_route_add_del,
567 {'mr_route':
568 {
569 'mr_table_id': table_id,
570 'mr_label': label,
571 'mr_eos': eos,
572 'mr_eos_proto': eos_proto,
573 'mr_is_multicast': is_multicast,
574 'mr_n_paths': len(paths),
575 'mr_paths': paths,
576 },
577 'mr_is_add': is_add,
578 'mr_is_multipath': is_multipath})
579
Neale Rannsad422ed2016-11-02 14:20:04 +0000580 def mpls_ip_bind_unbind(
581 self,
582 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700583 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000584 table_id=0,
585 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000586 is_bind=1):
587 """
588 """
589 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100590 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200591 {'mb_mpls_table_id': table_id,
592 'mb_label': label,
593 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200594 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700595 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000596
597 def mpls_tunnel_add_del(
598 self,
599 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700600 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000601 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800602 l2_only=0,
603 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000604 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000605 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000606 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100607 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700608 {'mt_is_add': is_add,
609 'mt_tunnel':
610 {
611 'mt_sw_if_index': tun_sw_if_index,
612 'mt_l2_only': l2_only,
613 'mt_is_multicast': is_multicast,
614 'mt_n_paths': len(paths),
615 'mt_paths': paths,
616 }})
Matus Fabiande886752016-12-07 03:38:19 -0800617
Steve Shin7957d6e2016-12-19 09:24:50 -0800618 def input_acl_set_interface(
619 self,
620 is_add,
621 sw_if_index,
622 ip4_table_index=0xFFFFFFFF,
623 ip6_table_index=0xFFFFFFFF,
624 l2_table_index=0xFFFFFFFF):
625 """
626 :param is_add:
627 :param sw_if_index:
628 :param ip4_table_index: (Default value = 0xFFFFFFFF)
629 :param ip6_table_index: (Default value = 0xFFFFFFFF)
630 :param l2_table_index: (Default value = 0xFFFFFFFF)
631 """
632
633 return self.api(
634 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100635 {'sw_if_index': sw_if_index,
636 'ip4_table_index': ip4_table_index,
637 'ip6_table_index': ip6_table_index,
638 'l2_table_index': l2_table_index,
639 'is_add': is_add})
640
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100641 def output_acl_set_interface(
642 self,
643 is_add,
644 sw_if_index,
645 ip4_table_index=0xFFFFFFFF,
646 ip6_table_index=0xFFFFFFFF,
647 l2_table_index=0xFFFFFFFF):
648 """
649 :param is_add:
650 :param sw_if_index:
651 :param ip4_table_index: (Default value = 0xFFFFFFFF)
652 :param ip6_table_index: (Default value = 0xFFFFFFFF)
653 :param l2_table_index: (Default value = 0xFFFFFFFF)
654 """
655
656 return self.api(
657 self.papi.output_acl_set_interface,
658 {'sw_if_index': sw_if_index,
659 'ip4_table_index': ip4_table_index,
660 'ip6_table_index': ip6_table_index,
661 'l2_table_index': l2_table_index,
662 'is_add': is_add})
663
Klement Sekera77fabdb2017-01-02 07:46:14 +0100664 def set_ipfix_exporter(
665 self,
666 collector_address,
667 src_address,
668 path_mtu,
669 template_interval,
670 vrf_id=0,
671 collector_port=4739,
672 udp_checksum=0):
673 return self.api(
674 self.papi.set_ipfix_exporter,
675 {
676 'collector_address': collector_address,
677 'collector_port': collector_port,
678 'src_address': src_address,
679 'vrf_id': vrf_id,
680 'path_mtu': path_mtu,
681 'template_interval': template_interval,
682 'udp_checksum': udp_checksum,
683 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800684
Neale Ranns097fa662018-05-01 05:17:55 -0700685 def mfib_signal_dump(self):
686 return self.api(self.papi.mfib_signal_dump, {})
687
688 def ip_mroute_dump(self, table_id, is_ip6=False):
689 return self.api(self.papi.ip_mroute_dump,
690 {'table': {
691 'table_id': table_id,
692 'is_ip6': is_ip6
693 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000694
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800695 def vxlan_gpe_add_del_tunnel(
696 self,
697 src_addr,
698 dst_addr,
699 mcast_sw_if_index=0xFFFFFFFF,
700 is_add=1,
701 is_ipv6=0,
702 encap_vrf_id=0,
703 decap_vrf_id=0,
704 protocol=3,
705 vni=0):
706 """
707
708 :param local:
709 :param remote:
710 :param is_add: (Default value = 1)
711 :param is_ipv6: (Default value = 0)
712 :param encap_vrf_id: (Default value = 0)
713 :param decap_vrf_id: (Default value = 0)
714 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
715 :param protocol: (Default value = 3)
716 :param vni: (Default value = 0)
717
718 """
719 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
720 {'is_add': is_add,
721 'is_ipv6': is_ipv6,
722 'local': src_addr,
723 'remote': dst_addr,
724 'mcast_sw_if_index': mcast_sw_if_index,
725 'encap_vrf_id': encap_vrf_id,
726 'decap_vrf_id': decap_vrf_id,
727 'protocol': protocol,
728 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800729
Neale Ranns79a05f52018-09-11 07:39:43 -0700730 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
731 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000732 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200733
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800734 def pppoe_add_del_session(
735 self,
736 client_ip,
737 client_mac,
738 session_id=0,
739 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800740 decap_vrf_id=0):
741 """
742
743 :param is_add: (Default value = 1)
744 :param is_ipv6: (Default value = 0)
745 :param client_ip:
746 :param session_id: (Default value = 0)
747 :param client_mac:
748 :param decap_vrf_id: (Default value = 0)
749
750 """
751 return self.api(self.papi.pppoe_add_del_session,
752 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800753 'session_id': session_id,
754 'client_ip': client_ip,
755 'decap_vrf_id': decap_vrf_id,
756 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200757
Neale Ranns7c922dc2018-08-30 06:12:27 -0700758 def sr_mpls_policy_add(self, bsid, weight, type, segments):
759 return self.api(self.papi.sr_mpls_policy_add,
760 {'bsid': bsid,
761 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100762 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700763 'n_segments': len(segments),
764 'segments': segments})
765
766 def sr_mpls_policy_del(self, bsid):
767 return self.api(self.papi.sr_mpls_policy_del,
768 {'bsid': bsid})
769
Neale Rannsd91c1db2017-07-31 02:30:50 -0700770 def ip_punt_police(self,
771 policer_index,
772 is_ip6=0,
773 is_add=1):
774 return self.api(self.papi.ip_punt_police,
775 {'policer_index': policer_index,
776 'is_add': is_add,
777 'is_ip6': is_ip6})
778
779 def ip_punt_redirect(self,
780 rx_sw_if_index,
781 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +0100782 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -0700783 is_add=1):
784 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +0100785 {'punt': {'rx_sw_if_index': rx_sw_if_index,
786 'tx_sw_if_index': tx_sw_if_index,
787 'nh': address},
788 'is_add': is_add})
789
790 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
791 return self.api(self.papi.ip_punt_redirect_dump,
792 {'sw_if_index': sw_if_index,
793 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700794
795 def bier_table_add_del(self,
796 bti,
797 mpls_label,
798 is_add=1):
799 """ BIER Table add/del """
800 return self.api(
801 self.papi.bier_table_add_del,
802 {'bt_tbl_id': {"bt_set": bti.set_id,
803 "bt_sub_domain": bti.sub_domain_id,
804 "bt_hdr_len_id": bti.hdr_len_id},
805 'bt_label': mpls_label,
806 'bt_is_add': is_add})
807
808 def bier_table_dump(self):
809 return self.api(self.papi.bier_table_dump, {})
810
811 def bier_route_add_del(self,
812 bti,
813 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800814 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700815 is_add=1,
816 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700817 """ BIER Route add/del """
818 return self.api(
819 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700820 {
821 'br_route': {
822 'br_tbl_id': {"bt_set": bti.set_id,
823 "bt_sub_domain": bti.sub_domain_id,
824 "bt_hdr_len_id": bti.hdr_len_id},
825 'br_bp': bp,
826 'br_n_paths': len(paths),
827 'br_paths': paths,
828 },
829 'br_is_add': is_add,
830 'br_is_replace': is_replace
831 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700832
833 def bier_route_dump(self, bti):
834 return self.api(
835 self.papi.bier_route_dump,
836 {'br_tbl_id': {"bt_set": bti.set_id,
837 "bt_sub_domain": bti.sub_domain_id,
838 "bt_hdr_len_id": bti.hdr_len_id}})
839
840 def bier_imp_add(self,
841 bti,
842 src,
843 ibytes,
844 is_add=1):
845 """ BIER Imposition Add """
846 return self.api(
847 self.papi.bier_imp_add,
848 {'bi_tbl_id': {"bt_set": bti.set_id,
849 "bt_sub_domain": bti.sub_domain_id,
850 "bt_hdr_len_id": bti.hdr_len_id},
851 'bi_src': src,
852 'bi_n_bytes': len(ibytes),
853 'bi_bytes': ibytes})
854
855 def bier_imp_del(self, bi_index):
856 """ BIER Imposition del """
857 return self.api(
858 self.papi.bier_imp_del,
859 {'bi_index': bi_index})
860
861 def bier_imp_dump(self):
862 return self.api(self.papi.bier_imp_dump, {})
863
864 def bier_disp_table_add_del(self,
865 bdti,
866 is_add=1):
867 """ BIER Disposition Table add/del """
868 return self.api(
869 self.papi.bier_disp_table_add_del,
870 {'bdt_tbl_id': bdti,
871 'bdt_is_add': is_add})
872
873 def bier_disp_table_dump(self):
874 return self.api(self.papi.bier_disp_table_dump, {})
875
876 def bier_disp_entry_add_del(self,
877 bdti,
878 bp,
879 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800880 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700881 next_hop,
882 next_hop_tbl_id=0,
883 next_hop_rpf_id=~0,
884 next_hop_is_ip4=1,
885 is_add=1):
886 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800887 lstack = []
888 while (len(lstack) < 16):
889 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700890 return self.api(
891 self.papi.bier_disp_entry_add_del,
892 {'bde_tbl_id': bdti,
893 'bde_bp': bp,
894 'bde_payload_proto': payload_proto,
895 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400896 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700897 'rpf_id': next_hop_rpf_id,
898 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800899 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700900 'bde_is_add': is_add})
901
902 def bier_disp_entry_dump(self, bdti):
903 return self.api(
904 self.papi.bier_disp_entry_dump,
905 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200906
Florin Coras3ea6ce22017-12-11 09:09:05 -0800907 def session_enable_disable(self, is_enabled):
908 return self.api(
909 self.papi.session_enable_disable,
910 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800911
912 def ipsec_spd_add_del(self, spd_id, is_add=1):
913 """ SPD add/del - Wrapper to add or del ipsec SPD
914 Sample CLI : 'ipsec spd add 1'
915
916 :param spd_id - SPD ID to be created in the vpp . mandatory
917 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
918 optional
919 :returns: reply from the API
920 """
921 return self.api(
922 self.papi.ipsec_spd_add_del, {
923 'spd_id': spd_id, 'is_add': is_add})
924
Neale Ranns311124e2019-01-24 04:52:25 -0800925 def ipsec_spds_dump(self):
926 return self.api(self.papi.ipsec_spds_dump, {})
927
“mystarrocks”23f0c452017-12-11 07:11:51 -0800928 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
929 """ IPSEC interface SPD add/del - \
930 Wrapper to associate/disassociate SPD to interface in VPP
931 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
932
933 :param spd_id - SPD ID to associate with the interface . mandatory
934 :param sw_if_index - Interface Index which needs to ipsec \
935 association mandatory
936 :param is_add - add(1) or del(0) association with interface \
937 (Default 1 - add) . optional
938 :returns: reply from the API
939 """
940 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200941 self.papi.ipsec_interface_add_del_spd,
942 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800943
Neale Ranns311124e2019-01-24 04:52:25 -0800944 def ipsec_spd_interface_dump(self, spd_index=None):
945 return self.api(self.papi.ipsec_spd_interface_dump,
946 {'spd_index': spd_index if spd_index else 0,
947 'spd_index_valid': 1 if spd_index else 0})
948
Neale Ranns17dcec02019-01-09 21:22:20 -0800949 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800950 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200951 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800952 local_address_start,
953 local_address_stop,
954 remote_address_start,
955 remote_address_stop,
956 local_port_start=0,
957 local_port_stop=65535,
958 remote_port_start=0,
959 remote_port_stop=65535,
960 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800961 policy=0,
962 priority=100,
963 is_outbound=1,
964 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200965 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800966 is_ip_any=0):
967 """ IPSEC policy SPD add/del -
968 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +0200969 :param spd_id: SPD ID for the policy
970 :param local_address_start: local-ip-range start address
971 :param local_address_stop : local-ip-range stop address
972 :param remote_address_start: remote-ip-range start address
973 :param remote_address_stop : remote-ip-range stop address
974 :param local_port_start: (Default value = 0)
975 :param local_port_stop: (Default value = 65535)
976 :param remote_port_start: (Default value = 0)
977 :param remote_port_stop: (Default value = 65535)
978 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
979 :param sa_id: Security Association ID for mapping it to SPD
980 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
981 (Default value = 0)
982 :param priority: value for the spd action (Default value = 100)
983 :param is_outbound: flag for inbound(0) or outbound(1)
984 (Default value = 1)
985 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800986 """
987 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800988 self.papi.ipsec_spd_entry_add_del,
989 {
990 'is_add': is_add,
991 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100992 {
993 'spd_id': spd_id,
994 'sa_id': sa_id,
995 'local_address_start': local_address_start,
996 'local_address_stop': local_address_stop,
997 'remote_address_start': remote_address_start,
998 'remote_address_stop': remote_address_stop,
999 'local_port_start': local_port_start,
1000 'local_port_stop': local_port_stop,
1001 'remote_port_start': remote_port_start,
1002 'remote_port_stop': remote_port_stop,
1003 'protocol': protocol,
1004 'policy': policy,
1005 'priority': priority,
1006 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +01001007 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001008 })
Florin Corasb795bd02017-12-14 11:30:48 -08001009
Neale Ranns311124e2019-01-24 04:52:25 -08001010 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1011 return self.api(self.papi.ipsec_spd_dump,
1012 {'spd_id': spd_id,
1013 'sa_id': sa_id})
1014
Klement Sekera31da2e32018-06-24 22:49:55 +02001015 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1016 remote_spi, crypto_alg, local_crypto_key,
1017 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001018 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001019 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +00001020 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +02001021 return self.api(
1022 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001023 {
1024 'local_ip': local_ip,
1025 'remote_ip': remote_ip,
1026 'local_spi': local_spi,
1027 'remote_spi': remote_spi,
1028 'crypto_alg': crypto_alg,
1029 'local_crypto_key_len': len(local_crypto_key),
1030 'local_crypto_key': local_crypto_key,
1031 'remote_crypto_key_len': len(remote_crypto_key),
1032 'remote_crypto_key': remote_crypto_key,
1033 'integ_alg': integ_alg,
1034 'local_integ_key_len': len(local_integ_key),
1035 'local_integ_key': local_integ_key,
1036 'remote_integ_key_len': len(remote_integ_key),
1037 'remote_integ_key': remote_integ_key,
1038 'is_add': is_add,
1039 'esn': esn,
1040 'anti_replay': anti_replay,
1041 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001042 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001043 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001044 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001045 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001046
Klement Sekerab4d30532018-11-08 13:00:02 +01001047 def ipsec_select_backend(self, protocol, index):
1048 return self.api(self.papi.ipsec_select_backend,
1049 {'protocol': protocol, 'index': index})
1050
1051 def ipsec_backend_dump(self):
1052 return self.api(self.papi.ipsec_backend_dump, {})
1053
Ole Troane1ade682019-03-04 23:55:43 +01001054 def app_namespace_add_del(self,
1055 namespace_id,
1056 ip4_fib_id=0,
1057 ip6_fib_id=0,
1058 sw_if_index=0xFFFFFFFF,
1059 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001060 return self.api(
1061 self.papi.app_namespace_add_del,
1062 {'secret': secret,
1063 'sw_if_index': sw_if_index,
1064 'ip4_fib_id': ip4_fib_id,
1065 'ip6_fib_id': ip6_fib_id,
Jakub Grajciarb4e5e502020-01-31 09:35:29 +01001066 'namespace_id': namespace_id})
Klement Sekera75e7d132017-09-20 08:26:30 +02001067
Neale Ranns50f0ac02019-05-15 02:13:37 -07001068 def punt_socket_register(self, reg, pathname,
1069 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001070 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001071 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001072 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001073 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001074 'pathname': pathname})
1075
Neale Ranns50f0ac02019-05-15 02:13:37 -07001076 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001077 """ Unregister punt socket """
1078 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001079 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +02001080
Neale Ranns4ba67722019-02-28 11:11:39 +00001081 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001082 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001083 """ GBP endpoint Add """
1084 return self.api(self.papi.gbp_endpoint_add,
1085 {'endpoint': {
1086 'sw_if_index': sw_if_index,
1087 'ips': ips,
1088 'n_ips': len(ips),
1089 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001090 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001091 'flags': flags,
1092 'tun': {
1093 'src': tun_src,
1094 'dst': tun_dst,
1095 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001096
1097 def gbp_endpoint_del(self, handle):
1098 """ GBP endpoint Del """
1099 return self.api(self.papi.gbp_endpoint_del,
1100 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001101
1102 def gbp_endpoint_dump(self):
1103 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001104 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001105
Neale Ranns4ba67722019-02-28 11:11:39 +00001106 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001107 rd, uplink_sw_if_index,
1108 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001109 """ GBP endpoint group Add """
1110 return self.api(self.papi.gbp_endpoint_group_add,
1111 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001112 {
1113 'uplink_sw_if_index': uplink_sw_if_index,
1114 'bd_id': bd,
1115 'rd_id': rd,
1116 'vnid': vnid,
1117 'sclass': sclass,
1118 'retention': retention
1119 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001120
Neale Ranns4ba67722019-02-28 11:11:39 +00001121 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001122 """ GBP endpoint group Del """
1123 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00001124 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07001125
Neale Ranns160c9232019-06-19 06:25:56 -07001126 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001127 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08001128 uu_fwd_sw_if_index,
1129 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001130 """ GBP bridge-domain Add """
1131 return self.api(self.papi.gbp_bridge_domain_add,
1132 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01001133 {
1134 'flags': flags,
1135 'bvi_sw_if_index': bvi_sw_if_index,
1136 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
1137 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07001138 'bd_id': bd_id,
1139 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01001140 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001141
1142 def gbp_bridge_domain_del(self, bd_id):
1143 """ GBP bridge-domain Del """
1144 return self.api(self.papi.gbp_bridge_domain_del,
1145 {'bd_id': bd_id})
1146
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001147 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07001148 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001149 ip4_table_id,
1150 ip6_table_id,
1151 ip4_uu_sw_if_index,
1152 ip6_uu_sw_if_index):
1153 """ GBP route-domain Add """
1154 return self.api(self.papi.gbp_route_domain_add,
1155 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01001156 {
Neale Ranns160c9232019-06-19 06:25:56 -07001157 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01001158 'ip4_table_id': ip4_table_id,
1159 'ip6_table_id': ip6_table_id,
1160 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
1161 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
1162 'rd_id': rd_id
1163 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001164
1165 def gbp_route_domain_del(self, rd_id):
1166 """ GBP route-domain Del """
1167 return self.api(self.papi.gbp_route_domain_del,
1168 {'rd_id': rd_id})
1169
Neale Ranns4ba67722019-02-28 11:11:39 +00001170 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07001171 """ GBP recirc Add/Del """
1172 return self.api(self.papi.gbp_recirc_add_del,
1173 {'is_add': is_add,
1174 'recirc': {
1175 'is_ext': is_ext,
1176 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001177 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07001178
1179 def gbp_recirc_dump(self):
1180 """ GBP recirc Dump """
1181 return self.api(self.papi.gbp_recirc_dump, {})
1182
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001183 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08001184 """ GBP recirc Add/Del """
1185 return self.api(self.papi.gbp_ext_itf_add_del,
1186 {'is_add': is_add,
1187 'ext_itf': {
1188 'sw_if_index': sw_if_index,
1189 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001190 'rd_id': rd_id,
1191 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08001192
1193 def gbp_ext_itf_dump(self):
1194 """ GBP recirc Dump """
1195 return self.api(self.papi.gbp_ext_itf_dump, {})
1196
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001197 def gbp_subnet_add_del(self, is_add, rd_id,
1198 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07001199 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00001200 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07001201 """ GBP Subnet Add/Del """
1202 return self.api(self.papi.gbp_subnet_add_del,
1203 {'is_add': is_add,
1204 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001205 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07001206 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001207 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07001208 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001209 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07001210
1211 def gbp_subnet_dump(self):
1212 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001213 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001214
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001215 def gbp_contract_dump(self):
1216 """ GBP contract Dump """
1217 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001218
Neale Ranns8da9fc62019-03-04 14:08:11 -08001219 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001220 """ GBP VXLAN tunnel add """
1221 return self.api(self.papi.gbp_vxlan_tunnel_add,
1222 {
1223 'tunnel': {
1224 'vni': vni,
1225 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001226 'bd_rd_id': bd_rd_id,
1227 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001228 }
1229 })
1230
1231 def gbp_vxlan_tunnel_del(self, vni):
1232 """ GBP VXLAN tunnel del """
1233 return self.api(self.papi.gbp_vxlan_tunnel_del,
1234 {
1235 'vni': vni,
1236 })
1237
1238 def gbp_vxlan_tunnel_dump(self):
1239 """ GBP VXLAN tunnel add/del """
1240 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1241
Neale Ranns947ea622018-06-07 23:48:20 -07001242 def igmp_enable_disable(self, sw_if_index, enable, host):
1243 """ Enable/disable IGMP on a given interface """
1244 return self.api(self.papi.igmp_enable_disable,
1245 {'enable': enable,
1246 'mode': host,
1247 'sw_if_index': sw_if_index})
1248
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001249 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1250 """ Add/del IGMP proxy device """
1251 return self.api(self.papi.igmp_proxy_device_add_del,
1252 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1253 'add': add})
1254
1255 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1256 """ Add/del interface to/from IGMP proxy device """
1257 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1258 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1259 'add': add})
1260
Neale Ranns947ea622018-06-07 23:48:20 -07001261 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001262 """ Listen for new (S,G) on specified interface
1263
1264 :param enable: add/del
1265 :param sw_if_index: interface sw index
1266 :param saddr: source ip4 addr
1267 :param gaddr: group ip4 addr
1268 """
1269 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001270 {
1271 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001272 {
1273 'filter': filter,
1274 'sw_if_index': sw_if_index,
1275 'n_srcs': len(saddrs),
1276 'saddrs': saddrs,
1277 'gaddr': gaddr
1278 }
Neale Ranns947ea622018-06-07 23:48:20 -07001279 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001280
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001281 def igmp_clear_interface(self, sw_if_index):
1282 """ Remove all (S,G)s from specified interface
1283 doesn't send IGMP report!
1284 """
1285 return self.api(
1286 self.papi.igmp_clear_interface, {
1287 'sw_if_index': sw_if_index})
1288
1289 def want_igmp_events(self, enable=1):
1290 return self.api(self.papi.want_igmp_events, {'enable': enable,
1291 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08001292
1293 def bond_create(
1294 self,
1295 mode,
1296 lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001297 numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08001298 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001299 mac_address='',
1300 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08001301 """
1302 :param mode: mode
1303 :param lb: load balance
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001304 :param numa_only: tx on local numa node for lacp mode
Steven9cd2d7a2017-12-20 12:43:01 -08001305 :param use_custom_mac: use custom mac
1306 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001307 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08001308 """
1309 return self.api(
1310 self.papi.bond_create,
1311 {'mode': mode,
1312 'lb': lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001313 'numa_only': numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08001314 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001315 'mac_address': mac_address,
1316 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08001317 })
1318
Neale Ranns17ff3c12018-07-04 10:24:24 -07001319 def pipe_delete(self, parent_sw_if_index):
1320 return self.api(self.papi.pipe_delete,
1321 {'parent_sw_if_index': parent_sw_if_index})
1322
Neale Rannsd1e68ab2018-10-01 01:42:13 -07001323 def svs_table_add_del(self, af, table_id, is_add=1):
1324 return self.api(self.papi.svs_table_add_del,
1325 {
1326 'table_id': table_id,
1327 'is_add': is_add,
1328 'af': af,
1329 })
1330
1331 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
1332 return self.api(self.papi.svs_route_add_del,
1333 {
1334 'table_id': table_id,
1335 'source_table_id': src_table_id,
1336 'prefix': prefix,
1337 'is_add': is_add,
1338 })
1339
1340 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
1341 return self.api(self.papi.svs_enable_disable,
1342 {
1343 'af': af,
1344 'table_id': table_id,
1345 'sw_if_index': sw_if_index,
1346 'is_enable': is_enable,
1347 })
Mohsin Kazmi29467b52019-10-08 19:42:38 +02001348
1349 def feature_gso_enable_disable(self, sw_if_index, enable_disable=1):
1350 return self.api(self.papi.feature_gso_enable_disable,
1351 {
1352 'sw_if_index': sw_if_index,
1353 'enable_disable': enable_disable,
1354 })