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 | |
| 1123 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1124 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1125 | {'mr_label': label, |
| 1126 | 'mr_eos': eos, |
| 1127 | 'mr_table_id': table_id, |
| 1128 | 'mr_classify_table_index': classify_table_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1129 | 'mr_is_add': is_add, |
| 1130 | 'mr_is_classify': is_classify, |
| 1131 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1132 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1133 | 'mr_is_resolve_host': is_resolve_host, |
| 1134 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1135 | 'mr_is_interface_rx': is_interface_rx, |
| 1136 | 'mr_is_rpf_id': is_rpf_id, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1137 | 'mr_next_hop_proto': next_hop_proto, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1138 | 'mr_next_hop_weight': next_hop_weight, |
| 1139 | 'mr_next_hop': next_hop_address, |
| 1140 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1141 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1142 | 'mr_next_hop_table_id': next_hop_table_id, |
| 1143 | 'mr_next_hop_via_label': next_hop_via_label, |
| 1144 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1145 | |
| 1146 | def mpls_ip_bind_unbind( |
| 1147 | self, |
| 1148 | label, |
| 1149 | dst_address, |
| 1150 | dst_address_length, |
| 1151 | table_id=0, |
| 1152 | ip_table_id=0, |
| 1153 | is_ip4=1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1154 | is_bind=1): |
| 1155 | """ |
| 1156 | """ |
| 1157 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1158 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1159 | {'mb_mpls_table_id': table_id, |
| 1160 | 'mb_label': label, |
| 1161 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1162 | 'mb_is_bind': is_bind, |
| 1163 | 'mb_is_ip4': is_ip4, |
| 1164 | 'mb_address_length': dst_address_length, |
| 1165 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1166 | |
| 1167 | def mpls_tunnel_add_del( |
| 1168 | self, |
| 1169 | tun_sw_if_index, |
| 1170 | next_hop_proto_is_ip4, |
| 1171 | next_hop_address, |
| 1172 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1173 | next_hop_table_id=0, |
| 1174 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1175 | next_hop_n_out_labels=0, |
| 1176 | next_hop_out_label_stack=[], |
| 1177 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1178 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1179 | l2_only=0, |
| 1180 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1181 | """ |
| 1182 | |
| 1183 | :param dst_address_length: |
| 1184 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1185 | :param dst_address: |
| 1186 | :param next_hop_address: |
| 1187 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1188 | :param vrf_id: (Default value = 0) |
| 1189 | :param lookup_in_vrf: (Default value = 0) |
| 1190 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1191 | :param is_add: (Default value = 1) |
| 1192 | :param is_drop: (Default value = 0) |
| 1193 | :param is_ipv6: (Default value = 0) |
| 1194 | :param is_local: (Default value = 0) |
| 1195 | :param is_classify: (Default value = 0) |
| 1196 | :param is_multipath: (Default value = 0) |
| 1197 | :param is_resolve_host: (Default value = 0) |
| 1198 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1199 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1200 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1201 | |
| 1202 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1203 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1204 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1205 | {'mt_sw_if_index': tun_sw_if_index, |
| 1206 | 'mt_is_add': is_add, |
| 1207 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1208 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1209 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 1210 | 'mt_next_hop_weight': next_hop_weight, |
| 1211 | 'mt_next_hop': next_hop_address, |
| 1212 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1213 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1214 | 'mt_next_hop_table_id': next_hop_table_id, |
| 1215 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1216 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1217 | def nat44_interface_add_del_feature( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1218 | self, |
| 1219 | sw_if_index, |
| 1220 | is_inside=1, |
| 1221 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1222 | """Enable/disable NAT44 feature on the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1223 | |
| 1224 | :param sw_if_index: Software index of the interface |
| 1225 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1226 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1227 | """ |
| 1228 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1229 | self.papi.nat44_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1230 | {'is_add': is_add, |
| 1231 | 'is_inside': is_inside, |
| 1232 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1233 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1234 | def nat44_interface_add_del_output_feature( |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1235 | self, |
| 1236 | sw_if_index, |
| 1237 | is_inside=1, |
| 1238 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1239 | """Enable/disable NAT44 output feature on the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1240 | |
| 1241 | :param sw_if_index: Software index of the interface |
| 1242 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1243 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1244 | """ |
| 1245 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1246 | self.papi.nat44_interface_add_del_output_feature, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1247 | {'is_add': is_add, |
| 1248 | 'is_inside': is_inside, |
| 1249 | 'sw_if_index': sw_if_index}) |
| 1250 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1251 | def nat44_add_del_static_mapping( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1252 | self, |
| 1253 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1254 | external_ip=0, |
| 1255 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1256 | local_port=0, |
| 1257 | external_port=0, |
| 1258 | addr_only=1, |
| 1259 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1260 | protocol=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1261 | twice_nat=0, |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1262 | out2in_only=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1263 | tag="", |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1264 | is_add=1): |
| 1265 | """Add/delete NAT44 static mapping |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1266 | |
| 1267 | :param local_ip: Local IP address |
| 1268 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1269 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1270 | :param local_port: Local port number (Default value = 0) |
| 1271 | :param external_port: External port number (Default value = 0) |
| 1272 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1273 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1274 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1275 | :param twice_nat: 1 if translate external host address and port |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1276 | :param out2in_only: if 1 rule is matching only out2in direction |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1277 | :param tag: Opaque string tag |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1278 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1279 | """ |
| 1280 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1281 | self.papi.nat44_add_del_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1282 | {'is_add': is_add, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1283 | 'addr_only': addr_only, |
| 1284 | 'local_ip_address': local_ip, |
| 1285 | 'external_ip_address': external_ip, |
| 1286 | 'local_port': local_port, |
| 1287 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1288 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1289 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1290 | 'protocol': protocol, |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1291 | 'twice_nat': twice_nat, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1292 | 'out2in_only': out2in_only, |
| 1293 | 'tag': tag}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1294 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1295 | def nat44_add_del_identity_mapping( |
| 1296 | self, |
| 1297 | ip='0', |
| 1298 | sw_if_index=0xFFFFFFFF, |
| 1299 | port=0, |
| 1300 | addr_only=1, |
| 1301 | vrf_id=0, |
| 1302 | protocol=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1303 | tag='', |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1304 | is_add=1): |
| 1305 | """Add/delete NAT44 identity mapping |
| 1306 | |
| 1307 | :param ip: IP address (Default value = 0) |
| 1308 | :param sw_if_index: Interface instead of IP address |
| 1309 | :param port: Port number (Default value = 0) |
| 1310 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1311 | :param vrf_id: VRF ID |
| 1312 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1313 | :param tag: Opaque string tag |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1314 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1315 | """ |
| 1316 | return self.api( |
| 1317 | self.papi.nat44_add_del_identity_mapping, |
| 1318 | {'is_add': is_add, |
| 1319 | 'addr_only': addr_only, |
| 1320 | 'ip_address': ip, |
| 1321 | 'port': port, |
| 1322 | 'sw_if_index': sw_if_index, |
| 1323 | 'vrf_id': vrf_id, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1324 | 'tag': tag, |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1325 | 'protocol': protocol}) |
| 1326 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1327 | def nat44_add_del_address_range( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1328 | self, |
| 1329 | first_ip_address, |
| 1330 | last_ip_address, |
| 1331 | is_add=1, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1332 | vrf_id=0xFFFFFFFF, |
| 1333 | twice_nat=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1334 | """Add/del NAT44 address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1335 | |
| 1336 | :param first_ip_address: First IP address |
| 1337 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1338 | :param vrf_id: VRF id for the address range |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1339 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1340 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1341 | """ |
| 1342 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1343 | self.papi.nat44_add_del_address_range, |
| 1344 | {'first_ip_address': first_ip_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1345 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1346 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1347 | 'twice_nat': twice_nat, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1348 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1349 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1350 | def nat44_address_dump(self): |
| 1351 | """Dump NAT44 addresses |
| 1352 | :return: Dictionary of NAT44 addresses |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1353 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1354 | return self.api(self.papi.nat44_address_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1355 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1356 | def nat44_interface_dump(self): |
| 1357 | """Dump interfaces with NAT44 feature |
| 1358 | :return: Dictionary of interfaces with NAT44 feature |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1359 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1360 | return self.api(self.papi.nat44_interface_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1361 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1362 | def nat44_interface_output_feature_dump(self): |
| 1363 | """Dump interfaces with NAT44 output feature |
| 1364 | :return: Dictionary of interfaces with NAT44 output feature |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1365 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1366 | return self.api(self.papi.nat44_interface_output_feature_dump, {}) |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1367 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1368 | def nat44_static_mapping_dump(self): |
| 1369 | """Dump NAT44 static mappings |
| 1370 | :return: Dictionary of NAT44 static mappings |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1371 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1372 | return self.api(self.papi.nat44_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1373 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1374 | def nat44_identity_mapping_dump(self): |
| 1375 | """Dump NAT44 identity mappings |
| 1376 | :return: Dictionary of NAT44 identity mappings |
| 1377 | """ |
| 1378 | return self.api(self.papi.nat44_identity_mapping_dump, {}) |
| 1379 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1380 | def nat_show_config(self): |
| 1381 | """Show NAT plugin config |
| 1382 | :return: NAT plugin config parameters |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1383 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1384 | return self.api(self.papi.nat_show_config, {}) |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1385 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1386 | def nat44_add_interface_addr( |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1387 | self, |
| 1388 | sw_if_index, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1389 | twice_nat=0, |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1390 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1391 | """Add/del NAT44 address from interface |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1392 | |
| 1393 | :param sw_if_index: Software index of the interface |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1394 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1395 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1396 | """ |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1397 | return self.api( |
| 1398 | self.papi.nat44_add_del_interface_addr, |
| 1399 | {'is_add': is_add, |
| 1400 | 'sw_if_index': sw_if_index, |
| 1401 | 'twice_nat': twice_nat}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1402 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1403 | def nat44_interface_addr_dump(self): |
| 1404 | """Dump NAT44 addresses interfaces |
| 1405 | :return: Dictionary of NAT44 addresses interfaces |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1406 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1407 | return self.api(self.papi.nat44_interface_addr_dump, {}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1408 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1409 | def nat_ipfix( |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1410 | self, |
| 1411 | domain_id=1, |
| 1412 | src_port=4739, |
| 1413 | enable=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1414 | """Enable/disable NAT IPFIX logging |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1415 | |
| 1416 | :param domain_id: Observation domain ID (Default value = 1) |
| 1417 | :param src_port: Source port number (Default value = 4739) |
| 1418 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1419 | """ |
| 1420 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1421 | self.papi.nat_ipfix_enable_disable, |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1422 | {'domain_id': domain_id, |
| 1423 | 'src_port': src_port, |
| 1424 | 'enable': enable}) |
| 1425 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1426 | def nat44_user_session_dump( |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1427 | self, |
| 1428 | ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1429 | vrf_id): |
| 1430 | """Dump NAT44 user's sessions |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1431 | |
| 1432 | :param ip_address: ip adress of the user to be dumped |
| 1433 | :param cpu_index: cpu_index on which the user is |
| 1434 | :param vrf_id: VRF ID |
| 1435 | :return: Dictionary of S-NAT sessions |
| 1436 | """ |
| 1437 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1438 | self.papi.nat44_user_session_dump, |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1439 | {'ip_address': ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1440 | 'vrf_id': vrf_id}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1441 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1442 | def nat44_user_dump(self): |
| 1443 | """Dump NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1444 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1445 | :return: Dictionary of NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1446 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1447 | return self.api(self.papi.nat44_user_dump, {}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1448 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1449 | def nat44_add_del_lb_static_mapping( |
| 1450 | self, |
| 1451 | external_addr, |
| 1452 | external_port, |
| 1453 | protocol, |
| 1454 | vrf_id=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1455 | twice_nat=0, |
Matus Fabian | 240b5ef | 2018-01-11 04:09:17 -0800 | [diff] [blame] | 1456 | out2in_only=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1457 | tag='', |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1458 | local_num=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 1459 | locals=[], |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1460 | is_add=1): |
| 1461 | """Add/delete NAT44 load balancing static mapping |
| 1462 | |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1463 | :param twice_nat: 1 if translate external host address and port |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1464 | :param tag: Opaque string tag |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1465 | :param is_add - 1 if add, 0 if delete |
| 1466 | """ |
| 1467 | return self.api( |
| 1468 | self.papi.nat44_add_del_lb_static_mapping, |
| 1469 | {'is_add': is_add, |
| 1470 | 'external_addr': external_addr, |
| 1471 | 'external_port': external_port, |
| 1472 | 'protocol': protocol, |
| 1473 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1474 | 'twice_nat': twice_nat, |
Matus Fabian | 240b5ef | 2018-01-11 04:09:17 -0800 | [diff] [blame] | 1475 | 'out2in_only': out2in_only, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1476 | 'tag': tag, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1477 | 'local_num': local_num, |
| 1478 | 'locals': locals}) |
| 1479 | |
| 1480 | def nat44_lb_static_mapping_dump(self): |
| 1481 | """Dump NAT44 load balancing static mappings |
| 1482 | |
| 1483 | :return: Dictionary of NAT44 load balancing static mapping |
| 1484 | """ |
| 1485 | return self.api(self.papi.nat44_lb_static_mapping_dump, {}) |
| 1486 | |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1487 | def nat44_del_session( |
| 1488 | self, |
| 1489 | addr, |
| 1490 | port, |
| 1491 | protocol, |
| 1492 | vrf_id=0, |
| 1493 | is_in=1): |
| 1494 | """Delete NAT44 session |
| 1495 | |
| 1496 | :param addr: IPv4 address |
| 1497 | :param por: port number |
| 1498 | :param protocol: IP protocol number |
| 1499 | :param vrf_id: VRF ID |
| 1500 | :param is_in: 1 if inside network addres and port pari, 0 if outside |
| 1501 | """ |
| 1502 | return self.api( |
| 1503 | self.papi.nat44_del_session, |
| 1504 | {'address': addr, |
| 1505 | 'port': port, |
| 1506 | 'protocol': protocol, |
| 1507 | 'vrf_id': vrf_id, |
| 1508 | 'is_in': is_in}) |
| 1509 | |
Juraj Sloboda | 7b92979 | 2017-11-23 13:20:48 +0100 | [diff] [blame] | 1510 | def nat44_forwarding_enable_disable( |
| 1511 | self, |
| 1512 | enable): |
| 1513 | """Enable/disable forwarding for NAT44 |
| 1514 | |
| 1515 | :param enable: 1 for enable, 0 for disable |
| 1516 | """ |
| 1517 | return self.api( |
| 1518 | self.papi.nat44_forwarding_enable_disable, |
| 1519 | {'enable': enable}) |
| 1520 | |
Matus Fabian | efcd1e9 | 2017-08-15 06:59:19 -0700 | [diff] [blame] | 1521 | def nat_set_reass( |
| 1522 | self, |
| 1523 | timeout=2, |
| 1524 | max_reass=1024, |
| 1525 | max_frag=5, |
| 1526 | drop_frag=0, |
| 1527 | is_ip6=0): |
| 1528 | """Set NAT virtual fragmentation reassembly |
| 1529 | |
| 1530 | :param timeout: reassembly timeout (Default 2sec) |
| 1531 | :param max_reass: maximum concurrent reassemblies (Default 1024) |
| 1532 | :param max_frag: maximum fragmets per reassembly (Default 5) |
| 1533 | :param drop_frag: if 0 translate fragments, otherwise drop fragments |
| 1534 | :param is_ip6: 1 if IPv6, 0 if IPv4 |
| 1535 | """ |
| 1536 | return self.api( |
| 1537 | self.papi.nat_set_reass, |
| 1538 | {'timeout': timeout, |
| 1539 | 'max_reass': max_reass, |
| 1540 | 'max_frag': max_frag, |
| 1541 | 'drop_frag': drop_frag, |
| 1542 | 'is_ip6': is_ip6}) |
| 1543 | |
| 1544 | def nat_get_reass(self): |
| 1545 | """Get NAT virtual fragmentation reassembly configuration |
| 1546 | |
| 1547 | :return: NAT virtual fragmentation reassembly configuration |
| 1548 | """ |
| 1549 | return self.api(self.papi.nat_get_reass, {}) |
| 1550 | |
| 1551 | def nat_reass_dump(self): |
| 1552 | """Dump NAT virtual fragmentation reassemblies |
| 1553 | |
| 1554 | :return: Dictionary of NAT virtual fragmentation reassemblies |
| 1555 | """ |
| 1556 | return self.api(self.papi.nat_reass_dump, {}) |
| 1557 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1558 | def nat_det_add_del_map( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1559 | self, |
| 1560 | in_addr, |
| 1561 | in_plen, |
| 1562 | out_addr, |
| 1563 | out_plen, |
| 1564 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1565 | """Add/delete deterministic NAT mapping |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1566 | |
| 1567 | :param is_add - 1 if add, 0 if delete |
| 1568 | :param in_addr - inside IP address |
| 1569 | :param in_plen - inside IP address prefix length |
| 1570 | :param out_addr - outside IP address |
| 1571 | :param out_plen - outside IP address prefix length |
| 1572 | """ |
| 1573 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1574 | self.papi.nat_det_add_del_map, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1575 | {'is_add': is_add, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1576 | 'is_nat44': 1, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1577 | 'in_addr': in_addr, |
| 1578 | 'in_plen': in_plen, |
| 1579 | 'out_addr': out_addr, |
| 1580 | 'out_plen': out_plen}) |
| 1581 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1582 | def nat_det_forward( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1583 | self, |
| 1584 | in_addr): |
| 1585 | """Get outside address and port range from inside address |
| 1586 | |
| 1587 | :param in_addr - inside IP address |
| 1588 | """ |
| 1589 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1590 | self.papi.nat_det_forward, |
| 1591 | {'in_addr': in_addr, |
| 1592 | 'is_nat44': 1}) |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1593 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1594 | def nat_det_reverse( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1595 | self, |
| 1596 | out_addr, |
| 1597 | out_port): |
| 1598 | """Get inside address from outside address and port |
| 1599 | |
| 1600 | :param out_addr - outside IP address |
| 1601 | :param out_port - outside port |
| 1602 | """ |
| 1603 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1604 | self.papi.nat_det_reverse, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1605 | {'out_addr': out_addr, |
| 1606 | 'out_port': out_port}) |
| 1607 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1608 | def nat_det_map_dump(self): |
| 1609 | """Dump deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1610 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1611 | :return: Dictionary of deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1612 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1613 | return self.api(self.papi.nat_det_map_dump, {}) |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1614 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1615 | def nat_det_set_timeouts( |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1616 | self, |
| 1617 | udp=300, |
| 1618 | tcp_established=7440, |
| 1619 | tcp_transitory=240, |
| 1620 | icmp=60): |
| 1621 | """Set values of timeouts for deterministic NAT (in seconds) |
| 1622 | |
| 1623 | :param udp - UDP timeout (Default value = 300) |
| 1624 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1625 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1626 | :param icmp - ICMP timeout (Default value = 60) |
| 1627 | """ |
| 1628 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1629 | self.papi.nat_det_set_timeouts, |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1630 | {'udp': udp, |
| 1631 | 'tcp_established': tcp_established, |
| 1632 | 'tcp_transitory': tcp_transitory, |
| 1633 | 'icmp': icmp}) |
| 1634 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1635 | def nat_det_get_timeouts(self): |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1636 | """Get values of timeouts for deterministic NAT |
| 1637 | |
| 1638 | :return: Timeouts for deterministic NAT (in seconds) |
| 1639 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1640 | return self.api(self.papi.nat_det_get_timeouts, {}) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1641 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1642 | def nat_det_close_session_out( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1643 | self, |
| 1644 | out_addr, |
| 1645 | out_port, |
| 1646 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1647 | ext_port): |
| 1648 | """Close deterministic NAT session using outside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1649 | |
| 1650 | :param out_addr - outside IP address |
| 1651 | :param out_port - outside port |
| 1652 | :param ext_addr - external host IP address |
| 1653 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1654 | """ |
| 1655 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1656 | self.papi.nat_det_close_session_out, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1657 | {'out_addr': out_addr, |
| 1658 | 'out_port': out_port, |
| 1659 | 'ext_addr': ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1660 | 'ext_port': ext_port}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1661 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1662 | def nat_det_close_session_in( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1663 | self, |
| 1664 | in_addr, |
| 1665 | in_port, |
| 1666 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1667 | ext_port): |
| 1668 | """Close deterministic NAT session using inside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1669 | |
| 1670 | :param in_addr - inside IP address |
| 1671 | :param in_port - inside port |
| 1672 | :param ext_addr - external host IP address |
| 1673 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1674 | """ |
| 1675 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1676 | self.papi.nat_det_close_session_in, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1677 | {'in_addr': in_addr, |
| 1678 | 'in_port': in_port, |
| 1679 | 'ext_addr': ext_addr, |
| 1680 | 'ext_port': ext_port, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1681 | 'is_nat44': 1}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1682 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1683 | def nat_det_session_dump( |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1684 | self, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1685 | user_addr): |
| 1686 | """Dump deterministic NAT sessions belonging to a user |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1687 | |
| 1688 | :param user_addr - inside IP address of the user |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1689 | :return: Dictionary of deterministic NAT sessions |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1690 | """ |
| 1691 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1692 | self.papi.nat_det_session_dump, |
| 1693 | {'is_nat44': 1, |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1694 | 'user_addr': user_addr}) |
| 1695 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1696 | def nat64_add_del_pool_addr_range( |
| 1697 | self, |
| 1698 | start_addr, |
| 1699 | end_addr, |
| 1700 | vrf_id=0xFFFFFFFF, |
| 1701 | is_add=1): |
| 1702 | """Add/del address range to NAT64 pool |
| 1703 | |
| 1704 | :param start_addr: First IP address |
| 1705 | :param end_addr: Last IP address |
| 1706 | :param vrf_id: VRF id for the address range |
| 1707 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1708 | """ |
| 1709 | return self.api( |
| 1710 | self.papi.nat64_add_del_pool_addr_range, |
| 1711 | {'start_addr': start_addr, |
| 1712 | 'end_addr': end_addr, |
| 1713 | 'vrf_id': vrf_id, |
| 1714 | 'is_add': is_add}) |
| 1715 | |
| 1716 | def nat64_pool_addr_dump(self): |
| 1717 | """Dump NAT64 pool addresses |
| 1718 | :return: Dictionary of NAT64 pool addresses |
| 1719 | """ |
| 1720 | return self.api(self.papi.nat64_pool_addr_dump, {}) |
| 1721 | |
| 1722 | def nat64_add_del_interface( |
| 1723 | self, |
| 1724 | sw_if_index, |
| 1725 | is_inside=1, |
| 1726 | is_add=1): |
| 1727 | """Enable/disable NAT64 feature on the interface |
| 1728 | :param sw_if_index: Index of the interface |
| 1729 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1730 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1731 | """ |
| 1732 | return self.api( |
| 1733 | self.papi.nat64_add_del_interface, |
| 1734 | {'sw_if_index': sw_if_index, |
| 1735 | 'is_inside': is_inside, |
| 1736 | 'is_add': is_add}) |
| 1737 | |
| 1738 | def nat64_interface_dump(self): |
| 1739 | """Dump interfaces with NAT64 feature |
| 1740 | :return: Dictionary of interfaces with NAT64 feature |
| 1741 | """ |
| 1742 | return self.api(self.papi.nat64_interface_dump, {}) |
| 1743 | |
| 1744 | def nat64_add_del_static_bib( |
| 1745 | self, |
| 1746 | in_ip, |
| 1747 | out_ip, |
| 1748 | in_port, |
| 1749 | out_port, |
| 1750 | protocol, |
| 1751 | vrf_id=0, |
| 1752 | is_add=1): |
| 1753 | """Add/delete S-NAT static BIB entry |
| 1754 | |
| 1755 | :param in_ip: Inside IPv6 address |
| 1756 | :param out_ip: Outside IPv4 address |
| 1757 | :param in_port: Inside port number |
| 1758 | :param out_port: Outside port number |
| 1759 | :param protocol: IP protocol |
| 1760 | :param vrf_id: VRF ID (Default value = 0) |
| 1761 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1762 | """ |
| 1763 | return self.api( |
| 1764 | self.papi.nat64_add_del_static_bib, |
| 1765 | {'i_addr': in_ip, |
| 1766 | 'o_addr': out_ip, |
| 1767 | 'i_port': in_port, |
| 1768 | 'o_port': out_port, |
| 1769 | 'vrf_id': vrf_id, |
| 1770 | 'proto': protocol, |
| 1771 | 'is_add': is_add}) |
| 1772 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1773 | def nat64_bib_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1774 | """Dump NAT64 BIB |
| 1775 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1776 | :param protocol: IP protocol (Default value = 255, all BIBs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1777 | :returns: Dictionary of NAT64 BIB entries |
| 1778 | """ |
| 1779 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 1780 | |
| 1781 | def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440, |
| 1782 | tcp_incoming_syn=6): |
| 1783 | """Set values of timeouts for NAT64 (in seconds) |
| 1784 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1785 | :param udpi: UDP timeout (Default value = 300) |
| 1786 | :param icmp: ICMP timeout (Default value = 60) |
| 1787 | :param tcp_trans: TCP transitory timeout (Default value = 240) |
| 1788 | :param tcp_est: TCP established timeout (Default value = 7440) |
| 1789 | :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1790 | """ |
| 1791 | return self.api( |
| 1792 | self.papi.nat64_set_timeouts, |
| 1793 | {'udp': udp, |
| 1794 | 'icmp': icmp, |
| 1795 | 'tcp_trans': tcp_trans, |
| 1796 | 'tcp_est': tcp_est, |
| 1797 | 'tcp_incoming_syn': tcp_incoming_syn}) |
| 1798 | |
| 1799 | def nat64_get_timeouts(self): |
| 1800 | """Get values of timeouts for NAT64 |
| 1801 | |
| 1802 | :return: Timeouts for NAT64 (in seconds) |
| 1803 | """ |
| 1804 | return self.api(self.papi.nat64_get_timeouts, {}) |
| 1805 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1806 | def nat64_st_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1807 | """Dump NAT64 session table |
| 1808 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1809 | :param protocol: IP protocol (Default value = 255, all STs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1810 | :returns: Dictionary of NAT64 sesstion table entries |
| 1811 | """ |
| 1812 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 1813 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1814 | def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1): |
| 1815 | """Add/del NAT64 prefix |
| 1816 | |
| 1817 | :param prefix: NAT64 prefix |
| 1818 | :param plen: NAT64 prefix length |
| 1819 | :param vrf_id: VRF id of tenant (Default 0) |
| 1820 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1821 | """ |
| 1822 | return self.api( |
| 1823 | self.papi.nat64_add_del_prefix, |
| 1824 | {'prefix': prefix, |
| 1825 | 'prefix_len': plen, |
| 1826 | 'vrf_id': vrf_id, |
| 1827 | 'is_add': is_add}) |
| 1828 | |
| 1829 | def nat64_prefix_dump(self): |
| 1830 | """Dump NAT64 prefix |
| 1831 | |
| 1832 | :returns: Dictionary of NAT64 prefixes |
| 1833 | """ |
| 1834 | return self.api(self.papi.nat64_prefix_dump, {}) |
| 1835 | |
Matus Fabian | 0938dcf | 2017-11-08 01:59:38 -0800 | [diff] [blame] | 1836 | def nat64_add_interface_addr( |
| 1837 | self, |
| 1838 | sw_if_index, |
| 1839 | is_add=1): |
| 1840 | """Add/del NAT64 address from interface |
| 1841 | |
| 1842 | :param sw_if_index: Software index of the interface |
| 1843 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1844 | """ |
| 1845 | return self.api(self.papi.nat64_add_del_interface_addr, |
| 1846 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1847 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 1848 | def dslite_set_aftr_addr(self, ip6, ip4): |
| 1849 | """Set DS-Lite AFTR addresses |
| 1850 | |
| 1851 | :param ip4: IPv4 address |
| 1852 | :param ip6: IPv6 address |
| 1853 | """ |
| 1854 | return self.api( |
| 1855 | self.papi.dslite_set_aftr_addr, |
| 1856 | {'ip4_addr': ip4, |
| 1857 | 'ip6_addr': ip6}) |
| 1858 | |
Juraj Sloboda | c5c6a33 | 2018-01-09 16:08:32 +0100 | [diff] [blame] | 1859 | def dslite_set_b4_addr(self, ip6, ip4): |
| 1860 | """Set DS-Lite B4 IPv6 address |
| 1861 | |
| 1862 | :param ip4: IPv4 address |
| 1863 | :param ip6: IPv6 address |
| 1864 | """ |
| 1865 | return self.api( |
| 1866 | self.papi.dslite_set_b4_addr, |
| 1867 | {'ip4_addr': ip4, |
| 1868 | 'ip6_addr': ip6}) |
| 1869 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 1870 | def dslite_add_del_pool_addr_range( |
| 1871 | self, |
| 1872 | start_addr, |
| 1873 | end_addr, |
| 1874 | is_add=1): |
| 1875 | """Add/del address range to DS-Lite pool |
| 1876 | |
| 1877 | :param start_addr: First IP address |
| 1878 | :param end_addr: Last IP address |
| 1879 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1880 | """ |
| 1881 | return self.api( |
| 1882 | self.papi.dslite_add_del_pool_addr_range, |
| 1883 | {'start_addr': start_addr, |
| 1884 | 'end_addr': end_addr, |
| 1885 | 'is_add': is_add}) |
| 1886 | |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 1887 | def nat66_add_del_interface( |
| 1888 | self, |
| 1889 | sw_if_index, |
| 1890 | is_inside=1, |
| 1891 | is_add=1): |
| 1892 | """Enable/disable NAT66 feature on the interface |
| 1893 | :param sw_if_index: Index of the interface |
| 1894 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1895 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1896 | """ |
| 1897 | return self.api( |
| 1898 | self.papi.nat66_add_del_interface, |
| 1899 | {'sw_if_index': sw_if_index, |
| 1900 | 'is_inside': is_inside, |
| 1901 | 'is_add': is_add}) |
| 1902 | |
| 1903 | def nat66_add_del_static_mapping( |
| 1904 | self, |
| 1905 | in_ip, |
| 1906 | out_ip, |
| 1907 | vrf_id=0, |
| 1908 | is_add=1): |
| 1909 | """Add/delete NAT66 static mapping |
| 1910 | |
| 1911 | :param in_ip: Inside IPv6 address |
| 1912 | :param out_ip: Outside IPv6 address |
| 1913 | :param vrf_id: VRF ID (Default value = 0) |
| 1914 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1915 | """ |
| 1916 | return self.api( |
| 1917 | self.papi.nat66_add_del_static_mapping, |
| 1918 | {'local_ip_address': in_ip, |
| 1919 | 'external_ip_address': out_ip, |
| 1920 | 'vrf_id': vrf_id, |
| 1921 | 'is_add': is_add}) |
| 1922 | |
| 1923 | def nat66_interface_dump(self): |
| 1924 | """Dump interfaces with NAT66 feature |
| 1925 | :return: Dictionary of interfaces with NAT66 feature |
| 1926 | """ |
| 1927 | return self.api(self.papi.nat66_interface_dump, {}) |
| 1928 | |
| 1929 | def nat66_static_mapping_dump(self): |
| 1930 | """Dump NAT66 static mappings |
| 1931 | :return: Dictionary of NAT66 static mappings |
| 1932 | """ |
| 1933 | return self.api(self.papi.nat66_static_mapping_dump, {}) |
| 1934 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1935 | def control_ping(self): |
| 1936 | self.api(self.papi.control_ping) |
| 1937 | |
| 1938 | 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] | 1939 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1940 | bfd_key_id=None, conf_key_id=None): |
| 1941 | if bfd_key_id is None: |
| 1942 | return self.api(self.papi.bfd_udp_add, |
| 1943 | { |
| 1944 | 'sw_if_index': sw_if_index, |
| 1945 | 'desired_min_tx': desired_min_tx, |
| 1946 | 'required_min_rx': required_min_rx, |
| 1947 | 'local_addr': local_addr, |
| 1948 | 'peer_addr': peer_addr, |
| 1949 | 'is_ipv6': is_ipv6, |
| 1950 | 'detect_mult': detect_mult, |
| 1951 | }) |
| 1952 | else: |
| 1953 | return self.api(self.papi.bfd_udp_add, |
| 1954 | { |
| 1955 | 'sw_if_index': sw_if_index, |
| 1956 | 'desired_min_tx': desired_min_tx, |
| 1957 | 'required_min_rx': required_min_rx, |
| 1958 | 'local_addr': local_addr, |
| 1959 | 'peer_addr': peer_addr, |
| 1960 | 'is_ipv6': is_ipv6, |
| 1961 | 'detect_mult': detect_mult, |
| 1962 | 'is_authenticated': 1, |
| 1963 | 'bfd_key_id': bfd_key_id, |
| 1964 | 'conf_key_id': conf_key_id, |
| 1965 | }) |
| 1966 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1967 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1968 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1969 | return self.api(self.papi.bfd_udp_mod, |
| 1970 | { |
| 1971 | 'sw_if_index': sw_if_index, |
| 1972 | 'desired_min_tx': desired_min_tx, |
| 1973 | 'required_min_rx': required_min_rx, |
| 1974 | 'local_addr': local_addr, |
| 1975 | 'peer_addr': peer_addr, |
| 1976 | 'is_ipv6': is_ipv6, |
| 1977 | 'detect_mult': detect_mult, |
| 1978 | }) |
| 1979 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1980 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1981 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1982 | is_delayed=False): |
| 1983 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1984 | { |
| 1985 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1986 | 'local_addr': local_addr, |
| 1987 | 'peer_addr': peer_addr, |
| 1988 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1989 | 'is_delayed': 1 if is_delayed else 0, |
| 1990 | 'bfd_key_id': bfd_key_id, |
| 1991 | 'conf_key_id': conf_key_id, |
| 1992 | }) |
| 1993 | |
| 1994 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1995 | is_ipv6=0, is_delayed=False): |
| 1996 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1997 | { |
| 1998 | 'sw_if_index': sw_if_index, |
| 1999 | 'local_addr': local_addr, |
| 2000 | 'peer_addr': peer_addr, |
| 2001 | 'is_ipv6': is_ipv6, |
| 2002 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2003 | }) |
| 2004 | |
| 2005 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 2006 | return self.api(self.papi.bfd_udp_del, |
| 2007 | { |
| 2008 | 'sw_if_index': sw_if_index, |
| 2009 | 'local_addr': local_addr, |
| 2010 | 'peer_addr': peer_addr, |
| 2011 | 'is_ipv6': is_ipv6, |
| 2012 | }) |
| 2013 | |
| 2014 | def bfd_udp_session_dump(self): |
| 2015 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 2016 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2017 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 2018 | peer_addr, is_ipv6=0): |
| 2019 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2020 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2021 | 'sw_if_index': sw_if_index, |
| 2022 | 'local_addr': local_addr, |
| 2023 | 'peer_addr': peer_addr, |
| 2024 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2025 | }) |
| 2026 | |
| 2027 | def want_bfd_events(self, enable_disable=1): |
| 2028 | return self.api(self.papi.want_bfd_events, { |
| 2029 | 'enable_disable': enable_disable, |
| 2030 | 'pid': os.getpid(), |
| 2031 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2032 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2033 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 2034 | return self.api(self.papi.bfd_auth_set_key, { |
| 2035 | 'conf_key_id': conf_key_id, |
| 2036 | 'auth_type': auth_type, |
| 2037 | 'key': key, |
| 2038 | 'key_len': len(key), |
| 2039 | }) |
| 2040 | |
| 2041 | def bfd_auth_del_key(self, conf_key_id): |
| 2042 | return self.api(self.papi.bfd_auth_del_key, { |
| 2043 | 'conf_key_id': conf_key_id, |
| 2044 | }) |
| 2045 | |
| 2046 | def bfd_auth_keys_dump(self): |
| 2047 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 2048 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2049 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 2050 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 2051 | {'sw_if_index': sw_if_index}) |
| 2052 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2053 | def bfd_udp_del_echo_source(self): |
| 2054 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 2055 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2056 | def classify_add_del_table( |
| 2057 | self, |
| 2058 | is_add, |
| 2059 | mask, |
| 2060 | match_n_vectors=1, |
| 2061 | table_index=0xFFFFFFFF, |
| 2062 | nbuckets=2, |
| 2063 | memory_size=2097152, |
| 2064 | skip_n_vectors=0, |
| 2065 | next_table_index=0xFFFFFFFF, |
| 2066 | miss_next_index=0xFFFFFFFF, |
| 2067 | current_data_flag=0, |
| 2068 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2069 | """ |
| 2070 | :param is_add: |
| 2071 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 2072 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 2073 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2074 | :param nbuckets: (Default value = 2) |
| 2075 | :param memory_size: (Default value = 2097152) |
| 2076 | :param skip_n_vectors: (Default value = 0) |
| 2077 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 2078 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 2079 | :param current_data_flag: (Default value = 0) |
| 2080 | :param current_data_offset: (Default value = 0) |
| 2081 | """ |
| 2082 | |
| 2083 | return self.api( |
| 2084 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2085 | {'is_add': is_add, |
| 2086 | 'table_index': table_index, |
| 2087 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2088 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2089 | 'skip_n_vectors': skip_n_vectors, |
| 2090 | 'match_n_vectors': match_n_vectors, |
| 2091 | 'next_table_index': next_table_index, |
| 2092 | 'miss_next_index': miss_next_index, |
| 2093 | 'current_data_flag': current_data_flag, |
| 2094 | 'current_data_offset': current_data_offset, |
| 2095 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2096 | |
| 2097 | def classify_add_del_session( |
| 2098 | self, |
| 2099 | is_add, |
| 2100 | table_index, |
| 2101 | match, |
| 2102 | opaque_index=0xFFFFFFFF, |
| 2103 | hit_next_index=0xFFFFFFFF, |
| 2104 | advance=0, |
| 2105 | action=0, |
| 2106 | metadata=0): |
| 2107 | """ |
| 2108 | :param is_add: |
| 2109 | :param table_index: |
| 2110 | :param match: |
| 2111 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 2112 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 2113 | :param advance: (Default value = 0) |
| 2114 | :param action: (Default value = 0) |
| 2115 | :param metadata: (Default value = 0) |
| 2116 | """ |
| 2117 | |
| 2118 | return self.api( |
| 2119 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2120 | {'is_add': is_add, |
| 2121 | 'table_index': table_index, |
| 2122 | 'hit_next_index': hit_next_index, |
| 2123 | 'opaque_index': opaque_index, |
| 2124 | 'advance': advance, |
| 2125 | 'action': action, |
| 2126 | 'metadata': metadata, |
| 2127 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2128 | |
| 2129 | def input_acl_set_interface( |
| 2130 | self, |
| 2131 | is_add, |
| 2132 | sw_if_index, |
| 2133 | ip4_table_index=0xFFFFFFFF, |
| 2134 | ip6_table_index=0xFFFFFFFF, |
| 2135 | l2_table_index=0xFFFFFFFF): |
| 2136 | """ |
| 2137 | :param is_add: |
| 2138 | :param sw_if_index: |
| 2139 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2140 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2141 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2142 | """ |
| 2143 | |
| 2144 | return self.api( |
| 2145 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2146 | {'sw_if_index': sw_if_index, |
| 2147 | 'ip4_table_index': ip4_table_index, |
| 2148 | 'ip6_table_index': ip6_table_index, |
| 2149 | 'l2_table_index': l2_table_index, |
| 2150 | 'is_add': is_add}) |
| 2151 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 2152 | def output_acl_set_interface( |
| 2153 | self, |
| 2154 | is_add, |
| 2155 | sw_if_index, |
| 2156 | ip4_table_index=0xFFFFFFFF, |
| 2157 | ip6_table_index=0xFFFFFFFF, |
| 2158 | l2_table_index=0xFFFFFFFF): |
| 2159 | """ |
| 2160 | :param is_add: |
| 2161 | :param sw_if_index: |
| 2162 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2163 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2164 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2165 | """ |
| 2166 | |
| 2167 | return self.api( |
| 2168 | self.papi.output_acl_set_interface, |
| 2169 | {'sw_if_index': sw_if_index, |
| 2170 | 'ip4_table_index': ip4_table_index, |
| 2171 | 'ip6_table_index': ip6_table_index, |
| 2172 | 'l2_table_index': l2_table_index, |
| 2173 | 'is_add': is_add}) |
| 2174 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2175 | def set_ipfix_exporter( |
| 2176 | self, |
| 2177 | collector_address, |
| 2178 | src_address, |
| 2179 | path_mtu, |
| 2180 | template_interval, |
| 2181 | vrf_id=0, |
| 2182 | collector_port=4739, |
| 2183 | udp_checksum=0): |
| 2184 | return self.api( |
| 2185 | self.papi.set_ipfix_exporter, |
| 2186 | { |
| 2187 | 'collector_address': collector_address, |
| 2188 | 'collector_port': collector_port, |
| 2189 | 'src_address': src_address, |
| 2190 | 'vrf_id': vrf_id, |
| 2191 | 'path_mtu': path_mtu, |
| 2192 | 'template_interval': template_interval, |
| 2193 | 'udp_checksum': udp_checksum, |
| 2194 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2195 | |
| 2196 | def dhcp_proxy_config(self, |
| 2197 | dhcp_server, |
| 2198 | dhcp_src_address, |
| 2199 | rx_table_id=0, |
| 2200 | server_table_id=0, |
| 2201 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2202 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2203 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2204 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2205 | { |
| 2206 | 'rx_vrf_id': rx_table_id, |
| 2207 | 'server_vrf_id': server_table_id, |
| 2208 | 'is_ipv6': is_ipv6, |
| 2209 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2210 | 'dhcp_server': dhcp_server, |
| 2211 | 'dhcp_src_address': dhcp_src_address, |
| 2212 | }) |
| 2213 | |
| 2214 | def dhcp_proxy_set_vss(self, |
| 2215 | table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2216 | vss_type=255, |
| 2217 | vpn_ascii_id="", |
| 2218 | oui=0, |
| 2219 | vpn_index=0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2220 | is_add=1, |
| 2221 | is_ip6=0): |
| 2222 | return self.api( |
| 2223 | self.papi.dhcp_proxy_set_vss, |
| 2224 | { |
| 2225 | 'tbl_id': table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2226 | 'vss_type': vss_type, |
| 2227 | 'vpn_ascii_id': vpn_ascii_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2228 | 'oui': oui, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2229 | 'vpn_index': vpn_index, |
| 2230 | 'is_add': is_add, |
| 2231 | 'is_ipv6': is_ip6, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2232 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2233 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2234 | def dhcp_client(self, |
| 2235 | sw_if_index, |
| 2236 | hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2237 | client_id='', |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2238 | is_add=1, |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 2239 | set_broadcast_flag=1, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2240 | want_dhcp_events=0): |
| 2241 | return self.api( |
| 2242 | self.papi.dhcp_client_config, |
| 2243 | { |
| 2244 | 'sw_if_index': sw_if_index, |
| 2245 | 'hostname': hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2246 | 'client_id': client_id, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2247 | 'is_add': is_add, |
| 2248 | 'want_dhcp_event': want_dhcp_events, |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 2249 | 'set_broadcast_flag': set_broadcast_flag, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2250 | 'pid': os.getpid(), |
| 2251 | }) |
| 2252 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2253 | def ip_mroute_add_del(self, |
| 2254 | src_address, |
| 2255 | grp_address, |
| 2256 | grp_address_length, |
| 2257 | e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2258 | next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2259 | next_hop_sw_if_index, |
| 2260 | i_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2261 | bier_imp=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2262 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2263 | table_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2264 | is_add=1, |
| 2265 | is_ipv6=0, |
| 2266 | is_local=0): |
| 2267 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2268 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2269 | """ |
| 2270 | return self.api( |
| 2271 | self.papi.ip_mroute_add_del, |
| 2272 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 2273 | 'entry_flags': e_flags, |
| 2274 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2275 | 'table_id': table_id, |
| 2276 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2277 | 'is_add': is_add, |
| 2278 | 'is_ipv6': is_ipv6, |
| 2279 | 'is_local': is_local, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2280 | 'bier_imp': bier_imp, |
| 2281 | 'next_hop_afi': next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2282 | 'grp_address_length': grp_address_length, |
| 2283 | 'grp_address': grp_address, |
| 2284 | 'src_address': src_address}) |
| 2285 | |
| 2286 | def mfib_signal_dump(self): |
| 2287 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 2288 | |
| 2289 | def ip_mfib_dump(self): |
| 2290 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2291 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2292 | def ip6_mfib_dump(self): |
| 2293 | return self.api(self.papi.ip6_mfib_dump, {}) |
| 2294 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2295 | def lisp_enable_disable(self, is_enabled): |
| 2296 | return self.api( |
| 2297 | self.papi.lisp_enable_disable, |
| 2298 | { |
| 2299 | 'is_en': is_enabled, |
| 2300 | }) |
| 2301 | |
| 2302 | def lisp_locator_set(self, |
| 2303 | ls_name, |
| 2304 | is_add=1): |
| 2305 | return self.api( |
| 2306 | self.papi.lisp_add_del_locator_set, |
| 2307 | { |
| 2308 | 'is_add': is_add, |
| 2309 | 'locator_set_name': ls_name |
| 2310 | }) |
| 2311 | |
| 2312 | def lisp_locator_set_dump(self): |
| 2313 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 2314 | |
| 2315 | def lisp_locator(self, |
| 2316 | ls_name, |
| 2317 | sw_if_index, |
| 2318 | priority=1, |
| 2319 | weight=1, |
| 2320 | is_add=1): |
| 2321 | return self.api( |
| 2322 | self.papi.lisp_add_del_locator, |
| 2323 | { |
| 2324 | 'is_add': is_add, |
| 2325 | 'locator_set_name': ls_name, |
| 2326 | 'sw_if_index': sw_if_index, |
| 2327 | 'priority': priority, |
| 2328 | 'weight': weight |
| 2329 | }) |
| 2330 | |
| 2331 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 2332 | return self.api( |
| 2333 | self.papi.lisp_locator_dump, |
| 2334 | { |
| 2335 | 'is_index_set': is_index_set, |
| 2336 | 'ls_name': ls_name, |
| 2337 | 'ls_index': ls_index, |
| 2338 | }) |
| 2339 | |
| 2340 | def lisp_local_mapping(self, |
| 2341 | ls_name, |
| 2342 | eid_type, |
| 2343 | eid, |
| 2344 | prefix_len, |
| 2345 | vni=0, |
| 2346 | key_id=0, |
| 2347 | key="", |
| 2348 | is_add=1): |
| 2349 | return self.api( |
| 2350 | self.papi.lisp_add_del_local_eid, |
| 2351 | { |
| 2352 | 'locator_set_name': ls_name, |
| 2353 | 'is_add': is_add, |
| 2354 | 'eid_type': eid_type, |
| 2355 | 'eid': eid, |
| 2356 | 'prefix_len': prefix_len, |
| 2357 | 'vni': vni, |
| 2358 | 'key_id': key_id, |
| 2359 | 'key': key |
| 2360 | }) |
| 2361 | |
| 2362 | def lisp_eid_table_dump(self, |
| 2363 | eid_set=0, |
| 2364 | prefix_length=0, |
| 2365 | vni=0, |
| 2366 | eid_type=0, |
| 2367 | eid=None, |
| 2368 | filter_opt=0): |
| 2369 | return self.api( |
| 2370 | self.papi.lisp_eid_table_dump, |
| 2371 | { |
| 2372 | 'eid_set': eid_set, |
| 2373 | 'prefix_length': prefix_length, |
| 2374 | 'vni': vni, |
| 2375 | 'eid_type': eid_type, |
| 2376 | 'eid': eid, |
| 2377 | 'filter': filter_opt, |
| 2378 | }) |
| 2379 | |
| 2380 | def lisp_remote_mapping(self, |
| 2381 | eid_type, |
| 2382 | eid, |
| 2383 | eid_prefix_len=0, |
| 2384 | vni=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 2385 | rlocs=[], |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2386 | rlocs_num=0, |
| 2387 | is_src_dst=0, |
| 2388 | is_add=1): |
| 2389 | return self.api( |
| 2390 | self.papi.lisp_add_del_remote_mapping, |
| 2391 | { |
| 2392 | 'is_add': is_add, |
| 2393 | 'eid_type': eid_type, |
| 2394 | 'eid': eid, |
| 2395 | 'eid_len': eid_prefix_len, |
| 2396 | 'rloc_num': rlocs_num, |
| 2397 | 'rlocs': rlocs, |
| 2398 | 'vni': vni, |
| 2399 | 'is_src_dst': is_src_dst, |
| 2400 | }) |
| 2401 | |
| 2402 | def lisp_adjacency(self, |
| 2403 | leid, |
| 2404 | reid, |
| 2405 | leid_len, |
| 2406 | reid_len, |
| 2407 | eid_type, |
| 2408 | is_add=1, |
| 2409 | vni=0): |
| 2410 | return self.api( |
| 2411 | self.papi.lisp_add_del_adjacency, |
| 2412 | { |
| 2413 | 'is_add': is_add, |
| 2414 | 'vni': vni, |
| 2415 | 'eid_type': eid_type, |
| 2416 | 'leid': leid, |
| 2417 | 'reid': reid, |
| 2418 | 'leid_len': leid_len, |
| 2419 | 'reid_len': reid_len, |
| 2420 | }) |
| 2421 | |
| 2422 | def lisp_adjacencies_get(self, vni=0): |
| 2423 | return self.api( |
| 2424 | self.papi.lisp_adjacencies_get, |
| 2425 | { |
| 2426 | 'vni': vni |
| 2427 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2428 | |
| 2429 | def map_add_domain(self, |
| 2430 | ip6_prefix, |
| 2431 | ip6_prefix_len, |
| 2432 | ip6_src, |
| 2433 | ip6_src_prefix_len, |
| 2434 | ip4_prefix, |
| 2435 | ip4_prefix_len, |
| 2436 | ea_bits_len=0, |
| 2437 | psid_offset=0, |
| 2438 | psid_length=0, |
| 2439 | is_translation=0, |
Juraj Sloboda | cba6936 | 2017-12-19 02:09:32 +0100 | [diff] [blame] | 2440 | is_rfc6052=0, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2441 | mtu=1280): |
| 2442 | return self.api( |
| 2443 | self.papi.map_add_domain, |
| 2444 | { |
| 2445 | 'ip6_prefix': ip6_prefix, |
| 2446 | 'ip6_prefix_len': ip6_prefix_len, |
| 2447 | 'ip4_prefix': ip4_prefix, |
| 2448 | 'ip4_prefix_len': ip4_prefix_len, |
| 2449 | 'ip6_src': ip6_src, |
| 2450 | 'ip6_src_prefix_len': ip6_src_prefix_len, |
| 2451 | 'ea_bits_len': ea_bits_len, |
| 2452 | 'psid_offset': psid_offset, |
| 2453 | 'psid_length': psid_length, |
| 2454 | 'is_translation': is_translation, |
Juraj Sloboda | cba6936 | 2017-12-19 02:09:32 +0100 | [diff] [blame] | 2455 | 'is_rfc6052': is_rfc6052, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2456 | 'mtu': mtu |
| 2457 | }) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2458 | |
| 2459 | def gtpu_add_del_tunnel( |
| 2460 | self, |
| 2461 | src_addr, |
| 2462 | dst_addr, |
| 2463 | is_add=1, |
| 2464 | is_ipv6=0, |
| 2465 | mcast_sw_if_index=0xFFFFFFFF, |
| 2466 | encap_vrf_id=0, |
| 2467 | decap_next_index=0xFFFFFFFF, |
| 2468 | teid=0): |
| 2469 | """ |
| 2470 | |
| 2471 | :param is_add: (Default value = 1) |
| 2472 | :param is_ipv6: (Default value = 0) |
| 2473 | :param src_addr: |
| 2474 | :param dst_addr: |
| 2475 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2476 | :param encap_vrf_id: (Default value = 0) |
| 2477 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2478 | :param teid: (Default value = 0) |
| 2479 | |
| 2480 | """ |
| 2481 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 2482 | {'is_add': is_add, |
| 2483 | 'is_ipv6': is_ipv6, |
| 2484 | 'src_address': src_addr, |
| 2485 | 'dst_address': dst_addr, |
| 2486 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2487 | 'encap_vrf_id': encap_vrf_id, |
| 2488 | 'decap_next_index': decap_next_index, |
| 2489 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 2490 | |
| 2491 | def vxlan_gpe_add_del_tunnel( |
| 2492 | self, |
| 2493 | src_addr, |
| 2494 | dst_addr, |
| 2495 | mcast_sw_if_index=0xFFFFFFFF, |
| 2496 | is_add=1, |
| 2497 | is_ipv6=0, |
| 2498 | encap_vrf_id=0, |
| 2499 | decap_vrf_id=0, |
| 2500 | protocol=3, |
| 2501 | vni=0): |
| 2502 | """ |
| 2503 | |
| 2504 | :param local: |
| 2505 | :param remote: |
| 2506 | :param is_add: (Default value = 1) |
| 2507 | :param is_ipv6: (Default value = 0) |
| 2508 | :param encap_vrf_id: (Default value = 0) |
| 2509 | :param decap_vrf_id: (Default value = 0) |
| 2510 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2511 | :param protocol: (Default value = 3) |
| 2512 | :param vni: (Default value = 0) |
| 2513 | |
| 2514 | """ |
| 2515 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 2516 | {'is_add': is_add, |
| 2517 | 'is_ipv6': is_ipv6, |
| 2518 | 'local': src_addr, |
| 2519 | 'remote': dst_addr, |
| 2520 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2521 | 'encap_vrf_id': encap_vrf_id, |
| 2522 | 'decap_vrf_id': decap_vrf_id, |
| 2523 | 'protocol': protocol, |
| 2524 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2525 | |
| 2526 | def pppoe_add_del_session( |
| 2527 | self, |
| 2528 | client_ip, |
| 2529 | client_mac, |
| 2530 | session_id=0, |
| 2531 | is_add=1, |
| 2532 | is_ipv6=0, |
| 2533 | decap_vrf_id=0): |
| 2534 | """ |
| 2535 | |
| 2536 | :param is_add: (Default value = 1) |
| 2537 | :param is_ipv6: (Default value = 0) |
| 2538 | :param client_ip: |
| 2539 | :param session_id: (Default value = 0) |
| 2540 | :param client_mac: |
| 2541 | :param decap_vrf_id: (Default value = 0) |
| 2542 | |
| 2543 | """ |
| 2544 | return self.api(self.papi.pppoe_add_del_session, |
| 2545 | {'is_add': is_add, |
| 2546 | 'is_ipv6': is_ipv6, |
| 2547 | 'session_id': session_id, |
| 2548 | 'client_ip': client_ip, |
| 2549 | 'decap_vrf_id': decap_vrf_id, |
| 2550 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2551 | |
| 2552 | def sr_localsid_add_del(self, |
| 2553 | localsid_addr, |
| 2554 | behavior, |
| 2555 | nh_addr, |
| 2556 | is_del=0, |
| 2557 | end_psp=0, |
| 2558 | sw_if_index=0xFFFFFFFF, |
| 2559 | vlan_index=0, |
| 2560 | fib_table=0, |
| 2561 | ): |
| 2562 | """ Add/del IPv6 SR local-SID. |
| 2563 | |
| 2564 | :param localsid_addr: |
| 2565 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 2566 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
| 2567 | :param nh_addr: |
| 2568 | :param is_del: (Default value = 0) |
| 2569 | :param end_psp: (Default value = 0) |
| 2570 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 2571 | :param vlan_index: (Default value = 0) |
| 2572 | :param fib_table: (Default value = 0) |
| 2573 | """ |
| 2574 | return self.api( |
| 2575 | self.papi.sr_localsid_add_del, |
| 2576 | {'is_del': is_del, |
| 2577 | 'localsid_addr': localsid_addr, |
| 2578 | 'end_psp': end_psp, |
| 2579 | 'behavior': behavior, |
| 2580 | 'sw_if_index': sw_if_index, |
| 2581 | 'vlan_index': vlan_index, |
| 2582 | 'fib_table': fib_table, |
| 2583 | 'nh_addr': nh_addr |
| 2584 | } |
| 2585 | ) |
| 2586 | |
| 2587 | def sr_policy_add( |
| 2588 | self, |
| 2589 | bsid_addr, |
| 2590 | weight=1, |
| 2591 | is_encap=1, |
| 2592 | type=0, |
| 2593 | fib_table=0, |
| 2594 | n_segments=0, |
| 2595 | segments=[]): |
| 2596 | """ |
| 2597 | :param bsid_addr: bindingSID of the SR Policy |
| 2598 | :param weight: weight of the sid list. optional. (default: 1) |
| 2599 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 2600 | (default: Encap) |
| 2601 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 2602 | (default: default) |
| 2603 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 2604 | (default: 0) |
| 2605 | :param n_segments: number of segments \ |
| 2606 | (default: 0) |
| 2607 | :param segments: a vector of IPv6 address composing the segment list \ |
| 2608 | (default: []) |
| 2609 | """ |
| 2610 | return self.api( |
| 2611 | self.papi.sr_policy_add, |
| 2612 | {'bsid_addr': bsid_addr, |
| 2613 | 'weight': weight, |
| 2614 | 'is_encap': is_encap, |
| 2615 | 'type': type, |
| 2616 | 'fib_table': fib_table, |
| 2617 | 'n_segments': n_segments, |
| 2618 | 'segments': segments |
| 2619 | } |
| 2620 | ) |
| 2621 | |
| 2622 | def sr_policy_del( |
| 2623 | self, |
| 2624 | bsid_addr, |
| 2625 | sr_policy_index=0): |
| 2626 | """ |
| 2627 | :param bsid: bindingSID of the SR Policy |
| 2628 | :param sr_policy_index: index of the sr policy (default: 0) |
| 2629 | """ |
| 2630 | return self.api( |
| 2631 | self.papi.sr_policy_del, |
| 2632 | {'bsid_addr': bsid_addr, |
| 2633 | 'sr_policy_index': sr_policy_index |
| 2634 | }) |
| 2635 | |
| 2636 | def sr_steering_add_del( |
| 2637 | self, |
| 2638 | is_del, |
| 2639 | bsid_addr, |
| 2640 | sr_policy_index, |
| 2641 | table_id, |
| 2642 | prefix_addr, |
| 2643 | mask_width, |
| 2644 | sw_if_index, |
| 2645 | traffic_type): |
| 2646 | """ |
| 2647 | Steer traffic L2 and L3 traffic through a given SR policy |
| 2648 | |
| 2649 | :param is_del: delete or add |
| 2650 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 2651 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 2652 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 2653 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 2654 | :param mask_width: is the mask for L3 traffic type |
| 2655 | :param sw_if_index: is the incoming interface for L2 traffic |
| 2656 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 2657 | """ |
| 2658 | return self.api( |
| 2659 | self.papi.sr_steering_add_del, |
| 2660 | {'is_del': is_del, |
| 2661 | 'bsid_addr': bsid_addr, |
| 2662 | 'sr_policy_index': sr_policy_index, |
| 2663 | 'table_id': table_id, |
| 2664 | 'prefix_addr': prefix_addr, |
| 2665 | 'mask_width': mask_width, |
| 2666 | 'sw_if_index': sw_if_index, |
| 2667 | 'traffic_type': traffic_type |
| 2668 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2669 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2670 | def acl_add_replace(self, acl_index, r, tag='', |
| 2671 | expected_retval=0): |
| 2672 | """Add/replace an ACL |
| 2673 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 2674 | :param acl_rule r: ACL rules array. |
| 2675 | :param str tag: symbolic tag (description) for this ACL. |
| 2676 | :param int count: number of rules. |
| 2677 | """ |
| 2678 | return self.api(self.papi.acl_add_replace, |
| 2679 | {'acl_index': acl_index, |
| 2680 | 'r': r, |
| 2681 | 'count': len(r), |
| 2682 | 'tag': tag}, |
| 2683 | expected_retval=expected_retval) |
| 2684 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 2685 | def acl_del(self, acl_index, expected_retval=0): |
| 2686 | """ |
| 2687 | |
| 2688 | :param acl_index: |
| 2689 | :return: |
| 2690 | """ |
| 2691 | return self.api(self.papi.acl_del, |
| 2692 | {'acl_index': acl_index}, |
| 2693 | expected_retval=expected_retval) |
| 2694 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2695 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 2696 | expected_retval=0): |
| 2697 | return self.api(self.papi.acl_interface_set_acl_list, |
| 2698 | {'sw_if_index': sw_if_index, |
| 2699 | 'count': len(acls), |
| 2700 | 'n_input': n_input, |
| 2701 | 'acls': acls}, |
| 2702 | expected_retval=expected_retval) |
| 2703 | |
Andrew Yourtchenko | c43b3f9 | 2018-02-06 17:42:32 +0100 | [diff] [blame] | 2704 | def acl_interface_set_etype_whitelist(self, sw_if_index, |
| 2705 | n_input, whitelist, |
| 2706 | expected_retval=0): |
| 2707 | return self.api(self.papi.acl_interface_set_etype_whitelist, |
| 2708 | {'sw_if_index': sw_if_index, |
| 2709 | 'count': len(whitelist), |
| 2710 | 'n_input': n_input, |
| 2711 | 'whitelist': whitelist}, |
| 2712 | expected_retval=expected_retval) |
| 2713 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 2714 | def acl_interface_add_del(self, |
| 2715 | sw_if_index, |
| 2716 | acl_index, |
| 2717 | is_add=1): |
| 2718 | """ Add/Delete ACL to/from interface |
| 2719 | |
| 2720 | :param sw_if_index: |
| 2721 | :param acl_index: |
| 2722 | :param is_add: (Default value = 1) |
| 2723 | """ |
| 2724 | |
| 2725 | return self.api(self.papi.acl_interface_add_del, |
| 2726 | {'is_add': is_add, |
| 2727 | 'is_input': 1, |
| 2728 | 'sw_if_index': sw_if_index, |
| 2729 | 'acl_index': acl_index}) |
| 2730 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2731 | def acl_dump(self, acl_index, expected_retval=0): |
| 2732 | return self.api(self.papi.acl_dump, |
| 2733 | {'acl_index': acl_index}, |
| 2734 | expected_retval=expected_retval) |
| 2735 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2736 | def macip_acl_add(self, rules, tag=""): |
| 2737 | """ Add MACIP acl |
| 2738 | |
| 2739 | :param rules: list of rules for given acl |
| 2740 | :param tag: acl tag |
| 2741 | """ |
| 2742 | |
| 2743 | return self.api(self.papi.macip_acl_add, |
| 2744 | {'r': rules, |
| 2745 | 'count': len(rules), |
| 2746 | 'tag': tag}) |
| 2747 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2748 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 2749 | """ Add MACIP acl |
| 2750 | |
| 2751 | :param rules: list of rules for given acl |
| 2752 | :param tag: acl tag |
| 2753 | """ |
| 2754 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2755 | return self.api(self.papi.macip_acl_add_replace, |
| 2756 | {'acl_index': acl_index, |
| 2757 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2758 | 'count': len(rules), |
| 2759 | 'tag': tag}) |
| 2760 | |
| 2761 | def macip_acl_del(self, acl_index): |
| 2762 | """ |
| 2763 | |
| 2764 | :param acl_index: |
| 2765 | :return: |
| 2766 | """ |
| 2767 | return self.api(self.papi.macip_acl_del, |
| 2768 | {'acl_index': acl_index}) |
| 2769 | |
| 2770 | def macip_acl_interface_add_del(self, |
| 2771 | sw_if_index, |
| 2772 | acl_index, |
| 2773 | is_add=1): |
| 2774 | """ Add MACIP acl to interface |
| 2775 | |
| 2776 | :param sw_if_index: |
| 2777 | :param acl_index: |
| 2778 | :param is_add: (Default value = 1) |
| 2779 | """ |
| 2780 | |
| 2781 | return self.api(self.papi.macip_acl_interface_add_del, |
| 2782 | {'is_add': is_add, |
| 2783 | 'sw_if_index': sw_if_index, |
| 2784 | 'acl_index': acl_index}) |
| 2785 | |
| 2786 | def macip_acl_interface_get(self): |
| 2787 | """ Return interface acls dump |
| 2788 | """ |
| 2789 | return self.api( |
| 2790 | self.papi.macip_acl_interface_get, {}) |
| 2791 | |
| 2792 | def macip_acl_dump(self, acl_index=4294967295): |
| 2793 | """ Return MACIP acl dump |
| 2794 | """ |
| 2795 | |
| 2796 | return self.api( |
| 2797 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2798 | |
| 2799 | def policer_add_del(self, |
| 2800 | name, |
| 2801 | cir, |
| 2802 | eir, |
| 2803 | cb, |
| 2804 | eb, |
| 2805 | is_add=1, |
| 2806 | rate_type=0, |
| 2807 | round_type=0, |
| 2808 | ptype=0, |
| 2809 | color_aware=0, |
| 2810 | conform_action_type=1, |
| 2811 | conform_dscp=0, |
| 2812 | exceed_action_type=0, |
| 2813 | exceed_dscp=0, |
| 2814 | violate_action_type=0, |
| 2815 | violate_dscp=0): |
| 2816 | return self.api(self.papi.policer_add_del, |
| 2817 | {'name': name, |
| 2818 | 'cir': cir, |
| 2819 | 'eir': eir, |
| 2820 | 'cb': cb, |
| 2821 | 'eb': eb, |
| 2822 | 'is_add': is_add, |
| 2823 | 'rate_type': rate_type, |
| 2824 | 'round_type': round_type, |
| 2825 | 'type': ptype, |
| 2826 | 'color_aware': color_aware, |
| 2827 | 'conform_action_type': conform_action_type, |
| 2828 | 'conform_dscp': conform_dscp, |
| 2829 | 'exceed_action_type': exceed_action_type, |
| 2830 | 'exceed_dscp': exceed_dscp, |
| 2831 | 'violate_action_type': violate_action_type, |
| 2832 | 'violate_dscp': violate_dscp}) |
| 2833 | |
| 2834 | def ip_punt_police(self, |
| 2835 | policer_index, |
| 2836 | is_ip6=0, |
| 2837 | is_add=1): |
| 2838 | return self.api(self.papi.ip_punt_police, |
| 2839 | {'policer_index': policer_index, |
| 2840 | 'is_add': is_add, |
| 2841 | 'is_ip6': is_ip6}) |
| 2842 | |
| 2843 | def ip_punt_redirect(self, |
| 2844 | rx_sw_if_index, |
| 2845 | tx_sw_if_index, |
| 2846 | nh, |
| 2847 | is_ip6=0, |
| 2848 | is_add=1): |
| 2849 | return self.api(self.papi.ip_punt_redirect, |
| 2850 | {'rx_sw_if_index': rx_sw_if_index, |
| 2851 | 'tx_sw_if_index': tx_sw_if_index, |
| 2852 | 'nh': nh, |
| 2853 | 'is_add': is_add, |
| 2854 | 'is_ip6': is_ip6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2855 | |
| 2856 | def bier_table_add_del(self, |
| 2857 | bti, |
| 2858 | mpls_label, |
| 2859 | is_add=1): |
| 2860 | """ BIER Table add/del """ |
| 2861 | return self.api( |
| 2862 | self.papi.bier_table_add_del, |
| 2863 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 2864 | "bt_sub_domain": bti.sub_domain_id, |
| 2865 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2866 | 'bt_label': mpls_label, |
| 2867 | 'bt_is_add': is_add}) |
| 2868 | |
| 2869 | def bier_table_dump(self): |
| 2870 | return self.api(self.papi.bier_table_dump, {}) |
| 2871 | |
| 2872 | def bier_route_add_del(self, |
| 2873 | bti, |
| 2874 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2875 | paths, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2876 | is_add=1): |
| 2877 | """ BIER Route add/del """ |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2878 | br_paths = [] |
| 2879 | for p in paths: |
| 2880 | br_paths.append({'next_hop': p.nh_addr, |
| 2881 | 'weight': 1, |
| 2882 | 'afi': 0, |
| 2883 | 'preference': 0, |
| 2884 | 'table_id': p.nh_table_id, |
| 2885 | 'next_hop_id': p.next_hop_id, |
| 2886 | 'is_udp_encap': p.is_udp_encap, |
| 2887 | 'n_labels': len(p.nh_labels), |
| 2888 | 'label_stack': p.nh_labels}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2889 | return self.api( |
| 2890 | self.papi.bier_route_add_del, |
| 2891 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2892 | "bt_sub_domain": bti.sub_domain_id, |
| 2893 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2894 | 'br_bp': bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 2895 | 'br_n_paths': len(br_paths), |
| 2896 | 'br_paths': br_paths, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2897 | 'br_is_add': is_add}) |
| 2898 | |
| 2899 | def bier_route_dump(self, bti): |
| 2900 | return self.api( |
| 2901 | self.papi.bier_route_dump, |
| 2902 | {'br_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 | |
| 2906 | def bier_imp_add(self, |
| 2907 | bti, |
| 2908 | src, |
| 2909 | ibytes, |
| 2910 | is_add=1): |
| 2911 | """ BIER Imposition Add """ |
| 2912 | return self.api( |
| 2913 | self.papi.bier_imp_add, |
| 2914 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 2915 | "bt_sub_domain": bti.sub_domain_id, |
| 2916 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2917 | 'bi_src': src, |
| 2918 | 'bi_n_bytes': len(ibytes), |
| 2919 | 'bi_bytes': ibytes}) |
| 2920 | |
| 2921 | def bier_imp_del(self, bi_index): |
| 2922 | """ BIER Imposition del """ |
| 2923 | return self.api( |
| 2924 | self.papi.bier_imp_del, |
| 2925 | {'bi_index': bi_index}) |
| 2926 | |
| 2927 | def bier_imp_dump(self): |
| 2928 | return self.api(self.papi.bier_imp_dump, {}) |
| 2929 | |
| 2930 | def bier_disp_table_add_del(self, |
| 2931 | bdti, |
| 2932 | is_add=1): |
| 2933 | """ BIER Disposition Table add/del """ |
| 2934 | return self.api( |
| 2935 | self.papi.bier_disp_table_add_del, |
| 2936 | {'bdt_tbl_id': bdti, |
| 2937 | 'bdt_is_add': is_add}) |
| 2938 | |
| 2939 | def bier_disp_table_dump(self): |
| 2940 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 2941 | |
| 2942 | def bier_disp_entry_add_del(self, |
| 2943 | bdti, |
| 2944 | bp, |
| 2945 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 2946 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2947 | next_hop, |
| 2948 | next_hop_tbl_id=0, |
| 2949 | next_hop_rpf_id=~0, |
| 2950 | next_hop_is_ip4=1, |
| 2951 | is_add=1): |
| 2952 | """ BIER Route add/del """ |
| 2953 | return self.api( |
| 2954 | self.papi.bier_disp_entry_add_del, |
| 2955 | {'bde_tbl_id': bdti, |
| 2956 | 'bde_bp': bp, |
| 2957 | 'bde_payload_proto': payload_proto, |
| 2958 | 'bde_n_paths': 1, |
| 2959 | 'bde_paths': [{'next_hop': next_hop, |
| 2960 | 'table_id': next_hop_tbl_id, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 2961 | 'afi': next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2962 | 'rpf_id': next_hop_rpf_id, |
| 2963 | 'n_labels': 0, |
| 2964 | 'label_stack': [0]}], |
| 2965 | 'bde_is_add': is_add}) |
| 2966 | |
| 2967 | def bier_disp_entry_dump(self, bdti): |
| 2968 | return self.api( |
| 2969 | self.papi.bier_disp_entry_dump, |
| 2970 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 2971 | |
| 2972 | def add_node_next(self, node_name, next_name): |
| 2973 | """ Set the next node for a given node request |
| 2974 | |
| 2975 | :param node_name: |
| 2976 | :param next_name: |
| 2977 | """ |
| 2978 | return self.api(self.papi.add_node_next, |
| 2979 | {'node_name': node_name, |
| 2980 | 'next_name': next_name}) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 2981 | |
| 2982 | def session_enable_disable(self, is_enabled): |
| 2983 | return self.api( |
| 2984 | self.papi.session_enable_disable, |
| 2985 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 2986 | |
| 2987 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 2988 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 2989 | Sample CLI : 'ipsec spd add 1' |
| 2990 | |
| 2991 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 2992 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 2993 | optional |
| 2994 | :returns: reply from the API |
| 2995 | """ |
| 2996 | return self.api( |
| 2997 | self.papi.ipsec_spd_add_del, { |
| 2998 | 'spd_id': spd_id, 'is_add': is_add}) |
| 2999 | |
| 3000 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 3001 | """ IPSEC interface SPD add/del - \ |
| 3002 | Wrapper to associate/disassociate SPD to interface in VPP |
| 3003 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 3004 | |
| 3005 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 3006 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 3007 | association mandatory |
| 3008 | :param is_add - add(1) or del(0) association with interface \ |
| 3009 | (Default 1 - add) . optional |
| 3010 | :returns: reply from the API |
| 3011 | """ |
| 3012 | return self.api( |
| 3013 | self.papi.ipsec_interface_add_del_spd, { |
| 3014 | 'spd_id': spd_id, |
| 3015 | 'sw_if_index': sw_if_index, 'is_add': is_add}) |
| 3016 | |
| 3017 | def ipsec_sad_add_del_entry(self, |
| 3018 | sad_id, |
| 3019 | spi, |
| 3020 | tunnel_src_address='', |
| 3021 | tunnel_dst_address='', |
| 3022 | protocol=0, |
| 3023 | integrity_algorithm=2, |
| 3024 | integrity_key_length=0, |
| 3025 | integrity_key='C91KUR9GYMm5GfkEvNjX', |
| 3026 | crypto_algorithm=1, |
| 3027 | crypto_key_length=0, |
| 3028 | crypto_key='JPjyOWBeVEQiMe7h', |
| 3029 | is_add=1, |
| 3030 | is_tunnel=1): |
| 3031 | """ IPSEC SA add/del |
| 3032 | Sample CLI : 'ipsec sa add 10 spi 1001 esp \ |
| 3033 | crypto-key 4a506a794f574265564551694d653768 \ |
| 3034 | crypto-alg aes-cbc-128 \ |
| 3035 | integ-key 4339314b55523947594d6d3547666b45764e6a58 \ |
| 3036 | integ-alg sha1-96 tunnel-src 192.168.100.3 \ |
| 3037 | tunnel-dst 192.168.100.2' |
| 3038 | Sample CLI : 'ipsec sa add 20 spi 2001 \ |
| 3039 | integ-key 4339314b55523947594d6d3547666b45764e6a58 \ |
| 3040 | integ-alg sha1-96' |
| 3041 | |
| 3042 | :param sad_id - Security Association ID to be \ |
| 3043 | created or deleted. mandatory |
| 3044 | :param spi - security param index of the SA in decimal. mandatory |
| 3045 | :param tunnel_src_address - incase of tunnel mode outer src address .\ |
| 3046 | mandatory for tunnel mode |
| 3047 | :param tunnel_dst_address - incase of transport mode \ |
| 3048 | outer dst address. mandatory for tunnel mode |
| 3049 | :param protocol - AH(0) or ESP(1) protocol (Default 0 - AH). optional |
| 3050 | :param integrity_algorithm - value range 1-6 Default(2 - SHA1_96).\ |
| 3051 | optional ** |
| 3052 | :param integrity_key - value in string \ |
| 3053 | (Default C91KUR9GYMm5GfkEvNjX).optional |
| 3054 | :param integrity_key_length - length of the key string in bytes\ |
| 3055 | (Default 0 - integrity disabled). optional |
| 3056 | :param crypto_algorithm - value range 1-11 Default \ |
| 3057 | (1- AES_CBC_128).optional ** |
| 3058 | :param crypto_key - value in string(Default JPjyOWBeVEQiMe7h).optional |
| 3059 | :param crypto_key_length - length of the key string in bytes\ |
| 3060 | (Default 0 - crypto disabled). optional |
| 3061 | :param is_add - add(1) or del(0) ipsec SA entry(Default 1 - add) .\ |
| 3062 | optional |
| 3063 | :param is_tunnel - tunnel mode (1) or transport mode(0) \ |
| 3064 | (Default 1 - tunnel). optional |
| 3065 | :returns: reply from the API |
| 3066 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 3067 | crypto and ipsec algorithms |
| 3068 | """ |
| 3069 | return self.api( |
| 3070 | self.papi.ipsec_sad_add_del_entry, |
| 3071 | {'sad_id': sad_id, |
| 3072 | 'spi': spi, |
| 3073 | 'tunnel_src_address': tunnel_src_address, |
| 3074 | 'tunnel_dst_address': tunnel_dst_address, |
| 3075 | 'protocol': protocol, |
| 3076 | 'integrity_algorithm': integrity_algorithm, |
| 3077 | 'integrity_key_length': integrity_key_length, |
| 3078 | 'integrity_key': integrity_key, |
| 3079 | 'crypto_algorithm': crypto_algorithm, |
| 3080 | 'crypto_key_length': crypto_key_length, |
| 3081 | 'crypto_key': crypto_key, |
| 3082 | 'is_add': is_add, |
| 3083 | 'is_tunnel': is_tunnel}) |
| 3084 | |
| 3085 | def ipsec_spd_add_del_entry(self, |
| 3086 | spd_id, |
| 3087 | local_address_start, |
| 3088 | local_address_stop, |
| 3089 | remote_address_start, |
| 3090 | remote_address_stop, |
| 3091 | local_port_start=0, |
| 3092 | local_port_stop=65535, |
| 3093 | remote_port_start=0, |
| 3094 | remote_port_stop=65535, |
| 3095 | protocol=0, |
| 3096 | sa_id=10, |
| 3097 | policy=0, |
| 3098 | priority=100, |
| 3099 | is_outbound=1, |
| 3100 | is_add=1, |
| 3101 | is_ip_any=0): |
| 3102 | """ IPSEC policy SPD add/del - |
| 3103 | Wrapper to configure ipsec SPD policy entries in VPP |
| 3104 | Sample CLI : 'ipsec policy add spd 1 inbound priority 10 action \ |
| 3105 | protect sa 20 local-ip-range 192.168.4.4 - 192.168.4.4 \ |
| 3106 | remote-ip-range 192.168.3.3 - 192.168.3.3' |
| 3107 | |
| 3108 | :param spd_id - SPD ID for the policy . mandatory |
| 3109 | :param local_address_start - local-ip-range start address . mandatory |
| 3110 | :param local_address_stop - local-ip-range stop address . mandatory |
| 3111 | :param remote_address_start - remote-ip-range start address . mandatory |
| 3112 | :param remote_address_stop - remote-ip-range stop address . mandatory |
| 3113 | :param local_port_start - (Default 0) . optional |
| 3114 | :param local_port_stop - (Default 65535). optional |
| 3115 | :param remote_port_start - (Default 0). optional |
| 3116 | :param remote_port_stop - (Default 65535). optional |
| 3117 | :param protocol - Any(0), AH(51) & ESP(50) protocol (Default 0 - Any). |
| 3118 | optional |
| 3119 | :param sa_id - Security Association ID for mapping it to SPD |
| 3120 | (default 10). optional |
| 3121 | :param policy - bypass(0), discard(1), resolve(2) or protect(3)action |
| 3122 | (Default 0 - bypass). optional |
| 3123 | :param priotity - value for the spd action (Default 100). optional |
| 3124 | :param is_outbound - flag for inbound(0) or outbound(1) |
| 3125 | (Default 1 - outbound). optional |
| 3126 | :param is_add flag - for addition(1) or deletion(0) of the spd |
| 3127 | (Default 1 - addtion). optional |
| 3128 | :returns: reply from the API |
| 3129 | """ |
| 3130 | return self.api( |
| 3131 | self.papi.ipsec_spd_add_del_entry, |
| 3132 | {'spd_id': spd_id, |
| 3133 | 'local_address_start': local_address_start, |
| 3134 | 'local_address_stop': local_address_stop, |
| 3135 | 'remote_address_start': remote_address_start, |
| 3136 | 'remote_address_stop': remote_address_stop, |
| 3137 | 'local_port_start': local_port_start, |
| 3138 | 'local_port_stop': local_port_stop, |
| 3139 | 'remote_port_start': remote_port_start, |
| 3140 | 'remote_port_stop': remote_port_stop, |
| 3141 | 'is_add': is_add, |
| 3142 | 'protocol': protocol, |
| 3143 | 'policy': policy, |
| 3144 | 'priority': priority, |
| 3145 | 'is_outbound': is_outbound, |
| 3146 | 'sa_id': sa_id, |
| 3147 | 'is_ip_any': is_ip_any}) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 3148 | |
| 3149 | def app_namespace_add(self, |
| 3150 | namespace_id, |
| 3151 | ip4_fib_id=0, |
| 3152 | ip6_fib_id=0, |
| 3153 | sw_if_index=0xFFFFFFFF, |
| 3154 | secret=0): |
| 3155 | return self.api( |
| 3156 | self.papi.app_namespace_add_del, |
| 3157 | {'secret': secret, |
| 3158 | 'sw_if_index': sw_if_index, |
| 3159 | 'ip4_fib_id': ip4_fib_id, |
| 3160 | 'ip6_fib_id': ip6_fib_id, |
| 3161 | 'namespace_id': namespace_id, |
| 3162 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 3163 | |
| 3164 | def punt_socket_register(self, l4_port, pathname, header_version=1, |
| 3165 | is_ip4=1, l4_protocol=0x11): |
| 3166 | """ Punt to socket """ |
| 3167 | return self.api(self.papi.punt_socket_register, |
| 3168 | {'is_ip4': is_ip4, |
| 3169 | 'l4_protocol': l4_protocol, |
| 3170 | 'l4_port': l4_port, |
| 3171 | 'pathname': pathname, |
| 3172 | 'header_version': header_version}) |
| 3173 | |
| 3174 | def ip_reassembly_set(self, timeout_ms, max_reassemblies, |
| 3175 | expire_walk_interval_ms, is_ip6=0): |
| 3176 | """ Set IP reassembly parameters """ |
| 3177 | return self.api(self.papi.ip_reassembly_set, |
| 3178 | {'is_ip6': is_ip6, |
| 3179 | 'timeout_ms': timeout_ms, |
| 3180 | 'expire_walk_interval_ms': expire_walk_interval_ms, |
| 3181 | 'max_reassemblies': max_reassemblies}) |
| 3182 | |
| 3183 | def ip_reassembly_get(self, is_ip6=0): |
| 3184 | """ Get IP reassembly parameters """ |
| 3185 | return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3186 | |
| 3187 | def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg): |
| 3188 | """ GBP endpoint Add/Del """ |
| 3189 | return self.api(self.papi.gbp_endpoint_add_del, |
| 3190 | {'is_add': is_add, |
| 3191 | 'endpoint': { |
| 3192 | 'is_ip6': is_ip6, |
| 3193 | 'sw_if_index': sw_if_index, |
| 3194 | 'address': addr, |
| 3195 | 'epg_id': epg}}) |
| 3196 | |
| 3197 | def gbp_endpoint_dump(self): |
| 3198 | """ GBP endpoint Dump """ |
| 3199 | return self.api(self.papi.gbp_endpoint_dump, {}) |
| 3200 | |
| 3201 | def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index): |
| 3202 | """ GBP contract Add/Del """ |
| 3203 | return self.api(self.papi.gbp_contract_add_del, |
| 3204 | {'is_add': is_add, |
| 3205 | 'contract': { |
| 3206 | 'acl_index': acl_index, |
| 3207 | 'src_epg': src_epg, |
| 3208 | 'dst_epg': dst_epg}}) |
| 3209 | |
| 3210 | def gbp_contract_dump(self): |
| 3211 | """ GBP contract Dump """ |
| 3212 | return self.api(self.papi.gbp_contract_dump, {}) |