blob: 8b637f0bd491c31a8d9754f836a2cd521e7ad279 [file] [log] [blame]
Ole Troan9a475372019-03-05 16:58:24 +01001# NB NB NB NB NB NB NB NB NB NB NB
2#
3# NOTE: The API binary wrappers in this file are in the process of being
4# deprecated. DO NOT ADD NEW WRAPPERS HERE. Call the functions using
5# named arguments directly instead.
6#
7
Paul Vinciguerra00671cf2018-11-25 12:47:04 -08008import os
Klement Sekera0e3c0de2016-09-29 14:43:44 +02009import time
Klement Sekerae4504c62016-12-08 10:16:41 +010010from collections import deque
Klement Sekeraf62ae122016-10-11 11:47:09 +020011
Ole Troanf159f582019-02-28 20:20:47 +010012from six import moves, iteritems
Paul Vinciguerra84679192019-01-13 11:33:52 -080013from vpp_papi import VPP, mac_pton
Paul Vinciguerra00671cf2018-11-25 12:47:04 -080014from hook import Hook
Paul Vinciguerrab5f15bd2019-03-17 08:42:58 -070015from vpp_ip_route import MPLS_IETF_MAX_LABEL, MPLS_LABEL_INVALID
Klement Sekeraf62ae122016-10-11 11:47:09 +020016
Klement Sekera0e3c0de2016-09-29 14:43:44 +020017
Neale Ranns039cbfe2018-02-27 03:45:38 -080018class QOS_SOURCE:
19 EXT = 0
20 VLAN = 1
21 MPLS = 2
22 IP = 3
23
24
Matus Fabianb4515b42018-11-19 04:25:32 -080025class SYSLOG_SEVERITY:
26 EMERG = 0
27 ALERT = 1
28 CRIT = 2
29 ERR = 3
30 WARN = 4
31 NOTICE = 5
32 INFO = 6
33 DBG = 7
34
Ole Troan9a475372019-03-05 16:58:24 +010035
Ole Troanf159f582019-02-28 20:20:47 +010036#
37# Dictionary keyed on message name to override default values for
38# named parameters
39#
Ole Troan9a475372019-03-05 16:58:24 +010040defaultmapping = {
41 'map_add_domain': {'mtu': 1280},
42 'syslog_set_sender': {'collector_port': 514,
43 'max_msg_size': 480},
44 'acl_interface_add_del': {'is_add': 1, 'is_input': 1},
45 'acl_interface_list_dump': {'sw_if_index': 4294967295, },
46 'app_namespace_add_del': {'sw_if_index': 4294967295, },
47 'bd_ip_mac_add_del': {'is_add': 1, },
48 'bier_disp_entry_add_del': {'next_hop_rpf_id': -1, 'next_hop_is_ip4': 1,
49 'is_add': 1, },
50 'bier_disp_table_add_del': {'is_add': 1, },
51 'bier_imp_add': {'is_add': 1, },
52 'bier_route_add_del': {'is_add': 1, },
53 'bier_table_add_del': {'is_add': 1, },
54 'bridge_domain_add_del': {'flood': 1, 'uu_flood': 1, 'forward': 1,
55 'learn': 1, 'is_add': 1, },
56 'classify_add_del_table': {'match_n_vectors': 1, 'table_index': 4294967295,
57 'nbuckets': 2, 'memory_size': 2097152,
58 'next_table_index': 4294967295,
59 'miss_next_index': 4294967295, },
60 'dhcp6_client_enable_disable': {'enable': 1, },
61 'dhcp6_clients_enable_disable': {'enable': 1, },
62 'dhcp6_pd_client_enable_disable': {'enable': 1, },
63 'dhcp6_send_client_message': {'server_index': 4294967295, 'mrc': 1, },
64 'dhcp_client_config': {'is_add': 1, 'set_broadcast_flag': 1, },
65 'dhcp_proxy_config': {'is_add': 1, },
66 'dhcp_proxy_set_vss': {'vss_type': 255, 'is_add': 1, },
67 'dslite_add_del_pool_addr_range': {'is_add': 1, },
68 'gbp_subnet_add_del': {'sw_if_index': 4294967295, 'epg_id': 65535, },
69 'geneve_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
70 'decap_next_index': 4294967295, },
Neale Ranns5a8844b2019-04-16 07:15:35 +000071 'gre_tunnel_add_del': {'instance': 4294967295, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +010072 'gtpu_add_del_tunnel': {'is_add': 1, 'mcast_sw_if_index': 4294967295,
73 'decap_next_index': 4294967295, },
74 'input_acl_set_interface': {'ip4_table_index': 4294967295,
75 'ip6_table_index': 4294967295,
76 'l2_table_index': 4294967295, },
77 'ip6_add_del_address_using_prefix': {'is_add': 1, },
78 'ip6nd_send_router_solicitation': {'irt': 1, 'mrt': 120, },
79 'ip_add_del_route': {'next_hop_sw_if_index': 4294967295,
80 'next_hop_weight': 1, 'next_hop_via_label': 1048576,
81 'next_hop_id': 4294967295,
82 'classify_table_index': 4294967295, 'is_add': 1, },
83 'ip_mroute_add_del': {'is_add': 1, },
84 'ip_neighbor_add_del': {'is_add': 1, },
85 'ip_punt_police': {'is_add': 1, },
86 'ip_punt_redirect': {'is_add': 1, },
87 'ip_table_add_del': {'is_add': 1, },
88 'ip_unnumbered_dump': {'sw_if_index': 4294967295, },
89 'ipip_add_tunnel': {'is_ipv6': 1, 'instance': 4294967295, },
90 'ipsec_interface_add_del_spd': {'is_add': 1, },
91 'ipsec_sad_entry_add_del': {'is_add': 1, },
92 'ipsec_spd_add_del': {'is_add': 1, },
93 'ipsec_spd_dump': {'sa_id': 4294967295, },
94 'ipsec_spd_entry_add_del': {'local_port_stop': 65535,
95 'remote_port_stop': 65535, 'priority': 100,
96 'is_outbound': 1,
97 'is_add': 1, },
98 'ipsec_tunnel_if_add_del': {'is_add': 1, 'anti_replay': 1, },
99 'l2_emulation': {'enable': 1, },
100 'l2fib_add_del': {'is_add': 1, },
Paul Vinciguerraf7f13342019-03-19 11:54:39 -0700101 'lb_conf': {'sticky_buckets_per_core': 4294967295,
102 'flow_timeout': 4294967295},
Ole Troan9a475372019-03-05 16:58:24 +0100103 'lisp_add_del_adjacency': {'is_add': 1, },
104 'lisp_add_del_local_eid': {'is_add': 1, },
105 'lisp_add_del_locator': {'priority': 1, 'weight': 1, 'is_add': 1, },
106 'lisp_add_del_locator_set': {'is_add': 1, },
107 'lisp_add_del_remote_mapping': {'is_add': 1, },
108 'macip_acl_add_replace': {'acl_index': 4294967295, },
109 'macip_acl_dump': {'acl_index': 4294967295, },
110 'macip_acl_interface_add_del': {'is_add': 1, },
111 'mpls_ip_bind_unbind': {'is_ip4': 1, 'is_bind': 1, },
Ole Troana5b2eec2019-03-11 19:23:25 +0100112 'mpls_route_add_del': {'mr_next_hop_sw_if_index': 4294967295,
113 'mr_next_hop_weight': 1,
114 'mr_next_hop_via_label': 1048576,
115 'mr_is_add': 1,
116 'mr_classify_table_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100117 'mpls_table_add_del': {'is_add': 1, },
118 'mpls_tunnel_add_del': {'next_hop_sw_if_index': 4294967295,
119 'next_hop_weight': 1,
120 'next_hop_via_label': 1048576,
121 'is_add': 1, },
122 'mpls_tunnel_dump': {'sw_if_index': 4294967295, },
123 'nat44_add_del_address_range': {'is_add': 1, 'vrf_id': 4294967295, },
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800124 'nat44_add_del_identity_mapping': {'ip': b'0', 'sw_if_index': 4294967295,
Ole Trøan89fec712019-04-23 12:38:35 +0000125 'addr_only': 1, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100126 'nat44_add_del_interface_addr': {'is_add': 1, },
127 'nat44_add_del_lb_static_mapping': {'is_add': 1, },
128 'nat44_add_del_static_mapping': {'external_sw_if_index': 4294967295,
Ole Trøan89fec712019-04-23 12:38:35 +0000129 'addr_only': 1, 'is_add': 1, },
130 'nat44_del_session': {'is_in': 1, },
131 'nat44_interface_add_del_feature': {'is_inside': 1, 'is_add': 1, },
132 'nat44_interface_add_del_output_feature': {'is_inside': 1, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100133 'nat44_lb_static_mapping_add_del_local': {'is_add': 1, },
Ole Trøan89fec712019-04-23 12:38:35 +0000134 'nat64_add_del_interface': {'is_inside': 1, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100135 'nat64_add_del_interface_addr': {'is_add': 1, },
136 'nat64_add_del_pool_addr_range': {'vrf_id': 4294967295, 'is_add': 1, },
137 'nat64_add_del_prefix': {'is_add': 1, },
138 'nat64_add_del_static_bib': {'is_add': 1, },
139 'nat64_bib_dump': {'protocol': 255, },
140 'nat64_st_dump': {'protocol': 255, },
Ole Trøan89fec712019-04-23 12:38:35 +0000141 'nat66_add_del_interface': {'is_inside': 1, 'is_add': 1, },
Ole Troan9a475372019-03-05 16:58:24 +0100142 'nat66_add_del_static_mapping': {'is_add': 1, },
143 'nat_det_add_del_map': {'is_add': 1, },
144 'nat_ha_resync': {'want_resync_event': 1, },
145 'nat_ha_set_failover': {'refresh': 10, },
146 'nat_ha_set_listener': {'path_mtu': 512, },
147 'nat_ipfix_enable_disable': {'domain_id': 1, 'src_port': 4739,
148 'enable': 1, },
149 'nat_set_mss_clamping': {'mss_value': 1500, },
150 'nat_set_reass': {'timeout': 2, 'max_reass': 1024, 'max_frag': 5, },
151 'nat_set_timeouts': {'udp': 300, 'tcp_established': 7440,
152 'tcp_transitory': 240, 'icmp': 60, },
153 'output_acl_set_interface': {'ip4_table_index': 4294967295,
154 'ip6_table_index': 4294967295,
155 'l2_table_index': 4294967295, },
156 'pppoe_add_del_session': {'is_add': 1, },
157 'policer_add_del': {'is_add': 1, 'conform_action_type': 1, },
158 'proxy_arp_add_del': {'is_add': 1, },
159 'proxy_arp_intfc_enable_disable': {'is_enable': 1, },
160 'punt_socket_register': {'protocol': 17, 'header_version': 1,
161 'is_ip4': 1, },
162 'punt_socket_deregister': {'protocol': 17, 'is_ip4': 1, },
163 'punt_socket_dump': {'is_ip6': 1, },
164 'set_ip_flow_hash': {'src': 1, 'dst': 1, 'sport': 1, 'dport': 1,
165 'proto': 1, },
166 'set_ipfix_exporter': {'collector_port': 4739, },
167 'sr_localsid_add_del': {'sw_if_index': 4294967295, },
168 'sr_policy_add': {'weight': 1, 'is_encap': 1, },
169 'svs_enable_disable': {'is_enable': 1, },
170 'svs_route_add_del': {'is_add': 1, },
171 'svs_table_add_del': {'is_add': 1, },
172 'sw_interface_add_del_address': {'is_add': 1, },
Paul Vinciguerra6407ba52019-04-04 13:22:20 -0700173 'sw_interface_dump': {'sw_if_index': 4294967295, },
Ole Troan9a475372019-03-05 16:58:24 +0100174 'sw_interface_ip6nd_ra_prefix': {'val_lifetime': 4294967295,
175 'pref_lifetime': 4294967295, },
176 'sw_interface_set_ip_directed_broadcast': {'enable': 1, },
177 'sw_interface_set_l2_bridge': {'enable': 1, },
178 'sw_interface_set_mpls_enable': {'enable': 1, },
179 'sw_interface_set_mtu': {'mtu': [0, 0, 0, 0], },
180 'sw_interface_set_unnumbered': {'is_add': 1, },
181 'sw_interface_span_enable_disable': {'state': 1, },
182 'vxlan_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
183 'decap_next_index': 4294967295,
184 'instance': 4294967295, },
185 'vxlan_gbp_tunnel_add_del': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
186 'instance': 4294967295, },
187 'vxlan_gbp_tunnel_dump': {'sw_if_index': 4294967295, },
188 'vxlan_gpe_add_del_tunnel': {'mcast_sw_if_index': 4294967295, 'is_add': 1,
189 'protocol': 3, },
190 'want_bfd_events': {'enable_disable': 1, },
191 'want_dhcp6_pd_reply_events': {'enable_disable': 1, },
192 'want_dhcp6_reply_events': {'enable_disable': 1, },
193 'want_igmp_events': {'enable': 1, },
194 'want_interface_events': {'enable_disable': 1, },
195 'want_ip4_arp_events': {'enable_disable': 1, 'ip': '0.0.0.0', },
196 'want_ip6_nd_events': {'enable_disable': 1, 'ip': '::', },
197 'want_ip6_ra_events': {'enable_disable': 1, },
198 'want_l2_macs_events': {'enable_disable': 1, },
199}
Ole Troanf159f582019-02-28 20:20:47 +0100200
Matus Fabianb4515b42018-11-19 04:25:32 -0800201
Klement Sekera73884482017-02-23 09:26:30 +0100202class UnexpectedApiReturnValueError(Exception):
203 """ exception raised when the API return value is unexpected """
204 pass
205
206
Klement Sekeraf62ae122016-10-11 11:47:09 +0200207class VppPapiProvider(object):
208 """VPP-api provider using vpp-papi
209
210 @property hook: hook object providing before and after api/cli hooks
Klement Sekeraf62ae122016-10-11 11:47:09 +0200211 """
212
Klement Sekerae0545ef2017-01-25 08:00:40 +0100213 _zero, _negative = range(2)
214
Klement Sekera611864f2018-09-26 11:19:00 +0200215 def __init__(self, name, shm_prefix, test_class, read_timeout):
Paul Vinciguerra895e2f82019-01-08 20:37:40 -0800216 self.hook = Hook(test_class)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200217 self.name = name
218 self.shm_prefix = shm_prefix
Klement Sekera7bb873a2016-11-18 07:38:42 +0100219 self.test_class = test_class
Klement Sekerae0545ef2017-01-25 08:00:40 +0100220 self._expect_api_retval = self._zero
221 self._expect_stack = []
Ole Troan7e3a8752016-12-05 10:27:09 +0100222
Klement Sekerab8c72a42018-11-08 11:21:39 +0100223 install_dir = os.getenv('VPP_INSTALL_PATH')
Ole Troan7e3a8752016-12-05 10:27:09 +0100224
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800225 # Vapi requires 'VPP_API_DIR', not set when run from Makefile.
226 if 'VPP_API_DIR' not in os.environ:
227 os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH')
228
Ole Troan4ff09ae2019-04-15 11:27:22 +0200229 use_socket = False
230 try:
231 if os.environ['SOCKET'] == '1':
232 use_socket = True
233 except:
234 pass
Paul Vinciguerra04575c52019-01-13 10:26:05 -0800235 self.vpp = VPP(logger=test_class.logger,
Ole Troan4ff09ae2019-04-15 11:27:22 +0200236 read_timeout=read_timeout,
237 use_socket=use_socket,
238 server_address=test_class.api_sock)
Klement Sekerae4504c62016-12-08 10:16:41 +0100239 self._events = deque()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200240
Klement Sekerae0545ef2017-01-25 08:00:40 +0100241 def __enter__(self):
242 return self
243
Klement Sekera7d6afb32018-11-08 11:52:04 +0100244 def assert_negative_api_retval(self):
245 """ Expect API failure - used with with, e.g.:
246 with self.vapi.assert_negative_api_retval():
247 self.vapi.<api call expected to fail>
248 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100249 self._expect_stack.append(self._expect_api_retval)
250 self._expect_api_retval = self._negative
251 return self
252
Klement Sekera7d6afb32018-11-08 11:52:04 +0100253 def assert_zero_api_retval(self):
254 """ Expect API success - used with with, e.g.:
255 with self.vapi.assert_negative_api_retval():
256 self.vapi.<api call expected to succeed>
257
258 note: this is useful only inside another with block
259 as success is the default expected value
260 """
Klement Sekerae0545ef2017-01-25 08:00:40 +0100261 self._expect_stack.append(self._expect_api_retval)
262 self._expect_api_retval = self._zero
263 return self
264
265 def __exit__(self, exc_type, exc_value, traceback):
266 self._expect_api_retval = self._expect_stack.pop()
267
Klement Sekeraf62ae122016-10-11 11:47:09 +0200268 def register_hook(self, hook):
269 """Replace hook registration with new hook
270
271 :param hook:
272
273 """
274 self.hook = hook
275
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200276 def collect_events(self):
Klement Sekerae4504c62016-12-08 10:16:41 +0100277 """ Collect all events from the internal queue and clear the queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200278 e = self._events
Klement Sekerae4504c62016-12-08 10:16:41 +0100279 self._events = deque()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200280 return e
281
282 def wait_for_event(self, timeout, name=None):
Klement Sekerae4504c62016-12-08 10:16:41 +0100283 """ Wait for and return next event. """
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100284 if name:
Klement Sekeraacb9b8e2017-02-14 02:55:31 +0100285 self.test_class.logger.debug("Expecting event '%s' within %ss",
286 name, timeout)
Eyal Bari20197482017-09-13 12:29:08 +0300287 else:
288 self.test_class.logger.debug("Expecting event within %ss",
289 timeout)
Klement Sekerae4504c62016-12-08 10:16:41 +0100290 if self._events:
291 self.test_class.logger.debug("Not waiting, event already queued")
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200292 limit = time.time() + timeout
293 while time.time() < limit:
294 if self._events:
Klement Sekerae4504c62016-12-08 10:16:41 +0100295 e = self._events.popleft()
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200296 if name and type(e).__name__ != name:
297 raise Exception(
298 "Unexpected event received: %s, expected: %s" %
299 (type(e).__name__, name))
Klement Sekerae4504c62016-12-08 10:16:41 +0100300 self.test_class.logger.debug("Returning event %s:%s" %
301 (name, e))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200302 return e
Paul Vinciguerra0f6602c2019-03-10 09:10:54 -0700303 self.test_class.sleep(0) # yield
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200304 raise Exception("Event did not occur within timeout")
305
306 def __call__(self, name, event):
Klement Sekerae4504c62016-12-08 10:16:41 +0100307 """ Enqueue event in the internal event queue. """
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200308 # FIXME use the name instead of relying on type(e).__name__ ?
309 # FIXME #2 if this throws, it is eaten silently, Ole?
Klement Sekerae4504c62016-12-08 10:16:41 +0100310 self.test_class.logger.debug("New event: %s: %s" % (name, event))
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200311 self._events.append(event)
312
Ole Troanf159f582019-02-28 20:20:47 +0100313 def factory(self, name, apifn):
314 def f(*a, **ka):
315 fields = apifn._func.msg.fields
316
317 # add positional and kw arguments
318 d = ka
319 for i, o in enumerate(fields[3:]):
320 try:
321 d[o] = a[i]
322 except:
323 break
324
325 # Default override
326 if name in defaultmapping:
327 for k, v in iteritems(defaultmapping[name]):
328 if k in d:
329 continue
330 d[k] = v
331 return self.api(apifn, d)
Ole Troan9a475372019-03-05 16:58:24 +0100332
Ole Troanf159f582019-02-28 20:20:47 +0100333 return f
334
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800335 def __getattribute__(self, name):
Ole Troanf159f582019-02-28 20:20:47 +0100336 try:
Paul Vinciguerra7ab99702019-03-05 04:30:04 -0800337 method = super(VppPapiProvider, self).__getattribute__(name)
338 except AttributeError:
339 method = self.factory(name, getattr(self.papi, name))
340 # lazily load the method so we don't need to call factory
341 # again for this name.
342 setattr(self, name, method)
343 return method
Ole Troanf159f582019-02-28 20:20:47 +0100344
Klement Sekeraf62ae122016-10-11 11:47:09 +0200345 def connect(self):
346 """Connect the API to VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100347 self.vpp.connect(self.name, self.shm_prefix)
348 self.papi = self.vpp.api
349 self.vpp.register_event_callback(self)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200350
351 def disconnect(self):
352 """Disconnect the API from VPP"""
Klement Sekera7112c542017-03-01 09:53:19 +0100353 self.vpp.disconnect()
Klement Sekeraf62ae122016-10-11 11:47:09 +0200354
355 def api(self, api_fn, api_args, expected_retval=0):
Klement Sekerae4504c62016-12-08 10:16:41 +0100356 """ Call API function and check it's return value.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200357 Call the appropriate hooks before and after the API call
358
359 :param api_fn: API function to call
360 :param api_args: tuple of API function arguments
361 :param expected_retval: Expected return value (Default value = 0)
362 :returns: reply from the API
363
364 """
365 self.hook.before_api(api_fn.__name__, api_args)
Ole Troan7e3a8752016-12-05 10:27:09 +0100366 reply = api_fn(**api_args)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100367 if self._expect_api_retval == self._negative:
368 if hasattr(reply, 'retval') and reply.retval >= 0:
Ole Troan9a475372019-03-05 16:58:24 +0100369 msg = "API call passed unexpectedly: expected negative " \
370 "return value instead of %d in %s" % \
371 (reply.retval, moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100372 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100373 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100374 elif self._expect_api_retval == self._zero:
375 if hasattr(reply, 'retval') and reply.retval != expected_retval:
Ole Troan9a475372019-03-05 16:58:24 +0100376 msg = "API call failed, expected %d return value instead " \
377 "of %d in %s" % (expected_retval, reply.retval,
378 moves.reprlib.repr(reply))
Klement Sekerae0545ef2017-01-25 08:00:40 +0100379 self.test_class.logger.info(msg)
Klement Sekera73884482017-02-23 09:26:30 +0100380 raise UnexpectedApiReturnValueError(msg)
Klement Sekerae0545ef2017-01-25 08:00:40 +0100381 else:
382 raise Exception("Internal error, unexpected value for "
383 "self._expect_api_retval %s" %
384 self._expect_api_retval)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200385 self.hook.after_api(api_fn.__name__, api_args)
386 return reply
387
388 def cli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100389 """ Execute a CLI, calling the before/after hooks appropriately.
Klement Sekeraf62ae122016-10-11 11:47:09 +0200390
391 :param cli: CLI to execute
392 :returns: CLI output
393
394 """
395 self.hook.before_cli(cli)
396 cli += '\n'
Ole Troan413f4a52018-11-28 11:36:05 +0100397 r = self.papi.cli_inband(cmd=cli)
Klement Sekeraf62ae122016-10-11 11:47:09 +0200398 self.hook.after_cli(cli)
Jan49c0fca2016-10-26 15:44:27 +0200399 if hasattr(r, 'reply'):
Ole Troan413f4a52018-11-28 11:36:05 +0100400 return r.reply
Klement Sekeraf62ae122016-10-11 11:47:09 +0200401
Jan49c0fca2016-10-26 15:44:27 +0200402 def ppcli(self, cli):
Klement Sekerae4504c62016-12-08 10:16:41 +0100403 """ Helper method to print CLI command in case of info logging level.
Jan49c0fca2016-10-26 15:44:27 +0200404
405 :param cli: CLI to execute
406 :returns: CLI output
407 """
Ed Warnickeb8ff5d62016-11-28 13:59:22 -0600408 return cli + "\n" + str(self.cli(cli))
Jan49c0fca2016-10-26 15:44:27 +0200409
Neale Ranns37029302018-08-10 05:30:06 -0700410 def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
Eyal Bari20197482017-09-13 12:29:08 +0300411 return self.api(self.papi.want_ip4_arp_events,
412 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700413 'ip': ip,
Eyal Bari20197482017-09-13 12:29:08 +0300414 'pid': os.getpid(), })
415
Neale Ranns37029302018-08-10 05:30:06 -0700416 def want_ip6_nd_events(self, enable_disable=1, ip="::"):
Eyal Baric125ecc2017-09-20 11:29:17 +0300417 return self.api(self.papi.want_ip6_nd_events,
418 {'enable_disable': enable_disable,
Neale Ranns37029302018-08-10 05:30:06 -0700419 'ip': ip,
Eyal Baric125ecc2017-09-20 11:29:17 +0300420 'pid': os.getpid(), })
421
Juraj Sloboda4b9669d2018-01-15 10:39:21 +0100422 def want_ip6_ra_events(self, enable_disable=1):
423 return self.api(self.papi.want_ip6_ra_events,
424 {'enable_disable': enable_disable,
425 'pid': os.getpid(), })
426
427 def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120,
428 mrc=0, mrd=0):
429 return self.api(self.papi.ip6nd_send_router_solicitation,
430 {'irt': irt,
431 'mrt': mrt,
432 'mrc': mrc,
433 'mrd': mrd,
434 'sw_if_index': sw_if_index})
435
Juraj Slobodab3f90502018-10-04 15:15:16 +0200436 def want_interface_events(self, enable_disable=1):
437 return self.api(self.papi.want_interface_events,
438 {'enable_disable': enable_disable,
439 'pid': os.getpid(), })
440
Ole Troane1ade682019-03-04 23:55:43 +0100441 def want_l2_macs_events(self, enable_disable=1, scan_delay=0,
442 max_macs_in_event=0, learn_limit=0):
Eyal Bari24db0ec2017-09-27 21:43:51 +0300443 return self.api(self.papi.want_l2_macs_events,
444 {'enable_disable': enable_disable,
445 'scan_delay': scan_delay,
446 'max_macs_in_event': max_macs_in_event,
447 'learn_limit': learn_limit,
448 'pid': os.getpid(), })
449
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200450 def want_dhcp6_reply_events(self, enable_disable=1):
451 return self.api(self.papi.want_dhcp6_reply_events,
452 {'enable_disable': enable_disable,
453 'pid': os.getpid()})
454
Juraj Sloboda81119e82018-05-25 14:02:20 +0200455 def want_dhcp6_pd_reply_events(self, enable_disable=1):
456 return self.api(self.papi.want_dhcp6_pd_reply_events,
457 {'enable_disable': enable_disable,
458 'pid': os.getpid()})
459
Juraj Sloboda81119e82018-05-25 14:02:20 +0200460 def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2,
461 prefixes, server_index=0xFFFFFFFF,
462 irt=0, mrt=0, mrc=1, mrd=0, stop=0,
463 ):
464 return self.api(self.papi.dhcp6_pd_send_client_message,
465 {'sw_if_index': sw_if_index,
466 'server_index': server_index,
467 'irt': irt,
468 'mrt': mrt,
469 'mrc': mrc,
470 'mrd': mrd,
471 'stop': stop,
472 'msg_type': msg_type,
473 'T1': T1,
474 'T2': T2,
475 'n_prefixes': len(prefixes),
476 'prefixes': prefixes})
477
Juraj Slobodadd3b8f72018-05-04 14:20:06 +0200478 def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='',
479 enable=1):
480 return self.api(self.papi.dhcp6_client_enable_disable,
481 {'sw_if_index': sw_if_index,
482 'enable': enable})
483
Juraj Sloboda81119e82018-05-25 14:02:20 +0200484 def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='',
485 enable=1):
486 return self.api(self.papi.dhcp6_pd_client_enable_disable,
487 {'sw_if_index': sw_if_index,
488 'prefix_group': prefix_group,
489 'enable': enable})
490
491 def ip6_add_del_address_using_prefix(self, sw_if_index, address,
492 prefix_length, prefix_group,
493 is_add=1):
494 return self.api(self.papi.ip6_add_del_address_using_prefix,
495 {'sw_if_index': sw_if_index,
496 'prefix_group': prefix_group,
497 'address': address,
498 'prefix_length': prefix_length,
499 'is_add': is_add})
500
Neale Rannsc819fc62018-02-16 02:44:05 -0800501 def sw_interface_set_mac_address(self, sw_if_index, mac):
502 return self.api(self.papi.sw_interface_set_mac_address,
503 {'sw_if_index': sw_if_index,
504 'mac_address': mac})
505
Ole Troane1ade682019-03-04 23:55:43 +0100506 def p2p_ethernet_add(self, sw_if_index, remote_mac, subif_id):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200507 """Create p2p ethernet subinterface
508
509 :param sw_if_index: main (parent) interface
510 :param remote_mac: client (remote) mac address
511
512 """
513 return self.api(
514 self.papi.p2p_ethernet_add,
515 {'parent_if_index': sw_if_index,
516 'remote_mac': remote_mac,
517 'subif_id': subif_id})
518
Ole Troane1ade682019-03-04 23:55:43 +0100519 def p2p_ethernet_del(self, sw_if_index, remote_mac):
Pavel Kotucek15ac81c2017-06-20 14:00:26 +0200520 """Delete p2p ethernet subinterface
521
522 :param sw_if_index: main (parent) interface
523 :param remote_mac: client (remote) mac address
524
525 """
526 return self.api(
527 self.papi.p2p_ethernet_del,
528 {'parent_if_index': sw_if_index,
529 'remote_mac': remote_mac})
530
Klement Sekeraf62ae122016-10-11 11:47:09 +0200531 def create_vlan_subif(self, sw_if_index, vlan):
532 """
533
534 :param vlan:
535 :param sw_if_index:
536
537 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100538 return self.api(self.papi.create_vlan_subif,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200539 {'sw_if_index': sw_if_index,
540 'vlan_id': vlan})
Klement Sekeraf62ae122016-10-11 11:47:09 +0200541
Matej Klotton0178d522016-11-04 11:11:44 +0100542 def create_loopback(self, mac=''):
543 """
544
545 :param mac: (Optional)
546 """
Ole Troan7e3a8752016-12-05 10:27:09 +0100547 return self.api(self.papi.create_loopback,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200548 {'mac_address': mac})
Matej Klotton0178d522016-11-04 11:11:44 +0100549
Matej Klotton0178d522016-11-04 11:11:44 +0100550 def ip_neighbor_add_del(self,
551 sw_if_index,
552 mac_address,
Neale Ranns37029302018-08-10 05:30:06 -0700553 ip_address,
Matej Klotton0178d522016-11-04 11:11:44 +0100554 is_add=1,
Neale Ranns37029302018-08-10 05:30:06 -0700555 flags=0):
Matej Klotton0178d522016-11-04 11:11:44 +0100556 """ Add neighbor MAC to IPv4 or IPv6 address.
557
558 :param sw_if_index:
559 :param mac_address:
560 :param dst_address:
Matej Klotton0178d522016-11-04 11:11:44 +0100561 :param is_add: (Default value = 1)
Neale Ranns37029302018-08-10 05:30:06 -0700562 :param flags: (Default value = 0/NONE)
Matej Klotton0178d522016-11-04 11:11:44 +0100563 """
Matej Klotton0178d522016-11-04 11:11:44 +0100564 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100565 self.papi.ip_neighbor_add_del,
Neale Ranns37029302018-08-10 05:30:06 -0700566 {
567 'is_add': is_add,
568 'neighbor': {
569 'sw_if_index': sw_if_index,
570 'flags': flags,
571 'mac_address': mac_address,
572 'ip_address': ip_address
573 }
574 }
Matej Klotton0178d522016-11-04 11:11:44 +0100575 )
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100576
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800577 def proxy_arp_add_del(self,
Neale Ranns37029302018-08-10 05:30:06 -0700578 low,
579 hi,
580 table_id=0,
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800581 is_add=1):
582 """ Config Proxy Arp Range.
583
584 :param low_address: Start address in the rnage to Proxy for
585 :param hi_address: End address in the rnage to Proxy for
586 :param vrf_id: The VRF/table in which to proxy
587 """
588
589 return self.api(
590 self.papi.proxy_arp_add_del,
Neale Ranns0053de62018-05-22 08:40:52 -0700591 {'proxy':
Ole Troan9a475372019-03-05 16:58:24 +0100592 {
593 'table_id': table_id,
594 'low': low,
595 'hi': hi,
596 },
597 'is_add': is_add})
Neale Ranns39f9d8b2017-02-16 21:57:05 -0800598
599 def proxy_arp_intfc_enable_disable(self,
600 sw_if_index,
601 is_enable=1):
602 """ Enable/Disable an interface for proxy ARP requests
603
604 :param sw_if_index: Interface
605 :param enable_disable: Enable/Disable
606 """
607
608 return self.api(
609 self.papi.proxy_arp_intfc_enable_disable,
610 {'sw_if_index': sw_if_index,
611 'enable_disable': is_enable
612 }
613 )
614
Neale Ranns5a8844b2019-04-16 07:15:35 +0000615 def gre_tunnel_add_del(self,
616 src,
617 dst,
Neale Ranns177bbdc2016-11-15 09:46:51 +0000618 outer_fib_id=0,
John Loa43ccae2018-02-13 17:15:23 -0500619 tunnel_type=0,
620 instance=0xFFFFFFFF,
621 session_id=0,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000622 is_add=1):
Neale Ranns177bbdc2016-11-15 09:46:51 +0000623 """ Add a GRE tunnel
624
625 :param src_address:
626 :param dst_address:
627 :param outer_fib_id: (Default value = 0)
John Loa43ccae2018-02-13 17:15:23 -0500628 :param tunnel_type: (Default value = 0)
629 :param instance: (Default value = 0xFFFFFFFF)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700630 :param session_id: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000631 :param is_add: (Default value = 1)
632 :param is_ipv6: (Default value = 0)
Neale Ranns177bbdc2016-11-15 09:46:51 +0000633 """
634
635 return self.api(
Neale Ranns5a8844b2019-04-16 07:15:35 +0000636 self.papi.gre_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200637 {'is_add': is_add,
Neale Ranns5a8844b2019-04-16 07:15:35 +0000638 'tunnel':
639 {
640 'type': tunnel_type,
641 'instance': instance,
642 'src': src,
643 'dst': dst,
644 'outer_fib_id': outer_fib_id,
645 'session_id': session_id}
646 }
Neale Ranns177bbdc2016-11-15 09:46:51 +0000647 )
Neale Rannsad422ed2016-11-02 14:20:04 +0000648
Neale Rannsd0df49f2018-08-08 01:06:40 -0700649 def udp_encap_add(self,
Neale Rannsd0df49f2018-08-08 01:06:40 -0700650 src_ip,
651 dst_ip,
652 src_port,
653 dst_port,
654 table_id=0):
Neale Ranns810086d2017-11-05 16:26:46 -0800655 """ Add a GRE tunnel
Neale Ranns810086d2017-11-05 16:26:46 -0800656 :param src_ip:
657 :param dst_ip:
658 :param src_port:
659 :param dst_port:
660 :param outer_fib_id: (Default value = 0)
Neale Ranns810086d2017-11-05 16:26:46 -0800661 """
662
663 return self.api(
Neale Rannsd0df49f2018-08-08 01:06:40 -0700664 self.papi.udp_encap_add,
665 {
666 'udp_encap': {
Neale Rannsd0df49f2018-08-08 01:06:40 -0700667 'src_ip': src_ip,
668 'dst_ip': dst_ip,
669 'src_port': src_port,
670 'dst_port': dst_port,
671 'table_id': table_id
672 }
673 })
674
Neale Ranns15002542017-09-10 04:39:11 -0700675 def mpls_table_add_del(
676 self,
677 table_id,
678 is_add=1):
679 """
680
681 :param table_id
682 :param is_add: (Default value = 1)
683
684 """
685
686 return self.api(
687 self.papi.mpls_table_add_del,
688 {'mt_table_id': table_id,
689 'mt_is_add': is_add})
690
Neale Rannsad422ed2016-11-02 14:20:04 +0000691 def mpls_ip_bind_unbind(
692 self,
693 label,
694 dst_address,
695 dst_address_length,
696 table_id=0,
697 ip_table_id=0,
698 is_ip4=1,
Neale Rannsad422ed2016-11-02 14:20:04 +0000699 is_bind=1):
700 """
701 """
702 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100703 self.papi.mpls_ip_bind_unbind,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200704 {'mb_mpls_table_id': table_id,
705 'mb_label': label,
706 'mb_ip_table_id': ip_table_id,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200707 'mb_is_bind': is_bind,
708 'mb_is_ip4': is_ip4,
709 'mb_address_length': dst_address_length,
710 'mb_address': dst_address})
Neale Rannsad422ed2016-11-02 14:20:04 +0000711
712 def mpls_tunnel_add_del(
713 self,
714 tun_sw_if_index,
715 next_hop_proto_is_ip4,
716 next_hop_address,
717 next_hop_sw_if_index=0xFFFFFFFF,
718 next_hop_table_id=0,
719 next_hop_weight=1,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200720 next_hop_n_out_labels=0,
721 next_hop_out_label_stack=[],
722 next_hop_via_label=MPLS_LABEL_INVALID,
Neale Rannsad422ed2016-11-02 14:20:04 +0000723 is_add=1,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800724 l2_only=0,
725 is_multicast=0):
Neale Rannsad422ed2016-11-02 14:20:04 +0000726 """
727
728 :param dst_address_length:
729 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
730 :param dst_address:
731 :param next_hop_address:
732 :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF)
733 :param vrf_id: (Default value = 0)
734 :param lookup_in_vrf: (Default value = 0)
735 :param classify_table_index: (Default value = 0xFFFFFFFF)
Neale Rannsad422ed2016-11-02 14:20:04 +0000736 :param is_add: (Default value = 1)
737 :param is_drop: (Default value = 0)
738 :param is_ipv6: (Default value = 0)
739 :param is_local: (Default value = 0)
740 :param is_classify: (Default value = 0)
741 :param is_multipath: (Default value = 0)
742 :param is_resolve_host: (Default value = 0)
743 :param is_resolve_attached: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000744 :param next_hop_weight: (Default value = 1)
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800745 :param is_multicast: (Default value = 0)
Neale Rannsad422ed2016-11-02 14:20:04 +0000746
747 """
Neale Rannsad422ed2016-11-02 14:20:04 +0000748 return self.api(
Ole Troan7e3a8752016-12-05 10:27:09 +0100749 self.papi.mpls_tunnel_add_del,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200750 {'mt_sw_if_index': tun_sw_if_index,
751 'mt_is_add': is_add,
752 'mt_l2_only': l2_only,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800753 'mt_is_multicast': is_multicast,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200754 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
755 'mt_next_hop_weight': next_hop_weight,
756 'mt_next_hop': next_hop_address,
757 'mt_next_hop_n_out_labels': next_hop_n_out_labels,
758 'mt_next_hop_sw_if_index': next_hop_sw_if_index,
759 'mt_next_hop_table_id': next_hop_table_id,
Neale Ranns7c922dc2018-08-30 06:12:27 -0700760 'mt_next_hop_via_label': next_hop_via_label,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200761 'mt_next_hop_out_label_stack': next_hop_out_label_stack})
Matus Fabiande886752016-12-07 03:38:19 -0800762
Matus Fabian2ba92e32017-08-21 07:05:03 -0700763 def nat44_interface_add_del_feature(
Matus Fabiande886752016-12-07 03:38:19 -0800764 self,
765 sw_if_index,
Ole Trøan89fec712019-04-23 12:38:35 +0000766 is_inside=1,
767 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700768 """Enable/disable NAT44 feature on the interface
Matus Fabiande886752016-12-07 03:38:19 -0800769
770 :param sw_if_index: Software index of the interface
Ole Trøan89fec712019-04-23 12:38:35 +0000771 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800772 :param is_add: 1 if add, 0 if delete (Default value = 1)
773 """
774 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700775 self.papi.nat44_interface_add_del_feature,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200776 {'is_add': is_add,
Ole Trøan89fec712019-04-23 12:38:35 +0000777 'is_inside': is_inside,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200778 'sw_if_index': sw_if_index})
Matus Fabiande886752016-12-07 03:38:19 -0800779
Matus Fabian2ba92e32017-08-21 07:05:03 -0700780 def nat44_interface_add_del_output_feature(
Matus Fabian93d84c92017-07-19 08:06:01 -0700781 self,
782 sw_if_index,
Ole Trøan89fec712019-04-23 12:38:35 +0000783 is_inside=1,
784 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700785 """Enable/disable NAT44 output feature on the interface
Matus Fabian93d84c92017-07-19 08:06:01 -0700786
787 :param sw_if_index: Software index of the interface
Ole Trøan89fec712019-04-23 12:38:35 +0000788 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
Matus Fabian93d84c92017-07-19 08:06:01 -0700789 :param is_add: 1 if add, 0 if delete (Default value = 1)
790 """
791 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700792 self.papi.nat44_interface_add_del_output_feature,
Matus Fabian93d84c92017-07-19 08:06:01 -0700793 {'is_add': is_add,
Ole Trøan89fec712019-04-23 12:38:35 +0000794 'is_inside': is_inside,
Matus Fabian93d84c92017-07-19 08:06:01 -0700795 'sw_if_index': sw_if_index})
796
Matus Fabian2ba92e32017-08-21 07:05:03 -0700797 def nat44_add_del_static_mapping(
Matus Fabiande886752016-12-07 03:38:19 -0800798 self,
799 local_ip,
Matus Fabian36532bd2017-01-23 23:42:28 -0800800 external_ip=0,
801 external_sw_if_index=0xFFFFFFFF,
Matus Fabiande886752016-12-07 03:38:19 -0800802 local_port=0,
803 external_port=0,
Ole Trøan89fec712019-04-23 12:38:35 +0000804 addr_only=1,
Matus Fabiande886752016-12-07 03:38:19 -0800805 vrf_id=0,
Matus Fabian09d96f42017-02-02 01:43:00 -0800806 protocol=0,
Ole Trøan89fec712019-04-23 12:38:35 +0000807 twice_nat=0,
808 self_twice_nat=0,
809 out2in_only=0,
810 tag="",
811 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700812 """Add/delete NAT44 static mapping
Matus Fabiande886752016-12-07 03:38:19 -0800813
814 :param local_ip: Local IP address
815 :param external_ip: External IP address
Matus Fabian36532bd2017-01-23 23:42:28 -0800816 :param external_sw_if_index: External interface instead of IP address
Matus Fabiande886752016-12-07 03:38:19 -0800817 :param local_port: Local port number (Default value = 0)
818 :param external_port: External port number (Default value = 0)
Ole Trøan89fec712019-04-23 12:38:35 +0000819 :param addr_only: 1 if address only mapping, 0 if address and port
Matus Fabiande886752016-12-07 03:38:19 -0800820 :param vrf_id: VRF ID
Matus Fabian09d96f42017-02-02 01:43:00 -0800821 :param protocol: IP protocol (Default value = 0)
Ole Trøan89fec712019-04-23 12:38:35 +0000822 :param twice_nat: 1 if translate external host address and port
823 :param self_twice_nat: 1 if translate external host address and port
824 whenever external host address equals
825 local address of internal host
826 :param out2in_only: if 1 rule is matching only out2in direction
Filip Vargabed14212019-04-15 18:52:43 +0200827 :param tag: Opaque string tag
Ole Trøan89fec712019-04-23 12:38:35 +0000828 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800829 """
830 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700831 self.papi.nat44_add_del_static_mapping,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200832 {'is_add': is_add,
Ole Trøan89fec712019-04-23 12:38:35 +0000833 'addr_only': addr_only,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200834 'local_ip_address': local_ip,
835 'external_ip_address': external_ip,
836 'local_port': local_port,
837 'external_port': external_port,
Matus Fabian36532bd2017-01-23 23:42:28 -0800838 'external_sw_if_index': external_sw_if_index,
Matus Fabian09d96f42017-02-02 01:43:00 -0800839 'vrf_id': vrf_id,
Ole Trøan89fec712019-04-23 12:38:35 +0000840 'protocol': protocol,
841 'twice_nat': twice_nat,
842 'self_twice_nat': self_twice_nat,
843 'out2in_only': out2in_only,
Matus Fabian5f224992018-01-25 21:59:16 -0800844 'tag': tag})
Matus Fabiande886752016-12-07 03:38:19 -0800845
Matus Fabianab7a8052017-11-28 04:29:41 -0800846 def nat44_add_del_identity_mapping(
847 self,
Paul Vinciguerra22ab6f72019-03-07 17:55:33 -0800848 ip=b'0',
Matus Fabianab7a8052017-11-28 04:29:41 -0800849 sw_if_index=0xFFFFFFFF,
850 port=0,
Ole Trøan89fec712019-04-23 12:38:35 +0000851 addr_only=1,
Matus Fabianab7a8052017-11-28 04:29:41 -0800852 vrf_id=0,
853 protocol=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800854 tag='',
Matus Fabianab7a8052017-11-28 04:29:41 -0800855 is_add=1):
856 """Add/delete NAT44 identity mapping
857
858 :param ip: IP address (Default value = 0)
859 :param sw_if_index: Interface instead of IP address
860 :param port: Port number (Default value = 0)
Ole Trøan89fec712019-04-23 12:38:35 +0000861 :param addr_only: 1 if address only mapping, 0 if address and port
Matus Fabianab7a8052017-11-28 04:29:41 -0800862 :param vrf_id: VRF ID
863 :param protocol: IP protocol (Default value = 0)
Matus Fabian5f224992018-01-25 21:59:16 -0800864 :param tag: Opaque string tag
Matus Fabianab7a8052017-11-28 04:29:41 -0800865 :param is_add: 1 if add, 0 if delete (Default value = 1)
866 """
867 return self.api(
868 self.papi.nat44_add_del_identity_mapping,
869 {'is_add': is_add,
Ole Trøan89fec712019-04-23 12:38:35 +0000870 'addr_only': addr_only,
Matus Fabianab7a8052017-11-28 04:29:41 -0800871 'ip_address': ip,
872 'port': port,
873 'sw_if_index': sw_if_index,
874 'vrf_id': vrf_id,
Ole Trøan89fec712019-04-23 12:38:35 +0000875 'tag': tag,
876 'protocol': protocol})
Matus Fabianab7a8052017-11-28 04:29:41 -0800877
Matus Fabian2ba92e32017-08-21 07:05:03 -0700878 def nat44_add_del_address_range(
Matus Fabiande886752016-12-07 03:38:19 -0800879 self,
880 first_ip_address,
881 last_ip_address,
882 is_add=1,
Matus Fabianb932d262017-12-18 05:38:24 -0800883 vrf_id=0xFFFFFFFF,
Ole Trøan89fec712019-04-23 12:38:35 +0000884 twice_nat=0):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700885 """Add/del NAT44 address range
Matus Fabiande886752016-12-07 03:38:19 -0800886
887 :param first_ip_address: First IP address
888 :param last_ip_address: Last IP address
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800889 :param vrf_id: VRF id for the address range
Ole Trøan89fec712019-04-23 12:38:35 +0000890 :param twice_nat: twice NAT address for extenral hosts
Matus Fabiande886752016-12-07 03:38:19 -0800891 :param is_add: 1 if add, 0 if delete (Default value = 1)
Matus Fabiande886752016-12-07 03:38:19 -0800892 """
893 return self.api(
Matus Fabian2ba92e32017-08-21 07:05:03 -0700894 self.papi.nat44_add_del_address_range,
895 {'first_ip_address': first_ip_address,
Klement Sekera0e3c0de2016-09-29 14:43:44 +0200896 'last_ip_address': last_ip_address,
Juraj Slobodaeab38d92017-03-06 19:55:21 -0800897 'vrf_id': vrf_id,
Ole Trøan89fec712019-04-23 12:38:35 +0000898 'twice_nat': twice_nat,
899 'is_add': is_add})
Matus Fabiande886752016-12-07 03:38:19 -0800900
Ole Troane1ade682019-03-04 23:55:43 +0100901 def nat44_add_del_interface_addr(
Matus Fabian8bf68e82017-01-12 04:24:35 -0800902 self,
903 sw_if_index,
Ole Trøan89fec712019-04-23 12:38:35 +0000904 twice_nat=0,
Matus Fabian8bf68e82017-01-12 04:24:35 -0800905 is_add=1):
Matus Fabian2ba92e32017-08-21 07:05:03 -0700906 """Add/del NAT44 address from interface
Matus Fabian8bf68e82017-01-12 04:24:35 -0800907
908 :param sw_if_index: Software index of the interface
Ole Trøan89fec712019-04-23 12:38:35 +0000909 :param twice_nat: twice NAT address for external hosts
Matus Fabian8bf68e82017-01-12 04:24:35 -0800910 :param is_add: 1 if add, 0 if delete (Default value = 1)
911 """
Matus Fabianb932d262017-12-18 05:38:24 -0800912 return self.api(
913 self.papi.nat44_add_del_interface_addr,
914 {'is_add': is_add,
915 'sw_if_index': sw_if_index,
Ole Trøan89fec712019-04-23 12:38:35 +0000916 'twice_nat': twice_nat})
Matus Fabian8bf68e82017-01-12 04:24:35 -0800917
Matus Fabian704018c2017-09-04 02:17:18 -0700918 def nat44_add_del_lb_static_mapping(
919 self,
920 external_addr,
921 external_port,
922 protocol,
Ole Trøan89fec712019-04-23 12:38:35 +0000923 twice_nat=0,
924 self_twice_nat=0,
925 out2in_only=0,
Matus Fabian5f224992018-01-25 21:59:16 -0800926 tag='',
Matus Fabianea5b5be2018-09-03 05:02:23 -0700927 affinity=0,
Matus Fabian704018c2017-09-04 02:17:18 -0700928 local_num=0,
Ole Troan895b6e82017-10-20 13:28:20 +0200929 locals=[],
Matus Fabian704018c2017-09-04 02:17:18 -0700930 is_add=1):
931 """Add/delete NAT44 load balancing static mapping
932
Ole Trøan89fec712019-04-23 12:38:35 +0000933 :param twice_nat: 1 if translate external host address and port
Matus Fabian5f224992018-01-25 21:59:16 -0800934 :param tag: Opaque string tag
Matus Fabianea5b5be2018-09-03 05:02:23 -0700935 :param affinity: if 0 disabled, otherwise client IP affinity timeout
Matus Fabian704018c2017-09-04 02:17:18 -0700936 :param is_add - 1 if add, 0 if delete
937 """
938 return self.api(
939 self.papi.nat44_add_del_lb_static_mapping,
940 {'is_add': is_add,
941 'external_addr': external_addr,
942 'external_port': external_port,
943 'protocol': protocol,
Ole Trøan89fec712019-04-23 12:38:35 +0000944 'twice_nat': twice_nat,
945 'self_twice_nat': self_twice_nat,
946 'out2in_only': out2in_only,
947 'tag': tag,
Matus Fabianea5b5be2018-09-03 05:02:23 -0700948 'affinity': affinity,
Matus Fabian704018c2017-09-04 02:17:18 -0700949 'local_num': local_num,
Ole Trøan89fec712019-04-23 12:38:35 +0000950 'locals': locals})
Matus Fabian704018c2017-09-04 02:17:18 -0700951
Matus Fabianb6865082018-12-06 03:11:09 -0800952 def nat44_lb_static_mapping_add_del_local(
Ole Troan9a475372019-03-05 16:58:24 +0100953 self,
954 external_addr,
955 external_port,
956 local_addr,
957 local_port,
958 protocol,
959 probability,
960 vrf_id=0,
961 is_add=1):
Matus Fabianb6865082018-12-06 03:11:09 -0800962 """Add/delete NAT44 load-balancing static mapping rule backend
963
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -0700964 :param external_addr: external IPv4 address of the service
Matus Fabianb6865082018-12-06 03:11:09 -0800965 :param external_port: external L4 port number of the service
966 :param local_addr: IPv4 address of the internal node
967 :param local_port: L4 port number of the internal node
968 :param protocol: IP protocol number
969 :param probability: probability of the internal node
970 :param vrf_id: VRF id of the internal node
971 :param is_add: 1 if add, 0 if delete
972 """
973 return self.api(
974 self.papi.nat44_lb_static_mapping_add_del_local,
975 {'is_add': is_add,
976 'external_addr': external_addr,
977 'external_port': external_port,
978 'local': {
979 'addr': local_addr,
980 'port': local_port,
981 'probability': probability,
982 'vrf_id': vrf_id},
983 'protocol': protocol})
984
Matus Fabian5ba86f72017-10-26 03:37:38 -0700985 def nat44_del_session(
986 self,
987 addr,
988 port,
989 protocol,
990 vrf_id=0,
Ole Trøan89fec712019-04-23 12:38:35 +0000991 is_in=1,
Matus Fabian70a26ac2018-05-14 06:20:28 -0700992 ext_host_address=None,
993 ext_host_port=0):
Matus Fabian5ba86f72017-10-26 03:37:38 -0700994 """Delete NAT44 session
995
996 :param addr: IPv4 address
997 :param por: port number
998 :param protocol: IP protocol number
999 :param vrf_id: VRF ID
Ole Trøan89fec712019-04-23 12:38:35 +00001000 :param is_in: 1 if inside network address and port pair, 0 if outside
Matus Fabian70a26ac2018-05-14 06:20:28 -07001001 :param ext_host_address: external host IPv4 address
1002 :param ext_host_port: external host port
Matus Fabian5ba86f72017-10-26 03:37:38 -07001003 """
Ole Trøan89fec712019-04-23 12:38:35 +00001004 if ext_host_address is None:
1005 return self.api(
1006 self.papi.nat44_del_session,
1007 {'address': addr,
1008 'port': port,
1009 'protocol': protocol,
1010 'vrf_id': vrf_id,
1011 'is_in': is_in})
1012 else:
1013 return self.api(
1014 self.papi.nat44_del_session,
1015 {'address': addr,
1016 'port': port,
1017 'protocol': protocol,
1018 'vrf_id': vrf_id,
1019 'is_in': is_in,
1020 'ext_host_valid': 1,
1021 'ext_host_address': ext_host_address,
1022 'ext_host_port': ext_host_port})
Matus Fabian5ba86f72017-10-26 03:37:38 -07001023
Juraj Sloboda7b929792017-11-23 13:20:48 +01001024 def nat44_forwarding_enable_disable(
1025 self,
1026 enable):
1027 """Enable/disable forwarding for NAT44
1028
1029 :param enable: 1 for enable, 0 for disable
1030 """
1031 return self.api(
1032 self.papi.nat44_forwarding_enable_disable,
1033 {'enable': enable})
1034
Ole Trøan89fec712019-04-23 12:38:35 +00001035 def nat_det_add_del_map(
1036 self,
1037 in_addr,
1038 in_plen,
1039 out_addr,
1040 out_plen,
1041 is_add=1):
1042 """Add/delete deterministic NAT mapping
1043
1044 :param is_add - 1 if add, 0 if delete
1045 :param in_addr - inside IP address
1046 :param in_plen - inside IP address prefix length
1047 :param out_addr - outside IP address
1048 :param out_plen - outside IP address prefix length
1049 """
1050 return self.api(
1051 self.papi.nat_det_add_del_map,
1052 {'is_add': is_add,
1053 'is_nat44': 1,
1054 'in_addr': in_addr,
1055 'in_plen': in_plen,
1056 'out_addr': out_addr,
1057 'out_plen': out_plen})
1058
1059 def nat_det_forward(
1060 self,
1061 in_addr):
1062 """Get outside address and port range from inside address
1063
1064 :param in_addr - inside IP address
1065 """
1066 return self.api(
1067 self.papi.nat_det_forward,
1068 {'in_addr': in_addr,
1069 'is_nat44': 1})
1070
1071 def nat_det_reverse(
1072 self,
1073 out_addr,
1074 out_port):
1075 """Get inside address from outside address and port
1076
1077 :param out_addr - outside IP address
1078 :param out_port - outside port
1079 """
1080 return self.api(
1081 self.papi.nat_det_reverse,
1082 {'out_addr': out_addr,
1083 'out_port': out_port})
1084
Matus Fabian2ba92e32017-08-21 07:05:03 -07001085 def nat_det_map_dump(self):
1086 """Dump deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001087
Matus Fabian2ba92e32017-08-21 07:05:03 -07001088 :return: Dictionary of deterministic NAT mappings
Martin17a75cb2017-03-08 05:53:20 -08001089 """
Matus Fabian2ba92e32017-08-21 07:05:03 -07001090 return self.api(self.papi.nat_det_map_dump, {})
Martin17a75cb2017-03-08 05:53:20 -08001091
Matus Fabianbb4e0222018-09-13 02:36:25 -07001092 def nat_set_mss_clamping(self, enable=0, mss_value=1500):
1093 """Set TCP MSS rewriting configuration
1094
1095 :param enable: disable(0)/enable(1) MSS rewriting feature
1096 :param mss_value: MSS value to be used for MSS rewriting
1097 """
1098 return self.api(
1099 self.papi.nat_set_mss_clamping,
1100 {'enable': enable, 'mss_value': mss_value})
1101
Ole Trøan89fec712019-04-23 12:38:35 +00001102 def nat_det_close_session_in(
1103 self,
1104 in_addr,
1105 in_port,
1106 ext_addr,
1107 ext_port):
1108 """Close deterministic NAT session using inside address and port
1109
1110 :param in_addr - inside IP address
1111 :param in_port - inside port
1112 :param ext_addr - external host IP address
1113 :param ext_port - external host port
1114 """
1115 return self.api(
1116 self.papi.nat_det_close_session_in,
1117 {'in_addr': in_addr,
1118 'in_port': in_port,
1119 'ext_addr': ext_addr,
1120 'ext_port': ext_port,
1121 'is_nat44': 1})
1122
1123 def nat_det_session_dump(
1124 self,
1125 user_addr):
1126 """Dump deterministic NAT sessions belonging to a user
1127
1128 :param user_addr - inside IP address of the user
1129 :return: Dictionary of deterministic NAT sessions
1130 """
1131 return self.api(
1132 self.papi.nat_det_session_dump,
1133 {'is_nat44': 1,
1134 'user_addr': user_addr})
1135
1136 def nat64_add_del_interface(
1137 self,
1138 sw_if_index,
1139 is_inside=1,
1140 is_add=1):
1141 """Enable/disable NAT64 feature on the interface
1142 :param sw_if_index: Index of the interface
1143 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
1144 :param is_add: 1 if add, 0 if delete (Default value = 1)
1145 """
1146 return self.api(
1147 self.papi.nat64_add_del_interface,
1148 {'sw_if_index': sw_if_index,
1149 'is_inside': is_inside,
1150 'is_add': is_add})
1151
Matus Fabian06596c52017-06-06 04:53:28 -07001152 def nat64_add_del_static_bib(
1153 self,
1154 in_ip,
1155 out_ip,
1156 in_port,
1157 out_port,
1158 protocol,
1159 vrf_id=0,
1160 is_add=1):
1161 """Add/delete S-NAT static BIB entry
1162
1163 :param in_ip: Inside IPv6 address
1164 :param out_ip: Outside IPv4 address
1165 :param in_port: Inside port number
1166 :param out_port: Outside port number
1167 :param protocol: IP protocol
1168 :param vrf_id: VRF ID (Default value = 0)
1169 :param is_add: 1 if add, 0 if delete (Default value = 1)
1170 """
1171 return self.api(
1172 self.papi.nat64_add_del_static_bib,
1173 {'i_addr': in_ip,
1174 'o_addr': out_ip,
1175 'i_port': in_port,
1176 'o_port': out_port,
1177 'vrf_id': vrf_id,
1178 'proto': protocol,
1179 'is_add': is_add})
1180
Matus Fabianab9a59c2017-08-16 05:37:36 -07001181 def nat64_bib_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001182 """Dump NAT64 BIB
1183
Matus Fabianab9a59c2017-08-16 05:37:36 -07001184 :param protocol: IP protocol (Default value = 255, all BIBs)
Matus Fabian06596c52017-06-06 04:53:28 -07001185 :returns: Dictionary of NAT64 BIB entries
1186 """
1187 return self.api(self.papi.nat64_bib_dump, {'proto': protocol})
1188
Matus Fabianab9a59c2017-08-16 05:37:36 -07001189 def nat64_st_dump(self, protocol=255):
Matus Fabian06596c52017-06-06 04:53:28 -07001190 """Dump NAT64 session table
1191
Matus Fabianab9a59c2017-08-16 05:37:36 -07001192 :param protocol: IP protocol (Default value = 255, all STs)
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001193 :returns: Dictionary of NAT64 session table entries
Matus Fabian06596c52017-06-06 04:53:28 -07001194 """
1195 return self.api(self.papi.nat64_st_dump, {'proto': protocol})
1196
Ole Trøan89fec712019-04-23 12:38:35 +00001197 def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1):
Matus Fabian428dc912017-06-21 06:15:18 -07001198 """Add/del NAT64 prefix
1199
1200 :param prefix: NAT64 prefix
Ole Trøan89fec712019-04-23 12:38:35 +00001201 :param plen: NAT64 prefix length
Matus Fabian428dc912017-06-21 06:15:18 -07001202 :param vrf_id: VRF id of tenant (Default 0)
1203 :param is_add: 1 if add, 0 if delete (Default value = 1)
1204 """
1205 return self.api(
1206 self.papi.nat64_add_del_prefix,
1207 {'prefix': prefix,
Ole Trøan89fec712019-04-23 12:38:35 +00001208 'prefix_len': plen,
Matus Fabian428dc912017-06-21 06:15:18 -07001209 'vrf_id': vrf_id,
1210 'is_add': is_add})
1211
Ole Troane1ade682019-03-04 23:55:43 +01001212 def nat64_add_del_interface_addr(
Matus Fabian0938dcf2017-11-08 01:59:38 -08001213 self,
1214 sw_if_index,
1215 is_add=1):
1216 """Add/del NAT64 address from interface
1217
1218 :param sw_if_index: Software index of the interface
1219 :param is_add: 1 if add, 0 if delete (Default value = 1)
1220 """
1221 return self.api(self.papi.nat64_add_del_interface_addr,
1222 {'is_add': is_add, 'sw_if_index': sw_if_index})
1223
Matus Fabian8ebe6252017-11-06 05:04:53 -08001224 def dslite_set_aftr_addr(self, ip6, ip4):
1225 """Set DS-Lite AFTR addresses
1226
1227 :param ip4: IPv4 address
1228 :param ip6: IPv6 address
1229 """
1230 return self.api(
1231 self.papi.dslite_set_aftr_addr,
1232 {'ip4_addr': ip4,
1233 'ip6_addr': ip6})
1234
Juraj Slobodac5c6a332018-01-09 16:08:32 +01001235 def dslite_set_b4_addr(self, ip6, ip4):
1236 """Set DS-Lite B4 IPv6 address
1237
1238 :param ip4: IPv4 address
1239 :param ip6: IPv6 address
1240 """
1241 return self.api(
1242 self.papi.dslite_set_b4_addr,
1243 {'ip4_addr': ip4,
1244 'ip6_addr': ip6})
1245
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001246 def nat66_add_del_interface(
1247 self,
1248 sw_if_index,
Ole Trøan89fec712019-04-23 12:38:35 +00001249 is_inside=1,
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001250 is_add=1):
1251 """Enable/disable NAT66 feature on the interface
1252 :param sw_if_index: Index of the interface
Ole Trøan89fec712019-04-23 12:38:35 +00001253 :param is_inside: 1 if inside, 0 if outside (Default value = 1)
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001254 :param is_add: 1 if add, 0 if delete (Default value = 1)
1255 """
1256 return self.api(
1257 self.papi.nat66_add_del_interface,
Ole Trøan89fec712019-04-23 12:38:35 +00001258 {'sw_if_index': sw_if_index,
1259 'is_inside': is_inside,
1260 'is_add': is_add})
Matus Fabianf2a23cc2018-01-22 03:41:53 -08001261
1262 def nat66_add_del_static_mapping(
1263 self,
1264 in_ip,
1265 out_ip,
1266 vrf_id=0,
1267 is_add=1):
1268 """Add/delete NAT66 static mapping
1269
1270 :param in_ip: Inside IPv6 address
1271 :param out_ip: Outside IPv6 address
1272 :param vrf_id: VRF ID (Default value = 0)
1273 :param is_add: 1 if add, 0 if delete (Default value = 1)
1274 """
1275 return self.api(
1276 self.papi.nat66_add_del_static_mapping,
1277 {'local_ip_address': in_ip,
1278 'external_ip_address': out_ip,
1279 'vrf_id': vrf_id,
1280 'is_add': is_add})
1281
Matus Fabian34931eb2019-02-26 09:05:23 -08001282 def nat_ha_set_listener(self, addr, port, path_mtu=512):
1283 """Set HA listener (local settings)
1284
1285 :param addr: local IP4 address
1286 :param port: local UDP port number
1287 :param path_mtu: path MTU (Default value = 512)
1288 """
1289 return self.api(self.papi.nat_ha_set_listener,
1290 {'ip_address': addr,
1291 'port': port,
1292 'path_mtu': path_mtu})
1293
1294 def nat_ha_get_listener(self):
1295 """Get HA listener/local configuration"""
1296 return self.api(self.papi.nat_ha_get_listener, {})
1297
1298 def nat_ha_set_failover(self, addr, port, refresh=10):
1299 """Set HA failover (remote settings)
1300
1301 :param addr: failover IP4 address
Paul Vinciguerra8feeaff2019-03-27 11:25:48 -07001302 :param port: failover UDP port number
Matus Fabian34931eb2019-02-26 09:05:23 -08001303 :param refresh: number of seconds after which to send session refresh
1304 """
1305 return self.api(self.papi.nat_ha_set_failover,
1306 {'ip_address': addr,
1307 'port': port,
1308 'session_refresh_interval': refresh})
1309
Matus Fabian34931eb2019-02-26 09:05:23 -08001310 def nat_ha_resync(self, want_resync_event=1):
1311 """Resync HA (resend existing sessions to new failover)
1312 :param want_resync_event: if non-zero resync completed event sent
1313 """
1314 return self.api(self.papi.nat_ha_resync,
1315 {'want_resync_event': want_resync_event,
1316 'pid': os.getpid()})
1317
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001318 def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
Klement Sekerab17dd962017-01-09 07:43:48 +01001319 detect_mult, local_addr, peer_addr, is_ipv6=0,
1320 bfd_key_id=None, conf_key_id=None):
1321 if bfd_key_id is None:
1322 return self.api(self.papi.bfd_udp_add,
1323 {
1324 'sw_if_index': sw_if_index,
1325 'desired_min_tx': desired_min_tx,
1326 'required_min_rx': required_min_rx,
1327 'local_addr': local_addr,
1328 'peer_addr': peer_addr,
1329 'is_ipv6': is_ipv6,
1330 'detect_mult': detect_mult,
1331 })
1332 else:
1333 return self.api(self.papi.bfd_udp_add,
1334 {
1335 'sw_if_index': sw_if_index,
1336 'desired_min_tx': desired_min_tx,
1337 'required_min_rx': required_min_rx,
1338 'local_addr': local_addr,
1339 'peer_addr': peer_addr,
1340 'is_ipv6': is_ipv6,
1341 'detect_mult': detect_mult,
1342 'is_authenticated': 1,
1343 'bfd_key_id': bfd_key_id,
1344 'conf_key_id': conf_key_id,
1345 })
1346
Klement Sekeraa57a9702017-02-02 06:58:07 +01001347 def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1348 detect_mult, local_addr, peer_addr, is_ipv6=0):
1349 return self.api(self.papi.bfd_udp_mod,
1350 {
1351 'sw_if_index': sw_if_index,
1352 'desired_min_tx': desired_min_tx,
1353 'required_min_rx': required_min_rx,
1354 'local_addr': local_addr,
1355 'peer_addr': peer_addr,
1356 'is_ipv6': is_ipv6,
1357 'detect_mult': detect_mult,
1358 })
1359
Klement Sekerab17dd962017-01-09 07:43:48 +01001360 def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1361 is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1362 is_delayed=False):
1363 return self.api(self.papi.bfd_udp_auth_activate,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001364 {
1365 'sw_if_index': sw_if_index,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001366 'local_addr': local_addr,
1367 'peer_addr': peer_addr,
1368 'is_ipv6': is_ipv6,
Klement Sekerab17dd962017-01-09 07:43:48 +01001369 'is_delayed': 1 if is_delayed else 0,
1370 'bfd_key_id': bfd_key_id,
1371 'conf_key_id': conf_key_id,
1372 })
1373
Klement Sekerab17dd962017-01-09 07:43:48 +01001374 def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1375 peer_addr, is_ipv6=0):
1376 return self.api(self.papi.bfd_udp_session_set_flags, {
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001377 'admin_up_down': admin_up_down,
Klement Sekerab17dd962017-01-09 07:43:48 +01001378 'sw_if_index': sw_if_index,
1379 'local_addr': local_addr,
1380 'peer_addr': peer_addr,
1381 'is_ipv6': is_ipv6,
Klement Sekera0e3c0de2016-09-29 14:43:44 +02001382 })
1383
1384 def want_bfd_events(self, enable_disable=1):
1385 return self.api(self.papi.want_bfd_events, {
1386 'enable_disable': enable_disable,
1387 'pid': os.getpid(),
1388 })
Steve Shin7957d6e2016-12-19 09:24:50 -08001389
Klement Sekerab17dd962017-01-09 07:43:48 +01001390 def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1391 return self.api(self.papi.bfd_auth_set_key, {
1392 'conf_key_id': conf_key_id,
1393 'auth_type': auth_type,
1394 'key': key,
1395 'key_len': len(key),
1396 })
1397
Steve Shin7957d6e2016-12-19 09:24:50 -08001398 def classify_add_del_table(
1399 self,
1400 is_add,
1401 mask,
1402 match_n_vectors=1,
1403 table_index=0xFFFFFFFF,
1404 nbuckets=2,
1405 memory_size=2097152,
1406 skip_n_vectors=0,
1407 next_table_index=0xFFFFFFFF,
1408 miss_next_index=0xFFFFFFFF,
1409 current_data_flag=0,
1410 current_data_offset=0):
Steve Shin7957d6e2016-12-19 09:24:50 -08001411 """
1412 :param is_add:
1413 :param mask:
Klement Sekerada505f62017-01-04 12:58:53 +01001414 :param match_n_vectors: (Default value = 1)
Matej Klotton8d8a1da2016-12-22 11:06:56 +01001415 :param table_index: (Default value = 0xFFFFFFFF)
Steve Shin7957d6e2016-12-19 09:24:50 -08001416 :param nbuckets: (Default value = 2)
1417 :param memory_size: (Default value = 2097152)
1418 :param skip_n_vectors: (Default value = 0)
1419 :param next_table_index: (Default value = 0xFFFFFFFF)
1420 :param miss_next_index: (Default value = 0xFFFFFFFF)
1421 :param current_data_flag: (Default value = 0)
1422 :param current_data_offset: (Default value = 0)
1423 """
1424
Juraj Sloboda75282452018-06-12 14:20:49 +02001425 mask_len = ((len(mask) - 1) / 16 + 1) * 16
1426 mask = mask + '\0' * (mask_len - len(mask))
Steve Shin7957d6e2016-12-19 09:24:50 -08001427 return self.api(
1428 self.papi.classify_add_del_table,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001429 {'is_add': is_add,
1430 'table_index': table_index,
1431 'nbuckets': nbuckets,
Steve Shin7957d6e2016-12-19 09:24:50 -08001432 'memory_size': memory_size,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001433 'skip_n_vectors': skip_n_vectors,
1434 'match_n_vectors': match_n_vectors,
1435 'next_table_index': next_table_index,
1436 'miss_next_index': miss_next_index,
1437 'current_data_flag': current_data_flag,
1438 'current_data_offset': current_data_offset,
Juraj Sloboda75282452018-06-12 14:20:49 +02001439 'mask_len': mask_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001440 'mask': mask})
Steve Shin7957d6e2016-12-19 09:24:50 -08001441
1442 def classify_add_del_session(
1443 self,
1444 is_add,
1445 table_index,
1446 match,
1447 opaque_index=0xFFFFFFFF,
1448 hit_next_index=0xFFFFFFFF,
1449 advance=0,
1450 action=0,
1451 metadata=0):
1452 """
1453 :param is_add:
1454 :param table_index:
1455 :param match:
1456 :param opaque_index: (Default value = 0xFFFFFFFF)
1457 :param hit_next_index: (Default value = 0xFFFFFFFF)
1458 :param advance: (Default value = 0)
1459 :param action: (Default value = 0)
1460 :param metadata: (Default value = 0)
1461 """
1462
Juraj Sloboda75282452018-06-12 14:20:49 +02001463 match_len = ((len(match) - 1) / 16 + 1) * 16
1464 match = match + '\0' * (match_len - len(match))
Steve Shin7957d6e2016-12-19 09:24:50 -08001465 return self.api(
1466 self.papi.classify_add_del_session,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001467 {'is_add': is_add,
1468 'table_index': table_index,
1469 'hit_next_index': hit_next_index,
1470 'opaque_index': opaque_index,
1471 'advance': advance,
1472 'action': action,
1473 'metadata': metadata,
Juraj Sloboda75282452018-06-12 14:20:49 +02001474 'match_len': match_len,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001475 'match': match})
Steve Shin7957d6e2016-12-19 09:24:50 -08001476
1477 def input_acl_set_interface(
1478 self,
1479 is_add,
1480 sw_if_index,
1481 ip4_table_index=0xFFFFFFFF,
1482 ip6_table_index=0xFFFFFFFF,
1483 l2_table_index=0xFFFFFFFF):
1484 """
1485 :param is_add:
1486 :param sw_if_index:
1487 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1488 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1489 :param l2_table_index: (Default value = 0xFFFFFFFF)
1490 """
1491
1492 return self.api(
1493 self.papi.input_acl_set_interface,
Klement Sekera77fabdb2017-01-02 07:46:14 +01001494 {'sw_if_index': sw_if_index,
1495 'ip4_table_index': ip4_table_index,
1496 'ip6_table_index': ip6_table_index,
1497 'l2_table_index': l2_table_index,
1498 'is_add': is_add})
1499
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01001500 def output_acl_set_interface(
1501 self,
1502 is_add,
1503 sw_if_index,
1504 ip4_table_index=0xFFFFFFFF,
1505 ip6_table_index=0xFFFFFFFF,
1506 l2_table_index=0xFFFFFFFF):
1507 """
1508 :param is_add:
1509 :param sw_if_index:
1510 :param ip4_table_index: (Default value = 0xFFFFFFFF)
1511 :param ip6_table_index: (Default value = 0xFFFFFFFF)
1512 :param l2_table_index: (Default value = 0xFFFFFFFF)
1513 """
1514
1515 return self.api(
1516 self.papi.output_acl_set_interface,
1517 {'sw_if_index': sw_if_index,
1518 'ip4_table_index': ip4_table_index,
1519 'ip6_table_index': ip6_table_index,
1520 'l2_table_index': l2_table_index,
1521 'is_add': is_add})
1522
Klement Sekera77fabdb2017-01-02 07:46:14 +01001523 def set_ipfix_exporter(
1524 self,
1525 collector_address,
1526 src_address,
1527 path_mtu,
1528 template_interval,
1529 vrf_id=0,
1530 collector_port=4739,
1531 udp_checksum=0):
1532 return self.api(
1533 self.papi.set_ipfix_exporter,
1534 {
1535 'collector_address': collector_address,
1536 'collector_port': collector_port,
1537 'src_address': src_address,
1538 'vrf_id': vrf_id,
1539 'path_mtu': path_mtu,
1540 'template_interval': template_interval,
1541 'udp_checksum': udp_checksum,
1542 })
Neale Rannsfca0c242017-01-13 07:57:46 -08001543
1544 def dhcp_proxy_config(self,
1545 dhcp_server,
1546 dhcp_src_address,
1547 rx_table_id=0,
1548 server_table_id=0,
1549 is_add=1,
Neale Ranns20a175a2017-02-14 07:28:41 -08001550 is_ipv6=0):
Neale Rannsfca0c242017-01-13 07:57:46 -08001551 return self.api(
Neale Ranns20a175a2017-02-14 07:28:41 -08001552 self.papi.dhcp_proxy_config,
Neale Rannsfca0c242017-01-13 07:57:46 -08001553 {
1554 'rx_vrf_id': rx_table_id,
1555 'server_vrf_id': server_table_id,
1556 'is_ipv6': is_ipv6,
1557 'is_add': is_add,
Neale Rannsfca0c242017-01-13 07:57:46 -08001558 'dhcp_server': dhcp_server,
1559 'dhcp_src_address': dhcp_src_address,
1560 })
1561
1562 def dhcp_proxy_set_vss(self,
1563 table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001564 vss_type=255,
1565 vpn_ascii_id="",
1566 oui=0,
1567 vpn_index=0,
Neale Rannsfca0c242017-01-13 07:57:46 -08001568 is_add=1,
1569 is_ip6=0):
1570 return self.api(
1571 self.papi.dhcp_proxy_set_vss,
1572 {
1573 'tbl_id': table_id,
John Lo70bfcaf2017-11-14 13:19:26 -05001574 'vss_type': vss_type,
1575 'vpn_ascii_id': vpn_ascii_id,
Neale Rannsfca0c242017-01-13 07:57:46 -08001576 'oui': oui,
John Lo70bfcaf2017-11-14 13:19:26 -05001577 'vpn_index': vpn_index,
1578 'is_add': is_add,
1579 'is_ipv6': is_ip6,
Neale Rannsfca0c242017-01-13 07:57:46 -08001580 })
Neale Ranns32e1c012016-11-22 17:07:28 +00001581
Ole Troane1ade682019-03-04 23:55:43 +01001582 def dhcp_client_config(self,
1583 sw_if_index,
1584 hostname,
1585 client_id='',
1586 is_add=1,
1587 set_broadcast_flag=1,
1588 want_dhcp_events=0):
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001589 return self.api(
1590 self.papi.dhcp_client_config,
1591 {
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001592 'is_add': is_add,
Neale Rannsdaff1782018-05-16 04:12:18 -07001593 'client': {
1594 'sw_if_index': sw_if_index,
1595 'hostname': hostname,
1596 'id': client_id,
1597 'want_dhcp_event': want_dhcp_events,
1598 'set_broadcast_flag': set_broadcast_flag,
1599 'pid': os.getpid()}
Neale Rannsa2fbf6b2017-07-18 08:23:32 -07001600 })
1601
Neale Ranns32e1c012016-11-22 17:07:28 +00001602 def ip_mroute_add_del(self,
1603 src_address,
1604 grp_address,
1605 grp_address_length,
1606 e_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001607 next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001608 next_hop_sw_if_index,
Neale Rannse821ab12017-06-01 07:45:05 -07001609 next_hop_address,
Neale Ranns32e1c012016-11-22 17:07:28 +00001610 i_flags,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001611 bier_imp=0,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001612 rpf_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001613 table_id=0,
Neale Ranns32e1c012016-11-22 17:07:28 +00001614 is_add=1,
1615 is_ipv6=0,
1616 is_local=0):
1617 """
Neale Rannsd792d9c2017-10-21 10:53:20 -07001618 IP Multicast Route add/del
Neale Ranns32e1c012016-11-22 17:07:28 +00001619 """
1620 return self.api(
1621 self.papi.ip_mroute_add_del,
1622 {'next_hop_sw_if_index': next_hop_sw_if_index,
1623 'entry_flags': e_flags,
1624 'itf_flags': i_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001625 'table_id': table_id,
1626 'rpf_id': rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +00001627 'is_add': is_add,
1628 'is_ipv6': is_ipv6,
1629 'is_local': is_local,
Neale Rannsd792d9c2017-10-21 10:53:20 -07001630 'bier_imp': bier_imp,
1631 'next_hop_afi': next_hop_afi,
Neale Ranns32e1c012016-11-22 17:07:28 +00001632 'grp_address_length': grp_address_length,
1633 'grp_address': grp_address,
Neale Rannse821ab12017-06-01 07:45:05 -07001634 'src_address': src_address,
1635 'nh_address': next_hop_address})
Neale Ranns32e1c012016-11-22 17:07:28 +00001636
Filip Tehlar770e89e2017-01-31 10:39:16 +01001637 def lisp_enable_disable(self, is_enabled):
1638 return self.api(
1639 self.papi.lisp_enable_disable,
1640 {
1641 'is_en': is_enabled,
1642 })
1643
Ole Troane1ade682019-03-04 23:55:43 +01001644 def lisp_add_del_locator_set(self,
1645 ls_name,
1646 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001647 return self.api(
1648 self.papi.lisp_add_del_locator_set,
1649 {
1650 'is_add': is_add,
1651 'locator_set_name': ls_name
1652 })
1653
Ole Troane1ade682019-03-04 23:55:43 +01001654 def lisp_add_del_locator(self,
1655 ls_name,
1656 sw_if_index,
1657 priority=1,
1658 weight=1,
1659 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001660 return self.api(
1661 self.papi.lisp_add_del_locator,
1662 {
1663 'is_add': is_add,
1664 'locator_set_name': ls_name,
1665 'sw_if_index': sw_if_index,
1666 'priority': priority,
1667 'weight': weight
1668 })
1669
1670 def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1671 return self.api(
1672 self.papi.lisp_locator_dump,
1673 {
1674 'is_index_set': is_index_set,
1675 'ls_name': ls_name,
1676 'ls_index': ls_index,
1677 })
1678
Ole Troane1ade682019-03-04 23:55:43 +01001679 def lisp_add_del_local_eid(self,
1680 ls_name,
1681 eid_type,
1682 eid,
1683 prefix_len,
1684 vni=0,
1685 key_id=0,
1686 key="",
1687 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001688 return self.api(
1689 self.papi.lisp_add_del_local_eid,
1690 {
1691 'locator_set_name': ls_name,
1692 'is_add': is_add,
1693 'eid_type': eid_type,
1694 'eid': eid,
1695 'prefix_len': prefix_len,
1696 'vni': vni,
1697 'key_id': key_id,
1698 'key': key
1699 })
1700
1701 def lisp_eid_table_dump(self,
1702 eid_set=0,
1703 prefix_length=0,
1704 vni=0,
1705 eid_type=0,
1706 eid=None,
1707 filter_opt=0):
1708 return self.api(
1709 self.papi.lisp_eid_table_dump,
1710 {
1711 'eid_set': eid_set,
1712 'prefix_length': prefix_length,
1713 'vni': vni,
1714 'eid_type': eid_type,
1715 'eid': eid,
1716 'filter': filter_opt,
1717 })
1718
Ole Troane1ade682019-03-04 23:55:43 +01001719 def lisp_add_del_remote_mapping(self,
1720 eid_type,
1721 eid,
1722 eid_prefix_len=0,
1723 vni=0,
1724 rlocs=[],
1725 rlocs_num=0,
1726 is_src_dst=0,
1727 is_add=1):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001728 return self.api(
1729 self.papi.lisp_add_del_remote_mapping,
1730 {
1731 'is_add': is_add,
1732 'eid_type': eid_type,
1733 'eid': eid,
1734 'eid_len': eid_prefix_len,
1735 'rloc_num': rlocs_num,
1736 'rlocs': rlocs,
1737 'vni': vni,
1738 'is_src_dst': is_src_dst,
1739 })
1740
Ole Troane1ade682019-03-04 23:55:43 +01001741 def lisp_add_del_adjacency(self,
1742 leid,
1743 reid,
1744 leid_len,
1745 reid_len,
1746 eid_type,
1747 is_add=1,
1748 vni=0):
Filip Tehlar770e89e2017-01-31 10:39:16 +01001749 return self.api(
1750 self.papi.lisp_add_del_adjacency,
1751 {
1752 'is_add': is_add,
1753 'vni': vni,
1754 'eid_type': eid_type,
1755 'leid': leid,
1756 'reid': reid,
1757 'leid_len': leid_len,
1758 'reid_len': reid_len,
1759 })
1760
Hongjun Nief486b12017-04-12 19:21:16 +08001761 def gtpu_add_del_tunnel(
1762 self,
1763 src_addr,
1764 dst_addr,
1765 is_add=1,
1766 is_ipv6=0,
1767 mcast_sw_if_index=0xFFFFFFFF,
1768 encap_vrf_id=0,
1769 decap_next_index=0xFFFFFFFF,
1770 teid=0):
1771 """
1772
1773 :param is_add: (Default value = 1)
1774 :param is_ipv6: (Default value = 0)
1775 :param src_addr:
1776 :param dst_addr:
1777 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1778 :param encap_vrf_id: (Default value = 0)
1779 :param decap_next_index: (Default value = 0xFFFFFFFF)
1780 :param teid: (Default value = 0)
1781
1782 """
1783 return self.api(self.papi.gtpu_add_del_tunnel,
1784 {'is_add': is_add,
1785 'is_ipv6': is_ipv6,
1786 'src_address': src_addr,
1787 'dst_address': dst_addr,
1788 'mcast_sw_if_index': mcast_sw_if_index,
1789 'encap_vrf_id': encap_vrf_id,
1790 'decap_next_index': decap_next_index,
1791 'teid': teid})
Hongjun Ni8a0a0ae2017-05-27 20:23:09 +08001792
1793 def vxlan_gpe_add_del_tunnel(
1794 self,
1795 src_addr,
1796 dst_addr,
1797 mcast_sw_if_index=0xFFFFFFFF,
1798 is_add=1,
1799 is_ipv6=0,
1800 encap_vrf_id=0,
1801 decap_vrf_id=0,
1802 protocol=3,
1803 vni=0):
1804 """
1805
1806 :param local:
1807 :param remote:
1808 :param is_add: (Default value = 1)
1809 :param is_ipv6: (Default value = 0)
1810 :param encap_vrf_id: (Default value = 0)
1811 :param decap_vrf_id: (Default value = 0)
1812 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1813 :param protocol: (Default value = 3)
1814 :param vni: (Default value = 0)
1815
1816 """
1817 return self.api(self.papi.vxlan_gpe_add_del_tunnel,
1818 {'is_add': is_add,
1819 'is_ipv6': is_ipv6,
1820 'local': src_addr,
1821 'remote': dst_addr,
1822 'mcast_sw_if_index': mcast_sw_if_index,
1823 'encap_vrf_id': encap_vrf_id,
1824 'decap_vrf_id': decap_vrf_id,
1825 'protocol': protocol,
1826 'vni': vni})
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001827
Neale Ranns79a05f52018-09-11 07:39:43 -07001828 def vxlan_gbp_tunnel_add_del(
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001829 self,
Neale Ranns79a05f52018-09-11 07:39:43 -07001830 src,
1831 dst,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001832 mcast_sw_if_index=0xFFFFFFFF,
1833 is_add=1,
1834 is_ipv6=0,
Neale Ranns79a05f52018-09-11 07:39:43 -07001835 encap_table_id=0,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001836 vni=0,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001837 mode=1,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001838 instance=0xFFFFFFFF):
1839 """
1840
1841 :param dst_addr:
1842 :param src_addr:
1843 :param is_add: (Default value = 1)
1844 :param is_ipv6: (Default value = 0)
Neale Ranns79a05f52018-09-11 07:39:43 -07001845 :param encap_table_id: (Default value = 0)
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001846 :param decap_next_index: (Default value = 0xFFFFFFFF)
1847 :param mcast_sw_if_index: (Default value = 0xFFFFFFFF)
1848 :param vni: (Default value = 0)
1849 :param instance: (Default value = 0xFFFFFFFF)
1850
1851 """
Neale Ranns79a05f52018-09-11 07:39:43 -07001852 return self.api(self.papi.vxlan_gbp_tunnel_add_del,
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001853 {'is_add': is_add,
Neale Ranns79a05f52018-09-11 07:39:43 -07001854 'tunnel': {
1855 'src': src,
1856 'dst': dst,
1857 'mcast_sw_if_index': mcast_sw_if_index,
1858 'encap_table_id': encap_table_id,
Neale Ranns79a05f52018-09-11 07:39:43 -07001859 'vni': vni,
Neale Ranns4dd4cf42019-03-27 05:06:47 -07001860 'instance': instance,
1861 "mode": mode}})
Neale Ranns79a05f52018-09-11 07:39:43 -07001862
1863 def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff):
1864 return self.api(self.papi.vxlan_gbp_tunnel_dump,
Ole Troan0bcad322018-12-11 13:04:01 +01001865 {'sw_if_index': sw_if_index,
1866 '_no_type_conversion': True})
Mohsin Kazmi61b94c62018-08-20 18:32:39 +02001867
Hongjun Ni62f9cdd2017-07-04 20:11:57 +08001868 def pppoe_add_del_session(
1869 self,
1870 client_ip,
1871 client_mac,
1872 session_id=0,
1873 is_add=1,
1874 is_ipv6=0,
1875 decap_vrf_id=0):
1876 """
1877
1878 :param is_add: (Default value = 1)
1879 :param is_ipv6: (Default value = 0)
1880 :param client_ip:
1881 :param session_id: (Default value = 0)
1882 :param client_mac:
1883 :param decap_vrf_id: (Default value = 0)
1884
1885 """
1886 return self.api(self.papi.pppoe_add_del_session,
1887 {'is_add': is_add,
1888 'is_ipv6': is_ipv6,
1889 'session_id': session_id,
1890 'client_ip': client_ip,
1891 'decap_vrf_id': decap_vrf_id,
1892 'client_mac': client_mac})
Kris Michielsen91074432017-06-22 13:00:20 +02001893
Neale Ranns7c922dc2018-08-30 06:12:27 -07001894 def sr_mpls_policy_add(self, bsid, weight, type, segments):
1895 return self.api(self.papi.sr_mpls_policy_add,
1896 {'bsid': bsid,
1897 'weight': weight,
1898 'type': type,
1899 'n_segments': len(segments),
1900 'segments': segments})
1901
1902 def sr_mpls_policy_del(self, bsid):
1903 return self.api(self.papi.sr_mpls_policy_del,
1904 {'bsid': bsid})
1905
Kris Michielsen91074432017-06-22 13:00:20 +02001906 def sr_localsid_add_del(self,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001907 localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001908 behavior,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001909 nh_addr4,
1910 nh_addr6,
Kris Michielsen91074432017-06-22 13:00:20 +02001911 is_del=0,
1912 end_psp=0,
1913 sw_if_index=0xFFFFFFFF,
1914 vlan_index=0,
1915 fib_table=0,
1916 ):
1917 """ Add/del IPv6 SR local-SID.
1918
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001919 :param localsid:
Kris Michielsen91074432017-06-22 13:00:20 +02001920 :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5;
1921 :param behavior: END.DX4=6; END.DT6=7; END.DT4=8
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001922 :param nh_addr4:
1923 :param nh_addr6:
Kris Michielsen91074432017-06-22 13:00:20 +02001924 :param is_del: (Default value = 0)
1925 :param end_psp: (Default value = 0)
1926 :param sw_if_index: (Default value = 0xFFFFFFFF)
1927 :param vlan_index: (Default value = 0)
1928 :param fib_table: (Default value = 0)
1929 """
1930 return self.api(
1931 self.papi.sr_localsid_add_del,
1932 {'is_del': is_del,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001933 'localsid': localsid,
Kris Michielsen91074432017-06-22 13:00:20 +02001934 'end_psp': end_psp,
1935 'behavior': behavior,
1936 'sw_if_index': sw_if_index,
1937 'vlan_index': vlan_index,
1938 'fib_table': fib_table,
Pablo Camarillo3337bd22018-06-19 15:49:02 +02001939 'nh_addr4': nh_addr4,
1940 'nh_addr6': nh_addr6
Kris Michielsen91074432017-06-22 13:00:20 +02001941 }
1942 )
1943
1944 def sr_policy_add(
1945 self,
1946 bsid_addr,
1947 weight=1,
1948 is_encap=1,
1949 type=0,
1950 fib_table=0,
1951 n_segments=0,
1952 segments=[]):
1953 """
1954 :param bsid_addr: bindingSID of the SR Policy
1955 :param weight: weight of the sid list. optional. (default: 1)
1956 :param is_encap: (bool) whether SR policy should Encap or SRH insert \
1957 (default: Encap)
1958 :param type: type/behavior of the SR policy. (default or spray) \
1959 (default: default)
1960 :param fib_table: VRF where to install the FIB entry for the BSID \
1961 (default: 0)
1962 :param n_segments: number of segments \
1963 (default: 0)
1964 :param segments: a vector of IPv6 address composing the segment list \
1965 (default: [])
1966 """
1967 return self.api(
1968 self.papi.sr_policy_add,
1969 {'bsid_addr': bsid_addr,
1970 'weight': weight,
1971 'is_encap': is_encap,
1972 'type': type,
1973 'fib_table': fib_table,
1974 'n_segments': n_segments,
1975 'segments': segments
1976 }
1977 )
1978
1979 def sr_policy_del(
1980 self,
1981 bsid_addr,
1982 sr_policy_index=0):
1983 """
1984 :param bsid: bindingSID of the SR Policy
1985 :param sr_policy_index: index of the sr policy (default: 0)
1986 """
1987 return self.api(
1988 self.papi.sr_policy_del,
1989 {'bsid_addr': bsid_addr,
1990 'sr_policy_index': sr_policy_index
1991 })
1992
1993 def sr_steering_add_del(
1994 self,
1995 is_del,
1996 bsid_addr,
1997 sr_policy_index,
1998 table_id,
1999 prefix_addr,
2000 mask_width,
2001 sw_if_index,
2002 traffic_type):
2003 """
2004 Steer traffic L2 and L3 traffic through a given SR policy
2005
2006 :param is_del: delete or add
2007 :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index)
2008 :param sr_policy: is the index of the SR Policy (alt to bsid)
2009 :param table_id: is the VRF where to install the FIB entry for the BSID
2010 :param prefix_addr: is the IPv4/v6 address for L3 traffic type
2011 :param mask_width: is the mask for L3 traffic type
2012 :param sw_if_index: is the incoming interface for L2 traffic
2013 :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2)
2014 """
2015 return self.api(
2016 self.papi.sr_steering_add_del,
2017 {'is_del': is_del,
2018 'bsid_addr': bsid_addr,
2019 'sr_policy_index': sr_policy_index,
2020 'table_id': table_id,
2021 'prefix_addr': prefix_addr,
2022 'mask_width': mask_width,
2023 'sw_if_index': sw_if_index,
2024 'traffic_type': traffic_type
2025 })
Pavel Kotucek932f7412017-09-07 14:44:52 +02002026
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002027 def acl_add_replace(self, acl_index, r, tag='',
2028 expected_retval=0):
2029 """Add/replace an ACL
2030 :param int acl_index: ACL index to replace, 2^32-1 to create new ACL.
2031 :param acl_rule r: ACL rules array.
2032 :param str tag: symbolic tag (description) for this ACL.
2033 :param int count: number of rules.
2034 """
2035 return self.api(self.papi.acl_add_replace,
2036 {'acl_index': acl_index,
2037 'r': r,
2038 'count': len(r),
2039 'tag': tag},
2040 expected_retval=expected_retval)
2041
Andrew Yourtchenko987abe92017-09-27 13:50:31 +02002042 def acl_del(self, acl_index, expected_retval=0):
2043 """
2044
2045 :param acl_index:
2046 :return:
2047 """
2048 return self.api(self.papi.acl_del,
2049 {'acl_index': acl_index},
2050 expected_retval=expected_retval)
2051
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002052 def acl_interface_set_acl_list(self, sw_if_index, n_input, acls,
2053 expected_retval=0):
2054 return self.api(self.papi.acl_interface_set_acl_list,
2055 {'sw_if_index': sw_if_index,
2056 'count': len(acls),
2057 'n_input': n_input,
2058 'acls': acls},
2059 expected_retval=expected_retval)
2060
Andrew Yourtchenkoc43b3f92018-02-06 17:42:32 +01002061 def acl_interface_set_etype_whitelist(self, sw_if_index,
2062 n_input, whitelist,
2063 expected_retval=0):
2064 return self.api(self.papi.acl_interface_set_etype_whitelist,
2065 {'sw_if_index': sw_if_index,
2066 'count': len(whitelist),
2067 'n_input': n_input,
2068 'whitelist': whitelist},
2069 expected_retval=expected_retval)
2070
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02002071 def acl_interface_add_del(self,
2072 sw_if_index,
2073 acl_index,
2074 is_add=1):
2075 """ Add/Delete ACL to/from interface
2076
2077 :param sw_if_index:
2078 :param acl_index:
2079 :param is_add: (Default value = 1)
2080 """
2081
2082 return self.api(self.papi.acl_interface_add_del,
2083 {'is_add': is_add,
2084 'is_input': 1,
2085 'sw_if_index': sw_if_index,
2086 'acl_index': acl_index})
2087
Andrew Yourtchenko51d26512017-09-14 18:26:36 +02002088 def acl_dump(self, acl_index, expected_retval=0):
2089 return self.api(self.papi.acl_dump,
2090 {'acl_index': acl_index},
2091 expected_retval=expected_retval)
2092
Andrew Yourtchenko0e89dfc2018-03-23 09:34:29 +01002093 def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF,
2094 expected_retval=0):
2095 return self.api(self.papi.acl_interface_list_dump,
2096 {'sw_if_index': sw_if_index},
2097 expected_retval=expected_retval)
2098
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002099 def macip_acl_add(self, rules, tag=""):
2100 """ Add MACIP acl
2101
2102 :param rules: list of rules for given acl
2103 :param tag: acl tag
2104 """
2105
2106 return self.api(self.papi.macip_acl_add,
2107 {'r': rules,
2108 'count': len(rules),
2109 'tag': tag})
2110
Pavel Kotucek932f7412017-09-07 14:44:52 +02002111 def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""):
2112 """ Add MACIP acl
2113
2114 :param rules: list of rules for given acl
2115 :param tag: acl tag
2116 """
2117
Pavel Kotucekc29940c2017-09-07 08:17:31 +02002118 return self.api(self.papi.macip_acl_add_replace,
2119 {'acl_index': acl_index,
2120 'r': rules,
Pavel Kotucek932f7412017-09-07 14:44:52 +02002121 'count': len(rules),
2122 'tag': tag})
2123
Pavel Kotucek932f7412017-09-07 14:44:52 +02002124 def macip_acl_interface_add_del(self,
2125 sw_if_index,
2126 acl_index,
2127 is_add=1):
2128 """ Add MACIP acl to interface
2129
2130 :param sw_if_index:
2131 :param acl_index:
2132 :param is_add: (Default value = 1)
2133 """
2134
2135 return self.api(self.papi.macip_acl_interface_add_del,
2136 {'is_add': is_add,
2137 'sw_if_index': sw_if_index,
2138 'acl_index': acl_index})
2139
Pavel Kotucek932f7412017-09-07 14:44:52 +02002140 def macip_acl_dump(self, acl_index=4294967295):
2141 """ Return MACIP acl dump
2142 """
2143
2144 return self.api(
2145 self.papi.macip_acl_dump, {'acl_index': acl_index})
Neale Rannsd91c1db2017-07-31 02:30:50 -07002146
2147 def policer_add_del(self,
2148 name,
2149 cir,
2150 eir,
2151 cb,
2152 eb,
2153 is_add=1,
2154 rate_type=0,
2155 round_type=0,
2156 ptype=0,
2157 color_aware=0,
2158 conform_action_type=1,
2159 conform_dscp=0,
2160 exceed_action_type=0,
2161 exceed_dscp=0,
2162 violate_action_type=0,
2163 violate_dscp=0):
2164 return self.api(self.papi.policer_add_del,
2165 {'name': name,
2166 'cir': cir,
2167 'eir': eir,
2168 'cb': cb,
2169 'eb': eb,
2170 'is_add': is_add,
2171 'rate_type': rate_type,
2172 'round_type': round_type,
2173 'type': ptype,
2174 'color_aware': color_aware,
2175 'conform_action_type': conform_action_type,
2176 'conform_dscp': conform_dscp,
2177 'exceed_action_type': exceed_action_type,
2178 'exceed_dscp': exceed_dscp,
2179 'violate_action_type': violate_action_type,
2180 'violate_dscp': violate_dscp})
2181
2182 def ip_punt_police(self,
2183 policer_index,
2184 is_ip6=0,
2185 is_add=1):
2186 return self.api(self.papi.ip_punt_police,
2187 {'policer_index': policer_index,
2188 'is_add': is_add,
2189 'is_ip6': is_ip6})
2190
2191 def ip_punt_redirect(self,
2192 rx_sw_if_index,
2193 tx_sw_if_index,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002194 address,
Neale Rannsd91c1db2017-07-31 02:30:50 -07002195 is_add=1):
2196 return self.api(self.papi.ip_punt_redirect,
Pavel Kotucek609e1212018-11-27 09:59:44 +01002197 {'punt': {'rx_sw_if_index': rx_sw_if_index,
2198 'tx_sw_if_index': tx_sw_if_index,
2199 'nh': address},
2200 'is_add': is_add})
2201
2202 def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
2203 return self.api(self.papi.ip_punt_redirect_dump,
2204 {'sw_if_index': sw_if_index,
2205 'is_ipv6': is_ipv6})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002206
2207 def bier_table_add_del(self,
2208 bti,
2209 mpls_label,
2210 is_add=1):
2211 """ BIER Table add/del """
2212 return self.api(
2213 self.papi.bier_table_add_del,
2214 {'bt_tbl_id': {"bt_set": bti.set_id,
2215 "bt_sub_domain": bti.sub_domain_id,
2216 "bt_hdr_len_id": bti.hdr_len_id},
2217 'bt_label': mpls_label,
2218 'bt_is_add': is_add})
2219
2220 def bier_table_dump(self):
2221 return self.api(self.papi.bier_table_dump, {})
2222
2223 def bier_route_add_del(self,
2224 bti,
2225 bp,
Neale Ranns91286372017-12-05 13:24:04 -08002226 paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002227 is_add=1,
2228 is_replace=0):
Neale Rannsd792d9c2017-10-21 10:53:20 -07002229 """ BIER Route add/del """
2230 return self.api(
2231 self.papi.bier_route_add_del,
2232 {'br_tbl_id': {"bt_set": bti.set_id,
2233 "bt_sub_domain": bti.sub_domain_id,
2234 "bt_hdr_len_id": bti.hdr_len_id},
2235 'br_bp': bp,
Neale Ranns31ed7442018-02-23 05:29:09 -08002236 'br_n_paths': len(paths),
2237 'br_paths': paths,
Neale Rannsef90ed02018-09-13 08:45:12 -07002238 'br_is_add': is_add,
2239 'br_is_replace': is_replace})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002240
2241 def bier_route_dump(self, bti):
2242 return self.api(
2243 self.papi.bier_route_dump,
2244 {'br_tbl_id': {"bt_set": bti.set_id,
2245 "bt_sub_domain": bti.sub_domain_id,
2246 "bt_hdr_len_id": bti.hdr_len_id}})
2247
2248 def bier_imp_add(self,
2249 bti,
2250 src,
2251 ibytes,
2252 is_add=1):
2253 """ BIER Imposition Add """
2254 return self.api(
2255 self.papi.bier_imp_add,
2256 {'bi_tbl_id': {"bt_set": bti.set_id,
2257 "bt_sub_domain": bti.sub_domain_id,
2258 "bt_hdr_len_id": bti.hdr_len_id},
2259 'bi_src': src,
2260 'bi_n_bytes': len(ibytes),
2261 'bi_bytes': ibytes})
2262
2263 def bier_imp_del(self, bi_index):
2264 """ BIER Imposition del """
2265 return self.api(
2266 self.papi.bier_imp_del,
2267 {'bi_index': bi_index})
2268
2269 def bier_imp_dump(self):
2270 return self.api(self.papi.bier_imp_dump, {})
2271
2272 def bier_disp_table_add_del(self,
2273 bdti,
2274 is_add=1):
2275 """ BIER Disposition Table add/del """
2276 return self.api(
2277 self.papi.bier_disp_table_add_del,
2278 {'bdt_tbl_id': bdti,
2279 'bdt_is_add': is_add})
2280
2281 def bier_disp_table_dump(self):
2282 return self.api(self.papi.bier_disp_table_dump, {})
2283
2284 def bier_disp_entry_add_del(self,
2285 bdti,
2286 bp,
2287 payload_proto,
Neale Rannsf0510722018-01-31 11:35:41 -08002288 next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002289 next_hop,
2290 next_hop_tbl_id=0,
2291 next_hop_rpf_id=~0,
2292 next_hop_is_ip4=1,
2293 is_add=1):
2294 """ BIER Route add/del """
Neale Ranns31ed7442018-02-23 05:29:09 -08002295 lstack = []
2296 while (len(lstack) < 16):
2297 lstack.append({})
Neale Rannsd792d9c2017-10-21 10:53:20 -07002298 return self.api(
2299 self.papi.bier_disp_entry_add_del,
2300 {'bde_tbl_id': bdti,
2301 'bde_bp': bp,
2302 'bde_payload_proto': payload_proto,
2303 'bde_n_paths': 1,
2304 'bde_paths': [{'next_hop': next_hop,
2305 'table_id': next_hop_tbl_id,
Neale Rannsf0510722018-01-31 11:35:41 -08002306 'afi': next_hop_afi,
Neale Rannsd792d9c2017-10-21 10:53:20 -07002307 'rpf_id': next_hop_rpf_id,
2308 'n_labels': 0,
Neale Ranns31ed7442018-02-23 05:29:09 -08002309 'label_stack': lstack}],
Neale Rannsd792d9c2017-10-21 10:53:20 -07002310 'bde_is_add': is_add})
2311
2312 def bier_disp_entry_dump(self, bdti):
2313 return self.api(
2314 self.papi.bier_disp_entry_dump,
2315 {'bde_tbl_id': bdti})
Gabriel Ganne8527f122017-10-02 11:41:24 +02002316
Florin Coras3ea6ce22017-12-11 09:09:05 -08002317 def session_enable_disable(self, is_enabled):
2318 return self.api(
2319 self.papi.session_enable_disable,
2320 {'is_enable': is_enabled})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002321
2322 def ipsec_spd_add_del(self, spd_id, is_add=1):
2323 """ SPD add/del - Wrapper to add or del ipsec SPD
2324 Sample CLI : 'ipsec spd add 1'
2325
2326 :param spd_id - SPD ID to be created in the vpp . mandatory
2327 :param is_add - create (1) or delete(0) SPD (Default 1 - add) .
2328 optional
2329 :returns: reply from the API
2330 """
2331 return self.api(
2332 self.papi.ipsec_spd_add_del, {
2333 'spd_id': spd_id, 'is_add': is_add})
2334
Neale Ranns311124e2019-01-24 04:52:25 -08002335 def ipsec_spds_dump(self):
2336 return self.api(self.papi.ipsec_spds_dump, {})
2337
“mystarrocks”23f0c452017-12-11 07:11:51 -08002338 def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1):
2339 """ IPSEC interface SPD add/del - \
2340 Wrapper to associate/disassociate SPD to interface in VPP
2341 Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1'
2342
2343 :param spd_id - SPD ID to associate with the interface . mandatory
2344 :param sw_if_index - Interface Index which needs to ipsec \
2345 association mandatory
2346 :param is_add - add(1) or del(0) association with interface \
2347 (Default 1 - add) . optional
2348 :returns: reply from the API
2349 """
2350 return self.api(
Klement Sekera4b089f22018-04-17 18:04:57 +02002351 self.papi.ipsec_interface_add_del_spd,
2352 {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add})
“mystarrocks”23f0c452017-12-11 07:11:51 -08002353
Neale Ranns311124e2019-01-24 04:52:25 -08002354 def ipsec_spd_interface_dump(self, spd_index=None):
2355 return self.api(self.papi.ipsec_spd_interface_dump,
2356 {'spd_index': spd_index if spd_index else 0,
2357 'spd_index_valid': 1 if spd_index else 0})
2358
Neale Ranns17dcec02019-01-09 21:22:20 -08002359 def ipsec_sad_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002360 sad_id,
2361 spi,
Klement Sekera31da2e32018-06-24 22:49:55 +02002362 integrity_algorithm,
2363 integrity_key,
2364 crypto_algorithm,
2365 crypto_key,
2366 protocol,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002367 tunnel_src_address='',
2368 tunnel_dst_address='',
Neale Ranns17dcec02019-01-09 21:22:20 -08002369 flags=0,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002370 salt=0,
Neale Ranns17dcec02019-01-09 21:22:20 -08002371 is_add=1):
“mystarrocks”23f0c452017-12-11 07:11:51 -08002372 """ IPSEC SA add/del
Klement Sekera31da2e32018-06-24 22:49:55 +02002373 :param sad_id: security association ID
2374 :param spi: security param index of the SA in decimal
2375 :param integrity_algorithm:
2376 :param integrity_key:
2377 :param crypto_algorithm:
2378 :param crypto_key:
2379 :param protocol: AH(0) or ESP(1) protocol
2380 :param tunnel_src_address: tunnel mode outer src address
2381 :param tunnel_dst_address: tunnel mode outer dst address
2382 :param is_add:
2383 :param is_tunnel:
“mystarrocks”23f0c452017-12-11 07:11:51 -08002384 :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of
2385 crypto and ipsec algorithms
2386 """
2387 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002388 self.papi.ipsec_sad_entry_add_del,
2389 {
2390 'is_add': is_add,
2391 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002392 {
2393 'sad_id': sad_id,
2394 'spi': spi,
2395 'tunnel_src': tunnel_src_address,
2396 'tunnel_dst': tunnel_dst_address,
2397 'protocol': protocol,
2398 'integrity_algorithm': integrity_algorithm,
2399 'integrity_key': {
2400 'length': len(integrity_key),
2401 'data': integrity_key,
2402 },
2403 'crypto_algorithm': crypto_algorithm,
2404 'crypto_key': {
2405 'length': len(crypto_key),
2406 'data': crypto_key,
2407 },
2408 'flags': flags,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002409 'salt': salt,
Ole Troan9a475372019-03-05 16:58:24 +01002410 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002411 })
“mystarrocks”23f0c452017-12-11 07:11:51 -08002412
Neale Ranns311124e2019-01-24 04:52:25 -08002413 def ipsec_sa_dump(self, sa_id=None):
2414 return self.api(self.papi.ipsec_sa_dump,
2415 {'sa_id': sa_id if sa_id else 0xffffffff})
2416
Neale Ranns17dcec02019-01-09 21:22:20 -08002417 def ipsec_spd_entry_add_del(self,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002418 spd_id,
Klement Sekera31da2e32018-06-24 22:49:55 +02002419 sa_id,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002420 local_address_start,
2421 local_address_stop,
2422 remote_address_start,
2423 remote_address_stop,
2424 local_port_start=0,
2425 local_port_stop=65535,
2426 remote_port_start=0,
2427 remote_port_stop=65535,
2428 protocol=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002429 policy=0,
2430 priority=100,
2431 is_outbound=1,
2432 is_add=1,
Klement Sekera611864f2018-09-26 11:19:00 +02002433 is_ipv6=0,
“mystarrocks”23f0c452017-12-11 07:11:51 -08002434 is_ip_any=0):
2435 """ IPSEC policy SPD add/del -
2436 Wrapper to configure ipsec SPD policy entries in VPP
Klement Sekera31da2e32018-06-24 22:49:55 +02002437 :param spd_id: SPD ID for the policy
2438 :param local_address_start: local-ip-range start address
2439 :param local_address_stop : local-ip-range stop address
2440 :param remote_address_start: remote-ip-range start address
2441 :param remote_address_stop : remote-ip-range stop address
2442 :param local_port_start: (Default value = 0)
2443 :param local_port_stop: (Default value = 65535)
2444 :param remote_port_start: (Default value = 0)
2445 :param remote_port_stop: (Default value = 65535)
2446 :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0)
2447 :param sa_id: Security Association ID for mapping it to SPD
2448 :param policy: bypass(0), discard(1), resolve(2) or protect(3) action
2449 (Default value = 0)
2450 :param priority: value for the spd action (Default value = 100)
2451 :param is_outbound: flag for inbound(0) or outbound(1)
2452 (Default value = 1)
2453 :param is_add: (Default value = 1)
“mystarrocks”23f0c452017-12-11 07:11:51 -08002454 """
2455 return self.api(
Neale Ranns17dcec02019-01-09 21:22:20 -08002456 self.papi.ipsec_spd_entry_add_del,
2457 {
2458 'is_add': is_add,
2459 'entry':
Ole Troan9a475372019-03-05 16:58:24 +01002460 {
2461 'spd_id': spd_id,
2462 'sa_id': sa_id,
2463 'local_address_start': local_address_start,
2464 'local_address_stop': local_address_stop,
2465 'remote_address_start': remote_address_start,
2466 'remote_address_stop': remote_address_stop,
2467 'local_port_start': local_port_start,
2468 'local_port_stop': local_port_stop,
2469 'remote_port_start': remote_port_start,
2470 'remote_port_stop': remote_port_stop,
2471 'protocol': protocol,
2472 'policy': policy,
2473 'priority': priority,
2474 'is_outbound': is_outbound,
2475 'is_ip_any': is_ip_any
2476 }
Neale Ranns17dcec02019-01-09 21:22:20 -08002477 })
Florin Corasb795bd02017-12-14 11:30:48 -08002478
Neale Ranns311124e2019-01-24 04:52:25 -08002479 def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff):
2480 return self.api(self.papi.ipsec_spd_dump,
2481 {'spd_id': spd_id,
2482 'sa_id': sa_id})
2483
Klement Sekera31da2e32018-06-24 22:49:55 +02002484 def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi,
2485 remote_spi, crypto_alg, local_crypto_key,
2486 remote_crypto_key, integ_alg, local_integ_key,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002487 remote_integ_key, is_add=1, esn=0, salt=0,
Klement Sekera31da2e32018-06-24 22:49:55 +02002488 anti_replay=1, renumber=0, show_instance=0):
2489 return self.api(
2490 self.papi.ipsec_tunnel_if_add_del,
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002491 {
2492 'local_ip': local_ip,
2493 'remote_ip': remote_ip,
2494 'local_spi': local_spi,
2495 'remote_spi': remote_spi,
2496 'crypto_alg': crypto_alg,
2497 'local_crypto_key_len': len(local_crypto_key),
2498 'local_crypto_key': local_crypto_key,
2499 'remote_crypto_key_len': len(remote_crypto_key),
2500 'remote_crypto_key': remote_crypto_key,
2501 'integ_alg': integ_alg,
2502 'local_integ_key_len': len(local_integ_key),
2503 'local_integ_key': local_integ_key,
2504 'remote_integ_key_len': len(remote_integ_key),
2505 'remote_integ_key': remote_integ_key,
2506 'is_add': is_add,
2507 'esn': esn,
2508 'anti_replay': anti_replay,
2509 'renumber': renumber,
Neale Ranns80f6fd52019-04-16 02:41:34 +00002510 'show_instance': show_instance,
2511 'salt': salt
Kingwel Xie1ba5bc82019-03-20 07:21:58 -04002512 })
Klement Sekera31da2e32018-06-24 22:49:55 +02002513
Neale Rannsf05e7322019-03-29 20:23:58 +00002514 def ipsec_gre_tunnel_add_del(self, local_ip, remote_ip,
2515 sa_out, sa_in, is_add=1):
2516 return self.api(self.papi.ipsec_gre_tunnel_add_del,
2517 {
2518 'is_add': is_add,
2519 'tunnel': {
2520 'src': local_ip,
2521 'dst': remote_ip,
2522 'local_sa_id': sa_out,
2523 'remote_sa_id': sa_in
2524 }
2525 })
2526
Klement Sekerab4d30532018-11-08 13:00:02 +01002527 def ipsec_select_backend(self, protocol, index):
2528 return self.api(self.papi.ipsec_select_backend,
2529 {'protocol': protocol, 'index': index})
2530
2531 def ipsec_backend_dump(self):
2532 return self.api(self.papi.ipsec_backend_dump, {})
2533
Ole Troane1ade682019-03-04 23:55:43 +01002534 def app_namespace_add_del(self,
2535 namespace_id,
2536 ip4_fib_id=0,
2537 ip6_fib_id=0,
2538 sw_if_index=0xFFFFFFFF,
2539 secret=0):
Florin Corasb795bd02017-12-14 11:30:48 -08002540 return self.api(
2541 self.papi.app_namespace_add_del,
2542 {'secret': secret,
2543 'sw_if_index': sw_if_index,
2544 'ip4_fib_id': ip4_fib_id,
2545 'ip6_fib_id': ip6_fib_id,
2546 'namespace_id': namespace_id,
2547 'namespace_id_len': len(namespace_id)})
Klement Sekera75e7d132017-09-20 08:26:30 +02002548
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002549 def punt_socket_register(self, port, pathname, protocol=0x11,
2550 header_version=1, is_ip4=1):
2551 """ Register punt socket """
Klement Sekera75e7d132017-09-20 08:26:30 +02002552 return self.api(self.papi.punt_socket_register,
Pavel Kotuceke88865d2018-11-28 07:42:11 +01002553 {'header_version': header_version,
2554 'punt': {'ipv': is_ip4,
2555 'l4_protocol': protocol,
2556 'l4_port': port},
2557 'pathname': pathname})
2558
2559 def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1):
2560 """ Unregister punt socket """
2561 return self.api(self.papi.punt_socket_deregister,
2562 {'punt': {'ipv': is_ip4,
2563 'l4_protocol': protocol,
2564 'l4_port': port}})
2565
2566 def punt_socket_dump(self, is_ip6=1):
2567 """ Dump punt socket"""
2568 return self.api(self.papi.punt_socket_dump,
2569 {'is_ipv6': is_ip6})
Klement Sekera75e7d132017-09-20 08:26:30 +02002570
Neale Ranns4ba67722019-02-28 11:11:39 +00002571 def gbp_endpoint_add(self, sw_if_index, ips, mac, sclass, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002572 tun_src, tun_dst):
Neale Rannsc0a93142018-09-05 15:42:26 -07002573 """ GBP endpoint Add """
2574 return self.api(self.papi.gbp_endpoint_add,
2575 {'endpoint': {
2576 'sw_if_index': sw_if_index,
2577 'ips': ips,
2578 'n_ips': len(ips),
2579 'mac': mac,
Neale Ranns4ba67722019-02-28 11:11:39 +00002580 'sclass': sclass,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002581 'flags': flags,
2582 'tun': {
2583 'src': tun_src,
2584 'dst': tun_dst,
2585 }}})
Neale Rannsc0a93142018-09-05 15:42:26 -07002586
2587 def gbp_endpoint_del(self, handle):
2588 """ GBP endpoint Del """
2589 return self.api(self.papi.gbp_endpoint_del,
2590 {'handle': handle})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002591
2592 def gbp_endpoint_dump(self):
2593 """ GBP endpoint Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002594 return self.api(self.papi.gbp_endpoint_dump,
2595 {'_no_type_conversion': True})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002596
Neale Ranns4ba67722019-02-28 11:11:39 +00002597 def gbp_endpoint_group_add(self, vnid, sclass, bd,
Neale Ranns32f6d8e2019-03-05 04:22:08 -08002598 rd, uplink_sw_if_index,
2599 retention):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002600 """ GBP endpoint group Add """
2601 return self.api(self.papi.gbp_endpoint_group_add,
2602 {'epg':
Ole Troan9a475372019-03-05 16:58:24 +01002603 {
2604 'uplink_sw_if_index': uplink_sw_if_index,
2605 'bd_id': bd,
2606 'rd_id': rd,
2607 'vnid': vnid,
2608 'sclass': sclass,
2609 'retention': retention
2610 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002611
Neale Ranns4ba67722019-02-28 11:11:39 +00002612 def gbp_endpoint_group_del(self, sclass):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002613 """ GBP endpoint group Del """
2614 return self.api(self.papi.gbp_endpoint_group_del,
Neale Ranns4ba67722019-02-28 11:11:39 +00002615 {'sclass': sclass})
Neale Ranns25b04942018-04-04 09:34:50 -07002616
Neale Rannsc29c0af2018-11-07 04:21:12 -08002617 def gbp_bridge_domain_add(self, bd_id, flags,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002618 bvi_sw_if_index,
Neale Ranns879d11c2019-01-21 23:34:18 -08002619 uu_fwd_sw_if_index,
2620 bm_flood_sw_if_index):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002621 """ GBP bridge-domain Add """
2622 return self.api(self.papi.gbp_bridge_domain_add,
2623 {'bd':
Ole Troan9a475372019-03-05 16:58:24 +01002624 {
2625 'flags': flags,
2626 'bvi_sw_if_index': bvi_sw_if_index,
2627 'uu_fwd_sw_if_index': uu_fwd_sw_if_index,
2628 'bm_flood_sw_if_index': bm_flood_sw_if_index,
2629 'bd_id': bd_id
2630 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002631
2632 def gbp_bridge_domain_del(self, bd_id):
2633 """ GBP bridge-domain Del """
2634 return self.api(self.papi.gbp_bridge_domain_del,
2635 {'bd_id': bd_id})
2636
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002637 def gbp_route_domain_add(self, rd_id,
2638 ip4_table_id,
2639 ip6_table_id,
2640 ip4_uu_sw_if_index,
2641 ip6_uu_sw_if_index):
2642 """ GBP route-domain Add """
2643 return self.api(self.papi.gbp_route_domain_add,
2644 {'rd':
Ole Troan9a475372019-03-05 16:58:24 +01002645 {
2646 'ip4_table_id': ip4_table_id,
2647 'ip6_table_id': ip6_table_id,
2648 'ip4_uu_sw_if_index': ip4_uu_sw_if_index,
2649 'ip6_uu_sw_if_index': ip6_uu_sw_if_index,
2650 'rd_id': rd_id
2651 }})
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002652
2653 def gbp_route_domain_del(self, rd_id):
2654 """ GBP route-domain Del """
2655 return self.api(self.papi.gbp_route_domain_del,
2656 {'rd_id': rd_id})
2657
Neale Ranns4ba67722019-02-28 11:11:39 +00002658 def gbp_recirc_add_del(self, is_add, sw_if_index, sclass, is_ext):
Neale Ranns25b04942018-04-04 09:34:50 -07002659 """ GBP recirc Add/Del """
2660 return self.api(self.papi.gbp_recirc_add_del,
2661 {'is_add': is_add,
2662 'recirc': {
2663 'is_ext': is_ext,
2664 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002665 'sclass': sclass}})
Neale Ranns25b04942018-04-04 09:34:50 -07002666
2667 def gbp_recirc_dump(self):
2668 """ GBP recirc Dump """
2669 return self.api(self.papi.gbp_recirc_dump, {})
2670
Neale Rannsb6a47952018-11-21 05:44:35 -08002671 def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id):
2672 """ GBP recirc Add/Del """
2673 return self.api(self.papi.gbp_ext_itf_add_del,
2674 {'is_add': is_add,
2675 'ext_itf': {
2676 'sw_if_index': sw_if_index,
2677 'bd_id': bd_id,
2678 'rd_id': rd_id}})
2679
2680 def gbp_ext_itf_dump(self):
2681 """ GBP recirc Dump """
2682 return self.api(self.papi.gbp_ext_itf_dump, {})
2683
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002684 def gbp_subnet_add_del(self, is_add, rd_id,
2685 prefix, type,
Neale Ranns25b04942018-04-04 09:34:50 -07002686 sw_if_index=0xffffffff,
Neale Ranns4ba67722019-02-28 11:11:39 +00002687 sclass=0xffff):
Neale Ranns25b04942018-04-04 09:34:50 -07002688 """ GBP Subnet Add/Del """
2689 return self.api(self.papi.gbp_subnet_add_del,
2690 {'is_add': is_add,
2691 'subnet': {
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002692 'type': type,
Neale Ranns25b04942018-04-04 09:34:50 -07002693 'sw_if_index': sw_if_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002694 'sclass': sclass,
Neale Rannsc0a93142018-09-05 15:42:26 -07002695 'prefix': prefix,
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002696 'rd_id': rd_id}})
Neale Ranns25b04942018-04-04 09:34:50 -07002697
2698 def gbp_subnet_dump(self):
2699 """ GBP Subnet Dump """
Ole Troan0bcad322018-12-11 13:04:01 +01002700 return self.api(self.papi.gbp_subnet_dump,
2701 {'_no_type_conversion': True})
Neale Ranns25b04942018-04-04 09:34:50 -07002702
Neale Ranns4ba67722019-02-28 11:11:39 +00002703 def gbp_contract_add_del(self, is_add, sclass, dclass, acl_index,
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002704 rules, allowed_ethertypes):
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002705 """ GBP contract Add/Del """
2706 return self.api(self.papi.gbp_contract_add_del,
2707 {'is_add': is_add,
2708 'contract': {
2709 'acl_index': acl_index,
Neale Ranns4ba67722019-02-28 11:11:39 +00002710 'sclass': sclass,
2711 'dclass': dclass,
Neale Ranns13a08cc2018-11-07 09:25:54 -08002712 'n_rules': len(rules),
Neale Ranns1c17e2e2018-12-20 12:03:59 -08002713 'rules': rules,
2714 'n_ether_types': len(allowed_ethertypes),
2715 'allowed_ethertypes': allowed_ethertypes}})
Neale Rannsbc27d1b2018-02-05 01:13:38 -08002716
2717 def gbp_contract_dump(self):
2718 """ GBP contract Dump """
2719 return self.api(self.papi.gbp_contract_dump, {})
Ole Troan6ee40512018-02-12 18:14:39 +01002720
Neale Ranns8da9fc62019-03-04 14:08:11 -08002721 def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode, src):
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002722 """ GBP VXLAN tunnel add """
2723 return self.api(self.papi.gbp_vxlan_tunnel_add,
2724 {
2725 'tunnel': {
2726 'vni': vni,
2727 'mode': mode,
Neale Ranns8da9fc62019-03-04 14:08:11 -08002728 'bd_rd_id': bd_rd_id,
2729 'src': src
Neale Ranns93cc3ee2018-10-10 07:22:51 -07002730 }
2731 })
2732
2733 def gbp_vxlan_tunnel_del(self, vni):
2734 """ GBP VXLAN tunnel del """
2735 return self.api(self.papi.gbp_vxlan_tunnel_del,
2736 {
2737 'vni': vni,
2738 })
2739
2740 def gbp_vxlan_tunnel_dump(self):
2741 """ GBP VXLAN tunnel add/del """
2742 return self.api(self.papi.gbp_vxlan_tunnel_dump, {})
2743
Neale Ranns039cbfe2018-02-27 03:45:38 -08002744 def qos_egress_map_update(self, id, outputs):
2745 """ QOS egress map update """
2746 return self.api(self.papi.qos_egress_map_update,
2747 {'map_id': id,
2748 'rows': outputs})
2749
2750 def qos_egress_map_delete(self, id):
2751 """ QOS egress map delete """
2752 return self.api(self.papi.qos_egress_map_delete,
2753 {'map_id': id})
2754
2755 def qos_mark_enable_disable(self, sw_if_index,
2756 output_source,
2757 map_id,
2758 enable):
2759 """ QOS Mark Enable/Disable """
2760 return self.api(self.papi.qos_mark_enable_disable,
2761 {'map_id': map_id,
2762 'sw_if_index': sw_if_index,
2763 'output_source': output_source,
2764 'enable': enable})
2765
Neale Ranns947ea622018-06-07 23:48:20 -07002766 def igmp_enable_disable(self, sw_if_index, enable, host):
2767 """ Enable/disable IGMP on a given interface """
2768 return self.api(self.papi.igmp_enable_disable,
2769 {'enable': enable,
2770 'mode': host,
2771 'sw_if_index': sw_if_index})
2772
Jakub Grajciar97748ca2018-10-04 11:05:35 +02002773 def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add):
2774 """ Add/del IGMP proxy device """
2775 return self.api(self.papi.igmp_proxy_device_add_del,
2776 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2777 'add': add})
2778
2779 def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add):
2780 """ Add/del interface to/from IGMP proxy device """
2781 return self.api(self.papi.igmp_proxy_device_add_del_interface,
2782 {'vrf_id': vrf_id, 'sw_if_index': sw_if_index,
2783 'add': add})
2784
Neale Ranns947ea622018-06-07 23:48:20 -07002785 def igmp_listen(self, filter, sw_if_index, saddrs, gaddr):
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002786 """ Listen for new (S,G) on specified interface
2787
2788 :param enable: add/del
2789 :param sw_if_index: interface sw index
2790 :param saddr: source ip4 addr
2791 :param gaddr: group ip4 addr
2792 """
2793 return self.api(self.papi.igmp_listen,
Neale Ranns947ea622018-06-07 23:48:20 -07002794 {
2795 'group':
Ole Troan9a475372019-03-05 16:58:24 +01002796 {
2797 'filter': filter,
2798 'sw_if_index': sw_if_index,
2799 'n_srcs': len(saddrs),
2800 'saddrs': saddrs,
2801 'gaddr': gaddr
2802 }
Neale Ranns947ea622018-06-07 23:48:20 -07002803 })
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002804
Jakub Grajciar7b867a82017-12-08 16:28:42 +01002805 def igmp_clear_interface(self, sw_if_index):
2806 """ Remove all (S,G)s from specified interface
2807 doesn't send IGMP report!
2808 """
2809 return self.api(
2810 self.papi.igmp_clear_interface, {
2811 'sw_if_index': sw_if_index})
2812
2813 def want_igmp_events(self, enable=1):
2814 return self.api(self.papi.want_igmp_events, {'enable': enable,
2815 'pid': os.getpid()})
Steven9cd2d7a2017-12-20 12:43:01 -08002816
2817 def bond_create(
2818 self,
2819 mode,
2820 lb,
2821 use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002822 mac_address='',
2823 interface_id=0xFFFFFFFF):
Steven9cd2d7a2017-12-20 12:43:01 -08002824 """
2825 :param mode: mode
2826 :param lb: load balance
2827 :param use_custom_mac: use custom mac
2828 :param mac_address: mac address
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002829 :param interface_id: custom interface ID
Steven9cd2d7a2017-12-20 12:43:01 -08002830 """
2831 return self.api(
2832 self.papi.bond_create,
2833 {'mode': mode,
2834 'lb': lb,
2835 'use_custom_mac': use_custom_mac,
Alexander Chernavinad9d5282018-12-13 09:08:09 -05002836 'mac_address': mac_address,
2837 'id': interface_id
Steven9cd2d7a2017-12-20 12:43:01 -08002838 })
2839
Neale Ranns17ff3c12018-07-04 10:24:24 -07002840 def pipe_delete(self, parent_sw_if_index):
2841 return self.api(self.papi.pipe_delete,
2842 {'parent_sw_if_index': parent_sw_if_index})
2843
Jakub Grajciarb1be2a02018-09-19 13:36:16 +02002844 def memif_create(
2845 self,
2846 role,
2847 mode,
2848 rx_queues=None,
2849 tx_queues=None,
2850 _id=None,
2851 socket_id=None,
2852 secret=None,
2853 ring_size=None,
2854 buffer_size=None,
2855 hw_addr=None):
2856 return self.api(self.papi.memif_create,
2857 {'role': role,
2858 'mode': mode,
2859 'rx_queues': rx_queues,
2860 'tx_queues': tx_queues,
2861 'id': _id,
2862 'socket_id': socket_id,
2863 'secret': secret,
2864 'ring_size': ring_size,
2865 'buffer_size': buffer_size,
2866 'hw_addr': hw_addr})
2867
Neale Rannsd1e68ab2018-10-01 01:42:13 -07002868 def svs_table_add_del(self, af, table_id, is_add=1):
2869 return self.api(self.papi.svs_table_add_del,
2870 {
2871 'table_id': table_id,
2872 'is_add': is_add,
2873 'af': af,
2874 })
2875
2876 def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1):
2877 return self.api(self.papi.svs_route_add_del,
2878 {
2879 'table_id': table_id,
2880 'source_table_id': src_table_id,
2881 'prefix': prefix,
2882 'is_add': is_add,
2883 })
2884
2885 def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1):
2886 return self.api(self.papi.svs_enable_disable,
2887 {
2888 'af': af,
2889 'table_id': table_id,
2890 'sw_if_index': sw_if_index,
2891 'is_enable': is_enable,
2892 })