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