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