blob: 65b58f15f52f0ab3fc35aadb3cb10e1fac310849 [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 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
50 'decap_next_index': 4294967295, },
51 'input_acl_set_interface': {'ip4_table_index': 4294967295,
52 'ip6_table_index': 4294967295,
53 'l2_table_index': 4294967295, },
54 'ip6_add_del_address_using_prefix': {'is_add': 1, },
55 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
56 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
57 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010058 'classify_table_index': 4294967295, 'is_add': 1, },
59 'ip_mroute_add_del': {'is_add': 1, },
60 'ip_neighbor_add_del': {'is_add': 1, },
61 'ip_punt_police': {'is_add': 1, },
62 'ip_punt_redirect': {'is_add': 1, },
Neale Ranns097fa662018-05-01 05:17:55 -070063 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010064 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010065 'ipsec_interface_add_del_spd': {'is_add': 1, },
66 'ipsec_sad_entry_add_del': {'is_add': 1, },
67 'ipsec_spd_add_del': {'is_add': 1, },
68 'ipsec_spd_dump': {'sa_id': 4294967295, },
69 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
70 'remote_port_stop': 65535, 'priority': 100,
71 'is_outbound': 1,
72 'is_add': 1, },
73 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
74 'l2_emulation': {'enable': 1, },
75 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -070076 'lb_conf': {'sticky_buckets_per_core': 4294967295,
77 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +010078 'lisp_add_del_adjacency': {'is_add': 1, },
79 'lisp_add_del_local_eid': {'is_add': 1, },
80 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
81 'lisp_add_del_locator_set': {'is_add': 1, },
82 'lisp_add_del_remote_mapping': {'is_add': 1, },
83 'macip_acl_add_replace': {'acl_index': 4294967295, },
84 'macip_acl_dump': {'acl_index': 4294967295, },
85 'macip_acl_interface_add_del': {'is_add': 1, },
86 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010087 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
88 'mr_next_hop_weight': 1,
89 'mr_next_hop_via_label': 1048576,
90 'mr_is_add': 1,
91 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010092 'mpls_table_add_del': {'is_add': 1, },
93 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
94 'next_hop_weight': 1,
95 'next_hop_via_label': 1048576,
96 'is_add': 1, },
97 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010098 'output_acl_set_interface': {'ip4_table_index': 4294967295,
99 'ip6_table_index': 4294967295,
100 'l2_table_index': 4294967295, },
101 'pppoe_add_del_session': {'is_add': 1, },
102 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
103 'proxy_arp_add_del': {'is_add': 1, },
104 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100105 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
106 'proto': 1, },
107 'set_ipfix_exporter': {'collector_port': 4739, },
108 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
109 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
110 'svs_enable_disable': {'is_enable': 1, },
111 'svs_route_add_del': {'is_add': 1, },
112 'svs_table_add_del': {'is_add': 1, },
113 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700114 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100115 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
116 'pref_lifetime': 4294967295, },
117 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
118 'sw_interface_set_l2_bridge': {'enable': 1, },
119 'sw_interface_set_mpls_enable': {'enable': 1, },
120 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
121 'sw_interface_set_unnumbered': {'is_add': 1, },
122 'sw_interface_span_enable_disable': {'state': 1, },
123 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
124 'decap_next_index': 4294967295,
125 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100126 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
127 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
128 'protocol': 3, },
129 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100130 'want_igmp_events': {'enable': 1, },
131 'want_interface_events': {'enable_disable': 1, },
132 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
133 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
134 'want_ip6_ra_events': {'enable_disable': 1, },
135 'want_l2_macs_events': {'enable_disable': 1, },
136}
Ole Troanf159f582019-02-28 20:20:47 +0100137
Matus Fabianb4515b42018-11-19 04:25:32 -0800138
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400139class CliFailedCommandError(Exception):
140 """ cli command failed."""
141
142
143class CliSyntaxError(Exception):
144 """ cli command had a syntax error."""
145
146
Klement Sekera73884482017-02-23 09:26:30 +0100147class UnexpectedApiReturnValueError(Exception):
148 """ exception raised when the API return value is unexpected """
149 pass
150
151
Klement Sekeraf62ae122016-10-11 11:47:09 +0200152class VppPapiProvider(object):
153 """VPP-api provider using vpp-papi
154
155 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200156 """
157
Klement Sekerae0545ef2017-01-25 08:00:40 +0100158 _zero, _negative = range(2)
159
Klement Sekera611864f2018-09-26 11:19:00 +0200160 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800161 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200162 self.name = name
163 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100164 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100165 self._expect_api_retval = self._zero
166 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100167
Paul Vinciguerra19542292019-03-17 17:34:46 -0700168 # install_dir is a class attribute. We need to set it before
169 # calling the constructor.
170 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800171
Ole Troan4ff09ae2019-04-15 11:27:22 +0200172 use_socket = False
173 try:
174 if os.environ['SOCKET'] == '1':
175 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400176 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200177 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700178
179 self.vpp = VPPApiClient(logger=test_class.logger,
180 read_timeout=read_timeout,
181 use_socket=use_socket,
182 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100183 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200184
Klement Sekerae0545ef2017-01-25 08:00:40 +0100185 def __enter__(self):
186 return self
187
Klement Sekera7d6afb32018-11-08 11:52:04 +0100188 def assert_negative_api_retval(self):
189 """ Expect API failure - used with with, e.g.:
190 with self.vapi.assert_negative_api_retval():
191 self.vapi.<api call expected to fail>
192 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100193 self._expect_stack.append(self._expect_api_retval)
194 self._expect_api_retval = self._negative
195 return self
196
Klement Sekera7d6afb32018-11-08 11:52:04 +0100197 def assert_zero_api_retval(self):
198 """ Expect API success - used with with, e.g.:
199 with self.vapi.assert_negative_api_retval():
200 self.vapi.<api call expected to succeed>
201
202 note: this is useful only inside another with block
203 as success is the default expected value
204 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100205 self._expect_stack.append(self._expect_api_retval)
206 self._expect_api_retval = self._zero
207 return self
208
209 def __exit__(self, exc_type, exc_value, traceback):
210 self._expect_api_retval = self._expect_stack.pop()
211
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212 def register_hook(self, hook):
213 """Replace hook registration with new hook
214
215 :param hook:
216
217 """
218 self.hook = hook
219
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200220 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100221 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200222 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100223 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200224 return e
225
226 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100227 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100228 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100229 self.test_class.logger.debug("Expecting event '%s' within %ss",
230 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300231 else:
232 self.test_class.logger.debug("Expecting event within %ss",
233 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100234 if self._events:
235 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200236 limit = time.time() + timeout
237 while time.time() < limit:
238 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100239 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200240 if name and type(e).__name__ != name:
241 raise Exception(
242 "Unexpected event received: %s, expected: %s" %
243 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100244 self.test_class.logger.debug("Returning event %s:%s" %
245 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200246 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700247 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200248 raise Exception("Event did not occur within timeout")
249
250 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100251 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200252 # FIXME use the name instead of relying on type(e).__name__ ?
253 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100254 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200255 self._events.append(event)
256
Ole Troanf159f582019-02-28 20:20:47 +0100257 def factory(self, name, apifn):
258 def f(*a, **ka):
259 fields = apifn._func.msg.fields
260
261 # add positional and kw arguments
262 d = ka
263 for i, o in enumerate(fields[3:]):
264 try:
265 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200266 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100267 break
268
269 # Default override
270 if name in defaultmapping:
271 for k, v in iteritems(defaultmapping[name]):
272 if k in d:
273 continue
274 d[k] = v
275 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100276
Ole Troanf159f582019-02-28 20:20:47 +0100277 return f
278
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800279 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100280 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800281 method = super(VppPapiProvider, self).__getattribute__(name)
282 except AttributeError:
283 method = self.factory(name, getattr(self.papi, name))
284 # lazily load the method so we don't need to call factory
285 # again for this name.
286 setattr(self, name, method)
287 return method
Ole Troanf159f582019-02-28 20:20:47 +0100288
Klement Sekeraf62ae122016-10-11 11:47:09 +0200289 def connect(self):
290 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100291 self.vpp.connect(self.name, self.shm_prefix)
292 self.papi = self.vpp.api
293 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200294
295 def disconnect(self):
296 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100297 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200298
299 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100300 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200301 Call the appropriate hooks before and after the API call
302
303 :param api_fn: API function to call
304 :param api_args: tuple of API function arguments
305 :param expected_retval: Expected return value (Default value = 0)
306 :returns: reply from the API
307
308 """
309 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100310 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100311 if self._expect_api_retval == self._negative:
312 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100313 msg = "API call passed unexpectedly: expected negative " \
314 "return value instead of %d in %s" % \
315 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100316 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100317 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100318 elif self._expect_api_retval == self._zero:
319 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100320 msg = "API call failed, expected %d return value instead " \
321 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400322 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100323 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100324 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100325 else:
326 raise Exception("Internal error, unexpected value for "
327 "self._expect_api_retval %s" %
328 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200329 self.hook.after_api(api_fn.__name__, api_args)
330 return reply
331
Dave Barach5932ce12019-10-09 17:28:04 -0400332 def cli_return_response(self, cli):
333 """ Execute a CLI, calling the before/after hooks appropriately.
334 Return the reply without examining it
335
336 :param cli: CLI to execute
337 :returns: response object
338
339 """
340 self.hook.before_cli(cli)
341 cli += '\n'
342 r = self.papi.cli_inband(cmd=cli)
343 self.hook.after_cli(cli)
344 return r
345
Klement Sekeraf62ae122016-10-11 11:47:09 +0200346 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100347 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200348
349 :param cli: CLI to execute
350 :returns: CLI output
351
352 """
Dave Barach5932ce12019-10-09 17:28:04 -0400353 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400354 if r.retval == -156:
355 raise CliSyntaxError(r.reply)
356 if r.retval != 0:
357 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200358 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100359 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200360
Jan49c0fca2016-10-26 15:44:27 +0200361 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100362 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200363
364 :param cli: CLI to execute
365 :returns: CLI output
366 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200367 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200368
Neale Ranns37029302018-08-10 05:30:06 -0700369 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300370 return self.api(self.papi.want_ip4_arp_events,
371 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700372 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300373 'pid': os.getpid(), })
374
Neale Ranns37029302018-08-10 05:30:06 -0700375 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300376 return self.api(self.papi.want_ip6_nd_events,
377 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700378 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300379 'pid': os.getpid(), })
380
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100381 def want_ip6_ra_events(self, enable_disable=1):
382 return self.api(self.papi.want_ip6_ra_events,
383 {'enable_disable': enable_disable,
384 'pid': os.getpid(), })
385
386 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
387 mrc=0, mrd=0):
388 return self.api(self.papi.ip6nd_send_router_solicitation,
389 {'irt': irt,
390 'mrt': mrt,
391 'mrc': mrc,
392 'mrd': mrd,
393 'sw_if_index': sw_if_index})
394
Juraj Slobodab3f90502018-10-04 15:15:16 +0200395 def want_interface_events(self, enable_disable=1):
396 return self.api(self.papi.want_interface_events,
397 {'enable_disable': enable_disable,
398 'pid': os.getpid(), })
399
Ole Troane1ade682019-03-04 23:55:43 +0100400 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
401 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300402 return self.api(self.papi.want_l2_macs_events,
403 {'enable_disable': enable_disable,
404 'scan_delay': scan_delay,
405 'max_macs_in_event': max_macs_in_event,
406 'learn_limit': learn_limit,
407 'pid': os.getpid(), })
408
Neale Rannsc819fc62018-02-16 02:44:05 -0800409 def sw_interface_set_mac_address(self, sw_if_index, mac):
410 return self.api(self.papi.sw_interface_set_mac_address,
411 {'sw_if_index': sw_if_index,
412 'mac_address': mac})
413
Ole Troane1ade682019-03-04 23:55:43 +0100414 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200415 """Create p2p ethernet subinterface
416
417 :param sw_if_index: main (parent) interface
418 :param remote_mac: client (remote) mac address
419
420 """
421 return self.api(
422 self.papi.p2p_ethernet_add,
423 {'parent_if_index': sw_if_index,
424 'remote_mac': remote_mac,
425 'subif_id': subif_id})
426
Ole Troane1ade682019-03-04 23:55:43 +0100427 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200428 """Delete p2p ethernet subinterface
429
430 :param sw_if_index: main (parent) interface
431 :param remote_mac: client (remote) mac address
432
433 """
434 return self.api(
435 self.papi.p2p_ethernet_del,
436 {'parent_if_index': sw_if_index,
437 'remote_mac': remote_mac})
438
Klement Sekeraf62ae122016-10-11 11:47:09 +0200439 def create_vlan_subif(self, sw_if_index, vlan):
440 """
441
442 :param vlan:
443 :param sw_if_index:
444
445 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100446 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200447 {'sw_if_index': sw_if_index,
448 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200449
Matej Klotton0178d522016-11-04 11:11:44 +0100450 def create_loopback(self, mac=''):
451 """
452
453 :param mac: (Optional)
454 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100455 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200456 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100457
Neale Ranns097fa662018-05-01 05:17:55 -0700458 def ip_route_dump(self, table_id, is_ip6=False):
459 return self.api(self.papi.ip_route_dump,
460 {'table': {
461 'table_id': table_id,
462 'is_ip6': is_ip6
463 }})
464
Matej Klotton0178d522016-11-04 11:11:44 +0100465 def ip_neighbor_add_del(self,
466 sw_if_index,
467 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700468 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100469 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700470 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100471 """ Add neighbor MAC to IPv4 or IPv6 address.
472
473 :param sw_if_index:
474 :param mac_address:
475 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100476 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700477 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100478 """
Matej Klotton0178d522016-11-04 11:11:44 +0100479 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100480 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700481 {
482 'is_add': is_add,
483 'neighbor': {
484 'sw_if_index': sw_if_index,
485 'flags': flags,
486 'mac_address': mac_address,
487 'ip_address': ip_address
488 }
489 }
Matej Klotton0178d522016-11-04 11:11:44 +0100490 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100491
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800492 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700493 low,
494 hi,
495 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800496 is_add=1):
497 """ Config Proxy Arp Range.
498
499 :param low_address: Start address in the rnage to Proxy for
500 :param hi_address: End address in the rnage to Proxy for
501 :param vrf_id: The VRF/table in which to proxy
502 """
503
504 return self.api(
505 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700506 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100507 {
508 'table_id': table_id,
509 'low': low,
510 'hi': hi,
511 },
512 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800513
514 def proxy_arp_intfc_enable_disable(self,
515 sw_if_index,
516 is_enable=1):
517 """ Enable/Disable an interface for proxy ARP requests
518
519 :param sw_if_index: Interface
520 :param enable_disable: Enable/Disable
521 """
522
523 return self.api(
524 self.papi.proxy_arp_intfc_enable_disable,
525 {'sw_if_index': sw_if_index,
526 'enable_disable': is_enable
527 }
528 )
529
Neale Ranns5a8844b2019-04-16 07:15:35 +0000530 def gre_tunnel_add_del(self,
531 src,
532 dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000533 outer_table_id=0,
534 type=0,
535 mode=0,
John Loa43ccae2018-02-13 17:15:23 -0500536 instance=0xFFFFFFFF,
537 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000538 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000539 """ Add a GRE tunnel
540
541 :param src_address:
542 :param dst_address:
543 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500544 :param tunnel_type: (Default value = 0)
545 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700546 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000547 :param is_add: (Default value = 1)
548 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000549 """
550
551 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000552 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200553 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000554 'tunnel':
555 {
Neale Ranns5f8f6172019-04-18 10:23:56 +0000556 'type': type,
557 'mode': mode,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000558 'instance': instance,
559 'src': src,
560 'dst': dst,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000561 'outer_table_id': outer_table_id,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000562 'session_id': session_id}
563 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000564 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000565
Neale Rannsd0df49f2018-08-08 01:06:40 -0700566 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700567 src_ip,
568 dst_ip,
569 src_port,
570 dst_port,
571 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800572 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800573 :param src_ip:
574 :param dst_ip:
575 :param src_port:
576 :param dst_port:
577 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800578 """
579
580 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700581 self.papi.udp_encap_add,
582 {
583 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700584 'src_ip': src_ip,
585 'dst_ip': dst_ip,
586 'src_port': src_port,
587 'dst_port': dst_port,
588 'table_id': table_id
589 }
590 })
591
Neale Ranns097fa662018-05-01 05:17:55 -0700592 def udp_encap_del(self, id):
593 return self.api(self.papi.udp_encap_del, {'id': id})
594
595 def udp_encap_dump(self):
596 return self.api(self.papi.udp_encap_dump, {})
597
598 def want_udp_encap_stats(self, enable=1):
599 return self.api(self.papi.want_udp_encap_stats,
600 {'enable': enable,
601 'pid': os.getpid()})
602
603 def mpls_route_dump(self, table_id):
604 return self.api(self.papi.mpls_route_dump,
605 {'table': {
606 'mt_table_id': table_id
607 }})
608
609 def mpls_table_dump(self):
610 return self.api(self.papi.mpls_table_dump, {})
611
Neale Ranns15002542017-09-10 04:39:11 -0700612 def mpls_table_add_del(
613 self,
614 table_id,
615 is_add=1):
616 """
617
618 :param table_id
619 :param is_add: (Default value = 1)
620
621 """
622
623 return self.api(
624 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700625 {'mt_table':
626 {
627 'mt_table_id': table_id,
628 },
Neale Ranns15002542017-09-10 04:39:11 -0700629 'mt_is_add': is_add})
630
Neale Ranns097fa662018-05-01 05:17:55 -0700631 def mpls_route_add_del(self,
632 table_id,
633 label,
634 eos,
635 eos_proto,
636 is_multicast,
637 paths,
638 is_add,
639 is_multipath):
640 """ MPLS Route add/del """
641 return self.api(
642 self.papi.mpls_route_add_del,
643 {'mr_route':
644 {
645 'mr_table_id': table_id,
646 'mr_label': label,
647 'mr_eos': eos,
648 'mr_eos_proto': eos_proto,
649 'mr_is_multicast': is_multicast,
650 'mr_n_paths': len(paths),
651 'mr_paths': paths,
652 },
653 'mr_is_add': is_add,
654 'mr_is_multipath': is_multipath})
655
Neale Rannsad422ed2016-11-02 14:20:04 +0000656 def mpls_ip_bind_unbind(
657 self,
658 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700659 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000660 table_id=0,
661 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000662 is_bind=1):
663 """
664 """
665 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100666 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200667 {'mb_mpls_table_id': table_id,
668 'mb_label': label,
669 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200670 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700671 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000672
673 def mpls_tunnel_add_del(
674 self,
675 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700676 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000677 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800678 l2_only=0,
679 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000680 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000681 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000682 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100683 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700684 {'mt_is_add': is_add,
685 'mt_tunnel':
686 {
687 'mt_sw_if_index': tun_sw_if_index,
688 'mt_l2_only': l2_only,
689 'mt_is_multicast': is_multicast,
690 'mt_n_paths': len(paths),
691 'mt_paths': paths,
692 }})
Matus Fabiande886752016-12-07 03:38:19 -0800693
Steve Shin7957d6e2016-12-19 09:24:50 -0800694 def input_acl_set_interface(
695 self,
696 is_add,
697 sw_if_index,
698 ip4_table_index=0xFFFFFFFF,
699 ip6_table_index=0xFFFFFFFF,
700 l2_table_index=0xFFFFFFFF):
701 """
702 :param is_add:
703 :param sw_if_index:
704 :param ip4_table_index: (Default value = 0xFFFFFFFF)
705 :param ip6_table_index: (Default value = 0xFFFFFFFF)
706 :param l2_table_index: (Default value = 0xFFFFFFFF)
707 """
708
709 return self.api(
710 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100711 {'sw_if_index': sw_if_index,
712 'ip4_table_index': ip4_table_index,
713 'ip6_table_index': ip6_table_index,
714 'l2_table_index': l2_table_index,
715 'is_add': is_add})
716
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100717 def output_acl_set_interface(
718 self,
719 is_add,
720 sw_if_index,
721 ip4_table_index=0xFFFFFFFF,
722 ip6_table_index=0xFFFFFFFF,
723 l2_table_index=0xFFFFFFFF):
724 """
725 :param is_add:
726 :param sw_if_index:
727 :param ip4_table_index: (Default value = 0xFFFFFFFF)
728 :param ip6_table_index: (Default value = 0xFFFFFFFF)
729 :param l2_table_index: (Default value = 0xFFFFFFFF)
730 """
731
732 return self.api(
733 self.papi.output_acl_set_interface,
734 {'sw_if_index': sw_if_index,
735 'ip4_table_index': ip4_table_index,
736 'ip6_table_index': ip6_table_index,
737 'l2_table_index': l2_table_index,
738 'is_add': is_add})
739
Klement Sekera77fabdb2017-01-02 07:46:14 +0100740 def set_ipfix_exporter(
741 self,
742 collector_address,
743 src_address,
744 path_mtu,
745 template_interval,
746 vrf_id=0,
747 collector_port=4739,
748 udp_checksum=0):
749 return self.api(
750 self.papi.set_ipfix_exporter,
751 {
752 'collector_address': collector_address,
753 'collector_port': collector_port,
754 'src_address': src_address,
755 'vrf_id': vrf_id,
756 'path_mtu': path_mtu,
757 'template_interval': template_interval,
758 'udp_checksum': udp_checksum,
759 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800760
Neale Ranns32e1c012016-11-22 17:07:28 +0000761 def ip_mroute_add_del(self,
Neale Ranns097fa662018-05-01 05:17:55 -0700762 table_id,
763 prefix,
Neale Ranns32e1c012016-11-22 17:07:28 +0000764 e_flags,
Neale Ranns097fa662018-05-01 05:17:55 -0700765 rpf_id,
766 paths,
Neale Ranns32e1c012016-11-22 17:07:28 +0000767 is_add=1,
Neale Ranns097fa662018-05-01 05:17:55 -0700768 is_multipath=1):
Neale Ranns32e1c012016-11-22 17:07:28 +0000769 """
Neale Rannsd792d9c2017-10-21 10:53:20 -0700770 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +0000771 """
772 return self.api(
773 self.papi.ip_mroute_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700774 {
775 'is_add': is_add,
776 'is_multipath': is_multipath,
777 'route': {
778 'table_id': table_id,
779 'entry_flags': e_flags,
780 'rpf_id': rpf_id,
781 'prefix': prefix,
782 'n_paths': len(paths),
783 'paths': paths,
784 }
785 })
786
787 def mfib_signal_dump(self):
788 return self.api(self.papi.mfib_signal_dump, {})
789
790 def ip_mroute_dump(self, table_id, is_ip6=False):
791 return self.api(self.papi.ip_mroute_dump,
792 {'table': {
793 'table_id': table_id,
794 'is_ip6': is_ip6
795 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000796
Filip Tehlar770e89e2017-01-31 10:39:16 +0100797 def lisp_enable_disable(self, is_enabled):
798 return self.api(
799 self.papi.lisp_enable_disable,
800 {
801 'is_en': is_enabled,
802 })
803
Ole Troane1ade682019-03-04 23:55:43 +0100804 def lisp_add_del_locator_set(self,
805 ls_name,
806 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100807 return self.api(
808 self.papi.lisp_add_del_locator_set,
809 {
810 'is_add': is_add,
811 'locator_set_name': ls_name
812 })
813
Ole Troane1ade682019-03-04 23:55:43 +0100814 def lisp_add_del_locator(self,
815 ls_name,
816 sw_if_index,
817 priority=1,
818 weight=1,
819 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100820 return self.api(
821 self.papi.lisp_add_del_locator,
822 {
823 'is_add': is_add,
824 'locator_set_name': ls_name,
825 'sw_if_index': sw_if_index,
826 'priority': priority,
827 'weight': weight
828 })
829
830 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
831 return self.api(
832 self.papi.lisp_locator_dump,
833 {
834 'is_index_set': is_index_set,
835 'ls_name': ls_name,
836 'ls_index': ls_index,
837 })
838
Ole Troane1ade682019-03-04 23:55:43 +0100839 def lisp_add_del_local_eid(self,
840 ls_name,
841 eid_type,
842 eid,
843 prefix_len,
844 vni=0,
845 key_id=0,
846 key="",
847 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100848 return self.api(
849 self.papi.lisp_add_del_local_eid,
850 {
851 'locator_set_name': ls_name,
852 'is_add': is_add,
853 'eid_type': eid_type,
854 'eid': eid,
855 'prefix_len': prefix_len,
856 'vni': vni,
857 'key_id': key_id,
858 'key': key
859 })
860
861 def lisp_eid_table_dump(self,
862 eid_set=0,
863 prefix_length=0,
864 vni=0,
865 eid_type=0,
866 eid=None,
867 filter_opt=0):
868 return self.api(
869 self.papi.lisp_eid_table_dump,
870 {
871 'eid_set': eid_set,
872 'prefix_length': prefix_length,
873 'vni': vni,
874 'eid_type': eid_type,
875 'eid': eid,
876 'filter': filter_opt,
877 })
878
Ole Troane1ade682019-03-04 23:55:43 +0100879 def lisp_add_del_remote_mapping(self,
880 eid_type,
881 eid,
882 eid_prefix_len=0,
883 vni=0,
884 rlocs=[],
885 rlocs_num=0,
886 is_src_dst=0,
887 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100888 return self.api(
889 self.papi.lisp_add_del_remote_mapping,
890 {
891 'is_add': is_add,
892 'eid_type': eid_type,
893 'eid': eid,
894 'eid_len': eid_prefix_len,
895 'rloc_num': rlocs_num,
896 'rlocs': rlocs,
897 'vni': vni,
898 'is_src_dst': is_src_dst,
899 })
900
Ole Troane1ade682019-03-04 23:55:43 +0100901 def lisp_add_del_adjacency(self,
902 leid,
903 reid,
904 leid_len,
905 reid_len,
906 eid_type,
907 is_add=1,
908 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +0100909 return self.api(
910 self.papi.lisp_add_del_adjacency,
911 {
912 'is_add': is_add,
913 'vni': vni,
914 'eid_type': eid_type,
915 'leid': leid,
916 'reid': reid,
917 'leid_len': leid_len,
918 'reid_len': reid_len,
919 })
920
Hongjun Nief486b12017-04-12 19:21:16 +0800921 def gtpu_add_del_tunnel(
922 self,
923 src_addr,
924 dst_addr,
925 is_add=1,
926 is_ipv6=0,
927 mcast_sw_if_index=0xFFFFFFFF,
928 encap_vrf_id=0,
929 decap_next_index=0xFFFFFFFF,
930 teid=0):
931 """
932
933 :param is_add: (Default value = 1)
934 :param is_ipv6: (Default value = 0)
935 :param src_addr:
936 :param dst_addr:
937 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
938 :param encap_vrf_id: (Default value = 0)
939 :param decap_next_index: (Default value = 0xFFFFFFFF)
940 :param teid: (Default value = 0)
941
942 """
943 return self.api(self.papi.gtpu_add_del_tunnel,
944 {'is_add': is_add,
945 'is_ipv6': is_ipv6,
946 'src_address': src_addr,
947 'dst_address': dst_addr,
948 'mcast_sw_if_index': mcast_sw_if_index,
949 'encap_vrf_id': encap_vrf_id,
950 'decap_next_index': decap_next_index,
951 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800952
953 def vxlan_gpe_add_del_tunnel(
954 self,
955 src_addr,
956 dst_addr,
957 mcast_sw_if_index=0xFFFFFFFF,
958 is_add=1,
959 is_ipv6=0,
960 encap_vrf_id=0,
961 decap_vrf_id=0,
962 protocol=3,
963 vni=0):
964 """
965
966 :param local:
967 :param remote:
968 :param is_add: (Default value = 1)
969 :param is_ipv6: (Default value = 0)
970 :param encap_vrf_id: (Default value = 0)
971 :param decap_vrf_id: (Default value = 0)
972 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
973 :param protocol: (Default value = 3)
974 :param vni: (Default value = 0)
975
976 """
977 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
978 {'is_add': is_add,
979 'is_ipv6': is_ipv6,
980 'local': src_addr,
981 'remote': dst_addr,
982 'mcast_sw_if_index': mcast_sw_if_index,
983 'encap_vrf_id': encap_vrf_id,
984 'decap_vrf_id': decap_vrf_id,
985 'protocol': protocol,
986 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800987
Neale Ranns79a05f52018-09-11 07:39:43 -0700988 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
989 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000990 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200991
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800992 def pppoe_add_del_session(
993 self,
994 client_ip,
995 client_mac,
996 session_id=0,
997 is_add=1,
998 is_ipv6=0,
999 decap_vrf_id=0):
1000 """
1001
1002 :param is_add: (Default value = 1)
1003 :param is_ipv6: (Default value = 0)
1004 :param client_ip:
1005 :param session_id: (Default value = 0)
1006 :param client_mac:
1007 :param decap_vrf_id: (Default value = 0)
1008
1009 """
1010 return self.api(self.papi.pppoe_add_del_session,
1011 {'is_add': is_add,
1012 'is_ipv6': is_ipv6,
1013 'session_id': session_id,
1014 'client_ip': client_ip,
1015 'decap_vrf_id': decap_vrf_id,
1016 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001017
Neale Ranns7c922dc2018-08-30 06:12:27 -07001018 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1019 return self.api(self.papi.sr_mpls_policy_add,
1020 {'bsid': bsid,
1021 'weight': weight,
1022 'type': type,
1023 'n_segments': len(segments),
1024 'segments': segments})
1025
1026 def sr_mpls_policy_del(self, bsid):
1027 return self.api(self.papi.sr_mpls_policy_del,
1028 {'bsid': bsid})
1029
Kris Michielsen91074432017-06-22 13:00:20 +02001030 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001031 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001032 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001033 nh_addr4,
1034 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001035 is_del=0,
1036 end_psp=0,
1037 sw_if_index=0xFFFFFFFF,
1038 vlan_index=0,
1039 fib_table=0,
1040 ):
1041 """ Add/del IPv6 SR local-SID.
1042
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001043 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001044 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1045 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001046 :param nh_addr4:
1047 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001048 :param is_del: (Default value = 0)
1049 :param end_psp: (Default value = 0)
1050 :param sw_if_index: (Default value = 0xFFFFFFFF)
1051 :param vlan_index: (Default value = 0)
1052 :param fib_table: (Default value = 0)
1053 """
1054 return self.api(
1055 self.papi.sr_localsid_add_del,
1056 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001057 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001058 'end_psp': end_psp,
1059 'behavior': behavior,
1060 'sw_if_index': sw_if_index,
1061 'vlan_index': vlan_index,
1062 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001063 'nh_addr4': nh_addr4,
1064 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001065 }
1066 )
1067
1068 def sr_policy_add(
1069 self,
1070 bsid_addr,
1071 weight=1,
1072 is_encap=1,
1073 type=0,
1074 fib_table=0,
1075 n_segments=0,
1076 segments=[]):
1077 """
1078 :param bsid_addr: bindingSID of the SR Policy
1079 :param weight: weight of the sid list. optional. (default: 1)
1080 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1081 (default: Encap)
1082 :param type: type/behavior of the SR policy. (default or spray) \
1083 (default: default)
1084 :param fib_table: VRF where to install the FIB entry for the BSID \
1085 (default: 0)
1086 :param n_segments: number of segments \
1087 (default: 0)
1088 :param segments: a vector of IPv6 address composing the segment list \
1089 (default: [])
1090 """
1091 return self.api(
1092 self.papi.sr_policy_add,
1093 {'bsid_addr': bsid_addr,
1094 'weight': weight,
1095 'is_encap': is_encap,
1096 'type': type,
1097 'fib_table': fib_table,
1098 'n_segments': n_segments,
1099 'segments': segments
1100 }
1101 )
1102
1103 def sr_policy_del(
1104 self,
1105 bsid_addr,
1106 sr_policy_index=0):
1107 """
1108 :param bsid: bindingSID of the SR Policy
1109 :param sr_policy_index: index of the sr policy (default: 0)
1110 """
1111 return self.api(
1112 self.papi.sr_policy_del,
1113 {'bsid_addr': bsid_addr,
1114 'sr_policy_index': sr_policy_index
1115 })
1116
1117 def sr_steering_add_del(
1118 self,
1119 is_del,
1120 bsid_addr,
1121 sr_policy_index,
1122 table_id,
1123 prefix_addr,
1124 mask_width,
1125 sw_if_index,
1126 traffic_type):
1127 """
1128 Steer traffic L2 and L3 traffic through a given SR policy
1129
1130 :param is_del: delete or add
1131 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1132 :param sr_policy: is the index of the SR Policy (alt to bsid)
1133 :param table_id: is the VRF where to install the FIB entry for the BSID
1134 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1135 :param mask_width: is the mask for L3 traffic type
1136 :param sw_if_index: is the incoming interface for L2 traffic
1137 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1138 """
1139 return self.api(
1140 self.papi.sr_steering_add_del,
1141 {'is_del': is_del,
1142 'bsid_addr': bsid_addr,
1143 'sr_policy_index': sr_policy_index,
1144 'table_id': table_id,
1145 'prefix_addr': prefix_addr,
1146 'mask_width': mask_width,
1147 'sw_if_index': sw_if_index,
1148 'traffic_type': traffic_type
1149 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001150
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001151 def acl_add_replace(self, acl_index, r, tag='',
1152 expected_retval=0):
1153 """Add/replace an ACL
1154 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1155 :param acl_rule r: ACL rules array.
1156 :param str tag: symbolic tag (description) for this ACL.
1157 :param int count: number of rules.
1158 """
1159 return self.api(self.papi.acl_add_replace,
1160 {'acl_index': acl_index,
1161 'r': r,
1162 'count': len(r),
1163 'tag': tag},
1164 expected_retval=expected_retval)
1165
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001166 def acl_del(self, acl_index, expected_retval=0):
1167 """
1168
1169 :param acl_index:
1170 :return:
1171 """
1172 return self.api(self.papi.acl_del,
1173 {'acl_index': acl_index},
1174 expected_retval=expected_retval)
1175
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001176 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1177 expected_retval=0):
1178 return self.api(self.papi.acl_interface_set_acl_list,
1179 {'sw_if_index': sw_if_index,
1180 'count': len(acls),
1181 'n_input': n_input,
1182 'acls': acls},
1183 expected_retval=expected_retval)
1184
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001185 def acl_interface_set_etype_whitelist(self, sw_if_index,
1186 n_input, whitelist,
1187 expected_retval=0):
1188 return self.api(self.papi.acl_interface_set_etype_whitelist,
1189 {'sw_if_index': sw_if_index,
1190 'count': len(whitelist),
1191 'n_input': n_input,
1192 'whitelist': whitelist},
1193 expected_retval=expected_retval)
1194
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001195 def acl_interface_add_del(self,
1196 sw_if_index,
1197 acl_index,
1198 is_add=1):
1199 """ Add/Delete ACL to/from interface
1200
1201 :param sw_if_index:
1202 :param acl_index:
1203 :param is_add: (Default value = 1)
1204 """
1205
1206 return self.api(self.papi.acl_interface_add_del,
1207 {'is_add': is_add,
1208 'is_input': 1,
1209 'sw_if_index': sw_if_index,
1210 'acl_index': acl_index})
1211
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001212 def acl_dump(self, acl_index, expected_retval=0):
1213 return self.api(self.papi.acl_dump,
1214 {'acl_index': acl_index},
1215 expected_retval=expected_retval)
1216
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001217 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1218 expected_retval=0):
1219 return self.api(self.papi.acl_interface_list_dump,
1220 {'sw_if_index': sw_if_index},
1221 expected_retval=expected_retval)
1222
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001223 def macip_acl_add(self, rules, tag=""):
1224 """ Add MACIP acl
1225
1226 :param rules: list of rules for given acl
1227 :param tag: acl tag
1228 """
1229
1230 return self.api(self.papi.macip_acl_add,
1231 {'r': rules,
1232 'count': len(rules),
1233 'tag': tag})
1234
Pavel Kotucek932f7412017-09-07 14:44:52 +02001235 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1236 """ Add MACIP acl
1237
1238 :param rules: list of rules for given acl
1239 :param tag: acl tag
1240 """
1241
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001242 return self.api(self.papi.macip_acl_add_replace,
1243 {'acl_index': acl_index,
1244 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001245 'count': len(rules),
1246 'tag': tag})
1247
Pavel Kotucek932f7412017-09-07 14:44:52 +02001248 def macip_acl_interface_add_del(self,
1249 sw_if_index,
1250 acl_index,
1251 is_add=1):
1252 """ Add MACIP acl to interface
1253
1254 :param sw_if_index:
1255 :param acl_index:
1256 :param is_add: (Default value = 1)
1257 """
1258
1259 return self.api(self.papi.macip_acl_interface_add_del,
1260 {'is_add': is_add,
1261 'sw_if_index': sw_if_index,
1262 'acl_index': acl_index})
1263
Pavel Kotucek932f7412017-09-07 14:44:52 +02001264 def macip_acl_dump(self, acl_index=4294967295):
1265 """ Return MACIP acl dump
1266 """
1267
1268 return self.api(
1269 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001270
1271 def policer_add_del(self,
1272 name,
1273 cir,
1274 eir,
1275 cb,
1276 eb,
1277 is_add=1,
1278 rate_type=0,
1279 round_type=0,
1280 ptype=0,
1281 color_aware=0,
1282 conform_action_type=1,
1283 conform_dscp=0,
1284 exceed_action_type=0,
1285 exceed_dscp=0,
1286 violate_action_type=0,
1287 violate_dscp=0):
1288 return self.api(self.papi.policer_add_del,
1289 {'name': name,
1290 'cir': cir,
1291 'eir': eir,
1292 'cb': cb,
1293 'eb': eb,
1294 'is_add': is_add,
1295 'rate_type': rate_type,
1296 'round_type': round_type,
1297 'type': ptype,
1298 'color_aware': color_aware,
1299 'conform_action_type': conform_action_type,
1300 'conform_dscp': conform_dscp,
1301 'exceed_action_type': exceed_action_type,
1302 'exceed_dscp': exceed_dscp,
1303 'violate_action_type': violate_action_type,
1304 'violate_dscp': violate_dscp})
1305
1306 def ip_punt_police(self,
1307 policer_index,
1308 is_ip6=0,
1309 is_add=1):
1310 return self.api(self.papi.ip_punt_police,
1311 {'policer_index': policer_index,
1312 'is_add': is_add,
1313 'is_ip6': is_ip6})
1314
1315 def ip_punt_redirect(self,
1316 rx_sw_if_index,
1317 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001318 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001319 is_add=1):
1320 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001321 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1322 'tx_sw_if_index': tx_sw_if_index,
1323 'nh': address},
1324 'is_add': is_add})
1325
1326 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1327 return self.api(self.papi.ip_punt_redirect_dump,
1328 {'sw_if_index': sw_if_index,
1329 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001330
1331 def bier_table_add_del(self,
1332 bti,
1333 mpls_label,
1334 is_add=1):
1335 """ BIER Table add/del """
1336 return self.api(
1337 self.papi.bier_table_add_del,
1338 {'bt_tbl_id': {"bt_set": bti.set_id,
1339 "bt_sub_domain": bti.sub_domain_id,
1340 "bt_hdr_len_id": bti.hdr_len_id},
1341 'bt_label': mpls_label,
1342 'bt_is_add': is_add})
1343
1344 def bier_table_dump(self):
1345 return self.api(self.papi.bier_table_dump, {})
1346
1347 def bier_route_add_del(self,
1348 bti,
1349 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001350 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001351 is_add=1,
1352 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001353 """ BIER Route add/del """
1354 return self.api(
1355 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001356 {
1357 'br_route': {
1358 'br_tbl_id': {"bt_set": bti.set_id,
1359 "bt_sub_domain": bti.sub_domain_id,
1360 "bt_hdr_len_id": bti.hdr_len_id},
1361 'br_bp': bp,
1362 'br_n_paths': len(paths),
1363 'br_paths': paths,
1364 },
1365 'br_is_add': is_add,
1366 'br_is_replace': is_replace
1367 })
Neale Rannsd792d9c2017-10-21 10:53:20 -07001368
1369 def bier_route_dump(self, bti):
1370 return self.api(
1371 self.papi.bier_route_dump,
1372 {'br_tbl_id': {"bt_set": bti.set_id,
1373 "bt_sub_domain": bti.sub_domain_id,
1374 "bt_hdr_len_id": bti.hdr_len_id}})
1375
1376 def bier_imp_add(self,
1377 bti,
1378 src,
1379 ibytes,
1380 is_add=1):
1381 """ BIER Imposition Add """
1382 return self.api(
1383 self.papi.bier_imp_add,
1384 {'bi_tbl_id': {"bt_set": bti.set_id,
1385 "bt_sub_domain": bti.sub_domain_id,
1386 "bt_hdr_len_id": bti.hdr_len_id},
1387 'bi_src': src,
1388 'bi_n_bytes': len(ibytes),
1389 'bi_bytes': ibytes})
1390
1391 def bier_imp_del(self, bi_index):
1392 """ BIER Imposition del """
1393 return self.api(
1394 self.papi.bier_imp_del,
1395 {'bi_index': bi_index})
1396
1397 def bier_imp_dump(self):
1398 return self.api(self.papi.bier_imp_dump, {})
1399
1400 def bier_disp_table_add_del(self,
1401 bdti,
1402 is_add=1):
1403 """ BIER Disposition Table add/del """
1404 return self.api(
1405 self.papi.bier_disp_table_add_del,
1406 {'bdt_tbl_id': bdti,
1407 'bdt_is_add': is_add})
1408
1409 def bier_disp_table_dump(self):
1410 return self.api(self.papi.bier_disp_table_dump, {})
1411
1412 def bier_disp_entry_add_del(self,
1413 bdti,
1414 bp,
1415 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001416 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001417 next_hop,
1418 next_hop_tbl_id=0,
1419 next_hop_rpf_id=~0,
1420 next_hop_is_ip4=1,
1421 is_add=1):
1422 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001423 lstack = []
1424 while (len(lstack) < 16):
1425 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001426 return self.api(
1427 self.papi.bier_disp_entry_add_del,
1428 {'bde_tbl_id': bdti,
1429 'bde_bp': bp,
1430 'bde_payload_proto': payload_proto,
1431 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -04001432 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001433 'rpf_id': next_hop_rpf_id,
1434 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001435 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001436 'bde_is_add': is_add})
1437
1438 def bier_disp_entry_dump(self, bdti):
1439 return self.api(
1440 self.papi.bier_disp_entry_dump,
1441 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001442
Florin Coras3ea6ce22017-12-11 09:09:05 -08001443 def session_enable_disable(self, is_enabled):
1444 return self.api(
1445 self.papi.session_enable_disable,
1446 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001447
1448 def ipsec_spd_add_del(self, spd_id, is_add=1):
1449 """ SPD add/del - Wrapper to add or del ipsec SPD
1450 Sample CLI : 'ipsec spd add 1'
1451
1452 :param spd_id - SPD ID to be created in the vpp . mandatory
1453 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1454 optional
1455 :returns: reply from the API
1456 """
1457 return self.api(
1458 self.papi.ipsec_spd_add_del, {
1459 'spd_id': spd_id, 'is_add': is_add})
1460
Neale Ranns311124e2019-01-24 04:52:25 -08001461 def ipsec_spds_dump(self):
1462 return self.api(self.papi.ipsec_spds_dump, {})
1463
“mystarrocks”23f0c452017-12-11 07:11:51 -08001464 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1465 """ IPSEC interface SPD add/del - \
1466 Wrapper to associate/disassociate SPD to interface in VPP
1467 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1468
1469 :param spd_id - SPD ID to associate with the interface . mandatory
1470 :param sw_if_index - Interface Index which needs to ipsec \
1471 association mandatory
1472 :param is_add - add(1) or del(0) association with interface \
1473 (Default 1 - add) . optional
1474 :returns: reply from the API
1475 """
1476 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001477 self.papi.ipsec_interface_add_del_spd,
1478 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001479
Neale Ranns311124e2019-01-24 04:52:25 -08001480 def ipsec_spd_interface_dump(self, spd_index=None):
1481 return self.api(self.papi.ipsec_spd_interface_dump,
1482 {'spd_index': spd_index if spd_index else 0,
1483 'spd_index_valid': 1 if spd_index else 0})
1484
Neale Ranns17dcec02019-01-09 21:22:20 -08001485 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001486 sad_id,
1487 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001488 integrity_algorithm,
1489 integrity_key,
1490 crypto_algorithm,
1491 crypto_key,
1492 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001493 tunnel_src_address='',
1494 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001495 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001496 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001497 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001498 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001499 :param sad_id: security association ID
1500 :param spi: security param index of the SA in decimal
1501 :param integrity_algorithm:
1502 :param integrity_key:
1503 :param crypto_algorithm:
1504 :param crypto_key:
1505 :param protocol: AH(0) or ESP(1) protocol
1506 :param tunnel_src_address: tunnel mode outer src address
1507 :param tunnel_dst_address: tunnel mode outer dst address
1508 :param is_add:
1509 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001510 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1511 crypto and ipsec algorithms
1512 """
1513 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001514 self.papi.ipsec_sad_entry_add_del,
1515 {
1516 'is_add': is_add,
1517 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001518 {
1519 'sad_id': sad_id,
1520 'spi': spi,
1521 'tunnel_src': tunnel_src_address,
1522 'tunnel_dst': tunnel_dst_address,
1523 'protocol': protocol,
1524 'integrity_algorithm': integrity_algorithm,
1525 'integrity_key': {
1526 'length': len(integrity_key),
1527 'data': integrity_key,
1528 },
1529 'crypto_algorithm': crypto_algorithm,
1530 'crypto_key': {
1531 'length': len(crypto_key),
1532 'data': crypto_key,
1533 },
1534 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001535 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001536 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001537 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001538
Neale Ranns311124e2019-01-24 04:52:25 -08001539 def ipsec_sa_dump(self, sa_id=None):
1540 return self.api(self.papi.ipsec_sa_dump,
1541 {'sa_id': sa_id if sa_id else 0xffffffff})
1542
Neale Ranns17dcec02019-01-09 21:22:20 -08001543 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001544 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001545 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001546 local_address_start,
1547 local_address_stop,
1548 remote_address_start,
1549 remote_address_stop,
1550 local_port_start=0,
1551 local_port_stop=65535,
1552 remote_port_start=0,
1553 remote_port_stop=65535,
1554 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001555 policy=0,
1556 priority=100,
1557 is_outbound=1,
1558 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001559 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001560 is_ip_any=0):
1561 """ IPSEC policy SPD add/del -
1562 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001563 :param spd_id: SPD ID for the policy
1564 :param local_address_start: local-ip-range start address
1565 :param local_address_stop : local-ip-range stop address
1566 :param remote_address_start: remote-ip-range start address
1567 :param remote_address_stop : remote-ip-range stop address
1568 :param local_port_start: (Default value = 0)
1569 :param local_port_stop: (Default value = 65535)
1570 :param remote_port_start: (Default value = 0)
1571 :param remote_port_stop: (Default value = 65535)
1572 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1573 :param sa_id: Security Association ID for mapping it to SPD
1574 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1575 (Default value = 0)
1576 :param priority: value for the spd action (Default value = 100)
1577 :param is_outbound: flag for inbound(0) or outbound(1)
1578 (Default value = 1)
1579 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001580 """
1581 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001582 self.papi.ipsec_spd_entry_add_del,
1583 {
1584 'is_add': is_add,
1585 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001586 {
1587 'spd_id': spd_id,
1588 'sa_id': sa_id,
1589 'local_address_start': local_address_start,
1590 'local_address_stop': local_address_stop,
1591 'remote_address_start': remote_address_start,
1592 'remote_address_stop': remote_address_stop,
1593 'local_port_start': local_port_start,
1594 'local_port_stop': local_port_stop,
1595 'remote_port_start': remote_port_start,
1596 'remote_port_stop': remote_port_stop,
1597 'protocol': protocol,
1598 'policy': policy,
1599 'priority': priority,
1600 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +01001601 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001602 })
Florin Corasb795bd02017-12-14 11:30:48 -08001603
Neale Ranns311124e2019-01-24 04:52:25 -08001604 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1605 return self.api(self.papi.ipsec_spd_dump,
1606 {'spd_id': spd_id,
1607 'sa_id': sa_id})
1608
Klement Sekera31da2e32018-06-24 22:49:55 +02001609 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1610 remote_spi, crypto_alg, local_crypto_key,
1611 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001612 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001613 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +00001614 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +02001615 return self.api(
1616 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001617 {
1618 'local_ip': local_ip,
1619 'remote_ip': remote_ip,
1620 'local_spi': local_spi,
1621 'remote_spi': remote_spi,
1622 'crypto_alg': crypto_alg,
1623 'local_crypto_key_len': len(local_crypto_key),
1624 'local_crypto_key': local_crypto_key,
1625 'remote_crypto_key_len': len(remote_crypto_key),
1626 'remote_crypto_key': remote_crypto_key,
1627 'integ_alg': integ_alg,
1628 'local_integ_key_len': len(local_integ_key),
1629 'local_integ_key': local_integ_key,
1630 'remote_integ_key_len': len(remote_integ_key),
1631 'remote_integ_key': remote_integ_key,
1632 'is_add': is_add,
1633 'esn': esn,
1634 'anti_replay': anti_replay,
1635 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001636 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001637 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001638 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001639 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001640
Klement Sekerab4d30532018-11-08 13:00:02 +01001641 def ipsec_select_backend(self, protocol, index):
1642 return self.api(self.papi.ipsec_select_backend,
1643 {'protocol': protocol, 'index': index})
1644
1645 def ipsec_backend_dump(self):
1646 return self.api(self.papi.ipsec_backend_dump, {})
1647
Ole Troane1ade682019-03-04 23:55:43 +01001648 def app_namespace_add_del(self,
1649 namespace_id,
1650 ip4_fib_id=0,
1651 ip6_fib_id=0,
1652 sw_if_index=0xFFFFFFFF,
1653 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001654 return self.api(
1655 self.papi.app_namespace_add_del,
1656 {'secret': secret,
1657 'sw_if_index': sw_if_index,
1658 'ip4_fib_id': ip4_fib_id,
1659 'ip6_fib_id': ip6_fib_id,
1660 'namespace_id': namespace_id,
1661 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001662
Neale Ranns50f0ac02019-05-15 02:13:37 -07001663 def punt_socket_register(self, reg, pathname,
1664 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001665 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001666 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001667 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001668 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001669 'pathname': pathname})
1670
Neale Ranns50f0ac02019-05-15 02:13:37 -07001671 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001672 """ Unregister punt socket """
1673 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001674 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +02001675
Neale Ranns4ba67722019-02-28 11:11:39 +00001676 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001677 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001678 """ GBP endpoint Add """
1679 return self.api(self.papi.gbp_endpoint_add,
1680 {'endpoint': {
1681 'sw_if_index': sw_if_index,
1682 'ips': ips,
1683 'n_ips': len(ips),
1684 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001685 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001686 'flags': flags,
1687 'tun': {
1688 'src': tun_src,
1689 'dst': tun_dst,
1690 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001691
1692 def gbp_endpoint_del(self, handle):
1693 """ GBP endpoint Del """
1694 return self.api(self.papi.gbp_endpoint_del,
1695 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001696
1697 def gbp_endpoint_dump(self):
1698 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001699 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001700
Neale Ranns4ba67722019-02-28 11:11:39 +00001701 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001702 rd, uplink_sw_if_index,
1703 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001704 """ GBP endpoint group Add """
1705 return self.api(self.papi.gbp_endpoint_group_add,
1706 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001707 {
1708 'uplink_sw_if_index': uplink_sw_if_index,
1709 'bd_id': bd,
1710 'rd_id': rd,
1711 'vnid': vnid,
1712 'sclass': sclass,
1713 'retention': retention
1714 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001715
Neale Ranns4ba67722019-02-28 11:11:39 +00001716 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001717 """ GBP endpoint group Del """
1718 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00001719 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07001720
Neale Ranns160c9232019-06-19 06:25:56 -07001721 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001722 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08001723 uu_fwd_sw_if_index,
1724 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001725 """ GBP bridge-domain Add """
1726 return self.api(self.papi.gbp_bridge_domain_add,
1727 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01001728 {
1729 'flags': flags,
1730 'bvi_sw_if_index': bvi_sw_if_index,
1731 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
1732 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07001733 'bd_id': bd_id,
1734 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01001735 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001736
1737 def gbp_bridge_domain_del(self, bd_id):
1738 """ GBP bridge-domain Del """
1739 return self.api(self.papi.gbp_bridge_domain_del,
1740 {'bd_id': bd_id})
1741
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001742 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07001743 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001744 ip4_table_id,
1745 ip6_table_id,
1746 ip4_uu_sw_if_index,
1747 ip6_uu_sw_if_index):
1748 """ GBP route-domain Add """
1749 return self.api(self.papi.gbp_route_domain_add,
1750 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01001751 {
Neale Ranns160c9232019-06-19 06:25:56 -07001752 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01001753 'ip4_table_id': ip4_table_id,
1754 'ip6_table_id': ip6_table_id,
1755 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
1756 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
1757 'rd_id': rd_id
1758 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001759
1760 def gbp_route_domain_del(self, rd_id):
1761 """ GBP route-domain Del """
1762 return self.api(self.papi.gbp_route_domain_del,
1763 {'rd_id': rd_id})
1764
Neale Ranns4ba67722019-02-28 11:11:39 +00001765 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07001766 """ GBP recirc Add/Del """
1767 return self.api(self.papi.gbp_recirc_add_del,
1768 {'is_add': is_add,
1769 'recirc': {
1770 'is_ext': is_ext,
1771 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001772 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07001773
1774 def gbp_recirc_dump(self):
1775 """ GBP recirc Dump """
1776 return self.api(self.papi.gbp_recirc_dump, {})
1777
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001778 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08001779 """ GBP recirc Add/Del """
1780 return self.api(self.papi.gbp_ext_itf_add_del,
1781 {'is_add': is_add,
1782 'ext_itf': {
1783 'sw_if_index': sw_if_index,
1784 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001785 'rd_id': rd_id,
1786 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08001787
1788 def gbp_ext_itf_dump(self):
1789 """ GBP recirc Dump """
1790 return self.api(self.papi.gbp_ext_itf_dump, {})
1791
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001792 def gbp_subnet_add_del(self, is_add, rd_id,
1793 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07001794 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00001795 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07001796 """ GBP Subnet Add/Del """
1797 return self.api(self.papi.gbp_subnet_add_del,
1798 {'is_add': is_add,
1799 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001800 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07001801 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001802 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07001803 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001804 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07001805
1806 def gbp_subnet_dump(self):
1807 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001808 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001809
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001810 def gbp_contract_dump(self):
1811 """ GBP contract Dump """
1812 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001813
Neale Ranns8da9fc62019-03-04 14:08:11 -08001814 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001815 """ GBP VXLAN tunnel add """
1816 return self.api(self.papi.gbp_vxlan_tunnel_add,
1817 {
1818 'tunnel': {
1819 'vni': vni,
1820 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001821 'bd_rd_id': bd_rd_id,
1822 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001823 }
1824 })
1825
1826 def gbp_vxlan_tunnel_del(self, vni):
1827 """ GBP VXLAN tunnel del """
1828 return self.api(self.papi.gbp_vxlan_tunnel_del,
1829 {
1830 'vni': vni,
1831 })
1832
1833 def gbp_vxlan_tunnel_dump(self):
1834 """ GBP VXLAN tunnel add/del """
1835 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1836
Neale Ranns947ea622018-06-07 23:48:20 -07001837 def igmp_enable_disable(self, sw_if_index, enable, host):
1838 """ Enable/disable IGMP on a given interface """
1839 return self.api(self.papi.igmp_enable_disable,
1840 {'enable': enable,
1841 'mode': host,
1842 'sw_if_index': sw_if_index})
1843
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001844 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1845 """ Add/del IGMP proxy device """
1846 return self.api(self.papi.igmp_proxy_device_add_del,
1847 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1848 'add': add})
1849
1850 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1851 """ Add/del interface to/from IGMP proxy device """
1852 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1853 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1854 'add': add})
1855
Neale Ranns947ea622018-06-07 23:48:20 -07001856 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001857 """ Listen for new (S,G) on specified interface
1858
1859 :param enable: add/del
1860 :param sw_if_index: interface sw index
1861 :param saddr: source ip4 addr
1862 :param gaddr: group ip4 addr
1863 """
1864 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001865 {
1866 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001867 {
1868 'filter': filter,
1869 'sw_if_index': sw_if_index,
1870 'n_srcs': len(saddrs),
1871 'saddrs': saddrs,
1872 'gaddr': gaddr
1873 }
Neale Ranns947ea622018-06-07 23:48:20 -07001874 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001875
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001876 def igmp_clear_interface(self, sw_if_index):
1877 """ Remove all (S,G)s from specified interface
1878 doesn't send IGMP report!
1879 """
1880 return self.api(
1881 self.papi.igmp_clear_interface, {
1882 'sw_if_index': sw_if_index})
1883
1884 def want_igmp_events(self, enable=1):
1885 return self.api(self.papi.want_igmp_events, {'enable': enable,
1886 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08001887
1888 def bond_create(
1889 self,
1890 mode,
1891 lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001892 numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08001893 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001894 mac_address='',
1895 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08001896 """
1897 :param mode: mode
1898 :param lb: load balance
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001899 :param numa_only: tx on local numa node for lacp mode
Steven9cd2d7a2017-12-20 12:43:01 -08001900 :param use_custom_mac: use custom mac
1901 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001902 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08001903 """
1904 return self.api(
1905 self.papi.bond_create,
1906 {'mode': mode,
1907 'lb': lb,
Zhiyong Yang751e3f32019-06-26 05:49:14 -04001908 'numa_only': numa_only,
Steven9cd2d7a2017-12-20 12:43:01 -08001909 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05001910 'mac_address': mac_address,
1911 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08001912 })
1913
Neale Ranns17ff3c12018-07-04 10:24:24 -07001914 def pipe_delete(self, parent_sw_if_index):
1915 return self.api(self.papi.pipe_delete,
1916 {'parent_sw_if_index': parent_sw_if_index})
1917
Neale Rannsd1e68ab2018-10-01 01:42:13 -07001918 def svs_table_add_del(self, af, table_id, is_add=1):
1919 return self.api(self.papi.svs_table_add_del,
1920 {
1921 'table_id': table_id,
1922 'is_add': is_add,
1923 'af': af,
1924 })
1925
1926 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
1927 return self.api(self.papi.svs_route_add_del,
1928 {
1929 'table_id': table_id,
1930 'source_table_id': src_table_id,
1931 'prefix': prefix,
1932 'is_add': is_add,
1933 })
1934
1935 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
1936 return self.api(self.papi.svs_enable_disable,
1937 {
1938 'af': af,
1939 'table_id': table_id,
1940 'sw_if_index': sw_if_index,
1941 'is_enable': is_enable,
1942 })
Mohsin Kazmi29467b52019-10-08 19:42:38 +02001943
1944 def feature_gso_enable_disable(self, sw_if_index, enable_disable=1):
1945 return self.api(self.papi.feature_gso_enable_disable,
1946 {
1947 'sw_if_index': sw_if_index,
1948 'enable_disable': enable_disable,
1949 })