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 | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 31 | class VppPapiProvider(object): |
| 32 | """VPP-api provider using vpp-papi |
| 33 | |
| 34 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 35 | """ |
| 36 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 37 | _zero, _negative = range(2) |
| 38 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 39 | def __init__(self, name, shm_prefix, test_class): |
Klement Sekera | 277b89c | 2016-10-28 13:20:27 +0200 | [diff] [blame] | 40 | self.hook = Hook("vpp-papi-provider") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 41 | self.name = name |
| 42 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 43 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 44 | self._expect_api_retval = self._zero |
| 45 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 46 | jsonfiles = [] |
| 47 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 48 | install_dir = os.getenv('VPP_TEST_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 49 | for root, dirnames, filenames in os.walk(install_dir): |
| 50 | for filename in fnmatch.filter(filenames, '*.api.json'): |
| 51 | jsonfiles.append(os.path.join(root, filename)) |
| 52 | |
| 53 | self.papi = VPP(jsonfiles) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 54 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 55 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 56 | def __enter__(self): |
| 57 | return self |
| 58 | |
| 59 | def expect_negative_api_retval(self): |
| 60 | """ Expect API failure """ |
| 61 | self._expect_stack.append(self._expect_api_retval) |
| 62 | self._expect_api_retval = self._negative |
| 63 | return self |
| 64 | |
| 65 | def expect_zero_api_retval(self): |
| 66 | """ Expect API success """ |
| 67 | self._expect_stack.append(self._expect_api_retval) |
| 68 | self._expect_api_retval = self._zero |
| 69 | return self |
| 70 | |
| 71 | def __exit__(self, exc_type, exc_value, traceback): |
| 72 | self._expect_api_retval = self._expect_stack.pop() |
| 73 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 74 | def register_hook(self, hook): |
| 75 | """Replace hook registration with new hook |
| 76 | |
| 77 | :param hook: |
| 78 | |
| 79 | """ |
| 80 | self.hook = hook |
| 81 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 82 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 83 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 84 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 85 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 86 | return e |
| 87 | |
| 88 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 89 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 90 | if name: |
| 91 | self.test_class.logger.debug("Expecting event within %ss", |
| 92 | timeout) |
| 93 | else: |
| 94 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 95 | name, timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 96 | if self._events: |
| 97 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 98 | limit = time.time() + timeout |
| 99 | while time.time() < limit: |
| 100 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 101 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 102 | if name and type(e).__name__ != name: |
| 103 | raise Exception( |
| 104 | "Unexpected event received: %s, expected: %s" % |
| 105 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 106 | self.test_class.logger.debug("Returning event %s:%s" % |
| 107 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 108 | return e |
| 109 | time.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 110 | raise Exception("Event did not occur within timeout") |
| 111 | |
| 112 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 113 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 114 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 115 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 116 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 117 | self._events.append(event) |
| 118 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 119 | def connect(self): |
| 120 | """Connect the API to VPP""" |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 121 | self.papi.connect(self.name, self.shm_prefix) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 122 | self.papi.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 123 | |
| 124 | def disconnect(self): |
| 125 | """Disconnect the API from VPP""" |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 126 | self.papi.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 127 | |
| 128 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 129 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 130 | Call the appropriate hooks before and after the API call |
| 131 | |
| 132 | :param api_fn: API function to call |
| 133 | :param api_args: tuple of API function arguments |
| 134 | :param expected_retval: Expected return value (Default value = 0) |
| 135 | :returns: reply from the API |
| 136 | |
| 137 | """ |
| 138 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 139 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 140 | if self._expect_api_retval == self._negative: |
| 141 | if hasattr(reply, 'retval') and reply.retval >= 0: |
| 142 | msg = "API call passed unexpectedly: expected negative "\ |
| 143 | "return value instead of %d in %s" % \ |
| 144 | (reply.retval, repr(reply)) |
| 145 | self.test_class.logger.info(msg) |
| 146 | raise Exception(msg) |
| 147 | elif self._expect_api_retval == self._zero: |
| 148 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
| 149 | msg = "API call failed, expected zero return value instead "\ |
| 150 | "of %d in %s" % (expected_retval, repr(reply)) |
| 151 | self.test_class.logger.info(msg) |
| 152 | raise Exception(msg) |
| 153 | else: |
| 154 | raise Exception("Internal error, unexpected value for " |
| 155 | "self._expect_api_retval %s" % |
| 156 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 157 | self.hook.after_api(api_fn.__name__, api_args) |
| 158 | return reply |
| 159 | |
| 160 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 161 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 162 | |
| 163 | :param cli: CLI to execute |
| 164 | :returns: CLI output |
| 165 | |
| 166 | """ |
| 167 | self.hook.before_cli(cli) |
| 168 | cli += '\n' |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 169 | r = self.papi.cli_inband(length=len(cli), cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 170 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 171 | if hasattr(r, 'reply'): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 172 | return r.reply.decode().rstrip('\x00') |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 173 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 174 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 175 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 176 | |
| 177 | :param cli: CLI to execute |
| 178 | :returns: CLI output |
| 179 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 180 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 181 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 182 | def _convert_mac(self, mac): |
| 183 | return int(mac.replace(":", ""), 16) << 16 |
| 184 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 185 | def show_version(self): |
| 186 | """ """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 187 | return self.papi.show_version() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 188 | |
| 189 | def pg_create_interface(self, pg_index): |
| 190 | """ |
| 191 | |
| 192 | :param pg_index: |
| 193 | |
| 194 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 195 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 196 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 197 | |
| 198 | def sw_interface_dump(self, filter=None): |
| 199 | """ |
| 200 | |
| 201 | :param filter: (Default value = None) |
| 202 | |
| 203 | """ |
| 204 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 205 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 206 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 207 | args = {} |
| 208 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 209 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 210 | 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] | 211 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 212 | |
| 213 | :param sw_if_index: |
| 214 | :param is_ipv6: |
| 215 | :param table_id: |
| 216 | |
| 217 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 218 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 219 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 220 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 221 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 222 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 223 | is_ipv6=0, is_add=1, del_all=0): |
| 224 | """ |
| 225 | |
| 226 | :param addr: param is_ipv6: (Default value = 0) |
| 227 | :param sw_if_index: |
| 228 | :param addr_len: |
| 229 | :param is_ipv6: (Default value = 0) |
| 230 | :param is_add: (Default value = 1) |
| 231 | :param del_all: (Default value = 0) |
| 232 | |
| 233 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 234 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 235 | {'sw_if_index': sw_if_index, |
| 236 | 'is_add': is_add, |
| 237 | 'is_ipv6': is_ipv6, |
| 238 | 'del_all': del_all, |
| 239 | 'address_length': addr_len, |
| 240 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 241 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 242 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 243 | is_enable=1): |
| 244 | """ |
| 245 | Enable/Disable MPLS on the interface |
| 246 | :param sw_if_index: |
| 247 | :param is_enable: (Default value = 1) |
| 248 | |
| 249 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 250 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 251 | {'sw_if_index': sw_if_index, |
| 252 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 253 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame^] | 254 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 255 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame^] | 256 | {'sw_if_index': sw_if_index, |
| 257 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 258 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 259 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 260 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 261 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 262 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 263 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 264 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 265 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 266 | 'suppress': suppress, |
| 267 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 268 | |
| 269 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 270 | """ |
| 271 | Enable/Disable An interface for IPv6 |
| 272 | """ |
| 273 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 274 | {'sw_if_index': sw_if_index, |
| 275 | 'enable': enable}) |
| 276 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 277 | def vxlan_add_del_tunnel( |
| 278 | self, |
| 279 | src_addr, |
| 280 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 281 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 282 | is_add=1, |
| 283 | is_ipv6=0, |
| 284 | encap_vrf_id=0, |
| 285 | decap_next_index=0xFFFFFFFF, |
| 286 | vni=0): |
| 287 | """ |
| 288 | |
| 289 | :param dst_addr: |
| 290 | :param src_addr: |
| 291 | :param is_add: (Default value = 1) |
| 292 | :param is_ipv6: (Default value = 0) |
| 293 | :param encap_vrf_id: (Default value = 0) |
| 294 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 295 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 296 | :param vni: (Default value = 0) |
| 297 | |
| 298 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 299 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 300 | {'is_add': is_add, |
| 301 | 'is_ipv6': is_ipv6, |
| 302 | 'src_address': src_addr, |
| 303 | 'dst_address': dst_addr, |
| 304 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 305 | 'encap_vrf_id': encap_vrf_id, |
| 306 | 'decap_next_index': decap_next_index, |
| 307 | 'vni': vni}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 308 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 309 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 310 | learn=1, arp_term=0, is_add=1): |
| 311 | """Create/delete bridge domain. |
| 312 | |
| 313 | :param int bd_id: Bridge domain index. |
| 314 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 315 | (Default value = 1) |
| 316 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 317 | (Default value = 1) |
| 318 | :param int forward: Enable/disable forwarding on all interfaces in |
| 319 | the BD. (Default value = 1) |
| 320 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 321 | (Default value = 1) |
| 322 | :param int arp_term: Enable/disable arp termination in the BD. |
| 323 | (Default value = 1) |
| 324 | :param int is_add: Add or delete flag. (Default value = 1) |
| 325 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 326 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 327 | {'bd_id': bd_id, |
| 328 | 'flood': flood, |
| 329 | 'uu_flood': uu_flood, |
| 330 | 'forward': forward, |
| 331 | 'learn': learn, |
| 332 | 'arp_term': arp_term, |
| 333 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 334 | |
| 335 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 336 | filter_mac=0, bvi_mac=0): |
| 337 | """Create/delete L2 FIB entry. |
| 338 | |
| 339 | :param str mac: MAC address to create FIB entry for. |
| 340 | :param int bd_id: Bridge domain index. |
| 341 | :param int sw_if_index: Software interface index of the interface. |
| 342 | :param int is_add: Add or delete flag. (Default value = 1) |
| 343 | :param int static_mac: Set to 1 to create static MAC entry. |
| 344 | (Default value = 0) |
| 345 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 346 | destination MAC address contains defined MAC address. |
| 347 | (Default value = 0) |
| 348 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 349 | interface. (Default value = 0) |
| 350 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 351 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 352 | {'mac': self._convert_mac(mac), |
| 353 | 'bd_id': bd_id, |
| 354 | 'sw_if_index': sw_if_index, |
| 355 | 'is_add': is_add, |
| 356 | 'static_mac': static_mac, |
| 357 | 'filter_mac': filter_mac, |
| 358 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 359 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 360 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 361 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 362 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 363 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 364 | :param int sw_if_index: Software interface index of the interface. |
| 365 | :param int bd_id: Bridge domain index. |
| 366 | :param int shg: Split-horizon group index. (Default value = 0) |
| 367 | :param int bvi: Set interface as a bridge group virtual interface. |
| 368 | (Default value = 0) |
| 369 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 370 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 371 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 372 | {'rx_sw_if_index': sw_if_index, |
| 373 | 'bd_id': bd_id, |
| 374 | 'shg': shg, |
| 375 | 'bvi': bvi, |
| 376 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 377 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 378 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 379 | """Enable/disable required feature of the bridge domain with defined ID. |
| 380 | |
| 381 | :param int bd_id: Bridge domain ID. |
| 382 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 383 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 384 | - learn (1 << 0), |
| 385 | - forward (1 << 1), |
| 386 | - flood (1 << 2), |
| 387 | - uu-flood (1 << 3) or |
| 388 | - arp-term (1 << 4). |
| 389 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 390 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 391 | {'bd_id': bd_id, |
| 392 | 'is_set': is_set, |
| 393 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 394 | |
| 395 | def bridge_domain_dump(self, bd_id=0): |
| 396 | """ |
| 397 | |
| 398 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 399 | existing bridge domains returned) |
| 400 | :return: Dictionary of bridge domain(s) data. |
| 401 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 402 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 403 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 404 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 405 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 406 | enable): |
| 407 | """Create or delete unidirectional cross-connect from Tx interface to |
| 408 | Rx interface. |
| 409 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 410 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 411 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 412 | :param int enable: Create cross-connect if equal to 1, delete |
| 413 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 414 | |
| 415 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 416 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 417 | {'rx_sw_if_index': rx_sw_if_index, |
| 418 | 'tx_sw_if_index': tx_sw_if_index, |
| 419 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 420 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 421 | def sw_interface_set_l2_tag_rewrite( |
| 422 | self, |
| 423 | sw_if_index, |
| 424 | vtr_oper, |
| 425 | push=0, |
| 426 | tag1=0, |
| 427 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 428 | """L2 interface vlan tag rewrite configure request |
| 429 | :param client_index - opaque cookie to identify the sender |
| 430 | :param context - sender context, to match reply w/ request |
| 431 | :param sw_if_index - interface the operation is applied to |
| 432 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 433 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 434 | :param tag1 - Needed for any push or translate vtr op |
| 435 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 436 | |
| 437 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 438 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 439 | {'sw_if_index': sw_if_index, |
| 440 | 'vtr_op': vtr_oper, |
| 441 | 'push_dot1q': push, |
| 442 | 'tag1': tag1, |
| 443 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 444 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 445 | def sw_interface_set_flags(self, sw_if_index, admin_up_down, |
| 446 | link_up_down=0, deleted=0): |
| 447 | """ |
| 448 | |
| 449 | :param admin_up_down: |
| 450 | :param sw_if_index: |
| 451 | :param link_up_down: (Default value = 0) |
| 452 | :param deleted: (Default value = 0) |
| 453 | |
| 454 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 455 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 456 | {'sw_if_index': sw_if_index, |
| 457 | 'admin_up_down': admin_up_down, |
| 458 | 'link_up_down': link_up_down, |
| 459 | 'deleted': deleted}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 460 | |
| 461 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 462 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 463 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 464 | """Create subinterface |
| 465 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 466 | |
| 467 | :param sub_id: param inner_vlan: |
| 468 | :param sw_if_index: |
| 469 | :param outer_vlan: |
| 470 | :param inner_vlan: |
| 471 | :param no_tags: (Default value = 0) |
| 472 | :param one_tag: (Default value = 0) |
| 473 | :param two_tags: (Default value = 0) |
| 474 | :param dot1ad: (Default value = 0) |
| 475 | :param exact_match: (Default value = 0) |
| 476 | :param default_sub: (Default value = 0) |
| 477 | :param outer_vlan_id_any: (Default value = 0) |
| 478 | :param inner_vlan_id_any: (Default value = 0) |
| 479 | |
| 480 | """ |
| 481 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 482 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 483 | {'sw_if_index': sw_if_index, |
| 484 | 'sub_id': sub_id, |
| 485 | 'no_tags': no_tags, |
| 486 | 'one_tag': one_tag, |
| 487 | 'two_tags': two_tags, |
| 488 | 'dot1ad': dot1ad, |
| 489 | 'exact_match': exact_match, |
| 490 | 'default_sub': default_sub, |
| 491 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 492 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 493 | 'outer_vlan_id': outer_vlan, |
| 494 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 495 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 496 | def delete_subif(self, sw_if_index): |
| 497 | """Delete subinterface |
| 498 | |
| 499 | :param sw_if_index: |
| 500 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 501 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 502 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 503 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 504 | def create_vlan_subif(self, sw_if_index, vlan): |
| 505 | """ |
| 506 | |
| 507 | :param vlan: |
| 508 | :param sw_if_index: |
| 509 | |
| 510 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 511 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 512 | {'sw_if_index': sw_if_index, |
| 513 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 514 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 515 | def create_loopback(self, mac=''): |
| 516 | """ |
| 517 | |
| 518 | :param mac: (Optional) |
| 519 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 520 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 521 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 522 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 523 | def delete_loopback(self, sw_if_index): |
| 524 | return self.api(self.papi.delete_loopback, |
| 525 | {'sw_if_index': sw_if_index, }) |
| 526 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 527 | def ip_add_del_route( |
| 528 | self, |
| 529 | dst_address, |
| 530 | dst_address_length, |
| 531 | next_hop_address, |
| 532 | next_hop_sw_if_index=0xFFFFFFFF, |
| 533 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 534 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 535 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 536 | next_hop_n_out_labels=0, |
| 537 | next_hop_out_label_stack=[], |
| 538 | next_hop_via_label=MPLS_LABEL_INVALID, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 539 | create_vrf_if_needed=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 540 | is_resolve_host=0, |
| 541 | is_resolve_attached=0, |
| 542 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 543 | is_add=1, |
| 544 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 545 | is_unreach=0, |
| 546 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 547 | is_ipv6=0, |
| 548 | is_local=0, |
| 549 | is_classify=0, |
| 550 | is_multipath=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 551 | not_last=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 552 | """ |
| 553 | |
| 554 | :param dst_address_length: |
| 555 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 556 | :param dst_address: |
| 557 | :param next_hop_address: |
| 558 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 559 | :param vrf_id: (Default value = 0) |
| 560 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 561 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 562 | :param create_vrf_if_needed: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 563 | :param is_add: (Default value = 1) |
| 564 | :param is_drop: (Default value = 0) |
| 565 | :param is_ipv6: (Default value = 0) |
| 566 | :param is_local: (Default value = 0) |
| 567 | :param is_classify: (Default value = 0) |
| 568 | :param is_multipath: (Default value = 0) |
| 569 | :param is_resolve_host: (Default value = 0) |
| 570 | :param is_resolve_attached: (Default value = 0) |
| 571 | :param not_last: (Default value = 0) |
| 572 | :param next_hop_weight: (Default value = 1) |
| 573 | |
| 574 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 575 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 576 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 577 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 578 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 579 | 'table_id': table_id, |
| 580 | 'classify_table_index': classify_table_index, |
| 581 | 'next_hop_table_id': next_hop_table_id, |
| 582 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 583 | 'is_add': is_add, |
| 584 | 'is_drop': is_drop, |
| 585 | 'is_unreach': is_unreach, |
| 586 | 'is_prohibit': is_prohibit, |
| 587 | 'is_ipv6': is_ipv6, |
| 588 | 'is_local': is_local, |
| 589 | 'is_classify': is_classify, |
| 590 | 'is_multipath': is_multipath, |
| 591 | 'is_resolve_host': is_resolve_host, |
| 592 | 'is_resolve_attached': is_resolve_attached, |
| 593 | 'not_last': not_last, |
| 594 | 'next_hop_weight': next_hop_weight, |
| 595 | 'dst_address_length': dst_address_length, |
| 596 | 'dst_address': dst_address, |
| 597 | 'next_hop_address': next_hop_address, |
| 598 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 599 | 'next_hop_via_label': next_hop_via_label, |
| 600 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 601 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 602 | def ip_fib_dump(self): |
| 603 | return self.api(self.papi.ip_fib_dump, {}) |
| 604 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame^] | 605 | def ip6_fib_dump(self): |
| 606 | return self.api(self.papi.ip6_fib_dump, {}) |
| 607 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 608 | def ip_neighbor_add_del(self, |
| 609 | sw_if_index, |
| 610 | mac_address, |
| 611 | dst_address, |
| 612 | vrf_id=0, |
| 613 | is_add=1, |
| 614 | is_ipv6=0, |
| 615 | is_static=0, |
| 616 | ): |
| 617 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 618 | |
| 619 | :param sw_if_index: |
| 620 | :param mac_address: |
| 621 | :param dst_address: |
| 622 | :param vrf_id: (Default value = 0) |
| 623 | :param is_add: (Default value = 1) |
| 624 | :param is_ipv6: (Default value = 0) |
| 625 | :param is_static: (Default value = 0) |
| 626 | """ |
| 627 | |
| 628 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 629 | self.papi.ip_neighbor_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 630 | {'vrf_id': vrf_id, |
| 631 | 'sw_if_index': sw_if_index, |
| 632 | 'is_add': is_add, |
| 633 | 'is_ipv6': is_ipv6, |
| 634 | 'is_static': is_static, |
| 635 | 'mac_address': mac_address, |
| 636 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 637 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 638 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 639 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 640 | def reset_vrf(self, |
| 641 | vrf_id, |
| 642 | is_ipv6=0, |
| 643 | ): |
| 644 | """ Reset VRF (remove all routes etc.) request. |
| 645 | |
| 646 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 647 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 648 | """ |
| 649 | |
| 650 | return self.api( |
| 651 | self.papi.reset_vrf, |
| 652 | {'vrf_id': vrf_id, |
| 653 | 'is_ipv6': is_ipv6, |
| 654 | } |
| 655 | ) |
| 656 | |
| 657 | def reset_fib(self, |
| 658 | vrf_id, |
| 659 | is_ipv6=0, |
| 660 | ): |
| 661 | """ Reset VRF (remove all routes etc.) request. |
| 662 | |
| 663 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 664 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 665 | """ |
| 666 | |
| 667 | return self.api( |
| 668 | self.papi.reset_fib, |
| 669 | {'vrf_id': vrf_id, |
| 670 | 'is_ipv6': is_ipv6, |
| 671 | } |
| 672 | ) |
| 673 | |
| 674 | def ip_dump(self, |
| 675 | is_ipv6=0, |
| 676 | ): |
| 677 | """ Return IP dump. |
| 678 | |
| 679 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 680 | """ |
| 681 | |
| 682 | return self.api( |
| 683 | self.papi.ip_dump, |
| 684 | {'is_ipv6': is_ipv6, |
| 685 | } |
| 686 | ) |
| 687 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 688 | def sw_interface_span_enable_disable( |
Ole Troan | 399ca1c | 2016-12-06 23:00:38 +0100 | [diff] [blame] | 689 | self, sw_if_index_from, sw_if_index_to, state=1): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 690 | """ |
| 691 | |
| 692 | :param sw_if_index_from: |
| 693 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 694 | :param state: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 695 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 696 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 697 | {'sw_if_index_from': sw_if_index_from, |
| 698 | 'sw_if_index_to': sw_if_index_to, |
| 699 | 'state': state}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 700 | |
| 701 | def gre_tunnel_add_del(self, |
| 702 | src_address, |
| 703 | dst_address, |
| 704 | outer_fib_id=0, |
| 705 | is_teb=0, |
| 706 | is_add=1, |
| 707 | is_ip6=0): |
| 708 | """ Add a GRE tunnel |
| 709 | |
| 710 | :param src_address: |
| 711 | :param dst_address: |
| 712 | :param outer_fib_id: (Default value = 0) |
| 713 | :param is_add: (Default value = 1) |
| 714 | :param is_ipv6: (Default value = 0) |
| 715 | :param is_teb: (Default value = 0) |
| 716 | """ |
| 717 | |
| 718 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 719 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 720 | {'is_add': is_add, |
| 721 | 'is_ipv6': is_ip6, |
| 722 | 'teb': is_teb, |
| 723 | 'src_address': src_address, |
| 724 | 'dst_address': dst_address, |
| 725 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 726 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 727 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 728 | def mpls_fib_dump(self): |
| 729 | return self.api(self.papi.mpls_fib_dump, {}) |
| 730 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 731 | def mpls_route_add_del( |
| 732 | self, |
| 733 | label, |
| 734 | eos, |
| 735 | next_hop_proto_is_ip4, |
| 736 | next_hop_address, |
| 737 | next_hop_sw_if_index=0xFFFFFFFF, |
| 738 | table_id=0, |
| 739 | next_hop_table_id=0, |
| 740 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 741 | next_hop_n_out_labels=0, |
| 742 | next_hop_out_label_stack=[], |
| 743 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 744 | create_vrf_if_needed=0, |
| 745 | is_resolve_host=0, |
| 746 | is_resolve_attached=0, |
| 747 | is_add=1, |
| 748 | is_drop=0, |
| 749 | is_multipath=0, |
| 750 | classify_table_index=0xFFFFFFFF, |
| 751 | is_classify=0, |
| 752 | not_last=0): |
| 753 | """ |
| 754 | |
| 755 | :param dst_address_length: |
| 756 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 757 | :param dst_address: |
| 758 | :param next_hop_address: |
| 759 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 760 | :param vrf_id: (Default value = 0) |
| 761 | :param lookup_in_vrf: (Default value = 0) |
| 762 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 763 | :param create_vrf_if_needed: (Default value = 0) |
| 764 | :param is_add: (Default value = 1) |
| 765 | :param is_drop: (Default value = 0) |
| 766 | :param is_ipv6: (Default value = 0) |
| 767 | :param is_local: (Default value = 0) |
| 768 | :param is_classify: (Default value = 0) |
| 769 | :param is_multipath: (Default value = 0) |
| 770 | :param is_resolve_host: (Default value = 0) |
| 771 | :param is_resolve_attached: (Default value = 0) |
| 772 | :param not_last: (Default value = 0) |
| 773 | :param next_hop_weight: (Default value = 1) |
| 774 | |
| 775 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 776 | |
| 777 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 778 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 779 | {'mr_label': label, |
| 780 | 'mr_eos': eos, |
| 781 | 'mr_table_id': table_id, |
| 782 | 'mr_classify_table_index': classify_table_index, |
| 783 | 'mr_create_table_if_needed': create_vrf_if_needed, |
| 784 | 'mr_is_add': is_add, |
| 785 | 'mr_is_classify': is_classify, |
| 786 | 'mr_is_multipath': is_multipath, |
| 787 | 'mr_is_resolve_host': is_resolve_host, |
| 788 | 'mr_is_resolve_attached': is_resolve_attached, |
| 789 | 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 790 | 'mr_next_hop_weight': next_hop_weight, |
| 791 | 'mr_next_hop': next_hop_address, |
| 792 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 793 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 794 | 'mr_next_hop_table_id': next_hop_table_id, |
| 795 | 'mr_next_hop_via_label': next_hop_via_label, |
| 796 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 797 | |
| 798 | def mpls_ip_bind_unbind( |
| 799 | self, |
| 800 | label, |
| 801 | dst_address, |
| 802 | dst_address_length, |
| 803 | table_id=0, |
| 804 | ip_table_id=0, |
| 805 | is_ip4=1, |
| 806 | create_vrf_if_needed=0, |
| 807 | is_bind=1): |
| 808 | """ |
| 809 | """ |
| 810 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 811 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 812 | {'mb_mpls_table_id': table_id, |
| 813 | 'mb_label': label, |
| 814 | 'mb_ip_table_id': ip_table_id, |
| 815 | 'mb_create_table_if_needed': create_vrf_if_needed, |
| 816 | 'mb_is_bind': is_bind, |
| 817 | 'mb_is_ip4': is_ip4, |
| 818 | 'mb_address_length': dst_address_length, |
| 819 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 820 | |
| 821 | def mpls_tunnel_add_del( |
| 822 | self, |
| 823 | tun_sw_if_index, |
| 824 | next_hop_proto_is_ip4, |
| 825 | next_hop_address, |
| 826 | next_hop_sw_if_index=0xFFFFFFFF, |
| 827 | next_hop_table_id=0, |
| 828 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 829 | next_hop_n_out_labels=0, |
| 830 | next_hop_out_label_stack=[], |
| 831 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 832 | create_vrf_if_needed=0, |
| 833 | is_add=1, |
| 834 | l2_only=0): |
| 835 | """ |
| 836 | |
| 837 | :param dst_address_length: |
| 838 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 839 | :param dst_address: |
| 840 | :param next_hop_address: |
| 841 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 842 | :param vrf_id: (Default value = 0) |
| 843 | :param lookup_in_vrf: (Default value = 0) |
| 844 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 845 | :param create_vrf_if_needed: (Default value = 0) |
| 846 | :param is_add: (Default value = 1) |
| 847 | :param is_drop: (Default value = 0) |
| 848 | :param is_ipv6: (Default value = 0) |
| 849 | :param is_local: (Default value = 0) |
| 850 | :param is_classify: (Default value = 0) |
| 851 | :param is_multipath: (Default value = 0) |
| 852 | :param is_resolve_host: (Default value = 0) |
| 853 | :param is_resolve_attached: (Default value = 0) |
| 854 | :param not_last: (Default value = 0) |
| 855 | :param next_hop_weight: (Default value = 1) |
| 856 | |
| 857 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 858 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 859 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 860 | {'mt_sw_if_index': tun_sw_if_index, |
| 861 | 'mt_is_add': is_add, |
| 862 | 'mt_l2_only': l2_only, |
| 863 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 864 | 'mt_next_hop_weight': next_hop_weight, |
| 865 | 'mt_next_hop': next_hop_address, |
| 866 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 867 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 868 | 'mt_next_hop_table_id': next_hop_table_id, |
| 869 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 870 | |
| 871 | def snat_interface_add_del_feature( |
| 872 | self, |
| 873 | sw_if_index, |
| 874 | is_inside=1, |
| 875 | is_add=1): |
| 876 | """Enable/disable S-NAT feature on the interface |
| 877 | |
| 878 | :param sw_if_index: Software index of the interface |
| 879 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 880 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 881 | """ |
| 882 | return self.api( |
| 883 | self.papi.snat_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 884 | {'is_add': is_add, |
| 885 | 'is_inside': is_inside, |
| 886 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 887 | |
| 888 | def snat_add_static_mapping( |
| 889 | self, |
| 890 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 891 | external_ip=0, |
| 892 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 893 | local_port=0, |
| 894 | external_port=0, |
| 895 | addr_only=1, |
| 896 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 897 | protocol=0, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 898 | is_add=1, |
| 899 | is_ip4=1): |
| 900 | """Add/delete S-NAT static mapping |
| 901 | |
| 902 | :param local_ip: Local IP address |
| 903 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 904 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 905 | :param local_port: Local port number (Default value = 0) |
| 906 | :param external_port: External port number (Default value = 0) |
| 907 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 908 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 909 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 910 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 911 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 912 | """ |
| 913 | return self.api( |
| 914 | self.papi.snat_add_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 915 | {'is_add': is_add, |
| 916 | 'is_ip4': is_ip4, |
| 917 | 'addr_only': addr_only, |
| 918 | 'local_ip_address': local_ip, |
| 919 | 'external_ip_address': external_ip, |
| 920 | 'local_port': local_port, |
| 921 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 922 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 923 | 'vrf_id': vrf_id, |
| 924 | 'protocol': protocol}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 925 | |
| 926 | def snat_add_address_range( |
| 927 | self, |
| 928 | first_ip_address, |
| 929 | last_ip_address, |
| 930 | is_add=1, |
| 931 | is_ip4=1): |
| 932 | """Add/del S-NAT address range |
| 933 | |
| 934 | :param first_ip_address: First IP address |
| 935 | :param last_ip_address: Last IP address |
| 936 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 937 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 938 | """ |
| 939 | return self.api( |
| 940 | self.papi.snat_add_address_range, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 941 | {'is_ip4': is_ip4, |
| 942 | 'first_ip_address': first_ip_address, |
| 943 | 'last_ip_address': last_ip_address, |
| 944 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 945 | |
| 946 | def snat_address_dump(self): |
| 947 | """Dump S-NAT addresses |
| 948 | :return: Dictionary of S-NAT addresses |
| 949 | """ |
| 950 | return self.api(self.papi.snat_address_dump, {}) |
| 951 | |
| 952 | def snat_interface_dump(self): |
| 953 | """Dump interfaces with S-NAT feature |
| 954 | :return: Dictionary of interfaces with S-NAT feature |
| 955 | """ |
| 956 | return self.api(self.papi.snat_interface_dump, {}) |
| 957 | |
| 958 | def snat_static_mapping_dump(self): |
| 959 | """Dump S-NAT static mappings |
| 960 | :return: Dictionary of S-NAT static mappings |
| 961 | """ |
| 962 | return self.api(self.papi.snat_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 963 | |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 964 | def snat_show_config(self): |
| 965 | """Show S-NAT config |
| 966 | :return: S-NAT config parameters |
| 967 | """ |
| 968 | return self.api(self.papi.snat_show_config, {}) |
| 969 | |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 970 | def snat_add_interface_addr( |
| 971 | self, |
| 972 | sw_if_index, |
| 973 | is_add=1): |
| 974 | """Add/del S-NAT address from interface |
| 975 | |
| 976 | :param sw_if_index: Software index of the interface |
| 977 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 978 | """ |
| 979 | return self.api(self.papi.snat_add_del_interface_addr, |
| 980 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 981 | |
| 982 | def snat_interface_addr_dump(self): |
| 983 | """Dump S-NAT addresses interfaces |
| 984 | :return: Dictionary of S-NAT addresses interfaces |
| 985 | """ |
| 986 | return self.api(self.papi.snat_interface_addr_dump, {}) |
| 987 | |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 988 | def snat_ipfix( |
| 989 | self, |
| 990 | domain_id=1, |
| 991 | src_port=4739, |
| 992 | enable=1): |
| 993 | """Enable/disable S-NAT IPFIX logging |
| 994 | |
| 995 | :param domain_id: Observation domain ID (Default value = 1) |
| 996 | :param src_port: Source port number (Default value = 4739) |
| 997 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 998 | """ |
| 999 | return self.api( |
| 1000 | self.papi.snat_ipfix_enable_disable, |
| 1001 | {'domain_id': domain_id, |
| 1002 | 'src_port': src_port, |
| 1003 | 'enable': enable}) |
| 1004 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1005 | def control_ping(self): |
| 1006 | self.api(self.papi.control_ping) |
| 1007 | |
| 1008 | 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] | 1009 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1010 | bfd_key_id=None, conf_key_id=None): |
| 1011 | if bfd_key_id is None: |
| 1012 | return self.api(self.papi.bfd_udp_add, |
| 1013 | { |
| 1014 | 'sw_if_index': sw_if_index, |
| 1015 | 'desired_min_tx': desired_min_tx, |
| 1016 | 'required_min_rx': required_min_rx, |
| 1017 | 'local_addr': local_addr, |
| 1018 | 'peer_addr': peer_addr, |
| 1019 | 'is_ipv6': is_ipv6, |
| 1020 | 'detect_mult': detect_mult, |
| 1021 | }) |
| 1022 | else: |
| 1023 | return self.api(self.papi.bfd_udp_add, |
| 1024 | { |
| 1025 | 'sw_if_index': sw_if_index, |
| 1026 | 'desired_min_tx': desired_min_tx, |
| 1027 | 'required_min_rx': required_min_rx, |
| 1028 | 'local_addr': local_addr, |
| 1029 | 'peer_addr': peer_addr, |
| 1030 | 'is_ipv6': is_ipv6, |
| 1031 | 'detect_mult': detect_mult, |
| 1032 | 'is_authenticated': 1, |
| 1033 | 'bfd_key_id': bfd_key_id, |
| 1034 | 'conf_key_id': conf_key_id, |
| 1035 | }) |
| 1036 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1037 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1038 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1039 | return self.api(self.papi.bfd_udp_mod, |
| 1040 | { |
| 1041 | 'sw_if_index': sw_if_index, |
| 1042 | 'desired_min_tx': desired_min_tx, |
| 1043 | 'required_min_rx': required_min_rx, |
| 1044 | 'local_addr': local_addr, |
| 1045 | 'peer_addr': peer_addr, |
| 1046 | 'is_ipv6': is_ipv6, |
| 1047 | 'detect_mult': detect_mult, |
| 1048 | }) |
| 1049 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1050 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1051 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1052 | is_delayed=False): |
| 1053 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1054 | { |
| 1055 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1056 | 'local_addr': local_addr, |
| 1057 | 'peer_addr': peer_addr, |
| 1058 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1059 | 'is_delayed': 1 if is_delayed else 0, |
| 1060 | 'bfd_key_id': bfd_key_id, |
| 1061 | 'conf_key_id': conf_key_id, |
| 1062 | }) |
| 1063 | |
| 1064 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1065 | is_ipv6=0, is_delayed=False): |
| 1066 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1067 | { |
| 1068 | 'sw_if_index': sw_if_index, |
| 1069 | 'local_addr': local_addr, |
| 1070 | 'peer_addr': peer_addr, |
| 1071 | 'is_ipv6': is_ipv6, |
| 1072 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1073 | }) |
| 1074 | |
| 1075 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1076 | return self.api(self.papi.bfd_udp_del, |
| 1077 | { |
| 1078 | 'sw_if_index': sw_if_index, |
| 1079 | 'local_addr': local_addr, |
| 1080 | 'peer_addr': peer_addr, |
| 1081 | 'is_ipv6': is_ipv6, |
| 1082 | }) |
| 1083 | |
| 1084 | def bfd_udp_session_dump(self): |
| 1085 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1086 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1087 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1088 | peer_addr, is_ipv6=0): |
| 1089 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1090 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1091 | 'sw_if_index': sw_if_index, |
| 1092 | 'local_addr': local_addr, |
| 1093 | 'peer_addr': peer_addr, |
| 1094 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1095 | }) |
| 1096 | |
| 1097 | def want_bfd_events(self, enable_disable=1): |
| 1098 | return self.api(self.papi.want_bfd_events, { |
| 1099 | 'enable_disable': enable_disable, |
| 1100 | 'pid': os.getpid(), |
| 1101 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1102 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1103 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1104 | return self.api(self.papi.bfd_auth_set_key, { |
| 1105 | 'conf_key_id': conf_key_id, |
| 1106 | 'auth_type': auth_type, |
| 1107 | 'key': key, |
| 1108 | 'key_len': len(key), |
| 1109 | }) |
| 1110 | |
| 1111 | def bfd_auth_del_key(self, conf_key_id): |
| 1112 | return self.api(self.papi.bfd_auth_del_key, { |
| 1113 | 'conf_key_id': conf_key_id, |
| 1114 | }) |
| 1115 | |
| 1116 | def bfd_auth_keys_dump(self): |
| 1117 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1118 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1119 | def classify_add_del_table( |
| 1120 | self, |
| 1121 | is_add, |
| 1122 | mask, |
| 1123 | match_n_vectors=1, |
| 1124 | table_index=0xFFFFFFFF, |
| 1125 | nbuckets=2, |
| 1126 | memory_size=2097152, |
| 1127 | skip_n_vectors=0, |
| 1128 | next_table_index=0xFFFFFFFF, |
| 1129 | miss_next_index=0xFFFFFFFF, |
| 1130 | current_data_flag=0, |
| 1131 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1132 | """ |
| 1133 | :param is_add: |
| 1134 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1135 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1136 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1137 | :param nbuckets: (Default value = 2) |
| 1138 | :param memory_size: (Default value = 2097152) |
| 1139 | :param skip_n_vectors: (Default value = 0) |
| 1140 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1141 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1142 | :param current_data_flag: (Default value = 0) |
| 1143 | :param current_data_offset: (Default value = 0) |
| 1144 | """ |
| 1145 | |
| 1146 | return self.api( |
| 1147 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1148 | {'is_add': is_add, |
| 1149 | 'table_index': table_index, |
| 1150 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1151 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1152 | 'skip_n_vectors': skip_n_vectors, |
| 1153 | 'match_n_vectors': match_n_vectors, |
| 1154 | 'next_table_index': next_table_index, |
| 1155 | 'miss_next_index': miss_next_index, |
| 1156 | 'current_data_flag': current_data_flag, |
| 1157 | 'current_data_offset': current_data_offset, |
| 1158 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1159 | |
| 1160 | def classify_add_del_session( |
| 1161 | self, |
| 1162 | is_add, |
| 1163 | table_index, |
| 1164 | match, |
| 1165 | opaque_index=0xFFFFFFFF, |
| 1166 | hit_next_index=0xFFFFFFFF, |
| 1167 | advance=0, |
| 1168 | action=0, |
| 1169 | metadata=0): |
| 1170 | """ |
| 1171 | :param is_add: |
| 1172 | :param table_index: |
| 1173 | :param match: |
| 1174 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1175 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1176 | :param advance: (Default value = 0) |
| 1177 | :param action: (Default value = 0) |
| 1178 | :param metadata: (Default value = 0) |
| 1179 | """ |
| 1180 | |
| 1181 | return self.api( |
| 1182 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1183 | {'is_add': is_add, |
| 1184 | 'table_index': table_index, |
| 1185 | 'hit_next_index': hit_next_index, |
| 1186 | 'opaque_index': opaque_index, |
| 1187 | 'advance': advance, |
| 1188 | 'action': action, |
| 1189 | 'metadata': metadata, |
| 1190 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1191 | |
| 1192 | def input_acl_set_interface( |
| 1193 | self, |
| 1194 | is_add, |
| 1195 | sw_if_index, |
| 1196 | ip4_table_index=0xFFFFFFFF, |
| 1197 | ip6_table_index=0xFFFFFFFF, |
| 1198 | l2_table_index=0xFFFFFFFF): |
| 1199 | """ |
| 1200 | :param is_add: |
| 1201 | :param sw_if_index: |
| 1202 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1203 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1204 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1205 | """ |
| 1206 | |
| 1207 | return self.api( |
| 1208 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1209 | {'sw_if_index': sw_if_index, |
| 1210 | 'ip4_table_index': ip4_table_index, |
| 1211 | 'ip6_table_index': ip6_table_index, |
| 1212 | 'l2_table_index': l2_table_index, |
| 1213 | 'is_add': is_add}) |
| 1214 | |
| 1215 | def set_ipfix_exporter( |
| 1216 | self, |
| 1217 | collector_address, |
| 1218 | src_address, |
| 1219 | path_mtu, |
| 1220 | template_interval, |
| 1221 | vrf_id=0, |
| 1222 | collector_port=4739, |
| 1223 | udp_checksum=0): |
| 1224 | return self.api( |
| 1225 | self.papi.set_ipfix_exporter, |
| 1226 | { |
| 1227 | 'collector_address': collector_address, |
| 1228 | 'collector_port': collector_port, |
| 1229 | 'src_address': src_address, |
| 1230 | 'vrf_id': vrf_id, |
| 1231 | 'path_mtu': path_mtu, |
| 1232 | 'template_interval': template_interval, |
| 1233 | 'udp_checksum': udp_checksum, |
| 1234 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1235 | |
| 1236 | def dhcp_proxy_config(self, |
| 1237 | dhcp_server, |
| 1238 | dhcp_src_address, |
| 1239 | rx_table_id=0, |
| 1240 | server_table_id=0, |
| 1241 | is_add=1, |
| 1242 | is_ipv6=0, |
| 1243 | insert_circuit_id=0): |
| 1244 | return self.api( |
| 1245 | self.papi.dhcp_proxy_config_2, |
| 1246 | { |
| 1247 | 'rx_vrf_id': rx_table_id, |
| 1248 | 'server_vrf_id': server_table_id, |
| 1249 | 'is_ipv6': is_ipv6, |
| 1250 | 'is_add': is_add, |
| 1251 | 'insert_circuit_id': insert_circuit_id, |
| 1252 | 'dhcp_server': dhcp_server, |
| 1253 | 'dhcp_src_address': dhcp_src_address, |
| 1254 | }) |
| 1255 | |
| 1256 | def dhcp_proxy_set_vss(self, |
| 1257 | table_id, |
| 1258 | fib_id, |
| 1259 | oui, |
| 1260 | is_add=1, |
| 1261 | is_ip6=0): |
| 1262 | return self.api( |
| 1263 | self.papi.dhcp_proxy_set_vss, |
| 1264 | { |
| 1265 | 'tbl_id': table_id, |
| 1266 | 'fib_id': fib_id, |
| 1267 | 'is_ipv6': is_ip6, |
| 1268 | 'is_add': is_add, |
| 1269 | 'oui': oui, |
| 1270 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1271 | |
| 1272 | def ip_mroute_add_del(self, |
| 1273 | src_address, |
| 1274 | grp_address, |
| 1275 | grp_address_length, |
| 1276 | e_flags, |
| 1277 | next_hop_sw_if_index, |
| 1278 | i_flags, |
| 1279 | table_id=0, |
| 1280 | create_vrf_if_needed=0, |
| 1281 | is_add=1, |
| 1282 | is_ipv6=0, |
| 1283 | is_local=0): |
| 1284 | """ |
| 1285 | """ |
| 1286 | return self.api( |
| 1287 | self.papi.ip_mroute_add_del, |
| 1288 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 1289 | 'entry_flags': e_flags, |
| 1290 | 'itf_flags': i_flags, |
| 1291 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 1292 | 'is_add': is_add, |
| 1293 | 'is_ipv6': is_ipv6, |
| 1294 | 'is_local': is_local, |
| 1295 | 'grp_address_length': grp_address_length, |
| 1296 | 'grp_address': grp_address, |
| 1297 | 'src_address': src_address}) |
| 1298 | |
| 1299 | def mfib_signal_dump(self): |
| 1300 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1301 | |
| 1302 | def ip_mfib_dump(self): |
| 1303 | return self.api(self.papi.ip_mfib_dump, {}) |