blob: 6b3358b2b232d5120945d43aeff5e667e2c99608 [file] [log] [blame]
Ole Troan9a475372019-03-05 16:58:24 +01001# NB NB NB NB NB NB NB NB NB NB NB
2#
3# NOTE: The API binary wrappers in this file are in the process of being
4# deprecated. DO NOT ADD NEW WRAPPERS HERE. Call the functions using
5# named arguments directly instead.
6#
7
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02009import time
Klement Sekerae4504c62016-12-08 10:16:41 +010010from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +020011
Ole Troanf159f582019-02-28 20:20:47 +010012from six import moves, iteritems
Paul Vinciguerra84679192019-01-13 11:33:52 -080013from vpp_papi import VPP, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080014from hook import Hook
Paul Vinciguerrab5f15bd2019-03-17 08:42:58 -070015from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
Klement Sekeraf62ae122016-10-11 11:47:09 +020016
Klement Sekera0e3c0de2016-09-29 14:43:44 +020017
Neale Ranns039cbfe2018-02-27 03:45:38 -080018class QOS_SOURCE:
19 EXT = 0
20 VLAN = 1
21 MPLS = 2
22 IP = 3
23
24
Matus Fabianb4515b42018-11-19 04:25:32 -080025class SYSLOG_SEVERITY:
26 EMERG = 0
27 ALERT = 1
28 CRIT = 2
29 ERR = 3
30 WARN = 4
31 NOTICE = 5
32 INFO = 6
33 DBG = 7
34
Ole Troan9a475372019-03-05 16:58:24 +010035
Ole Troanf159f582019-02-28 20:20:47 +010036#
37# Dictionary keyed on message name to override default values for
38# named parameters
39#
Ole Troan9a475372019-03-05 16:58:24 +010040defaultmapping = {
41 'map_add_domain': {'mtu': 1280},
42 'syslog_set_sender': {'collector_port': 514,
43 'max_msg_size': 480},
44 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
45 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
46 'app_namespace_add_del': {'sw_if_index': 4294967295, },
47 'bd_ip_mac_add_del': {'is_add': 1, },
48 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
49 'is_add': 1, },
50 'bier_disp_table_add_del': {'is_add': 1, },
51 'bier_imp_add': {'is_add': 1, },
52 'bier_route_add_del': {'is_add': 1, },
53 'bier_table_add_del': {'is_add': 1, },
54 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
55 'learn': 1, 'is_add': 1, },
56 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
57 'nbuckets': 2, 'memory_size': 2097152,
58 'next_table_index': 4294967295,
59 'miss_next_index': 4294967295, },
60 'dhcp6_client_enable_disable': {'enable': 1, },
61 'dhcp6_clients_enable_disable': {'enable': 1, },
62 'dhcp6_pd_client_enable_disable': {'enable': 1, },
63 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
64 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
65 'dhcp_proxy_config': {'is_add': 1, },
66 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
67 'dslite_add_del_pool_addr_range': {'is_add': 1, },
68 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
69 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
70 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000071 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010072 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
73 'decap_next_index': 4294967295, },
74 'input_acl_set_interface': {'ip4_table_index': 4294967295,
75 'ip6_table_index': 4294967295,
76 'l2_table_index': 4294967295, },
77 'ip6_add_del_address_using_prefix': {'is_add': 1, },
78 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
79 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
80 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
81 'next_hop_id': 4294967295,
82 'classify_table_index': 4294967295, 'is_add': 1, },
83 'ip_mroute_add_del': {'is_add': 1, },
84 'ip_neighbor_add_del': {'is_add': 1, },
85 'ip_punt_police': {'is_add': 1, },
86 'ip_punt_redirect': {'is_add': 1, },
87 'ip_table_add_del': {'is_add': 1, },
88 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
89 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
90 'ipsec_interface_add_del_spd': {'is_add': 1, },
91 'ipsec_sad_entry_add_del': {'is_add': 1, },
92 'ipsec_spd_add_del': {'is_add': 1, },
93 'ipsec_spd_dump': {'sa_id': 4294967295, },
94 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
95 'remote_port_stop': 65535, 'priority': 100,
96 'is_outbound': 1,
97 'is_add': 1, },
98 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
99 'l2_emulation': {'enable': 1, },
100 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700101 'lb_conf': {'sticky_buckets_per_core': 4294967295,
102 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +0100103 'lisp_add_del_adjacency': {'is_add': 1, },
104 'lisp_add_del_local_eid': {'is_add': 1, },
105 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
106 'lisp_add_del_locator_set': {'is_add': 1, },
107 'lisp_add_del_remote_mapping': {'is_add': 1, },
108 'macip_acl_add_replace': {'acl_index': 4294967295, },
109 'macip_acl_dump': {'acl_index': 4294967295, },
110 'macip_acl_interface_add_del': {'is_add': 1, },
111 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +0100112 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
113 'mr_next_hop_weight': 1,
114 'mr_next_hop_via_label': 1048576,
115 'mr_is_add': 1,
116 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100117 'mpls_table_add_del': {'is_add': 1, },
118 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
119 'next_hop_weight': 1,
120 'next_hop_via_label': 1048576,
121 'is_add': 1, },
122 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
123 'nat44_add_del_address_range': {'is_add': 1, 'vrf_id': 4294967295, },
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800124 'nat44_add_del_identity_mapping': {'ip': b'0', 'sw_if_index': 4294967295,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200125 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100126 '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,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200129 'is_add': 1, },
130 'nat44_interface_add_del_feature': {'is_add': 1, },
131 'nat44_interface_add_del_output_feature': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100132 'nat44_lb_static_mapping_add_del_local': {'is_add': 1, },
Filip Vargadd1e3e72019-04-15 18:52:43 +0200133 'nat64_add_del_interface': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100134 'nat64_add_del_interface_addr': {'is_add': 1, },
135 'nat64_add_del_pool_addr_range': {'vrf_id': 4294967295, 'is_add': 1, },
136 'nat64_add_del_prefix': {'is_add': 1, },
137 'nat64_add_del_static_bib': {'is_add': 1, },
138 'nat64_bib_dump': {'protocol': 255, },
139 'nat64_st_dump': {'protocol': 255, },
Filip Vargadd1e3e72019-04-15 18:52:43 +0200140 'nat66_add_del_interface': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100141 'nat66_add_del_static_mapping': {'is_add': 1, },
142 'nat_det_add_del_map': {'is_add': 1, },
143 'nat_ha_resync': {'want_resync_event': 1, },
144 'nat_ha_set_failover': {'refresh': 10, },
145 'nat_ha_set_listener': {'path_mtu': 512, },
146 'nat_ipfix_enable_disable': {'domain_id': 1, 'src_port': 4739,
147 'enable': 1, },
148 'nat_set_mss_clamping': {'mss_value': 1500, },
149 'nat_set_reass': {'timeout': 2, 'max_reass': 1024, 'max_frag': 5, },
150 'nat_set_timeouts': {'udp': 300, 'tcp_established': 7440,
151 'tcp_transitory': 240, 'icmp': 60, },
152 'output_acl_set_interface': {'ip4_table_index': 4294967295,
153 'ip6_table_index': 4294967295,
154 'l2_table_index': 4294967295, },
155 'pppoe_add_del_session': {'is_add': 1, },
156 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
157 'proxy_arp_add_del': {'is_add': 1, },
158 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
159 'punt_socket_register': {'protocol': 17, 'header_version': 1,
160 'is_ip4': 1, },
161 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, },
162 'punt_socket_dump': {'is_ip6': 1, },
163 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
164 'proto': 1, },
165 'set_ipfix_exporter': {'collector_port': 4739, },
166 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
167 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
168 'svs_enable_disable': {'is_enable': 1, },
169 'svs_route_add_del': {'is_add': 1, },
170 'svs_table_add_del': {'is_add': 1, },
171 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700172 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100173 '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
Ole Troan4ff09ae2019-04-15 11:27:22 +0200228 use_socket = False
229 try:
230 if os.environ['SOCKET'] == '1':
231 use_socket = True
232 except:
233 pass
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800234 self.vpp = VPP(logger=test_class.logger,
Ole Troan4ff09ae2019-04-15 11:27:22 +0200235 read_timeout=read_timeout,
236 use_socket=use_socket,
237 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100238 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200239
Klement Sekerae0545ef2017-01-25 08:00:40 +0100240 def __enter__(self):
241 return self
242
Klement Sekera7d6afb32018-11-08 11:52:04 +0100243 def assert_negative_api_retval(self):
244 """ Expect API failure - used with with, e.g.:
245 with self.vapi.assert_negative_api_retval():
246 self.vapi.<api call expected to fail>
247 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100248 self._expect_stack.append(self._expect_api_retval)
249 self._expect_api_retval = self._negative
250 return self
251
Klement Sekera7d6afb32018-11-08 11:52:04 +0100252 def assert_zero_api_retval(self):
253 """ Expect API success - used with with, e.g.:
254 with self.vapi.assert_negative_api_retval():
255 self.vapi.<api call expected to succeed>
256
257 note: this is useful only inside another with block
258 as success is the default expected value
259 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100260 self._expect_stack.append(self._expect_api_retval)
261 self._expect_api_retval = self._zero
262 return self
263
264 def __exit__(self, exc_type, exc_value, traceback):
265 self._expect_api_retval = self._expect_stack.pop()
266
Klement Sekeraf62ae122016-10-11 11:47:09 +0200267 def register_hook(self, hook):
268 """Replace hook registration with new hook
269
270 :param hook:
271
272 """
273 self.hook = hook
274
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200275 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100276 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200277 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100278 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200279 return e
280
281 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100282 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100283 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100284 self.test_class.logger.debug("Expecting event '%s' within %ss",
285 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300286 else:
287 self.test_class.logger.debug("Expecting event within %ss",
288 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100289 if self._events:
290 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200291 limit = time.time() + timeout
292 while time.time() < limit:
293 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100294 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200295 if name and type(e).__name__ != name:
296 raise Exception(
297 "Unexpected event received: %s, expected: %s" %
298 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100299 self.test_class.logger.debug("Returning event %s:%s" %
300 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200301 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700302 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200303 raise Exception("Event did not occur within timeout")
304
305 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100306 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200307 # FIXME use the name instead of relying on type(e).__name__ ?
308 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100309 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200310 self._events.append(event)
311
Ole Troanf159f582019-02-28 20:20:47 +0100312 def factory(self, name, apifn):
313 def f(*a, **ka):
314 fields = apifn._func.msg.fields
315
316 # add positional and kw arguments
317 d = ka
318 for i, o in enumerate(fields[3:]):
319 try:
320 d[o] = a[i]
321 except:
322 break
323
324 # Default override
325 if name in defaultmapping:
326 for k, v in iteritems(defaultmapping[name]):
327 if k in d:
328 continue
329 d[k] = v
330 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100331
Ole Troanf159f582019-02-28 20:20:47 +0100332 return f
333
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800334 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100335 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800336 method = super(VppPapiProvider, self).__getattribute__(name)
337 except AttributeError:
338 method = self.factory(name, getattr(self.papi, name))
339 # lazily load the method so we don't need to call factory
340 # again for this name.
341 setattr(self, name, method)
342 return method
Ole Troanf159f582019-02-28 20:20:47 +0100343
Klement Sekeraf62ae122016-10-11 11:47:09 +0200344 def connect(self):
345 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100346 self.vpp.connect(self.name, self.shm_prefix)
347 self.papi = self.vpp.api
348 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200349
350 def disconnect(self):
351 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100352 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200353
354 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100355 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200356 Call the appropriate hooks before and after the API call
357
358 :param api_fn: API function to call
359 :param api_args: tuple of API function arguments
360 :param expected_retval: Expected return value (Default value = 0)
361 :returns: reply from the API
362
363 """
364 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100365 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100366 if self._expect_api_retval == self._negative:
367 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100368 msg = "API call passed unexpectedly: expected negative " \
369 "return value instead of %d in %s" % \
370 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100371 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100372 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100373 elif self._expect_api_retval == self._zero:
374 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100375 msg = "API call failed, expected %d return value instead " \
376 "of %d in %s" % (expected_retval, reply.retval,
377 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100378 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100379 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100380 else:
381 raise Exception("Internal error, unexpected value for "
382 "self._expect_api_retval %s" %
383 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200384 self.hook.after_api(api_fn.__name__, api_args)
385 return reply
386
387 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100388 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200389
390 :param cli: CLI to execute
391 :returns: CLI output
392
393 """
394 self.hook.before_cli(cli)
395 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100396 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200397 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200398 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100399 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200400
Jan49c0fca2016-10-26 15:44:27 +0200401 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100402 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200403
404 :param cli: CLI to execute
405 :returns: CLI output
406 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600407 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200408
Neale Ranns37029302018-08-10 05:30:06 -0700409 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300410 return self.api(self.papi.want_ip4_arp_events,
411 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700412 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300413 'pid': os.getpid(), })
414
Neale Ranns37029302018-08-10 05:30:06 -0700415 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300416 return self.api(self.papi.want_ip6_nd_events,
417 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700418 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300419 'pid': os.getpid(), })
420
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100421 def want_ip6_ra_events(self, enable_disable=1):
422 return self.api(self.papi.want_ip6_ra_events,
423 {'enable_disable': enable_disable,
424 'pid': os.getpid(), })
425
426 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
427 mrc=0, mrd=0):
428 return self.api(self.papi.ip6nd_send_router_solicitation,
429 {'irt': irt,
430 'mrt': mrt,
431 'mrc': mrc,
432 'mrd': mrd,
433 'sw_if_index': sw_if_index})
434
Juraj Slobodab3f90502018-10-04 15:15:16 +0200435 def want_interface_events(self, enable_disable=1):
436 return self.api(self.papi.want_interface_events,
437 {'enable_disable': enable_disable,
438 'pid': os.getpid(), })
439
Ole Troane1ade682019-03-04 23:55:43 +0100440 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
441 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300442 return self.api(self.papi.want_l2_macs_events,
443 {'enable_disable': enable_disable,
444 'scan_delay': scan_delay,
445 'max_macs_in_event': max_macs_in_event,
446 'learn_limit': learn_limit,
447 'pid': os.getpid(), })
448
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200449 def want_dhcp6_reply_events(self, enable_disable=1):
450 return self.api(self.papi.want_dhcp6_reply_events,
451 {'enable_disable': enable_disable,
452 'pid': os.getpid()})
453
Juraj Sloboda81119e82018-05-25 14:02:20 +0200454 def want_dhcp6_pd_reply_events(self, enable_disable=1):
455 return self.api(self.papi.want_dhcp6_pd_reply_events,
456 {'enable_disable': enable_disable,
457 'pid': os.getpid()})
458
Juraj Sloboda81119e82018-05-25 14:02:20 +0200459 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
460 prefixes, server_index=0xFFFFFFFF,
461 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
462 ):
463 return self.api(self.papi.dhcp6_pd_send_client_message,
464 {'sw_if_index': sw_if_index,
465 'server_index': server_index,
466 'irt': irt,
467 'mrt': mrt,
468 'mrc': mrc,
469 'mrd': mrd,
470 'stop': stop,
471 'msg_type': msg_type,
472 'T1': T1,
473 'T2': T2,
474 'n_prefixes': len(prefixes),
475 'prefixes': prefixes})
476
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200477 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
478 enable=1):
479 return self.api(self.papi.dhcp6_client_enable_disable,
480 {'sw_if_index': sw_if_index,
481 'enable': enable})
482
Juraj Sloboda81119e82018-05-25 14:02:20 +0200483 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
484 enable=1):
485 return self.api(self.papi.dhcp6_pd_client_enable_disable,
486 {'sw_if_index': sw_if_index,
487 'prefix_group': prefix_group,
488 'enable': enable})
489
490 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
491 prefix_length, prefix_group,
492 is_add=1):
493 return self.api(self.papi.ip6_add_del_address_using_prefix,
494 {'sw_if_index': sw_if_index,
495 'prefix_group': prefix_group,
496 'address': address,
497 'prefix_length': prefix_length,
498 'is_add': is_add})
499
Neale Rannsc819fc62018-02-16 02:44:05 -0800500 def sw_interface_set_mac_address(self, sw_if_index, mac):
501 return self.api(self.papi.sw_interface_set_mac_address,
502 {'sw_if_index': sw_if_index,
503 'mac_address': mac})
504
Ole Troane1ade682019-03-04 23:55:43 +0100505 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200506 """Create p2p ethernet subinterface
507
508 :param sw_if_index: main (parent) interface
509 :param remote_mac: client (remote) mac address
510
511 """
512 return self.api(
513 self.papi.p2p_ethernet_add,
514 {'parent_if_index': sw_if_index,
515 'remote_mac': remote_mac,
516 'subif_id': subif_id})
517
Ole Troane1ade682019-03-04 23:55:43 +0100518 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200519 """Delete p2p ethernet subinterface
520
521 :param sw_if_index: main (parent) interface
522 :param remote_mac: client (remote) mac address
523
524 """
525 return self.api(
526 self.papi.p2p_ethernet_del,
527 {'parent_if_index': sw_if_index,
528 'remote_mac': remote_mac})
529
Klement Sekeraf62ae122016-10-11 11:47:09 +0200530 def create_vlan_subif(self, sw_if_index, vlan):
531 """
532
533 :param vlan:
534 :param sw_if_index:
535
536 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100537 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200538 {'sw_if_index': sw_if_index,
539 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200540
Matej Klotton0178d522016-11-04 11:11:44 +0100541 def create_loopback(self, mac=''):
542 """
543
544 :param mac: (Optional)
545 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100546 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200547 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100548
Matej Klotton0178d522016-11-04 11:11:44 +0100549 def ip_neighbor_add_del(self,
550 sw_if_index,
551 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700552 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100553 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700554 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100555 """ Add neighbor MAC to IPv4 or IPv6 address.
556
557 :param sw_if_index:
558 :param mac_address:
559 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100560 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700561 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100562 """
Matej Klotton0178d522016-11-04 11:11:44 +0100563 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100564 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700565 {
566 'is_add': is_add,
567 'neighbor': {
568 'sw_if_index': sw_if_index,
569 'flags': flags,
570 'mac_address': mac_address,
571 'ip_address': ip_address
572 }
573 }
Matej Klotton0178d522016-11-04 11:11:44 +0100574 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100575
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800576 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700577 low,
578 hi,
579 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800580 is_add=1):
581 """ Config Proxy Arp Range.
582
583 :param low_address: Start address in the rnage to Proxy for
584 :param hi_address: End address in the rnage to Proxy for
585 :param vrf_id: The VRF/table in which to proxy
586 """
587
588 return self.api(
589 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700590 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100591 {
592 'table_id': table_id,
593 'low': low,
594 'hi': hi,
595 },
596 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800597
598 def proxy_arp_intfc_enable_disable(self,
599 sw_if_index,
600 is_enable=1):
601 """ Enable/Disable an interface for proxy ARP requests
602
603 :param sw_if_index: Interface
604 :param enable_disable: Enable/Disable
605 """
606
607 return self.api(
608 self.papi.proxy_arp_intfc_enable_disable,
609 {'sw_if_index': sw_if_index,
610 'enable_disable': is_enable
611 }
612 )
613
Neale Ranns5a8844b2019-04-16 07:15:35 +0000614 def gre_tunnel_add_del(self,
615 src,
616 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000617 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500618 tunnel_type=0,
619 instance=0xFFFFFFFF,
620 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000621 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000622 """ Add a GRE tunnel
623
624 :param src_address:
625 :param dst_address:
626 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500627 :param tunnel_type: (Default value = 0)
628 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700629 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000630 :param is_add: (Default value = 1)
631 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000632 """
633
634 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000635 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200636 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000637 'tunnel':
638 {
639 'type': tunnel_type,
640 'instance': instance,
641 'src': src,
642 'dst': dst,
643 'outer_fib_id': outer_fib_id,
644 'session_id': session_id}
645 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000646 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000647
Neale Rannsd0df49f2018-08-08 01:06:40 -0700648 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700649 src_ip,
650 dst_ip,
651 src_port,
652 dst_port,
653 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800654 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800655 :param src_ip:
656 :param dst_ip:
657 :param src_port:
658 :param dst_port:
659 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800660 """
661
662 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700663 self.papi.udp_encap_add,
664 {
665 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700666 'src_ip': src_ip,
667 'dst_ip': dst_ip,
668 'src_port': src_port,
669 'dst_port': dst_port,
670 'table_id': table_id
671 }
672 })
673
Neale Ranns15002542017-09-10 04:39:11 -0700674 def mpls_table_add_del(
675 self,
676 table_id,
677 is_add=1):
678 """
679
680 :param table_id
681 :param is_add: (Default value = 1)
682
683 """
684
685 return self.api(
686 self.papi.mpls_table_add_del,
687 {'mt_table_id': table_id,
688 'mt_is_add': is_add})
689
Neale Rannsad422ed2016-11-02 14:20:04 +0000690 def mpls_ip_bind_unbind(
691 self,
692 label,
693 dst_address,
694 dst_address_length,
695 table_id=0,
696 ip_table_id=0,
697 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000698 is_bind=1):
699 """
700 """
701 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100702 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200703 {'mb_mpls_table_id': table_id,
704 'mb_label': label,
705 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200706 'mb_is_bind': is_bind,
707 'mb_is_ip4': is_ip4,
708 'mb_address_length': dst_address_length,
709 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000710
711 def mpls_tunnel_add_del(
712 self,
713 tun_sw_if_index,
714 next_hop_proto_is_ip4,
715 next_hop_address,
716 next_hop_sw_if_index=0xFFFFFFFF,
717 next_hop_table_id=0,
718 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200719 next_hop_n_out_labels=0,
720 next_hop_out_label_stack=[],
721 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000722 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800723 l2_only=0,
724 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000725 """
726
727 :param dst_address_length:
728 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
729 :param dst_address:
730 :param next_hop_address:
731 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
732 :param vrf_id: (Default value = 0)
733 :param lookup_in_vrf: (Default value = 0)
734 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000735 :param is_add: (Default value = 1)
736 :param is_drop: (Default value = 0)
737 :param is_ipv6: (Default value = 0)
738 :param is_local: (Default value = 0)
739 :param is_classify: (Default value = 0)
740 :param is_multipath: (Default value = 0)
741 :param is_resolve_host: (Default value = 0)
742 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000743 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800744 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000745
746 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000747 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100748 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200749 {'mt_sw_if_index': tun_sw_if_index,
750 'mt_is_add': is_add,
751 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800752 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200753 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
754 'mt_next_hop_weight': next_hop_weight,
755 'mt_next_hop': next_hop_address,
756 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
757 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
758 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700759 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200760 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800761
Matus Fabian2ba92e32017-08-21 07:05:03 -0700762 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -0800763 self,
764 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200765 is_add=1,
766 flags=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700767 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -0800768
769 :param sw_if_index: Software index of the interface
Matus Fabiande886752016-12-07 03:38:19 -0800770 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200771 :param flags: NAT_IS_INSIDE if inside else outside
Matus Fabiande886752016-12-07 03:38:19 -0800772 """
773 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700774 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200775 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200776 'flags': flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200777 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800778
Matus Fabian2ba92e32017-08-21 07:05:03 -0700779 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -0700780 self,
781 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200782 is_add=1,
783 flags=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700784 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700785
786 :param sw_if_index: Software index of the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700787 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200788 :param flags: NAT_IS_INSIDE if inside else outside
Matus Fabian93d84c92017-07-19 08:06:01 -0700789 """
790 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700791 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -0700792 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200793 'flags': flags,
Matus Fabian93d84c92017-07-19 08:06:01 -0700794 'sw_if_index': sw_if_index})
795
Matus Fabian2ba92e32017-08-21 07:05:03 -0700796 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -0800797 self,
798 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800799 external_ip=0,
800 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800801 local_port=0,
802 external_port=0,
Matus Fabiande886752016-12-07 03:38:19 -0800803 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800804 protocol=0,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200805 is_add=1,
806 flags=0,
807 tag=""):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700808 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -0800809
810 :param local_ip: Local IP address
811 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800812 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800813 :param local_port: Local port number (Default value = 0)
814 :param external_port: External port number (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -0800815 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800816 :param protocol: IP protocol (Default value = 0)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200817 :param flags: NAT configuration flags
Ole Trøan89fec712019-04-23 12:38:35 +0000818 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200819 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -0800820 """
821 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700822 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200823 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200824 'flags': flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200825 'local_ip_address': local_ip,
826 'external_ip_address': external_ip,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200827 'protocol': protocol,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200828 'local_port': local_port,
829 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800830 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800831 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -0800832 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -0800833
Matus Fabianab7a8052017-11-28 04:29:41 -0800834 def nat44_add_del_identity_mapping(
835 self,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800836 ip=b'0',
Matus Fabianab7a8052017-11-28 04:29:41 -0800837 sw_if_index=0xFFFFFFFF,
838 port=0,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200839 flags=0,
Matus Fabianab7a8052017-11-28 04:29:41 -0800840 vrf_id=0,
841 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800842 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -0800843 is_add=1):
844 """Add/delete NAT44 identity mapping
845
846 :param ip: IP address (Default value = 0)
847 :param sw_if_index: Interface instead of IP address
848 :param port: Port number (Default value = 0)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200849 :param flags: NAT configuration flags (NAT_IS_ADDR_ONLY)
Matus Fabianab7a8052017-11-28 04:29:41 -0800850 :param vrf_id: VRF ID
851 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -0800852 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -0800853 :param is_add: 1 if add, 0 if delete (Default value = 1)
854 """
855 return self.api(
856 self.papi.nat44_add_del_identity_mapping,
857 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200858 'flags': flags,
Matus Fabianab7a8052017-11-28 04:29:41 -0800859 'ip_address': ip,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200860 'protocol': protocol,
Matus Fabianab7a8052017-11-28 04:29:41 -0800861 'port': port,
862 'sw_if_index': sw_if_index,
863 'vrf_id': vrf_id,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200864 'tag': tag})
Matus Fabianab7a8052017-11-28 04:29:41 -0800865
Matus Fabian2ba92e32017-08-21 07:05:03 -0700866 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -0800867 self,
868 first_ip_address,
869 last_ip_address,
870 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -0800871 vrf_id=0xFFFFFFFF,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200872 flags=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700873 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -0800874
875 :param first_ip_address: First IP address
876 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800877 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -0800878 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200879 :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
Matus Fabiande886752016-12-07 03:38:19 -0800880 """
881 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700882 self.papi.nat44_add_del_address_range,
883 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200884 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800885 'vrf_id': vrf_id,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200886 'is_add': is_add,
887 'flags': flags})
Matus Fabiande886752016-12-07 03:38:19 -0800888
Ole Troane1ade682019-03-04 23:55:43 +0100889 def nat44_add_del_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -0800890 self,
891 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200892 flags=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -0800893 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700894 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -0800895
896 :param sw_if_index: Software index of the interface
Filip Vargadd1e3e72019-04-15 18:52:43 +0200897 :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
Matus Fabian8bf68e82017-01-12 04:24:35 -0800898 :param is_add: 1 if add, 0 if delete (Default value = 1)
899 """
Matus Fabianb932d262017-12-18 05:38:24 -0800900 return self.api(
901 self.papi.nat44_add_del_interface_addr,
902 {'is_add': is_add,
903 'sw_if_index': sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200904 'flags': flags})
Matus Fabian8bf68e82017-01-12 04:24:35 -0800905
Matus Fabian704018c2017-09-04 02:17:18 -0700906 def nat44_add_del_lb_static_mapping(
907 self,
908 external_addr,
909 external_port,
910 protocol,
Matus Fabian5f224992018-01-25 21:59:16 -0800911 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -0700912 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700913 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +0200914 locals=[],
Filip Vargadd1e3e72019-04-15 18:52:43 +0200915 flags=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700916 is_add=1):
917 """Add/delete NAT44 load balancing static mapping
918
Matus Fabian5f224992018-01-25 21:59:16 -0800919 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -0700920 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Filip Vargadd1e3e72019-04-15 18:52:43 +0200921 :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
Matus Fabian704018c2017-09-04 02:17:18 -0700922 :param is_add - 1 if add, 0 if delete
923 """
924 return self.api(
925 self.papi.nat44_add_del_lb_static_mapping,
926 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200927 'flags': flags,
Matus Fabian704018c2017-09-04 02:17:18 -0700928 'external_addr': external_addr,
929 'external_port': external_port,
930 'protocol': protocol,
Matus Fabianea5b5be2018-09-03 05:02:23 -0700931 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -0700932 'local_num': local_num,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200933 'locals': locals,
934 'tag': tag})
Matus Fabian704018c2017-09-04 02:17:18 -0700935
Matus Fabianb6865082018-12-06 03:11:09 -0800936 def nat44_lb_static_mapping_add_del_local(
Ole Troan9a475372019-03-05 16:58:24 +0100937 self,
938 external_addr,
939 external_port,
940 local_addr,
941 local_port,
942 protocol,
943 probability,
944 vrf_id=0,
945 is_add=1):
Matus Fabianb6865082018-12-06 03:11:09 -0800946 """Add/delete NAT44 load-balancing static mapping rule backend
947
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700948 :param external_addr: external IPv4 address of the service
Matus Fabianb6865082018-12-06 03:11:09 -0800949 :param external_port: external L4 port number of the service
950 :param local_addr: IPv4 address of the internal node
951 :param local_port: L4 port number of the internal node
952 :param protocol: IP protocol number
953 :param probability: probability of the internal node
954 :param vrf_id: VRF id of the internal node
955 :param is_add: 1 if add, 0 if delete
956 """
957 return self.api(
958 self.papi.nat44_lb_static_mapping_add_del_local,
959 {'is_add': is_add,
960 'external_addr': external_addr,
961 'external_port': external_port,
962 'local': {
963 'addr': local_addr,
964 'port': local_port,
965 'probability': probability,
966 'vrf_id': vrf_id},
967 'protocol': protocol})
968
Matus Fabian5ba86f72017-10-26 03:37:38 -0700969 def nat44_del_session(
970 self,
971 addr,
972 port,
973 protocol,
974 vrf_id=0,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200975 flags=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -0700976 ext_host_address=None,
977 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -0700978 """Delete NAT44 session
979
980 :param addr: IPv4 address
981 :param por: port number
982 :param protocol: IP protocol number
983 :param vrf_id: VRF ID
Filip Vargadd1e3e72019-04-15 18:52:43 +0200984 :param flags: NAT configuration flags (NAT_IS_INSIDE)
Matus Fabian70a26ac2018-05-14 06:20:28 -0700985 :param ext_host_address: external host IPv4 address
986 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -0700987 """
Filip Vargadd1e3e72019-04-15 18:52:43 +0200988 return self.api(
989 self.papi.nat44_del_session,
990 {'address': addr,
991 'protocol': protocol,
992 'port': port,
993 'vrf_id': vrf_id,
994 'flags': flags,
995 'ext_host_address': ext_host_address,
996 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -0700997
Juraj Sloboda7b929792017-11-23 13:20:48 +0100998 def nat44_forwarding_enable_disable(
999 self,
1000 enable):
1001 """Enable/disable forwarding for NAT44
1002
1003 :param enable: 1 for enable, 0 for disable
1004 """
1005 return self.api(
1006 self.papi.nat44_forwarding_enable_disable,
1007 {'enable': enable})
1008
Matus Fabian2ba92e32017-08-21 07:05:03 -07001009 def nat_det_map_dump(self):
1010 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001011
Matus Fabian2ba92e32017-08-21 07:05:03 -07001012 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001013 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001014 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001015
Matus Fabianbb4e0222018-09-13 02:36:25 -07001016 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1017 """Set TCP MSS rewriting configuration
1018
1019 :param enable: disable(0)/enable(1) MSS rewriting feature
1020 :param mss_value: MSS value to be used for MSS rewriting
1021 """
1022 return self.api(
1023 self.papi.nat_set_mss_clamping,
1024 {'enable': enable, 'mss_value': mss_value})
1025
Matus Fabian06596c52017-06-06 04:53:28 -07001026 def nat64_add_del_static_bib(
1027 self,
1028 in_ip,
1029 out_ip,
1030 in_port,
1031 out_port,
1032 protocol,
1033 vrf_id=0,
1034 is_add=1):
1035 """Add/delete S-NAT static BIB entry
1036
1037 :param in_ip: Inside IPv6 address
1038 :param out_ip: Outside IPv4 address
1039 :param in_port: Inside port number
1040 :param out_port: Outside port number
1041 :param protocol: IP protocol
1042 :param vrf_id: VRF ID (Default value = 0)
1043 :param is_add: 1 if add, 0 if delete (Default value = 1)
1044 """
1045 return self.api(
1046 self.papi.nat64_add_del_static_bib,
1047 {'i_addr': in_ip,
1048 'o_addr': out_ip,
1049 'i_port': in_port,
1050 'o_port': out_port,
1051 'vrf_id': vrf_id,
1052 'proto': protocol,
1053 'is_add': is_add})
1054
Matus Fabianab9a59c2017-08-16 05:37:36 -07001055 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001056 """Dump NAT64 BIB
1057
Matus Fabianab9a59c2017-08-16 05:37:36 -07001058 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001059 :returns: Dictionary of NAT64 BIB entries
1060 """
1061 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1062
Matus Fabianab9a59c2017-08-16 05:37:36 -07001063 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001064 """Dump NAT64 session table
1065
Matus Fabianab9a59c2017-08-16 05:37:36 -07001066 :param protocol: IP protocol (Default value = 255, all STs)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001067 :returns: Dictionary of NAT64 session table entries
Matus Fabian06596c52017-06-06 04:53:28 -07001068 """
1069 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1070
Filip Vargadd1e3e72019-04-15 18:52:43 +02001071 def nat64_add_del_prefix(self, prefix, vrf_id=0, is_add=1):
Matus Fabian428dc912017-06-21 06:15:18 -07001072 """Add/del NAT64 prefix
1073
1074 :param prefix: NAT64 prefix
Matus Fabian428dc912017-06-21 06:15:18 -07001075 :param vrf_id: VRF id of tenant (Default 0)
1076 :param is_add: 1 if add, 0 if delete (Default value = 1)
1077 """
1078 return self.api(
1079 self.papi.nat64_add_del_prefix,
1080 {'prefix': prefix,
Matus Fabian428dc912017-06-21 06:15:18 -07001081 'vrf_id': vrf_id,
1082 'is_add': is_add})
1083
Ole Troane1ade682019-03-04 23:55:43 +01001084 def nat64_add_del_interface_addr(
Matus Fabian0938dcf2017-11-08 01:59:38 -08001085 self,
1086 sw_if_index,
1087 is_add=1):
1088 """Add/del NAT64 address from interface
1089
1090 :param sw_if_index: Software index of the interface
1091 :param is_add: 1 if add, 0 if delete (Default value = 1)
1092 """
1093 return self.api(self.papi.nat64_add_del_interface_addr,
1094 {'is_add': is_add, 'sw_if_index': sw_if_index})
1095
Matus Fabian8ebe6252017-11-06 05:04:53 -08001096 def dslite_set_aftr_addr(self, ip6, ip4):
1097 """Set DS-Lite AFTR addresses
1098
1099 :param ip4: IPv4 address
1100 :param ip6: IPv6 address
1101 """
1102 return self.api(
1103 self.papi.dslite_set_aftr_addr,
1104 {'ip4_addr': ip4,
1105 'ip6_addr': ip6})
1106
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001107 def dslite_set_b4_addr(self, ip6, ip4):
1108 """Set DS-Lite B4 IPv6 address
1109
1110 :param ip4: IPv4 address
1111 :param ip6: IPv6 address
1112 """
1113 return self.api(
1114 self.papi.dslite_set_b4_addr,
1115 {'ip4_addr': ip4,
1116 'ip6_addr': ip6})
1117
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001118 def nat66_add_del_interface(
1119 self,
1120 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +02001121 flags=0,
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001122 is_add=1):
1123 """Enable/disable NAT66 feature on the interface
Filip Vargadd1e3e72019-04-15 18:52:43 +02001124
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001125 :param sw_if_index: Index of the interface
Filip Vargadd1e3e72019-04-15 18:52:43 +02001126 :param flags: NAT configuration flags (NAT_IS_INSIDE)
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001127 :param is_add: 1 if add, 0 if delete (Default value = 1)
1128 """
1129 return self.api(
1130 self.papi.nat66_add_del_interface,
Filip Vargadd1e3e72019-04-15 18:52:43 +02001131 {'is_add': is_add,
1132 'flags': flags,
1133 'sw_if_index': sw_if_index})
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001134
1135 def nat66_add_del_static_mapping(
1136 self,
1137 in_ip,
1138 out_ip,
1139 vrf_id=0,
1140 is_add=1):
1141 """Add/delete NAT66 static mapping
1142
1143 :param in_ip: Inside IPv6 address
1144 :param out_ip: Outside IPv6 address
1145 :param vrf_id: VRF ID (Default value = 0)
1146 :param is_add: 1 if add, 0 if delete (Default value = 1)
1147 """
1148 return self.api(
1149 self.papi.nat66_add_del_static_mapping,
1150 {'local_ip_address': in_ip,
1151 'external_ip_address': out_ip,
1152 'vrf_id': vrf_id,
1153 'is_add': is_add})
1154
Matus Fabian34931eb2019-02-26 09:05:23 -08001155 def nat_ha_set_listener(self, addr, port, path_mtu=512):
1156 """Set HA listener (local settings)
1157
1158 :param addr: local IP4 address
1159 :param port: local UDP port number
1160 :param path_mtu: path MTU (Default value = 512)
1161 """
1162 return self.api(self.papi.nat_ha_set_listener,
1163 {'ip_address': addr,
1164 'port': port,
1165 'path_mtu': path_mtu})
1166
1167 def nat_ha_get_listener(self):
1168 """Get HA listener/local configuration"""
1169 return self.api(self.papi.nat_ha_get_listener, {})
1170
1171 def nat_ha_set_failover(self, addr, port, refresh=10):
1172 """Set HA failover (remote settings)
1173
1174 :param addr: failover IP4 address
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001175 :param port: failover UDP port number
Matus Fabian34931eb2019-02-26 09:05:23 -08001176 :param refresh: number of seconds after which to send session refresh
1177 """
1178 return self.api(self.papi.nat_ha_set_failover,
1179 {'ip_address': addr,
1180 'port': port,
1181 'session_refresh_interval': refresh})
1182
Matus Fabian34931eb2019-02-26 09:05:23 -08001183 def nat_ha_resync(self, want_resync_event=1):
1184 """Resync HA (resend existing sessions to new failover)
1185 :param want_resync_event: if non-zero resync completed event sent
1186 """
1187 return self.api(self.papi.nat_ha_resync,
1188 {'want_resync_event': want_resync_event,
1189 'pid': os.getpid()})
1190
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001191 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001192 detect_mult, local_addr, peer_addr, is_ipv6=0,
1193 bfd_key_id=None, conf_key_id=None):
1194 if bfd_key_id is None:
1195 return self.api(self.papi.bfd_udp_add,
1196 {
1197 'sw_if_index': sw_if_index,
1198 'desired_min_tx': desired_min_tx,
1199 'required_min_rx': required_min_rx,
1200 'local_addr': local_addr,
1201 'peer_addr': peer_addr,
1202 'is_ipv6': is_ipv6,
1203 'detect_mult': detect_mult,
1204 })
1205 else:
1206 return self.api(self.papi.bfd_udp_add,
1207 {
1208 'sw_if_index': sw_if_index,
1209 'desired_min_tx': desired_min_tx,
1210 'required_min_rx': required_min_rx,
1211 'local_addr': local_addr,
1212 'peer_addr': peer_addr,
1213 'is_ipv6': is_ipv6,
1214 'detect_mult': detect_mult,
1215 'is_authenticated': 1,
1216 'bfd_key_id': bfd_key_id,
1217 'conf_key_id': conf_key_id,
1218 })
1219
Klement Sekeraa57a9702017-02-02 06:58:07 +01001220 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1221 detect_mult, local_addr, peer_addr, is_ipv6=0):
1222 return self.api(self.papi.bfd_udp_mod,
1223 {
1224 'sw_if_index': sw_if_index,
1225 'desired_min_tx': desired_min_tx,
1226 'required_min_rx': required_min_rx,
1227 'local_addr': local_addr,
1228 'peer_addr': peer_addr,
1229 'is_ipv6': is_ipv6,
1230 'detect_mult': detect_mult,
1231 })
1232
Klement Sekerab17dd962017-01-09 07:43:48 +01001233 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1234 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1235 is_delayed=False):
1236 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001237 {
1238 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001239 'local_addr': local_addr,
1240 'peer_addr': peer_addr,
1241 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001242 'is_delayed': 1 if is_delayed else 0,
1243 'bfd_key_id': bfd_key_id,
1244 'conf_key_id': conf_key_id,
1245 })
1246
Klement Sekerab17dd962017-01-09 07:43:48 +01001247 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1248 peer_addr, is_ipv6=0):
1249 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001250 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001251 'sw_if_index': sw_if_index,
1252 'local_addr': local_addr,
1253 'peer_addr': peer_addr,
1254 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001255 })
1256
1257 def want_bfd_events(self, enable_disable=1):
1258 return self.api(self.papi.want_bfd_events, {
1259 'enable_disable': enable_disable,
1260 'pid': os.getpid(),
1261 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001262
Klement Sekerab17dd962017-01-09 07:43:48 +01001263 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1264 return self.api(self.papi.bfd_auth_set_key, {
1265 'conf_key_id': conf_key_id,
1266 'auth_type': auth_type,
1267 'key': key,
1268 'key_len': len(key),
1269 })
1270
Steve Shin7957d6e2016-12-19 09:24:50 -08001271 def classify_add_del_table(
1272 self,
1273 is_add,
1274 mask,
1275 match_n_vectors=1,
1276 table_index=0xFFFFFFFF,
1277 nbuckets=2,
1278 memory_size=2097152,
1279 skip_n_vectors=0,
1280 next_table_index=0xFFFFFFFF,
1281 miss_next_index=0xFFFFFFFF,
1282 current_data_flag=0,
1283 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001284 """
1285 :param is_add:
1286 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001287 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001288 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001289 :param nbuckets: (Default value = 2)
1290 :param memory_size: (Default value = 2097152)
1291 :param skip_n_vectors: (Default value = 0)
1292 :param next_table_index: (Default value = 0xFFFFFFFF)
1293 :param miss_next_index: (Default value = 0xFFFFFFFF)
1294 :param current_data_flag: (Default value = 0)
1295 :param current_data_offset: (Default value = 0)
1296 """
1297
Juraj Sloboda75282452018-06-12 14:20:49 +02001298 mask_len = ((len(mask) - 1) / 16 + 1) * 16
1299 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08001300 return self.api(
1301 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001302 {'is_add': is_add,
1303 'table_index': table_index,
1304 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001305 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001306 'skip_n_vectors': skip_n_vectors,
1307 'match_n_vectors': match_n_vectors,
1308 'next_table_index': next_table_index,
1309 'miss_next_index': miss_next_index,
1310 'current_data_flag': current_data_flag,
1311 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02001312 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001313 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001314
1315 def classify_add_del_session(
1316 self,
1317 is_add,
1318 table_index,
1319 match,
1320 opaque_index=0xFFFFFFFF,
1321 hit_next_index=0xFFFFFFFF,
1322 advance=0,
1323 action=0,
1324 metadata=0):
1325 """
1326 :param is_add:
1327 :param table_index:
1328 :param match:
1329 :param opaque_index: (Default value = 0xFFFFFFFF)
1330 :param hit_next_index: (Default value = 0xFFFFFFFF)
1331 :param advance: (Default value = 0)
1332 :param action: (Default value = 0)
1333 :param metadata: (Default value = 0)
1334 """
1335
Juraj Sloboda75282452018-06-12 14:20:49 +02001336 match_len = ((len(match) - 1) / 16 + 1) * 16
1337 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08001338 return self.api(
1339 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001340 {'is_add': is_add,
1341 'table_index': table_index,
1342 'hit_next_index': hit_next_index,
1343 'opaque_index': opaque_index,
1344 'advance': advance,
1345 'action': action,
1346 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02001347 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001348 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001349
1350 def input_acl_set_interface(
1351 self,
1352 is_add,
1353 sw_if_index,
1354 ip4_table_index=0xFFFFFFFF,
1355 ip6_table_index=0xFFFFFFFF,
1356 l2_table_index=0xFFFFFFFF):
1357 """
1358 :param is_add:
1359 :param sw_if_index:
1360 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1361 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1362 :param l2_table_index: (Default value = 0xFFFFFFFF)
1363 """
1364
1365 return self.api(
1366 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001367 {'sw_if_index': sw_if_index,
1368 'ip4_table_index': ip4_table_index,
1369 'ip6_table_index': ip6_table_index,
1370 'l2_table_index': l2_table_index,
1371 'is_add': is_add})
1372
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01001373 def output_acl_set_interface(
1374 self,
1375 is_add,
1376 sw_if_index,
1377 ip4_table_index=0xFFFFFFFF,
1378 ip6_table_index=0xFFFFFFFF,
1379 l2_table_index=0xFFFFFFFF):
1380 """
1381 :param is_add:
1382 :param sw_if_index:
1383 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1384 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1385 :param l2_table_index: (Default value = 0xFFFFFFFF)
1386 """
1387
1388 return self.api(
1389 self.papi.output_acl_set_interface,
1390 {'sw_if_index': sw_if_index,
1391 'ip4_table_index': ip4_table_index,
1392 'ip6_table_index': ip6_table_index,
1393 'l2_table_index': l2_table_index,
1394 'is_add': is_add})
1395
Klement Sekera77fabdb2017-01-02 07:46:14 +01001396 def set_ipfix_exporter(
1397 self,
1398 collector_address,
1399 src_address,
1400 path_mtu,
1401 template_interval,
1402 vrf_id=0,
1403 collector_port=4739,
1404 udp_checksum=0):
1405 return self.api(
1406 self.papi.set_ipfix_exporter,
1407 {
1408 'collector_address': collector_address,
1409 'collector_port': collector_port,
1410 'src_address': src_address,
1411 'vrf_id': vrf_id,
1412 'path_mtu': path_mtu,
1413 'template_interval': template_interval,
1414 'udp_checksum': udp_checksum,
1415 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001416
1417 def dhcp_proxy_config(self,
1418 dhcp_server,
1419 dhcp_src_address,
1420 rx_table_id=0,
1421 server_table_id=0,
1422 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001423 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001424 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001425 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001426 {
1427 'rx_vrf_id': rx_table_id,
1428 'server_vrf_id': server_table_id,
1429 'is_ipv6': is_ipv6,
1430 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001431 'dhcp_server': dhcp_server,
1432 'dhcp_src_address': dhcp_src_address,
1433 })
1434
1435 def dhcp_proxy_set_vss(self,
1436 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001437 vss_type=255,
1438 vpn_ascii_id="",
1439 oui=0,
1440 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001441 is_add=1,
1442 is_ip6=0):
1443 return self.api(
1444 self.papi.dhcp_proxy_set_vss,
1445 {
1446 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001447 'vss_type': vss_type,
1448 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001449 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001450 'vpn_index': vpn_index,
1451 'is_add': is_add,
1452 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001453 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001454
Ole Troane1ade682019-03-04 23:55:43 +01001455 def dhcp_client_config(self,
1456 sw_if_index,
1457 hostname,
1458 client_id='',
1459 is_add=1,
1460 set_broadcast_flag=1,
1461 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001462 return self.api(
1463 self.papi.dhcp_client_config,
1464 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001465 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001466 'client': {
1467 'sw_if_index': sw_if_index,
1468 'hostname': hostname,
1469 'id': client_id,
1470 'want_dhcp_event': want_dhcp_events,
1471 'set_broadcast_flag': set_broadcast_flag,
1472 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001473 })
1474
Neale Ranns32e1c012016-11-22 17:07:28 +00001475 def ip_mroute_add_del(self,
1476 src_address,
1477 grp_address,
1478 grp_address_length,
1479 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001480 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001481 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001482 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001483 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001484 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001485 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001486 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001487 is_add=1,
1488 is_ipv6=0,
1489 is_local=0):
1490 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001491 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001492 """
1493 return self.api(
1494 self.papi.ip_mroute_add_del,
1495 {'next_hop_sw_if_index': next_hop_sw_if_index,
1496 'entry_flags': e_flags,
1497 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001498 'table_id': table_id,
1499 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001500 'is_add': is_add,
1501 'is_ipv6': is_ipv6,
1502 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001503 'bier_imp': bier_imp,
1504 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001505 'grp_address_length': grp_address_length,
1506 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001507 'src_address': src_address,
1508 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001509
Filip Tehlar770e89e2017-01-31 10:39:16 +01001510 def lisp_enable_disable(self, is_enabled):
1511 return self.api(
1512 self.papi.lisp_enable_disable,
1513 {
1514 'is_en': is_enabled,
1515 })
1516
Ole Troane1ade682019-03-04 23:55:43 +01001517 def lisp_add_del_locator_set(self,
1518 ls_name,
1519 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001520 return self.api(
1521 self.papi.lisp_add_del_locator_set,
1522 {
1523 'is_add': is_add,
1524 'locator_set_name': ls_name
1525 })
1526
Ole Troane1ade682019-03-04 23:55:43 +01001527 def lisp_add_del_locator(self,
1528 ls_name,
1529 sw_if_index,
1530 priority=1,
1531 weight=1,
1532 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001533 return self.api(
1534 self.papi.lisp_add_del_locator,
1535 {
1536 'is_add': is_add,
1537 'locator_set_name': ls_name,
1538 'sw_if_index': sw_if_index,
1539 'priority': priority,
1540 'weight': weight
1541 })
1542
1543 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1544 return self.api(
1545 self.papi.lisp_locator_dump,
1546 {
1547 'is_index_set': is_index_set,
1548 'ls_name': ls_name,
1549 'ls_index': ls_index,
1550 })
1551
Ole Troane1ade682019-03-04 23:55:43 +01001552 def lisp_add_del_local_eid(self,
1553 ls_name,
1554 eid_type,
1555 eid,
1556 prefix_len,
1557 vni=0,
1558 key_id=0,
1559 key="",
1560 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001561 return self.api(
1562 self.papi.lisp_add_del_local_eid,
1563 {
1564 'locator_set_name': ls_name,
1565 'is_add': is_add,
1566 'eid_type': eid_type,
1567 'eid': eid,
1568 'prefix_len': prefix_len,
1569 'vni': vni,
1570 'key_id': key_id,
1571 'key': key
1572 })
1573
1574 def lisp_eid_table_dump(self,
1575 eid_set=0,
1576 prefix_length=0,
1577 vni=0,
1578 eid_type=0,
1579 eid=None,
1580 filter_opt=0):
1581 return self.api(
1582 self.papi.lisp_eid_table_dump,
1583 {
1584 'eid_set': eid_set,
1585 'prefix_length': prefix_length,
1586 'vni': vni,
1587 'eid_type': eid_type,
1588 'eid': eid,
1589 'filter': filter_opt,
1590 })
1591
Ole Troane1ade682019-03-04 23:55:43 +01001592 def lisp_add_del_remote_mapping(self,
1593 eid_type,
1594 eid,
1595 eid_prefix_len=0,
1596 vni=0,
1597 rlocs=[],
1598 rlocs_num=0,
1599 is_src_dst=0,
1600 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001601 return self.api(
1602 self.papi.lisp_add_del_remote_mapping,
1603 {
1604 'is_add': is_add,
1605 'eid_type': eid_type,
1606 'eid': eid,
1607 'eid_len': eid_prefix_len,
1608 'rloc_num': rlocs_num,
1609 'rlocs': rlocs,
1610 'vni': vni,
1611 'is_src_dst': is_src_dst,
1612 })
1613
Ole Troane1ade682019-03-04 23:55:43 +01001614 def lisp_add_del_adjacency(self,
1615 leid,
1616 reid,
1617 leid_len,
1618 reid_len,
1619 eid_type,
1620 is_add=1,
1621 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001622 return self.api(
1623 self.papi.lisp_add_del_adjacency,
1624 {
1625 'is_add': is_add,
1626 'vni': vni,
1627 'eid_type': eid_type,
1628 'leid': leid,
1629 'reid': reid,
1630 'leid_len': leid_len,
1631 'reid_len': reid_len,
1632 })
1633
Hongjun Nief486b12017-04-12 19:21:16 +08001634 def gtpu_add_del_tunnel(
1635 self,
1636 src_addr,
1637 dst_addr,
1638 is_add=1,
1639 is_ipv6=0,
1640 mcast_sw_if_index=0xFFFFFFFF,
1641 encap_vrf_id=0,
1642 decap_next_index=0xFFFFFFFF,
1643 teid=0):
1644 """
1645
1646 :param is_add: (Default value = 1)
1647 :param is_ipv6: (Default value = 0)
1648 :param src_addr:
1649 :param dst_addr:
1650 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1651 :param encap_vrf_id: (Default value = 0)
1652 :param decap_next_index: (Default value = 0xFFFFFFFF)
1653 :param teid: (Default value = 0)
1654
1655 """
1656 return self.api(self.papi.gtpu_add_del_tunnel,
1657 {'is_add': is_add,
1658 'is_ipv6': is_ipv6,
1659 'src_address': src_addr,
1660 'dst_address': dst_addr,
1661 'mcast_sw_if_index': mcast_sw_if_index,
1662 'encap_vrf_id': encap_vrf_id,
1663 'decap_next_index': decap_next_index,
1664 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001665
1666 def vxlan_gpe_add_del_tunnel(
1667 self,
1668 src_addr,
1669 dst_addr,
1670 mcast_sw_if_index=0xFFFFFFFF,
1671 is_add=1,
1672 is_ipv6=0,
1673 encap_vrf_id=0,
1674 decap_vrf_id=0,
1675 protocol=3,
1676 vni=0):
1677 """
1678
1679 :param local:
1680 :param remote:
1681 :param is_add: (Default value = 1)
1682 :param is_ipv6: (Default value = 0)
1683 :param encap_vrf_id: (Default value = 0)
1684 :param decap_vrf_id: (Default value = 0)
1685 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1686 :param protocol: (Default value = 3)
1687 :param vni: (Default value = 0)
1688
1689 """
1690 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1691 {'is_add': is_add,
1692 'is_ipv6': is_ipv6,
1693 'local': src_addr,
1694 'remote': dst_addr,
1695 'mcast_sw_if_index': mcast_sw_if_index,
1696 'encap_vrf_id': encap_vrf_id,
1697 'decap_vrf_id': decap_vrf_id,
1698 'protocol': protocol,
1699 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001700
Neale Ranns79a05f52018-09-11 07:39:43 -07001701 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001702 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001703 src,
1704 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001705 mcast_sw_if_index=0xFFFFFFFF,
1706 is_add=1,
1707 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001708 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001709 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001710 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001711 instance=0xFFFFFFFF):
1712 """
1713
1714 :param dst_addr:
1715 :param src_addr:
1716 :param is_add: (Default value = 1)
1717 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001718 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001719 :param decap_next_index: (Default value = 0xFFFFFFFF)
1720 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1721 :param vni: (Default value = 0)
1722 :param instance: (Default value = 0xFFFFFFFF)
1723
1724 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001725 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001726 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001727 'tunnel': {
1728 'src': src,
1729 'dst': dst,
1730 'mcast_sw_if_index': mcast_sw_if_index,
1731 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001732 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001733 'instance': instance,
1734 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001735
1736 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1737 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001738 {'sw_if_index': sw_if_index,
1739 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001740
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001741 def pppoe_add_del_session(
1742 self,
1743 client_ip,
1744 client_mac,
1745 session_id=0,
1746 is_add=1,
1747 is_ipv6=0,
1748 decap_vrf_id=0):
1749 """
1750
1751 :param is_add: (Default value = 1)
1752 :param is_ipv6: (Default value = 0)
1753 :param client_ip:
1754 :param session_id: (Default value = 0)
1755 :param client_mac:
1756 :param decap_vrf_id: (Default value = 0)
1757
1758 """
1759 return self.api(self.papi.pppoe_add_del_session,
1760 {'is_add': is_add,
1761 'is_ipv6': is_ipv6,
1762 'session_id': session_id,
1763 'client_ip': client_ip,
1764 'decap_vrf_id': decap_vrf_id,
1765 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001766
Neale Ranns7c922dc2018-08-30 06:12:27 -07001767 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1768 return self.api(self.papi.sr_mpls_policy_add,
1769 {'bsid': bsid,
1770 'weight': weight,
1771 'type': type,
1772 'n_segments': len(segments),
1773 'segments': segments})
1774
1775 def sr_mpls_policy_del(self, bsid):
1776 return self.api(self.papi.sr_mpls_policy_del,
1777 {'bsid': bsid})
1778
Kris Michielsen91074432017-06-22 13:00:20 +02001779 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001780 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001781 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001782 nh_addr4,
1783 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001784 is_del=0,
1785 end_psp=0,
1786 sw_if_index=0xFFFFFFFF,
1787 vlan_index=0,
1788 fib_table=0,
1789 ):
1790 """ Add/del IPv6 SR local-SID.
1791
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001792 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001793 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1794 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001795 :param nh_addr4:
1796 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001797 :param is_del: (Default value = 0)
1798 :param end_psp: (Default value = 0)
1799 :param sw_if_index: (Default value = 0xFFFFFFFF)
1800 :param vlan_index: (Default value = 0)
1801 :param fib_table: (Default value = 0)
1802 """
1803 return self.api(
1804 self.papi.sr_localsid_add_del,
1805 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001806 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001807 'end_psp': end_psp,
1808 'behavior': behavior,
1809 'sw_if_index': sw_if_index,
1810 'vlan_index': vlan_index,
1811 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001812 'nh_addr4': nh_addr4,
1813 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001814 }
1815 )
1816
1817 def sr_policy_add(
1818 self,
1819 bsid_addr,
1820 weight=1,
1821 is_encap=1,
1822 type=0,
1823 fib_table=0,
1824 n_segments=0,
1825 segments=[]):
1826 """
1827 :param bsid_addr: bindingSID of the SR Policy
1828 :param weight: weight of the sid list. optional. (default: 1)
1829 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1830 (default: Encap)
1831 :param type: type/behavior of the SR policy. (default or spray) \
1832 (default: default)
1833 :param fib_table: VRF where to install the FIB entry for the BSID \
1834 (default: 0)
1835 :param n_segments: number of segments \
1836 (default: 0)
1837 :param segments: a vector of IPv6 address composing the segment list \
1838 (default: [])
1839 """
1840 return self.api(
1841 self.papi.sr_policy_add,
1842 {'bsid_addr': bsid_addr,
1843 'weight': weight,
1844 'is_encap': is_encap,
1845 'type': type,
1846 'fib_table': fib_table,
1847 'n_segments': n_segments,
1848 'segments': segments
1849 }
1850 )
1851
1852 def sr_policy_del(
1853 self,
1854 bsid_addr,
1855 sr_policy_index=0):
1856 """
1857 :param bsid: bindingSID of the SR Policy
1858 :param sr_policy_index: index of the sr policy (default: 0)
1859 """
1860 return self.api(
1861 self.papi.sr_policy_del,
1862 {'bsid_addr': bsid_addr,
1863 'sr_policy_index': sr_policy_index
1864 })
1865
1866 def sr_steering_add_del(
1867 self,
1868 is_del,
1869 bsid_addr,
1870 sr_policy_index,
1871 table_id,
1872 prefix_addr,
1873 mask_width,
1874 sw_if_index,
1875 traffic_type):
1876 """
1877 Steer traffic L2 and L3 traffic through a given SR policy
1878
1879 :param is_del: delete or add
1880 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1881 :param sr_policy: is the index of the SR Policy (alt to bsid)
1882 :param table_id: is the VRF where to install the FIB entry for the BSID
1883 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1884 :param mask_width: is the mask for L3 traffic type
1885 :param sw_if_index: is the incoming interface for L2 traffic
1886 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1887 """
1888 return self.api(
1889 self.papi.sr_steering_add_del,
1890 {'is_del': is_del,
1891 'bsid_addr': bsid_addr,
1892 'sr_policy_index': sr_policy_index,
1893 'table_id': table_id,
1894 'prefix_addr': prefix_addr,
1895 'mask_width': mask_width,
1896 'sw_if_index': sw_if_index,
1897 'traffic_type': traffic_type
1898 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001899
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001900 def acl_add_replace(self, acl_index, r, tag='',
1901 expected_retval=0):
1902 """Add/replace an ACL
1903 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1904 :param acl_rule r: ACL rules array.
1905 :param str tag: symbolic tag (description) for this ACL.
1906 :param int count: number of rules.
1907 """
1908 return self.api(self.papi.acl_add_replace,
1909 {'acl_index': acl_index,
1910 'r': r,
1911 'count': len(r),
1912 'tag': tag},
1913 expected_retval=expected_retval)
1914
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001915 def acl_del(self, acl_index, expected_retval=0):
1916 """
1917
1918 :param acl_index:
1919 :return:
1920 """
1921 return self.api(self.papi.acl_del,
1922 {'acl_index': acl_index},
1923 expected_retval=expected_retval)
1924
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001925 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1926 expected_retval=0):
1927 return self.api(self.papi.acl_interface_set_acl_list,
1928 {'sw_if_index': sw_if_index,
1929 'count': len(acls),
1930 'n_input': n_input,
1931 'acls': acls},
1932 expected_retval=expected_retval)
1933
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001934 def acl_interface_set_etype_whitelist(self, sw_if_index,
1935 n_input, whitelist,
1936 expected_retval=0):
1937 return self.api(self.papi.acl_interface_set_etype_whitelist,
1938 {'sw_if_index': sw_if_index,
1939 'count': len(whitelist),
1940 'n_input': n_input,
1941 'whitelist': whitelist},
1942 expected_retval=expected_retval)
1943
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001944 def acl_interface_add_del(self,
1945 sw_if_index,
1946 acl_index,
1947 is_add=1):
1948 """ Add/Delete ACL to/from interface
1949
1950 :param sw_if_index:
1951 :param acl_index:
1952 :param is_add: (Default value = 1)
1953 """
1954
1955 return self.api(self.papi.acl_interface_add_del,
1956 {'is_add': is_add,
1957 'is_input': 1,
1958 'sw_if_index': sw_if_index,
1959 'acl_index': acl_index})
1960
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001961 def acl_dump(self, acl_index, expected_retval=0):
1962 return self.api(self.papi.acl_dump,
1963 {'acl_index': acl_index},
1964 expected_retval=expected_retval)
1965
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001966 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1967 expected_retval=0):
1968 return self.api(self.papi.acl_interface_list_dump,
1969 {'sw_if_index': sw_if_index},
1970 expected_retval=expected_retval)
1971
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001972 def macip_acl_add(self, rules, tag=""):
1973 """ Add MACIP acl
1974
1975 :param rules: list of rules for given acl
1976 :param tag: acl tag
1977 """
1978
1979 return self.api(self.papi.macip_acl_add,
1980 {'r': rules,
1981 'count': len(rules),
1982 'tag': tag})
1983
Pavel Kotucek932f7412017-09-07 14:44:52 +02001984 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1985 """ Add MACIP acl
1986
1987 :param rules: list of rules for given acl
1988 :param tag: acl tag
1989 """
1990
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001991 return self.api(self.papi.macip_acl_add_replace,
1992 {'acl_index': acl_index,
1993 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001994 'count': len(rules),
1995 'tag': tag})
1996
Pavel Kotucek932f7412017-09-07 14:44:52 +02001997 def macip_acl_interface_add_del(self,
1998 sw_if_index,
1999 acl_index,
2000 is_add=1):
2001 """ Add MACIP acl to interface
2002
2003 :param sw_if_index:
2004 :param acl_index:
2005 :param is_add: (Default value = 1)
2006 """
2007
2008 return self.api(self.papi.macip_acl_interface_add_del,
2009 {'is_add': is_add,
2010 'sw_if_index': sw_if_index,
2011 'acl_index': acl_index})
2012
Pavel Kotucek932f7412017-09-07 14:44:52 +02002013 def macip_acl_dump(self, acl_index=4294967295):
2014 """ Return MACIP acl dump
2015 """
2016
2017 return self.api(
2018 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002019
2020 def policer_add_del(self,
2021 name,
2022 cir,
2023 eir,
2024 cb,
2025 eb,
2026 is_add=1,
2027 rate_type=0,
2028 round_type=0,
2029 ptype=0,
2030 color_aware=0,
2031 conform_action_type=1,
2032 conform_dscp=0,
2033 exceed_action_type=0,
2034 exceed_dscp=0,
2035 violate_action_type=0,
2036 violate_dscp=0):
2037 return self.api(self.papi.policer_add_del,
2038 {'name': name,
2039 'cir': cir,
2040 'eir': eir,
2041 'cb': cb,
2042 'eb': eb,
2043 'is_add': is_add,
2044 'rate_type': rate_type,
2045 'round_type': round_type,
2046 'type': ptype,
2047 'color_aware': color_aware,
2048 'conform_action_type': conform_action_type,
2049 'conform_dscp': conform_dscp,
2050 'exceed_action_type': exceed_action_type,
2051 'exceed_dscp': exceed_dscp,
2052 'violate_action_type': violate_action_type,
2053 'violate_dscp': violate_dscp})
2054
2055 def ip_punt_police(self,
2056 policer_index,
2057 is_ip6=0,
2058 is_add=1):
2059 return self.api(self.papi.ip_punt_police,
2060 {'policer_index': policer_index,
2061 'is_add': is_add,
2062 'is_ip6': is_ip6})
2063
2064 def ip_punt_redirect(self,
2065 rx_sw_if_index,
2066 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002067 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002068 is_add=1):
2069 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002070 {'punt': {'rx_sw_if_index': rx_sw_if_index,
2071 'tx_sw_if_index': tx_sw_if_index,
2072 'nh': address},
2073 'is_add': is_add})
2074
2075 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
2076 return self.api(self.papi.ip_punt_redirect_dump,
2077 {'sw_if_index': sw_if_index,
2078 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002079
2080 def bier_table_add_del(self,
2081 bti,
2082 mpls_label,
2083 is_add=1):
2084 """ BIER Table add/del """
2085 return self.api(
2086 self.papi.bier_table_add_del,
2087 {'bt_tbl_id': {"bt_set": bti.set_id,
2088 "bt_sub_domain": bti.sub_domain_id,
2089 "bt_hdr_len_id": bti.hdr_len_id},
2090 'bt_label': mpls_label,
2091 'bt_is_add': is_add})
2092
2093 def bier_table_dump(self):
2094 return self.api(self.papi.bier_table_dump, {})
2095
2096 def bier_route_add_del(self,
2097 bti,
2098 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002099 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002100 is_add=1,
2101 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07002102 """ BIER Route add/del """
2103 return self.api(
2104 self.papi.bier_route_add_del,
2105 {'br_tbl_id': {"bt_set": bti.set_id,
2106 "bt_sub_domain": bti.sub_domain_id,
2107 "bt_hdr_len_id": bti.hdr_len_id},
2108 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002109 'br_n_paths': len(paths),
2110 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002111 'br_is_add': is_add,
2112 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002113
2114 def bier_route_dump(self, bti):
2115 return self.api(
2116 self.papi.bier_route_dump,
2117 {'br_tbl_id': {"bt_set": bti.set_id,
2118 "bt_sub_domain": bti.sub_domain_id,
2119 "bt_hdr_len_id": bti.hdr_len_id}})
2120
2121 def bier_imp_add(self,
2122 bti,
2123 src,
2124 ibytes,
2125 is_add=1):
2126 """ BIER Imposition Add """
2127 return self.api(
2128 self.papi.bier_imp_add,
2129 {'bi_tbl_id': {"bt_set": bti.set_id,
2130 "bt_sub_domain": bti.sub_domain_id,
2131 "bt_hdr_len_id": bti.hdr_len_id},
2132 'bi_src': src,
2133 'bi_n_bytes': len(ibytes),
2134 'bi_bytes': ibytes})
2135
2136 def bier_imp_del(self, bi_index):
2137 """ BIER Imposition del """
2138 return self.api(
2139 self.papi.bier_imp_del,
2140 {'bi_index': bi_index})
2141
2142 def bier_imp_dump(self):
2143 return self.api(self.papi.bier_imp_dump, {})
2144
2145 def bier_disp_table_add_del(self,
2146 bdti,
2147 is_add=1):
2148 """ BIER Disposition Table add/del """
2149 return self.api(
2150 self.papi.bier_disp_table_add_del,
2151 {'bdt_tbl_id': bdti,
2152 'bdt_is_add': is_add})
2153
2154 def bier_disp_table_dump(self):
2155 return self.api(self.papi.bier_disp_table_dump, {})
2156
2157 def bier_disp_entry_add_del(self,
2158 bdti,
2159 bp,
2160 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002161 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002162 next_hop,
2163 next_hop_tbl_id=0,
2164 next_hop_rpf_id=~0,
2165 next_hop_is_ip4=1,
2166 is_add=1):
2167 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002168 lstack = []
2169 while (len(lstack) < 16):
2170 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002171 return self.api(
2172 self.papi.bier_disp_entry_add_del,
2173 {'bde_tbl_id': bdti,
2174 'bde_bp': bp,
2175 'bde_payload_proto': payload_proto,
2176 'bde_n_paths': 1,
2177 'bde_paths': [{'next_hop': next_hop,
2178 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002179 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002180 'rpf_id': next_hop_rpf_id,
2181 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002182 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002183 'bde_is_add': is_add})
2184
2185 def bier_disp_entry_dump(self, bdti):
2186 return self.api(
2187 self.papi.bier_disp_entry_dump,
2188 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002189
Florin Coras3ea6ce22017-12-11 09:09:05 -08002190 def session_enable_disable(self, is_enabled):
2191 return self.api(
2192 self.papi.session_enable_disable,
2193 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002194
2195 def ipsec_spd_add_del(self, spd_id, is_add=1):
2196 """ SPD add/del - Wrapper to add or del ipsec SPD
2197 Sample CLI : 'ipsec spd add 1'
2198
2199 :param spd_id - SPD ID to be created in the vpp . mandatory
2200 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2201 optional
2202 :returns: reply from the API
2203 """
2204 return self.api(
2205 self.papi.ipsec_spd_add_del, {
2206 'spd_id': spd_id, 'is_add': is_add})
2207
Neale Ranns311124e2019-01-24 04:52:25 -08002208 def ipsec_spds_dump(self):
2209 return self.api(self.papi.ipsec_spds_dump, {})
2210
“mystarrocks”23f0c452017-12-11 07:11:51 -08002211 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2212 """ IPSEC interface SPD add/del - \
2213 Wrapper to associate/disassociate SPD to interface in VPP
2214 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2215
2216 :param spd_id - SPD ID to associate with the interface . mandatory
2217 :param sw_if_index - Interface Index which needs to ipsec \
2218 association mandatory
2219 :param is_add - add(1) or del(0) association with interface \
2220 (Default 1 - add) . optional
2221 :returns: reply from the API
2222 """
2223 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02002224 self.papi.ipsec_interface_add_del_spd,
2225 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002226
Neale Ranns311124e2019-01-24 04:52:25 -08002227 def ipsec_spd_interface_dump(self, spd_index=None):
2228 return self.api(self.papi.ipsec_spd_interface_dump,
2229 {'spd_index': spd_index if spd_index else 0,
2230 'spd_index_valid': 1 if spd_index else 0})
2231
Neale Ranns17dcec02019-01-09 21:22:20 -08002232 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002233 sad_id,
2234 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02002235 integrity_algorithm,
2236 integrity_key,
2237 crypto_algorithm,
2238 crypto_key,
2239 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002240 tunnel_src_address='',
2241 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08002242 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002243 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08002244 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08002245 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02002246 :param sad_id: security association ID
2247 :param spi: security param index of the SA in decimal
2248 :param integrity_algorithm:
2249 :param integrity_key:
2250 :param crypto_algorithm:
2251 :param crypto_key:
2252 :param protocol: AH(0) or ESP(1) protocol
2253 :param tunnel_src_address: tunnel mode outer src address
2254 :param tunnel_dst_address: tunnel mode outer dst address
2255 :param is_add:
2256 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08002257 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
2258 crypto and ipsec algorithms
2259 """
2260 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002261 self.papi.ipsec_sad_entry_add_del,
2262 {
2263 'is_add': is_add,
2264 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002265 {
2266 'sad_id': sad_id,
2267 'spi': spi,
2268 'tunnel_src': tunnel_src_address,
2269 'tunnel_dst': tunnel_dst_address,
2270 'protocol': protocol,
2271 'integrity_algorithm': integrity_algorithm,
2272 'integrity_key': {
2273 'length': len(integrity_key),
2274 'data': integrity_key,
2275 },
2276 'crypto_algorithm': crypto_algorithm,
2277 'crypto_key': {
2278 'length': len(crypto_key),
2279 'data': crypto_key,
2280 },
2281 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002282 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01002283 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002284 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08002285
Neale Ranns311124e2019-01-24 04:52:25 -08002286 def ipsec_sa_dump(self, sa_id=None):
2287 return self.api(self.papi.ipsec_sa_dump,
2288 {'sa_id': sa_id if sa_id else 0xffffffff})
2289
Neale Ranns17dcec02019-01-09 21:22:20 -08002290 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002291 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02002292 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002293 local_address_start,
2294 local_address_stop,
2295 remote_address_start,
2296 remote_address_stop,
2297 local_port_start=0,
2298 local_port_stop=65535,
2299 remote_port_start=0,
2300 remote_port_stop=65535,
2301 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002302 policy=0,
2303 priority=100,
2304 is_outbound=1,
2305 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02002306 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002307 is_ip_any=0):
2308 """ IPSEC policy SPD add/del -
2309 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02002310 :param spd_id: SPD ID for the policy
2311 :param local_address_start: local-ip-range start address
2312 :param local_address_stop : local-ip-range stop address
2313 :param remote_address_start: remote-ip-range start address
2314 :param remote_address_stop : remote-ip-range stop address
2315 :param local_port_start: (Default value = 0)
2316 :param local_port_stop: (Default value = 65535)
2317 :param remote_port_start: (Default value = 0)
2318 :param remote_port_stop: (Default value = 65535)
2319 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
2320 :param sa_id: Security Association ID for mapping it to SPD
2321 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
2322 (Default value = 0)
2323 :param priority: value for the spd action (Default value = 100)
2324 :param is_outbound: flag for inbound(0) or outbound(1)
2325 (Default value = 1)
2326 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08002327 """
2328 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002329 self.papi.ipsec_spd_entry_add_del,
2330 {
2331 'is_add': is_add,
2332 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002333 {
2334 'spd_id': spd_id,
2335 'sa_id': sa_id,
2336 'local_address_start': local_address_start,
2337 'local_address_stop': local_address_stop,
2338 'remote_address_start': remote_address_start,
2339 'remote_address_stop': remote_address_stop,
2340 'local_port_start': local_port_start,
2341 'local_port_stop': local_port_stop,
2342 'remote_port_start': remote_port_start,
2343 'remote_port_stop': remote_port_stop,
2344 'protocol': protocol,
2345 'policy': policy,
2346 'priority': priority,
2347 'is_outbound': is_outbound,
2348 'is_ip_any': is_ip_any
2349 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002350 })
Florin Corasb795bd02017-12-14 11:30:48 -08002351
Neale Ranns311124e2019-01-24 04:52:25 -08002352 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
2353 return self.api(self.papi.ipsec_spd_dump,
2354 {'spd_id': spd_id,
2355 'sa_id': sa_id})
2356
Klement Sekera31da2e32018-06-24 22:49:55 +02002357 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
2358 remote_spi, crypto_alg, local_crypto_key,
2359 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002360 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02002361 anti_replay=1, renumber=0, show_instance=0):
2362 return self.api(
2363 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002364 {
2365 'local_ip': local_ip,
2366 'remote_ip': remote_ip,
2367 'local_spi': local_spi,
2368 'remote_spi': remote_spi,
2369 'crypto_alg': crypto_alg,
2370 'local_crypto_key_len': len(local_crypto_key),
2371 'local_crypto_key': local_crypto_key,
2372 'remote_crypto_key_len': len(remote_crypto_key),
2373 'remote_crypto_key': remote_crypto_key,
2374 'integ_alg': integ_alg,
2375 'local_integ_key_len': len(local_integ_key),
2376 'local_integ_key': local_integ_key,
2377 'remote_integ_key_len': len(remote_integ_key),
2378 'remote_integ_key': remote_integ_key,
2379 'is_add': is_add,
2380 'esn': esn,
2381 'anti_replay': anti_replay,
2382 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002383 'show_instance': show_instance,
2384 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002385 })
Klement Sekera31da2e32018-06-24 22:49:55 +02002386
Neale Rannsf05e7322019-03-29 20:23:58 +00002387 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
2388 sa_out, sa_in, is_add=1):
2389 return self.api(self.papi.ipsec_gre_tunnel_add_del,
2390 {
2391 'is_add': is_add,
2392 'tunnel': {
2393 'src': local_ip,
2394 'dst': remote_ip,
2395 'local_sa_id': sa_out,
2396 'remote_sa_id': sa_in
2397 }
2398 })
2399
Klement Sekerab4d30532018-11-08 13:00:02 +01002400 def ipsec_select_backend(self, protocol, index):
2401 return self.api(self.papi.ipsec_select_backend,
2402 {'protocol': protocol, 'index': index})
2403
2404 def ipsec_backend_dump(self):
2405 return self.api(self.papi.ipsec_backend_dump, {})
2406
Ole Troane1ade682019-03-04 23:55:43 +01002407 def app_namespace_add_del(self,
2408 namespace_id,
2409 ip4_fib_id=0,
2410 ip6_fib_id=0,
2411 sw_if_index=0xFFFFFFFF,
2412 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08002413 return self.api(
2414 self.papi.app_namespace_add_del,
2415 {'secret': secret,
2416 'sw_if_index': sw_if_index,
2417 'ip4_fib_id': ip4_fib_id,
2418 'ip6_fib_id': ip6_fib_id,
2419 'namespace_id': namespace_id,
2420 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02002421
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002422 def punt_socket_register(self, port, pathname, protocol=0x11,
2423 header_version=1, is_ip4=1):
2424 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02002425 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002426 {'header_version': header_version,
2427 'punt': {'ipv': is_ip4,
2428 'l4_protocol': protocol,
2429 'l4_port': port},
2430 'pathname': pathname})
2431
2432 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
2433 """ Unregister punt socket """
2434 return self.api(self.papi.punt_socket_deregister,
2435 {'punt': {'ipv': is_ip4,
2436 'l4_protocol': protocol,
2437 'l4_port': port}})
2438
2439 def punt_socket_dump(self, is_ip6=1):
2440 """ Dump punt socket"""
2441 return self.api(self.papi.punt_socket_dump,
2442 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02002443
Neale Ranns4ba67722019-02-28 11:11:39 +00002444 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002445 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07002446 """ GBP endpoint Add """
2447 return self.api(self.papi.gbp_endpoint_add,
2448 {'endpoint': {
2449 'sw_if_index': sw_if_index,
2450 'ips': ips,
2451 'n_ips': len(ips),
2452 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00002453 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002454 'flags': flags,
2455 'tun': {
2456 'src': tun_src,
2457 'dst': tun_dst,
2458 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002459
2460 def gbp_endpoint_del(self, handle):
2461 """ GBP endpoint Del """
2462 return self.api(self.papi.gbp_endpoint_del,
2463 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002464
2465 def gbp_endpoint_dump(self):
2466 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002467 return self.api(self.papi.gbp_endpoint_dump,
2468 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002469
Neale Ranns4ba67722019-02-28 11:11:39 +00002470 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002471 rd, uplink_sw_if_index,
2472 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002473 """ GBP endpoint group Add """
2474 return self.api(self.papi.gbp_endpoint_group_add,
2475 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002476 {
2477 'uplink_sw_if_index': uplink_sw_if_index,
2478 'bd_id': bd,
2479 'rd_id': rd,
2480 'vnid': vnid,
2481 'sclass': sclass,
2482 'retention': retention
2483 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002484
Neale Ranns4ba67722019-02-28 11:11:39 +00002485 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002486 """ GBP endpoint group Del """
2487 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002488 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002489
Neale Rannsc29c0af2018-11-07 04:21:12 -08002490 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002491 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002492 uu_fwd_sw_if_index,
2493 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002494 """ GBP bridge-domain Add """
2495 return self.api(self.papi.gbp_bridge_domain_add,
2496 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002497 {
2498 'flags': flags,
2499 'bvi_sw_if_index': bvi_sw_if_index,
2500 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2501 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2502 'bd_id': bd_id
2503 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002504
2505 def gbp_bridge_domain_del(self, bd_id):
2506 """ GBP bridge-domain Del """
2507 return self.api(self.papi.gbp_bridge_domain_del,
2508 {'bd_id': bd_id})
2509
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002510 def gbp_route_domain_add(self, rd_id,
2511 ip4_table_id,
2512 ip6_table_id,
2513 ip4_uu_sw_if_index,
2514 ip6_uu_sw_if_index):
2515 """ GBP route-domain Add """
2516 return self.api(self.papi.gbp_route_domain_add,
2517 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002518 {
2519 'ip4_table_id': ip4_table_id,
2520 'ip6_table_id': ip6_table_id,
2521 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2522 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2523 'rd_id': rd_id
2524 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002525
2526 def gbp_route_domain_del(self, rd_id):
2527 """ GBP route-domain Del """
2528 return self.api(self.papi.gbp_route_domain_del,
2529 {'rd_id': rd_id})
2530
Neale Ranns4ba67722019-02-28 11:11:39 +00002531 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002532 """ GBP recirc Add/Del """
2533 return self.api(self.papi.gbp_recirc_add_del,
2534 {'is_add': is_add,
2535 'recirc': {
2536 'is_ext': is_ext,
2537 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002538 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002539
2540 def gbp_recirc_dump(self):
2541 """ GBP recirc Dump """
2542 return self.api(self.papi.gbp_recirc_dump, {})
2543
Neale Rannsb6a47952018-11-21 05:44:35 -08002544 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2545 """ GBP recirc Add/Del """
2546 return self.api(self.papi.gbp_ext_itf_add_del,
2547 {'is_add': is_add,
2548 'ext_itf': {
2549 'sw_if_index': sw_if_index,
2550 'bd_id': bd_id,
2551 'rd_id': rd_id}})
2552
2553 def gbp_ext_itf_dump(self):
2554 """ GBP recirc Dump """
2555 return self.api(self.papi.gbp_ext_itf_dump, {})
2556
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002557 def gbp_subnet_add_del(self, is_add, rd_id,
2558 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002559 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002560 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002561 """ GBP Subnet Add/Del """
2562 return self.api(self.papi.gbp_subnet_add_del,
2563 {'is_add': is_add,
2564 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002565 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002566 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002567 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002568 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002569 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002570
2571 def gbp_subnet_dump(self):
2572 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002573 return self.api(self.papi.gbp_subnet_dump,
2574 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002575
Neale Ranns4ba67722019-02-28 11:11:39 +00002576 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002577 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002578 """ GBP contract Add/Del """
2579 return self.api(self.papi.gbp_contract_add_del,
2580 {'is_add': is_add,
2581 'contract': {
2582 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002583 'sclass': sclass,
2584 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002585 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002586 'rules': rules,
2587 'n_ether_types': len(allowed_ethertypes),
2588 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002589
2590 def gbp_contract_dump(self):
2591 """ GBP contract Dump """
2592 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002593
Neale Ranns8da9fc62019-03-04 14:08:11 -08002594 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002595 """ GBP VXLAN tunnel add """
2596 return self.api(self.papi.gbp_vxlan_tunnel_add,
2597 {
2598 'tunnel': {
2599 'vni': vni,
2600 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002601 'bd_rd_id': bd_rd_id,
2602 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002603 }
2604 })
2605
2606 def gbp_vxlan_tunnel_del(self, vni):
2607 """ GBP VXLAN tunnel del """
2608 return self.api(self.papi.gbp_vxlan_tunnel_del,
2609 {
2610 'vni': vni,
2611 })
2612
2613 def gbp_vxlan_tunnel_dump(self):
2614 """ GBP VXLAN tunnel add/del """
2615 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2616
Neale Ranns039cbfe2018-02-27 03:45:38 -08002617 def qos_egress_map_update(self, id, outputs):
2618 """ QOS egress map update """
2619 return self.api(self.papi.qos_egress_map_update,
2620 {'map_id': id,
2621 'rows': outputs})
2622
2623 def qos_egress_map_delete(self, id):
2624 """ QOS egress map delete """
2625 return self.api(self.papi.qos_egress_map_delete,
2626 {'map_id': id})
2627
2628 def qos_mark_enable_disable(self, sw_if_index,
2629 output_source,
2630 map_id,
2631 enable):
2632 """ QOS Mark Enable/Disable """
2633 return self.api(self.papi.qos_mark_enable_disable,
2634 {'map_id': map_id,
2635 'sw_if_index': sw_if_index,
2636 'output_source': output_source,
2637 'enable': enable})
2638
Neale Ranns947ea622018-06-07 23:48:20 -07002639 def igmp_enable_disable(self, sw_if_index, enable, host):
2640 """ Enable/disable IGMP on a given interface """
2641 return self.api(self.papi.igmp_enable_disable,
2642 {'enable': enable,
2643 'mode': host,
2644 'sw_if_index': sw_if_index})
2645
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002646 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2647 """ Add/del IGMP proxy device """
2648 return self.api(self.papi.igmp_proxy_device_add_del,
2649 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2650 'add': add})
2651
2652 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2653 """ Add/del interface to/from IGMP proxy device """
2654 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2655 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2656 'add': add})
2657
Neale Ranns947ea622018-06-07 23:48:20 -07002658 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002659 """ Listen for new (S,G) on specified interface
2660
2661 :param enable: add/del
2662 :param sw_if_index: interface sw index
2663 :param saddr: source ip4 addr
2664 :param gaddr: group ip4 addr
2665 """
2666 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002667 {
2668 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002669 {
2670 'filter': filter,
2671 'sw_if_index': sw_if_index,
2672 'n_srcs': len(saddrs),
2673 'saddrs': saddrs,
2674 'gaddr': gaddr
2675 }
Neale Ranns947ea622018-06-07 23:48:20 -07002676 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002677
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002678 def igmp_clear_interface(self, sw_if_index):
2679 """ Remove all (S,G)s from specified interface
2680 doesn't send IGMP report!
2681 """
2682 return self.api(
2683 self.papi.igmp_clear_interface, {
2684 'sw_if_index': sw_if_index})
2685
2686 def want_igmp_events(self, enable=1):
2687 return self.api(self.papi.want_igmp_events, {'enable': enable,
2688 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002689
2690 def bond_create(
2691 self,
2692 mode,
2693 lb,
2694 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002695 mac_address='',
2696 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002697 """
2698 :param mode: mode
2699 :param lb: load balance
2700 :param use_custom_mac: use custom mac
2701 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002702 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002703 """
2704 return self.api(
2705 self.papi.bond_create,
2706 {'mode': mode,
2707 'lb': lb,
2708 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002709 'mac_address': mac_address,
2710 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002711 })
2712
Neale Ranns17ff3c12018-07-04 10:24:24 -07002713 def pipe_delete(self, parent_sw_if_index):
2714 return self.api(self.papi.pipe_delete,
2715 {'parent_sw_if_index': parent_sw_if_index})
2716
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002717 def memif_create(
2718 self,
2719 role,
2720 mode,
2721 rx_queues=None,
2722 tx_queues=None,
2723 _id=None,
2724 socket_id=None,
2725 secret=None,
2726 ring_size=None,
2727 buffer_size=None,
2728 hw_addr=None):
2729 return self.api(self.papi.memif_create,
2730 {'role': role,
2731 'mode': mode,
2732 'rx_queues': rx_queues,
2733 'tx_queues': tx_queues,
2734 'id': _id,
2735 'socket_id': socket_id,
2736 'secret': secret,
2737 'ring_size': ring_size,
2738 'buffer_size': buffer_size,
2739 'hw_addr': hw_addr})
2740
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002741 def svs_table_add_del(self, af, table_id, is_add=1):
2742 return self.api(self.papi.svs_table_add_del,
2743 {
2744 'table_id': table_id,
2745 'is_add': is_add,
2746 'af': af,
2747 })
2748
2749 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2750 return self.api(self.papi.svs_route_add_del,
2751 {
2752 'table_id': table_id,
2753 'source_table_id': src_table_id,
2754 'prefix': prefix,
2755 'is_add': is_add,
2756 })
2757
2758 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2759 return self.api(self.papi.svs_enable_disable,
2760 {
2761 'af': af,
2762 'table_id': table_id,
2763 'sw_if_index': sw_if_index,
2764 'is_enable': is_enable,
2765 })