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