blob: 86f13d1c54e50275c9f81c48de648e3aae8262c3 [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, },
Paul Vinciguerra9a29f792019-04-30 20:44:25 -070056 'bvi_create': {'user_instance': 4294967295, },
57 'bvi_delete': {},
Ole Troan9a475372019-03-05 16:58:24 +010058 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
59 'nbuckets': 2, 'memory_size': 2097152,
60 'next_table_index': 4294967295,
61 'miss_next_index': 4294967295, },
62 'dhcp6_client_enable_disable': {'enable': 1, },
63 'dhcp6_clients_enable_disable': {'enable': 1, },
64 'dhcp6_pd_client_enable_disable': {'enable': 1, },
65 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
66 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
67 'dhcp_proxy_config': {'is_add': 1, },
68 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
69 'dslite_add_del_pool_addr_range': {'is_add': 1, },
70 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
71 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
72 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000073 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010074 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
75 'decap_next_index': 4294967295, },
76 'input_acl_set_interface': {'ip4_table_index': 4294967295,
77 'ip6_table_index': 4294967295,
78 'l2_table_index': 4294967295, },
79 'ip6_add_del_address_using_prefix': {'is_add': 1, },
80 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
81 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
82 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
83 'next_hop_id': 4294967295,
84 'classify_table_index': 4294967295, 'is_add': 1, },
85 'ip_mroute_add_del': {'is_add': 1, },
86 'ip_neighbor_add_del': {'is_add': 1, },
87 'ip_punt_police': {'is_add': 1, },
88 'ip_punt_redirect': {'is_add': 1, },
89 'ip_table_add_del': {'is_add': 1, },
90 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
91 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
92 'ipsec_interface_add_del_spd': {'is_add': 1, },
93 'ipsec_sad_entry_add_del': {'is_add': 1, },
94 'ipsec_spd_add_del': {'is_add': 1, },
95 'ipsec_spd_dump': {'sa_id': 4294967295, },
96 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
97 'remote_port_stop': 65535, 'priority': 100,
98 'is_outbound': 1,
99 'is_add': 1, },
100 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
101 'l2_emulation': {'enable': 1, },
102 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700103 'lb_conf': {'sticky_buckets_per_core': 4294967295,
104 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +0100105 'lisp_add_del_adjacency': {'is_add': 1, },
106 'lisp_add_del_local_eid': {'is_add': 1, },
107 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
108 'lisp_add_del_locator_set': {'is_add': 1, },
109 'lisp_add_del_remote_mapping': {'is_add': 1, },
110 'macip_acl_add_replace': {'acl_index': 4294967295, },
111 'macip_acl_dump': {'acl_index': 4294967295, },
112 'macip_acl_interface_add_del': {'is_add': 1, },
113 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +0100114 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
115 'mr_next_hop_weight': 1,
116 'mr_next_hop_via_label': 1048576,
117 'mr_is_add': 1,
118 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100119 'mpls_table_add_del': {'is_add': 1, },
120 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
121 'next_hop_weight': 1,
122 'next_hop_via_label': 1048576,
123 'is_add': 1, },
124 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
125 'nat44_add_del_address_range': {'is_add': 1, 'vrf_id': 4294967295, },
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800126 'nat44_add_del_identity_mapping': {'ip': b'0', 'sw_if_index': 4294967295,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200127 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100128 'nat44_add_del_interface_addr': {'is_add': 1, },
129 'nat44_add_del_lb_static_mapping': {'is_add': 1, },
130 'nat44_add_del_static_mapping': {'external_sw_if_index': 4294967295,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200131 'is_add': 1, },
132 'nat44_interface_add_del_feature': {'is_add': 1, },
133 'nat44_interface_add_del_output_feature': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100134 'nat44_lb_static_mapping_add_del_local': {'is_add': 1, },
Filip Vargadd1e3e72019-04-15 18:52:43 +0200135 'nat64_add_del_interface': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100136 'nat64_add_del_interface_addr': {'is_add': 1, },
137 'nat64_add_del_pool_addr_range': {'vrf_id': 4294967295, 'is_add': 1, },
138 'nat64_add_del_prefix': {'is_add': 1, },
139 'nat64_add_del_static_bib': {'is_add': 1, },
140 'nat64_bib_dump': {'protocol': 255, },
141 'nat64_st_dump': {'protocol': 255, },
Filip Vargadd1e3e72019-04-15 18:52:43 +0200142 'nat66_add_del_interface': {'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100143 'nat66_add_del_static_mapping': {'is_add': 1, },
144 'nat_det_add_del_map': {'is_add': 1, },
145 'nat_ha_resync': {'want_resync_event': 1, },
146 'nat_ha_set_failover': {'refresh': 10, },
147 'nat_ha_set_listener': {'path_mtu': 512, },
148 'nat_ipfix_enable_disable': {'domain_id': 1, 'src_port': 4739,
149 'enable': 1, },
150 'nat_set_mss_clamping': {'mss_value': 1500, },
151 'nat_set_reass': {'timeout': 2, 'max_reass': 1024, 'max_frag': 5, },
152 'nat_set_timeouts': {'udp': 300, 'tcp_established': 7440,
153 'tcp_transitory': 240, 'icmp': 60, },
154 'output_acl_set_interface': {'ip4_table_index': 4294967295,
155 'ip6_table_index': 4294967295,
156 'l2_table_index': 4294967295, },
157 'pppoe_add_del_session': {'is_add': 1, },
158 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
159 'proxy_arp_add_del': {'is_add': 1, },
160 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
161 'punt_socket_register': {'protocol': 17, 'header_version': 1,
162 'is_ip4': 1, },
163 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, },
164 'punt_socket_dump': {'is_ip6': 1, },
165 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
166 'proto': 1, },
167 'set_ipfix_exporter': {'collector_port': 4739, },
168 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
169 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
170 'svs_enable_disable': {'is_enable': 1, },
171 'svs_route_add_del': {'is_add': 1, },
172 'svs_table_add_del': {'is_add': 1, },
173 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700174 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100175 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
176 'pref_lifetime': 4294967295, },
177 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
178 'sw_interface_set_l2_bridge': {'enable': 1, },
179 'sw_interface_set_mpls_enable': {'enable': 1, },
180 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
181 'sw_interface_set_unnumbered': {'is_add': 1, },
182 'sw_interface_span_enable_disable': {'state': 1, },
183 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
184 'decap_next_index': 4294967295,
185 'instance': 4294967295, },
186 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
187 'instance': 4294967295, },
188 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
189 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
190 'protocol': 3, },
191 'want_bfd_events': {'enable_disable': 1, },
192 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
193 'want_dhcp6_reply_events': {'enable_disable': 1, },
194 'want_igmp_events': {'enable': 1, },
195 'want_interface_events': {'enable_disable': 1, },
196 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
197 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
198 'want_ip6_ra_events': {'enable_disable': 1, },
199 'want_l2_macs_events': {'enable_disable': 1, },
200}
Ole Troanf159f582019-02-28 20:20:47 +0100201
Matus Fabianb4515b42018-11-19 04:25:32 -0800202
Klement Sekera73884482017-02-23 09:26:30 +0100203class UnexpectedApiReturnValueError(Exception):
204 """ exception raised when the API return value is unexpected """
205 pass
206
207
Klement Sekeraf62ae122016-10-11 11:47:09 +0200208class VppPapiProvider(object):
209 """VPP-api provider using vpp-papi
210
211 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200212 """
213
Klement Sekerae0545ef2017-01-25 08:00:40 +0100214 _zero, _negative = range(2)
215
Klement Sekera611864f2018-09-26 11:19:00 +0200216 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800217 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200218 self.name = name
219 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100220 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100221 self._expect_api_retval = self._zero
222 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100223
Klement Sekerab8c72a42018-11-08 11:21:39 +0100224 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +0100225
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800226 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
227 if 'VPP_API_DIR' not in os.environ:
228 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
229
Ole Troan4ff09ae2019-04-15 11:27:22 +0200230 use_socket = False
231 try:
232 if os.environ['SOCKET'] == '1':
233 use_socket = True
234 except:
235 pass
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800236 self.vpp = VPP(logger=test_class.logger,
Ole Troan4ff09ae2019-04-15 11:27:22 +0200237 read_timeout=read_timeout,
238 use_socket=use_socket,
239 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100240 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200241
Klement Sekerae0545ef2017-01-25 08:00:40 +0100242 def __enter__(self):
243 return self
244
Klement Sekera7d6afb32018-11-08 11:52:04 +0100245 def assert_negative_api_retval(self):
246 """ Expect API failure - used with with, e.g.:
247 with self.vapi.assert_negative_api_retval():
248 self.vapi.<api call expected to fail>
249 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100250 self._expect_stack.append(self._expect_api_retval)
251 self._expect_api_retval = self._negative
252 return self
253
Klement Sekera7d6afb32018-11-08 11:52:04 +0100254 def assert_zero_api_retval(self):
255 """ Expect API success - used with with, e.g.:
256 with self.vapi.assert_negative_api_retval():
257 self.vapi.<api call expected to succeed>
258
259 note: this is useful only inside another with block
260 as success is the default expected value
261 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100262 self._expect_stack.append(self._expect_api_retval)
263 self._expect_api_retval = self._zero
264 return self
265
266 def __exit__(self, exc_type, exc_value, traceback):
267 self._expect_api_retval = self._expect_stack.pop()
268
Klement Sekeraf62ae122016-10-11 11:47:09 +0200269 def register_hook(self, hook):
270 """Replace hook registration with new hook
271
272 :param hook:
273
274 """
275 self.hook = hook
276
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200277 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100278 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200279 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100280 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200281 return e
282
283 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100284 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100285 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100286 self.test_class.logger.debug("Expecting event '%s' within %ss",
287 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300288 else:
289 self.test_class.logger.debug("Expecting event within %ss",
290 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100291 if self._events:
292 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200293 limit = time.time() + timeout
294 while time.time() < limit:
295 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100296 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200297 if name and type(e).__name__ != name:
298 raise Exception(
299 "Unexpected event received: %s, expected: %s" %
300 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100301 self.test_class.logger.debug("Returning event %s:%s" %
302 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200303 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700304 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200305 raise Exception("Event did not occur within timeout")
306
307 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100308 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200309 # FIXME use the name instead of relying on type(e).__name__ ?
310 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100311 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200312 self._events.append(event)
313
Ole Troanf159f582019-02-28 20:20:47 +0100314 def factory(self, name, apifn):
315 def f(*a, **ka):
316 fields = apifn._func.msg.fields
317
318 # add positional and kw arguments
319 d = ka
320 for i, o in enumerate(fields[3:]):
321 try:
322 d[o] = a[i]
323 except:
324 break
325
326 # Default override
327 if name in defaultmapping:
328 for k, v in iteritems(defaultmapping[name]):
329 if k in d:
330 continue
331 d[k] = v
332 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100333
Ole Troanf159f582019-02-28 20:20:47 +0100334 return f
335
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800336 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100337 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800338 method = super(VppPapiProvider, self).__getattribute__(name)
339 except AttributeError:
340 method = self.factory(name, getattr(self.papi, name))
341 # lazily load the method so we don't need to call factory
342 # again for this name.
343 setattr(self, name, method)
344 return method
Ole Troanf159f582019-02-28 20:20:47 +0100345
Klement Sekeraf62ae122016-10-11 11:47:09 +0200346 def connect(self):
347 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100348 self.vpp.connect(self.name, self.shm_prefix)
349 self.papi = self.vpp.api
350 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200351
352 def disconnect(self):
353 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100354 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200355
356 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100357 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200358 Call the appropriate hooks before and after the API call
359
360 :param api_fn: API function to call
361 :param api_args: tuple of API function arguments
362 :param expected_retval: Expected return value (Default value = 0)
363 :returns: reply from the API
364
365 """
366 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100367 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100368 if self._expect_api_retval == self._negative:
369 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100370 msg = "API call passed unexpectedly: expected negative " \
371 "return value instead of %d in %s" % \
372 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100373 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100374 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100375 elif self._expect_api_retval == self._zero:
376 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100377 msg = "API call failed, expected %d return value instead " \
378 "of %d in %s" % (expected_retval, reply.retval,
379 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100380 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100381 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100382 else:
383 raise Exception("Internal error, unexpected value for "
384 "self._expect_api_retval %s" %
385 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200386 self.hook.after_api(api_fn.__name__, api_args)
387 return reply
388
389 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100390 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200391
392 :param cli: CLI to execute
393 :returns: CLI output
394
395 """
396 self.hook.before_cli(cli)
397 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100398 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200399 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200400 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100401 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200402
Jan49c0fca2016-10-26 15:44:27 +0200403 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100404 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200405
406 :param cli: CLI to execute
407 :returns: CLI output
408 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600409 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200410
Neale Ranns37029302018-08-10 05:30:06 -0700411 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300412 return self.api(self.papi.want_ip4_arp_events,
413 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700414 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300415 'pid': os.getpid(), })
416
Neale Ranns37029302018-08-10 05:30:06 -0700417 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300418 return self.api(self.papi.want_ip6_nd_events,
419 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700420 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300421 'pid': os.getpid(), })
422
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100423 def want_ip6_ra_events(self, enable_disable=1):
424 return self.api(self.papi.want_ip6_ra_events,
425 {'enable_disable': enable_disable,
426 'pid': os.getpid(), })
427
428 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
429 mrc=0, mrd=0):
430 return self.api(self.papi.ip6nd_send_router_solicitation,
431 {'irt': irt,
432 'mrt': mrt,
433 'mrc': mrc,
434 'mrd': mrd,
435 'sw_if_index': sw_if_index})
436
Juraj Slobodab3f90502018-10-04 15:15:16 +0200437 def want_interface_events(self, enable_disable=1):
438 return self.api(self.papi.want_interface_events,
439 {'enable_disable': enable_disable,
440 'pid': os.getpid(), })
441
Ole Troane1ade682019-03-04 23:55:43 +0100442 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
443 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300444 return self.api(self.papi.want_l2_macs_events,
445 {'enable_disable': enable_disable,
446 'scan_delay': scan_delay,
447 'max_macs_in_event': max_macs_in_event,
448 'learn_limit': learn_limit,
449 'pid': os.getpid(), })
450
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200451 def want_dhcp6_reply_events(self, enable_disable=1):
452 return self.api(self.papi.want_dhcp6_reply_events,
453 {'enable_disable': enable_disable,
454 'pid': os.getpid()})
455
Juraj Sloboda81119e82018-05-25 14:02:20 +0200456 def want_dhcp6_pd_reply_events(self, enable_disable=1):
457 return self.api(self.papi.want_dhcp6_pd_reply_events,
458 {'enable_disable': enable_disable,
459 'pid': os.getpid()})
460
Juraj Sloboda81119e82018-05-25 14:02:20 +0200461 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
462 prefixes, server_index=0xFFFFFFFF,
463 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
464 ):
465 return self.api(self.papi.dhcp6_pd_send_client_message,
466 {'sw_if_index': sw_if_index,
467 'server_index': server_index,
468 'irt': irt,
469 'mrt': mrt,
470 'mrc': mrc,
471 'mrd': mrd,
472 'stop': stop,
473 'msg_type': msg_type,
474 'T1': T1,
475 'T2': T2,
476 'n_prefixes': len(prefixes),
477 'prefixes': prefixes})
478
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200479 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
480 enable=1):
481 return self.api(self.papi.dhcp6_client_enable_disable,
482 {'sw_if_index': sw_if_index,
483 'enable': enable})
484
Juraj Sloboda81119e82018-05-25 14:02:20 +0200485 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
486 enable=1):
487 return self.api(self.papi.dhcp6_pd_client_enable_disable,
488 {'sw_if_index': sw_if_index,
489 'prefix_group': prefix_group,
490 'enable': enable})
491
492 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
493 prefix_length, prefix_group,
494 is_add=1):
495 return self.api(self.papi.ip6_add_del_address_using_prefix,
496 {'sw_if_index': sw_if_index,
497 'prefix_group': prefix_group,
498 'address': address,
499 'prefix_length': prefix_length,
500 'is_add': is_add})
501
Neale Rannsc819fc62018-02-16 02:44:05 -0800502 def sw_interface_set_mac_address(self, sw_if_index, mac):
503 return self.api(self.papi.sw_interface_set_mac_address,
504 {'sw_if_index': sw_if_index,
505 'mac_address': mac})
506
Ole Troane1ade682019-03-04 23:55:43 +0100507 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200508 """Create p2p ethernet subinterface
509
510 :param sw_if_index: main (parent) interface
511 :param remote_mac: client (remote) mac address
512
513 """
514 return self.api(
515 self.papi.p2p_ethernet_add,
516 {'parent_if_index': sw_if_index,
517 'remote_mac': remote_mac,
518 'subif_id': subif_id})
519
Ole Troane1ade682019-03-04 23:55:43 +0100520 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200521 """Delete p2p ethernet subinterface
522
523 :param sw_if_index: main (parent) interface
524 :param remote_mac: client (remote) mac address
525
526 """
527 return self.api(
528 self.papi.p2p_ethernet_del,
529 {'parent_if_index': sw_if_index,
530 'remote_mac': remote_mac})
531
Klement Sekeraf62ae122016-10-11 11:47:09 +0200532 def create_vlan_subif(self, sw_if_index, vlan):
533 """
534
535 :param vlan:
536 :param sw_if_index:
537
538 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100539 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200540 {'sw_if_index': sw_if_index,
541 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200542
Matej Klotton0178d522016-11-04 11:11:44 +0100543 def create_loopback(self, mac=''):
544 """
545
546 :param mac: (Optional)
547 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100548 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200549 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100550
Matej Klotton0178d522016-11-04 11:11:44 +0100551 def ip_neighbor_add_del(self,
552 sw_if_index,
553 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700554 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100555 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700556 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100557 """ Add neighbor MAC to IPv4 or IPv6 address.
558
559 :param sw_if_index:
560 :param mac_address:
561 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100562 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700563 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100564 """
Matej Klotton0178d522016-11-04 11:11:44 +0100565 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100566 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700567 {
568 'is_add': is_add,
569 'neighbor': {
570 'sw_if_index': sw_if_index,
571 'flags': flags,
572 'mac_address': mac_address,
573 'ip_address': ip_address
574 }
575 }
Matej Klotton0178d522016-11-04 11:11:44 +0100576 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100577
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800578 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700579 low,
580 hi,
581 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800582 is_add=1):
583 """ Config Proxy Arp Range.
584
585 :param low_address: Start address in the rnage to Proxy for
586 :param hi_address: End address in the rnage to Proxy for
587 :param vrf_id: The VRF/table in which to proxy
588 """
589
590 return self.api(
591 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700592 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100593 {
594 'table_id': table_id,
595 'low': low,
596 'hi': hi,
597 },
598 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800599
600 def proxy_arp_intfc_enable_disable(self,
601 sw_if_index,
602 is_enable=1):
603 """ Enable/Disable an interface for proxy ARP requests
604
605 :param sw_if_index: Interface
606 :param enable_disable: Enable/Disable
607 """
608
609 return self.api(
610 self.papi.proxy_arp_intfc_enable_disable,
611 {'sw_if_index': sw_if_index,
612 'enable_disable': is_enable
613 }
614 )
615
Neale Ranns5a8844b2019-04-16 07:15:35 +0000616 def gre_tunnel_add_del(self,
617 src,
618 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000619 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500620 tunnel_type=0,
621 instance=0xFFFFFFFF,
622 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000623 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000624 """ Add a GRE tunnel
625
626 :param src_address:
627 :param dst_address:
628 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500629 :param tunnel_type: (Default value = 0)
630 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700631 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000632 :param is_add: (Default value = 1)
633 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000634 """
635
636 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000637 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200638 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000639 'tunnel':
640 {
641 'type': tunnel_type,
642 'instance': instance,
643 'src': src,
644 'dst': dst,
645 'outer_fib_id': outer_fib_id,
646 'session_id': session_id}
647 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000648 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000649
Neale Rannsd0df49f2018-08-08 01:06:40 -0700650 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700651 src_ip,
652 dst_ip,
653 src_port,
654 dst_port,
655 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800656 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800657 :param src_ip:
658 :param dst_ip:
659 :param src_port:
660 :param dst_port:
661 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800662 """
663
664 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700665 self.papi.udp_encap_add,
666 {
667 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700668 'src_ip': src_ip,
669 'dst_ip': dst_ip,
670 'src_port': src_port,
671 'dst_port': dst_port,
672 'table_id': table_id
673 }
674 })
675
Neale Ranns15002542017-09-10 04:39:11 -0700676 def mpls_table_add_del(
677 self,
678 table_id,
679 is_add=1):
680 """
681
682 :param table_id
683 :param is_add: (Default value = 1)
684
685 """
686
687 return self.api(
688 self.papi.mpls_table_add_del,
689 {'mt_table_id': table_id,
690 'mt_is_add': is_add})
691
Neale Rannsad422ed2016-11-02 14:20:04 +0000692 def mpls_ip_bind_unbind(
693 self,
694 label,
695 dst_address,
696 dst_address_length,
697 table_id=0,
698 ip_table_id=0,
699 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000700 is_bind=1):
701 """
702 """
703 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100704 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200705 {'mb_mpls_table_id': table_id,
706 'mb_label': label,
707 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200708 'mb_is_bind': is_bind,
709 'mb_is_ip4': is_ip4,
710 'mb_address_length': dst_address_length,
711 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000712
713 def mpls_tunnel_add_del(
714 self,
715 tun_sw_if_index,
716 next_hop_proto_is_ip4,
717 next_hop_address,
718 next_hop_sw_if_index=0xFFFFFFFF,
719 next_hop_table_id=0,
720 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200721 next_hop_n_out_labels=0,
722 next_hop_out_label_stack=[],
723 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000724 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800725 l2_only=0,
726 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000727 """
728
729 :param dst_address_length:
730 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
731 :param dst_address:
732 :param next_hop_address:
733 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
734 :param vrf_id: (Default value = 0)
735 :param lookup_in_vrf: (Default value = 0)
736 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000737 :param is_add: (Default value = 1)
738 :param is_drop: (Default value = 0)
739 :param is_ipv6: (Default value = 0)
740 :param is_local: (Default value = 0)
741 :param is_classify: (Default value = 0)
742 :param is_multipath: (Default value = 0)
743 :param is_resolve_host: (Default value = 0)
744 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000745 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800746 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000747
748 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000749 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100750 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200751 {'mt_sw_if_index': tun_sw_if_index,
752 'mt_is_add': is_add,
753 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800754 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200755 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
756 'mt_next_hop_weight': next_hop_weight,
757 'mt_next_hop': next_hop_address,
758 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
759 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
760 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700761 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200762 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800763
Matus Fabian2ba92e32017-08-21 07:05:03 -0700764 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -0800765 self,
766 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200767 is_add=1,
768 flags=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700769 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -0800770
771 :param sw_if_index: Software index of the interface
Matus Fabiande886752016-12-07 03:38:19 -0800772 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200773 :param flags: NAT_IS_INSIDE if inside else outside
Matus Fabiande886752016-12-07 03:38:19 -0800774 """
775 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700776 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200777 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200778 'flags': flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200779 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800780
Matus Fabian2ba92e32017-08-21 07:05:03 -0700781 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -0700782 self,
783 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200784 is_add=1,
785 flags=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700786 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700787
788 :param sw_if_index: Software index of the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700789 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200790 :param flags: NAT_IS_INSIDE if inside else outside
Matus Fabian93d84c92017-07-19 08:06:01 -0700791 """
792 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700793 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -0700794 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200795 'flags': flags,
Matus Fabian93d84c92017-07-19 08:06:01 -0700796 'sw_if_index': sw_if_index})
797
Matus Fabian2ba92e32017-08-21 07:05:03 -0700798 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -0800799 self,
800 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800801 external_ip=0,
802 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800803 local_port=0,
804 external_port=0,
Matus Fabiande886752016-12-07 03:38:19 -0800805 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800806 protocol=0,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200807 is_add=1,
808 flags=0,
809 tag=""):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700810 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -0800811
812 :param local_ip: Local IP address
813 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800814 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800815 :param local_port: Local port number (Default value = 0)
816 :param external_port: External port number (Default value = 0)
Matus Fabiande886752016-12-07 03:38:19 -0800817 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800818 :param protocol: IP protocol (Default value = 0)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200819 :param flags: NAT configuration flags
Ole Trøan89fec712019-04-23 12:38:35 +0000820 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200821 :param tag: Opaque string tag
Matus Fabiande886752016-12-07 03:38:19 -0800822 """
823 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700824 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200825 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200826 'flags': flags,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200827 'local_ip_address': local_ip,
828 'external_ip_address': external_ip,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200829 'protocol': protocol,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200830 'local_port': local_port,
831 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800832 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800833 'vrf_id': vrf_id,
Matus Fabian5f224992018-01-25 21:59:16 -0800834 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -0800835
Matus Fabianab7a8052017-11-28 04:29:41 -0800836 def nat44_add_del_identity_mapping(
837 self,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800838 ip=b'0',
Matus Fabianab7a8052017-11-28 04:29:41 -0800839 sw_if_index=0xFFFFFFFF,
840 port=0,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200841 flags=0,
Matus Fabianab7a8052017-11-28 04:29:41 -0800842 vrf_id=0,
843 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800844 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -0800845 is_add=1):
846 """Add/delete NAT44 identity mapping
847
848 :param ip: IP address (Default value = 0)
849 :param sw_if_index: Interface instead of IP address
850 :param port: Port number (Default value = 0)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200851 :param flags: NAT configuration flags (NAT_IS_ADDR_ONLY)
Matus Fabianab7a8052017-11-28 04:29:41 -0800852 :param vrf_id: VRF ID
853 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -0800854 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -0800855 :param is_add: 1 if add, 0 if delete (Default value = 1)
856 """
857 return self.api(
858 self.papi.nat44_add_del_identity_mapping,
859 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200860 'flags': flags,
Matus Fabianab7a8052017-11-28 04:29:41 -0800861 'ip_address': ip,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200862 'protocol': protocol,
Matus Fabianab7a8052017-11-28 04:29:41 -0800863 'port': port,
864 'sw_if_index': sw_if_index,
865 'vrf_id': vrf_id,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200866 'tag': tag})
Matus Fabianab7a8052017-11-28 04:29:41 -0800867
Matus Fabian2ba92e32017-08-21 07:05:03 -0700868 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -0800869 self,
870 first_ip_address,
871 last_ip_address,
872 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -0800873 vrf_id=0xFFFFFFFF,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200874 flags=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700875 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -0800876
877 :param first_ip_address: First IP address
878 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800879 :param vrf_id: VRF id for the address range
Matus Fabiande886752016-12-07 03:38:19 -0800880 :param is_add: 1 if add, 0 if delete (Default value = 1)
Filip Vargadd1e3e72019-04-15 18:52:43 +0200881 :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
Matus Fabiande886752016-12-07 03:38:19 -0800882 """
883 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700884 self.papi.nat44_add_del_address_range,
885 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200886 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800887 'vrf_id': vrf_id,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200888 'is_add': is_add,
889 'flags': flags})
Matus Fabiande886752016-12-07 03:38:19 -0800890
Ole Troane1ade682019-03-04 23:55:43 +0100891 def nat44_add_del_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -0800892 self,
893 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200894 flags=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -0800895 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700896 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -0800897
898 :param sw_if_index: Software index of the interface
Filip Vargadd1e3e72019-04-15 18:52:43 +0200899 :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
Matus Fabian8bf68e82017-01-12 04:24:35 -0800900 :param is_add: 1 if add, 0 if delete (Default value = 1)
901 """
Matus Fabianb932d262017-12-18 05:38:24 -0800902 return self.api(
903 self.papi.nat44_add_del_interface_addr,
904 {'is_add': is_add,
905 'sw_if_index': sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200906 'flags': flags})
Matus Fabian8bf68e82017-01-12 04:24:35 -0800907
Matus Fabian704018c2017-09-04 02:17:18 -0700908 def nat44_add_del_lb_static_mapping(
909 self,
910 external_addr,
911 external_port,
912 protocol,
Matus Fabian5f224992018-01-25 21:59:16 -0800913 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -0700914 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700915 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +0200916 locals=[],
Filip Vargadd1e3e72019-04-15 18:52:43 +0200917 flags=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700918 is_add=1):
919 """Add/delete NAT44 load balancing static mapping
920
Matus Fabian5f224992018-01-25 21:59:16 -0800921 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -0700922 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Filip Vargadd1e3e72019-04-15 18:52:43 +0200923 :param flags: NAT configuration flags (NAT_IS_TWICE_NAT)
Matus Fabian704018c2017-09-04 02:17:18 -0700924 :param is_add - 1 if add, 0 if delete
925 """
926 return self.api(
927 self.papi.nat44_add_del_lb_static_mapping,
928 {'is_add': is_add,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200929 'flags': flags,
Matus Fabian704018c2017-09-04 02:17:18 -0700930 'external_addr': external_addr,
931 'external_port': external_port,
932 'protocol': protocol,
Matus Fabianea5b5be2018-09-03 05:02:23 -0700933 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -0700934 'local_num': local_num,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200935 'locals': locals,
936 'tag': tag})
Matus Fabian704018c2017-09-04 02:17:18 -0700937
Matus Fabianb6865082018-12-06 03:11:09 -0800938 def nat44_lb_static_mapping_add_del_local(
Ole Troan9a475372019-03-05 16:58:24 +0100939 self,
940 external_addr,
941 external_port,
942 local_addr,
943 local_port,
944 protocol,
945 probability,
946 vrf_id=0,
947 is_add=1):
Matus Fabianb6865082018-12-06 03:11:09 -0800948 """Add/delete NAT44 load-balancing static mapping rule backend
949
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700950 :param external_addr: external IPv4 address of the service
Matus Fabianb6865082018-12-06 03:11:09 -0800951 :param external_port: external L4 port number of the service
952 :param local_addr: IPv4 address of the internal node
953 :param local_port: L4 port number of the internal node
954 :param protocol: IP protocol number
955 :param probability: probability of the internal node
956 :param vrf_id: VRF id of the internal node
957 :param is_add: 1 if add, 0 if delete
958 """
959 return self.api(
960 self.papi.nat44_lb_static_mapping_add_del_local,
961 {'is_add': is_add,
962 'external_addr': external_addr,
963 'external_port': external_port,
964 'local': {
965 'addr': local_addr,
966 'port': local_port,
967 'probability': probability,
968 'vrf_id': vrf_id},
969 'protocol': protocol})
970
Matus Fabian5ba86f72017-10-26 03:37:38 -0700971 def nat44_del_session(
972 self,
973 addr,
974 port,
975 protocol,
976 vrf_id=0,
Filip Vargadd1e3e72019-04-15 18:52:43 +0200977 flags=0,
Matus Fabian70a26ac2018-05-14 06:20:28 -0700978 ext_host_address=None,
979 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -0700980 """Delete NAT44 session
981
982 :param addr: IPv4 address
983 :param por: port number
984 :param protocol: IP protocol number
985 :param vrf_id: VRF ID
Filip Vargadd1e3e72019-04-15 18:52:43 +0200986 :param flags: NAT configuration flags (NAT_IS_INSIDE)
Matus Fabian70a26ac2018-05-14 06:20:28 -0700987 :param ext_host_address: external host IPv4 address
988 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -0700989 """
Filip Vargadd1e3e72019-04-15 18:52:43 +0200990 return self.api(
991 self.papi.nat44_del_session,
992 {'address': addr,
993 'protocol': protocol,
994 'port': port,
995 'vrf_id': vrf_id,
996 'flags': flags,
997 'ext_host_address': ext_host_address,
998 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -0700999
Juraj Sloboda7b929792017-11-23 13:20:48 +01001000 def nat44_forwarding_enable_disable(
1001 self,
1002 enable):
1003 """Enable/disable forwarding for NAT44
1004
1005 :param enable: 1 for enable, 0 for disable
1006 """
1007 return self.api(
1008 self.papi.nat44_forwarding_enable_disable,
1009 {'enable': enable})
1010
Matus Fabian2ba92e32017-08-21 07:05:03 -07001011 def nat_det_map_dump(self):
1012 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001013
Matus Fabian2ba92e32017-08-21 07:05:03 -07001014 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001015 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001016 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001017
Matus Fabianbb4e0222018-09-13 02:36:25 -07001018 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1019 """Set TCP MSS rewriting configuration
1020
1021 :param enable: disable(0)/enable(1) MSS rewriting feature
1022 :param mss_value: MSS value to be used for MSS rewriting
1023 """
1024 return self.api(
1025 self.papi.nat_set_mss_clamping,
1026 {'enable': enable, 'mss_value': mss_value})
1027
Matus Fabian06596c52017-06-06 04:53:28 -07001028 def nat64_add_del_static_bib(
1029 self,
1030 in_ip,
1031 out_ip,
1032 in_port,
1033 out_port,
1034 protocol,
1035 vrf_id=0,
1036 is_add=1):
1037 """Add/delete S-NAT static BIB entry
1038
1039 :param in_ip: Inside IPv6 address
1040 :param out_ip: Outside IPv4 address
1041 :param in_port: Inside port number
1042 :param out_port: Outside port number
1043 :param protocol: IP protocol
1044 :param vrf_id: VRF ID (Default value = 0)
1045 :param is_add: 1 if add, 0 if delete (Default value = 1)
1046 """
1047 return self.api(
1048 self.papi.nat64_add_del_static_bib,
1049 {'i_addr': in_ip,
1050 'o_addr': out_ip,
1051 'i_port': in_port,
1052 'o_port': out_port,
1053 'vrf_id': vrf_id,
1054 'proto': protocol,
1055 'is_add': is_add})
1056
Matus Fabianab9a59c2017-08-16 05:37:36 -07001057 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001058 """Dump NAT64 BIB
1059
Matus Fabianab9a59c2017-08-16 05:37:36 -07001060 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001061 :returns: Dictionary of NAT64 BIB entries
1062 """
1063 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1064
Matus Fabianab9a59c2017-08-16 05:37:36 -07001065 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001066 """Dump NAT64 session table
1067
Matus Fabianab9a59c2017-08-16 05:37:36 -07001068 :param protocol: IP protocol (Default value = 255, all STs)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001069 :returns: Dictionary of NAT64 session table entries
Matus Fabian06596c52017-06-06 04:53:28 -07001070 """
1071 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1072
Filip Vargadd1e3e72019-04-15 18:52:43 +02001073 def nat64_add_del_prefix(self, prefix, vrf_id=0, is_add=1):
Matus Fabian428dc912017-06-21 06:15:18 -07001074 """Add/del NAT64 prefix
1075
1076 :param prefix: NAT64 prefix
Matus Fabian428dc912017-06-21 06:15:18 -07001077 :param vrf_id: VRF id of tenant (Default 0)
1078 :param is_add: 1 if add, 0 if delete (Default value = 1)
1079 """
1080 return self.api(
1081 self.papi.nat64_add_del_prefix,
1082 {'prefix': prefix,
Matus Fabian428dc912017-06-21 06:15:18 -07001083 'vrf_id': vrf_id,
1084 'is_add': is_add})
1085
Ole Troane1ade682019-03-04 23:55:43 +01001086 def nat64_add_del_interface_addr(
Matus Fabian0938dcf2017-11-08 01:59:38 -08001087 self,
1088 sw_if_index,
1089 is_add=1):
1090 """Add/del NAT64 address from interface
1091
1092 :param sw_if_index: Software index of the interface
1093 :param is_add: 1 if add, 0 if delete (Default value = 1)
1094 """
1095 return self.api(self.papi.nat64_add_del_interface_addr,
1096 {'is_add': is_add, 'sw_if_index': sw_if_index})
1097
Matus Fabian8ebe6252017-11-06 05:04:53 -08001098 def dslite_set_aftr_addr(self, ip6, ip4):
1099 """Set DS-Lite AFTR addresses
1100
1101 :param ip4: IPv4 address
1102 :param ip6: IPv6 address
1103 """
1104 return self.api(
1105 self.papi.dslite_set_aftr_addr,
1106 {'ip4_addr': ip4,
1107 'ip6_addr': ip6})
1108
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001109 def dslite_set_b4_addr(self, ip6, ip4):
1110 """Set DS-Lite B4 IPv6 address
1111
1112 :param ip4: IPv4 address
1113 :param ip6: IPv6 address
1114 """
1115 return self.api(
1116 self.papi.dslite_set_b4_addr,
1117 {'ip4_addr': ip4,
1118 'ip6_addr': ip6})
1119
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001120 def nat66_add_del_interface(
1121 self,
1122 sw_if_index,
Filip Vargadd1e3e72019-04-15 18:52:43 +02001123 flags=0,
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001124 is_add=1):
1125 """Enable/disable NAT66 feature on the interface
Filip Vargadd1e3e72019-04-15 18:52:43 +02001126
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001127 :param sw_if_index: Index of the interface
Filip Vargadd1e3e72019-04-15 18:52:43 +02001128 :param flags: NAT configuration flags (NAT_IS_INSIDE)
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001129 :param is_add: 1 if add, 0 if delete (Default value = 1)
1130 """
1131 return self.api(
1132 self.papi.nat66_add_del_interface,
Filip Vargadd1e3e72019-04-15 18:52:43 +02001133 {'is_add': is_add,
1134 'flags': flags,
1135 'sw_if_index': sw_if_index})
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001136
1137 def nat66_add_del_static_mapping(
1138 self,
1139 in_ip,
1140 out_ip,
1141 vrf_id=0,
1142 is_add=1):
1143 """Add/delete NAT66 static mapping
1144
1145 :param in_ip: Inside IPv6 address
1146 :param out_ip: Outside IPv6 address
1147 :param vrf_id: VRF ID (Default value = 0)
1148 :param is_add: 1 if add, 0 if delete (Default value = 1)
1149 """
1150 return self.api(
1151 self.papi.nat66_add_del_static_mapping,
1152 {'local_ip_address': in_ip,
1153 'external_ip_address': out_ip,
1154 'vrf_id': vrf_id,
1155 'is_add': is_add})
1156
Matus Fabian34931eb2019-02-26 09:05:23 -08001157 def nat_ha_set_listener(self, addr, port, path_mtu=512):
1158 """Set HA listener (local settings)
1159
1160 :param addr: local IP4 address
1161 :param port: local UDP port number
1162 :param path_mtu: path MTU (Default value = 512)
1163 """
1164 return self.api(self.papi.nat_ha_set_listener,
1165 {'ip_address': addr,
1166 'port': port,
1167 'path_mtu': path_mtu})
1168
1169 def nat_ha_get_listener(self):
1170 """Get HA listener/local configuration"""
1171 return self.api(self.papi.nat_ha_get_listener, {})
1172
1173 def nat_ha_set_failover(self, addr, port, refresh=10):
1174 """Set HA failover (remote settings)
1175
1176 :param addr: failover IP4 address
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001177 :param port: failover UDP port number
Matus Fabian34931eb2019-02-26 09:05:23 -08001178 :param refresh: number of seconds after which to send session refresh
1179 """
1180 return self.api(self.papi.nat_ha_set_failover,
1181 {'ip_address': addr,
1182 'port': port,
1183 'session_refresh_interval': refresh})
1184
Matus Fabian34931eb2019-02-26 09:05:23 -08001185 def nat_ha_resync(self, want_resync_event=1):
1186 """Resync HA (resend existing sessions to new failover)
1187 :param want_resync_event: if non-zero resync completed event sent
1188 """
1189 return self.api(self.papi.nat_ha_resync,
1190 {'want_resync_event': want_resync_event,
1191 'pid': os.getpid()})
1192
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001193 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001194 detect_mult, local_addr, peer_addr, is_ipv6=0,
1195 bfd_key_id=None, conf_key_id=None):
1196 if bfd_key_id is None:
1197 return self.api(self.papi.bfd_udp_add,
1198 {
1199 'sw_if_index': sw_if_index,
1200 'desired_min_tx': desired_min_tx,
1201 'required_min_rx': required_min_rx,
1202 'local_addr': local_addr,
1203 'peer_addr': peer_addr,
1204 'is_ipv6': is_ipv6,
1205 'detect_mult': detect_mult,
1206 })
1207 else:
1208 return self.api(self.papi.bfd_udp_add,
1209 {
1210 'sw_if_index': sw_if_index,
1211 'desired_min_tx': desired_min_tx,
1212 'required_min_rx': required_min_rx,
1213 'local_addr': local_addr,
1214 'peer_addr': peer_addr,
1215 'is_ipv6': is_ipv6,
1216 'detect_mult': detect_mult,
1217 'is_authenticated': 1,
1218 'bfd_key_id': bfd_key_id,
1219 'conf_key_id': conf_key_id,
1220 })
1221
Klement Sekeraa57a9702017-02-02 06:58:07 +01001222 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1223 detect_mult, local_addr, peer_addr, is_ipv6=0):
1224 return self.api(self.papi.bfd_udp_mod,
1225 {
1226 'sw_if_index': sw_if_index,
1227 'desired_min_tx': desired_min_tx,
1228 'required_min_rx': required_min_rx,
1229 'local_addr': local_addr,
1230 'peer_addr': peer_addr,
1231 'is_ipv6': is_ipv6,
1232 'detect_mult': detect_mult,
1233 })
1234
Klement Sekerab17dd962017-01-09 07:43:48 +01001235 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1236 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1237 is_delayed=False):
1238 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001239 {
1240 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001241 'local_addr': local_addr,
1242 'peer_addr': peer_addr,
1243 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001244 'is_delayed': 1 if is_delayed else 0,
1245 'bfd_key_id': bfd_key_id,
1246 'conf_key_id': conf_key_id,
1247 })
1248
Klement Sekerab17dd962017-01-09 07:43:48 +01001249 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1250 peer_addr, is_ipv6=0):
1251 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001252 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001253 'sw_if_index': sw_if_index,
1254 'local_addr': local_addr,
1255 'peer_addr': peer_addr,
1256 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001257 })
1258
1259 def want_bfd_events(self, enable_disable=1):
1260 return self.api(self.papi.want_bfd_events, {
1261 'enable_disable': enable_disable,
1262 'pid': os.getpid(),
1263 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001264
Klement Sekerab17dd962017-01-09 07:43:48 +01001265 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1266 return self.api(self.papi.bfd_auth_set_key, {
1267 'conf_key_id': conf_key_id,
1268 'auth_type': auth_type,
1269 'key': key,
1270 'key_len': len(key),
1271 })
1272
Steve Shin7957d6e2016-12-19 09:24:50 -08001273 def classify_add_del_table(
1274 self,
1275 is_add,
1276 mask,
1277 match_n_vectors=1,
1278 table_index=0xFFFFFFFF,
1279 nbuckets=2,
1280 memory_size=2097152,
1281 skip_n_vectors=0,
1282 next_table_index=0xFFFFFFFF,
1283 miss_next_index=0xFFFFFFFF,
1284 current_data_flag=0,
1285 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001286 """
1287 :param is_add:
1288 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001289 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001290 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001291 :param nbuckets: (Default value = 2)
1292 :param memory_size: (Default value = 2097152)
1293 :param skip_n_vectors: (Default value = 0)
1294 :param next_table_index: (Default value = 0xFFFFFFFF)
1295 :param miss_next_index: (Default value = 0xFFFFFFFF)
1296 :param current_data_flag: (Default value = 0)
1297 :param current_data_offset: (Default value = 0)
1298 """
1299
Juraj Sloboda75282452018-06-12 14:20:49 +02001300 mask_len = ((len(mask) - 1) / 16 + 1) * 16
1301 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08001302 return self.api(
1303 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001304 {'is_add': is_add,
1305 'table_index': table_index,
1306 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001307 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001308 'skip_n_vectors': skip_n_vectors,
1309 'match_n_vectors': match_n_vectors,
1310 'next_table_index': next_table_index,
1311 'miss_next_index': miss_next_index,
1312 'current_data_flag': current_data_flag,
1313 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02001314 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001315 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001316
1317 def classify_add_del_session(
1318 self,
1319 is_add,
1320 table_index,
1321 match,
1322 opaque_index=0xFFFFFFFF,
1323 hit_next_index=0xFFFFFFFF,
1324 advance=0,
1325 action=0,
1326 metadata=0):
1327 """
1328 :param is_add:
1329 :param table_index:
1330 :param match:
1331 :param opaque_index: (Default value = 0xFFFFFFFF)
1332 :param hit_next_index: (Default value = 0xFFFFFFFF)
1333 :param advance: (Default value = 0)
1334 :param action: (Default value = 0)
1335 :param metadata: (Default value = 0)
1336 """
1337
Juraj Sloboda75282452018-06-12 14:20:49 +02001338 match_len = ((len(match) - 1) / 16 + 1) * 16
1339 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08001340 return self.api(
1341 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001342 {'is_add': is_add,
1343 'table_index': table_index,
1344 'hit_next_index': hit_next_index,
1345 'opaque_index': opaque_index,
1346 'advance': advance,
1347 'action': action,
1348 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02001349 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001350 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001351
1352 def input_acl_set_interface(
1353 self,
1354 is_add,
1355 sw_if_index,
1356 ip4_table_index=0xFFFFFFFF,
1357 ip6_table_index=0xFFFFFFFF,
1358 l2_table_index=0xFFFFFFFF):
1359 """
1360 :param is_add:
1361 :param sw_if_index:
1362 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1363 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1364 :param l2_table_index: (Default value = 0xFFFFFFFF)
1365 """
1366
1367 return self.api(
1368 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001369 {'sw_if_index': sw_if_index,
1370 'ip4_table_index': ip4_table_index,
1371 'ip6_table_index': ip6_table_index,
1372 'l2_table_index': l2_table_index,
1373 'is_add': is_add})
1374
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01001375 def output_acl_set_interface(
1376 self,
1377 is_add,
1378 sw_if_index,
1379 ip4_table_index=0xFFFFFFFF,
1380 ip6_table_index=0xFFFFFFFF,
1381 l2_table_index=0xFFFFFFFF):
1382 """
1383 :param is_add:
1384 :param sw_if_index:
1385 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1386 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1387 :param l2_table_index: (Default value = 0xFFFFFFFF)
1388 """
1389
1390 return self.api(
1391 self.papi.output_acl_set_interface,
1392 {'sw_if_index': sw_if_index,
1393 'ip4_table_index': ip4_table_index,
1394 'ip6_table_index': ip6_table_index,
1395 'l2_table_index': l2_table_index,
1396 'is_add': is_add})
1397
Klement Sekera77fabdb2017-01-02 07:46:14 +01001398 def set_ipfix_exporter(
1399 self,
1400 collector_address,
1401 src_address,
1402 path_mtu,
1403 template_interval,
1404 vrf_id=0,
1405 collector_port=4739,
1406 udp_checksum=0):
1407 return self.api(
1408 self.papi.set_ipfix_exporter,
1409 {
1410 'collector_address': collector_address,
1411 'collector_port': collector_port,
1412 'src_address': src_address,
1413 'vrf_id': vrf_id,
1414 'path_mtu': path_mtu,
1415 'template_interval': template_interval,
1416 'udp_checksum': udp_checksum,
1417 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001418
1419 def dhcp_proxy_config(self,
1420 dhcp_server,
1421 dhcp_src_address,
1422 rx_table_id=0,
1423 server_table_id=0,
1424 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001425 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001426 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001427 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001428 {
1429 'rx_vrf_id': rx_table_id,
1430 'server_vrf_id': server_table_id,
1431 'is_ipv6': is_ipv6,
1432 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001433 'dhcp_server': dhcp_server,
1434 'dhcp_src_address': dhcp_src_address,
1435 })
1436
1437 def dhcp_proxy_set_vss(self,
1438 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001439 vss_type=255,
1440 vpn_ascii_id="",
1441 oui=0,
1442 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001443 is_add=1,
1444 is_ip6=0):
1445 return self.api(
1446 self.papi.dhcp_proxy_set_vss,
1447 {
1448 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001449 'vss_type': vss_type,
1450 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001451 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001452 'vpn_index': vpn_index,
1453 'is_add': is_add,
1454 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001455 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001456
Ole Troane1ade682019-03-04 23:55:43 +01001457 def dhcp_client_config(self,
1458 sw_if_index,
1459 hostname,
1460 client_id='',
1461 is_add=1,
1462 set_broadcast_flag=1,
1463 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001464 return self.api(
1465 self.papi.dhcp_client_config,
1466 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001467 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001468 'client': {
1469 'sw_if_index': sw_if_index,
1470 'hostname': hostname,
1471 'id': client_id,
1472 'want_dhcp_event': want_dhcp_events,
1473 'set_broadcast_flag': set_broadcast_flag,
1474 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001475 })
1476
Neale Ranns32e1c012016-11-22 17:07:28 +00001477 def ip_mroute_add_del(self,
1478 src_address,
1479 grp_address,
1480 grp_address_length,
1481 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001482 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001483 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001484 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001485 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001486 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001487 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001488 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001489 is_add=1,
1490 is_ipv6=0,
1491 is_local=0):
1492 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001493 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001494 """
1495 return self.api(
1496 self.papi.ip_mroute_add_del,
1497 {'next_hop_sw_if_index': next_hop_sw_if_index,
1498 'entry_flags': e_flags,
1499 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001500 'table_id': table_id,
1501 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001502 'is_add': is_add,
1503 'is_ipv6': is_ipv6,
1504 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001505 'bier_imp': bier_imp,
1506 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001507 'grp_address_length': grp_address_length,
1508 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001509 'src_address': src_address,
1510 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001511
Filip Tehlar770e89e2017-01-31 10:39:16 +01001512 def lisp_enable_disable(self, is_enabled):
1513 return self.api(
1514 self.papi.lisp_enable_disable,
1515 {
1516 'is_en': is_enabled,
1517 })
1518
Ole Troane1ade682019-03-04 23:55:43 +01001519 def lisp_add_del_locator_set(self,
1520 ls_name,
1521 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001522 return self.api(
1523 self.papi.lisp_add_del_locator_set,
1524 {
1525 'is_add': is_add,
1526 'locator_set_name': ls_name
1527 })
1528
Ole Troane1ade682019-03-04 23:55:43 +01001529 def lisp_add_del_locator(self,
1530 ls_name,
1531 sw_if_index,
1532 priority=1,
1533 weight=1,
1534 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001535 return self.api(
1536 self.papi.lisp_add_del_locator,
1537 {
1538 'is_add': is_add,
1539 'locator_set_name': ls_name,
1540 'sw_if_index': sw_if_index,
1541 'priority': priority,
1542 'weight': weight
1543 })
1544
1545 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1546 return self.api(
1547 self.papi.lisp_locator_dump,
1548 {
1549 'is_index_set': is_index_set,
1550 'ls_name': ls_name,
1551 'ls_index': ls_index,
1552 })
1553
Ole Troane1ade682019-03-04 23:55:43 +01001554 def lisp_add_del_local_eid(self,
1555 ls_name,
1556 eid_type,
1557 eid,
1558 prefix_len,
1559 vni=0,
1560 key_id=0,
1561 key="",
1562 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001563 return self.api(
1564 self.papi.lisp_add_del_local_eid,
1565 {
1566 'locator_set_name': ls_name,
1567 'is_add': is_add,
1568 'eid_type': eid_type,
1569 'eid': eid,
1570 'prefix_len': prefix_len,
1571 'vni': vni,
1572 'key_id': key_id,
1573 'key': key
1574 })
1575
1576 def lisp_eid_table_dump(self,
1577 eid_set=0,
1578 prefix_length=0,
1579 vni=0,
1580 eid_type=0,
1581 eid=None,
1582 filter_opt=0):
1583 return self.api(
1584 self.papi.lisp_eid_table_dump,
1585 {
1586 'eid_set': eid_set,
1587 'prefix_length': prefix_length,
1588 'vni': vni,
1589 'eid_type': eid_type,
1590 'eid': eid,
1591 'filter': filter_opt,
1592 })
1593
Ole Troane1ade682019-03-04 23:55:43 +01001594 def lisp_add_del_remote_mapping(self,
1595 eid_type,
1596 eid,
1597 eid_prefix_len=0,
1598 vni=0,
1599 rlocs=[],
1600 rlocs_num=0,
1601 is_src_dst=0,
1602 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001603 return self.api(
1604 self.papi.lisp_add_del_remote_mapping,
1605 {
1606 'is_add': is_add,
1607 'eid_type': eid_type,
1608 'eid': eid,
1609 'eid_len': eid_prefix_len,
1610 'rloc_num': rlocs_num,
1611 'rlocs': rlocs,
1612 'vni': vni,
1613 'is_src_dst': is_src_dst,
1614 })
1615
Ole Troane1ade682019-03-04 23:55:43 +01001616 def lisp_add_del_adjacency(self,
1617 leid,
1618 reid,
1619 leid_len,
1620 reid_len,
1621 eid_type,
1622 is_add=1,
1623 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001624 return self.api(
1625 self.papi.lisp_add_del_adjacency,
1626 {
1627 'is_add': is_add,
1628 'vni': vni,
1629 'eid_type': eid_type,
1630 'leid': leid,
1631 'reid': reid,
1632 'leid_len': leid_len,
1633 'reid_len': reid_len,
1634 })
1635
Hongjun Nief486b12017-04-12 19:21:16 +08001636 def gtpu_add_del_tunnel(
1637 self,
1638 src_addr,
1639 dst_addr,
1640 is_add=1,
1641 is_ipv6=0,
1642 mcast_sw_if_index=0xFFFFFFFF,
1643 encap_vrf_id=0,
1644 decap_next_index=0xFFFFFFFF,
1645 teid=0):
1646 """
1647
1648 :param is_add: (Default value = 1)
1649 :param is_ipv6: (Default value = 0)
1650 :param src_addr:
1651 :param dst_addr:
1652 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1653 :param encap_vrf_id: (Default value = 0)
1654 :param decap_next_index: (Default value = 0xFFFFFFFF)
1655 :param teid: (Default value = 0)
1656
1657 """
1658 return self.api(self.papi.gtpu_add_del_tunnel,
1659 {'is_add': is_add,
1660 'is_ipv6': is_ipv6,
1661 'src_address': src_addr,
1662 'dst_address': dst_addr,
1663 'mcast_sw_if_index': mcast_sw_if_index,
1664 'encap_vrf_id': encap_vrf_id,
1665 'decap_next_index': decap_next_index,
1666 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001667
1668 def vxlan_gpe_add_del_tunnel(
1669 self,
1670 src_addr,
1671 dst_addr,
1672 mcast_sw_if_index=0xFFFFFFFF,
1673 is_add=1,
1674 is_ipv6=0,
1675 encap_vrf_id=0,
1676 decap_vrf_id=0,
1677 protocol=3,
1678 vni=0):
1679 """
1680
1681 :param local:
1682 :param remote:
1683 :param is_add: (Default value = 1)
1684 :param is_ipv6: (Default value = 0)
1685 :param encap_vrf_id: (Default value = 0)
1686 :param decap_vrf_id: (Default value = 0)
1687 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1688 :param protocol: (Default value = 3)
1689 :param vni: (Default value = 0)
1690
1691 """
1692 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1693 {'is_add': is_add,
1694 'is_ipv6': is_ipv6,
1695 'local': src_addr,
1696 'remote': dst_addr,
1697 'mcast_sw_if_index': mcast_sw_if_index,
1698 'encap_vrf_id': encap_vrf_id,
1699 'decap_vrf_id': decap_vrf_id,
1700 'protocol': protocol,
1701 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001702
Neale Ranns79a05f52018-09-11 07:39:43 -07001703 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001704 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001705 src,
1706 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001707 mcast_sw_if_index=0xFFFFFFFF,
1708 is_add=1,
1709 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001710 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001711 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001712 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001713 instance=0xFFFFFFFF):
1714 """
1715
1716 :param dst_addr:
1717 :param src_addr:
1718 :param is_add: (Default value = 1)
1719 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001720 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001721 :param decap_next_index: (Default value = 0xFFFFFFFF)
1722 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1723 :param vni: (Default value = 0)
1724 :param instance: (Default value = 0xFFFFFFFF)
1725
1726 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001727 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001728 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001729 'tunnel': {
1730 'src': src,
1731 'dst': dst,
1732 'mcast_sw_if_index': mcast_sw_if_index,
1733 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001734 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001735 'instance': instance,
1736 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001737
1738 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1739 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001740 {'sw_if_index': sw_if_index,
1741 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001742
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001743 def pppoe_add_del_session(
1744 self,
1745 client_ip,
1746 client_mac,
1747 session_id=0,
1748 is_add=1,
1749 is_ipv6=0,
1750 decap_vrf_id=0):
1751 """
1752
1753 :param is_add: (Default value = 1)
1754 :param is_ipv6: (Default value = 0)
1755 :param client_ip:
1756 :param session_id: (Default value = 0)
1757 :param client_mac:
1758 :param decap_vrf_id: (Default value = 0)
1759
1760 """
1761 return self.api(self.papi.pppoe_add_del_session,
1762 {'is_add': is_add,
1763 'is_ipv6': is_ipv6,
1764 'session_id': session_id,
1765 'client_ip': client_ip,
1766 'decap_vrf_id': decap_vrf_id,
1767 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001768
Neale Ranns7c922dc2018-08-30 06:12:27 -07001769 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1770 return self.api(self.papi.sr_mpls_policy_add,
1771 {'bsid': bsid,
1772 'weight': weight,
1773 'type': type,
1774 'n_segments': len(segments),
1775 'segments': segments})
1776
1777 def sr_mpls_policy_del(self, bsid):
1778 return self.api(self.papi.sr_mpls_policy_del,
1779 {'bsid': bsid})
1780
Kris Michielsen91074432017-06-22 13:00:20 +02001781 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001782 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001783 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001784 nh_addr4,
1785 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001786 is_del=0,
1787 end_psp=0,
1788 sw_if_index=0xFFFFFFFF,
1789 vlan_index=0,
1790 fib_table=0,
1791 ):
1792 """ Add/del IPv6 SR local-SID.
1793
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001794 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001795 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1796 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001797 :param nh_addr4:
1798 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001799 :param is_del: (Default value = 0)
1800 :param end_psp: (Default value = 0)
1801 :param sw_if_index: (Default value = 0xFFFFFFFF)
1802 :param vlan_index: (Default value = 0)
1803 :param fib_table: (Default value = 0)
1804 """
1805 return self.api(
1806 self.papi.sr_localsid_add_del,
1807 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001808 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001809 'end_psp': end_psp,
1810 'behavior': behavior,
1811 'sw_if_index': sw_if_index,
1812 'vlan_index': vlan_index,
1813 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001814 'nh_addr4': nh_addr4,
1815 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001816 }
1817 )
1818
1819 def sr_policy_add(
1820 self,
1821 bsid_addr,
1822 weight=1,
1823 is_encap=1,
1824 type=0,
1825 fib_table=0,
1826 n_segments=0,
1827 segments=[]):
1828 """
1829 :param bsid_addr: bindingSID of the SR Policy
1830 :param weight: weight of the sid list. optional. (default: 1)
1831 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1832 (default: Encap)
1833 :param type: type/behavior of the SR policy. (default or spray) \
1834 (default: default)
1835 :param fib_table: VRF where to install the FIB entry for the BSID \
1836 (default: 0)
1837 :param n_segments: number of segments \
1838 (default: 0)
1839 :param segments: a vector of IPv6 address composing the segment list \
1840 (default: [])
1841 """
1842 return self.api(
1843 self.papi.sr_policy_add,
1844 {'bsid_addr': bsid_addr,
1845 'weight': weight,
1846 'is_encap': is_encap,
1847 'type': type,
1848 'fib_table': fib_table,
1849 'n_segments': n_segments,
1850 'segments': segments
1851 }
1852 )
1853
1854 def sr_policy_del(
1855 self,
1856 bsid_addr,
1857 sr_policy_index=0):
1858 """
1859 :param bsid: bindingSID of the SR Policy
1860 :param sr_policy_index: index of the sr policy (default: 0)
1861 """
1862 return self.api(
1863 self.papi.sr_policy_del,
1864 {'bsid_addr': bsid_addr,
1865 'sr_policy_index': sr_policy_index
1866 })
1867
1868 def sr_steering_add_del(
1869 self,
1870 is_del,
1871 bsid_addr,
1872 sr_policy_index,
1873 table_id,
1874 prefix_addr,
1875 mask_width,
1876 sw_if_index,
1877 traffic_type):
1878 """
1879 Steer traffic L2 and L3 traffic through a given SR policy
1880
1881 :param is_del: delete or add
1882 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
1883 :param sr_policy: is the index of the SR Policy (alt to bsid)
1884 :param table_id: is the VRF where to install the FIB entry for the BSID
1885 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
1886 :param mask_width: is the mask for L3 traffic type
1887 :param sw_if_index: is the incoming interface for L2 traffic
1888 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
1889 """
1890 return self.api(
1891 self.papi.sr_steering_add_del,
1892 {'is_del': is_del,
1893 'bsid_addr': bsid_addr,
1894 'sr_policy_index': sr_policy_index,
1895 'table_id': table_id,
1896 'prefix_addr': prefix_addr,
1897 'mask_width': mask_width,
1898 'sw_if_index': sw_if_index,
1899 'traffic_type': traffic_type
1900 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02001901
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001902 def acl_add_replace(self, acl_index, r, tag='',
1903 expected_retval=0):
1904 """Add/replace an ACL
1905 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
1906 :param acl_rule r: ACL rules array.
1907 :param str tag: symbolic tag (description) for this ACL.
1908 :param int count: number of rules.
1909 """
1910 return self.api(self.papi.acl_add_replace,
1911 {'acl_index': acl_index,
1912 'r': r,
1913 'count': len(r),
1914 'tag': tag},
1915 expected_retval=expected_retval)
1916
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02001917 def acl_del(self, acl_index, expected_retval=0):
1918 """
1919
1920 :param acl_index:
1921 :return:
1922 """
1923 return self.api(self.papi.acl_del,
1924 {'acl_index': acl_index},
1925 expected_retval=expected_retval)
1926
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001927 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
1928 expected_retval=0):
1929 return self.api(self.papi.acl_interface_set_acl_list,
1930 {'sw_if_index': sw_if_index,
1931 'count': len(acls),
1932 'n_input': n_input,
1933 'acls': acls},
1934 expected_retval=expected_retval)
1935
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01001936 def acl_interface_set_etype_whitelist(self, sw_if_index,
1937 n_input, whitelist,
1938 expected_retval=0):
1939 return self.api(self.papi.acl_interface_set_etype_whitelist,
1940 {'sw_if_index': sw_if_index,
1941 'count': len(whitelist),
1942 'n_input': n_input,
1943 'whitelist': whitelist},
1944 expected_retval=expected_retval)
1945
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001946 def acl_interface_add_del(self,
1947 sw_if_index,
1948 acl_index,
1949 is_add=1):
1950 """ Add/Delete ACL to/from interface
1951
1952 :param sw_if_index:
1953 :param acl_index:
1954 :param is_add: (Default value = 1)
1955 """
1956
1957 return self.api(self.papi.acl_interface_add_del,
1958 {'is_add': is_add,
1959 'is_input': 1,
1960 'sw_if_index': sw_if_index,
1961 'acl_index': acl_index})
1962
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02001963 def acl_dump(self, acl_index, expected_retval=0):
1964 return self.api(self.papi.acl_dump,
1965 {'acl_index': acl_index},
1966 expected_retval=expected_retval)
1967
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01001968 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
1969 expected_retval=0):
1970 return self.api(self.papi.acl_interface_list_dump,
1971 {'sw_if_index': sw_if_index},
1972 expected_retval=expected_retval)
1973
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001974 def macip_acl_add(self, rules, tag=""):
1975 """ Add MACIP acl
1976
1977 :param rules: list of rules for given acl
1978 :param tag: acl tag
1979 """
1980
1981 return self.api(self.papi.macip_acl_add,
1982 {'r': rules,
1983 'count': len(rules),
1984 'tag': tag})
1985
Pavel Kotucek932f7412017-09-07 14:44:52 +02001986 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
1987 """ Add MACIP acl
1988
1989 :param rules: list of rules for given acl
1990 :param tag: acl tag
1991 """
1992
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001993 return self.api(self.papi.macip_acl_add_replace,
1994 {'acl_index': acl_index,
1995 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02001996 'count': len(rules),
1997 'tag': tag})
1998
Pavel Kotucek932f7412017-09-07 14:44:52 +02001999 def macip_acl_interface_add_del(self,
2000 sw_if_index,
2001 acl_index,
2002 is_add=1):
2003 """ Add MACIP acl to interface
2004
2005 :param sw_if_index:
2006 :param acl_index:
2007 :param is_add: (Default value = 1)
2008 """
2009
2010 return self.api(self.papi.macip_acl_interface_add_del,
2011 {'is_add': is_add,
2012 'sw_if_index': sw_if_index,
2013 'acl_index': acl_index})
2014
Pavel Kotucek932f7412017-09-07 14:44:52 +02002015 def macip_acl_dump(self, acl_index=4294967295):
2016 """ Return MACIP acl dump
2017 """
2018
2019 return self.api(
2020 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002021
2022 def policer_add_del(self,
2023 name,
2024 cir,
2025 eir,
2026 cb,
2027 eb,
2028 is_add=1,
2029 rate_type=0,
2030 round_type=0,
2031 ptype=0,
2032 color_aware=0,
2033 conform_action_type=1,
2034 conform_dscp=0,
2035 exceed_action_type=0,
2036 exceed_dscp=0,
2037 violate_action_type=0,
2038 violate_dscp=0):
2039 return self.api(self.papi.policer_add_del,
2040 {'name': name,
2041 'cir': cir,
2042 'eir': eir,
2043 'cb': cb,
2044 'eb': eb,
2045 'is_add': is_add,
2046 'rate_type': rate_type,
2047 'round_type': round_type,
2048 'type': ptype,
2049 'color_aware': color_aware,
2050 'conform_action_type': conform_action_type,
2051 'conform_dscp': conform_dscp,
2052 'exceed_action_type': exceed_action_type,
2053 'exceed_dscp': exceed_dscp,
2054 'violate_action_type': violate_action_type,
2055 'violate_dscp': violate_dscp})
2056
2057 def ip_punt_police(self,
2058 policer_index,
2059 is_ip6=0,
2060 is_add=1):
2061 return self.api(self.papi.ip_punt_police,
2062 {'policer_index': policer_index,
2063 'is_add': is_add,
2064 'is_ip6': is_ip6})
2065
2066 def ip_punt_redirect(self,
2067 rx_sw_if_index,
2068 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002069 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002070 is_add=1):
2071 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002072 {'punt': {'rx_sw_if_index': rx_sw_if_index,
2073 'tx_sw_if_index': tx_sw_if_index,
2074 'nh': address},
2075 'is_add': is_add})
2076
2077 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
2078 return self.api(self.papi.ip_punt_redirect_dump,
2079 {'sw_if_index': sw_if_index,
2080 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002081
2082 def bier_table_add_del(self,
2083 bti,
2084 mpls_label,
2085 is_add=1):
2086 """ BIER Table add/del """
2087 return self.api(
2088 self.papi.bier_table_add_del,
2089 {'bt_tbl_id': {"bt_set": bti.set_id,
2090 "bt_sub_domain": bti.sub_domain_id,
2091 "bt_hdr_len_id": bti.hdr_len_id},
2092 'bt_label': mpls_label,
2093 'bt_is_add': is_add})
2094
2095 def bier_table_dump(self):
2096 return self.api(self.papi.bier_table_dump, {})
2097
2098 def bier_route_add_del(self,
2099 bti,
2100 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002101 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002102 is_add=1,
2103 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07002104 """ BIER Route add/del """
2105 return self.api(
2106 self.papi.bier_route_add_del,
2107 {'br_tbl_id': {"bt_set": bti.set_id,
2108 "bt_sub_domain": bti.sub_domain_id,
2109 "bt_hdr_len_id": bti.hdr_len_id},
2110 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002111 'br_n_paths': len(paths),
2112 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002113 'br_is_add': is_add,
2114 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002115
2116 def bier_route_dump(self, bti):
2117 return self.api(
2118 self.papi.bier_route_dump,
2119 {'br_tbl_id': {"bt_set": bti.set_id,
2120 "bt_sub_domain": bti.sub_domain_id,
2121 "bt_hdr_len_id": bti.hdr_len_id}})
2122
2123 def bier_imp_add(self,
2124 bti,
2125 src,
2126 ibytes,
2127 is_add=1):
2128 """ BIER Imposition Add """
2129 return self.api(
2130 self.papi.bier_imp_add,
2131 {'bi_tbl_id': {"bt_set": bti.set_id,
2132 "bt_sub_domain": bti.sub_domain_id,
2133 "bt_hdr_len_id": bti.hdr_len_id},
2134 'bi_src': src,
2135 'bi_n_bytes': len(ibytes),
2136 'bi_bytes': ibytes})
2137
2138 def bier_imp_del(self, bi_index):
2139 """ BIER Imposition del """
2140 return self.api(
2141 self.papi.bier_imp_del,
2142 {'bi_index': bi_index})
2143
2144 def bier_imp_dump(self):
2145 return self.api(self.papi.bier_imp_dump, {})
2146
2147 def bier_disp_table_add_del(self,
2148 bdti,
2149 is_add=1):
2150 """ BIER Disposition Table add/del """
2151 return self.api(
2152 self.papi.bier_disp_table_add_del,
2153 {'bdt_tbl_id': bdti,
2154 'bdt_is_add': is_add})
2155
2156 def bier_disp_table_dump(self):
2157 return self.api(self.papi.bier_disp_table_dump, {})
2158
2159 def bier_disp_entry_add_del(self,
2160 bdti,
2161 bp,
2162 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002163 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002164 next_hop,
2165 next_hop_tbl_id=0,
2166 next_hop_rpf_id=~0,
2167 next_hop_is_ip4=1,
2168 is_add=1):
2169 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002170 lstack = []
2171 while (len(lstack) < 16):
2172 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002173 return self.api(
2174 self.papi.bier_disp_entry_add_del,
2175 {'bde_tbl_id': bdti,
2176 'bde_bp': bp,
2177 'bde_payload_proto': payload_proto,
2178 'bde_n_paths': 1,
2179 'bde_paths': [{'next_hop': next_hop,
2180 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002181 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002182 'rpf_id': next_hop_rpf_id,
2183 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002184 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002185 'bde_is_add': is_add})
2186
2187 def bier_disp_entry_dump(self, bdti):
2188 return self.api(
2189 self.papi.bier_disp_entry_dump,
2190 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002191
Florin Coras3ea6ce22017-12-11 09:09:05 -08002192 def session_enable_disable(self, is_enabled):
2193 return self.api(
2194 self.papi.session_enable_disable,
2195 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002196
2197 def ipsec_spd_add_del(self, spd_id, is_add=1):
2198 """ SPD add/del - Wrapper to add or del ipsec SPD
2199 Sample CLI : 'ipsec spd add 1'
2200
2201 :param spd_id - SPD ID to be created in the vpp . mandatory
2202 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2203 optional
2204 :returns: reply from the API
2205 """
2206 return self.api(
2207 self.papi.ipsec_spd_add_del, {
2208 'spd_id': spd_id, 'is_add': is_add})
2209
Neale Ranns311124e2019-01-24 04:52:25 -08002210 def ipsec_spds_dump(self):
2211 return self.api(self.papi.ipsec_spds_dump, {})
2212
“mystarrocks”23f0c452017-12-11 07:11:51 -08002213 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2214 """ IPSEC interface SPD add/del - \
2215 Wrapper to associate/disassociate SPD to interface in VPP
2216 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2217
2218 :param spd_id - SPD ID to associate with the interface . mandatory
2219 :param sw_if_index - Interface Index which needs to ipsec \
2220 association mandatory
2221 :param is_add - add(1) or del(0) association with interface \
2222 (Default 1 - add) . optional
2223 :returns: reply from the API
2224 """
2225 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02002226 self.papi.ipsec_interface_add_del_spd,
2227 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002228
Neale Ranns311124e2019-01-24 04:52:25 -08002229 def ipsec_spd_interface_dump(self, spd_index=None):
2230 return self.api(self.papi.ipsec_spd_interface_dump,
2231 {'spd_index': spd_index if spd_index else 0,
2232 'spd_index_valid': 1 if spd_index else 0})
2233
Neale Ranns17dcec02019-01-09 21:22:20 -08002234 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002235 sad_id,
2236 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02002237 integrity_algorithm,
2238 integrity_key,
2239 crypto_algorithm,
2240 crypto_key,
2241 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002242 tunnel_src_address='',
2243 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08002244 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002245 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08002246 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08002247 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02002248 :param sad_id: security association ID
2249 :param spi: security param index of the SA in decimal
2250 :param integrity_algorithm:
2251 :param integrity_key:
2252 :param crypto_algorithm:
2253 :param crypto_key:
2254 :param protocol: AH(0) or ESP(1) protocol
2255 :param tunnel_src_address: tunnel mode outer src address
2256 :param tunnel_dst_address: tunnel mode outer dst address
2257 :param is_add:
2258 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08002259 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
2260 crypto and ipsec algorithms
2261 """
2262 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002263 self.papi.ipsec_sad_entry_add_del,
2264 {
2265 'is_add': is_add,
2266 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002267 {
2268 'sad_id': sad_id,
2269 'spi': spi,
2270 'tunnel_src': tunnel_src_address,
2271 'tunnel_dst': tunnel_dst_address,
2272 'protocol': protocol,
2273 'integrity_algorithm': integrity_algorithm,
2274 'integrity_key': {
2275 'length': len(integrity_key),
2276 'data': integrity_key,
2277 },
2278 'crypto_algorithm': crypto_algorithm,
2279 'crypto_key': {
2280 'length': len(crypto_key),
2281 'data': crypto_key,
2282 },
2283 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002284 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01002285 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002286 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08002287
Neale Ranns311124e2019-01-24 04:52:25 -08002288 def ipsec_sa_dump(self, sa_id=None):
2289 return self.api(self.papi.ipsec_sa_dump,
2290 {'sa_id': sa_id if sa_id else 0xffffffff})
2291
Neale Ranns17dcec02019-01-09 21:22:20 -08002292 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002293 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02002294 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002295 local_address_start,
2296 local_address_stop,
2297 remote_address_start,
2298 remote_address_stop,
2299 local_port_start=0,
2300 local_port_stop=65535,
2301 remote_port_start=0,
2302 remote_port_stop=65535,
2303 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002304 policy=0,
2305 priority=100,
2306 is_outbound=1,
2307 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02002308 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002309 is_ip_any=0):
2310 """ IPSEC policy SPD add/del -
2311 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02002312 :param spd_id: SPD ID for the policy
2313 :param local_address_start: local-ip-range start address
2314 :param local_address_stop : local-ip-range stop address
2315 :param remote_address_start: remote-ip-range start address
2316 :param remote_address_stop : remote-ip-range stop address
2317 :param local_port_start: (Default value = 0)
2318 :param local_port_stop: (Default value = 65535)
2319 :param remote_port_start: (Default value = 0)
2320 :param remote_port_stop: (Default value = 65535)
2321 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
2322 :param sa_id: Security Association ID for mapping it to SPD
2323 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
2324 (Default value = 0)
2325 :param priority: value for the spd action (Default value = 100)
2326 :param is_outbound: flag for inbound(0) or outbound(1)
2327 (Default value = 1)
2328 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08002329 """
2330 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002331 self.papi.ipsec_spd_entry_add_del,
2332 {
2333 'is_add': is_add,
2334 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002335 {
2336 'spd_id': spd_id,
2337 'sa_id': sa_id,
2338 'local_address_start': local_address_start,
2339 'local_address_stop': local_address_stop,
2340 'remote_address_start': remote_address_start,
2341 'remote_address_stop': remote_address_stop,
2342 'local_port_start': local_port_start,
2343 'local_port_stop': local_port_stop,
2344 'remote_port_start': remote_port_start,
2345 'remote_port_stop': remote_port_stop,
2346 'protocol': protocol,
2347 'policy': policy,
2348 'priority': priority,
2349 'is_outbound': is_outbound,
2350 'is_ip_any': is_ip_any
2351 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002352 })
Florin Corasb795bd02017-12-14 11:30:48 -08002353
Neale Ranns311124e2019-01-24 04:52:25 -08002354 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
2355 return self.api(self.papi.ipsec_spd_dump,
2356 {'spd_id': spd_id,
2357 'sa_id': sa_id})
2358
Klement Sekera31da2e32018-06-24 22:49:55 +02002359 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
2360 remote_spi, crypto_alg, local_crypto_key,
2361 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002362 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02002363 anti_replay=1, renumber=0, show_instance=0):
2364 return self.api(
2365 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002366 {
2367 'local_ip': local_ip,
2368 'remote_ip': remote_ip,
2369 'local_spi': local_spi,
2370 'remote_spi': remote_spi,
2371 'crypto_alg': crypto_alg,
2372 'local_crypto_key_len': len(local_crypto_key),
2373 'local_crypto_key': local_crypto_key,
2374 'remote_crypto_key_len': len(remote_crypto_key),
2375 'remote_crypto_key': remote_crypto_key,
2376 'integ_alg': integ_alg,
2377 'local_integ_key_len': len(local_integ_key),
2378 'local_integ_key': local_integ_key,
2379 'remote_integ_key_len': len(remote_integ_key),
2380 'remote_integ_key': remote_integ_key,
2381 'is_add': is_add,
2382 'esn': esn,
2383 'anti_replay': anti_replay,
2384 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002385 'show_instance': show_instance,
2386 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002387 })
Klement Sekera31da2e32018-06-24 22:49:55 +02002388
Neale Rannsf05e7322019-03-29 20:23:58 +00002389 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
2390 sa_out, sa_in, is_add=1):
2391 return self.api(self.papi.ipsec_gre_tunnel_add_del,
2392 {
2393 'is_add': is_add,
2394 'tunnel': {
2395 'src': local_ip,
2396 'dst': remote_ip,
2397 'local_sa_id': sa_out,
2398 'remote_sa_id': sa_in
2399 }
2400 })
2401
Klement Sekerab4d30532018-11-08 13:00:02 +01002402 def ipsec_select_backend(self, protocol, index):
2403 return self.api(self.papi.ipsec_select_backend,
2404 {'protocol': protocol, 'index': index})
2405
2406 def ipsec_backend_dump(self):
2407 return self.api(self.papi.ipsec_backend_dump, {})
2408
Ole Troane1ade682019-03-04 23:55:43 +01002409 def app_namespace_add_del(self,
2410 namespace_id,
2411 ip4_fib_id=0,
2412 ip6_fib_id=0,
2413 sw_if_index=0xFFFFFFFF,
2414 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08002415 return self.api(
2416 self.papi.app_namespace_add_del,
2417 {'secret': secret,
2418 'sw_if_index': sw_if_index,
2419 'ip4_fib_id': ip4_fib_id,
2420 'ip6_fib_id': ip6_fib_id,
2421 'namespace_id': namespace_id,
2422 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02002423
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002424 def punt_socket_register(self, port, pathname, protocol=0x11,
2425 header_version=1, is_ip4=1):
2426 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02002427 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002428 {'header_version': header_version,
2429 'punt': {'ipv': is_ip4,
2430 'l4_protocol': protocol,
2431 'l4_port': port},
2432 'pathname': pathname})
2433
2434 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
2435 """ Unregister punt socket """
2436 return self.api(self.papi.punt_socket_deregister,
2437 {'punt': {'ipv': is_ip4,
2438 'l4_protocol': protocol,
2439 'l4_port': port}})
2440
2441 def punt_socket_dump(self, is_ip6=1):
2442 """ Dump punt socket"""
2443 return self.api(self.papi.punt_socket_dump,
2444 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02002445
Neale Ranns4ba67722019-02-28 11:11:39 +00002446 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002447 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07002448 """ GBP endpoint Add """
2449 return self.api(self.papi.gbp_endpoint_add,
2450 {'endpoint': {
2451 'sw_if_index': sw_if_index,
2452 'ips': ips,
2453 'n_ips': len(ips),
2454 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00002455 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002456 'flags': flags,
2457 'tun': {
2458 'src': tun_src,
2459 'dst': tun_dst,
2460 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002461
2462 def gbp_endpoint_del(self, handle):
2463 """ GBP endpoint Del """
2464 return self.api(self.papi.gbp_endpoint_del,
2465 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002466
2467 def gbp_endpoint_dump(self):
2468 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002469 return self.api(self.papi.gbp_endpoint_dump,
2470 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002471
Neale Ranns4ba67722019-02-28 11:11:39 +00002472 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002473 rd, uplink_sw_if_index,
2474 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002475 """ GBP endpoint group Add """
2476 return self.api(self.papi.gbp_endpoint_group_add,
2477 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002478 {
2479 'uplink_sw_if_index': uplink_sw_if_index,
2480 'bd_id': bd,
2481 'rd_id': rd,
2482 'vnid': vnid,
2483 'sclass': sclass,
2484 'retention': retention
2485 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002486
Neale Ranns4ba67722019-02-28 11:11:39 +00002487 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002488 """ GBP endpoint group Del """
2489 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002490 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002491
Neale Rannsc29c0af2018-11-07 04:21:12 -08002492 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002493 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002494 uu_fwd_sw_if_index,
2495 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002496 """ GBP bridge-domain Add """
2497 return self.api(self.papi.gbp_bridge_domain_add,
2498 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002499 {
2500 'flags': flags,
2501 'bvi_sw_if_index': bvi_sw_if_index,
2502 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2503 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2504 'bd_id': bd_id
2505 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002506
2507 def gbp_bridge_domain_del(self, bd_id):
2508 """ GBP bridge-domain Del """
2509 return self.api(self.papi.gbp_bridge_domain_del,
2510 {'bd_id': bd_id})
2511
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002512 def gbp_route_domain_add(self, rd_id,
2513 ip4_table_id,
2514 ip6_table_id,
2515 ip4_uu_sw_if_index,
2516 ip6_uu_sw_if_index):
2517 """ GBP route-domain Add """
2518 return self.api(self.papi.gbp_route_domain_add,
2519 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002520 {
2521 'ip4_table_id': ip4_table_id,
2522 'ip6_table_id': ip6_table_id,
2523 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2524 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2525 'rd_id': rd_id
2526 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002527
2528 def gbp_route_domain_del(self, rd_id):
2529 """ GBP route-domain Del """
2530 return self.api(self.papi.gbp_route_domain_del,
2531 {'rd_id': rd_id})
2532
Neale Ranns4ba67722019-02-28 11:11:39 +00002533 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002534 """ GBP recirc Add/Del """
2535 return self.api(self.papi.gbp_recirc_add_del,
2536 {'is_add': is_add,
2537 'recirc': {
2538 'is_ext': is_ext,
2539 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002540 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002541
2542 def gbp_recirc_dump(self):
2543 """ GBP recirc Dump """
2544 return self.api(self.papi.gbp_recirc_dump, {})
2545
Neale Rannsb6a47952018-11-21 05:44:35 -08002546 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2547 """ GBP recirc Add/Del """
2548 return self.api(self.papi.gbp_ext_itf_add_del,
2549 {'is_add': is_add,
2550 'ext_itf': {
2551 'sw_if_index': sw_if_index,
2552 'bd_id': bd_id,
2553 'rd_id': rd_id}})
2554
2555 def gbp_ext_itf_dump(self):
2556 """ GBP recirc Dump """
2557 return self.api(self.papi.gbp_ext_itf_dump, {})
2558
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002559 def gbp_subnet_add_del(self, is_add, rd_id,
2560 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002561 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002562 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002563 """ GBP Subnet Add/Del """
2564 return self.api(self.papi.gbp_subnet_add_del,
2565 {'is_add': is_add,
2566 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002567 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002568 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002569 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002570 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002571 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002572
2573 def gbp_subnet_dump(self):
2574 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002575 return self.api(self.papi.gbp_subnet_dump,
2576 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002577
Neale Ranns4ba67722019-02-28 11:11:39 +00002578 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002579 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002580 """ GBP contract Add/Del """
2581 return self.api(self.papi.gbp_contract_add_del,
2582 {'is_add': is_add,
2583 'contract': {
2584 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002585 'sclass': sclass,
2586 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002587 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002588 'rules': rules,
2589 'n_ether_types': len(allowed_ethertypes),
2590 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002591
2592 def gbp_contract_dump(self):
2593 """ GBP contract Dump """
2594 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002595
Neale Ranns8da9fc62019-03-04 14:08:11 -08002596 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002597 """ GBP VXLAN tunnel add """
2598 return self.api(self.papi.gbp_vxlan_tunnel_add,
2599 {
2600 'tunnel': {
2601 'vni': vni,
2602 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002603 'bd_rd_id': bd_rd_id,
2604 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002605 }
2606 })
2607
2608 def gbp_vxlan_tunnel_del(self, vni):
2609 """ GBP VXLAN tunnel del """
2610 return self.api(self.papi.gbp_vxlan_tunnel_del,
2611 {
2612 'vni': vni,
2613 })
2614
2615 def gbp_vxlan_tunnel_dump(self):
2616 """ GBP VXLAN tunnel add/del """
2617 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2618
Neale Ranns039cbfe2018-02-27 03:45:38 -08002619 def qos_egress_map_update(self, id, outputs):
2620 """ QOS egress map update """
2621 return self.api(self.papi.qos_egress_map_update,
2622 {'map_id': id,
2623 'rows': outputs})
2624
2625 def qos_egress_map_delete(self, id):
2626 """ QOS egress map delete """
2627 return self.api(self.papi.qos_egress_map_delete,
2628 {'map_id': id})
2629
2630 def qos_mark_enable_disable(self, sw_if_index,
2631 output_source,
2632 map_id,
2633 enable):
2634 """ QOS Mark Enable/Disable """
2635 return self.api(self.papi.qos_mark_enable_disable,
2636 {'map_id': map_id,
2637 'sw_if_index': sw_if_index,
2638 'output_source': output_source,
2639 'enable': enable})
2640
Neale Ranns947ea622018-06-07 23:48:20 -07002641 def igmp_enable_disable(self, sw_if_index, enable, host):
2642 """ Enable/disable IGMP on a given interface """
2643 return self.api(self.papi.igmp_enable_disable,
2644 {'enable': enable,
2645 'mode': host,
2646 'sw_if_index': sw_if_index})
2647
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002648 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2649 """ Add/del IGMP proxy device """
2650 return self.api(self.papi.igmp_proxy_device_add_del,
2651 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2652 'add': add})
2653
2654 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2655 """ Add/del interface to/from IGMP proxy device """
2656 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2657 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2658 'add': add})
2659
Neale Ranns947ea622018-06-07 23:48:20 -07002660 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002661 """ Listen for new (S,G) on specified interface
2662
2663 :param enable: add/del
2664 :param sw_if_index: interface sw index
2665 :param saddr: source ip4 addr
2666 :param gaddr: group ip4 addr
2667 """
2668 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002669 {
2670 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002671 {
2672 'filter': filter,
2673 'sw_if_index': sw_if_index,
2674 'n_srcs': len(saddrs),
2675 'saddrs': saddrs,
2676 'gaddr': gaddr
2677 }
Neale Ranns947ea622018-06-07 23:48:20 -07002678 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002679
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002680 def igmp_clear_interface(self, sw_if_index):
2681 """ Remove all (S,G)s from specified interface
2682 doesn't send IGMP report!
2683 """
2684 return self.api(
2685 self.papi.igmp_clear_interface, {
2686 'sw_if_index': sw_if_index})
2687
2688 def want_igmp_events(self, enable=1):
2689 return self.api(self.papi.want_igmp_events, {'enable': enable,
2690 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002691
2692 def bond_create(
2693 self,
2694 mode,
2695 lb,
2696 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002697 mac_address='',
2698 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002699 """
2700 :param mode: mode
2701 :param lb: load balance
2702 :param use_custom_mac: use custom mac
2703 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002704 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002705 """
2706 return self.api(
2707 self.papi.bond_create,
2708 {'mode': mode,
2709 'lb': lb,
2710 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002711 'mac_address': mac_address,
2712 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002713 })
2714
Neale Ranns17ff3c12018-07-04 10:24:24 -07002715 def pipe_delete(self, parent_sw_if_index):
2716 return self.api(self.papi.pipe_delete,
2717 {'parent_sw_if_index': parent_sw_if_index})
2718
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002719 def memif_create(
2720 self,
2721 role,
2722 mode,
2723 rx_queues=None,
2724 tx_queues=None,
2725 _id=None,
2726 socket_id=None,
2727 secret=None,
2728 ring_size=None,
2729 buffer_size=None,
2730 hw_addr=None):
2731 return self.api(self.papi.memif_create,
2732 {'role': role,
2733 'mode': mode,
2734 'rx_queues': rx_queues,
2735 'tx_queues': tx_queues,
2736 'id': _id,
2737 'socket_id': socket_id,
2738 'secret': secret,
2739 'ring_size': ring_size,
2740 'buffer_size': buffer_size,
2741 'hw_addr': hw_addr})
2742
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002743 def svs_table_add_del(self, af, table_id, is_add=1):
2744 return self.api(self.papi.svs_table_add_del,
2745 {
2746 'table_id': table_id,
2747 'is_add': is_add,
2748 'af': af,
2749 })
2750
2751 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2752 return self.api(self.papi.svs_route_add_del,
2753 {
2754 'table_id': table_id,
2755 'source_table_id': src_table_id,
2756 'prefix': prefix,
2757 'is_add': is_add,
2758 })
2759
2760 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2761 return self.api(self.papi.svs_enable_disable,
2762 {
2763 'af': af,
2764 'table_id': table_id,
2765 'sw_if_index': sw_if_index,
2766 'is_enable': is_enable,
2767 })