blob: 62175e2310dab538a878288b798c7e34dd89740f [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, },
71 'gre_add_del_tunnel': {'instance': 4294967295, 'is_add': 1, },
72 '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, },
173 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
174 'pref_lifetime': 4294967295, },
175 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
176 'sw_interface_set_l2_bridge': {'enable': 1, },
177 'sw_interface_set_mpls_enable': {'enable': 1, },
178 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
179 'sw_interface_set_unnumbered': {'is_add': 1, },
180 'sw_interface_span_enable_disable': {'state': 1, },
181 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
182 'decap_next_index': 4294967295,
183 'instance': 4294967295, },
184 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
185 'instance': 4294967295, },
186 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
187 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
188 'protocol': 3, },
189 'want_bfd_events': {'enable_disable': 1, },
190 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
191 'want_dhcp6_reply_events': {'enable_disable': 1, },
192 'want_igmp_events': {'enable': 1, },
193 'want_interface_events': {'enable_disable': 1, },
194 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
195 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
196 'want_ip6_ra_events': {'enable_disable': 1, },
197 'want_l2_macs_events': {'enable_disable': 1, },
198}
Ole Troanf159f582019-02-28 20:20:47 +0100199
Matus Fabianb4515b42018-11-19 04:25:32 -0800200
Klement Sekera73884482017-02-23 09:26:30 +0100201class UnexpectedApiReturnValueError(Exception):
202 """ exception raised when the API return value is unexpected """
203 pass
204
205
Klement Sekeraf62ae122016-10-11 11:47:09 +0200206class VppPapiProvider(object):
207 """VPP-api provider using vpp-papi
208
209 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200210 """
211
Klement Sekerae0545ef2017-01-25 08:00:40 +0100212 _zero, _negative = range(2)
213
Klement Sekera611864f2018-09-26 11:19:00 +0200214 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800215 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200216 self.name = name
217 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100218 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100219 self._expect_api_retval = self._zero
220 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100221
Klement Sekerab8c72a42018-11-08 11:21:39 +0100222 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +0100223
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800224 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
225 if 'VPP_API_DIR' not in os.environ:
226 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
227
228 self.vpp = VPP(logger=test_class.logger,
Klement Sekera611864f2018-09-26 11:19:00 +0200229 read_timeout=read_timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100230 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200231
Klement Sekerae0545ef2017-01-25 08:00:40 +0100232 def __enter__(self):
233 return self
234
Klement Sekera7d6afb32018-11-08 11:52:04 +0100235 def assert_negative_api_retval(self):
236 """ Expect API failure - used with with, e.g.:
237 with self.vapi.assert_negative_api_retval():
238 self.vapi.<api call expected to fail>
239 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100240 self._expect_stack.append(self._expect_api_retval)
241 self._expect_api_retval = self._negative
242 return self
243
Klement Sekera7d6afb32018-11-08 11:52:04 +0100244 def assert_zero_api_retval(self):
245 """ Expect API success - used with with, e.g.:
246 with self.vapi.assert_negative_api_retval():
247 self.vapi.<api call expected to succeed>
248
249 note: this is useful only inside another with block
250 as success is the default expected value
251 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100252 self._expect_stack.append(self._expect_api_retval)
253 self._expect_api_retval = self._zero
254 return self
255
256 def __exit__(self, exc_type, exc_value, traceback):
257 self._expect_api_retval = self._expect_stack.pop()
258
Klement Sekeraf62ae122016-10-11 11:47:09 +0200259 def register_hook(self, hook):
260 """Replace hook registration with new hook
261
262 :param hook:
263
264 """
265 self.hook = hook
266
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200267 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100268 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200269 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100270 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200271 return e
272
273 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100274 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100275 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100276 self.test_class.logger.debug("Expecting event '%s' within %ss",
277 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300278 else:
279 self.test_class.logger.debug("Expecting event within %ss",
280 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100281 if self._events:
282 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200283 limit = time.time() + timeout
284 while time.time() < limit:
285 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100286 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200287 if name and type(e).__name__ != name:
288 raise Exception(
289 "Unexpected event received: %s, expected: %s" %
290 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100291 self.test_class.logger.debug("Returning event %s:%s" %
292 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200293 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700294 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200295 raise Exception("Event did not occur within timeout")
296
297 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100298 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200299 # FIXME use the name instead of relying on type(e).__name__ ?
300 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100301 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200302 self._events.append(event)
303
Ole Troanf159f582019-02-28 20:20:47 +0100304 def factory(self, name, apifn):
305 def f(*a, **ka):
306 fields = apifn._func.msg.fields
307
308 # add positional and kw arguments
309 d = ka
310 for i, o in enumerate(fields[3:]):
311 try:
312 d[o] = a[i]
313 except:
314 break
315
316 # Default override
317 if name in defaultmapping:
318 for k, v in iteritems(defaultmapping[name]):
319 if k in d:
320 continue
321 d[k] = v
322 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100323
Ole Troanf159f582019-02-28 20:20:47 +0100324 return f
325
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800326 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100327 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800328 method = super(VppPapiProvider, self).__getattribute__(name)
329 except AttributeError:
330 method = self.factory(name, getattr(self.papi, name))
331 # lazily load the method so we don't need to call factory
332 # again for this name.
333 setattr(self, name, method)
334 return method
Ole Troanf159f582019-02-28 20:20:47 +0100335
Klement Sekeraf62ae122016-10-11 11:47:09 +0200336 def connect(self):
337 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100338 self.vpp.connect(self.name, self.shm_prefix)
339 self.papi = self.vpp.api
340 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200341
342 def disconnect(self):
343 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100344 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200345
346 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100347 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200348 Call the appropriate hooks before and after the API call
349
350 :param api_fn: API function to call
351 :param api_args: tuple of API function arguments
352 :param expected_retval: Expected return value (Default value = 0)
353 :returns: reply from the API
354
355 """
356 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100357 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100358 if self._expect_api_retval == self._negative:
359 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100360 msg = "API call passed unexpectedly: expected negative " \
361 "return value instead of %d in %s" % \
362 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100363 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100364 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100365 elif self._expect_api_retval == self._zero:
366 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100367 msg = "API call failed, expected %d return value instead " \
368 "of %d in %s" % (expected_retval, reply.retval,
369 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100370 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100371 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100372 else:
373 raise Exception("Internal error, unexpected value for "
374 "self._expect_api_retval %s" %
375 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200376 self.hook.after_api(api_fn.__name__, api_args)
377 return reply
378
379 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100380 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200381
382 :param cli: CLI to execute
383 :returns: CLI output
384
385 """
386 self.hook.before_cli(cli)
387 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100388 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200389 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200390 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100391 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200392
Jan49c0fca2016-10-26 15:44:27 +0200393 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100394 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200395
396 :param cli: CLI to execute
397 :returns: CLI output
398 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600399 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200400
Neale Ranns37029302018-08-10 05:30:06 -0700401 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300402 return self.api(self.papi.want_ip4_arp_events,
403 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700404 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300405 'pid': os.getpid(), })
406
Neale Ranns37029302018-08-10 05:30:06 -0700407 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300408 return self.api(self.papi.want_ip6_nd_events,
409 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700410 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300411 'pid': os.getpid(), })
412
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100413 def want_ip6_ra_events(self, enable_disable=1):
414 return self.api(self.papi.want_ip6_ra_events,
415 {'enable_disable': enable_disable,
416 'pid': os.getpid(), })
417
418 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
419 mrc=0, mrd=0):
420 return self.api(self.papi.ip6nd_send_router_solicitation,
421 {'irt': irt,
422 'mrt': mrt,
423 'mrc': mrc,
424 'mrd': mrd,
425 'sw_if_index': sw_if_index})
426
Juraj Slobodab3f90502018-10-04 15:15:16 +0200427 def want_interface_events(self, enable_disable=1):
428 return self.api(self.papi.want_interface_events,
429 {'enable_disable': enable_disable,
430 'pid': os.getpid(), })
431
Ole Troane1ade682019-03-04 23:55:43 +0100432 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
433 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300434 return self.api(self.papi.want_l2_macs_events,
435 {'enable_disable': enable_disable,
436 'scan_delay': scan_delay,
437 'max_macs_in_event': max_macs_in_event,
438 'learn_limit': learn_limit,
439 'pid': os.getpid(), })
440
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200441 def want_dhcp6_reply_events(self, enable_disable=1):
442 return self.api(self.papi.want_dhcp6_reply_events,
443 {'enable_disable': enable_disable,
444 'pid': os.getpid()})
445
Juraj Sloboda81119e82018-05-25 14:02:20 +0200446 def want_dhcp6_pd_reply_events(self, enable_disable=1):
447 return self.api(self.papi.want_dhcp6_pd_reply_events,
448 {'enable_disable': enable_disable,
449 'pid': os.getpid()})
450
Juraj Sloboda81119e82018-05-25 14:02:20 +0200451 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
452 prefixes, server_index=0xFFFFFFFF,
453 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
454 ):
455 return self.api(self.papi.dhcp6_pd_send_client_message,
456 {'sw_if_index': sw_if_index,
457 'server_index': server_index,
458 'irt': irt,
459 'mrt': mrt,
460 'mrc': mrc,
461 'mrd': mrd,
462 'stop': stop,
463 'msg_type': msg_type,
464 'T1': T1,
465 'T2': T2,
466 'n_prefixes': len(prefixes),
467 'prefixes': prefixes})
468
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200469 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
470 enable=1):
471 return self.api(self.papi.dhcp6_client_enable_disable,
472 {'sw_if_index': sw_if_index,
473 'enable': enable})
474
Juraj Sloboda81119e82018-05-25 14:02:20 +0200475 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
476 enable=1):
477 return self.api(self.papi.dhcp6_pd_client_enable_disable,
478 {'sw_if_index': sw_if_index,
479 'prefix_group': prefix_group,
480 'enable': enable})
481
482 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
483 prefix_length, prefix_group,
484 is_add=1):
485 return self.api(self.papi.ip6_add_del_address_using_prefix,
486 {'sw_if_index': sw_if_index,
487 'prefix_group': prefix_group,
488 'address': address,
489 'prefix_length': prefix_length,
490 'is_add': is_add})
491
Neale Rannsc819fc62018-02-16 02:44:05 -0800492 def sw_interface_set_mac_address(self, sw_if_index, mac):
493 return self.api(self.papi.sw_interface_set_mac_address,
494 {'sw_if_index': sw_if_index,
495 'mac_address': mac})
496
Ole Troane1ade682019-03-04 23:55:43 +0100497 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200498 """Create p2p ethernet subinterface
499
500 :param sw_if_index: main (parent) interface
501 :param remote_mac: client (remote) mac address
502
503 """
504 return self.api(
505 self.papi.p2p_ethernet_add,
506 {'parent_if_index': sw_if_index,
507 'remote_mac': remote_mac,
508 'subif_id': subif_id})
509
Ole Troane1ade682019-03-04 23:55:43 +0100510 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200511 """Delete p2p ethernet subinterface
512
513 :param sw_if_index: main (parent) interface
514 :param remote_mac: client (remote) mac address
515
516 """
517 return self.api(
518 self.papi.p2p_ethernet_del,
519 {'parent_if_index': sw_if_index,
520 'remote_mac': remote_mac})
521
Klement Sekeraf62ae122016-10-11 11:47:09 +0200522 def create_vlan_subif(self, sw_if_index, vlan):
523 """
524
525 :param vlan:
526 :param sw_if_index:
527
528 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100529 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200530 {'sw_if_index': sw_if_index,
531 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200532
Matej Klotton0178d522016-11-04 11:11:44 +0100533 def create_loopback(self, mac=''):
534 """
535
536 :param mac: (Optional)
537 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100538 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200539 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100540
Matej Klotton0178d522016-11-04 11:11:44 +0100541 def ip_neighbor_add_del(self,
542 sw_if_index,
543 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700544 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100545 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700546 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100547 """ Add neighbor MAC to IPv4 or IPv6 address.
548
549 :param sw_if_index:
550 :param mac_address:
551 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100552 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700553 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100554 """
Matej Klotton0178d522016-11-04 11:11:44 +0100555 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100556 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700557 {
558 'is_add': is_add,
559 'neighbor': {
560 'sw_if_index': sw_if_index,
561 'flags': flags,
562 'mac_address': mac_address,
563 'ip_address': ip_address
564 }
565 }
Matej Klotton0178d522016-11-04 11:11:44 +0100566 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100567
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800568 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700569 low,
570 hi,
571 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800572 is_add=1):
573 """ Config Proxy Arp Range.
574
575 :param low_address: Start address in the rnage to Proxy for
576 :param hi_address: End address in the rnage to Proxy for
577 :param vrf_id: The VRF/table in which to proxy
578 """
579
580 return self.api(
581 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700582 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100583 {
584 'table_id': table_id,
585 'low': low,
586 'hi': hi,
587 },
588 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800589
590 def proxy_arp_intfc_enable_disable(self,
591 sw_if_index,
592 is_enable=1):
593 """ Enable/Disable an interface for proxy ARP requests
594
595 :param sw_if_index: Interface
596 :param enable_disable: Enable/Disable
597 """
598
599 return self.api(
600 self.papi.proxy_arp_intfc_enable_disable,
601 {'sw_if_index': sw_if_index,
602 'enable_disable': is_enable
603 }
604 )
605
Ole Troane1ade682019-03-04 23:55:43 +0100606 def gre_add_del_tunnel(self,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000607 src_address,
608 dst_address,
609 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500610 tunnel_type=0,
611 instance=0xFFFFFFFF,
612 session_id=0,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000613 is_add=1,
614 is_ip6=0):
615 """ 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(
Ole Troan7e3a8752016-12-05 10:27:09 +0100628 self.papi.gre_add_del_tunnel,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200629 {'is_add': is_add,
630 'is_ipv6': is_ip6,
John Loa43ccae2018-02-13 17:15:23 -0500631 'tunnel_type': tunnel_type,
632 'instance': instance,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200633 'src_address': src_address,
634 'dst_address': dst_address,
John Loa43ccae2018-02-13 17:15:23 -0500635 'outer_fib_id': outer_fib_id,
636 'session_id': session_id}
Neale Ranns177bbdc2016-11-15 09:46:51 +0000637 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000638
Neale Rannsd0df49f2018-08-08 01:06:40 -0700639 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700640 src_ip,
641 dst_ip,
642 src_port,
643 dst_port,
644 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800645 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800646 :param src_ip:
647 :param dst_ip:
648 :param src_port:
649 :param dst_port:
650 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800651 """
652
653 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700654 self.papi.udp_encap_add,
655 {
656 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700657 'src_ip': src_ip,
658 'dst_ip': dst_ip,
659 'src_port': src_port,
660 'dst_port': dst_port,
661 'table_id': table_id
662 }
663 })
664
Neale Ranns15002542017-09-10 04:39:11 -0700665 def mpls_table_add_del(
666 self,
667 table_id,
668 is_add=1):
669 """
670
671 :param table_id
672 :param is_add: (Default value = 1)
673
674 """
675
676 return self.api(
677 self.papi.mpls_table_add_del,
678 {'mt_table_id': table_id,
679 'mt_is_add': is_add})
680
Neale Rannsad422ed2016-11-02 14:20:04 +0000681 def mpls_ip_bind_unbind(
682 self,
683 label,
684 dst_address,
685 dst_address_length,
686 table_id=0,
687 ip_table_id=0,
688 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000689 is_bind=1):
690 """
691 """
692 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100693 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200694 {'mb_mpls_table_id': table_id,
695 'mb_label': label,
696 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200697 'mb_is_bind': is_bind,
698 'mb_is_ip4': is_ip4,
699 'mb_address_length': dst_address_length,
700 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000701
702 def mpls_tunnel_add_del(
703 self,
704 tun_sw_if_index,
705 next_hop_proto_is_ip4,
706 next_hop_address,
707 next_hop_sw_if_index=0xFFFFFFFF,
708 next_hop_table_id=0,
709 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200710 next_hop_n_out_labels=0,
711 next_hop_out_label_stack=[],
712 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000713 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800714 l2_only=0,
715 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000716 """
717
718 :param dst_address_length:
719 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
720 :param dst_address:
721 :param next_hop_address:
722 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
723 :param vrf_id: (Default value = 0)
724 :param lookup_in_vrf: (Default value = 0)
725 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000726 :param is_add: (Default value = 1)
727 :param is_drop: (Default value = 0)
728 :param is_ipv6: (Default value = 0)
729 :param is_local: (Default value = 0)
730 :param is_classify: (Default value = 0)
731 :param is_multipath: (Default value = 0)
732 :param is_resolve_host: (Default value = 0)
733 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000734 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800735 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000736
737 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000738 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100739 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200740 {'mt_sw_if_index': tun_sw_if_index,
741 'mt_is_add': is_add,
742 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800743 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200744 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
745 'mt_next_hop_weight': next_hop_weight,
746 'mt_next_hop': next_hop_address,
747 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
748 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
749 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700750 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200751 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800752
Matus Fabian2ba92e32017-08-21 07:05:03 -0700753 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -0800754 self,
755 sw_if_index,
756 is_inside=1,
757 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700758 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -0800759
760 :param sw_if_index: Software index of the interface
761 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
762 :param is_add: 1 if add, 0 if delete (Default value = 1)
763 """
764 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700765 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200766 {'is_add': is_add,
767 'is_inside': is_inside,
768 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800769
Matus Fabian2ba92e32017-08-21 07:05:03 -0700770 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -0700771 self,
772 sw_if_index,
773 is_inside=1,
774 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700775 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700776
777 :param sw_if_index: Software index of the interface
778 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
779 :param is_add: 1 if add, 0 if delete (Default value = 1)
780 """
781 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700782 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -0700783 {'is_add': is_add,
784 'is_inside': is_inside,
785 'sw_if_index': sw_if_index})
786
Matus Fabian2ba92e32017-08-21 07:05:03 -0700787 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -0800788 self,
789 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800790 external_ip=0,
791 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800792 local_port=0,
793 external_port=0,
794 addr_only=1,
795 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800796 protocol=0,
Matus Fabianb932d262017-12-18 05:38:24 -0800797 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200798 self_twice_nat=0,
Matus Fabiane82488f2018-01-18 03:38:45 -0800799 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800800 tag="",
Matus Fabian2ba92e32017-08-21 07:05:03 -0700801 is_add=1):
802 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -0800803
804 :param local_ip: Local IP address
805 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800806 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800807 :param local_port: Local port number (Default value = 0)
808 :param external_port: External port number (Default value = 0)
809 :param addr_only: 1 if address only mapping, 0 if address and port
810 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800811 :param protocol: IP protocol (Default value = 0)
Matus Fabianb932d262017-12-18 05:38:24 -0800812 :param twice_nat: 1 if translate external host address and port
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200813 :param self_twice_nat: 1 if translate external host address and port
814 whenever external host address equals
815 local address of internal host
Matus Fabiane82488f2018-01-18 03:38:45 -0800816 :param out2in_only: if 1 rule is matching only out2in direction
Matus Fabian5f224992018-01-25 21:59:16 -0800817 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -0800818 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800819 """
820 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700821 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200822 {'is_add': is_add,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200823 'addr_only': addr_only,
824 'local_ip_address': local_ip,
825 'external_ip_address': external_ip,
826 'local_port': local_port,
827 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800828 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800829 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -0800830 'protocol': protocol,
Matus Fabiane82488f2018-01-18 03:38:45 -0800831 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200832 'self_twice_nat': self_twice_nat,
Matus Fabian5f224992018-01-25 21:59:16 -0800833 'out2in_only': out2in_only,
834 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -0800835
Matus Fabianab7a8052017-11-28 04:29:41 -0800836 def nat44_add_del_identity_mapping(
837 self,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800838 ip=b'0',
Matus Fabianab7a8052017-11-28 04:29:41 -0800839 sw_if_index=0xFFFFFFFF,
840 port=0,
841 addr_only=1,
842 vrf_id=0,
843 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800844 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -0800845 is_add=1):
846 """Add/delete NAT44 identity mapping
847
848 :param ip: IP address (Default value = 0)
849 :param sw_if_index: Interface instead of IP address
850 :param port: Port number (Default value = 0)
851 :param addr_only: 1 if address only mapping, 0 if address and port
852 :param vrf_id: VRF ID
853 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -0800854 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -0800855 :param is_add: 1 if add, 0 if delete (Default value = 1)
856 """
857 return self.api(
858 self.papi.nat44_add_del_identity_mapping,
859 {'is_add': is_add,
860 'addr_only': addr_only,
861 'ip_address': ip,
862 'port': port,
863 'sw_if_index': sw_if_index,
864 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -0800865 'tag': tag,
Matus Fabianab7a8052017-11-28 04:29:41 -0800866 'protocol': protocol})
867
Matus Fabian2ba92e32017-08-21 07:05:03 -0700868 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -0800869 self,
870 first_ip_address,
871 last_ip_address,
872 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -0800873 vrf_id=0xFFFFFFFF,
874 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700875 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -0800876
877 :param first_ip_address: First IP address
878 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800879 :param vrf_id: VRF id for the address range
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700880 :param twice_nat: twice NAT address for extenral hosts
Matus Fabiande886752016-12-07 03:38:19 -0800881 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800882 """
883 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700884 self.papi.nat44_add_del_address_range,
885 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200886 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800887 'vrf_id': vrf_id,
Matus Fabianb932d262017-12-18 05:38:24 -0800888 'twice_nat': twice_nat,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200889 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -0800890
Ole Troane1ade682019-03-04 23:55:43 +0100891 def nat44_add_del_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -0800892 self,
893 sw_if_index,
Matus Fabianb932d262017-12-18 05:38:24 -0800894 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -0800895 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700896 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -0800897
898 :param sw_if_index: Software index of the interface
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700899 :param twice_nat: twice NAT address for external hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -0800900 :param is_add: 1 if add, 0 if delete (Default value = 1)
901 """
Matus Fabianb932d262017-12-18 05:38:24 -0800902 return self.api(
903 self.papi.nat44_add_del_interface_addr,
904 {'is_add': is_add,
905 'sw_if_index': sw_if_index,
906 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -0800907
Matus Fabian704018c2017-09-04 02:17:18 -0700908 def nat44_add_del_lb_static_mapping(
909 self,
910 external_addr,
911 external_port,
912 protocol,
Matus Fabianb932d262017-12-18 05:38:24 -0800913 twice_nat=0,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200914 self_twice_nat=0,
Matus Fabian240b5ef2018-01-11 04:09:17 -0800915 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800916 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -0700917 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700918 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +0200919 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -0700920 is_add=1):
921 """Add/delete NAT44 load balancing static mapping
922
Matus Fabianb932d262017-12-18 05:38:24 -0800923 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -0800924 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -0700925 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -0700926 :param is_add - 1 if add, 0 if delete
927 """
928 return self.api(
929 self.papi.nat44_add_del_lb_static_mapping,
930 {'is_add': is_add,
931 'external_addr': external_addr,
932 'external_port': external_port,
933 'protocol': protocol,
Matus Fabianb932d262017-12-18 05:38:24 -0800934 'twice_nat': twice_nat,
Juraj Sloboda1e5c07d2018-04-10 13:51:54 +0200935 'self_twice_nat': self_twice_nat,
Matus Fabian240b5ef2018-01-11 04:09:17 -0800936 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -0800937 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -0700938 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -0700939 'local_num': local_num,
940 'locals': locals})
941
Matus Fabianb6865082018-12-06 03:11:09 -0800942 def nat44_lb_static_mapping_add_del_local(
Ole Troan9a475372019-03-05 16:58:24 +0100943 self,
944 external_addr,
945 external_port,
946 local_addr,
947 local_port,
948 protocol,
949 probability,
950 vrf_id=0,
951 is_add=1):
Matus Fabianb6865082018-12-06 03:11:09 -0800952 """Add/delete NAT44 load-balancing static mapping rule backend
953
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700954 :param external_addr: external IPv4 address of the service
Matus Fabianb6865082018-12-06 03:11:09 -0800955 :param external_port: external L4 port number of the service
956 :param local_addr: IPv4 address of the internal node
957 :param local_port: L4 port number of the internal node
958 :param protocol: IP protocol number
959 :param probability: probability of the internal node
960 :param vrf_id: VRF id of the internal node
961 :param is_add: 1 if add, 0 if delete
962 """
963 return self.api(
964 self.papi.nat44_lb_static_mapping_add_del_local,
965 {'is_add': is_add,
966 'external_addr': external_addr,
967 'external_port': external_port,
968 'local': {
969 'addr': local_addr,
970 'port': local_port,
971 'probability': probability,
972 'vrf_id': vrf_id},
973 'protocol': protocol})
974
Matus Fabian5ba86f72017-10-26 03:37:38 -0700975 def nat44_del_session(
976 self,
977 addr,
978 port,
979 protocol,
980 vrf_id=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -0700981 is_in=1,
982 ext_host_address=None,
983 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -0700984 """Delete NAT44 session
985
986 :param addr: IPv4 address
987 :param por: port number
988 :param protocol: IP protocol number
989 :param vrf_id: VRF ID
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700990 :param is_in: 1 if inside network address and port pair, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -0700991 :param ext_host_address: external host IPv4 address
992 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -0700993 """
Matus Fabian70a26ac2018-05-14 06:20:28 -0700994 if ext_host_address is None:
995 return self.api(
996 self.papi.nat44_del_session,
997 {'address': addr,
998 'port': port,
999 'protocol': protocol,
1000 'vrf_id': vrf_id,
1001 'is_in': is_in})
1002 else:
1003 return self.api(
1004 self.papi.nat44_del_session,
1005 {'address': addr,
1006 'port': port,
1007 'protocol': protocol,
1008 'vrf_id': vrf_id,
1009 'is_in': is_in,
1010 'ext_host_valid': 1,
1011 'ext_host_address': ext_host_address,
1012 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001013
Juraj Sloboda7b929792017-11-23 13:20:48 +01001014 def nat44_forwarding_enable_disable(
1015 self,
1016 enable):
1017 """Enable/disable forwarding for NAT44
1018
1019 :param enable: 1 for enable, 0 for disable
1020 """
1021 return self.api(
1022 self.papi.nat44_forwarding_enable_disable,
1023 {'enable': enable})
1024
Matus Fabian2ba92e32017-08-21 07:05:03 -07001025 def nat_det_add_del_map(
Matus Fabian066f0342017-02-10 03:48:01 -08001026 self,
1027 in_addr,
1028 in_plen,
1029 out_addr,
1030 out_plen,
1031 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -07001032 """Add/delete deterministic NAT mapping
Matus Fabian066f0342017-02-10 03:48:01 -08001033
1034 :param is_add - 1 if add, 0 if delete
1035 :param in_addr - inside IP address
1036 :param in_plen - inside IP address prefix length
1037 :param out_addr - outside IP address
1038 :param out_plen - outside IP address prefix length
1039 """
1040 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001041 self.papi.nat_det_add_del_map,
Matus Fabian066f0342017-02-10 03:48:01 -08001042 {'is_add': is_add,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001043 'is_nat44': 1,
Matus Fabian066f0342017-02-10 03:48:01 -08001044 'in_addr': in_addr,
1045 'in_plen': in_plen,
1046 'out_addr': out_addr,
1047 'out_plen': out_plen})
1048
Matus Fabian2ba92e32017-08-21 07:05:03 -07001049 def nat_det_forward(
Matus Fabian066f0342017-02-10 03:48:01 -08001050 self,
1051 in_addr):
1052 """Get outside address and port range from inside address
1053
1054 :param in_addr - inside IP address
1055 """
1056 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001057 self.papi.nat_det_forward,
1058 {'in_addr': in_addr,
1059 'is_nat44': 1})
Matus Fabian066f0342017-02-10 03:48:01 -08001060
Matus Fabian2ba92e32017-08-21 07:05:03 -07001061 def nat_det_reverse(
Matus Fabian066f0342017-02-10 03:48:01 -08001062 self,
1063 out_addr,
1064 out_port):
1065 """Get inside address from outside address and port
1066
1067 :param out_addr - outside IP address
1068 :param out_port - outside port
1069 """
1070 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001071 self.papi.nat_det_reverse,
Matus Fabian066f0342017-02-10 03:48:01 -08001072 {'out_addr': out_addr,
1073 'out_port': out_port})
1074
Matus Fabian2ba92e32017-08-21 07:05:03 -07001075 def nat_det_map_dump(self):
1076 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001077
Matus Fabian2ba92e32017-08-21 07:05:03 -07001078 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001079 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001080 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001081
Matus Fabianbb4e0222018-09-13 02:36:25 -07001082 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1083 """Set TCP MSS rewriting configuration
1084
1085 :param enable: disable(0)/enable(1) MSS rewriting feature
1086 :param mss_value: MSS value to be used for MSS rewriting
1087 """
1088 return self.api(
1089 self.papi.nat_set_mss_clamping,
1090 {'enable': enable, 'mss_value': mss_value})
1091
Matus Fabian2ba92e32017-08-21 07:05:03 -07001092 def nat_det_close_session_in(
Martin Gálik6bc8c642017-04-19 01:12:27 -07001093 self,
1094 in_addr,
1095 in_port,
1096 ext_addr,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001097 ext_port):
1098 """Close deterministic NAT session using inside address and port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001099
1100 :param in_addr - inside IP address
1101 :param in_port - inside port
1102 :param ext_addr - external host IP address
1103 :param ext_port - external host port
Martin Gálik6bc8c642017-04-19 01:12:27 -07001104 """
1105 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001106 self.papi.nat_det_close_session_in,
Martin Gálik6bc8c642017-04-19 01:12:27 -07001107 {'in_addr': in_addr,
1108 'in_port': in_port,
1109 'ext_addr': ext_addr,
1110 'ext_port': ext_port,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001111 'is_nat44': 1})
Martin Gálik6bc8c642017-04-19 01:12:27 -07001112
Matus Fabian2ba92e32017-08-21 07:05:03 -07001113 def nat_det_session_dump(
Martin Gálik9806eae2017-04-25 01:25:08 -07001114 self,
Matus Fabian2ba92e32017-08-21 07:05:03 -07001115 user_addr):
1116 """Dump deterministic NAT sessions belonging to a user
Martin Gálik9806eae2017-04-25 01:25:08 -07001117
1118 :param user_addr - inside IP address of the user
Matus Fabian2ba92e32017-08-21 07:05:03 -07001119 :return: Dictionary of deterministic NAT sessions
Martin Gálik9806eae2017-04-25 01:25:08 -07001120 """
1121 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -07001122 self.papi.nat_det_session_dump,
1123 {'is_nat44': 1,
Martin Gálik9806eae2017-04-25 01:25:08 -07001124 'user_addr': user_addr})
1125
Matus Fabian06596c52017-06-06 04:53:28 -07001126 def nat64_add_del_interface(
1127 self,
1128 sw_if_index,
1129 is_inside=1,
1130 is_add=1):
1131 """Enable/disable NAT64 feature on the interface
1132 :param sw_if_index: Index of the interface
1133 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1134 :param is_add: 1 if add, 0 if delete (Default value = 1)
1135 """
1136 return self.api(
1137 self.papi.nat64_add_del_interface,
1138 {'sw_if_index': sw_if_index,
1139 'is_inside': is_inside,
1140 'is_add': is_add})
1141
Matus Fabian06596c52017-06-06 04:53:28 -07001142 def nat64_add_del_static_bib(
1143 self,
1144 in_ip,
1145 out_ip,
1146 in_port,
1147 out_port,
1148 protocol,
1149 vrf_id=0,
1150 is_add=1):
1151 """Add/delete S-NAT static BIB entry
1152
1153 :param in_ip: Inside IPv6 address
1154 :param out_ip: Outside IPv4 address
1155 :param in_port: Inside port number
1156 :param out_port: Outside port number
1157 :param protocol: IP protocol
1158 :param vrf_id: VRF ID (Default value = 0)
1159 :param is_add: 1 if add, 0 if delete (Default value = 1)
1160 """
1161 return self.api(
1162 self.papi.nat64_add_del_static_bib,
1163 {'i_addr': in_ip,
1164 'o_addr': out_ip,
1165 'i_port': in_port,
1166 'o_port': out_port,
1167 'vrf_id': vrf_id,
1168 'proto': protocol,
1169 'is_add': is_add})
1170
Matus Fabianab9a59c2017-08-16 05:37:36 -07001171 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001172 """Dump NAT64 BIB
1173
Matus Fabianab9a59c2017-08-16 05:37:36 -07001174 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001175 :returns: Dictionary of NAT64 BIB entries
1176 """
1177 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1178
Matus Fabianab9a59c2017-08-16 05:37:36 -07001179 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001180 """Dump NAT64 session table
1181
Matus Fabianab9a59c2017-08-16 05:37:36 -07001182 :param protocol: IP protocol (Default value = 255, all STs)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001183 :returns: Dictionary of NAT64 session table entries
Matus Fabian06596c52017-06-06 04:53:28 -07001184 """
1185 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1186
Matus Fabian428dc912017-06-21 06:15:18 -07001187 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
1188 """Add/del NAT64 prefix
1189
1190 :param prefix: NAT64 prefix
1191 :param plen: NAT64 prefix length
1192 :param vrf_id: VRF id of tenant (Default 0)
1193 :param is_add: 1 if add, 0 if delete (Default value = 1)
1194 """
1195 return self.api(
1196 self.papi.nat64_add_del_prefix,
1197 {'prefix': prefix,
1198 'prefix_len': plen,
1199 'vrf_id': vrf_id,
1200 'is_add': is_add})
1201
Ole Troane1ade682019-03-04 23:55:43 +01001202 def nat64_add_del_interface_addr(
Matus Fabian0938dcf2017-11-08 01:59:38 -08001203 self,
1204 sw_if_index,
1205 is_add=1):
1206 """Add/del NAT64 address from interface
1207
1208 :param sw_if_index: Software index of the interface
1209 :param is_add: 1 if add, 0 if delete (Default value = 1)
1210 """
1211 return self.api(self.papi.nat64_add_del_interface_addr,
1212 {'is_add': is_add, 'sw_if_index': sw_if_index})
1213
Matus Fabian8ebe6252017-11-06 05:04:53 -08001214 def dslite_set_aftr_addr(self, ip6, ip4):
1215 """Set DS-Lite AFTR addresses
1216
1217 :param ip4: IPv4 address
1218 :param ip6: IPv6 address
1219 """
1220 return self.api(
1221 self.papi.dslite_set_aftr_addr,
1222 {'ip4_addr': ip4,
1223 'ip6_addr': ip6})
1224
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001225 def dslite_set_b4_addr(self, ip6, ip4):
1226 """Set DS-Lite B4 IPv6 address
1227
1228 :param ip4: IPv4 address
1229 :param ip6: IPv6 address
1230 """
1231 return self.api(
1232 self.papi.dslite_set_b4_addr,
1233 {'ip4_addr': ip4,
1234 'ip6_addr': ip6})
1235
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001236 def nat66_add_del_interface(
1237 self,
1238 sw_if_index,
1239 is_inside=1,
1240 is_add=1):
1241 """Enable/disable NAT66 feature on the interface
1242 :param sw_if_index: Index of the interface
1243 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1244 :param is_add: 1 if add, 0 if delete (Default value = 1)
1245 """
1246 return self.api(
1247 self.papi.nat66_add_del_interface,
1248 {'sw_if_index': sw_if_index,
1249 'is_inside': is_inside,
1250 'is_add': is_add})
1251
1252 def nat66_add_del_static_mapping(
1253 self,
1254 in_ip,
1255 out_ip,
1256 vrf_id=0,
1257 is_add=1):
1258 """Add/delete NAT66 static mapping
1259
1260 :param in_ip: Inside IPv6 address
1261 :param out_ip: Outside IPv6 address
1262 :param vrf_id: VRF ID (Default value = 0)
1263 :param is_add: 1 if add, 0 if delete (Default value = 1)
1264 """
1265 return self.api(
1266 self.papi.nat66_add_del_static_mapping,
1267 {'local_ip_address': in_ip,
1268 'external_ip_address': out_ip,
1269 'vrf_id': vrf_id,
1270 'is_add': is_add})
1271
Matus Fabian34931eb2019-02-26 09:05:23 -08001272 def nat_ha_set_listener(self, addr, port, path_mtu=512):
1273 """Set HA listener (local settings)
1274
1275 :param addr: local IP4 address
1276 :param port: local UDP port number
1277 :param path_mtu: path MTU (Default value = 512)
1278 """
1279 return self.api(self.papi.nat_ha_set_listener,
1280 {'ip_address': addr,
1281 'port': port,
1282 'path_mtu': path_mtu})
1283
1284 def nat_ha_get_listener(self):
1285 """Get HA listener/local configuration"""
1286 return self.api(self.papi.nat_ha_get_listener, {})
1287
1288 def nat_ha_set_failover(self, addr, port, refresh=10):
1289 """Set HA failover (remote settings)
1290
1291 :param addr: failover IP4 address
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001292 :param port: failover UDP port number
Matus Fabian34931eb2019-02-26 09:05:23 -08001293 :param refresh: number of seconds after which to send session refresh
1294 """
1295 return self.api(self.papi.nat_ha_set_failover,
1296 {'ip_address': addr,
1297 'port': port,
1298 'session_refresh_interval': refresh})
1299
Matus Fabian34931eb2019-02-26 09:05:23 -08001300 def nat_ha_resync(self, want_resync_event=1):
1301 """Resync HA (resend existing sessions to new failover)
1302 :param want_resync_event: if non-zero resync completed event sent
1303 """
1304 return self.api(self.papi.nat_ha_resync,
1305 {'want_resync_event': want_resync_event,
1306 'pid': os.getpid()})
1307
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001308 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001309 detect_mult, local_addr, peer_addr, is_ipv6=0,
1310 bfd_key_id=None, conf_key_id=None):
1311 if bfd_key_id is None:
1312 return self.api(self.papi.bfd_udp_add,
1313 {
1314 'sw_if_index': sw_if_index,
1315 'desired_min_tx': desired_min_tx,
1316 'required_min_rx': required_min_rx,
1317 'local_addr': local_addr,
1318 'peer_addr': peer_addr,
1319 'is_ipv6': is_ipv6,
1320 'detect_mult': detect_mult,
1321 })
1322 else:
1323 return self.api(self.papi.bfd_udp_add,
1324 {
1325 'sw_if_index': sw_if_index,
1326 'desired_min_tx': desired_min_tx,
1327 'required_min_rx': required_min_rx,
1328 'local_addr': local_addr,
1329 'peer_addr': peer_addr,
1330 'is_ipv6': is_ipv6,
1331 'detect_mult': detect_mult,
1332 'is_authenticated': 1,
1333 'bfd_key_id': bfd_key_id,
1334 'conf_key_id': conf_key_id,
1335 })
1336
Klement Sekeraa57a9702017-02-02 06:58:07 +01001337 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1338 detect_mult, local_addr, peer_addr, is_ipv6=0):
1339 return self.api(self.papi.bfd_udp_mod,
1340 {
1341 'sw_if_index': sw_if_index,
1342 'desired_min_tx': desired_min_tx,
1343 'required_min_rx': required_min_rx,
1344 'local_addr': local_addr,
1345 'peer_addr': peer_addr,
1346 'is_ipv6': is_ipv6,
1347 'detect_mult': detect_mult,
1348 })
1349
Klement Sekerab17dd962017-01-09 07:43:48 +01001350 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1351 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1352 is_delayed=False):
1353 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001354 {
1355 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001356 'local_addr': local_addr,
1357 'peer_addr': peer_addr,
1358 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001359 'is_delayed': 1 if is_delayed else 0,
1360 'bfd_key_id': bfd_key_id,
1361 'conf_key_id': conf_key_id,
1362 })
1363
Klement Sekerab17dd962017-01-09 07:43:48 +01001364 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1365 peer_addr, is_ipv6=0):
1366 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001367 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001368 'sw_if_index': sw_if_index,
1369 'local_addr': local_addr,
1370 'peer_addr': peer_addr,
1371 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001372 })
1373
1374 def want_bfd_events(self, enable_disable=1):
1375 return self.api(self.papi.want_bfd_events, {
1376 'enable_disable': enable_disable,
1377 'pid': os.getpid(),
1378 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001379
Klement Sekerab17dd962017-01-09 07:43:48 +01001380 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1381 return self.api(self.papi.bfd_auth_set_key, {
1382 'conf_key_id': conf_key_id,
1383 'auth_type': auth_type,
1384 'key': key,
1385 'key_len': len(key),
1386 })
1387
Steve Shin7957d6e2016-12-19 09:24:50 -08001388 def classify_add_del_table(
1389 self,
1390 is_add,
1391 mask,
1392 match_n_vectors=1,
1393 table_index=0xFFFFFFFF,
1394 nbuckets=2,
1395 memory_size=2097152,
1396 skip_n_vectors=0,
1397 next_table_index=0xFFFFFFFF,
1398 miss_next_index=0xFFFFFFFF,
1399 current_data_flag=0,
1400 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001401 """
1402 :param is_add:
1403 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001404 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001405 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001406 :param nbuckets: (Default value = 2)
1407 :param memory_size: (Default value = 2097152)
1408 :param skip_n_vectors: (Default value = 0)
1409 :param next_table_index: (Default value = 0xFFFFFFFF)
1410 :param miss_next_index: (Default value = 0xFFFFFFFF)
1411 :param current_data_flag: (Default value = 0)
1412 :param current_data_offset: (Default value = 0)
1413 """
1414
Juraj Sloboda75282452018-06-12 14:20:49 +02001415 mask_len = ((len(mask) - 1) / 16 + 1) * 16
1416 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08001417 return self.api(
1418 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001419 {'is_add': is_add,
1420 'table_index': table_index,
1421 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001422 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001423 'skip_n_vectors': skip_n_vectors,
1424 'match_n_vectors': match_n_vectors,
1425 'next_table_index': next_table_index,
1426 'miss_next_index': miss_next_index,
1427 'current_data_flag': current_data_flag,
1428 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02001429 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001430 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001431
1432 def classify_add_del_session(
1433 self,
1434 is_add,
1435 table_index,
1436 match,
1437 opaque_index=0xFFFFFFFF,
1438 hit_next_index=0xFFFFFFFF,
1439 advance=0,
1440 action=0,
1441 metadata=0):
1442 """
1443 :param is_add:
1444 :param table_index:
1445 :param match:
1446 :param opaque_index: (Default value = 0xFFFFFFFF)
1447 :param hit_next_index: (Default value = 0xFFFFFFFF)
1448 :param advance: (Default value = 0)
1449 :param action: (Default value = 0)
1450 :param metadata: (Default value = 0)
1451 """
1452
Juraj Sloboda75282452018-06-12 14:20:49 +02001453 match_len = ((len(match) - 1) / 16 + 1) * 16
1454 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08001455 return self.api(
1456 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001457 {'is_add': is_add,
1458 'table_index': table_index,
1459 'hit_next_index': hit_next_index,
1460 'opaque_index': opaque_index,
1461 'advance': advance,
1462 'action': action,
1463 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02001464 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001465 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001466
1467 def input_acl_set_interface(
1468 self,
1469 is_add,
1470 sw_if_index,
1471 ip4_table_index=0xFFFFFFFF,
1472 ip6_table_index=0xFFFFFFFF,
1473 l2_table_index=0xFFFFFFFF):
1474 """
1475 :param is_add:
1476 :param sw_if_index:
1477 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1478 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1479 :param l2_table_index: (Default value = 0xFFFFFFFF)
1480 """
1481
1482 return self.api(
1483 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001484 {'sw_if_index': sw_if_index,
1485 'ip4_table_index': ip4_table_index,
1486 'ip6_table_index': ip6_table_index,
1487 'l2_table_index': l2_table_index,
1488 'is_add': is_add})
1489
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01001490 def output_acl_set_interface(
1491 self,
1492 is_add,
1493 sw_if_index,
1494 ip4_table_index=0xFFFFFFFF,
1495 ip6_table_index=0xFFFFFFFF,
1496 l2_table_index=0xFFFFFFFF):
1497 """
1498 :param is_add:
1499 :param sw_if_index:
1500 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1501 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1502 :param l2_table_index: (Default value = 0xFFFFFFFF)
1503 """
1504
1505 return self.api(
1506 self.papi.output_acl_set_interface,
1507 {'sw_if_index': sw_if_index,
1508 'ip4_table_index': ip4_table_index,
1509 'ip6_table_index': ip6_table_index,
1510 'l2_table_index': l2_table_index,
1511 'is_add': is_add})
1512
Klement Sekera77fabdb2017-01-02 07:46:14 +01001513 def set_ipfix_exporter(
1514 self,
1515 collector_address,
1516 src_address,
1517 path_mtu,
1518 template_interval,
1519 vrf_id=0,
1520 collector_port=4739,
1521 udp_checksum=0):
1522 return self.api(
1523 self.papi.set_ipfix_exporter,
1524 {
1525 'collector_address': collector_address,
1526 'collector_port': collector_port,
1527 'src_address': src_address,
1528 'vrf_id': vrf_id,
1529 'path_mtu': path_mtu,
1530 'template_interval': template_interval,
1531 'udp_checksum': udp_checksum,
1532 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001533
1534 def dhcp_proxy_config(self,
1535 dhcp_server,
1536 dhcp_src_address,
1537 rx_table_id=0,
1538 server_table_id=0,
1539 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001540 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001541 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001542 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001543 {
1544 'rx_vrf_id': rx_table_id,
1545 'server_vrf_id': server_table_id,
1546 'is_ipv6': is_ipv6,
1547 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001548 'dhcp_server': dhcp_server,
1549 'dhcp_src_address': dhcp_src_address,
1550 })
1551
1552 def dhcp_proxy_set_vss(self,
1553 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001554 vss_type=255,
1555 vpn_ascii_id="",
1556 oui=0,
1557 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001558 is_add=1,
1559 is_ip6=0):
1560 return self.api(
1561 self.papi.dhcp_proxy_set_vss,
1562 {
1563 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001564 'vss_type': vss_type,
1565 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001566 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001567 'vpn_index': vpn_index,
1568 'is_add': is_add,
1569 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001570 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001571
Ole Troane1ade682019-03-04 23:55:43 +01001572 def dhcp_client_config(self,
1573 sw_if_index,
1574 hostname,
1575 client_id='',
1576 is_add=1,
1577 set_broadcast_flag=1,
1578 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001579 return self.api(
1580 self.papi.dhcp_client_config,
1581 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001582 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001583 'client': {
1584 'sw_if_index': sw_if_index,
1585 'hostname': hostname,
1586 'id': client_id,
1587 'want_dhcp_event': want_dhcp_events,
1588 'set_broadcast_flag': set_broadcast_flag,
1589 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001590 })
1591
Neale Ranns32e1c012016-11-22 17:07:28 +00001592 def ip_mroute_add_del(self,
1593 src_address,
1594 grp_address,
1595 grp_address_length,
1596 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001597 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001598 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001599 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001600 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001601 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001602 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001603 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001604 is_add=1,
1605 is_ipv6=0,
1606 is_local=0):
1607 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001608 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001609 """
1610 return self.api(
1611 self.papi.ip_mroute_add_del,
1612 {'next_hop_sw_if_index': next_hop_sw_if_index,
1613 'entry_flags': e_flags,
1614 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001615 'table_id': table_id,
1616 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001617 'is_add': is_add,
1618 'is_ipv6': is_ipv6,
1619 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001620 'bier_imp': bier_imp,
1621 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001622 'grp_address_length': grp_address_length,
1623 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001624 'src_address': src_address,
1625 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001626
Filip Tehlar770e89e2017-01-31 10:39:16 +01001627 def lisp_enable_disable(self, is_enabled):
1628 return self.api(
1629 self.papi.lisp_enable_disable,
1630 {
1631 'is_en': is_enabled,
1632 })
1633
Ole Troane1ade682019-03-04 23:55:43 +01001634 def lisp_add_del_locator_set(self,
1635 ls_name,
1636 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001637 return self.api(
1638 self.papi.lisp_add_del_locator_set,
1639 {
1640 'is_add': is_add,
1641 'locator_set_name': ls_name
1642 })
1643
Ole Troane1ade682019-03-04 23:55:43 +01001644 def lisp_add_del_locator(self,
1645 ls_name,
1646 sw_if_index,
1647 priority=1,
1648 weight=1,
1649 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001650 return self.api(
1651 self.papi.lisp_add_del_locator,
1652 {
1653 'is_add': is_add,
1654 'locator_set_name': ls_name,
1655 'sw_if_index': sw_if_index,
1656 'priority': priority,
1657 'weight': weight
1658 })
1659
1660 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1661 return self.api(
1662 self.papi.lisp_locator_dump,
1663 {
1664 'is_index_set': is_index_set,
1665 'ls_name': ls_name,
1666 'ls_index': ls_index,
1667 })
1668
Ole Troane1ade682019-03-04 23:55:43 +01001669 def lisp_add_del_local_eid(self,
1670 ls_name,
1671 eid_type,
1672 eid,
1673 prefix_len,
1674 vni=0,
1675 key_id=0,
1676 key="",
1677 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001678 return self.api(
1679 self.papi.lisp_add_del_local_eid,
1680 {
1681 'locator_set_name': ls_name,
1682 'is_add': is_add,
1683 'eid_type': eid_type,
1684 'eid': eid,
1685 'prefix_len': prefix_len,
1686 'vni': vni,
1687 'key_id': key_id,
1688 'key': key
1689 })
1690
1691 def lisp_eid_table_dump(self,
1692 eid_set=0,
1693 prefix_length=0,
1694 vni=0,
1695 eid_type=0,
1696 eid=None,
1697 filter_opt=0):
1698 return self.api(
1699 self.papi.lisp_eid_table_dump,
1700 {
1701 'eid_set': eid_set,
1702 'prefix_length': prefix_length,
1703 'vni': vni,
1704 'eid_type': eid_type,
1705 'eid': eid,
1706 'filter': filter_opt,
1707 })
1708
Ole Troane1ade682019-03-04 23:55:43 +01001709 def lisp_add_del_remote_mapping(self,
1710 eid_type,
1711 eid,
1712 eid_prefix_len=0,
1713 vni=0,
1714 rlocs=[],
1715 rlocs_num=0,
1716 is_src_dst=0,
1717 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001718 return self.api(
1719 self.papi.lisp_add_del_remote_mapping,
1720 {
1721 'is_add': is_add,
1722 'eid_type': eid_type,
1723 'eid': eid,
1724 'eid_len': eid_prefix_len,
1725 'rloc_num': rlocs_num,
1726 'rlocs': rlocs,
1727 'vni': vni,
1728 'is_src_dst': is_src_dst,
1729 })
1730
Ole Troane1ade682019-03-04 23:55:43 +01001731 def lisp_add_del_adjacency(self,
1732 leid,
1733 reid,
1734 leid_len,
1735 reid_len,
1736 eid_type,
1737 is_add=1,
1738 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001739 return self.api(
1740 self.papi.lisp_add_del_adjacency,
1741 {
1742 'is_add': is_add,
1743 'vni': vni,
1744 'eid_type': eid_type,
1745 'leid': leid,
1746 'reid': reid,
1747 'leid_len': leid_len,
1748 'reid_len': reid_len,
1749 })
1750
Hongjun Nief486b12017-04-12 19:21:16 +08001751 def gtpu_add_del_tunnel(
1752 self,
1753 src_addr,
1754 dst_addr,
1755 is_add=1,
1756 is_ipv6=0,
1757 mcast_sw_if_index=0xFFFFFFFF,
1758 encap_vrf_id=0,
1759 decap_next_index=0xFFFFFFFF,
1760 teid=0):
1761 """
1762
1763 :param is_add: (Default value = 1)
1764 :param is_ipv6: (Default value = 0)
1765 :param src_addr:
1766 :param dst_addr:
1767 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1768 :param encap_vrf_id: (Default value = 0)
1769 :param decap_next_index: (Default value = 0xFFFFFFFF)
1770 :param teid: (Default value = 0)
1771
1772 """
1773 return self.api(self.papi.gtpu_add_del_tunnel,
1774 {'is_add': is_add,
1775 'is_ipv6': is_ipv6,
1776 'src_address': src_addr,
1777 'dst_address': dst_addr,
1778 'mcast_sw_if_index': mcast_sw_if_index,
1779 'encap_vrf_id': encap_vrf_id,
1780 'decap_next_index': decap_next_index,
1781 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001782
1783 def vxlan_gpe_add_del_tunnel(
1784 self,
1785 src_addr,
1786 dst_addr,
1787 mcast_sw_if_index=0xFFFFFFFF,
1788 is_add=1,
1789 is_ipv6=0,
1790 encap_vrf_id=0,
1791 decap_vrf_id=0,
1792 protocol=3,
1793 vni=0):
1794 """
1795
1796 :param local:
1797 :param remote:
1798 :param is_add: (Default value = 1)
1799 :param is_ipv6: (Default value = 0)
1800 :param encap_vrf_id: (Default value = 0)
1801 :param decap_vrf_id: (Default value = 0)
1802 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1803 :param protocol: (Default value = 3)
1804 :param vni: (Default value = 0)
1805
1806 """
1807 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1808 {'is_add': is_add,
1809 'is_ipv6': is_ipv6,
1810 'local': src_addr,
1811 'remote': dst_addr,
1812 'mcast_sw_if_index': mcast_sw_if_index,
1813 'encap_vrf_id': encap_vrf_id,
1814 'decap_vrf_id': decap_vrf_id,
1815 'protocol': protocol,
1816 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001817
Neale Ranns79a05f52018-09-11 07:39:43 -07001818 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001819 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001820 src,
1821 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001822 mcast_sw_if_index=0xFFFFFFFF,
1823 is_add=1,
1824 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001825 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001826 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001827 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001828 instance=0xFFFFFFFF):
1829 """
1830
1831 :param dst_addr:
1832 :param src_addr:
1833 :param is_add: (Default value = 1)
1834 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001835 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001836 :param decap_next_index: (Default value = 0xFFFFFFFF)
1837 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1838 :param vni: (Default value = 0)
1839 :param instance: (Default value = 0xFFFFFFFF)
1840
1841 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001842 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001843 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001844 'tunnel': {
1845 'src': src,
1846 'dst': dst,
1847 'mcast_sw_if_index': mcast_sw_if_index,
1848 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001849 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001850 'instance': instance,
1851 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001852
1853 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1854 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001855 {'sw_if_index': sw_if_index,
1856 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001857
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001858 def pppoe_add_del_session(
1859 self,
1860 client_ip,
1861 client_mac,
1862 session_id=0,
1863 is_add=1,
1864 is_ipv6=0,
1865 decap_vrf_id=0):
1866 """
1867
1868 :param is_add: (Default value = 1)
1869 :param is_ipv6: (Default value = 0)
1870 :param client_ip:
1871 :param session_id: (Default value = 0)
1872 :param client_mac:
1873 :param decap_vrf_id: (Default value = 0)
1874
1875 """
1876 return self.api(self.papi.pppoe_add_del_session,
1877 {'is_add': is_add,
1878 'is_ipv6': is_ipv6,
1879 'session_id': session_id,
1880 'client_ip': client_ip,
1881 'decap_vrf_id': decap_vrf_id,
1882 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001883
Neale Ranns7c922dc2018-08-30 06:12:27 -07001884 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1885 return self.api(self.papi.sr_mpls_policy_add,
1886 {'bsid': bsid,
1887 'weight': weight,
1888 'type': type,
1889 'n_segments': len(segments),
1890 'segments': segments})
1891
1892 def sr_mpls_policy_del(self, bsid):
1893 return self.api(self.papi.sr_mpls_policy_del,
1894 {'bsid': bsid})
1895
Kris Michielsen91074432017-06-22 13:00:20 +02001896 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001897 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001898 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001899 nh_addr4,
1900 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001901 is_del=0,
1902 end_psp=0,
1903 sw_if_index=0xFFFFFFFF,
1904 vlan_index=0,
1905 fib_table=0,
1906 ):
1907 """ Add/del IPv6 SR local-SID.
1908
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001909 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001910 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1911 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001912 :param nh_addr4:
1913 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001914 :param is_del: (Default value = 0)
1915 :param end_psp: (Default value = 0)
1916 :param sw_if_index: (Default value = 0xFFFFFFFF)
1917 :param vlan_index: (Default value = 0)
1918 :param fib_table: (Default value = 0)
1919 """
1920 return self.api(
1921 self.papi.sr_localsid_add_del,
1922 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001923 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001924 'end_psp': end_psp,
1925 'behavior': behavior,
1926 'sw_if_index': sw_if_index,
1927 'vlan_index': vlan_index,
1928 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001929 'nh_addr4': nh_addr4,
1930 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001931 }
1932 )
1933
1934 def sr_policy_add(
1935 self,
1936 bsid_addr,
1937 weight=1,
1938 is_encap=1,
1939 type=0,
1940 fib_table=0,
1941 n_segments=0,
1942 segments=[]):
1943 """
1944 :param bsid_addr: bindingSID of the SR Policy
1945 :param weight: weight of the sid list. optional. (default: 1)
1946 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1947 (default: Encap)
1948 :param type: type/behavior of the SR policy. (default or spray) \
1949 (default: default)
1950 :param fib_table: VRF where to install the FIB entry for the BSID \
1951 (default: 0)
1952 :param n_segments: number of segments \
1953 (default: 0)
1954 :param segments: a vector of IPv6 address composing the segment list \
1955 (default: [])
1956 """
1957 return self.api(
1958 self.papi.sr_policy_add,
1959 {'bsid_addr': bsid_addr,
1960 'weight': weight,
1961 'is_encap': is_encap,
1962 'type': type,
1963 'fib_table': fib_table,
1964 'n_segments': n_segments,
1965 'segments': segments
1966 }
1967 )
1968
1969 def sr_policy_del(
1970 self,
1971 bsid_addr,
1972 sr_policy_index=0):
1973 """
1974 :param bsid: bindingSID of the SR Policy
1975 :param sr_policy_index: index of the sr policy (default: 0)
1976 """
1977 return self.api(
1978 self.papi.sr_policy_del,
1979 {'bsid_addr': bsid_addr,
1980 'sr_policy_index': sr_policy_index
1981 })
1982
1983 def sr_steering_add_del(
1984 self,
1985 is_del,
1986 bsid_addr,
1987 sr_policy_index,
1988 table_id,
1989 prefix_addr,
1990 mask_width,
1991 sw_if_index,
1992 traffic_type):
1993 """
1994 Steer traffic L2 and L3 traffic through a given SR policy
1995
1996 :param is_del: delete or add
1997 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1998 :param sr_policy: is the index of the SR Policy (alt to bsid)
1999 :param table_id: is the VRF where to install the FIB entry for the BSID
2000 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2001 :param mask_width: is the mask for L3 traffic type
2002 :param sw_if_index: is the incoming interface for L2 traffic
2003 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2004 """
2005 return self.api(
2006 self.papi.sr_steering_add_del,
2007 {'is_del': is_del,
2008 'bsid_addr': bsid_addr,
2009 'sr_policy_index': sr_policy_index,
2010 'table_id': table_id,
2011 'prefix_addr': prefix_addr,
2012 'mask_width': mask_width,
2013 'sw_if_index': sw_if_index,
2014 'traffic_type': traffic_type
2015 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002016
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002017 def acl_add_replace(self, acl_index, r, tag='',
2018 expected_retval=0):
2019 """Add/replace an ACL
2020 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2021 :param acl_rule r: ACL rules array.
2022 :param str tag: symbolic tag (description) for this ACL.
2023 :param int count: number of rules.
2024 """
2025 return self.api(self.papi.acl_add_replace,
2026 {'acl_index': acl_index,
2027 'r': r,
2028 'count': len(r),
2029 'tag': tag},
2030 expected_retval=expected_retval)
2031
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002032 def acl_del(self, acl_index, expected_retval=0):
2033 """
2034
2035 :param acl_index:
2036 :return:
2037 """
2038 return self.api(self.papi.acl_del,
2039 {'acl_index': acl_index},
2040 expected_retval=expected_retval)
2041
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002042 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2043 expected_retval=0):
2044 return self.api(self.papi.acl_interface_set_acl_list,
2045 {'sw_if_index': sw_if_index,
2046 'count': len(acls),
2047 'n_input': n_input,
2048 'acls': acls},
2049 expected_retval=expected_retval)
2050
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002051 def acl_interface_set_etype_whitelist(self, sw_if_index,
2052 n_input, whitelist,
2053 expected_retval=0):
2054 return self.api(self.papi.acl_interface_set_etype_whitelist,
2055 {'sw_if_index': sw_if_index,
2056 'count': len(whitelist),
2057 'n_input': n_input,
2058 'whitelist': whitelist},
2059 expected_retval=expected_retval)
2060
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002061 def acl_interface_add_del(self,
2062 sw_if_index,
2063 acl_index,
2064 is_add=1):
2065 """ Add/Delete ACL to/from interface
2066
2067 :param sw_if_index:
2068 :param acl_index:
2069 :param is_add: (Default value = 1)
2070 """
2071
2072 return self.api(self.papi.acl_interface_add_del,
2073 {'is_add': is_add,
2074 'is_input': 1,
2075 'sw_if_index': sw_if_index,
2076 'acl_index': acl_index})
2077
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002078 def acl_dump(self, acl_index, expected_retval=0):
2079 return self.api(self.papi.acl_dump,
2080 {'acl_index': acl_index},
2081 expected_retval=expected_retval)
2082
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002083 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2084 expected_retval=0):
2085 return self.api(self.papi.acl_interface_list_dump,
2086 {'sw_if_index': sw_if_index},
2087 expected_retval=expected_retval)
2088
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002089 def macip_acl_add(self, rules, tag=""):
2090 """ Add MACIP acl
2091
2092 :param rules: list of rules for given acl
2093 :param tag: acl tag
2094 """
2095
2096 return self.api(self.papi.macip_acl_add,
2097 {'r': rules,
2098 'count': len(rules),
2099 'tag': tag})
2100
Pavel Kotucek932f7412017-09-07 14:44:52 +02002101 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2102 """ Add MACIP acl
2103
2104 :param rules: list of rules for given acl
2105 :param tag: acl tag
2106 """
2107
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002108 return self.api(self.papi.macip_acl_add_replace,
2109 {'acl_index': acl_index,
2110 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002111 'count': len(rules),
2112 'tag': tag})
2113
Pavel Kotucek932f7412017-09-07 14:44:52 +02002114 def macip_acl_interface_add_del(self,
2115 sw_if_index,
2116 acl_index,
2117 is_add=1):
2118 """ Add MACIP acl to interface
2119
2120 :param sw_if_index:
2121 :param acl_index:
2122 :param is_add: (Default value = 1)
2123 """
2124
2125 return self.api(self.papi.macip_acl_interface_add_del,
2126 {'is_add': is_add,
2127 'sw_if_index': sw_if_index,
2128 'acl_index': acl_index})
2129
Pavel Kotucek932f7412017-09-07 14:44:52 +02002130 def macip_acl_dump(self, acl_index=4294967295):
2131 """ Return MACIP acl dump
2132 """
2133
2134 return self.api(
2135 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002136
2137 def policer_add_del(self,
2138 name,
2139 cir,
2140 eir,
2141 cb,
2142 eb,
2143 is_add=1,
2144 rate_type=0,
2145 round_type=0,
2146 ptype=0,
2147 color_aware=0,
2148 conform_action_type=1,
2149 conform_dscp=0,
2150 exceed_action_type=0,
2151 exceed_dscp=0,
2152 violate_action_type=0,
2153 violate_dscp=0):
2154 return self.api(self.papi.policer_add_del,
2155 {'name': name,
2156 'cir': cir,
2157 'eir': eir,
2158 'cb': cb,
2159 'eb': eb,
2160 'is_add': is_add,
2161 'rate_type': rate_type,
2162 'round_type': round_type,
2163 'type': ptype,
2164 'color_aware': color_aware,
2165 'conform_action_type': conform_action_type,
2166 'conform_dscp': conform_dscp,
2167 'exceed_action_type': exceed_action_type,
2168 'exceed_dscp': exceed_dscp,
2169 'violate_action_type': violate_action_type,
2170 'violate_dscp': violate_dscp})
2171
2172 def ip_punt_police(self,
2173 policer_index,
2174 is_ip6=0,
2175 is_add=1):
2176 return self.api(self.papi.ip_punt_police,
2177 {'policer_index': policer_index,
2178 'is_add': is_add,
2179 'is_ip6': is_ip6})
2180
2181 def ip_punt_redirect(self,
2182 rx_sw_if_index,
2183 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002184 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002185 is_add=1):
2186 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002187 {'punt': {'rx_sw_if_index': rx_sw_if_index,
2188 'tx_sw_if_index': tx_sw_if_index,
2189 'nh': address},
2190 'is_add': is_add})
2191
2192 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
2193 return self.api(self.papi.ip_punt_redirect_dump,
2194 {'sw_if_index': sw_if_index,
2195 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002196
2197 def bier_table_add_del(self,
2198 bti,
2199 mpls_label,
2200 is_add=1):
2201 """ BIER Table add/del """
2202 return self.api(
2203 self.papi.bier_table_add_del,
2204 {'bt_tbl_id': {"bt_set": bti.set_id,
2205 "bt_sub_domain": bti.sub_domain_id,
2206 "bt_hdr_len_id": bti.hdr_len_id},
2207 'bt_label': mpls_label,
2208 'bt_is_add': is_add})
2209
2210 def bier_table_dump(self):
2211 return self.api(self.papi.bier_table_dump, {})
2212
2213 def bier_route_add_del(self,
2214 bti,
2215 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002216 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002217 is_add=1,
2218 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07002219 """ BIER Route add/del """
2220 return self.api(
2221 self.papi.bier_route_add_del,
2222 {'br_tbl_id': {"bt_set": bti.set_id,
2223 "bt_sub_domain": bti.sub_domain_id,
2224 "bt_hdr_len_id": bti.hdr_len_id},
2225 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002226 'br_n_paths': len(paths),
2227 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002228 'br_is_add': is_add,
2229 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002230
2231 def bier_route_dump(self, bti):
2232 return self.api(
2233 self.papi.bier_route_dump,
2234 {'br_tbl_id': {"bt_set": bti.set_id,
2235 "bt_sub_domain": bti.sub_domain_id,
2236 "bt_hdr_len_id": bti.hdr_len_id}})
2237
2238 def bier_imp_add(self,
2239 bti,
2240 src,
2241 ibytes,
2242 is_add=1):
2243 """ BIER Imposition Add """
2244 return self.api(
2245 self.papi.bier_imp_add,
2246 {'bi_tbl_id': {"bt_set": bti.set_id,
2247 "bt_sub_domain": bti.sub_domain_id,
2248 "bt_hdr_len_id": bti.hdr_len_id},
2249 'bi_src': src,
2250 'bi_n_bytes': len(ibytes),
2251 'bi_bytes': ibytes})
2252
2253 def bier_imp_del(self, bi_index):
2254 """ BIER Imposition del """
2255 return self.api(
2256 self.papi.bier_imp_del,
2257 {'bi_index': bi_index})
2258
2259 def bier_imp_dump(self):
2260 return self.api(self.papi.bier_imp_dump, {})
2261
2262 def bier_disp_table_add_del(self,
2263 bdti,
2264 is_add=1):
2265 """ BIER Disposition Table add/del """
2266 return self.api(
2267 self.papi.bier_disp_table_add_del,
2268 {'bdt_tbl_id': bdti,
2269 'bdt_is_add': is_add})
2270
2271 def bier_disp_table_dump(self):
2272 return self.api(self.papi.bier_disp_table_dump, {})
2273
2274 def bier_disp_entry_add_del(self,
2275 bdti,
2276 bp,
2277 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002278 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002279 next_hop,
2280 next_hop_tbl_id=0,
2281 next_hop_rpf_id=~0,
2282 next_hop_is_ip4=1,
2283 is_add=1):
2284 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002285 lstack = []
2286 while (len(lstack) < 16):
2287 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002288 return self.api(
2289 self.papi.bier_disp_entry_add_del,
2290 {'bde_tbl_id': bdti,
2291 'bde_bp': bp,
2292 'bde_payload_proto': payload_proto,
2293 'bde_n_paths': 1,
2294 'bde_paths': [{'next_hop': next_hop,
2295 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002296 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002297 'rpf_id': next_hop_rpf_id,
2298 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002299 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002300 'bde_is_add': is_add})
2301
2302 def bier_disp_entry_dump(self, bdti):
2303 return self.api(
2304 self.papi.bier_disp_entry_dump,
2305 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002306
Florin Coras3ea6ce22017-12-11 09:09:05 -08002307 def session_enable_disable(self, is_enabled):
2308 return self.api(
2309 self.papi.session_enable_disable,
2310 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002311
2312 def ipsec_spd_add_del(self, spd_id, is_add=1):
2313 """ SPD add/del - Wrapper to add or del ipsec SPD
2314 Sample CLI : 'ipsec spd add 1'
2315
2316 :param spd_id - SPD ID to be created in the vpp . mandatory
2317 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2318 optional
2319 :returns: reply from the API
2320 """
2321 return self.api(
2322 self.papi.ipsec_spd_add_del, {
2323 'spd_id': spd_id, 'is_add': is_add})
2324
Neale Ranns311124e2019-01-24 04:52:25 -08002325 def ipsec_spds_dump(self):
2326 return self.api(self.papi.ipsec_spds_dump, {})
2327
“mystarrocks”23f0c452017-12-11 07:11:51 -08002328 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2329 """ IPSEC interface SPD add/del - \
2330 Wrapper to associate/disassociate SPD to interface in VPP
2331 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2332
2333 :param spd_id - SPD ID to associate with the interface . mandatory
2334 :param sw_if_index - Interface Index which needs to ipsec \
2335 association mandatory
2336 :param is_add - add(1) or del(0) association with interface \
2337 (Default 1 - add) . optional
2338 :returns: reply from the API
2339 """
2340 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02002341 self.papi.ipsec_interface_add_del_spd,
2342 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002343
Neale Ranns311124e2019-01-24 04:52:25 -08002344 def ipsec_spd_interface_dump(self, spd_index=None):
2345 return self.api(self.papi.ipsec_spd_interface_dump,
2346 {'spd_index': spd_index if spd_index else 0,
2347 'spd_index_valid': 1 if spd_index else 0})
2348
Neale Ranns17dcec02019-01-09 21:22:20 -08002349 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002350 sad_id,
2351 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02002352 integrity_algorithm,
2353 integrity_key,
2354 crypto_algorithm,
2355 crypto_key,
2356 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002357 tunnel_src_address='',
2358 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08002359 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002360 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08002361 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08002362 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02002363 :param sad_id: security association ID
2364 :param spi: security param index of the SA in decimal
2365 :param integrity_algorithm:
2366 :param integrity_key:
2367 :param crypto_algorithm:
2368 :param crypto_key:
2369 :param protocol: AH(0) or ESP(1) protocol
2370 :param tunnel_src_address: tunnel mode outer src address
2371 :param tunnel_dst_address: tunnel mode outer dst address
2372 :param is_add:
2373 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08002374 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
2375 crypto and ipsec algorithms
2376 """
2377 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002378 self.papi.ipsec_sad_entry_add_del,
2379 {
2380 'is_add': is_add,
2381 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002382 {
2383 'sad_id': sad_id,
2384 'spi': spi,
2385 'tunnel_src': tunnel_src_address,
2386 'tunnel_dst': tunnel_dst_address,
2387 'protocol': protocol,
2388 'integrity_algorithm': integrity_algorithm,
2389 'integrity_key': {
2390 'length': len(integrity_key),
2391 'data': integrity_key,
2392 },
2393 'crypto_algorithm': crypto_algorithm,
2394 'crypto_key': {
2395 'length': len(crypto_key),
2396 'data': crypto_key,
2397 },
2398 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002399 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01002400 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002401 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08002402
Neale Ranns311124e2019-01-24 04:52:25 -08002403 def ipsec_sa_dump(self, sa_id=None):
2404 return self.api(self.papi.ipsec_sa_dump,
2405 {'sa_id': sa_id if sa_id else 0xffffffff})
2406
Neale Ranns17dcec02019-01-09 21:22:20 -08002407 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002408 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02002409 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002410 local_address_start,
2411 local_address_stop,
2412 remote_address_start,
2413 remote_address_stop,
2414 local_port_start=0,
2415 local_port_stop=65535,
2416 remote_port_start=0,
2417 remote_port_stop=65535,
2418 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002419 policy=0,
2420 priority=100,
2421 is_outbound=1,
2422 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02002423 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002424 is_ip_any=0):
2425 """ IPSEC policy SPD add/del -
2426 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02002427 :param spd_id: SPD ID for the policy
2428 :param local_address_start: local-ip-range start address
2429 :param local_address_stop : local-ip-range stop address
2430 :param remote_address_start: remote-ip-range start address
2431 :param remote_address_stop : remote-ip-range stop address
2432 :param local_port_start: (Default value = 0)
2433 :param local_port_stop: (Default value = 65535)
2434 :param remote_port_start: (Default value = 0)
2435 :param remote_port_stop: (Default value = 65535)
2436 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
2437 :param sa_id: Security Association ID for mapping it to SPD
2438 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
2439 (Default value = 0)
2440 :param priority: value for the spd action (Default value = 100)
2441 :param is_outbound: flag for inbound(0) or outbound(1)
2442 (Default value = 1)
2443 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08002444 """
2445 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002446 self.papi.ipsec_spd_entry_add_del,
2447 {
2448 'is_add': is_add,
2449 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002450 {
2451 'spd_id': spd_id,
2452 'sa_id': sa_id,
2453 'local_address_start': local_address_start,
2454 'local_address_stop': local_address_stop,
2455 'remote_address_start': remote_address_start,
2456 'remote_address_stop': remote_address_stop,
2457 'local_port_start': local_port_start,
2458 'local_port_stop': local_port_stop,
2459 'remote_port_start': remote_port_start,
2460 'remote_port_stop': remote_port_stop,
2461 'protocol': protocol,
2462 'policy': policy,
2463 'priority': priority,
2464 'is_outbound': is_outbound,
2465 'is_ip_any': is_ip_any
2466 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002467 })
Florin Corasb795bd02017-12-14 11:30:48 -08002468
Neale Ranns311124e2019-01-24 04:52:25 -08002469 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
2470 return self.api(self.papi.ipsec_spd_dump,
2471 {'spd_id': spd_id,
2472 'sa_id': sa_id})
2473
Klement Sekera31da2e32018-06-24 22:49:55 +02002474 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
2475 remote_spi, crypto_alg, local_crypto_key,
2476 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002477 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02002478 anti_replay=1, renumber=0, show_instance=0):
2479 return self.api(
2480 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002481 {
2482 'local_ip': local_ip,
2483 'remote_ip': remote_ip,
2484 'local_spi': local_spi,
2485 'remote_spi': remote_spi,
2486 'crypto_alg': crypto_alg,
2487 'local_crypto_key_len': len(local_crypto_key),
2488 'local_crypto_key': local_crypto_key,
2489 'remote_crypto_key_len': len(remote_crypto_key),
2490 'remote_crypto_key': remote_crypto_key,
2491 'integ_alg': integ_alg,
2492 'local_integ_key_len': len(local_integ_key),
2493 'local_integ_key': local_integ_key,
2494 'remote_integ_key_len': len(remote_integ_key),
2495 'remote_integ_key': remote_integ_key,
2496 'is_add': is_add,
2497 'esn': esn,
2498 'anti_replay': anti_replay,
2499 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002500 'show_instance': show_instance,
2501 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002502 })
Klement Sekera31da2e32018-06-24 22:49:55 +02002503
Neale Rannsf05e7322019-03-29 20:23:58 +00002504 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
2505 sa_out, sa_in, is_add=1):
2506 return self.api(self.papi.ipsec_gre_tunnel_add_del,
2507 {
2508 'is_add': is_add,
2509 'tunnel': {
2510 'src': local_ip,
2511 'dst': remote_ip,
2512 'local_sa_id': sa_out,
2513 'remote_sa_id': sa_in
2514 }
2515 })
2516
Klement Sekerab4d30532018-11-08 13:00:02 +01002517 def ipsec_select_backend(self, protocol, index):
2518 return self.api(self.papi.ipsec_select_backend,
2519 {'protocol': protocol, 'index': index})
2520
2521 def ipsec_backend_dump(self):
2522 return self.api(self.papi.ipsec_backend_dump, {})
2523
Ole Troane1ade682019-03-04 23:55:43 +01002524 def app_namespace_add_del(self,
2525 namespace_id,
2526 ip4_fib_id=0,
2527 ip6_fib_id=0,
2528 sw_if_index=0xFFFFFFFF,
2529 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08002530 return self.api(
2531 self.papi.app_namespace_add_del,
2532 {'secret': secret,
2533 'sw_if_index': sw_if_index,
2534 'ip4_fib_id': ip4_fib_id,
2535 'ip6_fib_id': ip6_fib_id,
2536 'namespace_id': namespace_id,
2537 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02002538
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002539 def punt_socket_register(self, port, pathname, protocol=0x11,
2540 header_version=1, is_ip4=1):
2541 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02002542 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002543 {'header_version': header_version,
2544 'punt': {'ipv': is_ip4,
2545 'l4_protocol': protocol,
2546 'l4_port': port},
2547 'pathname': pathname})
2548
2549 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
2550 """ Unregister punt socket """
2551 return self.api(self.papi.punt_socket_deregister,
2552 {'punt': {'ipv': is_ip4,
2553 'l4_protocol': protocol,
2554 'l4_port': port}})
2555
2556 def punt_socket_dump(self, is_ip6=1):
2557 """ Dump punt socket"""
2558 return self.api(self.papi.punt_socket_dump,
2559 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02002560
Neale Ranns4ba67722019-02-28 11:11:39 +00002561 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002562 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07002563 """ GBP endpoint Add """
2564 return self.api(self.papi.gbp_endpoint_add,
2565 {'endpoint': {
2566 'sw_if_index': sw_if_index,
2567 'ips': ips,
2568 'n_ips': len(ips),
2569 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00002570 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002571 'flags': flags,
2572 'tun': {
2573 'src': tun_src,
2574 'dst': tun_dst,
2575 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002576
2577 def gbp_endpoint_del(self, handle):
2578 """ GBP endpoint Del """
2579 return self.api(self.papi.gbp_endpoint_del,
2580 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002581
2582 def gbp_endpoint_dump(self):
2583 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002584 return self.api(self.papi.gbp_endpoint_dump,
2585 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002586
Neale Ranns4ba67722019-02-28 11:11:39 +00002587 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002588 rd, uplink_sw_if_index,
2589 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002590 """ GBP endpoint group Add """
2591 return self.api(self.papi.gbp_endpoint_group_add,
2592 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002593 {
2594 'uplink_sw_if_index': uplink_sw_if_index,
2595 'bd_id': bd,
2596 'rd_id': rd,
2597 'vnid': vnid,
2598 'sclass': sclass,
2599 'retention': retention
2600 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002601
Neale Ranns4ba67722019-02-28 11:11:39 +00002602 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002603 """ GBP endpoint group Del """
2604 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002605 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002606
Neale Rannsc29c0af2018-11-07 04:21:12 -08002607 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002608 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002609 uu_fwd_sw_if_index,
2610 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002611 """ GBP bridge-domain Add """
2612 return self.api(self.papi.gbp_bridge_domain_add,
2613 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002614 {
2615 'flags': flags,
2616 'bvi_sw_if_index': bvi_sw_if_index,
2617 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2618 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2619 'bd_id': bd_id
2620 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002621
2622 def gbp_bridge_domain_del(self, bd_id):
2623 """ GBP bridge-domain Del """
2624 return self.api(self.papi.gbp_bridge_domain_del,
2625 {'bd_id': bd_id})
2626
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002627 def gbp_route_domain_add(self, rd_id,
2628 ip4_table_id,
2629 ip6_table_id,
2630 ip4_uu_sw_if_index,
2631 ip6_uu_sw_if_index):
2632 """ GBP route-domain Add """
2633 return self.api(self.papi.gbp_route_domain_add,
2634 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002635 {
2636 'ip4_table_id': ip4_table_id,
2637 'ip6_table_id': ip6_table_id,
2638 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2639 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2640 'rd_id': rd_id
2641 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002642
2643 def gbp_route_domain_del(self, rd_id):
2644 """ GBP route-domain Del """
2645 return self.api(self.papi.gbp_route_domain_del,
2646 {'rd_id': rd_id})
2647
Neale Ranns4ba67722019-02-28 11:11:39 +00002648 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002649 """ GBP recirc Add/Del """
2650 return self.api(self.papi.gbp_recirc_add_del,
2651 {'is_add': is_add,
2652 'recirc': {
2653 'is_ext': is_ext,
2654 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002655 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002656
2657 def gbp_recirc_dump(self):
2658 """ GBP recirc Dump """
2659 return self.api(self.papi.gbp_recirc_dump, {})
2660
Neale Rannsb6a47952018-11-21 05:44:35 -08002661 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2662 """ GBP recirc Add/Del """
2663 return self.api(self.papi.gbp_ext_itf_add_del,
2664 {'is_add': is_add,
2665 'ext_itf': {
2666 'sw_if_index': sw_if_index,
2667 'bd_id': bd_id,
2668 'rd_id': rd_id}})
2669
2670 def gbp_ext_itf_dump(self):
2671 """ GBP recirc Dump """
2672 return self.api(self.papi.gbp_ext_itf_dump, {})
2673
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002674 def gbp_subnet_add_del(self, is_add, rd_id,
2675 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002676 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002677 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002678 """ GBP Subnet Add/Del """
2679 return self.api(self.papi.gbp_subnet_add_del,
2680 {'is_add': is_add,
2681 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002682 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002683 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002684 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002685 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002686 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002687
2688 def gbp_subnet_dump(self):
2689 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002690 return self.api(self.papi.gbp_subnet_dump,
2691 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002692
Neale Ranns4ba67722019-02-28 11:11:39 +00002693 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002694 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002695 """ GBP contract Add/Del """
2696 return self.api(self.papi.gbp_contract_add_del,
2697 {'is_add': is_add,
2698 'contract': {
2699 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002700 'sclass': sclass,
2701 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002702 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002703 'rules': rules,
2704 'n_ether_types': len(allowed_ethertypes),
2705 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002706
2707 def gbp_contract_dump(self):
2708 """ GBP contract Dump """
2709 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002710
Neale Ranns8da9fc62019-03-04 14:08:11 -08002711 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002712 """ GBP VXLAN tunnel add """
2713 return self.api(self.papi.gbp_vxlan_tunnel_add,
2714 {
2715 'tunnel': {
2716 'vni': vni,
2717 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002718 'bd_rd_id': bd_rd_id,
2719 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002720 }
2721 })
2722
2723 def gbp_vxlan_tunnel_del(self, vni):
2724 """ GBP VXLAN tunnel del """
2725 return self.api(self.papi.gbp_vxlan_tunnel_del,
2726 {
2727 'vni': vni,
2728 })
2729
2730 def gbp_vxlan_tunnel_dump(self):
2731 """ GBP VXLAN tunnel add/del """
2732 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2733
Neale Ranns039cbfe2018-02-27 03:45:38 -08002734 def qos_egress_map_update(self, id, outputs):
2735 """ QOS egress map update """
2736 return self.api(self.papi.qos_egress_map_update,
2737 {'map_id': id,
2738 'rows': outputs})
2739
2740 def qos_egress_map_delete(self, id):
2741 """ QOS egress map delete """
2742 return self.api(self.papi.qos_egress_map_delete,
2743 {'map_id': id})
2744
2745 def qos_mark_enable_disable(self, sw_if_index,
2746 output_source,
2747 map_id,
2748 enable):
2749 """ QOS Mark Enable/Disable """
2750 return self.api(self.papi.qos_mark_enable_disable,
2751 {'map_id': map_id,
2752 'sw_if_index': sw_if_index,
2753 'output_source': output_source,
2754 'enable': enable})
2755
Neale Ranns947ea622018-06-07 23:48:20 -07002756 def igmp_enable_disable(self, sw_if_index, enable, host):
2757 """ Enable/disable IGMP on a given interface """
2758 return self.api(self.papi.igmp_enable_disable,
2759 {'enable': enable,
2760 'mode': host,
2761 'sw_if_index': sw_if_index})
2762
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002763 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2764 """ Add/del IGMP proxy device """
2765 return self.api(self.papi.igmp_proxy_device_add_del,
2766 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2767 'add': add})
2768
2769 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2770 """ Add/del interface to/from IGMP proxy device """
2771 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2772 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2773 'add': add})
2774
Neale Ranns947ea622018-06-07 23:48:20 -07002775 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002776 """ Listen for new (S,G) on specified interface
2777
2778 :param enable: add/del
2779 :param sw_if_index: interface sw index
2780 :param saddr: source ip4 addr
2781 :param gaddr: group ip4 addr
2782 """
2783 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002784 {
2785 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002786 {
2787 'filter': filter,
2788 'sw_if_index': sw_if_index,
2789 'n_srcs': len(saddrs),
2790 'saddrs': saddrs,
2791 'gaddr': gaddr
2792 }
Neale Ranns947ea622018-06-07 23:48:20 -07002793 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002794
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002795 def igmp_clear_interface(self, sw_if_index):
2796 """ Remove all (S,G)s from specified interface
2797 doesn't send IGMP report!
2798 """
2799 return self.api(
2800 self.papi.igmp_clear_interface, {
2801 'sw_if_index': sw_if_index})
2802
2803 def want_igmp_events(self, enable=1):
2804 return self.api(self.papi.want_igmp_events, {'enable': enable,
2805 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002806
2807 def bond_create(
2808 self,
2809 mode,
2810 lb,
2811 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002812 mac_address='',
2813 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002814 """
2815 :param mode: mode
2816 :param lb: load balance
2817 :param use_custom_mac: use custom mac
2818 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002819 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002820 """
2821 return self.api(
2822 self.papi.bond_create,
2823 {'mode': mode,
2824 'lb': lb,
2825 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002826 'mac_address': mac_address,
2827 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002828 })
2829
Neale Ranns17ff3c12018-07-04 10:24:24 -07002830 def pipe_delete(self, parent_sw_if_index):
2831 return self.api(self.papi.pipe_delete,
2832 {'parent_sw_if_index': parent_sw_if_index})
2833
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002834 def memif_create(
2835 self,
2836 role,
2837 mode,
2838 rx_queues=None,
2839 tx_queues=None,
2840 _id=None,
2841 socket_id=None,
2842 secret=None,
2843 ring_size=None,
2844 buffer_size=None,
2845 hw_addr=None):
2846 return self.api(self.papi.memif_create,
2847 {'role': role,
2848 'mode': mode,
2849 'rx_queues': rx_queues,
2850 'tx_queues': tx_queues,
2851 'id': _id,
2852 'socket_id': socket_id,
2853 'secret': secret,
2854 'ring_size': ring_size,
2855 'buffer_size': buffer_size,
2856 'hw_addr': hw_addr})
2857
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002858 def svs_table_add_del(self, af, table_id, is_add=1):
2859 return self.api(self.papi.svs_table_add_del,
2860 {
2861 'table_id': table_id,
2862 'is_add': is_add,
2863 'af': af,
2864 })
2865
2866 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2867 return self.api(self.papi.svs_route_add_del,
2868 {
2869 'table_id': table_id,
2870 'source_table_id': src_table_id,
2871 'prefix': prefix,
2872 'is_add': is_add,
2873 })
2874
2875 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2876 return self.api(self.papi.svs_enable_disable,
2877 {
2878 'af': af,
2879 'table_id': table_id,
2880 'sw_if_index': sw_if_index,
2881 'is_enable': is_enable,
2882 })