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 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 39 | class QOS_SOURCE: |
| 40 | EXT = 0 |
| 41 | VLAN = 1 |
| 42 | MPLS = 2 |
| 43 | IP = 3 |
| 44 | |
| 45 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 46 | class UnexpectedApiReturnValueError(Exception): |
| 47 | """ exception raised when the API return value is unexpected """ |
| 48 | pass |
| 49 | |
| 50 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 51 | class VppPapiProvider(object): |
| 52 | """VPP-api provider using vpp-papi |
| 53 | |
| 54 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 55 | """ |
| 56 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 57 | _zero, _negative = range(2) |
| 58 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 59 | def __init__(self, name, shm_prefix, test_class): |
Klement Sekera | 277b89c | 2016-10-28 13:20:27 +0200 | [diff] [blame] | 60 | self.hook = Hook("vpp-papi-provider") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 61 | self.name = name |
| 62 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 63 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 64 | self._expect_api_retval = self._zero |
| 65 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 66 | jsonfiles = [] |
| 67 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 68 | install_dir = os.getenv('VPP_TEST_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 69 | for root, dirnames, filenames in os.walk(install_dir): |
| 70 | for filename in fnmatch.filter(filenames, '*.api.json'): |
| 71 | jsonfiles.append(os.path.join(root, filename)) |
| 72 | |
Ole Troan | a7564e8 | 2018-06-12 21:06:44 +0200 | [diff] [blame] | 73 | self.vpp = VPP(jsonfiles, logger=test_class.logger, read_timeout=5) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 74 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 75 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 76 | def __enter__(self): |
| 77 | return self |
| 78 | |
| 79 | def expect_negative_api_retval(self): |
| 80 | """ Expect API failure """ |
| 81 | self._expect_stack.append(self._expect_api_retval) |
| 82 | self._expect_api_retval = self._negative |
| 83 | return self |
| 84 | |
| 85 | def expect_zero_api_retval(self): |
| 86 | """ Expect API success """ |
| 87 | self._expect_stack.append(self._expect_api_retval) |
| 88 | self._expect_api_retval = self._zero |
| 89 | return self |
| 90 | |
| 91 | def __exit__(self, exc_type, exc_value, traceback): |
| 92 | self._expect_api_retval = self._expect_stack.pop() |
| 93 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 94 | def register_hook(self, hook): |
| 95 | """Replace hook registration with new hook |
| 96 | |
| 97 | :param hook: |
| 98 | |
| 99 | """ |
| 100 | self.hook = hook |
| 101 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 102 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 103 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 104 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 105 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 106 | return e |
| 107 | |
| 108 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 109 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 110 | if name: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 111 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 112 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 113 | else: |
| 114 | self.test_class.logger.debug("Expecting event within %ss", |
| 115 | timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 116 | if self._events: |
| 117 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 118 | limit = time.time() + timeout |
| 119 | while time.time() < limit: |
| 120 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 121 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 122 | if name and type(e).__name__ != name: |
| 123 | raise Exception( |
| 124 | "Unexpected event received: %s, expected: %s" % |
| 125 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 126 | self.test_class.logger.debug("Returning event %s:%s" % |
| 127 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 128 | return e |
| 129 | time.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 130 | raise Exception("Event did not occur within timeout") |
| 131 | |
| 132 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 133 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 134 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 135 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 136 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 137 | self._events.append(event) |
| 138 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 139 | def connect(self): |
| 140 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 141 | self.vpp.connect(self.name, self.shm_prefix) |
| 142 | self.papi = self.vpp.api |
| 143 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 144 | |
| 145 | def disconnect(self): |
| 146 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 147 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 148 | |
| 149 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 150 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 151 | Call the appropriate hooks before and after the API call |
| 152 | |
| 153 | :param api_fn: API function to call |
| 154 | :param api_args: tuple of API function arguments |
| 155 | :param expected_retval: Expected return value (Default value = 0) |
| 156 | :returns: reply from the API |
| 157 | |
| 158 | """ |
| 159 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 160 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 161 | if self._expect_api_retval == self._negative: |
| 162 | if hasattr(reply, 'retval') and reply.retval >= 0: |
| 163 | msg = "API call passed unexpectedly: expected negative "\ |
| 164 | "return value instead of %d in %s" % \ |
| 165 | (reply.retval, repr(reply)) |
| 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 | elif self._expect_api_retval == self._zero: |
| 169 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 170 | msg = "API call failed, expected %d return value instead "\ |
| 171 | "of %d in %s" % (expected_retval, reply.retval, |
| 172 | repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 173 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 174 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 175 | else: |
| 176 | raise Exception("Internal error, unexpected value for " |
| 177 | "self._expect_api_retval %s" % |
| 178 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 179 | self.hook.after_api(api_fn.__name__, api_args) |
| 180 | return reply |
| 181 | |
| 182 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 183 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 184 | |
| 185 | :param cli: CLI to execute |
| 186 | :returns: CLI output |
| 187 | |
| 188 | """ |
| 189 | self.hook.before_cli(cli) |
| 190 | cli += '\n' |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 191 | r = self.papi.cli_inband(length=len(cli), cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 192 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 193 | if hasattr(r, 'reply'): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 194 | return r.reply.decode().rstrip('\x00') |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 195 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 196 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 197 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 198 | |
| 199 | :param cli: CLI to execute |
| 200 | :returns: CLI output |
| 201 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 202 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 203 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 204 | def _convert_mac(self, mac): |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 205 | return mac.replace(':', '').decode('hex') |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 206 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 207 | def show_version(self): |
| 208 | """ """ |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 209 | return self.api(self.papi.show_version, {}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 210 | |
| 211 | def pg_create_interface(self, pg_index): |
| 212 | """ |
| 213 | |
| 214 | :param pg_index: |
| 215 | |
| 216 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 217 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 218 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 219 | |
| 220 | def sw_interface_dump(self, filter=None): |
| 221 | """ |
| 222 | |
| 223 | :param filter: (Default value = None) |
| 224 | |
| 225 | """ |
| 226 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 227 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 228 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 229 | args = {} |
| 230 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 231 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 232 | 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] | 233 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 234 | |
| 235 | :param sw_if_index: |
| 236 | :param is_ipv6: |
| 237 | :param table_id: |
| 238 | |
| 239 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 240 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 241 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 242 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 243 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 244 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 245 | is_ipv6=0, is_add=1, del_all=0): |
| 246 | """ |
| 247 | |
| 248 | :param addr: param is_ipv6: (Default value = 0) |
| 249 | :param sw_if_index: |
| 250 | :param addr_len: |
| 251 | :param is_ipv6: (Default value = 0) |
| 252 | :param is_add: (Default value = 1) |
| 253 | :param del_all: (Default value = 0) |
| 254 | |
| 255 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 256 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 257 | {'sw_if_index': sw_if_index, |
| 258 | 'is_add': is_add, |
| 259 | 'is_ipv6': is_ipv6, |
| 260 | 'del_all': del_all, |
| 261 | 'address_length': addr_len, |
| 262 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 263 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 264 | def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index, |
| 265 | is_add=1): |
| 266 | """ Set the Interface to be unnumbered |
| 267 | |
| 268 | :param is_add: (Default value = 1) |
| 269 | :param sw_if_index - interface That will be unnumbered |
| 270 | :param ip_sw_if_index - interface with an IP addres |
| 271 | |
| 272 | """ |
| 273 | return self.api(self.papi.sw_interface_set_unnumbered, |
| 274 | {'sw_if_index': ip_sw_if_index, |
| 275 | 'unnumbered_sw_if_index': sw_if_index, |
| 276 | 'is_add': is_add}) |
| 277 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 278 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 279 | is_enable=1): |
| 280 | """ |
| 281 | Enable/Disable MPLS on the interface |
| 282 | :param sw_if_index: |
| 283 | :param is_enable: (Default value = 1) |
| 284 | |
| 285 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 286 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 287 | {'sw_if_index': sw_if_index, |
| 288 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 289 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 290 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 291 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 292 | {'sw_if_index': sw_if_index, |
| 293 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 294 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 295 | def set_ip_flow_hash(self, |
| 296 | table_id, |
| 297 | src=1, |
| 298 | dst=1, |
| 299 | sport=1, |
| 300 | dport=1, |
| 301 | proto=1, |
| 302 | reverse=0, |
| 303 | is_ip6=0): |
| 304 | return self.api(self.papi.set_ip_flow_hash, |
| 305 | {'vrf_id': table_id, |
| 306 | 'src': src, |
| 307 | 'dst': dst, |
| 308 | 'dport': dport, |
| 309 | 'sport': sport, |
| 310 | 'proto': proto, |
| 311 | 'reverse': reverse, |
| 312 | 'is_ipv6': is_ip6}) |
| 313 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 314 | def ip6_nd_proxy(self, address, sw_if_index, is_del=0): |
| 315 | return self.api(self.papi.ip6nd_proxy_add_del, |
| 316 | {'address': address, |
| 317 | 'sw_if_index': sw_if_index, |
| 318 | 'is_del': is_del}) |
| 319 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 320 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 321 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 322 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 323 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 324 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 325 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 326 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 327 | 'suppress': suppress, |
| 328 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 329 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 330 | def ip6_sw_interface_ra_prefix(self, |
| 331 | sw_if_index, |
| 332 | address, |
| 333 | address_length, |
| 334 | use_default=0, |
| 335 | no_advertise=0, |
| 336 | off_link=0, |
| 337 | no_autoconfig=0, |
| 338 | no_onlink=0, |
| 339 | is_no=0, |
| 340 | val_lifetime=0xffffffff, |
| 341 | pref_lifetime=0xffffffff): |
| 342 | return self.api(self.papi.sw_interface_ip6nd_ra_prefix, |
| 343 | {'sw_if_index': sw_if_index, |
| 344 | 'address': address, |
| 345 | 'address_length': address_length, |
| 346 | 'use_default': use_default, |
| 347 | 'no_advertise': no_advertise, |
| 348 | 'off_link': off_link, |
| 349 | 'no_autoconfig': no_autoconfig, |
| 350 | 'no_onlink': no_onlink, |
| 351 | 'is_no': is_no, |
| 352 | 'val_lifetime': val_lifetime, |
| 353 | 'pref_lifetime': pref_lifetime}) |
| 354 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 355 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 356 | """ |
| 357 | Enable/Disable An interface for IPv6 |
| 358 | """ |
| 359 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 360 | {'sw_if_index': sw_if_index, |
| 361 | 'enable': enable}) |
| 362 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 363 | def vxlan_add_del_tunnel( |
| 364 | self, |
| 365 | src_addr, |
| 366 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 367 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 368 | is_add=1, |
| 369 | is_ipv6=0, |
| 370 | encap_vrf_id=0, |
| 371 | decap_next_index=0xFFFFFFFF, |
Jon Loeliger | 3d460bd | 2018-02-01 16:36:12 -0600 | [diff] [blame] | 372 | vni=0, |
| 373 | instance=0xFFFFFFFF): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 374 | """ |
| 375 | |
| 376 | :param dst_addr: |
| 377 | :param src_addr: |
| 378 | :param is_add: (Default value = 1) |
| 379 | :param is_ipv6: (Default value = 0) |
| 380 | :param encap_vrf_id: (Default value = 0) |
| 381 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 382 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 383 | :param vni: (Default value = 0) |
Jon Loeliger | 3d460bd | 2018-02-01 16:36:12 -0600 | [diff] [blame] | 384 | :param instance: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 385 | |
| 386 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 387 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 388 | {'is_add': is_add, |
| 389 | 'is_ipv6': is_ipv6, |
| 390 | 'src_address': src_addr, |
| 391 | 'dst_address': dst_addr, |
| 392 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 393 | 'encap_vrf_id': encap_vrf_id, |
| 394 | 'decap_next_index': decap_next_index, |
Jon Loeliger | 3d460bd | 2018-02-01 16:36:12 -0600 | [diff] [blame] | 395 | 'vni': vni, |
| 396 | 'instance': instance}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 397 | |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 398 | def geneve_add_del_tunnel( |
| 399 | self, |
| 400 | local_addr, |
| 401 | remote_addr, |
| 402 | mcast_sw_if_index=0xFFFFFFFF, |
| 403 | is_add=1, |
| 404 | is_ipv6=0, |
| 405 | encap_vrf_id=0, |
| 406 | decap_next_index=0xFFFFFFFF, |
| 407 | vni=0): |
| 408 | """ |
| 409 | |
| 410 | :param remote_addr: |
| 411 | :param local_addr: |
| 412 | :param is_add: (Default value = 1) |
| 413 | :param is_ipv6: (Default value = 0) |
| 414 | :param encap_vrf_id: (Default value = 0) |
| 415 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 416 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 417 | :param vni: (Default value = 0) |
| 418 | |
| 419 | """ |
| 420 | return self.api(self.papi.geneve_add_del_tunnel, |
| 421 | {'is_add': is_add, |
| 422 | 'is_ipv6': is_ipv6, |
| 423 | 'local_address': local_addr, |
| 424 | 'remote_address': remote_addr, |
| 425 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 426 | 'encap_vrf_id': encap_vrf_id, |
| 427 | 'decap_next_index': decap_next_index, |
| 428 | 'vni': vni}) |
| 429 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 430 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 431 | learn=1, arp_term=0, is_add=1): |
| 432 | """Create/delete bridge domain. |
| 433 | |
| 434 | :param int bd_id: Bridge domain index. |
| 435 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 436 | (Default value = 1) |
| 437 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 438 | (Default value = 1) |
| 439 | :param int forward: Enable/disable forwarding on all interfaces in |
| 440 | the BD. (Default value = 1) |
| 441 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 442 | (Default value = 1) |
| 443 | :param int arp_term: Enable/disable arp termination in the BD. |
| 444 | (Default value = 1) |
| 445 | :param int is_add: Add or delete flag. (Default value = 1) |
| 446 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 447 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 448 | {'bd_id': bd_id, |
| 449 | 'flood': flood, |
| 450 | 'uu_flood': uu_flood, |
| 451 | 'forward': forward, |
| 452 | 'learn': learn, |
| 453 | 'arp_term': arp_term, |
| 454 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 455 | |
Eyal Bari | c86e592 | 2017-07-02 18:33:16 +0300 | [diff] [blame] | 456 | def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1): |
| 457 | return self.api(self.papi.bd_ip_mac_add_del, |
| 458 | {'bd_id': bd_id, |
| 459 | 'is_add': is_add, |
| 460 | 'is_ipv6': is_ipv6, |
| 461 | 'ip_address': ip, |
| 462 | 'mac_address': mac}) |
| 463 | |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 464 | def want_ip4_arp_events(self, enable_disable=1, address=0): |
| 465 | return self.api(self.papi.want_ip4_arp_events, |
| 466 | {'enable_disable': enable_disable, |
| 467 | 'address': address, |
| 468 | 'pid': os.getpid(), }) |
| 469 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 470 | def want_ip6_nd_events(self, enable_disable=1, address=0): |
| 471 | return self.api(self.papi.want_ip6_nd_events, |
| 472 | {'enable_disable': enable_disable, |
| 473 | 'address': address, |
| 474 | 'pid': os.getpid(), }) |
| 475 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 476 | def want_ip6_ra_events(self, enable_disable=1): |
| 477 | return self.api(self.papi.want_ip6_ra_events, |
| 478 | {'enable_disable': enable_disable, |
| 479 | 'pid': os.getpid(), }) |
| 480 | |
| 481 | def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120, |
| 482 | mrc=0, mrd=0): |
| 483 | return self.api(self.papi.ip6nd_send_router_solicitation, |
| 484 | {'irt': irt, |
| 485 | 'mrt': mrt, |
| 486 | 'mrc': mrc, |
| 487 | 'mrd': mrd, |
| 488 | 'sw_if_index': sw_if_index}) |
| 489 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 490 | def ip6_nd_address_autoconfig(self, sw_if_index, enable, |
| 491 | install_default_routes): |
| 492 | return self.api(self.papi.ip6_nd_address_autoconfig, |
| 493 | {'sw_if_index': sw_if_index, |
| 494 | 'enable': enable, |
| 495 | 'install_default_routes': install_default_routes}) |
| 496 | |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 497 | def want_macs_learn_events(self, enable_disable=1, scan_delay=0, |
| 498 | max_macs_in_event=0, learn_limit=0): |
| 499 | return self.api(self.papi.want_l2_macs_events, |
| 500 | {'enable_disable': enable_disable, |
| 501 | 'scan_delay': scan_delay, |
| 502 | 'max_macs_in_event': max_macs_in_event, |
| 503 | 'learn_limit': learn_limit, |
| 504 | 'pid': os.getpid(), }) |
| 505 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 506 | def want_dhcp6_reply_events(self, enable_disable=1): |
| 507 | return self.api(self.papi.want_dhcp6_reply_events, |
| 508 | {'enable_disable': enable_disable, |
| 509 | 'pid': os.getpid()}) |
| 510 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 511 | def want_dhcp6_pd_reply_events(self, enable_disable=1): |
| 512 | return self.api(self.papi.want_dhcp6_pd_reply_events, |
| 513 | {'enable_disable': enable_disable, |
| 514 | 'pid': os.getpid()}) |
| 515 | |
| 516 | def dhcp6_clients_enable_disable(self, enable=1): |
| 517 | return self.api(self.papi.dhcp6_clients_enable_disable, |
| 518 | {'enable': enable}) |
| 519 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 520 | def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2, |
| 521 | addresses, server_index=0xFFFFFFFF, |
| 522 | irt=0, mrt=0, mrc=1, mrd=0, stop=0, |
| 523 | ): |
| 524 | return self.api(self.papi.dhcp6_send_client_message, |
| 525 | {'sw_if_index': sw_if_index, |
| 526 | 'server_index': server_index, |
| 527 | 'irt': irt, |
| 528 | 'mrt': mrt, |
| 529 | 'mrc': mrc, |
| 530 | 'mrd': mrd, |
| 531 | 'stop': stop, |
| 532 | 'msg_type': msg_type, |
| 533 | 'T1': T1, |
| 534 | 'T2': T2, |
| 535 | 'n_addresses': len(addresses), |
| 536 | 'addresses': addresses}) |
| 537 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 538 | def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2, |
| 539 | prefixes, server_index=0xFFFFFFFF, |
| 540 | irt=0, mrt=0, mrc=1, mrd=0, stop=0, |
| 541 | ): |
| 542 | return self.api(self.papi.dhcp6_pd_send_client_message, |
| 543 | {'sw_if_index': sw_if_index, |
| 544 | 'server_index': server_index, |
| 545 | 'irt': irt, |
| 546 | 'mrt': mrt, |
| 547 | 'mrc': mrc, |
| 548 | 'mrd': mrd, |
| 549 | 'stop': stop, |
| 550 | 'msg_type': msg_type, |
| 551 | 'T1': T1, |
| 552 | 'T2': T2, |
| 553 | 'n_prefixes': len(prefixes), |
| 554 | 'prefixes': prefixes}) |
| 555 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 556 | def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='', |
| 557 | enable=1): |
| 558 | return self.api(self.papi.dhcp6_client_enable_disable, |
| 559 | {'sw_if_index': sw_if_index, |
| 560 | 'enable': enable}) |
| 561 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 562 | def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='', |
| 563 | enable=1): |
| 564 | return self.api(self.papi.dhcp6_pd_client_enable_disable, |
| 565 | {'sw_if_index': sw_if_index, |
| 566 | 'prefix_group': prefix_group, |
| 567 | 'enable': enable}) |
| 568 | |
| 569 | def ip6_add_del_address_using_prefix(self, sw_if_index, address, |
| 570 | prefix_length, prefix_group, |
| 571 | is_add=1): |
| 572 | return self.api(self.papi.ip6_add_del_address_using_prefix, |
| 573 | {'sw_if_index': sw_if_index, |
| 574 | 'prefix_group': prefix_group, |
| 575 | 'address': address, |
| 576 | 'prefix_length': prefix_length, |
| 577 | 'is_add': is_add}) |
| 578 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 579 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 580 | filter_mac=0, bvi_mac=0): |
| 581 | """Create/delete L2 FIB entry. |
| 582 | |
| 583 | :param str mac: MAC address to create FIB entry for. |
| 584 | :param int bd_id: Bridge domain index. |
| 585 | :param int sw_if_index: Software interface index of the interface. |
| 586 | :param int is_add: Add or delete flag. (Default value = 1) |
| 587 | :param int static_mac: Set to 1 to create static MAC entry. |
| 588 | (Default value = 0) |
| 589 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 590 | destination MAC address contains defined MAC address. |
| 591 | (Default value = 0) |
| 592 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 593 | interface. (Default value = 0) |
| 594 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 595 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 596 | {'mac': self._convert_mac(mac), |
| 597 | 'bd_id': bd_id, |
| 598 | 'sw_if_index': sw_if_index, |
| 599 | 'is_add': is_add, |
| 600 | 'static_mac': static_mac, |
| 601 | 'filter_mac': filter_mac, |
| 602 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 603 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 604 | def l2fib_flush_int(self, sw_if_index): |
| 605 | """Flush L2 FIB entries for sw_if_index. |
| 606 | |
| 607 | :param int sw_if_index: Software interface index of the interface. |
| 608 | """ |
| 609 | return self.api(self.papi.l2fib_flush_int, |
| 610 | {'sw_if_index': sw_if_index}) |
| 611 | |
| 612 | def l2fib_flush_bd(self, bd_id): |
| 613 | """Flush L2 FIB entries for bd_id. |
| 614 | |
| 615 | :param int sw_if_index: Bridge Domain id. |
| 616 | """ |
| 617 | return self.api(self.papi.l2fib_flush_bd, |
| 618 | {'bd_id': bd_id}) |
| 619 | |
| 620 | def l2fib_flush_all(self): |
| 621 | """Flush all L2 FIB. |
| 622 | """ |
| 623 | return self.api(self.papi.l2fib_flush_all, {}) |
| 624 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 625 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 626 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 627 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 628 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 629 | :param int sw_if_index: Software interface index of the interface. |
| 630 | :param int bd_id: Bridge domain index. |
| 631 | :param int shg: Split-horizon group index. (Default value = 0) |
| 632 | :param int bvi: Set interface as a bridge group virtual interface. |
| 633 | (Default value = 0) |
| 634 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 635 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 636 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 637 | {'rx_sw_if_index': sw_if_index, |
| 638 | 'bd_id': bd_id, |
| 639 | 'shg': shg, |
| 640 | 'bvi': bvi, |
| 641 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 642 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 643 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
Chris Luke | d042194 | 2018-04-10 15:19:54 -0400 | [diff] [blame] | 644 | """Enable/disable required feature of the bridge domain with defined |
| 645 | ID. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 646 | |
| 647 | :param int bd_id: Bridge domain ID. |
| 648 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 649 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 650 | - learn (1 << 0), |
| 651 | - forward (1 << 1), |
| 652 | - flood (1 << 2), |
| 653 | - uu-flood (1 << 3) or |
| 654 | - arp-term (1 << 4). |
| 655 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 656 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 657 | {'bd_id': bd_id, |
| 658 | 'is_set': is_set, |
| 659 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 660 | |
| 661 | def bridge_domain_dump(self, bd_id=0): |
| 662 | """ |
| 663 | |
| 664 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 665 | existing bridge domains returned) |
| 666 | :return: Dictionary of bridge domain(s) data. |
| 667 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 668 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 669 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 670 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 671 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 672 | enable): |
| 673 | """Create or delete unidirectional cross-connect from Tx interface to |
| 674 | Rx interface. |
| 675 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 676 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 677 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 678 | :param int enable: Create cross-connect if equal to 1, delete |
| 679 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 680 | |
| 681 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 682 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 683 | {'rx_sw_if_index': rx_sw_if_index, |
| 684 | 'tx_sw_if_index': tx_sw_if_index, |
| 685 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 686 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 687 | def sw_interface_set_l2_tag_rewrite( |
| 688 | self, |
| 689 | sw_if_index, |
| 690 | vtr_oper, |
| 691 | push=0, |
| 692 | tag1=0, |
| 693 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 694 | """L2 interface vlan tag rewrite configure request |
| 695 | :param client_index - opaque cookie to identify the sender |
| 696 | :param context - sender context, to match reply w/ request |
| 697 | :param sw_if_index - interface the operation is applied to |
| 698 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 699 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 700 | :param tag1 - Needed for any push or translate vtr op |
| 701 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 702 | |
| 703 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 704 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 705 | {'sw_if_index': sw_if_index, |
| 706 | 'vtr_op': vtr_oper, |
| 707 | 'push_dot1q': push, |
| 708 | 'tag1': tag1, |
| 709 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 710 | |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 711 | def sw_interface_set_l2_emulation( |
| 712 | self, |
| 713 | sw_if_index, |
| 714 | enable=1): |
| 715 | """L2 Emulation |
| 716 | :param sw_if_index - interface the operation is applied to |
| 717 | |
| 718 | """ |
| 719 | return self.api(self.papi.l2_emulation, |
| 720 | {'sw_if_index': sw_if_index, |
| 721 | 'enable': enable}) |
| 722 | |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 723 | def sw_interface_set_flags(self, sw_if_index, admin_up_down): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 724 | """ |
| 725 | |
| 726 | :param admin_up_down: |
| 727 | :param sw_if_index: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 728 | |
| 729 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 730 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 731 | {'sw_if_index': sw_if_index, |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 732 | 'admin_up_down': admin_up_down}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 733 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 734 | def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]): |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 735 | """ |
| 736 | :param sw_if_index: |
| 737 | :param mtu: |
| 738 | |
| 739 | """ |
| 740 | return self.api(self.papi.sw_interface_set_mtu, |
| 741 | {'sw_if_index': sw_if_index, |
| 742 | 'mtu': mtu}) |
| 743 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 744 | def sw_interface_set_promiscuous(self, sw_if_index, enable): |
| 745 | """ |
| 746 | :param sw_if_index: |
| 747 | :param enable: |
| 748 | |
| 749 | """ |
| 750 | return self.api(self.papi.sw_interface_set_promiscuous, |
| 751 | {'sw_if_index': sw_if_index, |
| 752 | 'enable': enable}) |
| 753 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 754 | def sw_interface_set_mac_address(self, sw_if_index, mac): |
| 755 | return self.api(self.papi.sw_interface_set_mac_address, |
| 756 | {'sw_if_index': sw_if_index, |
| 757 | 'mac_address': mac}) |
| 758 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 759 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 760 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 761 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 762 | """Create subinterface |
| 763 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 764 | |
| 765 | :param sub_id: param inner_vlan: |
| 766 | :param sw_if_index: |
| 767 | :param outer_vlan: |
| 768 | :param inner_vlan: |
| 769 | :param no_tags: (Default value = 0) |
| 770 | :param one_tag: (Default value = 0) |
| 771 | :param two_tags: (Default value = 0) |
| 772 | :param dot1ad: (Default value = 0) |
| 773 | :param exact_match: (Default value = 0) |
| 774 | :param default_sub: (Default value = 0) |
| 775 | :param outer_vlan_id_any: (Default value = 0) |
| 776 | :param inner_vlan_id_any: (Default value = 0) |
| 777 | |
| 778 | """ |
| 779 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 780 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 781 | {'sw_if_index': sw_if_index, |
| 782 | 'sub_id': sub_id, |
| 783 | 'no_tags': no_tags, |
| 784 | 'one_tag': one_tag, |
| 785 | 'two_tags': two_tags, |
| 786 | 'dot1ad': dot1ad, |
| 787 | 'exact_match': exact_match, |
| 788 | 'default_sub': default_sub, |
| 789 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 790 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 791 | 'outer_vlan_id': outer_vlan, |
| 792 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 793 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 794 | def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id): |
| 795 | """Create p2p ethernet subinterface |
| 796 | |
| 797 | :param sw_if_index: main (parent) interface |
| 798 | :param remote_mac: client (remote) mac address |
| 799 | |
| 800 | """ |
| 801 | return self.api( |
| 802 | self.papi.p2p_ethernet_add, |
| 803 | {'parent_if_index': sw_if_index, |
| 804 | 'remote_mac': remote_mac, |
| 805 | 'subif_id': subif_id}) |
| 806 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 807 | def delete_subif(self, sw_if_index): |
| 808 | """Delete subinterface |
| 809 | |
| 810 | :param sw_if_index: |
| 811 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 812 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 813 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 814 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 815 | def delete_p2pethernet_subif(self, sw_if_index, remote_mac): |
| 816 | """Delete p2p ethernet subinterface |
| 817 | |
| 818 | :param sw_if_index: main (parent) interface |
| 819 | :param remote_mac: client (remote) mac address |
| 820 | |
| 821 | """ |
| 822 | return self.api( |
| 823 | self.papi.p2p_ethernet_del, |
| 824 | {'parent_if_index': sw_if_index, |
| 825 | 'remote_mac': remote_mac}) |
| 826 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 827 | def create_vlan_subif(self, sw_if_index, vlan): |
| 828 | """ |
| 829 | |
| 830 | :param vlan: |
| 831 | :param sw_if_index: |
| 832 | |
| 833 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 834 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 835 | {'sw_if_index': sw_if_index, |
| 836 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 837 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 838 | def create_loopback(self, mac=''): |
| 839 | """ |
| 840 | |
| 841 | :param mac: (Optional) |
| 842 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 843 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 844 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 845 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 846 | def delete_loopback(self, sw_if_index): |
| 847 | return self.api(self.papi.delete_loopback, |
| 848 | {'sw_if_index': sw_if_index, }) |
| 849 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 850 | def ip_table_add_del(self, |
| 851 | table_id, |
| 852 | is_add=1, |
| 853 | is_ipv6=0): |
| 854 | """ |
| 855 | |
| 856 | :param table_id |
| 857 | :param is_add: (Default value = 1) |
| 858 | :param is_ipv6: (Default value = 0) |
| 859 | |
| 860 | """ |
| 861 | |
| 862 | return self.api( |
| 863 | self.papi.ip_table_add_del, |
| 864 | {'table_id': table_id, |
| 865 | 'is_add': is_add, |
| 866 | 'is_ipv6': is_ipv6}) |
| 867 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 868 | def ip_add_del_route( |
| 869 | self, |
| 870 | dst_address, |
| 871 | dst_address_length, |
| 872 | next_hop_address, |
| 873 | next_hop_sw_if_index=0xFFFFFFFF, |
| 874 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 875 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 876 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 877 | next_hop_n_out_labels=0, |
| 878 | next_hop_out_label_stack=[], |
| 879 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 880 | next_hop_id=0xFFFFFFFF, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 881 | is_resolve_host=0, |
| 882 | is_resolve_attached=0, |
| 883 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 884 | is_add=1, |
| 885 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 886 | is_unreach=0, |
| 887 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 888 | is_ipv6=0, |
| 889 | is_local=0, |
| 890 | is_classify=0, |
| 891 | is_multipath=0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 892 | is_dvr=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 893 | is_udp_encap=0, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 894 | is_source_lookup=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 895 | """ |
| 896 | |
| 897 | :param dst_address_length: |
| 898 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 899 | :param dst_address: |
| 900 | :param next_hop_address: |
| 901 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 902 | :param vrf_id: (Default value = 0) |
| 903 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 904 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 905 | :param is_add: (Default value = 1) |
| 906 | :param is_drop: (Default value = 0) |
| 907 | :param is_ipv6: (Default value = 0) |
| 908 | :param is_local: (Default value = 0) |
| 909 | :param is_classify: (Default value = 0) |
| 910 | :param is_multipath: (Default value = 0) |
| 911 | :param is_resolve_host: (Default value = 0) |
| 912 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 913 | :param is_dvr: (Default value = 0) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 914 | :param is_source_lookup: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 915 | :param next_hop_weight: (Default value = 1) |
| 916 | |
| 917 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 918 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 919 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 920 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 921 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 922 | 'table_id': table_id, |
| 923 | 'classify_table_index': classify_table_index, |
| 924 | 'next_hop_table_id': next_hop_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 925 | 'is_add': is_add, |
| 926 | 'is_drop': is_drop, |
| 927 | 'is_unreach': is_unreach, |
| 928 | 'is_prohibit': is_prohibit, |
| 929 | 'is_ipv6': is_ipv6, |
| 930 | 'is_local': is_local, |
| 931 | 'is_classify': is_classify, |
| 932 | 'is_multipath': is_multipath, |
| 933 | 'is_resolve_host': is_resolve_host, |
| 934 | 'is_resolve_attached': is_resolve_attached, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 935 | 'is_dvr': is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 936 | 'is_source_lookup': is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 937 | 'is_udp_encap': is_udp_encap, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 938 | 'next_hop_weight': next_hop_weight, |
| 939 | 'dst_address_length': dst_address_length, |
| 940 | 'dst_address': dst_address, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 941 | 'next_hop_id': next_hop_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 942 | 'next_hop_address': next_hop_address, |
| 943 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 944 | 'next_hop_via_label': next_hop_via_label, |
| 945 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 946 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 947 | def ip_fib_dump(self): |
| 948 | return self.api(self.papi.ip_fib_dump, {}) |
| 949 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 950 | def ip6_fib_dump(self): |
| 951 | return self.api(self.papi.ip6_fib_dump, {}) |
| 952 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 953 | def ip_neighbor_add_del(self, |
| 954 | sw_if_index, |
| 955 | mac_address, |
| 956 | dst_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 957 | is_add=1, |
| 958 | is_ipv6=0, |
| 959 | is_static=0, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 960 | is_no_adj_fib=0, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 961 | ): |
| 962 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 963 | |
| 964 | :param sw_if_index: |
| 965 | :param mac_address: |
| 966 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 967 | :param is_add: (Default value = 1) |
| 968 | :param is_ipv6: (Default value = 0) |
| 969 | :param is_static: (Default value = 0) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 970 | :param is_no_adj_fib: (Default value = 0) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 971 | """ |
| 972 | |
| 973 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 974 | self.papi.ip_neighbor_add_del, |
Neale Ranns | baf2e90 | 2017-02-25 04:20:00 -0800 | [diff] [blame] | 975 | {'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 976 | 'is_add': is_add, |
| 977 | 'is_ipv6': is_ipv6, |
| 978 | 'is_static': is_static, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 979 | 'is_no_adj_fib': is_no_adj_fib, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 980 | 'mac_address': mac_address, |
| 981 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 982 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 983 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 984 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 985 | def ip_neighbor_dump(self, |
| 986 | sw_if_index, |
| 987 | is_ipv6=0): |
| 988 | """ Return IP neighbor dump. |
| 989 | |
| 990 | :param sw_if_index: |
| 991 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 992 | """ |
| 993 | |
| 994 | return self.api( |
| 995 | self.papi.ip_neighbor_dump, |
| 996 | {'is_ipv6': is_ipv6, |
| 997 | 'sw_if_index': sw_if_index |
| 998 | } |
| 999 | ) |
| 1000 | |
| 1001 | def proxy_arp_add_del(self, |
| 1002 | low_address, |
| 1003 | hi_address, |
| 1004 | vrf_id=0, |
| 1005 | is_add=1): |
| 1006 | """ Config Proxy Arp Range. |
| 1007 | |
| 1008 | :param low_address: Start address in the rnage to Proxy for |
| 1009 | :param hi_address: End address in the rnage to Proxy for |
| 1010 | :param vrf_id: The VRF/table in which to proxy |
| 1011 | """ |
| 1012 | |
| 1013 | return self.api( |
| 1014 | self.papi.proxy_arp_add_del, |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 1015 | {'proxy': |
| 1016 | { |
| 1017 | 'vrf_id': vrf_id, |
| 1018 | 'low_address': low_address, |
| 1019 | 'hi_address': hi_address, |
| 1020 | }, |
| 1021 | 'is_add': is_add}) |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 1022 | |
| 1023 | def proxy_arp_intfc_enable_disable(self, |
| 1024 | sw_if_index, |
| 1025 | is_enable=1): |
| 1026 | """ Enable/Disable an interface for proxy ARP requests |
| 1027 | |
| 1028 | :param sw_if_index: Interface |
| 1029 | :param enable_disable: Enable/Disable |
| 1030 | """ |
| 1031 | |
| 1032 | return self.api( |
| 1033 | self.papi.proxy_arp_intfc_enable_disable, |
| 1034 | {'sw_if_index': sw_if_index, |
| 1035 | 'enable_disable': is_enable |
| 1036 | } |
| 1037 | ) |
| 1038 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 1039 | def reset_vrf(self, |
| 1040 | vrf_id, |
| 1041 | is_ipv6=0, |
| 1042 | ): |
| 1043 | """ Reset VRF (remove all routes etc.) request. |
| 1044 | |
| 1045 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 1046 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1047 | """ |
| 1048 | |
| 1049 | return self.api( |
| 1050 | self.papi.reset_vrf, |
| 1051 | {'vrf_id': vrf_id, |
| 1052 | 'is_ipv6': is_ipv6, |
| 1053 | } |
| 1054 | ) |
| 1055 | |
| 1056 | def reset_fib(self, |
| 1057 | vrf_id, |
| 1058 | is_ipv6=0, |
| 1059 | ): |
| 1060 | """ Reset VRF (remove all routes etc.) request. |
| 1061 | |
| 1062 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 1063 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1064 | """ |
| 1065 | |
| 1066 | return self.api( |
| 1067 | self.papi.reset_fib, |
| 1068 | {'vrf_id': vrf_id, |
| 1069 | 'is_ipv6': is_ipv6, |
| 1070 | } |
| 1071 | ) |
| 1072 | |
| 1073 | def ip_dump(self, |
| 1074 | is_ipv6=0, |
| 1075 | ): |
| 1076 | """ Return IP dump. |
| 1077 | |
| 1078 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1079 | """ |
| 1080 | |
| 1081 | return self.api( |
| 1082 | self.papi.ip_dump, |
| 1083 | {'is_ipv6': is_ipv6, |
| 1084 | } |
| 1085 | ) |
| 1086 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 1087 | def sw_interface_span_enable_disable( |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 1088 | 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] | 1089 | """ |
| 1090 | |
| 1091 | :param sw_if_index_from: |
| 1092 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 1093 | :param state: |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 1094 | :param is_l2: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 1095 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1096 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1097 | {'sw_if_index_from': sw_if_index_from, |
| 1098 | 'sw_if_index_to': sw_if_index_to, |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 1099 | 'state': state, |
| 1100 | 'is_l2': is_l2, |
| 1101 | }) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1102 | |
| 1103 | def gre_tunnel_add_del(self, |
| 1104 | src_address, |
| 1105 | dst_address, |
| 1106 | outer_fib_id=0, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1107 | tunnel_type=0, |
| 1108 | instance=0xFFFFFFFF, |
| 1109 | session_id=0, |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1110 | is_add=1, |
| 1111 | is_ip6=0): |
| 1112 | """ Add a GRE tunnel |
| 1113 | |
| 1114 | :param src_address: |
| 1115 | :param dst_address: |
| 1116 | :param outer_fib_id: (Default value = 0) |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1117 | :param tunnel_type: (Default value = 0) |
| 1118 | :param instance: (Default value = 0xFFFFFFFF) |
| 1119 | :param session_id: (Defalt value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1120 | :param is_add: (Default value = 1) |
| 1121 | :param is_ipv6: (Default value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1122 | """ |
| 1123 | |
| 1124 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1125 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1126 | {'is_add': is_add, |
| 1127 | 'is_ipv6': is_ip6, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1128 | 'tunnel_type': tunnel_type, |
| 1129 | 'instance': instance, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1130 | 'src_address': src_address, |
| 1131 | 'dst_address': dst_address, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1132 | 'outer_fib_id': outer_fib_id, |
| 1133 | 'session_id': session_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1134 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1135 | |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1136 | def udp_encap_add_del(self, |
| 1137 | id, |
| 1138 | src_ip, |
| 1139 | dst_ip, |
| 1140 | src_port, |
| 1141 | dst_port, |
| 1142 | table_id=0, |
| 1143 | is_add=1, |
| 1144 | is_ip6=0): |
| 1145 | """ Add a GRE tunnel |
| 1146 | :param id: user provided ID |
| 1147 | :param src_ip: |
| 1148 | :param dst_ip: |
| 1149 | :param src_port: |
| 1150 | :param dst_port: |
| 1151 | :param outer_fib_id: (Default value = 0) |
| 1152 | :param is_add: (Default value = 1) |
| 1153 | :param is_ipv6: (Default value = 0) |
| 1154 | """ |
| 1155 | |
| 1156 | return self.api( |
| 1157 | self.papi.udp_encap_add_del, |
| 1158 | {'id': id, |
| 1159 | 'is_add': is_add, |
| 1160 | 'is_ip6': is_ip6, |
| 1161 | 'src_ip': src_ip, |
| 1162 | 'dst_ip': dst_ip, |
| 1163 | 'src_port': src_port, |
| 1164 | 'dst_port': dst_port, |
| 1165 | 'table_id': table_id} |
| 1166 | ) |
| 1167 | |
| 1168 | def udp_encap_dump(self): |
| 1169 | return self.api(self.papi.udp_encap_dump, {}) |
| 1170 | |
Neale Ranns | 43b1f44 | 2018-03-20 01:47:35 -0700 | [diff] [blame] | 1171 | def want_udp_encap_stats(self, enable=1): |
| 1172 | return self.api(self.papi.want_udp_encap_stats, |
| 1173 | {'enable': enable, |
| 1174 | 'pid': os.getpid()}) |
| 1175 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1176 | def mpls_fib_dump(self): |
| 1177 | return self.api(self.papi.mpls_fib_dump, {}) |
| 1178 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1179 | def mpls_table_add_del( |
| 1180 | self, |
| 1181 | table_id, |
| 1182 | is_add=1): |
| 1183 | """ |
| 1184 | |
| 1185 | :param table_id |
| 1186 | :param is_add: (Default value = 1) |
| 1187 | |
| 1188 | """ |
| 1189 | |
| 1190 | return self.api( |
| 1191 | self.papi.mpls_table_add_del, |
| 1192 | {'mt_table_id': table_id, |
| 1193 | 'mt_is_add': is_add}) |
| 1194 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1195 | def mpls_route_add_del( |
| 1196 | self, |
| 1197 | label, |
| 1198 | eos, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1199 | next_hop_proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1200 | next_hop_address, |
| 1201 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1202 | table_id=0, |
| 1203 | next_hop_table_id=0, |
| 1204 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1205 | next_hop_n_out_labels=0, |
| 1206 | next_hop_out_label_stack=[], |
| 1207 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1208 | is_resolve_host=0, |
| 1209 | is_resolve_attached=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1210 | is_interface_rx=0, |
| 1211 | is_rpf_id=0, |
| 1212 | is_multicast=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1213 | is_add=1, |
| 1214 | is_drop=0, |
| 1215 | is_multipath=0, |
| 1216 | classify_table_index=0xFFFFFFFF, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 1217 | is_classify=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1218 | """ |
| 1219 | |
| 1220 | :param dst_address_length: |
| 1221 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1222 | :param dst_address: |
| 1223 | :param next_hop_address: |
| 1224 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1225 | :param vrf_id: (Default value = 0) |
| 1226 | :param lookup_in_vrf: (Default value = 0) |
| 1227 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1228 | :param is_add: (Default value = 1) |
| 1229 | :param is_drop: (Default value = 0) |
| 1230 | :param is_ipv6: (Default value = 0) |
| 1231 | :param is_local: (Default value = 0) |
| 1232 | :param is_classify: (Default value = 0) |
| 1233 | :param is_multipath: (Default value = 0) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1234 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1235 | :param is_resolve_host: (Default value = 0) |
| 1236 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1237 | :param next_hop_weight: (Default value = 1) |
| 1238 | |
| 1239 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1240 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1241 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1242 | {'mr_label': label, |
| 1243 | 'mr_eos': eos, |
| 1244 | 'mr_table_id': table_id, |
| 1245 | 'mr_classify_table_index': classify_table_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1246 | 'mr_is_add': is_add, |
| 1247 | 'mr_is_classify': is_classify, |
| 1248 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1249 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1250 | 'mr_is_resolve_host': is_resolve_host, |
| 1251 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1252 | 'mr_is_interface_rx': is_interface_rx, |
| 1253 | 'mr_is_rpf_id': is_rpf_id, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1254 | 'mr_next_hop_proto': next_hop_proto, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1255 | 'mr_next_hop_weight': next_hop_weight, |
| 1256 | 'mr_next_hop': next_hop_address, |
| 1257 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1258 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1259 | 'mr_next_hop_table_id': next_hop_table_id, |
| 1260 | 'mr_next_hop_via_label': next_hop_via_label, |
| 1261 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1262 | |
| 1263 | def mpls_ip_bind_unbind( |
| 1264 | self, |
| 1265 | label, |
| 1266 | dst_address, |
| 1267 | dst_address_length, |
| 1268 | table_id=0, |
| 1269 | ip_table_id=0, |
| 1270 | is_ip4=1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1271 | is_bind=1): |
| 1272 | """ |
| 1273 | """ |
| 1274 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1275 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1276 | {'mb_mpls_table_id': table_id, |
| 1277 | 'mb_label': label, |
| 1278 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1279 | 'mb_is_bind': is_bind, |
| 1280 | 'mb_is_ip4': is_ip4, |
| 1281 | 'mb_address_length': dst_address_length, |
| 1282 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1283 | |
| 1284 | def mpls_tunnel_add_del( |
| 1285 | self, |
| 1286 | tun_sw_if_index, |
| 1287 | next_hop_proto_is_ip4, |
| 1288 | next_hop_address, |
| 1289 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1290 | next_hop_table_id=0, |
| 1291 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1292 | next_hop_n_out_labels=0, |
| 1293 | next_hop_out_label_stack=[], |
| 1294 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1295 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1296 | l2_only=0, |
| 1297 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1298 | """ |
| 1299 | |
| 1300 | :param dst_address_length: |
| 1301 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1302 | :param dst_address: |
| 1303 | :param next_hop_address: |
| 1304 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1305 | :param vrf_id: (Default value = 0) |
| 1306 | :param lookup_in_vrf: (Default value = 0) |
| 1307 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1308 | :param is_add: (Default value = 1) |
| 1309 | :param is_drop: (Default value = 0) |
| 1310 | :param is_ipv6: (Default value = 0) |
| 1311 | :param is_local: (Default value = 0) |
| 1312 | :param is_classify: (Default value = 0) |
| 1313 | :param is_multipath: (Default value = 0) |
| 1314 | :param is_resolve_host: (Default value = 0) |
| 1315 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1316 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1317 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1318 | |
| 1319 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1320 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1321 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1322 | {'mt_sw_if_index': tun_sw_if_index, |
| 1323 | 'mt_is_add': is_add, |
| 1324 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1325 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1326 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 1327 | 'mt_next_hop_weight': next_hop_weight, |
| 1328 | 'mt_next_hop': next_hop_address, |
| 1329 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1330 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1331 | 'mt_next_hop_table_id': next_hop_table_id, |
| 1332 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1333 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1334 | def nat44_interface_add_del_feature( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1335 | self, |
| 1336 | sw_if_index, |
| 1337 | is_inside=1, |
| 1338 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1339 | """Enable/disable NAT44 feature on the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1340 | |
| 1341 | :param sw_if_index: Software index of the interface |
| 1342 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1343 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1344 | """ |
| 1345 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1346 | self.papi.nat44_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1347 | {'is_add': is_add, |
| 1348 | 'is_inside': is_inside, |
| 1349 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1350 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1351 | def nat44_interface_add_del_output_feature( |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1352 | self, |
| 1353 | sw_if_index, |
| 1354 | is_inside=1, |
| 1355 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1356 | """Enable/disable NAT44 output feature on the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1357 | |
| 1358 | :param sw_if_index: Software index of the interface |
| 1359 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1360 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1361 | """ |
| 1362 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1363 | self.papi.nat44_interface_add_del_output_feature, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1364 | {'is_add': is_add, |
| 1365 | 'is_inside': is_inside, |
| 1366 | 'sw_if_index': sw_if_index}) |
| 1367 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1368 | def nat44_add_del_static_mapping( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1369 | self, |
| 1370 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1371 | external_ip=0, |
| 1372 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1373 | local_port=0, |
| 1374 | external_port=0, |
| 1375 | addr_only=1, |
| 1376 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1377 | protocol=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1378 | twice_nat=0, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1379 | self_twice_nat=0, |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1380 | out2in_only=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1381 | tag="", |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1382 | is_add=1): |
| 1383 | """Add/delete NAT44 static mapping |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1384 | |
| 1385 | :param local_ip: Local IP address |
| 1386 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1387 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1388 | :param local_port: Local port number (Default value = 0) |
| 1389 | :param external_port: External port number (Default value = 0) |
| 1390 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1391 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1392 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1393 | :param twice_nat: 1 if translate external host address and port |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1394 | :param self_twice_nat: 1 if translate external host address and port |
| 1395 | whenever external host address equals |
| 1396 | local address of internal host |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1397 | :param out2in_only: if 1 rule is matching only out2in direction |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1398 | :param tag: Opaque string tag |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1399 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1400 | """ |
| 1401 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1402 | self.papi.nat44_add_del_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1403 | {'is_add': is_add, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1404 | 'addr_only': addr_only, |
| 1405 | 'local_ip_address': local_ip, |
| 1406 | 'external_ip_address': external_ip, |
| 1407 | 'local_port': local_port, |
| 1408 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1409 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1410 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1411 | 'protocol': protocol, |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1412 | 'twice_nat': twice_nat, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1413 | 'self_twice_nat': self_twice_nat, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1414 | 'out2in_only': out2in_only, |
| 1415 | 'tag': tag}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1416 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1417 | def nat44_add_del_identity_mapping( |
| 1418 | self, |
| 1419 | ip='0', |
| 1420 | sw_if_index=0xFFFFFFFF, |
| 1421 | port=0, |
| 1422 | addr_only=1, |
| 1423 | vrf_id=0, |
| 1424 | protocol=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1425 | tag='', |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1426 | is_add=1): |
| 1427 | """Add/delete NAT44 identity mapping |
| 1428 | |
| 1429 | :param ip: IP address (Default value = 0) |
| 1430 | :param sw_if_index: Interface instead of IP address |
| 1431 | :param port: Port number (Default value = 0) |
| 1432 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1433 | :param vrf_id: VRF ID |
| 1434 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1435 | :param tag: Opaque string tag |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1436 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1437 | """ |
| 1438 | return self.api( |
| 1439 | self.papi.nat44_add_del_identity_mapping, |
| 1440 | {'is_add': is_add, |
| 1441 | 'addr_only': addr_only, |
| 1442 | 'ip_address': ip, |
| 1443 | 'port': port, |
| 1444 | 'sw_if_index': sw_if_index, |
| 1445 | 'vrf_id': vrf_id, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1446 | 'tag': tag, |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1447 | 'protocol': protocol}) |
| 1448 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1449 | def nat44_add_del_address_range( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1450 | self, |
| 1451 | first_ip_address, |
| 1452 | last_ip_address, |
| 1453 | is_add=1, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1454 | vrf_id=0xFFFFFFFF, |
| 1455 | twice_nat=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1456 | """Add/del NAT44 address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1457 | |
| 1458 | :param first_ip_address: First IP address |
| 1459 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1460 | :param vrf_id: VRF id for the address range |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1461 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1462 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1463 | """ |
| 1464 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1465 | self.papi.nat44_add_del_address_range, |
| 1466 | {'first_ip_address': first_ip_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1467 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1468 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1469 | 'twice_nat': twice_nat, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1470 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1471 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1472 | def nat44_address_dump(self): |
| 1473 | """Dump NAT44 addresses |
| 1474 | :return: Dictionary of NAT44 addresses |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1475 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1476 | return self.api(self.papi.nat44_address_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1477 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1478 | def nat44_interface_dump(self): |
| 1479 | """Dump interfaces with NAT44 feature |
| 1480 | :return: Dictionary of interfaces with NAT44 feature |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1481 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1482 | return self.api(self.papi.nat44_interface_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1483 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1484 | def nat44_interface_output_feature_dump(self): |
| 1485 | """Dump interfaces with NAT44 output feature |
| 1486 | :return: Dictionary of interfaces with NAT44 output feature |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1487 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1488 | return self.api(self.papi.nat44_interface_output_feature_dump, {}) |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1489 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1490 | def nat44_static_mapping_dump(self): |
| 1491 | """Dump NAT44 static mappings |
| 1492 | :return: Dictionary of NAT44 static mappings |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1493 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1494 | return self.api(self.papi.nat44_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1495 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1496 | def nat44_identity_mapping_dump(self): |
| 1497 | """Dump NAT44 identity mappings |
| 1498 | :return: Dictionary of NAT44 identity mappings |
| 1499 | """ |
| 1500 | return self.api(self.papi.nat44_identity_mapping_dump, {}) |
| 1501 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1502 | def nat_show_config(self): |
| 1503 | """Show NAT plugin config |
| 1504 | :return: NAT plugin config parameters |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1505 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1506 | return self.api(self.papi.nat_show_config, {}) |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1507 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1508 | def nat44_add_interface_addr( |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1509 | self, |
| 1510 | sw_if_index, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1511 | twice_nat=0, |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1512 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1513 | """Add/del NAT44 address from interface |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1514 | |
| 1515 | :param sw_if_index: Software index of the interface |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1516 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1517 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1518 | """ |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1519 | return self.api( |
| 1520 | self.papi.nat44_add_del_interface_addr, |
| 1521 | {'is_add': is_add, |
| 1522 | 'sw_if_index': sw_if_index, |
| 1523 | 'twice_nat': twice_nat}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1524 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1525 | def nat44_interface_addr_dump(self): |
| 1526 | """Dump NAT44 addresses interfaces |
| 1527 | :return: Dictionary of NAT44 addresses interfaces |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1528 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1529 | return self.api(self.papi.nat44_interface_addr_dump, {}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1530 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1531 | def nat_ipfix( |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1532 | self, |
| 1533 | domain_id=1, |
| 1534 | src_port=4739, |
| 1535 | enable=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1536 | """Enable/disable NAT IPFIX logging |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1537 | |
| 1538 | :param domain_id: Observation domain ID (Default value = 1) |
| 1539 | :param src_port: Source port number (Default value = 4739) |
| 1540 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1541 | """ |
| 1542 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1543 | self.papi.nat_ipfix_enable_disable, |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1544 | {'domain_id': domain_id, |
| 1545 | 'src_port': src_port, |
| 1546 | 'enable': enable}) |
| 1547 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1548 | def nat44_user_session_dump( |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1549 | self, |
| 1550 | ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1551 | vrf_id): |
| 1552 | """Dump NAT44 user's sessions |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1553 | |
| 1554 | :param ip_address: ip adress of the user to be dumped |
| 1555 | :param cpu_index: cpu_index on which the user is |
| 1556 | :param vrf_id: VRF ID |
| 1557 | :return: Dictionary of S-NAT sessions |
| 1558 | """ |
| 1559 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1560 | self.papi.nat44_user_session_dump, |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1561 | {'ip_address': ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1562 | 'vrf_id': vrf_id}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1563 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1564 | def nat44_user_dump(self): |
| 1565 | """Dump NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1566 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1567 | :return: Dictionary of NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1568 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1569 | return self.api(self.papi.nat44_user_dump, {}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1570 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1571 | def nat44_add_del_lb_static_mapping( |
| 1572 | self, |
| 1573 | external_addr, |
| 1574 | external_port, |
| 1575 | protocol, |
| 1576 | vrf_id=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1577 | twice_nat=0, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1578 | self_twice_nat=0, |
Matus Fabian | 240b5ef | 2018-01-11 04:09:17 -0800 | [diff] [blame] | 1579 | out2in_only=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1580 | tag='', |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1581 | local_num=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 1582 | locals=[], |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1583 | is_add=1): |
| 1584 | """Add/delete NAT44 load balancing static mapping |
| 1585 | |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1586 | :param twice_nat: 1 if translate external host address and port |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1587 | :param tag: Opaque string tag |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1588 | :param is_add - 1 if add, 0 if delete |
| 1589 | """ |
| 1590 | return self.api( |
| 1591 | self.papi.nat44_add_del_lb_static_mapping, |
| 1592 | {'is_add': is_add, |
| 1593 | 'external_addr': external_addr, |
| 1594 | 'external_port': external_port, |
| 1595 | 'protocol': protocol, |
| 1596 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1597 | 'twice_nat': twice_nat, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1598 | 'self_twice_nat': self_twice_nat, |
Matus Fabian | 240b5ef | 2018-01-11 04:09:17 -0800 | [diff] [blame] | 1599 | 'out2in_only': out2in_only, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1600 | 'tag': tag, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1601 | 'local_num': local_num, |
| 1602 | 'locals': locals}) |
| 1603 | |
| 1604 | def nat44_lb_static_mapping_dump(self): |
| 1605 | """Dump NAT44 load balancing static mappings |
| 1606 | |
| 1607 | :return: Dictionary of NAT44 load balancing static mapping |
| 1608 | """ |
| 1609 | return self.api(self.papi.nat44_lb_static_mapping_dump, {}) |
| 1610 | |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1611 | def nat44_del_session( |
| 1612 | self, |
| 1613 | addr, |
| 1614 | port, |
| 1615 | protocol, |
| 1616 | vrf_id=0, |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 1617 | is_in=1, |
| 1618 | ext_host_address=None, |
| 1619 | ext_host_port=0): |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1620 | """Delete NAT44 session |
| 1621 | |
| 1622 | :param addr: IPv4 address |
| 1623 | :param por: port number |
| 1624 | :param protocol: IP protocol number |
| 1625 | :param vrf_id: VRF ID |
| 1626 | :param is_in: 1 if inside network addres and port pari, 0 if outside |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 1627 | :param ext_host_address: external host IPv4 address |
| 1628 | :param ext_host_port: external host port |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1629 | """ |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 1630 | if ext_host_address is None: |
| 1631 | return self.api( |
| 1632 | self.papi.nat44_del_session, |
| 1633 | {'address': addr, |
| 1634 | 'port': port, |
| 1635 | 'protocol': protocol, |
| 1636 | 'vrf_id': vrf_id, |
| 1637 | 'is_in': is_in}) |
| 1638 | else: |
| 1639 | return self.api( |
| 1640 | self.papi.nat44_del_session, |
| 1641 | {'address': addr, |
| 1642 | 'port': port, |
| 1643 | 'protocol': protocol, |
| 1644 | 'vrf_id': vrf_id, |
| 1645 | 'is_in': is_in, |
| 1646 | 'ext_host_valid': 1, |
| 1647 | 'ext_host_address': ext_host_address, |
| 1648 | 'ext_host_port': ext_host_port}) |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1649 | |
Juraj Sloboda | 7b92979 | 2017-11-23 13:20:48 +0100 | [diff] [blame] | 1650 | def nat44_forwarding_enable_disable( |
| 1651 | self, |
| 1652 | enable): |
| 1653 | """Enable/disable forwarding for NAT44 |
| 1654 | |
| 1655 | :param enable: 1 for enable, 0 for disable |
| 1656 | """ |
| 1657 | return self.api( |
| 1658 | self.papi.nat44_forwarding_enable_disable, |
| 1659 | {'enable': enable}) |
| 1660 | |
Matus Fabian | efcd1e9 | 2017-08-15 06:59:19 -0700 | [diff] [blame] | 1661 | def nat_set_reass( |
| 1662 | self, |
| 1663 | timeout=2, |
| 1664 | max_reass=1024, |
| 1665 | max_frag=5, |
| 1666 | drop_frag=0, |
| 1667 | is_ip6=0): |
| 1668 | """Set NAT virtual fragmentation reassembly |
| 1669 | |
| 1670 | :param timeout: reassembly timeout (Default 2sec) |
| 1671 | :param max_reass: maximum concurrent reassemblies (Default 1024) |
| 1672 | :param max_frag: maximum fragmets per reassembly (Default 5) |
| 1673 | :param drop_frag: if 0 translate fragments, otherwise drop fragments |
| 1674 | :param is_ip6: 1 if IPv6, 0 if IPv4 |
| 1675 | """ |
| 1676 | return self.api( |
| 1677 | self.papi.nat_set_reass, |
| 1678 | {'timeout': timeout, |
| 1679 | 'max_reass': max_reass, |
| 1680 | 'max_frag': max_frag, |
| 1681 | 'drop_frag': drop_frag, |
| 1682 | 'is_ip6': is_ip6}) |
| 1683 | |
| 1684 | def nat_get_reass(self): |
| 1685 | """Get NAT virtual fragmentation reassembly configuration |
| 1686 | |
| 1687 | :return: NAT virtual fragmentation reassembly configuration |
| 1688 | """ |
| 1689 | return self.api(self.papi.nat_get_reass, {}) |
| 1690 | |
| 1691 | def nat_reass_dump(self): |
| 1692 | """Dump NAT virtual fragmentation reassemblies |
| 1693 | |
| 1694 | :return: Dictionary of NAT virtual fragmentation reassemblies |
| 1695 | """ |
| 1696 | return self.api(self.papi.nat_reass_dump, {}) |
| 1697 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1698 | def nat_det_add_del_map( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1699 | self, |
| 1700 | in_addr, |
| 1701 | in_plen, |
| 1702 | out_addr, |
| 1703 | out_plen, |
| 1704 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1705 | """Add/delete deterministic NAT mapping |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1706 | |
| 1707 | :param is_add - 1 if add, 0 if delete |
| 1708 | :param in_addr - inside IP address |
| 1709 | :param in_plen - inside IP address prefix length |
| 1710 | :param out_addr - outside IP address |
| 1711 | :param out_plen - outside IP address prefix length |
| 1712 | """ |
| 1713 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1714 | self.papi.nat_det_add_del_map, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1715 | {'is_add': is_add, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1716 | 'is_nat44': 1, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1717 | 'in_addr': in_addr, |
| 1718 | 'in_plen': in_plen, |
| 1719 | 'out_addr': out_addr, |
| 1720 | 'out_plen': out_plen}) |
| 1721 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1722 | def nat_det_forward( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1723 | self, |
| 1724 | in_addr): |
| 1725 | """Get outside address and port range from inside address |
| 1726 | |
| 1727 | :param in_addr - inside IP address |
| 1728 | """ |
| 1729 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1730 | self.papi.nat_det_forward, |
| 1731 | {'in_addr': in_addr, |
| 1732 | 'is_nat44': 1}) |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1733 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1734 | def nat_det_reverse( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1735 | self, |
| 1736 | out_addr, |
| 1737 | out_port): |
| 1738 | """Get inside address from outside address and port |
| 1739 | |
| 1740 | :param out_addr - outside IP address |
| 1741 | :param out_port - outside port |
| 1742 | """ |
| 1743 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1744 | self.papi.nat_det_reverse, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1745 | {'out_addr': out_addr, |
| 1746 | 'out_port': out_port}) |
| 1747 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1748 | def nat_det_map_dump(self): |
| 1749 | """Dump deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1750 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1751 | :return: Dictionary of deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1752 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1753 | return self.api(self.papi.nat_det_map_dump, {}) |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1754 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1755 | def nat_det_set_timeouts( |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1756 | self, |
| 1757 | udp=300, |
| 1758 | tcp_established=7440, |
| 1759 | tcp_transitory=240, |
| 1760 | icmp=60): |
| 1761 | """Set values of timeouts for deterministic NAT (in seconds) |
| 1762 | |
| 1763 | :param udp - UDP timeout (Default value = 300) |
| 1764 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1765 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1766 | :param icmp - ICMP timeout (Default value = 60) |
| 1767 | """ |
| 1768 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1769 | self.papi.nat_det_set_timeouts, |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1770 | {'udp': udp, |
| 1771 | 'tcp_established': tcp_established, |
| 1772 | 'tcp_transitory': tcp_transitory, |
| 1773 | 'icmp': icmp}) |
| 1774 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1775 | def nat_det_get_timeouts(self): |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1776 | """Get values of timeouts for deterministic NAT |
| 1777 | |
| 1778 | :return: Timeouts for deterministic NAT (in seconds) |
| 1779 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1780 | return self.api(self.papi.nat_det_get_timeouts, {}) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1781 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1782 | def nat_det_close_session_out( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1783 | self, |
| 1784 | out_addr, |
| 1785 | out_port, |
| 1786 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1787 | ext_port): |
| 1788 | """Close deterministic NAT session using outside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1789 | |
| 1790 | :param out_addr - outside IP address |
| 1791 | :param out_port - outside port |
| 1792 | :param ext_addr - external host IP address |
| 1793 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1794 | """ |
| 1795 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1796 | self.papi.nat_det_close_session_out, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1797 | {'out_addr': out_addr, |
| 1798 | 'out_port': out_port, |
| 1799 | 'ext_addr': ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1800 | 'ext_port': ext_port}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1801 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1802 | def nat_det_close_session_in( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1803 | self, |
| 1804 | in_addr, |
| 1805 | in_port, |
| 1806 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1807 | ext_port): |
| 1808 | """Close deterministic NAT session using inside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1809 | |
| 1810 | :param in_addr - inside IP address |
| 1811 | :param in_port - inside port |
| 1812 | :param ext_addr - external host IP address |
| 1813 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1814 | """ |
| 1815 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1816 | self.papi.nat_det_close_session_in, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1817 | {'in_addr': in_addr, |
| 1818 | 'in_port': in_port, |
| 1819 | 'ext_addr': ext_addr, |
| 1820 | 'ext_port': ext_port, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1821 | 'is_nat44': 1}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1822 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1823 | def nat_det_session_dump( |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1824 | self, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1825 | user_addr): |
| 1826 | """Dump deterministic NAT sessions belonging to a user |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1827 | |
| 1828 | :param user_addr - inside IP address of the user |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1829 | :return: Dictionary of deterministic NAT sessions |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1830 | """ |
| 1831 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1832 | self.papi.nat_det_session_dump, |
| 1833 | {'is_nat44': 1, |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1834 | 'user_addr': user_addr}) |
| 1835 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1836 | def nat64_add_del_pool_addr_range( |
| 1837 | self, |
| 1838 | start_addr, |
| 1839 | end_addr, |
| 1840 | vrf_id=0xFFFFFFFF, |
| 1841 | is_add=1): |
| 1842 | """Add/del address range to NAT64 pool |
| 1843 | |
| 1844 | :param start_addr: First IP address |
| 1845 | :param end_addr: Last IP address |
| 1846 | :param vrf_id: VRF id for the address range |
| 1847 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1848 | """ |
| 1849 | return self.api( |
| 1850 | self.papi.nat64_add_del_pool_addr_range, |
| 1851 | {'start_addr': start_addr, |
| 1852 | 'end_addr': end_addr, |
| 1853 | 'vrf_id': vrf_id, |
| 1854 | 'is_add': is_add}) |
| 1855 | |
| 1856 | def nat64_pool_addr_dump(self): |
| 1857 | """Dump NAT64 pool addresses |
| 1858 | :return: Dictionary of NAT64 pool addresses |
| 1859 | """ |
| 1860 | return self.api(self.papi.nat64_pool_addr_dump, {}) |
| 1861 | |
| 1862 | def nat64_add_del_interface( |
| 1863 | self, |
| 1864 | sw_if_index, |
| 1865 | is_inside=1, |
| 1866 | is_add=1): |
| 1867 | """Enable/disable NAT64 feature on the interface |
| 1868 | :param sw_if_index: Index of the interface |
| 1869 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1870 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1871 | """ |
| 1872 | return self.api( |
| 1873 | self.papi.nat64_add_del_interface, |
| 1874 | {'sw_if_index': sw_if_index, |
| 1875 | 'is_inside': is_inside, |
| 1876 | 'is_add': is_add}) |
| 1877 | |
| 1878 | def nat64_interface_dump(self): |
| 1879 | """Dump interfaces with NAT64 feature |
| 1880 | :return: Dictionary of interfaces with NAT64 feature |
| 1881 | """ |
| 1882 | return self.api(self.papi.nat64_interface_dump, {}) |
| 1883 | |
| 1884 | def nat64_add_del_static_bib( |
| 1885 | self, |
| 1886 | in_ip, |
| 1887 | out_ip, |
| 1888 | in_port, |
| 1889 | out_port, |
| 1890 | protocol, |
| 1891 | vrf_id=0, |
| 1892 | is_add=1): |
| 1893 | """Add/delete S-NAT static BIB entry |
| 1894 | |
| 1895 | :param in_ip: Inside IPv6 address |
| 1896 | :param out_ip: Outside IPv4 address |
| 1897 | :param in_port: Inside port number |
| 1898 | :param out_port: Outside port number |
| 1899 | :param protocol: IP protocol |
| 1900 | :param vrf_id: VRF ID (Default value = 0) |
| 1901 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1902 | """ |
| 1903 | return self.api( |
| 1904 | self.papi.nat64_add_del_static_bib, |
| 1905 | {'i_addr': in_ip, |
| 1906 | 'o_addr': out_ip, |
| 1907 | 'i_port': in_port, |
| 1908 | 'o_port': out_port, |
| 1909 | 'vrf_id': vrf_id, |
| 1910 | 'proto': protocol, |
| 1911 | 'is_add': is_add}) |
| 1912 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1913 | def nat64_bib_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1914 | """Dump NAT64 BIB |
| 1915 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1916 | :param protocol: IP protocol (Default value = 255, all BIBs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1917 | :returns: Dictionary of NAT64 BIB entries |
| 1918 | """ |
| 1919 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 1920 | |
| 1921 | def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440, |
| 1922 | tcp_incoming_syn=6): |
| 1923 | """Set values of timeouts for NAT64 (in seconds) |
| 1924 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1925 | :param udpi: UDP timeout (Default value = 300) |
| 1926 | :param icmp: ICMP timeout (Default value = 60) |
| 1927 | :param tcp_trans: TCP transitory timeout (Default value = 240) |
| 1928 | :param tcp_est: TCP established timeout (Default value = 7440) |
| 1929 | :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1930 | """ |
| 1931 | return self.api( |
| 1932 | self.papi.nat64_set_timeouts, |
| 1933 | {'udp': udp, |
| 1934 | 'icmp': icmp, |
| 1935 | 'tcp_trans': tcp_trans, |
| 1936 | 'tcp_est': tcp_est, |
| 1937 | 'tcp_incoming_syn': tcp_incoming_syn}) |
| 1938 | |
| 1939 | def nat64_get_timeouts(self): |
| 1940 | """Get values of timeouts for NAT64 |
| 1941 | |
| 1942 | :return: Timeouts for NAT64 (in seconds) |
| 1943 | """ |
| 1944 | return self.api(self.papi.nat64_get_timeouts, {}) |
| 1945 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1946 | def nat64_st_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1947 | """Dump NAT64 session table |
| 1948 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1949 | :param protocol: IP protocol (Default value = 255, all STs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1950 | :returns: Dictionary of NAT64 sesstion table entries |
| 1951 | """ |
| 1952 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 1953 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1954 | def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1): |
| 1955 | """Add/del NAT64 prefix |
| 1956 | |
| 1957 | :param prefix: NAT64 prefix |
| 1958 | :param plen: NAT64 prefix length |
| 1959 | :param vrf_id: VRF id of tenant (Default 0) |
| 1960 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1961 | """ |
| 1962 | return self.api( |
| 1963 | self.papi.nat64_add_del_prefix, |
| 1964 | {'prefix': prefix, |
| 1965 | 'prefix_len': plen, |
| 1966 | 'vrf_id': vrf_id, |
| 1967 | 'is_add': is_add}) |
| 1968 | |
| 1969 | def nat64_prefix_dump(self): |
| 1970 | """Dump NAT64 prefix |
| 1971 | |
| 1972 | :returns: Dictionary of NAT64 prefixes |
| 1973 | """ |
| 1974 | return self.api(self.papi.nat64_prefix_dump, {}) |
| 1975 | |
Matus Fabian | 0938dcf | 2017-11-08 01:59:38 -0800 | [diff] [blame] | 1976 | def nat64_add_interface_addr( |
| 1977 | self, |
| 1978 | sw_if_index, |
| 1979 | is_add=1): |
| 1980 | """Add/del NAT64 address from interface |
| 1981 | |
| 1982 | :param sw_if_index: Software index of the interface |
| 1983 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1984 | """ |
| 1985 | return self.api(self.papi.nat64_add_del_interface_addr, |
| 1986 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1987 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 1988 | def dslite_set_aftr_addr(self, ip6, ip4): |
| 1989 | """Set DS-Lite AFTR addresses |
| 1990 | |
| 1991 | :param ip4: IPv4 address |
| 1992 | :param ip6: IPv6 address |
| 1993 | """ |
| 1994 | return self.api( |
| 1995 | self.papi.dslite_set_aftr_addr, |
| 1996 | {'ip4_addr': ip4, |
| 1997 | 'ip6_addr': ip6}) |
| 1998 | |
Juraj Sloboda | c5c6a33 | 2018-01-09 16:08:32 +0100 | [diff] [blame] | 1999 | def dslite_set_b4_addr(self, ip6, ip4): |
| 2000 | """Set DS-Lite B4 IPv6 address |
| 2001 | |
| 2002 | :param ip4: IPv4 address |
| 2003 | :param ip6: IPv6 address |
| 2004 | """ |
| 2005 | return self.api( |
| 2006 | self.papi.dslite_set_b4_addr, |
| 2007 | {'ip4_addr': ip4, |
| 2008 | 'ip6_addr': ip6}) |
| 2009 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 2010 | def dslite_add_del_pool_addr_range( |
| 2011 | self, |
| 2012 | start_addr, |
| 2013 | end_addr, |
| 2014 | is_add=1): |
| 2015 | """Add/del address range to DS-Lite pool |
| 2016 | |
| 2017 | :param start_addr: First IP address |
| 2018 | :param end_addr: Last IP address |
| 2019 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2020 | """ |
| 2021 | return self.api( |
| 2022 | self.papi.dslite_add_del_pool_addr_range, |
| 2023 | {'start_addr': start_addr, |
| 2024 | 'end_addr': end_addr, |
| 2025 | 'is_add': is_add}) |
| 2026 | |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 2027 | def nat66_add_del_interface( |
| 2028 | self, |
| 2029 | sw_if_index, |
| 2030 | is_inside=1, |
| 2031 | is_add=1): |
| 2032 | """Enable/disable NAT66 feature on the interface |
| 2033 | :param sw_if_index: Index of the interface |
| 2034 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 2035 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2036 | """ |
| 2037 | return self.api( |
| 2038 | self.papi.nat66_add_del_interface, |
| 2039 | {'sw_if_index': sw_if_index, |
| 2040 | 'is_inside': is_inside, |
| 2041 | 'is_add': is_add}) |
| 2042 | |
| 2043 | def nat66_add_del_static_mapping( |
| 2044 | self, |
| 2045 | in_ip, |
| 2046 | out_ip, |
| 2047 | vrf_id=0, |
| 2048 | is_add=1): |
| 2049 | """Add/delete NAT66 static mapping |
| 2050 | |
| 2051 | :param in_ip: Inside IPv6 address |
| 2052 | :param out_ip: Outside IPv6 address |
| 2053 | :param vrf_id: VRF ID (Default value = 0) |
| 2054 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2055 | """ |
| 2056 | return self.api( |
| 2057 | self.papi.nat66_add_del_static_mapping, |
| 2058 | {'local_ip_address': in_ip, |
| 2059 | 'external_ip_address': out_ip, |
| 2060 | 'vrf_id': vrf_id, |
| 2061 | 'is_add': is_add}) |
| 2062 | |
| 2063 | def nat66_interface_dump(self): |
| 2064 | """Dump interfaces with NAT66 feature |
| 2065 | :return: Dictionary of interfaces with NAT66 feature |
| 2066 | """ |
| 2067 | return self.api(self.papi.nat66_interface_dump, {}) |
| 2068 | |
| 2069 | def nat66_static_mapping_dump(self): |
| 2070 | """Dump NAT66 static mappings |
| 2071 | :return: Dictionary of NAT66 static mappings |
| 2072 | """ |
| 2073 | return self.api(self.papi.nat66_static_mapping_dump, {}) |
| 2074 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2075 | def control_ping(self): |
| 2076 | self.api(self.papi.control_ping) |
| 2077 | |
| 2078 | 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] | 2079 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 2080 | bfd_key_id=None, conf_key_id=None): |
| 2081 | if bfd_key_id is None: |
| 2082 | return self.api(self.papi.bfd_udp_add, |
| 2083 | { |
| 2084 | 'sw_if_index': sw_if_index, |
| 2085 | 'desired_min_tx': desired_min_tx, |
| 2086 | 'required_min_rx': required_min_rx, |
| 2087 | 'local_addr': local_addr, |
| 2088 | 'peer_addr': peer_addr, |
| 2089 | 'is_ipv6': is_ipv6, |
| 2090 | 'detect_mult': detect_mult, |
| 2091 | }) |
| 2092 | else: |
| 2093 | return self.api(self.papi.bfd_udp_add, |
| 2094 | { |
| 2095 | 'sw_if_index': sw_if_index, |
| 2096 | 'desired_min_tx': desired_min_tx, |
| 2097 | 'required_min_rx': required_min_rx, |
| 2098 | 'local_addr': local_addr, |
| 2099 | 'peer_addr': peer_addr, |
| 2100 | 'is_ipv6': is_ipv6, |
| 2101 | 'detect_mult': detect_mult, |
| 2102 | 'is_authenticated': 1, |
| 2103 | 'bfd_key_id': bfd_key_id, |
| 2104 | 'conf_key_id': conf_key_id, |
| 2105 | }) |
| 2106 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 2107 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 2108 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 2109 | return self.api(self.papi.bfd_udp_mod, |
| 2110 | { |
| 2111 | 'sw_if_index': sw_if_index, |
| 2112 | 'desired_min_tx': desired_min_tx, |
| 2113 | 'required_min_rx': required_min_rx, |
| 2114 | 'local_addr': local_addr, |
| 2115 | 'peer_addr': peer_addr, |
| 2116 | 'is_ipv6': is_ipv6, |
| 2117 | 'detect_mult': detect_mult, |
| 2118 | }) |
| 2119 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2120 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 2121 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 2122 | is_delayed=False): |
| 2123 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2124 | { |
| 2125 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2126 | 'local_addr': local_addr, |
| 2127 | 'peer_addr': peer_addr, |
| 2128 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2129 | 'is_delayed': 1 if is_delayed else 0, |
| 2130 | 'bfd_key_id': bfd_key_id, |
| 2131 | 'conf_key_id': conf_key_id, |
| 2132 | }) |
| 2133 | |
| 2134 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 2135 | is_ipv6=0, is_delayed=False): |
| 2136 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 2137 | { |
| 2138 | 'sw_if_index': sw_if_index, |
| 2139 | 'local_addr': local_addr, |
| 2140 | 'peer_addr': peer_addr, |
| 2141 | 'is_ipv6': is_ipv6, |
| 2142 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2143 | }) |
| 2144 | |
| 2145 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 2146 | return self.api(self.papi.bfd_udp_del, |
| 2147 | { |
| 2148 | 'sw_if_index': sw_if_index, |
| 2149 | 'local_addr': local_addr, |
| 2150 | 'peer_addr': peer_addr, |
| 2151 | 'is_ipv6': is_ipv6, |
| 2152 | }) |
| 2153 | |
| 2154 | def bfd_udp_session_dump(self): |
| 2155 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 2156 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2157 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 2158 | peer_addr, is_ipv6=0): |
| 2159 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2160 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2161 | 'sw_if_index': sw_if_index, |
| 2162 | 'local_addr': local_addr, |
| 2163 | 'peer_addr': peer_addr, |
| 2164 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2165 | }) |
| 2166 | |
| 2167 | def want_bfd_events(self, enable_disable=1): |
| 2168 | return self.api(self.papi.want_bfd_events, { |
| 2169 | 'enable_disable': enable_disable, |
| 2170 | 'pid': os.getpid(), |
| 2171 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2172 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2173 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 2174 | return self.api(self.papi.bfd_auth_set_key, { |
| 2175 | 'conf_key_id': conf_key_id, |
| 2176 | 'auth_type': auth_type, |
| 2177 | 'key': key, |
| 2178 | 'key_len': len(key), |
| 2179 | }) |
| 2180 | |
| 2181 | def bfd_auth_del_key(self, conf_key_id): |
| 2182 | return self.api(self.papi.bfd_auth_del_key, { |
| 2183 | 'conf_key_id': conf_key_id, |
| 2184 | }) |
| 2185 | |
| 2186 | def bfd_auth_keys_dump(self): |
| 2187 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 2188 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2189 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 2190 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 2191 | {'sw_if_index': sw_if_index}) |
| 2192 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2193 | def bfd_udp_del_echo_source(self): |
| 2194 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 2195 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2196 | def classify_add_del_table( |
| 2197 | self, |
| 2198 | is_add, |
| 2199 | mask, |
| 2200 | match_n_vectors=1, |
| 2201 | table_index=0xFFFFFFFF, |
| 2202 | nbuckets=2, |
| 2203 | memory_size=2097152, |
| 2204 | skip_n_vectors=0, |
| 2205 | next_table_index=0xFFFFFFFF, |
| 2206 | miss_next_index=0xFFFFFFFF, |
| 2207 | current_data_flag=0, |
| 2208 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2209 | """ |
| 2210 | :param is_add: |
| 2211 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 2212 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 2213 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2214 | :param nbuckets: (Default value = 2) |
| 2215 | :param memory_size: (Default value = 2097152) |
| 2216 | :param skip_n_vectors: (Default value = 0) |
| 2217 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 2218 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 2219 | :param current_data_flag: (Default value = 0) |
| 2220 | :param current_data_offset: (Default value = 0) |
| 2221 | """ |
| 2222 | |
| 2223 | return self.api( |
| 2224 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2225 | {'is_add': is_add, |
| 2226 | 'table_index': table_index, |
| 2227 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2228 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2229 | 'skip_n_vectors': skip_n_vectors, |
| 2230 | 'match_n_vectors': match_n_vectors, |
| 2231 | 'next_table_index': next_table_index, |
| 2232 | 'miss_next_index': miss_next_index, |
| 2233 | 'current_data_flag': current_data_flag, |
| 2234 | 'current_data_offset': current_data_offset, |
| 2235 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2236 | |
| 2237 | def classify_add_del_session( |
| 2238 | self, |
| 2239 | is_add, |
| 2240 | table_index, |
| 2241 | match, |
| 2242 | opaque_index=0xFFFFFFFF, |
| 2243 | hit_next_index=0xFFFFFFFF, |
| 2244 | advance=0, |
| 2245 | action=0, |
| 2246 | metadata=0): |
| 2247 | """ |
| 2248 | :param is_add: |
| 2249 | :param table_index: |
| 2250 | :param match: |
| 2251 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 2252 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 2253 | :param advance: (Default value = 0) |
| 2254 | :param action: (Default value = 0) |
| 2255 | :param metadata: (Default value = 0) |
| 2256 | """ |
| 2257 | |
| 2258 | return self.api( |
| 2259 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2260 | {'is_add': is_add, |
| 2261 | 'table_index': table_index, |
| 2262 | 'hit_next_index': hit_next_index, |
| 2263 | 'opaque_index': opaque_index, |
| 2264 | 'advance': advance, |
| 2265 | 'action': action, |
| 2266 | 'metadata': metadata, |
| 2267 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2268 | |
| 2269 | def input_acl_set_interface( |
| 2270 | self, |
| 2271 | is_add, |
| 2272 | sw_if_index, |
| 2273 | ip4_table_index=0xFFFFFFFF, |
| 2274 | ip6_table_index=0xFFFFFFFF, |
| 2275 | l2_table_index=0xFFFFFFFF): |
| 2276 | """ |
| 2277 | :param is_add: |
| 2278 | :param sw_if_index: |
| 2279 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2280 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2281 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2282 | """ |
| 2283 | |
| 2284 | return self.api( |
| 2285 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2286 | {'sw_if_index': sw_if_index, |
| 2287 | 'ip4_table_index': ip4_table_index, |
| 2288 | 'ip6_table_index': ip6_table_index, |
| 2289 | 'l2_table_index': l2_table_index, |
| 2290 | 'is_add': is_add}) |
| 2291 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 2292 | def output_acl_set_interface( |
| 2293 | self, |
| 2294 | is_add, |
| 2295 | sw_if_index, |
| 2296 | ip4_table_index=0xFFFFFFFF, |
| 2297 | ip6_table_index=0xFFFFFFFF, |
| 2298 | l2_table_index=0xFFFFFFFF): |
| 2299 | """ |
| 2300 | :param is_add: |
| 2301 | :param sw_if_index: |
| 2302 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2303 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2304 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2305 | """ |
| 2306 | |
| 2307 | return self.api( |
| 2308 | self.papi.output_acl_set_interface, |
| 2309 | {'sw_if_index': sw_if_index, |
| 2310 | 'ip4_table_index': ip4_table_index, |
| 2311 | 'ip6_table_index': ip6_table_index, |
| 2312 | 'l2_table_index': l2_table_index, |
| 2313 | 'is_add': is_add}) |
| 2314 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2315 | def set_ipfix_exporter( |
| 2316 | self, |
| 2317 | collector_address, |
| 2318 | src_address, |
| 2319 | path_mtu, |
| 2320 | template_interval, |
| 2321 | vrf_id=0, |
| 2322 | collector_port=4739, |
| 2323 | udp_checksum=0): |
| 2324 | return self.api( |
| 2325 | self.papi.set_ipfix_exporter, |
| 2326 | { |
| 2327 | 'collector_address': collector_address, |
| 2328 | 'collector_port': collector_port, |
| 2329 | 'src_address': src_address, |
| 2330 | 'vrf_id': vrf_id, |
| 2331 | 'path_mtu': path_mtu, |
| 2332 | 'template_interval': template_interval, |
| 2333 | 'udp_checksum': udp_checksum, |
| 2334 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2335 | |
| 2336 | def dhcp_proxy_config(self, |
| 2337 | dhcp_server, |
| 2338 | dhcp_src_address, |
| 2339 | rx_table_id=0, |
| 2340 | server_table_id=0, |
| 2341 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2342 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2343 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2344 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2345 | { |
| 2346 | 'rx_vrf_id': rx_table_id, |
| 2347 | 'server_vrf_id': server_table_id, |
| 2348 | 'is_ipv6': is_ipv6, |
| 2349 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2350 | 'dhcp_server': dhcp_server, |
| 2351 | 'dhcp_src_address': dhcp_src_address, |
| 2352 | }) |
| 2353 | |
| 2354 | def dhcp_proxy_set_vss(self, |
| 2355 | table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2356 | vss_type=255, |
| 2357 | vpn_ascii_id="", |
| 2358 | oui=0, |
| 2359 | vpn_index=0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2360 | is_add=1, |
| 2361 | is_ip6=0): |
| 2362 | return self.api( |
| 2363 | self.papi.dhcp_proxy_set_vss, |
| 2364 | { |
| 2365 | 'tbl_id': table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2366 | 'vss_type': vss_type, |
| 2367 | 'vpn_ascii_id': vpn_ascii_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2368 | 'oui': oui, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2369 | 'vpn_index': vpn_index, |
| 2370 | 'is_add': is_add, |
| 2371 | 'is_ipv6': is_ip6, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2372 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2373 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 2374 | def dhcp_client_dump(self): |
| 2375 | return self.api(self.papi.dhcp_client_dump, {}) |
| 2376 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2377 | def dhcp_client(self, |
| 2378 | sw_if_index, |
| 2379 | hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2380 | client_id='', |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2381 | is_add=1, |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 2382 | set_broadcast_flag=1, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2383 | want_dhcp_events=0): |
| 2384 | return self.api( |
| 2385 | self.papi.dhcp_client_config, |
| 2386 | { |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2387 | 'is_add': is_add, |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 2388 | 'client': { |
| 2389 | 'sw_if_index': sw_if_index, |
| 2390 | 'hostname': hostname, |
| 2391 | 'id': client_id, |
| 2392 | 'want_dhcp_event': want_dhcp_events, |
| 2393 | 'set_broadcast_flag': set_broadcast_flag, |
| 2394 | 'pid': os.getpid()} |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2395 | }) |
| 2396 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2397 | def ip_mroute_add_del(self, |
| 2398 | src_address, |
| 2399 | grp_address, |
| 2400 | grp_address_length, |
| 2401 | e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2402 | next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2403 | next_hop_sw_if_index, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 2404 | next_hop_address, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2405 | i_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2406 | bier_imp=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2407 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2408 | table_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2409 | is_add=1, |
| 2410 | is_ipv6=0, |
| 2411 | is_local=0): |
| 2412 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2413 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2414 | """ |
| 2415 | return self.api( |
| 2416 | self.papi.ip_mroute_add_del, |
| 2417 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 2418 | 'entry_flags': e_flags, |
| 2419 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2420 | 'table_id': table_id, |
| 2421 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2422 | 'is_add': is_add, |
| 2423 | 'is_ipv6': is_ipv6, |
| 2424 | 'is_local': is_local, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2425 | 'bier_imp': bier_imp, |
| 2426 | 'next_hop_afi': next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2427 | 'grp_address_length': grp_address_length, |
| 2428 | 'grp_address': grp_address, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 2429 | 'src_address': src_address, |
| 2430 | 'nh_address': next_hop_address}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2431 | |
| 2432 | def mfib_signal_dump(self): |
| 2433 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 2434 | |
| 2435 | def ip_mfib_dump(self): |
| 2436 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2437 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2438 | def ip6_mfib_dump(self): |
| 2439 | return self.api(self.papi.ip6_mfib_dump, {}) |
| 2440 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2441 | def lisp_enable_disable(self, is_enabled): |
| 2442 | return self.api( |
| 2443 | self.papi.lisp_enable_disable, |
| 2444 | { |
| 2445 | 'is_en': is_enabled, |
| 2446 | }) |
| 2447 | |
| 2448 | def lisp_locator_set(self, |
| 2449 | ls_name, |
| 2450 | is_add=1): |
| 2451 | return self.api( |
| 2452 | self.papi.lisp_add_del_locator_set, |
| 2453 | { |
| 2454 | 'is_add': is_add, |
| 2455 | 'locator_set_name': ls_name |
| 2456 | }) |
| 2457 | |
| 2458 | def lisp_locator_set_dump(self): |
| 2459 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 2460 | |
| 2461 | def lisp_locator(self, |
| 2462 | ls_name, |
| 2463 | sw_if_index, |
| 2464 | priority=1, |
| 2465 | weight=1, |
| 2466 | is_add=1): |
| 2467 | return self.api( |
| 2468 | self.papi.lisp_add_del_locator, |
| 2469 | { |
| 2470 | 'is_add': is_add, |
| 2471 | 'locator_set_name': ls_name, |
| 2472 | 'sw_if_index': sw_if_index, |
| 2473 | 'priority': priority, |
| 2474 | 'weight': weight |
| 2475 | }) |
| 2476 | |
| 2477 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 2478 | return self.api( |
| 2479 | self.papi.lisp_locator_dump, |
| 2480 | { |
| 2481 | 'is_index_set': is_index_set, |
| 2482 | 'ls_name': ls_name, |
| 2483 | 'ls_index': ls_index, |
| 2484 | }) |
| 2485 | |
| 2486 | def lisp_local_mapping(self, |
| 2487 | ls_name, |
| 2488 | eid_type, |
| 2489 | eid, |
| 2490 | prefix_len, |
| 2491 | vni=0, |
| 2492 | key_id=0, |
| 2493 | key="", |
| 2494 | is_add=1): |
| 2495 | return self.api( |
| 2496 | self.papi.lisp_add_del_local_eid, |
| 2497 | { |
| 2498 | 'locator_set_name': ls_name, |
| 2499 | 'is_add': is_add, |
| 2500 | 'eid_type': eid_type, |
| 2501 | 'eid': eid, |
| 2502 | 'prefix_len': prefix_len, |
| 2503 | 'vni': vni, |
| 2504 | 'key_id': key_id, |
| 2505 | 'key': key |
| 2506 | }) |
| 2507 | |
| 2508 | def lisp_eid_table_dump(self, |
| 2509 | eid_set=0, |
| 2510 | prefix_length=0, |
| 2511 | vni=0, |
| 2512 | eid_type=0, |
| 2513 | eid=None, |
| 2514 | filter_opt=0): |
| 2515 | return self.api( |
| 2516 | self.papi.lisp_eid_table_dump, |
| 2517 | { |
| 2518 | 'eid_set': eid_set, |
| 2519 | 'prefix_length': prefix_length, |
| 2520 | 'vni': vni, |
| 2521 | 'eid_type': eid_type, |
| 2522 | 'eid': eid, |
| 2523 | 'filter': filter_opt, |
| 2524 | }) |
| 2525 | |
| 2526 | def lisp_remote_mapping(self, |
| 2527 | eid_type, |
| 2528 | eid, |
| 2529 | eid_prefix_len=0, |
| 2530 | vni=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 2531 | rlocs=[], |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2532 | rlocs_num=0, |
| 2533 | is_src_dst=0, |
| 2534 | is_add=1): |
| 2535 | return self.api( |
| 2536 | self.papi.lisp_add_del_remote_mapping, |
| 2537 | { |
| 2538 | 'is_add': is_add, |
| 2539 | 'eid_type': eid_type, |
| 2540 | 'eid': eid, |
| 2541 | 'eid_len': eid_prefix_len, |
| 2542 | 'rloc_num': rlocs_num, |
| 2543 | 'rlocs': rlocs, |
| 2544 | 'vni': vni, |
| 2545 | 'is_src_dst': is_src_dst, |
| 2546 | }) |
| 2547 | |
| 2548 | def lisp_adjacency(self, |
| 2549 | leid, |
| 2550 | reid, |
| 2551 | leid_len, |
| 2552 | reid_len, |
| 2553 | eid_type, |
| 2554 | is_add=1, |
| 2555 | vni=0): |
| 2556 | return self.api( |
| 2557 | self.papi.lisp_add_del_adjacency, |
| 2558 | { |
| 2559 | 'is_add': is_add, |
| 2560 | 'vni': vni, |
| 2561 | 'eid_type': eid_type, |
| 2562 | 'leid': leid, |
| 2563 | 'reid': reid, |
| 2564 | 'leid_len': leid_len, |
| 2565 | 'reid_len': reid_len, |
| 2566 | }) |
| 2567 | |
| 2568 | def lisp_adjacencies_get(self, vni=0): |
| 2569 | return self.api( |
| 2570 | self.papi.lisp_adjacencies_get, |
| 2571 | { |
| 2572 | 'vni': vni |
| 2573 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2574 | |
| 2575 | def map_add_domain(self, |
| 2576 | ip6_prefix, |
| 2577 | ip6_prefix_len, |
| 2578 | ip6_src, |
| 2579 | ip6_src_prefix_len, |
| 2580 | ip4_prefix, |
| 2581 | ip4_prefix_len, |
| 2582 | ea_bits_len=0, |
| 2583 | psid_offset=0, |
| 2584 | psid_length=0, |
| 2585 | is_translation=0, |
Juraj Sloboda | cba6936 | 2017-12-19 02:09:32 +0100 | [diff] [blame] | 2586 | is_rfc6052=0, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2587 | mtu=1280): |
| 2588 | return self.api( |
| 2589 | self.papi.map_add_domain, |
| 2590 | { |
| 2591 | 'ip6_prefix': ip6_prefix, |
| 2592 | 'ip6_prefix_len': ip6_prefix_len, |
| 2593 | 'ip4_prefix': ip4_prefix, |
| 2594 | 'ip4_prefix_len': ip4_prefix_len, |
| 2595 | 'ip6_src': ip6_src, |
| 2596 | 'ip6_src_prefix_len': ip6_src_prefix_len, |
| 2597 | 'ea_bits_len': ea_bits_len, |
| 2598 | 'psid_offset': psid_offset, |
| 2599 | 'psid_length': psid_length, |
| 2600 | 'is_translation': is_translation, |
Juraj Sloboda | cba6936 | 2017-12-19 02:09:32 +0100 | [diff] [blame] | 2601 | 'is_rfc6052': is_rfc6052, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2602 | 'mtu': mtu |
| 2603 | }) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2604 | |
| 2605 | def gtpu_add_del_tunnel( |
| 2606 | self, |
| 2607 | src_addr, |
| 2608 | dst_addr, |
| 2609 | is_add=1, |
| 2610 | is_ipv6=0, |
| 2611 | mcast_sw_if_index=0xFFFFFFFF, |
| 2612 | encap_vrf_id=0, |
| 2613 | decap_next_index=0xFFFFFFFF, |
| 2614 | teid=0): |
| 2615 | """ |
| 2616 | |
| 2617 | :param is_add: (Default value = 1) |
| 2618 | :param is_ipv6: (Default value = 0) |
| 2619 | :param src_addr: |
| 2620 | :param dst_addr: |
| 2621 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2622 | :param encap_vrf_id: (Default value = 0) |
| 2623 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2624 | :param teid: (Default value = 0) |
| 2625 | |
| 2626 | """ |
| 2627 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 2628 | {'is_add': is_add, |
| 2629 | 'is_ipv6': is_ipv6, |
| 2630 | 'src_address': src_addr, |
| 2631 | 'dst_address': dst_addr, |
| 2632 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2633 | 'encap_vrf_id': encap_vrf_id, |
| 2634 | 'decap_next_index': decap_next_index, |
| 2635 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 2636 | |
| 2637 | def vxlan_gpe_add_del_tunnel( |
| 2638 | self, |
| 2639 | src_addr, |
| 2640 | dst_addr, |
| 2641 | mcast_sw_if_index=0xFFFFFFFF, |
| 2642 | is_add=1, |
| 2643 | is_ipv6=0, |
| 2644 | encap_vrf_id=0, |
| 2645 | decap_vrf_id=0, |
| 2646 | protocol=3, |
| 2647 | vni=0): |
| 2648 | """ |
| 2649 | |
| 2650 | :param local: |
| 2651 | :param remote: |
| 2652 | :param is_add: (Default value = 1) |
| 2653 | :param is_ipv6: (Default value = 0) |
| 2654 | :param encap_vrf_id: (Default value = 0) |
| 2655 | :param decap_vrf_id: (Default value = 0) |
| 2656 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2657 | :param protocol: (Default value = 3) |
| 2658 | :param vni: (Default value = 0) |
| 2659 | |
| 2660 | """ |
| 2661 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 2662 | {'is_add': is_add, |
| 2663 | 'is_ipv6': is_ipv6, |
| 2664 | 'local': src_addr, |
| 2665 | 'remote': dst_addr, |
| 2666 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2667 | 'encap_vrf_id': encap_vrf_id, |
| 2668 | 'decap_vrf_id': decap_vrf_id, |
| 2669 | 'protocol': protocol, |
| 2670 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2671 | |
| 2672 | def pppoe_add_del_session( |
| 2673 | self, |
| 2674 | client_ip, |
| 2675 | client_mac, |
| 2676 | session_id=0, |
| 2677 | is_add=1, |
| 2678 | is_ipv6=0, |
| 2679 | decap_vrf_id=0): |
| 2680 | """ |
| 2681 | |
| 2682 | :param is_add: (Default value = 1) |
| 2683 | :param is_ipv6: (Default value = 0) |
| 2684 | :param client_ip: |
| 2685 | :param session_id: (Default value = 0) |
| 2686 | :param client_mac: |
| 2687 | :param decap_vrf_id: (Default value = 0) |
| 2688 | |
| 2689 | """ |
| 2690 | return self.api(self.papi.pppoe_add_del_session, |
| 2691 | {'is_add': is_add, |
| 2692 | 'is_ipv6': is_ipv6, |
| 2693 | 'session_id': session_id, |
| 2694 | 'client_ip': client_ip, |
| 2695 | 'decap_vrf_id': decap_vrf_id, |
| 2696 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2697 | |
| 2698 | def sr_localsid_add_del(self, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2699 | localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2700 | behavior, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2701 | nh_addr4, |
| 2702 | nh_addr6, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2703 | is_del=0, |
| 2704 | end_psp=0, |
| 2705 | sw_if_index=0xFFFFFFFF, |
| 2706 | vlan_index=0, |
| 2707 | fib_table=0, |
| 2708 | ): |
| 2709 | """ Add/del IPv6 SR local-SID. |
| 2710 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2711 | :param localsid: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2712 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 2713 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2714 | :param nh_addr4: |
| 2715 | :param nh_addr6: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2716 | :param is_del: (Default value = 0) |
| 2717 | :param end_psp: (Default value = 0) |
| 2718 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 2719 | :param vlan_index: (Default value = 0) |
| 2720 | :param fib_table: (Default value = 0) |
| 2721 | """ |
| 2722 | return self.api( |
| 2723 | self.papi.sr_localsid_add_del, |
| 2724 | {'is_del': is_del, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2725 | 'localsid': localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2726 | 'end_psp': end_psp, |
| 2727 | 'behavior': behavior, |
| 2728 | 'sw_if_index': sw_if_index, |
| 2729 | 'vlan_index': vlan_index, |
| 2730 | 'fib_table': fib_table, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2731 | 'nh_addr4': nh_addr4, |
| 2732 | 'nh_addr6': nh_addr6 |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2733 | } |
| 2734 | ) |
| 2735 | |
| 2736 | def sr_policy_add( |
| 2737 | self, |
| 2738 | bsid_addr, |
| 2739 | weight=1, |
| 2740 | is_encap=1, |
| 2741 | type=0, |
| 2742 | fib_table=0, |
| 2743 | n_segments=0, |
| 2744 | segments=[]): |
| 2745 | """ |
| 2746 | :param bsid_addr: bindingSID of the SR Policy |
| 2747 | :param weight: weight of the sid list. optional. (default: 1) |
| 2748 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 2749 | (default: Encap) |
| 2750 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 2751 | (default: default) |
| 2752 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 2753 | (default: 0) |
| 2754 | :param n_segments: number of segments \ |
| 2755 | (default: 0) |
| 2756 | :param segments: a vector of IPv6 address composing the segment list \ |
| 2757 | (default: []) |
| 2758 | """ |
| 2759 | return self.api( |
| 2760 | self.papi.sr_policy_add, |
| 2761 | {'bsid_addr': bsid_addr, |
| 2762 | 'weight': weight, |
| 2763 | 'is_encap': is_encap, |
| 2764 | 'type': type, |
| 2765 | 'fib_table': fib_table, |
| 2766 | 'n_segments': n_segments, |
| 2767 | 'segments': segments |
| 2768 | } |
| 2769 | ) |
| 2770 | |
| 2771 | def sr_policy_del( |
| 2772 | self, |
| 2773 | bsid_addr, |
| 2774 | sr_policy_index=0): |
| 2775 | """ |
| 2776 | :param bsid: bindingSID of the SR Policy |
| 2777 | :param sr_policy_index: index of the sr policy (default: 0) |
| 2778 | """ |
| 2779 | return self.api( |
| 2780 | self.papi.sr_policy_del, |
| 2781 | {'bsid_addr': bsid_addr, |
| 2782 | 'sr_policy_index': sr_policy_index |
| 2783 | }) |
| 2784 | |
| 2785 | def sr_steering_add_del( |
| 2786 | self, |
| 2787 | is_del, |
| 2788 | bsid_addr, |
| 2789 | sr_policy_index, |
| 2790 | table_id, |
| 2791 | prefix_addr, |
| 2792 | mask_width, |
| 2793 | sw_if_index, |
| 2794 | traffic_type): |
| 2795 | """ |
| 2796 | Steer traffic L2 and L3 traffic through a given SR policy |
| 2797 | |
| 2798 | :param is_del: delete or add |
| 2799 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 2800 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 2801 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 2802 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 2803 | :param mask_width: is the mask for L3 traffic type |
| 2804 | :param sw_if_index: is the incoming interface for L2 traffic |
| 2805 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 2806 | """ |
| 2807 | return self.api( |
| 2808 | self.papi.sr_steering_add_del, |
| 2809 | {'is_del': is_del, |
| 2810 | 'bsid_addr': bsid_addr, |
| 2811 | 'sr_policy_index': sr_policy_index, |
| 2812 | 'table_id': table_id, |
| 2813 | 'prefix_addr': prefix_addr, |
| 2814 | 'mask_width': mask_width, |
| 2815 | 'sw_if_index': sw_if_index, |
| 2816 | 'traffic_type': traffic_type |
| 2817 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2818 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2819 | def acl_add_replace(self, acl_index, r, tag='', |
| 2820 | expected_retval=0): |
| 2821 | """Add/replace an ACL |
| 2822 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 2823 | :param acl_rule r: ACL rules array. |
| 2824 | :param str tag: symbolic tag (description) for this ACL. |
| 2825 | :param int count: number of rules. |
| 2826 | """ |
| 2827 | return self.api(self.papi.acl_add_replace, |
| 2828 | {'acl_index': acl_index, |
| 2829 | 'r': r, |
| 2830 | 'count': len(r), |
| 2831 | 'tag': tag}, |
| 2832 | expected_retval=expected_retval) |
| 2833 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 2834 | def acl_del(self, acl_index, expected_retval=0): |
| 2835 | """ |
| 2836 | |
| 2837 | :param acl_index: |
| 2838 | :return: |
| 2839 | """ |
| 2840 | return self.api(self.papi.acl_del, |
| 2841 | {'acl_index': acl_index}, |
| 2842 | expected_retval=expected_retval) |
| 2843 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2844 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 2845 | expected_retval=0): |
| 2846 | return self.api(self.papi.acl_interface_set_acl_list, |
| 2847 | {'sw_if_index': sw_if_index, |
| 2848 | 'count': len(acls), |
| 2849 | 'n_input': n_input, |
| 2850 | 'acls': acls}, |
| 2851 | expected_retval=expected_retval) |
| 2852 | |
Andrew Yourtchenko | c43b3f9 | 2018-02-06 17:42:32 +0100 | [diff] [blame] | 2853 | def acl_interface_set_etype_whitelist(self, sw_if_index, |
| 2854 | n_input, whitelist, |
| 2855 | expected_retval=0): |
| 2856 | return self.api(self.papi.acl_interface_set_etype_whitelist, |
| 2857 | {'sw_if_index': sw_if_index, |
| 2858 | 'count': len(whitelist), |
| 2859 | 'n_input': n_input, |
| 2860 | 'whitelist': whitelist}, |
| 2861 | expected_retval=expected_retval) |
| 2862 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 2863 | def acl_interface_add_del(self, |
| 2864 | sw_if_index, |
| 2865 | acl_index, |
| 2866 | is_add=1): |
| 2867 | """ Add/Delete ACL to/from interface |
| 2868 | |
| 2869 | :param sw_if_index: |
| 2870 | :param acl_index: |
| 2871 | :param is_add: (Default value = 1) |
| 2872 | """ |
| 2873 | |
| 2874 | return self.api(self.papi.acl_interface_add_del, |
| 2875 | {'is_add': is_add, |
| 2876 | 'is_input': 1, |
| 2877 | 'sw_if_index': sw_if_index, |
| 2878 | 'acl_index': acl_index}) |
| 2879 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2880 | def acl_dump(self, acl_index, expected_retval=0): |
| 2881 | return self.api(self.papi.acl_dump, |
| 2882 | {'acl_index': acl_index}, |
| 2883 | expected_retval=expected_retval) |
| 2884 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 2885 | def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF, |
| 2886 | expected_retval=0): |
| 2887 | return self.api(self.papi.acl_interface_list_dump, |
| 2888 | {'sw_if_index': sw_if_index}, |
| 2889 | expected_retval=expected_retval) |
| 2890 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2891 | def macip_acl_add(self, rules, tag=""): |
| 2892 | """ Add MACIP acl |
| 2893 | |
| 2894 | :param rules: list of rules for given acl |
| 2895 | :param tag: acl tag |
| 2896 | """ |
| 2897 | |
| 2898 | return self.api(self.papi.macip_acl_add, |
| 2899 | {'r': rules, |
| 2900 | 'count': len(rules), |
| 2901 | 'tag': tag}) |
| 2902 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2903 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 2904 | """ Add MACIP acl |
| 2905 | |
| 2906 | :param rules: list of rules for given acl |
| 2907 | :param tag: acl tag |
| 2908 | """ |
| 2909 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2910 | return self.api(self.papi.macip_acl_add_replace, |
| 2911 | {'acl_index': acl_index, |
| 2912 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2913 | 'count': len(rules), |
| 2914 | 'tag': tag}) |
| 2915 | |
| 2916 | def macip_acl_del(self, acl_index): |
| 2917 | """ |
| 2918 | |
| 2919 | :param acl_index: |
| 2920 | :return: |
| 2921 | """ |
| 2922 | return self.api(self.papi.macip_acl_del, |
| 2923 | {'acl_index': acl_index}) |
| 2924 | |
| 2925 | def macip_acl_interface_add_del(self, |
| 2926 | sw_if_index, |
| 2927 | acl_index, |
| 2928 | is_add=1): |
| 2929 | """ Add MACIP acl to interface |
| 2930 | |
| 2931 | :param sw_if_index: |
| 2932 | :param acl_index: |
| 2933 | :param is_add: (Default value = 1) |
| 2934 | """ |
| 2935 | |
| 2936 | return self.api(self.papi.macip_acl_interface_add_del, |
| 2937 | {'is_add': is_add, |
| 2938 | 'sw_if_index': sw_if_index, |
| 2939 | 'acl_index': acl_index}) |
| 2940 | |
| 2941 | def macip_acl_interface_get(self): |
| 2942 | """ Return interface acls dump |
| 2943 | """ |
| 2944 | return self.api( |
| 2945 | self.papi.macip_acl_interface_get, {}) |
| 2946 | |
| 2947 | def macip_acl_dump(self, acl_index=4294967295): |
| 2948 | """ Return MACIP acl dump |
| 2949 | """ |
| 2950 | |
| 2951 | return self.api( |
| 2952 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2953 | |
| 2954 | def policer_add_del(self, |
| 2955 | name, |
| 2956 | cir, |
| 2957 | eir, |
| 2958 | cb, |
| 2959 | eb, |
| 2960 | is_add=1, |
| 2961 | rate_type=0, |
| 2962 | round_type=0, |
| 2963 | ptype=0, |
| 2964 | color_aware=0, |
| 2965 | conform_action_type=1, |
| 2966 | conform_dscp=0, |
| 2967 | exceed_action_type=0, |
| 2968 | exceed_dscp=0, |
| 2969 | violate_action_type=0, |
| 2970 | violate_dscp=0): |
| 2971 | return self.api(self.papi.policer_add_del, |
| 2972 | {'name': name, |
| 2973 | 'cir': cir, |
| 2974 | 'eir': eir, |
| 2975 | 'cb': cb, |
| 2976 | 'eb': eb, |
| 2977 | 'is_add': is_add, |
| 2978 | 'rate_type': rate_type, |
| 2979 | 'round_type': round_type, |
| 2980 | 'type': ptype, |
| 2981 | 'color_aware': color_aware, |
| 2982 | 'conform_action_type': conform_action_type, |
| 2983 | 'conform_dscp': conform_dscp, |
| 2984 | 'exceed_action_type': exceed_action_type, |
| 2985 | 'exceed_dscp': exceed_dscp, |
| 2986 | 'violate_action_type': violate_action_type, |
| 2987 | 'violate_dscp': violate_dscp}) |
| 2988 | |
| 2989 | def ip_punt_police(self, |
| 2990 | policer_index, |
| 2991 | is_ip6=0, |
| 2992 | is_add=1): |
| 2993 | return self.api(self.papi.ip_punt_police, |
| 2994 | {'policer_index': policer_index, |
| 2995 | 'is_add': is_add, |
| 2996 | 'is_ip6': is_ip6}) |
| 2997 | |
| 2998 | def ip_punt_redirect(self, |
| 2999 | rx_sw_if_index, |
| 3000 | tx_sw_if_index, |
| 3001 | nh, |
| 3002 | is_ip6=0, |
| 3003 | is_add=1): |
| 3004 | return self.api(self.papi.ip_punt_redirect, |
| 3005 | {'rx_sw_if_index': rx_sw_if_index, |
| 3006 | 'tx_sw_if_index': tx_sw_if_index, |
| 3007 | 'nh': nh, |
| 3008 | 'is_add': is_add, |
| 3009 | 'is_ip6': is_ip6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3010 | |
| 3011 | def bier_table_add_del(self, |
| 3012 | bti, |
| 3013 | mpls_label, |
| 3014 | is_add=1): |
| 3015 | """ BIER Table add/del """ |
| 3016 | return self.api( |
| 3017 | self.papi.bier_table_add_del, |
| 3018 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 3019 | "bt_sub_domain": bti.sub_domain_id, |
| 3020 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 3021 | 'bt_label': mpls_label, |
| 3022 | 'bt_is_add': is_add}) |
| 3023 | |
| 3024 | def bier_table_dump(self): |
| 3025 | return self.api(self.papi.bier_table_dump, {}) |
| 3026 | |
| 3027 | def bier_route_add_del(self, |
| 3028 | bti, |
| 3029 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 3030 | paths, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3031 | is_add=1): |
| 3032 | """ BIER Route add/del """ |
| 3033 | return self.api( |
| 3034 | self.papi.bier_route_add_del, |
| 3035 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 3036 | "bt_sub_domain": bti.sub_domain_id, |
| 3037 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 3038 | 'br_bp': bp, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 3039 | 'br_n_paths': len(paths), |
| 3040 | 'br_paths': paths, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3041 | 'br_is_add': is_add}) |
| 3042 | |
| 3043 | def bier_route_dump(self, bti): |
| 3044 | return self.api( |
| 3045 | self.papi.bier_route_dump, |
| 3046 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 3047 | "bt_sub_domain": bti.sub_domain_id, |
| 3048 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 3049 | |
| 3050 | def bier_imp_add(self, |
| 3051 | bti, |
| 3052 | src, |
| 3053 | ibytes, |
| 3054 | is_add=1): |
| 3055 | """ BIER Imposition Add """ |
| 3056 | return self.api( |
| 3057 | self.papi.bier_imp_add, |
| 3058 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 3059 | "bt_sub_domain": bti.sub_domain_id, |
| 3060 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 3061 | 'bi_src': src, |
| 3062 | 'bi_n_bytes': len(ibytes), |
| 3063 | 'bi_bytes': ibytes}) |
| 3064 | |
| 3065 | def bier_imp_del(self, bi_index): |
| 3066 | """ BIER Imposition del """ |
| 3067 | return self.api( |
| 3068 | self.papi.bier_imp_del, |
| 3069 | {'bi_index': bi_index}) |
| 3070 | |
| 3071 | def bier_imp_dump(self): |
| 3072 | return self.api(self.papi.bier_imp_dump, {}) |
| 3073 | |
| 3074 | def bier_disp_table_add_del(self, |
| 3075 | bdti, |
| 3076 | is_add=1): |
| 3077 | """ BIER Disposition Table add/del """ |
| 3078 | return self.api( |
| 3079 | self.papi.bier_disp_table_add_del, |
| 3080 | {'bdt_tbl_id': bdti, |
| 3081 | 'bdt_is_add': is_add}) |
| 3082 | |
| 3083 | def bier_disp_table_dump(self): |
| 3084 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 3085 | |
| 3086 | def bier_disp_entry_add_del(self, |
| 3087 | bdti, |
| 3088 | bp, |
| 3089 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 3090 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3091 | next_hop, |
| 3092 | next_hop_tbl_id=0, |
| 3093 | next_hop_rpf_id=~0, |
| 3094 | next_hop_is_ip4=1, |
| 3095 | is_add=1): |
| 3096 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 3097 | lstack = [] |
| 3098 | while (len(lstack) < 16): |
| 3099 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3100 | return self.api( |
| 3101 | self.papi.bier_disp_entry_add_del, |
| 3102 | {'bde_tbl_id': bdti, |
| 3103 | 'bde_bp': bp, |
| 3104 | 'bde_payload_proto': payload_proto, |
| 3105 | 'bde_n_paths': 1, |
| 3106 | 'bde_paths': [{'next_hop': next_hop, |
| 3107 | 'table_id': next_hop_tbl_id, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 3108 | 'afi': next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3109 | 'rpf_id': next_hop_rpf_id, |
| 3110 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 3111 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3112 | 'bde_is_add': is_add}) |
| 3113 | |
| 3114 | def bier_disp_entry_dump(self, bdti): |
| 3115 | return self.api( |
| 3116 | self.papi.bier_disp_entry_dump, |
| 3117 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 3118 | |
| 3119 | def add_node_next(self, node_name, next_name): |
| 3120 | """ Set the next node for a given node request |
| 3121 | |
| 3122 | :param node_name: |
| 3123 | :param next_name: |
| 3124 | """ |
| 3125 | return self.api(self.papi.add_node_next, |
| 3126 | {'node_name': node_name, |
| 3127 | 'next_name': next_name}) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 3128 | |
| 3129 | def session_enable_disable(self, is_enabled): |
| 3130 | return self.api( |
| 3131 | self.papi.session_enable_disable, |
| 3132 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3133 | |
| 3134 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 3135 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 3136 | Sample CLI : 'ipsec spd add 1' |
| 3137 | |
| 3138 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 3139 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 3140 | optional |
| 3141 | :returns: reply from the API |
| 3142 | """ |
| 3143 | return self.api( |
| 3144 | self.papi.ipsec_spd_add_del, { |
| 3145 | 'spd_id': spd_id, 'is_add': is_add}) |
| 3146 | |
| 3147 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 3148 | """ IPSEC interface SPD add/del - \ |
| 3149 | Wrapper to associate/disassociate SPD to interface in VPP |
| 3150 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 3151 | |
| 3152 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 3153 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 3154 | association mandatory |
| 3155 | :param is_add - add(1) or del(0) association with interface \ |
| 3156 | (Default 1 - add) . optional |
| 3157 | :returns: reply from the API |
| 3158 | """ |
| 3159 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 3160 | self.papi.ipsec_interface_add_del_spd, |
| 3161 | {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3162 | |
| 3163 | def ipsec_sad_add_del_entry(self, |
| 3164 | sad_id, |
| 3165 | spi, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3166 | integrity_algorithm, |
| 3167 | integrity_key, |
| 3168 | crypto_algorithm, |
| 3169 | crypto_key, |
| 3170 | protocol, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3171 | tunnel_src_address='', |
| 3172 | tunnel_dst_address='', |
Ole Troan | e0d2bd6 | 2018-06-22 22:36:46 +0200 | [diff] [blame] | 3173 | is_tunnel=1, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3174 | is_add=1, |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 3175 | udp_encap=0): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3176 | """ IPSEC SA add/del |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3177 | :param sad_id: security association ID |
| 3178 | :param spi: security param index of the SA in decimal |
| 3179 | :param integrity_algorithm: |
| 3180 | :param integrity_key: |
| 3181 | :param crypto_algorithm: |
| 3182 | :param crypto_key: |
| 3183 | :param protocol: AH(0) or ESP(1) protocol |
| 3184 | :param tunnel_src_address: tunnel mode outer src address |
| 3185 | :param tunnel_dst_address: tunnel mode outer dst address |
| 3186 | :param is_add: |
| 3187 | :param is_tunnel: |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3188 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 3189 | crypto and ipsec algorithms |
| 3190 | """ |
| 3191 | return self.api( |
| 3192 | self.papi.ipsec_sad_add_del_entry, |
| 3193 | {'sad_id': sad_id, |
| 3194 | 'spi': spi, |
| 3195 | 'tunnel_src_address': tunnel_src_address, |
| 3196 | 'tunnel_dst_address': tunnel_dst_address, |
| 3197 | 'protocol': protocol, |
| 3198 | 'integrity_algorithm': integrity_algorithm, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3199 | 'integrity_key_length': len(integrity_key), |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3200 | 'integrity_key': integrity_key, |
| 3201 | 'crypto_algorithm': crypto_algorithm, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3202 | 'crypto_key_length': len(crypto_key) if crypto_key is not None |
| 3203 | else 0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3204 | 'crypto_key': crypto_key, |
| 3205 | 'is_add': is_add, |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 3206 | 'is_tunnel': is_tunnel, |
| 3207 | 'udp_encap': udp_encap}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3208 | |
| 3209 | def ipsec_spd_add_del_entry(self, |
| 3210 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3211 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3212 | local_address_start, |
| 3213 | local_address_stop, |
| 3214 | remote_address_start, |
| 3215 | remote_address_stop, |
| 3216 | local_port_start=0, |
| 3217 | local_port_stop=65535, |
| 3218 | remote_port_start=0, |
| 3219 | remote_port_stop=65535, |
| 3220 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3221 | policy=0, |
| 3222 | priority=100, |
| 3223 | is_outbound=1, |
| 3224 | is_add=1, |
| 3225 | is_ip_any=0): |
| 3226 | """ IPSEC policy SPD add/del - |
| 3227 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3228 | :param spd_id: SPD ID for the policy |
| 3229 | :param local_address_start: local-ip-range start address |
| 3230 | :param local_address_stop : local-ip-range stop address |
| 3231 | :param remote_address_start: remote-ip-range start address |
| 3232 | :param remote_address_stop : remote-ip-range stop address |
| 3233 | :param local_port_start: (Default value = 0) |
| 3234 | :param local_port_stop: (Default value = 65535) |
| 3235 | :param remote_port_start: (Default value = 0) |
| 3236 | :param remote_port_stop: (Default value = 65535) |
| 3237 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 3238 | :param sa_id: Security Association ID for mapping it to SPD |
| 3239 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 3240 | (Default value = 0) |
| 3241 | :param priority: value for the spd action (Default value = 100) |
| 3242 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 3243 | (Default value = 1) |
| 3244 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3245 | """ |
| 3246 | return self.api( |
| 3247 | self.papi.ipsec_spd_add_del_entry, |
| 3248 | {'spd_id': spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3249 | 'sa_id': sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3250 | 'local_address_start': local_address_start, |
| 3251 | 'local_address_stop': local_address_stop, |
| 3252 | 'remote_address_start': remote_address_start, |
| 3253 | 'remote_address_stop': remote_address_stop, |
| 3254 | 'local_port_start': local_port_start, |
| 3255 | 'local_port_stop': local_port_stop, |
| 3256 | 'remote_port_start': remote_port_start, |
| 3257 | 'remote_port_stop': remote_port_stop, |
| 3258 | 'is_add': is_add, |
| 3259 | 'protocol': protocol, |
| 3260 | 'policy': policy, |
| 3261 | 'priority': priority, |
| 3262 | 'is_outbound': is_outbound, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3263 | 'is_ip_any': is_ip_any}) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 3264 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3265 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 3266 | remote_spi, crypto_alg, local_crypto_key, |
| 3267 | remote_crypto_key, integ_alg, local_integ_key, |
| 3268 | remote_integ_key, is_add=1, esn=0, |
| 3269 | anti_replay=1, renumber=0, show_instance=0): |
| 3270 | return self.api( |
| 3271 | self.papi.ipsec_tunnel_if_add_del, |
| 3272 | {'local_ip': local_ip, 'remote_ip': remote_ip, |
| 3273 | 'local_spi': local_spi, 'remote_spi': remote_spi, |
| 3274 | 'crypto_alg': crypto_alg, |
| 3275 | 'local_crypto_key_len': len(local_crypto_key), |
| 3276 | 'local_crypto_key': local_crypto_key, |
| 3277 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 3278 | 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg, |
| 3279 | 'local_integ_key_len': len(local_integ_key), |
| 3280 | 'local_integ_key': local_integ_key, |
| 3281 | 'remote_integ_key_len': len(remote_integ_key), |
| 3282 | 'remote_integ_key': remote_integ_key, 'is_add': is_add, |
| 3283 | 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber, |
| 3284 | 'show_instance': show_instance |
| 3285 | }) |
| 3286 | |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 3287 | def app_namespace_add(self, |
| 3288 | namespace_id, |
| 3289 | ip4_fib_id=0, |
| 3290 | ip6_fib_id=0, |
| 3291 | sw_if_index=0xFFFFFFFF, |
| 3292 | secret=0): |
| 3293 | return self.api( |
| 3294 | self.papi.app_namespace_add_del, |
| 3295 | {'secret': secret, |
| 3296 | 'sw_if_index': sw_if_index, |
| 3297 | 'ip4_fib_id': ip4_fib_id, |
| 3298 | 'ip6_fib_id': ip6_fib_id, |
| 3299 | 'namespace_id': namespace_id, |
| 3300 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 3301 | |
| 3302 | def punt_socket_register(self, l4_port, pathname, header_version=1, |
| 3303 | is_ip4=1, l4_protocol=0x11): |
| 3304 | """ Punt to socket """ |
| 3305 | return self.api(self.papi.punt_socket_register, |
| 3306 | {'is_ip4': is_ip4, |
| 3307 | 'l4_protocol': l4_protocol, |
| 3308 | 'l4_port': l4_port, |
| 3309 | 'pathname': pathname, |
| 3310 | 'header_version': header_version}) |
| 3311 | |
| 3312 | def ip_reassembly_set(self, timeout_ms, max_reassemblies, |
| 3313 | expire_walk_interval_ms, is_ip6=0): |
| 3314 | """ Set IP reassembly parameters """ |
| 3315 | return self.api(self.papi.ip_reassembly_set, |
| 3316 | {'is_ip6': is_ip6, |
| 3317 | 'timeout_ms': timeout_ms, |
| 3318 | 'expire_walk_interval_ms': expire_walk_interval_ms, |
| 3319 | 'max_reassemblies': max_reassemblies}) |
| 3320 | |
| 3321 | def ip_reassembly_get(self, is_ip6=0): |
| 3322 | """ Get IP reassembly parameters """ |
| 3323 | return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3324 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 3325 | def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False, |
| 3326 | enable_ip6=False): |
| 3327 | """ Enable/disable IP reassembly """ |
| 3328 | return self.api(self.papi.ip_reassembly_enable_disable, |
| 3329 | {'sw_if_index': sw_if_index, |
| 3330 | 'enable_ip4': 1 if enable_ip4 else 0, |
| 3331 | 'enable_ip6': 1 if enable_ip6 else 0, |
| 3332 | }) |
| 3333 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3334 | def gbp_endpoint_add_del(self, is_add, sw_if_index, addr, is_ip6, epg): |
| 3335 | """ GBP endpoint Add/Del """ |
| 3336 | return self.api(self.papi.gbp_endpoint_add_del, |
| 3337 | {'is_add': is_add, |
| 3338 | 'endpoint': { |
| 3339 | 'is_ip6': is_ip6, |
| 3340 | 'sw_if_index': sw_if_index, |
| 3341 | 'address': addr, |
| 3342 | 'epg_id': epg}}) |
| 3343 | |
| 3344 | def gbp_endpoint_dump(self): |
| 3345 | """ GBP endpoint Dump """ |
| 3346 | return self.api(self.papi.gbp_endpoint_dump, {}) |
| 3347 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3348 | def gbp_endpoint_group_add_del(self, is_add, epg, bd, |
| 3349 | ip4_rd, |
| 3350 | ip6_rd, |
| 3351 | uplink_sw_if_index): |
| 3352 | """ GBP endpoint group Add/Del """ |
| 3353 | return self.api(self.papi.gbp_endpoint_group_add_del, |
| 3354 | {'is_add': is_add, |
| 3355 | 'epg': { |
| 3356 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 3357 | 'bd_id': bd, |
| 3358 | 'ip4_table_id': ip4_rd, |
| 3359 | 'ip6_table_id': ip6_rd, |
| 3360 | 'epg_id': epg}}) |
| 3361 | |
| 3362 | def gbp_endpoint_group_dump(self): |
| 3363 | """ GBP endpoint group Dump """ |
| 3364 | return self.api(self.papi.gbp_endpoint_group_dump, {}) |
| 3365 | |
| 3366 | def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext): |
| 3367 | """ GBP recirc Add/Del """ |
| 3368 | return self.api(self.papi.gbp_recirc_add_del, |
| 3369 | {'is_add': is_add, |
| 3370 | 'recirc': { |
| 3371 | 'is_ext': is_ext, |
| 3372 | 'sw_if_index': sw_if_index, |
| 3373 | 'epg_id': epg}}) |
| 3374 | |
| 3375 | def gbp_recirc_dump(self): |
| 3376 | """ GBP recirc Dump """ |
| 3377 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 3378 | |
| 3379 | def gbp_subnet_add_del(self, is_add, table_id, |
| 3380 | is_internal, |
| 3381 | addr, addr_len, |
| 3382 | sw_if_index=0xffffffff, |
| 3383 | epg_id=0xffffffff, |
| 3384 | is_ip6=False): |
| 3385 | """ GBP Subnet Add/Del """ |
| 3386 | return self.api(self.papi.gbp_subnet_add_del, |
| 3387 | {'is_add': is_add, |
| 3388 | 'subnet': { |
| 3389 | 'is_internal': is_internal, |
| 3390 | 'is_ip6': is_ip6, |
| 3391 | 'sw_if_index': sw_if_index, |
| 3392 | 'epg_id': epg_id, |
| 3393 | 'address': addr, |
| 3394 | 'address_length': addr_len, |
| 3395 | 'table_id': table_id}}) |
| 3396 | |
| 3397 | def gbp_subnet_dump(self): |
| 3398 | """ GBP Subnet Dump """ |
| 3399 | return self.api(self.papi.gbp_subnet_dump, {}) |
| 3400 | |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3401 | def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index): |
| 3402 | """ GBP contract Add/Del """ |
| 3403 | return self.api(self.papi.gbp_contract_add_del, |
| 3404 | {'is_add': is_add, |
| 3405 | 'contract': { |
| 3406 | 'acl_index': acl_index, |
| 3407 | 'src_epg': src_epg, |
| 3408 | 'dst_epg': dst_epg}}) |
| 3409 | |
| 3410 | def gbp_contract_dump(self): |
| 3411 | """ GBP contract Dump """ |
| 3412 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3413 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3414 | def ipip_6rd_add_tunnel(self, fib_index, ip6_prefix, ip6_prefix_len, |
| 3415 | ip4_prefix, ip4_prefix_len, ip4_src, |
| 3416 | security_check): |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3417 | """ 6RD tunnel Add """ |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3418 | return self.api(self.papi.ipip_6rd_add_tunnel, |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3419 | {'fib_index': fib_index, |
| 3420 | 'ip6_prefix': ip6_prefix, |
| 3421 | 'ip6_prefix_len': ip6_prefix_len, |
| 3422 | 'ip4_prefix': ip4_prefix, |
| 3423 | 'ip4_prefix_len': ip4_prefix_len, |
| 3424 | 'ip4_src': ip4_src, |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3425 | 'security_check': security_check}) |
| 3426 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3427 | def ipip_6rd_del_tunnel(self, sw_if_index): |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3428 | """ 6RD tunnel Delete """ |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3429 | return self.api(self.papi.ipip_6rd_del_tunnel, |
| 3430 | {'sw_if_index': sw_if_index}) |
| 3431 | |
| 3432 | def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1, |
Ole Troan | d57f636 | 2018-05-24 13:21:43 +0200 | [diff] [blame] | 3433 | instance=0xFFFFFFFF, fib_index=0, tc_tos=0): |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3434 | """ IPIP tunnel Add/Del """ |
| 3435 | return self.api(self.papi.ipip_add_tunnel, |
| 3436 | {'is_ipv6': is_ipv6, |
| 3437 | 'instance': instance, |
| 3438 | 'src_address': src_address, |
| 3439 | 'dst_address': dst_address, |
Ole Troan | d57f636 | 2018-05-24 13:21:43 +0200 | [diff] [blame] | 3440 | 'fib_index': fib_index, |
| 3441 | 'tc_tos': tc_tos}) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3442 | |
| 3443 | def ipip_del_tunnel(self, sw_if_index): |
| 3444 | """ IPIP tunnel Delete """ |
| 3445 | return self.api(self.papi.ipip_del_tunnel, |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3446 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 3447 | |
| 3448 | def qos_egress_map_update(self, id, outputs): |
| 3449 | """ QOS egress map update """ |
| 3450 | return self.api(self.papi.qos_egress_map_update, |
| 3451 | {'map_id': id, |
| 3452 | 'rows': outputs}) |
| 3453 | |
| 3454 | def qos_egress_map_delete(self, id): |
| 3455 | """ QOS egress map delete """ |
| 3456 | return self.api(self.papi.qos_egress_map_delete, |
| 3457 | {'map_id': id}) |
| 3458 | |
| 3459 | def qos_mark_enable_disable(self, sw_if_index, |
| 3460 | output_source, |
| 3461 | map_id, |
| 3462 | enable): |
| 3463 | """ QOS Mark Enable/Disable """ |
| 3464 | return self.api(self.papi.qos_mark_enable_disable, |
| 3465 | {'map_id': map_id, |
| 3466 | 'sw_if_index': sw_if_index, |
| 3467 | 'output_source': output_source, |
| 3468 | 'enable': enable}) |
| 3469 | |
| 3470 | def qos_record_enable_disable(self, sw_if_index, input_source, enable): |
| 3471 | """ IP QoS recording Enble/Disable """ |
| 3472 | return self.api(self.papi.qos_record_enable_disable, |
| 3473 | {'sw_if_index': sw_if_index, |
| 3474 | 'input_source': input_source, |
| 3475 | 'enable': enable}) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3476 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3477 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 3478 | """ Enable/disable IGMP on a given interface """ |
| 3479 | return self.api(self.papi.igmp_enable_disable, |
| 3480 | {'enable': enable, |
| 3481 | 'mode': host, |
| 3482 | 'sw_if_index': sw_if_index}) |
| 3483 | |
| 3484 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3485 | """ Listen for new (S,G) on specified interface |
| 3486 | |
| 3487 | :param enable: add/del |
| 3488 | :param sw_if_index: interface sw index |
| 3489 | :param saddr: source ip4 addr |
| 3490 | :param gaddr: group ip4 addr |
| 3491 | """ |
| 3492 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3493 | { |
| 3494 | 'group': |
| 3495 | { |
| 3496 | 'filter': filter, |
| 3497 | 'sw_if_index': sw_if_index, |
| 3498 | 'n_srcs': len(saddrs), |
| 3499 | 'saddrs': saddrs, |
| 3500 | 'gaddr': |
| 3501 | { |
| 3502 | 'address': gaddr |
| 3503 | } |
| 3504 | } |
| 3505 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3506 | |
| 3507 | def igmp_dump(self, sw_if_index=None): |
| 3508 | """ Dump all (S,G) interface configurations """ |
| 3509 | if sw_if_index is None: |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3510 | sw_if_index = 0xffffffff |
| 3511 | return self.api(self.papi.igmp_dump, |
| 3512 | {'sw_if_index': sw_if_index}) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3513 | |
| 3514 | def igmp_clear_interface(self, sw_if_index): |
| 3515 | """ Remove all (S,G)s from specified interface |
| 3516 | doesn't send IGMP report! |
| 3517 | """ |
| 3518 | return self.api( |
| 3519 | self.papi.igmp_clear_interface, { |
| 3520 | 'sw_if_index': sw_if_index}) |
| 3521 | |
| 3522 | def want_igmp_events(self, enable=1): |
| 3523 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 3524 | 'pid': os.getpid()}) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 3525 | |
| 3526 | def bond_create( |
| 3527 | self, |
| 3528 | mode, |
| 3529 | lb, |
| 3530 | use_custom_mac, |
| 3531 | mac_address=''): |
| 3532 | """ |
| 3533 | :param mode: mode |
| 3534 | :param lb: load balance |
| 3535 | :param use_custom_mac: use custom mac |
| 3536 | :param mac_address: mac address |
| 3537 | """ |
| 3538 | return self.api( |
| 3539 | self.papi.bond_create, |
| 3540 | {'mode': mode, |
| 3541 | 'lb': lb, |
| 3542 | 'use_custom_mac': use_custom_mac, |
| 3543 | 'mac_address': mac_address |
| 3544 | }) |
| 3545 | |
| 3546 | def bond_delete( |
| 3547 | self, |
| 3548 | sw_if_index): |
| 3549 | """ |
| 3550 | :param sw_if_index: interface the operation is applied to |
| 3551 | """ |
| 3552 | return self.api(self.papi.bond_delete, |
| 3553 | {'sw_if_index': sw_if_index}) |
| 3554 | |
| 3555 | def bond_enslave( |
| 3556 | self, |
| 3557 | sw_if_index, |
| 3558 | bond_sw_if_index, |
| 3559 | is_passive, |
| 3560 | is_long_timeout): |
| 3561 | """ |
| 3562 | :param sw_if_index: slave sw_if_index |
| 3563 | :param bond_sw_if_index: bond sw_if_index |
| 3564 | :param is_passive: is passive lacp speaker |
| 3565 | :param is_long_time: 90 seconds timeout instead of 3 seconds timeout |
| 3566 | """ |
| 3567 | return self.api( |
| 3568 | self.papi.bond_enslave, |
| 3569 | {'sw_if_index': sw_if_index, |
| 3570 | 'bond_sw_if_index': bond_sw_if_index, |
| 3571 | 'is_passive': is_passive, |
| 3572 | 'is_long_timeout': is_long_timeout |
| 3573 | }) |
| 3574 | |
| 3575 | def bond_detach_slave( |
| 3576 | self, |
| 3577 | sw_if_index): |
| 3578 | """ |
| 3579 | :param sw_if_index: slave interface the operation is applied to |
| 3580 | """ |
| 3581 | return self.api(self.papi.bond_detach_slave, |
| 3582 | {'sw_if_index': sw_if_index}) |
| 3583 | |
| 3584 | def sw_interface_slave_dump( |
| 3585 | self, |
| 3586 | sw_if_index): |
| 3587 | """ |
| 3588 | :param sw_if_index: bond sw_if_index |
| 3589 | """ |
| 3590 | return self.api(self.papi.sw_interface_slave_dump, |
| 3591 | {'sw_if_index': sw_if_index}) |
| 3592 | |
| 3593 | def sw_interface_bond_dump( |
| 3594 | self): |
| 3595 | """ |
| 3596 | |
| 3597 | """ |
| 3598 | return self.api(self.papi.sw_interface_bond_dump, |
| 3599 | {}) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 3600 | |
| 3601 | def create_vhost_user_if( |
| 3602 | self, |
| 3603 | is_server, |
| 3604 | sock_filename, |
| 3605 | renumber, |
| 3606 | custom_dev_instance, |
| 3607 | use_custom_mac, |
| 3608 | mac_address, |
| 3609 | tag=''): |
| 3610 | """ |
| 3611 | :param is_server: is server |
| 3612 | :param sock_filename: socket name |
| 3613 | :param renumber: renumber |
| 3614 | :param custom_dev_instance: custom dev instance |
| 3615 | :param use_custom_mac: use custom mac |
| 3616 | :param mac_address: mac address |
| 3617 | :param tag: tag (default '' |
| 3618 | """ |
| 3619 | return self.api( |
| 3620 | self.papi.create_vhost_user_if, |
| 3621 | {'is_server': is_server, |
| 3622 | 'sock_filename': sock_filename, |
| 3623 | 'renumber': renumber, |
| 3624 | 'custom_dev_instance': custom_dev_instance, |
| 3625 | 'use_custom_mac': use_custom_mac, |
| 3626 | 'mac_address': mac_address, |
| 3627 | 'tag': tag |
| 3628 | }) |
| 3629 | |
| 3630 | def delete_vhost_user_if( |
| 3631 | self, |
| 3632 | sw_if_index): |
| 3633 | """ |
| 3634 | :param sw_if_index: interface the operation is applied to |
| 3635 | """ |
| 3636 | return self.api(self.papi.delete_vhost_user_if, |
| 3637 | {'sw_if_index': sw_if_index, }) |
| 3638 | |
| 3639 | def sw_interface_vhost_user_dump( |
| 3640 | self): |
| 3641 | """ |
| 3642 | |
| 3643 | """ |
| 3644 | return self.api(self.papi.sw_interface_vhost_user_dump, |
| 3645 | {}) |
Andrew Yourtchenko | 669d07d | 2017-11-17 14:38:18 +0100 | [diff] [blame] | 3646 | |
| 3647 | def abf_policy_add_del(self, is_add, policy): |
| 3648 | return self.api( |
| 3649 | self.papi.abf_policy_add_del, |
| 3650 | {'is_add': is_add, |
| 3651 | 'policy': policy}) |
| 3652 | |
| 3653 | def abf_itf_attach_add_del(self, is_add, attach): |
| 3654 | return self.api( |
| 3655 | self.papi.abf_itf_attach_add_del, |
| 3656 | {'is_add': is_add, |
| 3657 | 'attach': attach}) |
| 3658 | |
| 3659 | def abf_policy_dump(self): |
| 3660 | return self.api( |
| 3661 | self.papi.abf_policy_dump, {}) |
| 3662 | |
| 3663 | def abf_itf_attach_dump(self): |
| 3664 | return self.api( |
| 3665 | self.papi.abf_itf_attach_dump, {}) |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 3666 | |
| 3667 | def pipe_create(self, is_specified, user_instance): |
| 3668 | return self.api(self.papi.pipe_create, |
| 3669 | {'is_specified': is_specified, |
| 3670 | 'user_instance': user_instance}) |
| 3671 | |
| 3672 | def pipe_delete(self, parent_sw_if_index): |
| 3673 | return self.api(self.papi.pipe_delete, |
| 3674 | {'parent_sw_if_index': parent_sw_if_index}) |
| 3675 | |
| 3676 | def pipe_dump(self): |
| 3677 | return self.api(self.papi.pipe_dump, {}) |