blob: 62fc0aa42b3c8db8774aed7b0aa417d9d1f5c1c3 [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 Vinciguerra84679192019-01-13 11:33:52 -080013from vpp_papi import VPP, 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
Neale Ranns039cbfe2018-02-27 03:45:38 -080018class QOS_SOURCE:
19 EXT = 0
20 VLAN = 1
21 MPLS = 2
22 IP = 3
23
24
Matus Fabianb4515b42018-11-19 04:25:32 -080025class SYSLOG_SEVERITY:
26 EMERG = 0
27 ALERT = 1
28 CRIT = 2
29 ERR = 3
30 WARN = 4
31 NOTICE = 5
32 INFO = 6
33 DBG = 7
34
Ole Troan9a475372019-03-05 16:58:24 +010035
Ole Troanf159f582019-02-28 20:20:47 +010036#
37# Dictionary keyed on message name to override default values for
38# named parameters
39#
Ole Troan9a475372019-03-05 16:58:24 +010040defaultmapping = {
41 'map_add_domain': {'mtu': 1280},
42 'syslog_set_sender': {'collector_port': 514,
43 'max_msg_size': 480},
44 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
45 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
46 'app_namespace_add_del': {'sw_if_index': 4294967295, },
47 'bd_ip_mac_add_del': {'is_add': 1, },
48 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
49 'is_add': 1, },
50 'bier_disp_table_add_del': {'is_add': 1, },
51 'bier_imp_add': {'is_add': 1, },
52 'bier_route_add_del': {'is_add': 1, },
53 'bier_table_add_del': {'is_add': 1, },
54 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
55 'learn': 1, 'is_add': 1, },
56 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
57 'nbuckets': 2, 'memory_size': 2097152,
58 'next_table_index': 4294967295,
59 'miss_next_index': 4294967295, },
60 'dhcp6_client_enable_disable': {'enable': 1, },
61 'dhcp6_clients_enable_disable': {'enable': 1, },
62 'dhcp6_pd_client_enable_disable': {'enable': 1, },
63 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
64 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
65 'dhcp_proxy_config': {'is_add': 1, },
66 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
67 'dslite_add_del_pool_addr_range': {'is_add': 1, },
68 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
69 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
70 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000071 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010072 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
73 'decap_next_index': 4294967295, },
74 'input_acl_set_interface': {'ip4_table_index': 4294967295,
75 'ip6_table_index': 4294967295,
76 'l2_table_index': 4294967295, },
77 'ip6_add_del_address_using_prefix': {'is_add': 1, },
78 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
79 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
80 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
81 'next_hop_id': 4294967295,
82 'classify_table_index': 4294967295, 'is_add': 1, },
83 'ip_mroute_add_del': {'is_add': 1, },
84 'ip_neighbor_add_del': {'is_add': 1, },
85 'ip_punt_police': {'is_add': 1, },
86 'ip_punt_redirect': {'is_add': 1, },
87 'ip_table_add_del': {'is_add': 1, },
88 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
89 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
90 'ipsec_interface_add_del_spd': {'is_add': 1, },
91 'ipsec_sad_entry_add_del': {'is_add': 1, },
92 'ipsec_spd_add_del': {'is_add': 1, },
93 'ipsec_spd_dump': {'sa_id': 4294967295, },
94 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
95 'remote_port_stop': 65535, 'priority': 100,
96 'is_outbound': 1,
97 'is_add': 1, },
98 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
99 'l2_emulation': {'enable': 1, },
100 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700101 'lb_conf': {'sticky_buckets_per_core': 4294967295,
102 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +0100103 'lisp_add_del_adjacency': {'is_add': 1, },
104 'lisp_add_del_local_eid': {'is_add': 1, },
105 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
106 'lisp_add_del_locator_set': {'is_add': 1, },
107 'lisp_add_del_remote_mapping': {'is_add': 1, },
108 'macip_acl_add_replace': {'acl_index': 4294967295, },
109 'macip_acl_dump': {'acl_index': 4294967295, },
110 'macip_acl_interface_add_del': {'is_add': 1, },
111 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +0100112 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
113 'mr_next_hop_weight': 1,
114 'mr_next_hop_via_label': 1048576,
115 'mr_is_add': 1,
116 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100117 'mpls_table_add_del': {'is_add': 1, },
118 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
119 'next_hop_weight': 1,
120 'next_hop_via_label': 1048576,
121 'is_add': 1, },
122 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
123 'nat44_add_del_address_range': {'is_add': 1, 'vrf_id': 4294967295, },
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800124 'nat44_add_del_identity_mapping': {'ip': b'0', 'sw_if_index': 4294967295,
Ole Troan9a475372019-03-05 16:58:24 +0100125 'addr_only': 1, 'is_add': 1, },
126 'nat44_add_del_interface_addr': {'is_add': 1, },
127 'nat44_add_del_lb_static_mapping': {'is_add': 1, },
128 'nat44_add_del_static_mapping': {'external_sw_if_index': 4294967295,
129 'addr_only': 1, 'is_add': 1, },
130 'nat44_del_session': {'is_in': 1, },
131 'nat44_interface_add_del_feature': {'is_inside': 1, 'is_add': 1, },
132 'nat44_interface_add_del_output_feature': {'is_inside': 1, 'is_add': 1, },
133 'nat44_lb_static_mapping_add_del_local': {'is_add': 1, },
134 'nat64_add_del_interface': {'is_inside': 1, 'is_add': 1, },
135 'nat64_add_del_interface_addr': {'is_add': 1, },
136 'nat64_add_del_pool_addr_range': {'vrf_id': 4294967295, 'is_add': 1, },
137 'nat64_add_del_prefix': {'is_add': 1, },
138 'nat64_add_del_static_bib': {'is_add': 1, },
139 'nat64_bib_dump': {'protocol': 255, },
140 'nat64_st_dump': {'protocol': 255, },
141 'nat66_add_del_interface': {'is_inside': 1, 'is_add': 1, },
142 'nat66_add_del_static_mapping': {'is_add': 1, },
143 'nat_det_add_del_map': {'is_add': 1, },
144 'nat_ha_resync': {'want_resync_event': 1, },
145 'nat_ha_set_failover': {'refresh': 10, },
146 'nat_ha_set_listener': {'path_mtu': 512, },
147 'nat_ipfix_enable_disable': {'domain_id': 1, 'src_port': 4739,
148 'enable': 1, },
149 'nat_set_mss_clamping': {'mss_value': 1500, },
150 'nat_set_reass': {'timeout': 2, 'max_reass': 1024, 'max_frag': 5, },
151 'nat_set_timeouts': {'udp': 300, 'tcp_established': 7440,
152 'tcp_transitory': 240, 'icmp': 60, },
153 'output_acl_set_interface': {'ip4_table_index': 4294967295,
154 'ip6_table_index': 4294967295,
155 'l2_table_index': 4294967295, },
156 'pppoe_add_del_session': {'is_add': 1, },
157 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
158 'proxy_arp_add_del': {'is_add': 1, },
159 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
160 'punt_socket_register': {'protocol': 17, 'header_version': 1,
161 'is_ip4': 1, },
162 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, },
163 'punt_socket_dump': {'is_ip6': 1, },
164 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
165 'proto': 1, },
166 'set_ipfix_exporter': {'collector_port': 4739, },
167 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
168 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
169 'svs_enable_disable': {'is_enable': 1, },
170 'svs_route_add_del': {'is_add': 1, },
171 'svs_table_add_del': {'is_add': 1, },
172 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700173 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100174 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
175 'pref_lifetime': 4294967295, },
176 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
177 'sw_interface_set_l2_bridge': {'enable': 1, },
178 'sw_interface_set_mpls_enable': {'enable': 1, },
179 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
180 'sw_interface_set_unnumbered': {'is_add': 1, },
181 'sw_interface_span_enable_disable': {'state': 1, },
182 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
183 'decap_next_index': 4294967295,
184 'instance': 4294967295, },
185 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
186 'instance': 4294967295, },
187 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
188 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
189 'protocol': 3, },
190 'want_bfd_events': {'enable_disable': 1, },
191 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
192 'want_dhcp6_reply_events': {'enable_disable': 1, },
193 'want_igmp_events': {'enable': 1, },
194 'want_interface_events': {'enable_disable': 1, },
195 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
196 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
197 'want_ip6_ra_events': {'enable_disable': 1, },
198 'want_l2_macs_events': {'enable_disable': 1, },
199}
Ole Troanf159f582019-02-28 20:20:47 +0100200
Matus Fabianb4515b42018-11-19 04:25:32 -0800201
Klement Sekera73884482017-02-23 09:26:30 +0100202class UnexpectedApiReturnValueError(Exception):
203 """ exception raised when the API return value is unexpected """
204 pass
205
206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207class VppPapiProvider(object):
208 """VPP-api provider using vpp-papi
209
210 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200211 """
212
Klement Sekerae0545ef2017-01-25 08:00:40 +0100213 _zero, _negative = range(2)
214
Klement Sekera611864f2018-09-26 11:19:00 +0200215 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800216 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217 self.name = name
218 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100219 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100220 self._expect_api_retval = self._zero
221 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100222
Klement Sekerab8c72a42018-11-08 11:21:39 +0100223 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +0100224
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800225 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
226 if 'VPP_API_DIR' not in os.environ:
227 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
228
229 self.vpp = VPP(logger=test_class.logger,
Klement Sekera611864f2018-09-26 11:19:00 +0200230 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100231 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200232
Klement Sekerae0545ef2017-01-25 08:00:40 +0100233 def __enter__(self):
234 return self
235
Klement Sekera7d6afb32018-11-08 11:52:04 +0100236 def assert_negative_api_retval(self):
237 """ Expect API failure - used with with, e.g.:
238 with self.vapi.assert_negative_api_retval():
239 self.vapi.<api call expected to fail>
240 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100241 self._expect_stack.append(self._expect_api_retval)
242 self._expect_api_retval = self._negative
243 return self
244
Klement Sekera7d6afb32018-11-08 11:52:04 +0100245 def assert_zero_api_retval(self):
246 """ Expect API success - used with with, e.g.:
247 with self.vapi.assert_negative_api_retval():
248 self.vapi.<api call expected to succeed>
249
250 note: this is useful only inside another with block
251 as success is the default expected value
252 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100253 self._expect_stack.append(self._expect_api_retval)
254 self._expect_api_retval = self._zero
255 return self
256
257 def __exit__(self, exc_type, exc_value, traceback):
258 self._expect_api_retval = self._expect_stack.pop()
259
Klement Sekeraf62ae122016-10-11 11:47:09 +0200260 def register_hook(self, hook):
261 """Replace hook registration with new hook
262
263 :param hook:
264
265 """
266 self.hook = hook
267
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200268 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100269 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200270 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100271 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200272 return e
273
274 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100275 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100276 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100277 self.test_class.logger.debug("Expecting event '%s' within %ss",
278 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300279 else:
280 self.test_class.logger.debug("Expecting event within %ss",
281 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100282 if self._events:
283 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200284 limit = time.time() + timeout
285 while time.time() < limit:
286 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100287 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200288 if name and type(e).__name__ != name:
289 raise Exception(
290 "Unexpected event received: %s, expected: %s" %
291 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100292 self.test_class.logger.debug("Returning event %s:%s" %
293 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200294 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700295 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200296 raise Exception("Event did not occur within timeout")
297
298 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100299 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200300 # FIXME use the name instead of relying on type(e).__name__ ?
301 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100302 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200303 self._events.append(event)
304
Ole Troanf159f582019-02-28 20:20:47 +0100305 def factory(self, name, apifn):
306 def f(*a, **ka):
307 fields = apifn._func.msg.fields
308
309 # add positional and kw arguments
310 d = ka
311 for i, o in enumerate(fields[3:]):
312 try:
313 d[o] = a[i]
314 except:
315 break
316
317 # Default override
318 if name in defaultmapping:
319 for k, v in iteritems(defaultmapping[name]):
320 if k in d:
321 continue
322 d[k] = v
323 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100324
Ole Troanf159f582019-02-28 20:20:47 +0100325 return f
326
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800327 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100328 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800329 method = super(VppPapiProvider, self).__getattribute__(name)
330 except AttributeError:
331 method = self.factory(name, getattr(self.papi, name))
332 # lazily load the method so we don't need to call factory
333 # again for this name.
334 setattr(self, name, method)
335 return method
Ole Troanf159f582019-02-28 20:20:47 +0100336
Klement Sekeraf62ae122016-10-11 11:47:09 +0200337 def connect(self):
338 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100339 self.vpp.connect(self.name, self.shm_prefix)
340 self.papi = self.vpp.api
341 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200342
343 def disconnect(self):
344 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100345 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200346
347 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100348 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200349 Call the appropriate hooks before and after the API call
350
351 :param api_fn: API function to call
352 :param api_args: tuple of API function arguments
353 :param expected_retval: Expected return value (Default value = 0)
354 :returns: reply from the API
355
356 """
357 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100358 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100359 if self._expect_api_retval == self._negative:
360 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100361 msg = "API call passed unexpectedly: expected negative " \
362 "return value instead of %d in %s" % \
363 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100364 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100365 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100366 elif self._expect_api_retval == self._zero:
367 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100368 msg = "API call failed, expected %d return value instead " \
369 "of %d in %s" % (expected_retval, reply.retval,
370 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100371 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100372 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100373 else:
374 raise Exception("Internal error, unexpected value for "
375 "self._expect_api_retval %s" %
376 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200377 self.hook.after_api(api_fn.__name__, api_args)
378 return reply
379
380 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100381 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200382
383 :param cli: CLI to execute
384 :returns: CLI output
385
386 """
387 self.hook.before_cli(cli)
388 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100389 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200390 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200391 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100392 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200393
Jan49c0fca2016-10-26 15:44:27 +0200394 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100395 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200396
397 :param cli: CLI to execute
398 :returns: CLI output
399 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600400 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200401
Neale Ranns37029302018-08-10 05:30:06 -0700402 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300403 return self.api(self.papi.want_ip4_arp_events,
404 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700405 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300406 'pid': os.getpid(), })
407
Neale Ranns37029302018-08-10 05:30:06 -0700408 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300409 return self.api(self.papi.want_ip6_nd_events,
410 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700411 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300412 'pid': os.getpid(), })
413
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100414 def want_ip6_ra_events(self, enable_disable=1):
415 return self.api(self.papi.want_ip6_ra_events,
416 {'enable_disable': enable_disable,
417 'pid': os.getpid(), })
418
419 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
420 mrc=0, mrd=0):
421 return self.api(self.papi.ip6nd_send_router_solicitation,
422 {'irt': irt,
423 'mrt': mrt,
424 'mrc': mrc,
425 'mrd': mrd,
426 'sw_if_index': sw_if_index})
427
Juraj Slobodab3f90502018-10-04 15:15:16 +0200428 def want_interface_events(self, enable_disable=1):
429 return self.api(self.papi.want_interface_events,
430 {'enable_disable': enable_disable,
431 'pid': os.getpid(), })
432
Ole Troane1ade682019-03-04 23:55:43 +0100433 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
434 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300435 return self.api(self.papi.want_l2_macs_events,
436 {'enable_disable': enable_disable,
437 'scan_delay': scan_delay,
438 'max_macs_in_event': max_macs_in_event,
439 'learn_limit': learn_limit,
440 'pid': os.getpid(), })
441
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200442 def want_dhcp6_reply_events(self, enable_disable=1):
443 return self.api(self.papi.want_dhcp6_reply_events,
444 {'enable_disable': enable_disable,
445 'pid': os.getpid()})
446
Juraj Sloboda81119e82018-05-25 14:02:20 +0200447 def want_dhcp6_pd_reply_events(self, enable_disable=1):
448 return self.api(self.papi.want_dhcp6_pd_reply_events,
449 {'enable_disable': enable_disable,
450 'pid': os.getpid()})
451
Juraj Sloboda81119e82018-05-25 14:02:20 +0200452 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
453 prefixes, server_index=0xFFFFFFFF,
454 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
455 ):
456 return self.api(self.papi.dhcp6_pd_send_client_message,
457 {'sw_if_index': sw_if_index,
458 'server_index': server_index,
459 'irt': irt,
460 'mrt': mrt,
461 'mrc': mrc,
462 'mrd': mrd,
463 'stop': stop,
464 'msg_type': msg_type,
465 'T1': T1,
466 'T2': T2,
467 'n_prefixes': len(prefixes),
468 'prefixes': prefixes})
469
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200470 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
471 enable=1):
472 return self.api(self.papi.dhcp6_client_enable_disable,
473 {'sw_if_index': sw_if_index,
474 'enable': enable})
475
Juraj Sloboda81119e82018-05-25 14:02:20 +0200476 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
477 enable=1):
478 return self.api(self.papi.dhcp6_pd_client_enable_disable,
479 {'sw_if_index': sw_if_index,
480 'prefix_group': prefix_group,
481 'enable': enable})
482
483 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
484 prefix_length, prefix_group,
485 is_add=1):
486 return self.api(self.papi.ip6_add_del_address_using_prefix,
487 {'sw_if_index': sw_if_index,
488 'prefix_group': prefix_group,
489 'address': address,
490 'prefix_length': prefix_length,
491 'is_add': is_add})
492
Neale Rannsc819fc62018-02-16 02:44:05 -0800493 def sw_interface_set_mac_address(self, sw_if_index, mac):
494 return self.api(self.papi.sw_interface_set_mac_address,
495 {'sw_if_index': sw_if_index,
496 'mac_address': mac})
497
Ole Troane1ade682019-03-04 23:55:43 +0100498 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200499 """Create p2p ethernet subinterface
500
501 :param sw_if_index: main (parent) interface
502 :param remote_mac: client (remote) mac address
503
504 """
505 return self.api(
506 self.papi.p2p_ethernet_add,
507 {'parent_if_index': sw_if_index,
508 'remote_mac': remote_mac,
509 'subif_id': subif_id})
510
Ole Troane1ade682019-03-04 23:55:43 +0100511 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200512 """Delete p2p ethernet subinterface
513
514 :param sw_if_index: main (parent) interface
515 :param remote_mac: client (remote) mac address
516
517 """
518 return self.api(
519 self.papi.p2p_ethernet_del,
520 {'parent_if_index': sw_if_index,
521 'remote_mac': remote_mac})
522
Klement Sekeraf62ae122016-10-11 11:47:09 +0200523 def create_vlan_subif(self, sw_if_index, vlan):
524 """
525
526 :param vlan:
527 :param sw_if_index:
528
529 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100530 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200531 {'sw_if_index': sw_if_index,
532 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200533
Matej Klotton0178d522016-11-04 11:11:44 +0100534 def create_loopback(self, mac=''):
535 """
536
537 :param mac: (Optional)
538 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100539 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200540 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100541
Matej Klotton0178d522016-11-04 11:11:44 +0100542 def ip_neighbor_add_del(self,
543 sw_if_index,
544 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700545 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100546 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700547 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100548 """ Add neighbor MAC to IPv4 or IPv6 address.
549
550 :param sw_if_index:
551 :param mac_address:
552 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100553 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700554 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100555 """
Matej Klotton0178d522016-11-04 11:11:44 +0100556 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100557 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700558 {
559 'is_add': is_add,
560 'neighbor': {
561 'sw_if_index': sw_if_index,
562 'flags': flags,
563 'mac_address': mac_address,
564 'ip_address': ip_address
565 }
566 }
Matej Klotton0178d522016-11-04 11:11:44 +0100567 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100568
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800569 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700570 low,
571 hi,
572 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800573 is_add=1):
574 """ Config Proxy Arp Range.
575
576 :param low_address: Start address in the rnage to Proxy for
577 :param hi_address: End address in the rnage to Proxy for
578 :param vrf_id: The VRF/table in which to proxy
579 """
580
581 return self.api(
582 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700583 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100584 {
585 'table_id': table_id,
586 'low': low,
587 'hi': hi,
588 },
589 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800590
591 def proxy_arp_intfc_enable_disable(self,
592 sw_if_index,
593 is_enable=1):
594 """ Enable/Disable an interface for proxy ARP requests
595
596 :param sw_if_index: Interface
597 :param enable_disable: Enable/Disable
598 """
599
600 return self.api(
601 self.papi.proxy_arp_intfc_enable_disable,
602 {'sw_if_index': sw_if_index,
603 'enable_disable': is_enable
604 }
605 )
606
Neale Ranns5a8844b2019-04-16 07:15:35 +0000607 def gre_tunnel_add_del(self,
608 src,
609 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000610 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500611 tunnel_type=0,
612 instance=0xFFFFFFFF,
613 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000614 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000615 """ Add a GRE tunnel
616
617 :param src_address:
618 :param dst_address:
619 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500620 :param tunnel_type: (Default value = 0)
621 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700622 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000623 :param is_add: (Default value = 1)
624 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000625 """
626
627 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000628 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200629 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000630 'tunnel':
631 {
632 'type': tunnel_type,
633 'instance': instance,
634 'src': src,
635 'dst': dst,
636 'outer_fib_id': outer_fib_id,
637 'session_id': session_id}
638 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000639 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000640
Neale Rannsd0df49f2018-08-08 01:06:40 -0700641 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700642 src_ip,
643 dst_ip,
644 src_port,
645 dst_port,
646 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800647 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800648 :param src_ip:
649 :param dst_ip:
650 :param src_port:
651 :param dst_port:
652 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800653 """
654
655 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700656 self.papi.udp_encap_add,
657 {
658 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700659 'src_ip': src_ip,
660 'dst_ip': dst_ip,
661 'src_port': src_port,
662 'dst_port': dst_port,
663 'table_id': table_id
664 }
665 })
666
Neale Ranns15002542017-09-10 04:39:11 -0700667 def mpls_table_add_del(
668 self,
669 table_id,
670 is_add=1):
671 """
672
673 :param table_id
674 :param is_add: (Default value = 1)
675
676 """
677
678 return self.api(
679 self.papi.mpls_table_add_del,
680 {'mt_table_id': table_id,
681 'mt_is_add': is_add})
682
Neale Rannsad422ed2016-11-02 14:20:04 +0000683 def mpls_ip_bind_unbind(
684 self,
685 label,
686 dst_address,
687 dst_address_length,
688 table_id=0,
689 ip_table_id=0,
690 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000691 is_bind=1):
692 """
693 """
694 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100695 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200696 {'mb_mpls_table_id': table_id,
697 'mb_label': label,
698 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200699 'mb_is_bind': is_bind,
700 'mb_is_ip4': is_ip4,
701 'mb_address_length': dst_address_length,
702 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000703
704 def mpls_tunnel_add_del(
705 self,
706 tun_sw_if_index,
707 next_hop_proto_is_ip4,
708 next_hop_address,
709 next_hop_sw_if_index=0xFFFFFFFF,
710 next_hop_table_id=0,
711 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200712 next_hop_n_out_labels=0,
713 next_hop_out_label_stack=[],
714 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000715 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800716 l2_only=0,
717 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000718 """
719
720 :param dst_address_length:
721 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
722 :param dst_address:
723 :param next_hop_address:
724 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
725 :param vrf_id: (Default value = 0)
726 :param lookup_in_vrf: (Default value = 0)
727 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000728 :param is_add: (Default value = 1)
729 :param is_drop: (Default value = 0)
730 :param is_ipv6: (Default value = 0)
731 :param is_local: (Default value = 0)
732 :param is_classify: (Default value = 0)
733 :param is_multipath: (Default value = 0)
734 :param is_resolve_host: (Default value = 0)
735 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000736 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800737 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000738
739 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000740 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100741 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200742 {'mt_sw_if_index': tun_sw_if_index,
743 'mt_is_add': is_add,
744 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800745 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200746 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
747 'mt_next_hop_weight': next_hop_weight,
748 'mt_next_hop': next_hop_address,
749 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
750 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
751 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700752 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200753 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800754
Matus Fabian2ba92e32017-08-21 07:05:03 -0700755 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -0800756 self,
757 sw_if_index,
758 is_inside=1,
759 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700760 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -0800761
762 :param sw_if_index: Software index of the interface
763 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
764 :param is_add: 1 if add, 0 if delete (Default value = 1)
765 """
766 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700767 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200768 {'is_add': is_add,
769 'is_inside': is_inside,
770 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800771
Matus Fabian2ba92e32017-08-21 07:05:03 -0700772 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -0700773 self,
774 sw_if_index,
775 is_inside=1,
776 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700777 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700778
779 :param sw_if_index: Software index of the interface
780 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
781 :param is_add: 1 if add, 0 if delete (Default value = 1)
782 """
783 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700784 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -0700785 {'is_add': is_add,
786 'is_inside': is_inside,
787 'sw_if_index': sw_if_index})
788
Matus Fabian2ba92e32017-08-21 07:05:03 -0700789 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -0800790 self,
791 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800792 external_ip=0,
793 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800794 local_port=0,
795 external_port=0,
796 addr_only=1,
797 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800798 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -0800799 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200800 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -0800801 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800802 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -0700803 is_add=1):
804 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -0800805
806 :param local_ip: Local IP address
807 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800808 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800809 :param local_port: Local port number (Default value = 0)
810 :param external_port: External port number (Default value = 0)
811 :param addr_only: 1 if address only mapping, 0 if address and port
812 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800813 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -0800814 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200815 :param self_twice_nat: 1 if translate external host address and port
816 whenever external host address equals
817 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -0800818 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -0800819 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -0800820 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800821 """
822 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700823 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200824 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200825 'addr_only': addr_only,
826 'local_ip_address': local_ip,
827 'external_ip_address': external_ip,
828 'local_port': local_port,
829 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800830 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800831 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -0800832 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -0800833 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200834 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -0800835 'out2in_only': out2in_only,
836 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -0800837
Matus Fabianab7a8052017-11-28 04:29:41 -0800838 def nat44_add_del_identity_mapping(
839 self,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800840 ip=b'0',
Matus Fabianab7a8052017-11-28 04:29:41 -0800841 sw_if_index=0xFFFFFFFF,
842 port=0,
843 addr_only=1,
844 vrf_id=0,
845 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800846 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -0800847 is_add=1):
848 """Add/delete NAT44 identity mapping
849
850 :param ip: IP address (Default value = 0)
851 :param sw_if_index: Interface instead of IP address
852 :param port: Port number (Default value = 0)
853 :param addr_only: 1 if address only mapping, 0 if address and port
854 :param vrf_id: VRF ID
855 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -0800856 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -0800857 :param is_add: 1 if add, 0 if delete (Default value = 1)
858 """
859 return self.api(
860 self.papi.nat44_add_del_identity_mapping,
861 {'is_add': is_add,
862 'addr_only': addr_only,
863 'ip_address': ip,
864 'port': port,
865 'sw_if_index': sw_if_index,
866 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -0800867 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -0800868 'protocol': protocol})
869
Matus Fabian2ba92e32017-08-21 07:05:03 -0700870 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -0800871 self,
872 first_ip_address,
873 last_ip_address,
874 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -0800875 vrf_id=0xFFFFFFFF,
876 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700877 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -0800878
879 :param first_ip_address: First IP address
880 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800881 :param vrf_id: VRF id for the address range
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700882 :param twice_nat: twice NAT address for extenral hosts
Matus Fabiande886752016-12-07 03:38:19 -0800883 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800884 """
885 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700886 self.papi.nat44_add_del_address_range,
887 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200888 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800889 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -0800890 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200891 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -0800892
Ole Troane1ade682019-03-04 23:55:43 +0100893 def nat44_add_del_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -0800894 self,
895 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -0800896 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -0800897 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700898 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -0800899
900 :param sw_if_index: Software index of the interface
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700901 :param twice_nat: twice NAT address for external hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -0800902 :param is_add: 1 if add, 0 if delete (Default value = 1)
903 """
Matus Fabianb932d262017-12-18 05:38:24 -0800904 return self.api(
905 self.papi.nat44_add_del_interface_addr,
906 {'is_add': is_add,
907 'sw_if_index': sw_if_index,
908 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -0800909
Matus Fabian704018c2017-09-04 02:17:18 -0700910 def nat44_add_del_lb_static_mapping(
911 self,
912 external_addr,
913 external_port,
914 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -0800915 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200916 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -0800917 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800918 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -0700919 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700920 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +0200921 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -0700922 is_add=1):
923 """Add/delete NAT44 load balancing static mapping
924
Matus Fabianb932d262017-12-18 05:38:24 -0800925 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -0800926 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -0700927 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -0700928 :param is_add - 1 if add, 0 if delete
929 """
930 return self.api(
931 self.papi.nat44_add_del_lb_static_mapping,
932 {'is_add': is_add,
933 'external_addr': external_addr,
934 'external_port': external_port,
935 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -0800936 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200937 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -0800938 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -0800939 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -0700940 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -0700941 'local_num': local_num,
942 'locals': locals})
943
Matus Fabianb6865082018-12-06 03:11:09 -0800944 def nat44_lb_static_mapping_add_del_local(
Ole Troan9a475372019-03-05 16:58:24 +0100945 self,
946 external_addr,
947 external_port,
948 local_addr,
949 local_port,
950 protocol,
951 probability,
952 vrf_id=0,
953 is_add=1):
Matus Fabianb6865082018-12-06 03:11:09 -0800954 """Add/delete NAT44 load-balancing static mapping rule backend
955
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700956 :param external_addr: external IPv4 address of the service
Matus Fabianb6865082018-12-06 03:11:09 -0800957 :param external_port: external L4 port number of the service
958 :param local_addr: IPv4 address of the internal node
959 :param local_port: L4 port number of the internal node
960 :param protocol: IP protocol number
961 :param probability: probability of the internal node
962 :param vrf_id: VRF id of the internal node
963 :param is_add: 1 if add, 0 if delete
964 """
965 return self.api(
966 self.papi.nat44_lb_static_mapping_add_del_local,
967 {'is_add': is_add,
968 'external_addr': external_addr,
969 'external_port': external_port,
970 'local': {
971 'addr': local_addr,
972 'port': local_port,
973 'probability': probability,
974 'vrf_id': vrf_id},
975 'protocol': protocol})
976
Matus Fabian5ba86f72017-10-26 03:37:38 -0700977 def nat44_del_session(
978 self,
979 addr,
980 port,
981 protocol,
982 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -0700983 is_in=1,
984 ext_host_address=None,
985 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -0700986 """Delete NAT44 session
987
988 :param addr: IPv4 address
989 :param por: port number
990 :param protocol: IP protocol number
991 :param vrf_id: VRF ID
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700992 :param is_in: 1 if inside network address and port pair, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -0700993 :param ext_host_address: external host IPv4 address
994 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -0700995 """
Matus Fabian70a26ac2018-05-14 06:20:28 -0700996 if ext_host_address is None:
997 return self.api(
998 self.papi.nat44_del_session,
999 {'address': addr,
1000 'port': port,
1001 'protocol': protocol,
1002 'vrf_id': vrf_id,
1003 'is_in': is_in})
1004 else:
1005 return self.api(
1006 self.papi.nat44_del_session,
1007 {'address': addr,
1008 'port': port,
1009 'protocol': protocol,
1010 'vrf_id': vrf_id,
1011 'is_in': is_in,
1012 'ext_host_valid': 1,
1013 'ext_host_address': ext_host_address,
1014 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001015
Juraj Sloboda7b929792017-11-23 13:20:48 +01001016 def nat44_forwarding_enable_disable(
1017 self,
1018 enable):
1019 """Enable/disable forwarding for NAT44
1020
1021 :param enable: 1 for enable, 0 for disable
1022 """
1023 return self.api(
1024 self.papi.nat44_forwarding_enable_disable,
1025 {'enable': enable})
1026
Matus Fabian2ba92e32017-08-21 07:05:03 -07001027 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001028 self,
1029 in_addr,
1030 in_plen,
1031 out_addr,
1032 out_plen,
1033 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001034 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001035
1036 :param is_add - 1 if add, 0 if delete
1037 :param in_addr - inside IP address
1038 :param in_plen - inside IP address prefix length
1039 :param out_addr - outside IP address
1040 :param out_plen - outside IP address prefix length
1041 """
1042 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001043 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001044 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001045 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001046 'in_addr': in_addr,
1047 'in_plen': in_plen,
1048 'out_addr': out_addr,
1049 'out_plen': out_plen})
1050
Matus Fabian2ba92e32017-08-21 07:05:03 -07001051 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001052 self,
1053 in_addr):
1054 """Get outside address and port range from inside address
1055
1056 :param in_addr - inside IP address
1057 """
1058 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001059 self.papi.nat_det_forward,
1060 {'in_addr': in_addr,
1061 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001062
Matus Fabian2ba92e32017-08-21 07:05:03 -07001063 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001064 self,
1065 out_addr,
1066 out_port):
1067 """Get inside address from outside address and port
1068
1069 :param out_addr - outside IP address
1070 :param out_port - outside port
1071 """
1072 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001073 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001074 {'out_addr': out_addr,
1075 'out_port': out_port})
1076
Matus Fabian2ba92e32017-08-21 07:05:03 -07001077 def nat_det_map_dump(self):
1078 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001079
Matus Fabian2ba92e32017-08-21 07:05:03 -07001080 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001081 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001082 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001083
Matus Fabianbb4e0222018-09-13 02:36:25 -07001084 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1085 """Set TCP MSS rewriting configuration
1086
1087 :param enable: disable(0)/enable(1) MSS rewriting feature
1088 :param mss_value: MSS value to be used for MSS rewriting
1089 """
1090 return self.api(
1091 self.papi.nat_set_mss_clamping,
1092 {'enable': enable, 'mss_value': mss_value})
1093
Matus Fabian2ba92e32017-08-21 07:05:03 -07001094 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001095 self,
1096 in_addr,
1097 in_port,
1098 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001099 ext_port):
1100 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001101
1102 :param in_addr - inside IP address
1103 :param in_port - inside port
1104 :param ext_addr - external host IP address
1105 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001106 """
1107 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001108 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001109 {'in_addr': in_addr,
1110 'in_port': in_port,
1111 'ext_addr': ext_addr,
1112 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001113 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001114
Matus Fabian2ba92e32017-08-21 07:05:03 -07001115 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001116 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001117 user_addr):
1118 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001119
1120 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001121 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001122 """
1123 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001124 self.papi.nat_det_session_dump,
1125 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001126 'user_addr': user_addr})
1127
Matus Fabian06596c52017-06-06 04:53:28 -07001128 def nat64_add_del_interface(
1129 self,
1130 sw_if_index,
1131 is_inside=1,
1132 is_add=1):
1133 """Enable/disable NAT64 feature on the interface
1134 :param sw_if_index: Index of the interface
1135 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1136 :param is_add: 1 if add, 0 if delete (Default value = 1)
1137 """
1138 return self.api(
1139 self.papi.nat64_add_del_interface,
1140 {'sw_if_index': sw_if_index,
1141 'is_inside': is_inside,
1142 'is_add': is_add})
1143
Matus Fabian06596c52017-06-06 04:53:28 -07001144 def nat64_add_del_static_bib(
1145 self,
1146 in_ip,
1147 out_ip,
1148 in_port,
1149 out_port,
1150 protocol,
1151 vrf_id=0,
1152 is_add=1):
1153 """Add/delete S-NAT static BIB entry
1154
1155 :param in_ip: Inside IPv6 address
1156 :param out_ip: Outside IPv4 address
1157 :param in_port: Inside port number
1158 :param out_port: Outside port number
1159 :param protocol: IP protocol
1160 :param vrf_id: VRF ID (Default value = 0)
1161 :param is_add: 1 if add, 0 if delete (Default value = 1)
1162 """
1163 return self.api(
1164 self.papi.nat64_add_del_static_bib,
1165 {'i_addr': in_ip,
1166 'o_addr': out_ip,
1167 'i_port': in_port,
1168 'o_port': out_port,
1169 'vrf_id': vrf_id,
1170 'proto': protocol,
1171 'is_add': is_add})
1172
Matus Fabianab9a59c2017-08-16 05:37:36 -07001173 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001174 """Dump NAT64 BIB
1175
Matus Fabianab9a59c2017-08-16 05:37:36 -07001176 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001177 :returns: Dictionary of NAT64 BIB entries
1178 """
1179 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1180
Matus Fabianab9a59c2017-08-16 05:37:36 -07001181 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001182 """Dump NAT64 session table
1183
Matus Fabianab9a59c2017-08-16 05:37:36 -07001184 :param protocol: IP protocol (Default value = 255, all STs)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001185 :returns: Dictionary of NAT64 session table entries
Matus Fabian06596c52017-06-06 04:53:28 -07001186 """
1187 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1188
Matus Fabian428dc912017-06-21 06:15:18 -07001189 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1190 """Add/del NAT64 prefix
1191
1192 :param prefix: NAT64 prefix
1193 :param plen: NAT64 prefix length
1194 :param vrf_id: VRF id of tenant (Default 0)
1195 :param is_add: 1 if add, 0 if delete (Default value = 1)
1196 """
1197 return self.api(
1198 self.papi.nat64_add_del_prefix,
1199 {'prefix': prefix,
1200 'prefix_len': plen,
1201 'vrf_id': vrf_id,
1202 'is_add': is_add})
1203
Ole Troane1ade682019-03-04 23:55:43 +01001204 def nat64_add_del_interface_addr(
Matus Fabian0938dcf2017-11-08 01:59:38 -08001205 self,
1206 sw_if_index,
1207 is_add=1):
1208 """Add/del NAT64 address from interface
1209
1210 :param sw_if_index: Software index of the interface
1211 :param is_add: 1 if add, 0 if delete (Default value = 1)
1212 """
1213 return self.api(self.papi.nat64_add_del_interface_addr,
1214 {'is_add': is_add, 'sw_if_index': sw_if_index})
1215
Matus Fabian8ebe6252017-11-06 05:04:53 -08001216 def dslite_set_aftr_addr(self, ip6, ip4):
1217 """Set DS-Lite AFTR addresses
1218
1219 :param ip4: IPv4 address
1220 :param ip6: IPv6 address
1221 """
1222 return self.api(
1223 self.papi.dslite_set_aftr_addr,
1224 {'ip4_addr': ip4,
1225 'ip6_addr': ip6})
1226
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001227 def dslite_set_b4_addr(self, ip6, ip4):
1228 """Set DS-Lite B4 IPv6 address
1229
1230 :param ip4: IPv4 address
1231 :param ip6: IPv6 address
1232 """
1233 return self.api(
1234 self.papi.dslite_set_b4_addr,
1235 {'ip4_addr': ip4,
1236 'ip6_addr': ip6})
1237
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001238 def nat66_add_del_interface(
1239 self,
1240 sw_if_index,
1241 is_inside=1,
1242 is_add=1):
1243 """Enable/disable NAT66 feature on the interface
1244 :param sw_if_index: Index of the interface
1245 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1246 :param is_add: 1 if add, 0 if delete (Default value = 1)
1247 """
1248 return self.api(
1249 self.papi.nat66_add_del_interface,
1250 {'sw_if_index': sw_if_index,
1251 'is_inside': is_inside,
1252 'is_add': is_add})
1253
1254 def nat66_add_del_static_mapping(
1255 self,
1256 in_ip,
1257 out_ip,
1258 vrf_id=0,
1259 is_add=1):
1260 """Add/delete NAT66 static mapping
1261
1262 :param in_ip: Inside IPv6 address
1263 :param out_ip: Outside IPv6 address
1264 :param vrf_id: VRF ID (Default value = 0)
1265 :param is_add: 1 if add, 0 if delete (Default value = 1)
1266 """
1267 return self.api(
1268 self.papi.nat66_add_del_static_mapping,
1269 {'local_ip_address': in_ip,
1270 'external_ip_address': out_ip,
1271 'vrf_id': vrf_id,
1272 'is_add': is_add})
1273
Matus Fabian34931eb2019-02-26 09:05:23 -08001274 def nat_ha_set_listener(self, addr, port, path_mtu=512):
1275 """Set HA listener (local settings)
1276
1277 :param addr: local IP4 address
1278 :param port: local UDP port number
1279 :param path_mtu: path MTU (Default value = 512)
1280 """
1281 return self.api(self.papi.nat_ha_set_listener,
1282 {'ip_address': addr,
1283 'port': port,
1284 'path_mtu': path_mtu})
1285
1286 def nat_ha_get_listener(self):
1287 """Get HA listener/local configuration"""
1288 return self.api(self.papi.nat_ha_get_listener, {})
1289
1290 def nat_ha_set_failover(self, addr, port, refresh=10):
1291 """Set HA failover (remote settings)
1292
1293 :param addr: failover IP4 address
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001294 :param port: failover UDP port number
Matus Fabian34931eb2019-02-26 09:05:23 -08001295 :param refresh: number of seconds after which to send session refresh
1296 """
1297 return self.api(self.papi.nat_ha_set_failover,
1298 {'ip_address': addr,
1299 'port': port,
1300 'session_refresh_interval': refresh})
1301
Matus Fabian34931eb2019-02-26 09:05:23 -08001302 def nat_ha_resync(self, want_resync_event=1):
1303 """Resync HA (resend existing sessions to new failover)
1304 :param want_resync_event: if non-zero resync completed event sent
1305 """
1306 return self.api(self.papi.nat_ha_resync,
1307 {'want_resync_event': want_resync_event,
1308 'pid': os.getpid()})
1309
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001310 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001311 detect_mult, local_addr, peer_addr, is_ipv6=0,
1312 bfd_key_id=None, conf_key_id=None):
1313 if bfd_key_id is None:
1314 return self.api(self.papi.bfd_udp_add,
1315 {
1316 'sw_if_index': sw_if_index,
1317 'desired_min_tx': desired_min_tx,
1318 'required_min_rx': required_min_rx,
1319 'local_addr': local_addr,
1320 'peer_addr': peer_addr,
1321 'is_ipv6': is_ipv6,
1322 'detect_mult': detect_mult,
1323 })
1324 else:
1325 return self.api(self.papi.bfd_udp_add,
1326 {
1327 'sw_if_index': sw_if_index,
1328 'desired_min_tx': desired_min_tx,
1329 'required_min_rx': required_min_rx,
1330 'local_addr': local_addr,
1331 'peer_addr': peer_addr,
1332 'is_ipv6': is_ipv6,
1333 'detect_mult': detect_mult,
1334 'is_authenticated': 1,
1335 'bfd_key_id': bfd_key_id,
1336 'conf_key_id': conf_key_id,
1337 })
1338
Klement Sekeraa57a9702017-02-02 06:58:07 +01001339 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1340 detect_mult, local_addr, peer_addr, is_ipv6=0):
1341 return self.api(self.papi.bfd_udp_mod,
1342 {
1343 'sw_if_index': sw_if_index,
1344 'desired_min_tx': desired_min_tx,
1345 'required_min_rx': required_min_rx,
1346 'local_addr': local_addr,
1347 'peer_addr': peer_addr,
1348 'is_ipv6': is_ipv6,
1349 'detect_mult': detect_mult,
1350 })
1351
Klement Sekerab17dd962017-01-09 07:43:48 +01001352 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1353 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1354 is_delayed=False):
1355 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001356 {
1357 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001358 'local_addr': local_addr,
1359 'peer_addr': peer_addr,
1360 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001361 'is_delayed': 1 if is_delayed else 0,
1362 'bfd_key_id': bfd_key_id,
1363 'conf_key_id': conf_key_id,
1364 })
1365
Klement Sekerab17dd962017-01-09 07:43:48 +01001366 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1367 peer_addr, is_ipv6=0):
1368 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001369 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001370 'sw_if_index': sw_if_index,
1371 'local_addr': local_addr,
1372 'peer_addr': peer_addr,
1373 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001374 })
1375
1376 def want_bfd_events(self, enable_disable=1):
1377 return self.api(self.papi.want_bfd_events, {
1378 'enable_disable': enable_disable,
1379 'pid': os.getpid(),
1380 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001381
Klement Sekerab17dd962017-01-09 07:43:48 +01001382 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1383 return self.api(self.papi.bfd_auth_set_key, {
1384 'conf_key_id': conf_key_id,
1385 'auth_type': auth_type,
1386 'key': key,
1387 'key_len': len(key),
1388 })
1389
Steve Shin7957d6e2016-12-19 09:24:50 -08001390 def classify_add_del_table(
1391 self,
1392 is_add,
1393 mask,
1394 match_n_vectors=1,
1395 table_index=0xFFFFFFFF,
1396 nbuckets=2,
1397 memory_size=2097152,
1398 skip_n_vectors=0,
1399 next_table_index=0xFFFFFFFF,
1400 miss_next_index=0xFFFFFFFF,
1401 current_data_flag=0,
1402 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001403 """
1404 :param is_add:
1405 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001406 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001407 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001408 :param nbuckets: (Default value = 2)
1409 :param memory_size: (Default value = 2097152)
1410 :param skip_n_vectors: (Default value = 0)
1411 :param next_table_index: (Default value = 0xFFFFFFFF)
1412 :param miss_next_index: (Default value = 0xFFFFFFFF)
1413 :param current_data_flag: (Default value = 0)
1414 :param current_data_offset: (Default value = 0)
1415 """
1416
Juraj Sloboda75282452018-06-12 14:20:49 +02001417 mask_len = ((len(mask) - 1) / 16 + 1) * 16
1418 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08001419 return self.api(
1420 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001421 {'is_add': is_add,
1422 'table_index': table_index,
1423 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001424 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001425 'skip_n_vectors': skip_n_vectors,
1426 'match_n_vectors': match_n_vectors,
1427 'next_table_index': next_table_index,
1428 'miss_next_index': miss_next_index,
1429 'current_data_flag': current_data_flag,
1430 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02001431 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001432 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001433
1434 def classify_add_del_session(
1435 self,
1436 is_add,
1437 table_index,
1438 match,
1439 opaque_index=0xFFFFFFFF,
1440 hit_next_index=0xFFFFFFFF,
1441 advance=0,
1442 action=0,
1443 metadata=0):
1444 """
1445 :param is_add:
1446 :param table_index:
1447 :param match:
1448 :param opaque_index: (Default value = 0xFFFFFFFF)
1449 :param hit_next_index: (Default value = 0xFFFFFFFF)
1450 :param advance: (Default value = 0)
1451 :param action: (Default value = 0)
1452 :param metadata: (Default value = 0)
1453 """
1454
Juraj Sloboda75282452018-06-12 14:20:49 +02001455 match_len = ((len(match) - 1) / 16 + 1) * 16
1456 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08001457 return self.api(
1458 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001459 {'is_add': is_add,
1460 'table_index': table_index,
1461 'hit_next_index': hit_next_index,
1462 'opaque_index': opaque_index,
1463 'advance': advance,
1464 'action': action,
1465 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02001466 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001467 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001468
1469 def input_acl_set_interface(
1470 self,
1471 is_add,
1472 sw_if_index,
1473 ip4_table_index=0xFFFFFFFF,
1474 ip6_table_index=0xFFFFFFFF,
1475 l2_table_index=0xFFFFFFFF):
1476 """
1477 :param is_add:
1478 :param sw_if_index:
1479 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1480 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1481 :param l2_table_index: (Default value = 0xFFFFFFFF)
1482 """
1483
1484 return self.api(
1485 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001486 {'sw_if_index': sw_if_index,
1487 'ip4_table_index': ip4_table_index,
1488 'ip6_table_index': ip6_table_index,
1489 'l2_table_index': l2_table_index,
1490 'is_add': is_add})
1491
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01001492 def output_acl_set_interface(
1493 self,
1494 is_add,
1495 sw_if_index,
1496 ip4_table_index=0xFFFFFFFF,
1497 ip6_table_index=0xFFFFFFFF,
1498 l2_table_index=0xFFFFFFFF):
1499 """
1500 :param is_add:
1501 :param sw_if_index:
1502 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1503 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1504 :param l2_table_index: (Default value = 0xFFFFFFFF)
1505 """
1506
1507 return self.api(
1508 self.papi.output_acl_set_interface,
1509 {'sw_if_index': sw_if_index,
1510 'ip4_table_index': ip4_table_index,
1511 'ip6_table_index': ip6_table_index,
1512 'l2_table_index': l2_table_index,
1513 'is_add': is_add})
1514
Klement Sekera77fabdb2017-01-02 07:46:14 +01001515 def set_ipfix_exporter(
1516 self,
1517 collector_address,
1518 src_address,
1519 path_mtu,
1520 template_interval,
1521 vrf_id=0,
1522 collector_port=4739,
1523 udp_checksum=0):
1524 return self.api(
1525 self.papi.set_ipfix_exporter,
1526 {
1527 'collector_address': collector_address,
1528 'collector_port': collector_port,
1529 'src_address': src_address,
1530 'vrf_id': vrf_id,
1531 'path_mtu': path_mtu,
1532 'template_interval': template_interval,
1533 'udp_checksum': udp_checksum,
1534 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001535
1536 def dhcp_proxy_config(self,
1537 dhcp_server,
1538 dhcp_src_address,
1539 rx_table_id=0,
1540 server_table_id=0,
1541 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001542 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001543 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001544 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001545 {
1546 'rx_vrf_id': rx_table_id,
1547 'server_vrf_id': server_table_id,
1548 'is_ipv6': is_ipv6,
1549 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001550 'dhcp_server': dhcp_server,
1551 'dhcp_src_address': dhcp_src_address,
1552 })
1553
1554 def dhcp_proxy_set_vss(self,
1555 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001556 vss_type=255,
1557 vpn_ascii_id="",
1558 oui=0,
1559 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001560 is_add=1,
1561 is_ip6=0):
1562 return self.api(
1563 self.papi.dhcp_proxy_set_vss,
1564 {
1565 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001566 'vss_type': vss_type,
1567 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001568 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001569 'vpn_index': vpn_index,
1570 'is_add': is_add,
1571 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001572 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001573
Ole Troane1ade682019-03-04 23:55:43 +01001574 def dhcp_client_config(self,
1575 sw_if_index,
1576 hostname,
1577 client_id='',
1578 is_add=1,
1579 set_broadcast_flag=1,
1580 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001581 return self.api(
1582 self.papi.dhcp_client_config,
1583 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001584 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001585 'client': {
1586 'sw_if_index': sw_if_index,
1587 'hostname': hostname,
1588 'id': client_id,
1589 'want_dhcp_event': want_dhcp_events,
1590 'set_broadcast_flag': set_broadcast_flag,
1591 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001592 })
1593
Neale Ranns32e1c012016-11-22 17:07:28 +00001594 def ip_mroute_add_del(self,
1595 src_address,
1596 grp_address,
1597 grp_address_length,
1598 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001599 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001600 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001601 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001602 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001603 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001604 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001605 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001606 is_add=1,
1607 is_ipv6=0,
1608 is_local=0):
1609 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001610 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001611 """
1612 return self.api(
1613 self.papi.ip_mroute_add_del,
1614 {'next_hop_sw_if_index': next_hop_sw_if_index,
1615 'entry_flags': e_flags,
1616 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001617 'table_id': table_id,
1618 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001619 'is_add': is_add,
1620 'is_ipv6': is_ipv6,
1621 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001622 'bier_imp': bier_imp,
1623 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001624 'grp_address_length': grp_address_length,
1625 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001626 'src_address': src_address,
1627 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001628
Filip Tehlar770e89e2017-01-31 10:39:16 +01001629 def lisp_enable_disable(self, is_enabled):
1630 return self.api(
1631 self.papi.lisp_enable_disable,
1632 {
1633 'is_en': is_enabled,
1634 })
1635
Ole Troane1ade682019-03-04 23:55:43 +01001636 def lisp_add_del_locator_set(self,
1637 ls_name,
1638 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001639 return self.api(
1640 self.papi.lisp_add_del_locator_set,
1641 {
1642 'is_add': is_add,
1643 'locator_set_name': ls_name
1644 })
1645
Ole Troane1ade682019-03-04 23:55:43 +01001646 def lisp_add_del_locator(self,
1647 ls_name,
1648 sw_if_index,
1649 priority=1,
1650 weight=1,
1651 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001652 return self.api(
1653 self.papi.lisp_add_del_locator,
1654 {
1655 'is_add': is_add,
1656 'locator_set_name': ls_name,
1657 'sw_if_index': sw_if_index,
1658 'priority': priority,
1659 'weight': weight
1660 })
1661
1662 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1663 return self.api(
1664 self.papi.lisp_locator_dump,
1665 {
1666 'is_index_set': is_index_set,
1667 'ls_name': ls_name,
1668 'ls_index': ls_index,
1669 })
1670
Ole Troane1ade682019-03-04 23:55:43 +01001671 def lisp_add_del_local_eid(self,
1672 ls_name,
1673 eid_type,
1674 eid,
1675 prefix_len,
1676 vni=0,
1677 key_id=0,
1678 key="",
1679 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001680 return self.api(
1681 self.papi.lisp_add_del_local_eid,
1682 {
1683 'locator_set_name': ls_name,
1684 'is_add': is_add,
1685 'eid_type': eid_type,
1686 'eid': eid,
1687 'prefix_len': prefix_len,
1688 'vni': vni,
1689 'key_id': key_id,
1690 'key': key
1691 })
1692
1693 def lisp_eid_table_dump(self,
1694 eid_set=0,
1695 prefix_length=0,
1696 vni=0,
1697 eid_type=0,
1698 eid=None,
1699 filter_opt=0):
1700 return self.api(
1701 self.papi.lisp_eid_table_dump,
1702 {
1703 'eid_set': eid_set,
1704 'prefix_length': prefix_length,
1705 'vni': vni,
1706 'eid_type': eid_type,
1707 'eid': eid,
1708 'filter': filter_opt,
1709 })
1710
Ole Troane1ade682019-03-04 23:55:43 +01001711 def lisp_add_del_remote_mapping(self,
1712 eid_type,
1713 eid,
1714 eid_prefix_len=0,
1715 vni=0,
1716 rlocs=[],
1717 rlocs_num=0,
1718 is_src_dst=0,
1719 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001720 return self.api(
1721 self.papi.lisp_add_del_remote_mapping,
1722 {
1723 'is_add': is_add,
1724 'eid_type': eid_type,
1725 'eid': eid,
1726 'eid_len': eid_prefix_len,
1727 'rloc_num': rlocs_num,
1728 'rlocs': rlocs,
1729 'vni': vni,
1730 'is_src_dst': is_src_dst,
1731 })
1732
Ole Troane1ade682019-03-04 23:55:43 +01001733 def lisp_add_del_adjacency(self,
1734 leid,
1735 reid,
1736 leid_len,
1737 reid_len,
1738 eid_type,
1739 is_add=1,
1740 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001741 return self.api(
1742 self.papi.lisp_add_del_adjacency,
1743 {
1744 'is_add': is_add,
1745 'vni': vni,
1746 'eid_type': eid_type,
1747 'leid': leid,
1748 'reid': reid,
1749 'leid_len': leid_len,
1750 'reid_len': reid_len,
1751 })
1752
Hongjun Nief486b12017-04-12 19:21:16 +08001753 def gtpu_add_del_tunnel(
1754 self,
1755 src_addr,
1756 dst_addr,
1757 is_add=1,
1758 is_ipv6=0,
1759 mcast_sw_if_index=0xFFFFFFFF,
1760 encap_vrf_id=0,
1761 decap_next_index=0xFFFFFFFF,
1762 teid=0):
1763 """
1764
1765 :param is_add: (Default value = 1)
1766 :param is_ipv6: (Default value = 0)
1767 :param src_addr:
1768 :param dst_addr:
1769 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1770 :param encap_vrf_id: (Default value = 0)
1771 :param decap_next_index: (Default value = 0xFFFFFFFF)
1772 :param teid: (Default value = 0)
1773
1774 """
1775 return self.api(self.papi.gtpu_add_del_tunnel,
1776 {'is_add': is_add,
1777 'is_ipv6': is_ipv6,
1778 'src_address': src_addr,
1779 'dst_address': dst_addr,
1780 'mcast_sw_if_index': mcast_sw_if_index,
1781 'encap_vrf_id': encap_vrf_id,
1782 'decap_next_index': decap_next_index,
1783 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001784
1785 def vxlan_gpe_add_del_tunnel(
1786 self,
1787 src_addr,
1788 dst_addr,
1789 mcast_sw_if_index=0xFFFFFFFF,
1790 is_add=1,
1791 is_ipv6=0,
1792 encap_vrf_id=0,
1793 decap_vrf_id=0,
1794 protocol=3,
1795 vni=0):
1796 """
1797
1798 :param local:
1799 :param remote:
1800 :param is_add: (Default value = 1)
1801 :param is_ipv6: (Default value = 0)
1802 :param encap_vrf_id: (Default value = 0)
1803 :param decap_vrf_id: (Default value = 0)
1804 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1805 :param protocol: (Default value = 3)
1806 :param vni: (Default value = 0)
1807
1808 """
1809 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1810 {'is_add': is_add,
1811 'is_ipv6': is_ipv6,
1812 'local': src_addr,
1813 'remote': dst_addr,
1814 'mcast_sw_if_index': mcast_sw_if_index,
1815 'encap_vrf_id': encap_vrf_id,
1816 'decap_vrf_id': decap_vrf_id,
1817 'protocol': protocol,
1818 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001819
Neale Ranns79a05f52018-09-11 07:39:43 -07001820 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001821 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001822 src,
1823 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001824 mcast_sw_if_index=0xFFFFFFFF,
1825 is_add=1,
1826 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001827 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001828 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001829 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001830 instance=0xFFFFFFFF):
1831 """
1832
1833 :param dst_addr:
1834 :param src_addr:
1835 :param is_add: (Default value = 1)
1836 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001837 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001838 :param decap_next_index: (Default value = 0xFFFFFFFF)
1839 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1840 :param vni: (Default value = 0)
1841 :param instance: (Default value = 0xFFFFFFFF)
1842
1843 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001844 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001845 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001846 'tunnel': {
1847 'src': src,
1848 'dst': dst,
1849 'mcast_sw_if_index': mcast_sw_if_index,
1850 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001851 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001852 'instance': instance,
1853 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001854
1855 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1856 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001857 {'sw_if_index': sw_if_index,
1858 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001859
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001860 def pppoe_add_del_session(
1861 self,
1862 client_ip,
1863 client_mac,
1864 session_id=0,
1865 is_add=1,
1866 is_ipv6=0,
1867 decap_vrf_id=0):
1868 """
1869
1870 :param is_add: (Default value = 1)
1871 :param is_ipv6: (Default value = 0)
1872 :param client_ip:
1873 :param session_id: (Default value = 0)
1874 :param client_mac:
1875 :param decap_vrf_id: (Default value = 0)
1876
1877 """
1878 return self.api(self.papi.pppoe_add_del_session,
1879 {'is_add': is_add,
1880 'is_ipv6': is_ipv6,
1881 'session_id': session_id,
1882 'client_ip': client_ip,
1883 'decap_vrf_id': decap_vrf_id,
1884 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001885
Neale Ranns7c922dc2018-08-30 06:12:27 -07001886 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1887 return self.api(self.papi.sr_mpls_policy_add,
1888 {'bsid': bsid,
1889 'weight': weight,
1890 'type': type,
1891 'n_segments': len(segments),
1892 'segments': segments})
1893
1894 def sr_mpls_policy_del(self, bsid):
1895 return self.api(self.papi.sr_mpls_policy_del,
1896 {'bsid': bsid})
1897
Kris Michielsen91074432017-06-22 13:00:20 +02001898 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001899 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001900 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001901 nh_addr4,
1902 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001903 is_del=0,
1904 end_psp=0,
1905 sw_if_index=0xFFFFFFFF,
1906 vlan_index=0,
1907 fib_table=0,
1908 ):
1909 """ Add/del IPv6 SR local-SID.
1910
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001911 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001912 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1913 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001914 :param nh_addr4:
1915 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001916 :param is_del: (Default value = 0)
1917 :param end_psp: (Default value = 0)
1918 :param sw_if_index: (Default value = 0xFFFFFFFF)
1919 :param vlan_index: (Default value = 0)
1920 :param fib_table: (Default value = 0)
1921 """
1922 return self.api(
1923 self.papi.sr_localsid_add_del,
1924 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001925 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001926 'end_psp': end_psp,
1927 'behavior': behavior,
1928 'sw_if_index': sw_if_index,
1929 'vlan_index': vlan_index,
1930 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001931 'nh_addr4': nh_addr4,
1932 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001933 }
1934 )
1935
1936 def sr_policy_add(
1937 self,
1938 bsid_addr,
1939 weight=1,
1940 is_encap=1,
1941 type=0,
1942 fib_table=0,
1943 n_segments=0,
1944 segments=[]):
1945 """
1946 :param bsid_addr: bindingSID of the SR Policy
1947 :param weight: weight of the sid list. optional. (default: 1)
1948 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1949 (default: Encap)
1950 :param type: type/behavior of the SR policy. (default or spray) \
1951 (default: default)
1952 :param fib_table: VRF where to install the FIB entry for the BSID \
1953 (default: 0)
1954 :param n_segments: number of segments \
1955 (default: 0)
1956 :param segments: a vector of IPv6 address composing the segment list \
1957 (default: [])
1958 """
1959 return self.api(
1960 self.papi.sr_policy_add,
1961 {'bsid_addr': bsid_addr,
1962 'weight': weight,
1963 'is_encap': is_encap,
1964 'type': type,
1965 'fib_table': fib_table,
1966 'n_segments': n_segments,
1967 'segments': segments
1968 }
1969 )
1970
1971 def sr_policy_del(
1972 self,
1973 bsid_addr,
1974 sr_policy_index=0):
1975 """
1976 :param bsid: bindingSID of the SR Policy
1977 :param sr_policy_index: index of the sr policy (default: 0)
1978 """
1979 return self.api(
1980 self.papi.sr_policy_del,
1981 {'bsid_addr': bsid_addr,
1982 'sr_policy_index': sr_policy_index
1983 })
1984
1985 def sr_steering_add_del(
1986 self,
1987 is_del,
1988 bsid_addr,
1989 sr_policy_index,
1990 table_id,
1991 prefix_addr,
1992 mask_width,
1993 sw_if_index,
1994 traffic_type):
1995 """
1996 Steer traffic L2 and L3 traffic through a given SR policy
1997
1998 :param is_del: delete or add
1999 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2000 :param sr_policy: is the index of the SR Policy (alt to bsid)
2001 :param table_id: is the VRF where to install the FIB entry for the BSID
2002 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2003 :param mask_width: is the mask for L3 traffic type
2004 :param sw_if_index: is the incoming interface for L2 traffic
2005 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2006 """
2007 return self.api(
2008 self.papi.sr_steering_add_del,
2009 {'is_del': is_del,
2010 'bsid_addr': bsid_addr,
2011 'sr_policy_index': sr_policy_index,
2012 'table_id': table_id,
2013 'prefix_addr': prefix_addr,
2014 'mask_width': mask_width,
2015 'sw_if_index': sw_if_index,
2016 'traffic_type': traffic_type
2017 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002018
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002019 def acl_add_replace(self, acl_index, r, tag='',
2020 expected_retval=0):
2021 """Add/replace an ACL
2022 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2023 :param acl_rule r: ACL rules array.
2024 :param str tag: symbolic tag (description) for this ACL.
2025 :param int count: number of rules.
2026 """
2027 return self.api(self.papi.acl_add_replace,
2028 {'acl_index': acl_index,
2029 'r': r,
2030 'count': len(r),
2031 'tag': tag},
2032 expected_retval=expected_retval)
2033
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002034 def acl_del(self, acl_index, expected_retval=0):
2035 """
2036
2037 :param acl_index:
2038 :return:
2039 """
2040 return self.api(self.papi.acl_del,
2041 {'acl_index': acl_index},
2042 expected_retval=expected_retval)
2043
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002044 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2045 expected_retval=0):
2046 return self.api(self.papi.acl_interface_set_acl_list,
2047 {'sw_if_index': sw_if_index,
2048 'count': len(acls),
2049 'n_input': n_input,
2050 'acls': acls},
2051 expected_retval=expected_retval)
2052
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002053 def acl_interface_set_etype_whitelist(self, sw_if_index,
2054 n_input, whitelist,
2055 expected_retval=0):
2056 return self.api(self.papi.acl_interface_set_etype_whitelist,
2057 {'sw_if_index': sw_if_index,
2058 'count': len(whitelist),
2059 'n_input': n_input,
2060 'whitelist': whitelist},
2061 expected_retval=expected_retval)
2062
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002063 def acl_interface_add_del(self,
2064 sw_if_index,
2065 acl_index,
2066 is_add=1):
2067 """ Add/Delete ACL to/from interface
2068
2069 :param sw_if_index:
2070 :param acl_index:
2071 :param is_add: (Default value = 1)
2072 """
2073
2074 return self.api(self.papi.acl_interface_add_del,
2075 {'is_add': is_add,
2076 'is_input': 1,
2077 'sw_if_index': sw_if_index,
2078 'acl_index': acl_index})
2079
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002080 def acl_dump(self, acl_index, expected_retval=0):
2081 return self.api(self.papi.acl_dump,
2082 {'acl_index': acl_index},
2083 expected_retval=expected_retval)
2084
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002085 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2086 expected_retval=0):
2087 return self.api(self.papi.acl_interface_list_dump,
2088 {'sw_if_index': sw_if_index},
2089 expected_retval=expected_retval)
2090
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002091 def macip_acl_add(self, rules, tag=""):
2092 """ Add MACIP acl
2093
2094 :param rules: list of rules for given acl
2095 :param tag: acl tag
2096 """
2097
2098 return self.api(self.papi.macip_acl_add,
2099 {'r': rules,
2100 'count': len(rules),
2101 'tag': tag})
2102
Pavel Kotucek932f7412017-09-07 14:44:52 +02002103 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2104 """ Add MACIP acl
2105
2106 :param rules: list of rules for given acl
2107 :param tag: acl tag
2108 """
2109
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002110 return self.api(self.papi.macip_acl_add_replace,
2111 {'acl_index': acl_index,
2112 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002113 'count': len(rules),
2114 'tag': tag})
2115
Pavel Kotucek932f7412017-09-07 14:44:52 +02002116 def macip_acl_interface_add_del(self,
2117 sw_if_index,
2118 acl_index,
2119 is_add=1):
2120 """ Add MACIP acl to interface
2121
2122 :param sw_if_index:
2123 :param acl_index:
2124 :param is_add: (Default value = 1)
2125 """
2126
2127 return self.api(self.papi.macip_acl_interface_add_del,
2128 {'is_add': is_add,
2129 'sw_if_index': sw_if_index,
2130 'acl_index': acl_index})
2131
Pavel Kotucek932f7412017-09-07 14:44:52 +02002132 def macip_acl_dump(self, acl_index=4294967295):
2133 """ Return MACIP acl dump
2134 """
2135
2136 return self.api(
2137 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002138
2139 def policer_add_del(self,
2140 name,
2141 cir,
2142 eir,
2143 cb,
2144 eb,
2145 is_add=1,
2146 rate_type=0,
2147 round_type=0,
2148 ptype=0,
2149 color_aware=0,
2150 conform_action_type=1,
2151 conform_dscp=0,
2152 exceed_action_type=0,
2153 exceed_dscp=0,
2154 violate_action_type=0,
2155 violate_dscp=0):
2156 return self.api(self.papi.policer_add_del,
2157 {'name': name,
2158 'cir': cir,
2159 'eir': eir,
2160 'cb': cb,
2161 'eb': eb,
2162 'is_add': is_add,
2163 'rate_type': rate_type,
2164 'round_type': round_type,
2165 'type': ptype,
2166 'color_aware': color_aware,
2167 'conform_action_type': conform_action_type,
2168 'conform_dscp': conform_dscp,
2169 'exceed_action_type': exceed_action_type,
2170 'exceed_dscp': exceed_dscp,
2171 'violate_action_type': violate_action_type,
2172 'violate_dscp': violate_dscp})
2173
2174 def ip_punt_police(self,
2175 policer_index,
2176 is_ip6=0,
2177 is_add=1):
2178 return self.api(self.papi.ip_punt_police,
2179 {'policer_index': policer_index,
2180 'is_add': is_add,
2181 'is_ip6': is_ip6})
2182
2183 def ip_punt_redirect(self,
2184 rx_sw_if_index,
2185 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002186 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002187 is_add=1):
2188 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002189 {'punt': {'rx_sw_if_index': rx_sw_if_index,
2190 'tx_sw_if_index': tx_sw_if_index,
2191 'nh': address},
2192 'is_add': is_add})
2193
2194 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
2195 return self.api(self.papi.ip_punt_redirect_dump,
2196 {'sw_if_index': sw_if_index,
2197 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002198
2199 def bier_table_add_del(self,
2200 bti,
2201 mpls_label,
2202 is_add=1):
2203 """ BIER Table add/del """
2204 return self.api(
2205 self.papi.bier_table_add_del,
2206 {'bt_tbl_id': {"bt_set": bti.set_id,
2207 "bt_sub_domain": bti.sub_domain_id,
2208 "bt_hdr_len_id": bti.hdr_len_id},
2209 'bt_label': mpls_label,
2210 'bt_is_add': is_add})
2211
2212 def bier_table_dump(self):
2213 return self.api(self.papi.bier_table_dump, {})
2214
2215 def bier_route_add_del(self,
2216 bti,
2217 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002218 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002219 is_add=1,
2220 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07002221 """ BIER Route add/del """
2222 return self.api(
2223 self.papi.bier_route_add_del,
2224 {'br_tbl_id': {"bt_set": bti.set_id,
2225 "bt_sub_domain": bti.sub_domain_id,
2226 "bt_hdr_len_id": bti.hdr_len_id},
2227 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002228 'br_n_paths': len(paths),
2229 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002230 'br_is_add': is_add,
2231 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002232
2233 def bier_route_dump(self, bti):
2234 return self.api(
2235 self.papi.bier_route_dump,
2236 {'br_tbl_id': {"bt_set": bti.set_id,
2237 "bt_sub_domain": bti.sub_domain_id,
2238 "bt_hdr_len_id": bti.hdr_len_id}})
2239
2240 def bier_imp_add(self,
2241 bti,
2242 src,
2243 ibytes,
2244 is_add=1):
2245 """ BIER Imposition Add """
2246 return self.api(
2247 self.papi.bier_imp_add,
2248 {'bi_tbl_id': {"bt_set": bti.set_id,
2249 "bt_sub_domain": bti.sub_domain_id,
2250 "bt_hdr_len_id": bti.hdr_len_id},
2251 'bi_src': src,
2252 'bi_n_bytes': len(ibytes),
2253 'bi_bytes': ibytes})
2254
2255 def bier_imp_del(self, bi_index):
2256 """ BIER Imposition del """
2257 return self.api(
2258 self.papi.bier_imp_del,
2259 {'bi_index': bi_index})
2260
2261 def bier_imp_dump(self):
2262 return self.api(self.papi.bier_imp_dump, {})
2263
2264 def bier_disp_table_add_del(self,
2265 bdti,
2266 is_add=1):
2267 """ BIER Disposition Table add/del """
2268 return self.api(
2269 self.papi.bier_disp_table_add_del,
2270 {'bdt_tbl_id': bdti,
2271 'bdt_is_add': is_add})
2272
2273 def bier_disp_table_dump(self):
2274 return self.api(self.papi.bier_disp_table_dump, {})
2275
2276 def bier_disp_entry_add_del(self,
2277 bdti,
2278 bp,
2279 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002280 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002281 next_hop,
2282 next_hop_tbl_id=0,
2283 next_hop_rpf_id=~0,
2284 next_hop_is_ip4=1,
2285 is_add=1):
2286 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002287 lstack = []
2288 while (len(lstack) < 16):
2289 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002290 return self.api(
2291 self.papi.bier_disp_entry_add_del,
2292 {'bde_tbl_id': bdti,
2293 'bde_bp': bp,
2294 'bde_payload_proto': payload_proto,
2295 'bde_n_paths': 1,
2296 'bde_paths': [{'next_hop': next_hop,
2297 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002298 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002299 'rpf_id': next_hop_rpf_id,
2300 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002301 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002302 'bde_is_add': is_add})
2303
2304 def bier_disp_entry_dump(self, bdti):
2305 return self.api(
2306 self.papi.bier_disp_entry_dump,
2307 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002308
Florin Coras3ea6ce22017-12-11 09:09:05 -08002309 def session_enable_disable(self, is_enabled):
2310 return self.api(
2311 self.papi.session_enable_disable,
2312 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002313
2314 def ipsec_spd_add_del(self, spd_id, is_add=1):
2315 """ SPD add/del - Wrapper to add or del ipsec SPD
2316 Sample CLI : 'ipsec spd add 1'
2317
2318 :param spd_id - SPD ID to be created in the vpp . mandatory
2319 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2320 optional
2321 :returns: reply from the API
2322 """
2323 return self.api(
2324 self.papi.ipsec_spd_add_del, {
2325 'spd_id': spd_id, 'is_add': is_add})
2326
Neale Ranns311124e2019-01-24 04:52:25 -08002327 def ipsec_spds_dump(self):
2328 return self.api(self.papi.ipsec_spds_dump, {})
2329
“mystarrocks”23f0c452017-12-11 07:11:51 -08002330 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2331 """ IPSEC interface SPD add/del - \
2332 Wrapper to associate/disassociate SPD to interface in VPP
2333 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2334
2335 :param spd_id - SPD ID to associate with the interface . mandatory
2336 :param sw_if_index - Interface Index which needs to ipsec \
2337 association mandatory
2338 :param is_add - add(1) or del(0) association with interface \
2339 (Default 1 - add) . optional
2340 :returns: reply from the API
2341 """
2342 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02002343 self.papi.ipsec_interface_add_del_spd,
2344 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002345
Neale Ranns311124e2019-01-24 04:52:25 -08002346 def ipsec_spd_interface_dump(self, spd_index=None):
2347 return self.api(self.papi.ipsec_spd_interface_dump,
2348 {'spd_index': spd_index if spd_index else 0,
2349 'spd_index_valid': 1 if spd_index else 0})
2350
Neale Ranns17dcec02019-01-09 21:22:20 -08002351 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002352 sad_id,
2353 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02002354 integrity_algorithm,
2355 integrity_key,
2356 crypto_algorithm,
2357 crypto_key,
2358 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002359 tunnel_src_address='',
2360 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08002361 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002362 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08002363 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08002364 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02002365 :param sad_id: security association ID
2366 :param spi: security param index of the SA in decimal
2367 :param integrity_algorithm:
2368 :param integrity_key:
2369 :param crypto_algorithm:
2370 :param crypto_key:
2371 :param protocol: AH(0) or ESP(1) protocol
2372 :param tunnel_src_address: tunnel mode outer src address
2373 :param tunnel_dst_address: tunnel mode outer dst address
2374 :param is_add:
2375 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08002376 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
2377 crypto and ipsec algorithms
2378 """
2379 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002380 self.papi.ipsec_sad_entry_add_del,
2381 {
2382 'is_add': is_add,
2383 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002384 {
2385 'sad_id': sad_id,
2386 'spi': spi,
2387 'tunnel_src': tunnel_src_address,
2388 'tunnel_dst': tunnel_dst_address,
2389 'protocol': protocol,
2390 'integrity_algorithm': integrity_algorithm,
2391 'integrity_key': {
2392 'length': len(integrity_key),
2393 'data': integrity_key,
2394 },
2395 'crypto_algorithm': crypto_algorithm,
2396 'crypto_key': {
2397 'length': len(crypto_key),
2398 'data': crypto_key,
2399 },
2400 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002401 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01002402 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002403 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08002404
Neale Ranns311124e2019-01-24 04:52:25 -08002405 def ipsec_sa_dump(self, sa_id=None):
2406 return self.api(self.papi.ipsec_sa_dump,
2407 {'sa_id': sa_id if sa_id else 0xffffffff})
2408
Neale Ranns17dcec02019-01-09 21:22:20 -08002409 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002410 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02002411 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002412 local_address_start,
2413 local_address_stop,
2414 remote_address_start,
2415 remote_address_stop,
2416 local_port_start=0,
2417 local_port_stop=65535,
2418 remote_port_start=0,
2419 remote_port_stop=65535,
2420 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002421 policy=0,
2422 priority=100,
2423 is_outbound=1,
2424 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02002425 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002426 is_ip_any=0):
2427 """ IPSEC policy SPD add/del -
2428 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02002429 :param spd_id: SPD ID for the policy
2430 :param local_address_start: local-ip-range start address
2431 :param local_address_stop : local-ip-range stop address
2432 :param remote_address_start: remote-ip-range start address
2433 :param remote_address_stop : remote-ip-range stop address
2434 :param local_port_start: (Default value = 0)
2435 :param local_port_stop: (Default value = 65535)
2436 :param remote_port_start: (Default value = 0)
2437 :param remote_port_stop: (Default value = 65535)
2438 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
2439 :param sa_id: Security Association ID for mapping it to SPD
2440 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
2441 (Default value = 0)
2442 :param priority: value for the spd action (Default value = 100)
2443 :param is_outbound: flag for inbound(0) or outbound(1)
2444 (Default value = 1)
2445 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08002446 """
2447 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002448 self.papi.ipsec_spd_entry_add_del,
2449 {
2450 'is_add': is_add,
2451 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002452 {
2453 'spd_id': spd_id,
2454 'sa_id': sa_id,
2455 'local_address_start': local_address_start,
2456 'local_address_stop': local_address_stop,
2457 'remote_address_start': remote_address_start,
2458 'remote_address_stop': remote_address_stop,
2459 'local_port_start': local_port_start,
2460 'local_port_stop': local_port_stop,
2461 'remote_port_start': remote_port_start,
2462 'remote_port_stop': remote_port_stop,
2463 'protocol': protocol,
2464 'policy': policy,
2465 'priority': priority,
2466 'is_outbound': is_outbound,
2467 'is_ip_any': is_ip_any
2468 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002469 })
Florin Corasb795bd02017-12-14 11:30:48 -08002470
Neale Ranns311124e2019-01-24 04:52:25 -08002471 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
2472 return self.api(self.papi.ipsec_spd_dump,
2473 {'spd_id': spd_id,
2474 'sa_id': sa_id})
2475
Klement Sekera31da2e32018-06-24 22:49:55 +02002476 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
2477 remote_spi, crypto_alg, local_crypto_key,
2478 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002479 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02002480 anti_replay=1, renumber=0, show_instance=0):
2481 return self.api(
2482 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002483 {
2484 'local_ip': local_ip,
2485 'remote_ip': remote_ip,
2486 'local_spi': local_spi,
2487 'remote_spi': remote_spi,
2488 'crypto_alg': crypto_alg,
2489 'local_crypto_key_len': len(local_crypto_key),
2490 'local_crypto_key': local_crypto_key,
2491 'remote_crypto_key_len': len(remote_crypto_key),
2492 'remote_crypto_key': remote_crypto_key,
2493 'integ_alg': integ_alg,
2494 'local_integ_key_len': len(local_integ_key),
2495 'local_integ_key': local_integ_key,
2496 'remote_integ_key_len': len(remote_integ_key),
2497 'remote_integ_key': remote_integ_key,
2498 'is_add': is_add,
2499 'esn': esn,
2500 'anti_replay': anti_replay,
2501 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002502 'show_instance': show_instance,
2503 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002504 })
Klement Sekera31da2e32018-06-24 22:49:55 +02002505
Neale Rannsf05e7322019-03-29 20:23:58 +00002506 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
2507 sa_out, sa_in, is_add=1):
2508 return self.api(self.papi.ipsec_gre_tunnel_add_del,
2509 {
2510 'is_add': is_add,
2511 'tunnel': {
2512 'src': local_ip,
2513 'dst': remote_ip,
2514 'local_sa_id': sa_out,
2515 'remote_sa_id': sa_in
2516 }
2517 })
2518
Klement Sekerab4d30532018-11-08 13:00:02 +01002519 def ipsec_select_backend(self, protocol, index):
2520 return self.api(self.papi.ipsec_select_backend,
2521 {'protocol': protocol, 'index': index})
2522
2523 def ipsec_backend_dump(self):
2524 return self.api(self.papi.ipsec_backend_dump, {})
2525
Ole Troane1ade682019-03-04 23:55:43 +01002526 def app_namespace_add_del(self,
2527 namespace_id,
2528 ip4_fib_id=0,
2529 ip6_fib_id=0,
2530 sw_if_index=0xFFFFFFFF,
2531 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08002532 return self.api(
2533 self.papi.app_namespace_add_del,
2534 {'secret': secret,
2535 'sw_if_index': sw_if_index,
2536 'ip4_fib_id': ip4_fib_id,
2537 'ip6_fib_id': ip6_fib_id,
2538 'namespace_id': namespace_id,
2539 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02002540
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002541 def punt_socket_register(self, port, pathname, protocol=0x11,
2542 header_version=1, is_ip4=1):
2543 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02002544 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002545 {'header_version': header_version,
2546 'punt': {'ipv': is_ip4,
2547 'l4_protocol': protocol,
2548 'l4_port': port},
2549 'pathname': pathname})
2550
2551 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
2552 """ Unregister punt socket """
2553 return self.api(self.papi.punt_socket_deregister,
2554 {'punt': {'ipv': is_ip4,
2555 'l4_protocol': protocol,
2556 'l4_port': port}})
2557
2558 def punt_socket_dump(self, is_ip6=1):
2559 """ Dump punt socket"""
2560 return self.api(self.papi.punt_socket_dump,
2561 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02002562
Neale Ranns4ba67722019-02-28 11:11:39 +00002563 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002564 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07002565 """ GBP endpoint Add """
2566 return self.api(self.papi.gbp_endpoint_add,
2567 {'endpoint': {
2568 'sw_if_index': sw_if_index,
2569 'ips': ips,
2570 'n_ips': len(ips),
2571 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00002572 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002573 'flags': flags,
2574 'tun': {
2575 'src': tun_src,
2576 'dst': tun_dst,
2577 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002578
2579 def gbp_endpoint_del(self, handle):
2580 """ GBP endpoint Del """
2581 return self.api(self.papi.gbp_endpoint_del,
2582 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002583
2584 def gbp_endpoint_dump(self):
2585 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002586 return self.api(self.papi.gbp_endpoint_dump,
2587 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002588
Neale Ranns4ba67722019-02-28 11:11:39 +00002589 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002590 rd, uplink_sw_if_index,
2591 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002592 """ GBP endpoint group Add """
2593 return self.api(self.papi.gbp_endpoint_group_add,
2594 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002595 {
2596 'uplink_sw_if_index': uplink_sw_if_index,
2597 'bd_id': bd,
2598 'rd_id': rd,
2599 'vnid': vnid,
2600 'sclass': sclass,
2601 'retention': retention
2602 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002603
Neale Ranns4ba67722019-02-28 11:11:39 +00002604 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002605 """ GBP endpoint group Del """
2606 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002607 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002608
Neale Rannsc29c0af2018-11-07 04:21:12 -08002609 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002610 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002611 uu_fwd_sw_if_index,
2612 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002613 """ GBP bridge-domain Add """
2614 return self.api(self.papi.gbp_bridge_domain_add,
2615 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002616 {
2617 'flags': flags,
2618 'bvi_sw_if_index': bvi_sw_if_index,
2619 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2620 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2621 'bd_id': bd_id
2622 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002623
2624 def gbp_bridge_domain_del(self, bd_id):
2625 """ GBP bridge-domain Del """
2626 return self.api(self.papi.gbp_bridge_domain_del,
2627 {'bd_id': bd_id})
2628
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002629 def gbp_route_domain_add(self, rd_id,
2630 ip4_table_id,
2631 ip6_table_id,
2632 ip4_uu_sw_if_index,
2633 ip6_uu_sw_if_index):
2634 """ GBP route-domain Add """
2635 return self.api(self.papi.gbp_route_domain_add,
2636 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002637 {
2638 'ip4_table_id': ip4_table_id,
2639 'ip6_table_id': ip6_table_id,
2640 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2641 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2642 'rd_id': rd_id
2643 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002644
2645 def gbp_route_domain_del(self, rd_id):
2646 """ GBP route-domain Del """
2647 return self.api(self.papi.gbp_route_domain_del,
2648 {'rd_id': rd_id})
2649
Neale Ranns4ba67722019-02-28 11:11:39 +00002650 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002651 """ GBP recirc Add/Del """
2652 return self.api(self.papi.gbp_recirc_add_del,
2653 {'is_add': is_add,
2654 'recirc': {
2655 'is_ext': is_ext,
2656 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002657 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002658
2659 def gbp_recirc_dump(self):
2660 """ GBP recirc Dump """
2661 return self.api(self.papi.gbp_recirc_dump, {})
2662
Neale Rannsb6a47952018-11-21 05:44:35 -08002663 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2664 """ GBP recirc Add/Del """
2665 return self.api(self.papi.gbp_ext_itf_add_del,
2666 {'is_add': is_add,
2667 'ext_itf': {
2668 'sw_if_index': sw_if_index,
2669 'bd_id': bd_id,
2670 'rd_id': rd_id}})
2671
2672 def gbp_ext_itf_dump(self):
2673 """ GBP recirc Dump """
2674 return self.api(self.papi.gbp_ext_itf_dump, {})
2675
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002676 def gbp_subnet_add_del(self, is_add, rd_id,
2677 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002678 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002679 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002680 """ GBP Subnet Add/Del """
2681 return self.api(self.papi.gbp_subnet_add_del,
2682 {'is_add': is_add,
2683 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002684 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002685 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002686 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002687 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002688 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002689
2690 def gbp_subnet_dump(self):
2691 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002692 return self.api(self.papi.gbp_subnet_dump,
2693 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002694
Neale Ranns4ba67722019-02-28 11:11:39 +00002695 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002696 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002697 """ GBP contract Add/Del """
2698 return self.api(self.papi.gbp_contract_add_del,
2699 {'is_add': is_add,
2700 'contract': {
2701 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002702 'sclass': sclass,
2703 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002704 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002705 'rules': rules,
2706 'n_ether_types': len(allowed_ethertypes),
2707 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002708
2709 def gbp_contract_dump(self):
2710 """ GBP contract Dump """
2711 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002712
Neale Ranns8da9fc62019-03-04 14:08:11 -08002713 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002714 """ GBP VXLAN tunnel add """
2715 return self.api(self.papi.gbp_vxlan_tunnel_add,
2716 {
2717 'tunnel': {
2718 'vni': vni,
2719 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002720 'bd_rd_id': bd_rd_id,
2721 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002722 }
2723 })
2724
2725 def gbp_vxlan_tunnel_del(self, vni):
2726 """ GBP VXLAN tunnel del """
2727 return self.api(self.papi.gbp_vxlan_tunnel_del,
2728 {
2729 'vni': vni,
2730 })
2731
2732 def gbp_vxlan_tunnel_dump(self):
2733 """ GBP VXLAN tunnel add/del """
2734 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2735
Neale Ranns039cbfe2018-02-27 03:45:38 -08002736 def qos_egress_map_update(self, id, outputs):
2737 """ QOS egress map update """
2738 return self.api(self.papi.qos_egress_map_update,
2739 {'map_id': id,
2740 'rows': outputs})
2741
2742 def qos_egress_map_delete(self, id):
2743 """ QOS egress map delete """
2744 return self.api(self.papi.qos_egress_map_delete,
2745 {'map_id': id})
2746
2747 def qos_mark_enable_disable(self, sw_if_index,
2748 output_source,
2749 map_id,
2750 enable):
2751 """ QOS Mark Enable/Disable """
2752 return self.api(self.papi.qos_mark_enable_disable,
2753 {'map_id': map_id,
2754 'sw_if_index': sw_if_index,
2755 'output_source': output_source,
2756 'enable': enable})
2757
Neale Ranns947ea622018-06-07 23:48:20 -07002758 def igmp_enable_disable(self, sw_if_index, enable, host):
2759 """ Enable/disable IGMP on a given interface """
2760 return self.api(self.papi.igmp_enable_disable,
2761 {'enable': enable,
2762 'mode': host,
2763 'sw_if_index': sw_if_index})
2764
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002765 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2766 """ Add/del IGMP proxy device """
2767 return self.api(self.papi.igmp_proxy_device_add_del,
2768 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2769 'add': add})
2770
2771 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2772 """ Add/del interface to/from IGMP proxy device """
2773 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2774 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2775 'add': add})
2776
Neale Ranns947ea622018-06-07 23:48:20 -07002777 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002778 """ Listen for new (S,G) on specified interface
2779
2780 :param enable: add/del
2781 :param sw_if_index: interface sw index
2782 :param saddr: source ip4 addr
2783 :param gaddr: group ip4 addr
2784 """
2785 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002786 {
2787 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002788 {
2789 'filter': filter,
2790 'sw_if_index': sw_if_index,
2791 'n_srcs': len(saddrs),
2792 'saddrs': saddrs,
2793 'gaddr': gaddr
2794 }
Neale Ranns947ea622018-06-07 23:48:20 -07002795 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002796
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002797 def igmp_clear_interface(self, sw_if_index):
2798 """ Remove all (S,G)s from specified interface
2799 doesn't send IGMP report!
2800 """
2801 return self.api(
2802 self.papi.igmp_clear_interface, {
2803 'sw_if_index': sw_if_index})
2804
2805 def want_igmp_events(self, enable=1):
2806 return self.api(self.papi.want_igmp_events, {'enable': enable,
2807 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002808
2809 def bond_create(
2810 self,
2811 mode,
2812 lb,
2813 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002814 mac_address='',
2815 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002816 """
2817 :param mode: mode
2818 :param lb: load balance
2819 :param use_custom_mac: use custom mac
2820 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002821 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002822 """
2823 return self.api(
2824 self.papi.bond_create,
2825 {'mode': mode,
2826 'lb': lb,
2827 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002828 'mac_address': mac_address,
2829 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002830 })
2831
Neale Ranns17ff3c12018-07-04 10:24:24 -07002832 def pipe_delete(self, parent_sw_if_index):
2833 return self.api(self.papi.pipe_delete,
2834 {'parent_sw_if_index': parent_sw_if_index})
2835
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002836 def memif_create(
2837 self,
2838 role,
2839 mode,
2840 rx_queues=None,
2841 tx_queues=None,
2842 _id=None,
2843 socket_id=None,
2844 secret=None,
2845 ring_size=None,
2846 buffer_size=None,
2847 hw_addr=None):
2848 return self.api(self.papi.memif_create,
2849 {'role': role,
2850 'mode': mode,
2851 'rx_queues': rx_queues,
2852 'tx_queues': tx_queues,
2853 'id': _id,
2854 'socket_id': socket_id,
2855 'secret': secret,
2856 'ring_size': ring_size,
2857 'buffer_size': buffer_size,
2858 'hw_addr': hw_addr})
2859
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002860 def svs_table_add_del(self, af, table_id, is_add=1):
2861 return self.api(self.papi.svs_table_add_del,
2862 {
2863 'table_id': table_id,
2864 'is_add': is_add,
2865 'af': af,
2866 })
2867
2868 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2869 return self.api(self.papi.svs_route_add_del,
2870 {
2871 'table_id': table_id,
2872 'source_table_id': src_table_id,
2873 'prefix': prefix,
2874 'is_add': is_add,
2875 })
2876
2877 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2878 return self.api(self.papi.svs_enable_disable,
2879 {
2880 'af': af,
2881 'table_id': table_id,
2882 'sw_if_index': sw_if_index,
2883 'is_enable': is_enable,
2884 })