blob: 29a5716508cda3ae150da396b4a8177654903acc [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, },
30 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
31 'is_add': 1, },
32 'bier_disp_table_add_del': {'is_add': 1, },
33 'bier_imp_add': {'is_add': 1, },
34 'bier_route_add_del': {'is_add': 1, },
35 'bier_table_add_del': {'is_add': 1, },
36 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
37 'learn': 1, 'is_add': 1, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070038 'bvi_create': {'user_instance': 4294967295, },
39 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010040 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
41 'nbuckets': 2, 'memory_size': 2097152,
42 'next_table_index': 4294967295,
43 'miss_next_index': 4294967295, },
44 'dhcp6_client_enable_disable': {'enable': 1, },
45 'dhcp6_clients_enable_disable': {'enable': 1, },
46 'dhcp6_pd_client_enable_disable': {'enable': 1, },
47 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
48 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
49 'dhcp_proxy_config': {'is_add': 1, },
50 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010051 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
52 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
53 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000054 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010055 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
56 'decap_next_index': 4294967295, },
57 'input_acl_set_interface': {'ip4_table_index': 4294967295,
58 'ip6_table_index': 4294967295,
59 'l2_table_index': 4294967295, },
60 'ip6_add_del_address_using_prefix': {'is_add': 1, },
61 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
62 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
63 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
64 'next_hop_id': 4294967295,
65 'classify_table_index': 4294967295, 'is_add': 1, },
66 'ip_mroute_add_del': {'is_add': 1, },
67 'ip_neighbor_add_del': {'is_add': 1, },
68 'ip_punt_police': {'is_add': 1, },
69 'ip_punt_redirect': {'is_add': 1, },
Neale Ranns097fa662018-05-01 05:17:55 -070070 'ip_route_add_del': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010071 'ip_table_add_del': {'is_add': 1, },
72 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +010073 'ipsec_interface_add_del_spd': {'is_add': 1, },
74 'ipsec_sad_entry_add_del': {'is_add': 1, },
75 'ipsec_spd_add_del': {'is_add': 1, },
76 'ipsec_spd_dump': {'sa_id': 4294967295, },
77 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
78 'remote_port_stop': 65535, 'priority': 100,
79 'is_outbound': 1,
80 'is_add': 1, },
81 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
82 'l2_emulation': {'enable': 1, },
83 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -070084 'lb_conf': {'sticky_buckets_per_core': 4294967295,
85 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +010086 'lisp_add_del_adjacency': {'is_add': 1, },
87 'lisp_add_del_local_eid': {'is_add': 1, },
88 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
89 'lisp_add_del_locator_set': {'is_add': 1, },
90 'lisp_add_del_remote_mapping': {'is_add': 1, },
91 'macip_acl_add_replace': {'acl_index': 4294967295, },
92 'macip_acl_dump': {'acl_index': 4294967295, },
93 'macip_acl_interface_add_del': {'is_add': 1, },
94 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +010095 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
96 'mr_next_hop_weight': 1,
97 'mr_next_hop_via_label': 1048576,
98 'mr_is_add': 1,
99 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100100 'mpls_table_add_del': {'is_add': 1, },
101 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
102 'next_hop_weight': 1,
103 'next_hop_via_label': 1048576,
104 'is_add': 1, },
105 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100106 'output_acl_set_interface': {'ip4_table_index': 4294967295,
107 'ip6_table_index': 4294967295,
108 'l2_table_index': 4294967295, },
109 'pppoe_add_del_session': {'is_add': 1, },
110 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
111 'proxy_arp_add_del': {'is_add': 1, },
112 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100113 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
114 'proto': 1, },
115 'set_ipfix_exporter': {'collector_port': 4739, },
116 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
117 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
118 'svs_enable_disable': {'is_enable': 1, },
119 'svs_route_add_del': {'is_add': 1, },
120 'svs_table_add_del': {'is_add': 1, },
121 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700122 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100123 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
124 'pref_lifetime': 4294967295, },
125 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
126 'sw_interface_set_l2_bridge': {'enable': 1, },
127 'sw_interface_set_mpls_enable': {'enable': 1, },
128 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
129 'sw_interface_set_unnumbered': {'is_add': 1, },
130 'sw_interface_span_enable_disable': {'state': 1, },
131 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
132 'decap_next_index': 4294967295,
133 'instance': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100134 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
135 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
136 'protocol': 3, },
137 'want_bfd_events': {'enable_disable': 1, },
138 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
139 'want_dhcp6_reply_events': {'enable_disable': 1, },
140 'want_igmp_events': {'enable': 1, },
141 'want_interface_events': {'enable_disable': 1, },
142 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
143 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
144 'want_ip6_ra_events': {'enable_disable': 1, },
145 'want_l2_macs_events': {'enable_disable': 1, },
146}
Ole Troanf159f582019-02-28 20:20:47 +0100147
Matus Fabianb4515b42018-11-19 04:25:32 -0800148
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400149class CliFailedCommandError(Exception):
150 """ cli command failed."""
151
152
153class CliSyntaxError(Exception):
154 """ cli command had a syntax error."""
155
156
Klement Sekera73884482017-02-23 09:26:30 +0100157class UnexpectedApiReturnValueError(Exception):
158 """ exception raised when the API return value is unexpected """
159 pass
160
161
Klement Sekeraf62ae122016-10-11 11:47:09 +0200162class VppPapiProvider(object):
163 """VPP-api provider using vpp-papi
164
165 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200166 """
167
Klement Sekerae0545ef2017-01-25 08:00:40 +0100168 _zero, _negative = range(2)
169
Klement Sekera611864f2018-09-26 11:19:00 +0200170 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800171 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200172 self.name = name
173 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100174 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100175 self._expect_api_retval = self._zero
176 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100177
Paul Vinciguerra19542292019-03-17 17:34:46 -0700178 # install_dir is a class attribute. We need to set it before
179 # calling the constructor.
180 VPPApiClient.apidir = os.getenv('VPP_INSTALL_PATH')
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800181
Ole Troan4ff09ae2019-04-15 11:27:22 +0200182 use_socket = False
183 try:
184 if os.environ['SOCKET'] == '1':
185 use_socket = True
Paul Vinciguerrabff9f2f2019-05-09 16:12:35 -0400186 except KeyError:
Ole Troan4ff09ae2019-04-15 11:27:22 +0200187 pass
Paul Vinciguerra19542292019-03-17 17:34:46 -0700188
189 self.vpp = VPPApiClient(logger=test_class.logger,
190 read_timeout=read_timeout,
191 use_socket=use_socket,
192 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100193 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200194
Klement Sekerae0545ef2017-01-25 08:00:40 +0100195 def __enter__(self):
196 return self
197
Klement Sekera7d6afb32018-11-08 11:52:04 +0100198 def assert_negative_api_retval(self):
199 """ Expect API failure - used with with, e.g.:
200 with self.vapi.assert_negative_api_retval():
201 self.vapi.<api call expected to fail>
202 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100203 self._expect_stack.append(self._expect_api_retval)
204 self._expect_api_retval = self._negative
205 return self
206
Klement Sekera7d6afb32018-11-08 11:52:04 +0100207 def assert_zero_api_retval(self):
208 """ Expect API success - used with with, e.g.:
209 with self.vapi.assert_negative_api_retval():
210 self.vapi.<api call expected to succeed>
211
212 note: this is useful only inside another with block
213 as success is the default expected value
214 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100215 self._expect_stack.append(self._expect_api_retval)
216 self._expect_api_retval = self._zero
217 return self
218
219 def __exit__(self, exc_type, exc_value, traceback):
220 self._expect_api_retval = self._expect_stack.pop()
221
Klement Sekeraf62ae122016-10-11 11:47:09 +0200222 def register_hook(self, hook):
223 """Replace hook registration with new hook
224
225 :param hook:
226
227 """
228 self.hook = hook
229
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200230 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100231 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200232 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100233 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200234 return e
235
236 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100237 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100238 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100239 self.test_class.logger.debug("Expecting event '%s' within %ss",
240 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300241 else:
242 self.test_class.logger.debug("Expecting event within %ss",
243 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100244 if self._events:
245 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200246 limit = time.time() + timeout
247 while time.time() < limit:
248 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100249 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200250 if name and type(e).__name__ != name:
251 raise Exception(
252 "Unexpected event received: %s, expected: %s" %
253 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100254 self.test_class.logger.debug("Returning event %s:%s" %
255 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200256 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700257 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200258 raise Exception("Event did not occur within timeout")
259
260 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100261 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200262 # FIXME use the name instead of relying on type(e).__name__ ?
263 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100264 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200265 self._events.append(event)
266
Ole Troanf159f582019-02-28 20:20:47 +0100267 def factory(self, name, apifn):
268 def f(*a, **ka):
269 fields = apifn._func.msg.fields
270
271 # add positional and kw arguments
272 d = ka
273 for i, o in enumerate(fields[3:]):
274 try:
275 d[o] = a[i]
276 except:
277 break
278
279 # Default override
280 if name in defaultmapping:
281 for k, v in iteritems(defaultmapping[name]):
282 if k in d:
283 continue
284 d[k] = v
285 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100286
Ole Troanf159f582019-02-28 20:20:47 +0100287 return f
288
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800289 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100290 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800291 method = super(VppPapiProvider, self).__getattribute__(name)
292 except AttributeError:
293 method = self.factory(name, getattr(self.papi, name))
294 # lazily load the method so we don't need to call factory
295 # again for this name.
296 setattr(self, name, method)
297 return method
Ole Troanf159f582019-02-28 20:20:47 +0100298
Klement Sekeraf62ae122016-10-11 11:47:09 +0200299 def connect(self):
300 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100301 self.vpp.connect(self.name, self.shm_prefix)
302 self.papi = self.vpp.api
303 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200304
305 def disconnect(self):
306 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100307 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200308
309 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100310 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200311 Call the appropriate hooks before and after the API call
312
313 :param api_fn: API function to call
314 :param api_args: tuple of API function arguments
315 :param expected_retval: Expected return value (Default value = 0)
316 :returns: reply from the API
317
318 """
319 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100320 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100321 if self._expect_api_retval == self._negative:
322 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100323 msg = "API call passed unexpectedly: expected negative " \
324 "return value instead of %d in %s" % \
325 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100326 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100327 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100328 elif self._expect_api_retval == self._zero:
329 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100330 msg = "API call failed, expected %d return value instead " \
331 "of %d in %s" % (expected_retval, reply.retval,
Paul Vinciguerra1b534f52019-06-15 20:31:31 -0400332 repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100333 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100334 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100335 else:
336 raise Exception("Internal error, unexpected value for "
337 "self._expect_api_retval %s" %
338 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200339 self.hook.after_api(api_fn.__name__, api_args)
340 return reply
341
342 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100343 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200344
345 :param cli: CLI to execute
346 :returns: CLI output
347
348 """
349 self.hook.before_cli(cli)
350 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100351 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200352 self.hook.after_cli(cli)
Paul Vinciguerra9673e3e2019-05-10 20:41:08 -0400353 if r.retval == -156:
354 raise CliSyntaxError(r.reply)
355 if r.retval != 0:
356 raise CliFailedCommandError(r.reply)
Jan49c0fca2016-10-26 15:44:27 +0200357 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100358 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200359
Jan49c0fca2016-10-26 15:44:27 +0200360 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100361 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200362
363 :param cli: CLI to execute
364 :returns: CLI output
365 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600366 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200367
Neale Ranns37029302018-08-10 05:30:06 -0700368 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300369 return self.api(self.papi.want_ip4_arp_events,
370 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700371 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300372 'pid': os.getpid(), })
373
Neale Ranns37029302018-08-10 05:30:06 -0700374 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300375 return self.api(self.papi.want_ip6_nd_events,
376 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700377 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300378 'pid': os.getpid(), })
379
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100380 def want_ip6_ra_events(self, enable_disable=1):
381 return self.api(self.papi.want_ip6_ra_events,
382 {'enable_disable': enable_disable,
383 'pid': os.getpid(), })
384
385 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
386 mrc=0, mrd=0):
387 return self.api(self.papi.ip6nd_send_router_solicitation,
388 {'irt': irt,
389 'mrt': mrt,
390 'mrc': mrc,
391 'mrd': mrd,
392 'sw_if_index': sw_if_index})
393
Juraj Slobodab3f90502018-10-04 15:15:16 +0200394 def want_interface_events(self, enable_disable=1):
395 return self.api(self.papi.want_interface_events,
396 {'enable_disable': enable_disable,
397 'pid': os.getpid(), })
398
Ole Troane1ade682019-03-04 23:55:43 +0100399 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
400 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300401 return self.api(self.papi.want_l2_macs_events,
402 {'enable_disable': enable_disable,
403 'scan_delay': scan_delay,
404 'max_macs_in_event': max_macs_in_event,
405 'learn_limit': learn_limit,
406 'pid': os.getpid(), })
407
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200408 def want_dhcp6_reply_events(self, enable_disable=1):
409 return self.api(self.papi.want_dhcp6_reply_events,
410 {'enable_disable': enable_disable,
411 'pid': os.getpid()})
412
Juraj Sloboda81119e82018-05-25 14:02:20 +0200413 def want_dhcp6_pd_reply_events(self, enable_disable=1):
414 return self.api(self.papi.want_dhcp6_pd_reply_events,
415 {'enable_disable': enable_disable,
416 'pid': os.getpid()})
417
Juraj Sloboda81119e82018-05-25 14:02:20 +0200418 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
419 prefixes, server_index=0xFFFFFFFF,
420 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
421 ):
422 return self.api(self.papi.dhcp6_pd_send_client_message,
423 {'sw_if_index': sw_if_index,
424 'server_index': server_index,
425 'irt': irt,
426 'mrt': mrt,
427 'mrc': mrc,
428 'mrd': mrd,
429 'stop': stop,
430 'msg_type': msg_type,
431 'T1': T1,
432 'T2': T2,
433 'n_prefixes': len(prefixes),
434 'prefixes': prefixes})
435
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200436 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
437 enable=1):
438 return self.api(self.papi.dhcp6_client_enable_disable,
439 {'sw_if_index': sw_if_index,
440 'enable': enable})
441
Juraj Sloboda81119e82018-05-25 14:02:20 +0200442 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
443 enable=1):
444 return self.api(self.papi.dhcp6_pd_client_enable_disable,
445 {'sw_if_index': sw_if_index,
446 'prefix_group': prefix_group,
447 'enable': enable})
448
449 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
450 prefix_length, prefix_group,
451 is_add=1):
452 return self.api(self.papi.ip6_add_del_address_using_prefix,
453 {'sw_if_index': sw_if_index,
454 'prefix_group': prefix_group,
455 'address': address,
456 'prefix_length': prefix_length,
457 'is_add': is_add})
458
Neale Rannsc819fc62018-02-16 02:44:05 -0800459 def sw_interface_set_mac_address(self, sw_if_index, mac):
460 return self.api(self.papi.sw_interface_set_mac_address,
461 {'sw_if_index': sw_if_index,
462 'mac_address': mac})
463
Ole Troane1ade682019-03-04 23:55:43 +0100464 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200465 """Create p2p ethernet subinterface
466
467 :param sw_if_index: main (parent) interface
468 :param remote_mac: client (remote) mac address
469
470 """
471 return self.api(
472 self.papi.p2p_ethernet_add,
473 {'parent_if_index': sw_if_index,
474 'remote_mac': remote_mac,
475 'subif_id': subif_id})
476
Ole Troane1ade682019-03-04 23:55:43 +0100477 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200478 """Delete p2p ethernet subinterface
479
480 :param sw_if_index: main (parent) interface
481 :param remote_mac: client (remote) mac address
482
483 """
484 return self.api(
485 self.papi.p2p_ethernet_del,
486 {'parent_if_index': sw_if_index,
487 'remote_mac': remote_mac})
488
Klement Sekeraf62ae122016-10-11 11:47:09 +0200489 def create_vlan_subif(self, sw_if_index, vlan):
490 """
491
492 :param vlan:
493 :param sw_if_index:
494
495 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100496 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200497 {'sw_if_index': sw_if_index,
498 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200499
Matej Klotton0178d522016-11-04 11:11:44 +0100500 def create_loopback(self, mac=''):
501 """
502
503 :param mac: (Optional)
504 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100505 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200506 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100507
Neale Ranns097fa662018-05-01 05:17:55 -0700508 def ip_table_add_del(self,
509 table_id,
510 is_add=1,
511 is_ipv6=0):
512 """
513
514 :param table_id
515 :param is_add: (Default value = 1)
516 :param is_ipv6: (Default value = 0)
517
518 """
519
520 return self.api(
521 self.papi.ip_table_add_del,
522 {'table':
523 {
524 'table_id': table_id,
525 'is_ip6': is_ipv6
526 },
527 'is_add': is_add})
528
529 def ip_table_dump(self):
530 return self.api(self.papi.ip_table_dump, {})
531
532 def ip_route_dump(self, table_id, is_ip6=False):
533 return self.api(self.papi.ip_route_dump,
534 {'table': {
535 'table_id': table_id,
536 'is_ip6': is_ip6
537 }})
538
Matej Klotton0178d522016-11-04 11:11:44 +0100539 def ip_neighbor_add_del(self,
540 sw_if_index,
541 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700542 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100543 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700544 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100545 """ Add neighbor MAC to IPv4 or IPv6 address.
546
547 :param sw_if_index:
548 :param mac_address:
549 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100550 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700551 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100552 """
Matej Klotton0178d522016-11-04 11:11:44 +0100553 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100554 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700555 {
556 'is_add': is_add,
557 'neighbor': {
558 'sw_if_index': sw_if_index,
559 'flags': flags,
560 'mac_address': mac_address,
561 'ip_address': ip_address
562 }
563 }
Matej Klotton0178d522016-11-04 11:11:44 +0100564 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100565
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800566 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700567 low,
568 hi,
569 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800570 is_add=1):
571 """ Config Proxy Arp Range.
572
573 :param low_address: Start address in the rnage to Proxy for
574 :param hi_address: End address in the rnage to Proxy for
575 :param vrf_id: The VRF/table in which to proxy
576 """
577
578 return self.api(
579 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700580 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100581 {
582 'table_id': table_id,
583 'low': low,
584 'hi': hi,
585 },
586 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800587
588 def proxy_arp_intfc_enable_disable(self,
589 sw_if_index,
590 is_enable=1):
591 """ Enable/Disable an interface for proxy ARP requests
592
593 :param sw_if_index: Interface
594 :param enable_disable: Enable/Disable
595 """
596
597 return self.api(
598 self.papi.proxy_arp_intfc_enable_disable,
599 {'sw_if_index': sw_if_index,
600 'enable_disable': is_enable
601 }
602 )
603
Neale Ranns5a8844b2019-04-16 07:15:35 +0000604 def gre_tunnel_add_del(self,
605 src,
606 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000607 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500608 tunnel_type=0,
609 instance=0xFFFFFFFF,
610 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000611 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000612 """ Add a GRE tunnel
613
614 :param src_address:
615 :param dst_address:
616 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500617 :param tunnel_type: (Default value = 0)
618 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700619 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000620 :param is_add: (Default value = 1)
621 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000622 """
623
624 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000625 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200626 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000627 'tunnel':
628 {
629 'type': tunnel_type,
630 'instance': instance,
631 'src': src,
632 'dst': dst,
633 'outer_fib_id': outer_fib_id,
634 'session_id': session_id}
635 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000636 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000637
Neale Rannsd0df49f2018-08-08 01:06:40 -0700638 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700639 src_ip,
640 dst_ip,
641 src_port,
642 dst_port,
643 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800644 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800645 :param src_ip:
646 :param dst_ip:
647 :param src_port:
648 :param dst_port:
649 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800650 """
651
652 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700653 self.papi.udp_encap_add,
654 {
655 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700656 'src_ip': src_ip,
657 'dst_ip': dst_ip,
658 'src_port': src_port,
659 'dst_port': dst_port,
660 'table_id': table_id
661 }
662 })
663
Neale Ranns097fa662018-05-01 05:17:55 -0700664 def udp_encap_del(self, id):
665 return self.api(self.papi.udp_encap_del, {'id': id})
666
667 def udp_encap_dump(self):
668 return self.api(self.papi.udp_encap_dump, {})
669
670 def want_udp_encap_stats(self, enable=1):
671 return self.api(self.papi.want_udp_encap_stats,
672 {'enable': enable,
673 'pid': os.getpid()})
674
675 def mpls_route_dump(self, table_id):
676 return self.api(self.papi.mpls_route_dump,
677 {'table': {
678 'mt_table_id': table_id
679 }})
680
681 def mpls_table_dump(self):
682 return self.api(self.papi.mpls_table_dump, {})
683
Neale Ranns15002542017-09-10 04:39:11 -0700684 def mpls_table_add_del(
685 self,
686 table_id,
687 is_add=1):
688 """
689
690 :param table_id
691 :param is_add: (Default value = 1)
692
693 """
694
695 return self.api(
696 self.papi.mpls_table_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700697 {'mt_table':
698 {
699 'mt_table_id': table_id,
700 },
Neale Ranns15002542017-09-10 04:39:11 -0700701 'mt_is_add': is_add})
702
Neale Ranns097fa662018-05-01 05:17:55 -0700703 def mpls_route_add_del(self,
704 table_id,
705 label,
706 eos,
707 eos_proto,
708 is_multicast,
709 paths,
710 is_add,
711 is_multipath):
712 """ MPLS Route add/del """
713 return self.api(
714 self.papi.mpls_route_add_del,
715 {'mr_route':
716 {
717 'mr_table_id': table_id,
718 'mr_label': label,
719 'mr_eos': eos,
720 'mr_eos_proto': eos_proto,
721 'mr_is_multicast': is_multicast,
722 'mr_n_paths': len(paths),
723 'mr_paths': paths,
724 },
725 'mr_is_add': is_add,
726 'mr_is_multipath': is_multipath})
727
Neale Rannsad422ed2016-11-02 14:20:04 +0000728 def mpls_ip_bind_unbind(
729 self,
730 label,
Neale Ranns097fa662018-05-01 05:17:55 -0700731 prefix,
Neale Rannsad422ed2016-11-02 14:20:04 +0000732 table_id=0,
733 ip_table_id=0,
Neale Rannsad422ed2016-11-02 14:20:04 +0000734 is_bind=1):
735 """
736 """
737 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100738 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200739 {'mb_mpls_table_id': table_id,
740 'mb_label': label,
741 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200742 'mb_is_bind': is_bind,
Neale Ranns097fa662018-05-01 05:17:55 -0700743 'mb_prefix': prefix})
Neale Rannsad422ed2016-11-02 14:20:04 +0000744
745 def mpls_tunnel_add_del(
746 self,
747 tun_sw_if_index,
Neale Ranns097fa662018-05-01 05:17:55 -0700748 paths,
Neale Rannsad422ed2016-11-02 14:20:04 +0000749 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800750 l2_only=0,
751 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000752 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000753 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000754 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100755 self.papi.mpls_tunnel_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -0700756 {'mt_is_add': is_add,
757 'mt_tunnel':
758 {
759 'mt_sw_if_index': tun_sw_if_index,
760 'mt_l2_only': l2_only,
761 'mt_is_multicast': is_multicast,
762 'mt_n_paths': len(paths),
763 'mt_paths': paths,
764 }})
Matus Fabiande886752016-12-07 03:38:19 -0800765
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200766 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +0100767 detect_mult, local_addr, peer_addr, is_ipv6=0,
768 bfd_key_id=None, conf_key_id=None):
769 if bfd_key_id is None:
770 return self.api(self.papi.bfd_udp_add,
771 {
772 'sw_if_index': sw_if_index,
773 'desired_min_tx': desired_min_tx,
774 'required_min_rx': required_min_rx,
775 'local_addr': local_addr,
776 'peer_addr': peer_addr,
777 'is_ipv6': is_ipv6,
778 'detect_mult': detect_mult,
779 })
780 else:
781 return self.api(self.papi.bfd_udp_add,
782 {
783 'sw_if_index': sw_if_index,
784 'desired_min_tx': desired_min_tx,
785 'required_min_rx': required_min_rx,
786 'local_addr': local_addr,
787 'peer_addr': peer_addr,
788 'is_ipv6': is_ipv6,
789 'detect_mult': detect_mult,
790 'is_authenticated': 1,
791 'bfd_key_id': bfd_key_id,
792 'conf_key_id': conf_key_id,
793 })
794
Klement Sekeraa57a9702017-02-02 06:58:07 +0100795 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
796 detect_mult, local_addr, peer_addr, is_ipv6=0):
797 return self.api(self.papi.bfd_udp_mod,
798 {
799 'sw_if_index': sw_if_index,
800 'desired_min_tx': desired_min_tx,
801 'required_min_rx': required_min_rx,
802 'local_addr': local_addr,
803 'peer_addr': peer_addr,
804 'is_ipv6': is_ipv6,
805 'detect_mult': detect_mult,
806 })
807
Klement Sekerab17dd962017-01-09 07:43:48 +0100808 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
809 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
810 is_delayed=False):
811 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200812 {
813 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200814 'local_addr': local_addr,
815 'peer_addr': peer_addr,
816 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +0100817 'is_delayed': 1 if is_delayed else 0,
818 'bfd_key_id': bfd_key_id,
819 'conf_key_id': conf_key_id,
820 })
821
Klement Sekerab17dd962017-01-09 07:43:48 +0100822 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
823 peer_addr, is_ipv6=0):
824 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200825 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +0100826 'sw_if_index': sw_if_index,
827 'local_addr': local_addr,
828 'peer_addr': peer_addr,
829 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200830 })
831
832 def want_bfd_events(self, enable_disable=1):
833 return self.api(self.papi.want_bfd_events, {
834 'enable_disable': enable_disable,
835 'pid': os.getpid(),
836 })
Steve Shin7957d6e2016-12-19 09:24:50 -0800837
Klement Sekerab17dd962017-01-09 07:43:48 +0100838 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
839 return self.api(self.papi.bfd_auth_set_key, {
840 'conf_key_id': conf_key_id,
841 'auth_type': auth_type,
842 'key': key,
843 'key_len': len(key),
844 })
845
Steve Shin7957d6e2016-12-19 09:24:50 -0800846 def classify_add_del_table(
847 self,
848 is_add,
849 mask,
850 match_n_vectors=1,
851 table_index=0xFFFFFFFF,
852 nbuckets=2,
853 memory_size=2097152,
854 skip_n_vectors=0,
855 next_table_index=0xFFFFFFFF,
856 miss_next_index=0xFFFFFFFF,
857 current_data_flag=0,
858 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -0800859 """
860 :param is_add:
861 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +0100862 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +0100863 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -0800864 :param nbuckets: (Default value = 2)
865 :param memory_size: (Default value = 2097152)
866 :param skip_n_vectors: (Default value = 0)
867 :param next_table_index: (Default value = 0xFFFFFFFF)
868 :param miss_next_index: (Default value = 0xFFFFFFFF)
869 :param current_data_flag: (Default value = 0)
870 :param current_data_offset: (Default value = 0)
871 """
872
Juraj Sloboda75282452018-06-12 14:20:49 +0200873 mask_len = ((len(mask) - 1) / 16 + 1) * 16
874 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -0800875 return self.api(
876 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100877 {'is_add': is_add,
878 'table_index': table_index,
879 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -0800880 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100881 'skip_n_vectors': skip_n_vectors,
882 'match_n_vectors': match_n_vectors,
883 'next_table_index': next_table_index,
884 'miss_next_index': miss_next_index,
885 'current_data_flag': current_data_flag,
886 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +0200887 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100888 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -0800889
890 def classify_add_del_session(
891 self,
892 is_add,
893 table_index,
894 match,
895 opaque_index=0xFFFFFFFF,
896 hit_next_index=0xFFFFFFFF,
897 advance=0,
898 action=0,
899 metadata=0):
900 """
901 :param is_add:
902 :param table_index:
903 :param match:
904 :param opaque_index: (Default value = 0xFFFFFFFF)
905 :param hit_next_index: (Default value = 0xFFFFFFFF)
906 :param advance: (Default value = 0)
907 :param action: (Default value = 0)
908 :param metadata: (Default value = 0)
909 """
910
Juraj Sloboda75282452018-06-12 14:20:49 +0200911 match_len = ((len(match) - 1) / 16 + 1) * 16
912 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -0800913 return self.api(
914 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100915 {'is_add': is_add,
916 'table_index': table_index,
917 'hit_next_index': hit_next_index,
918 'opaque_index': opaque_index,
919 'advance': advance,
920 'action': action,
921 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +0200922 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100923 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -0800924
925 def input_acl_set_interface(
926 self,
927 is_add,
928 sw_if_index,
929 ip4_table_index=0xFFFFFFFF,
930 ip6_table_index=0xFFFFFFFF,
931 l2_table_index=0xFFFFFFFF):
932 """
933 :param is_add:
934 :param sw_if_index:
935 :param ip4_table_index: (Default value = 0xFFFFFFFF)
936 :param ip6_table_index: (Default value = 0xFFFFFFFF)
937 :param l2_table_index: (Default value = 0xFFFFFFFF)
938 """
939
940 return self.api(
941 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +0100942 {'sw_if_index': sw_if_index,
943 'ip4_table_index': ip4_table_index,
944 'ip6_table_index': ip6_table_index,
945 'l2_table_index': l2_table_index,
946 'is_add': is_add})
947
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100948 def output_acl_set_interface(
949 self,
950 is_add,
951 sw_if_index,
952 ip4_table_index=0xFFFFFFFF,
953 ip6_table_index=0xFFFFFFFF,
954 l2_table_index=0xFFFFFFFF):
955 """
956 :param is_add:
957 :param sw_if_index:
958 :param ip4_table_index: (Default value = 0xFFFFFFFF)
959 :param ip6_table_index: (Default value = 0xFFFFFFFF)
960 :param l2_table_index: (Default value = 0xFFFFFFFF)
961 """
962
963 return self.api(
964 self.papi.output_acl_set_interface,
965 {'sw_if_index': sw_if_index,
966 'ip4_table_index': ip4_table_index,
967 'ip6_table_index': ip6_table_index,
968 'l2_table_index': l2_table_index,
969 'is_add': is_add})
970
Klement Sekera77fabdb2017-01-02 07:46:14 +0100971 def set_ipfix_exporter(
972 self,
973 collector_address,
974 src_address,
975 path_mtu,
976 template_interval,
977 vrf_id=0,
978 collector_port=4739,
979 udp_checksum=0):
980 return self.api(
981 self.papi.set_ipfix_exporter,
982 {
983 'collector_address': collector_address,
984 'collector_port': collector_port,
985 'src_address': src_address,
986 'vrf_id': vrf_id,
987 'path_mtu': path_mtu,
988 'template_interval': template_interval,
989 'udp_checksum': udp_checksum,
990 })
Neale Rannsfca0c242017-01-13 07:57:46 -0800991
992 def dhcp_proxy_config(self,
993 dhcp_server,
994 dhcp_src_address,
995 rx_table_id=0,
996 server_table_id=0,
997 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -0800998 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -0800999 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001000 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001001 {
1002 'rx_vrf_id': rx_table_id,
1003 'server_vrf_id': server_table_id,
1004 'is_ipv6': is_ipv6,
1005 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001006 'dhcp_server': dhcp_server,
1007 'dhcp_src_address': dhcp_src_address,
1008 })
1009
1010 def dhcp_proxy_set_vss(self,
1011 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001012 vss_type=255,
1013 vpn_ascii_id="",
1014 oui=0,
1015 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001016 is_add=1,
1017 is_ip6=0):
1018 return self.api(
1019 self.papi.dhcp_proxy_set_vss,
1020 {
1021 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001022 'vss_type': vss_type,
1023 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001024 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001025 'vpn_index': vpn_index,
1026 'is_add': is_add,
1027 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001028 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001029
Ole Troane1ade682019-03-04 23:55:43 +01001030 def dhcp_client_config(self,
1031 sw_if_index,
1032 hostname,
1033 client_id='',
1034 is_add=1,
1035 set_broadcast_flag=1,
1036 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001037 return self.api(
1038 self.papi.dhcp_client_config,
1039 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001040 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001041 'client': {
1042 'sw_if_index': sw_if_index,
1043 'hostname': hostname,
1044 'id': client_id,
1045 'want_dhcp_event': want_dhcp_events,
1046 'set_broadcast_flag': set_broadcast_flag,
1047 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001048 })
1049
Neale Ranns32e1c012016-11-22 17:07:28 +00001050 def ip_mroute_add_del(self,
Neale Ranns097fa662018-05-01 05:17:55 -07001051 table_id,
1052 prefix,
Neale Ranns32e1c012016-11-22 17:07:28 +00001053 e_flags,
Neale Ranns097fa662018-05-01 05:17:55 -07001054 rpf_id,
1055 paths,
Neale Ranns32e1c012016-11-22 17:07:28 +00001056 is_add=1,
Neale Ranns097fa662018-05-01 05:17:55 -07001057 is_multipath=1):
Neale Ranns32e1c012016-11-22 17:07:28 +00001058 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001059 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001060 """
1061 return self.api(
1062 self.papi.ip_mroute_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001063 {
1064 'is_add': is_add,
1065 'is_multipath': is_multipath,
1066 'route': {
1067 'table_id': table_id,
1068 'entry_flags': e_flags,
1069 'rpf_id': rpf_id,
1070 'prefix': prefix,
1071 'n_paths': len(paths),
1072 'paths': paths,
1073 }
1074 })
1075
1076 def mfib_signal_dump(self):
1077 return self.api(self.papi.mfib_signal_dump, {})
1078
1079 def ip_mroute_dump(self, table_id, is_ip6=False):
1080 return self.api(self.papi.ip_mroute_dump,
1081 {'table': {
1082 'table_id': table_id,
1083 'is_ip6': is_ip6
1084 }})
Neale Ranns32e1c012016-11-22 17:07:28 +00001085
Filip Tehlar770e89e2017-01-31 10:39:16 +01001086 def lisp_enable_disable(self, is_enabled):
1087 return self.api(
1088 self.papi.lisp_enable_disable,
1089 {
1090 'is_en': is_enabled,
1091 })
1092
Ole Troane1ade682019-03-04 23:55:43 +01001093 def lisp_add_del_locator_set(self,
1094 ls_name,
1095 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001096 return self.api(
1097 self.papi.lisp_add_del_locator_set,
1098 {
1099 'is_add': is_add,
1100 'locator_set_name': ls_name
1101 })
1102
Ole Troane1ade682019-03-04 23:55:43 +01001103 def lisp_add_del_locator(self,
1104 ls_name,
1105 sw_if_index,
1106 priority=1,
1107 weight=1,
1108 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001109 return self.api(
1110 self.papi.lisp_add_del_locator,
1111 {
1112 'is_add': is_add,
1113 'locator_set_name': ls_name,
1114 'sw_if_index': sw_if_index,
1115 'priority': priority,
1116 'weight': weight
1117 })
1118
1119 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1120 return self.api(
1121 self.papi.lisp_locator_dump,
1122 {
1123 'is_index_set': is_index_set,
1124 'ls_name': ls_name,
1125 'ls_index': ls_index,
1126 })
1127
Ole Troane1ade682019-03-04 23:55:43 +01001128 def lisp_add_del_local_eid(self,
1129 ls_name,
1130 eid_type,
1131 eid,
1132 prefix_len,
1133 vni=0,
1134 key_id=0,
1135 key="",
1136 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001137 return self.api(
1138 self.papi.lisp_add_del_local_eid,
1139 {
1140 'locator_set_name': ls_name,
1141 'is_add': is_add,
1142 'eid_type': eid_type,
1143 'eid': eid,
1144 'prefix_len': prefix_len,
1145 'vni': vni,
1146 'key_id': key_id,
1147 'key': key
1148 })
1149
1150 def lisp_eid_table_dump(self,
1151 eid_set=0,
1152 prefix_length=0,
1153 vni=0,
1154 eid_type=0,
1155 eid=None,
1156 filter_opt=0):
1157 return self.api(
1158 self.papi.lisp_eid_table_dump,
1159 {
1160 'eid_set': eid_set,
1161 'prefix_length': prefix_length,
1162 'vni': vni,
1163 'eid_type': eid_type,
1164 'eid': eid,
1165 'filter': filter_opt,
1166 })
1167
Ole Troane1ade682019-03-04 23:55:43 +01001168 def lisp_add_del_remote_mapping(self,
1169 eid_type,
1170 eid,
1171 eid_prefix_len=0,
1172 vni=0,
1173 rlocs=[],
1174 rlocs_num=0,
1175 is_src_dst=0,
1176 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001177 return self.api(
1178 self.papi.lisp_add_del_remote_mapping,
1179 {
1180 'is_add': is_add,
1181 'eid_type': eid_type,
1182 'eid': eid,
1183 'eid_len': eid_prefix_len,
1184 'rloc_num': rlocs_num,
1185 'rlocs': rlocs,
1186 'vni': vni,
1187 'is_src_dst': is_src_dst,
1188 })
1189
Ole Troane1ade682019-03-04 23:55:43 +01001190 def lisp_add_del_adjacency(self,
1191 leid,
1192 reid,
1193 leid_len,
1194 reid_len,
1195 eid_type,
1196 is_add=1,
1197 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001198 return self.api(
1199 self.papi.lisp_add_del_adjacency,
1200 {
1201 'is_add': is_add,
1202 'vni': vni,
1203 'eid_type': eid_type,
1204 'leid': leid,
1205 'reid': reid,
1206 'leid_len': leid_len,
1207 'reid_len': reid_len,
1208 })
1209
Hongjun Nief486b12017-04-12 19:21:16 +08001210 def gtpu_add_del_tunnel(
1211 self,
1212 src_addr,
1213 dst_addr,
1214 is_add=1,
1215 is_ipv6=0,
1216 mcast_sw_if_index=0xFFFFFFFF,
1217 encap_vrf_id=0,
1218 decap_next_index=0xFFFFFFFF,
1219 teid=0):
1220 """
1221
1222 :param is_add: (Default value = 1)
1223 :param is_ipv6: (Default value = 0)
1224 :param src_addr:
1225 :param dst_addr:
1226 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1227 :param encap_vrf_id: (Default value = 0)
1228 :param decap_next_index: (Default value = 0xFFFFFFFF)
1229 :param teid: (Default value = 0)
1230
1231 """
1232 return self.api(self.papi.gtpu_add_del_tunnel,
1233 {'is_add': is_add,
1234 'is_ipv6': is_ipv6,
1235 'src_address': src_addr,
1236 'dst_address': dst_addr,
1237 'mcast_sw_if_index': mcast_sw_if_index,
1238 'encap_vrf_id': encap_vrf_id,
1239 'decap_next_index': decap_next_index,
1240 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001241
1242 def vxlan_gpe_add_del_tunnel(
1243 self,
1244 src_addr,
1245 dst_addr,
1246 mcast_sw_if_index=0xFFFFFFFF,
1247 is_add=1,
1248 is_ipv6=0,
1249 encap_vrf_id=0,
1250 decap_vrf_id=0,
1251 protocol=3,
1252 vni=0):
1253 """
1254
1255 :param local:
1256 :param remote:
1257 :param is_add: (Default value = 1)
1258 :param is_ipv6: (Default value = 0)
1259 :param encap_vrf_id: (Default value = 0)
1260 :param decap_vrf_id: (Default value = 0)
1261 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1262 :param protocol: (Default value = 3)
1263 :param vni: (Default value = 0)
1264
1265 """
1266 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1267 {'is_add': is_add,
1268 'is_ipv6': is_ipv6,
1269 'local': src_addr,
1270 'remote': dst_addr,
1271 'mcast_sw_if_index': mcast_sw_if_index,
1272 'encap_vrf_id': encap_vrf_id,
1273 'decap_vrf_id': decap_vrf_id,
1274 'protocol': protocol,
1275 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001276
Neale Ranns79a05f52018-09-11 07:39:43 -07001277 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1278 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001279 {'sw_if_index': sw_if_index,
1280 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001281
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001282 def pppoe_add_del_session(
1283 self,
1284 client_ip,
1285 client_mac,
1286 session_id=0,
1287 is_add=1,
1288 is_ipv6=0,
1289 decap_vrf_id=0):
1290 """
1291
1292 :param is_add: (Default value = 1)
1293 :param is_ipv6: (Default value = 0)
1294 :param client_ip:
1295 :param session_id: (Default value = 0)
1296 :param client_mac:
1297 :param decap_vrf_id: (Default value = 0)
1298
1299 """
1300 return self.api(self.papi.pppoe_add_del_session,
1301 {'is_add': is_add,
1302 'is_ipv6': is_ipv6,
1303 'session_id': session_id,
1304 'client_ip': client_ip,
1305 'decap_vrf_id': decap_vrf_id,
1306 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001307
Neale Ranns7c922dc2018-08-30 06:12:27 -07001308 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1309 return self.api(self.papi.sr_mpls_policy_add,
1310 {'bsid': bsid,
1311 'weight': weight,
1312 'type': type,
1313 'n_segments': len(segments),
1314 'segments': segments})
1315
1316 def sr_mpls_policy_del(self, bsid):
1317 return self.api(self.papi.sr_mpls_policy_del,
1318 {'bsid': bsid})
1319
Kris Michielsen91074432017-06-22 13:00:20 +02001320 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001321 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001322 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001323 nh_addr4,
1324 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001325 is_del=0,
1326 end_psp=0,
1327 sw_if_index=0xFFFFFFFF,
1328 vlan_index=0,
1329 fib_table=0,
1330 ):
1331 """ Add/del IPv6 SR local-SID.
1332
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001333 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001334 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1335 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001336 :param nh_addr4:
1337 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001338 :param is_del: (Default value = 0)
1339 :param end_psp: (Default value = 0)
1340 :param sw_if_index: (Default value = 0xFFFFFFFF)
1341 :param vlan_index: (Default value = 0)
1342 :param fib_table: (Default value = 0)
1343 """
1344 return self.api(
1345 self.papi.sr_localsid_add_del,
1346 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001347 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001348 'end_psp': end_psp,
1349 'behavior': behavior,
1350 'sw_if_index': sw_if_index,
1351 'vlan_index': vlan_index,
1352 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001353 'nh_addr4': nh_addr4,
1354 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001355 }
1356 )
1357
1358 def sr_policy_add(
1359 self,
1360 bsid_addr,
1361 weight=1,
1362 is_encap=1,
1363 type=0,
1364 fib_table=0,
1365 n_segments=0,
1366 segments=[]):
1367 """
1368 :param bsid_addr: bindingSID of the SR Policy
1369 :param weight: weight of the sid list. optional. (default: 1)
1370 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1371 (default: Encap)
1372 :param type: type/behavior of the SR policy. (default or spray) \
1373 (default: default)
1374 :param fib_table: VRF where to install the FIB entry for the BSID \
1375 (default: 0)
1376 :param n_segments: number of segments \
1377 (default: 0)
1378 :param segments: a vector of IPv6 address composing the segment list \
1379 (default: [])
1380 """
1381 return self.api(
1382 self.papi.sr_policy_add,
1383 {'bsid_addr': bsid_addr,
1384 'weight': weight,
1385 'is_encap': is_encap,
1386 'type': type,
1387 'fib_table': fib_table,
1388 'n_segments': n_segments,
1389 'segments': segments
1390 }
1391 )
1392
1393 def sr_policy_del(
1394 self,
1395 bsid_addr,
1396 sr_policy_index=0):
1397 """
1398 :param bsid: bindingSID of the SR Policy
1399 :param sr_policy_index: index of the sr policy (default: 0)
1400 """
1401 return self.api(
1402 self.papi.sr_policy_del,
1403 {'bsid_addr': bsid_addr,
1404 'sr_policy_index': sr_policy_index
1405 })
1406
1407 def sr_steering_add_del(
1408 self,
1409 is_del,
1410 bsid_addr,
1411 sr_policy_index,
1412 table_id,
1413 prefix_addr,
1414 mask_width,
1415 sw_if_index,
1416 traffic_type):
1417 """
1418 Steer traffic L2 and L3 traffic through a given SR policy
1419
1420 :param is_del: delete or add
1421 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1422 :param sr_policy: is the index of the SR Policy (alt to bsid)
1423 :param table_id: is the VRF where to install the FIB entry for the BSID
1424 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1425 :param mask_width: is the mask for L3 traffic type
1426 :param sw_if_index: is the incoming interface for L2 traffic
1427 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1428 """
1429 return self.api(
1430 self.papi.sr_steering_add_del,
1431 {'is_del': is_del,
1432 'bsid_addr': bsid_addr,
1433 'sr_policy_index': sr_policy_index,
1434 'table_id': table_id,
1435 'prefix_addr': prefix_addr,
1436 'mask_width': mask_width,
1437 'sw_if_index': sw_if_index,
1438 'traffic_type': traffic_type
1439 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001440
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001441 def acl_add_replace(self, acl_index, r, tag='',
1442 expected_retval=0):
1443 """Add/replace an ACL
1444 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1445 :param acl_rule r: ACL rules array.
1446 :param str tag: symbolic tag (description) for this ACL.
1447 :param int count: number of rules.
1448 """
1449 return self.api(self.papi.acl_add_replace,
1450 {'acl_index': acl_index,
1451 'r': r,
1452 'count': len(r),
1453 'tag': tag},
1454 expected_retval=expected_retval)
1455
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001456 def acl_del(self, acl_index, expected_retval=0):
1457 """
1458
1459 :param acl_index:
1460 :return:
1461 """
1462 return self.api(self.papi.acl_del,
1463 {'acl_index': acl_index},
1464 expected_retval=expected_retval)
1465
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001466 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1467 expected_retval=0):
1468 return self.api(self.papi.acl_interface_set_acl_list,
1469 {'sw_if_index': sw_if_index,
1470 'count': len(acls),
1471 'n_input': n_input,
1472 'acls': acls},
1473 expected_retval=expected_retval)
1474
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001475 def acl_interface_set_etype_whitelist(self, sw_if_index,
1476 n_input, whitelist,
1477 expected_retval=0):
1478 return self.api(self.papi.acl_interface_set_etype_whitelist,
1479 {'sw_if_index': sw_if_index,
1480 'count': len(whitelist),
1481 'n_input': n_input,
1482 'whitelist': whitelist},
1483 expected_retval=expected_retval)
1484
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001485 def acl_interface_add_del(self,
1486 sw_if_index,
1487 acl_index,
1488 is_add=1):
1489 """ Add/Delete ACL to/from interface
1490
1491 :param sw_if_index:
1492 :param acl_index:
1493 :param is_add: (Default value = 1)
1494 """
1495
1496 return self.api(self.papi.acl_interface_add_del,
1497 {'is_add': is_add,
1498 'is_input': 1,
1499 'sw_if_index': sw_if_index,
1500 'acl_index': acl_index})
1501
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001502 def acl_dump(self, acl_index, expected_retval=0):
1503 return self.api(self.papi.acl_dump,
1504 {'acl_index': acl_index},
1505 expected_retval=expected_retval)
1506
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001507 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1508 expected_retval=0):
1509 return self.api(self.papi.acl_interface_list_dump,
1510 {'sw_if_index': sw_if_index},
1511 expected_retval=expected_retval)
1512
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001513 def macip_acl_add(self, rules, tag=""):
1514 """ Add MACIP acl
1515
1516 :param rules: list of rules for given acl
1517 :param tag: acl tag
1518 """
1519
1520 return self.api(self.papi.macip_acl_add,
1521 {'r': rules,
1522 'count': len(rules),
1523 'tag': tag})
1524
Pavel Kotucek932f7412017-09-07 14:44:52 +02001525 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1526 """ Add MACIP acl
1527
1528 :param rules: list of rules for given acl
1529 :param tag: acl tag
1530 """
1531
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001532 return self.api(self.papi.macip_acl_add_replace,
1533 {'acl_index': acl_index,
1534 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001535 'count': len(rules),
1536 'tag': tag})
1537
Pavel Kotucek932f7412017-09-07 14:44:52 +02001538 def macip_acl_interface_add_del(self,
1539 sw_if_index,
1540 acl_index,
1541 is_add=1):
1542 """ Add MACIP acl to interface
1543
1544 :param sw_if_index:
1545 :param acl_index:
1546 :param is_add: (Default value = 1)
1547 """
1548
1549 return self.api(self.papi.macip_acl_interface_add_del,
1550 {'is_add': is_add,
1551 'sw_if_index': sw_if_index,
1552 'acl_index': acl_index})
1553
Pavel Kotucek932f7412017-09-07 14:44:52 +02001554 def macip_acl_dump(self, acl_index=4294967295):
1555 """ Return MACIP acl dump
1556 """
1557
1558 return self.api(
1559 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07001560
1561 def policer_add_del(self,
1562 name,
1563 cir,
1564 eir,
1565 cb,
1566 eb,
1567 is_add=1,
1568 rate_type=0,
1569 round_type=0,
1570 ptype=0,
1571 color_aware=0,
1572 conform_action_type=1,
1573 conform_dscp=0,
1574 exceed_action_type=0,
1575 exceed_dscp=0,
1576 violate_action_type=0,
1577 violate_dscp=0):
1578 return self.api(self.papi.policer_add_del,
1579 {'name': name,
1580 'cir': cir,
1581 'eir': eir,
1582 'cb': cb,
1583 'eb': eb,
1584 'is_add': is_add,
1585 'rate_type': rate_type,
1586 'round_type': round_type,
1587 'type': ptype,
1588 'color_aware': color_aware,
1589 'conform_action_type': conform_action_type,
1590 'conform_dscp': conform_dscp,
1591 'exceed_action_type': exceed_action_type,
1592 'exceed_dscp': exceed_dscp,
1593 'violate_action_type': violate_action_type,
1594 'violate_dscp': violate_dscp})
1595
1596 def ip_punt_police(self,
1597 policer_index,
1598 is_ip6=0,
1599 is_add=1):
1600 return self.api(self.papi.ip_punt_police,
1601 {'policer_index': policer_index,
1602 'is_add': is_add,
1603 'is_ip6': is_ip6})
1604
1605 def ip_punt_redirect(self,
1606 rx_sw_if_index,
1607 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001608 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07001609 is_add=1):
1610 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01001611 {'punt': {'rx_sw_if_index': rx_sw_if_index,
1612 'tx_sw_if_index': tx_sw_if_index,
1613 'nh': address},
1614 'is_add': is_add})
1615
1616 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
1617 return self.api(self.papi.ip_punt_redirect_dump,
1618 {'sw_if_index': sw_if_index,
1619 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001620
1621 def bier_table_add_del(self,
1622 bti,
1623 mpls_label,
1624 is_add=1):
1625 """ BIER Table add/del """
1626 return self.api(
1627 self.papi.bier_table_add_del,
1628 {'bt_tbl_id': {"bt_set": bti.set_id,
1629 "bt_sub_domain": bti.sub_domain_id,
1630 "bt_hdr_len_id": bti.hdr_len_id},
1631 'bt_label': mpls_label,
1632 'bt_is_add': is_add})
1633
1634 def bier_table_dump(self):
1635 return self.api(self.papi.bier_table_dump, {})
1636
1637 def bier_route_add_del(self,
1638 bti,
1639 bp,
Neale Ranns91286372017-12-05 13:24:04 -08001640 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07001641 is_add=1,
1642 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07001643 """ BIER Route add/del """
1644 return self.api(
1645 self.papi.bier_route_add_del,
Neale Ranns097fa662018-05-01 05:17:55 -07001646 {
1647 'br_route': {
1648 'br_tbl_id': {"bt_set": bti.set_id,
1649 "bt_sub_domain": bti.sub_domain_id,
1650 "bt_hdr_len_id": bti.hdr_len_id},
1651 'br_bp': bp,
1652 'br_n_paths': len(paths),
1653 'br_paths': paths,
1654 },
1655 'br_is_add': is_add,
1656 'br_is_replace': is_replace
1657 })
Neale Rannsd792d9c2017-10-21 10:53:20 -07001658
1659 def bier_route_dump(self, bti):
1660 return self.api(
1661 self.papi.bier_route_dump,
1662 {'br_tbl_id': {"bt_set": bti.set_id,
1663 "bt_sub_domain": bti.sub_domain_id,
1664 "bt_hdr_len_id": bti.hdr_len_id}})
1665
1666 def bier_imp_add(self,
1667 bti,
1668 src,
1669 ibytes,
1670 is_add=1):
1671 """ BIER Imposition Add """
1672 return self.api(
1673 self.papi.bier_imp_add,
1674 {'bi_tbl_id': {"bt_set": bti.set_id,
1675 "bt_sub_domain": bti.sub_domain_id,
1676 "bt_hdr_len_id": bti.hdr_len_id},
1677 'bi_src': src,
1678 'bi_n_bytes': len(ibytes),
1679 'bi_bytes': ibytes})
1680
1681 def bier_imp_del(self, bi_index):
1682 """ BIER Imposition del """
1683 return self.api(
1684 self.papi.bier_imp_del,
1685 {'bi_index': bi_index})
1686
1687 def bier_imp_dump(self):
1688 return self.api(self.papi.bier_imp_dump, {})
1689
1690 def bier_disp_table_add_del(self,
1691 bdti,
1692 is_add=1):
1693 """ BIER Disposition Table add/del """
1694 return self.api(
1695 self.papi.bier_disp_table_add_del,
1696 {'bdt_tbl_id': bdti,
1697 'bdt_is_add': is_add})
1698
1699 def bier_disp_table_dump(self):
1700 return self.api(self.papi.bier_disp_table_dump, {})
1701
1702 def bier_disp_entry_add_del(self,
1703 bdti,
1704 bp,
1705 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08001706 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001707 next_hop,
1708 next_hop_tbl_id=0,
1709 next_hop_rpf_id=~0,
1710 next_hop_is_ip4=1,
1711 is_add=1):
1712 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08001713 lstack = []
1714 while (len(lstack) < 16):
1715 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07001716 return self.api(
1717 self.papi.bier_disp_entry_add_del,
1718 {'bde_tbl_id': bdti,
1719 'bde_bp': bp,
1720 'bde_payload_proto': payload_proto,
1721 'bde_n_paths': 1,
1722 'bde_paths': [{'next_hop': next_hop,
1723 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08001724 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001725 'rpf_id': next_hop_rpf_id,
1726 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08001727 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07001728 'bde_is_add': is_add})
1729
1730 def bier_disp_entry_dump(self, bdti):
1731 return self.api(
1732 self.papi.bier_disp_entry_dump,
1733 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02001734
Florin Coras3ea6ce22017-12-11 09:09:05 -08001735 def session_enable_disable(self, is_enabled):
1736 return self.api(
1737 self.papi.session_enable_disable,
1738 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001739
1740 def ipsec_spd_add_del(self, spd_id, is_add=1):
1741 """ SPD add/del - Wrapper to add or del ipsec SPD
1742 Sample CLI : 'ipsec spd add 1'
1743
1744 :param spd_id - SPD ID to be created in the vpp . mandatory
1745 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
1746 optional
1747 :returns: reply from the API
1748 """
1749 return self.api(
1750 self.papi.ipsec_spd_add_del, {
1751 'spd_id': spd_id, 'is_add': is_add})
1752
Neale Ranns311124e2019-01-24 04:52:25 -08001753 def ipsec_spds_dump(self):
1754 return self.api(self.papi.ipsec_spds_dump, {})
1755
“mystarrocks”23f0c452017-12-11 07:11:51 -08001756 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
1757 """ IPSEC interface SPD add/del - \
1758 Wrapper to associate/disassociate SPD to interface in VPP
1759 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
1760
1761 :param spd_id - SPD ID to associate with the interface . mandatory
1762 :param sw_if_index - Interface Index which needs to ipsec \
1763 association mandatory
1764 :param is_add - add(1) or del(0) association with interface \
1765 (Default 1 - add) . optional
1766 :returns: reply from the API
1767 """
1768 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02001769 self.papi.ipsec_interface_add_del_spd,
1770 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08001771
Neale Ranns311124e2019-01-24 04:52:25 -08001772 def ipsec_spd_interface_dump(self, spd_index=None):
1773 return self.api(self.papi.ipsec_spd_interface_dump,
1774 {'spd_index': spd_index if spd_index else 0,
1775 'spd_index_valid': 1 if spd_index else 0})
1776
Neale Ranns17dcec02019-01-09 21:22:20 -08001777 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001778 sad_id,
1779 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02001780 integrity_algorithm,
1781 integrity_key,
1782 crypto_algorithm,
1783 crypto_key,
1784 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001785 tunnel_src_address='',
1786 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08001787 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001788 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08001789 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08001790 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02001791 :param sad_id: security association ID
1792 :param spi: security param index of the SA in decimal
1793 :param integrity_algorithm:
1794 :param integrity_key:
1795 :param crypto_algorithm:
1796 :param crypto_key:
1797 :param protocol: AH(0) or ESP(1) protocol
1798 :param tunnel_src_address: tunnel mode outer src address
1799 :param tunnel_dst_address: tunnel mode outer dst address
1800 :param is_add:
1801 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08001802 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
1803 crypto and ipsec algorithms
1804 """
1805 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001806 self.papi.ipsec_sad_entry_add_del,
1807 {
1808 'is_add': is_add,
1809 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001810 {
1811 'sad_id': sad_id,
1812 'spi': spi,
1813 'tunnel_src': tunnel_src_address,
1814 'tunnel_dst': tunnel_dst_address,
1815 'protocol': protocol,
1816 'integrity_algorithm': integrity_algorithm,
1817 'integrity_key': {
1818 'length': len(integrity_key),
1819 'data': integrity_key,
1820 },
1821 'crypto_algorithm': crypto_algorithm,
1822 'crypto_key': {
1823 'length': len(crypto_key),
1824 'data': crypto_key,
1825 },
1826 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001827 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01001828 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001829 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08001830
Neale Ranns311124e2019-01-24 04:52:25 -08001831 def ipsec_sa_dump(self, sa_id=None):
1832 return self.api(self.papi.ipsec_sa_dump,
1833 {'sa_id': sa_id if sa_id else 0xffffffff})
1834
Neale Ranns17dcec02019-01-09 21:22:20 -08001835 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001836 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02001837 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001838 local_address_start,
1839 local_address_stop,
1840 remote_address_start,
1841 remote_address_stop,
1842 local_port_start=0,
1843 local_port_stop=65535,
1844 remote_port_start=0,
1845 remote_port_stop=65535,
1846 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001847 policy=0,
1848 priority=100,
1849 is_outbound=1,
1850 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02001851 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08001852 is_ip_any=0):
1853 """ IPSEC policy SPD add/del -
1854 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02001855 :param spd_id: SPD ID for the policy
1856 :param local_address_start: local-ip-range start address
1857 :param local_address_stop : local-ip-range stop address
1858 :param remote_address_start: remote-ip-range start address
1859 :param remote_address_stop : remote-ip-range stop address
1860 :param local_port_start: (Default value = 0)
1861 :param local_port_stop: (Default value = 65535)
1862 :param remote_port_start: (Default value = 0)
1863 :param remote_port_stop: (Default value = 65535)
1864 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
1865 :param sa_id: Security Association ID for mapping it to SPD
1866 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
1867 (Default value = 0)
1868 :param priority: value for the spd action (Default value = 100)
1869 :param is_outbound: flag for inbound(0) or outbound(1)
1870 (Default value = 1)
1871 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08001872 """
1873 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08001874 self.papi.ipsec_spd_entry_add_del,
1875 {
1876 'is_add': is_add,
1877 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01001878 {
1879 'spd_id': spd_id,
1880 'sa_id': sa_id,
1881 'local_address_start': local_address_start,
1882 'local_address_stop': local_address_stop,
1883 'remote_address_start': remote_address_start,
1884 'remote_address_stop': remote_address_stop,
1885 'local_port_start': local_port_start,
1886 'local_port_stop': local_port_stop,
1887 'remote_port_start': remote_port_start,
1888 'remote_port_stop': remote_port_stop,
1889 'protocol': protocol,
1890 'policy': policy,
1891 'priority': priority,
1892 'is_outbound': is_outbound,
1893 'is_ip_any': is_ip_any
1894 }
Neale Ranns17dcec02019-01-09 21:22:20 -08001895 })
Florin Corasb795bd02017-12-14 11:30:48 -08001896
Neale Ranns311124e2019-01-24 04:52:25 -08001897 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
1898 return self.api(self.papi.ipsec_spd_dump,
1899 {'spd_id': spd_id,
1900 'sa_id': sa_id})
1901
Klement Sekera31da2e32018-06-24 22:49:55 +02001902 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
1903 remote_spi, crypto_alg, local_crypto_key,
1904 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001905 remote_integ_key, is_add=1, esn=0, salt=0,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001906 anti_replay=1, renumber=0,
1907 udp_encap=0, show_instance=0):
Klement Sekera31da2e32018-06-24 22:49:55 +02001908 return self.api(
1909 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001910 {
1911 'local_ip': local_ip,
1912 'remote_ip': remote_ip,
1913 'local_spi': local_spi,
1914 'remote_spi': remote_spi,
1915 'crypto_alg': crypto_alg,
1916 'local_crypto_key_len': len(local_crypto_key),
1917 'local_crypto_key': local_crypto_key,
1918 'remote_crypto_key_len': len(remote_crypto_key),
1919 'remote_crypto_key': remote_crypto_key,
1920 'integ_alg': integ_alg,
1921 'local_integ_key_len': len(local_integ_key),
1922 'local_integ_key': local_integ_key,
1923 'remote_integ_key_len': len(remote_integ_key),
1924 'remote_integ_key': remote_integ_key,
1925 'is_add': is_add,
1926 'esn': esn,
1927 'anti_replay': anti_replay,
1928 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001929 'show_instance': show_instance,
Neale Rannsa6bee0a2019-06-14 01:13:25 -07001930 'udp_encap': udp_encap,
Neale Ranns80f6fd52019-04-16 02:41:34 +00001931 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04001932 })
Klement Sekera31da2e32018-06-24 22:49:55 +02001933
Klement Sekerab4d30532018-11-08 13:00:02 +01001934 def ipsec_select_backend(self, protocol, index):
1935 return self.api(self.papi.ipsec_select_backend,
1936 {'protocol': protocol, 'index': index})
1937
1938 def ipsec_backend_dump(self):
1939 return self.api(self.papi.ipsec_backend_dump, {})
1940
Ole Troane1ade682019-03-04 23:55:43 +01001941 def app_namespace_add_del(self,
1942 namespace_id,
1943 ip4_fib_id=0,
1944 ip6_fib_id=0,
1945 sw_if_index=0xFFFFFFFF,
1946 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08001947 return self.api(
1948 self.papi.app_namespace_add_del,
1949 {'secret': secret,
1950 'sw_if_index': sw_if_index,
1951 'ip4_fib_id': ip4_fib_id,
1952 'ip6_fib_id': ip6_fib_id,
1953 'namespace_id': namespace_id,
1954 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02001955
Neale Ranns50f0ac02019-05-15 02:13:37 -07001956 def punt_socket_register(self, reg, pathname,
1957 header_version=1):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001958 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02001959 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001960 {'header_version': header_version,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001961 'punt': reg,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001962 'pathname': pathname})
1963
Neale Ranns50f0ac02019-05-15 02:13:37 -07001964 def punt_socket_deregister(self, reg):
Pavel Kotuceke88865d2018-11-28 07:42:11 +01001965 """ Unregister punt socket """
1966 return self.api(self.papi.punt_socket_deregister,
Neale Ranns50f0ac02019-05-15 02:13:37 -07001967 {'punt': reg})
Klement Sekera75e7d132017-09-20 08:26:30 +02001968
Neale Ranns4ba67722019-02-28 11:11:39 +00001969 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001970 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07001971 """ GBP endpoint Add """
1972 return self.api(self.papi.gbp_endpoint_add,
1973 {'endpoint': {
1974 'sw_if_index': sw_if_index,
1975 'ips': ips,
1976 'n_ips': len(ips),
1977 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00001978 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001979 'flags': flags,
1980 'tun': {
1981 'src': tun_src,
1982 'dst': tun_dst,
1983 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07001984
1985 def gbp_endpoint_del(self, handle):
1986 """ GBP endpoint Del """
1987 return self.api(self.papi.gbp_endpoint_del,
1988 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001989
1990 def gbp_endpoint_dump(self):
1991 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01001992 return self.api(self.papi.gbp_endpoint_dump,
1993 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08001994
Neale Ranns4ba67722019-02-28 11:11:39 +00001995 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08001996 rd, uplink_sw_if_index,
1997 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07001998 """ GBP endpoint group Add """
1999 return self.api(self.papi.gbp_endpoint_group_add,
2000 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002001 {
2002 'uplink_sw_if_index': uplink_sw_if_index,
2003 'bd_id': bd,
2004 'rd_id': rd,
2005 'vnid': vnid,
2006 'sclass': sclass,
2007 'retention': retention
2008 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002009
Neale Ranns4ba67722019-02-28 11:11:39 +00002010 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002011 """ GBP endpoint group Del """
2012 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002013 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002014
Neale Rannsc29c0af2018-11-07 04:21:12 -08002015 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002016 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002017 uu_fwd_sw_if_index,
2018 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002019 """ GBP bridge-domain Add """
2020 return self.api(self.papi.gbp_bridge_domain_add,
2021 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002022 {
2023 'flags': flags,
2024 'bvi_sw_if_index': bvi_sw_if_index,
2025 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2026 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2027 'bd_id': bd_id
2028 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002029
2030 def gbp_bridge_domain_del(self, bd_id):
2031 """ GBP bridge-domain Del """
2032 return self.api(self.papi.gbp_bridge_domain_del,
2033 {'bd_id': bd_id})
2034
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002035 def gbp_route_domain_add(self, rd_id,
2036 ip4_table_id,
2037 ip6_table_id,
2038 ip4_uu_sw_if_index,
2039 ip6_uu_sw_if_index):
2040 """ GBP route-domain Add """
2041 return self.api(self.papi.gbp_route_domain_add,
2042 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002043 {
2044 'ip4_table_id': ip4_table_id,
2045 'ip6_table_id': ip6_table_id,
2046 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2047 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2048 'rd_id': rd_id
2049 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002050
2051 def gbp_route_domain_del(self, rd_id):
2052 """ GBP route-domain Del """
2053 return self.api(self.papi.gbp_route_domain_del,
2054 {'rd_id': rd_id})
2055
Neale Ranns4ba67722019-02-28 11:11:39 +00002056 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002057 """ GBP recirc Add/Del """
2058 return self.api(self.papi.gbp_recirc_add_del,
2059 {'is_add': is_add,
2060 'recirc': {
2061 'is_ext': is_ext,
2062 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002063 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002064
2065 def gbp_recirc_dump(self):
2066 """ GBP recirc Dump """
2067 return self.api(self.papi.gbp_recirc_dump, {})
2068
Neale Rannsb6a47952018-11-21 05:44:35 -08002069 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2070 """ GBP recirc Add/Del """
2071 return self.api(self.papi.gbp_ext_itf_add_del,
2072 {'is_add': is_add,
2073 'ext_itf': {
2074 'sw_if_index': sw_if_index,
2075 'bd_id': bd_id,
2076 'rd_id': rd_id}})
2077
2078 def gbp_ext_itf_dump(self):
2079 """ GBP recirc Dump """
2080 return self.api(self.papi.gbp_ext_itf_dump, {})
2081
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002082 def gbp_subnet_add_del(self, is_add, rd_id,
2083 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002084 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002085 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002086 """ GBP Subnet Add/Del """
2087 return self.api(self.papi.gbp_subnet_add_del,
2088 {'is_add': is_add,
2089 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002090 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002091 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002092 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002093 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002094 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002095
2096 def gbp_subnet_dump(self):
2097 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002098 return self.api(self.papi.gbp_subnet_dump,
2099 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002100
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002101 def gbp_contract_dump(self):
2102 """ GBP contract Dump """
2103 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002104
Neale Ranns8da9fc62019-03-04 14:08:11 -08002105 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002106 """ GBP VXLAN tunnel add """
2107 return self.api(self.papi.gbp_vxlan_tunnel_add,
2108 {
2109 'tunnel': {
2110 'vni': vni,
2111 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002112 'bd_rd_id': bd_rd_id,
2113 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002114 }
2115 })
2116
2117 def gbp_vxlan_tunnel_del(self, vni):
2118 """ GBP VXLAN tunnel del """
2119 return self.api(self.papi.gbp_vxlan_tunnel_del,
2120 {
2121 'vni': vni,
2122 })
2123
2124 def gbp_vxlan_tunnel_dump(self):
2125 """ GBP VXLAN tunnel add/del """
2126 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2127
Neale Ranns039cbfe2018-02-27 03:45:38 -08002128 def qos_egress_map_update(self, id, outputs):
2129 """ QOS egress map update """
2130 return self.api(self.papi.qos_egress_map_update,
2131 {'map_id': id,
2132 'rows': outputs})
2133
2134 def qos_egress_map_delete(self, id):
2135 """ QOS egress map delete """
2136 return self.api(self.papi.qos_egress_map_delete,
2137 {'map_id': id})
2138
2139 def qos_mark_enable_disable(self, sw_if_index,
2140 output_source,
2141 map_id,
2142 enable):
2143 """ QOS Mark Enable/Disable """
2144 return self.api(self.papi.qos_mark_enable_disable,
2145 {'map_id': map_id,
2146 'sw_if_index': sw_if_index,
2147 'output_source': output_source,
2148 'enable': enable})
2149
Neale Ranns947ea622018-06-07 23:48:20 -07002150 def igmp_enable_disable(self, sw_if_index, enable, host):
2151 """ Enable/disable IGMP on a given interface """
2152 return self.api(self.papi.igmp_enable_disable,
2153 {'enable': enable,
2154 'mode': host,
2155 'sw_if_index': sw_if_index})
2156
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002157 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2158 """ Add/del IGMP proxy device """
2159 return self.api(self.papi.igmp_proxy_device_add_del,
2160 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2161 'add': add})
2162
2163 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2164 """ Add/del interface to/from IGMP proxy device """
2165 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2166 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2167 'add': add})
2168
Neale Ranns947ea622018-06-07 23:48:20 -07002169 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002170 """ Listen for new (S,G) on specified interface
2171
2172 :param enable: add/del
2173 :param sw_if_index: interface sw index
2174 :param saddr: source ip4 addr
2175 :param gaddr: group ip4 addr
2176 """
2177 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002178 {
2179 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002180 {
2181 'filter': filter,
2182 'sw_if_index': sw_if_index,
2183 'n_srcs': len(saddrs),
2184 'saddrs': saddrs,
2185 'gaddr': gaddr
2186 }
Neale Ranns947ea622018-06-07 23:48:20 -07002187 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002188
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002189 def igmp_clear_interface(self, sw_if_index):
2190 """ Remove all (S,G)s from specified interface
2191 doesn't send IGMP report!
2192 """
2193 return self.api(
2194 self.papi.igmp_clear_interface, {
2195 'sw_if_index': sw_if_index})
2196
2197 def want_igmp_events(self, enable=1):
2198 return self.api(self.papi.want_igmp_events, {'enable': enable,
2199 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002200
2201 def bond_create(
2202 self,
2203 mode,
2204 lb,
2205 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002206 mac_address='',
2207 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002208 """
2209 :param mode: mode
2210 :param lb: load balance
2211 :param use_custom_mac: use custom mac
2212 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002213 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002214 """
2215 return self.api(
2216 self.papi.bond_create,
2217 {'mode': mode,
2218 'lb': lb,
2219 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002220 'mac_address': mac_address,
2221 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002222 })
2223
Neale Ranns17ff3c12018-07-04 10:24:24 -07002224 def pipe_delete(self, parent_sw_if_index):
2225 return self.api(self.papi.pipe_delete,
2226 {'parent_sw_if_index': parent_sw_if_index})
2227
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002228 def svs_table_add_del(self, af, table_id, is_add=1):
2229 return self.api(self.papi.svs_table_add_del,
2230 {
2231 'table_id': table_id,
2232 'is_add': is_add,
2233 'af': af,
2234 })
2235
2236 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2237 return self.api(self.papi.svs_route_add_del,
2238 {
2239 'table_id': table_id,
2240 'source_table_id': src_table_id,
2241 'prefix': prefix,
2242 'is_add': is_add,
2243 })
2244
2245 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2246 return self.api(self.papi.svs_enable_disable,
2247 {
2248 'af': af,
2249 'table_id': table_id,
2250 'sw_if_index': sw_if_index,
2251 'is_enable': is_enable,
2252 })