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