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