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: |
| 28 | L2_POP_1 = 3 |
| 29 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 30 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 31 | class UnexpectedApiReturnValueError(Exception): |
| 32 | """ exception raised when the API return value is unexpected """ |
| 33 | pass |
| 34 | |
| 35 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 36 | class VppPapiProvider(object): |
| 37 | """VPP-api provider using vpp-papi |
| 38 | |
| 39 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 40 | """ |
| 41 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 42 | _zero, _negative = range(2) |
| 43 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 44 | def __init__(self, name, shm_prefix, test_class): |
Klement Sekera | 277b89c | 2016-10-28 13:20:27 +0200 | [diff] [blame] | 45 | self.hook = Hook("vpp-papi-provider") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 46 | self.name = name |
| 47 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 48 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 49 | self._expect_api_retval = self._zero |
| 50 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 51 | jsonfiles = [] |
| 52 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 53 | install_dir = os.getenv('VPP_TEST_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 54 | for root, dirnames, filenames in os.walk(install_dir): |
| 55 | for filename in fnmatch.filter(filenames, '*.api.json'): |
| 56 | jsonfiles.append(os.path.join(root, filename)) |
| 57 | |
Ole Troan | 3cc4971 | 2017-03-08 12:02:24 +0100 | [diff] [blame] | 58 | self.vpp = VPP(jsonfiles, logger=test_class.logger) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 59 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 60 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 61 | def __enter__(self): |
| 62 | return self |
| 63 | |
| 64 | def expect_negative_api_retval(self): |
| 65 | """ Expect API failure """ |
| 66 | self._expect_stack.append(self._expect_api_retval) |
| 67 | self._expect_api_retval = self._negative |
| 68 | return self |
| 69 | |
| 70 | def expect_zero_api_retval(self): |
| 71 | """ Expect API success """ |
| 72 | self._expect_stack.append(self._expect_api_retval) |
| 73 | self._expect_api_retval = self._zero |
| 74 | return self |
| 75 | |
| 76 | def __exit__(self, exc_type, exc_value, traceback): |
| 77 | self._expect_api_retval = self._expect_stack.pop() |
| 78 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 79 | def register_hook(self, hook): |
| 80 | """Replace hook registration with new hook |
| 81 | |
| 82 | :param hook: |
| 83 | |
| 84 | """ |
| 85 | self.hook = hook |
| 86 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 87 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 88 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 89 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 90 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 91 | return e |
| 92 | |
| 93 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 94 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 95 | if name: |
| 96 | self.test_class.logger.debug("Expecting event within %ss", |
| 97 | timeout) |
| 98 | else: |
| 99 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 100 | name, timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 101 | if self._events: |
| 102 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 103 | limit = time.time() + timeout |
| 104 | while time.time() < limit: |
| 105 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 106 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 107 | if name and type(e).__name__ != name: |
| 108 | raise Exception( |
| 109 | "Unexpected event received: %s, expected: %s" % |
| 110 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 111 | self.test_class.logger.debug("Returning event %s:%s" % |
| 112 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 113 | return e |
| 114 | time.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 115 | raise Exception("Event did not occur within timeout") |
| 116 | |
| 117 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 118 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 119 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 120 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 121 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 122 | self._events.append(event) |
| 123 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 124 | def connect(self): |
| 125 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 126 | self.vpp.connect(self.name, self.shm_prefix) |
| 127 | self.papi = self.vpp.api |
| 128 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 129 | |
| 130 | def disconnect(self): |
| 131 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 132 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 133 | |
| 134 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 135 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 136 | Call the appropriate hooks before and after the API call |
| 137 | |
| 138 | :param api_fn: API function to call |
| 139 | :param api_args: tuple of API function arguments |
| 140 | :param expected_retval: Expected return value (Default value = 0) |
| 141 | :returns: reply from the API |
| 142 | |
| 143 | """ |
| 144 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 145 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 146 | if self._expect_api_retval == self._negative: |
| 147 | if hasattr(reply, 'retval') and reply.retval >= 0: |
| 148 | msg = "API call passed unexpectedly: expected negative "\ |
| 149 | "return value instead of %d in %s" % \ |
| 150 | (reply.retval, repr(reply)) |
| 151 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 152 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 153 | elif self._expect_api_retval == self._zero: |
| 154 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 155 | msg = "API call failed, expected %d return value instead "\ |
| 156 | "of %d in %s" % (expected_retval, reply.retval, |
| 157 | repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 158 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 159 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 160 | else: |
| 161 | raise Exception("Internal error, unexpected value for " |
| 162 | "self._expect_api_retval %s" % |
| 163 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 164 | self.hook.after_api(api_fn.__name__, api_args) |
| 165 | return reply |
| 166 | |
| 167 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 168 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 169 | |
| 170 | :param cli: CLI to execute |
| 171 | :returns: CLI output |
| 172 | |
| 173 | """ |
| 174 | self.hook.before_cli(cli) |
| 175 | cli += '\n' |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 176 | r = self.papi.cli_inband(length=len(cli), cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 177 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 178 | if hasattr(r, 'reply'): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 179 | return r.reply.decode().rstrip('\x00') |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 180 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 181 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 182 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 183 | |
| 184 | :param cli: CLI to execute |
| 185 | :returns: CLI output |
| 186 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 187 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 188 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 189 | def _convert_mac(self, mac): |
| 190 | return int(mac.replace(":", ""), 16) << 16 |
| 191 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 192 | def show_version(self): |
| 193 | """ """ |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 194 | return self.api(self.papi.show_version, {}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 195 | |
| 196 | def pg_create_interface(self, pg_index): |
| 197 | """ |
| 198 | |
| 199 | :param pg_index: |
| 200 | |
| 201 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 202 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 203 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 204 | |
| 205 | def sw_interface_dump(self, filter=None): |
| 206 | """ |
| 207 | |
| 208 | :param filter: (Default value = None) |
| 209 | |
| 210 | """ |
| 211 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 212 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 213 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 214 | args = {} |
| 215 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 216 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 217 | 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] | 218 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 219 | |
| 220 | :param sw_if_index: |
| 221 | :param is_ipv6: |
| 222 | :param table_id: |
| 223 | |
| 224 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 225 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 226 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 227 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 228 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 229 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 230 | is_ipv6=0, is_add=1, del_all=0): |
| 231 | """ |
| 232 | |
| 233 | :param addr: param is_ipv6: (Default value = 0) |
| 234 | :param sw_if_index: |
| 235 | :param addr_len: |
| 236 | :param is_ipv6: (Default value = 0) |
| 237 | :param is_add: (Default value = 1) |
| 238 | :param del_all: (Default value = 0) |
| 239 | |
| 240 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 241 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 242 | {'sw_if_index': sw_if_index, |
| 243 | 'is_add': is_add, |
| 244 | 'is_ipv6': is_ipv6, |
| 245 | 'del_all': del_all, |
| 246 | 'address_length': addr_len, |
| 247 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 248 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 249 | def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index, |
| 250 | is_add=1): |
| 251 | """ Set the Interface to be unnumbered |
| 252 | |
| 253 | :param is_add: (Default value = 1) |
| 254 | :param sw_if_index - interface That will be unnumbered |
| 255 | :param ip_sw_if_index - interface with an IP addres |
| 256 | |
| 257 | """ |
| 258 | return self.api(self.papi.sw_interface_set_unnumbered, |
| 259 | {'sw_if_index': ip_sw_if_index, |
| 260 | 'unnumbered_sw_if_index': sw_if_index, |
| 261 | 'is_add': is_add}) |
| 262 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 263 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 264 | is_enable=1): |
| 265 | """ |
| 266 | Enable/Disable MPLS on the interface |
| 267 | :param sw_if_index: |
| 268 | :param is_enable: (Default value = 1) |
| 269 | |
| 270 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 271 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 272 | {'sw_if_index': sw_if_index, |
| 273 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 274 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 275 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 276 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 277 | {'sw_if_index': sw_if_index, |
| 278 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 279 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 280 | def set_ip_flow_hash(self, |
| 281 | table_id, |
| 282 | src=1, |
| 283 | dst=1, |
| 284 | sport=1, |
| 285 | dport=1, |
| 286 | proto=1, |
| 287 | reverse=0, |
| 288 | is_ip6=0): |
| 289 | return self.api(self.papi.set_ip_flow_hash, |
| 290 | {'vrf_id': table_id, |
| 291 | 'src': src, |
| 292 | 'dst': dst, |
| 293 | 'dport': dport, |
| 294 | 'sport': sport, |
| 295 | 'proto': proto, |
| 296 | 'reverse': reverse, |
| 297 | 'is_ipv6': is_ip6}) |
| 298 | |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 299 | def ip6_nd_proxy(self, address, sw_if_index, is_del=0): |
| 300 | return self.api(self.papi.ip6nd_proxy_add_del, |
| 301 | {'address': address, |
| 302 | 'sw_if_index': sw_if_index, |
| 303 | 'is_del': is_del}) |
| 304 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 305 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 306 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 307 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 308 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 309 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 310 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 311 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 312 | 'suppress': suppress, |
| 313 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 314 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 315 | def ip6_sw_interface_ra_prefix(self, |
| 316 | sw_if_index, |
| 317 | address, |
| 318 | address_length, |
| 319 | use_default=0, |
| 320 | no_advertise=0, |
| 321 | off_link=0, |
| 322 | no_autoconfig=0, |
| 323 | no_onlink=0, |
| 324 | is_no=0, |
| 325 | val_lifetime=0xffffffff, |
| 326 | pref_lifetime=0xffffffff): |
| 327 | return self.api(self.papi.sw_interface_ip6nd_ra_prefix, |
| 328 | {'sw_if_index': sw_if_index, |
| 329 | 'address': address, |
| 330 | 'address_length': address_length, |
| 331 | 'use_default': use_default, |
| 332 | 'no_advertise': no_advertise, |
| 333 | 'off_link': off_link, |
| 334 | 'no_autoconfig': no_autoconfig, |
| 335 | 'no_onlink': no_onlink, |
| 336 | 'is_no': is_no, |
| 337 | 'val_lifetime': val_lifetime, |
| 338 | 'pref_lifetime': pref_lifetime}) |
| 339 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 340 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 341 | """ |
| 342 | Enable/Disable An interface for IPv6 |
| 343 | """ |
| 344 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 345 | {'sw_if_index': sw_if_index, |
| 346 | 'enable': enable}) |
| 347 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 348 | def vxlan_add_del_tunnel( |
| 349 | self, |
| 350 | src_addr, |
| 351 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 352 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 353 | is_add=1, |
| 354 | is_ipv6=0, |
| 355 | encap_vrf_id=0, |
| 356 | decap_next_index=0xFFFFFFFF, |
| 357 | vni=0): |
| 358 | """ |
| 359 | |
| 360 | :param dst_addr: |
| 361 | :param src_addr: |
| 362 | :param is_add: (Default value = 1) |
| 363 | :param is_ipv6: (Default value = 0) |
| 364 | :param encap_vrf_id: (Default value = 0) |
| 365 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 366 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 367 | :param vni: (Default value = 0) |
| 368 | |
| 369 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 370 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 371 | {'is_add': is_add, |
| 372 | 'is_ipv6': is_ipv6, |
| 373 | 'src_address': src_addr, |
| 374 | 'dst_address': dst_addr, |
| 375 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 376 | 'encap_vrf_id': encap_vrf_id, |
| 377 | 'decap_next_index': decap_next_index, |
| 378 | 'vni': vni}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 379 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 380 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 381 | learn=1, arp_term=0, is_add=1): |
| 382 | """Create/delete bridge domain. |
| 383 | |
| 384 | :param int bd_id: Bridge domain index. |
| 385 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 386 | (Default value = 1) |
| 387 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 388 | (Default value = 1) |
| 389 | :param int forward: Enable/disable forwarding on all interfaces in |
| 390 | the BD. (Default value = 1) |
| 391 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 392 | (Default value = 1) |
| 393 | :param int arp_term: Enable/disable arp termination in the BD. |
| 394 | (Default value = 1) |
| 395 | :param int is_add: Add or delete flag. (Default value = 1) |
| 396 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 397 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 398 | {'bd_id': bd_id, |
| 399 | 'flood': flood, |
| 400 | 'uu_flood': uu_flood, |
| 401 | 'forward': forward, |
| 402 | 'learn': learn, |
| 403 | 'arp_term': arp_term, |
| 404 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 405 | |
| 406 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 407 | filter_mac=0, bvi_mac=0): |
| 408 | """Create/delete L2 FIB entry. |
| 409 | |
| 410 | :param str mac: MAC address to create FIB entry for. |
| 411 | :param int bd_id: Bridge domain index. |
| 412 | :param int sw_if_index: Software interface index of the interface. |
| 413 | :param int is_add: Add or delete flag. (Default value = 1) |
| 414 | :param int static_mac: Set to 1 to create static MAC entry. |
| 415 | (Default value = 0) |
| 416 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 417 | destination MAC address contains defined MAC address. |
| 418 | (Default value = 0) |
| 419 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 420 | interface. (Default value = 0) |
| 421 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 422 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 423 | {'mac': self._convert_mac(mac), |
| 424 | 'bd_id': bd_id, |
| 425 | 'sw_if_index': sw_if_index, |
| 426 | 'is_add': is_add, |
| 427 | 'static_mac': static_mac, |
| 428 | 'filter_mac': filter_mac, |
| 429 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 430 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 431 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 432 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 433 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 434 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 435 | :param int sw_if_index: Software interface index of the interface. |
| 436 | :param int bd_id: Bridge domain index. |
| 437 | :param int shg: Split-horizon group index. (Default value = 0) |
| 438 | :param int bvi: Set interface as a bridge group virtual interface. |
| 439 | (Default value = 0) |
| 440 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 441 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 442 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 443 | {'rx_sw_if_index': sw_if_index, |
| 444 | 'bd_id': bd_id, |
| 445 | 'shg': shg, |
| 446 | 'bvi': bvi, |
| 447 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 448 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 449 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 450 | """Enable/disable required feature of the bridge domain with defined ID. |
| 451 | |
| 452 | :param int bd_id: Bridge domain ID. |
| 453 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 454 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 455 | - learn (1 << 0), |
| 456 | - forward (1 << 1), |
| 457 | - flood (1 << 2), |
| 458 | - uu-flood (1 << 3) or |
| 459 | - arp-term (1 << 4). |
| 460 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 461 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 462 | {'bd_id': bd_id, |
| 463 | 'is_set': is_set, |
| 464 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 465 | |
| 466 | def bridge_domain_dump(self, bd_id=0): |
| 467 | """ |
| 468 | |
| 469 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 470 | existing bridge domains returned) |
| 471 | :return: Dictionary of bridge domain(s) data. |
| 472 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 473 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 474 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 475 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 476 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 477 | enable): |
| 478 | """Create or delete unidirectional cross-connect from Tx interface to |
| 479 | Rx interface. |
| 480 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 481 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 482 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 483 | :param int enable: Create cross-connect if equal to 1, delete |
| 484 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 485 | |
| 486 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 487 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 488 | {'rx_sw_if_index': rx_sw_if_index, |
| 489 | 'tx_sw_if_index': tx_sw_if_index, |
| 490 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 491 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 492 | def sw_interface_set_l2_tag_rewrite( |
| 493 | self, |
| 494 | sw_if_index, |
| 495 | vtr_oper, |
| 496 | push=0, |
| 497 | tag1=0, |
| 498 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 499 | """L2 interface vlan tag rewrite configure request |
| 500 | :param client_index - opaque cookie to identify the sender |
| 501 | :param context - sender context, to match reply w/ request |
| 502 | :param sw_if_index - interface the operation is applied to |
| 503 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 504 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 505 | :param tag1 - Needed for any push or translate vtr op |
| 506 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 507 | |
| 508 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 509 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 510 | {'sw_if_index': sw_if_index, |
| 511 | 'vtr_op': vtr_oper, |
| 512 | 'push_dot1q': push, |
| 513 | 'tag1': tag1, |
| 514 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 515 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 516 | def sw_interface_set_flags(self, sw_if_index, admin_up_down, |
| 517 | link_up_down=0, deleted=0): |
| 518 | """ |
| 519 | |
| 520 | :param admin_up_down: |
| 521 | :param sw_if_index: |
| 522 | :param link_up_down: (Default value = 0) |
| 523 | :param deleted: (Default value = 0) |
| 524 | |
| 525 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 526 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 527 | {'sw_if_index': sw_if_index, |
| 528 | 'admin_up_down': admin_up_down, |
| 529 | 'link_up_down': link_up_down, |
| 530 | 'deleted': deleted}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 531 | |
| 532 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 533 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 534 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 535 | """Create subinterface |
| 536 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 537 | |
| 538 | :param sub_id: param inner_vlan: |
| 539 | :param sw_if_index: |
| 540 | :param outer_vlan: |
| 541 | :param inner_vlan: |
| 542 | :param no_tags: (Default value = 0) |
| 543 | :param one_tag: (Default value = 0) |
| 544 | :param two_tags: (Default value = 0) |
| 545 | :param dot1ad: (Default value = 0) |
| 546 | :param exact_match: (Default value = 0) |
| 547 | :param default_sub: (Default value = 0) |
| 548 | :param outer_vlan_id_any: (Default value = 0) |
| 549 | :param inner_vlan_id_any: (Default value = 0) |
| 550 | |
| 551 | """ |
| 552 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 553 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 554 | {'sw_if_index': sw_if_index, |
| 555 | 'sub_id': sub_id, |
| 556 | 'no_tags': no_tags, |
| 557 | 'one_tag': one_tag, |
| 558 | 'two_tags': two_tags, |
| 559 | 'dot1ad': dot1ad, |
| 560 | 'exact_match': exact_match, |
| 561 | 'default_sub': default_sub, |
| 562 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 563 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 564 | 'outer_vlan_id': outer_vlan, |
| 565 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 566 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 567 | def delete_subif(self, sw_if_index): |
| 568 | """Delete subinterface |
| 569 | |
| 570 | :param sw_if_index: |
| 571 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 572 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 573 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 574 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 575 | def create_vlan_subif(self, sw_if_index, vlan): |
| 576 | """ |
| 577 | |
| 578 | :param vlan: |
| 579 | :param sw_if_index: |
| 580 | |
| 581 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 582 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 583 | {'sw_if_index': sw_if_index, |
| 584 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 585 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 586 | def create_loopback(self, mac=''): |
| 587 | """ |
| 588 | |
| 589 | :param mac: (Optional) |
| 590 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 591 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 592 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 593 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 594 | def delete_loopback(self, sw_if_index): |
| 595 | return self.api(self.papi.delete_loopback, |
| 596 | {'sw_if_index': sw_if_index, }) |
| 597 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 598 | def ip_add_del_route( |
| 599 | self, |
| 600 | dst_address, |
| 601 | dst_address_length, |
| 602 | next_hop_address, |
| 603 | next_hop_sw_if_index=0xFFFFFFFF, |
| 604 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 605 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 606 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 607 | next_hop_n_out_labels=0, |
| 608 | next_hop_out_label_stack=[], |
| 609 | next_hop_via_label=MPLS_LABEL_INVALID, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 610 | create_vrf_if_needed=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 611 | is_resolve_host=0, |
| 612 | is_resolve_attached=0, |
| 613 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 614 | is_add=1, |
| 615 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 616 | is_unreach=0, |
| 617 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 618 | is_ipv6=0, |
| 619 | is_local=0, |
| 620 | is_classify=0, |
| 621 | is_multipath=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 622 | not_last=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 623 | """ |
| 624 | |
| 625 | :param dst_address_length: |
| 626 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 627 | :param dst_address: |
| 628 | :param next_hop_address: |
| 629 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 630 | :param vrf_id: (Default value = 0) |
| 631 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 632 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 633 | :param create_vrf_if_needed: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 634 | :param is_add: (Default value = 1) |
| 635 | :param is_drop: (Default value = 0) |
| 636 | :param is_ipv6: (Default value = 0) |
| 637 | :param is_local: (Default value = 0) |
| 638 | :param is_classify: (Default value = 0) |
| 639 | :param is_multipath: (Default value = 0) |
| 640 | :param is_resolve_host: (Default value = 0) |
| 641 | :param is_resolve_attached: (Default value = 0) |
| 642 | :param not_last: (Default value = 0) |
| 643 | :param next_hop_weight: (Default value = 1) |
| 644 | |
| 645 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 646 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 647 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 648 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 649 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 650 | 'table_id': table_id, |
| 651 | 'classify_table_index': classify_table_index, |
| 652 | 'next_hop_table_id': next_hop_table_id, |
| 653 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 654 | 'is_add': is_add, |
| 655 | 'is_drop': is_drop, |
| 656 | 'is_unreach': is_unreach, |
| 657 | 'is_prohibit': is_prohibit, |
| 658 | 'is_ipv6': is_ipv6, |
| 659 | 'is_local': is_local, |
| 660 | 'is_classify': is_classify, |
| 661 | 'is_multipath': is_multipath, |
| 662 | 'is_resolve_host': is_resolve_host, |
| 663 | 'is_resolve_attached': is_resolve_attached, |
| 664 | 'not_last': not_last, |
| 665 | 'next_hop_weight': next_hop_weight, |
| 666 | 'dst_address_length': dst_address_length, |
| 667 | 'dst_address': dst_address, |
| 668 | 'next_hop_address': next_hop_address, |
| 669 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 670 | 'next_hop_via_label': next_hop_via_label, |
| 671 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 672 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 673 | def ip_fib_dump(self): |
| 674 | return self.api(self.papi.ip_fib_dump, {}) |
| 675 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 676 | def ip6_fib_dump(self): |
| 677 | return self.api(self.papi.ip6_fib_dump, {}) |
| 678 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 679 | def ip_neighbor_add_del(self, |
| 680 | sw_if_index, |
| 681 | mac_address, |
| 682 | dst_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 683 | is_add=1, |
| 684 | is_ipv6=0, |
| 685 | is_static=0, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 686 | is_no_adj_fib=0, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 687 | ): |
| 688 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 689 | |
| 690 | :param sw_if_index: |
| 691 | :param mac_address: |
| 692 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 693 | :param is_add: (Default value = 1) |
| 694 | :param is_ipv6: (Default value = 0) |
| 695 | :param is_static: (Default value = 0) |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 696 | :param is_no_adj_fib: (Default value = 0) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 697 | """ |
| 698 | |
| 699 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 700 | self.papi.ip_neighbor_add_del, |
Neale Ranns | baf2e90 | 2017-02-25 04:20:00 -0800 | [diff] [blame] | 701 | {'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 702 | 'is_add': is_add, |
| 703 | 'is_ipv6': is_ipv6, |
| 704 | 'is_static': is_static, |
Neale Ranns | b3b2de7 | 2017-03-08 05:17:22 -0800 | [diff] [blame] | 705 | 'is_no_adj_fib': is_no_adj_fib, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 706 | 'mac_address': mac_address, |
| 707 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 708 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 709 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 710 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 711 | def ip_neighbor_dump(self, |
| 712 | sw_if_index, |
| 713 | is_ipv6=0): |
| 714 | """ Return IP neighbor dump. |
| 715 | |
| 716 | :param sw_if_index: |
| 717 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 718 | """ |
| 719 | |
| 720 | return self.api( |
| 721 | self.papi.ip_neighbor_dump, |
| 722 | {'is_ipv6': is_ipv6, |
| 723 | 'sw_if_index': sw_if_index |
| 724 | } |
| 725 | ) |
| 726 | |
| 727 | def proxy_arp_add_del(self, |
| 728 | low_address, |
| 729 | hi_address, |
| 730 | vrf_id=0, |
| 731 | is_add=1): |
| 732 | """ Config Proxy Arp Range. |
| 733 | |
| 734 | :param low_address: Start address in the rnage to Proxy for |
| 735 | :param hi_address: End address in the rnage to Proxy for |
| 736 | :param vrf_id: The VRF/table in which to proxy |
| 737 | """ |
| 738 | |
| 739 | return self.api( |
| 740 | self.papi.proxy_arp_add_del, |
| 741 | {'vrf_id': vrf_id, |
| 742 | 'is_add': is_add, |
| 743 | 'low_address': low_address, |
| 744 | 'hi_address': hi_address, |
| 745 | } |
| 746 | ) |
| 747 | |
| 748 | def proxy_arp_intfc_enable_disable(self, |
| 749 | sw_if_index, |
| 750 | is_enable=1): |
| 751 | """ Enable/Disable an interface for proxy ARP requests |
| 752 | |
| 753 | :param sw_if_index: Interface |
| 754 | :param enable_disable: Enable/Disable |
| 755 | """ |
| 756 | |
| 757 | return self.api( |
| 758 | self.papi.proxy_arp_intfc_enable_disable, |
| 759 | {'sw_if_index': sw_if_index, |
| 760 | 'enable_disable': is_enable |
| 761 | } |
| 762 | ) |
| 763 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 764 | def reset_vrf(self, |
| 765 | vrf_id, |
| 766 | is_ipv6=0, |
| 767 | ): |
| 768 | """ Reset VRF (remove all routes etc.) request. |
| 769 | |
| 770 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 771 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 772 | """ |
| 773 | |
| 774 | return self.api( |
| 775 | self.papi.reset_vrf, |
| 776 | {'vrf_id': vrf_id, |
| 777 | 'is_ipv6': is_ipv6, |
| 778 | } |
| 779 | ) |
| 780 | |
| 781 | def reset_fib(self, |
| 782 | vrf_id, |
| 783 | is_ipv6=0, |
| 784 | ): |
| 785 | """ Reset VRF (remove all routes etc.) request. |
| 786 | |
| 787 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 788 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 789 | """ |
| 790 | |
| 791 | return self.api( |
| 792 | self.papi.reset_fib, |
| 793 | {'vrf_id': vrf_id, |
| 794 | 'is_ipv6': is_ipv6, |
| 795 | } |
| 796 | ) |
| 797 | |
| 798 | def ip_dump(self, |
| 799 | is_ipv6=0, |
| 800 | ): |
| 801 | """ Return IP dump. |
| 802 | |
| 803 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 804 | """ |
| 805 | |
| 806 | return self.api( |
| 807 | self.papi.ip_dump, |
| 808 | {'is_ipv6': is_ipv6, |
| 809 | } |
| 810 | ) |
| 811 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 812 | def sw_interface_span_enable_disable( |
Ole Troan | 399ca1c | 2016-12-06 23:00:38 +0100 | [diff] [blame] | 813 | self, sw_if_index_from, sw_if_index_to, state=1): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 814 | """ |
| 815 | |
| 816 | :param sw_if_index_from: |
| 817 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 818 | :param state: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 819 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 820 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 821 | {'sw_if_index_from': sw_if_index_from, |
| 822 | 'sw_if_index_to': sw_if_index_to, |
| 823 | 'state': state}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 824 | |
| 825 | def gre_tunnel_add_del(self, |
| 826 | src_address, |
| 827 | dst_address, |
| 828 | outer_fib_id=0, |
| 829 | is_teb=0, |
| 830 | is_add=1, |
| 831 | is_ip6=0): |
| 832 | """ Add a GRE tunnel |
| 833 | |
| 834 | :param src_address: |
| 835 | :param dst_address: |
| 836 | :param outer_fib_id: (Default value = 0) |
| 837 | :param is_add: (Default value = 1) |
| 838 | :param is_ipv6: (Default value = 0) |
| 839 | :param is_teb: (Default value = 0) |
| 840 | """ |
| 841 | |
| 842 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 843 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 844 | {'is_add': is_add, |
| 845 | 'is_ipv6': is_ip6, |
| 846 | 'teb': is_teb, |
| 847 | 'src_address': src_address, |
| 848 | 'dst_address': dst_address, |
| 849 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 850 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 851 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 852 | def mpls_fib_dump(self): |
| 853 | return self.api(self.papi.mpls_fib_dump, {}) |
| 854 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 855 | def mpls_route_add_del( |
| 856 | self, |
| 857 | label, |
| 858 | eos, |
| 859 | next_hop_proto_is_ip4, |
| 860 | next_hop_address, |
| 861 | next_hop_sw_if_index=0xFFFFFFFF, |
| 862 | table_id=0, |
| 863 | next_hop_table_id=0, |
| 864 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 865 | next_hop_n_out_labels=0, |
| 866 | next_hop_out_label_stack=[], |
| 867 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 868 | create_vrf_if_needed=0, |
| 869 | is_resolve_host=0, |
| 870 | is_resolve_attached=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 871 | is_interface_rx=0, |
| 872 | is_rpf_id=0, |
| 873 | is_multicast=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 874 | is_add=1, |
| 875 | is_drop=0, |
| 876 | is_multipath=0, |
| 877 | classify_table_index=0xFFFFFFFF, |
| 878 | is_classify=0, |
| 879 | not_last=0): |
| 880 | """ |
| 881 | |
| 882 | :param dst_address_length: |
| 883 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 884 | :param dst_address: |
| 885 | :param next_hop_address: |
| 886 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 887 | :param vrf_id: (Default value = 0) |
| 888 | :param lookup_in_vrf: (Default value = 0) |
| 889 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 890 | :param create_vrf_if_needed: (Default value = 0) |
| 891 | :param is_add: (Default value = 1) |
| 892 | :param is_drop: (Default value = 0) |
| 893 | :param is_ipv6: (Default value = 0) |
| 894 | :param is_local: (Default value = 0) |
| 895 | :param is_classify: (Default value = 0) |
| 896 | :param is_multipath: (Default value = 0) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 897 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 898 | :param is_resolve_host: (Default value = 0) |
| 899 | :param is_resolve_attached: (Default value = 0) |
| 900 | :param not_last: (Default value = 0) |
| 901 | :param next_hop_weight: (Default value = 1) |
| 902 | |
| 903 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 904 | |
| 905 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 906 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 907 | {'mr_label': label, |
| 908 | 'mr_eos': eos, |
| 909 | 'mr_table_id': table_id, |
| 910 | 'mr_classify_table_index': classify_table_index, |
| 911 | 'mr_create_table_if_needed': create_vrf_if_needed, |
| 912 | 'mr_is_add': is_add, |
| 913 | 'mr_is_classify': is_classify, |
| 914 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 915 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 916 | 'mr_is_resolve_host': is_resolve_host, |
| 917 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 918 | 'mr_is_interface_rx': is_interface_rx, |
| 919 | 'mr_is_rpf_id': is_rpf_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 920 | 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 921 | 'mr_next_hop_weight': next_hop_weight, |
| 922 | 'mr_next_hop': next_hop_address, |
| 923 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 924 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 925 | 'mr_next_hop_table_id': next_hop_table_id, |
| 926 | 'mr_next_hop_via_label': next_hop_via_label, |
| 927 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 928 | |
| 929 | def mpls_ip_bind_unbind( |
| 930 | self, |
| 931 | label, |
| 932 | dst_address, |
| 933 | dst_address_length, |
| 934 | table_id=0, |
| 935 | ip_table_id=0, |
| 936 | is_ip4=1, |
| 937 | create_vrf_if_needed=0, |
| 938 | is_bind=1): |
| 939 | """ |
| 940 | """ |
| 941 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 942 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 943 | {'mb_mpls_table_id': table_id, |
| 944 | 'mb_label': label, |
| 945 | 'mb_ip_table_id': ip_table_id, |
| 946 | 'mb_create_table_if_needed': create_vrf_if_needed, |
| 947 | 'mb_is_bind': is_bind, |
| 948 | 'mb_is_ip4': is_ip4, |
| 949 | 'mb_address_length': dst_address_length, |
| 950 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 951 | |
| 952 | def mpls_tunnel_add_del( |
| 953 | self, |
| 954 | tun_sw_if_index, |
| 955 | next_hop_proto_is_ip4, |
| 956 | next_hop_address, |
| 957 | next_hop_sw_if_index=0xFFFFFFFF, |
| 958 | next_hop_table_id=0, |
| 959 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 960 | next_hop_n_out_labels=0, |
| 961 | next_hop_out_label_stack=[], |
| 962 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 963 | create_vrf_if_needed=0, |
| 964 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 965 | l2_only=0, |
| 966 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 967 | """ |
| 968 | |
| 969 | :param dst_address_length: |
| 970 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 971 | :param dst_address: |
| 972 | :param next_hop_address: |
| 973 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 974 | :param vrf_id: (Default value = 0) |
| 975 | :param lookup_in_vrf: (Default value = 0) |
| 976 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 977 | :param create_vrf_if_needed: (Default value = 0) |
| 978 | :param is_add: (Default value = 1) |
| 979 | :param is_drop: (Default value = 0) |
| 980 | :param is_ipv6: (Default value = 0) |
| 981 | :param is_local: (Default value = 0) |
| 982 | :param is_classify: (Default value = 0) |
| 983 | :param is_multipath: (Default value = 0) |
| 984 | :param is_resolve_host: (Default value = 0) |
| 985 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 986 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 987 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 988 | |
| 989 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 990 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 991 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 992 | {'mt_sw_if_index': tun_sw_if_index, |
| 993 | 'mt_is_add': is_add, |
| 994 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 995 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 996 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 997 | 'mt_next_hop_weight': next_hop_weight, |
| 998 | 'mt_next_hop': next_hop_address, |
| 999 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1000 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1001 | 'mt_next_hop_table_id': next_hop_table_id, |
| 1002 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1003 | |
| 1004 | def snat_interface_add_del_feature( |
| 1005 | self, |
| 1006 | sw_if_index, |
| 1007 | is_inside=1, |
| 1008 | is_add=1): |
| 1009 | """Enable/disable S-NAT feature on the interface |
| 1010 | |
| 1011 | :param sw_if_index: Software index of the interface |
| 1012 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1013 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1014 | """ |
| 1015 | return self.api( |
| 1016 | self.papi.snat_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1017 | {'is_add': is_add, |
| 1018 | 'is_inside': is_inside, |
| 1019 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1020 | |
| 1021 | def snat_add_static_mapping( |
| 1022 | self, |
| 1023 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1024 | external_ip=0, |
| 1025 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1026 | local_port=0, |
| 1027 | external_port=0, |
| 1028 | addr_only=1, |
| 1029 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1030 | protocol=0, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1031 | is_add=1, |
| 1032 | is_ip4=1): |
| 1033 | """Add/delete S-NAT static mapping |
| 1034 | |
| 1035 | :param local_ip: Local IP address |
| 1036 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1037 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1038 | :param local_port: Local port number (Default value = 0) |
| 1039 | :param external_port: External port number (Default value = 0) |
| 1040 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1041 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1042 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1043 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1044 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1045 | """ |
| 1046 | return self.api( |
| 1047 | self.papi.snat_add_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1048 | {'is_add': is_add, |
| 1049 | 'is_ip4': is_ip4, |
| 1050 | 'addr_only': addr_only, |
| 1051 | 'local_ip_address': local_ip, |
| 1052 | 'external_ip_address': external_ip, |
| 1053 | 'local_port': local_port, |
| 1054 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1055 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1056 | 'vrf_id': vrf_id, |
| 1057 | 'protocol': protocol}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1058 | |
| 1059 | def snat_add_address_range( |
| 1060 | self, |
| 1061 | first_ip_address, |
| 1062 | last_ip_address, |
| 1063 | is_add=1, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1064 | is_ip4=1, |
| 1065 | vrf_id=0xFFFFFFFF): |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1066 | """Add/del S-NAT address range |
| 1067 | |
| 1068 | :param first_ip_address: First IP address |
| 1069 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1070 | :param vrf_id: VRF id for the address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1071 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1072 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1073 | """ |
| 1074 | return self.api( |
| 1075 | self.papi.snat_add_address_range, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1076 | {'is_ip4': is_ip4, |
| 1077 | 'first_ip_address': first_ip_address, |
| 1078 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1079 | 'vrf_id': vrf_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1080 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1081 | |
| 1082 | def snat_address_dump(self): |
| 1083 | """Dump S-NAT addresses |
| 1084 | :return: Dictionary of S-NAT addresses |
| 1085 | """ |
| 1086 | return self.api(self.papi.snat_address_dump, {}) |
| 1087 | |
| 1088 | def snat_interface_dump(self): |
| 1089 | """Dump interfaces with S-NAT feature |
| 1090 | :return: Dictionary of interfaces with S-NAT feature |
| 1091 | """ |
| 1092 | return self.api(self.papi.snat_interface_dump, {}) |
| 1093 | |
| 1094 | def snat_static_mapping_dump(self): |
| 1095 | """Dump S-NAT static mappings |
| 1096 | :return: Dictionary of S-NAT static mappings |
| 1097 | """ |
| 1098 | return self.api(self.papi.snat_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1099 | |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1100 | def snat_show_config(self): |
| 1101 | """Show S-NAT config |
| 1102 | :return: S-NAT config parameters |
| 1103 | """ |
| 1104 | return self.api(self.papi.snat_show_config, {}) |
| 1105 | |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1106 | def snat_add_interface_addr( |
| 1107 | self, |
| 1108 | sw_if_index, |
| 1109 | is_add=1): |
| 1110 | """Add/del S-NAT address from interface |
| 1111 | |
| 1112 | :param sw_if_index: Software index of the interface |
| 1113 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1114 | """ |
| 1115 | return self.api(self.papi.snat_add_del_interface_addr, |
| 1116 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1117 | |
| 1118 | def snat_interface_addr_dump(self): |
| 1119 | """Dump S-NAT addresses interfaces |
| 1120 | :return: Dictionary of S-NAT addresses interfaces |
| 1121 | """ |
| 1122 | return self.api(self.papi.snat_interface_addr_dump, {}) |
| 1123 | |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1124 | def snat_ipfix( |
| 1125 | self, |
| 1126 | domain_id=1, |
| 1127 | src_port=4739, |
| 1128 | enable=1): |
| 1129 | """Enable/disable S-NAT IPFIX logging |
| 1130 | |
| 1131 | :param domain_id: Observation domain ID (Default value = 1) |
| 1132 | :param src_port: Source port number (Default value = 4739) |
| 1133 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1134 | """ |
| 1135 | return self.api( |
| 1136 | self.papi.snat_ipfix_enable_disable, |
| 1137 | {'domain_id': domain_id, |
| 1138 | 'src_port': src_port, |
| 1139 | 'enable': enable}) |
| 1140 | |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1141 | def snat_user_session_dump( |
| 1142 | self, |
| 1143 | ip_address, |
Martin | 6b7fcda | 2017-03-08 03:31:02 -0800 | [diff] [blame] | 1144 | vrf_id, |
| 1145 | is_ip4=1): |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1146 | """Dump S-NAT user's sessions |
| 1147 | |
| 1148 | :param ip_address: ip adress of the user to be dumped |
| 1149 | :param cpu_index: cpu_index on which the user is |
| 1150 | :param vrf_id: VRF ID |
| 1151 | :return: Dictionary of S-NAT sessions |
| 1152 | """ |
| 1153 | return self.api( |
| 1154 | self.papi.snat_user_session_dump, |
| 1155 | {'ip_address': ip_address, |
Martin | 6b7fcda | 2017-03-08 03:31:02 -0800 | [diff] [blame] | 1156 | 'vrf_id': vrf_id, |
| 1157 | 'is_ip4': is_ip4}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1158 | |
| 1159 | def snat_user_dump(self): |
| 1160 | """Dump S-NAT users |
| 1161 | |
| 1162 | :return: Dictionary of S-NAT users |
| 1163 | """ |
| 1164 | return self.api(self.papi.snat_user_dump, {}) |
| 1165 | |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1166 | def snat_add_det_map( |
| 1167 | self, |
| 1168 | in_addr, |
| 1169 | in_plen, |
| 1170 | out_addr, |
| 1171 | out_plen, |
| 1172 | is_add=1): |
| 1173 | """Add/delete S-NAT deterministic mapping |
| 1174 | |
| 1175 | :param is_add - 1 if add, 0 if delete |
| 1176 | :param in_addr - inside IP address |
| 1177 | :param in_plen - inside IP address prefix length |
| 1178 | :param out_addr - outside IP address |
| 1179 | :param out_plen - outside IP address prefix length |
| 1180 | """ |
| 1181 | return self.api( |
| 1182 | self.papi.snat_add_det_map, |
| 1183 | {'is_add': is_add, |
| 1184 | 'in_addr': in_addr, |
| 1185 | 'in_plen': in_plen, |
| 1186 | 'out_addr': out_addr, |
| 1187 | 'out_plen': out_plen}) |
| 1188 | |
| 1189 | def snat_det_forward( |
| 1190 | self, |
| 1191 | in_addr): |
| 1192 | """Get outside address and port range from inside address |
| 1193 | |
| 1194 | :param in_addr - inside IP address |
| 1195 | """ |
| 1196 | return self.api( |
| 1197 | self.papi.snat_det_forward, |
| 1198 | {'in_addr': in_addr}) |
| 1199 | |
| 1200 | def snat_det_reverse( |
| 1201 | self, |
| 1202 | out_addr, |
| 1203 | out_port): |
| 1204 | """Get inside address from outside address and port |
| 1205 | |
| 1206 | :param out_addr - outside IP address |
| 1207 | :param out_port - outside port |
| 1208 | """ |
| 1209 | return self.api( |
| 1210 | self.papi.snat_det_reverse, |
| 1211 | {'out_addr': out_addr, |
| 1212 | 'out_port': out_port}) |
| 1213 | |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1214 | def snat_det_map_dump(self): |
| 1215 | """Dump S-NAT deterministic mappings |
| 1216 | |
| 1217 | :return: Dictionary of S-NAT deterministic mappings |
| 1218 | """ |
| 1219 | return self.api(self.papi.snat_det_map_dump, {}) |
| 1220 | |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1221 | def snat_det_set_timeouts( |
| 1222 | self, |
| 1223 | udp=300, |
| 1224 | tcp_established=7440, |
| 1225 | tcp_transitory=240, |
| 1226 | icmp=60): |
| 1227 | """Set values of timeouts for deterministic NAT (in seconds) |
| 1228 | |
| 1229 | :param udp - UDP timeout (Default value = 300) |
| 1230 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1231 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1232 | :param icmp - ICMP timeout (Default value = 60) |
| 1233 | """ |
| 1234 | return self.api( |
| 1235 | self.papi.snat_det_set_timeouts, |
| 1236 | {'udp': udp, |
| 1237 | 'tcp_established': tcp_established, |
| 1238 | 'tcp_transitory': tcp_transitory, |
| 1239 | 'icmp': icmp}) |
| 1240 | |
| 1241 | def snat_det_get_timeouts(self): |
| 1242 | """Get values of timeouts for deterministic NAT |
| 1243 | |
| 1244 | :return: Timeouts for deterministic NAT (in seconds) |
| 1245 | """ |
| 1246 | return self.api(self.papi.snat_det_get_timeouts, {}) |
| 1247 | |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1248 | def snat_det_close_session_out( |
| 1249 | self, |
| 1250 | out_addr, |
| 1251 | out_port, |
| 1252 | ext_addr, |
| 1253 | ext_port, |
| 1254 | is_ip4=1): |
| 1255 | """Close CGN session using outside address and port |
| 1256 | |
| 1257 | :param out_addr - outside IP address |
| 1258 | :param out_port - outside port |
| 1259 | :param ext_addr - external host IP address |
| 1260 | :param ext_port - external host port |
| 1261 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1262 | """ |
| 1263 | return self.api( |
| 1264 | self.papi.snat_det_close_session_out, |
| 1265 | {'out_addr': out_addr, |
| 1266 | 'out_port': out_port, |
| 1267 | 'ext_addr': ext_addr, |
| 1268 | 'ext_port': ext_port, |
| 1269 | 'is_ip4': is_ip4}) |
| 1270 | |
| 1271 | def snat_det_close_session_in( |
| 1272 | self, |
| 1273 | in_addr, |
| 1274 | in_port, |
| 1275 | ext_addr, |
| 1276 | ext_port, |
| 1277 | is_ip4=1): |
| 1278 | """Close CGN session using inside address and port |
| 1279 | |
| 1280 | :param in_addr - inside IP address |
| 1281 | :param in_port - inside port |
| 1282 | :param ext_addr - external host IP address |
| 1283 | :param ext_port - external host port |
| 1284 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1285 | """ |
| 1286 | return self.api( |
| 1287 | self.papi.snat_det_close_session_in, |
| 1288 | {'in_addr': in_addr, |
| 1289 | 'in_port': in_port, |
| 1290 | 'ext_addr': ext_addr, |
| 1291 | 'ext_port': ext_port, |
| 1292 | 'is_ip4': is_ip4}) |
| 1293 | |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1294 | def snat_det_session_dump( |
| 1295 | self, |
| 1296 | user_addr, |
| 1297 | is_ip4=1): |
| 1298 | """Dump S-NAT deterministic sessions belonging to a user |
| 1299 | |
| 1300 | :param user_addr - inside IP address of the user |
| 1301 | :param is_ip4: - 1 if address type is IPv4 (Default value = 1) |
| 1302 | :return: Dictionary of S-NAT deterministic sessions |
| 1303 | """ |
| 1304 | return self.api( |
| 1305 | self.papi.snat_det_session_dump, |
| 1306 | {'is_ip4': is_ip4, |
| 1307 | 'user_addr': user_addr}) |
| 1308 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1309 | def control_ping(self): |
| 1310 | self.api(self.papi.control_ping) |
| 1311 | |
| 1312 | 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] | 1313 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1314 | bfd_key_id=None, conf_key_id=None): |
| 1315 | if bfd_key_id is None: |
| 1316 | return self.api(self.papi.bfd_udp_add, |
| 1317 | { |
| 1318 | 'sw_if_index': sw_if_index, |
| 1319 | 'desired_min_tx': desired_min_tx, |
| 1320 | 'required_min_rx': required_min_rx, |
| 1321 | 'local_addr': local_addr, |
| 1322 | 'peer_addr': peer_addr, |
| 1323 | 'is_ipv6': is_ipv6, |
| 1324 | 'detect_mult': detect_mult, |
| 1325 | }) |
| 1326 | else: |
| 1327 | return self.api(self.papi.bfd_udp_add, |
| 1328 | { |
| 1329 | 'sw_if_index': sw_if_index, |
| 1330 | 'desired_min_tx': desired_min_tx, |
| 1331 | 'required_min_rx': required_min_rx, |
| 1332 | 'local_addr': local_addr, |
| 1333 | 'peer_addr': peer_addr, |
| 1334 | 'is_ipv6': is_ipv6, |
| 1335 | 'detect_mult': detect_mult, |
| 1336 | 'is_authenticated': 1, |
| 1337 | 'bfd_key_id': bfd_key_id, |
| 1338 | 'conf_key_id': conf_key_id, |
| 1339 | }) |
| 1340 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1341 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1342 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1343 | return self.api(self.papi.bfd_udp_mod, |
| 1344 | { |
| 1345 | 'sw_if_index': sw_if_index, |
| 1346 | 'desired_min_tx': desired_min_tx, |
| 1347 | 'required_min_rx': required_min_rx, |
| 1348 | 'local_addr': local_addr, |
| 1349 | 'peer_addr': peer_addr, |
| 1350 | 'is_ipv6': is_ipv6, |
| 1351 | 'detect_mult': detect_mult, |
| 1352 | }) |
| 1353 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1354 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1355 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1356 | is_delayed=False): |
| 1357 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1358 | { |
| 1359 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1360 | 'local_addr': local_addr, |
| 1361 | 'peer_addr': peer_addr, |
| 1362 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1363 | 'is_delayed': 1 if is_delayed else 0, |
| 1364 | 'bfd_key_id': bfd_key_id, |
| 1365 | 'conf_key_id': conf_key_id, |
| 1366 | }) |
| 1367 | |
| 1368 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1369 | is_ipv6=0, is_delayed=False): |
| 1370 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1371 | { |
| 1372 | 'sw_if_index': sw_if_index, |
| 1373 | 'local_addr': local_addr, |
| 1374 | 'peer_addr': peer_addr, |
| 1375 | 'is_ipv6': is_ipv6, |
| 1376 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1377 | }) |
| 1378 | |
| 1379 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1380 | return self.api(self.papi.bfd_udp_del, |
| 1381 | { |
| 1382 | 'sw_if_index': sw_if_index, |
| 1383 | 'local_addr': local_addr, |
| 1384 | 'peer_addr': peer_addr, |
| 1385 | 'is_ipv6': is_ipv6, |
| 1386 | }) |
| 1387 | |
| 1388 | def bfd_udp_session_dump(self): |
| 1389 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1390 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1391 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1392 | peer_addr, is_ipv6=0): |
| 1393 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1394 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1395 | 'sw_if_index': sw_if_index, |
| 1396 | 'local_addr': local_addr, |
| 1397 | 'peer_addr': peer_addr, |
| 1398 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1399 | }) |
| 1400 | |
| 1401 | def want_bfd_events(self, enable_disable=1): |
| 1402 | return self.api(self.papi.want_bfd_events, { |
| 1403 | 'enable_disable': enable_disable, |
| 1404 | 'pid': os.getpid(), |
| 1405 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1406 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1407 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1408 | return self.api(self.papi.bfd_auth_set_key, { |
| 1409 | 'conf_key_id': conf_key_id, |
| 1410 | 'auth_type': auth_type, |
| 1411 | 'key': key, |
| 1412 | 'key_len': len(key), |
| 1413 | }) |
| 1414 | |
| 1415 | def bfd_auth_del_key(self, conf_key_id): |
| 1416 | return self.api(self.papi.bfd_auth_del_key, { |
| 1417 | 'conf_key_id': conf_key_id, |
| 1418 | }) |
| 1419 | |
| 1420 | def bfd_auth_keys_dump(self): |
| 1421 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1422 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1423 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 1424 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 1425 | {'sw_if_index': sw_if_index}) |
| 1426 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1427 | def bfd_udp_del_echo_source(self): |
| 1428 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 1429 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1430 | def classify_add_del_table( |
| 1431 | self, |
| 1432 | is_add, |
| 1433 | mask, |
| 1434 | match_n_vectors=1, |
| 1435 | table_index=0xFFFFFFFF, |
| 1436 | nbuckets=2, |
| 1437 | memory_size=2097152, |
| 1438 | skip_n_vectors=0, |
| 1439 | next_table_index=0xFFFFFFFF, |
| 1440 | miss_next_index=0xFFFFFFFF, |
| 1441 | current_data_flag=0, |
| 1442 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1443 | """ |
| 1444 | :param is_add: |
| 1445 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1446 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1447 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1448 | :param nbuckets: (Default value = 2) |
| 1449 | :param memory_size: (Default value = 2097152) |
| 1450 | :param skip_n_vectors: (Default value = 0) |
| 1451 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1452 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1453 | :param current_data_flag: (Default value = 0) |
| 1454 | :param current_data_offset: (Default value = 0) |
| 1455 | """ |
| 1456 | |
| 1457 | return self.api( |
| 1458 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1459 | {'is_add': is_add, |
| 1460 | 'table_index': table_index, |
| 1461 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1462 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1463 | 'skip_n_vectors': skip_n_vectors, |
| 1464 | 'match_n_vectors': match_n_vectors, |
| 1465 | 'next_table_index': next_table_index, |
| 1466 | 'miss_next_index': miss_next_index, |
| 1467 | 'current_data_flag': current_data_flag, |
| 1468 | 'current_data_offset': current_data_offset, |
| 1469 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1470 | |
| 1471 | def classify_add_del_session( |
| 1472 | self, |
| 1473 | is_add, |
| 1474 | table_index, |
| 1475 | match, |
| 1476 | opaque_index=0xFFFFFFFF, |
| 1477 | hit_next_index=0xFFFFFFFF, |
| 1478 | advance=0, |
| 1479 | action=0, |
| 1480 | metadata=0): |
| 1481 | """ |
| 1482 | :param is_add: |
| 1483 | :param table_index: |
| 1484 | :param match: |
| 1485 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1486 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1487 | :param advance: (Default value = 0) |
| 1488 | :param action: (Default value = 0) |
| 1489 | :param metadata: (Default value = 0) |
| 1490 | """ |
| 1491 | |
| 1492 | return self.api( |
| 1493 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1494 | {'is_add': is_add, |
| 1495 | 'table_index': table_index, |
| 1496 | 'hit_next_index': hit_next_index, |
| 1497 | 'opaque_index': opaque_index, |
| 1498 | 'advance': advance, |
| 1499 | 'action': action, |
| 1500 | 'metadata': metadata, |
| 1501 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1502 | |
| 1503 | def input_acl_set_interface( |
| 1504 | self, |
| 1505 | is_add, |
| 1506 | sw_if_index, |
| 1507 | ip4_table_index=0xFFFFFFFF, |
| 1508 | ip6_table_index=0xFFFFFFFF, |
| 1509 | l2_table_index=0xFFFFFFFF): |
| 1510 | """ |
| 1511 | :param is_add: |
| 1512 | :param sw_if_index: |
| 1513 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1514 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1515 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1516 | """ |
| 1517 | |
| 1518 | return self.api( |
| 1519 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1520 | {'sw_if_index': sw_if_index, |
| 1521 | 'ip4_table_index': ip4_table_index, |
| 1522 | 'ip6_table_index': ip6_table_index, |
| 1523 | 'l2_table_index': l2_table_index, |
| 1524 | 'is_add': is_add}) |
| 1525 | |
| 1526 | def set_ipfix_exporter( |
| 1527 | self, |
| 1528 | collector_address, |
| 1529 | src_address, |
| 1530 | path_mtu, |
| 1531 | template_interval, |
| 1532 | vrf_id=0, |
| 1533 | collector_port=4739, |
| 1534 | udp_checksum=0): |
| 1535 | return self.api( |
| 1536 | self.papi.set_ipfix_exporter, |
| 1537 | { |
| 1538 | 'collector_address': collector_address, |
| 1539 | 'collector_port': collector_port, |
| 1540 | 'src_address': src_address, |
| 1541 | 'vrf_id': vrf_id, |
| 1542 | 'path_mtu': path_mtu, |
| 1543 | 'template_interval': template_interval, |
| 1544 | 'udp_checksum': udp_checksum, |
| 1545 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1546 | |
| 1547 | def dhcp_proxy_config(self, |
| 1548 | dhcp_server, |
| 1549 | dhcp_src_address, |
| 1550 | rx_table_id=0, |
| 1551 | server_table_id=0, |
| 1552 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1553 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1554 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1555 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1556 | { |
| 1557 | 'rx_vrf_id': rx_table_id, |
| 1558 | 'server_vrf_id': server_table_id, |
| 1559 | 'is_ipv6': is_ipv6, |
| 1560 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1561 | 'dhcp_server': dhcp_server, |
| 1562 | 'dhcp_src_address': dhcp_src_address, |
| 1563 | }) |
| 1564 | |
| 1565 | def dhcp_proxy_set_vss(self, |
| 1566 | table_id, |
| 1567 | fib_id, |
| 1568 | oui, |
| 1569 | is_add=1, |
| 1570 | is_ip6=0): |
| 1571 | return self.api( |
| 1572 | self.papi.dhcp_proxy_set_vss, |
| 1573 | { |
| 1574 | 'tbl_id': table_id, |
| 1575 | 'fib_id': fib_id, |
| 1576 | 'is_ipv6': is_ip6, |
| 1577 | 'is_add': is_add, |
| 1578 | 'oui': oui, |
| 1579 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1580 | |
| 1581 | def ip_mroute_add_del(self, |
| 1582 | src_address, |
| 1583 | grp_address, |
| 1584 | grp_address_length, |
| 1585 | e_flags, |
| 1586 | next_hop_sw_if_index, |
| 1587 | i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1588 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1589 | table_id=0, |
| 1590 | create_vrf_if_needed=0, |
| 1591 | is_add=1, |
| 1592 | is_ipv6=0, |
| 1593 | is_local=0): |
| 1594 | """ |
| 1595 | """ |
| 1596 | return self.api( |
| 1597 | self.papi.ip_mroute_add_del, |
| 1598 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 1599 | 'entry_flags': e_flags, |
| 1600 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1601 | 'table_id': table_id, |
| 1602 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1603 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 1604 | 'is_add': is_add, |
| 1605 | 'is_ipv6': is_ipv6, |
| 1606 | 'is_local': is_local, |
| 1607 | 'grp_address_length': grp_address_length, |
| 1608 | 'grp_address': grp_address, |
| 1609 | 'src_address': src_address}) |
| 1610 | |
| 1611 | def mfib_signal_dump(self): |
| 1612 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1613 | |
| 1614 | def ip_mfib_dump(self): |
| 1615 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1616 | |
| 1617 | def lisp_enable_disable(self, is_enabled): |
| 1618 | return self.api( |
| 1619 | self.papi.lisp_enable_disable, |
| 1620 | { |
| 1621 | 'is_en': is_enabled, |
| 1622 | }) |
| 1623 | |
| 1624 | def lisp_locator_set(self, |
| 1625 | ls_name, |
| 1626 | is_add=1): |
| 1627 | return self.api( |
| 1628 | self.papi.lisp_add_del_locator_set, |
| 1629 | { |
| 1630 | 'is_add': is_add, |
| 1631 | 'locator_set_name': ls_name |
| 1632 | }) |
| 1633 | |
| 1634 | def lisp_locator_set_dump(self): |
| 1635 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 1636 | |
| 1637 | def lisp_locator(self, |
| 1638 | ls_name, |
| 1639 | sw_if_index, |
| 1640 | priority=1, |
| 1641 | weight=1, |
| 1642 | is_add=1): |
| 1643 | return self.api( |
| 1644 | self.papi.lisp_add_del_locator, |
| 1645 | { |
| 1646 | 'is_add': is_add, |
| 1647 | 'locator_set_name': ls_name, |
| 1648 | 'sw_if_index': sw_if_index, |
| 1649 | 'priority': priority, |
| 1650 | 'weight': weight |
| 1651 | }) |
| 1652 | |
| 1653 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 1654 | return self.api( |
| 1655 | self.papi.lisp_locator_dump, |
| 1656 | { |
| 1657 | 'is_index_set': is_index_set, |
| 1658 | 'ls_name': ls_name, |
| 1659 | 'ls_index': ls_index, |
| 1660 | }) |
| 1661 | |
| 1662 | def lisp_local_mapping(self, |
| 1663 | ls_name, |
| 1664 | eid_type, |
| 1665 | eid, |
| 1666 | prefix_len, |
| 1667 | vni=0, |
| 1668 | key_id=0, |
| 1669 | key="", |
| 1670 | is_add=1): |
| 1671 | return self.api( |
| 1672 | self.papi.lisp_add_del_local_eid, |
| 1673 | { |
| 1674 | 'locator_set_name': ls_name, |
| 1675 | 'is_add': is_add, |
| 1676 | 'eid_type': eid_type, |
| 1677 | 'eid': eid, |
| 1678 | 'prefix_len': prefix_len, |
| 1679 | 'vni': vni, |
| 1680 | 'key_id': key_id, |
| 1681 | 'key': key |
| 1682 | }) |
| 1683 | |
| 1684 | def lisp_eid_table_dump(self, |
| 1685 | eid_set=0, |
| 1686 | prefix_length=0, |
| 1687 | vni=0, |
| 1688 | eid_type=0, |
| 1689 | eid=None, |
| 1690 | filter_opt=0): |
| 1691 | return self.api( |
| 1692 | self.papi.lisp_eid_table_dump, |
| 1693 | { |
| 1694 | 'eid_set': eid_set, |
| 1695 | 'prefix_length': prefix_length, |
| 1696 | 'vni': vni, |
| 1697 | 'eid_type': eid_type, |
| 1698 | 'eid': eid, |
| 1699 | 'filter': filter_opt, |
| 1700 | }) |
| 1701 | |
| 1702 | def lisp_remote_mapping(self, |
| 1703 | eid_type, |
| 1704 | eid, |
| 1705 | eid_prefix_len=0, |
| 1706 | vni=0, |
| 1707 | rlocs=None, |
| 1708 | rlocs_num=0, |
| 1709 | is_src_dst=0, |
| 1710 | is_add=1): |
| 1711 | return self.api( |
| 1712 | self.papi.lisp_add_del_remote_mapping, |
| 1713 | { |
| 1714 | 'is_add': is_add, |
| 1715 | 'eid_type': eid_type, |
| 1716 | 'eid': eid, |
| 1717 | 'eid_len': eid_prefix_len, |
| 1718 | 'rloc_num': rlocs_num, |
| 1719 | 'rlocs': rlocs, |
| 1720 | 'vni': vni, |
| 1721 | 'is_src_dst': is_src_dst, |
| 1722 | }) |
| 1723 | |
| 1724 | def lisp_adjacency(self, |
| 1725 | leid, |
| 1726 | reid, |
| 1727 | leid_len, |
| 1728 | reid_len, |
| 1729 | eid_type, |
| 1730 | is_add=1, |
| 1731 | vni=0): |
| 1732 | return self.api( |
| 1733 | self.papi.lisp_add_del_adjacency, |
| 1734 | { |
| 1735 | 'is_add': is_add, |
| 1736 | 'vni': vni, |
| 1737 | 'eid_type': eid_type, |
| 1738 | 'leid': leid, |
| 1739 | 'reid': reid, |
| 1740 | 'leid_len': leid_len, |
| 1741 | 'reid_len': reid_len, |
| 1742 | }) |
| 1743 | |
| 1744 | def lisp_adjacencies_get(self, vni=0): |
| 1745 | return self.api( |
| 1746 | self.papi.lisp_adjacencies_get, |
| 1747 | { |
| 1748 | 'vni': vni |
| 1749 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 1750 | |
| 1751 | def map_add_domain(self, |
| 1752 | ip6_prefix, |
| 1753 | ip6_prefix_len, |
| 1754 | ip6_src, |
| 1755 | ip6_src_prefix_len, |
| 1756 | ip4_prefix, |
| 1757 | ip4_prefix_len, |
| 1758 | ea_bits_len=0, |
| 1759 | psid_offset=0, |
| 1760 | psid_length=0, |
| 1761 | is_translation=0, |
| 1762 | mtu=1280): |
| 1763 | return self.api( |
| 1764 | self.papi.map_add_domain, |
| 1765 | { |
| 1766 | 'ip6_prefix': ip6_prefix, |
| 1767 | 'ip6_prefix_len': ip6_prefix_len, |
| 1768 | 'ip4_prefix': ip4_prefix, |
| 1769 | 'ip4_prefix_len': ip4_prefix_len, |
| 1770 | 'ip6_src': ip6_src, |
| 1771 | 'ip6_src_prefix_len': ip6_src_prefix_len, |
| 1772 | 'ea_bits_len': ea_bits_len, |
| 1773 | 'psid_offset': psid_offset, |
| 1774 | 'psid_length': psid_length, |
| 1775 | 'is_translation': is_translation, |
| 1776 | 'mtu': mtu |
| 1777 | }) |