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 | |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 58 | self.vpp = VPP(jsonfiles) |
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: |
| 155 | msg = "API call failed, expected zero return value instead "\ |
| 156 | "of %d in %s" % (expected_retval, repr(reply)) |
| 157 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 158 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 159 | else: |
| 160 | raise Exception("Internal error, unexpected value for " |
| 161 | "self._expect_api_retval %s" % |
| 162 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 163 | self.hook.after_api(api_fn.__name__, api_args) |
| 164 | return reply |
| 165 | |
| 166 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 167 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 168 | |
| 169 | :param cli: CLI to execute |
| 170 | :returns: CLI output |
| 171 | |
| 172 | """ |
| 173 | self.hook.before_cli(cli) |
| 174 | cli += '\n' |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 175 | r = self.papi.cli_inband(length=len(cli), cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 176 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 177 | if hasattr(r, 'reply'): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 178 | return r.reply.decode().rstrip('\x00') |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 179 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 180 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 181 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 182 | |
| 183 | :param cli: CLI to execute |
| 184 | :returns: CLI output |
| 185 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 186 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 187 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 188 | def _convert_mac(self, mac): |
| 189 | return int(mac.replace(":", ""), 16) << 16 |
| 190 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 191 | def show_version(self): |
| 192 | """ """ |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 193 | return self.api(self.papi.show_version, {}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 194 | |
| 195 | def pg_create_interface(self, pg_index): |
| 196 | """ |
| 197 | |
| 198 | :param pg_index: |
| 199 | |
| 200 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 201 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 202 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 203 | |
| 204 | def sw_interface_dump(self, filter=None): |
| 205 | """ |
| 206 | |
| 207 | :param filter: (Default value = None) |
| 208 | |
| 209 | """ |
| 210 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 211 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 212 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 213 | args = {} |
| 214 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 215 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 216 | 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] | 217 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 218 | |
| 219 | :param sw_if_index: |
| 220 | :param is_ipv6: |
| 221 | :param table_id: |
| 222 | |
| 223 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 224 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 225 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 226 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 227 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 228 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 229 | is_ipv6=0, is_add=1, del_all=0): |
| 230 | """ |
| 231 | |
| 232 | :param addr: param is_ipv6: (Default value = 0) |
| 233 | :param sw_if_index: |
| 234 | :param addr_len: |
| 235 | :param is_ipv6: (Default value = 0) |
| 236 | :param is_add: (Default value = 1) |
| 237 | :param del_all: (Default value = 0) |
| 238 | |
| 239 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 240 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 241 | {'sw_if_index': sw_if_index, |
| 242 | 'is_add': is_add, |
| 243 | 'is_ipv6': is_ipv6, |
| 244 | 'del_all': del_all, |
| 245 | 'address_length': addr_len, |
| 246 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 247 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 248 | def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index, |
| 249 | is_add=1): |
| 250 | """ Set the Interface to be unnumbered |
| 251 | |
| 252 | :param is_add: (Default value = 1) |
| 253 | :param sw_if_index - interface That will be unnumbered |
| 254 | :param ip_sw_if_index - interface with an IP addres |
| 255 | |
| 256 | """ |
| 257 | return self.api(self.papi.sw_interface_set_unnumbered, |
| 258 | {'sw_if_index': ip_sw_if_index, |
| 259 | 'unnumbered_sw_if_index': sw_if_index, |
| 260 | 'is_add': is_add}) |
| 261 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 262 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 263 | is_enable=1): |
| 264 | """ |
| 265 | Enable/Disable MPLS on the interface |
| 266 | :param sw_if_index: |
| 267 | :param is_enable: (Default value = 1) |
| 268 | |
| 269 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 270 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 271 | {'sw_if_index': sw_if_index, |
| 272 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 273 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 274 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 275 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 276 | {'sw_if_index': sw_if_index, |
| 277 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 278 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 279 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 280 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 281 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 282 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 283 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 284 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 285 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 286 | 'suppress': suppress, |
| 287 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 288 | |
| 289 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 290 | """ |
| 291 | Enable/Disable An interface for IPv6 |
| 292 | """ |
| 293 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 294 | {'sw_if_index': sw_if_index, |
| 295 | 'enable': enable}) |
| 296 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 297 | def vxlan_add_del_tunnel( |
| 298 | self, |
| 299 | src_addr, |
| 300 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 301 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 302 | is_add=1, |
| 303 | is_ipv6=0, |
| 304 | encap_vrf_id=0, |
| 305 | decap_next_index=0xFFFFFFFF, |
| 306 | vni=0): |
| 307 | """ |
| 308 | |
| 309 | :param dst_addr: |
| 310 | :param src_addr: |
| 311 | :param is_add: (Default value = 1) |
| 312 | :param is_ipv6: (Default value = 0) |
| 313 | :param encap_vrf_id: (Default value = 0) |
| 314 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 315 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 316 | :param vni: (Default value = 0) |
| 317 | |
| 318 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 319 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 320 | {'is_add': is_add, |
| 321 | 'is_ipv6': is_ipv6, |
| 322 | 'src_address': src_addr, |
| 323 | 'dst_address': dst_addr, |
| 324 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 325 | 'encap_vrf_id': encap_vrf_id, |
| 326 | 'decap_next_index': decap_next_index, |
| 327 | 'vni': vni}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 328 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 329 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 330 | learn=1, arp_term=0, is_add=1): |
| 331 | """Create/delete bridge domain. |
| 332 | |
| 333 | :param int bd_id: Bridge domain index. |
| 334 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 335 | (Default value = 1) |
| 336 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 337 | (Default value = 1) |
| 338 | :param int forward: Enable/disable forwarding on all interfaces in |
| 339 | the BD. (Default value = 1) |
| 340 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 341 | (Default value = 1) |
| 342 | :param int arp_term: Enable/disable arp termination in the BD. |
| 343 | (Default value = 1) |
| 344 | :param int is_add: Add or delete flag. (Default value = 1) |
| 345 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 346 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 347 | {'bd_id': bd_id, |
| 348 | 'flood': flood, |
| 349 | 'uu_flood': uu_flood, |
| 350 | 'forward': forward, |
| 351 | 'learn': learn, |
| 352 | 'arp_term': arp_term, |
| 353 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 354 | |
| 355 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 356 | filter_mac=0, bvi_mac=0): |
| 357 | """Create/delete L2 FIB entry. |
| 358 | |
| 359 | :param str mac: MAC address to create FIB entry for. |
| 360 | :param int bd_id: Bridge domain index. |
| 361 | :param int sw_if_index: Software interface index of the interface. |
| 362 | :param int is_add: Add or delete flag. (Default value = 1) |
| 363 | :param int static_mac: Set to 1 to create static MAC entry. |
| 364 | (Default value = 0) |
| 365 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 366 | destination MAC address contains defined MAC address. |
| 367 | (Default value = 0) |
| 368 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 369 | interface. (Default value = 0) |
| 370 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 371 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 372 | {'mac': self._convert_mac(mac), |
| 373 | 'bd_id': bd_id, |
| 374 | 'sw_if_index': sw_if_index, |
| 375 | 'is_add': is_add, |
| 376 | 'static_mac': static_mac, |
| 377 | 'filter_mac': filter_mac, |
| 378 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 379 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 380 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 381 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 382 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 383 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 384 | :param int sw_if_index: Software interface index of the interface. |
| 385 | :param int bd_id: Bridge domain index. |
| 386 | :param int shg: Split-horizon group index. (Default value = 0) |
| 387 | :param int bvi: Set interface as a bridge group virtual interface. |
| 388 | (Default value = 0) |
| 389 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 390 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 391 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 392 | {'rx_sw_if_index': sw_if_index, |
| 393 | 'bd_id': bd_id, |
| 394 | 'shg': shg, |
| 395 | 'bvi': bvi, |
| 396 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 397 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 398 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 399 | """Enable/disable required feature of the bridge domain with defined ID. |
| 400 | |
| 401 | :param int bd_id: Bridge domain ID. |
| 402 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 403 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 404 | - learn (1 << 0), |
| 405 | - forward (1 << 1), |
| 406 | - flood (1 << 2), |
| 407 | - uu-flood (1 << 3) or |
| 408 | - arp-term (1 << 4). |
| 409 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 410 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 411 | {'bd_id': bd_id, |
| 412 | 'is_set': is_set, |
| 413 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 414 | |
| 415 | def bridge_domain_dump(self, bd_id=0): |
| 416 | """ |
| 417 | |
| 418 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 419 | existing bridge domains returned) |
| 420 | :return: Dictionary of bridge domain(s) data. |
| 421 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 422 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 423 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 424 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 425 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 426 | enable): |
| 427 | """Create or delete unidirectional cross-connect from Tx interface to |
| 428 | Rx interface. |
| 429 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 430 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 431 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 432 | :param int enable: Create cross-connect if equal to 1, delete |
| 433 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 434 | |
| 435 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 436 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 437 | {'rx_sw_if_index': rx_sw_if_index, |
| 438 | 'tx_sw_if_index': tx_sw_if_index, |
| 439 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 440 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 441 | def sw_interface_set_l2_tag_rewrite( |
| 442 | self, |
| 443 | sw_if_index, |
| 444 | vtr_oper, |
| 445 | push=0, |
| 446 | tag1=0, |
| 447 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 448 | """L2 interface vlan tag rewrite configure request |
| 449 | :param client_index - opaque cookie to identify the sender |
| 450 | :param context - sender context, to match reply w/ request |
| 451 | :param sw_if_index - interface the operation is applied to |
| 452 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 453 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 454 | :param tag1 - Needed for any push or translate vtr op |
| 455 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 456 | |
| 457 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 458 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 459 | {'sw_if_index': sw_if_index, |
| 460 | 'vtr_op': vtr_oper, |
| 461 | 'push_dot1q': push, |
| 462 | 'tag1': tag1, |
| 463 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 464 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 465 | def sw_interface_set_flags(self, sw_if_index, admin_up_down, |
| 466 | link_up_down=0, deleted=0): |
| 467 | """ |
| 468 | |
| 469 | :param admin_up_down: |
| 470 | :param sw_if_index: |
| 471 | :param link_up_down: (Default value = 0) |
| 472 | :param deleted: (Default value = 0) |
| 473 | |
| 474 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 475 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 476 | {'sw_if_index': sw_if_index, |
| 477 | 'admin_up_down': admin_up_down, |
| 478 | 'link_up_down': link_up_down, |
| 479 | 'deleted': deleted}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 480 | |
| 481 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 482 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 483 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 484 | """Create subinterface |
| 485 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 486 | |
| 487 | :param sub_id: param inner_vlan: |
| 488 | :param sw_if_index: |
| 489 | :param outer_vlan: |
| 490 | :param inner_vlan: |
| 491 | :param no_tags: (Default value = 0) |
| 492 | :param one_tag: (Default value = 0) |
| 493 | :param two_tags: (Default value = 0) |
| 494 | :param dot1ad: (Default value = 0) |
| 495 | :param exact_match: (Default value = 0) |
| 496 | :param default_sub: (Default value = 0) |
| 497 | :param outer_vlan_id_any: (Default value = 0) |
| 498 | :param inner_vlan_id_any: (Default value = 0) |
| 499 | |
| 500 | """ |
| 501 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 502 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 503 | {'sw_if_index': sw_if_index, |
| 504 | 'sub_id': sub_id, |
| 505 | 'no_tags': no_tags, |
| 506 | 'one_tag': one_tag, |
| 507 | 'two_tags': two_tags, |
| 508 | 'dot1ad': dot1ad, |
| 509 | 'exact_match': exact_match, |
| 510 | 'default_sub': default_sub, |
| 511 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 512 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 513 | 'outer_vlan_id': outer_vlan, |
| 514 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 515 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 516 | def delete_subif(self, sw_if_index): |
| 517 | """Delete subinterface |
| 518 | |
| 519 | :param sw_if_index: |
| 520 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 521 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 522 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 523 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 524 | def create_vlan_subif(self, sw_if_index, vlan): |
| 525 | """ |
| 526 | |
| 527 | :param vlan: |
| 528 | :param sw_if_index: |
| 529 | |
| 530 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 531 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 532 | {'sw_if_index': sw_if_index, |
| 533 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 534 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 535 | def create_loopback(self, mac=''): |
| 536 | """ |
| 537 | |
| 538 | :param mac: (Optional) |
| 539 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 540 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 541 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 542 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 543 | def delete_loopback(self, sw_if_index): |
| 544 | return self.api(self.papi.delete_loopback, |
| 545 | {'sw_if_index': sw_if_index, }) |
| 546 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 547 | def ip_add_del_route( |
| 548 | self, |
| 549 | dst_address, |
| 550 | dst_address_length, |
| 551 | next_hop_address, |
| 552 | next_hop_sw_if_index=0xFFFFFFFF, |
| 553 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 554 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 555 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 556 | next_hop_n_out_labels=0, |
| 557 | next_hop_out_label_stack=[], |
| 558 | next_hop_via_label=MPLS_LABEL_INVALID, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 559 | create_vrf_if_needed=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 560 | is_resolve_host=0, |
| 561 | is_resolve_attached=0, |
| 562 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 563 | is_add=1, |
| 564 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 565 | is_unreach=0, |
| 566 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 567 | is_ipv6=0, |
| 568 | is_local=0, |
| 569 | is_classify=0, |
| 570 | is_multipath=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 571 | not_last=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 572 | """ |
| 573 | |
| 574 | :param dst_address_length: |
| 575 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 576 | :param dst_address: |
| 577 | :param next_hop_address: |
| 578 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 579 | :param vrf_id: (Default value = 0) |
| 580 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 581 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 582 | :param create_vrf_if_needed: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 583 | :param is_add: (Default value = 1) |
| 584 | :param is_drop: (Default value = 0) |
| 585 | :param is_ipv6: (Default value = 0) |
| 586 | :param is_local: (Default value = 0) |
| 587 | :param is_classify: (Default value = 0) |
| 588 | :param is_multipath: (Default value = 0) |
| 589 | :param is_resolve_host: (Default value = 0) |
| 590 | :param is_resolve_attached: (Default value = 0) |
| 591 | :param not_last: (Default value = 0) |
| 592 | :param next_hop_weight: (Default value = 1) |
| 593 | |
| 594 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 595 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 596 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 597 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 598 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 599 | 'table_id': table_id, |
| 600 | 'classify_table_index': classify_table_index, |
| 601 | 'next_hop_table_id': next_hop_table_id, |
| 602 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 603 | 'is_add': is_add, |
| 604 | 'is_drop': is_drop, |
| 605 | 'is_unreach': is_unreach, |
| 606 | 'is_prohibit': is_prohibit, |
| 607 | 'is_ipv6': is_ipv6, |
| 608 | 'is_local': is_local, |
| 609 | 'is_classify': is_classify, |
| 610 | 'is_multipath': is_multipath, |
| 611 | 'is_resolve_host': is_resolve_host, |
| 612 | 'is_resolve_attached': is_resolve_attached, |
| 613 | 'not_last': not_last, |
| 614 | 'next_hop_weight': next_hop_weight, |
| 615 | 'dst_address_length': dst_address_length, |
| 616 | 'dst_address': dst_address, |
| 617 | 'next_hop_address': next_hop_address, |
| 618 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 619 | 'next_hop_via_label': next_hop_via_label, |
| 620 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 621 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 622 | def ip_fib_dump(self): |
| 623 | return self.api(self.papi.ip_fib_dump, {}) |
| 624 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 625 | def ip6_fib_dump(self): |
| 626 | return self.api(self.papi.ip6_fib_dump, {}) |
| 627 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 628 | def ip_neighbor_add_del(self, |
| 629 | sw_if_index, |
| 630 | mac_address, |
| 631 | dst_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 632 | is_add=1, |
| 633 | is_ipv6=0, |
| 634 | is_static=0, |
| 635 | ): |
| 636 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 637 | |
| 638 | :param sw_if_index: |
| 639 | :param mac_address: |
| 640 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 641 | :param is_add: (Default value = 1) |
| 642 | :param is_ipv6: (Default value = 0) |
| 643 | :param is_static: (Default value = 0) |
| 644 | """ |
| 645 | |
| 646 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 647 | self.papi.ip_neighbor_add_del, |
Neale Ranns | baf2e90 | 2017-02-25 04:20:00 -0800 | [diff] [blame] | 648 | {'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 649 | 'is_add': is_add, |
| 650 | 'is_ipv6': is_ipv6, |
| 651 | 'is_static': is_static, |
| 652 | 'mac_address': mac_address, |
| 653 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 654 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 655 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 656 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 657 | def ip_neighbor_dump(self, |
| 658 | sw_if_index, |
| 659 | is_ipv6=0): |
| 660 | """ Return IP neighbor dump. |
| 661 | |
| 662 | :param sw_if_index: |
| 663 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 664 | """ |
| 665 | |
| 666 | return self.api( |
| 667 | self.papi.ip_neighbor_dump, |
| 668 | {'is_ipv6': is_ipv6, |
| 669 | 'sw_if_index': sw_if_index |
| 670 | } |
| 671 | ) |
| 672 | |
| 673 | def proxy_arp_add_del(self, |
| 674 | low_address, |
| 675 | hi_address, |
| 676 | vrf_id=0, |
| 677 | is_add=1): |
| 678 | """ Config Proxy Arp Range. |
| 679 | |
| 680 | :param low_address: Start address in the rnage to Proxy for |
| 681 | :param hi_address: End address in the rnage to Proxy for |
| 682 | :param vrf_id: The VRF/table in which to proxy |
| 683 | """ |
| 684 | |
| 685 | return self.api( |
| 686 | self.papi.proxy_arp_add_del, |
| 687 | {'vrf_id': vrf_id, |
| 688 | 'is_add': is_add, |
| 689 | 'low_address': low_address, |
| 690 | 'hi_address': hi_address, |
| 691 | } |
| 692 | ) |
| 693 | |
| 694 | def proxy_arp_intfc_enable_disable(self, |
| 695 | sw_if_index, |
| 696 | is_enable=1): |
| 697 | """ Enable/Disable an interface for proxy ARP requests |
| 698 | |
| 699 | :param sw_if_index: Interface |
| 700 | :param enable_disable: Enable/Disable |
| 701 | """ |
| 702 | |
| 703 | return self.api( |
| 704 | self.papi.proxy_arp_intfc_enable_disable, |
| 705 | {'sw_if_index': sw_if_index, |
| 706 | 'enable_disable': is_enable |
| 707 | } |
| 708 | ) |
| 709 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 710 | def reset_vrf(self, |
| 711 | vrf_id, |
| 712 | is_ipv6=0, |
| 713 | ): |
| 714 | """ Reset VRF (remove all routes etc.) request. |
| 715 | |
| 716 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 717 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 718 | """ |
| 719 | |
| 720 | return self.api( |
| 721 | self.papi.reset_vrf, |
| 722 | {'vrf_id': vrf_id, |
| 723 | 'is_ipv6': is_ipv6, |
| 724 | } |
| 725 | ) |
| 726 | |
| 727 | def reset_fib(self, |
| 728 | vrf_id, |
| 729 | is_ipv6=0, |
| 730 | ): |
| 731 | """ Reset VRF (remove all routes etc.) request. |
| 732 | |
| 733 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 734 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 735 | """ |
| 736 | |
| 737 | return self.api( |
| 738 | self.papi.reset_fib, |
| 739 | {'vrf_id': vrf_id, |
| 740 | 'is_ipv6': is_ipv6, |
| 741 | } |
| 742 | ) |
| 743 | |
| 744 | def ip_dump(self, |
| 745 | is_ipv6=0, |
| 746 | ): |
| 747 | """ Return IP dump. |
| 748 | |
| 749 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 750 | """ |
| 751 | |
| 752 | return self.api( |
| 753 | self.papi.ip_dump, |
| 754 | {'is_ipv6': is_ipv6, |
| 755 | } |
| 756 | ) |
| 757 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 758 | def sw_interface_span_enable_disable( |
Ole Troan | 399ca1c | 2016-12-06 23:00:38 +0100 | [diff] [blame] | 759 | self, sw_if_index_from, sw_if_index_to, state=1): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 760 | """ |
| 761 | |
| 762 | :param sw_if_index_from: |
| 763 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 764 | :param state: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 765 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 766 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 767 | {'sw_if_index_from': sw_if_index_from, |
| 768 | 'sw_if_index_to': sw_if_index_to, |
| 769 | 'state': state}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 770 | |
| 771 | def gre_tunnel_add_del(self, |
| 772 | src_address, |
| 773 | dst_address, |
| 774 | outer_fib_id=0, |
| 775 | is_teb=0, |
| 776 | is_add=1, |
| 777 | is_ip6=0): |
| 778 | """ Add a GRE tunnel |
| 779 | |
| 780 | :param src_address: |
| 781 | :param dst_address: |
| 782 | :param outer_fib_id: (Default value = 0) |
| 783 | :param is_add: (Default value = 1) |
| 784 | :param is_ipv6: (Default value = 0) |
| 785 | :param is_teb: (Default value = 0) |
| 786 | """ |
| 787 | |
| 788 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 789 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 790 | {'is_add': is_add, |
| 791 | 'is_ipv6': is_ip6, |
| 792 | 'teb': is_teb, |
| 793 | 'src_address': src_address, |
| 794 | 'dst_address': dst_address, |
| 795 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 796 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 797 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 798 | def mpls_fib_dump(self): |
| 799 | return self.api(self.papi.mpls_fib_dump, {}) |
| 800 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 801 | def mpls_route_add_del( |
| 802 | self, |
| 803 | label, |
| 804 | eos, |
| 805 | next_hop_proto_is_ip4, |
| 806 | next_hop_address, |
| 807 | next_hop_sw_if_index=0xFFFFFFFF, |
| 808 | table_id=0, |
| 809 | next_hop_table_id=0, |
| 810 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 811 | next_hop_n_out_labels=0, |
| 812 | next_hop_out_label_stack=[], |
| 813 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 814 | create_vrf_if_needed=0, |
| 815 | is_resolve_host=0, |
| 816 | is_resolve_attached=0, |
| 817 | is_add=1, |
| 818 | is_drop=0, |
| 819 | is_multipath=0, |
| 820 | classify_table_index=0xFFFFFFFF, |
| 821 | is_classify=0, |
| 822 | not_last=0): |
| 823 | """ |
| 824 | |
| 825 | :param dst_address_length: |
| 826 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 827 | :param dst_address: |
| 828 | :param next_hop_address: |
| 829 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 830 | :param vrf_id: (Default value = 0) |
| 831 | :param lookup_in_vrf: (Default value = 0) |
| 832 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 833 | :param create_vrf_if_needed: (Default value = 0) |
| 834 | :param is_add: (Default value = 1) |
| 835 | :param is_drop: (Default value = 0) |
| 836 | :param is_ipv6: (Default value = 0) |
| 837 | :param is_local: (Default value = 0) |
| 838 | :param is_classify: (Default value = 0) |
| 839 | :param is_multipath: (Default value = 0) |
| 840 | :param is_resolve_host: (Default value = 0) |
| 841 | :param is_resolve_attached: (Default value = 0) |
| 842 | :param not_last: (Default value = 0) |
| 843 | :param next_hop_weight: (Default value = 1) |
| 844 | |
| 845 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 846 | |
| 847 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 848 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 849 | {'mr_label': label, |
| 850 | 'mr_eos': eos, |
| 851 | 'mr_table_id': table_id, |
| 852 | 'mr_classify_table_index': classify_table_index, |
| 853 | 'mr_create_table_if_needed': create_vrf_if_needed, |
| 854 | 'mr_is_add': is_add, |
| 855 | 'mr_is_classify': is_classify, |
| 856 | 'mr_is_multipath': is_multipath, |
| 857 | 'mr_is_resolve_host': is_resolve_host, |
| 858 | 'mr_is_resolve_attached': is_resolve_attached, |
| 859 | 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 860 | 'mr_next_hop_weight': next_hop_weight, |
| 861 | 'mr_next_hop': next_hop_address, |
| 862 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 863 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 864 | 'mr_next_hop_table_id': next_hop_table_id, |
| 865 | 'mr_next_hop_via_label': next_hop_via_label, |
| 866 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 867 | |
| 868 | def mpls_ip_bind_unbind( |
| 869 | self, |
| 870 | label, |
| 871 | dst_address, |
| 872 | dst_address_length, |
| 873 | table_id=0, |
| 874 | ip_table_id=0, |
| 875 | is_ip4=1, |
| 876 | create_vrf_if_needed=0, |
| 877 | is_bind=1): |
| 878 | """ |
| 879 | """ |
| 880 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 881 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 882 | {'mb_mpls_table_id': table_id, |
| 883 | 'mb_label': label, |
| 884 | 'mb_ip_table_id': ip_table_id, |
| 885 | 'mb_create_table_if_needed': create_vrf_if_needed, |
| 886 | 'mb_is_bind': is_bind, |
| 887 | 'mb_is_ip4': is_ip4, |
| 888 | 'mb_address_length': dst_address_length, |
| 889 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 890 | |
| 891 | def mpls_tunnel_add_del( |
| 892 | self, |
| 893 | tun_sw_if_index, |
| 894 | next_hop_proto_is_ip4, |
| 895 | next_hop_address, |
| 896 | next_hop_sw_if_index=0xFFFFFFFF, |
| 897 | next_hop_table_id=0, |
| 898 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 899 | next_hop_n_out_labels=0, |
| 900 | next_hop_out_label_stack=[], |
| 901 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 902 | create_vrf_if_needed=0, |
| 903 | is_add=1, |
| 904 | l2_only=0): |
| 905 | """ |
| 906 | |
| 907 | :param dst_address_length: |
| 908 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 909 | :param dst_address: |
| 910 | :param next_hop_address: |
| 911 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 912 | :param vrf_id: (Default value = 0) |
| 913 | :param lookup_in_vrf: (Default value = 0) |
| 914 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 915 | :param create_vrf_if_needed: (Default value = 0) |
| 916 | :param is_add: (Default value = 1) |
| 917 | :param is_drop: (Default value = 0) |
| 918 | :param is_ipv6: (Default value = 0) |
| 919 | :param is_local: (Default value = 0) |
| 920 | :param is_classify: (Default value = 0) |
| 921 | :param is_multipath: (Default value = 0) |
| 922 | :param is_resolve_host: (Default value = 0) |
| 923 | :param is_resolve_attached: (Default value = 0) |
| 924 | :param not_last: (Default value = 0) |
| 925 | :param next_hop_weight: (Default value = 1) |
| 926 | |
| 927 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 928 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 929 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 930 | {'mt_sw_if_index': tun_sw_if_index, |
| 931 | 'mt_is_add': is_add, |
| 932 | 'mt_l2_only': l2_only, |
| 933 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 934 | 'mt_next_hop_weight': next_hop_weight, |
| 935 | 'mt_next_hop': next_hop_address, |
| 936 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 937 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 938 | 'mt_next_hop_table_id': next_hop_table_id, |
| 939 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 940 | |
| 941 | def snat_interface_add_del_feature( |
| 942 | self, |
| 943 | sw_if_index, |
| 944 | is_inside=1, |
| 945 | is_add=1): |
| 946 | """Enable/disable S-NAT feature on the interface |
| 947 | |
| 948 | :param sw_if_index: Software index of the interface |
| 949 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 950 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 951 | """ |
| 952 | return self.api( |
| 953 | self.papi.snat_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 954 | {'is_add': is_add, |
| 955 | 'is_inside': is_inside, |
| 956 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 957 | |
| 958 | def snat_add_static_mapping( |
| 959 | self, |
| 960 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 961 | external_ip=0, |
| 962 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 963 | local_port=0, |
| 964 | external_port=0, |
| 965 | addr_only=1, |
| 966 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 967 | protocol=0, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 968 | is_add=1, |
| 969 | is_ip4=1): |
| 970 | """Add/delete S-NAT static mapping |
| 971 | |
| 972 | :param local_ip: Local IP address |
| 973 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 974 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 975 | :param local_port: Local port number (Default value = 0) |
| 976 | :param external_port: External port number (Default value = 0) |
| 977 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 978 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 979 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 980 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 981 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 982 | """ |
| 983 | return self.api( |
| 984 | self.papi.snat_add_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 985 | {'is_add': is_add, |
| 986 | 'is_ip4': is_ip4, |
| 987 | 'addr_only': addr_only, |
| 988 | 'local_ip_address': local_ip, |
| 989 | 'external_ip_address': external_ip, |
| 990 | 'local_port': local_port, |
| 991 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 992 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 993 | 'vrf_id': vrf_id, |
| 994 | 'protocol': protocol}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 995 | |
| 996 | def snat_add_address_range( |
| 997 | self, |
| 998 | first_ip_address, |
| 999 | last_ip_address, |
| 1000 | is_add=1, |
| 1001 | is_ip4=1): |
| 1002 | """Add/del S-NAT address range |
| 1003 | |
| 1004 | :param first_ip_address: First IP address |
| 1005 | :param last_ip_address: Last IP address |
| 1006 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1007 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 1008 | """ |
| 1009 | return self.api( |
| 1010 | self.papi.snat_add_address_range, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1011 | {'is_ip4': is_ip4, |
| 1012 | 'first_ip_address': first_ip_address, |
| 1013 | 'last_ip_address': last_ip_address, |
| 1014 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1015 | |
| 1016 | def snat_address_dump(self): |
| 1017 | """Dump S-NAT addresses |
| 1018 | :return: Dictionary of S-NAT addresses |
| 1019 | """ |
| 1020 | return self.api(self.papi.snat_address_dump, {}) |
| 1021 | |
| 1022 | def snat_interface_dump(self): |
| 1023 | """Dump interfaces with S-NAT feature |
| 1024 | :return: Dictionary of interfaces with S-NAT feature |
| 1025 | """ |
| 1026 | return self.api(self.papi.snat_interface_dump, {}) |
| 1027 | |
| 1028 | def snat_static_mapping_dump(self): |
| 1029 | """Dump S-NAT static mappings |
| 1030 | :return: Dictionary of S-NAT static mappings |
| 1031 | """ |
| 1032 | return self.api(self.papi.snat_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1033 | |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1034 | def snat_show_config(self): |
| 1035 | """Show S-NAT config |
| 1036 | :return: S-NAT config parameters |
| 1037 | """ |
| 1038 | return self.api(self.papi.snat_show_config, {}) |
| 1039 | |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1040 | def snat_add_interface_addr( |
| 1041 | self, |
| 1042 | sw_if_index, |
| 1043 | is_add=1): |
| 1044 | """Add/del S-NAT address from interface |
| 1045 | |
| 1046 | :param sw_if_index: Software index of the interface |
| 1047 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1048 | """ |
| 1049 | return self.api(self.papi.snat_add_del_interface_addr, |
| 1050 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 1051 | |
| 1052 | def snat_interface_addr_dump(self): |
| 1053 | """Dump S-NAT addresses interfaces |
| 1054 | :return: Dictionary of S-NAT addresses interfaces |
| 1055 | """ |
| 1056 | return self.api(self.papi.snat_interface_addr_dump, {}) |
| 1057 | |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1058 | def snat_ipfix( |
| 1059 | self, |
| 1060 | domain_id=1, |
| 1061 | src_port=4739, |
| 1062 | enable=1): |
| 1063 | """Enable/disable S-NAT IPFIX logging |
| 1064 | |
| 1065 | :param domain_id: Observation domain ID (Default value = 1) |
| 1066 | :param src_port: Source port number (Default value = 4739) |
| 1067 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1068 | """ |
| 1069 | return self.api( |
| 1070 | self.papi.snat_ipfix_enable_disable, |
| 1071 | {'domain_id': domain_id, |
| 1072 | 'src_port': src_port, |
| 1073 | 'enable': enable}) |
| 1074 | |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1075 | def snat_user_session_dump( |
| 1076 | self, |
| 1077 | ip_address, |
| 1078 | vrf_id): |
| 1079 | """Dump S-NAT user's sessions |
| 1080 | |
| 1081 | :param ip_address: ip adress of the user to be dumped |
| 1082 | :param cpu_index: cpu_index on which the user is |
| 1083 | :param vrf_id: VRF ID |
| 1084 | :return: Dictionary of S-NAT sessions |
| 1085 | """ |
| 1086 | return self.api( |
| 1087 | self.papi.snat_user_session_dump, |
| 1088 | {'ip_address': ip_address, |
| 1089 | 'vrf_id': vrf_id}) |
| 1090 | |
| 1091 | def snat_user_dump(self): |
| 1092 | """Dump S-NAT users |
| 1093 | |
| 1094 | :return: Dictionary of S-NAT users |
| 1095 | """ |
| 1096 | return self.api(self.papi.snat_user_dump, {}) |
| 1097 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1098 | def control_ping(self): |
| 1099 | self.api(self.papi.control_ping) |
| 1100 | |
| 1101 | 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] | 1102 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1103 | bfd_key_id=None, conf_key_id=None): |
| 1104 | if bfd_key_id is None: |
| 1105 | return self.api(self.papi.bfd_udp_add, |
| 1106 | { |
| 1107 | 'sw_if_index': sw_if_index, |
| 1108 | 'desired_min_tx': desired_min_tx, |
| 1109 | 'required_min_rx': required_min_rx, |
| 1110 | 'local_addr': local_addr, |
| 1111 | 'peer_addr': peer_addr, |
| 1112 | 'is_ipv6': is_ipv6, |
| 1113 | 'detect_mult': detect_mult, |
| 1114 | }) |
| 1115 | else: |
| 1116 | return self.api(self.papi.bfd_udp_add, |
| 1117 | { |
| 1118 | 'sw_if_index': sw_if_index, |
| 1119 | 'desired_min_tx': desired_min_tx, |
| 1120 | 'required_min_rx': required_min_rx, |
| 1121 | 'local_addr': local_addr, |
| 1122 | 'peer_addr': peer_addr, |
| 1123 | 'is_ipv6': is_ipv6, |
| 1124 | 'detect_mult': detect_mult, |
| 1125 | 'is_authenticated': 1, |
| 1126 | 'bfd_key_id': bfd_key_id, |
| 1127 | 'conf_key_id': conf_key_id, |
| 1128 | }) |
| 1129 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1130 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1131 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1132 | return self.api(self.papi.bfd_udp_mod, |
| 1133 | { |
| 1134 | 'sw_if_index': sw_if_index, |
| 1135 | 'desired_min_tx': desired_min_tx, |
| 1136 | 'required_min_rx': required_min_rx, |
| 1137 | 'local_addr': local_addr, |
| 1138 | 'peer_addr': peer_addr, |
| 1139 | 'is_ipv6': is_ipv6, |
| 1140 | 'detect_mult': detect_mult, |
| 1141 | }) |
| 1142 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1143 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1144 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1145 | is_delayed=False): |
| 1146 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1147 | { |
| 1148 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1149 | 'local_addr': local_addr, |
| 1150 | 'peer_addr': peer_addr, |
| 1151 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1152 | 'is_delayed': 1 if is_delayed else 0, |
| 1153 | 'bfd_key_id': bfd_key_id, |
| 1154 | 'conf_key_id': conf_key_id, |
| 1155 | }) |
| 1156 | |
| 1157 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1158 | is_ipv6=0, is_delayed=False): |
| 1159 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1160 | { |
| 1161 | 'sw_if_index': sw_if_index, |
| 1162 | 'local_addr': local_addr, |
| 1163 | 'peer_addr': peer_addr, |
| 1164 | 'is_ipv6': is_ipv6, |
| 1165 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1166 | }) |
| 1167 | |
| 1168 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1169 | return self.api(self.papi.bfd_udp_del, |
| 1170 | { |
| 1171 | 'sw_if_index': sw_if_index, |
| 1172 | 'local_addr': local_addr, |
| 1173 | 'peer_addr': peer_addr, |
| 1174 | 'is_ipv6': is_ipv6, |
| 1175 | }) |
| 1176 | |
| 1177 | def bfd_udp_session_dump(self): |
| 1178 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1179 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1180 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1181 | peer_addr, is_ipv6=0): |
| 1182 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1183 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1184 | 'sw_if_index': sw_if_index, |
| 1185 | 'local_addr': local_addr, |
| 1186 | 'peer_addr': peer_addr, |
| 1187 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1188 | }) |
| 1189 | |
| 1190 | def want_bfd_events(self, enable_disable=1): |
| 1191 | return self.api(self.papi.want_bfd_events, { |
| 1192 | 'enable_disable': enable_disable, |
| 1193 | 'pid': os.getpid(), |
| 1194 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1195 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1196 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1197 | return self.api(self.papi.bfd_auth_set_key, { |
| 1198 | 'conf_key_id': conf_key_id, |
| 1199 | 'auth_type': auth_type, |
| 1200 | 'key': key, |
| 1201 | 'key_len': len(key), |
| 1202 | }) |
| 1203 | |
| 1204 | def bfd_auth_del_key(self, conf_key_id): |
| 1205 | return self.api(self.papi.bfd_auth_del_key, { |
| 1206 | 'conf_key_id': conf_key_id, |
| 1207 | }) |
| 1208 | |
| 1209 | def bfd_auth_keys_dump(self): |
| 1210 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1211 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 1212 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 1213 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 1214 | {'sw_if_index': sw_if_index}) |
| 1215 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 1216 | def bfd_udp_del_echo_source(self): |
| 1217 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 1218 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1219 | def classify_add_del_table( |
| 1220 | self, |
| 1221 | is_add, |
| 1222 | mask, |
| 1223 | match_n_vectors=1, |
| 1224 | table_index=0xFFFFFFFF, |
| 1225 | nbuckets=2, |
| 1226 | memory_size=2097152, |
| 1227 | skip_n_vectors=0, |
| 1228 | next_table_index=0xFFFFFFFF, |
| 1229 | miss_next_index=0xFFFFFFFF, |
| 1230 | current_data_flag=0, |
| 1231 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1232 | """ |
| 1233 | :param is_add: |
| 1234 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1235 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1236 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1237 | :param nbuckets: (Default value = 2) |
| 1238 | :param memory_size: (Default value = 2097152) |
| 1239 | :param skip_n_vectors: (Default value = 0) |
| 1240 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1241 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1242 | :param current_data_flag: (Default value = 0) |
| 1243 | :param current_data_offset: (Default value = 0) |
| 1244 | """ |
| 1245 | |
| 1246 | return self.api( |
| 1247 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1248 | {'is_add': is_add, |
| 1249 | 'table_index': table_index, |
| 1250 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1251 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1252 | 'skip_n_vectors': skip_n_vectors, |
| 1253 | 'match_n_vectors': match_n_vectors, |
| 1254 | 'next_table_index': next_table_index, |
| 1255 | 'miss_next_index': miss_next_index, |
| 1256 | 'current_data_flag': current_data_flag, |
| 1257 | 'current_data_offset': current_data_offset, |
| 1258 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1259 | |
| 1260 | def classify_add_del_session( |
| 1261 | self, |
| 1262 | is_add, |
| 1263 | table_index, |
| 1264 | match, |
| 1265 | opaque_index=0xFFFFFFFF, |
| 1266 | hit_next_index=0xFFFFFFFF, |
| 1267 | advance=0, |
| 1268 | action=0, |
| 1269 | metadata=0): |
| 1270 | """ |
| 1271 | :param is_add: |
| 1272 | :param table_index: |
| 1273 | :param match: |
| 1274 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1275 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1276 | :param advance: (Default value = 0) |
| 1277 | :param action: (Default value = 0) |
| 1278 | :param metadata: (Default value = 0) |
| 1279 | """ |
| 1280 | |
| 1281 | return self.api( |
| 1282 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1283 | {'is_add': is_add, |
| 1284 | 'table_index': table_index, |
| 1285 | 'hit_next_index': hit_next_index, |
| 1286 | 'opaque_index': opaque_index, |
| 1287 | 'advance': advance, |
| 1288 | 'action': action, |
| 1289 | 'metadata': metadata, |
| 1290 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1291 | |
| 1292 | def input_acl_set_interface( |
| 1293 | self, |
| 1294 | is_add, |
| 1295 | sw_if_index, |
| 1296 | ip4_table_index=0xFFFFFFFF, |
| 1297 | ip6_table_index=0xFFFFFFFF, |
| 1298 | l2_table_index=0xFFFFFFFF): |
| 1299 | """ |
| 1300 | :param is_add: |
| 1301 | :param sw_if_index: |
| 1302 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1303 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1304 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1305 | """ |
| 1306 | |
| 1307 | return self.api( |
| 1308 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1309 | {'sw_if_index': sw_if_index, |
| 1310 | 'ip4_table_index': ip4_table_index, |
| 1311 | 'ip6_table_index': ip6_table_index, |
| 1312 | 'l2_table_index': l2_table_index, |
| 1313 | 'is_add': is_add}) |
| 1314 | |
| 1315 | def set_ipfix_exporter( |
| 1316 | self, |
| 1317 | collector_address, |
| 1318 | src_address, |
| 1319 | path_mtu, |
| 1320 | template_interval, |
| 1321 | vrf_id=0, |
| 1322 | collector_port=4739, |
| 1323 | udp_checksum=0): |
| 1324 | return self.api( |
| 1325 | self.papi.set_ipfix_exporter, |
| 1326 | { |
| 1327 | 'collector_address': collector_address, |
| 1328 | 'collector_port': collector_port, |
| 1329 | 'src_address': src_address, |
| 1330 | 'vrf_id': vrf_id, |
| 1331 | 'path_mtu': path_mtu, |
| 1332 | 'template_interval': template_interval, |
| 1333 | 'udp_checksum': udp_checksum, |
| 1334 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1335 | |
| 1336 | def dhcp_proxy_config(self, |
| 1337 | dhcp_server, |
| 1338 | dhcp_src_address, |
| 1339 | rx_table_id=0, |
| 1340 | server_table_id=0, |
| 1341 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1342 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1343 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 1344 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1345 | { |
| 1346 | 'rx_vrf_id': rx_table_id, |
| 1347 | 'server_vrf_id': server_table_id, |
| 1348 | 'is_ipv6': is_ipv6, |
| 1349 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1350 | 'dhcp_server': dhcp_server, |
| 1351 | 'dhcp_src_address': dhcp_src_address, |
| 1352 | }) |
| 1353 | |
| 1354 | def dhcp_proxy_set_vss(self, |
| 1355 | table_id, |
| 1356 | fib_id, |
| 1357 | oui, |
| 1358 | is_add=1, |
| 1359 | is_ip6=0): |
| 1360 | return self.api( |
| 1361 | self.papi.dhcp_proxy_set_vss, |
| 1362 | { |
| 1363 | 'tbl_id': table_id, |
| 1364 | 'fib_id': fib_id, |
| 1365 | 'is_ipv6': is_ip6, |
| 1366 | 'is_add': is_add, |
| 1367 | 'oui': oui, |
| 1368 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1369 | |
| 1370 | def ip_mroute_add_del(self, |
| 1371 | src_address, |
| 1372 | grp_address, |
| 1373 | grp_address_length, |
| 1374 | e_flags, |
| 1375 | next_hop_sw_if_index, |
| 1376 | i_flags, |
| 1377 | table_id=0, |
| 1378 | create_vrf_if_needed=0, |
| 1379 | is_add=1, |
| 1380 | is_ipv6=0, |
| 1381 | is_local=0): |
| 1382 | """ |
| 1383 | """ |
| 1384 | return self.api( |
| 1385 | self.papi.ip_mroute_add_del, |
| 1386 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 1387 | 'entry_flags': e_flags, |
| 1388 | 'itf_flags': i_flags, |
| 1389 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 1390 | 'is_add': is_add, |
| 1391 | 'is_ipv6': is_ipv6, |
| 1392 | 'is_local': is_local, |
| 1393 | 'grp_address_length': grp_address_length, |
| 1394 | 'grp_address': grp_address, |
| 1395 | 'src_address': src_address}) |
| 1396 | |
| 1397 | def mfib_signal_dump(self): |
| 1398 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1399 | |
| 1400 | def ip_mfib_dump(self): |
| 1401 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 1402 | |
| 1403 | def lisp_enable_disable(self, is_enabled): |
| 1404 | return self.api( |
| 1405 | self.papi.lisp_enable_disable, |
| 1406 | { |
| 1407 | 'is_en': is_enabled, |
| 1408 | }) |
| 1409 | |
| 1410 | def lisp_locator_set(self, |
| 1411 | ls_name, |
| 1412 | is_add=1): |
| 1413 | return self.api( |
| 1414 | self.papi.lisp_add_del_locator_set, |
| 1415 | { |
| 1416 | 'is_add': is_add, |
| 1417 | 'locator_set_name': ls_name |
| 1418 | }) |
| 1419 | |
| 1420 | def lisp_locator_set_dump(self): |
| 1421 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 1422 | |
| 1423 | def lisp_locator(self, |
| 1424 | ls_name, |
| 1425 | sw_if_index, |
| 1426 | priority=1, |
| 1427 | weight=1, |
| 1428 | is_add=1): |
| 1429 | return self.api( |
| 1430 | self.papi.lisp_add_del_locator, |
| 1431 | { |
| 1432 | 'is_add': is_add, |
| 1433 | 'locator_set_name': ls_name, |
| 1434 | 'sw_if_index': sw_if_index, |
| 1435 | 'priority': priority, |
| 1436 | 'weight': weight |
| 1437 | }) |
| 1438 | |
| 1439 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 1440 | return self.api( |
| 1441 | self.papi.lisp_locator_dump, |
| 1442 | { |
| 1443 | 'is_index_set': is_index_set, |
| 1444 | 'ls_name': ls_name, |
| 1445 | 'ls_index': ls_index, |
| 1446 | }) |
| 1447 | |
| 1448 | def lisp_local_mapping(self, |
| 1449 | ls_name, |
| 1450 | eid_type, |
| 1451 | eid, |
| 1452 | prefix_len, |
| 1453 | vni=0, |
| 1454 | key_id=0, |
| 1455 | key="", |
| 1456 | is_add=1): |
| 1457 | return self.api( |
| 1458 | self.papi.lisp_add_del_local_eid, |
| 1459 | { |
| 1460 | 'locator_set_name': ls_name, |
| 1461 | 'is_add': is_add, |
| 1462 | 'eid_type': eid_type, |
| 1463 | 'eid': eid, |
| 1464 | 'prefix_len': prefix_len, |
| 1465 | 'vni': vni, |
| 1466 | 'key_id': key_id, |
| 1467 | 'key': key |
| 1468 | }) |
| 1469 | |
| 1470 | def lisp_eid_table_dump(self, |
| 1471 | eid_set=0, |
| 1472 | prefix_length=0, |
| 1473 | vni=0, |
| 1474 | eid_type=0, |
| 1475 | eid=None, |
| 1476 | filter_opt=0): |
| 1477 | return self.api( |
| 1478 | self.papi.lisp_eid_table_dump, |
| 1479 | { |
| 1480 | 'eid_set': eid_set, |
| 1481 | 'prefix_length': prefix_length, |
| 1482 | 'vni': vni, |
| 1483 | 'eid_type': eid_type, |
| 1484 | 'eid': eid, |
| 1485 | 'filter': filter_opt, |
| 1486 | }) |
| 1487 | |
| 1488 | def lisp_remote_mapping(self, |
| 1489 | eid_type, |
| 1490 | eid, |
| 1491 | eid_prefix_len=0, |
| 1492 | vni=0, |
| 1493 | rlocs=None, |
| 1494 | rlocs_num=0, |
| 1495 | is_src_dst=0, |
| 1496 | is_add=1): |
| 1497 | return self.api( |
| 1498 | self.papi.lisp_add_del_remote_mapping, |
| 1499 | { |
| 1500 | 'is_add': is_add, |
| 1501 | 'eid_type': eid_type, |
| 1502 | 'eid': eid, |
| 1503 | 'eid_len': eid_prefix_len, |
| 1504 | 'rloc_num': rlocs_num, |
| 1505 | 'rlocs': rlocs, |
| 1506 | 'vni': vni, |
| 1507 | 'is_src_dst': is_src_dst, |
| 1508 | }) |
| 1509 | |
| 1510 | def lisp_adjacency(self, |
| 1511 | leid, |
| 1512 | reid, |
| 1513 | leid_len, |
| 1514 | reid_len, |
| 1515 | eid_type, |
| 1516 | is_add=1, |
| 1517 | vni=0): |
| 1518 | return self.api( |
| 1519 | self.papi.lisp_add_del_adjacency, |
| 1520 | { |
| 1521 | 'is_add': is_add, |
| 1522 | 'vni': vni, |
| 1523 | 'eid_type': eid_type, |
| 1524 | 'leid': leid, |
| 1525 | 'reid': reid, |
| 1526 | 'leid_len': leid_len, |
| 1527 | 'reid_len': reid_len, |
| 1528 | }) |
| 1529 | |
| 1530 | def lisp_adjacencies_get(self, vni=0): |
| 1531 | return self.api( |
| 1532 | self.papi.lisp_adjacencies_get, |
| 1533 | { |
| 1534 | 'vni': vni |
| 1535 | }) |