blob: 309fc3f5c58ddf5954deeaa71010bac1a0ad0a21 [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 = {
23 'map_add_domain': {'mtu': 1280},
24 'syslog_set_sender': {'collector_port': 514,
25 'max_msg_size': 480},
26 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
27 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
28 'app_namespace_add_del': {'sw_if_index': 4294967295, },
29 'bd_ip_mac_add_del': {'is_add': 1, },
Jakub Grajciar4682feb2019-09-02 13:28:52 +020030 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None,
31 'conf_key_id': None},
32 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None,
33 'is_delayed': False},
Ole Troan9a475372019-03-05 16:58:24 +010034 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
35 'is_add': 1, },
36 'bier_disp_table_add_del': {'is_add': 1, },
37 'bier_imp_add': {'is_add': 1, },
38 'bier_route_add_del': {'is_add': 1, },
39 'bier_table_add_del': {'is_add': 1, },
Jakub Grajciar3d1ef872019-08-26 12:55:15 +020040 'bond_create': {'mac_address': '', 'id': 0xFFFFFFFF},
Ole Troan9a475372019-03-05 16:58:24 +010041 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
42 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070043 'bvi_create': {'user_instance': 4294967295, },
44 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010045 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
46 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
47 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000048 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010049 'input_acl_set_interface': {'ip4_table_index': 4294967295,
50 'ip6_table_index': 4294967295,
51 'l2_table_index': 4294967295, },
52 'ip6_add_del_address_using_prefix': {'is_add': 1, },
53 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
54 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
55 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010056 'classify_table_index': 4294967295, 'is_add': 1, },
57 'ip_mroute_add_del': {'is_add': 1, },
58 'ip_neighbor_add_del': {'is_add': 1, },
59 'ip_punt_police': {'is_add': 1, },
60 'ip_punt_redirect': {'is_add': 1, },
Neale Ranns097fa662018-05-01 05:17:55 -070061 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010062 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010063 'ipsec_interface_add_del_spd': {'is_add': 1, },
64 'ipsec_sad_entry_add_del': {'is_add': 1, },
65 'ipsec_spd_add_del': {'is_add': 1, },
66 'ipsec_spd_dump': {'sa_id': 4294967295, },
67 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
68 'remote_port_stop': 65535, 'priority': 100,
69 'is_outbound': 1,
70 'is_add': 1, },
71 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
72 'l2_emulation': {'enable': 1, },
73 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -070074 'lb_conf': {'sticky_buckets_per_core': 4294967295,
75 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +010076 'lisp_add_del_adjacency': {'is_add': 1, },
77 'lisp_add_del_local_eid': {'is_add': 1, },
78 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
79 'lisp_add_del_locator_set': {'is_add': 1, },
80 'lisp_add_del_remote_mapping': {'is_add': 1, },
81 'macip_acl_add_replace': {'acl_index': 4294967295, },
82 'macip_acl_dump': {'acl_index': 4294967295, },
83 'macip_acl_interface_add_del': {'is_add': 1, },
84 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010085 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
86 'mr_next_hop_weight': 1,
87 'mr_next_hop_via_label': 1048576,
88 'mr_is_add': 1,
89 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010090 'mpls_table_add_del': {'is_add': 1, },
91 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
92 'next_hop_weight': 1,
93 'next_hop_via_label': 1048576,
94 'is_add': 1, },
95 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010096 'output_acl_set_interface': {'ip4_table_index': 4294967295,
97 'ip6_table_index': 4294967295,
98 'l2_table_index': 4294967295, },
99 'pppoe_add_del_session': {'is_add': 1, },
100 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
101 'proxy_arp_add_del': {'is_add': 1, },
102 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100103 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
104 'proto': 1, },
105 'set_ipfix_exporter': {'collector_port': 4739, },
106 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
107 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
108 'svs_enable_disable': {'is_enable': 1, },
109 'svs_route_add_del': {'is_add': 1, },
110 'svs_table_add_del': {'is_add': 1, },
111 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700112 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100113 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
114 'pref_lifetime': 4294967295, },
115 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
116 'sw_interface_set_l2_bridge': {'enable': 1, },
117 'sw_interface_set_mpls_enable': {'enable': 1, },
118 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
119 'sw_interface_set_unnumbered': {'is_add': 1, },
120 'sw_interface_span_enable_disable': {'state': 1, },
121 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
122 'decap_next_index': 4294967295,
123 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100124 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
125 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
126 'protocol': 3, },
127 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100128 'want_igmp_events': {'enable': 1, },
129 'want_interface_events': {'enable_disable': 1, },
130 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
131 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
132 'want_ip6_ra_events': {'enable_disable': 1, },
133 'want_l2_macs_events': {'enable_disable': 1, },
134}
Ole Troanf159f582019-02-28 20:20:47 +0100135
Matus Fabianb4515b42018-11-19 04:25:32 -0800136
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400137class CliFailedCommandError(Exception):
138 """ cli command failed."""
139
140
141class CliSyntaxError(Exception):
142 """ cli command had a syntax error."""
143
144
Klement Sekera73884482017-02-23 09:26:30 +0100145class UnexpectedApiReturnValueError(Exception):
146 """ exception raised when the API return value is unexpected """
147 pass
148
149
Klement Sekeraf62ae122016-10-11 11:47:09 +0200150class VppPapiProvider(object):
151 """VPP-api provider using vpp-papi
152
153 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200154 """
155
Klement Sekerae0545ef2017-01-25 08:00:40 +0100156 _zero, _negative = range(2)
157
Klement Sekera611864f2018-09-26 11:19:00 +0200158 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800159 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200160 self.name = name
161 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100162 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100163 self._expect_api_retval = self._zero
164 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100165
Paul Vinciguerra19542292019-03-17 17:34:46 -0700166 # install_dir is a class attribute. We need to set it before
167 # calling the constructor.
168 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800169
Ole Troan4ff09ae2019-04-15 11:27:22 +0200170 use_socket = False
171 try:
172 if os.environ['SOCKET'] == '1':
173 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400174 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200175 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700176
177 self.vpp = VPPApiClient(logger=test_class.logger,
178 read_timeout=read_timeout,
179 use_socket=use_socket,
180 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100181 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200182
Klement Sekerae0545ef2017-01-25 08:00:40 +0100183 def __enter__(self):
184 return self
185
Klement Sekera7d6afb32018-11-08 11:52:04 +0100186 def assert_negative_api_retval(self):
187 """ Expect API failure - used with with, e.g.:
188 with self.vapi.assert_negative_api_retval():
189 self.vapi.<api call expected to fail>
190 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100191 self._expect_stack.append(self._expect_api_retval)
192 self._expect_api_retval = self._negative
193 return self
194
Klement Sekera7d6afb32018-11-08 11:52:04 +0100195 def assert_zero_api_retval(self):
196 """ Expect API success - used with with, e.g.:
197 with self.vapi.assert_negative_api_retval():
198 self.vapi.<api call expected to succeed>
199
200 note: this is useful only inside another with block
201 as success is the default expected value
202 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100203 self._expect_stack.append(self._expect_api_retval)
204 self._expect_api_retval = self._zero
205 return self
206
207 def __exit__(self, exc_type, exc_value, traceback):
208 self._expect_api_retval = self._expect_stack.pop()
209
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210 def register_hook(self, hook):
211 """Replace hook registration with new hook
212
213 :param hook:
214
215 """
216 self.hook = hook
217
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200218 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100219 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100221 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200222 return e
223
224 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100225 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100226 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100227 self.test_class.logger.debug("Expecting event '%s' within %ss",
228 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300229 else:
230 self.test_class.logger.debug("Expecting event within %ss",
231 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100232 if self._events:
233 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 limit = time.time() + timeout
235 while time.time() < limit:
236 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100237 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200238 if name and type(e).__name__ != name:
239 raise Exception(
240 "Unexpected event received: %s, expected: %s" %
241 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100242 self.test_class.logger.debug("Returning event %s:%s" %
243 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200244 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700245 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200246 raise Exception("Event did not occur within timeout")
247
248 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100249 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200250 # FIXME use the name instead of relying on type(e).__name__ ?
251 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100252 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200253 self._events.append(event)
254
Ole Troanf159f582019-02-28 20:20:47 +0100255 def factory(self, name, apifn):
256 def f(*a, **ka):
257 fields = apifn._func.msg.fields
258
259 # add positional and kw arguments
260 d = ka
261 for i, o in enumerate(fields[3:]):
262 try:
263 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200264 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100265 break
266
267 # Default override
268 if name in defaultmapping:
269 for k, v in iteritems(defaultmapping[name]):
270 if k in d:
271 continue
272 d[k] = v
273 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100274
Ole Troanf159f582019-02-28 20:20:47 +0100275 return f
276
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800277 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100278 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800279 method = super(VppPapiProvider, self).__getattribute__(name)
280 except AttributeError:
281 method = self.factory(name, getattr(self.papi, name))
282 # lazily load the method so we don't need to call factory
283 # again for this name.
284 setattr(self, name, method)
285 return method
Ole Troanf159f582019-02-28 20:20:47 +0100286
Klement Sekeraf62ae122016-10-11 11:47:09 +0200287 def connect(self):
288 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100289 self.vpp.connect(self.name, self.shm_prefix)
290 self.papi = self.vpp.api
291 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200292
293 def disconnect(self):
294 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100295 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200296
297 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100298 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200299 Call the appropriate hooks before and after the API call
300
301 :param api_fn: API function to call
302 :param api_args: tuple of API function arguments
303 :param expected_retval: Expected return value (Default value = 0)
304 :returns: reply from the API
305
306 """
307 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100308 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100309 if self._expect_api_retval == self._negative:
310 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100311 msg = "API call passed unexpectedly: expected negative " \
312 "return value instead of %d in %s" % \
313 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100314 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100315 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100316 elif self._expect_api_retval == self._zero:
317 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100318 msg = "API call failed, expected %d return value instead " \
319 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400320 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100321 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100322 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100323 else:
324 raise Exception("Internal error, unexpected value for "
325 "self._expect_api_retval %s" %
326 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200327 self.hook.after_api(api_fn.__name__, api_args)
328 return reply
329
Dave Barach5932ce12019-10-09 17:28:04 -0400330 def cli_return_response(self, cli):
331 """ Execute a CLI, calling the before/after hooks appropriately.
332 Return the reply without examining it
333
334 :param cli: CLI to execute
335 :returns: response object
336
337 """
338 self.hook.before_cli(cli)
339 cli += '\n'
340 r = self.papi.cli_inband(cmd=cli)
341 self.hook.after_cli(cli)
342 return r
343
Klement Sekeraf62ae122016-10-11 11:47:09 +0200344 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100345 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200346
347 :param cli: CLI to execute
348 :returns: CLI output
349
350 """
Dave Barach5932ce12019-10-09 17:28:04 -0400351 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400352 if r.retval == -156:
353 raise CliSyntaxError(r.reply)
354 if r.retval != 0:
355 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200356 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100357 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200358
Jan49c0fca2016-10-26 15:44:27 +0200359 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100360 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200361
362 :param cli: CLI to execute
363 :returns: CLI output
364 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200365 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200366
Neale Ranns37029302018-08-10 05:30:06 -0700367 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300368 return self.api(self.papi.want_ip4_arp_events,
369 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700370 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300371 'pid': os.getpid(), })
372
Neale Ranns37029302018-08-10 05:30:06 -0700373 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300374 return self.api(self.papi.want_ip6_nd_events,
375 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700376 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300377 'pid': os.getpid(), })
378
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100379 def want_ip6_ra_events(self, enable_disable=1):
380 return self.api(self.papi.want_ip6_ra_events,
381 {'enable_disable': enable_disable,
382 'pid': os.getpid(), })
383
384 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
385 mrc=0, mrd=0):
386 return self.api(self.papi.ip6nd_send_router_solicitation,
387 {'irt': irt,
388 'mrt': mrt,
389 'mrc': mrc,
390 'mrd': mrd,
391 'sw_if_index': sw_if_index})
392
Juraj Slobodab3f90502018-10-04 15:15:16 +0200393 def want_interface_events(self, enable_disable=1):
394 return self.api(self.papi.want_interface_events,
395 {'enable_disable': enable_disable,
396 'pid': os.getpid(), })
397
Ole Troane1ade682019-03-04 23:55:43 +0100398 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
399 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300400 return self.api(self.papi.want_l2_macs_events,
401 {'enable_disable': enable_disable,
402 'scan_delay': scan_delay,
403 'max_macs_in_event': max_macs_in_event,
404 'learn_limit': learn_limit,
405 'pid': os.getpid(), })
406
Neale Rannsc819fc62018-02-16 02:44:05 -0800407 def sw_interface_set_mac_address(self, sw_if_index, mac):
408 return self.api(self.papi.sw_interface_set_mac_address,
409 {'sw_if_index': sw_if_index,
410 'mac_address': mac})
411
Ole Troane1ade682019-03-04 23:55:43 +0100412 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200413 """Create p2p ethernet subinterface
414
415 :param sw_if_index: main (parent) interface
416 :param remote_mac: client (remote) mac address
417
418 """
419 return self.api(
420 self.papi.p2p_ethernet_add,
421 {'parent_if_index': sw_if_index,
422 'remote_mac': remote_mac,
423 'subif_id': subif_id})
424
Ole Troane1ade682019-03-04 23:55:43 +0100425 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200426 """Delete p2p ethernet subinterface
427
428 :param sw_if_index: main (parent) interface
429 :param remote_mac: client (remote) mac address
430
431 """
432 return self.api(
433 self.papi.p2p_ethernet_del,
434 {'parent_if_index': sw_if_index,
435 'remote_mac': remote_mac})
436
Klement Sekeraf62ae122016-10-11 11:47:09 +0200437 def create_vlan_subif(self, sw_if_index, vlan):
438 """
439
440 :param vlan:
441 :param sw_if_index:
442
443 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100444 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200445 {'sw_if_index': sw_if_index,
446 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200447
Matej Klotton0178d522016-11-04 11:11:44 +0100448 def create_loopback(self, mac=''):
449 """
450
451 :param mac: (Optional)
452 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100453 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200454 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100455
Neale Ranns097fa662018-05-01 05:17:55 -0700456 def ip_route_dump(self, table_id, is_ip6=False):
457 return self.api(self.papi.ip_route_dump,
458 {'table': {
459 'table_id': table_id,
460 'is_ip6': is_ip6
461 }})
462
Matej Klotton0178d522016-11-04 11:11:44 +0100463 def ip_neighbor_add_del(self,
464 sw_if_index,
465 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700466 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100467 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700468 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100469 """ Add neighbor MAC to IPv4 or IPv6 address.
470
471 :param sw_if_index:
472 :param mac_address:
473 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100474 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700475 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100476 """
Matej Klotton0178d522016-11-04 11:11:44 +0100477 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100478 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700479 {
480 'is_add': is_add,
481 'neighbor': {
482 'sw_if_index': sw_if_index,
483 'flags': flags,
484 'mac_address': mac_address,
485 'ip_address': ip_address
486 }
487 }
Matej Klotton0178d522016-11-04 11:11:44 +0100488 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100489
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800490 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700491 low,
492 hi,
493 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800494 is_add=1):
495 """ Config Proxy Arp Range.
496
497 :param low_address: Start address in the rnage to Proxy for
498 :param hi_address: End address in the rnage to Proxy for
499 :param vrf_id: The VRF/table in which to proxy
500 """
501
502 return self.api(
503 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700504 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100505 {
506 'table_id': table_id,
507 'low': low,
508 'hi': hi,
509 },
510 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800511
512 def proxy_arp_intfc_enable_disable(self,
513 sw_if_index,
514 is_enable=1):
515 """ Enable/Disable an interface for proxy ARP requests
516
517 :param sw_if_index: Interface
518 :param enable_disable: Enable/Disable
519 """
520
521 return self.api(
522 self.papi.proxy_arp_intfc_enable_disable,
523 {'sw_if_index': sw_if_index,
524 'enable_disable': is_enable
525 }
526 )
527
Neale Ranns5a8844b2019-04-16 07:15:35 +0000528 def gre_tunnel_add_del(self,
529 src,
530 dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000531 outer_table_id=0,
532 type=0,
533 mode=0,
John Loa43ccae2018-02-13 17:15:23 -0500534 instance=0xFFFFFFFF,
535 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000536 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000537 """ Add a GRE tunnel
538
539 :param src_address:
540 :param dst_address:
541 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500542 :param tunnel_type: (Default value = 0)
543 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700544 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000545 :param is_add: (Default value = 1)
546 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000547 """
548
549 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000550 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200551 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000552 'tunnel':
553 {
Neale Ranns5f8f6172019-04-18 10:23:56 +0000554 'type': type,
555 'mode': mode,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000556 'instance': instance,
557 'src': src,
558 'dst': dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000559 'outer_table_id': outer_table_id,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000560 'session_id': session_id}
561 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000562 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000563
Neale Rannsd0df49f2018-08-08 01:06:40 -0700564 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700565 src_ip,
566 dst_ip,
567 src_port,
568 dst_port,
569 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800570 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800571 :param src_ip:
572 :param dst_ip:
573 :param src_port:
574 :param dst_port:
575 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800576 """
577
578 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700579 self.papi.udp_encap_add,
580 {
581 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700582 'src_ip': src_ip,
583 'dst_ip': dst_ip,
584 'src_port': src_port,
585 'dst_port': dst_port,
586 'table_id': table_id
587 }
588 })
589
Neale Ranns097fa662018-05-01 05:17:55 -0700590 def udp_encap_del(self, id):
591 return self.api(self.papi.udp_encap_del, {'id': id})
592
593 def udp_encap_dump(self):
594 return self.api(self.papi.udp_encap_dump, {})
595
596 def want_udp_encap_stats(self, enable=1):
597 return self.api(self.papi.want_udp_encap_stats,
598 {'enable': enable,
599 'pid': os.getpid()})
600
601 def mpls_route_dump(self, table_id):
602 return self.api(self.papi.mpls_route_dump,
603 {'table': {
604 'mt_table_id': table_id
605 }})
606
607 def mpls_table_dump(self):
608 return self.api(self.papi.mpls_table_dump, {})
609
Neale Ranns15002542017-09-10 04:39:11 -0700610 def mpls_table_add_del(
611 self,
612 table_id,
613 is_add=1):
614 """
615
616 :param table_id
617 :param is_add: (Default value = 1)
618
619 """
620
621 return self.api(
622 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700623 {'mt_table':
624 {
625 'mt_table_id': table_id,
626 },
Neale Ranns15002542017-09-10 04:39:11 -0700627 'mt_is_add': is_add})
628
Neale Ranns097fa662018-05-01 05:17:55 -0700629 def mpls_route_add_del(self,
630 table_id,
631 label,
632 eos,
633 eos_proto,
634 is_multicast,
635 paths,
636 is_add,
637 is_multipath):
638 """ MPLS Route add/del """
639 return self.api(
640 self.papi.mpls_route_add_del,
641 {'mr_route':
642 {
643 'mr_table_id': table_id,
644 'mr_label': label,
645 'mr_eos': eos,
646 'mr_eos_proto': eos_proto,
647 'mr_is_multicast': is_multicast,
648 'mr_n_paths': len(paths),
649 'mr_paths': paths,
650 },
651 'mr_is_add': is_add,
652 'mr_is_multipath': is_multipath})
653
Neale Rannsad422ed2016-11-02 14:20:04 +0000654 def mpls_ip_bind_unbind(
655 self,
656 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700657 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000658 table_id=0,
659 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000660 is_bind=1):
661 """
662 """
663 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100664 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200665 {'mb_mpls_table_id': table_id,
666 'mb_label': label,
667 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200668 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700669 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000670
671 def mpls_tunnel_add_del(
672 self,
673 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700674 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000675 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800676 l2_only=0,
677 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000678 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000679 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000680 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100681 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700682 {'mt_is_add': is_add,
683 'mt_tunnel':
684 {
685 'mt_sw_if_index': tun_sw_if_index,
686 'mt_l2_only': l2_only,
687 'mt_is_multicast': is_multicast,
688 'mt_n_paths': len(paths),
689 'mt_paths': paths,
690 }})
Matus Fabiande886752016-12-07 03:38:19 -0800691
Steve Shin7957d6e2016-12-19 09:24:50 -0800692 def input_acl_set_interface(
693 self,
694 is_add,
695 sw_if_index,
696 ip4_table_index=0xFFFFFFFF,
697 ip6_table_index=0xFFFFFFFF,
698 l2_table_index=0xFFFFFFFF):
699 """
700 :param is_add:
701 :param sw_if_index:
702 :param ip4_table_index: (Default value = 0xFFFFFFFF)
703 :param ip6_table_index: (Default value = 0xFFFFFFFF)
704 :param l2_table_index: (Default value = 0xFFFFFFFF)
705 """
706
707 return self.api(
708 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100709 {'sw_if_index': sw_if_index,
710 'ip4_table_index': ip4_table_index,
711 'ip6_table_index': ip6_table_index,
712 'l2_table_index': l2_table_index,
713 'is_add': is_add})
714
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100715 def output_acl_set_interface(
716 self,
717 is_add,
718 sw_if_index,
719 ip4_table_index=0xFFFFFFFF,
720 ip6_table_index=0xFFFFFFFF,
721 l2_table_index=0xFFFFFFFF):
722 """
723 :param is_add:
724 :param sw_if_index:
725 :param ip4_table_index: (Default value = 0xFFFFFFFF)
726 :param ip6_table_index: (Default value = 0xFFFFFFFF)
727 :param l2_table_index: (Default value = 0xFFFFFFFF)
728 """
729
730 return self.api(
731 self.papi.output_acl_set_interface,
732 {'sw_if_index': sw_if_index,
733 'ip4_table_index': ip4_table_index,
734 'ip6_table_index': ip6_table_index,
735 'l2_table_index': l2_table_index,
736 'is_add': is_add})
737
Klement Sekera77fabdb2017-01-02 07:46:14 +0100738 def set_ipfix_exporter(
739 self,
740 collector_address,
741 src_address,
742 path_mtu,
743 template_interval,
744 vrf_id=0,
745 collector_port=4739,
746 udp_checksum=0):
747 return self.api(
748 self.papi.set_ipfix_exporter,
749 {
750 'collector_address': collector_address,
751 'collector_port': collector_port,
752 'src_address': src_address,
753 'vrf_id': vrf_id,
754 'path_mtu': path_mtu,
755 'template_interval': template_interval,
756 'udp_checksum': udp_checksum,
757 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800758
Neale Ranns32e1c012016-11-22 17:07:28 +0000759 def ip_mroute_add_del(self,
Neale Ranns097fa662018-05-01 05:17:55 -0700760 table_id,
761 prefix,
Neale Ranns32e1c012016-11-22 17:07:28 +0000762 e_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700763 rpf_id,
764 paths,
Neale Ranns32e1c012016-11-22 17:07:28 +0000765 is_add=1,
Neale Ranns097fa662018-05-01 05:17:55 -0700766 is_multipath=1):
Neale Ranns32e1c012016-11-22 17:07:28 +0000767 """
Neale Rannsd792d9c2017-10-21 10:53:20 -0700768 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +0000769 """
770 return self.api(
771 self.papi.ip_mroute_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700772 {
773 'is_add': is_add,
774 'is_multipath': is_multipath,
775 'route': {
776 'table_id': table_id,
777 'entry_flags': e_flags,
778 'rpf_id': rpf_id,
779 'prefix': prefix,
780 'n_paths': len(paths),
781 'paths': paths,
782 }
783 })
784
785 def mfib_signal_dump(self):
786 return self.api(self.papi.mfib_signal_dump, {})
787
788 def ip_mroute_dump(self, table_id, is_ip6=False):
789 return self.api(self.papi.ip_mroute_dump,
790 {'table': {
791 'table_id': table_id,
792 'is_ip6': is_ip6
793 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000794
Filip Tehlar770e89e2017-01-31 10:39:16 +0100795 def lisp_enable_disable(self, is_enabled):
796 return self.api(
797 self.papi.lisp_enable_disable,
798 {
799 'is_en': is_enabled,
800 })
801
Ole Troane1ade682019-03-04 23:55:43 +0100802 def lisp_add_del_locator_set(self,
803 ls_name,
804 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100805 return self.api(
806 self.papi.lisp_add_del_locator_set,
807 {
808 'is_add': is_add,
809 'locator_set_name': ls_name
810 })
811
Ole Troane1ade682019-03-04 23:55:43 +0100812 def lisp_add_del_locator(self,
813 ls_name,
814 sw_if_index,
815 priority=1,
816 weight=1,
817 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100818 return self.api(
819 self.papi.lisp_add_del_locator,
820 {
821 'is_add': is_add,
822 'locator_set_name': ls_name,
823 'sw_if_index': sw_if_index,
824 'priority': priority,
825 'weight': weight
826 })
827
828 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
829 return self.api(
830 self.papi.lisp_locator_dump,
831 {
832 'is_index_set': is_index_set,
833 'ls_name': ls_name,
834 'ls_index': ls_index,
835 })
836
Ole Troane1ade682019-03-04 23:55:43 +0100837 def lisp_add_del_local_eid(self,
838 ls_name,
839 eid_type,
840 eid,
841 prefix_len,
842 vni=0,
843 key_id=0,
844 key="",
845 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100846 return self.api(
847 self.papi.lisp_add_del_local_eid,
848 {
849 'locator_set_name': ls_name,
850 'is_add': is_add,
851 'eid_type': eid_type,
852 'eid': eid,
853 'prefix_len': prefix_len,
854 'vni': vni,
855 'key_id': key_id,
856 'key': key
857 })
858
859 def lisp_eid_table_dump(self,
860 eid_set=0,
861 prefix_length=0,
862 vni=0,
863 eid_type=0,
864 eid=None,
865 filter_opt=0):
866 return self.api(
867 self.papi.lisp_eid_table_dump,
868 {
869 'eid_set': eid_set,
870 'prefix_length': prefix_length,
871 'vni': vni,
872 'eid_type': eid_type,
873 'eid': eid,
874 'filter': filter_opt,
875 })
876
Ole Troane1ade682019-03-04 23:55:43 +0100877 def lisp_add_del_remote_mapping(self,
878 eid_type,
879 eid,
880 eid_prefix_len=0,
881 vni=0,
882 rlocs=[],
883 rlocs_num=0,
884 is_src_dst=0,
885 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100886 return self.api(
887 self.papi.lisp_add_del_remote_mapping,
888 {
889 'is_add': is_add,
890 'eid_type': eid_type,
891 'eid': eid,
892 'eid_len': eid_prefix_len,
893 'rloc_num': rlocs_num,
894 'rlocs': rlocs,
895 'vni': vni,
896 'is_src_dst': is_src_dst,
897 })
898
Ole Troane1ade682019-03-04 23:55:43 +0100899 def lisp_add_del_adjacency(self,
900 leid,
901 reid,
902 leid_len,
903 reid_len,
904 eid_type,
905 is_add=1,
906 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100907 return self.api(
908 self.papi.lisp_add_del_adjacency,
909 {
910 'is_add': is_add,
911 'vni': vni,
912 'eid_type': eid_type,
913 'leid': leid,
914 'reid': reid,
915 'leid_len': leid_len,
916 'reid_len': reid_len,
917 })
918
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800919 def vxlan_gpe_add_del_tunnel(
920 self,
921 src_addr,
922 dst_addr,
923 mcast_sw_if_index=0xFFFFFFFF,
924 is_add=1,
925 is_ipv6=0,
926 encap_vrf_id=0,
927 decap_vrf_id=0,
928 protocol=3,
929 vni=0):
930 """
931
932 :param local:
933 :param remote:
934 :param is_add: (Default value = 1)
935 :param is_ipv6: (Default value = 0)
936 :param encap_vrf_id: (Default value = 0)
937 :param decap_vrf_id: (Default value = 0)
938 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
939 :param protocol: (Default value = 3)
940 :param vni: (Default value = 0)
941
942 """
943 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
944 {'is_add': is_add,
945 'is_ipv6': is_ipv6,
946 'local': src_addr,
947 'remote': dst_addr,
948 'mcast_sw_if_index': mcast_sw_if_index,
949 'encap_vrf_id': encap_vrf_id,
950 'decap_vrf_id': decap_vrf_id,
951 'protocol': protocol,
952 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800953
Neale Ranns79a05f52018-09-11 07:39:43 -0700954 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
955 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000956 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200957
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800958 def pppoe_add_del_session(
959 self,
960 client_ip,
961 client_mac,
962 session_id=0,
963 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800964 decap_vrf_id=0):
965 """
966
967 :param is_add: (Default value = 1)
968 :param is_ipv6: (Default value = 0)
969 :param client_ip:
970 :param session_id: (Default value = 0)
971 :param client_mac:
972 :param decap_vrf_id: (Default value = 0)
973
974 """
975 return self.api(self.papi.pppoe_add_del_session,
976 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800977 'session_id': session_id,
978 'client_ip': client_ip,
979 'decap_vrf_id': decap_vrf_id,
980 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200981
Neale Ranns7c922dc2018-08-30 06:12:27 -0700982 def sr_mpls_policy_add(self, bsid, weight, type, segments):
983 return self.api(self.papi.sr_mpls_policy_add,
984 {'bsid': bsid,
985 'weight': weight,
986 'type': type,
987 'n_segments': len(segments),
988 'segments': segments})
989
990 def sr_mpls_policy_del(self, bsid):
991 return self.api(self.papi.sr_mpls_policy_del,
992 {'bsid': bsid})
993
Kris Michielsen91074432017-06-22 13:00:20 +0200994 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200995 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +0200996 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200997 nh_addr4,
998 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +0200999 is_del=0,
1000 end_psp=0,
1001 sw_if_index=0xFFFFFFFF,
1002 vlan_index=0,
1003 fib_table=0,
1004 ):
1005 """ Add/del IPv6 SR local-SID.
1006
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001007 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001008 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1009 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001010 :param nh_addr4:
1011 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001012 :param is_del: (Default value = 0)
1013 :param end_psp: (Default value = 0)
1014 :param sw_if_index: (Default value = 0xFFFFFFFF)
1015 :param vlan_index: (Default value = 0)
1016 :param fib_table: (Default value = 0)
1017 """
1018 return self.api(
1019 self.papi.sr_localsid_add_del,
1020 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001021 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001022 'end_psp': end_psp,
1023 'behavior': behavior,
1024 'sw_if_index': sw_if_index,
1025 'vlan_index': vlan_index,
1026 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001027 'nh_addr4': nh_addr4,
1028 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001029 }
1030 )
1031
1032 def sr_policy_add(
1033 self,
1034 bsid_addr,
1035 weight=1,
1036 is_encap=1,
1037 type=0,
1038 fib_table=0,
1039 n_segments=0,
1040 segments=[]):
1041 """
1042 :param bsid_addr: bindingSID of the SR Policy
1043 :param weight: weight of the sid list. optional. (default: 1)
1044 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1045 (default: Encap)
1046 :param type: type/behavior of the SR policy. (default or spray) \
1047 (default: default)
1048 :param fib_table: VRF where to install the FIB entry for the BSID \
1049 (default: 0)
1050 :param n_segments: number of segments \
1051 (default: 0)
1052 :param segments: a vector of IPv6 address composing the segment list \
1053 (default: [])
1054 """
1055 return self.api(
1056 self.papi.sr_policy_add,
1057 {'bsid_addr': bsid_addr,
1058 'weight': weight,
1059 'is_encap': is_encap,
1060 'type': type,
1061 'fib_table': fib_table,
1062 'n_segments': n_segments,
1063 'segments': segments
1064 }
1065 )
1066
1067 def sr_policy_del(
1068 self,
1069 bsid_addr,
1070 sr_policy_index=0):
1071 """
1072 :param bsid: bindingSID of the SR Policy
1073 :param sr_policy_index: index of the sr policy (default: 0)
1074 """
1075 return self.api(
1076 self.papi.sr_policy_del,
1077 {'bsid_addr': bsid_addr,
1078 'sr_policy_index': sr_policy_index
1079 })
1080
1081 def sr_steering_add_del(
1082 self,
1083 is_del,
1084 bsid_addr,
1085 sr_policy_index,
1086 table_id,
1087 prefix_addr,
1088 mask_width,
1089 sw_if_index,
1090 traffic_type):
1091 """
1092 Steer traffic L2 and L3 traffic through a given SR policy
1093
1094 :param is_del: delete or add
1095 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1096 :param sr_policy: is the index of the SR Policy (alt to bsid)
1097 :param table_id: is the VRF where to install the FIB entry for the BSID
1098 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1099 :param mask_width: is the mask for L3 traffic type
1100 :param sw_if_index: is the incoming interface for L2 traffic
1101 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1102 """
1103 return self.api(
1104 self.papi.sr_steering_add_del,
1105 {'is_del': is_del,
1106 'bsid_addr': bsid_addr,
1107 'sr_policy_index': sr_policy_index,
1108 'table_id': table_id,
1109 'prefix_addr': prefix_addr,
1110 'mask_width': mask_width,
1111 'sw_if_index': sw_if_index,
1112 'traffic_type': traffic_type
1113 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001114
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001115 def acl_add_replace(self, acl_index, r, tag='',
1116 expected_retval=0):
1117 """Add/replace an ACL
1118 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1119 :param acl_rule r: ACL rules array.
1120 :param str tag: symbolic tag (description) for this ACL.
1121 :param int count: number of rules.
1122 """
1123 return self.api(self.papi.acl_add_replace,
1124 {'acl_index': acl_index,
1125 'r': r,
1126 'count': len(r),
1127 'tag': tag},
1128 expected_retval=expected_retval)
1129
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001130 def acl_del(self, acl_index, expected_retval=0):
1131 """
1132
1133 :param acl_index:
1134 :return:
1135 """
1136 return self.api(self.papi.acl_del,
1137 {'acl_index': acl_index},
1138 expected_retval=expected_retval)
1139
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001140 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1141 expected_retval=0):
1142 return self.api(self.papi.acl_interface_set_acl_list,
1143 {'sw_if_index': sw_if_index,
1144 'count': len(acls),
1145 'n_input': n_input,
1146 'acls': acls},
1147 expected_retval=expected_retval)
1148
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001149 def acl_interface_set_etype_whitelist(self, sw_if_index,
1150 n_input, whitelist,
1151 expected_retval=0):
1152 return self.api(self.papi.acl_interface_set_etype_whitelist,
1153 {'sw_if_index': sw_if_index,
1154 'count': len(whitelist),
1155 'n_input': n_input,
1156 'whitelist': whitelist},
1157 expected_retval=expected_retval)
1158
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001159 def acl_interface_add_del(self,
1160 sw_if_index,
1161 acl_index,
1162 is_add=1):
1163 """ Add/Delete ACL to/from interface
1164
1165 :param sw_if_index:
1166 :param acl_index:
1167 :param is_add: (Default value = 1)
1168 """
1169
1170 return self.api(self.papi.acl_interface_add_del,
1171 {'is_add': is_add,
1172 'is_input': 1,
1173 'sw_if_index': sw_if_index,
1174 'acl_index': acl_index})
1175
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001176 def acl_dump(self, acl_index, expected_retval=0):
1177 return self.api(self.papi.acl_dump,
1178 {'acl_index': acl_index},
1179 expected_retval=expected_retval)
1180
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001181 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1182 expected_retval=0):
1183 return self.api(self.papi.acl_interface_list_dump,
1184 {'sw_if_index': sw_if_index},
1185 expected_retval=expected_retval)
1186
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001187 def macip_acl_add(self, rules, tag=""):
1188 """ Add MACIP acl
1189
1190 :param rules: list of rules for given acl
1191 :param tag: acl tag
1192 """
1193
1194 return self.api(self.papi.macip_acl_add,
1195 {'r': rules,
1196 'count': len(rules),
1197 'tag': tag})
1198
Pavel Kotucek932f7412017-09-07 14:44:52 +02001199 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1200 """ Add MACIP acl
1201
1202 :param rules: list of rules for given acl
1203 :param tag: acl tag
1204 """
1205
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001206 return self.api(self.papi.macip_acl_add_replace,
1207 {'acl_index': acl_index,
1208 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001209 'count': len(rules),
1210 'tag': tag})
1211
Pavel Kotucek932f7412017-09-07 14:44:52 +02001212 def macip_acl_interface_add_del(self,
1213 sw_if_index,
1214 acl_index,
1215 is_add=1):
1216 """ Add MACIP acl to interface
1217
1218 :param sw_if_index:
1219 :param acl_index:
1220 :param is_add: (Default value = 1)
1221 """
1222
1223 return self.api(self.papi.macip_acl_interface_add_del,
1224 {'is_add': is_add,
1225 'sw_if_index': sw_if_index,
1226 'acl_index': acl_index})
1227
Pavel Kotucek932f7412017-09-07 14:44:52 +02001228 def macip_acl_dump(self, acl_index=4294967295):
1229 """ Return MACIP acl dump
1230 """
1231
1232 return self.api(
1233 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001234
1235 def policer_add_del(self,
1236 name,
1237 cir,
1238 eir,
1239 cb,
1240 eb,
1241 is_add=1,
1242 rate_type=0,
1243 round_type=0,
1244 ptype=0,
1245 color_aware=0,
1246 conform_action_type=1,
1247 conform_dscp=0,
1248 exceed_action_type=0,
1249 exceed_dscp=0,
1250 violate_action_type=0,
1251 violate_dscp=0):
1252 return self.api(self.papi.policer_add_del,
1253 {'name': name,
1254 'cir': cir,
1255 'eir': eir,
1256 'cb': cb,
1257 'eb': eb,
1258 'is_add': is_add,
1259 'rate_type': rate_type,
1260 'round_type': round_type,
1261 'type': ptype,
1262 'color_aware': color_aware,
1263 'conform_action_type': conform_action_type,
1264 'conform_dscp': conform_dscp,
1265 'exceed_action_type': exceed_action_type,
1266 'exceed_dscp': exceed_dscp,
1267 'violate_action_type': violate_action_type,
1268 'violate_dscp': violate_dscp})
1269
1270 def ip_punt_police(self,
1271 policer_index,
1272 is_ip6=0,
1273 is_add=1):
1274 return self.api(self.papi.ip_punt_police,
1275 {'policer_index': policer_index,
1276 'is_add': is_add,
1277 'is_ip6': is_ip6})
1278
1279 def ip_punt_redirect(self,
1280 rx_sw_if_index,
1281 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001282 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001283 is_add=1):
1284 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001285 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1286 'tx_sw_if_index': tx_sw_if_index,
1287 'nh': address},
1288 'is_add': is_add})
1289
1290 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1291 return self.api(self.papi.ip_punt_redirect_dump,
1292 {'sw_if_index': sw_if_index,
1293 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001294
1295 def bier_table_add_del(self,
1296 bti,
1297 mpls_label,
1298 is_add=1):
1299 """ BIER Table add/del """
1300 return self.api(
1301 self.papi.bier_table_add_del,
1302 {'bt_tbl_id': {"bt_set": bti.set_id,
1303 "bt_sub_domain": bti.sub_domain_id,
1304 "bt_hdr_len_id": bti.hdr_len_id},
1305 'bt_label': mpls_label,
1306 'bt_is_add': is_add})
1307
1308 def bier_table_dump(self):
1309 return self.api(self.papi.bier_table_dump, {})
1310
1311 def bier_route_add_del(self,
1312 bti,
1313 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001314 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001315 is_add=1,
1316 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001317 """ BIER Route add/del """
1318 return self.api(
1319 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001320 {
1321 'br_route': {
1322 'br_tbl_id': {"bt_set": bti.set_id,
1323 "bt_sub_domain": bti.sub_domain_id,
1324 "bt_hdr_len_id": bti.hdr_len_id},
1325 'br_bp': bp,
1326 'br_n_paths': len(paths),
1327 'br_paths': paths,
1328 },
1329 'br_is_add': is_add,
1330 'br_is_replace': is_replace
1331 })
Neale Rannsd792d9c2017-10-21 10:53:20 -07001332
1333 def bier_route_dump(self, bti):
1334 return self.api(
1335 self.papi.bier_route_dump,
1336 {'br_tbl_id': {"bt_set": bti.set_id,
1337 "bt_sub_domain": bti.sub_domain_id,
1338 "bt_hdr_len_id": bti.hdr_len_id}})
1339
1340 def bier_imp_add(self,
1341 bti,
1342 src,
1343 ibytes,
1344 is_add=1):
1345 """ BIER Imposition Add """
1346 return self.api(
1347 self.papi.bier_imp_add,
1348 {'bi_tbl_id': {"bt_set": bti.set_id,
1349 "bt_sub_domain": bti.sub_domain_id,
1350 "bt_hdr_len_id": bti.hdr_len_id},
1351 'bi_src': src,
1352 'bi_n_bytes': len(ibytes),
1353 'bi_bytes': ibytes})
1354
1355 def bier_imp_del(self, bi_index):
1356 """ BIER Imposition del """
1357 return self.api(
1358 self.papi.bier_imp_del,
1359 {'bi_index': bi_index})
1360
1361 def bier_imp_dump(self):
1362 return self.api(self.papi.bier_imp_dump, {})
1363
1364 def bier_disp_table_add_del(self,
1365 bdti,
1366 is_add=1):
1367 """ BIER Disposition Table add/del """
1368 return self.api(
1369 self.papi.bier_disp_table_add_del,
1370 {'bdt_tbl_id': bdti,
1371 'bdt_is_add': is_add})
1372
1373 def bier_disp_table_dump(self):
1374 return self.api(self.papi.bier_disp_table_dump, {})
1375
1376 def bier_disp_entry_add_del(self,
1377 bdti,
1378 bp,
1379 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001380 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001381 next_hop,
1382 next_hop_tbl_id=0,
1383 next_hop_rpf_id=~0,
1384 next_hop_is_ip4=1,
1385 is_add=1):
1386 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001387 lstack = []
1388 while (len(lstack) < 16):
1389 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001390 return self.api(
1391 self.papi.bier_disp_entry_add_del,
1392 {'bde_tbl_id': bdti,
1393 'bde_bp': bp,
1394 'bde_payload_proto': payload_proto,
1395 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -04001396 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001397 'rpf_id': next_hop_rpf_id,
1398 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001399 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001400 'bde_is_add': is_add})
1401
1402 def bier_disp_entry_dump(self, bdti):
1403 return self.api(
1404 self.papi.bier_disp_entry_dump,
1405 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001406
Florin Coras3ea6ce22017-12-11 09:09:05 -08001407 def session_enable_disable(self, is_enabled):
1408 return self.api(
1409 self.papi.session_enable_disable,
1410 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001411
1412 def ipsec_spd_add_del(self, spd_id, is_add=1):
1413 """ SPD add/del - Wrapper to add or del ipsec SPD
1414 Sample CLI : 'ipsec spd add 1'
1415
1416 :param spd_id - SPD ID to be created in the vpp . mandatory
1417 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1418 optional
1419 :returns: reply from the API
1420 """
1421 return self.api(
1422 self.papi.ipsec_spd_add_del, {
1423 'spd_id': spd_id, 'is_add': is_add})
1424
Neale Ranns311124e2019-01-24 04:52:25 -08001425 def ipsec_spds_dump(self):
1426 return self.api(self.papi.ipsec_spds_dump, {})
1427
“mystarrocks”23f0c452017-12-11 07:11:51 -08001428 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1429 """ IPSEC interface SPD add/del - \
1430 Wrapper to associate/disassociate SPD to interface in VPP
1431 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1432
1433 :param spd_id - SPD ID to associate with the interface . mandatory
1434 :param sw_if_index - Interface Index which needs to ipsec \
1435 association mandatory
1436 :param is_add - add(1) or del(0) association with interface \
1437 (Default 1 - add) . optional
1438 :returns: reply from the API
1439 """
1440 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001441 self.papi.ipsec_interface_add_del_spd,
1442 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001443
Neale Ranns311124e2019-01-24 04:52:25 -08001444 def ipsec_spd_interface_dump(self, spd_index=None):
1445 return self.api(self.papi.ipsec_spd_interface_dump,
1446 {'spd_index': spd_index if spd_index else 0,
1447 'spd_index_valid': 1 if spd_index else 0})
1448
Neale Ranns17dcec02019-01-09 21:22:20 -08001449 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001450 sad_id,
1451 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001452 integrity_algorithm,
1453 integrity_key,
1454 crypto_algorithm,
1455 crypto_key,
1456 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001457 tunnel_src_address='',
1458 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001459 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001460 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001461 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001462 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001463 :param sad_id: security association ID
1464 :param spi: security param index of the SA in decimal
1465 :param integrity_algorithm:
1466 :param integrity_key:
1467 :param crypto_algorithm:
1468 :param crypto_key:
1469 :param protocol: AH(0) or ESP(1) protocol
1470 :param tunnel_src_address: tunnel mode outer src address
1471 :param tunnel_dst_address: tunnel mode outer dst address
1472 :param is_add:
1473 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001474 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1475 crypto and ipsec algorithms
1476 """
1477 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001478 self.papi.ipsec_sad_entry_add_del,
1479 {
1480 'is_add': is_add,
1481 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001482 {
1483 'sad_id': sad_id,
1484 'spi': spi,
1485 'tunnel_src': tunnel_src_address,
1486 'tunnel_dst': tunnel_dst_address,
1487 'protocol': protocol,
1488 'integrity_algorithm': integrity_algorithm,
1489 'integrity_key': {
1490 'length': len(integrity_key),
1491 'data': integrity_key,
1492 },
1493 'crypto_algorithm': crypto_algorithm,
1494 'crypto_key': {
1495 'length': len(crypto_key),
1496 'data': crypto_key,
1497 },
1498 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001499 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001500 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001501 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001502
Neale Ranns311124e2019-01-24 04:52:25 -08001503 def ipsec_sa_dump(self, sa_id=None):
1504 return self.api(self.papi.ipsec_sa_dump,
1505 {'sa_id': sa_id if sa_id else 0xffffffff})
1506
Neale Ranns17dcec02019-01-09 21:22:20 -08001507 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001508 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001509 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001510 local_address_start,
1511 local_address_stop,
1512 remote_address_start,
1513 remote_address_stop,
1514 local_port_start=0,
1515 local_port_stop=65535,
1516 remote_port_start=0,
1517 remote_port_stop=65535,
1518 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001519 policy=0,
1520 priority=100,
1521 is_outbound=1,
1522 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001523 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001524 is_ip_any=0):
1525 """ IPSEC policy SPD add/del -
1526 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001527 :param spd_id: SPD ID for the policy
1528 :param local_address_start: local-ip-range start address
1529 :param local_address_stop : local-ip-range stop address
1530 :param remote_address_start: remote-ip-range start address
1531 :param remote_address_stop : remote-ip-range stop address
1532 :param local_port_start: (Default value = 0)
1533 :param local_port_stop: (Default value = 65535)
1534 :param remote_port_start: (Default value = 0)
1535 :param remote_port_stop: (Default value = 65535)
1536 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1537 :param sa_id: Security Association ID for mapping it to SPD
1538 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1539 (Default value = 0)
1540 :param priority: value for the spd action (Default value = 100)
1541 :param is_outbound: flag for inbound(0) or outbound(1)
1542 (Default value = 1)
1543 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001544 """
1545 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001546 self.papi.ipsec_spd_entry_add_del,
1547 {
1548 'is_add': is_add,
1549 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001550 {
1551 'spd_id': spd_id,
1552 'sa_id': sa_id,
1553 'local_address_start': local_address_start,
1554 'local_address_stop': local_address_stop,
1555 'remote_address_start': remote_address_start,
1556 'remote_address_stop': remote_address_stop,
1557 'local_port_start': local_port_start,
1558 'local_port_stop': local_port_stop,
1559 'remote_port_start': remote_port_start,
1560 'remote_port_stop': remote_port_stop,
1561 'protocol': protocol,
1562 'policy': policy,
1563 'priority': priority,
1564 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +01001565 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001566 })
Florin Corasb795bd02017-12-14 11:30:48 -08001567
Neale Ranns311124e2019-01-24 04:52:25 -08001568 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1569 return self.api(self.papi.ipsec_spd_dump,
1570 {'spd_id': spd_id,
1571 'sa_id': sa_id})
1572
Klement Sekera31da2e32018-06-24 22:49:55 +02001573 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1574 remote_spi, crypto_alg, local_crypto_key,
1575 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001576 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001577 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +00001578 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +02001579 return self.api(
1580 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001581 {
1582 'local_ip': local_ip,
1583 'remote_ip': remote_ip,
1584 'local_spi': local_spi,
1585 'remote_spi': remote_spi,
1586 'crypto_alg': crypto_alg,
1587 'local_crypto_key_len': len(local_crypto_key),
1588 'local_crypto_key': local_crypto_key,
1589 'remote_crypto_key_len': len(remote_crypto_key),
1590 'remote_crypto_key': remote_crypto_key,
1591 'integ_alg': integ_alg,
1592 'local_integ_key_len': len(local_integ_key),
1593 'local_integ_key': local_integ_key,
1594 'remote_integ_key_len': len(remote_integ_key),
1595 'remote_integ_key': remote_integ_key,
1596 'is_add': is_add,
1597 'esn': esn,
1598 'anti_replay': anti_replay,
1599 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001600 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001601 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001602 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001603 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001604
Klement Sekerab4d30532018-11-08 13:00:02 +01001605 def ipsec_select_backend(self, protocol, index):
1606 return self.api(self.papi.ipsec_select_backend,
1607 {'protocol': protocol, 'index': index})
1608
1609 def ipsec_backend_dump(self):
1610 return self.api(self.papi.ipsec_backend_dump, {})
1611
Ole Troane1ade682019-03-04 23:55:43 +01001612 def app_namespace_add_del(self,
1613 namespace_id,
1614 ip4_fib_id=0,
1615 ip6_fib_id=0,
1616 sw_if_index=0xFFFFFFFF,
1617 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001618 return self.api(
1619 self.papi.app_namespace_add_del,
1620 {'secret': secret,
1621 'sw_if_index': sw_if_index,
1622 'ip4_fib_id': ip4_fib_id,
1623 'ip6_fib_id': ip6_fib_id,
1624 'namespace_id': namespace_id,
1625 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001626
Neale Ranns50f0ac02019-05-15 02:13:37 -07001627 def punt_socket_register(self, reg, pathname,
1628 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001629 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001630 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001631 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001632 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001633 'pathname': pathname})
1634
Neale Ranns50f0ac02019-05-15 02:13:37 -07001635 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001636 """ Unregister punt socket """
1637 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001638 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +02001639
Neale Ranns4ba67722019-02-28 11:11:39 +00001640 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001641 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001642 """ GBP endpoint Add """
1643 return self.api(self.papi.gbp_endpoint_add,
1644 {'endpoint': {
1645 'sw_if_index': sw_if_index,
1646 'ips': ips,
1647 'n_ips': len(ips),
1648 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001649 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001650 'flags': flags,
1651 'tun': {
1652 'src': tun_src,
1653 'dst': tun_dst,
1654 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001655
1656 def gbp_endpoint_del(self, handle):
1657 """ GBP endpoint Del """
1658 return self.api(self.papi.gbp_endpoint_del,
1659 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001660
1661 def gbp_endpoint_dump(self):
1662 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001663 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001664
Neale Ranns4ba67722019-02-28 11:11:39 +00001665 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001666 rd, uplink_sw_if_index,
1667 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001668 """ GBP endpoint group Add """
1669 return self.api(self.papi.gbp_endpoint_group_add,
1670 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001671 {
1672 'uplink_sw_if_index': uplink_sw_if_index,
1673 'bd_id': bd,
1674 'rd_id': rd,
1675 'vnid': vnid,
1676 'sclass': sclass,
1677 'retention': retention
1678 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001679
Neale Ranns4ba67722019-02-28 11:11:39 +00001680 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001681 """ GBP endpoint group Del """
1682 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00001683 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07001684
Neale Ranns160c9232019-06-19 06:25:56 -07001685 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001686 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08001687 uu_fwd_sw_if_index,
1688 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001689 """ GBP bridge-domain Add """
1690 return self.api(self.papi.gbp_bridge_domain_add,
1691 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01001692 {
1693 'flags': flags,
1694 'bvi_sw_if_index': bvi_sw_if_index,
1695 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
1696 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07001697 'bd_id': bd_id,
1698 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01001699 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001700
1701 def gbp_bridge_domain_del(self, bd_id):
1702 """ GBP bridge-domain Del """
1703 return self.api(self.papi.gbp_bridge_domain_del,
1704 {'bd_id': bd_id})
1705
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001706 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07001707 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001708 ip4_table_id,
1709 ip6_table_id,
1710 ip4_uu_sw_if_index,
1711 ip6_uu_sw_if_index):
1712 """ GBP route-domain Add """
1713 return self.api(self.papi.gbp_route_domain_add,
1714 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01001715 {
Neale Ranns160c9232019-06-19 06:25:56 -07001716 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01001717 'ip4_table_id': ip4_table_id,
1718 'ip6_table_id': ip6_table_id,
1719 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
1720 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
1721 'rd_id': rd_id
1722 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001723
1724 def gbp_route_domain_del(self, rd_id):
1725 """ GBP route-domain Del """
1726 return self.api(self.papi.gbp_route_domain_del,
1727 {'rd_id': rd_id})
1728
Neale Ranns4ba67722019-02-28 11:11:39 +00001729 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07001730 """ GBP recirc Add/Del """
1731 return self.api(self.papi.gbp_recirc_add_del,
1732 {'is_add': is_add,
1733 'recirc': {
1734 'is_ext': is_ext,
1735 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001736 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07001737
1738 def gbp_recirc_dump(self):
1739 """ GBP recirc Dump """
1740 return self.api(self.papi.gbp_recirc_dump, {})
1741
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001742 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08001743 """ GBP recirc Add/Del """
1744 return self.api(self.papi.gbp_ext_itf_add_del,
1745 {'is_add': is_add,
1746 'ext_itf': {
1747 'sw_if_index': sw_if_index,
1748 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001749 'rd_id': rd_id,
1750 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08001751
1752 def gbp_ext_itf_dump(self):
1753 """ GBP recirc Dump """
1754 return self.api(self.papi.gbp_ext_itf_dump, {})
1755
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001756 def gbp_subnet_add_del(self, is_add, rd_id,
1757 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07001758 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00001759 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07001760 """ GBP Subnet Add/Del """
1761 return self.api(self.papi.gbp_subnet_add_del,
1762 {'is_add': is_add,
1763 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001764 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07001765 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001766 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07001767 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001768 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07001769
1770 def gbp_subnet_dump(self):
1771 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001772 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001773
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001774 def gbp_contract_dump(self):
1775 """ GBP contract Dump """
1776 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001777
Neale Ranns8da9fc62019-03-04 14:08:11 -08001778 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001779 """ GBP VXLAN tunnel add """
1780 return self.api(self.papi.gbp_vxlan_tunnel_add,
1781 {
1782 'tunnel': {
1783 'vni': vni,
1784 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001785 'bd_rd_id': bd_rd_id,
1786 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001787 }
1788 })
1789
1790 def gbp_vxlan_tunnel_del(self, vni):
1791 """ GBP VXLAN tunnel del """
1792 return self.api(self.papi.gbp_vxlan_tunnel_del,
1793 {
1794 'vni': vni,
1795 })
1796
1797 def gbp_vxlan_tunnel_dump(self):
1798 """ GBP VXLAN tunnel add/del """
1799 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1800
Neale Ranns947ea622018-06-07 23:48:20 -07001801 def igmp_enable_disable(self, sw_if_index, enable, host):
1802 """ Enable/disable IGMP on a given interface """
1803 return self.api(self.papi.igmp_enable_disable,
1804 {'enable': enable,
1805 'mode': host,
1806 'sw_if_index': sw_if_index})
1807
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001808 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1809 """ Add/del IGMP proxy device """
1810 return self.api(self.papi.igmp_proxy_device_add_del,
1811 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1812 'add': add})
1813
1814 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1815 """ Add/del interface to/from IGMP proxy device """
1816 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1817 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1818 'add': add})
1819
Neale Ranns947ea622018-06-07 23:48:20 -07001820 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001821 """ Listen for new (S,G) on specified interface
1822
1823 :param enable: add/del
1824 :param sw_if_index: interface sw index
1825 :param saddr: source ip4 addr
1826 :param gaddr: group ip4 addr
1827 """
1828 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001829 {
1830 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001831 {
1832 'filter': filter,
1833 'sw_if_index': sw_if_index,
1834 'n_srcs': len(saddrs),
1835 'saddrs': saddrs,
1836 'gaddr': gaddr
1837 }
Neale Ranns947ea622018-06-07 23:48:20 -07001838 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001839
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001840 def igmp_clear_interface(self, sw_if_index):
1841 """ Remove all (S,G)s from specified interface
1842 doesn't send IGMP report!
1843 """
1844 return self.api(
1845 self.papi.igmp_clear_interface, {
1846 'sw_if_index': sw_if_index})
1847
1848 def want_igmp_events(self, enable=1):
1849 return self.api(self.papi.want_igmp_events, {'enable': enable,
1850 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08001851
1852 def bond_create(
1853 self,
1854 mode,
1855 lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001856 numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08001857 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001858 mac_address='',
1859 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08001860 """
1861 :param mode: mode
1862 :param lb: load balance
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001863 :param numa_only: tx on local numa node for lacp mode
Steven9cd2d7a2017-12-20 12:43:01 -08001864 :param use_custom_mac: use custom mac
1865 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001866 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08001867 """
1868 return self.api(
1869 self.papi.bond_create,
1870 {'mode': mode,
1871 'lb': lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001872 'numa_only': numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08001873 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001874 'mac_address': mac_address,
1875 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08001876 })
1877
Neale Ranns17ff3c12018-07-04 10:24:24 -07001878 def pipe_delete(self, parent_sw_if_index):
1879 return self.api(self.papi.pipe_delete,
1880 {'parent_sw_if_index': parent_sw_if_index})
1881
Neale Rannsd1e68ab2018-10-01 01:42:13 -07001882 def svs_table_add_del(self, af, table_id, is_add=1):
1883 return self.api(self.papi.svs_table_add_del,
1884 {
1885 'table_id': table_id,
1886 'is_add': is_add,
1887 'af': af,
1888 })
1889
1890 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
1891 return self.api(self.papi.svs_route_add_del,
1892 {
1893 'table_id': table_id,
1894 'source_table_id': src_table_id,
1895 'prefix': prefix,
1896 'is_add': is_add,
1897 })
1898
1899 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
1900 return self.api(self.papi.svs_enable_disable,
1901 {
1902 'af': af,
1903 'table_id': table_id,
1904 'sw_if_index': sw_if_index,
1905 'is_enable': is_enable,
1906 })
Mohsin Kazmi29467b52019-10-08 19:42:38 +02001907
1908 def feature_gso_enable_disable(self, sw_if_index, enable_disable=1):
1909 return self.api(self.papi.feature_gso_enable_disable,
1910 {
1911 'sw_if_index': sw_if_index,
1912 'enable_disable': enable_disable,
1913 })