CGN: Deterministic NAT (VPP-623)
[vpp.git] / test / vpp_papi_provider.py
1 import os
2 import fnmatch
3 import time
4 from hook import Hook
5 from collections import deque
6
7 # Sphinx creates auto-generated documentation by importing the python source
8 # files and collecting the docstrings from them. The NO_VPP_PAPI flag allows
9 # the vpp_papi_provider.py file to be importable without having to build
10 # the whole vpp api if the user only wishes to generate the test documentation.
11 do_import = True
12 try:
13     no_vpp_papi = os.getenv("NO_VPP_PAPI")
14     if no_vpp_papi == "1":
15         do_import = False
16 except:
17     pass
18
19 if do_import:
20     from vpp_papi import VPP
21
22 # from vnet/vnet/mpls/mpls_types.h
23 MPLS_IETF_MAX_LABEL = 0xfffff
24 MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
25
26
27 class L2_VTR_OP:
28     L2_POP_1 = 3
29
30
31 class UnexpectedApiReturnValueError(Exception):
32     """ exception raised when the API return value is unexpected """
33     pass
34
35
36 class VppPapiProvider(object):
37     """VPP-api provider using vpp-papi
38
39     @property hook: hook object providing before and after api/cli hooks
40     """
41
42     _zero, _negative = range(2)
43
44     def __init__(self, name, shm_prefix, test_class):
45         self.hook = Hook("vpp-papi-provider")
46         self.name = name
47         self.shm_prefix = shm_prefix
48         self.test_class = test_class
49         self._expect_api_retval = self._zero
50         self._expect_stack = []
51         jsonfiles = []
52
53         install_dir = os.getenv('VPP_TEST_INSTALL_PATH')
54         for root, dirnames, filenames in os.walk(install_dir):
55             for filename in fnmatch.filter(filenames, '*.api.json'):
56                 jsonfiles.append(os.path.join(root, filename))
57
58         self.vpp = VPP(jsonfiles)
59         self._events = deque()
60
61     def __enter__(self):
62         return self
63
64     def expect_negative_api_retval(self):
65         """ Expect API failure """
66         self._expect_stack.append(self._expect_api_retval)
67         self._expect_api_retval = self._negative
68         return self
69
70     def expect_zero_api_retval(self):
71         """ Expect API success """
72         self._expect_stack.append(self._expect_api_retval)
73         self._expect_api_retval = self._zero
74         return self
75
76     def __exit__(self, exc_type, exc_value, traceback):
77         self._expect_api_retval = self._expect_stack.pop()
78
79     def register_hook(self, hook):
80         """Replace hook registration with new hook
81
82         :param hook:
83
84         """
85         self.hook = hook
86
87     def collect_events(self):
88         """ Collect all events from the internal queue and clear the queue. """
89         e = self._events
90         self._events = deque()
91         return e
92
93     def wait_for_event(self, timeout, name=None):
94         """ Wait for and return next event. """
95         if name:
96             self.test_class.logger.debug("Expecting event within %ss",
97                                          timeout)
98         else:
99             self.test_class.logger.debug("Expecting event '%s' within %ss",
100                                          name, timeout)
101         if self._events:
102             self.test_class.logger.debug("Not waiting, event already queued")
103         limit = time.time() + timeout
104         while time.time() < limit:
105             if self._events:
106                 e = self._events.popleft()
107                 if name and type(e).__name__ != name:
108                     raise Exception(
109                         "Unexpected event received: %s, expected: %s" %
110                         (type(e).__name__, name))
111                 self.test_class.logger.debug("Returning event %s:%s" %
112                                              (name, e))
113                 return e
114             time.sleep(0)  # yield
115         raise Exception("Event did not occur within timeout")
116
117     def __call__(self, name, event):
118         """ Enqueue event in the internal event queue. """
119         # FIXME use the name instead of relying on type(e).__name__ ?
120         # FIXME #2 if this throws, it is eaten silently, Ole?
121         self.test_class.logger.debug("New event: %s: %s" % (name, event))
122         self._events.append(event)
123
124     def connect(self):
125         """Connect the API to VPP"""
126         self.vpp.connect(self.name, self.shm_prefix)
127         self.papi = self.vpp.api
128         self.vpp.register_event_callback(self)
129
130     def disconnect(self):
131         """Disconnect the API from VPP"""
132         self.vpp.disconnect()
133
134     def api(self, api_fn, api_args, expected_retval=0):
135         """ Call API function and check it's return value.
136         Call the appropriate hooks before and after the API call
137
138         :param api_fn: API function to call
139         :param api_args: tuple of API function arguments
140         :param expected_retval: Expected return value (Default value = 0)
141         :returns: reply from the API
142
143         """
144         self.hook.before_api(api_fn.__name__, api_args)
145         reply = api_fn(**api_args)
146         if self._expect_api_retval == self._negative:
147             if hasattr(reply, 'retval') and reply.retval >= 0:
148                 msg = "API call passed unexpectedly: expected negative "\
149                     "return value instead of %d in %s" % \
150                     (reply.retval, repr(reply))
151                 self.test_class.logger.info(msg)
152                 raise UnexpectedApiReturnValueError(msg)
153         elif self._expect_api_retval == self._zero:
154             if hasattr(reply, 'retval') and reply.retval != expected_retval:
155                 msg = "API call failed, expected zero return value instead "\
156                     "of %d in %s" % (expected_retval, repr(reply))
157                 self.test_class.logger.info(msg)
158                 raise UnexpectedApiReturnValueError(msg)
159         else:
160             raise Exception("Internal error, unexpected value for "
161                             "self._expect_api_retval %s" %
162                             self._expect_api_retval)
163         self.hook.after_api(api_fn.__name__, api_args)
164         return reply
165
166     def cli(self, cli):
167         """ Execute a CLI, calling the before/after hooks appropriately.
168
169         :param cli: CLI to execute
170         :returns: CLI output
171
172         """
173         self.hook.before_cli(cli)
174         cli += '\n'
175         r = self.papi.cli_inband(length=len(cli), cmd=cli)
176         self.hook.after_cli(cli)
177         if hasattr(r, 'reply'):
178             return r.reply.decode().rstrip('\x00')
179
180     def ppcli(self, cli):
181         """ Helper method to print CLI command in case of info logging level.
182
183         :param cli: CLI to execute
184         :returns: CLI output
185         """
186         return cli + "\n" + str(self.cli(cli))
187
188     def _convert_mac(self, mac):
189         return int(mac.replace(":", ""), 16) << 16
190
191     def show_version(self):
192         """ """
193         return self.api(self.papi.show_version, {})
194
195     def pg_create_interface(self, pg_index):
196         """
197
198         :param pg_index:
199
200         """
201         return self.api(self.papi.pg_create_interface,
202                         {"interface_id": pg_index})
203
204     def sw_interface_dump(self, filter=None):
205         """
206
207         :param filter:  (Default value = None)
208
209         """
210         if filter is not None:
211             args = {"name_filter_valid": 1, "name_filter": filter}
212         else:
213             args = {}
214         return self.api(self.papi.sw_interface_dump, args)
215
216     def sw_interface_set_table(self, sw_if_index, is_ipv6, table_id):
217         """ Set the IPvX Table-id for the Interface
218
219         :param sw_if_index:
220         :param is_ipv6:
221         :param table_id:
222
223         """
224         return self.api(self.papi.sw_interface_set_table,
225                         {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6,
226                          'vrf_id': table_id})
227
228     def sw_interface_add_del_address(self, sw_if_index, addr, addr_len,
229                                      is_ipv6=0, is_add=1, del_all=0):
230         """
231
232         :param addr: param is_ipv6:  (Default value = 0)
233         :param sw_if_index:
234         :param addr_len:
235         :param is_ipv6:  (Default value = 0)
236         :param is_add:  (Default value = 1)
237         :param del_all:  (Default value = 0)
238
239         """
240         return self.api(self.papi.sw_interface_add_del_address,
241                         {'sw_if_index': sw_if_index,
242                          'is_add': is_add,
243                          'is_ipv6': is_ipv6,
244                          'del_all': del_all,
245                          'address_length': addr_len,
246                          'address': addr})
247
248     def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index,
249                                     is_add=1):
250         """ Set the Interface to be unnumbered
251
252         :param is_add:  (Default value = 1)
253         :param sw_if_index - interface That will be unnumbered
254         :param ip_sw_if_index - interface with an IP addres
255
256         """
257         return self.api(self.papi.sw_interface_set_unnumbered,
258                         {'sw_if_index': ip_sw_if_index,
259                          'unnumbered_sw_if_index': sw_if_index,
260                          'is_add': is_add})
261
262     def sw_interface_enable_disable_mpls(self, sw_if_index,
263                                          is_enable=1):
264         """
265         Enable/Disable MPLS on the interface
266         :param sw_if_index:
267         :param is_enable:  (Default value = 1)
268
269         """
270         return self.api(self.papi.sw_interface_set_mpls_enable,
271                         {'sw_if_index': sw_if_index,
272                          'enable': is_enable})
273
274     def sw_interface_ra_suppress(self, sw_if_index, suppress=1):
275         return self.api(self.papi.sw_interface_ip6nd_ra_config,
276                         {'sw_if_index': sw_if_index,
277                          'suppress': suppress})
278
279     def ip6_sw_interface_ra_config(self, sw_if_index,
280                                    no,
281                                    suppress,
282                                    send_unicast):
283         return self.api(self.papi.sw_interface_ip6nd_ra_config,
284                         {'sw_if_index': sw_if_index,
285                          'is_no': no,
286                          'suppress': suppress,
287                          'send_unicast': send_unicast})
288
289     def ip6_sw_interface_ra_prefix(self,
290                                    sw_if_index,
291                                    address,
292                                    address_length,
293                                    use_default=0,
294                                    no_advertise=0,
295                                    off_link=0,
296                                    no_autoconfig=0,
297                                    no_onlink=0,
298                                    is_no=0,
299                                    val_lifetime=0xffffffff,
300                                    pref_lifetime=0xffffffff):
301         return self.api(self.papi.sw_interface_ip6nd_ra_prefix,
302                         {'sw_if_index': sw_if_index,
303                          'address': address,
304                          'address_length': address_length,
305                          'use_default': use_default,
306                          'no_advertise': no_advertise,
307                          'off_link': off_link,
308                          'no_autoconfig': no_autoconfig,
309                          'no_onlink': no_onlink,
310                          'is_no': is_no,
311                          'val_lifetime': val_lifetime,
312                          'pref_lifetime': pref_lifetime})
313
314     def ip6_sw_interface_enable_disable(self, sw_if_index, enable):
315         """
316         Enable/Disable An interface for IPv6
317         """
318         return self.api(self.papi.sw_interface_ip6_enable_disable,
319                         {'sw_if_index': sw_if_index,
320                          'enable': enable})
321
322     def vxlan_add_del_tunnel(
323             self,
324             src_addr,
325             dst_addr,
326             mcast_sw_if_index=0xFFFFFFFF,
327             is_add=1,
328             is_ipv6=0,
329             encap_vrf_id=0,
330             decap_next_index=0xFFFFFFFF,
331             vni=0):
332         """
333
334         :param dst_addr:
335         :param src_addr:
336         :param is_add:  (Default value = 1)
337         :param is_ipv6:  (Default value = 0)
338         :param encap_vrf_id:  (Default value = 0)
339         :param decap_next_index:  (Default value = 0xFFFFFFFF)
340         :param mcast_sw_if_index:  (Default value = 0xFFFFFFFF)
341         :param vni:  (Default value = 0)
342
343         """
344         return self.api(self.papi.vxlan_add_del_tunnel,
345                         {'is_add': is_add,
346                          'is_ipv6': is_ipv6,
347                          'src_address': src_addr,
348                          'dst_address': dst_addr,
349                          'mcast_sw_if_index': mcast_sw_if_index,
350                          'encap_vrf_id': encap_vrf_id,
351                          'decap_next_index': decap_next_index,
352                          'vni': vni})
353
354     def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1,
355                               learn=1, arp_term=0, is_add=1):
356         """Create/delete bridge domain.
357
358         :param int bd_id: Bridge domain index.
359         :param int flood: Enable/disable bcast/mcast flooding in the BD.
360             (Default value = 1)
361         :param int uu_flood: Enable/disable unknown unicast flood in the BD.
362             (Default value = 1)
363         :param int forward: Enable/disable forwarding on all interfaces in
364             the BD. (Default value = 1)
365         :param int learn: Enable/disable learning on all interfaces in the BD.
366             (Default value = 1)
367         :param int arp_term: Enable/disable arp termination in the BD.
368             (Default value = 1)
369         :param int is_add: Add or delete flag. (Default value = 1)
370         """
371         return self.api(self.papi.bridge_domain_add_del,
372                         {'bd_id': bd_id,
373                          'flood': flood,
374                          'uu_flood': uu_flood,
375                          'forward': forward,
376                          'learn': learn,
377                          'arp_term': arp_term,
378                          'is_add': is_add})
379
380     def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0,
381                       filter_mac=0, bvi_mac=0):
382         """Create/delete L2 FIB entry.
383
384         :param str mac: MAC address to create FIB entry for.
385         :param int bd_id: Bridge domain index.
386         :param int sw_if_index: Software interface index of the interface.
387         :param int is_add: Add or delete flag. (Default value = 1)
388         :param int static_mac: Set to 1 to create static MAC entry.
389             (Default value = 0)
390         :param int filter_mac: Set to 1 to drop packet that's source or
391             destination MAC address contains defined MAC address.
392             (Default value = 0)
393         :param int bvi_mac: Set to 1 to create entry that points to BVI
394             interface. (Default value = 0)
395         """
396         return self.api(self.papi.l2fib_add_del,
397                         {'mac': self._convert_mac(mac),
398                          'bd_id': bd_id,
399                          'sw_if_index': sw_if_index,
400                          'is_add': is_add,
401                          'static_mac': static_mac,
402                          'filter_mac': filter_mac,
403                          'bvi_mac': bvi_mac})
404
405     def sw_interface_set_l2_bridge(self, sw_if_index, bd_id,
406                                    shg=0, bvi=0, enable=1):
407         """Add/remove interface to/from bridge domain.
408
409         :param int sw_if_index: Software interface index of the interface.
410         :param int bd_id: Bridge domain index.
411         :param int shg: Split-horizon group index. (Default value = 0)
412         :param int bvi: Set interface as a bridge group virtual interface.
413             (Default value = 0)
414         :param int enable: Add or remove interface. (Default value = 1)
415         """
416         return self.api(self.papi.sw_interface_set_l2_bridge,
417                         {'rx_sw_if_index': sw_if_index,
418                          'bd_id': bd_id,
419                          'shg': shg,
420                          'bvi': bvi,
421                          'enable': enable})
422
423     def bridge_flags(self, bd_id, is_set, feature_bitmap):
424         """Enable/disable required feature of the bridge domain with defined ID.
425
426         :param int bd_id: Bridge domain ID.
427         :param int is_set: Set to 1 to enable, set to 0 to disable the feature.
428         :param int feature_bitmap: Bitmap value of the feature to be set:
429             - learn (1 << 0),
430             - forward (1 << 1),
431             - flood (1 << 2),
432             - uu-flood (1 << 3) or
433             - arp-term (1 << 4).
434         """
435         return self.api(self.papi.bridge_flags,
436                         {'bd_id': bd_id,
437                          'is_set': is_set,
438                          'feature_bitmap': feature_bitmap})
439
440     def bridge_domain_dump(self, bd_id=0):
441         """
442
443         :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all
444             existing bridge domains returned)
445         :return: Dictionary of bridge domain(s) data.
446         """
447         return self.api(self.papi.bridge_domain_dump,
448                         {'bd_id': bd_id})
449
450     def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index,
451                                      enable):
452         """Create or delete unidirectional cross-connect from Tx interface to
453         Rx interface.
454
455         :param int rx_sw_if_index: Software interface index of Rx interface.
456         :param int tx_sw_if_index: Software interface index of Tx interface.
457         :param int enable: Create cross-connect if equal to 1, delete
458             cross-connect if equal to 0.
459
460         """
461         return self.api(self.papi.sw_interface_set_l2_xconnect,
462                         {'rx_sw_if_index': rx_sw_if_index,
463                          'tx_sw_if_index': tx_sw_if_index,
464                          'enable': enable})
465
466     def sw_interface_set_l2_tag_rewrite(
467             self,
468             sw_if_index,
469             vtr_oper,
470             push=0,
471             tag1=0,
472             tag2=0):
473         """L2 interface vlan tag rewrite configure request
474         :param client_index - opaque cookie to identify the sender
475         :param context - sender context, to match reply w/ request
476         :param sw_if_index - interface the operation is applied to
477         :param vtr_op - Choose from l2_vtr_op_t enum values
478         :param push_dot1q - first pushed flag dot1q id set, else dot1ad
479         :param tag1 - Needed for any push or translate vtr op
480         :param tag2 - Needed for any push 2 or translate x-2 vtr ops
481
482         """
483         return self.api(self.papi.l2_interface_vlan_tag_rewrite,
484                         {'sw_if_index': sw_if_index,
485                          'vtr_op': vtr_oper,
486                          'push_dot1q': push,
487                          'tag1': tag1,
488                          'tag2': tag2})
489
490     def sw_interface_set_flags(self, sw_if_index, admin_up_down,
491                                link_up_down=0, deleted=0):
492         """
493
494         :param admin_up_down:
495         :param sw_if_index:
496         :param link_up_down:  (Default value = 0)
497         :param deleted:  (Default value = 0)
498
499         """
500         return self.api(self.papi.sw_interface_set_flags,
501                         {'sw_if_index': sw_if_index,
502                          'admin_up_down': admin_up_down,
503                          'link_up_down': link_up_down,
504                          'deleted': deleted})
505
506     def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan,
507                      no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0,
508                      default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0):
509         """Create subinterface
510         from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad
511
512         :param sub_id: param inner_vlan:
513         :param sw_if_index:
514         :param outer_vlan:
515         :param inner_vlan:
516         :param no_tags:  (Default value = 0)
517         :param one_tag:  (Default value = 0)
518         :param two_tags:  (Default value = 0)
519         :param dot1ad:  (Default value = 0)
520         :param exact_match:  (Default value = 0)
521         :param default_sub:  (Default value = 0)
522         :param outer_vlan_id_any:  (Default value = 0)
523         :param inner_vlan_id_any:  (Default value = 0)
524
525         """
526         return self.api(
527             self.papi.create_subif,
528             {'sw_if_index': sw_if_index,
529              'sub_id': sub_id,
530              'no_tags': no_tags,
531              'one_tag': one_tag,
532              'two_tags': two_tags,
533              'dot1ad': dot1ad,
534              'exact_match': exact_match,
535              'default_sub': default_sub,
536              'outer_vlan_id_any': outer_vlan_id_any,
537              'inner_vlan_id_any': inner_vlan_id_any,
538              'outer_vlan_id': outer_vlan,
539              'inner_vlan_id': inner_vlan})
540
541     def delete_subif(self, sw_if_index):
542         """Delete subinterface
543
544         :param sw_if_index:
545         """
546         return self.api(self.papi.delete_subif,
547                         {'sw_if_index': sw_if_index})
548
549     def create_vlan_subif(self, sw_if_index, vlan):
550         """
551
552         :param vlan:
553         :param sw_if_index:
554
555         """
556         return self.api(self.papi.create_vlan_subif,
557                         {'sw_if_index': sw_if_index,
558                          'vlan_id': vlan})
559
560     def create_loopback(self, mac=''):
561         """
562
563         :param mac: (Optional)
564         """
565         return self.api(self.papi.create_loopback,
566                         {'mac_address': mac})
567
568     def delete_loopback(self, sw_if_index):
569         return self.api(self.papi.delete_loopback,
570                         {'sw_if_index': sw_if_index, })
571
572     def ip_add_del_route(
573             self,
574             dst_address,
575             dst_address_length,
576             next_hop_address,
577             next_hop_sw_if_index=0xFFFFFFFF,
578             table_id=0,
579             next_hop_table_id=0,
580             next_hop_weight=1,
581             next_hop_n_out_labels=0,
582             next_hop_out_label_stack=[],
583             next_hop_via_label=MPLS_LABEL_INVALID,
584             create_vrf_if_needed=0,
585             is_resolve_host=0,
586             is_resolve_attached=0,
587             classify_table_index=0xFFFFFFFF,
588             is_add=1,
589             is_drop=0,
590             is_unreach=0,
591             is_prohibit=0,
592             is_ipv6=0,
593             is_local=0,
594             is_classify=0,
595             is_multipath=0,
596             not_last=0):
597         """
598
599         :param dst_address_length:
600         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
601         :param dst_address:
602         :param next_hop_address:
603         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
604         :param vrf_id:  (Default value = 0)
605         :param lookup_in_vrf:  (Default value = 0)
606         :param classify_table_index:  (Default value = 0xFFFFFFFF)
607         :param create_vrf_if_needed:  (Default value = 0)
608         :param is_add:  (Default value = 1)
609         :param is_drop:  (Default value = 0)
610         :param is_ipv6:  (Default value = 0)
611         :param is_local:  (Default value = 0)
612         :param is_classify:  (Default value = 0)
613         :param is_multipath:  (Default value = 0)
614         :param is_resolve_host:  (Default value = 0)
615         :param is_resolve_attached:  (Default value = 0)
616         :param not_last:  (Default value = 0)
617         :param next_hop_weight:  (Default value = 1)
618
619         """
620
621         return self.api(
622             self.papi.ip_add_del_route,
623             {'next_hop_sw_if_index': next_hop_sw_if_index,
624              'table_id': table_id,
625              'classify_table_index': classify_table_index,
626              'next_hop_table_id': next_hop_table_id,
627              'create_vrf_if_needed': create_vrf_if_needed,
628              'is_add': is_add,
629              'is_drop': is_drop,
630              'is_unreach': is_unreach,
631              'is_prohibit': is_prohibit,
632              'is_ipv6': is_ipv6,
633              'is_local': is_local,
634              'is_classify': is_classify,
635              'is_multipath': is_multipath,
636              'is_resolve_host': is_resolve_host,
637              'is_resolve_attached': is_resolve_attached,
638              'not_last': not_last,
639              'next_hop_weight': next_hop_weight,
640              'dst_address_length': dst_address_length,
641              'dst_address': dst_address,
642              'next_hop_address': next_hop_address,
643              'next_hop_n_out_labels': next_hop_n_out_labels,
644              'next_hop_via_label': next_hop_via_label,
645              'next_hop_out_label_stack': next_hop_out_label_stack})
646
647     def ip_fib_dump(self):
648         return self.api(self.papi.ip_fib_dump, {})
649
650     def ip6_fib_dump(self):
651         return self.api(self.papi.ip6_fib_dump, {})
652
653     def ip_neighbor_add_del(self,
654                             sw_if_index,
655                             mac_address,
656                             dst_address,
657                             is_add=1,
658                             is_ipv6=0,
659                             is_static=0,
660                             ):
661         """ Add neighbor MAC to IPv4 or IPv6 address.
662
663         :param sw_if_index:
664         :param mac_address:
665         :param dst_address:
666         :param is_add:  (Default value = 1)
667         :param is_ipv6:  (Default value = 0)
668         :param is_static:  (Default value = 0)
669         """
670
671         return self.api(
672             self.papi.ip_neighbor_add_del,
673             {'sw_if_index': sw_if_index,
674              'is_add': is_add,
675              'is_ipv6': is_ipv6,
676              'is_static': is_static,
677              'mac_address': mac_address,
678              'dst_address': dst_address
679              }
680         )
681
682     def ip_neighbor_dump(self,
683                          sw_if_index,
684                          is_ipv6=0):
685         """ Return IP neighbor dump.
686
687         :param sw_if_index:
688         :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
689         """
690
691         return self.api(
692             self.papi.ip_neighbor_dump,
693             {'is_ipv6': is_ipv6,
694              'sw_if_index': sw_if_index
695              }
696         )
697
698     def proxy_arp_add_del(self,
699                           low_address,
700                           hi_address,
701                           vrf_id=0,
702                           is_add=1):
703         """ Config Proxy Arp Range.
704
705         :param low_address: Start address in the rnage to Proxy for
706         :param hi_address: End address in the rnage to Proxy for
707         :param vrf_id: The VRF/table in which to proxy
708         """
709
710         return self.api(
711             self.papi.proxy_arp_add_del,
712             {'vrf_id': vrf_id,
713              'is_add': is_add,
714              'low_address': low_address,
715              'hi_address': hi_address,
716              }
717         )
718
719     def proxy_arp_intfc_enable_disable(self,
720                                        sw_if_index,
721                                        is_enable=1):
722         """ Enable/Disable an interface for proxy ARP requests
723
724         :param sw_if_index: Interface
725         :param enable_disable: Enable/Disable
726         """
727
728         return self.api(
729             self.papi.proxy_arp_intfc_enable_disable,
730             {'sw_if_index': sw_if_index,
731              'enable_disable': is_enable
732              }
733         )
734
735     def reset_vrf(self,
736                   vrf_id,
737                   is_ipv6=0,
738                   ):
739         """ Reset VRF (remove all routes etc.) request.
740
741         :param int vrf_id: ID of the FIB table / VRF to reset.
742         :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
743         """
744
745         return self.api(
746             self.papi.reset_vrf,
747             {'vrf_id': vrf_id,
748              'is_ipv6': is_ipv6,
749              }
750         )
751
752     def reset_fib(self,
753                   vrf_id,
754                   is_ipv6=0,
755                   ):
756         """ Reset VRF (remove all routes etc.) request.
757
758         :param int vrf_id: ID of the FIB table / VRF to reset.
759         :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
760         """
761
762         return self.api(
763             self.papi.reset_fib,
764             {'vrf_id': vrf_id,
765              'is_ipv6': is_ipv6,
766              }
767         )
768
769     def ip_dump(self,
770                 is_ipv6=0,
771                 ):
772         """ Return IP dump.
773
774         :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0)
775         """
776
777         return self.api(
778             self.papi.ip_dump,
779             {'is_ipv6': is_ipv6,
780              }
781         )
782
783     def sw_interface_span_enable_disable(
784             self, sw_if_index_from, sw_if_index_to, state=1):
785         """
786
787         :param sw_if_index_from:
788         :param sw_if_index_to:
789         :param state:
790         """
791         return self.api(self.papi.sw_interface_span_enable_disable,
792                         {'sw_if_index_from': sw_if_index_from,
793                          'sw_if_index_to': sw_if_index_to,
794                          'state': state})
795
796     def gre_tunnel_add_del(self,
797                            src_address,
798                            dst_address,
799                            outer_fib_id=0,
800                            is_teb=0,
801                            is_add=1,
802                            is_ip6=0):
803         """ Add a GRE tunnel
804
805         :param src_address:
806         :param dst_address:
807         :param outer_fib_id:  (Default value = 0)
808         :param is_add:  (Default value = 1)
809         :param is_ipv6:  (Default value = 0)
810         :param is_teb:  (Default value = 0)
811         """
812
813         return self.api(
814             self.papi.gre_add_del_tunnel,
815             {'is_add': is_add,
816              'is_ipv6': is_ip6,
817              'teb': is_teb,
818              'src_address': src_address,
819              'dst_address': dst_address,
820              'outer_fib_id': outer_fib_id}
821         )
822
823     def mpls_fib_dump(self):
824         return self.api(self.papi.mpls_fib_dump, {})
825
826     def mpls_route_add_del(
827             self,
828             label,
829             eos,
830             next_hop_proto_is_ip4,
831             next_hop_address,
832             next_hop_sw_if_index=0xFFFFFFFF,
833             table_id=0,
834             next_hop_table_id=0,
835             next_hop_weight=1,
836             next_hop_n_out_labels=0,
837             next_hop_out_label_stack=[],
838             next_hop_via_label=MPLS_LABEL_INVALID,
839             create_vrf_if_needed=0,
840             is_resolve_host=0,
841             is_resolve_attached=0,
842             is_add=1,
843             is_drop=0,
844             is_multipath=0,
845             classify_table_index=0xFFFFFFFF,
846             is_classify=0,
847             not_last=0):
848         """
849
850         :param dst_address_length:
851         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
852         :param dst_address:
853         :param next_hop_address:
854         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
855         :param vrf_id:  (Default value = 0)
856         :param lookup_in_vrf:  (Default value = 0)
857         :param classify_table_index:  (Default value = 0xFFFFFFFF)
858         :param create_vrf_if_needed:  (Default value = 0)
859         :param is_add:  (Default value = 1)
860         :param is_drop:  (Default value = 0)
861         :param is_ipv6:  (Default value = 0)
862         :param is_local:  (Default value = 0)
863         :param is_classify:  (Default value = 0)
864         :param is_multipath:  (Default value = 0)
865         :param is_resolve_host:  (Default value = 0)
866         :param is_resolve_attached:  (Default value = 0)
867         :param not_last:  (Default value = 0)
868         :param next_hop_weight:  (Default value = 1)
869
870         """
871
872         return self.api(
873             self.papi.mpls_route_add_del,
874             {'mr_label': label,
875              'mr_eos': eos,
876              'mr_table_id': table_id,
877              'mr_classify_table_index': classify_table_index,
878              'mr_create_table_if_needed': create_vrf_if_needed,
879              'mr_is_add': is_add,
880              'mr_is_classify': is_classify,
881              'mr_is_multipath': is_multipath,
882              'mr_is_resolve_host': is_resolve_host,
883              'mr_is_resolve_attached': is_resolve_attached,
884              'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
885              'mr_next_hop_weight': next_hop_weight,
886              'mr_next_hop': next_hop_address,
887              'mr_next_hop_n_out_labels': next_hop_n_out_labels,
888              'mr_next_hop_sw_if_index': next_hop_sw_if_index,
889              'mr_next_hop_table_id': next_hop_table_id,
890              'mr_next_hop_via_label': next_hop_via_label,
891              'mr_next_hop_out_label_stack': next_hop_out_label_stack})
892
893     def mpls_ip_bind_unbind(
894             self,
895             label,
896             dst_address,
897             dst_address_length,
898             table_id=0,
899             ip_table_id=0,
900             is_ip4=1,
901             create_vrf_if_needed=0,
902             is_bind=1):
903         """
904         """
905         return self.api(
906             self.papi.mpls_ip_bind_unbind,
907             {'mb_mpls_table_id': table_id,
908              'mb_label': label,
909              'mb_ip_table_id': ip_table_id,
910              'mb_create_table_if_needed': create_vrf_if_needed,
911              'mb_is_bind': is_bind,
912              'mb_is_ip4': is_ip4,
913              'mb_address_length': dst_address_length,
914              'mb_address': dst_address})
915
916     def mpls_tunnel_add_del(
917             self,
918             tun_sw_if_index,
919             next_hop_proto_is_ip4,
920             next_hop_address,
921             next_hop_sw_if_index=0xFFFFFFFF,
922             next_hop_table_id=0,
923             next_hop_weight=1,
924             next_hop_n_out_labels=0,
925             next_hop_out_label_stack=[],
926             next_hop_via_label=MPLS_LABEL_INVALID,
927             create_vrf_if_needed=0,
928             is_add=1,
929             l2_only=0):
930         """
931
932         :param dst_address_length:
933         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
934         :param dst_address:
935         :param next_hop_address:
936         :param next_hop_sw_if_index:  (Default value = 0xFFFFFFFF)
937         :param vrf_id:  (Default value = 0)
938         :param lookup_in_vrf:  (Default value = 0)
939         :param classify_table_index:  (Default value = 0xFFFFFFFF)
940         :param create_vrf_if_needed:  (Default value = 0)
941         :param is_add:  (Default value = 1)
942         :param is_drop:  (Default value = 0)
943         :param is_ipv6:  (Default value = 0)
944         :param is_local:  (Default value = 0)
945         :param is_classify:  (Default value = 0)
946         :param is_multipath:  (Default value = 0)
947         :param is_resolve_host:  (Default value = 0)
948         :param is_resolve_attached:  (Default value = 0)
949         :param not_last:  (Default value = 0)
950         :param next_hop_weight:  (Default value = 1)
951
952         """
953         return self.api(
954             self.papi.mpls_tunnel_add_del,
955             {'mt_sw_if_index': tun_sw_if_index,
956              'mt_is_add': is_add,
957              'mt_l2_only': l2_only,
958              'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4,
959              'mt_next_hop_weight': next_hop_weight,
960              'mt_next_hop': next_hop_address,
961              'mt_next_hop_n_out_labels': next_hop_n_out_labels,
962              'mt_next_hop_sw_if_index': next_hop_sw_if_index,
963              'mt_next_hop_table_id': next_hop_table_id,
964              'mt_next_hop_out_label_stack': next_hop_out_label_stack})
965
966     def snat_interface_add_del_feature(
967             self,
968             sw_if_index,
969             is_inside=1,
970             is_add=1):
971         """Enable/disable S-NAT feature on the interface
972
973         :param sw_if_index: Software index of the interface
974         :param is_inside: 1 if inside, 0 if outside (Default value = 1)
975         :param is_add: 1 if add, 0 if delete (Default value = 1)
976         """
977         return self.api(
978             self.papi.snat_interface_add_del_feature,
979             {'is_add': is_add,
980              'is_inside': is_inside,
981              'sw_if_index': sw_if_index})
982
983     def snat_add_static_mapping(
984             self,
985             local_ip,
986             external_ip=0,
987             external_sw_if_index=0xFFFFFFFF,
988             local_port=0,
989             external_port=0,
990             addr_only=1,
991             vrf_id=0,
992             protocol=0,
993             is_add=1,
994             is_ip4=1):
995         """Add/delete S-NAT static mapping
996
997         :param local_ip: Local IP address
998         :param external_ip: External IP address
999         :param external_sw_if_index: External interface instead of IP address
1000         :param local_port: Local port number (Default value = 0)
1001         :param external_port: External port number (Default value = 0)
1002         :param addr_only: 1 if address only mapping, 0 if address and port
1003         :param vrf_id: VRF ID
1004         :param protocol: IP protocol (Default value = 0)
1005         :param is_add: 1 if add, 0 if delete (Default value = 1)
1006         :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1007         """
1008         return self.api(
1009             self.papi.snat_add_static_mapping,
1010             {'is_add': is_add,
1011              'is_ip4': is_ip4,
1012              'addr_only': addr_only,
1013              'local_ip_address': local_ip,
1014              'external_ip_address': external_ip,
1015              'local_port': local_port,
1016              'external_port': external_port,
1017              'external_sw_if_index': external_sw_if_index,
1018              'vrf_id': vrf_id,
1019              'protocol': protocol})
1020
1021     def snat_add_address_range(
1022             self,
1023             first_ip_address,
1024             last_ip_address,
1025             is_add=1,
1026             is_ip4=1,
1027             vrf_id=0xFFFFFFFF):
1028         """Add/del S-NAT address range
1029
1030         :param first_ip_address: First IP address
1031         :param last_ip_address: Last IP address
1032         :param vrf_id: VRF id for the address range
1033         :param is_add: 1 if add, 0 if delete (Default value = 1)
1034         :param is_ip4: 1 if address type is IPv4 (Default value = 1)
1035         """
1036         return self.api(
1037             self.papi.snat_add_address_range,
1038             {'is_ip4': is_ip4,
1039              'first_ip_address': first_ip_address,
1040              'last_ip_address': last_ip_address,
1041              'vrf_id': vrf_id,
1042              'is_add': is_add})
1043
1044     def snat_address_dump(self):
1045         """Dump S-NAT addresses
1046         :return: Dictionary of S-NAT addresses
1047         """
1048         return self.api(self.papi.snat_address_dump, {})
1049
1050     def snat_interface_dump(self):
1051         """Dump interfaces with S-NAT feature
1052         :return: Dictionary of interfaces with S-NAT feature
1053         """
1054         return self.api(self.papi.snat_interface_dump, {})
1055
1056     def snat_static_mapping_dump(self):
1057         """Dump S-NAT static mappings
1058         :return: Dictionary of S-NAT static mappings
1059         """
1060         return self.api(self.papi.snat_static_mapping_dump, {})
1061
1062     def snat_show_config(self):
1063         """Show S-NAT config
1064         :return: S-NAT config parameters
1065         """
1066         return self.api(self.papi.snat_show_config, {})
1067
1068     def snat_add_interface_addr(
1069             self,
1070             sw_if_index,
1071             is_add=1):
1072         """Add/del S-NAT address from interface
1073
1074         :param sw_if_index: Software index of the interface
1075         :param is_add: 1 if add, 0 if delete (Default value = 1)
1076         """
1077         return self.api(self.papi.snat_add_del_interface_addr,
1078                         {'is_add': is_add, 'sw_if_index': sw_if_index})
1079
1080     def snat_interface_addr_dump(self):
1081         """Dump S-NAT addresses interfaces
1082         :return: Dictionary of S-NAT addresses interfaces
1083         """
1084         return self.api(self.papi.snat_interface_addr_dump, {})
1085
1086     def snat_ipfix(
1087             self,
1088             domain_id=1,
1089             src_port=4739,
1090             enable=1):
1091         """Enable/disable S-NAT IPFIX logging
1092
1093         :param domain_id: Observation domain ID (Default value = 1)
1094         :param src_port: Source port number (Default value = 4739)
1095         :param enable: 1 if enable, 0 if disable (Default value = 1)
1096         """
1097         return self.api(
1098             self.papi.snat_ipfix_enable_disable,
1099             {'domain_id': domain_id,
1100              'src_port': src_port,
1101              'enable': enable})
1102
1103     def snat_user_session_dump(
1104             self,
1105             ip_address,
1106             vrf_id):
1107         """Dump S-NAT user's sessions
1108
1109         :param ip_address: ip adress of the user to be dumped
1110         :param cpu_index: cpu_index on which the user is
1111         :param vrf_id: VRF ID
1112         :return: Dictionary of S-NAT sessions
1113         """
1114         return self.api(
1115             self.papi.snat_user_session_dump,
1116             {'ip_address': ip_address,
1117              'vrf_id': vrf_id})
1118
1119     def snat_user_dump(self):
1120         """Dump S-NAT users
1121
1122         :return: Dictionary of S-NAT users
1123         """
1124         return self.api(self.papi.snat_user_dump, {})
1125
1126     def snat_add_det_map(
1127             self,
1128             in_addr,
1129             in_plen,
1130             out_addr,
1131             out_plen,
1132             is_add=1):
1133         """Add/delete S-NAT deterministic mapping
1134
1135         :param is_add - 1 if add, 0 if delete
1136         :param in_addr - inside IP address
1137         :param in_plen - inside IP address prefix length
1138         :param out_addr - outside IP address
1139         :param out_plen - outside IP address prefix length
1140         """
1141         return self.api(
1142             self.papi.snat_add_det_map,
1143             {'is_add': is_add,
1144              'in_addr': in_addr,
1145              'in_plen': in_plen,
1146              'out_addr': out_addr,
1147              'out_plen': out_plen})
1148
1149     def snat_det_forward(
1150             self,
1151             in_addr):
1152         """Get outside address and port range from inside address
1153
1154         :param in_addr - inside IP address
1155         """
1156         return self.api(
1157             self.papi.snat_det_forward,
1158             {'in_addr': in_addr})
1159
1160     def snat_det_reverse(
1161             self,
1162             out_addr,
1163             out_port):
1164         """Get inside address from outside address and port
1165
1166         :param out_addr - outside IP address
1167         :param out_port - outside port
1168         """
1169         return self.api(
1170             self.papi.snat_det_reverse,
1171             {'out_addr': out_addr,
1172              'out_port': out_port})
1173
1174     def control_ping(self):
1175         self.api(self.papi.control_ping)
1176
1177     def bfd_udp_add(self, sw_if_index, desired_min_tx, required_min_rx,
1178                     detect_mult, local_addr, peer_addr, is_ipv6=0,
1179                     bfd_key_id=None, conf_key_id=None):
1180         if bfd_key_id is None:
1181             return self.api(self.papi.bfd_udp_add,
1182                             {
1183                                 'sw_if_index': sw_if_index,
1184                                 'desired_min_tx': desired_min_tx,
1185                                 'required_min_rx': required_min_rx,
1186                                 'local_addr': local_addr,
1187                                 'peer_addr': peer_addr,
1188                                 'is_ipv6': is_ipv6,
1189                                 'detect_mult': detect_mult,
1190                             })
1191         else:
1192             return self.api(self.papi.bfd_udp_add,
1193                             {
1194                                 'sw_if_index': sw_if_index,
1195                                 'desired_min_tx': desired_min_tx,
1196                                 'required_min_rx': required_min_rx,
1197                                 'local_addr': local_addr,
1198                                 'peer_addr': peer_addr,
1199                                 'is_ipv6': is_ipv6,
1200                                 'detect_mult': detect_mult,
1201                                 'is_authenticated': 1,
1202                                 'bfd_key_id': bfd_key_id,
1203                                 'conf_key_id': conf_key_id,
1204                             })
1205
1206     def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx,
1207                     detect_mult, local_addr, peer_addr, is_ipv6=0):
1208         return self.api(self.papi.bfd_udp_mod,
1209                         {
1210                             'sw_if_index': sw_if_index,
1211                             'desired_min_tx': desired_min_tx,
1212                             'required_min_rx': required_min_rx,
1213                             'local_addr': local_addr,
1214                             'peer_addr': peer_addr,
1215                             'is_ipv6': is_ipv6,
1216                             'detect_mult': detect_mult,
1217                         })
1218
1219     def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr,
1220                               is_ipv6=0, bfd_key_id=None, conf_key_id=None,
1221                               is_delayed=False):
1222         return self.api(self.papi.bfd_udp_auth_activate,
1223                         {
1224                             'sw_if_index': sw_if_index,
1225                             'local_addr': local_addr,
1226                             'peer_addr': peer_addr,
1227                             'is_ipv6': is_ipv6,
1228                             'is_delayed': 1 if is_delayed else 0,
1229                             'bfd_key_id': bfd_key_id,
1230                             'conf_key_id': conf_key_id,
1231                         })
1232
1233     def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr,
1234                                 is_ipv6=0, is_delayed=False):
1235         return self.api(self.papi.bfd_udp_auth_deactivate,
1236                         {
1237                             'sw_if_index': sw_if_index,
1238                             'local_addr': local_addr,
1239                             'peer_addr': peer_addr,
1240                             'is_ipv6': is_ipv6,
1241                             'is_delayed': 1 if is_delayed else 0,
1242                         })
1243
1244     def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0):
1245         return self.api(self.papi.bfd_udp_del,
1246                         {
1247                             'sw_if_index': sw_if_index,
1248                             'local_addr': local_addr,
1249                             'peer_addr': peer_addr,
1250                             'is_ipv6': is_ipv6,
1251                         })
1252
1253     def bfd_udp_session_dump(self):
1254         return self.api(self.papi.bfd_udp_session_dump, {})
1255
1256     def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr,
1257                                   peer_addr, is_ipv6=0):
1258         return self.api(self.papi.bfd_udp_session_set_flags, {
1259             'admin_up_down': admin_up_down,
1260             'sw_if_index': sw_if_index,
1261             'local_addr': local_addr,
1262             'peer_addr': peer_addr,
1263             'is_ipv6': is_ipv6,
1264         })
1265
1266     def want_bfd_events(self, enable_disable=1):
1267         return self.api(self.papi.want_bfd_events, {
1268             'enable_disable': enable_disable,
1269             'pid': os.getpid(),
1270         })
1271
1272     def bfd_auth_set_key(self, conf_key_id, auth_type, key):
1273         return self.api(self.papi.bfd_auth_set_key, {
1274             'conf_key_id': conf_key_id,
1275             'auth_type': auth_type,
1276             'key': key,
1277             'key_len': len(key),
1278         })
1279
1280     def bfd_auth_del_key(self, conf_key_id):
1281         return self.api(self.papi.bfd_auth_del_key, {
1282             'conf_key_id': conf_key_id,
1283         })
1284
1285     def bfd_auth_keys_dump(self):
1286         return self.api(self.papi.bfd_auth_keys_dump, {})
1287
1288     def bfd_udp_set_echo_source(self, sw_if_index):
1289         return self.api(self.papi.bfd_udp_set_echo_source,
1290                         {'sw_if_index': sw_if_index})
1291
1292     def bfd_udp_del_echo_source(self):
1293         return self.api(self.papi.bfd_udp_del_echo_source, {})
1294
1295     def classify_add_del_table(
1296             self,
1297             is_add,
1298             mask,
1299             match_n_vectors=1,
1300             table_index=0xFFFFFFFF,
1301             nbuckets=2,
1302             memory_size=2097152,
1303             skip_n_vectors=0,
1304             next_table_index=0xFFFFFFFF,
1305             miss_next_index=0xFFFFFFFF,
1306             current_data_flag=0,
1307             current_data_offset=0):
1308         """
1309         :param is_add:
1310         :param mask:
1311         :param match_n_vectors: (Default value = 1)
1312         :param table_index: (Default value = 0xFFFFFFFF)
1313         :param nbuckets:  (Default value = 2)
1314         :param memory_size:  (Default value = 2097152)
1315         :param skip_n_vectors:  (Default value = 0)
1316         :param next_table_index:  (Default value = 0xFFFFFFFF)
1317         :param miss_next_index:  (Default value = 0xFFFFFFFF)
1318         :param current_data_flag:  (Default value = 0)
1319         :param current_data_offset:  (Default value = 0)
1320         """
1321
1322         return self.api(
1323             self.papi.classify_add_del_table,
1324             {'is_add': is_add,
1325              'table_index': table_index,
1326              'nbuckets': nbuckets,
1327              'memory_size': memory_size,
1328              'skip_n_vectors': skip_n_vectors,
1329              'match_n_vectors': match_n_vectors,
1330              'next_table_index': next_table_index,
1331              'miss_next_index': miss_next_index,
1332              'current_data_flag': current_data_flag,
1333              'current_data_offset': current_data_offset,
1334              'mask': mask})
1335
1336     def classify_add_del_session(
1337             self,
1338             is_add,
1339             table_index,
1340             match,
1341             opaque_index=0xFFFFFFFF,
1342             hit_next_index=0xFFFFFFFF,
1343             advance=0,
1344             action=0,
1345             metadata=0):
1346         """
1347         :param is_add:
1348         :param table_index:
1349         :param match:
1350         :param opaque_index:  (Default value = 0xFFFFFFFF)
1351         :param hit_next_index:  (Default value = 0xFFFFFFFF)
1352         :param advance:  (Default value = 0)
1353         :param action:  (Default value = 0)
1354         :param metadata:  (Default value = 0)
1355         """
1356
1357         return self.api(
1358             self.papi.classify_add_del_session,
1359             {'is_add': is_add,
1360              'table_index': table_index,
1361              'hit_next_index': hit_next_index,
1362              'opaque_index': opaque_index,
1363              'advance': advance,
1364              'action': action,
1365              'metadata': metadata,
1366              'match': match})
1367
1368     def input_acl_set_interface(
1369             self,
1370             is_add,
1371             sw_if_index,
1372             ip4_table_index=0xFFFFFFFF,
1373             ip6_table_index=0xFFFFFFFF,
1374             l2_table_index=0xFFFFFFFF):
1375         """
1376         :param is_add:
1377         :param sw_if_index:
1378         :param ip4_table_index:  (Default value = 0xFFFFFFFF)
1379         :param ip6_table_index:  (Default value = 0xFFFFFFFF)
1380         :param l2_table_index:  (Default value = 0xFFFFFFFF)
1381         """
1382
1383         return self.api(
1384             self.papi.input_acl_set_interface,
1385             {'sw_if_index': sw_if_index,
1386              'ip4_table_index': ip4_table_index,
1387              'ip6_table_index': ip6_table_index,
1388              'l2_table_index': l2_table_index,
1389              'is_add': is_add})
1390
1391     def set_ipfix_exporter(
1392             self,
1393             collector_address,
1394             src_address,
1395             path_mtu,
1396             template_interval,
1397             vrf_id=0,
1398             collector_port=4739,
1399             udp_checksum=0):
1400         return self.api(
1401             self.papi.set_ipfix_exporter,
1402             {
1403                 'collector_address': collector_address,
1404                 'collector_port': collector_port,
1405                 'src_address': src_address,
1406                 'vrf_id': vrf_id,
1407                 'path_mtu': path_mtu,
1408                 'template_interval': template_interval,
1409                 'udp_checksum': udp_checksum,
1410             })
1411
1412     def dhcp_proxy_config(self,
1413                           dhcp_server,
1414                           dhcp_src_address,
1415                           rx_table_id=0,
1416                           server_table_id=0,
1417                           is_add=1,
1418                           is_ipv6=0):
1419         return self.api(
1420             self.papi.dhcp_proxy_config,
1421             {
1422                 'rx_vrf_id': rx_table_id,
1423                 'server_vrf_id': server_table_id,
1424                 'is_ipv6': is_ipv6,
1425                 'is_add': is_add,
1426                 'dhcp_server': dhcp_server,
1427                 'dhcp_src_address': dhcp_src_address,
1428             })
1429
1430     def dhcp_proxy_set_vss(self,
1431                            table_id,
1432                            fib_id,
1433                            oui,
1434                            is_add=1,
1435                            is_ip6=0):
1436         return self.api(
1437             self.papi.dhcp_proxy_set_vss,
1438             {
1439                 'tbl_id': table_id,
1440                 'fib_id': fib_id,
1441                 'is_ipv6': is_ip6,
1442                 'is_add': is_add,
1443                 'oui': oui,
1444             })
1445
1446     def ip_mroute_add_del(self,
1447                           src_address,
1448                           grp_address,
1449                           grp_address_length,
1450                           e_flags,
1451                           next_hop_sw_if_index,
1452                           i_flags,
1453                           table_id=0,
1454                           create_vrf_if_needed=0,
1455                           is_add=1,
1456                           is_ipv6=0,
1457                           is_local=0):
1458         """
1459         """
1460         return self.api(
1461             self.papi.ip_mroute_add_del,
1462             {'next_hop_sw_if_index': next_hop_sw_if_index,
1463              'entry_flags': e_flags,
1464              'itf_flags': i_flags,
1465              'create_vrf_if_needed': create_vrf_if_needed,
1466              'is_add': is_add,
1467              'is_ipv6': is_ipv6,
1468              'is_local': is_local,
1469              'grp_address_length': grp_address_length,
1470              'grp_address': grp_address,
1471              'src_address': src_address})
1472
1473     def mfib_signal_dump(self):
1474         return self.api(self.papi.mfib_signal_dump, {})
1475
1476     def ip_mfib_dump(self):
1477         return self.api(self.papi.ip_mfib_dump, {})
1478
1479     def lisp_enable_disable(self, is_enabled):
1480         return self.api(
1481             self.papi.lisp_enable_disable,
1482             {
1483                 'is_en': is_enabled,
1484             })
1485
1486     def lisp_locator_set(self,
1487                          ls_name,
1488                          is_add=1):
1489         return self.api(
1490             self.papi.lisp_add_del_locator_set,
1491             {
1492                 'is_add': is_add,
1493                 'locator_set_name': ls_name
1494             })
1495
1496     def lisp_locator_set_dump(self):
1497         return self.api(self.papi.lisp_locator_set_dump, {})
1498
1499     def lisp_locator(self,
1500                      ls_name,
1501                      sw_if_index,
1502                      priority=1,
1503                      weight=1,
1504                      is_add=1):
1505         return self.api(
1506             self.papi.lisp_add_del_locator,
1507             {
1508                 'is_add': is_add,
1509                 'locator_set_name': ls_name,
1510                 'sw_if_index': sw_if_index,
1511                 'priority': priority,
1512                 'weight': weight
1513             })
1514
1515     def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0):
1516         return self.api(
1517             self.papi.lisp_locator_dump,
1518             {
1519                 'is_index_set': is_index_set,
1520                 'ls_name': ls_name,
1521                 'ls_index': ls_index,
1522             })
1523
1524     def lisp_local_mapping(self,
1525                            ls_name,
1526                            eid_type,
1527                            eid,
1528                            prefix_len,
1529                            vni=0,
1530                            key_id=0,
1531                            key="",
1532                            is_add=1):
1533         return self.api(
1534             self.papi.lisp_add_del_local_eid,
1535             {
1536                 'locator_set_name': ls_name,
1537                 'is_add': is_add,
1538                 'eid_type': eid_type,
1539                 'eid': eid,
1540                 'prefix_len': prefix_len,
1541                 'vni': vni,
1542                 'key_id': key_id,
1543                 'key': key
1544             })
1545
1546     def lisp_eid_table_dump(self,
1547                             eid_set=0,
1548                             prefix_length=0,
1549                             vni=0,
1550                             eid_type=0,
1551                             eid=None,
1552                             filter_opt=0):
1553         return self.api(
1554             self.papi.lisp_eid_table_dump,
1555             {
1556                 'eid_set': eid_set,
1557                 'prefix_length': prefix_length,
1558                 'vni': vni,
1559                 'eid_type': eid_type,
1560                 'eid': eid,
1561                 'filter': filter_opt,
1562             })
1563
1564     def lisp_remote_mapping(self,
1565                             eid_type,
1566                             eid,
1567                             eid_prefix_len=0,
1568                             vni=0,
1569                             rlocs=None,
1570                             rlocs_num=0,
1571                             is_src_dst=0,
1572                             is_add=1):
1573         return self.api(
1574             self.papi.lisp_add_del_remote_mapping,
1575             {
1576                 'is_add': is_add,
1577                 'eid_type': eid_type,
1578                 'eid': eid,
1579                 'eid_len': eid_prefix_len,
1580                 'rloc_num': rlocs_num,
1581                 'rlocs': rlocs,
1582                 'vni': vni,
1583                 'is_src_dst': is_src_dst,
1584             })
1585
1586     def lisp_adjacency(self,
1587                        leid,
1588                        reid,
1589                        leid_len,
1590                        reid_len,
1591                        eid_type,
1592                        is_add=1,
1593                        vni=0):
1594         return self.api(
1595             self.papi.lisp_add_del_adjacency,
1596             {
1597                 'is_add': is_add,
1598                 'vni': vni,
1599                 'eid_type': eid_type,
1600                 'leid': leid,
1601                 'reid': reid,
1602                 'leid_len': leid_len,
1603                 'reid_len': reid_len,
1604             })
1605
1606     def lisp_adjacencies_get(self, vni=0):
1607         return self.api(
1608             self.papi.lisp_adjacencies_get,
1609             {
1610                 'vni': vni
1611             })