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 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 39 | class UnexpectedApiReturnValueError(Exception): |
| 40 | """ exception raised when the API return value is unexpected """ |
| 41 | pass |
| 42 | |
| 43 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 44 | class VppPapiProvider(object): |
| 45 | """VPP-api provider using vpp-papi |
| 46 | |
| 47 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 48 | """ |
| 49 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 50 | _zero, _negative = range(2) |
| 51 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 52 | def __init__(self, name, shm_prefix, test_class): |
Klement Sekera | 277b89c | 2016-10-28 13:20:27 +0200 | [diff] [blame] | 53 | self.hook = Hook("vpp-papi-provider") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 54 | self.name = name |
| 55 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 56 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 57 | self._expect_api_retval = self._zero |
| 58 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 59 | jsonfiles = [] |
| 60 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 61 | install_dir = os.getenv('VPP_TEST_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 62 | for root, dirnames, filenames in os.walk(install_dir): |
| 63 | for filename in fnmatch.filter(filenames, '*.api.json'): |
| 64 | jsonfiles.append(os.path.join(root, filename)) |
| 65 | |
Ole Troan | 3cc4971 | 2017-03-08 12:02:24 +0100 | [diff] [blame] | 66 | self.vpp = VPP(jsonfiles, logger=test_class.logger) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 67 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 68 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 69 | def __enter__(self): |
| 70 | return self |
| 71 | |
| 72 | def expect_negative_api_retval(self): |
| 73 | """ Expect API failure """ |
| 74 | self._expect_stack.append(self._expect_api_retval) |
| 75 | self._expect_api_retval = self._negative |
| 76 | return self |
| 77 | |
| 78 | def expect_zero_api_retval(self): |
| 79 | """ Expect API success """ |
| 80 | self._expect_stack.append(self._expect_api_retval) |
| 81 | self._expect_api_retval = self._zero |
| 82 | return self |
| 83 | |
| 84 | def __exit__(self, exc_type, exc_value, traceback): |
| 85 | self._expect_api_retval = self._expect_stack.pop() |
| 86 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 87 | def register_hook(self, hook): |
| 88 | """Replace hook registration with new hook |
| 89 | |
| 90 | :param hook: |
| 91 | |
| 92 | """ |
| 93 | self.hook = hook |
| 94 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 95 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 96 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 97 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 98 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 99 | return e |
| 100 | |
| 101 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 102 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 103 | if name: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 104 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 105 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 106 | else: |
| 107 | self.test_class.logger.debug("Expecting event within %ss", |
| 108 | timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 109 | if self._events: |
| 110 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 111 | limit = time.time() + timeout |
| 112 | while time.time() < limit: |
| 113 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 114 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 115 | if name and type(e).__name__ != name: |
| 116 | raise Exception( |
| 117 | "Unexpected event received: %s, expected: %s" % |
| 118 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 119 | self.test_class.logger.debug("Returning event %s:%s" % |
| 120 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 121 | return e |
| 122 | time.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 123 | raise Exception("Event did not occur within timeout") |
| 124 | |
| 125 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 126 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 127 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 128 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 129 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 130 | self._events.append(event) |
| 131 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 132 | def connect(self): |
| 133 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 134 | self.vpp.connect(self.name, self.shm_prefix) |
| 135 | self.papi = self.vpp.api |
| 136 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 137 | |
| 138 | def disconnect(self): |
| 139 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 140 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 141 | |
| 142 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 143 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 144 | Call the appropriate hooks before and after the API call |
| 145 | |
| 146 | :param api_fn: API function to call |
| 147 | :param api_args: tuple of API function arguments |
| 148 | :param expected_retval: Expected return value (Default value = 0) |
| 149 | :returns: reply from the API |
| 150 | |
| 151 | """ |
| 152 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 153 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 154 | if self._expect_api_retval == self._negative: |
| 155 | if hasattr(reply, 'retval') and reply.retval >= 0: |
| 156 | msg = "API call passed unexpectedly: expected negative "\ |
| 157 | "return value instead of %d in %s" % \ |
| 158 | (reply.retval, repr(reply)) |
| 159 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 160 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 161 | elif self._expect_api_retval == self._zero: |
| 162 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 163 | msg = "API call failed, expected %d return value instead "\ |
| 164 | "of %d in %s" % (expected_retval, reply.retval, |
| 165 | repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 166 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 167 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 168 | else: |
| 169 | raise Exception("Internal error, unexpected value for " |
| 170 | "self._expect_api_retval %s" % |
| 171 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 172 | self.hook.after_api(api_fn.__name__, api_args) |
| 173 | return reply |
| 174 | |
| 175 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 176 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 177 | |
| 178 | :param cli: CLI to execute |
| 179 | :returns: CLI output |
| 180 | |
| 181 | """ |
| 182 | self.hook.before_cli(cli) |
| 183 | cli += '\n' |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 184 | r = self.papi.cli_inband(length=len(cli), cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 185 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 186 | if hasattr(r, 'reply'): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 187 | return r.reply.decode().rstrip('\x00') |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 188 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 189 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 190 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 191 | |
| 192 | :param cli: CLI to execute |
| 193 | :returns: CLI output |
| 194 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 195 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 196 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 197 | def _convert_mac(self, mac): |
Mohsin Kazmi | 57938f6 | 2017-10-27 21:28:07 +0200 | [diff] [blame] | 198 | return mac.replace(':', '').decode('hex') |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 199 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 200 | def show_version(self): |
| 201 | """ """ |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 202 | return self.api(self.papi.show_version, {}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 203 | |
| 204 | def pg_create_interface(self, pg_index): |
| 205 | """ |
| 206 | |
| 207 | :param pg_index: |
| 208 | |
| 209 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 210 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 211 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 212 | |
| 213 | def sw_interface_dump(self, filter=None): |
| 214 | """ |
| 215 | |
| 216 | :param filter: (Default value = None) |
| 217 | |
| 218 | """ |
| 219 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 220 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 221 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 222 | args = {} |
| 223 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 224 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 225 | 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] | 226 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 227 | |
| 228 | :param sw_if_index: |
| 229 | :param is_ipv6: |
| 230 | :param table_id: |
| 231 | |
| 232 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 233 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 234 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 235 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 236 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 237 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 238 | is_ipv6=0, is_add=1, del_all=0): |
| 239 | """ |
| 240 | |
| 241 | :param addr: param is_ipv6: (Default value = 0) |
| 242 | :param sw_if_index: |
| 243 | :param addr_len: |
| 244 | :param is_ipv6: (Default value = 0) |
| 245 | :param is_add: (Default value = 1) |
| 246 | :param del_all: (Default value = 0) |
| 247 | |
| 248 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 249 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 250 | {'sw_if_index': sw_if_index, |
| 251 | 'is_add': is_add, |
| 252 | 'is_ipv6': is_ipv6, |
| 253 | 'del_all': del_all, |
| 254 | 'address_length': addr_len, |
| 255 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 256 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 257 | def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index, |
| 258 | is_add=1): |
| 259 | """ Set the Interface to be unnumbered |
| 260 | |
| 261 | :param is_add: (Default value = 1) |
| 262 | :param sw_if_index - interface That will be unnumbered |
| 263 | :param ip_sw_if_index - interface with an IP addres |
| 264 | |
| 265 | """ |
| 266 | return self.api(self.papi.sw_interface_set_unnumbered, |
| 267 | {'sw_if_index': ip_sw_if_index, |
| 268 | 'unnumbered_sw_if_index': sw_if_index, |
| 269 | 'is_add': is_add}) |
| 270 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 271 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 272 | is_enable=1): |
| 273 | """ |
| 274 | Enable/Disable MPLS on the interface |
| 275 | :param sw_if_index: |
| 276 | :param is_enable: (Default value = 1) |
| 277 | |
| 278 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 279 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 280 | {'sw_if_index': sw_if_index, |
| 281 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 282 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 283 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 284 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 285 | {'sw_if_index': sw_if_index, |
| 286 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 287 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 288 | def set_ip_flow_hash(self, |
| 289 | table_id, |
| 290 | src=1, |
| 291 | dst=1, |
| 292 | sport=1, |
| 293 | dport=1, |
| 294 | proto=1, |
| 295 | reverse=0, |
| 296 | is_ip6=0): |
| 297 | return self.api(self.papi.set_ip_flow_hash, |
| 298 | {'vrf_id': table_id, |
| 299 | 'src': src, |
| 300 | 'dst': dst, |
| 301 | 'dport': dport, |
| 302 | 'sport': sport, |
| 303 | 'proto': proto, |
| 304 | 'reverse': reverse, |
| 305 | 'is_ipv6': is_ip6}) |
| 306 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 307 | def ip6_nd_proxy(self, address, sw_if_index, is_del=0): |
| 308 | return self.api(self.papi.ip6nd_proxy_add_del, |
| 309 | {'address': address, |
| 310 | 'sw_if_index': sw_if_index, |
| 311 | 'is_del': is_del}) |
| 312 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 313 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 314 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 315 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 316 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 317 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 318 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 319 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 320 | 'suppress': suppress, |
| 321 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 322 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 323 | def ip6_sw_interface_ra_prefix(self, |
| 324 | sw_if_index, |
| 325 | address, |
| 326 | address_length, |
| 327 | use_default=0, |
| 328 | no_advertise=0, |
| 329 | off_link=0, |
| 330 | no_autoconfig=0, |
| 331 | no_onlink=0, |
| 332 | is_no=0, |
| 333 | val_lifetime=0xffffffff, |
| 334 | pref_lifetime=0xffffffff): |
| 335 | return self.api(self.papi.sw_interface_ip6nd_ra_prefix, |
| 336 | {'sw_if_index': sw_if_index, |
| 337 | 'address': address, |
| 338 | 'address_length': address_length, |
| 339 | 'use_default': use_default, |
| 340 | 'no_advertise': no_advertise, |
| 341 | 'off_link': off_link, |
| 342 | 'no_autoconfig': no_autoconfig, |
| 343 | 'no_onlink': no_onlink, |
| 344 | 'is_no': is_no, |
| 345 | 'val_lifetime': val_lifetime, |
| 346 | 'pref_lifetime': pref_lifetime}) |
| 347 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 348 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 349 | """ |
| 350 | Enable/Disable An interface for IPv6 |
| 351 | """ |
| 352 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 353 | {'sw_if_index': sw_if_index, |
| 354 | 'enable': enable}) |
| 355 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 356 | def vxlan_add_del_tunnel( |
| 357 | self, |
| 358 | src_addr, |
| 359 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 360 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 361 | is_add=1, |
| 362 | is_ipv6=0, |
| 363 | encap_vrf_id=0, |
| 364 | decap_next_index=0xFFFFFFFF, |
| 365 | vni=0): |
| 366 | """ |
| 367 | |
| 368 | :param dst_addr: |
| 369 | :param src_addr: |
| 370 | :param is_add: (Default value = 1) |
| 371 | :param is_ipv6: (Default value = 0) |
| 372 | :param encap_vrf_id: (Default value = 0) |
| 373 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 374 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 375 | :param vni: (Default value = 0) |
| 376 | |
| 377 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 378 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 379 | {'is_add': is_add, |
| 380 | 'is_ipv6': is_ipv6, |
| 381 | 'src_address': src_addr, |
| 382 | 'dst_address': dst_addr, |
| 383 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 384 | 'encap_vrf_id': encap_vrf_id, |
| 385 | 'decap_next_index': decap_next_index, |
| 386 | 'vni': vni}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 387 | |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 388 | def geneve_add_del_tunnel( |
| 389 | self, |
| 390 | local_addr, |
| 391 | remote_addr, |
| 392 | mcast_sw_if_index=0xFFFFFFFF, |
| 393 | is_add=1, |
| 394 | is_ipv6=0, |
| 395 | encap_vrf_id=0, |
| 396 | decap_next_index=0xFFFFFFFF, |
| 397 | vni=0): |
| 398 | """ |
| 399 | |
| 400 | :param remote_addr: |
| 401 | :param local_addr: |
| 402 | :param is_add: (Default value = 1) |
| 403 | :param is_ipv6: (Default value = 0) |
| 404 | :param encap_vrf_id: (Default value = 0) |
| 405 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 406 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 407 | :param vni: (Default value = 0) |
| 408 | |
| 409 | """ |
| 410 | return self.api(self.papi.geneve_add_del_tunnel, |
| 411 | {'is_add': is_add, |
| 412 | 'is_ipv6': is_ipv6, |
| 413 | 'local_address': local_addr, |
| 414 | 'remote_address': remote_addr, |
| 415 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 416 | 'encap_vrf_id': encap_vrf_id, |
| 417 | 'decap_next_index': decap_next_index, |
| 418 | 'vni': vni}) |
| 419 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 420 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 421 | learn=1, arp_term=0, is_add=1): |
| 422 | """Create/delete bridge domain. |
| 423 | |
| 424 | :param int bd_id: Bridge domain index. |
| 425 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 426 | (Default value = 1) |
| 427 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 428 | (Default value = 1) |
| 429 | :param int forward: Enable/disable forwarding on all interfaces in |
| 430 | the BD. (Default value = 1) |
| 431 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 432 | (Default value = 1) |
| 433 | :param int arp_term: Enable/disable arp termination in the BD. |
| 434 | (Default value = 1) |
| 435 | :param int is_add: Add or delete flag. (Default value = 1) |
| 436 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 437 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 438 | {'bd_id': bd_id, |
| 439 | 'flood': flood, |
| 440 | 'uu_flood': uu_flood, |
| 441 | 'forward': forward, |
| 442 | 'learn': learn, |
| 443 | 'arp_term': arp_term, |
| 444 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 445 | |
Eyal Bari | c86e592 | 2017-07-02 18:33:16 +0300 | [diff] [blame] | 446 | def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1): |
| 447 | return self.api(self.papi.bd_ip_mac_add_del, |
| 448 | {'bd_id': bd_id, |
| 449 | 'is_add': is_add, |
| 450 | 'is_ipv6': is_ipv6, |
| 451 | 'ip_address': ip, |
| 452 | 'mac_address': mac}) |
| 453 | |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 454 | def want_ip4_arp_events(self, enable_disable=1, address=0): |
| 455 | return self.api(self.papi.want_ip4_arp_events, |
| 456 | {'enable_disable': enable_disable, |
| 457 | 'address': address, |
| 458 | 'pid': os.getpid(), }) |
| 459 | |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 460 | def want_ip6_nd_events(self, enable_disable=1, address=0): |
| 461 | return self.api(self.papi.want_ip6_nd_events, |
| 462 | {'enable_disable': enable_disable, |
| 463 | 'address': address, |
| 464 | 'pid': os.getpid(), }) |
| 465 | |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 466 | def want_macs_learn_events(self, enable_disable=1, scan_delay=0, |
| 467 | max_macs_in_event=0, learn_limit=0): |
| 468 | return self.api(self.papi.want_l2_macs_events, |
| 469 | {'enable_disable': enable_disable, |
| 470 | 'scan_delay': scan_delay, |
| 471 | 'max_macs_in_event': max_macs_in_event, |
| 472 | 'learn_limit': learn_limit, |
| 473 | 'pid': os.getpid(), }) |
| 474 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 475 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 476 | filter_mac=0, bvi_mac=0): |
| 477 | """Create/delete L2 FIB entry. |
| 478 | |
| 479 | :param str mac: MAC address to create FIB entry for. |
| 480 | :param int bd_id: Bridge domain index. |
| 481 | :param int sw_if_index: Software interface index of the interface. |
| 482 | :param int is_add: Add or delete flag. (Default value = 1) |
| 483 | :param int static_mac: Set to 1 to create static MAC entry. |
| 484 | (Default value = 0) |
| 485 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 486 | destination MAC address contains defined MAC address. |
| 487 | (Default value = 0) |
| 488 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 489 | interface. (Default value = 0) |
| 490 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 491 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 492 | {'mac': self._convert_mac(mac), |
| 493 | 'bd_id': bd_id, |
| 494 | 'sw_if_index': sw_if_index, |
| 495 | 'is_add': is_add, |
| 496 | 'static_mac': static_mac, |
| 497 | 'filter_mac': filter_mac, |
| 498 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 499 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 500 | def l2fib_flush_int(self, sw_if_index): |
| 501 | """Flush L2 FIB entries for sw_if_index. |
| 502 | |
| 503 | :param int sw_if_index: Software interface index of the interface. |
| 504 | """ |
| 505 | return self.api(self.papi.l2fib_flush_int, |
| 506 | {'sw_if_index': sw_if_index}) |
| 507 | |
| 508 | def l2fib_flush_bd(self, bd_id): |
| 509 | """Flush L2 FIB entries for bd_id. |
| 510 | |
| 511 | :param int sw_if_index: Bridge Domain id. |
| 512 | """ |
| 513 | return self.api(self.papi.l2fib_flush_bd, |
| 514 | {'bd_id': bd_id}) |
| 515 | |
| 516 | def l2fib_flush_all(self): |
| 517 | """Flush all L2 FIB. |
| 518 | """ |
| 519 | return self.api(self.papi.l2fib_flush_all, {}) |
| 520 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 521 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 522 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 523 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 524 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 525 | :param int sw_if_index: Software interface index of the interface. |
| 526 | :param int bd_id: Bridge domain index. |
| 527 | :param int shg: Split-horizon group index. (Default value = 0) |
| 528 | :param int bvi: Set interface as a bridge group virtual interface. |
| 529 | (Default value = 0) |
| 530 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 531 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 532 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 533 | {'rx_sw_if_index': sw_if_index, |
| 534 | 'bd_id': bd_id, |
| 535 | 'shg': shg, |
| 536 | 'bvi': bvi, |
| 537 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 538 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 539 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 540 | """Enable/disable required feature of the bridge domain with defined ID. |
| 541 | |
| 542 | :param int bd_id: Bridge domain ID. |
| 543 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 544 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 545 | - learn (1 << 0), |
| 546 | - forward (1 << 1), |
| 547 | - flood (1 << 2), |
| 548 | - uu-flood (1 << 3) or |
| 549 | - arp-term (1 << 4). |
| 550 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 551 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 552 | {'bd_id': bd_id, |
| 553 | 'is_set': is_set, |
| 554 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 555 | |
| 556 | def bridge_domain_dump(self, bd_id=0): |
| 557 | """ |
| 558 | |
| 559 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 560 | existing bridge domains returned) |
| 561 | :return: Dictionary of bridge domain(s) data. |
| 562 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 563 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 564 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 565 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 566 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 567 | enable): |
| 568 | """Create or delete unidirectional cross-connect from Tx interface to |
| 569 | Rx interface. |
| 570 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 571 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 572 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 573 | :param int enable: Create cross-connect if equal to 1, delete |
| 574 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 575 | |
| 576 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 577 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 578 | {'rx_sw_if_index': rx_sw_if_index, |
| 579 | 'tx_sw_if_index': tx_sw_if_index, |
| 580 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 581 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 582 | def sw_interface_set_l2_tag_rewrite( |
| 583 | self, |
| 584 | sw_if_index, |
| 585 | vtr_oper, |
| 586 | push=0, |
| 587 | tag1=0, |
| 588 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 589 | """L2 interface vlan tag rewrite configure request |
| 590 | :param client_index - opaque cookie to identify the sender |
| 591 | :param context - sender context, to match reply w/ request |
| 592 | :param sw_if_index - interface the operation is applied to |
| 593 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 594 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 595 | :param tag1 - Needed for any push or translate vtr op |
| 596 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 597 | |
| 598 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 599 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 600 | {'sw_if_index': sw_if_index, |
| 601 | 'vtr_op': vtr_oper, |
| 602 | 'push_dot1q': push, |
| 603 | 'tag1': tag1, |
| 604 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 605 | |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 606 | def sw_interface_set_flags(self, sw_if_index, admin_up_down): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 607 | """ |
| 608 | |
| 609 | :param admin_up_down: |
| 610 | :param sw_if_index: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 611 | |
| 612 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 613 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 614 | {'sw_if_index': sw_if_index, |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 615 | 'admin_up_down': admin_up_down}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 616 | |
| 617 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 618 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 619 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 620 | """Create subinterface |
| 621 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 622 | |
| 623 | :param sub_id: param inner_vlan: |
| 624 | :param sw_if_index: |
| 625 | :param outer_vlan: |
| 626 | :param inner_vlan: |
| 627 | :param no_tags: (Default value = 0) |
| 628 | :param one_tag: (Default value = 0) |
| 629 | :param two_tags: (Default value = 0) |
| 630 | :param dot1ad: (Default value = 0) |
| 631 | :param exact_match: (Default value = 0) |
| 632 | :param default_sub: (Default value = 0) |
| 633 | :param outer_vlan_id_any: (Default value = 0) |
| 634 | :param inner_vlan_id_any: (Default value = 0) |
| 635 | |
| 636 | """ |
| 637 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 638 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 639 | {'sw_if_index': sw_if_index, |
| 640 | 'sub_id': sub_id, |
| 641 | 'no_tags': no_tags, |
| 642 | 'one_tag': one_tag, |
| 643 | 'two_tags': two_tags, |
| 644 | 'dot1ad': dot1ad, |
| 645 | 'exact_match': exact_match, |
| 646 | 'default_sub': default_sub, |
| 647 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 648 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 649 | 'outer_vlan_id': outer_vlan, |
| 650 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 651 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 652 | def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id): |
| 653 | """Create p2p ethernet subinterface |
| 654 | |
| 655 | :param sw_if_index: main (parent) interface |
| 656 | :param remote_mac: client (remote) mac address |
| 657 | |
| 658 | """ |
| 659 | return self.api( |
| 660 | self.papi.p2p_ethernet_add, |
| 661 | {'parent_if_index': sw_if_index, |
| 662 | 'remote_mac': remote_mac, |
| 663 | 'subif_id': subif_id}) |
| 664 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 665 | def delete_subif(self, sw_if_index): |
| 666 | """Delete subinterface |
| 667 | |
| 668 | :param sw_if_index: |
| 669 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 670 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 671 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 672 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 673 | def delete_p2pethernet_subif(self, sw_if_index, remote_mac): |
| 674 | """Delete p2p ethernet subinterface |
| 675 | |
| 676 | :param sw_if_index: main (parent) interface |
| 677 | :param remote_mac: client (remote) mac address |
| 678 | |
| 679 | """ |
| 680 | return self.api( |
| 681 | self.papi.p2p_ethernet_del, |
| 682 | {'parent_if_index': sw_if_index, |
| 683 | 'remote_mac': remote_mac}) |
| 684 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 685 | def create_vlan_subif(self, sw_if_index, vlan): |
| 686 | """ |
| 687 | |
| 688 | :param vlan: |
| 689 | :param sw_if_index: |
| 690 | |
| 691 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 692 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 693 | {'sw_if_index': sw_if_index, |
| 694 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 695 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 696 | def create_loopback(self, mac=''): |
| 697 | """ |
| 698 | |
| 699 | :param mac: (Optional) |
| 700 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 701 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 702 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 703 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 704 | def delete_loopback(self, sw_if_index): |
| 705 | return self.api(self.papi.delete_loopback, |
| 706 | {'sw_if_index': sw_if_index, }) |
| 707 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 708 | def ip_table_add_del(self, |
| 709 | table_id, |
| 710 | is_add=1, |
| 711 | is_ipv6=0): |
| 712 | """ |
| 713 | |
| 714 | :param table_id |
| 715 | :param is_add: (Default value = 1) |
| 716 | :param is_ipv6: (Default value = 0) |
| 717 | |
| 718 | """ |
| 719 | |
| 720 | return self.api( |
| 721 | self.papi.ip_table_add_del, |
| 722 | {'table_id': table_id, |
| 723 | 'is_add': is_add, |
| 724 | 'is_ipv6': is_ipv6}) |
| 725 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 726 | def ip_add_del_route( |
| 727 | self, |
| 728 | dst_address, |
| 729 | dst_address_length, |
| 730 | next_hop_address, |
| 731 | next_hop_sw_if_index=0xFFFFFFFF, |
| 732 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 733 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 734 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 735 | next_hop_n_out_labels=0, |
| 736 | next_hop_out_label_stack=[], |
| 737 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 738 | next_hop_id=0xFFFFFFFF, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 739 | is_resolve_host=0, |
| 740 | is_resolve_attached=0, |
| 741 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 742 | is_add=1, |
| 743 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 744 | is_unreach=0, |
| 745 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 746 | is_ipv6=0, |
| 747 | is_local=0, |
| 748 | is_classify=0, |
| 749 | is_multipath=0, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 750 | is_l2_bridged=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 751 | is_udp_encap=0, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 752 | is_source_lookup=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 753 | """ |
| 754 | |
| 755 | :param dst_address_length: |
| 756 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 757 | :param dst_address: |
| 758 | :param next_hop_address: |
| 759 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 760 | :param vrf_id: (Default value = 0) |
| 761 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 762 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 763 | :param is_add: (Default value = 1) |
| 764 | :param is_drop: (Default value = 0) |
| 765 | :param is_ipv6: (Default value = 0) |
| 766 | :param is_local: (Default value = 0) |
| 767 | :param is_classify: (Default value = 0) |
| 768 | :param is_multipath: (Default value = 0) |
| 769 | :param is_resolve_host: (Default value = 0) |
| 770 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 771 | :param is_l2_bridged: (Default value = 0) |
| 772 | :param is_source_lookup: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 773 | :param next_hop_weight: (Default value = 1) |
| 774 | |
| 775 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 776 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 777 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 778 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 779 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 780 | 'table_id': table_id, |
| 781 | 'classify_table_index': classify_table_index, |
| 782 | 'next_hop_table_id': next_hop_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 783 | 'is_add': is_add, |
| 784 | 'is_drop': is_drop, |
| 785 | 'is_unreach': is_unreach, |
| 786 | 'is_prohibit': is_prohibit, |
| 787 | 'is_ipv6': is_ipv6, |
| 788 | 'is_local': is_local, |
| 789 | 'is_classify': is_classify, |
| 790 | 'is_multipath': is_multipath, |
| 791 | 'is_resolve_host': is_resolve_host, |
| 792 | 'is_resolve_attached': is_resolve_attached, |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 793 | 'is_l2_bridged': is_l2_bridged, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 794 | 'is_source_lookup': is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 795 | 'is_udp_encap': is_udp_encap, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 796 | 'next_hop_weight': next_hop_weight, |
| 797 | 'dst_address_length': dst_address_length, |
| 798 | 'dst_address': dst_address, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 799 | 'next_hop_id': next_hop_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 800 | 'next_hop_address': next_hop_address, |
| 801 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 802 | 'next_hop_via_label': next_hop_via_label, |
| 803 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 804 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 805 | def ip_fib_dump(self): |
| 806 | return self.api(self.papi.ip_fib_dump, {}) |
| 807 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 808 | def ip6_fib_dump(self): |
| 809 | return self.api(self.papi.ip6_fib_dump, {}) |
| 810 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 811 | def ip_neighbor_add_del(self, |
| 812 | sw_if_index, |
| 813 | mac_address, |
| 814 | dst_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 815 | is_add=1, |
| 816 | is_ipv6=0, |
| 817 | is_static=0, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 818 | is_no_adj_fib=0, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 819 | ): |
| 820 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 821 | |
| 822 | :param sw_if_index: |
| 823 | :param mac_address: |
| 824 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 825 | :param is_add: (Default value = 1) |
| 826 | :param is_ipv6: (Default value = 0) |
| 827 | :param is_static: (Default value = 0) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 828 | :param is_no_adj_fib: (Default value = 0) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 829 | """ |
| 830 | |
| 831 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 832 | self.papi.ip_neighbor_add_del, |
Neale Ranns | baf2e90 | 2017-02-25 04:20:00 -0800 | [diff] [blame] | 833 | {'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 834 | 'is_add': is_add, |
| 835 | 'is_ipv6': is_ipv6, |
| 836 | 'is_static': is_static, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 837 | 'is_no_adj_fib': is_no_adj_fib, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 838 | 'mac_address': mac_address, |
| 839 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 840 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 841 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 842 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 843 | def ip_neighbor_dump(self, |
| 844 | sw_if_index, |
| 845 | is_ipv6=0): |
| 846 | """ Return IP neighbor dump. |
| 847 | |
| 848 | :param sw_if_index: |
| 849 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 850 | """ |
| 851 | |
| 852 | return self.api( |
| 853 | self.papi.ip_neighbor_dump, |
| 854 | {'is_ipv6': is_ipv6, |
| 855 | 'sw_if_index': sw_if_index |
| 856 | } |
| 857 | ) |
| 858 | |
| 859 | def proxy_arp_add_del(self, |
| 860 | low_address, |
| 861 | hi_address, |
| 862 | vrf_id=0, |
| 863 | is_add=1): |
| 864 | """ Config Proxy Arp Range. |
| 865 | |
| 866 | :param low_address: Start address in the rnage to Proxy for |
| 867 | :param hi_address: End address in the rnage to Proxy for |
| 868 | :param vrf_id: The VRF/table in which to proxy |
| 869 | """ |
| 870 | |
| 871 | return self.api( |
| 872 | self.papi.proxy_arp_add_del, |
| 873 | {'vrf_id': vrf_id, |
| 874 | 'is_add': is_add, |
| 875 | 'low_address': low_address, |
| 876 | 'hi_address': hi_address, |
| 877 | } |
| 878 | ) |
| 879 | |
| 880 | def proxy_arp_intfc_enable_disable(self, |
| 881 | sw_if_index, |
| 882 | is_enable=1): |
| 883 | """ Enable/Disable an interface for proxy ARP requests |
| 884 | |
| 885 | :param sw_if_index: Interface |
| 886 | :param enable_disable: Enable/Disable |
| 887 | """ |
| 888 | |
| 889 | return self.api( |
| 890 | self.papi.proxy_arp_intfc_enable_disable, |
| 891 | {'sw_if_index': sw_if_index, |
| 892 | 'enable_disable': is_enable |
| 893 | } |
| 894 | ) |
| 895 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 896 | def reset_vrf(self, |
| 897 | vrf_id, |
| 898 | is_ipv6=0, |
| 899 | ): |
| 900 | """ Reset VRF (remove all routes etc.) request. |
| 901 | |
| 902 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 903 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 904 | """ |
| 905 | |
| 906 | return self.api( |
| 907 | self.papi.reset_vrf, |
| 908 | {'vrf_id': vrf_id, |
| 909 | 'is_ipv6': is_ipv6, |
| 910 | } |
| 911 | ) |
| 912 | |
| 913 | def reset_fib(self, |
| 914 | vrf_id, |
| 915 | is_ipv6=0, |
| 916 | ): |
| 917 | """ Reset VRF (remove all routes etc.) request. |
| 918 | |
| 919 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 920 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 921 | """ |
| 922 | |
| 923 | return self.api( |
| 924 | self.papi.reset_fib, |
| 925 | {'vrf_id': vrf_id, |
| 926 | 'is_ipv6': is_ipv6, |
| 927 | } |
| 928 | ) |
| 929 | |
| 930 | def ip_dump(self, |
| 931 | is_ipv6=0, |
| 932 | ): |
| 933 | """ Return IP dump. |
| 934 | |
| 935 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 936 | """ |
| 937 | |
| 938 | return self.api( |
| 939 | self.papi.ip_dump, |
| 940 | {'is_ipv6': is_ipv6, |
| 941 | } |
| 942 | ) |
| 943 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 944 | def sw_interface_span_enable_disable( |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 945 | 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] | 946 | """ |
| 947 | |
| 948 | :param sw_if_index_from: |
| 949 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 950 | :param state: |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 951 | :param is_l2: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 952 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 953 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 954 | {'sw_if_index_from': sw_if_index_from, |
| 955 | 'sw_if_index_to': sw_if_index_to, |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 956 | 'state': state, |
| 957 | 'is_l2': is_l2, |
| 958 | }) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 959 | |
| 960 | def gre_tunnel_add_del(self, |
| 961 | src_address, |
| 962 | dst_address, |
| 963 | outer_fib_id=0, |
| 964 | is_teb=0, |
| 965 | is_add=1, |
| 966 | is_ip6=0): |
| 967 | """ Add a GRE tunnel |
| 968 | |
| 969 | :param src_address: |
| 970 | :param dst_address: |
| 971 | :param outer_fib_id: (Default value = 0) |
| 972 | :param is_add: (Default value = 1) |
| 973 | :param is_ipv6: (Default value = 0) |
| 974 | :param is_teb: (Default value = 0) |
| 975 | """ |
| 976 | |
| 977 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 978 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 979 | {'is_add': is_add, |
| 980 | 'is_ipv6': is_ip6, |
| 981 | 'teb': is_teb, |
| 982 | 'src_address': src_address, |
| 983 | 'dst_address': dst_address, |
| 984 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 985 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 986 | |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 987 | def udp_encap_add_del(self, |
| 988 | id, |
| 989 | src_ip, |
| 990 | dst_ip, |
| 991 | src_port, |
| 992 | dst_port, |
| 993 | table_id=0, |
| 994 | is_add=1, |
| 995 | is_ip6=0): |
| 996 | """ Add a GRE tunnel |
| 997 | :param id: user provided ID |
| 998 | :param src_ip: |
| 999 | :param dst_ip: |
| 1000 | :param src_port: |
| 1001 | :param dst_port: |
| 1002 | :param outer_fib_id: (Default value = 0) |
| 1003 | :param is_add: (Default value = 1) |
| 1004 | :param is_ipv6: (Default value = 0) |
| 1005 | """ |
| 1006 | |
| 1007 | return self.api( |
| 1008 | self.papi.udp_encap_add_del, |
| 1009 | {'id': id, |
| 1010 | 'is_add': is_add, |
| 1011 | 'is_ip6': is_ip6, |
| 1012 | 'src_ip': src_ip, |
| 1013 | 'dst_ip': dst_ip, |
| 1014 | 'src_port': src_port, |
| 1015 | 'dst_port': dst_port, |
| 1016 | 'table_id': table_id} |
| 1017 | ) |
| 1018 | |
| 1019 | def udp_encap_dump(self): |
| 1020 | return self.api(self.papi.udp_encap_dump, {}) |
| 1021 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1022 | def mpls_fib_dump(self): |
| 1023 | return self.api(self.papi.mpls_fib_dump, {}) |
| 1024 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1025 | def mpls_table_add_del( |
| 1026 | self, |
| 1027 | table_id, |
| 1028 | is_add=1): |
| 1029 | """ |
| 1030 | |
| 1031 | :param table_id |
| 1032 | :param is_add: (Default value = 1) |
| 1033 | |
| 1034 | """ |
| 1035 | |
| 1036 | return self.api( |
| 1037 | self.papi.mpls_table_add_del, |
| 1038 | {'mt_table_id': table_id, |
| 1039 | 'mt_is_add': is_add}) |
| 1040 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1041 | def mpls_route_add_del( |
| 1042 | self, |
| 1043 | label, |
| 1044 | eos, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1045 | next_hop_proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1046 | next_hop_address, |
| 1047 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1048 | table_id=0, |
| 1049 | next_hop_table_id=0, |
| 1050 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1051 | next_hop_n_out_labels=0, |
| 1052 | next_hop_out_label_stack=[], |
| 1053 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1054 | is_resolve_host=0, |
| 1055 | is_resolve_attached=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1056 | is_interface_rx=0, |
| 1057 | is_rpf_id=0, |
| 1058 | is_multicast=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1059 | is_add=1, |
| 1060 | is_drop=0, |
| 1061 | is_multipath=0, |
| 1062 | classify_table_index=0xFFFFFFFF, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 1063 | is_classify=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1064 | """ |
| 1065 | |
| 1066 | :param dst_address_length: |
| 1067 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1068 | :param dst_address: |
| 1069 | :param next_hop_address: |
| 1070 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1071 | :param vrf_id: (Default value = 0) |
| 1072 | :param lookup_in_vrf: (Default value = 0) |
| 1073 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1074 | :param is_add: (Default value = 1) |
| 1075 | :param is_drop: (Default value = 0) |
| 1076 | :param is_ipv6: (Default value = 0) |
| 1077 | :param is_local: (Default value = 0) |
| 1078 | :param is_classify: (Default value = 0) |
| 1079 | :param is_multipath: (Default value = 0) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1080 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1081 | :param is_resolve_host: (Default value = 0) |
| 1082 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1083 | :param next_hop_weight: (Default value = 1) |
| 1084 | |
| 1085 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1086 | |
| 1087 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1088 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1089 | {'mr_label': label, |
| 1090 | 'mr_eos': eos, |
| 1091 | 'mr_table_id': table_id, |
| 1092 | 'mr_classify_table_index': classify_table_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1093 | 'mr_is_add': is_add, |
| 1094 | 'mr_is_classify': is_classify, |
| 1095 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1096 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1097 | 'mr_is_resolve_host': is_resolve_host, |
| 1098 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1099 | 'mr_is_interface_rx': is_interface_rx, |
| 1100 | 'mr_is_rpf_id': is_rpf_id, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1101 | 'mr_next_hop_proto': next_hop_proto, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1102 | 'mr_next_hop_weight': next_hop_weight, |
| 1103 | 'mr_next_hop': next_hop_address, |
| 1104 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1105 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1106 | 'mr_next_hop_table_id': next_hop_table_id, |
| 1107 | 'mr_next_hop_via_label': next_hop_via_label, |
| 1108 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1109 | |
| 1110 | def mpls_ip_bind_unbind( |
| 1111 | self, |
| 1112 | label, |
| 1113 | dst_address, |
| 1114 | dst_address_length, |
| 1115 | table_id=0, |
| 1116 | ip_table_id=0, |
| 1117 | is_ip4=1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1118 | is_bind=1): |
| 1119 | """ |
| 1120 | """ |
| 1121 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1122 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1123 | {'mb_mpls_table_id': table_id, |
| 1124 | 'mb_label': label, |
| 1125 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1126 | 'mb_is_bind': is_bind, |
| 1127 | 'mb_is_ip4': is_ip4, |
| 1128 | 'mb_address_length': dst_address_length, |
| 1129 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1130 | |
| 1131 | def mpls_tunnel_add_del( |
| 1132 | self, |
| 1133 | tun_sw_if_index, |
| 1134 | next_hop_proto_is_ip4, |
| 1135 | next_hop_address, |
| 1136 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1137 | next_hop_table_id=0, |
| 1138 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1139 | next_hop_n_out_labels=0, |
| 1140 | next_hop_out_label_stack=[], |
| 1141 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1142 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1143 | l2_only=0, |
| 1144 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1145 | """ |
| 1146 | |
| 1147 | :param dst_address_length: |
| 1148 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1149 | :param dst_address: |
| 1150 | :param next_hop_address: |
| 1151 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1152 | :param vrf_id: (Default value = 0) |
| 1153 | :param lookup_in_vrf: (Default value = 0) |
| 1154 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1155 | :param is_add: (Default value = 1) |
| 1156 | :param is_drop: (Default value = 0) |
| 1157 | :param is_ipv6: (Default value = 0) |
| 1158 | :param is_local: (Default value = 0) |
| 1159 | :param is_classify: (Default value = 0) |
| 1160 | :param is_multipath: (Default value = 0) |
| 1161 | :param is_resolve_host: (Default value = 0) |
| 1162 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1163 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1164 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1165 | |
| 1166 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1167 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1168 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1169 | {'mt_sw_if_index': tun_sw_if_index, |
| 1170 | 'mt_is_add': is_add, |
| 1171 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1172 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1173 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 1174 | 'mt_next_hop_weight': next_hop_weight, |
| 1175 | 'mt_next_hop': next_hop_address, |
| 1176 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1177 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1178 | 'mt_next_hop_table_id': next_hop_table_id, |
| 1179 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1180 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1181 | def nat44_interface_add_del_feature( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1182 | self, |
| 1183 | sw_if_index, |
| 1184 | is_inside=1, |
| 1185 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1186 | """Enable/disable NAT44 feature on the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1187 | |
| 1188 | :param sw_if_index: Software index of the interface |
| 1189 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1190 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1191 | """ |
| 1192 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1193 | self.papi.nat44_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1194 | {'is_add': is_add, |
| 1195 | 'is_inside': is_inside, |
| 1196 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1197 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1198 | def nat44_interface_add_del_output_feature( |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1199 | self, |
| 1200 | sw_if_index, |
| 1201 | is_inside=1, |
| 1202 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1203 | """Enable/disable NAT44 output feature on the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1204 | |
| 1205 | :param sw_if_index: Software index of the interface |
| 1206 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1207 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1208 | """ |
| 1209 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1210 | self.papi.nat44_interface_add_del_output_feature, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1211 | {'is_add': is_add, |
| 1212 | 'is_inside': is_inside, |
| 1213 | 'sw_if_index': sw_if_index}) |
| 1214 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1215 | def nat44_add_del_static_mapping( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1216 | self, |
| 1217 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1218 | external_ip=0, |
| 1219 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1220 | local_port=0, |
| 1221 | external_port=0, |
| 1222 | addr_only=1, |
| 1223 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1224 | protocol=0, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1225 | is_add=1): |
| 1226 | """Add/delete NAT44 static mapping |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1227 | |
| 1228 | :param local_ip: Local IP address |
| 1229 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1230 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1231 | :param local_port: Local port number (Default value = 0) |
| 1232 | :param external_port: External port number (Default value = 0) |
| 1233 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1234 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1235 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1236 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1237 | """ |
| 1238 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1239 | self.papi.nat44_add_del_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1240 | {'is_add': is_add, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1241 | 'addr_only': addr_only, |
| 1242 | 'local_ip_address': local_ip, |
| 1243 | 'external_ip_address': external_ip, |
| 1244 | 'local_port': local_port, |
| 1245 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1246 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1247 | 'vrf_id': vrf_id, |
| 1248 | 'protocol': protocol}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1249 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1250 | def nat44_add_del_address_range( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1251 | self, |
| 1252 | first_ip_address, |
| 1253 | last_ip_address, |
| 1254 | is_add=1, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1255 | vrf_id=0xFFFFFFFF): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1256 | """Add/del NAT44 address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1257 | |
| 1258 | :param first_ip_address: First IP address |
| 1259 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1260 | :param vrf_id: VRF id for the address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1261 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1262 | """ |
| 1263 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1264 | self.papi.nat44_add_del_address_range, |
| 1265 | {'first_ip_address': first_ip_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1266 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1267 | 'vrf_id': vrf_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1268 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1269 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1270 | def nat44_address_dump(self): |
| 1271 | """Dump NAT44 addresses |
| 1272 | :return: Dictionary of NAT44 addresses |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1273 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1274 | return self.api(self.papi.nat44_address_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1275 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1276 | def nat44_interface_dump(self): |
| 1277 | """Dump interfaces with NAT44 feature |
| 1278 | :return: Dictionary of interfaces with NAT44 feature |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1279 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1280 | return self.api(self.papi.nat44_interface_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1281 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1282 | def nat44_interface_output_feature_dump(self): |
| 1283 | """Dump interfaces with NAT44 output feature |
| 1284 | :return: Dictionary of interfaces with NAT44 output feature |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1285 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1286 | return self.api(self.papi.nat44_interface_output_feature_dump, {}) |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1287 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1288 | def nat44_static_mapping_dump(self): |
| 1289 | """Dump NAT44 static mappings |
| 1290 | :return: Dictionary of NAT44 static mappings |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1291 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1292 | return self.api(self.papi.nat44_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1293 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1294 | def nat_show_config(self): |
| 1295 | """Show NAT plugin config |
| 1296 | :return: NAT plugin config parameters |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1297 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1298 | return self.api(self.papi.nat_show_config, {}) |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1299 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1300 | def nat44_add_interface_addr( |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1301 | self, |
| 1302 | sw_if_index, |
| 1303 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1304 | """Add/del NAT44 address from interface |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1305 | |
| 1306 | :param sw_if_index: Software index of the interface |
| 1307 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1308 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1309 | return self.api(self.papi.nat44_add_del_interface_addr, |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1310 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1311 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1312 | def nat44_interface_addr_dump(self): |
| 1313 | """Dump NAT44 addresses interfaces |
| 1314 | :return: Dictionary of NAT44 addresses interfaces |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1315 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1316 | return self.api(self.papi.nat44_interface_addr_dump, {}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1317 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1318 | def nat_ipfix( |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1319 | self, |
| 1320 | domain_id=1, |
| 1321 | src_port=4739, |
| 1322 | enable=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1323 | """Enable/disable NAT IPFIX logging |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1324 | |
| 1325 | :param domain_id: Observation domain ID (Default value = 1) |
| 1326 | :param src_port: Source port number (Default value = 4739) |
| 1327 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1328 | """ |
| 1329 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1330 | self.papi.nat_ipfix_enable_disable, |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1331 | {'domain_id': domain_id, |
| 1332 | 'src_port': src_port, |
| 1333 | 'enable': enable}) |
| 1334 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1335 | def nat44_user_session_dump( |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1336 | self, |
| 1337 | ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1338 | vrf_id): |
| 1339 | """Dump NAT44 user's sessions |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1340 | |
| 1341 | :param ip_address: ip adress of the user to be dumped |
| 1342 | :param cpu_index: cpu_index on which the user is |
| 1343 | :param vrf_id: VRF ID |
| 1344 | :return: Dictionary of S-NAT sessions |
| 1345 | """ |
| 1346 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1347 | self.papi.nat44_user_session_dump, |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1348 | {'ip_address': ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1349 | 'vrf_id': vrf_id}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1350 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1351 | def nat44_user_dump(self): |
| 1352 | """Dump NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1353 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1354 | :return: Dictionary of NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1355 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1356 | return self.api(self.papi.nat44_user_dump, {}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1357 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1358 | def nat44_add_del_lb_static_mapping( |
| 1359 | self, |
| 1360 | external_addr, |
| 1361 | external_port, |
| 1362 | protocol, |
| 1363 | vrf_id=0, |
| 1364 | local_num=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 1365 | locals=[], |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1366 | is_add=1): |
| 1367 | """Add/delete NAT44 load balancing static mapping |
| 1368 | |
| 1369 | :param is_add - 1 if add, 0 if delete |
| 1370 | """ |
| 1371 | return self.api( |
| 1372 | self.papi.nat44_add_del_lb_static_mapping, |
| 1373 | {'is_add': is_add, |
| 1374 | 'external_addr': external_addr, |
| 1375 | 'external_port': external_port, |
| 1376 | 'protocol': protocol, |
| 1377 | 'vrf_id': vrf_id, |
| 1378 | 'local_num': local_num, |
| 1379 | 'locals': locals}) |
| 1380 | |
| 1381 | def nat44_lb_static_mapping_dump(self): |
| 1382 | """Dump NAT44 load balancing static mappings |
| 1383 | |
| 1384 | :return: Dictionary of NAT44 load balancing static mapping |
| 1385 | """ |
| 1386 | return self.api(self.papi.nat44_lb_static_mapping_dump, {}) |
| 1387 | |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1388 | def nat44_del_session( |
| 1389 | self, |
| 1390 | addr, |
| 1391 | port, |
| 1392 | protocol, |
| 1393 | vrf_id=0, |
| 1394 | is_in=1): |
| 1395 | """Delete NAT44 session |
| 1396 | |
| 1397 | :param addr: IPv4 address |
| 1398 | :param por: port number |
| 1399 | :param protocol: IP protocol number |
| 1400 | :param vrf_id: VRF ID |
| 1401 | :param is_in: 1 if inside network addres and port pari, 0 if outside |
| 1402 | """ |
| 1403 | return self.api( |
| 1404 | self.papi.nat44_del_session, |
| 1405 | {'address': addr, |
| 1406 | 'port': port, |
| 1407 | 'protocol': protocol, |
| 1408 | 'vrf_id': vrf_id, |
| 1409 | 'is_in': is_in}) |
| 1410 | |
Matus Fabian | efcd1e9 | 2017-08-15 06:59:19 -0700 | [diff] [blame] | 1411 | def nat_set_reass( |
| 1412 | self, |
| 1413 | timeout=2, |
| 1414 | max_reass=1024, |
| 1415 | max_frag=5, |
| 1416 | drop_frag=0, |
| 1417 | is_ip6=0): |
| 1418 | """Set NAT virtual fragmentation reassembly |
| 1419 | |
| 1420 | :param timeout: reassembly timeout (Default 2sec) |
| 1421 | :param max_reass: maximum concurrent reassemblies (Default 1024) |
| 1422 | :param max_frag: maximum fragmets per reassembly (Default 5) |
| 1423 | :param drop_frag: if 0 translate fragments, otherwise drop fragments |
| 1424 | :param is_ip6: 1 if IPv6, 0 if IPv4 |
| 1425 | """ |
| 1426 | return self.api( |
| 1427 | self.papi.nat_set_reass, |
| 1428 | {'timeout': timeout, |
| 1429 | 'max_reass': max_reass, |
| 1430 | 'max_frag': max_frag, |
| 1431 | 'drop_frag': drop_frag, |
| 1432 | 'is_ip6': is_ip6}) |
| 1433 | |
| 1434 | def nat_get_reass(self): |
| 1435 | """Get NAT virtual fragmentation reassembly configuration |
| 1436 | |
| 1437 | :return: NAT virtual fragmentation reassembly configuration |
| 1438 | """ |
| 1439 | return self.api(self.papi.nat_get_reass, {}) |
| 1440 | |
| 1441 | def nat_reass_dump(self): |
| 1442 | """Dump NAT virtual fragmentation reassemblies |
| 1443 | |
| 1444 | :return: Dictionary of NAT virtual fragmentation reassemblies |
| 1445 | """ |
| 1446 | return self.api(self.papi.nat_reass_dump, {}) |
| 1447 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1448 | def nat_det_add_del_map( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1449 | self, |
| 1450 | in_addr, |
| 1451 | in_plen, |
| 1452 | out_addr, |
| 1453 | out_plen, |
| 1454 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1455 | """Add/delete deterministic NAT mapping |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1456 | |
| 1457 | :param is_add - 1 if add, 0 if delete |
| 1458 | :param in_addr - inside IP address |
| 1459 | :param in_plen - inside IP address prefix length |
| 1460 | :param out_addr - outside IP address |
| 1461 | :param out_plen - outside IP address prefix length |
| 1462 | """ |
| 1463 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1464 | self.papi.nat_det_add_del_map, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1465 | {'is_add': is_add, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1466 | 'is_nat44': 1, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1467 | 'in_addr': in_addr, |
| 1468 | 'in_plen': in_plen, |
| 1469 | 'out_addr': out_addr, |
| 1470 | 'out_plen': out_plen}) |
| 1471 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1472 | def nat_det_forward( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1473 | self, |
| 1474 | in_addr): |
| 1475 | """Get outside address and port range from inside address |
| 1476 | |
| 1477 | :param in_addr - inside IP address |
| 1478 | """ |
| 1479 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1480 | self.papi.nat_det_forward, |
| 1481 | {'in_addr': in_addr, |
| 1482 | 'is_nat44': 1}) |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1483 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1484 | def nat_det_reverse( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1485 | self, |
| 1486 | out_addr, |
| 1487 | out_port): |
| 1488 | """Get inside address from outside address and port |
| 1489 | |
| 1490 | :param out_addr - outside IP address |
| 1491 | :param out_port - outside port |
| 1492 | """ |
| 1493 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1494 | self.papi.nat_det_reverse, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1495 | {'out_addr': out_addr, |
| 1496 | 'out_port': out_port}) |
| 1497 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1498 | def nat_det_map_dump(self): |
| 1499 | """Dump deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1500 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1501 | :return: Dictionary of deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1502 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1503 | return self.api(self.papi.nat_det_map_dump, {}) |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1504 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1505 | def nat_det_set_timeouts( |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1506 | self, |
| 1507 | udp=300, |
| 1508 | tcp_established=7440, |
| 1509 | tcp_transitory=240, |
| 1510 | icmp=60): |
| 1511 | """Set values of timeouts for deterministic NAT (in seconds) |
| 1512 | |
| 1513 | :param udp - UDP timeout (Default value = 300) |
| 1514 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1515 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1516 | :param icmp - ICMP timeout (Default value = 60) |
| 1517 | """ |
| 1518 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1519 | self.papi.nat_det_set_timeouts, |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1520 | {'udp': udp, |
| 1521 | 'tcp_established': tcp_established, |
| 1522 | 'tcp_transitory': tcp_transitory, |
| 1523 | 'icmp': icmp}) |
| 1524 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1525 | def nat_det_get_timeouts(self): |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1526 | """Get values of timeouts for deterministic NAT |
| 1527 | |
| 1528 | :return: Timeouts for deterministic NAT (in seconds) |
| 1529 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1530 | return self.api(self.papi.nat_det_get_timeouts, {}) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1531 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1532 | def nat_det_close_session_out( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1533 | self, |
| 1534 | out_addr, |
| 1535 | out_port, |
| 1536 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1537 | ext_port): |
| 1538 | """Close deterministic NAT session using outside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1539 | |
| 1540 | :param out_addr - outside IP address |
| 1541 | :param out_port - outside port |
| 1542 | :param ext_addr - external host IP address |
| 1543 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1544 | """ |
| 1545 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1546 | self.papi.nat_det_close_session_out, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1547 | {'out_addr': out_addr, |
| 1548 | 'out_port': out_port, |
| 1549 | 'ext_addr': ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1550 | 'ext_port': ext_port}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1551 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1552 | def nat_det_close_session_in( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1553 | self, |
| 1554 | in_addr, |
| 1555 | in_port, |
| 1556 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1557 | ext_port): |
| 1558 | """Close deterministic NAT session using inside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1559 | |
| 1560 | :param in_addr - inside IP address |
| 1561 | :param in_port - inside port |
| 1562 | :param ext_addr - external host IP address |
| 1563 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1564 | """ |
| 1565 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1566 | self.papi.nat_det_close_session_in, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1567 | {'in_addr': in_addr, |
| 1568 | 'in_port': in_port, |
| 1569 | 'ext_addr': ext_addr, |
| 1570 | 'ext_port': ext_port, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1571 | 'is_nat44': 1}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1572 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1573 | def nat_det_session_dump( |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1574 | self, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1575 | user_addr): |
| 1576 | """Dump deterministic NAT sessions belonging to a user |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1577 | |
| 1578 | :param user_addr - inside IP address of the user |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1579 | :return: Dictionary of deterministic NAT sessions |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1580 | """ |
| 1581 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1582 | self.papi.nat_det_session_dump, |
| 1583 | {'is_nat44': 1, |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1584 | 'user_addr': user_addr}) |
| 1585 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1586 | def nat64_add_del_pool_addr_range( |
| 1587 | self, |
| 1588 | start_addr, |
| 1589 | end_addr, |
| 1590 | vrf_id=0xFFFFFFFF, |
| 1591 | is_add=1): |
| 1592 | """Add/del address range to NAT64 pool |
| 1593 | |
| 1594 | :param start_addr: First IP address |
| 1595 | :param end_addr: Last IP address |
| 1596 | :param vrf_id: VRF id for the address range |
| 1597 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1598 | """ |
| 1599 | return self.api( |
| 1600 | self.papi.nat64_add_del_pool_addr_range, |
| 1601 | {'start_addr': start_addr, |
| 1602 | 'end_addr': end_addr, |
| 1603 | 'vrf_id': vrf_id, |
| 1604 | 'is_add': is_add}) |
| 1605 | |
| 1606 | def nat64_pool_addr_dump(self): |
| 1607 | """Dump NAT64 pool addresses |
| 1608 | :return: Dictionary of NAT64 pool addresses |
| 1609 | """ |
| 1610 | return self.api(self.papi.nat64_pool_addr_dump, {}) |
| 1611 | |
| 1612 | def nat64_add_del_interface( |
| 1613 | self, |
| 1614 | sw_if_index, |
| 1615 | is_inside=1, |
| 1616 | is_add=1): |
| 1617 | """Enable/disable NAT64 feature on the interface |
| 1618 | :param sw_if_index: Index of the interface |
| 1619 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1620 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1621 | """ |
| 1622 | return self.api( |
| 1623 | self.papi.nat64_add_del_interface, |
| 1624 | {'sw_if_index': sw_if_index, |
| 1625 | 'is_inside': is_inside, |
| 1626 | 'is_add': is_add}) |
| 1627 | |
| 1628 | def nat64_interface_dump(self): |
| 1629 | """Dump interfaces with NAT64 feature |
| 1630 | :return: Dictionary of interfaces with NAT64 feature |
| 1631 | """ |
| 1632 | return self.api(self.papi.nat64_interface_dump, {}) |
| 1633 | |
| 1634 | def nat64_add_del_static_bib( |
| 1635 | self, |
| 1636 | in_ip, |
| 1637 | out_ip, |
| 1638 | in_port, |
| 1639 | out_port, |
| 1640 | protocol, |
| 1641 | vrf_id=0, |
| 1642 | is_add=1): |
| 1643 | """Add/delete S-NAT static BIB entry |
| 1644 | |
| 1645 | :param in_ip: Inside IPv6 address |
| 1646 | :param out_ip: Outside IPv4 address |
| 1647 | :param in_port: Inside port number |
| 1648 | :param out_port: Outside port number |
| 1649 | :param protocol: IP protocol |
| 1650 | :param vrf_id: VRF ID (Default value = 0) |
| 1651 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1652 | """ |
| 1653 | return self.api( |
| 1654 | self.papi.nat64_add_del_static_bib, |
| 1655 | {'i_addr': in_ip, |
| 1656 | 'o_addr': out_ip, |
| 1657 | 'i_port': in_port, |
| 1658 | 'o_port': out_port, |
| 1659 | 'vrf_id': vrf_id, |
| 1660 | 'proto': protocol, |
| 1661 | 'is_add': is_add}) |
| 1662 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1663 | def nat64_bib_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1664 | """Dump NAT64 BIB |
| 1665 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1666 | :param protocol: IP protocol (Default value = 255, all BIBs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1667 | :returns: Dictionary of NAT64 BIB entries |
| 1668 | """ |
| 1669 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 1670 | |
| 1671 | def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440, |
| 1672 | tcp_incoming_syn=6): |
| 1673 | """Set values of timeouts for NAT64 (in seconds) |
| 1674 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1675 | :param udpi: UDP timeout (Default value = 300) |
| 1676 | :param icmp: ICMP timeout (Default value = 60) |
| 1677 | :param tcp_trans: TCP transitory timeout (Default value = 240) |
| 1678 | :param tcp_est: TCP established timeout (Default value = 7440) |
| 1679 | :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1680 | """ |
| 1681 | return self.api( |
| 1682 | self.papi.nat64_set_timeouts, |
| 1683 | {'udp': udp, |
| 1684 | 'icmp': icmp, |
| 1685 | 'tcp_trans': tcp_trans, |
| 1686 | 'tcp_est': tcp_est, |
| 1687 | 'tcp_incoming_syn': tcp_incoming_syn}) |
| 1688 | |
| 1689 | def nat64_get_timeouts(self): |
| 1690 | """Get values of timeouts for NAT64 |
| 1691 | |
| 1692 | :return: Timeouts for NAT64 (in seconds) |
| 1693 | """ |
| 1694 | return self.api(self.papi.nat64_get_timeouts, {}) |
| 1695 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1696 | def nat64_st_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1697 | """Dump NAT64 session table |
| 1698 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 1699 | :param protocol: IP protocol (Default value = 255, all STs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1700 | :returns: Dictionary of NAT64 sesstion table entries |
| 1701 | """ |
| 1702 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 1703 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 1704 | def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1): |
| 1705 | """Add/del NAT64 prefix |
| 1706 | |
| 1707 | :param prefix: NAT64 prefix |
| 1708 | :param plen: NAT64 prefix length |
| 1709 | :param vrf_id: VRF id of tenant (Default 0) |
| 1710 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1711 | """ |
| 1712 | return self.api( |
| 1713 | self.papi.nat64_add_del_prefix, |
| 1714 | {'prefix': prefix, |
| 1715 | 'prefix_len': plen, |
| 1716 | 'vrf_id': vrf_id, |
| 1717 | 'is_add': is_add}) |
| 1718 | |
| 1719 | def nat64_prefix_dump(self): |
| 1720 | """Dump NAT64 prefix |
| 1721 | |
| 1722 | :returns: Dictionary of NAT64 prefixes |
| 1723 | """ |
| 1724 | return self.api(self.papi.nat64_prefix_dump, {}) |
| 1725 | |
Matus Fabian | 0938dcf | 2017-11-08 01:59:38 -0800 | [diff] [blame] | 1726 | def nat64_add_interface_addr( |
| 1727 | self, |
| 1728 | sw_if_index, |
| 1729 | is_add=1): |
| 1730 | """Add/del NAT64 address from interface |
| 1731 | |
| 1732 | :param sw_if_index: Software index of the interface |
| 1733 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1734 | """ |
| 1735 | return self.api(self.papi.nat64_add_del_interface_addr, |
| 1736 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1737 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 1738 | def dslite_set_aftr_addr(self, ip6, ip4): |
| 1739 | """Set DS-Lite AFTR addresses |
| 1740 | |
| 1741 | :param ip4: IPv4 address |
| 1742 | :param ip6: IPv6 address |
| 1743 | """ |
| 1744 | return self.api( |
| 1745 | self.papi.dslite_set_aftr_addr, |
| 1746 | {'ip4_addr': ip4, |
| 1747 | 'ip6_addr': ip6}) |
| 1748 | |
| 1749 | def dslite_add_del_pool_addr_range( |
| 1750 | self, |
| 1751 | start_addr, |
| 1752 | end_addr, |
| 1753 | is_add=1): |
| 1754 | """Add/del address range to DS-Lite pool |
| 1755 | |
| 1756 | :param start_addr: First IP address |
| 1757 | :param end_addr: Last IP address |
| 1758 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1759 | """ |
| 1760 | return self.api( |
| 1761 | self.papi.dslite_add_del_pool_addr_range, |
| 1762 | {'start_addr': start_addr, |
| 1763 | 'end_addr': end_addr, |
| 1764 | 'is_add': is_add}) |
| 1765 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1766 | def control_ping(self): |
| 1767 | self.api(self.papi.control_ping) |
| 1768 | |
| 1769 | 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] | 1770 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1771 | bfd_key_id=None, conf_key_id=None): |
| 1772 | if bfd_key_id is None: |
| 1773 | return self.api(self.papi.bfd_udp_add, |
| 1774 | { |
| 1775 | 'sw_if_index': sw_if_index, |
| 1776 | 'desired_min_tx': desired_min_tx, |
| 1777 | 'required_min_rx': required_min_rx, |
| 1778 | 'local_addr': local_addr, |
| 1779 | 'peer_addr': peer_addr, |
| 1780 | 'is_ipv6': is_ipv6, |
| 1781 | 'detect_mult': detect_mult, |
| 1782 | }) |
| 1783 | else: |
| 1784 | return self.api(self.papi.bfd_udp_add, |
| 1785 | { |
| 1786 | 'sw_if_index': sw_if_index, |
| 1787 | 'desired_min_tx': desired_min_tx, |
| 1788 | 'required_min_rx': required_min_rx, |
| 1789 | 'local_addr': local_addr, |
| 1790 | 'peer_addr': peer_addr, |
| 1791 | 'is_ipv6': is_ipv6, |
| 1792 | 'detect_mult': detect_mult, |
| 1793 | 'is_authenticated': 1, |
| 1794 | 'bfd_key_id': bfd_key_id, |
| 1795 | 'conf_key_id': conf_key_id, |
| 1796 | }) |
| 1797 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1798 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1799 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1800 | return self.api(self.papi.bfd_udp_mod, |
| 1801 | { |
| 1802 | 'sw_if_index': sw_if_index, |
| 1803 | 'desired_min_tx': desired_min_tx, |
| 1804 | 'required_min_rx': required_min_rx, |
| 1805 | 'local_addr': local_addr, |
| 1806 | 'peer_addr': peer_addr, |
| 1807 | 'is_ipv6': is_ipv6, |
| 1808 | 'detect_mult': detect_mult, |
| 1809 | }) |
| 1810 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1811 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1812 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1813 | is_delayed=False): |
| 1814 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1815 | { |
| 1816 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1817 | 'local_addr': local_addr, |
| 1818 | 'peer_addr': peer_addr, |
| 1819 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1820 | 'is_delayed': 1 if is_delayed else 0, |
| 1821 | 'bfd_key_id': bfd_key_id, |
| 1822 | 'conf_key_id': conf_key_id, |
| 1823 | }) |
| 1824 | |
| 1825 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1826 | is_ipv6=0, is_delayed=False): |
| 1827 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1828 | { |
| 1829 | 'sw_if_index': sw_if_index, |
| 1830 | 'local_addr': local_addr, |
| 1831 | 'peer_addr': peer_addr, |
| 1832 | 'is_ipv6': is_ipv6, |
| 1833 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1834 | }) |
| 1835 | |
| 1836 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1837 | return self.api(self.papi.bfd_udp_del, |
| 1838 | { |
| 1839 | 'sw_if_index': sw_if_index, |
| 1840 | 'local_addr': local_addr, |
| 1841 | 'peer_addr': peer_addr, |
| 1842 | 'is_ipv6': is_ipv6, |
| 1843 | }) |
| 1844 | |
| 1845 | def bfd_udp_session_dump(self): |
| 1846 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1847 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1848 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1849 | peer_addr, is_ipv6=0): |
| 1850 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1851 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1852 | 'sw_if_index': sw_if_index, |
| 1853 | 'local_addr': local_addr, |
| 1854 | 'peer_addr': peer_addr, |
| 1855 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1856 | }) |
| 1857 | |
| 1858 | def want_bfd_events(self, enable_disable=1): |
| 1859 | return self.api(self.papi.want_bfd_events, { |
| 1860 | 'enable_disable': enable_disable, |
| 1861 | 'pid': os.getpid(), |
| 1862 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1863 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1864 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1865 | return self.api(self.papi.bfd_auth_set_key, { |
| 1866 | 'conf_key_id': conf_key_id, |
| 1867 | 'auth_type': auth_type, |
| 1868 | 'key': key, |
| 1869 | 'key_len': len(key), |
| 1870 | }) |
| 1871 | |
| 1872 | def bfd_auth_del_key(self, conf_key_id): |
| 1873 | return self.api(self.papi.bfd_auth_del_key, { |
| 1874 | 'conf_key_id': conf_key_id, |
| 1875 | }) |
| 1876 | |
| 1877 | def bfd_auth_keys_dump(self): |
| 1878 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1879 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1880 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 1881 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 1882 | {'sw_if_index': sw_if_index}) |
| 1883 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1884 | def bfd_udp_del_echo_source(self): |
| 1885 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 1886 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1887 | def classify_add_del_table( |
| 1888 | self, |
| 1889 | is_add, |
| 1890 | mask, |
| 1891 | match_n_vectors=1, |
| 1892 | table_index=0xFFFFFFFF, |
| 1893 | nbuckets=2, |
| 1894 | memory_size=2097152, |
| 1895 | skip_n_vectors=0, |
| 1896 | next_table_index=0xFFFFFFFF, |
| 1897 | miss_next_index=0xFFFFFFFF, |
| 1898 | current_data_flag=0, |
| 1899 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1900 | """ |
| 1901 | :param is_add: |
| 1902 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1903 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1904 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1905 | :param nbuckets: (Default value = 2) |
| 1906 | :param memory_size: (Default value = 2097152) |
| 1907 | :param skip_n_vectors: (Default value = 0) |
| 1908 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1909 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1910 | :param current_data_flag: (Default value = 0) |
| 1911 | :param current_data_offset: (Default value = 0) |
| 1912 | """ |
| 1913 | |
| 1914 | return self.api( |
| 1915 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1916 | {'is_add': is_add, |
| 1917 | 'table_index': table_index, |
| 1918 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1919 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1920 | 'skip_n_vectors': skip_n_vectors, |
| 1921 | 'match_n_vectors': match_n_vectors, |
| 1922 | 'next_table_index': next_table_index, |
| 1923 | 'miss_next_index': miss_next_index, |
| 1924 | 'current_data_flag': current_data_flag, |
| 1925 | 'current_data_offset': current_data_offset, |
| 1926 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1927 | |
| 1928 | def classify_add_del_session( |
| 1929 | self, |
| 1930 | is_add, |
| 1931 | table_index, |
| 1932 | match, |
| 1933 | opaque_index=0xFFFFFFFF, |
| 1934 | hit_next_index=0xFFFFFFFF, |
| 1935 | advance=0, |
| 1936 | action=0, |
| 1937 | metadata=0): |
| 1938 | """ |
| 1939 | :param is_add: |
| 1940 | :param table_index: |
| 1941 | :param match: |
| 1942 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1943 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1944 | :param advance: (Default value = 0) |
| 1945 | :param action: (Default value = 0) |
| 1946 | :param metadata: (Default value = 0) |
| 1947 | """ |
| 1948 | |
| 1949 | return self.api( |
| 1950 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1951 | {'is_add': is_add, |
| 1952 | 'table_index': table_index, |
| 1953 | 'hit_next_index': hit_next_index, |
| 1954 | 'opaque_index': opaque_index, |
| 1955 | 'advance': advance, |
| 1956 | 'action': action, |
| 1957 | 'metadata': metadata, |
| 1958 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1959 | |
| 1960 | def input_acl_set_interface( |
| 1961 | self, |
| 1962 | is_add, |
| 1963 | sw_if_index, |
| 1964 | ip4_table_index=0xFFFFFFFF, |
| 1965 | ip6_table_index=0xFFFFFFFF, |
| 1966 | l2_table_index=0xFFFFFFFF): |
| 1967 | """ |
| 1968 | :param is_add: |
| 1969 | :param sw_if_index: |
| 1970 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1971 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1972 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1973 | """ |
| 1974 | |
| 1975 | return self.api( |
| 1976 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1977 | {'sw_if_index': sw_if_index, |
| 1978 | 'ip4_table_index': ip4_table_index, |
| 1979 | 'ip6_table_index': ip6_table_index, |
| 1980 | 'l2_table_index': l2_table_index, |
| 1981 | 'is_add': is_add}) |
| 1982 | |
| 1983 | def set_ipfix_exporter( |
| 1984 | self, |
| 1985 | collector_address, |
| 1986 | src_address, |
| 1987 | path_mtu, |
| 1988 | template_interval, |
| 1989 | vrf_id=0, |
| 1990 | collector_port=4739, |
| 1991 | udp_checksum=0): |
| 1992 | return self.api( |
| 1993 | self.papi.set_ipfix_exporter, |
| 1994 | { |
| 1995 | 'collector_address': collector_address, |
| 1996 | 'collector_port': collector_port, |
| 1997 | 'src_address': src_address, |
| 1998 | 'vrf_id': vrf_id, |
| 1999 | 'path_mtu': path_mtu, |
| 2000 | 'template_interval': template_interval, |
| 2001 | 'udp_checksum': udp_checksum, |
| 2002 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2003 | |
| 2004 | def dhcp_proxy_config(self, |
| 2005 | dhcp_server, |
| 2006 | dhcp_src_address, |
| 2007 | rx_table_id=0, |
| 2008 | server_table_id=0, |
| 2009 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2010 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2011 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2012 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2013 | { |
| 2014 | 'rx_vrf_id': rx_table_id, |
| 2015 | 'server_vrf_id': server_table_id, |
| 2016 | 'is_ipv6': is_ipv6, |
| 2017 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2018 | 'dhcp_server': dhcp_server, |
| 2019 | 'dhcp_src_address': dhcp_src_address, |
| 2020 | }) |
| 2021 | |
| 2022 | def dhcp_proxy_set_vss(self, |
| 2023 | table_id, |
| 2024 | fib_id, |
| 2025 | oui, |
| 2026 | is_add=1, |
| 2027 | is_ip6=0): |
| 2028 | return self.api( |
| 2029 | self.papi.dhcp_proxy_set_vss, |
| 2030 | { |
| 2031 | 'tbl_id': table_id, |
| 2032 | 'fib_id': fib_id, |
| 2033 | 'is_ipv6': is_ip6, |
| 2034 | 'is_add': is_add, |
| 2035 | 'oui': oui, |
| 2036 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2037 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2038 | def dhcp_client(self, |
| 2039 | sw_if_index, |
| 2040 | hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2041 | client_id='', |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2042 | is_add=1, |
| 2043 | want_dhcp_events=0): |
| 2044 | return self.api( |
| 2045 | self.papi.dhcp_client_config, |
| 2046 | { |
| 2047 | 'sw_if_index': sw_if_index, |
| 2048 | 'hostname': hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2049 | 'client_id': client_id, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2050 | 'is_add': is_add, |
| 2051 | 'want_dhcp_event': want_dhcp_events, |
| 2052 | 'pid': os.getpid(), |
| 2053 | }) |
| 2054 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2055 | def ip_mroute_add_del(self, |
| 2056 | src_address, |
| 2057 | grp_address, |
| 2058 | grp_address_length, |
| 2059 | e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2060 | next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2061 | next_hop_sw_if_index, |
| 2062 | i_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2063 | bier_imp=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2064 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2065 | table_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2066 | is_add=1, |
| 2067 | is_ipv6=0, |
| 2068 | is_local=0): |
| 2069 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2070 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2071 | """ |
| 2072 | return self.api( |
| 2073 | self.papi.ip_mroute_add_del, |
| 2074 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 2075 | 'entry_flags': e_flags, |
| 2076 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2077 | 'table_id': table_id, |
| 2078 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2079 | 'is_add': is_add, |
| 2080 | 'is_ipv6': is_ipv6, |
| 2081 | 'is_local': is_local, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2082 | 'bier_imp': bier_imp, |
| 2083 | 'next_hop_afi': next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2084 | 'grp_address_length': grp_address_length, |
| 2085 | 'grp_address': grp_address, |
| 2086 | 'src_address': src_address}) |
| 2087 | |
| 2088 | def mfib_signal_dump(self): |
| 2089 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 2090 | |
| 2091 | def ip_mfib_dump(self): |
| 2092 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2093 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2094 | def ip6_mfib_dump(self): |
| 2095 | return self.api(self.papi.ip6_mfib_dump, {}) |
| 2096 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2097 | def lisp_enable_disable(self, is_enabled): |
| 2098 | return self.api( |
| 2099 | self.papi.lisp_enable_disable, |
| 2100 | { |
| 2101 | 'is_en': is_enabled, |
| 2102 | }) |
| 2103 | |
| 2104 | def lisp_locator_set(self, |
| 2105 | ls_name, |
| 2106 | is_add=1): |
| 2107 | return self.api( |
| 2108 | self.papi.lisp_add_del_locator_set, |
| 2109 | { |
| 2110 | 'is_add': is_add, |
| 2111 | 'locator_set_name': ls_name |
| 2112 | }) |
| 2113 | |
| 2114 | def lisp_locator_set_dump(self): |
| 2115 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 2116 | |
| 2117 | def lisp_locator(self, |
| 2118 | ls_name, |
| 2119 | sw_if_index, |
| 2120 | priority=1, |
| 2121 | weight=1, |
| 2122 | is_add=1): |
| 2123 | return self.api( |
| 2124 | self.papi.lisp_add_del_locator, |
| 2125 | { |
| 2126 | 'is_add': is_add, |
| 2127 | 'locator_set_name': ls_name, |
| 2128 | 'sw_if_index': sw_if_index, |
| 2129 | 'priority': priority, |
| 2130 | 'weight': weight |
| 2131 | }) |
| 2132 | |
| 2133 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 2134 | return self.api( |
| 2135 | self.papi.lisp_locator_dump, |
| 2136 | { |
| 2137 | 'is_index_set': is_index_set, |
| 2138 | 'ls_name': ls_name, |
| 2139 | 'ls_index': ls_index, |
| 2140 | }) |
| 2141 | |
| 2142 | def lisp_local_mapping(self, |
| 2143 | ls_name, |
| 2144 | eid_type, |
| 2145 | eid, |
| 2146 | prefix_len, |
| 2147 | vni=0, |
| 2148 | key_id=0, |
| 2149 | key="", |
| 2150 | is_add=1): |
| 2151 | return self.api( |
| 2152 | self.papi.lisp_add_del_local_eid, |
| 2153 | { |
| 2154 | 'locator_set_name': ls_name, |
| 2155 | 'is_add': is_add, |
| 2156 | 'eid_type': eid_type, |
| 2157 | 'eid': eid, |
| 2158 | 'prefix_len': prefix_len, |
| 2159 | 'vni': vni, |
| 2160 | 'key_id': key_id, |
| 2161 | 'key': key |
| 2162 | }) |
| 2163 | |
| 2164 | def lisp_eid_table_dump(self, |
| 2165 | eid_set=0, |
| 2166 | prefix_length=0, |
| 2167 | vni=0, |
| 2168 | eid_type=0, |
| 2169 | eid=None, |
| 2170 | filter_opt=0): |
| 2171 | return self.api( |
| 2172 | self.papi.lisp_eid_table_dump, |
| 2173 | { |
| 2174 | 'eid_set': eid_set, |
| 2175 | 'prefix_length': prefix_length, |
| 2176 | 'vni': vni, |
| 2177 | 'eid_type': eid_type, |
| 2178 | 'eid': eid, |
| 2179 | 'filter': filter_opt, |
| 2180 | }) |
| 2181 | |
| 2182 | def lisp_remote_mapping(self, |
| 2183 | eid_type, |
| 2184 | eid, |
| 2185 | eid_prefix_len=0, |
| 2186 | vni=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 2187 | rlocs=[], |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2188 | rlocs_num=0, |
| 2189 | is_src_dst=0, |
| 2190 | is_add=1): |
| 2191 | return self.api( |
| 2192 | self.papi.lisp_add_del_remote_mapping, |
| 2193 | { |
| 2194 | 'is_add': is_add, |
| 2195 | 'eid_type': eid_type, |
| 2196 | 'eid': eid, |
| 2197 | 'eid_len': eid_prefix_len, |
| 2198 | 'rloc_num': rlocs_num, |
| 2199 | 'rlocs': rlocs, |
| 2200 | 'vni': vni, |
| 2201 | 'is_src_dst': is_src_dst, |
| 2202 | }) |
| 2203 | |
| 2204 | def lisp_adjacency(self, |
| 2205 | leid, |
| 2206 | reid, |
| 2207 | leid_len, |
| 2208 | reid_len, |
| 2209 | eid_type, |
| 2210 | is_add=1, |
| 2211 | vni=0): |
| 2212 | return self.api( |
| 2213 | self.papi.lisp_add_del_adjacency, |
| 2214 | { |
| 2215 | 'is_add': is_add, |
| 2216 | 'vni': vni, |
| 2217 | 'eid_type': eid_type, |
| 2218 | 'leid': leid, |
| 2219 | 'reid': reid, |
| 2220 | 'leid_len': leid_len, |
| 2221 | 'reid_len': reid_len, |
| 2222 | }) |
| 2223 | |
| 2224 | def lisp_adjacencies_get(self, vni=0): |
| 2225 | return self.api( |
| 2226 | self.papi.lisp_adjacencies_get, |
| 2227 | { |
| 2228 | 'vni': vni |
| 2229 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2230 | |
| 2231 | def map_add_domain(self, |
| 2232 | ip6_prefix, |
| 2233 | ip6_prefix_len, |
| 2234 | ip6_src, |
| 2235 | ip6_src_prefix_len, |
| 2236 | ip4_prefix, |
| 2237 | ip4_prefix_len, |
| 2238 | ea_bits_len=0, |
| 2239 | psid_offset=0, |
| 2240 | psid_length=0, |
| 2241 | is_translation=0, |
| 2242 | mtu=1280): |
| 2243 | return self.api( |
| 2244 | self.papi.map_add_domain, |
| 2245 | { |
| 2246 | 'ip6_prefix': ip6_prefix, |
| 2247 | 'ip6_prefix_len': ip6_prefix_len, |
| 2248 | 'ip4_prefix': ip4_prefix, |
| 2249 | 'ip4_prefix_len': ip4_prefix_len, |
| 2250 | 'ip6_src': ip6_src, |
| 2251 | 'ip6_src_prefix_len': ip6_src_prefix_len, |
| 2252 | 'ea_bits_len': ea_bits_len, |
| 2253 | 'psid_offset': psid_offset, |
| 2254 | 'psid_length': psid_length, |
| 2255 | 'is_translation': is_translation, |
| 2256 | 'mtu': mtu |
| 2257 | }) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2258 | |
| 2259 | def gtpu_add_del_tunnel( |
| 2260 | self, |
| 2261 | src_addr, |
| 2262 | dst_addr, |
| 2263 | is_add=1, |
| 2264 | is_ipv6=0, |
| 2265 | mcast_sw_if_index=0xFFFFFFFF, |
| 2266 | encap_vrf_id=0, |
| 2267 | decap_next_index=0xFFFFFFFF, |
| 2268 | teid=0): |
| 2269 | """ |
| 2270 | |
| 2271 | :param is_add: (Default value = 1) |
| 2272 | :param is_ipv6: (Default value = 0) |
| 2273 | :param src_addr: |
| 2274 | :param dst_addr: |
| 2275 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2276 | :param encap_vrf_id: (Default value = 0) |
| 2277 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2278 | :param teid: (Default value = 0) |
| 2279 | |
| 2280 | """ |
| 2281 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 2282 | {'is_add': is_add, |
| 2283 | 'is_ipv6': is_ipv6, |
| 2284 | 'src_address': src_addr, |
| 2285 | 'dst_address': dst_addr, |
| 2286 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2287 | 'encap_vrf_id': encap_vrf_id, |
| 2288 | 'decap_next_index': decap_next_index, |
| 2289 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 2290 | |
| 2291 | def vxlan_gpe_add_del_tunnel( |
| 2292 | self, |
| 2293 | src_addr, |
| 2294 | dst_addr, |
| 2295 | mcast_sw_if_index=0xFFFFFFFF, |
| 2296 | is_add=1, |
| 2297 | is_ipv6=0, |
| 2298 | encap_vrf_id=0, |
| 2299 | decap_vrf_id=0, |
| 2300 | protocol=3, |
| 2301 | vni=0): |
| 2302 | """ |
| 2303 | |
| 2304 | :param local: |
| 2305 | :param remote: |
| 2306 | :param is_add: (Default value = 1) |
| 2307 | :param is_ipv6: (Default value = 0) |
| 2308 | :param encap_vrf_id: (Default value = 0) |
| 2309 | :param decap_vrf_id: (Default value = 0) |
| 2310 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2311 | :param protocol: (Default value = 3) |
| 2312 | :param vni: (Default value = 0) |
| 2313 | |
| 2314 | """ |
| 2315 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 2316 | {'is_add': is_add, |
| 2317 | 'is_ipv6': is_ipv6, |
| 2318 | 'local': src_addr, |
| 2319 | 'remote': dst_addr, |
| 2320 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2321 | 'encap_vrf_id': encap_vrf_id, |
| 2322 | 'decap_vrf_id': decap_vrf_id, |
| 2323 | 'protocol': protocol, |
| 2324 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2325 | |
| 2326 | def pppoe_add_del_session( |
| 2327 | self, |
| 2328 | client_ip, |
| 2329 | client_mac, |
| 2330 | session_id=0, |
| 2331 | is_add=1, |
| 2332 | is_ipv6=0, |
| 2333 | decap_vrf_id=0): |
| 2334 | """ |
| 2335 | |
| 2336 | :param is_add: (Default value = 1) |
| 2337 | :param is_ipv6: (Default value = 0) |
| 2338 | :param client_ip: |
| 2339 | :param session_id: (Default value = 0) |
| 2340 | :param client_mac: |
| 2341 | :param decap_vrf_id: (Default value = 0) |
| 2342 | |
| 2343 | """ |
| 2344 | return self.api(self.papi.pppoe_add_del_session, |
| 2345 | {'is_add': is_add, |
| 2346 | 'is_ipv6': is_ipv6, |
| 2347 | 'session_id': session_id, |
| 2348 | 'client_ip': client_ip, |
| 2349 | 'decap_vrf_id': decap_vrf_id, |
| 2350 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2351 | |
| 2352 | def sr_localsid_add_del(self, |
| 2353 | localsid_addr, |
| 2354 | behavior, |
| 2355 | nh_addr, |
| 2356 | is_del=0, |
| 2357 | end_psp=0, |
| 2358 | sw_if_index=0xFFFFFFFF, |
| 2359 | vlan_index=0, |
| 2360 | fib_table=0, |
| 2361 | ): |
| 2362 | """ Add/del IPv6 SR local-SID. |
| 2363 | |
| 2364 | :param localsid_addr: |
| 2365 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 2366 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
| 2367 | :param nh_addr: |
| 2368 | :param is_del: (Default value = 0) |
| 2369 | :param end_psp: (Default value = 0) |
| 2370 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 2371 | :param vlan_index: (Default value = 0) |
| 2372 | :param fib_table: (Default value = 0) |
| 2373 | """ |
| 2374 | return self.api( |
| 2375 | self.papi.sr_localsid_add_del, |
| 2376 | {'is_del': is_del, |
| 2377 | 'localsid_addr': localsid_addr, |
| 2378 | 'end_psp': end_psp, |
| 2379 | 'behavior': behavior, |
| 2380 | 'sw_if_index': sw_if_index, |
| 2381 | 'vlan_index': vlan_index, |
| 2382 | 'fib_table': fib_table, |
| 2383 | 'nh_addr': nh_addr |
| 2384 | } |
| 2385 | ) |
| 2386 | |
| 2387 | def sr_policy_add( |
| 2388 | self, |
| 2389 | bsid_addr, |
| 2390 | weight=1, |
| 2391 | is_encap=1, |
| 2392 | type=0, |
| 2393 | fib_table=0, |
| 2394 | n_segments=0, |
| 2395 | segments=[]): |
| 2396 | """ |
| 2397 | :param bsid_addr: bindingSID of the SR Policy |
| 2398 | :param weight: weight of the sid list. optional. (default: 1) |
| 2399 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 2400 | (default: Encap) |
| 2401 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 2402 | (default: default) |
| 2403 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 2404 | (default: 0) |
| 2405 | :param n_segments: number of segments \ |
| 2406 | (default: 0) |
| 2407 | :param segments: a vector of IPv6 address composing the segment list \ |
| 2408 | (default: []) |
| 2409 | """ |
| 2410 | return self.api( |
| 2411 | self.papi.sr_policy_add, |
| 2412 | {'bsid_addr': bsid_addr, |
| 2413 | 'weight': weight, |
| 2414 | 'is_encap': is_encap, |
| 2415 | 'type': type, |
| 2416 | 'fib_table': fib_table, |
| 2417 | 'n_segments': n_segments, |
| 2418 | 'segments': segments |
| 2419 | } |
| 2420 | ) |
| 2421 | |
| 2422 | def sr_policy_del( |
| 2423 | self, |
| 2424 | bsid_addr, |
| 2425 | sr_policy_index=0): |
| 2426 | """ |
| 2427 | :param bsid: bindingSID of the SR Policy |
| 2428 | :param sr_policy_index: index of the sr policy (default: 0) |
| 2429 | """ |
| 2430 | return self.api( |
| 2431 | self.papi.sr_policy_del, |
| 2432 | {'bsid_addr': bsid_addr, |
| 2433 | 'sr_policy_index': sr_policy_index |
| 2434 | }) |
| 2435 | |
| 2436 | def sr_steering_add_del( |
| 2437 | self, |
| 2438 | is_del, |
| 2439 | bsid_addr, |
| 2440 | sr_policy_index, |
| 2441 | table_id, |
| 2442 | prefix_addr, |
| 2443 | mask_width, |
| 2444 | sw_if_index, |
| 2445 | traffic_type): |
| 2446 | """ |
| 2447 | Steer traffic L2 and L3 traffic through a given SR policy |
| 2448 | |
| 2449 | :param is_del: delete or add |
| 2450 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 2451 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 2452 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 2453 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 2454 | :param mask_width: is the mask for L3 traffic type |
| 2455 | :param sw_if_index: is the incoming interface for L2 traffic |
| 2456 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 2457 | """ |
| 2458 | return self.api( |
| 2459 | self.papi.sr_steering_add_del, |
| 2460 | {'is_del': is_del, |
| 2461 | 'bsid_addr': bsid_addr, |
| 2462 | 'sr_policy_index': sr_policy_index, |
| 2463 | 'table_id': table_id, |
| 2464 | 'prefix_addr': prefix_addr, |
| 2465 | 'mask_width': mask_width, |
| 2466 | 'sw_if_index': sw_if_index, |
| 2467 | 'traffic_type': traffic_type |
| 2468 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2469 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2470 | def acl_add_replace(self, acl_index, r, tag='', |
| 2471 | expected_retval=0): |
| 2472 | """Add/replace an ACL |
| 2473 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 2474 | :param acl_rule r: ACL rules array. |
| 2475 | :param str tag: symbolic tag (description) for this ACL. |
| 2476 | :param int count: number of rules. |
| 2477 | """ |
| 2478 | return self.api(self.papi.acl_add_replace, |
| 2479 | {'acl_index': acl_index, |
| 2480 | 'r': r, |
| 2481 | 'count': len(r), |
| 2482 | 'tag': tag}, |
| 2483 | expected_retval=expected_retval) |
| 2484 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 2485 | def acl_del(self, acl_index, expected_retval=0): |
| 2486 | """ |
| 2487 | |
| 2488 | :param acl_index: |
| 2489 | :return: |
| 2490 | """ |
| 2491 | return self.api(self.papi.acl_del, |
| 2492 | {'acl_index': acl_index}, |
| 2493 | expected_retval=expected_retval) |
| 2494 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2495 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 2496 | expected_retval=0): |
| 2497 | return self.api(self.papi.acl_interface_set_acl_list, |
| 2498 | {'sw_if_index': sw_if_index, |
| 2499 | 'count': len(acls), |
| 2500 | 'n_input': n_input, |
| 2501 | 'acls': acls}, |
| 2502 | expected_retval=expected_retval) |
| 2503 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 2504 | def acl_interface_add_del(self, |
| 2505 | sw_if_index, |
| 2506 | acl_index, |
| 2507 | is_add=1): |
| 2508 | """ Add/Delete ACL to/from interface |
| 2509 | |
| 2510 | :param sw_if_index: |
| 2511 | :param acl_index: |
| 2512 | :param is_add: (Default value = 1) |
| 2513 | """ |
| 2514 | |
| 2515 | return self.api(self.papi.acl_interface_add_del, |
| 2516 | {'is_add': is_add, |
| 2517 | 'is_input': 1, |
| 2518 | 'sw_if_index': sw_if_index, |
| 2519 | 'acl_index': acl_index}) |
| 2520 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 2521 | def acl_dump(self, acl_index, expected_retval=0): |
| 2522 | return self.api(self.papi.acl_dump, |
| 2523 | {'acl_index': acl_index}, |
| 2524 | expected_retval=expected_retval) |
| 2525 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2526 | def macip_acl_add(self, rules, tag=""): |
| 2527 | """ Add MACIP acl |
| 2528 | |
| 2529 | :param rules: list of rules for given acl |
| 2530 | :param tag: acl tag |
| 2531 | """ |
| 2532 | |
| 2533 | return self.api(self.papi.macip_acl_add, |
| 2534 | {'r': rules, |
| 2535 | 'count': len(rules), |
| 2536 | 'tag': tag}) |
| 2537 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2538 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 2539 | """ Add MACIP acl |
| 2540 | |
| 2541 | :param rules: list of rules for given acl |
| 2542 | :param tag: acl tag |
| 2543 | """ |
| 2544 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 2545 | return self.api(self.papi.macip_acl_add_replace, |
| 2546 | {'acl_index': acl_index, |
| 2547 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 2548 | 'count': len(rules), |
| 2549 | 'tag': tag}) |
| 2550 | |
| 2551 | def macip_acl_del(self, acl_index): |
| 2552 | """ |
| 2553 | |
| 2554 | :param acl_index: |
| 2555 | :return: |
| 2556 | """ |
| 2557 | return self.api(self.papi.macip_acl_del, |
| 2558 | {'acl_index': acl_index}) |
| 2559 | |
| 2560 | def macip_acl_interface_add_del(self, |
| 2561 | sw_if_index, |
| 2562 | acl_index, |
| 2563 | is_add=1): |
| 2564 | """ Add MACIP acl to interface |
| 2565 | |
| 2566 | :param sw_if_index: |
| 2567 | :param acl_index: |
| 2568 | :param is_add: (Default value = 1) |
| 2569 | """ |
| 2570 | |
| 2571 | return self.api(self.papi.macip_acl_interface_add_del, |
| 2572 | {'is_add': is_add, |
| 2573 | 'sw_if_index': sw_if_index, |
| 2574 | 'acl_index': acl_index}) |
| 2575 | |
| 2576 | def macip_acl_interface_get(self): |
| 2577 | """ Return interface acls dump |
| 2578 | """ |
| 2579 | return self.api( |
| 2580 | self.papi.macip_acl_interface_get, {}) |
| 2581 | |
| 2582 | def macip_acl_dump(self, acl_index=4294967295): |
| 2583 | """ Return MACIP acl dump |
| 2584 | """ |
| 2585 | |
| 2586 | return self.api( |
| 2587 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 2588 | |
| 2589 | def policer_add_del(self, |
| 2590 | name, |
| 2591 | cir, |
| 2592 | eir, |
| 2593 | cb, |
| 2594 | eb, |
| 2595 | is_add=1, |
| 2596 | rate_type=0, |
| 2597 | round_type=0, |
| 2598 | ptype=0, |
| 2599 | color_aware=0, |
| 2600 | conform_action_type=1, |
| 2601 | conform_dscp=0, |
| 2602 | exceed_action_type=0, |
| 2603 | exceed_dscp=0, |
| 2604 | violate_action_type=0, |
| 2605 | violate_dscp=0): |
| 2606 | return self.api(self.papi.policer_add_del, |
| 2607 | {'name': name, |
| 2608 | 'cir': cir, |
| 2609 | 'eir': eir, |
| 2610 | 'cb': cb, |
| 2611 | 'eb': eb, |
| 2612 | 'is_add': is_add, |
| 2613 | 'rate_type': rate_type, |
| 2614 | 'round_type': round_type, |
| 2615 | 'type': ptype, |
| 2616 | 'color_aware': color_aware, |
| 2617 | 'conform_action_type': conform_action_type, |
| 2618 | 'conform_dscp': conform_dscp, |
| 2619 | 'exceed_action_type': exceed_action_type, |
| 2620 | 'exceed_dscp': exceed_dscp, |
| 2621 | 'violate_action_type': violate_action_type, |
| 2622 | 'violate_dscp': violate_dscp}) |
| 2623 | |
| 2624 | def ip_punt_police(self, |
| 2625 | policer_index, |
| 2626 | is_ip6=0, |
| 2627 | is_add=1): |
| 2628 | return self.api(self.papi.ip_punt_police, |
| 2629 | {'policer_index': policer_index, |
| 2630 | 'is_add': is_add, |
| 2631 | 'is_ip6': is_ip6}) |
| 2632 | |
| 2633 | def ip_punt_redirect(self, |
| 2634 | rx_sw_if_index, |
| 2635 | tx_sw_if_index, |
| 2636 | nh, |
| 2637 | is_ip6=0, |
| 2638 | is_add=1): |
| 2639 | return self.api(self.papi.ip_punt_redirect, |
| 2640 | {'rx_sw_if_index': rx_sw_if_index, |
| 2641 | 'tx_sw_if_index': tx_sw_if_index, |
| 2642 | 'nh': nh, |
| 2643 | 'is_add': is_add, |
| 2644 | 'is_ip6': is_ip6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2645 | |
| 2646 | def bier_table_add_del(self, |
| 2647 | bti, |
| 2648 | mpls_label, |
| 2649 | is_add=1): |
| 2650 | """ BIER Table add/del """ |
| 2651 | return self.api( |
| 2652 | self.papi.bier_table_add_del, |
| 2653 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 2654 | "bt_sub_domain": bti.sub_domain_id, |
| 2655 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2656 | 'bt_label': mpls_label, |
| 2657 | 'bt_is_add': is_add}) |
| 2658 | |
| 2659 | def bier_table_dump(self): |
| 2660 | return self.api(self.papi.bier_table_dump, {}) |
| 2661 | |
| 2662 | def bier_route_add_del(self, |
| 2663 | bti, |
| 2664 | bp, |
| 2665 | next_hop, |
| 2666 | next_hop_label, |
| 2667 | next_hop_table_id, |
| 2668 | next_hop_is_ip4=1, |
| 2669 | is_add=1): |
| 2670 | """ BIER Route add/del """ |
| 2671 | return self.api( |
| 2672 | self.papi.bier_route_add_del, |
| 2673 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2674 | "bt_sub_domain": bti.sub_domain_id, |
| 2675 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2676 | 'br_bp': bp, |
| 2677 | 'br_n_paths': 1, |
| 2678 | 'br_paths': [{'next_hop': next_hop, |
| 2679 | 'afi': 0, |
| 2680 | 'n_labels': 1, |
| 2681 | 'table_id': next_hop_table_id, |
| 2682 | 'label_stack': [next_hop_label]}], |
| 2683 | 'br_is_add': is_add}) |
| 2684 | |
| 2685 | def bier_route_dump(self, bti): |
| 2686 | return self.api( |
| 2687 | self.papi.bier_route_dump, |
| 2688 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 2689 | "bt_sub_domain": bti.sub_domain_id, |
| 2690 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 2691 | |
| 2692 | def bier_imp_add(self, |
| 2693 | bti, |
| 2694 | src, |
| 2695 | ibytes, |
| 2696 | is_add=1): |
| 2697 | """ BIER Imposition Add """ |
| 2698 | return self.api( |
| 2699 | self.papi.bier_imp_add, |
| 2700 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 2701 | "bt_sub_domain": bti.sub_domain_id, |
| 2702 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 2703 | 'bi_src': src, |
| 2704 | 'bi_n_bytes': len(ibytes), |
| 2705 | 'bi_bytes': ibytes}) |
| 2706 | |
| 2707 | def bier_imp_del(self, bi_index): |
| 2708 | """ BIER Imposition del """ |
| 2709 | return self.api( |
| 2710 | self.papi.bier_imp_del, |
| 2711 | {'bi_index': bi_index}) |
| 2712 | |
| 2713 | def bier_imp_dump(self): |
| 2714 | return self.api(self.papi.bier_imp_dump, {}) |
| 2715 | |
| 2716 | def bier_disp_table_add_del(self, |
| 2717 | bdti, |
| 2718 | is_add=1): |
| 2719 | """ BIER Disposition Table add/del """ |
| 2720 | return self.api( |
| 2721 | self.papi.bier_disp_table_add_del, |
| 2722 | {'bdt_tbl_id': bdti, |
| 2723 | 'bdt_is_add': is_add}) |
| 2724 | |
| 2725 | def bier_disp_table_dump(self): |
| 2726 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 2727 | |
| 2728 | def bier_disp_entry_add_del(self, |
| 2729 | bdti, |
| 2730 | bp, |
| 2731 | payload_proto, |
| 2732 | next_hop, |
| 2733 | next_hop_tbl_id=0, |
| 2734 | next_hop_rpf_id=~0, |
| 2735 | next_hop_is_ip4=1, |
| 2736 | is_add=1): |
| 2737 | """ BIER Route add/del """ |
| 2738 | return self.api( |
| 2739 | self.papi.bier_disp_entry_add_del, |
| 2740 | {'bde_tbl_id': bdti, |
| 2741 | 'bde_bp': bp, |
| 2742 | 'bde_payload_proto': payload_proto, |
| 2743 | 'bde_n_paths': 1, |
| 2744 | 'bde_paths': [{'next_hop': next_hop, |
| 2745 | 'table_id': next_hop_tbl_id, |
| 2746 | 'afi': 0, |
| 2747 | 'rpf_id': next_hop_rpf_id, |
| 2748 | 'n_labels': 0, |
| 2749 | 'label_stack': [0]}], |
| 2750 | 'bde_is_add': is_add}) |
| 2751 | |
| 2752 | def bier_disp_entry_dump(self, bdti): |
| 2753 | return self.api( |
| 2754 | self.papi.bier_disp_entry_dump, |
| 2755 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 2756 | |
| 2757 | def add_node_next(self, node_name, next_name): |
| 2758 | """ Set the next node for a given node request |
| 2759 | |
| 2760 | :param node_name: |
| 2761 | :param next_name: |
| 2762 | """ |
| 2763 | return self.api(self.papi.add_node_next, |
| 2764 | {'node_name': node_name, |
| 2765 | 'next_name': next_name}) |