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