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