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: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 104 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 105 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 106 | else: |
| 107 | self.test_class.logger.debug("Expecting event within %ss", |
| 108 | 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): |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 198 | return mac.replace(':', '').decode('hex') |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 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 | |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 388 | def geneve_add_del_tunnel( |
| 389 | self, |
| 390 | local_addr, |
| 391 | remote_addr, |
| 392 | mcast_sw_if_index=0xFFFFFFFF, |
| 393 | is_add=1, |
| 394 | is_ipv6=0, |
| 395 | encap_vrf_id=0, |
| 396 | decap_next_index=0xFFFFFFFF, |
| 397 | vni=0): |
| 398 | """ |
| 399 | |
| 400 | :param remote_addr: |
| 401 | :param local_addr: |
| 402 | :param is_add: (Default value = 1) |
| 403 | :param is_ipv6: (Default value = 0) |
| 404 | :param encap_vrf_id: (Default value = 0) |
| 405 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 406 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 407 | :param vni: (Default value = 0) |
| 408 | |
| 409 | """ |
| 410 | return self.api(self.papi.geneve_add_del_tunnel, |
| 411 | {'is_add': is_add, |
| 412 | 'is_ipv6': is_ipv6, |
| 413 | 'local_address': local_addr, |
| 414 | 'remote_address': remote_addr, |
| 415 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 416 | 'encap_vrf_id': encap_vrf_id, |
| 417 | 'decap_next_index': decap_next_index, |
| 418 | 'vni': vni}) |
| 419 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 420 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 421 | learn=1, arp_term=0, is_add=1): |
| 422 | """Create/delete bridge domain. |
| 423 | |
| 424 | :param int bd_id: Bridge domain index. |
| 425 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 426 | (Default value = 1) |
| 427 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 428 | (Default value = 1) |
| 429 | :param int forward: Enable/disable forwarding on all interfaces in |
| 430 | the BD. (Default value = 1) |
| 431 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 432 | (Default value = 1) |
| 433 | :param int arp_term: Enable/disable arp termination in the BD. |
| 434 | (Default value = 1) |
| 435 | :param int is_add: Add or delete flag. (Default value = 1) |
| 436 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 437 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 438 | {'bd_id': bd_id, |
| 439 | 'flood': flood, |
| 440 | 'uu_flood': uu_flood, |
| 441 | 'forward': forward, |
| 442 | 'learn': learn, |
| 443 | 'arp_term': arp_term, |
| 444 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 445 | |
Eyal Bari | c86e592 | 2017-07-02 18:33:16 +0300 | [diff] [blame] | 446 | def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1): |
| 447 | return self.api(self.papi.bd_ip_mac_add_del, |
| 448 | {'bd_id': bd_id, |
| 449 | 'is_add': is_add, |
| 450 | 'is_ipv6': is_ipv6, |
| 451 | 'ip_address': ip, |
| 452 | 'mac_address': mac}) |
| 453 | |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 454 | def want_ip4_arp_events(self, enable_disable=1, address=0): |
| 455 | return self.api(self.papi.want_ip4_arp_events, |
| 456 | {'enable_disable': enable_disable, |
| 457 | 'address': address, |
| 458 | 'pid': os.getpid(), }) |
| 459 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 460 | def want_ip6_nd_events(self, enable_disable=1, address=0): |
| 461 | return self.api(self.papi.want_ip6_nd_events, |
| 462 | {'enable_disable': enable_disable, |
| 463 | 'address': address, |
| 464 | 'pid': os.getpid(), }) |
| 465 | |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 466 | def want_macs_learn_events(self, enable_disable=1, scan_delay=0, |
| 467 | max_macs_in_event=0, learn_limit=0): |
| 468 | return self.api(self.papi.want_l2_macs_events, |
| 469 | {'enable_disable': enable_disable, |
| 470 | 'scan_delay': scan_delay, |
| 471 | 'max_macs_in_event': max_macs_in_event, |
| 472 | 'learn_limit': learn_limit, |
| 473 | 'pid': os.getpid(), }) |
| 474 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 475 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 476 | filter_mac=0, bvi_mac=0): |
| 477 | """Create/delete L2 FIB entry. |
| 478 | |
| 479 | :param str mac: MAC address to create FIB entry for. |
| 480 | :param int bd_id: Bridge domain index. |
| 481 | :param int sw_if_index: Software interface index of the interface. |
| 482 | :param int is_add: Add or delete flag. (Default value = 1) |
| 483 | :param int static_mac: Set to 1 to create static MAC entry. |
| 484 | (Default value = 0) |
| 485 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 486 | destination MAC address contains defined MAC address. |
| 487 | (Default value = 0) |
| 488 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 489 | interface. (Default value = 0) |
| 490 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 491 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 492 | {'mac': self._convert_mac(mac), |
| 493 | 'bd_id': bd_id, |
| 494 | 'sw_if_index': sw_if_index, |
| 495 | 'is_add': is_add, |
| 496 | 'static_mac': static_mac, |
| 497 | 'filter_mac': filter_mac, |
| 498 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 499 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 500 | def l2fib_flush_int(self, sw_if_index): |
| 501 | """Flush L2 FIB entries for sw_if_index. |
| 502 | |
| 503 | :param int sw_if_index: Software interface index of the interface. |
| 504 | """ |
| 505 | return self.api(self.papi.l2fib_flush_int, |
| 506 | {'sw_if_index': sw_if_index}) |
| 507 | |
| 508 | def l2fib_flush_bd(self, bd_id): |
| 509 | """Flush L2 FIB entries for bd_id. |
| 510 | |
| 511 | :param int sw_if_index: Bridge Domain id. |
| 512 | """ |
| 513 | return self.api(self.papi.l2fib_flush_bd, |
| 514 | {'bd_id': bd_id}) |
| 515 | |
| 516 | def l2fib_flush_all(self): |
| 517 | """Flush all L2 FIB. |
| 518 | """ |
| 519 | return self.api(self.papi.l2fib_flush_all, {}) |
| 520 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 521 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 522 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 523 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 524 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 525 | :param int sw_if_index: Software interface index of the interface. |
| 526 | :param int bd_id: Bridge domain index. |
| 527 | :param int shg: Split-horizon group index. (Default value = 0) |
| 528 | :param int bvi: Set interface as a bridge group virtual interface. |
| 529 | (Default value = 0) |
| 530 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 531 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 532 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 533 | {'rx_sw_if_index': sw_if_index, |
| 534 | 'bd_id': bd_id, |
| 535 | 'shg': shg, |
| 536 | 'bvi': bvi, |
| 537 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 538 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 539 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 540 | """Enable/disable required feature of the bridge domain with defined ID. |
| 541 | |
| 542 | :param int bd_id: Bridge domain ID. |
| 543 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 544 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 545 | - learn (1 << 0), |
| 546 | - forward (1 << 1), |
| 547 | - flood (1 << 2), |
| 548 | - uu-flood (1 << 3) or |
| 549 | - arp-term (1 << 4). |
| 550 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 551 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 552 | {'bd_id': bd_id, |
| 553 | 'is_set': is_set, |
| 554 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 555 | |
| 556 | def bridge_domain_dump(self, bd_id=0): |
| 557 | """ |
| 558 | |
| 559 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 560 | existing bridge domains returned) |
| 561 | :return: Dictionary of bridge domain(s) data. |
| 562 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 563 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 564 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 565 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 566 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 567 | enable): |
| 568 | """Create or delete unidirectional cross-connect from Tx interface to |
| 569 | Rx interface. |
| 570 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 571 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 572 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 573 | :param int enable: Create cross-connect if equal to 1, delete |
| 574 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 575 | |
| 576 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 577 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 578 | {'rx_sw_if_index': rx_sw_if_index, |
| 579 | 'tx_sw_if_index': tx_sw_if_index, |
| 580 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 581 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 582 | def sw_interface_set_l2_tag_rewrite( |
| 583 | self, |
| 584 | sw_if_index, |
| 585 | vtr_oper, |
| 586 | push=0, |
| 587 | tag1=0, |
| 588 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 589 | """L2 interface vlan tag rewrite configure request |
| 590 | :param client_index - opaque cookie to identify the sender |
| 591 | :param context - sender context, to match reply w/ request |
| 592 | :param sw_if_index - interface the operation is applied to |
| 593 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 594 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 595 | :param tag1 - Needed for any push or translate vtr op |
| 596 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 597 | |
| 598 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 599 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 600 | {'sw_if_index': sw_if_index, |
| 601 | 'vtr_op': vtr_oper, |
| 602 | 'push_dot1q': push, |
| 603 | 'tag1': tag1, |
| 604 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 605 | |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 606 | def sw_interface_set_l2_emulation( |
| 607 | self, |
| 608 | sw_if_index, |
| 609 | enable=1): |
| 610 | """L2 Emulation |
| 611 | :param sw_if_index - interface the operation is applied to |
| 612 | |
| 613 | """ |
| 614 | return self.api(self.papi.l2_emulation, |
| 615 | {'sw_if_index': sw_if_index, |
| 616 | 'enable': enable}) |
| 617 | |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 618 | def sw_interface_set_flags(self, sw_if_index, admin_up_down): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 619 | """ |
| 620 | |
| 621 | :param admin_up_down: |
| 622 | :param sw_if_index: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 623 | |
| 624 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 625 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 626 | {'sw_if_index': sw_if_index, |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 627 | 'admin_up_down': admin_up_down}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 628 | |
| 629 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 630 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 631 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 632 | """Create subinterface |
| 633 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 634 | |
| 635 | :param sub_id: param inner_vlan: |
| 636 | :param sw_if_index: |
| 637 | :param outer_vlan: |
| 638 | :param inner_vlan: |
| 639 | :param no_tags: (Default value = 0) |
| 640 | :param one_tag: (Default value = 0) |
| 641 | :param two_tags: (Default value = 0) |
| 642 | :param dot1ad: (Default value = 0) |
| 643 | :param exact_match: (Default value = 0) |
| 644 | :param default_sub: (Default value = 0) |
| 645 | :param outer_vlan_id_any: (Default value = 0) |
| 646 | :param inner_vlan_id_any: (Default value = 0) |
| 647 | |
| 648 | """ |
| 649 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 650 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 651 | {'sw_if_index': sw_if_index, |
| 652 | 'sub_id': sub_id, |
| 653 | 'no_tags': no_tags, |
| 654 | 'one_tag': one_tag, |
| 655 | 'two_tags': two_tags, |
| 656 | 'dot1ad': dot1ad, |
| 657 | 'exact_match': exact_match, |
| 658 | 'default_sub': default_sub, |
| 659 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 660 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 661 | 'outer_vlan_id': outer_vlan, |
| 662 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 663 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 664 | def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id): |
| 665 | """Create p2p ethernet subinterface |
| 666 | |
| 667 | :param sw_if_index: main (parent) interface |
| 668 | :param remote_mac: client (remote) mac address |
| 669 | |
| 670 | """ |
| 671 | return self.api( |
| 672 | self.papi.p2p_ethernet_add, |
| 673 | {'parent_if_index': sw_if_index, |
| 674 | 'remote_mac': remote_mac, |
| 675 | 'subif_id': subif_id}) |
| 676 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 677 | def delete_subif(self, sw_if_index): |
| 678 | """Delete subinterface |
| 679 | |
| 680 | :param sw_if_index: |
| 681 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 682 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 683 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 684 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 685 | def delete_p2pethernet_subif(self, sw_if_index, remote_mac): |
| 686 | """Delete p2p ethernet subinterface |
| 687 | |
| 688 | :param sw_if_index: main (parent) interface |
| 689 | :param remote_mac: client (remote) mac address |
| 690 | |
| 691 | """ |
| 692 | return self.api( |
| 693 | self.papi.p2p_ethernet_del, |
| 694 | {'parent_if_index': sw_if_index, |
| 695 | 'remote_mac': remote_mac}) |
| 696 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 697 | def create_vlan_subif(self, sw_if_index, vlan): |
| 698 | """ |
| 699 | |
| 700 | :param vlan: |
| 701 | :param sw_if_index: |
| 702 | |
| 703 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 704 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 705 | {'sw_if_index': sw_if_index, |
| 706 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 707 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 708 | def create_loopback(self, mac=''): |
| 709 | """ |
| 710 | |
| 711 | :param mac: (Optional) |
| 712 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 713 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 714 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 715 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 716 | def delete_loopback(self, sw_if_index): |
| 717 | return self.api(self.papi.delete_loopback, |
| 718 | {'sw_if_index': sw_if_index, }) |
| 719 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 720 | def ip_table_add_del(self, |
| 721 | table_id, |
| 722 | is_add=1, |
| 723 | is_ipv6=0): |
| 724 | """ |
| 725 | |
| 726 | :param table_id |
| 727 | :param is_add: (Default value = 1) |
| 728 | :param is_ipv6: (Default value = 0) |
| 729 | |
| 730 | """ |
| 731 | |
| 732 | return self.api( |
| 733 | self.papi.ip_table_add_del, |
| 734 | {'table_id': table_id, |
| 735 | 'is_add': is_add, |
| 736 | 'is_ipv6': is_ipv6}) |
| 737 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 738 | def ip_add_del_route( |
| 739 | self, |
| 740 | dst_address, |
| 741 | dst_address_length, |
| 742 | next_hop_address, |
| 743 | next_hop_sw_if_index=0xFFFFFFFF, |
| 744 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 745 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 746 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 747 | next_hop_n_out_labels=0, |
| 748 | next_hop_out_label_stack=[], |
| 749 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 750 | next_hop_id=0xFFFFFFFF, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 751 | is_resolve_host=0, |
| 752 | is_resolve_attached=0, |
| 753 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 754 | is_add=1, |
| 755 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 756 | is_unreach=0, |
| 757 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 758 | is_ipv6=0, |
| 759 | is_local=0, |
| 760 | is_classify=0, |
| 761 | is_multipath=0, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 762 | is_l2_bridged=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 763 | is_udp_encap=0, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 764 | is_source_lookup=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 765 | """ |
| 766 | |
| 767 | :param dst_address_length: |
| 768 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 769 | :param dst_address: |
| 770 | :param next_hop_address: |
| 771 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 772 | :param vrf_id: (Default value = 0) |
| 773 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 774 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 775 | :param is_add: (Default value = 1) |
| 776 | :param is_drop: (Default value = 0) |
| 777 | :param is_ipv6: (Default value = 0) |
| 778 | :param is_local: (Default value = 0) |
| 779 | :param is_classify: (Default value = 0) |
| 780 | :param is_multipath: (Default value = 0) |
| 781 | :param is_resolve_host: (Default value = 0) |
| 782 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 783 | :param is_l2_bridged: (Default value = 0) |
| 784 | :param is_source_lookup: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 785 | :param next_hop_weight: (Default value = 1) |
| 786 | |
| 787 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 788 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 789 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 790 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 791 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 792 | 'table_id': table_id, |
| 793 | 'classify_table_index': classify_table_index, |
| 794 | 'next_hop_table_id': next_hop_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 795 | 'is_add': is_add, |
| 796 | 'is_drop': is_drop, |
| 797 | 'is_unreach': is_unreach, |
| 798 | 'is_prohibit': is_prohibit, |
| 799 | 'is_ipv6': is_ipv6, |
| 800 | 'is_local': is_local, |
| 801 | 'is_classify': is_classify, |
| 802 | 'is_multipath': is_multipath, |
| 803 | 'is_resolve_host': is_resolve_host, |
| 804 | 'is_resolve_attached': is_resolve_attached, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 805 | 'is_l2_bridged': is_l2_bridged, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 806 | 'is_source_lookup': is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 807 | 'is_udp_encap': is_udp_encap, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 808 | 'next_hop_weight': next_hop_weight, |
| 809 | 'dst_address_length': dst_address_length, |
| 810 | 'dst_address': dst_address, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 811 | 'next_hop_id': next_hop_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 812 | 'next_hop_address': next_hop_address, |
| 813 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 814 | 'next_hop_via_label': next_hop_via_label, |
| 815 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 816 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 817 | def ip_fib_dump(self): |
| 818 | return self.api(self.papi.ip_fib_dump, {}) |
| 819 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 820 | def ip6_fib_dump(self): |
| 821 | return self.api(self.papi.ip6_fib_dump, {}) |
| 822 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 823 | def ip_neighbor_add_del(self, |
| 824 | sw_if_index, |
| 825 | mac_address, |
| 826 | dst_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 827 | is_add=1, |
| 828 | is_ipv6=0, |
| 829 | is_static=0, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 830 | is_no_adj_fib=0, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 831 | ): |
| 832 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 833 | |
| 834 | :param sw_if_index: |
| 835 | :param mac_address: |
| 836 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 837 | :param is_add: (Default value = 1) |
| 838 | :param is_ipv6: (Default value = 0) |
| 839 | :param is_static: (Default value = 0) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 840 | :param is_no_adj_fib: (Default value = 0) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 841 | """ |
| 842 | |
| 843 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 844 | self.papi.ip_neighbor_add_del, |
Neale Ranns | baf2e90 | 2017-02-25 04:20:00 -0800 | [diff] [blame] | 845 | {'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 846 | 'is_add': is_add, |
| 847 | 'is_ipv6': is_ipv6, |
| 848 | 'is_static': is_static, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 849 | 'is_no_adj_fib': is_no_adj_fib, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 850 | 'mac_address': mac_address, |
| 851 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 852 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 853 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 854 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 855 | def ip_neighbor_dump(self, |
| 856 | sw_if_index, |
| 857 | is_ipv6=0): |
| 858 | """ Return IP neighbor dump. |
| 859 | |
| 860 | :param sw_if_index: |
| 861 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 862 | """ |
| 863 | |
| 864 | return self.api( |
| 865 | self.papi.ip_neighbor_dump, |
| 866 | {'is_ipv6': is_ipv6, |
| 867 | 'sw_if_index': sw_if_index |
| 868 | } |
| 869 | ) |
| 870 | |
| 871 | def proxy_arp_add_del(self, |
| 872 | low_address, |
| 873 | hi_address, |
| 874 | vrf_id=0, |
| 875 | is_add=1): |
| 876 | """ Config Proxy Arp Range. |
| 877 | |
| 878 | :param low_address: Start address in the rnage to Proxy for |
| 879 | :param hi_address: End address in the rnage to Proxy for |
| 880 | :param vrf_id: The VRF/table in which to proxy |
| 881 | """ |
| 882 | |
| 883 | return self.api( |
| 884 | self.papi.proxy_arp_add_del, |
| 885 | {'vrf_id': vrf_id, |
| 886 | 'is_add': is_add, |
| 887 | 'low_address': low_address, |
| 888 | 'hi_address': hi_address, |
| 889 | } |
| 890 | ) |
| 891 | |
| 892 | def proxy_arp_intfc_enable_disable(self, |
| 893 | sw_if_index, |
| 894 | is_enable=1): |
| 895 | """ Enable/Disable an interface for proxy ARP requests |
| 896 | |
| 897 | :param sw_if_index: Interface |
| 898 | :param enable_disable: Enable/Disable |
| 899 | """ |
| 900 | |
| 901 | return self.api( |
| 902 | self.papi.proxy_arp_intfc_enable_disable, |
| 903 | {'sw_if_index': sw_if_index, |
| 904 | 'enable_disable': is_enable |
| 905 | } |
| 906 | ) |
| 907 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 908 | def reset_vrf(self, |
| 909 | vrf_id, |
| 910 | is_ipv6=0, |
| 911 | ): |
| 912 | """ Reset VRF (remove all routes etc.) request. |
| 913 | |
| 914 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 915 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 916 | """ |
| 917 | |
| 918 | return self.api( |
| 919 | self.papi.reset_vrf, |
| 920 | {'vrf_id': vrf_id, |
| 921 | 'is_ipv6': is_ipv6, |
| 922 | } |
| 923 | ) |
| 924 | |
| 925 | def reset_fib(self, |
| 926 | vrf_id, |
| 927 | is_ipv6=0, |
| 928 | ): |
| 929 | """ Reset VRF (remove all routes etc.) request. |
| 930 | |
| 931 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 932 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 933 | """ |
| 934 | |
| 935 | return self.api( |
| 936 | self.papi.reset_fib, |
| 937 | {'vrf_id': vrf_id, |
| 938 | 'is_ipv6': is_ipv6, |
| 939 | } |
| 940 | ) |
| 941 | |
| 942 | def ip_dump(self, |
| 943 | is_ipv6=0, |
| 944 | ): |
| 945 | """ Return IP dump. |
| 946 | |
| 947 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 948 | """ |
| 949 | |
| 950 | return self.api( |
| 951 | self.papi.ip_dump, |
| 952 | {'is_ipv6': is_ipv6, |
| 953 | } |
| 954 | ) |
| 955 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 956 | def sw_interface_span_enable_disable( |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 957 | 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] | 958 | """ |
| 959 | |
| 960 | :param sw_if_index_from: |
| 961 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 962 | :param state: |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 963 | :param is_l2: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 964 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 965 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 966 | {'sw_if_index_from': sw_if_index_from, |
| 967 | 'sw_if_index_to': sw_if_index_to, |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 968 | 'state': state, |
| 969 | 'is_l2': is_l2, |
| 970 | }) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 971 | |
| 972 | def gre_tunnel_add_del(self, |
| 973 | src_address, |
| 974 | dst_address, |
| 975 | outer_fib_id=0, |
| 976 | is_teb=0, |
| 977 | is_add=1, |
| 978 | is_ip6=0): |
| 979 | """ Add a GRE tunnel |
| 980 | |
| 981 | :param src_address: |
| 982 | :param dst_address: |
| 983 | :param outer_fib_id: (Default value = 0) |
| 984 | :param is_add: (Default value = 1) |
| 985 | :param is_ipv6: (Default value = 0) |
| 986 | :param is_teb: (Default value = 0) |
| 987 | """ |
| 988 | |
| 989 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 990 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 991 | {'is_add': is_add, |
| 992 | 'is_ipv6': is_ip6, |
| 993 | 'teb': is_teb, |
| 994 | 'src_address': src_address, |
| 995 | 'dst_address': dst_address, |
| 996 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 997 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 998 | |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 999 | def udp_encap_add_del(self, |
| 1000 | id, |
| 1001 | src_ip, |
| 1002 | dst_ip, |
| 1003 | src_port, |
| 1004 | dst_port, |
| 1005 | table_id=0, |
| 1006 | is_add=1, |
| 1007 | is_ip6=0): |
| 1008 | """ Add a GRE tunnel |
| 1009 | :param id: user provided ID |
| 1010 | :param src_ip: |
| 1011 | :param dst_ip: |
| 1012 | :param src_port: |
| 1013 | :param dst_port: |
| 1014 | :param outer_fib_id: (Default value = 0) |
| 1015 | :param is_add: (Default value = 1) |
| 1016 | :param is_ipv6: (Default value = 0) |
| 1017 | """ |
| 1018 | |
| 1019 | return self.api( |
| 1020 | self.papi.udp_encap_add_del, |
| 1021 | {'id': id, |
| 1022 | 'is_add': is_add, |
| 1023 | 'is_ip6': is_ip6, |
| 1024 | 'src_ip': src_ip, |
| 1025 | 'dst_ip': dst_ip, |
| 1026 | 'src_port': src_port, |
| 1027 | 'dst_port': dst_port, |
| 1028 | 'table_id': table_id} |
| 1029 | ) |
| 1030 | |
| 1031 | def udp_encap_dump(self): |
| 1032 | return self.api(self.papi.udp_encap_dump, {}) |
| 1033 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1034 | def mpls_fib_dump(self): |
| 1035 | return self.api(self.papi.mpls_fib_dump, {}) |
| 1036 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1037 | def mpls_table_add_del( |
| 1038 | self, |
| 1039 | table_id, |
| 1040 | is_add=1): |
| 1041 | """ |
| 1042 | |
| 1043 | :param table_id |
| 1044 | :param is_add: (Default value = 1) |
| 1045 | |
| 1046 | """ |
| 1047 | |
| 1048 | return self.api( |
| 1049 | self.papi.mpls_table_add_del, |
| 1050 | {'mt_table_id': table_id, |
| 1051 | 'mt_is_add': is_add}) |
| 1052 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1053 | def mpls_route_add_del( |
| 1054 | self, |
| 1055 | label, |
| 1056 | eos, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1057 | next_hop_proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1058 | next_hop_address, |
| 1059 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1060 | table_id=0, |
| 1061 | next_hop_table_id=0, |
| 1062 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1063 | next_hop_n_out_labels=0, |
| 1064 | next_hop_out_label_stack=[], |
| 1065 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1066 | is_resolve_host=0, |
| 1067 | is_resolve_attached=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1068 | is_interface_rx=0, |
| 1069 | is_rpf_id=0, |
| 1070 | is_multicast=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1071 | is_add=1, |
| 1072 | is_drop=0, |
| 1073 | is_multipath=0, |
| 1074 | classify_table_index=0xFFFFFFFF, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 1075 | is_classify=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1076 | """ |
| 1077 | |
| 1078 | :param dst_address_length: |
| 1079 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1080 | :param dst_address: |
| 1081 | :param next_hop_address: |
| 1082 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1083 | :param vrf_id: (Default value = 0) |
| 1084 | :param lookup_in_vrf: (Default value = 0) |
| 1085 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1086 | :param is_add: (Default value = 1) |
| 1087 | :param is_drop: (Default value = 0) |
| 1088 | :param is_ipv6: (Default value = 0) |
| 1089 | :param is_local: (Default value = 0) |
| 1090 | :param is_classify: (Default value = 0) |
| 1091 | :param is_multipath: (Default value = 0) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1092 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1093 | :param is_resolve_host: (Default value = 0) |
| 1094 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1095 | :param next_hop_weight: (Default value = 1) |
| 1096 | |
| 1097 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1098 | |
| 1099 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1100 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1101 | {'mr_label': label, |
| 1102 | 'mr_eos': eos, |
| 1103 | 'mr_table_id': table_id, |
| 1104 | 'mr_classify_table_index': classify_table_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1105 | 'mr_is_add': is_add, |
| 1106 | 'mr_is_classify': is_classify, |
| 1107 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1108 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1109 | 'mr_is_resolve_host': is_resolve_host, |
| 1110 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1111 | 'mr_is_interface_rx': is_interface_rx, |
| 1112 | 'mr_is_rpf_id': is_rpf_id, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1113 | 'mr_next_hop_proto': next_hop_proto, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1114 | 'mr_next_hop_weight': next_hop_weight, |
| 1115 | 'mr_next_hop': next_hop_address, |
| 1116 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1117 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1118 | 'mr_next_hop_table_id': next_hop_table_id, |
| 1119 | 'mr_next_hop_via_label': next_hop_via_label, |
| 1120 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1121 | |
| 1122 | def mpls_ip_bind_unbind( |
| 1123 | self, |
| 1124 | label, |
| 1125 | dst_address, |
| 1126 | dst_address_length, |
| 1127 | table_id=0, |
| 1128 | ip_table_id=0, |
| 1129 | is_ip4=1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1130 | is_bind=1): |
| 1131 | """ |
| 1132 | """ |
| 1133 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1134 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1135 | {'mb_mpls_table_id': table_id, |
| 1136 | 'mb_label': label, |
| 1137 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1138 | 'mb_is_bind': is_bind, |
| 1139 | 'mb_is_ip4': is_ip4, |
| 1140 | 'mb_address_length': dst_address_length, |
| 1141 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1142 | |
| 1143 | def mpls_tunnel_add_del( |
| 1144 | self, |
| 1145 | tun_sw_if_index, |
| 1146 | next_hop_proto_is_ip4, |
| 1147 | next_hop_address, |
| 1148 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1149 | next_hop_table_id=0, |
| 1150 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1151 | next_hop_n_out_labels=0, |
| 1152 | next_hop_out_label_stack=[], |
| 1153 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1154 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1155 | l2_only=0, |
| 1156 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1157 | """ |
| 1158 | |
| 1159 | :param dst_address_length: |
| 1160 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1161 | :param dst_address: |
| 1162 | :param next_hop_address: |
| 1163 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1164 | :param vrf_id: (Default value = 0) |
| 1165 | :param lookup_in_vrf: (Default value = 0) |
| 1166 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1167 | :param is_add: (Default value = 1) |
| 1168 | :param is_drop: (Default value = 0) |
| 1169 | :param is_ipv6: (Default value = 0) |
| 1170 | :param is_local: (Default value = 0) |
| 1171 | :param is_classify: (Default value = 0) |
| 1172 | :param is_multipath: (Default value = 0) |
| 1173 | :param is_resolve_host: (Default value = 0) |
| 1174 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1175 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1176 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1177 | |
| 1178 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1179 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1180 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1181 | {'mt_sw_if_index': tun_sw_if_index, |
| 1182 | 'mt_is_add': is_add, |
| 1183 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1184 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1185 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 1186 | 'mt_next_hop_weight': next_hop_weight, |
| 1187 | 'mt_next_hop': next_hop_address, |
| 1188 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1189 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1190 | 'mt_next_hop_table_id': next_hop_table_id, |
| 1191 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1192 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1193 | def nat44_interface_add_del_feature( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1194 | self, |
| 1195 | sw_if_index, |
| 1196 | is_inside=1, |
| 1197 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1198 | """Enable/disable NAT44 feature on the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1199 | |
| 1200 | :param sw_if_index: Software index of the interface |
| 1201 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1202 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1203 | """ |
| 1204 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1205 | self.papi.nat44_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1206 | {'is_add': is_add, |
| 1207 | 'is_inside': is_inside, |
| 1208 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1209 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1210 | def nat44_interface_add_del_output_feature( |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1211 | self, |
| 1212 | sw_if_index, |
| 1213 | is_inside=1, |
| 1214 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1215 | """Enable/disable NAT44 output feature on the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1216 | |
| 1217 | :param sw_if_index: Software index of the interface |
| 1218 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1219 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1220 | """ |
| 1221 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1222 | self.papi.nat44_interface_add_del_output_feature, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1223 | {'is_add': is_add, |
| 1224 | 'is_inside': is_inside, |
| 1225 | 'sw_if_index': sw_if_index}) |
| 1226 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1227 | def nat44_add_del_static_mapping( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1228 | self, |
| 1229 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1230 | external_ip=0, |
| 1231 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1232 | local_port=0, |
| 1233 | external_port=0, |
| 1234 | addr_only=1, |
| 1235 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1236 | protocol=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1237 | twice_nat=0, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1238 | is_add=1): |
| 1239 | """Add/delete NAT44 static mapping |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1240 | |
| 1241 | :param local_ip: Local IP address |
| 1242 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1243 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1244 | :param local_port: Local port number (Default value = 0) |
| 1245 | :param external_port: External port number (Default value = 0) |
| 1246 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1247 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1248 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1249 | :param twice_nat: 1 if translate external host address and port |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1250 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1251 | """ |
| 1252 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1253 | self.papi.nat44_add_del_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1254 | {'is_add': is_add, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1255 | 'addr_only': addr_only, |
| 1256 | 'local_ip_address': local_ip, |
| 1257 | 'external_ip_address': external_ip, |
| 1258 | 'local_port': local_port, |
| 1259 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1260 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1261 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1262 | 'protocol': protocol, |
| 1263 | 'twice_nat': twice_nat}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1264 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1265 | def nat44_add_del_identity_mapping( |
| 1266 | self, |
| 1267 | ip='0', |
| 1268 | sw_if_index=0xFFFFFFFF, |
| 1269 | port=0, |
| 1270 | addr_only=1, |
| 1271 | vrf_id=0, |
| 1272 | protocol=0, |
| 1273 | is_add=1): |
| 1274 | """Add/delete NAT44 identity mapping |
| 1275 | |
| 1276 | :param ip: IP address (Default value = 0) |
| 1277 | :param sw_if_index: Interface instead of IP address |
| 1278 | :param port: Port number (Default value = 0) |
| 1279 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1280 | :param vrf_id: VRF ID |
| 1281 | :param protocol: IP protocol (Default value = 0) |
| 1282 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1283 | """ |
| 1284 | return self.api( |
| 1285 | self.papi.nat44_add_del_identity_mapping, |
| 1286 | {'is_add': is_add, |
| 1287 | 'addr_only': addr_only, |
| 1288 | 'ip_address': ip, |
| 1289 | 'port': port, |
| 1290 | 'sw_if_index': sw_if_index, |
| 1291 | 'vrf_id': vrf_id, |
| 1292 | 'protocol': protocol}) |
| 1293 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1294 | def nat44_add_del_address_range( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1295 | self, |
| 1296 | first_ip_address, |
| 1297 | last_ip_address, |
| 1298 | is_add=1, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1299 | vrf_id=0xFFFFFFFF, |
| 1300 | twice_nat=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1301 | """Add/del NAT44 address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1302 | |
| 1303 | :param first_ip_address: First IP address |
| 1304 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1305 | :param vrf_id: VRF id for the address range |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1306 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1307 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1308 | """ |
| 1309 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1310 | self.papi.nat44_add_del_address_range, |
| 1311 | {'first_ip_address': first_ip_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1312 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1313 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1314 | 'twice_nat': twice_nat, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1315 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1316 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1317 | def nat44_address_dump(self): |
| 1318 | """Dump NAT44 addresses |
| 1319 | :return: Dictionary of NAT44 addresses |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1320 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1321 | return self.api(self.papi.nat44_address_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1322 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1323 | def nat44_interface_dump(self): |
| 1324 | """Dump interfaces with NAT44 feature |
| 1325 | :return: Dictionary of interfaces with NAT44 feature |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1326 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1327 | return self.api(self.papi.nat44_interface_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1328 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1329 | def nat44_interface_output_feature_dump(self): |
| 1330 | """Dump interfaces with NAT44 output feature |
| 1331 | :return: Dictionary of interfaces with NAT44 output feature |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1332 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1333 | return self.api(self.papi.nat44_interface_output_feature_dump, {}) |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1334 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1335 | def nat44_static_mapping_dump(self): |
| 1336 | """Dump NAT44 static mappings |
| 1337 | :return: Dictionary of NAT44 static mappings |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1338 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1339 | return self.api(self.papi.nat44_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1340 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1341 | def nat44_identity_mapping_dump(self): |
| 1342 | """Dump NAT44 identity mappings |
| 1343 | :return: Dictionary of NAT44 identity mappings |
| 1344 | """ |
| 1345 | return self.api(self.papi.nat44_identity_mapping_dump, {}) |
| 1346 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1347 | def nat_show_config(self): |
| 1348 | """Show NAT plugin config |
| 1349 | :return: NAT plugin config parameters |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1350 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1351 | return self.api(self.papi.nat_show_config, {}) |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1352 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1353 | def nat44_add_interface_addr( |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1354 | self, |
| 1355 | sw_if_index, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1356 | twice_nat=0, |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1357 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1358 | """Add/del NAT44 address from interface |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1359 | |
| 1360 | :param sw_if_index: Software index of the interface |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1361 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1362 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1363 | """ |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1364 | return self.api( |
| 1365 | self.papi.nat44_add_del_interface_addr, |
| 1366 | {'is_add': is_add, |
| 1367 | 'sw_if_index': sw_if_index, |
| 1368 | 'twice_nat': twice_nat}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1369 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1370 | def nat44_interface_addr_dump(self): |
| 1371 | """Dump NAT44 addresses interfaces |
| 1372 | :return: Dictionary of NAT44 addresses interfaces |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1373 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1374 | return self.api(self.papi.nat44_interface_addr_dump, {}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1375 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1376 | def nat_ipfix( |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1377 | self, |
| 1378 | domain_id=1, |
| 1379 | src_port=4739, |
| 1380 | enable=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1381 | """Enable/disable NAT IPFIX logging |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1382 | |
| 1383 | :param domain_id: Observation domain ID (Default value = 1) |
| 1384 | :param src_port: Source port number (Default value = 4739) |
| 1385 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1386 | """ |
| 1387 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1388 | self.papi.nat_ipfix_enable_disable, |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1389 | {'domain_id': domain_id, |
| 1390 | 'src_port': src_port, |
| 1391 | 'enable': enable}) |
| 1392 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1393 | def nat44_user_session_dump( |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1394 | self, |
| 1395 | ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1396 | vrf_id): |
| 1397 | """Dump NAT44 user's sessions |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1398 | |
| 1399 | :param ip_address: ip adress of the user to be dumped |
| 1400 | :param cpu_index: cpu_index on which the user is |
| 1401 | :param vrf_id: VRF ID |
| 1402 | :return: Dictionary of S-NAT sessions |
| 1403 | """ |
| 1404 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1405 | self.papi.nat44_user_session_dump, |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1406 | {'ip_address': ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1407 | 'vrf_id': vrf_id}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1408 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1409 | def nat44_user_dump(self): |
| 1410 | """Dump NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1411 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1412 | :return: Dictionary of NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1413 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1414 | return self.api(self.papi.nat44_user_dump, {}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1415 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1416 | def nat44_add_del_lb_static_mapping( |
| 1417 | self, |
| 1418 | external_addr, |
| 1419 | external_port, |
| 1420 | protocol, |
| 1421 | vrf_id=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1422 | twice_nat=0, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1423 | local_num=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 1424 | locals=[], |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1425 | is_add=1): |
| 1426 | """Add/delete NAT44 load balancing static mapping |
| 1427 | |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1428 | :param twice_nat: 1 if translate external host address and port |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1429 | :param is_add - 1 if add, 0 if delete |
| 1430 | """ |
| 1431 | return self.api( |
| 1432 | self.papi.nat44_add_del_lb_static_mapping, |
| 1433 | {'is_add': is_add, |
| 1434 | 'external_addr': external_addr, |
| 1435 | 'external_port': external_port, |
| 1436 | 'protocol': protocol, |
| 1437 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1438 | 'twice_nat': twice_nat, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1439 | 'local_num': local_num, |
| 1440 | 'locals': locals}) |
| 1441 | |
| 1442 | def nat44_lb_static_mapping_dump(self): |
| 1443 | """Dump NAT44 load balancing static mappings |
| 1444 | |
| 1445 | :return: Dictionary of NAT44 load balancing static mapping |
| 1446 | """ |
| 1447 | return self.api(self.papi.nat44_lb_static_mapping_dump, {}) |
| 1448 | |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1449 | def nat44_del_session( |
| 1450 | self, |
| 1451 | addr, |
| 1452 | port, |
| 1453 | protocol, |
| 1454 | vrf_id=0, |
| 1455 | is_in=1): |
| 1456 | """Delete NAT44 session |
| 1457 | |
| 1458 | :param addr: IPv4 address |
| 1459 | :param por: port number |
| 1460 | :param protocol: IP protocol number |
| 1461 | :param vrf_id: VRF ID |
| 1462 | :param is_in: 1 if inside network addres and port pari, 0 if outside |
| 1463 | """ |
| 1464 | return self.api( |
| 1465 | self.papi.nat44_del_session, |
| 1466 | {'address': addr, |
| 1467 | 'port': port, |
| 1468 | 'protocol': protocol, |
| 1469 | 'vrf_id': vrf_id, |
| 1470 | 'is_in': is_in}) |
| 1471 | |
Juraj Sloboda | 7b92979 | 2017-11-23 13:20:48 +0100 | [diff] [blame] | 1472 | def nat44_forwarding_enable_disable( |
| 1473 | self, |
| 1474 | enable): |
| 1475 | """Enable/disable forwarding for NAT44 |
| 1476 | |
| 1477 | :param enable: 1 for enable, 0 for disable |
| 1478 | """ |
| 1479 | return self.api( |
| 1480 | self.papi.nat44_forwarding_enable_disable, |
| 1481 | {'enable': enable}) |
| 1482 | |
Matus Fabian | efcd1e9 | 2017-08-15 06:59:19 -0700 | [diff] [blame] | 1483 | def nat_set_reass( |
| 1484 | self, |
| 1485 | timeout=2, |
| 1486 | max_reass=1024, |
| 1487 | max_frag=5, |
| 1488 | drop_frag=0, |
| 1489 | is_ip6=0): |
| 1490 | """Set NAT virtual fragmentation reassembly |
| 1491 | |
| 1492 | :param timeout: reassembly timeout (Default 2sec) |
| 1493 | :param max_reass: maximum concurrent reassemblies (Default 1024) |
| 1494 | :param max_frag: maximum fragmets per reassembly (Default 5) |
| 1495 | :param drop_frag: if 0 translate fragments, otherwise drop fragments |
| 1496 | :param is_ip6: 1 if IPv6, 0 if IPv4 |
| 1497 | """ |
| 1498 | return self.api( |
| 1499 | self.papi.nat_set_reass, |
| 1500 | {'timeout': timeout, |
| 1501 | 'max_reass': max_reass, |
| 1502 | 'max_frag': max_frag, |
| 1503 | 'drop_frag': drop_frag, |
| 1504 | 'is_ip6': is_ip6}) |
| 1505 | |
| 1506 | def nat_get_reass(self): |
| 1507 | """Get NAT virtual fragmentation reassembly configuration |
| 1508 | |
| 1509 | :return: NAT virtual fragmentation reassembly configuration |
| 1510 | """ |
| 1511 | return self.api(self.papi.nat_get_reass, {}) |
| 1512 | |
| 1513 | def nat_reass_dump(self): |
| 1514 | """Dump NAT virtual fragmentation reassemblies |
| 1515 | |
| 1516 | :return: Dictionary of NAT virtual fragmentation reassemblies |
| 1517 | """ |
| 1518 | return self.api(self.papi.nat_reass_dump, {}) |
| 1519 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1520 | def nat_det_add_del_map( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1521 | self, |
| 1522 | in_addr, |
| 1523 | in_plen, |
| 1524 | out_addr, |
| 1525 | out_plen, |
| 1526 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1527 | """Add/delete deterministic NAT mapping |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1528 | |
| 1529 | :param is_add - 1 if add, 0 if delete |
| 1530 | :param in_addr - inside IP address |
| 1531 | :param in_plen - inside IP address prefix length |
| 1532 | :param out_addr - outside IP address |
| 1533 | :param out_plen - outside IP address prefix length |
| 1534 | """ |
| 1535 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1536 | self.papi.nat_det_add_del_map, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1537 | {'is_add': is_add, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1538 | 'is_nat44': 1, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1539 | 'in_addr': in_addr, |
| 1540 | 'in_plen': in_plen, |
| 1541 | 'out_addr': out_addr, |
| 1542 | 'out_plen': out_plen}) |
| 1543 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1544 | def nat_det_forward( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1545 | self, |
| 1546 | in_addr): |
| 1547 | """Get outside address and port range from inside address |
| 1548 | |
| 1549 | :param in_addr - inside IP address |
| 1550 | """ |
| 1551 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1552 | self.papi.nat_det_forward, |
| 1553 | {'in_addr': in_addr, |
| 1554 | 'is_nat44': 1}) |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1555 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1556 | def nat_det_reverse( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1557 | self, |
| 1558 | out_addr, |
| 1559 | out_port): |
| 1560 | """Get inside address from outside address and port |
| 1561 | |
| 1562 | :param out_addr - outside IP address |
| 1563 | :param out_port - outside port |
| 1564 | """ |
| 1565 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1566 | self.papi.nat_det_reverse, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1567 | {'out_addr': out_addr, |
| 1568 | 'out_port': out_port}) |
| 1569 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1570 | def nat_det_map_dump(self): |
| 1571 | """Dump deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1572 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1573 | :return: Dictionary of deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1574 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1575 | return self.api(self.papi.nat_det_map_dump, {}) |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1576 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1577 | def nat_det_set_timeouts( |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1578 | self, |
| 1579 | udp=300, |
| 1580 | tcp_established=7440, |
| 1581 | tcp_transitory=240, |
| 1582 | icmp=60): |
| 1583 | """Set values of timeouts for deterministic NAT (in seconds) |
| 1584 | |
| 1585 | :param udp - UDP timeout (Default value = 300) |
| 1586 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1587 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1588 | :param icmp - ICMP timeout (Default value = 60) |
| 1589 | """ |
| 1590 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1591 | self.papi.nat_det_set_timeouts, |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1592 | {'udp': udp, |
| 1593 | 'tcp_established': tcp_established, |
| 1594 | 'tcp_transitory': tcp_transitory, |
| 1595 | 'icmp': icmp}) |
| 1596 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1597 | def nat_det_get_timeouts(self): |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1598 | """Get values of timeouts for deterministic NAT |
| 1599 | |
| 1600 | :return: Timeouts for deterministic NAT (in seconds) |
| 1601 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1602 | return self.api(self.papi.nat_det_get_timeouts, {}) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1603 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1604 | def nat_det_close_session_out( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1605 | self, |
| 1606 | out_addr, |
| 1607 | out_port, |
| 1608 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1609 | ext_port): |
| 1610 | """Close deterministic NAT session using outside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1611 | |
| 1612 | :param out_addr - outside IP address |
| 1613 | :param out_port - outside port |
| 1614 | :param ext_addr - external host IP address |
| 1615 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1616 | """ |
| 1617 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1618 | self.papi.nat_det_close_session_out, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1619 | {'out_addr': out_addr, |
| 1620 | 'out_port': out_port, |
| 1621 | 'ext_addr': ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1622 | 'ext_port': ext_port}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1623 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1624 | def nat_det_close_session_in( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1625 | self, |
| 1626 | in_addr, |
| 1627 | in_port, |
| 1628 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1629 | ext_port): |
| 1630 | """Close deterministic NAT session using inside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1631 | |
| 1632 | :param in_addr - inside IP address |
| 1633 | :param in_port - inside port |
| 1634 | :param ext_addr - external host IP address |
| 1635 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1636 | """ |
| 1637 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1638 | self.papi.nat_det_close_session_in, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1639 | {'in_addr': in_addr, |
| 1640 | 'in_port': in_port, |
| 1641 | 'ext_addr': ext_addr, |
| 1642 | 'ext_port': ext_port, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1643 | 'is_nat44': 1}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1644 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1645 | def nat_det_session_dump( |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1646 | self, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1647 | user_addr): |
| 1648 | """Dump deterministic NAT sessions belonging to a user |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1649 | |
| 1650 | :param user_addr - inside IP address of the user |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1651 | :return: Dictionary of deterministic NAT sessions |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1652 | """ |
| 1653 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1654 | self.papi.nat_det_session_dump, |
| 1655 | {'is_nat44': 1, |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1656 | 'user_addr': user_addr}) |
| 1657 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1658 | def nat64_add_del_pool_addr_range( |
| 1659 | self, |
| 1660 | start_addr, |
| 1661 | end_addr, |
| 1662 | vrf_id=0xFFFFFFFF, |
| 1663 | is_add=1): |
| 1664 | """Add/del address range to NAT64 pool |
| 1665 | |
| 1666 | :param start_addr: First IP address |
| 1667 | :param end_addr: Last IP address |
| 1668 | :param vrf_id: VRF id for the address range |
| 1669 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1670 | """ |
| 1671 | return self.api( |
| 1672 | self.papi.nat64_add_del_pool_addr_range, |
| 1673 | {'start_addr': start_addr, |
| 1674 | 'end_addr': end_addr, |
| 1675 | 'vrf_id': vrf_id, |
| 1676 | 'is_add': is_add}) |
| 1677 | |
| 1678 | def nat64_pool_addr_dump(self): |
| 1679 | """Dump NAT64 pool addresses |
| 1680 | :return: Dictionary of NAT64 pool addresses |
| 1681 | """ |
| 1682 | return self.api(self.papi.nat64_pool_addr_dump, {}) |
| 1683 | |
| 1684 | def nat64_add_del_interface( |
| 1685 | self, |
| 1686 | sw_if_index, |
| 1687 | is_inside=1, |
| 1688 | is_add=1): |
| 1689 | """Enable/disable NAT64 feature on the interface |
| 1690 | :param sw_if_index: Index of the interface |
| 1691 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1692 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1693 | """ |
| 1694 | return self.api( |
| 1695 | self.papi.nat64_add_del_interface, |
| 1696 | {'sw_if_index': sw_if_index, |
| 1697 | 'is_inside': is_inside, |
| 1698 | 'is_add': is_add}) |
| 1699 | |
| 1700 | def nat64_interface_dump(self): |
| 1701 | """Dump interfaces with NAT64 feature |
| 1702 | :return: Dictionary of interfaces with NAT64 feature |
| 1703 | """ |
| 1704 | return self.api(self.papi.nat64_interface_dump, {}) |
| 1705 | |
| 1706 | def nat64_add_del_static_bib( |
| 1707 | self, |
| 1708 | in_ip, |
| 1709 | out_ip, |
| 1710 | in_port, |
| 1711 | out_port, |
| 1712 | protocol, |
| 1713 | vrf_id=0, |
| 1714 | is_add=1): |
| 1715 | """Add/delete S-NAT static BIB entry |
| 1716 | |
| 1717 | :param in_ip: Inside IPv6 address |
| 1718 | :param out_ip: Outside IPv4 address |
| 1719 | :param in_port: Inside port number |
| 1720 | :param out_port: Outside port number |
| 1721 | :param protocol: IP protocol |
| 1722 | :param vrf_id: VRF ID (Default value = 0) |
| 1723 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1724 | """ |
| 1725 | return self.api( |
| 1726 | self.papi.nat64_add_del_static_bib, |
| 1727 | {'i_addr': in_ip, |
| 1728 | 'o_addr': out_ip, |
| 1729 | 'i_port': in_port, |
| 1730 | 'o_port': out_port, |
| 1731 | 'vrf_id': vrf_id, |
| 1732 | 'proto': protocol, |
| 1733 | 'is_add': is_add}) |
| 1734 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1735 | def nat64_bib_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1736 | """Dump NAT64 BIB |
| 1737 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1738 | :param protocol: IP protocol (Default value = 255, all BIBs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1739 | :returns: Dictionary of NAT64 BIB entries |
| 1740 | """ |
| 1741 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 1742 | |
| 1743 | def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440, |
| 1744 | tcp_incoming_syn=6): |
| 1745 | """Set values of timeouts for NAT64 (in seconds) |
| 1746 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1747 | :param udpi: UDP timeout (Default value = 300) |
| 1748 | :param icmp: ICMP timeout (Default value = 60) |
| 1749 | :param tcp_trans: TCP transitory timeout (Default value = 240) |
| 1750 | :param tcp_est: TCP established timeout (Default value = 7440) |
| 1751 | :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1752 | """ |
| 1753 | return self.api( |
| 1754 | self.papi.nat64_set_timeouts, |
| 1755 | {'udp': udp, |
| 1756 | 'icmp': icmp, |
| 1757 | 'tcp_trans': tcp_trans, |
| 1758 | 'tcp_est': tcp_est, |
| 1759 | 'tcp_incoming_syn': tcp_incoming_syn}) |
| 1760 | |
| 1761 | def nat64_get_timeouts(self): |
| 1762 | """Get values of timeouts for NAT64 |
| 1763 | |
| 1764 | :return: Timeouts for NAT64 (in seconds) |
| 1765 | """ |
| 1766 | return self.api(self.papi.nat64_get_timeouts, {}) |
| 1767 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1768 | def nat64_st_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1769 | """Dump NAT64 session table |
| 1770 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1771 | :param protocol: IP protocol (Default value = 255, all STs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1772 | :returns: Dictionary of NAT64 sesstion table entries |
| 1773 | """ |
| 1774 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 1775 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1776 | def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1): |
| 1777 | """Add/del NAT64 prefix |
| 1778 | |
| 1779 | :param prefix: NAT64 prefix |
| 1780 | :param plen: NAT64 prefix length |
| 1781 | :param vrf_id: VRF id of tenant (Default 0) |
| 1782 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1783 | """ |
| 1784 | return self.api( |
| 1785 | self.papi.nat64_add_del_prefix, |
| 1786 | {'prefix': prefix, |
| 1787 | 'prefix_len': plen, |
| 1788 | 'vrf_id': vrf_id, |
| 1789 | 'is_add': is_add}) |
| 1790 | |
| 1791 | def nat64_prefix_dump(self): |
| 1792 | """Dump NAT64 prefix |
| 1793 | |
| 1794 | :returns: Dictionary of NAT64 prefixes |
| 1795 | """ |
| 1796 | return self.api(self.papi.nat64_prefix_dump, {}) |
| 1797 | |
Matus Fabian | 0938dcf | 2017-11-08 01:59:38 -0800 | [diff] [blame] | 1798 | def nat64_add_interface_addr( |
| 1799 | self, |
| 1800 | sw_if_index, |
| 1801 | is_add=1): |
| 1802 | """Add/del NAT64 address from interface |
| 1803 | |
| 1804 | :param sw_if_index: Software index of the interface |
| 1805 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1806 | """ |
| 1807 | return self.api(self.papi.nat64_add_del_interface_addr, |
| 1808 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1809 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 1810 | def dslite_set_aftr_addr(self, ip6, ip4): |
| 1811 | """Set DS-Lite AFTR addresses |
| 1812 | |
| 1813 | :param ip4: IPv4 address |
| 1814 | :param ip6: IPv6 address |
| 1815 | """ |
| 1816 | return self.api( |
| 1817 | self.papi.dslite_set_aftr_addr, |
| 1818 | {'ip4_addr': ip4, |
| 1819 | 'ip6_addr': ip6}) |
| 1820 | |
| 1821 | def dslite_add_del_pool_addr_range( |
| 1822 | self, |
| 1823 | start_addr, |
| 1824 | end_addr, |
| 1825 | is_add=1): |
| 1826 | """Add/del address range to DS-Lite pool |
| 1827 | |
| 1828 | :param start_addr: First IP address |
| 1829 | :param end_addr: Last IP address |
| 1830 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1831 | """ |
| 1832 | return self.api( |
| 1833 | self.papi.dslite_add_del_pool_addr_range, |
| 1834 | {'start_addr': start_addr, |
| 1835 | 'end_addr': end_addr, |
| 1836 | 'is_add': is_add}) |
| 1837 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1838 | def control_ping(self): |
| 1839 | self.api(self.papi.control_ping) |
| 1840 | |
| 1841 | 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] | 1842 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1843 | bfd_key_id=None, conf_key_id=None): |
| 1844 | if bfd_key_id is None: |
| 1845 | return self.api(self.papi.bfd_udp_add, |
| 1846 | { |
| 1847 | 'sw_if_index': sw_if_index, |
| 1848 | 'desired_min_tx': desired_min_tx, |
| 1849 | 'required_min_rx': required_min_rx, |
| 1850 | 'local_addr': local_addr, |
| 1851 | 'peer_addr': peer_addr, |
| 1852 | 'is_ipv6': is_ipv6, |
| 1853 | 'detect_mult': detect_mult, |
| 1854 | }) |
| 1855 | else: |
| 1856 | return self.api(self.papi.bfd_udp_add, |
| 1857 | { |
| 1858 | 'sw_if_index': sw_if_index, |
| 1859 | 'desired_min_tx': desired_min_tx, |
| 1860 | 'required_min_rx': required_min_rx, |
| 1861 | 'local_addr': local_addr, |
| 1862 | 'peer_addr': peer_addr, |
| 1863 | 'is_ipv6': is_ipv6, |
| 1864 | 'detect_mult': detect_mult, |
| 1865 | 'is_authenticated': 1, |
| 1866 | 'bfd_key_id': bfd_key_id, |
| 1867 | 'conf_key_id': conf_key_id, |
| 1868 | }) |
| 1869 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1870 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1871 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1872 | return self.api(self.papi.bfd_udp_mod, |
| 1873 | { |
| 1874 | 'sw_if_index': sw_if_index, |
| 1875 | 'desired_min_tx': desired_min_tx, |
| 1876 | 'required_min_rx': required_min_rx, |
| 1877 | 'local_addr': local_addr, |
| 1878 | 'peer_addr': peer_addr, |
| 1879 | 'is_ipv6': is_ipv6, |
| 1880 | 'detect_mult': detect_mult, |
| 1881 | }) |
| 1882 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1883 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1884 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1885 | is_delayed=False): |
| 1886 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1887 | { |
| 1888 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1889 | 'local_addr': local_addr, |
| 1890 | 'peer_addr': peer_addr, |
| 1891 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1892 | 'is_delayed': 1 if is_delayed else 0, |
| 1893 | 'bfd_key_id': bfd_key_id, |
| 1894 | 'conf_key_id': conf_key_id, |
| 1895 | }) |
| 1896 | |
| 1897 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1898 | is_ipv6=0, is_delayed=False): |
| 1899 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1900 | { |
| 1901 | 'sw_if_index': sw_if_index, |
| 1902 | 'local_addr': local_addr, |
| 1903 | 'peer_addr': peer_addr, |
| 1904 | 'is_ipv6': is_ipv6, |
| 1905 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1906 | }) |
| 1907 | |
| 1908 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1909 | return self.api(self.papi.bfd_udp_del, |
| 1910 | { |
| 1911 | 'sw_if_index': sw_if_index, |
| 1912 | 'local_addr': local_addr, |
| 1913 | 'peer_addr': peer_addr, |
| 1914 | 'is_ipv6': is_ipv6, |
| 1915 | }) |
| 1916 | |
| 1917 | def bfd_udp_session_dump(self): |
| 1918 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1919 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1920 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1921 | peer_addr, is_ipv6=0): |
| 1922 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1923 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1924 | 'sw_if_index': sw_if_index, |
| 1925 | 'local_addr': local_addr, |
| 1926 | 'peer_addr': peer_addr, |
| 1927 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1928 | }) |
| 1929 | |
| 1930 | def want_bfd_events(self, enable_disable=1): |
| 1931 | return self.api(self.papi.want_bfd_events, { |
| 1932 | 'enable_disable': enable_disable, |
| 1933 | 'pid': os.getpid(), |
| 1934 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1935 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1936 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1937 | return self.api(self.papi.bfd_auth_set_key, { |
| 1938 | 'conf_key_id': conf_key_id, |
| 1939 | 'auth_type': auth_type, |
| 1940 | 'key': key, |
| 1941 | 'key_len': len(key), |
| 1942 | }) |
| 1943 | |
| 1944 | def bfd_auth_del_key(self, conf_key_id): |
| 1945 | return self.api(self.papi.bfd_auth_del_key, { |
| 1946 | 'conf_key_id': conf_key_id, |
| 1947 | }) |
| 1948 | |
| 1949 | def bfd_auth_keys_dump(self): |
| 1950 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1951 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1952 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 1953 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 1954 | {'sw_if_index': sw_if_index}) |
| 1955 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1956 | def bfd_udp_del_echo_source(self): |
| 1957 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 1958 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1959 | def classify_add_del_table( |
| 1960 | self, |
| 1961 | is_add, |
| 1962 | mask, |
| 1963 | match_n_vectors=1, |
| 1964 | table_index=0xFFFFFFFF, |
| 1965 | nbuckets=2, |
| 1966 | memory_size=2097152, |
| 1967 | skip_n_vectors=0, |
| 1968 | next_table_index=0xFFFFFFFF, |
| 1969 | miss_next_index=0xFFFFFFFF, |
| 1970 | current_data_flag=0, |
| 1971 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1972 | """ |
| 1973 | :param is_add: |
| 1974 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1975 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1976 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1977 | :param nbuckets: (Default value = 2) |
| 1978 | :param memory_size: (Default value = 2097152) |
| 1979 | :param skip_n_vectors: (Default value = 0) |
| 1980 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1981 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1982 | :param current_data_flag: (Default value = 0) |
| 1983 | :param current_data_offset: (Default value = 0) |
| 1984 | """ |
| 1985 | |
| 1986 | return self.api( |
| 1987 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1988 | {'is_add': is_add, |
| 1989 | 'table_index': table_index, |
| 1990 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1991 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1992 | 'skip_n_vectors': skip_n_vectors, |
| 1993 | 'match_n_vectors': match_n_vectors, |
| 1994 | 'next_table_index': next_table_index, |
| 1995 | 'miss_next_index': miss_next_index, |
| 1996 | 'current_data_flag': current_data_flag, |
| 1997 | 'current_data_offset': current_data_offset, |
| 1998 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1999 | |
| 2000 | def classify_add_del_session( |
| 2001 | self, |
| 2002 | is_add, |
| 2003 | table_index, |
| 2004 | match, |
| 2005 | opaque_index=0xFFFFFFFF, |
| 2006 | hit_next_index=0xFFFFFFFF, |
| 2007 | advance=0, |
| 2008 | action=0, |
| 2009 | metadata=0): |
| 2010 | """ |
| 2011 | :param is_add: |
| 2012 | :param table_index: |
| 2013 | :param match: |
| 2014 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 2015 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 2016 | :param advance: (Default value = 0) |
| 2017 | :param action: (Default value = 0) |
| 2018 | :param metadata: (Default value = 0) |
| 2019 | """ |
| 2020 | |
| 2021 | return self.api( |
| 2022 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2023 | {'is_add': is_add, |
| 2024 | 'table_index': table_index, |
| 2025 | 'hit_next_index': hit_next_index, |
| 2026 | 'opaque_index': opaque_index, |
| 2027 | 'advance': advance, |
| 2028 | 'action': action, |
| 2029 | 'metadata': metadata, |
| 2030 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2031 | |
| 2032 | def input_acl_set_interface( |
| 2033 | self, |
| 2034 | is_add, |
| 2035 | sw_if_index, |
| 2036 | ip4_table_index=0xFFFFFFFF, |
| 2037 | ip6_table_index=0xFFFFFFFF, |
| 2038 | l2_table_index=0xFFFFFFFF): |
| 2039 | """ |
| 2040 | :param is_add: |
| 2041 | :param sw_if_index: |
| 2042 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2043 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2044 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2045 | """ |
| 2046 | |
| 2047 | return self.api( |
| 2048 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2049 | {'sw_if_index': sw_if_index, |
| 2050 | 'ip4_table_index': ip4_table_index, |
| 2051 | 'ip6_table_index': ip6_table_index, |
| 2052 | 'l2_table_index': l2_table_index, |
| 2053 | 'is_add': is_add}) |
| 2054 | |
| 2055 | def set_ipfix_exporter( |
| 2056 | self, |
| 2057 | collector_address, |
| 2058 | src_address, |
| 2059 | path_mtu, |
| 2060 | template_interval, |
| 2061 | vrf_id=0, |
| 2062 | collector_port=4739, |
| 2063 | udp_checksum=0): |
| 2064 | return self.api( |
| 2065 | self.papi.set_ipfix_exporter, |
| 2066 | { |
| 2067 | 'collector_address': collector_address, |
| 2068 | 'collector_port': collector_port, |
| 2069 | 'src_address': src_address, |
| 2070 | 'vrf_id': vrf_id, |
| 2071 | 'path_mtu': path_mtu, |
| 2072 | 'template_interval': template_interval, |
| 2073 | 'udp_checksum': udp_checksum, |
| 2074 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2075 | |
| 2076 | def dhcp_proxy_config(self, |
| 2077 | dhcp_server, |
| 2078 | dhcp_src_address, |
| 2079 | rx_table_id=0, |
| 2080 | server_table_id=0, |
| 2081 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2082 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2083 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2084 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2085 | { |
| 2086 | 'rx_vrf_id': rx_table_id, |
| 2087 | 'server_vrf_id': server_table_id, |
| 2088 | 'is_ipv6': is_ipv6, |
| 2089 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2090 | 'dhcp_server': dhcp_server, |
| 2091 | 'dhcp_src_address': dhcp_src_address, |
| 2092 | }) |
| 2093 | |
| 2094 | def dhcp_proxy_set_vss(self, |
| 2095 | table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2096 | vss_type=255, |
| 2097 | vpn_ascii_id="", |
| 2098 | oui=0, |
| 2099 | vpn_index=0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2100 | is_add=1, |
| 2101 | is_ip6=0): |
| 2102 | return self.api( |
| 2103 | self.papi.dhcp_proxy_set_vss, |
| 2104 | { |
| 2105 | 'tbl_id': table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2106 | 'vss_type': vss_type, |
| 2107 | 'vpn_ascii_id': vpn_ascii_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2108 | 'oui': oui, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2109 | 'vpn_index': vpn_index, |
| 2110 | 'is_add': is_add, |
| 2111 | 'is_ipv6': is_ip6, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2112 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2113 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2114 | def dhcp_client(self, |
| 2115 | sw_if_index, |
| 2116 | hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2117 | client_id='', |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2118 | is_add=1, |
| 2119 | want_dhcp_events=0): |
| 2120 | return self.api( |
| 2121 | self.papi.dhcp_client_config, |
| 2122 | { |
| 2123 | 'sw_if_index': sw_if_index, |
| 2124 | 'hostname': hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2125 | 'client_id': client_id, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2126 | 'is_add': is_add, |
| 2127 | 'want_dhcp_event': want_dhcp_events, |
| 2128 | 'pid': os.getpid(), |
| 2129 | }) |
| 2130 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2131 | def ip_mroute_add_del(self, |
| 2132 | src_address, |
| 2133 | grp_address, |
| 2134 | grp_address_length, |
| 2135 | e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2136 | next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2137 | next_hop_sw_if_index, |
| 2138 | i_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2139 | bier_imp=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2140 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2141 | table_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2142 | is_add=1, |
| 2143 | is_ipv6=0, |
| 2144 | is_local=0): |
| 2145 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2146 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2147 | """ |
| 2148 | return self.api( |
| 2149 | self.papi.ip_mroute_add_del, |
| 2150 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 2151 | 'entry_flags': e_flags, |
| 2152 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2153 | 'table_id': table_id, |
| 2154 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2155 | 'is_add': is_add, |
| 2156 | 'is_ipv6': is_ipv6, |
| 2157 | 'is_local': is_local, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2158 | 'bier_imp': bier_imp, |
| 2159 | 'next_hop_afi': next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2160 | 'grp_address_length': grp_address_length, |
| 2161 | 'grp_address': grp_address, |
| 2162 | 'src_address': src_address}) |
| 2163 | |
| 2164 | def mfib_signal_dump(self): |
| 2165 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 2166 | |
| 2167 | def ip_mfib_dump(self): |
| 2168 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2169 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2170 | def ip6_mfib_dump(self): |
| 2171 | return self.api(self.papi.ip6_mfib_dump, {}) |
| 2172 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2173 | def lisp_enable_disable(self, is_enabled): |
| 2174 | return self.api( |
| 2175 | self.papi.lisp_enable_disable, |
| 2176 | { |
| 2177 | 'is_en': is_enabled, |
| 2178 | }) |
| 2179 | |
| 2180 | def lisp_locator_set(self, |
| 2181 | ls_name, |
| 2182 | is_add=1): |
| 2183 | return self.api( |
| 2184 | self.papi.lisp_add_del_locator_set, |
| 2185 | { |
| 2186 | 'is_add': is_add, |
| 2187 | 'locator_set_name': ls_name |
| 2188 | }) |
| 2189 | |
| 2190 | def lisp_locator_set_dump(self): |
| 2191 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 2192 | |
| 2193 | def lisp_locator(self, |
| 2194 | ls_name, |
| 2195 | sw_if_index, |
| 2196 | priority=1, |
| 2197 | weight=1, |
| 2198 | is_add=1): |
| 2199 | return self.api( |
| 2200 | self.papi.lisp_add_del_locator, |
| 2201 | { |
| 2202 | 'is_add': is_add, |
| 2203 | 'locator_set_name': ls_name, |
| 2204 | 'sw_if_index': sw_if_index, |
| 2205 | 'priority': priority, |
| 2206 | 'weight': weight |
| 2207 | }) |
| 2208 | |
| 2209 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 2210 | return self.api( |
| 2211 | self.papi.lisp_locator_dump, |
| 2212 | { |
| 2213 | 'is_index_set': is_index_set, |
| 2214 | 'ls_name': ls_name, |
| 2215 | 'ls_index': ls_index, |
| 2216 | }) |
| 2217 | |
| 2218 | def lisp_local_mapping(self, |
| 2219 | ls_name, |
| 2220 | eid_type, |
| 2221 | eid, |
| 2222 | prefix_len, |
| 2223 | vni=0, |
| 2224 | key_id=0, |
| 2225 | key="", |
| 2226 | is_add=1): |
| 2227 | return self.api( |
| 2228 | self.papi.lisp_add_del_local_eid, |
| 2229 | { |
| 2230 | 'locator_set_name': ls_name, |
| 2231 | 'is_add': is_add, |
| 2232 | 'eid_type': eid_type, |
| 2233 | 'eid': eid, |
| 2234 | 'prefix_len': prefix_len, |
| 2235 | 'vni': vni, |
| 2236 | 'key_id': key_id, |
| 2237 | 'key': key |
| 2238 | }) |
| 2239 | |
| 2240 | def lisp_eid_table_dump(self, |
| 2241 | eid_set=0, |
| 2242 | prefix_length=0, |
| 2243 | vni=0, |
| 2244 | eid_type=0, |
| 2245 | eid=None, |
| 2246 | filter_opt=0): |
| 2247 | return self.api( |
| 2248 | self.papi.lisp_eid_table_dump, |
| 2249 | { |
| 2250 | 'eid_set': eid_set, |
| 2251 | 'prefix_length': prefix_length, |
| 2252 | 'vni': vni, |
| 2253 | 'eid_type': eid_type, |
| 2254 | 'eid': eid, |
| 2255 | 'filter': filter_opt, |
| 2256 | }) |
| 2257 | |
| 2258 | def lisp_remote_mapping(self, |
| 2259 | eid_type, |
| 2260 | eid, |
| 2261 | eid_prefix_len=0, |
| 2262 | vni=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 2263 | rlocs=[], |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2264 | rlocs_num=0, |
| 2265 | is_src_dst=0, |
| 2266 | is_add=1): |
| 2267 | return self.api( |
| 2268 | self.papi.lisp_add_del_remote_mapping, |
| 2269 | { |
| 2270 | 'is_add': is_add, |
| 2271 | 'eid_type': eid_type, |
| 2272 | 'eid': eid, |
| 2273 | 'eid_len': eid_prefix_len, |
| 2274 | 'rloc_num': rlocs_num, |
| 2275 | 'rlocs': rlocs, |
| 2276 | 'vni': vni, |
| 2277 | 'is_src_dst': is_src_dst, |
| 2278 | }) |
| 2279 | |
| 2280 | def lisp_adjacency(self, |
| 2281 | leid, |
| 2282 | reid, |
| 2283 | leid_len, |
| 2284 | reid_len, |
| 2285 | eid_type, |
| 2286 | is_add=1, |
| 2287 | vni=0): |
| 2288 | return self.api( |
| 2289 | self.papi.lisp_add_del_adjacency, |
| 2290 | { |
| 2291 | 'is_add': is_add, |
| 2292 | 'vni': vni, |
| 2293 | 'eid_type': eid_type, |
| 2294 | 'leid': leid, |
| 2295 | 'reid': reid, |
| 2296 | 'leid_len': leid_len, |
| 2297 | 'reid_len': reid_len, |
| 2298 | }) |
| 2299 | |
| 2300 | def lisp_adjacencies_get(self, vni=0): |
| 2301 | return self.api( |
| 2302 | self.papi.lisp_adjacencies_get, |
| 2303 | { |
| 2304 | 'vni': vni |
| 2305 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2306 | |
| 2307 | def map_add_domain(self, |
| 2308 | ip6_prefix, |
| 2309 | ip6_prefix_len, |
| 2310 | ip6_src, |
| 2311 | ip6_src_prefix_len, |
| 2312 | ip4_prefix, |
| 2313 | ip4_prefix_len, |
| 2314 | ea_bits_len=0, |
| 2315 | psid_offset=0, |
| 2316 | psid_length=0, |
| 2317 | is_translation=0, |
| 2318 | mtu=1280): |
| 2319 | return self.api( |
| 2320 | self.papi.map_add_domain, |
| 2321 | { |
| 2322 | 'ip6_prefix': ip6_prefix, |
| 2323 | 'ip6_prefix_len': ip6_prefix_len, |
| 2324 | 'ip4_prefix': ip4_prefix, |
| 2325 | 'ip4_prefix_len': ip4_prefix_len, |
| 2326 | 'ip6_src': ip6_src, |
| 2327 | 'ip6_src_prefix_len': ip6_src_prefix_len, |
| 2328 | 'ea_bits_len': ea_bits_len, |
| 2329 | 'psid_offset': psid_offset, |
| 2330 | 'psid_length': psid_length, |
| 2331 | 'is_translation': is_translation, |
| 2332 | 'mtu': mtu |
| 2333 | }) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2334 | |
| 2335 | def gtpu_add_del_tunnel( |
| 2336 | self, |
| 2337 | src_addr, |
| 2338 | dst_addr, |
| 2339 | is_add=1, |
| 2340 | is_ipv6=0, |
| 2341 | mcast_sw_if_index=0xFFFFFFFF, |
| 2342 | encap_vrf_id=0, |
| 2343 | decap_next_index=0xFFFFFFFF, |
| 2344 | teid=0): |
| 2345 | """ |
| 2346 | |
| 2347 | :param is_add: (Default value = 1) |
| 2348 | :param is_ipv6: (Default value = 0) |
| 2349 | :param src_addr: |
| 2350 | :param dst_addr: |
| 2351 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2352 | :param encap_vrf_id: (Default value = 0) |
| 2353 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2354 | :param teid: (Default value = 0) |
| 2355 | |
| 2356 | """ |
| 2357 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 2358 | {'is_add': is_add, |
| 2359 | 'is_ipv6': is_ipv6, |
| 2360 | 'src_address': src_addr, |
| 2361 | 'dst_address': dst_addr, |
| 2362 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2363 | 'encap_vrf_id': encap_vrf_id, |
| 2364 | 'decap_next_index': decap_next_index, |
| 2365 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 2366 | |
| 2367 | def vxlan_gpe_add_del_tunnel( |
| 2368 | self, |
| 2369 | src_addr, |
| 2370 | dst_addr, |
| 2371 | mcast_sw_if_index=0xFFFFFFFF, |
| 2372 | is_add=1, |
| 2373 | is_ipv6=0, |
| 2374 | encap_vrf_id=0, |
| 2375 | decap_vrf_id=0, |
| 2376 | protocol=3, |
| 2377 | vni=0): |
| 2378 | """ |
| 2379 | |
| 2380 | :param local: |
| 2381 | :param remote: |
| 2382 | :param is_add: (Default value = 1) |
| 2383 | :param is_ipv6: (Default value = 0) |
| 2384 | :param encap_vrf_id: (Default value = 0) |
| 2385 | :param decap_vrf_id: (Default value = 0) |
| 2386 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2387 | :param protocol: (Default value = 3) |
| 2388 | :param vni: (Default value = 0) |
| 2389 | |
| 2390 | """ |
| 2391 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 2392 | {'is_add': is_add, |
| 2393 | 'is_ipv6': is_ipv6, |
| 2394 | 'local': src_addr, |
| 2395 | 'remote': dst_addr, |
| 2396 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2397 | 'encap_vrf_id': encap_vrf_id, |
| 2398 | 'decap_vrf_id': decap_vrf_id, |
| 2399 | 'protocol': protocol, |
| 2400 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2401 | |
| 2402 | def pppoe_add_del_session( |
| 2403 | self, |
| 2404 | client_ip, |
| 2405 | client_mac, |
| 2406 | session_id=0, |
| 2407 | is_add=1, |
| 2408 | is_ipv6=0, |
| 2409 | decap_vrf_id=0): |
| 2410 | """ |
| 2411 | |
| 2412 | :param is_add: (Default value = 1) |
| 2413 | :param is_ipv6: (Default value = 0) |
| 2414 | :param client_ip: |
| 2415 | :param session_id: (Default value = 0) |
| 2416 | :param client_mac: |
| 2417 | :param decap_vrf_id: (Default value = 0) |
| 2418 | |
| 2419 | """ |
| 2420 | return self.api(self.papi.pppoe_add_del_session, |
| 2421 | {'is_add': is_add, |
| 2422 | 'is_ipv6': is_ipv6, |
| 2423 | 'session_id': session_id, |
| 2424 | 'client_ip': client_ip, |
| 2425 | 'decap_vrf_id': decap_vrf_id, |
| 2426 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2427 | |
| 2428 | def sr_localsid_add_del(self, |
| 2429 | localsid_addr, |
| 2430 | behavior, |
| 2431 | nh_addr, |
| 2432 | is_del=0, |
| 2433 | end_psp=0, |
| 2434 | sw_if_index=0xFFFFFFFF, |
| 2435 | vlan_index=0, |
| 2436 | fib_table=0, |
| 2437 | ): |
| 2438 | """ Add/del IPv6 SR local-SID. |
| 2439 | |
| 2440 | :param localsid_addr: |
| 2441 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 2442 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
| 2443 | :param nh_addr: |
| 2444 | :param is_del: (Default value = 0) |
| 2445 | :param end_psp: (Default value = 0) |
| 2446 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 2447 | :param vlan_index: (Default value = 0) |
| 2448 | :param fib_table: (Default value = 0) |
| 2449 | """ |
| 2450 | return self.api( |
| 2451 | self.papi.sr_localsid_add_del, |
| 2452 | {'is_del': is_del, |
| 2453 | 'localsid_addr': localsid_addr, |
| 2454 | 'end_psp': end_psp, |
| 2455 | 'behavior': behavior, |
| 2456 | 'sw_if_index': sw_if_index, |
| 2457 | 'vlan_index': vlan_index, |
| 2458 | 'fib_table': fib_table, |
| 2459 | 'nh_addr': nh_addr |
| 2460 | } |
| 2461 | ) |
| 2462 | |
| 2463 | def sr_policy_add( |
| 2464 | self, |
| 2465 | bsid_addr, |
| 2466 | weight=1, |
| 2467 | is_encap=1, |
| 2468 | type=0, |
| 2469 | fib_table=0, |
| 2470 | n_segments=0, |
| 2471 | segments=[]): |
| 2472 | """ |
| 2473 | :param bsid_addr: bindingSID of the SR Policy |
| 2474 | :param weight: weight of the sid list. optional. (default: 1) |
| 2475 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 2476 | (default: Encap) |
| 2477 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 2478 | (default: default) |
| 2479 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 2480 | (default: 0) |
| 2481 | :param n_segments: number of segments \ |
| 2482 | (default: 0) |
| 2483 | :param segments: a vector of IPv6 address composing the segment list \ |
| 2484 | (default: []) |
| 2485 | """ |
| 2486 | return self.api( |
| 2487 | self.papi.sr_policy_add, |
| 2488 | {'bsid_addr': bsid_addr, |
| 2489 | 'weight': weight, |
| 2490 | 'is_encap': is_encap, |
| 2491 | 'type': type, |
| 2492 | 'fib_table': fib_table, |
| 2493 | 'n_segments': n_segments, |
| 2494 | 'segments': segments |
| 2495 | } |
| 2496 | ) |
| 2497 | |
| 2498 | def sr_policy_del( |
| 2499 | self, |
| 2500 | bsid_addr, |
| 2501 | sr_policy_index=0): |
| 2502 | """ |
| 2503 | :param bsid: bindingSID of the SR Policy |
| 2504 | :param sr_policy_index: index of the sr policy (default: 0) |
| 2505 | """ |
| 2506 | return self.api( |
| 2507 | self.papi.sr_policy_del, |
| 2508 | {'bsid_addr': bsid_addr, |
| 2509 | 'sr_policy_index': sr_policy_index |
| 2510 | }) |
| 2511 | |
| 2512 | def sr_steering_add_del( |
| 2513 | self, |
| 2514 | is_del, |
| 2515 | bsid_addr, |
| 2516 | sr_policy_index, |
| 2517 | table_id, |
| 2518 | prefix_addr, |
| 2519 | mask_width, |
| 2520 | sw_if_index, |
| 2521 | traffic_type): |
| 2522 | """ |
| 2523 | Steer traffic L2 and L3 traffic through a given SR policy |
| 2524 | |
| 2525 | :param is_del: delete or add |
| 2526 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 2527 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 2528 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 2529 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 2530 | :param mask_width: is the mask for L3 traffic type |
| 2531 | :param sw_if_index: is the incoming interface for L2 traffic |
| 2532 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 2533 | """ |
| 2534 | return self.api( |
| 2535 | self.papi.sr_steering_add_del, |
| 2536 | {'is_del': is_del, |
| 2537 | 'bsid_addr': bsid_addr, |
| 2538 | 'sr_policy_index': sr_policy_index, |
| 2539 | 'table_id': table_id, |
| 2540 | 'prefix_addr': prefix_addr, |
| 2541 | 'mask_width': mask_width, |
| 2542 | 'sw_if_index': sw_if_index, |
| 2543 | 'traffic_type': traffic_type |
| 2544 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2545 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2546 | def acl_add_replace(self, acl_index, r, tag='', |
| 2547 | expected_retval=0): |
| 2548 | """Add/replace an ACL |
| 2549 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 2550 | :param acl_rule r: ACL rules array. |
| 2551 | :param str tag: symbolic tag (description) for this ACL. |
| 2552 | :param int count: number of rules. |
| 2553 | """ |
| 2554 | return self.api(self.papi.acl_add_replace, |
| 2555 | {'acl_index': acl_index, |
| 2556 | 'r': r, |
| 2557 | 'count': len(r), |
| 2558 | 'tag': tag}, |
| 2559 | expected_retval=expected_retval) |
| 2560 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 2561 | def acl_del(self, acl_index, expected_retval=0): |
| 2562 | """ |
| 2563 | |
| 2564 | :param acl_index: |
| 2565 | :return: |
| 2566 | """ |
| 2567 | return self.api(self.papi.acl_del, |
| 2568 | {'acl_index': acl_index}, |
| 2569 | expected_retval=expected_retval) |
| 2570 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2571 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 2572 | expected_retval=0): |
| 2573 | return self.api(self.papi.acl_interface_set_acl_list, |
| 2574 | {'sw_if_index': sw_if_index, |
| 2575 | 'count': len(acls), |
| 2576 | 'n_input': n_input, |
| 2577 | 'acls': acls}, |
| 2578 | expected_retval=expected_retval) |
| 2579 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 2580 | def acl_interface_add_del(self, |
| 2581 | sw_if_index, |
| 2582 | acl_index, |
| 2583 | is_add=1): |
| 2584 | """ Add/Delete ACL to/from interface |
| 2585 | |
| 2586 | :param sw_if_index: |
| 2587 | :param acl_index: |
| 2588 | :param is_add: (Default value = 1) |
| 2589 | """ |
| 2590 | |
| 2591 | return self.api(self.papi.acl_interface_add_del, |
| 2592 | {'is_add': is_add, |
| 2593 | 'is_input': 1, |
| 2594 | 'sw_if_index': sw_if_index, |
| 2595 | 'acl_index': acl_index}) |
| 2596 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2597 | def acl_dump(self, acl_index, expected_retval=0): |
| 2598 | return self.api(self.papi.acl_dump, |
| 2599 | {'acl_index': acl_index}, |
| 2600 | expected_retval=expected_retval) |
| 2601 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2602 | def macip_acl_add(self, rules, tag=""): |
| 2603 | """ Add MACIP acl |
| 2604 | |
| 2605 | :param rules: list of rules for given acl |
| 2606 | :param tag: acl tag |
| 2607 | """ |
| 2608 | |
| 2609 | return self.api(self.papi.macip_acl_add, |
| 2610 | {'r': rules, |
| 2611 | 'count': len(rules), |
| 2612 | 'tag': tag}) |
| 2613 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2614 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 2615 | """ Add MACIP acl |
| 2616 | |
| 2617 | :param rules: list of rules for given acl |
| 2618 | :param tag: acl tag |
| 2619 | """ |
| 2620 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2621 | return self.api(self.papi.macip_acl_add_replace, |
| 2622 | {'acl_index': acl_index, |
| 2623 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2624 | 'count': len(rules), |
| 2625 | 'tag': tag}) |
| 2626 | |
| 2627 | def macip_acl_del(self, acl_index): |
| 2628 | """ |
| 2629 | |
| 2630 | :param acl_index: |
| 2631 | :return: |
| 2632 | """ |
| 2633 | return self.api(self.papi.macip_acl_del, |
| 2634 | {'acl_index': acl_index}) |
| 2635 | |
| 2636 | def macip_acl_interface_add_del(self, |
| 2637 | sw_if_index, |
| 2638 | acl_index, |
| 2639 | is_add=1): |
| 2640 | """ Add MACIP acl to interface |
| 2641 | |
| 2642 | :param sw_if_index: |
| 2643 | :param acl_index: |
| 2644 | :param is_add: (Default value = 1) |
| 2645 | """ |
| 2646 | |
| 2647 | return self.api(self.papi.macip_acl_interface_add_del, |
| 2648 | {'is_add': is_add, |
| 2649 | 'sw_if_index': sw_if_index, |
| 2650 | 'acl_index': acl_index}) |
| 2651 | |
| 2652 | def macip_acl_interface_get(self): |
| 2653 | """ Return interface acls dump |
| 2654 | """ |
| 2655 | return self.api( |
| 2656 | self.papi.macip_acl_interface_get, {}) |
| 2657 | |
| 2658 | def macip_acl_dump(self, acl_index=4294967295): |
| 2659 | """ Return MACIP acl dump |
| 2660 | """ |
| 2661 | |
| 2662 | return self.api( |
| 2663 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2664 | |
| 2665 | def policer_add_del(self, |
| 2666 | name, |
| 2667 | cir, |
| 2668 | eir, |
| 2669 | cb, |
| 2670 | eb, |
| 2671 | is_add=1, |
| 2672 | rate_type=0, |
| 2673 | round_type=0, |
| 2674 | ptype=0, |
| 2675 | color_aware=0, |
| 2676 | conform_action_type=1, |
| 2677 | conform_dscp=0, |
| 2678 | exceed_action_type=0, |
| 2679 | exceed_dscp=0, |
| 2680 | violate_action_type=0, |
| 2681 | violate_dscp=0): |
| 2682 | return self.api(self.papi.policer_add_del, |
| 2683 | {'name': name, |
| 2684 | 'cir': cir, |
| 2685 | 'eir': eir, |
| 2686 | 'cb': cb, |
| 2687 | 'eb': eb, |
| 2688 | 'is_add': is_add, |
| 2689 | 'rate_type': rate_type, |
| 2690 | 'round_type': round_type, |
| 2691 | 'type': ptype, |
| 2692 | 'color_aware': color_aware, |
| 2693 | 'conform_action_type': conform_action_type, |
| 2694 | 'conform_dscp': conform_dscp, |
| 2695 | 'exceed_action_type': exceed_action_type, |
| 2696 | 'exceed_dscp': exceed_dscp, |
| 2697 | 'violate_action_type': violate_action_type, |
| 2698 | 'violate_dscp': violate_dscp}) |
| 2699 | |
| 2700 | def ip_punt_police(self, |
| 2701 | policer_index, |
| 2702 | is_ip6=0, |
| 2703 | is_add=1): |
| 2704 | return self.api(self.papi.ip_punt_police, |
| 2705 | {'policer_index': policer_index, |
| 2706 | 'is_add': is_add, |
| 2707 | 'is_ip6': is_ip6}) |
| 2708 | |
| 2709 | def ip_punt_redirect(self, |
| 2710 | rx_sw_if_index, |
| 2711 | tx_sw_if_index, |
| 2712 | nh, |
| 2713 | is_ip6=0, |
| 2714 | is_add=1): |
| 2715 | return self.api(self.papi.ip_punt_redirect, |
| 2716 | {'rx_sw_if_index': rx_sw_if_index, |
| 2717 | 'tx_sw_if_index': tx_sw_if_index, |
| 2718 | 'nh': nh, |
| 2719 | 'is_add': is_add, |
| 2720 | 'is_ip6': is_ip6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2721 | |
| 2722 | def bier_table_add_del(self, |
| 2723 | bti, |
| 2724 | mpls_label, |
| 2725 | is_add=1): |
| 2726 | """ BIER Table add/del """ |
| 2727 | return self.api( |
| 2728 | self.papi.bier_table_add_del, |
| 2729 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 2730 | "bt_sub_domain": bti.sub_domain_id, |
| 2731 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2732 | 'bt_label': mpls_label, |
| 2733 | 'bt_is_add': is_add}) |
| 2734 | |
| 2735 | def bier_table_dump(self): |
| 2736 | return self.api(self.papi.bier_table_dump, {}) |
| 2737 | |
| 2738 | def bier_route_add_del(self, |
| 2739 | bti, |
| 2740 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2741 | paths, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2742 | is_add=1): |
| 2743 | """ BIER Route add/del """ |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2744 | br_paths = [] |
| 2745 | for p in paths: |
| 2746 | br_paths.append({'next_hop': p.nh_addr, |
| 2747 | 'weight': 1, |
| 2748 | 'afi': 0, |
| 2749 | 'preference': 0, |
| 2750 | 'table_id': p.nh_table_id, |
| 2751 | 'next_hop_id': p.next_hop_id, |
| 2752 | 'is_udp_encap': p.is_udp_encap, |
| 2753 | 'n_labels': len(p.nh_labels), |
| 2754 | 'label_stack': p.nh_labels}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2755 | return self.api( |
| 2756 | self.papi.bier_route_add_del, |
| 2757 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2758 | "bt_sub_domain": bti.sub_domain_id, |
| 2759 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2760 | 'br_bp': bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2761 | 'br_n_paths': len(br_paths), |
| 2762 | 'br_paths': br_paths, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2763 | 'br_is_add': is_add}) |
| 2764 | |
| 2765 | def bier_route_dump(self, bti): |
| 2766 | return self.api( |
| 2767 | self.papi.bier_route_dump, |
| 2768 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2769 | "bt_sub_domain": bti.sub_domain_id, |
| 2770 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 2771 | |
| 2772 | def bier_imp_add(self, |
| 2773 | bti, |
| 2774 | src, |
| 2775 | ibytes, |
| 2776 | is_add=1): |
| 2777 | """ BIER Imposition Add """ |
| 2778 | return self.api( |
| 2779 | self.papi.bier_imp_add, |
| 2780 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 2781 | "bt_sub_domain": bti.sub_domain_id, |
| 2782 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2783 | 'bi_src': src, |
| 2784 | 'bi_n_bytes': len(ibytes), |
| 2785 | 'bi_bytes': ibytes}) |
| 2786 | |
| 2787 | def bier_imp_del(self, bi_index): |
| 2788 | """ BIER Imposition del """ |
| 2789 | return self.api( |
| 2790 | self.papi.bier_imp_del, |
| 2791 | {'bi_index': bi_index}) |
| 2792 | |
| 2793 | def bier_imp_dump(self): |
| 2794 | return self.api(self.papi.bier_imp_dump, {}) |
| 2795 | |
| 2796 | def bier_disp_table_add_del(self, |
| 2797 | bdti, |
| 2798 | is_add=1): |
| 2799 | """ BIER Disposition Table add/del """ |
| 2800 | return self.api( |
| 2801 | self.papi.bier_disp_table_add_del, |
| 2802 | {'bdt_tbl_id': bdti, |
| 2803 | 'bdt_is_add': is_add}) |
| 2804 | |
| 2805 | def bier_disp_table_dump(self): |
| 2806 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 2807 | |
| 2808 | def bier_disp_entry_add_del(self, |
| 2809 | bdti, |
| 2810 | bp, |
| 2811 | payload_proto, |
| 2812 | next_hop, |
| 2813 | next_hop_tbl_id=0, |
| 2814 | next_hop_rpf_id=~0, |
| 2815 | next_hop_is_ip4=1, |
| 2816 | is_add=1): |
| 2817 | """ BIER Route add/del """ |
| 2818 | return self.api( |
| 2819 | self.papi.bier_disp_entry_add_del, |
| 2820 | {'bde_tbl_id': bdti, |
| 2821 | 'bde_bp': bp, |
| 2822 | 'bde_payload_proto': payload_proto, |
| 2823 | 'bde_n_paths': 1, |
| 2824 | 'bde_paths': [{'next_hop': next_hop, |
| 2825 | 'table_id': next_hop_tbl_id, |
| 2826 | 'afi': 0, |
| 2827 | 'rpf_id': next_hop_rpf_id, |
| 2828 | 'n_labels': 0, |
| 2829 | 'label_stack': [0]}], |
| 2830 | 'bde_is_add': is_add}) |
| 2831 | |
| 2832 | def bier_disp_entry_dump(self, bdti): |
| 2833 | return self.api( |
| 2834 | self.papi.bier_disp_entry_dump, |
| 2835 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 2836 | |
| 2837 | def add_node_next(self, node_name, next_name): |
| 2838 | """ Set the next node for a given node request |
| 2839 | |
| 2840 | :param node_name: |
| 2841 | :param next_name: |
| 2842 | """ |
| 2843 | return self.api(self.papi.add_node_next, |
| 2844 | {'node_name': node_name, |
| 2845 | 'next_name': next_name}) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 2846 | |
| 2847 | def session_enable_disable(self, is_enabled): |
| 2848 | return self.api( |
| 2849 | self.papi.session_enable_disable, |
| 2850 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2851 | |
| 2852 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 2853 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 2854 | Sample CLI : 'ipsec spd add 1' |
| 2855 | |
| 2856 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 2857 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 2858 | optional |
| 2859 | :returns: reply from the API |
| 2860 | """ |
| 2861 | return self.api( |
| 2862 | self.papi.ipsec_spd_add_del, { |
| 2863 | 'spd_id': spd_id, 'is_add': is_add}) |
| 2864 | |
| 2865 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 2866 | """ IPSEC interface SPD add/del - \ |
| 2867 | Wrapper to associate/disassociate SPD to interface in VPP |
| 2868 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 2869 | |
| 2870 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 2871 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 2872 | association mandatory |
| 2873 | :param is_add - add(1) or del(0) association with interface \ |
| 2874 | (Default 1 - add) . optional |
| 2875 | :returns: reply from the API |
| 2876 | """ |
| 2877 | return self.api( |
| 2878 | self.papi.ipsec_interface_add_del_spd, { |
| 2879 | 'spd_id': spd_id, |
| 2880 | 'sw_if_index': sw_if_index, 'is_add': is_add}) |
| 2881 | |
| 2882 | def ipsec_sad_add_del_entry(self, |
| 2883 | sad_id, |
| 2884 | spi, |
| 2885 | tunnel_src_address='', |
| 2886 | tunnel_dst_address='', |
| 2887 | protocol=0, |
| 2888 | integrity_algorithm=2, |
| 2889 | integrity_key_length=0, |
| 2890 | integrity_key='C91KUR9GYMm5GfkEvNjX', |
| 2891 | crypto_algorithm=1, |
| 2892 | crypto_key_length=0, |
| 2893 | crypto_key='JPjyOWBeVEQiMe7h', |
| 2894 | is_add=1, |
| 2895 | is_tunnel=1): |
| 2896 | """ IPSEC SA add/del |
| 2897 | Sample CLI : 'ipsec sa add 10 spi 1001 esp \ |
| 2898 | crypto-key 4a506a794f574265564551694d653768 \ |
| 2899 | crypto-alg aes-cbc-128 \ |
| 2900 | integ-key 4339314b55523947594d6d3547666b45764e6a58 \ |
| 2901 | integ-alg sha1-96 tunnel-src 192.168.100.3 \ |
| 2902 | tunnel-dst 192.168.100.2' |
| 2903 | Sample CLI : 'ipsec sa add 20 spi 2001 \ |
| 2904 | integ-key 4339314b55523947594d6d3547666b45764e6a58 \ |
| 2905 | integ-alg sha1-96' |
| 2906 | |
| 2907 | :param sad_id - Security Association ID to be \ |
| 2908 | created or deleted. mandatory |
| 2909 | :param spi - security param index of the SA in decimal. mandatory |
| 2910 | :param tunnel_src_address - incase of tunnel mode outer src address .\ |
| 2911 | mandatory for tunnel mode |
| 2912 | :param tunnel_dst_address - incase of transport mode \ |
| 2913 | outer dst address. mandatory for tunnel mode |
| 2914 | :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional |
| 2915 | :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\ |
| 2916 | optional ** |
| 2917 | :param integrity_key - value in string \ |
| 2918 | (Default C91KUR9GYMm5GfkEvNjX).optional |
| 2919 | :param integrity_key_length - length of the key string in bytes\ |
| 2920 | (Default 0 - integrity disabled). optional |
| 2921 | :param crypto_algorithm - value range 1-11 Default \ |
| 2922 | (1- AES_CBC_128).optional ** |
| 2923 | :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional |
| 2924 | :param crypto_key_length - length of the key string in bytes\ |
| 2925 | (Default 0 - crypto disabled). optional |
| 2926 | :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\ |
| 2927 | optional |
| 2928 | :param is_tunnel - tunnel mode (1) or transport mode(0) \ |
| 2929 | (Default 1 - tunnel). optional |
| 2930 | :returns: reply from the API |
| 2931 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 2932 | crypto and ipsec algorithms |
| 2933 | """ |
| 2934 | return self.api( |
| 2935 | self.papi.ipsec_sad_add_del_entry, |
| 2936 | {'sad_id': sad_id, |
| 2937 | 'spi': spi, |
| 2938 | 'tunnel_src_address': tunnel_src_address, |
| 2939 | 'tunnel_dst_address': tunnel_dst_address, |
| 2940 | 'protocol': protocol, |
| 2941 | 'integrity_algorithm': integrity_algorithm, |
| 2942 | 'integrity_key_length': integrity_key_length, |
| 2943 | 'integrity_key': integrity_key, |
| 2944 | 'crypto_algorithm': crypto_algorithm, |
| 2945 | 'crypto_key_length': crypto_key_length, |
| 2946 | 'crypto_key': crypto_key, |
| 2947 | 'is_add': is_add, |
| 2948 | 'is_tunnel': is_tunnel}) |
| 2949 | |
| 2950 | def ipsec_spd_add_del_entry(self, |
| 2951 | spd_id, |
| 2952 | local_address_start, |
| 2953 | local_address_stop, |
| 2954 | remote_address_start, |
| 2955 | remote_address_stop, |
| 2956 | local_port_start=0, |
| 2957 | local_port_stop=65535, |
| 2958 | remote_port_start=0, |
| 2959 | remote_port_stop=65535, |
| 2960 | protocol=0, |
| 2961 | sa_id=10, |
| 2962 | policy=0, |
| 2963 | priority=100, |
| 2964 | is_outbound=1, |
| 2965 | is_add=1, |
| 2966 | is_ip_any=0): |
| 2967 | """ IPSEC policy SPD add/del - |
| 2968 | Wrapper to configure ipsec SPD policy entries in VPP |
| 2969 | Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \ |
| 2970 | protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \ |
| 2971 | remote-ip-range 192.168.3.3 - 192.168.3.3' |
| 2972 | |
| 2973 | :param spd_id - SPD ID for the policy . mandatory |
| 2974 | :param local_address_start - local-ip-range start address . mandatory |
| 2975 | :param local_address_stop - local-ip-range stop address . mandatory |
| 2976 | :param remote_address_start - remote-ip-range start address . mandatory |
| 2977 | :param remote_address_stop - remote-ip-range stop address . mandatory |
| 2978 | :param local_port_start - (Default 0) . optional |
| 2979 | :param local_port_stop - (Default 65535). optional |
| 2980 | :param remote_port_start - (Default 0). optional |
| 2981 | :param remote_port_stop - (Default 65535). optional |
| 2982 | :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any). |
| 2983 | optional |
| 2984 | :param sa_id - Security Association ID for mapping it to SPD |
| 2985 | (default 10). optional |
| 2986 | :param policy - bypass(0), discard(1), resolve(2) or protect(3)action |
| 2987 | (Default 0 - bypass). optional |
| 2988 | :param priotity - value for the spd action (Default 100). optional |
| 2989 | :param is_outbound - flag for inbound(0) or outbound(1) |
| 2990 | (Default 1 - outbound). optional |
| 2991 | :param is_add flag - for addition(1) or deletion(0) of the spd |
| 2992 | (Default 1 - addtion). optional |
| 2993 | :returns: reply from the API |
| 2994 | """ |
| 2995 | return self.api( |
| 2996 | self.papi.ipsec_spd_add_del_entry, |
| 2997 | {'spd_id': spd_id, |
| 2998 | 'local_address_start': local_address_start, |
| 2999 | 'local_address_stop': local_address_stop, |
| 3000 | 'remote_address_start': remote_address_start, |
| 3001 | 'remote_address_stop': remote_address_stop, |
| 3002 | 'local_port_start': local_port_start, |
| 3003 | 'local_port_stop': local_port_stop, |
| 3004 | 'remote_port_start': remote_port_start, |
| 3005 | 'remote_port_stop': remote_port_stop, |
| 3006 | 'is_add': is_add, |
| 3007 | 'protocol': protocol, |
| 3008 | 'policy': policy, |
| 3009 | 'priority': priority, |
| 3010 | 'is_outbound': is_outbound, |
| 3011 | 'sa_id': sa_id, |
| 3012 | 'is_ip_any': is_ip_any}) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 3013 | |
| 3014 | def app_namespace_add(self, |
| 3015 | namespace_id, |
| 3016 | ip4_fib_id=0, |
| 3017 | ip6_fib_id=0, |
| 3018 | sw_if_index=0xFFFFFFFF, |
| 3019 | secret=0): |
| 3020 | return self.api( |
| 3021 | self.papi.app_namespace_add_del, |
| 3022 | {'secret': secret, |
| 3023 | 'sw_if_index': sw_if_index, |
| 3024 | 'ip4_fib_id': ip4_fib_id, |
| 3025 | 'ip6_fib_id': ip6_fib_id, |
| 3026 | 'namespace_id': namespace_id, |
| 3027 | 'namespace_id_len': len(namespace_id)}) |