blob: d677ab316b29836249ac585e6f013902630dbcab [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
Ole Troan4376ab22021-03-03 10:40:05 +010011import queue
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
Ole Troanf159f582019-02-28 20:20:47 +010017#
18# Dictionary keyed on message name to override default values for
19# named parameters
20#
Ole Troan9a475372019-03-05 16:58:24 +010021defaultmapping = {
Paul Vinciguerrac0e94412020-04-28 01:12:04 -040022
Ole Troan9a475372019-03-05 16:58:24 +010023 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
Ole Troan9a475372019-03-05 16:58:24 +010024 'bd_ip_mac_add_del': {'is_add': 1, },
Jakub Grajciar4682feb2019-09-02 13:28:52 +020025 'bfd_udp_add': {'is_authenticated': False, 'bfd_key_id': None,
26 'conf_key_id': None},
27 'bfd_udp_auth_activate': {'bfd_key_id': None, 'conf_key_id': None,
28 'is_delayed': False},
Ole Troan9a475372019-03-05 16:58:24 +010029 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
30 'is_add': 1, },
31 'bier_disp_table_add_del': {'is_add': 1, },
32 'bier_imp_add': {'is_add': 1, },
33 'bier_route_add_del': {'is_add': 1, },
34 'bier_table_add_del': {'is_add': 1, },
35 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
36 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070037 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010038 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
39 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
40 'decap_next_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010041 'input_acl_set_interface': {'ip4_table_index': 4294967295,
42 'ip6_table_index': 4294967295,
43 'l2_table_index': 4294967295, },
44 'ip6_add_del_address_using_prefix': {'is_add': 1, },
45 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
46 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
47 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
Ole Troan9a475372019-03-05 16:58:24 +010048 'classify_table_index': 4294967295, 'is_add': 1, },
49 'ip_mroute_add_del': {'is_add': 1, },
50 'ip_neighbor_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010051 'ipsec_interface_add_del_spd': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010052 'ipsec_spd_add_del': {'is_add': 1, },
53 'ipsec_spd_dump': {'sa_id': 4294967295, },
54 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
55 'remote_port_stop': 65535, 'priority': 100,
56 'is_outbound': 1,
57 'is_add': 1, },
58 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
59 'l2_emulation': {'enable': 1, },
60 'l2fib_add_del': {'is_add': 1, },
61 'lisp_add_del_adjacency': {'is_add': 1, },
62 'lisp_add_del_local_eid': {'is_add': 1, },
63 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
64 'lisp_add_del_locator_set': {'is_add': 1, },
65 'lisp_add_del_remote_mapping': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010066 'macip_acl_interface_add_del': {'is_add': 1, },
67 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010068 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
69 'mr_next_hop_weight': 1,
70 'mr_next_hop_via_label': 1048576,
71 'mr_is_add': 1,
72 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010073 'mpls_table_add_del': {'is_add': 1, },
74 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
75 'next_hop_weight': 1,
76 'next_hop_via_label': 1048576,
77 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010078 'output_acl_set_interface': {'ip4_table_index': 4294967295,
79 'ip6_table_index': 4294967295,
80 'l2_table_index': 4294967295, },
81 'pppoe_add_del_session': {'is_add': 1, },
Jakub Grajciarcd01fb42020-03-02 13:16:53 +010082 'policer_add_del': {'is_add': 1, 'conform_action': {'type': 1}, },
Ole Troan9a475372019-03-05 16:58:24 +010083 'set_ipfix_exporter': {'collector_port': 4739, },
Ole Troan9a475372019-03-05 16:58:24 +010084 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010085 'sw_interface_add_del_address': {'is_add': 1, },
86 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
87 'pref_lifetime': 4294967295, },
88 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
89 'sw_interface_set_l2_bridge': {'enable': 1, },
90 'sw_interface_set_mpls_enable': {'enable': 1, },
91 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
92 'sw_interface_set_unnumbered': {'is_add': 1, },
93 'sw_interface_span_enable_disable': {'state': 1, },
94 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
95 'decap_next_index': 4294967295,
96 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010097 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
98 'protocol': 3, },
99 'want_bfd_events': {'enable_disable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100100 'want_igmp_events': {'enable': 1, },
101 'want_interface_events': {'enable_disable': 1, },
Jakub Grajciar145e3302019-10-24 13:52:42 +0200102 'want_l2_macs_events': {'enable_disable': 1, 'pid': os.getpid(), },
Jerome Tollet0f8d1002021-01-07 12:44:17 +0100103 'want_l2_macs_events2': {'enable_disable': 1, 'pid': os.getpid(), },
Ole Troan9a475372019-03-05 16:58:24 +0100104}
Ole Troanf159f582019-02-28 20:20:47 +0100105
Matus Fabianb4515b42018-11-19 04:25:32 -0800106
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400107def as_fn_signature(d):
108 return ", ".join(f"{k}={v}" for k, v in d.items())
109
110
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400111class CliFailedCommandError(Exception):
112 """ cli command failed."""
113
114
115class CliSyntaxError(Exception):
116 """ cli command had a syntax error."""
117
118
Klement Sekera73884482017-02-23 09:26:30 +0100119class UnexpectedApiReturnValueError(Exception):
120 """ exception raised when the API return value is unexpected """
121 pass
122
123
Klement Sekeraf62ae122016-10-11 11:47:09 +0200124class VppPapiProvider(object):
125 """VPP-api provider using vpp-papi
126
127 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200128 """
129
Klement Sekerae0545ef2017-01-25 08:00:40 +0100130 _zero, _negative = range(2)
131
Ole Troan4376ab22021-03-03 10:40:05 +0100132 def __init__(self, name, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800133 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200134 self.name = name
Klement Sekera7bb873a2016-11-18 07:38:42 +0100135 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100136 self._expect_api_retval = self._zero
137 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100138
Paul Vinciguerra19542292019-03-17 17:34:46 -0700139 # install_dir is a class attribute. We need to set it before
140 # calling the constructor.
141 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800142
Paul Vinciguerra19542292019-03-17 17:34:46 -0700143 self.vpp = VPPApiClient(logger=test_class.logger,
144 read_timeout=read_timeout,
Ole Troan4376ab22021-03-03 10:40:05 +0100145 use_socket=True,
Paul Vinciguerra19542292019-03-17 17:34:46 -0700146 server_address=test_class.api_sock)
Ole Troan4376ab22021-03-03 10:40:05 +0100147 self._events = queue.Queue()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200148
Klement Sekerae0545ef2017-01-25 08:00:40 +0100149 def __enter__(self):
150 return self
151
Klement Sekera7d6afb32018-11-08 11:52:04 +0100152 def assert_negative_api_retval(self):
153 """ Expect API failure - used with with, e.g.:
154 with self.vapi.assert_negative_api_retval():
155 self.vapi.<api call expected to fail>
156 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100157 self._expect_stack.append(self._expect_api_retval)
158 self._expect_api_retval = self._negative
159 return self
160
Klement Sekera7d6afb32018-11-08 11:52:04 +0100161 def assert_zero_api_retval(self):
162 """ Expect API success - used with with, e.g.:
163 with self.vapi.assert_negative_api_retval():
164 self.vapi.<api call expected to succeed>
165
166 note: this is useful only inside another with block
167 as success is the default expected value
168 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100169 self._expect_stack.append(self._expect_api_retval)
170 self._expect_api_retval = self._zero
171 return self
172
173 def __exit__(self, exc_type, exc_value, traceback):
174 self._expect_api_retval = self._expect_stack.pop()
175
Klement Sekeraf62ae122016-10-11 11:47:09 +0200176 def register_hook(self, hook):
177 """Replace hook registration with new hook
178
179 :param hook:
180
181 """
182 self.hook = hook
183
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200184 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100185 """ Collect all events from the internal queue and clear the queue. """
Ole Troan4376ab22021-03-03 10:40:05 +0100186 result = []
187 while True:
188 try:
189 e = self._events.get(block=False)
190 result.append(e)
191 except queue.Empty:
192 return result
193 return result
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200194
195 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100196 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100197 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100198 self.test_class.logger.debug("Expecting event '%s' within %ss",
199 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300200 else:
201 self.test_class.logger.debug("Expecting event within %ss",
202 timeout)
Ole Troan4376ab22021-03-03 10:40:05 +0100203 try:
204 e = self._events.get(timeout=timeout)
205 except queue.Empty:
206 raise Exception("Event did not occur within timeout")
207 msgname = type(e).__name__
208 if name and msgname != name:
209 raise Exception("Unexpected event received: %s, expected: %s"
210 % msgname)
211 self.test_class.logger.debug("Returning event %s:%s" % (name, e))
212 return e
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200213
214 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100215 """ Enqueue event in the internal event queue. """
Klement Sekerae4504c62016-12-08 10:16:41 +0100216 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Ole Troan4376ab22021-03-03 10:40:05 +0100217 self._events.put(event)
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200218
Ole Troanf159f582019-02-28 20:20:47 +0100219 def factory(self, name, apifn):
220 def f(*a, **ka):
221 fields = apifn._func.msg.fields
222
223 # add positional and kw arguments
224 d = ka
225 for i, o in enumerate(fields[3:]):
226 try:
227 d[o] = a[i]
Jakub Grajciar4682feb2019-09-02 13:28:52 +0200228 except BaseException:
Ole Troanf159f582019-02-28 20:20:47 +0100229 break
230
231 # Default override
232 if name in defaultmapping:
233 for k, v in iteritems(defaultmapping[name]):
234 if k in d:
235 continue
236 d[k] = v
237 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100238
Ole Troanf159f582019-02-28 20:20:47 +0100239 return f
240
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800241 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100242 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800243 method = super(VppPapiProvider, self).__getattribute__(name)
244 except AttributeError:
245 method = self.factory(name, getattr(self.papi, name))
246 # lazily load the method so we don't need to call factory
247 # again for this name.
248 setattr(self, name, method)
249 return method
Ole Troanf159f582019-02-28 20:20:47 +0100250
Klement Sekeraf62ae122016-10-11 11:47:09 +0200251 def connect(self):
252 """Connect the API to VPP"""
Ole Troan4376ab22021-03-03 10:40:05 +0100253 # This might be called before VPP is prepared to listen to the socket
254 retries = 0
255 while not os.path.exists(self.test_class.api_sock):
256 time.sleep(0.5)
257 retries += 1
258 if retries > 120:
259 break
260 self.vpp.connect(self.name[:63])
Klement Sekera7112c542017-03-01 09:53:19 +0100261 self.papi = self.vpp.api
262 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200263
264 def disconnect(self):
265 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100266 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200267
268 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100269 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200270 Call the appropriate hooks before and after the API call
271
272 :param api_fn: API function to call
273 :param api_args: tuple of API function arguments
274 :param expected_retval: Expected return value (Default value = 0)
275 :returns: reply from the API
276
277 """
278 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100279 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100280 if self._expect_api_retval == self._negative:
281 if hasattr(reply, 'retval') and reply.retval >= 0:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400282 msg = "%s(%s) passed unexpectedly: expected negative " \
Ole Troan9a475372019-03-05 16:58:24 +0100283 "return value instead of %d in %s" % \
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400284 (api_fn.__name__, as_fn_signature(api_args),
285 reply.retval,
286 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100287 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100288 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100289 elif self._expect_api_retval == self._zero:
290 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Paul Vinciguerra0b0a84c2020-05-02 10:40:33 -0400291 msg = "%s(%s) failed, expected %d return value instead " \
292 "of %d in %s" % (api_fn.__name__,
293 as_fn_signature(api_args),
294 expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400295 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100296 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100297 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100298 else:
299 raise Exception("Internal error, unexpected value for "
300 "self._expect_api_retval %s" %
301 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200302 self.hook.after_api(api_fn.__name__, api_args)
303 return reply
304
Dave Barach5932ce12019-10-09 17:28:04 -0400305 def cli_return_response(self, cli):
306 """ Execute a CLI, calling the before/after hooks appropriately.
307 Return the reply without examining it
308
309 :param cli: CLI to execute
310 :returns: response object
311
312 """
313 self.hook.before_cli(cli)
314 cli += '\n'
315 r = self.papi.cli_inband(cmd=cli)
316 self.hook.after_cli(cli)
317 return r
318
Klement Sekeraf62ae122016-10-11 11:47:09 +0200319 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100320 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200321
322 :param cli: CLI to execute
323 :returns: CLI output
324
325 """
Dave Barach5932ce12019-10-09 17:28:04 -0400326 r = self.cli_return_response(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400327 if r.retval == -156:
328 raise CliSyntaxError(r.reply)
329 if r.retval != 0:
330 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200331 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100332 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200333
Jan49c0fca2016-10-26 15:44:27 +0200334 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100335 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200336
337 :param cli: CLI to execute
338 :returns: CLI output
339 """
Ole Troan6ed154f2019-10-15 19:31:55 +0200340 return cli + "\n" + self.cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200341
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100342 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
343 mrc=0, mrd=0):
344 return self.api(self.papi.ip6nd_send_router_solicitation,
345 {'irt': irt,
346 'mrt': mrt,
347 'mrc': mrc,
348 'mrd': mrd,
349 'sw_if_index': sw_if_index})
350
Juraj Slobodab3f90502018-10-04 15:15:16 +0200351 def want_interface_events(self, enable_disable=1):
352 return self.api(self.papi.want_interface_events,
353 {'enable_disable': enable_disable,
354 'pid': os.getpid(), })
355
Neale Rannsc819fc62018-02-16 02:44:05 -0800356 def sw_interface_set_mac_address(self, sw_if_index, mac):
357 return self.api(self.papi.sw_interface_set_mac_address,
358 {'sw_if_index': sw_if_index,
359 'mac_address': mac})
360
Ole Troane1ade682019-03-04 23:55:43 +0100361 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200362 """Create p2p ethernet subinterface
363
364 :param sw_if_index: main (parent) interface
365 :param remote_mac: client (remote) mac address
366
367 """
368 return self.api(
369 self.papi.p2p_ethernet_add,
370 {'parent_if_index': sw_if_index,
371 'remote_mac': remote_mac,
372 'subif_id': subif_id})
373
Ole Troane1ade682019-03-04 23:55:43 +0100374 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200375 """Delete p2p ethernet subinterface
376
377 :param sw_if_index: main (parent) interface
378 :param remote_mac: client (remote) mac address
379
380 """
381 return self.api(
382 self.papi.p2p_ethernet_del,
383 {'parent_if_index': sw_if_index,
384 'remote_mac': remote_mac})
385
Klement Sekeraf62ae122016-10-11 11:47:09 +0200386 def create_vlan_subif(self, sw_if_index, vlan):
387 """
388
389 :param vlan:
390 :param sw_if_index:
391
392 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100393 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200394 {'sw_if_index': sw_if_index,
395 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200396
Matej Klotton0178d522016-11-04 11:11:44 +0100397 def create_loopback(self, mac=''):
398 """
399
400 :param mac: (Optional)
401 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100402 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200403 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100404
Neale Ranns097fa662018-05-01 05:17:55 -0700405 def ip_route_dump(self, table_id, is_ip6=False):
406 return self.api(self.papi.ip_route_dump,
407 {'table': {
408 'table_id': table_id,
409 'is_ip6': is_ip6
410 }})
411
Neale Ranns976b2592019-12-04 06:11:00 +0000412 def ip_route_v2_dump(self, table_id, is_ip6=False, src=0):
413 return self.api(self.papi.ip_route_v2_dump,
414 {
415 'src': src,
416 'table': {
417 'table_id': table_id,
418 'is_ip6': is_ip6
419 }
420 })
421
Matej Klotton0178d522016-11-04 11:11:44 +0100422 def ip_neighbor_add_del(self,
423 sw_if_index,
424 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700425 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100426 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700427 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100428 """ Add neighbor MAC to IPv4 or IPv6 address.
429
430 :param sw_if_index:
431 :param mac_address:
432 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100433 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700434 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100435 """
Matej Klotton0178d522016-11-04 11:11:44 +0100436 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100437 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700438 {
439 'is_add': is_add,
440 'neighbor': {
441 'sw_if_index': sw_if_index,
442 'flags': flags,
443 'mac_address': mac_address,
444 'ip_address': ip_address
445 }
446 }
Matej Klotton0178d522016-11-04 11:11:44 +0100447 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100448
Neale Rannsd0df49f2018-08-08 01:06:40 -0700449 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700450 src_ip,
451 dst_ip,
452 src_port,
453 dst_port,
454 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800455 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800456 :param src_ip:
457 :param dst_ip:
458 :param src_port:
459 :param dst_port:
460 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800461 """
462
463 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700464 self.papi.udp_encap_add,
465 {
466 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700467 'src_ip': src_ip,
468 'dst_ip': dst_ip,
469 'src_port': src_port,
470 'dst_port': dst_port,
471 'table_id': table_id
472 }
473 })
474
Neale Ranns097fa662018-05-01 05:17:55 -0700475 def udp_encap_del(self, id):
476 return self.api(self.papi.udp_encap_del, {'id': id})
477
478 def udp_encap_dump(self):
479 return self.api(self.papi.udp_encap_dump, {})
480
481 def want_udp_encap_stats(self, enable=1):
482 return self.api(self.papi.want_udp_encap_stats,
483 {'enable': enable,
484 'pid': os.getpid()})
485
486 def mpls_route_dump(self, table_id):
487 return self.api(self.papi.mpls_route_dump,
488 {'table': {
489 'mt_table_id': table_id
490 }})
491
492 def mpls_table_dump(self):
493 return self.api(self.papi.mpls_table_dump, {})
494
Neale Ranns15002542017-09-10 04:39:11 -0700495 def mpls_table_add_del(
496 self,
497 table_id,
498 is_add=1):
499 """
500
501 :param table_id
502 :param is_add: (Default value = 1)
503
504 """
505
506 return self.api(
507 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700508 {'mt_table':
509 {
510 'mt_table_id': table_id,
511 },
Neale Ranns15002542017-09-10 04:39:11 -0700512 'mt_is_add': is_add})
513
Neale Ranns097fa662018-05-01 05:17:55 -0700514 def mpls_route_add_del(self,
515 table_id,
516 label,
517 eos,
518 eos_proto,
519 is_multicast,
520 paths,
521 is_add,
522 is_multipath):
523 """ MPLS Route add/del """
524 return self.api(
525 self.papi.mpls_route_add_del,
526 {'mr_route':
527 {
528 'mr_table_id': table_id,
529 'mr_label': label,
530 'mr_eos': eos,
531 'mr_eos_proto': eos_proto,
532 'mr_is_multicast': is_multicast,
533 'mr_n_paths': len(paths),
534 'mr_paths': paths,
535 },
536 'mr_is_add': is_add,
537 'mr_is_multipath': is_multipath})
538
Neale Rannsad422ed2016-11-02 14:20:04 +0000539 def mpls_ip_bind_unbind(
540 self,
541 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700542 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000543 table_id=0,
544 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000545 is_bind=1):
546 """
547 """
548 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100549 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200550 {'mb_mpls_table_id': table_id,
551 'mb_label': label,
552 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200553 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700554 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000555
556 def mpls_tunnel_add_del(
557 self,
558 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700559 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000560 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800561 l2_only=0,
562 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000563 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000564 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000565 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100566 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700567 {'mt_is_add': is_add,
568 'mt_tunnel':
569 {
570 'mt_sw_if_index': tun_sw_if_index,
571 'mt_l2_only': l2_only,
572 'mt_is_multicast': is_multicast,
573 'mt_n_paths': len(paths),
574 'mt_paths': paths,
575 }})
Matus Fabiande886752016-12-07 03:38:19 -0800576
Steve Shin7957d6e2016-12-19 09:24:50 -0800577 def input_acl_set_interface(
578 self,
579 is_add,
580 sw_if_index,
581 ip4_table_index=0xFFFFFFFF,
582 ip6_table_index=0xFFFFFFFF,
583 l2_table_index=0xFFFFFFFF):
584 """
585 :param is_add:
586 :param sw_if_index:
587 :param ip4_table_index: (Default value = 0xFFFFFFFF)
588 :param ip6_table_index: (Default value = 0xFFFFFFFF)
589 :param l2_table_index: (Default value = 0xFFFFFFFF)
590 """
591
592 return self.api(
593 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100594 {'sw_if_index': sw_if_index,
595 'ip4_table_index': ip4_table_index,
596 'ip6_table_index': ip6_table_index,
597 'l2_table_index': l2_table_index,
598 'is_add': is_add})
599
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100600 def output_acl_set_interface(
601 self,
602 is_add,
603 sw_if_index,
604 ip4_table_index=0xFFFFFFFF,
605 ip6_table_index=0xFFFFFFFF,
606 l2_table_index=0xFFFFFFFF):
607 """
608 :param is_add:
609 :param sw_if_index:
610 :param ip4_table_index: (Default value = 0xFFFFFFFF)
611 :param ip6_table_index: (Default value = 0xFFFFFFFF)
612 :param l2_table_index: (Default value = 0xFFFFFFFF)
613 """
614
615 return self.api(
616 self.papi.output_acl_set_interface,
617 {'sw_if_index': sw_if_index,
618 'ip4_table_index': ip4_table_index,
619 'ip6_table_index': ip6_table_index,
620 'l2_table_index': l2_table_index,
621 'is_add': is_add})
622
Klement Sekera77fabdb2017-01-02 07:46:14 +0100623 def set_ipfix_exporter(
624 self,
625 collector_address,
626 src_address,
627 path_mtu,
628 template_interval,
629 vrf_id=0,
630 collector_port=4739,
631 udp_checksum=0):
632 return self.api(
633 self.papi.set_ipfix_exporter,
634 {
635 'collector_address': collector_address,
636 'collector_port': collector_port,
637 'src_address': src_address,
638 'vrf_id': vrf_id,
639 'path_mtu': path_mtu,
640 'template_interval': template_interval,
641 'udp_checksum': udp_checksum,
642 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800643
Neale Ranns097fa662018-05-01 05:17:55 -0700644 def mfib_signal_dump(self):
645 return self.api(self.papi.mfib_signal_dump, {})
646
647 def ip_mroute_dump(self, table_id, is_ip6=False):
648 return self.api(self.papi.ip_mroute_dump,
649 {'table': {
650 'table_id': table_id,
651 'is_ip6': is_ip6
652 }})
Neale Ranns32e1c012016-11-22 17:07:28 +0000653
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +0800654 def vxlan_gpe_add_del_tunnel(
655 self,
656 src_addr,
657 dst_addr,
658 mcast_sw_if_index=0xFFFFFFFF,
659 is_add=1,
660 is_ipv6=0,
661 encap_vrf_id=0,
662 decap_vrf_id=0,
663 protocol=3,
664 vni=0):
665 """
666
667 :param local:
668 :param remote:
669 :param is_add: (Default value = 1)
670 :param is_ipv6: (Default value = 0)
671 :param encap_vrf_id: (Default value = 0)
672 :param decap_vrf_id: (Default value = 0)
673 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
674 :param protocol: (Default value = 3)
675 :param vni: (Default value = 0)
676
677 """
678 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
679 {'is_add': is_add,
680 'is_ipv6': is_ipv6,
681 'local': src_addr,
682 'remote': dst_addr,
683 'mcast_sw_if_index': mcast_sw_if_index,
684 'encap_vrf_id': encap_vrf_id,
685 'decap_vrf_id': decap_vrf_id,
686 'protocol': protocol,
687 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800688
Neale Ranns79a05f52018-09-11 07:39:43 -0700689 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
690 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Neale Rannsefd7bc22019-11-11 08:32:34 +0000691 {'sw_if_index': sw_if_index})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +0200692
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800693 def pppoe_add_del_session(
694 self,
695 client_ip,
696 client_mac,
697 session_id=0,
698 is_add=1,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800699 decap_vrf_id=0):
700 """
701
702 :param is_add: (Default value = 1)
703 :param is_ipv6: (Default value = 0)
704 :param client_ip:
705 :param session_id: (Default value = 0)
706 :param client_mac:
707 :param decap_vrf_id: (Default value = 0)
708
709 """
710 return self.api(self.papi.pppoe_add_del_session,
711 {'is_add': is_add,
Hongjun Ni62f9cdd2017-07-04 20:11:57 +0800712 'session_id': session_id,
713 'client_ip': client_ip,
714 'decap_vrf_id': decap_vrf_id,
715 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +0200716
Neale Ranns7c922dc2018-08-30 06:12:27 -0700717 def sr_mpls_policy_add(self, bsid, weight, type, segments):
718 return self.api(self.papi.sr_mpls_policy_add,
719 {'bsid': bsid,
720 'weight': weight,
Jakub Grajciar00ec4012020-01-31 10:17:29 +0100721 'is_spray': type,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700722 'n_segments': len(segments),
723 'segments': segments})
724
725 def sr_mpls_policy_del(self, bsid):
726 return self.api(self.papi.sr_mpls_policy_del,
727 {'bsid': bsid})
728
Neale Rannsd792d9c2017-10-21 10:53:20 -0700729 def bier_table_add_del(self,
730 bti,
731 mpls_label,
732 is_add=1):
733 """ BIER Table add/del """
734 return self.api(
735 self.papi.bier_table_add_del,
736 {'bt_tbl_id': {"bt_set": bti.set_id,
737 "bt_sub_domain": bti.sub_domain_id,
738 "bt_hdr_len_id": bti.hdr_len_id},
739 'bt_label': mpls_label,
740 'bt_is_add': is_add})
741
742 def bier_table_dump(self):
743 return self.api(self.papi.bier_table_dump, {})
744
745 def bier_route_add_del(self,
746 bti,
747 bp,
Neale Ranns91286372017-12-05 13:24:04 -0800748 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -0700749 is_add=1,
750 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -0700751 """ BIER Route add/del """
752 return self.api(
753 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700754 {
755 'br_route': {
756 'br_tbl_id': {"bt_set": bti.set_id,
757 "bt_sub_domain": bti.sub_domain_id,
758 "bt_hdr_len_id": bti.hdr_len_id},
759 'br_bp': bp,
760 'br_n_paths': len(paths),
761 'br_paths': paths,
762 },
763 'br_is_add': is_add,
764 'br_is_replace': is_replace
765 })
Neale Rannsd792d9c2017-10-21 10:53:20 -0700766
767 def bier_route_dump(self, bti):
768 return self.api(
769 self.papi.bier_route_dump,
770 {'br_tbl_id': {"bt_set": bti.set_id,
771 "bt_sub_domain": bti.sub_domain_id,
772 "bt_hdr_len_id": bti.hdr_len_id}})
773
774 def bier_imp_add(self,
775 bti,
776 src,
777 ibytes,
778 is_add=1):
779 """ BIER Imposition Add """
780 return self.api(
781 self.papi.bier_imp_add,
782 {'bi_tbl_id': {"bt_set": bti.set_id,
783 "bt_sub_domain": bti.sub_domain_id,
784 "bt_hdr_len_id": bti.hdr_len_id},
785 'bi_src': src,
786 'bi_n_bytes': len(ibytes),
787 'bi_bytes': ibytes})
788
789 def bier_imp_del(self, bi_index):
790 """ BIER Imposition del """
791 return self.api(
792 self.papi.bier_imp_del,
793 {'bi_index': bi_index})
794
795 def bier_imp_dump(self):
796 return self.api(self.papi.bier_imp_dump, {})
797
798 def bier_disp_table_add_del(self,
799 bdti,
800 is_add=1):
801 """ BIER Disposition Table add/del """
802 return self.api(
803 self.papi.bier_disp_table_add_del,
804 {'bdt_tbl_id': bdti,
805 'bdt_is_add': is_add})
806
807 def bier_disp_table_dump(self):
808 return self.api(self.papi.bier_disp_table_dump, {})
809
810 def bier_disp_entry_add_del(self,
811 bdti,
812 bp,
813 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -0800814 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700815 next_hop,
816 next_hop_tbl_id=0,
817 next_hop_rpf_id=~0,
818 next_hop_is_ip4=1,
819 is_add=1):
820 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -0800821 lstack = []
822 while (len(lstack) < 16):
823 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -0700824 return self.api(
825 self.papi.bier_disp_entry_add_del,
826 {'bde_tbl_id': bdti,
827 'bde_bp': bp,
828 'bde_payload_proto': payload_proto,
829 'bde_n_paths': 1,
Paul Vinciguerra79a32a42019-07-11 19:09:30 -0400830 'bde_paths': [{'table_id': next_hop_tbl_id,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700831 'rpf_id': next_hop_rpf_id,
832 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -0800833 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -0700834 'bde_is_add': is_add})
835
836 def bier_disp_entry_dump(self, bdti):
837 return self.api(
838 self.papi.bier_disp_entry_dump,
839 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +0200840
“mystarrocks”23f0c452017-12-11 07:11:51 -0800841 def ipsec_spd_add_del(self, spd_id, is_add=1):
842 """ SPD add/del - Wrapper to add or del ipsec SPD
843 Sample CLI : 'ipsec spd add 1'
844
845 :param spd_id - SPD ID to be created in the vpp . mandatory
846 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
847 optional
848 :returns: reply from the API
849 """
850 return self.api(
851 self.papi.ipsec_spd_add_del, {
852 'spd_id': spd_id, 'is_add': is_add})
853
Neale Ranns311124e2019-01-24 04:52:25 -0800854 def ipsec_spds_dump(self):
855 return self.api(self.papi.ipsec_spds_dump, {})
856
“mystarrocks”23f0c452017-12-11 07:11:51 -0800857 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
858 """ IPSEC interface SPD add/del - \
859 Wrapper to associate/disassociate SPD to interface in VPP
860 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
861
862 :param spd_id - SPD ID to associate with the interface . mandatory
863 :param sw_if_index - Interface Index which needs to ipsec \
864 association mandatory
865 :param is_add - add(1) or del(0) association with interface \
866 (Default 1 - add) . optional
867 :returns: reply from the API
868 """
869 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +0200870 self.papi.ipsec_interface_add_del_spd,
871 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -0800872
Neale Ranns311124e2019-01-24 04:52:25 -0800873 def ipsec_spd_interface_dump(self, spd_index=None):
874 return self.api(self.papi.ipsec_spd_interface_dump,
875 {'spd_index': spd_index if spd_index else 0,
876 'spd_index_valid': 1 if spd_index else 0})
877
Neale Ranns17dcec02019-01-09 21:22:20 -0800878 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800879 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +0200880 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800881 local_address_start,
882 local_address_stop,
883 remote_address_start,
884 remote_address_stop,
885 local_port_start=0,
886 local_port_stop=65535,
887 remote_port_start=0,
888 remote_port_stop=65535,
889 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800890 policy=0,
891 priority=100,
892 is_outbound=1,
893 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +0200894 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -0800895 is_ip_any=0):
896 """ IPSEC policy SPD add/del -
897 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +0200898 :param spd_id: SPD ID for the policy
899 :param local_address_start: local-ip-range start address
900 :param local_address_stop : local-ip-range stop address
901 :param remote_address_start: remote-ip-range start address
902 :param remote_address_stop : remote-ip-range stop address
903 :param local_port_start: (Default value = 0)
904 :param local_port_stop: (Default value = 65535)
905 :param remote_port_start: (Default value = 0)
906 :param remote_port_stop: (Default value = 65535)
907 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
908 :param sa_id: Security Association ID for mapping it to SPD
909 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
910 (Default value = 0)
911 :param priority: value for the spd action (Default value = 100)
912 :param is_outbound: flag for inbound(0) or outbound(1)
913 (Default value = 1)
914 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -0800915 """
916 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -0800917 self.papi.ipsec_spd_entry_add_del,
918 {
919 'is_add': is_add,
920 'entry':
Ole Troan9a475372019-03-05 16:58:24 +0100921 {
922 'spd_id': spd_id,
923 'sa_id': sa_id,
924 'local_address_start': local_address_start,
925 'local_address_stop': local_address_stop,
926 'remote_address_start': remote_address_start,
927 'remote_address_stop': remote_address_stop,
928 'local_port_start': local_port_start,
929 'local_port_stop': local_port_stop,
930 'remote_port_start': remote_port_start,
931 'remote_port_stop': remote_port_stop,
932 'protocol': protocol,
933 'policy': policy,
934 'priority': priority,
935 'is_outbound': is_outbound,
Ole Troan9a475372019-03-05 16:58:24 +0100936 }
Neale Ranns17dcec02019-01-09 21:22:20 -0800937 })
Florin Corasb795bd02017-12-14 11:30:48 -0800938
Neale Ranns311124e2019-01-24 04:52:25 -0800939 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
940 return self.api(self.papi.ipsec_spd_dump,
941 {'spd_id': spd_id,
942 'sa_id': sa_id})
943
Klement Sekera31da2e32018-06-24 22:49:55 +0200944 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
945 remote_spi, crypto_alg, local_crypto_key,
946 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000947 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700948 anti_replay=1, renumber=0,
Neale Ranns12989b52019-09-26 16:20:19 +0000949 udp_encap=0, show_instance=0xffffffff):
Klement Sekera31da2e32018-06-24 22:49:55 +0200950 return self.api(
951 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400952 {
953 'local_ip': local_ip,
954 'remote_ip': remote_ip,
955 'local_spi': local_spi,
956 'remote_spi': remote_spi,
957 'crypto_alg': crypto_alg,
958 'local_crypto_key_len': len(local_crypto_key),
959 'local_crypto_key': local_crypto_key,
960 'remote_crypto_key_len': len(remote_crypto_key),
961 'remote_crypto_key': remote_crypto_key,
962 'integ_alg': integ_alg,
963 'local_integ_key_len': len(local_integ_key),
964 'local_integ_key': local_integ_key,
965 'remote_integ_key_len': len(remote_integ_key),
966 'remote_integ_key': remote_integ_key,
967 'is_add': is_add,
968 'esn': esn,
969 'anti_replay': anti_replay,
970 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000971 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -0700972 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +0000973 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -0400974 })
Klement Sekera31da2e32018-06-24 22:49:55 +0200975
Klement Sekerab4d30532018-11-08 13:00:02 +0100976 def ipsec_select_backend(self, protocol, index):
977 return self.api(self.papi.ipsec_select_backend,
978 {'protocol': protocol, 'index': index})
979
980 def ipsec_backend_dump(self):
981 return self.api(self.papi.ipsec_backend_dump, {})
982
Neale Ranns50f0ac02019-05-15 02:13:37 -0700983 def punt_socket_register(self, reg, pathname,
984 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100985 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +0200986 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100987 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700988 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100989 'pathname': pathname})
990
Neale Ranns50f0ac02019-05-15 02:13:37 -0700991 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +0100992 """ Unregister punt socket """
993 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -0700994 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +0200995
Neale Ranns4ba67722019-02-28 11:11:39 +0000996 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -0700997 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -0700998 """ GBP endpoint Add """
999 return self.api(self.papi.gbp_endpoint_add,
1000 {'endpoint': {
1001 'sw_if_index': sw_if_index,
1002 'ips': ips,
1003 'n_ips': len(ips),
1004 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001005 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001006 'flags': flags,
1007 'tun': {
1008 'src': tun_src,
1009 'dst': tun_dst,
1010 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001011
1012 def gbp_endpoint_del(self, handle):
1013 """ GBP endpoint Del """
1014 return self.api(self.papi.gbp_endpoint_del,
1015 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001016
1017 def gbp_endpoint_dump(self):
1018 """ GBP endpoint Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001019 return self.api(self.papi.gbp_endpoint_dump, {})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001020
Neale Ranns4ba67722019-02-28 11:11:39 +00001021 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001022 rd, uplink_sw_if_index,
1023 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001024 """ GBP endpoint group Add """
1025 return self.api(self.papi.gbp_endpoint_group_add,
1026 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01001027 {
1028 'uplink_sw_if_index': uplink_sw_if_index,
1029 'bd_id': bd,
1030 'rd_id': rd,
1031 'vnid': vnid,
1032 'sclass': sclass,
1033 'retention': retention
1034 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001035
Neale Ranns4ba67722019-02-28 11:11:39 +00001036 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001037 """ GBP endpoint group Del """
1038 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00001039 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07001040
Neale Ranns160c9232019-06-19 06:25:56 -07001041 def gbp_bridge_domain_add(self, bd_id, rd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001042 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08001043 uu_fwd_sw_if_index,
1044 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001045 """ GBP bridge-domain Add """
1046 return self.api(self.papi.gbp_bridge_domain_add,
1047 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01001048 {
1049 'flags': flags,
1050 'bvi_sw_if_index': bvi_sw_if_index,
1051 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
1052 'bm_flood_sw_if_index': bm_flood_sw_if_index,
Neale Ranns160c9232019-06-19 06:25:56 -07001053 'bd_id': bd_id,
1054 'rd_id': rd_id
Ole Troan9a475372019-03-05 16:58:24 +01001055 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001056
1057 def gbp_bridge_domain_del(self, bd_id):
1058 """ GBP bridge-domain Del """
1059 return self.api(self.papi.gbp_bridge_domain_del,
1060 {'bd_id': bd_id})
1061
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001062 def gbp_route_domain_add(self, rd_id,
Neale Ranns160c9232019-06-19 06:25:56 -07001063 scope,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001064 ip4_table_id,
1065 ip6_table_id,
1066 ip4_uu_sw_if_index,
1067 ip6_uu_sw_if_index):
1068 """ GBP route-domain Add """
1069 return self.api(self.papi.gbp_route_domain_add,
1070 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01001071 {
Neale Ranns160c9232019-06-19 06:25:56 -07001072 'scope': scope,
Ole Troan9a475372019-03-05 16:58:24 +01001073 'ip4_table_id': ip4_table_id,
1074 'ip6_table_id': ip6_table_id,
1075 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
1076 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
1077 'rd_id': rd_id
1078 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001079
1080 def gbp_route_domain_del(self, rd_id):
1081 """ GBP route-domain Del """
1082 return self.api(self.papi.gbp_route_domain_del,
1083 {'rd_id': rd_id})
1084
Neale Ranns4ba67722019-02-28 11:11:39 +00001085 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07001086 """ GBP recirc Add/Del """
1087 return self.api(self.papi.gbp_recirc_add_del,
1088 {'is_add': is_add,
1089 'recirc': {
1090 'is_ext': is_ext,
1091 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001092 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07001093
1094 def gbp_recirc_dump(self):
1095 """ GBP recirc Dump """
1096 return self.api(self.papi.gbp_recirc_dump, {})
1097
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001098 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id, flags):
Neale Rannsb6a47952018-11-21 05:44:35 -08001099 """ GBP recirc Add/Del """
1100 return self.api(self.papi.gbp_ext_itf_add_del,
1101 {'is_add': is_add,
1102 'ext_itf': {
1103 'sw_if_index': sw_if_index,
1104 'bd_id': bd_id,
Benoît Ganneba6abfa2019-07-01 17:10:41 +02001105 'rd_id': rd_id,
1106 'flags': flags}})
Neale Rannsb6a47952018-11-21 05:44:35 -08001107
1108 def gbp_ext_itf_dump(self):
1109 """ GBP recirc Dump """
1110 return self.api(self.papi.gbp_ext_itf_dump, {})
1111
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001112 def gbp_subnet_add_del(self, is_add, rd_id,
1113 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07001114 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00001115 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07001116 """ GBP Subnet Add/Del """
1117 return self.api(self.papi.gbp_subnet_add_del,
1118 {'is_add': is_add,
1119 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001120 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07001121 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00001122 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07001123 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001124 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07001125
1126 def gbp_subnet_dump(self):
1127 """ GBP Subnet Dump """
Neale Rannsefd7bc22019-11-11 08:32:34 +00001128 return self.api(self.papi.gbp_subnet_dump, {})
Neale Ranns25b04942018-04-04 09:34:50 -07001129
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001130 def gbp_contract_dump(self):
1131 """ GBP contract Dump """
1132 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01001133
Neale Ranns8da9fc62019-03-04 14:08:11 -08001134 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001135 """ GBP VXLAN tunnel add """
1136 return self.api(self.papi.gbp_vxlan_tunnel_add,
1137 {
1138 'tunnel': {
1139 'vni': vni,
1140 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08001141 'bd_rd_id': bd_rd_id,
1142 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001143 }
1144 })
1145
1146 def gbp_vxlan_tunnel_del(self, vni):
1147 """ GBP VXLAN tunnel del """
1148 return self.api(self.papi.gbp_vxlan_tunnel_del,
1149 {
1150 'vni': vni,
1151 })
1152
1153 def gbp_vxlan_tunnel_dump(self):
1154 """ GBP VXLAN tunnel add/del """
1155 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
1156
Neale Ranns947ea622018-06-07 23:48:20 -07001157 def igmp_enable_disable(self, sw_if_index, enable, host):
1158 """ Enable/disable IGMP on a given interface """
1159 return self.api(self.papi.igmp_enable_disable,
1160 {'enable': enable,
1161 'mode': host,
1162 'sw_if_index': sw_if_index})
1163
Jakub Grajciar97748ca2018-10-04 11:05:35 +02001164 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
1165 """ Add/del IGMP proxy device """
1166 return self.api(self.papi.igmp_proxy_device_add_del,
1167 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1168 'add': add})
1169
1170 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
1171 """ Add/del interface to/from IGMP proxy device """
1172 return self.api(self.papi.igmp_proxy_device_add_del_interface,
1173 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
1174 'add': add})
1175
Neale Ranns947ea622018-06-07 23:48:20 -07001176 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001177 """ Listen for new (S,G) on specified interface
1178
1179 :param enable: add/del
1180 :param sw_if_index: interface sw index
1181 :param saddr: source ip4 addr
1182 :param gaddr: group ip4 addr
1183 """
1184 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07001185 {
1186 'group':
Ole Troan9a475372019-03-05 16:58:24 +01001187 {
1188 'filter': filter,
1189 'sw_if_index': sw_if_index,
1190 'n_srcs': len(saddrs),
1191 'saddrs': saddrs,
1192 'gaddr': gaddr
1193 }
Neale Ranns947ea622018-06-07 23:48:20 -07001194 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001195
Jakub Grajciar7b867a82017-12-08 16:28:42 +01001196 def igmp_clear_interface(self, sw_if_index):
1197 """ Remove all (S,G)s from specified interface
1198 doesn't send IGMP report!
1199 """
1200 return self.api(
1201 self.papi.igmp_clear_interface, {
1202 'sw_if_index': sw_if_index})
1203
1204 def want_igmp_events(self, enable=1):
1205 return self.api(self.papi.want_igmp_events, {'enable': enable,
1206 'pid': os.getpid()})