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: |
Eyal Bari | 284293a | 2017-06-06 14:18:55 +0300 | [diff] [blame] | 28 | L2_DISABLED = 0 |
| 29 | L2_PUSH_1 = 1 |
| 30 | L2_PUSH_2 = 2 |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 31 | L2_POP_1 = 3 |
Eyal Bari | 284293a | 2017-06-06 14:18:55 +0300 | [diff] [blame] | 32 | L2_POP_2 = 4 |
| 33 | L2_TRANSLATE_1_1 = 5 |
| 34 | L2_TRANSLATE_1_2 = 6 |
| 35 | L2_TRANSLATE_2_1 = 7 |
| 36 | L2_TRANSLATE_2_2 = 8 |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 37 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 38 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 39 | class UnexpectedApiReturnValueError(Exception): |
| 40 | """ exception raised when the API return value is unexpected """ |
| 41 | pass |
| 42 | |
| 43 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 44 | class VppPapiProvider(object): |
| 45 | """VPP-api provider using vpp-papi |
| 46 | |
| 47 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 48 | """ |
| 49 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 50 | _zero, _negative = range(2) |
| 51 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 52 | def __init__(self, name, shm_prefix, test_class): |
Klement Sekera | 277b89c | 2016-10-28 13:20:27 +0200 | [diff] [blame] | 53 | self.hook = Hook("vpp-papi-provider") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 54 | self.name = name |
| 55 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 56 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 57 | self._expect_api_retval = self._zero |
| 58 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 59 | jsonfiles = [] |
| 60 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 61 | install_dir = os.getenv('VPP_TEST_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 62 | for root, dirnames, filenames in os.walk(install_dir): |
| 63 | for filename in fnmatch.filter(filenames, '*.api.json'): |
| 64 | jsonfiles.append(os.path.join(root, filename)) |
| 65 | |
Ole Troan | 3cc4971 | 2017-03-08 12:02:24 +0100 | [diff] [blame] | 66 | self.vpp = VPP(jsonfiles, logger=test_class.logger) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 67 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 68 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 69 | def __enter__(self): |
| 70 | return self |
| 71 | |
| 72 | def expect_negative_api_retval(self): |
| 73 | """ Expect API failure """ |
| 74 | self._expect_stack.append(self._expect_api_retval) |
| 75 | self._expect_api_retval = self._negative |
| 76 | return self |
| 77 | |
| 78 | def expect_zero_api_retval(self): |
| 79 | """ Expect API success """ |
| 80 | self._expect_stack.append(self._expect_api_retval) |
| 81 | self._expect_api_retval = self._zero |
| 82 | return self |
| 83 | |
| 84 | def __exit__(self, exc_type, exc_value, traceback): |
| 85 | self._expect_api_retval = self._expect_stack.pop() |
| 86 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 87 | def register_hook(self, hook): |
| 88 | """Replace hook registration with new hook |
| 89 | |
| 90 | :param hook: |
| 91 | |
| 92 | """ |
| 93 | self.hook = hook |
| 94 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 95 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 96 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 97 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 98 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 99 | return e |
| 100 | |
| 101 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 102 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 103 | if name: |
| 104 | self.test_class.logger.debug("Expecting event within %ss", |
| 105 | timeout) |
| 106 | else: |
| 107 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 108 | name, timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 109 | if self._events: |
| 110 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 111 | limit = time.time() + timeout |
| 112 | while time.time() < limit: |
| 113 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 114 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 115 | if name and type(e).__name__ != name: |
| 116 | raise Exception( |
| 117 | "Unexpected event received: %s, expected: %s" % |
| 118 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 119 | self.test_class.logger.debug("Returning event %s:%s" % |
| 120 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 121 | return e |
| 122 | time.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 123 | raise Exception("Event did not occur within timeout") |
| 124 | |
| 125 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 126 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 127 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 128 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 129 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 130 | self._events.append(event) |
| 131 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 132 | def connect(self): |
| 133 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 134 | self.vpp.connect(self.name, self.shm_prefix) |
| 135 | self.papi = self.vpp.api |
| 136 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 137 | |
| 138 | def disconnect(self): |
| 139 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 140 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 141 | |
| 142 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 143 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 144 | Call the appropriate hooks before and after the API call |
| 145 | |
| 146 | :param api_fn: API function to call |
| 147 | :param api_args: tuple of API function arguments |
| 148 | :param expected_retval: Expected return value (Default value = 0) |
| 149 | :returns: reply from the API |
| 150 | |
| 151 | """ |
| 152 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 153 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 154 | if self._expect_api_retval == self._negative: |
| 155 | if hasattr(reply, 'retval') and reply.retval >= 0: |
| 156 | msg = "API call passed unexpectedly: expected negative "\ |
| 157 | "return value instead of %d in %s" % \ |
| 158 | (reply.retval, repr(reply)) |
| 159 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 160 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 161 | elif self._expect_api_retval == self._zero: |
| 162 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 163 | msg = "API call failed, expected %d return value instead "\ |
| 164 | "of %d in %s" % (expected_retval, reply.retval, |
| 165 | repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 166 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 167 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 168 | else: |
| 169 | raise Exception("Internal error, unexpected value for " |
| 170 | "self._expect_api_retval %s" % |
| 171 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 172 | self.hook.after_api(api_fn.__name__, api_args) |
| 173 | return reply |
| 174 | |
| 175 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 176 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 177 | |
| 178 | :param cli: CLI to execute |
| 179 | :returns: CLI output |
| 180 | |
| 181 | """ |
| 182 | self.hook.before_cli(cli) |
| 183 | cli += '\n' |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 184 | r = self.papi.cli_inband(length=len(cli), cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 185 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 186 | if hasattr(r, 'reply'): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 187 | return r.reply.decode().rstrip('\x00') |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 188 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 189 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 190 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 191 | |
| 192 | :param cli: CLI to execute |
| 193 | :returns: CLI output |
| 194 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 195 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 196 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 197 | def _convert_mac(self, mac): |
| 198 | return int(mac.replace(":", ""), 16) << 16 |
| 199 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 200 | def show_version(self): |
| 201 | """ """ |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 202 | return self.api(self.papi.show_version, {}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 203 | |
| 204 | def pg_create_interface(self, pg_index): |
| 205 | """ |
| 206 | |
| 207 | :param pg_index: |
| 208 | |
| 209 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 210 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 211 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 212 | |
| 213 | def sw_interface_dump(self, filter=None): |
| 214 | """ |
| 215 | |
| 216 | :param filter: (Default value = None) |
| 217 | |
| 218 | """ |
| 219 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 220 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 221 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 222 | args = {} |
| 223 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 224 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 225 | 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] | 226 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 227 | |
| 228 | :param sw_if_index: |
| 229 | :param is_ipv6: |
| 230 | :param table_id: |
| 231 | |
| 232 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 233 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 234 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 235 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 236 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 237 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 238 | is_ipv6=0, is_add=1, del_all=0): |
| 239 | """ |
| 240 | |
| 241 | :param addr: param is_ipv6: (Default value = 0) |
| 242 | :param sw_if_index: |
| 243 | :param addr_len: |
| 244 | :param is_ipv6: (Default value = 0) |
| 245 | :param is_add: (Default value = 1) |
| 246 | :param del_all: (Default value = 0) |
| 247 | |
| 248 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 249 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 250 | {'sw_if_index': sw_if_index, |
| 251 | 'is_add': is_add, |
| 252 | 'is_ipv6': is_ipv6, |
| 253 | 'del_all': del_all, |
| 254 | 'address_length': addr_len, |
| 255 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 256 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 257 | def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index, |
| 258 | is_add=1): |
| 259 | """ Set the Interface to be unnumbered |
| 260 | |
| 261 | :param is_add: (Default value = 1) |
| 262 | :param sw_if_index - interface That will be unnumbered |
| 263 | :param ip_sw_if_index - interface with an IP addres |
| 264 | |
| 265 | """ |
| 266 | return self.api(self.papi.sw_interface_set_unnumbered, |
| 267 | {'sw_if_index': ip_sw_if_index, |
| 268 | 'unnumbered_sw_if_index': sw_if_index, |
| 269 | 'is_add': is_add}) |
| 270 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 271 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 272 | is_enable=1): |
| 273 | """ |
| 274 | Enable/Disable MPLS on the interface |
| 275 | :param sw_if_index: |
| 276 | :param is_enable: (Default value = 1) |
| 277 | |
| 278 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 279 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 280 | {'sw_if_index': sw_if_index, |
| 281 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 282 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 283 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 284 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 285 | {'sw_if_index': sw_if_index, |
| 286 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 287 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 288 | def set_ip_flow_hash(self, |
| 289 | table_id, |
| 290 | src=1, |
| 291 | dst=1, |
| 292 | sport=1, |
| 293 | dport=1, |
| 294 | proto=1, |
| 295 | reverse=0, |
| 296 | is_ip6=0): |
| 297 | return self.api(self.papi.set_ip_flow_hash, |
| 298 | {'vrf_id': table_id, |
| 299 | 'src': src, |
| 300 | 'dst': dst, |
| 301 | 'dport': dport, |
| 302 | 'sport': sport, |
| 303 | 'proto': proto, |
| 304 | 'reverse': reverse, |
| 305 | 'is_ipv6': is_ip6}) |
| 306 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 307 | def ip6_nd_proxy(self, address, sw_if_index, is_del=0): |
| 308 | return self.api(self.papi.ip6nd_proxy_add_del, |
| 309 | {'address': address, |
| 310 | 'sw_if_index': sw_if_index, |
| 311 | 'is_del': is_del}) |
| 312 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 313 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 314 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 315 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 316 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 317 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 318 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 319 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 320 | 'suppress': suppress, |
| 321 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 322 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 323 | def ip6_sw_interface_ra_prefix(self, |
| 324 | sw_if_index, |
| 325 | address, |
| 326 | address_length, |
| 327 | use_default=0, |
| 328 | no_advertise=0, |
| 329 | off_link=0, |
| 330 | no_autoconfig=0, |
| 331 | no_onlink=0, |
| 332 | is_no=0, |
| 333 | val_lifetime=0xffffffff, |
| 334 | pref_lifetime=0xffffffff): |
| 335 | return self.api(self.papi.sw_interface_ip6nd_ra_prefix, |
| 336 | {'sw_if_index': sw_if_index, |
| 337 | 'address': address, |
| 338 | 'address_length': address_length, |
| 339 | 'use_default': use_default, |
| 340 | 'no_advertise': no_advertise, |
| 341 | 'off_link': off_link, |
| 342 | 'no_autoconfig': no_autoconfig, |
| 343 | 'no_onlink': no_onlink, |
| 344 | 'is_no': is_no, |
| 345 | 'val_lifetime': val_lifetime, |
| 346 | 'pref_lifetime': pref_lifetime}) |
| 347 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 348 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 349 | """ |
| 350 | Enable/Disable An interface for IPv6 |
| 351 | """ |
| 352 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 353 | {'sw_if_index': sw_if_index, |
| 354 | 'enable': enable}) |
| 355 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 356 | def vxlan_add_del_tunnel( |
| 357 | self, |
| 358 | src_addr, |
| 359 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 360 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 361 | is_add=1, |
| 362 | is_ipv6=0, |
| 363 | encap_vrf_id=0, |
| 364 | decap_next_index=0xFFFFFFFF, |
| 365 | vni=0): |
| 366 | """ |
| 367 | |
| 368 | :param dst_addr: |
| 369 | :param src_addr: |
| 370 | :param is_add: (Default value = 1) |
| 371 | :param is_ipv6: (Default value = 0) |
| 372 | :param encap_vrf_id: (Default value = 0) |
| 373 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 374 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 375 | :param vni: (Default value = 0) |
| 376 | |
| 377 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 378 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 379 | {'is_add': is_add, |
| 380 | 'is_ipv6': is_ipv6, |
| 381 | 'src_address': src_addr, |
| 382 | 'dst_address': dst_addr, |
| 383 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 384 | 'encap_vrf_id': encap_vrf_id, |
| 385 | 'decap_next_index': decap_next_index, |
| 386 | 'vni': vni}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 387 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 388 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 389 | learn=1, arp_term=0, is_add=1): |
| 390 | """Create/delete bridge domain. |
| 391 | |
| 392 | :param int bd_id: Bridge domain index. |
| 393 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 394 | (Default value = 1) |
| 395 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 396 | (Default value = 1) |
| 397 | :param int forward: Enable/disable forwarding on all interfaces in |
| 398 | the BD. (Default value = 1) |
| 399 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 400 | (Default value = 1) |
| 401 | :param int arp_term: Enable/disable arp termination in the BD. |
| 402 | (Default value = 1) |
| 403 | :param int is_add: Add or delete flag. (Default value = 1) |
| 404 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 405 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 406 | {'bd_id': bd_id, |
| 407 | 'flood': flood, |
| 408 | 'uu_flood': uu_flood, |
| 409 | 'forward': forward, |
| 410 | 'learn': learn, |
| 411 | 'arp_term': arp_term, |
| 412 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 413 | |
Eyal Bari | c86e592 | 2017-07-02 18:33:16 +0300 | [diff] [blame] | 414 | def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1): |
| 415 | return self.api(self.papi.bd_ip_mac_add_del, |
| 416 | {'bd_id': bd_id, |
| 417 | 'is_add': is_add, |
| 418 | 'is_ipv6': is_ipv6, |
| 419 | 'ip_address': ip, |
| 420 | 'mac_address': mac}) |
| 421 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 422 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 423 | filter_mac=0, bvi_mac=0): |
| 424 | """Create/delete L2 FIB entry. |
| 425 | |
| 426 | :param str mac: MAC address to create FIB entry for. |
| 427 | :param int bd_id: Bridge domain index. |
| 428 | :param int sw_if_index: Software interface index of the interface. |
| 429 | :param int is_add: Add or delete flag. (Default value = 1) |
| 430 | :param int static_mac: Set to 1 to create static MAC entry. |
| 431 | (Default value = 0) |
| 432 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 433 | destination MAC address contains defined MAC address. |
| 434 | (Default value = 0) |
| 435 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 436 | interface. (Default value = 0) |
| 437 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 438 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 439 | {'mac': self._convert_mac(mac), |
| 440 | 'bd_id': bd_id, |
| 441 | 'sw_if_index': sw_if_index, |
| 442 | 'is_add': is_add, |
| 443 | 'static_mac': static_mac, |
| 444 | 'filter_mac': filter_mac, |
| 445 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 446 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 447 | def l2fib_flush_int(self, sw_if_index): |
| 448 | """Flush L2 FIB entries for sw_if_index. |
| 449 | |
| 450 | :param int sw_if_index: Software interface index of the interface. |
| 451 | """ |
| 452 | return self.api(self.papi.l2fib_flush_int, |
| 453 | {'sw_if_index': sw_if_index}) |
| 454 | |
| 455 | def l2fib_flush_bd(self, bd_id): |
| 456 | """Flush L2 FIB entries for bd_id. |
| 457 | |
| 458 | :param int sw_if_index: Bridge Domain id. |
| 459 | """ |
| 460 | return self.api(self.papi.l2fib_flush_bd, |
| 461 | {'bd_id': bd_id}) |
| 462 | |
| 463 | def l2fib_flush_all(self): |
| 464 | """Flush all L2 FIB. |
| 465 | """ |
| 466 | return self.api(self.papi.l2fib_flush_all, {}) |
| 467 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 468 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 469 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 470 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 471 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 472 | :param int sw_if_index: Software interface index of the interface. |
| 473 | :param int bd_id: Bridge domain index. |
| 474 | :param int shg: Split-horizon group index. (Default value = 0) |
| 475 | :param int bvi: Set interface as a bridge group virtual interface. |
| 476 | (Default value = 0) |
| 477 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 478 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 479 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 480 | {'rx_sw_if_index': sw_if_index, |
| 481 | 'bd_id': bd_id, |
| 482 | 'shg': shg, |
| 483 | 'bvi': bvi, |
| 484 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 485 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 486 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 487 | """Enable/disable required feature of the bridge domain with defined ID. |
| 488 | |
| 489 | :param int bd_id: Bridge domain ID. |
| 490 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 491 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 492 | - learn (1 << 0), |
| 493 | - forward (1 << 1), |
| 494 | - flood (1 << 2), |
| 495 | - uu-flood (1 << 3) or |
| 496 | - arp-term (1 << 4). |
| 497 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 498 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 499 | {'bd_id': bd_id, |
| 500 | 'is_set': is_set, |
| 501 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 502 | |
| 503 | def bridge_domain_dump(self, bd_id=0): |
| 504 | """ |
| 505 | |
| 506 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 507 | existing bridge domains returned) |
| 508 | :return: Dictionary of bridge domain(s) data. |
| 509 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 510 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 511 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 512 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 513 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 514 | enable): |
| 515 | """Create or delete unidirectional cross-connect from Tx interface to |
| 516 | Rx interface. |
| 517 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 518 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 519 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 520 | :param int enable: Create cross-connect if equal to 1, delete |
| 521 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 522 | |
| 523 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 524 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 525 | {'rx_sw_if_index': rx_sw_if_index, |
| 526 | 'tx_sw_if_index': tx_sw_if_index, |
| 527 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 528 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 529 | def sw_interface_set_l2_tag_rewrite( |
| 530 | self, |
| 531 | sw_if_index, |
| 532 | vtr_oper, |
| 533 | push=0, |
| 534 | tag1=0, |
| 535 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 536 | """L2 interface vlan tag rewrite configure request |
| 537 | :param client_index - opaque cookie to identify the sender |
| 538 | :param context - sender context, to match reply w/ request |
| 539 | :param sw_if_index - interface the operation is applied to |
| 540 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 541 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 542 | :param tag1 - Needed for any push or translate vtr op |
| 543 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 544 | |
| 545 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 546 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 547 | {'sw_if_index': sw_if_index, |
| 548 | 'vtr_op': vtr_oper, |
| 549 | 'push_dot1q': push, |
| 550 | 'tag1': tag1, |
| 551 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 552 | |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 553 | def sw_interface_set_flags(self, sw_if_index, admin_up_down): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 554 | """ |
| 555 | |
| 556 | :param admin_up_down: |
| 557 | :param sw_if_index: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 558 | |
| 559 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 560 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 561 | {'sw_if_index': sw_if_index, |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 562 | 'admin_up_down': admin_up_down}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 563 | |
| 564 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 565 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 566 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 567 | """Create subinterface |
| 568 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 569 | |
| 570 | :param sub_id: param inner_vlan: |
| 571 | :param sw_if_index: |
| 572 | :param outer_vlan: |
| 573 | :param inner_vlan: |
| 574 | :param no_tags: (Default value = 0) |
| 575 | :param one_tag: (Default value = 0) |
| 576 | :param two_tags: (Default value = 0) |
| 577 | :param dot1ad: (Default value = 0) |
| 578 | :param exact_match: (Default value = 0) |
| 579 | :param default_sub: (Default value = 0) |
| 580 | :param outer_vlan_id_any: (Default value = 0) |
| 581 | :param inner_vlan_id_any: (Default value = 0) |
| 582 | |
| 583 | """ |
| 584 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 585 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 586 | {'sw_if_index': sw_if_index, |
| 587 | 'sub_id': sub_id, |
| 588 | 'no_tags': no_tags, |
| 589 | 'one_tag': one_tag, |
| 590 | 'two_tags': two_tags, |
| 591 | 'dot1ad': dot1ad, |
| 592 | 'exact_match': exact_match, |
| 593 | 'default_sub': default_sub, |
| 594 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 595 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 596 | 'outer_vlan_id': outer_vlan, |
| 597 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 598 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 599 | def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id): |
| 600 | """Create p2p ethernet subinterface |
| 601 | |
| 602 | :param sw_if_index: main (parent) interface |
| 603 | :param remote_mac: client (remote) mac address |
| 604 | |
| 605 | """ |
| 606 | return self.api( |
| 607 | self.papi.p2p_ethernet_add, |
| 608 | {'parent_if_index': sw_if_index, |
| 609 | 'remote_mac': remote_mac, |
| 610 | 'subif_id': subif_id}) |
| 611 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 612 | def delete_subif(self, sw_if_index): |
| 613 | """Delete subinterface |
| 614 | |
| 615 | :param sw_if_index: |
| 616 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 617 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 618 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 619 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 620 | def delete_p2pethernet_subif(self, sw_if_index, remote_mac): |
| 621 | """Delete p2p ethernet subinterface |
| 622 | |
| 623 | :param sw_if_index: main (parent) interface |
| 624 | :param remote_mac: client (remote) mac address |
| 625 | |
| 626 | """ |
| 627 | return self.api( |
| 628 | self.papi.p2p_ethernet_del, |
| 629 | {'parent_if_index': sw_if_index, |
| 630 | 'remote_mac': remote_mac}) |
| 631 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 632 | def create_vlan_subif(self, sw_if_index, vlan): |
| 633 | """ |
| 634 | |
| 635 | :param vlan: |
| 636 | :param sw_if_index: |
| 637 | |
| 638 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 639 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 640 | {'sw_if_index': sw_if_index, |
| 641 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 642 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 643 | def create_loopback(self, mac=''): |
| 644 | """ |
| 645 | |
| 646 | :param mac: (Optional) |
| 647 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 648 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 649 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 650 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 651 | def delete_loopback(self, sw_if_index): |
| 652 | return self.api(self.papi.delete_loopback, |
| 653 | {'sw_if_index': sw_if_index, }) |
| 654 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 655 | def ip_add_del_route( |
| 656 | self, |
| 657 | dst_address, |
| 658 | dst_address_length, |
| 659 | next_hop_address, |
| 660 | next_hop_sw_if_index=0xFFFFFFFF, |
| 661 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 662 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 663 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 664 | next_hop_n_out_labels=0, |
| 665 | next_hop_out_label_stack=[], |
| 666 | next_hop_via_label=MPLS_LABEL_INVALID, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 667 | create_vrf_if_needed=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 668 | is_resolve_host=0, |
| 669 | is_resolve_attached=0, |
| 670 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 671 | is_add=1, |
| 672 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 673 | is_unreach=0, |
| 674 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 675 | is_ipv6=0, |
| 676 | is_local=0, |
| 677 | is_classify=0, |
| 678 | is_multipath=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 679 | not_last=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 680 | """ |
| 681 | |
| 682 | :param dst_address_length: |
| 683 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 684 | :param dst_address: |
| 685 | :param next_hop_address: |
| 686 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 687 | :param vrf_id: (Default value = 0) |
| 688 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 689 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 690 | :param create_vrf_if_needed: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 691 | :param is_add: (Default value = 1) |
| 692 | :param is_drop: (Default value = 0) |
| 693 | :param is_ipv6: (Default value = 0) |
| 694 | :param is_local: (Default value = 0) |
| 695 | :param is_classify: (Default value = 0) |
| 696 | :param is_multipath: (Default value = 0) |
| 697 | :param is_resolve_host: (Default value = 0) |
| 698 | :param is_resolve_attached: (Default value = 0) |
| 699 | :param not_last: (Default value = 0) |
| 700 | :param next_hop_weight: (Default value = 1) |
| 701 | |
| 702 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 703 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 704 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 705 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 706 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 707 | 'table_id': table_id, |
| 708 | 'classify_table_index': classify_table_index, |
| 709 | 'next_hop_table_id': next_hop_table_id, |
| 710 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 711 | 'is_add': is_add, |
| 712 | 'is_drop': is_drop, |
| 713 | 'is_unreach': is_unreach, |
| 714 | 'is_prohibit': is_prohibit, |
| 715 | 'is_ipv6': is_ipv6, |
| 716 | 'is_local': is_local, |
| 717 | 'is_classify': is_classify, |
| 718 | 'is_multipath': is_multipath, |
| 719 | 'is_resolve_host': is_resolve_host, |
| 720 | 'is_resolve_attached': is_resolve_attached, |
| 721 | 'not_last': not_last, |
| 722 | 'next_hop_weight': next_hop_weight, |
| 723 | 'dst_address_length': dst_address_length, |
| 724 | 'dst_address': dst_address, |
| 725 | 'next_hop_address': next_hop_address, |
| 726 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 727 | 'next_hop_via_label': next_hop_via_label, |
| 728 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 729 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 730 | def ip_fib_dump(self): |
| 731 | return self.api(self.papi.ip_fib_dump, {}) |
| 732 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 733 | def ip6_fib_dump(self): |
| 734 | return self.api(self.papi.ip6_fib_dump, {}) |
| 735 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 736 | def ip_neighbor_add_del(self, |
| 737 | sw_if_index, |
| 738 | mac_address, |
| 739 | dst_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 740 | is_add=1, |
| 741 | is_ipv6=0, |
| 742 | is_static=0, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 743 | is_no_adj_fib=0, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 744 | ): |
| 745 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 746 | |
| 747 | :param sw_if_index: |
| 748 | :param mac_address: |
| 749 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 750 | :param is_add: (Default value = 1) |
| 751 | :param is_ipv6: (Default value = 0) |
| 752 | :param is_static: (Default value = 0) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 753 | :param is_no_adj_fib: (Default value = 0) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 754 | """ |
| 755 | |
| 756 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 757 | self.papi.ip_neighbor_add_del, |
Neale Ranns | baf2e90 | 2017-02-25 04:20:00 -0800 | [diff] [blame] | 758 | {'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 759 | 'is_add': is_add, |
| 760 | 'is_ipv6': is_ipv6, |
| 761 | 'is_static': is_static, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 762 | 'is_no_adj_fib': is_no_adj_fib, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 763 | 'mac_address': mac_address, |
| 764 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 765 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 766 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 767 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 768 | def ip_neighbor_dump(self, |
| 769 | sw_if_index, |
| 770 | is_ipv6=0): |
| 771 | """ Return IP neighbor dump. |
| 772 | |
| 773 | :param sw_if_index: |
| 774 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 775 | """ |
| 776 | |
| 777 | return self.api( |
| 778 | self.papi.ip_neighbor_dump, |
| 779 | {'is_ipv6': is_ipv6, |
| 780 | 'sw_if_index': sw_if_index |
| 781 | } |
| 782 | ) |
| 783 | |
| 784 | def proxy_arp_add_del(self, |
| 785 | low_address, |
| 786 | hi_address, |
| 787 | vrf_id=0, |
| 788 | is_add=1): |
| 789 | """ Config Proxy Arp Range. |
| 790 | |
| 791 | :param low_address: Start address in the rnage to Proxy for |
| 792 | :param hi_address: End address in the rnage to Proxy for |
| 793 | :param vrf_id: The VRF/table in which to proxy |
| 794 | """ |
| 795 | |
| 796 | return self.api( |
| 797 | self.papi.proxy_arp_add_del, |
| 798 | {'vrf_id': vrf_id, |
| 799 | 'is_add': is_add, |
| 800 | 'low_address': low_address, |
| 801 | 'hi_address': hi_address, |
| 802 | } |
| 803 | ) |
| 804 | |
| 805 | def proxy_arp_intfc_enable_disable(self, |
| 806 | sw_if_index, |
| 807 | is_enable=1): |
| 808 | """ Enable/Disable an interface for proxy ARP requests |
| 809 | |
| 810 | :param sw_if_index: Interface |
| 811 | :param enable_disable: Enable/Disable |
| 812 | """ |
| 813 | |
| 814 | return self.api( |
| 815 | self.papi.proxy_arp_intfc_enable_disable, |
| 816 | {'sw_if_index': sw_if_index, |
| 817 | 'enable_disable': is_enable |
| 818 | } |
| 819 | ) |
| 820 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 821 | def reset_vrf(self, |
| 822 | vrf_id, |
| 823 | is_ipv6=0, |
| 824 | ): |
| 825 | """ Reset VRF (remove all routes etc.) request. |
| 826 | |
| 827 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 828 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 829 | """ |
| 830 | |
| 831 | return self.api( |
| 832 | self.papi.reset_vrf, |
| 833 | {'vrf_id': vrf_id, |
| 834 | 'is_ipv6': is_ipv6, |
| 835 | } |
| 836 | ) |
| 837 | |
| 838 | def reset_fib(self, |
| 839 | vrf_id, |
| 840 | is_ipv6=0, |
| 841 | ): |
| 842 | """ Reset VRF (remove all routes etc.) request. |
| 843 | |
| 844 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 845 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 846 | """ |
| 847 | |
| 848 | return self.api( |
| 849 | self.papi.reset_fib, |
| 850 | {'vrf_id': vrf_id, |
| 851 | 'is_ipv6': is_ipv6, |
| 852 | } |
| 853 | ) |
| 854 | |
| 855 | def ip_dump(self, |
| 856 | is_ipv6=0, |
| 857 | ): |
| 858 | """ Return IP dump. |
| 859 | |
| 860 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 861 | """ |
| 862 | |
| 863 | return self.api( |
| 864 | self.papi.ip_dump, |
| 865 | {'is_ipv6': is_ipv6, |
| 866 | } |
| 867 | ) |
| 868 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 869 | def sw_interface_span_enable_disable( |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 870 | self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 871 | """ |
| 872 | |
| 873 | :param sw_if_index_from: |
| 874 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 875 | :param state: |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 876 | :param is_l2: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 877 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 878 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 879 | {'sw_if_index_from': sw_if_index_from, |
| 880 | 'sw_if_index_to': sw_if_index_to, |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 881 | 'state': state, |
| 882 | 'is_l2': is_l2, |
| 883 | }) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 884 | |
| 885 | def gre_tunnel_add_del(self, |
| 886 | src_address, |
| 887 | dst_address, |
| 888 | outer_fib_id=0, |
| 889 | is_teb=0, |
| 890 | is_add=1, |
| 891 | is_ip6=0): |
| 892 | """ Add a GRE tunnel |
| 893 | |
| 894 | :param src_address: |
| 895 | :param dst_address: |
| 896 | :param outer_fib_id: (Default value = 0) |
| 897 | :param is_add: (Default value = 1) |
| 898 | :param is_ipv6: (Default value = 0) |
| 899 | :param is_teb: (Default value = 0) |
| 900 | """ |
| 901 | |
| 902 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 903 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 904 | {'is_add': is_add, |
| 905 | 'is_ipv6': is_ip6, |
| 906 | 'teb': is_teb, |
| 907 | 'src_address': src_address, |
| 908 | 'dst_address': dst_address, |
| 909 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 910 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 911 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 912 | def mpls_fib_dump(self): |
| 913 | return self.api(self.papi.mpls_fib_dump, {}) |
| 914 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 915 | def mpls_route_add_del( |
| 916 | self, |
| 917 | label, |
| 918 | eos, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 919 | next_hop_proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 920 | next_hop_address, |
| 921 | next_hop_sw_if_index=0xFFFFFFFF, |
| 922 | table_id=0, |
| 923 | next_hop_table_id=0, |
| 924 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 925 | next_hop_n_out_labels=0, |
| 926 | next_hop_out_label_stack=[], |
| 927 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 928 | create_vrf_if_needed=0, |
| 929 | is_resolve_host=0, |
| 930 | is_resolve_attached=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 931 | is_interface_rx=0, |
| 932 | is_rpf_id=0, |
| 933 | is_multicast=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 934 | is_add=1, |
| 935 | is_drop=0, |
| 936 | is_multipath=0, |
| 937 | classify_table_index=0xFFFFFFFF, |
| 938 | is_classify=0, |
| 939 | not_last=0): |
| 940 | """ |
| 941 | |
| 942 | :param dst_address_length: |
| 943 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 944 | :param dst_address: |
| 945 | :param next_hop_address: |
| 946 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 947 | :param vrf_id: (Default value = 0) |
| 948 | :param lookup_in_vrf: (Default value = 0) |
| 949 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 950 | :param create_vrf_if_needed: (Default value = 0) |
| 951 | :param is_add: (Default value = 1) |
| 952 | :param is_drop: (Default value = 0) |
| 953 | :param is_ipv6: (Default value = 0) |
| 954 | :param is_local: (Default value = 0) |
| 955 | :param is_classify: (Default value = 0) |
| 956 | :param is_multipath: (Default value = 0) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 957 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 958 | :param is_resolve_host: (Default value = 0) |
| 959 | :param is_resolve_attached: (Default value = 0) |
| 960 | :param not_last: (Default value = 0) |
| 961 | :param next_hop_weight: (Default value = 1) |
| 962 | |
| 963 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 964 | |
| 965 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 966 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 967 | {'mr_label': label, |
| 968 | 'mr_eos': eos, |
| 969 | 'mr_table_id': table_id, |
| 970 | 'mr_classify_table_index': classify_table_index, |
| 971 | 'mr_create_table_if_needed': create_vrf_if_needed, |
| 972 | 'mr_is_add': is_add, |
| 973 | 'mr_is_classify': is_classify, |
| 974 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 975 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 976 | 'mr_is_resolve_host': is_resolve_host, |
| 977 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 978 | 'mr_is_interface_rx': is_interface_rx, |
| 979 | 'mr_is_rpf_id': is_rpf_id, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 980 | 'mr_next_hop_proto': next_hop_proto, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 981 | 'mr_next_hop_weight': next_hop_weight, |
| 982 | 'mr_next_hop': next_hop_address, |
| 983 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 984 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 985 | 'mr_next_hop_table_id': next_hop_table_id, |
| 986 | 'mr_next_hop_via_label': next_hop_via_label, |
| 987 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 988 | |
| 989 | def mpls_ip_bind_unbind( |
| 990 | self, |
| 991 | label, |
| 992 | dst_address, |
| 993 | dst_address_length, |
| 994 | table_id=0, |
| 995 | ip_table_id=0, |
| 996 | is_ip4=1, |
| 997 | create_vrf_if_needed=0, |
| 998 | is_bind=1): |
| 999 | """ |
| 1000 | """ |
| 1001 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1002 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1003 | {'mb_mpls_table_id': table_id, |
| 1004 | 'mb_label': label, |
| 1005 | 'mb_ip_table_id': ip_table_id, |
| 1006 | 'mb_create_table_if_needed': create_vrf_if_needed, |
| 1007 | 'mb_is_bind': is_bind, |
| 1008 | 'mb_is_ip4': is_ip4, |
| 1009 | 'mb_address_length': dst_address_length, |
| 1010 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1011 | |
| 1012 | def mpls_tunnel_add_del( |
| 1013 | self, |
| 1014 | tun_sw_if_index, |
| 1015 | next_hop_proto_is_ip4, |
| 1016 | next_hop_address, |
| 1017 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1018 | next_hop_table_id=0, |
| 1019 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1020 | next_hop_n_out_labels=0, |
| 1021 | next_hop_out_label_stack=[], |
| 1022 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1023 | create_vrf_if_needed=0, |
| 1024 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1025 | l2_only=0, |
| 1026 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1027 | """ |
| 1028 | |
| 1029 | :param dst_address_length: |
| 1030 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1031 | :param dst_address: |
| 1032 | :param next_hop_address: |
| 1033 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1034 | :param vrf_id: (Default value = 0) |
| 1035 | :param lookup_in_vrf: (Default value = 0) |
| 1036 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 1037 | :param create_vrf_if_needed: (Default value = 0) |
| 1038 | :param is_add: (Default value = 1) |
| 1039 | :param is_drop: (Default value = 0) |
| 1040 | :param is_ipv6: (Default value = 0) |
| 1041 | :param is_local: (Default value = 0) |
| 1042 | :param is_classify: (Default value = 0) |
| 1043 | :param is_multipath: (Default value = 0) |
| 1044 | :param is_resolve_host: (Default value = 0) |
| 1045 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1046 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1047 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1048 | |
| 1049 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1050 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1051 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1052 | {'mt_sw_if_index': tun_sw_if_index, |
| 1053 | 'mt_is_add': is_add, |
| 1054 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1055 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1056 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 1057 | 'mt_next_hop_weight': next_hop_weight, |
| 1058 | 'mt_next_hop': next_hop_address, |
| 1059 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1060 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1061 | 'mt_next_hop_table_id': next_hop_table_id, |
| 1062 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1063 | |
| 1064 | def snat_interface_add_del_feature( |
| 1065 | self, |
| 1066 | sw_if_index, |
| 1067 | is_inside=1, |
| 1068 | is_add=1): |
| 1069 | """Enable/disable S-NAT feature on the interface |
| 1070 | |
| 1071 | :param sw_if_index: Software index of the interface |
| 1072 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1073 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1074 | """ |
| 1075 | return self.api( |
| 1076 | self.papi.snat_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1077 | {'is_add': is_add, |
| 1078 | 'is_inside': is_inside, |
| 1079 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1080 | |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1081 | def snat_interface_add_del_output_feature( |
| 1082 | self, |
| 1083 | sw_if_index, |
| 1084 | is_inside=1, |
| 1085 | is_add=1): |
| 1086 | """Enable/disable S-NAT output feature on the interface |
| 1087 | |
| 1088 | :param sw_if_index: Software index of the interface |
| 1089 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1090 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1091 | """ |
| 1092 | return self.api( |
| 1093 | self.papi.snat_interface_add_del_output_feature, |
| 1094 | {'is_add': is_add, |
| 1095 | 'is_inside': is_inside, |
| 1096 | 'sw_if_index': sw_if_index}) |
| 1097 | |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1098 | def snat_add_static_mapping( |
| 1099 | self, |
| 1100 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1101 | external_ip=0, |
| 1102 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1103 | local_port=0, |
| 1104 | external_port=0, |
| 1105 | addr_only=1, |
| 1106 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1107 | protocol=0, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1108 | is_add=1, |
| 1109 | is_ip4=1): |
| 1110 | """Add/delete S-NAT static mapping |
| 1111 | |
| 1112 | :param local_ip: Local IP address |
| 1113 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1114 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1115 | :param local_port: Local port number (Default value = 0) |
| 1116 | :param external_port: External port number (Default value = 0) |
| 1117 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1118 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1119 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1120 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1121 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1122 | """ |
| 1123 | return self.api( |
| 1124 | self.papi.snat_add_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1125 | {'is_add': is_add, |
| 1126 | 'is_ip4': is_ip4, |
| 1127 | 'addr_only': addr_only, |
| 1128 | 'local_ip_address': local_ip, |
| 1129 | 'external_ip_address': external_ip, |
| 1130 | 'local_port': local_port, |
| 1131 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1132 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1133 | 'vrf_id': vrf_id, |
| 1134 | 'protocol': protocol}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1135 | |
| 1136 | def snat_add_address_range( |
| 1137 | self, |
| 1138 | first_ip_address, |
| 1139 | last_ip_address, |
| 1140 | is_add=1, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1141 | is_ip4=1, |
| 1142 | vrf_id=0xFFFFFFFF): |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1143 | """Add/del S-NAT address range |
| 1144 | |
| 1145 | :param first_ip_address: First IP address |
| 1146 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1147 | :param vrf_id: VRF id for the address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1148 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1149 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1150 | """ |
| 1151 | return self.api( |
| 1152 | self.papi.snat_add_address_range, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1153 | {'is_ip4': is_ip4, |
| 1154 | 'first_ip_address': first_ip_address, |
| 1155 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1156 | 'vrf_id': vrf_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1157 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1158 | |
| 1159 | def snat_address_dump(self): |
| 1160 | """Dump S-NAT addresses |
| 1161 | :return: Dictionary of S-NAT addresses |
| 1162 | """ |
| 1163 | return self.api(self.papi.snat_address_dump, {}) |
| 1164 | |
| 1165 | def snat_interface_dump(self): |
| 1166 | """Dump interfaces with S-NAT feature |
| 1167 | :return: Dictionary of interfaces with S-NAT feature |
| 1168 | """ |
| 1169 | return self.api(self.papi.snat_interface_dump, {}) |
| 1170 | |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1171 | def snat_interface_output_feature_dump(self): |
| 1172 | """Dump interfaces with S-NAT output feature |
| 1173 | :return: Dictionary of interfaces with S-NAT output feature |
| 1174 | """ |
| 1175 | return self.api(self.papi.snat_interface_output_feature_dump, {}) |
| 1176 | |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1177 | def snat_static_mapping_dump(self): |
| 1178 | """Dump S-NAT static mappings |
| 1179 | :return: Dictionary of S-NAT static mappings |
| 1180 | """ |
| 1181 | return self.api(self.papi.snat_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1182 | |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1183 | def snat_show_config(self): |
| 1184 | """Show S-NAT config |
| 1185 | :return: S-NAT config parameters |
| 1186 | """ |
| 1187 | return self.api(self.papi.snat_show_config, {}) |
| 1188 | |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1189 | def snat_add_interface_addr( |
| 1190 | self, |
| 1191 | sw_if_index, |
| 1192 | is_add=1): |
| 1193 | """Add/del S-NAT address from interface |
| 1194 | |
| 1195 | :param sw_if_index: Software index of the interface |
| 1196 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1197 | """ |
| 1198 | return self.api(self.papi.snat_add_del_interface_addr, |
| 1199 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1200 | |
| 1201 | def snat_interface_addr_dump(self): |
| 1202 | """Dump S-NAT addresses interfaces |
| 1203 | :return: Dictionary of S-NAT addresses interfaces |
| 1204 | """ |
| 1205 | return self.api(self.papi.snat_interface_addr_dump, {}) |
| 1206 | |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1207 | def snat_ipfix( |
| 1208 | self, |
| 1209 | domain_id=1, |
| 1210 | src_port=4739, |
| 1211 | enable=1): |
| 1212 | """Enable/disable S-NAT IPFIX logging |
| 1213 | |
| 1214 | :param domain_id: Observation domain ID (Default value = 1) |
| 1215 | :param src_port: Source port number (Default value = 4739) |
| 1216 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1217 | """ |
| 1218 | return self.api( |
| 1219 | self.papi.snat_ipfix_enable_disable, |
| 1220 | {'domain_id': domain_id, |
| 1221 | 'src_port': src_port, |
| 1222 | 'enable': enable}) |
| 1223 | |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1224 | def snat_user_session_dump( |
| 1225 | self, |
| 1226 | ip_address, |
Martin | 6b7fcda | 2017-03-08 03:31:02 -0800 | [diff] [blame] | 1227 | vrf_id, |
| 1228 | is_ip4=1): |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1229 | """Dump S-NAT user's sessions |
| 1230 | |
| 1231 | :param ip_address: ip adress of the user to be dumped |
| 1232 | :param cpu_index: cpu_index on which the user is |
| 1233 | :param vrf_id: VRF ID |
| 1234 | :return: Dictionary of S-NAT sessions |
| 1235 | """ |
| 1236 | return self.api( |
| 1237 | self.papi.snat_user_session_dump, |
| 1238 | {'ip_address': ip_address, |
Martin | 6b7fcda | 2017-03-08 03:31:02 -0800 | [diff] [blame] | 1239 | 'vrf_id': vrf_id, |
| 1240 | 'is_ip4': is_ip4}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1241 | |
| 1242 | def snat_user_dump(self): |
| 1243 | """Dump S-NAT users |
| 1244 | |
| 1245 | :return: Dictionary of S-NAT users |
| 1246 | """ |
| 1247 | return self.api(self.papi.snat_user_dump, {}) |
| 1248 | |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1249 | def snat_add_det_map( |
| 1250 | self, |
| 1251 | in_addr, |
| 1252 | in_plen, |
| 1253 | out_addr, |
| 1254 | out_plen, |
| 1255 | is_add=1): |
| 1256 | """Add/delete S-NAT deterministic mapping |
| 1257 | |
| 1258 | :param is_add - 1 if add, 0 if delete |
| 1259 | :param in_addr - inside IP address |
| 1260 | :param in_plen - inside IP address prefix length |
| 1261 | :param out_addr - outside IP address |
| 1262 | :param out_plen - outside IP address prefix length |
| 1263 | """ |
| 1264 | return self.api( |
| 1265 | self.papi.snat_add_det_map, |
| 1266 | {'is_add': is_add, |
| 1267 | 'in_addr': in_addr, |
| 1268 | 'in_plen': in_plen, |
| 1269 | 'out_addr': out_addr, |
| 1270 | 'out_plen': out_plen}) |
| 1271 | |
| 1272 | def snat_det_forward( |
| 1273 | self, |
| 1274 | in_addr): |
| 1275 | """Get outside address and port range from inside address |
| 1276 | |
| 1277 | :param in_addr - inside IP address |
| 1278 | """ |
| 1279 | return self.api( |
| 1280 | self.papi.snat_det_forward, |
| 1281 | {'in_addr': in_addr}) |
| 1282 | |
| 1283 | def snat_det_reverse( |
| 1284 | self, |
| 1285 | out_addr, |
| 1286 | out_port): |
| 1287 | """Get inside address from outside address and port |
| 1288 | |
| 1289 | :param out_addr - outside IP address |
| 1290 | :param out_port - outside port |
| 1291 | """ |
| 1292 | return self.api( |
| 1293 | self.papi.snat_det_reverse, |
| 1294 | {'out_addr': out_addr, |
| 1295 | 'out_port': out_port}) |
| 1296 | |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1297 | def snat_det_map_dump(self): |
| 1298 | """Dump S-NAT deterministic mappings |
| 1299 | |
| 1300 | :return: Dictionary of S-NAT deterministic mappings |
| 1301 | """ |
| 1302 | return self.api(self.papi.snat_det_map_dump, {}) |
| 1303 | |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1304 | def snat_det_set_timeouts( |
| 1305 | self, |
| 1306 | udp=300, |
| 1307 | tcp_established=7440, |
| 1308 | tcp_transitory=240, |
| 1309 | icmp=60): |
| 1310 | """Set values of timeouts for deterministic NAT (in seconds) |
| 1311 | |
| 1312 | :param udp - UDP timeout (Default value = 300) |
| 1313 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1314 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1315 | :param icmp - ICMP timeout (Default value = 60) |
| 1316 | """ |
| 1317 | return self.api( |
| 1318 | self.papi.snat_det_set_timeouts, |
| 1319 | {'udp': udp, |
| 1320 | 'tcp_established': tcp_established, |
| 1321 | 'tcp_transitory': tcp_transitory, |
| 1322 | 'icmp': icmp}) |
| 1323 | |
| 1324 | def snat_det_get_timeouts(self): |
| 1325 | """Get values of timeouts for deterministic NAT |
| 1326 | |
| 1327 | :return: Timeouts for deterministic NAT (in seconds) |
| 1328 | """ |
| 1329 | return self.api(self.papi.snat_det_get_timeouts, {}) |
| 1330 | |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1331 | def snat_det_close_session_out( |
| 1332 | self, |
| 1333 | out_addr, |
| 1334 | out_port, |
| 1335 | ext_addr, |
| 1336 | ext_port, |
| 1337 | is_ip4=1): |
| 1338 | """Close CGN session using outside address and port |
| 1339 | |
| 1340 | :param out_addr - outside IP address |
| 1341 | :param out_port - outside port |
| 1342 | :param ext_addr - external host IP address |
| 1343 | :param ext_port - external host port |
| 1344 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1345 | """ |
| 1346 | return self.api( |
| 1347 | self.papi.snat_det_close_session_out, |
| 1348 | {'out_addr': out_addr, |
| 1349 | 'out_port': out_port, |
| 1350 | 'ext_addr': ext_addr, |
| 1351 | 'ext_port': ext_port, |
| 1352 | 'is_ip4': is_ip4}) |
| 1353 | |
| 1354 | def snat_det_close_session_in( |
| 1355 | self, |
| 1356 | in_addr, |
| 1357 | in_port, |
| 1358 | ext_addr, |
| 1359 | ext_port, |
| 1360 | is_ip4=1): |
| 1361 | """Close CGN session using inside address and port |
| 1362 | |
| 1363 | :param in_addr - inside IP address |
| 1364 | :param in_port - inside port |
| 1365 | :param ext_addr - external host IP address |
| 1366 | :param ext_port - external host port |
| 1367 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1368 | """ |
| 1369 | return self.api( |
| 1370 | self.papi.snat_det_close_session_in, |
| 1371 | {'in_addr': in_addr, |
| 1372 | 'in_port': in_port, |
| 1373 | 'ext_addr': ext_addr, |
| 1374 | 'ext_port': ext_port, |
| 1375 | 'is_ip4': is_ip4}) |
| 1376 | |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1377 | def snat_det_session_dump( |
| 1378 | self, |
| 1379 | user_addr, |
| 1380 | is_ip4=1): |
| 1381 | """Dump S-NAT deterministic sessions belonging to a user |
| 1382 | |
| 1383 | :param user_addr - inside IP address of the user |
| 1384 | :param is_ip4: - 1 if address type is IPv4 (Default value = 1) |
| 1385 | :return: Dictionary of S-NAT deterministic sessions |
| 1386 | """ |
| 1387 | return self.api( |
| 1388 | self.papi.snat_det_session_dump, |
| 1389 | {'is_ip4': is_ip4, |
| 1390 | 'user_addr': user_addr}) |
| 1391 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1392 | def nat64_add_del_pool_addr_range( |
| 1393 | self, |
| 1394 | start_addr, |
| 1395 | end_addr, |
| 1396 | vrf_id=0xFFFFFFFF, |
| 1397 | is_add=1): |
| 1398 | """Add/del address range to NAT64 pool |
| 1399 | |
| 1400 | :param start_addr: First IP address |
| 1401 | :param end_addr: Last IP address |
| 1402 | :param vrf_id: VRF id for the address range |
| 1403 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1404 | """ |
| 1405 | return self.api( |
| 1406 | self.papi.nat64_add_del_pool_addr_range, |
| 1407 | {'start_addr': start_addr, |
| 1408 | 'end_addr': end_addr, |
| 1409 | 'vrf_id': vrf_id, |
| 1410 | 'is_add': is_add}) |
| 1411 | |
| 1412 | def nat64_pool_addr_dump(self): |
| 1413 | """Dump NAT64 pool addresses |
| 1414 | :return: Dictionary of NAT64 pool addresses |
| 1415 | """ |
| 1416 | return self.api(self.papi.nat64_pool_addr_dump, {}) |
| 1417 | |
| 1418 | def nat64_add_del_interface( |
| 1419 | self, |
| 1420 | sw_if_index, |
| 1421 | is_inside=1, |
| 1422 | is_add=1): |
| 1423 | """Enable/disable NAT64 feature on the interface |
| 1424 | :param sw_if_index: Index of the interface |
| 1425 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1426 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1427 | """ |
| 1428 | return self.api( |
| 1429 | self.papi.nat64_add_del_interface, |
| 1430 | {'sw_if_index': sw_if_index, |
| 1431 | 'is_inside': is_inside, |
| 1432 | 'is_add': is_add}) |
| 1433 | |
| 1434 | def nat64_interface_dump(self): |
| 1435 | """Dump interfaces with NAT64 feature |
| 1436 | :return: Dictionary of interfaces with NAT64 feature |
| 1437 | """ |
| 1438 | return self.api(self.papi.nat64_interface_dump, {}) |
| 1439 | |
| 1440 | def nat64_add_del_static_bib( |
| 1441 | self, |
| 1442 | in_ip, |
| 1443 | out_ip, |
| 1444 | in_port, |
| 1445 | out_port, |
| 1446 | protocol, |
| 1447 | vrf_id=0, |
| 1448 | is_add=1): |
| 1449 | """Add/delete S-NAT static BIB entry |
| 1450 | |
| 1451 | :param in_ip: Inside IPv6 address |
| 1452 | :param out_ip: Outside IPv4 address |
| 1453 | :param in_port: Inside port number |
| 1454 | :param out_port: Outside port number |
| 1455 | :param protocol: IP protocol |
| 1456 | :param vrf_id: VRF ID (Default value = 0) |
| 1457 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1458 | """ |
| 1459 | return self.api( |
| 1460 | self.papi.nat64_add_del_static_bib, |
| 1461 | {'i_addr': in_ip, |
| 1462 | 'o_addr': out_ip, |
| 1463 | 'i_port': in_port, |
| 1464 | 'o_port': out_port, |
| 1465 | 'vrf_id': vrf_id, |
| 1466 | 'proto': protocol, |
| 1467 | 'is_add': is_add}) |
| 1468 | |
| 1469 | def nat64_bib_dump(self, protocol): |
| 1470 | """Dump NAT64 BIB |
| 1471 | |
| 1472 | :param protocol: IP protocol |
| 1473 | :returns: Dictionary of NAT64 BIB entries |
| 1474 | """ |
| 1475 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 1476 | |
| 1477 | def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440, |
| 1478 | tcp_incoming_syn=6): |
| 1479 | """Set values of timeouts for NAT64 (in seconds) |
| 1480 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1481 | :param udpi: UDP timeout (Default value = 300) |
| 1482 | :param icmp: ICMP timeout (Default value = 60) |
| 1483 | :param tcp_trans: TCP transitory timeout (Default value = 240) |
| 1484 | :param tcp_est: TCP established timeout (Default value = 7440) |
| 1485 | :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1486 | """ |
| 1487 | return self.api( |
| 1488 | self.papi.nat64_set_timeouts, |
| 1489 | {'udp': udp, |
| 1490 | 'icmp': icmp, |
| 1491 | 'tcp_trans': tcp_trans, |
| 1492 | 'tcp_est': tcp_est, |
| 1493 | 'tcp_incoming_syn': tcp_incoming_syn}) |
| 1494 | |
| 1495 | def nat64_get_timeouts(self): |
| 1496 | """Get values of timeouts for NAT64 |
| 1497 | |
| 1498 | :return: Timeouts for NAT64 (in seconds) |
| 1499 | """ |
| 1500 | return self.api(self.papi.nat64_get_timeouts, {}) |
| 1501 | |
| 1502 | def nat64_st_dump(self, protocol): |
| 1503 | """Dump NAT64 session table |
| 1504 | |
| 1505 | :param protocol: IP protocol |
| 1506 | :returns: Dictionary of NAT64 sesstion table entries |
| 1507 | """ |
| 1508 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 1509 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1510 | def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1): |
| 1511 | """Add/del NAT64 prefix |
| 1512 | |
| 1513 | :param prefix: NAT64 prefix |
| 1514 | :param plen: NAT64 prefix length |
| 1515 | :param vrf_id: VRF id of tenant (Default 0) |
| 1516 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1517 | """ |
| 1518 | return self.api( |
| 1519 | self.papi.nat64_add_del_prefix, |
| 1520 | {'prefix': prefix, |
| 1521 | 'prefix_len': plen, |
| 1522 | 'vrf_id': vrf_id, |
| 1523 | 'is_add': is_add}) |
| 1524 | |
| 1525 | def nat64_prefix_dump(self): |
| 1526 | """Dump NAT64 prefix |
| 1527 | |
| 1528 | :returns: Dictionary of NAT64 prefixes |
| 1529 | """ |
| 1530 | return self.api(self.papi.nat64_prefix_dump, {}) |
| 1531 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1532 | def control_ping(self): |
| 1533 | self.api(self.papi.control_ping) |
| 1534 | |
| 1535 | 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] | 1536 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1537 | bfd_key_id=None, conf_key_id=None): |
| 1538 | if bfd_key_id is None: |
| 1539 | return self.api(self.papi.bfd_udp_add, |
| 1540 | { |
| 1541 | 'sw_if_index': sw_if_index, |
| 1542 | 'desired_min_tx': desired_min_tx, |
| 1543 | 'required_min_rx': required_min_rx, |
| 1544 | 'local_addr': local_addr, |
| 1545 | 'peer_addr': peer_addr, |
| 1546 | 'is_ipv6': is_ipv6, |
| 1547 | 'detect_mult': detect_mult, |
| 1548 | }) |
| 1549 | else: |
| 1550 | return self.api(self.papi.bfd_udp_add, |
| 1551 | { |
| 1552 | 'sw_if_index': sw_if_index, |
| 1553 | 'desired_min_tx': desired_min_tx, |
| 1554 | 'required_min_rx': required_min_rx, |
| 1555 | 'local_addr': local_addr, |
| 1556 | 'peer_addr': peer_addr, |
| 1557 | 'is_ipv6': is_ipv6, |
| 1558 | 'detect_mult': detect_mult, |
| 1559 | 'is_authenticated': 1, |
| 1560 | 'bfd_key_id': bfd_key_id, |
| 1561 | 'conf_key_id': conf_key_id, |
| 1562 | }) |
| 1563 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1564 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1565 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1566 | return self.api(self.papi.bfd_udp_mod, |
| 1567 | { |
| 1568 | 'sw_if_index': sw_if_index, |
| 1569 | 'desired_min_tx': desired_min_tx, |
| 1570 | 'required_min_rx': required_min_rx, |
| 1571 | 'local_addr': local_addr, |
| 1572 | 'peer_addr': peer_addr, |
| 1573 | 'is_ipv6': is_ipv6, |
| 1574 | 'detect_mult': detect_mult, |
| 1575 | }) |
| 1576 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1577 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1578 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1579 | is_delayed=False): |
| 1580 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1581 | { |
| 1582 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1583 | 'local_addr': local_addr, |
| 1584 | 'peer_addr': peer_addr, |
| 1585 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1586 | 'is_delayed': 1 if is_delayed else 0, |
| 1587 | 'bfd_key_id': bfd_key_id, |
| 1588 | 'conf_key_id': conf_key_id, |
| 1589 | }) |
| 1590 | |
| 1591 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1592 | is_ipv6=0, is_delayed=False): |
| 1593 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1594 | { |
| 1595 | 'sw_if_index': sw_if_index, |
| 1596 | 'local_addr': local_addr, |
| 1597 | 'peer_addr': peer_addr, |
| 1598 | 'is_ipv6': is_ipv6, |
| 1599 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1600 | }) |
| 1601 | |
| 1602 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1603 | return self.api(self.papi.bfd_udp_del, |
| 1604 | { |
| 1605 | 'sw_if_index': sw_if_index, |
| 1606 | 'local_addr': local_addr, |
| 1607 | 'peer_addr': peer_addr, |
| 1608 | 'is_ipv6': is_ipv6, |
| 1609 | }) |
| 1610 | |
| 1611 | def bfd_udp_session_dump(self): |
| 1612 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1613 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1614 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1615 | peer_addr, is_ipv6=0): |
| 1616 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1617 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1618 | 'sw_if_index': sw_if_index, |
| 1619 | 'local_addr': local_addr, |
| 1620 | 'peer_addr': peer_addr, |
| 1621 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1622 | }) |
| 1623 | |
| 1624 | def want_bfd_events(self, enable_disable=1): |
| 1625 | return self.api(self.papi.want_bfd_events, { |
| 1626 | 'enable_disable': enable_disable, |
| 1627 | 'pid': os.getpid(), |
| 1628 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1629 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1630 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1631 | return self.api(self.papi.bfd_auth_set_key, { |
| 1632 | 'conf_key_id': conf_key_id, |
| 1633 | 'auth_type': auth_type, |
| 1634 | 'key': key, |
| 1635 | 'key_len': len(key), |
| 1636 | }) |
| 1637 | |
| 1638 | def bfd_auth_del_key(self, conf_key_id): |
| 1639 | return self.api(self.papi.bfd_auth_del_key, { |
| 1640 | 'conf_key_id': conf_key_id, |
| 1641 | }) |
| 1642 | |
| 1643 | def bfd_auth_keys_dump(self): |
| 1644 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1645 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1646 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 1647 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 1648 | {'sw_if_index': sw_if_index}) |
| 1649 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1650 | def bfd_udp_del_echo_source(self): |
| 1651 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 1652 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1653 | def classify_add_del_table( |
| 1654 | self, |
| 1655 | is_add, |
| 1656 | mask, |
| 1657 | match_n_vectors=1, |
| 1658 | table_index=0xFFFFFFFF, |
| 1659 | nbuckets=2, |
| 1660 | memory_size=2097152, |
| 1661 | skip_n_vectors=0, |
| 1662 | next_table_index=0xFFFFFFFF, |
| 1663 | miss_next_index=0xFFFFFFFF, |
| 1664 | current_data_flag=0, |
| 1665 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1666 | """ |
| 1667 | :param is_add: |
| 1668 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1669 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1670 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1671 | :param nbuckets: (Default value = 2) |
| 1672 | :param memory_size: (Default value = 2097152) |
| 1673 | :param skip_n_vectors: (Default value = 0) |
| 1674 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1675 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1676 | :param current_data_flag: (Default value = 0) |
| 1677 | :param current_data_offset: (Default value = 0) |
| 1678 | """ |
| 1679 | |
| 1680 | return self.api( |
| 1681 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1682 | {'is_add': is_add, |
| 1683 | 'table_index': table_index, |
| 1684 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1685 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1686 | 'skip_n_vectors': skip_n_vectors, |
| 1687 | 'match_n_vectors': match_n_vectors, |
| 1688 | 'next_table_index': next_table_index, |
| 1689 | 'miss_next_index': miss_next_index, |
| 1690 | 'current_data_flag': current_data_flag, |
| 1691 | 'current_data_offset': current_data_offset, |
| 1692 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1693 | |
| 1694 | def classify_add_del_session( |
| 1695 | self, |
| 1696 | is_add, |
| 1697 | table_index, |
| 1698 | match, |
| 1699 | opaque_index=0xFFFFFFFF, |
| 1700 | hit_next_index=0xFFFFFFFF, |
| 1701 | advance=0, |
| 1702 | action=0, |
| 1703 | metadata=0): |
| 1704 | """ |
| 1705 | :param is_add: |
| 1706 | :param table_index: |
| 1707 | :param match: |
| 1708 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1709 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1710 | :param advance: (Default value = 0) |
| 1711 | :param action: (Default value = 0) |
| 1712 | :param metadata: (Default value = 0) |
| 1713 | """ |
| 1714 | |
| 1715 | return self.api( |
| 1716 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1717 | {'is_add': is_add, |
| 1718 | 'table_index': table_index, |
| 1719 | 'hit_next_index': hit_next_index, |
| 1720 | 'opaque_index': opaque_index, |
| 1721 | 'advance': advance, |
| 1722 | 'action': action, |
| 1723 | 'metadata': metadata, |
| 1724 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1725 | |
| 1726 | def input_acl_set_interface( |
| 1727 | self, |
| 1728 | is_add, |
| 1729 | sw_if_index, |
| 1730 | ip4_table_index=0xFFFFFFFF, |
| 1731 | ip6_table_index=0xFFFFFFFF, |
| 1732 | l2_table_index=0xFFFFFFFF): |
| 1733 | """ |
| 1734 | :param is_add: |
| 1735 | :param sw_if_index: |
| 1736 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1737 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1738 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1739 | """ |
| 1740 | |
| 1741 | return self.api( |
| 1742 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1743 | {'sw_if_index': sw_if_index, |
| 1744 | 'ip4_table_index': ip4_table_index, |
| 1745 | 'ip6_table_index': ip6_table_index, |
| 1746 | 'l2_table_index': l2_table_index, |
| 1747 | 'is_add': is_add}) |
| 1748 | |
| 1749 | def set_ipfix_exporter( |
| 1750 | self, |
| 1751 | collector_address, |
| 1752 | src_address, |
| 1753 | path_mtu, |
| 1754 | template_interval, |
| 1755 | vrf_id=0, |
| 1756 | collector_port=4739, |
| 1757 | udp_checksum=0): |
| 1758 | return self.api( |
| 1759 | self.papi.set_ipfix_exporter, |
| 1760 | { |
| 1761 | 'collector_address': collector_address, |
| 1762 | 'collector_port': collector_port, |
| 1763 | 'src_address': src_address, |
| 1764 | 'vrf_id': vrf_id, |
| 1765 | 'path_mtu': path_mtu, |
| 1766 | 'template_interval': template_interval, |
| 1767 | 'udp_checksum': udp_checksum, |
| 1768 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1769 | |
| 1770 | def dhcp_proxy_config(self, |
| 1771 | dhcp_server, |
| 1772 | dhcp_src_address, |
| 1773 | rx_table_id=0, |
| 1774 | server_table_id=0, |
| 1775 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1776 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1777 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1778 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1779 | { |
| 1780 | 'rx_vrf_id': rx_table_id, |
| 1781 | 'server_vrf_id': server_table_id, |
| 1782 | 'is_ipv6': is_ipv6, |
| 1783 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1784 | 'dhcp_server': dhcp_server, |
| 1785 | 'dhcp_src_address': dhcp_src_address, |
| 1786 | }) |
| 1787 | |
| 1788 | def dhcp_proxy_set_vss(self, |
| 1789 | table_id, |
| 1790 | fib_id, |
| 1791 | oui, |
| 1792 | is_add=1, |
| 1793 | is_ip6=0): |
| 1794 | return self.api( |
| 1795 | self.papi.dhcp_proxy_set_vss, |
| 1796 | { |
| 1797 | 'tbl_id': table_id, |
| 1798 | 'fib_id': fib_id, |
| 1799 | 'is_ipv6': is_ip6, |
| 1800 | 'is_add': is_add, |
| 1801 | 'oui': oui, |
| 1802 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1803 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1804 | def dhcp_client(self, |
| 1805 | sw_if_index, |
| 1806 | hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1807 | client_id='', |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1808 | is_add=1, |
| 1809 | want_dhcp_events=0): |
| 1810 | return self.api( |
| 1811 | self.papi.dhcp_client_config, |
| 1812 | { |
| 1813 | 'sw_if_index': sw_if_index, |
| 1814 | 'hostname': hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 1815 | 'client_id': client_id, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 1816 | 'is_add': is_add, |
| 1817 | 'want_dhcp_event': want_dhcp_events, |
| 1818 | 'pid': os.getpid(), |
| 1819 | }) |
| 1820 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1821 | def ip_mroute_add_del(self, |
| 1822 | src_address, |
| 1823 | grp_address, |
| 1824 | grp_address_length, |
| 1825 | e_flags, |
| 1826 | next_hop_sw_if_index, |
| 1827 | i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1828 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1829 | table_id=0, |
| 1830 | create_vrf_if_needed=0, |
| 1831 | is_add=1, |
| 1832 | is_ipv6=0, |
| 1833 | is_local=0): |
| 1834 | """ |
| 1835 | """ |
| 1836 | return self.api( |
| 1837 | self.papi.ip_mroute_add_del, |
| 1838 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 1839 | 'entry_flags': e_flags, |
| 1840 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1841 | 'table_id': table_id, |
| 1842 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1843 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 1844 | 'is_add': is_add, |
| 1845 | 'is_ipv6': is_ipv6, |
| 1846 | 'is_local': is_local, |
| 1847 | 'grp_address_length': grp_address_length, |
| 1848 | 'grp_address': grp_address, |
| 1849 | 'src_address': src_address}) |
| 1850 | |
| 1851 | def mfib_signal_dump(self): |
| 1852 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1853 | |
| 1854 | def ip_mfib_dump(self): |
| 1855 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1856 | |
| 1857 | def lisp_enable_disable(self, is_enabled): |
| 1858 | return self.api( |
| 1859 | self.papi.lisp_enable_disable, |
| 1860 | { |
| 1861 | 'is_en': is_enabled, |
| 1862 | }) |
| 1863 | |
| 1864 | def lisp_locator_set(self, |
| 1865 | ls_name, |
| 1866 | is_add=1): |
| 1867 | return self.api( |
| 1868 | self.papi.lisp_add_del_locator_set, |
| 1869 | { |
| 1870 | 'is_add': is_add, |
| 1871 | 'locator_set_name': ls_name |
| 1872 | }) |
| 1873 | |
| 1874 | def lisp_locator_set_dump(self): |
| 1875 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 1876 | |
| 1877 | def lisp_locator(self, |
| 1878 | ls_name, |
| 1879 | sw_if_index, |
| 1880 | priority=1, |
| 1881 | weight=1, |
| 1882 | is_add=1): |
| 1883 | return self.api( |
| 1884 | self.papi.lisp_add_del_locator, |
| 1885 | { |
| 1886 | 'is_add': is_add, |
| 1887 | 'locator_set_name': ls_name, |
| 1888 | 'sw_if_index': sw_if_index, |
| 1889 | 'priority': priority, |
| 1890 | 'weight': weight |
| 1891 | }) |
| 1892 | |
| 1893 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 1894 | return self.api( |
| 1895 | self.papi.lisp_locator_dump, |
| 1896 | { |
| 1897 | 'is_index_set': is_index_set, |
| 1898 | 'ls_name': ls_name, |
| 1899 | 'ls_index': ls_index, |
| 1900 | }) |
| 1901 | |
| 1902 | def lisp_local_mapping(self, |
| 1903 | ls_name, |
| 1904 | eid_type, |
| 1905 | eid, |
| 1906 | prefix_len, |
| 1907 | vni=0, |
| 1908 | key_id=0, |
| 1909 | key="", |
| 1910 | is_add=1): |
| 1911 | return self.api( |
| 1912 | self.papi.lisp_add_del_local_eid, |
| 1913 | { |
| 1914 | 'locator_set_name': ls_name, |
| 1915 | 'is_add': is_add, |
| 1916 | 'eid_type': eid_type, |
| 1917 | 'eid': eid, |
| 1918 | 'prefix_len': prefix_len, |
| 1919 | 'vni': vni, |
| 1920 | 'key_id': key_id, |
| 1921 | 'key': key |
| 1922 | }) |
| 1923 | |
| 1924 | def lisp_eid_table_dump(self, |
| 1925 | eid_set=0, |
| 1926 | prefix_length=0, |
| 1927 | vni=0, |
| 1928 | eid_type=0, |
| 1929 | eid=None, |
| 1930 | filter_opt=0): |
| 1931 | return self.api( |
| 1932 | self.papi.lisp_eid_table_dump, |
| 1933 | { |
| 1934 | 'eid_set': eid_set, |
| 1935 | 'prefix_length': prefix_length, |
| 1936 | 'vni': vni, |
| 1937 | 'eid_type': eid_type, |
| 1938 | 'eid': eid, |
| 1939 | 'filter': filter_opt, |
| 1940 | }) |
| 1941 | |
| 1942 | def lisp_remote_mapping(self, |
| 1943 | eid_type, |
| 1944 | eid, |
| 1945 | eid_prefix_len=0, |
| 1946 | vni=0, |
| 1947 | rlocs=None, |
| 1948 | rlocs_num=0, |
| 1949 | is_src_dst=0, |
| 1950 | is_add=1): |
| 1951 | return self.api( |
| 1952 | self.papi.lisp_add_del_remote_mapping, |
| 1953 | { |
| 1954 | 'is_add': is_add, |
| 1955 | 'eid_type': eid_type, |
| 1956 | 'eid': eid, |
| 1957 | 'eid_len': eid_prefix_len, |
| 1958 | 'rloc_num': rlocs_num, |
| 1959 | 'rlocs': rlocs, |
| 1960 | 'vni': vni, |
| 1961 | 'is_src_dst': is_src_dst, |
| 1962 | }) |
| 1963 | |
| 1964 | def lisp_adjacency(self, |
| 1965 | leid, |
| 1966 | reid, |
| 1967 | leid_len, |
| 1968 | reid_len, |
| 1969 | eid_type, |
| 1970 | is_add=1, |
| 1971 | vni=0): |
| 1972 | return self.api( |
| 1973 | self.papi.lisp_add_del_adjacency, |
| 1974 | { |
| 1975 | 'is_add': is_add, |
| 1976 | 'vni': vni, |
| 1977 | 'eid_type': eid_type, |
| 1978 | 'leid': leid, |
| 1979 | 'reid': reid, |
| 1980 | 'leid_len': leid_len, |
| 1981 | 'reid_len': reid_len, |
| 1982 | }) |
| 1983 | |
| 1984 | def lisp_adjacencies_get(self, vni=0): |
| 1985 | return self.api( |
| 1986 | self.papi.lisp_adjacencies_get, |
| 1987 | { |
| 1988 | 'vni': vni |
| 1989 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 1990 | |
| 1991 | def map_add_domain(self, |
| 1992 | ip6_prefix, |
| 1993 | ip6_prefix_len, |
| 1994 | ip6_src, |
| 1995 | ip6_src_prefix_len, |
| 1996 | ip4_prefix, |
| 1997 | ip4_prefix_len, |
| 1998 | ea_bits_len=0, |
| 1999 | psid_offset=0, |
| 2000 | psid_length=0, |
| 2001 | is_translation=0, |
| 2002 | mtu=1280): |
| 2003 | return self.api( |
| 2004 | self.papi.map_add_domain, |
| 2005 | { |
| 2006 | 'ip6_prefix': ip6_prefix, |
| 2007 | 'ip6_prefix_len': ip6_prefix_len, |
| 2008 | 'ip4_prefix': ip4_prefix, |
| 2009 | 'ip4_prefix_len': ip4_prefix_len, |
| 2010 | 'ip6_src': ip6_src, |
| 2011 | 'ip6_src_prefix_len': ip6_src_prefix_len, |
| 2012 | 'ea_bits_len': ea_bits_len, |
| 2013 | 'psid_offset': psid_offset, |
| 2014 | 'psid_length': psid_length, |
| 2015 | 'is_translation': is_translation, |
| 2016 | 'mtu': mtu |
| 2017 | }) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2018 | |
| 2019 | def gtpu_add_del_tunnel( |
| 2020 | self, |
| 2021 | src_addr, |
| 2022 | dst_addr, |
| 2023 | is_add=1, |
| 2024 | is_ipv6=0, |
| 2025 | mcast_sw_if_index=0xFFFFFFFF, |
| 2026 | encap_vrf_id=0, |
| 2027 | decap_next_index=0xFFFFFFFF, |
| 2028 | teid=0): |
| 2029 | """ |
| 2030 | |
| 2031 | :param is_add: (Default value = 1) |
| 2032 | :param is_ipv6: (Default value = 0) |
| 2033 | :param src_addr: |
| 2034 | :param dst_addr: |
| 2035 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2036 | :param encap_vrf_id: (Default value = 0) |
| 2037 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2038 | :param teid: (Default value = 0) |
| 2039 | |
| 2040 | """ |
| 2041 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 2042 | {'is_add': is_add, |
| 2043 | 'is_ipv6': is_ipv6, |
| 2044 | 'src_address': src_addr, |
| 2045 | 'dst_address': dst_addr, |
| 2046 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2047 | 'encap_vrf_id': encap_vrf_id, |
| 2048 | 'decap_next_index': decap_next_index, |
| 2049 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 2050 | |
| 2051 | def vxlan_gpe_add_del_tunnel( |
| 2052 | self, |
| 2053 | src_addr, |
| 2054 | dst_addr, |
| 2055 | mcast_sw_if_index=0xFFFFFFFF, |
| 2056 | is_add=1, |
| 2057 | is_ipv6=0, |
| 2058 | encap_vrf_id=0, |
| 2059 | decap_vrf_id=0, |
| 2060 | protocol=3, |
| 2061 | vni=0): |
| 2062 | """ |
| 2063 | |
| 2064 | :param local: |
| 2065 | :param remote: |
| 2066 | :param is_add: (Default value = 1) |
| 2067 | :param is_ipv6: (Default value = 0) |
| 2068 | :param encap_vrf_id: (Default value = 0) |
| 2069 | :param decap_vrf_id: (Default value = 0) |
| 2070 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2071 | :param protocol: (Default value = 3) |
| 2072 | :param vni: (Default value = 0) |
| 2073 | |
| 2074 | """ |
| 2075 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 2076 | {'is_add': is_add, |
| 2077 | 'is_ipv6': is_ipv6, |
| 2078 | 'local': src_addr, |
| 2079 | 'remote': dst_addr, |
| 2080 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2081 | 'encap_vrf_id': encap_vrf_id, |
| 2082 | 'decap_vrf_id': decap_vrf_id, |
| 2083 | 'protocol': protocol, |
| 2084 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2085 | |
| 2086 | def pppoe_add_del_session( |
| 2087 | self, |
| 2088 | client_ip, |
| 2089 | client_mac, |
| 2090 | session_id=0, |
| 2091 | is_add=1, |
| 2092 | is_ipv6=0, |
| 2093 | decap_vrf_id=0): |
| 2094 | """ |
| 2095 | |
| 2096 | :param is_add: (Default value = 1) |
| 2097 | :param is_ipv6: (Default value = 0) |
| 2098 | :param client_ip: |
| 2099 | :param session_id: (Default value = 0) |
| 2100 | :param client_mac: |
| 2101 | :param decap_vrf_id: (Default value = 0) |
| 2102 | |
| 2103 | """ |
| 2104 | return self.api(self.papi.pppoe_add_del_session, |
| 2105 | {'is_add': is_add, |
| 2106 | 'is_ipv6': is_ipv6, |
| 2107 | 'session_id': session_id, |
| 2108 | 'client_ip': client_ip, |
| 2109 | 'decap_vrf_id': decap_vrf_id, |
| 2110 | 'client_mac': client_mac}) |