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