BFD: basic asynchronous session up/down
[vpp.git] / test / vpp_papi_provider.py
1 import os
2 import fnmatch
3 import time
4 from hook import Hook
5
6 # Sphinx creates auto-generated documentation by importing the python source
7 # files and collecting the docstrings from them. The NO_VPP_PAPI flag allows the
8 # vpp_papi_provider.py file to be importable without having to build the whole
9 # vpp api if the user only wishes to generate the test documentation.
10 do_import = True
11 try:
12     no_vpp_papi = os.getenv("NO_VPP_PAPI")
13     if no_vpp_papi == "1":
14         do_import = False
15 except:
16     pass
17
18 if do_import:
19     from vpp_papi import VPP
20
21 # from vnet/vnet/mpls/mpls_types.h
22 MPLS_IETF_MAX_LABEL = 0xfffff
23 MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
24
25
26 class L2_VTR_OP:
27     L2_POP_1 = 3
28
29
30 class VppPapiProvider(object):
31     """VPP-api provider using vpp-papi
32
33     @property hook: hook object providing before and after api/cli hooks
34
35
36     """
37
38     def __init__(self, name, shm_prefix, test_class):
39         self.hook = Hook("vpp-papi-provider")
40         self.name = name
41         self.shm_prefix = shm_prefix
42         self.test_class = test_class
43         jsonfiles = []
44
45         install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
46         for root, dirnames, filenames in os.walk(install_dir):
47             for filename in fnmatch.filter(filenames, '*.api.json'):
48                 jsonfiles.append(os.path.join(root, filename))
49
50         self.papi = VPP(jsonfiles)
51         self._events = list()
52
53     def register_hook(self, hook):
54         """Replace hook registration with new hook
55
56         :param hook:
57
58         """
59         self.hook = hook
60
61     def collect_events(self):
62         e = self._events
63         self._events = list()
64         return e
65
66     def wait_for_event(self, timeout, name=None):
67         limit = time.time() + timeout
68         while time.time() < limit:
69             if self._events:
70                 e = self._events.pop(0)
71                 if name and type(e).__name__ != name:
72                     raise Exception(
73                         "Unexpected event received: %s, expected: %s" %
74                         (type(e).__name__, name))
75                 return e
76             time.sleep(0)  # yield
77         if name is not None:
78             raise Exception("Event %s did not occur within timeout" % name)
79         raise Exception("Event did not occur within timeout")
80
81     def __call__(self, name, event):
82         # FIXME use the name instead of relying on type(e).__name__ ?
83         # FIXME #2 if this throws, it is eaten silently, Ole?
84         self._events.append(event)
85
86     def connect(self):
87         """Connect the API to VPP"""
88         self.papi.connect(self.name, self.shm_prefix)
89         self.papi.register_event_callback(self)
90
91     def disconnect(self):
92         """Disconnect the API from VPP"""
93         self.papi.disconnect()
94
95     def api(self, api_fn, api_args, expected_retval=0):
96         """Call API function and check it's return value
97         Call the appropriate hooks before and after the API call
98
99         :param api_fn: API function to call
100         :param api_args: tuple of API function arguments
101         :param expected_retval: Expected return value (Default value = 0)
102         :returns: reply from the API
103
104         """
105         self.hook.before_api(api_fn.__name__, api_args)
106         reply = api_fn(**api_args)
107         if hasattr(reply, 'retval') and reply.retval != expected_retval:
108             msg = "API call failed, expected retval == %d, got %s" % (
109                 expected_retval, repr(reply))
110             self.test_class.logger.error(msg)
111             raise Exception(msg)
112         self.hook.after_api(api_fn.__name__, api_args)
113         return reply
114
115     def cli(self, cli):
116         """
117         Execute a CLI, calling the before/after hooks appropriately.
118
119         :param cli: CLI to execute
120         :returns: CLI output
121
122         """
123         self.hook.before_cli(cli)
124         cli += '\n'
125         r = self.papi.cli_inband(length=len(cli), cmd=cli)
126         self.hook.after_cli(cli)
127         if hasattr(r, 'reply'):
128             return r.reply.decode().rstrip('\x00')
129
130     def ppcli(self, cli):
131         """
132         Helping method to print CLI command in case of info logging level.
133
134         :param cli: CLI to execute
135         :returns: CLI output
136         """
137         return cli + "\n" + str(self.cli(cli))
138
139     def _convert_mac(self, mac):
140         return int(mac.replace(":", ""), 16) << 16
141
142     def show_version(self):
143         """ """
144         return self.papi.show_version()
145
146     def pg_create_interface(self, pg_index):
147         """
148
149         :param pg_index:
150
151         """
152         return self.api(self.papi.pg_create_interface,
153                         {"interface_id": pg_index})
154
155     def sw_interface_dump(self, filter=None):
156         """
157
158         :param filter:  (Default value = None)
159
160         """
161         if filter is not None:
162             args = {"name_filter_valid": 1, "name_filter": filter}
163         else:
164             args = {}
165         return self.api(self.papi.sw_interface_dump, args)
166
167     def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
168         """
169           Set the IPvX Table-id for the Interface
170
171         :param sw_if_index:
172         :param is_ipv6:
173         :param table_id:
174
175         """
176         return self.api(self.papi.sw_interface_set_table,
177                         {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
178                          'vrf_id': table_id})
179
180     def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
181                                      is_ipv6=0, is_add=1, del_all=0):
182         """
183
184         :param addr: param is_ipv6:  (Default value = 0)
185         :param sw_if_index:
186         :param addr_len:
187         :param is_ipv6:  (Default value = 0)
188         :param is_add:  (Default value = 1)
189         :param del_all:  (Default value = 0)
190
191         """
192         return self.api(self.papi.sw_interface_add_del_address,
193                         {'sw_if_index': sw_if_index,
194                          'is_add': is_add,
195                          'is_ipv6': is_ipv6,
196                          'del_all': del_all,
197                          'address_length': addr_len,
198                          'address': addr})
199
200     def sw_interface_enable_disable_mpls(self, sw_if_index,
201                                          is_enable=1):
202         """
203         Enable/Disable MPLS on the interface
204         :param sw_if_index:
205         :param is_enable:  (Default value = 1)
206
207         """
208         return self.api(self.papi.sw_interface_set_mpls_enable,
209                         {'sw_if_index': sw_if_index,
210                          'enable': is_enable})
211
212     def sw_interface_ra_suppress(self, sw_if_index):
213         return self.api(self.papi.sw_interface_ip6nd_ra_config,
214                         {'sw_if_index': sw_if_index})
215
216     def vxlan_add_del_tunnel(
217             self,
218             src_addr,
219             dst_addr,
220             mcast_sw_if_index=0xFFFFFFFF,
221             is_add=1,
222             is_ipv6=0,
223             encap_vrf_id=0,
224             decap_next_index=0xFFFFFFFF,
225             vni=0):
226         """
227
228         :param dst_addr:
229         :param src_addr:
230         :param is_add:  (Default value = 1)
231         :param is_ipv6:  (Default value = 0)
232         :param encap_vrf_id:  (Default value = 0)
233         :param decap_next_index:  (Default value = 0xFFFFFFFF)
234         :param mcast_sw_if_index:  (Default value = 0xFFFFFFFF)
235         :param vni:  (Default value = 0)
236
237         """
238         return self.api(self.papi.vxlan_add_del_tunnel,
239                         {'is_add': is_add,
240                          'is_ipv6': is_ipv6,
241                          'src_address': src_addr,
242                          'dst_address': dst_addr,
243                          'mcast_sw_if_index': mcast_sw_if_index,
244                          'encap_vrf_id': encap_vrf_id,
245                          'decap_next_index': decap_next_index,
246                          'vni': vni})
247
248     def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
249                               learn=1, arp_term=0, is_add=1):
250         """Create/delete bridge domain.
251
252         :param int bd_id: Bridge domain index.
253         :param int flood: Enable/disable bcast/mcast flooding in the BD.
254             (Default value = 1)
255         :param int uu_flood: Enable/disable unknown unicast flood in the BD.
256             (Default value = 1)
257         :param int forward: Enable/disable forwarding on all interfaces in
258             the BD. (Default value = 1)
259         :param int learn: Enable/disable learning on all interfaces in the BD.
260             (Default value = 1)
261         :param int arp_term: Enable/disable arp termination in the BD.
262             (Default value = 1)
263         :param int is_add: Add or delete flag. (Default value = 1)
264         """
265         return self.api(self.papi.bridge_domain_add_del,
266                         {'bd_id': bd_id,
267                          'flood': flood,
268                          'uu_flood': uu_flood,
269                          'forward': forward,
270                          'learn': learn,
271                          'arp_term': arp_term,
272                          'is_add': is_add})
273
274     def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
275                       filter_mac=0, bvi_mac=0):
276         """Create/delete L2 FIB entry.
277
278         :param str mac: MAC address to create FIB entry for.
279         :param int bd_id: Bridge domain index.
280         :param int sw_if_index: Software interface index of the interface.
281         :param int is_add: Add or delete flag. (Default value = 1)
282         :param int static_mac: Set to 1 to create static MAC entry.
283             (Default value = 0)
284         :param int filter_mac: Set to 1 to drop packet that's source or
285             destination MAC address contains defined MAC address.
286             (Default value = 0)
287         :param int bvi_mac: Set to 1 to create entry that points to BVI
288             interface. (Default value = 0)
289         """
290         return self.api(self.papi.l2fib_add_del,
291                         {'mac': self._convert_mac(mac),
292                          'bd_id': bd_id,
293                          'sw_if_index': sw_if_index,
294                          'is_add': is_add,
295                          'static_mac': static_mac,
296                          'filter_mac': filter_mac,
297                          'bvi_mac': bvi_mac})
298
299     def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
300                                    shg=0, bvi=0, enable=1):
301         """Add/remove interface to/from bridge domain.
302
303         :param int sw_if_index: Software interface index of the interface.
304         :param int bd_id: Bridge domain index.
305         :param int shg: Split-horizon group index. (Default value = 0)
306         :param int bvi: Set interface as a bridge group virtual interface.
307             (Default value = 0)
308         :param int enable: Add or remove interface. (Default value = 1)
309         """
310         return self.api(self.papi.sw_interface_set_l2_bridge,
311                         {'rx_sw_if_index': sw_if_index,
312                          'bd_id': bd_id,
313                          'shg': shg,
314                          'bvi': bvi,
315                          'enable': enable})
316
317     def bridge_flags(self, bd_id, is_set, feature_bitmap):
318         """Enable/disable required feature of the bridge domain with defined ID.
319
320         :param int bd_id: Bridge domain ID.
321         :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
322         :param int feature_bitmap: Bitmap value of the feature to be set:
323             - learn (1 << 0),
324             - forward (1 << 1),
325             - flood (1 << 2),
326             - uu-flood (1 << 3) or
327             - arp-term (1 << 4).
328         """
329         return self.api(self.papi.bridge_flags,
330                         {'bd_id': bd_id,
331                          'is_set': is_set,
332                          'feature_bitmap': feature_bitmap})
333
334     def bridge_domain_dump(self, bd_id=0):
335         """
336
337         :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
338             existing bridge domains returned)
339         :return: Dictionary of bridge domain(s) data.
340         """
341         return self.api(self.papi.bridge_domain_dump,
342                         {'bd_id': bd_id})
343
344     def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
345                                      enable):
346         """Create or delete unidirectional cross-connect from Tx interface to
347         Rx interface.
348
349         :param int rx_sw_if_index: Software interface index of Rx interface.
350         :param int tx_sw_if_index: Software interface index of Tx interface.
351         :param int enable: Create cross-connect if equal to 1, delete
352             cross-connect if equal to 0.
353
354         """
355         return self.api(self.papi.sw_interface_set_l2_xconnect,
356                         {'rx_sw_if_index': rx_sw_if_index,
357                          'tx_sw_if_index': tx_sw_if_index,
358                          'enable': enable})
359
360     def sw_interface_set_l2_tag_rewrite(
361             self,
362             sw_if_index,
363             vtr_oper,
364             push=0,
365             tag1=0,
366             tag2=0):
367         """L2 interface vlan tag rewrite configure request
368         :param client_index - opaque cookie to identify the sender
369         :param context - sender context, to match reply w/ request
370         :param sw_if_index - interface the operation is applied to
371         :param vtr_op - Choose from l2_vtr_op_t enum values
372         :param push_dot1q - first pushed flag dot1q id set, else dot1ad
373         :param tag1 - Needed for any push or translate vtr op
374         :param tag2 - Needed for any push 2 or translate x-2 vtr ops
375
376         """
377         return self.api(self.papi.l2_interface_vlan_tag_rewrite,
378                         {'sw_if_index': sw_if_index,
379                          'vtr_op': vtr_oper,
380                          'push_dot1q': push,
381                          'tag1': tag1,
382                          'tag2': tag2})
383
384     def sw_interface_set_flags(self, sw_if_index, admin_up_down,
385                                link_up_down=0, deleted=0):
386         """
387
388         :param admin_up_down:
389         :param sw_if_index:
390         :param link_up_down:  (Default value = 0)
391         :param deleted:  (Default value = 0)
392
393         """
394         return self.api(self.papi.sw_interface_set_flags,
395                         {'sw_if_index': sw_if_index,
396                          'admin_up_down': admin_up_down,
397                          'link_up_down': link_up_down,
398                          'deleted': deleted})
399
400     def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
401                      no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
402                      default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
403         """Create subinterface
404         from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
405
406         :param sub_id: param inner_vlan:
407         :param sw_if_index:
408         :param outer_vlan:
409         :param inner_vlan:
410         :param no_tags:  (Default value = 0)
411         :param one_tag:  (Default value = 0)
412         :param two_tags:  (Default value = 0)
413         :param dot1ad:  (Default value = 0)
414         :param exact_match:  (Default value = 0)
415         :param default_sub:  (Default value = 0)
416         :param outer_vlan_id_any:  (Default value = 0)
417         :param inner_vlan_id_any:  (Default value = 0)
418
419         """
420         return self.api(
421             self.papi.create_subif,
422             {'sw_if_index': sw_if_index,
423              'sub_id': sub_id,
424              'no_tags': no_tags,
425              'one_tag': one_tag,
426              'two_tags': two_tags,
427              'dot1ad': dot1ad,
428              'exact_match': exact_match,
429              'default_sub': default_sub,
430              'outer_vlan_id_any': outer_vlan_id_any,
431              'inner_vlan_id_any': inner_vlan_id_any,
432              'outer_vlan_id': outer_vlan,
433              'inner_vlan_id': inner_vlan})
434
435     def delete_subif(self, sw_if_index):
436         """Delete subinterface
437
438         :param sw_if_index:
439         """
440         return self.api(self.papi.delete_subif,
441                         {'sw_if_index': sw_if_index})
442
443     def create_vlan_subif(self, sw_if_index, vlan):
444         """
445
446         :param vlan:
447         :param sw_if_index:
448
449         """
450         return self.api(self.papi.create_vlan_subif,
451                         {'sw_if_index': sw_if_index,
452                          'vlan_id': vlan})
453
454     def create_loopback(self, mac=''):
455         """
456
457         :param mac: (Optional)
458         """
459         return self.api(self.papi.create_loopback,
460                         {'mac_address': mac})
461
462     def ip_add_del_route(
463             self,
464             dst_address,
465             dst_address_length,
466             next_hop_address,
467             next_hop_sw_if_index=0xFFFFFFFF,
468             table_id=0,
469             next_hop_table_id=0,
470             next_hop_weight=1,
471             next_hop_n_out_labels=0,
472             next_hop_out_label_stack=[],
473             next_hop_via_label=MPLS_LABEL_INVALID,
474             create_vrf_if_needed=0,
475             is_resolve_host=0,
476             is_resolve_attached=0,
477             classify_table_index=0xFFFFFFFF,
478             is_add=1,
479             is_drop=0,
480             is_unreach=0,
481             is_prohibit=0,
482             is_ipv6=0,
483             is_local=0,
484             is_classify=0,
485             is_multipath=0,
486             not_last=0):
487         """
488
489         :param dst_address_length:
490         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
491         :param dst_address:
492         :param next_hop_address:
493         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
494         :param vrf_id:  (Default value = 0)
495         :param lookup_in_vrf:  (Default value = 0)
496         :param classify_table_index:  (Default value = 0xFFFFFFFF)
497         :param create_vrf_if_needed:  (Default value = 0)
498         :param is_add:  (Default value = 1)
499         :param is_drop:  (Default value = 0)
500         :param is_ipv6:  (Default value = 0)
501         :param is_local:  (Default value = 0)
502         :param is_classify:  (Default value = 0)
503         :param is_multipath:  (Default value = 0)
504         :param is_resolve_host:  (Default value = 0)
505         :param is_resolve_attached:  (Default value = 0)
506         :param not_last:  (Default value = 0)
507         :param next_hop_weight:  (Default value = 1)
508
509         """
510
511         return self.api(
512             self.papi.ip_add_del_route,
513             {'next_hop_sw_if_index': next_hop_sw_if_index,
514              'table_id': table_id,
515              'classify_table_index': classify_table_index,
516              'next_hop_table_id': next_hop_table_id,
517              'create_vrf_if_needed': create_vrf_if_needed,
518              'is_add': is_add,
519              'is_drop': is_drop,
520              'is_unreach': is_unreach,
521              'is_prohibit': is_prohibit,
522              'is_ipv6': is_ipv6,
523              'is_local': is_local,
524              'is_classify': is_classify,
525              'is_multipath': is_multipath,
526              'is_resolve_host': is_resolve_host,
527              'is_resolve_attached': is_resolve_attached,
528              'not_last': not_last,
529              'next_hop_weight': next_hop_weight,
530              'dst_address_length': dst_address_length,
531              'dst_address': dst_address,
532              'next_hop_address': next_hop_address,
533              'next_hop_n_out_labels': next_hop_n_out_labels,
534              'next_hop_via_label': next_hop_via_label,
535              'next_hop_out_label_stack': next_hop_out_label_stack})
536
537     def ip_neighbor_add_del(self,
538                             sw_if_index,
539                             mac_address,
540                             dst_address,
541                             vrf_id=0,
542                             is_add=1,
543                             is_ipv6=0,
544                             is_static=0,
545                             ):
546         """ Add neighbor MAC to IPv4 or IPv6 address.
547
548         :param sw_if_index:
549         :param mac_address:
550         :param dst_address:
551         :param vrf_id:  (Default value = 0)
552         :param is_add:  (Default value = 1)
553         :param is_ipv6:  (Default value = 0)
554         :param is_static:  (Default value = 0)
555         """
556
557         return self.api(
558             self.papi.ip_neighbor_add_del,
559             {'vrf_id': vrf_id,
560              'sw_if_index': sw_if_index,
561              'is_add': is_add,
562              'is_ipv6': is_ipv6,
563              'is_static': is_static,
564              'mac_address': mac_address,
565              'dst_address': dst_address
566              }
567         )
568
569     def sw_interface_span_enable_disable(
570             self, sw_if_index_from, sw_if_index_to, state=1):
571         """
572
573         :param sw_if_index_from:
574         :param sw_if_index_to:
575         :param enable
576
577         """
578         return self.api(self.papi.sw_interface_span_enable_disable,
579                         {'sw_if_index_from': sw_if_index_from,
580                          'sw_if_index_to': sw_if_index_to,
581                          'state': state})
582
583     def gre_tunnel_add_del(self,
584                            src_address,
585                            dst_address,
586                            outer_fib_id=0,
587                            is_teb=0,
588                            is_add=1,
589                            is_ip6=0):
590         """ Add a GRE tunnel
591
592         :param src_address:
593         :param dst_address:
594         :param outer_fib_id:  (Default value = 0)
595         :param is_add:  (Default value = 1)
596         :param is_ipv6:  (Default value = 0)
597         :param is_teb:  (Default value = 0)
598         """
599
600         return self.api(
601             self.papi.gre_add_del_tunnel,
602             {'is_add': is_add,
603              'is_ipv6': is_ip6,
604              'teb': is_teb,
605              'src_address': src_address,
606              'dst_address': dst_address,
607              'outer_fib_id': outer_fib_id}
608         )
609
610     def mpls_route_add_del(
611             self,
612             label,
613             eos,
614             next_hop_proto_is_ip4,
615             next_hop_address,
616             next_hop_sw_if_index=0xFFFFFFFF,
617             table_id=0,
618             next_hop_table_id=0,
619             next_hop_weight=1,
620             next_hop_n_out_labels=0,
621             next_hop_out_label_stack=[],
622             next_hop_via_label=MPLS_LABEL_INVALID,
623             create_vrf_if_needed=0,
624             is_resolve_host=0,
625             is_resolve_attached=0,
626             is_add=1,
627             is_drop=0,
628             is_multipath=0,
629             classify_table_index=0xFFFFFFFF,
630             is_classify=0,
631             not_last=0):
632         """
633
634         :param dst_address_length:
635         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
636         :param dst_address:
637         :param next_hop_address:
638         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
639         :param vrf_id:  (Default value = 0)
640         :param lookup_in_vrf:  (Default value = 0)
641         :param classify_table_index:  (Default value = 0xFFFFFFFF)
642         :param create_vrf_if_needed:  (Default value = 0)
643         :param is_add:  (Default value = 1)
644         :param is_drop:  (Default value = 0)
645         :param is_ipv6:  (Default value = 0)
646         :param is_local:  (Default value = 0)
647         :param is_classify:  (Default value = 0)
648         :param is_multipath:  (Default value = 0)
649         :param is_resolve_host:  (Default value = 0)
650         :param is_resolve_attached:  (Default value = 0)
651         :param not_last:  (Default value = 0)
652         :param next_hop_weight:  (Default value = 1)
653
654         """
655
656         return self.api(
657             self.papi.mpls_route_add_del,
658             {'mr_label': label,
659              'mr_eos': eos,
660              'mr_table_id': table_id,
661              'mr_classify_table_index': classify_table_index,
662              'mr_create_table_if_needed': create_vrf_if_needed,
663              'mr_is_add': is_add,
664              'mr_is_classify': is_classify,
665              'mr_is_multipath': is_multipath,
666              'mr_is_resolve_host': is_resolve_host,
667              'mr_is_resolve_attached': is_resolve_attached,
668              'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
669              'mr_next_hop_weight': next_hop_weight,
670              'mr_next_hop': next_hop_address,
671              'mr_next_hop_n_out_labels': next_hop_n_out_labels,
672              'mr_next_hop_sw_if_index': next_hop_sw_if_index,
673              'mr_next_hop_table_id': next_hop_table_id,
674              'mr_next_hop_via_label': next_hop_via_label,
675              'mr_next_hop_out_label_stack': next_hop_out_label_stack})
676
677     def mpls_ip_bind_unbind(
678             self,
679             label,
680             dst_address,
681             dst_address_length,
682             table_id=0,
683             ip_table_id=0,
684             is_ip4=1,
685             create_vrf_if_needed=0,
686             is_bind=1):
687         """
688         """
689         return self.api(
690             self.papi.mpls_ip_bind_unbind,
691             {'mb_mpls_table_id': table_id,
692              'mb_label': label,
693              'mb_ip_table_id': ip_table_id,
694              'mb_create_table_if_needed': create_vrf_if_needed,
695              'mb_is_bind': is_bind,
696              'mb_is_ip4': is_ip4,
697              'mb_address_length': dst_address_length,
698              'mb_address': dst_address})
699
700     def mpls_tunnel_add_del(
701             self,
702             tun_sw_if_index,
703             next_hop_proto_is_ip4,
704             next_hop_address,
705             next_hop_sw_if_index=0xFFFFFFFF,
706             next_hop_table_id=0,
707             next_hop_weight=1,
708             next_hop_n_out_labels=0,
709             next_hop_out_label_stack=[],
710             next_hop_via_label=MPLS_LABEL_INVALID,
711             create_vrf_if_needed=0,
712             is_add=1,
713             l2_only=0):
714         """
715
716         :param dst_address_length:
717         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
718         :param dst_address:
719         :param next_hop_address:
720         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
721         :param vrf_id:  (Default value = 0)
722         :param lookup_in_vrf:  (Default value = 0)
723         :param classify_table_index:  (Default value = 0xFFFFFFFF)
724         :param create_vrf_if_needed:  (Default value = 0)
725         :param is_add:  (Default value = 1)
726         :param is_drop:  (Default value = 0)
727         :param is_ipv6:  (Default value = 0)
728         :param is_local:  (Default value = 0)
729         :param is_classify:  (Default value = 0)
730         :param is_multipath:  (Default value = 0)
731         :param is_resolve_host:  (Default value = 0)
732         :param is_resolve_attached:  (Default value = 0)
733         :param not_last:  (Default value = 0)
734         :param next_hop_weight:  (Default value = 1)
735
736         """
737         return self.api(
738             self.papi.mpls_tunnel_add_del,
739             {'mt_sw_if_index': tun_sw_if_index,
740              'mt_is_add': is_add,
741              'mt_l2_only': l2_only,
742              'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
743              'mt_next_hop_weight': next_hop_weight,
744              'mt_next_hop': next_hop_address,
745              'mt_next_hop_n_out_labels': next_hop_n_out_labels,
746              'mt_next_hop_sw_if_index': next_hop_sw_if_index,
747              'mt_next_hop_table_id': next_hop_table_id,
748              'mt_next_hop_out_label_stack': next_hop_out_label_stack})
749
750     def snat_interface_add_del_feature(
751             self,
752             sw_if_index,
753             is_inside=1,
754             is_add=1):
755         """Enable/disable S-NAT feature on the interface
756
757         :param sw_if_index: Software index of the interface
758         :param is_inside: 1 if inside, 0 if outside (Default value = 1)
759         :param is_add: 1 if add, 0 if delete (Default value = 1)
760         """
761         return self.api(
762             self.papi.snat_interface_add_del_feature,
763             {'is_add': is_add,
764              'is_inside': is_inside,
765              'sw_if_index': sw_if_index})
766
767     def snat_add_static_mapping(
768             self,
769             local_ip,
770             external_ip,
771             local_port=0,
772             external_port=0,
773             addr_only=1,
774             vrf_id=0,
775             is_add=1,
776             is_ip4=1):
777         """Add/delete S-NAT static mapping
778
779         :param local_ip: Local IP address
780         :param external_ip: External IP address
781         :param local_port: Local port number (Default value = 0)
782         :param external_port: External port number (Default value = 0)
783         :param addr_only: 1 if address only mapping, 0 if address and port
784         :param vrf_id: VRF ID
785         :param is_add: 1 if add, 0 if delete (Default value = 1)
786         :param is_ip4: 1 if address type is IPv4 (Default value = 1)
787         """
788         return self.api(
789             self.papi.snat_add_static_mapping,
790             {'is_add': is_add,
791              'is_ip4': is_ip4,
792              'addr_only': addr_only,
793              'local_ip_address': local_ip,
794              'external_ip_address': external_ip,
795              'local_port': local_port,
796              'external_port': external_port,
797              'vrf_id': vrf_id})
798
799     def snat_add_address_range(
800             self,
801             first_ip_address,
802             last_ip_address,
803             is_add=1,
804             is_ip4=1):
805         """Add/del S-NAT address range
806
807         :param first_ip_address: First IP address
808         :param last_ip_address: Last IP address
809         :param is_add: 1 if add, 0 if delete (Default value = 1)
810         :param is_ip4: 1 if address type is IPv4 (Default value = 1)
811         """
812         return self.api(
813             self.papi.snat_add_address_range,
814             {'is_ip4': is_ip4,
815              'first_ip_address': first_ip_address,
816              'last_ip_address': last_ip_address,
817              'is_add': is_add})
818
819     def snat_address_dump(self):
820         """Dump S-NAT addresses
821         :return: Dictionary of S-NAT addresses
822         """
823         return self.api(self.papi.snat_address_dump, {})
824
825     def snat_interface_dump(self):
826         """Dump interfaces with S-NAT feature
827         :return: Dictionary of interfaces with S-NAT feature
828         """
829         return self.api(self.papi.snat_interface_dump, {})
830
831     def snat_static_mapping_dump(self):
832         """Dump S-NAT static mappings
833         :return: Dictionary of S-NAT static mappings
834         """
835         return self.api(self.papi.snat_static_mapping_dump, {})
836
837     def control_ping(self):
838         self.api(self.papi.control_ping)
839
840     def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
841                     detect_mult, local_addr, peer_addr, is_ipv6=0):
842         return self.api(self.papi.bfd_udp_add,
843                         {
844                             'sw_if_index': sw_if_index,
845                             'desired_min_tx': desired_min_tx,
846                             'required_min_rx': required_min_rx,
847                             'local_addr': local_addr,
848                             'peer_addr': peer_addr,
849                             'is_ipv6': is_ipv6,
850                             'detect_mult': detect_mult,
851                         })
852
853     def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
854         return self.api(self.papi.bfd_udp_del,
855                         {
856                             'sw_if_index': sw_if_index,
857                             'local_addr': local_addr,
858                             'peer_addr': peer_addr,
859                             'is_ipv6': is_ipv6,
860                         })
861
862     def bfd_udp_session_dump(self):
863         return self.api(self.papi.bfd_udp_session_dump, {})
864
865     def bfd_session_set_flags(self, bs_idx, admin_up_down):
866         return self.api(self.papi.bfd_session_set_flags, {
867             'bs_index': bs_idx,
868             'admin_up_down': admin_up_down,
869         })
870
871     def want_bfd_events(self, enable_disable=1):
872         return self.api(self.papi.want_bfd_events, {
873             'enable_disable': enable_disable,
874             'pid': os.getpid(),
875         })