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 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 254 | def sw_interface_ra_suppress(self, sw_if_index): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 255 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 256 | {'sw_if_index': sw_if_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 257 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 258 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 259 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 260 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 261 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 262 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 263 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 264 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 265 | 'suppress': suppress, |
| 266 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 267 | |
| 268 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 269 | """ |
| 270 | Enable/Disable An interface for IPv6 |
| 271 | """ |
| 272 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 273 | {'sw_if_index': sw_if_index, |
| 274 | 'enable': enable}) |
| 275 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 276 | def vxlan_add_del_tunnel( |
| 277 | self, |
| 278 | src_addr, |
| 279 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 280 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 281 | is_add=1, |
| 282 | is_ipv6=0, |
| 283 | encap_vrf_id=0, |
| 284 | decap_next_index=0xFFFFFFFF, |
| 285 | vni=0): |
| 286 | """ |
| 287 | |
| 288 | :param dst_addr: |
| 289 | :param src_addr: |
| 290 | :param is_add: (Default value = 1) |
| 291 | :param is_ipv6: (Default value = 0) |
| 292 | :param encap_vrf_id: (Default value = 0) |
| 293 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 294 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 295 | :param vni: (Default value = 0) |
| 296 | |
| 297 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 298 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 299 | {'is_add': is_add, |
| 300 | 'is_ipv6': is_ipv6, |
| 301 | 'src_address': src_addr, |
| 302 | 'dst_address': dst_addr, |
| 303 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 304 | 'encap_vrf_id': encap_vrf_id, |
| 305 | 'decap_next_index': decap_next_index, |
| 306 | 'vni': vni}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 307 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 308 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 309 | learn=1, arp_term=0, is_add=1): |
| 310 | """Create/delete bridge domain. |
| 311 | |
| 312 | :param int bd_id: Bridge domain index. |
| 313 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 314 | (Default value = 1) |
| 315 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 316 | (Default value = 1) |
| 317 | :param int forward: Enable/disable forwarding on all interfaces in |
| 318 | the BD. (Default value = 1) |
| 319 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 320 | (Default value = 1) |
| 321 | :param int arp_term: Enable/disable arp termination in the BD. |
| 322 | (Default value = 1) |
| 323 | :param int is_add: Add or delete flag. (Default value = 1) |
| 324 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 325 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 326 | {'bd_id': bd_id, |
| 327 | 'flood': flood, |
| 328 | 'uu_flood': uu_flood, |
| 329 | 'forward': forward, |
| 330 | 'learn': learn, |
| 331 | 'arp_term': arp_term, |
| 332 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 333 | |
| 334 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 335 | filter_mac=0, bvi_mac=0): |
| 336 | """Create/delete L2 FIB entry. |
| 337 | |
| 338 | :param str mac: MAC address to create FIB entry for. |
| 339 | :param int bd_id: Bridge domain index. |
| 340 | :param int sw_if_index: Software interface index of the interface. |
| 341 | :param int is_add: Add or delete flag. (Default value = 1) |
| 342 | :param int static_mac: Set to 1 to create static MAC entry. |
| 343 | (Default value = 0) |
| 344 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 345 | destination MAC address contains defined MAC address. |
| 346 | (Default value = 0) |
| 347 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 348 | interface. (Default value = 0) |
| 349 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 350 | return self.api(self.papi.l2fib_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 351 | {'mac': self._convert_mac(mac), |
| 352 | 'bd_id': bd_id, |
| 353 | 'sw_if_index': sw_if_index, |
| 354 | 'is_add': is_add, |
| 355 | 'static_mac': static_mac, |
| 356 | 'filter_mac': filter_mac, |
| 357 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 358 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 359 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
| 360 | shg=0, bvi=0, enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 361 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 362 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 363 | :param int sw_if_index: Software interface index of the interface. |
| 364 | :param int bd_id: Bridge domain index. |
| 365 | :param int shg: Split-horizon group index. (Default value = 0) |
| 366 | :param int bvi: Set interface as a bridge group virtual interface. |
| 367 | (Default value = 0) |
| 368 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 369 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 370 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 371 | {'rx_sw_if_index': sw_if_index, |
| 372 | 'bd_id': bd_id, |
| 373 | 'shg': shg, |
| 374 | 'bvi': bvi, |
| 375 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 376 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 377 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
| 378 | """Enable/disable required feature of the bridge domain with defined ID. |
| 379 | |
| 380 | :param int bd_id: Bridge domain ID. |
| 381 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
| 382 | :param int feature_bitmap: Bitmap value of the feature to be set: |
| 383 | - learn (1 << 0), |
| 384 | - forward (1 << 1), |
| 385 | - flood (1 << 2), |
| 386 | - uu-flood (1 << 3) or |
| 387 | - arp-term (1 << 4). |
| 388 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 389 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 390 | {'bd_id': bd_id, |
| 391 | 'is_set': is_set, |
| 392 | 'feature_bitmap': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 393 | |
| 394 | def bridge_domain_dump(self, bd_id=0): |
| 395 | """ |
| 396 | |
| 397 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 398 | existing bridge domains returned) |
| 399 | :return: Dictionary of bridge domain(s) data. |
| 400 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 401 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 402 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 403 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 404 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 405 | enable): |
| 406 | """Create or delete unidirectional cross-connect from Tx interface to |
| 407 | Rx interface. |
| 408 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 409 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 410 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 411 | :param int enable: Create cross-connect if equal to 1, delete |
| 412 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 413 | |
| 414 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 415 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 416 | {'rx_sw_if_index': rx_sw_if_index, |
| 417 | 'tx_sw_if_index': tx_sw_if_index, |
| 418 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 419 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 420 | def sw_interface_set_l2_tag_rewrite( |
| 421 | self, |
| 422 | sw_if_index, |
| 423 | vtr_oper, |
| 424 | push=0, |
| 425 | tag1=0, |
| 426 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 427 | """L2 interface vlan tag rewrite configure request |
| 428 | :param client_index - opaque cookie to identify the sender |
| 429 | :param context - sender context, to match reply w/ request |
| 430 | :param sw_if_index - interface the operation is applied to |
| 431 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 432 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 433 | :param tag1 - Needed for any push or translate vtr op |
| 434 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 435 | |
| 436 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 437 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 438 | {'sw_if_index': sw_if_index, |
| 439 | 'vtr_op': vtr_oper, |
| 440 | 'push_dot1q': push, |
| 441 | 'tag1': tag1, |
| 442 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 443 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 444 | def sw_interface_set_flags(self, sw_if_index, admin_up_down, |
| 445 | link_up_down=0, deleted=0): |
| 446 | """ |
| 447 | |
| 448 | :param admin_up_down: |
| 449 | :param sw_if_index: |
| 450 | :param link_up_down: (Default value = 0) |
| 451 | :param deleted: (Default value = 0) |
| 452 | |
| 453 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 454 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 455 | {'sw_if_index': sw_if_index, |
| 456 | 'admin_up_down': admin_up_down, |
| 457 | 'link_up_down': link_up_down, |
| 458 | 'deleted': deleted}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 459 | |
| 460 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 461 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 462 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 463 | """Create subinterface |
| 464 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 465 | |
| 466 | :param sub_id: param inner_vlan: |
| 467 | :param sw_if_index: |
| 468 | :param outer_vlan: |
| 469 | :param inner_vlan: |
| 470 | :param no_tags: (Default value = 0) |
| 471 | :param one_tag: (Default value = 0) |
| 472 | :param two_tags: (Default value = 0) |
| 473 | :param dot1ad: (Default value = 0) |
| 474 | :param exact_match: (Default value = 0) |
| 475 | :param default_sub: (Default value = 0) |
| 476 | :param outer_vlan_id_any: (Default value = 0) |
| 477 | :param inner_vlan_id_any: (Default value = 0) |
| 478 | |
| 479 | """ |
| 480 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 481 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 482 | {'sw_if_index': sw_if_index, |
| 483 | 'sub_id': sub_id, |
| 484 | 'no_tags': no_tags, |
| 485 | 'one_tag': one_tag, |
| 486 | 'two_tags': two_tags, |
| 487 | 'dot1ad': dot1ad, |
| 488 | 'exact_match': exact_match, |
| 489 | 'default_sub': default_sub, |
| 490 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 491 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 492 | 'outer_vlan_id': outer_vlan, |
| 493 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 494 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 495 | def delete_subif(self, sw_if_index): |
| 496 | """Delete subinterface |
| 497 | |
| 498 | :param sw_if_index: |
| 499 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 500 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 501 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 502 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 503 | def create_vlan_subif(self, sw_if_index, vlan): |
| 504 | """ |
| 505 | |
| 506 | :param vlan: |
| 507 | :param sw_if_index: |
| 508 | |
| 509 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 510 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 511 | {'sw_if_index': sw_if_index, |
| 512 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 513 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 514 | def create_loopback(self, mac=''): |
| 515 | """ |
| 516 | |
| 517 | :param mac: (Optional) |
| 518 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 519 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 520 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 521 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 522 | def delete_loopback(self, sw_if_index): |
| 523 | return self.api(self.papi.delete_loopback, |
| 524 | {'sw_if_index': sw_if_index, }) |
| 525 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 526 | def ip_add_del_route( |
| 527 | self, |
| 528 | dst_address, |
| 529 | dst_address_length, |
| 530 | next_hop_address, |
| 531 | next_hop_sw_if_index=0xFFFFFFFF, |
| 532 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 533 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 534 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 535 | next_hop_n_out_labels=0, |
| 536 | next_hop_out_label_stack=[], |
| 537 | next_hop_via_label=MPLS_LABEL_INVALID, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 538 | create_vrf_if_needed=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 539 | is_resolve_host=0, |
| 540 | is_resolve_attached=0, |
| 541 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 542 | is_add=1, |
| 543 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 544 | is_unreach=0, |
| 545 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 546 | is_ipv6=0, |
| 547 | is_local=0, |
| 548 | is_classify=0, |
| 549 | is_multipath=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 550 | not_last=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 551 | """ |
| 552 | |
| 553 | :param dst_address_length: |
| 554 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 555 | :param dst_address: |
| 556 | :param next_hop_address: |
| 557 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 558 | :param vrf_id: (Default value = 0) |
| 559 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 560 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 561 | :param create_vrf_if_needed: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 562 | :param is_add: (Default value = 1) |
| 563 | :param is_drop: (Default value = 0) |
| 564 | :param is_ipv6: (Default value = 0) |
| 565 | :param is_local: (Default value = 0) |
| 566 | :param is_classify: (Default value = 0) |
| 567 | :param is_multipath: (Default value = 0) |
| 568 | :param is_resolve_host: (Default value = 0) |
| 569 | :param is_resolve_attached: (Default value = 0) |
| 570 | :param not_last: (Default value = 0) |
| 571 | :param next_hop_weight: (Default value = 1) |
| 572 | |
| 573 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 574 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 575 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 576 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 577 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 578 | 'table_id': table_id, |
| 579 | 'classify_table_index': classify_table_index, |
| 580 | 'next_hop_table_id': next_hop_table_id, |
| 581 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 582 | 'is_add': is_add, |
| 583 | 'is_drop': is_drop, |
| 584 | 'is_unreach': is_unreach, |
| 585 | 'is_prohibit': is_prohibit, |
| 586 | 'is_ipv6': is_ipv6, |
| 587 | 'is_local': is_local, |
| 588 | 'is_classify': is_classify, |
| 589 | 'is_multipath': is_multipath, |
| 590 | 'is_resolve_host': is_resolve_host, |
| 591 | 'is_resolve_attached': is_resolve_attached, |
| 592 | 'not_last': not_last, |
| 593 | 'next_hop_weight': next_hop_weight, |
| 594 | 'dst_address_length': dst_address_length, |
| 595 | 'dst_address': dst_address, |
| 596 | 'next_hop_address': next_hop_address, |
| 597 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 598 | 'next_hop_via_label': next_hop_via_label, |
| 599 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 600 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 601 | def ip_fib_dump(self): |
| 602 | return self.api(self.papi.ip_fib_dump, {}) |
| 603 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 604 | def ip_neighbor_add_del(self, |
| 605 | sw_if_index, |
| 606 | mac_address, |
| 607 | dst_address, |
| 608 | vrf_id=0, |
| 609 | is_add=1, |
| 610 | is_ipv6=0, |
| 611 | is_static=0, |
| 612 | ): |
| 613 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 614 | |
| 615 | :param sw_if_index: |
| 616 | :param mac_address: |
| 617 | :param dst_address: |
| 618 | :param vrf_id: (Default value = 0) |
| 619 | :param is_add: (Default value = 1) |
| 620 | :param is_ipv6: (Default value = 0) |
| 621 | :param is_static: (Default value = 0) |
| 622 | """ |
| 623 | |
| 624 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 625 | self.papi.ip_neighbor_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 626 | {'vrf_id': vrf_id, |
| 627 | 'sw_if_index': sw_if_index, |
| 628 | 'is_add': is_add, |
| 629 | 'is_ipv6': is_ipv6, |
| 630 | 'is_static': is_static, |
| 631 | 'mac_address': mac_address, |
| 632 | 'dst_address': dst_address |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 633 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 634 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 635 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 636 | def reset_vrf(self, |
| 637 | vrf_id, |
| 638 | is_ipv6=0, |
| 639 | ): |
| 640 | """ Reset VRF (remove all routes etc.) request. |
| 641 | |
| 642 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 643 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 644 | """ |
| 645 | |
| 646 | return self.api( |
| 647 | self.papi.reset_vrf, |
| 648 | {'vrf_id': vrf_id, |
| 649 | 'is_ipv6': is_ipv6, |
| 650 | } |
| 651 | ) |
| 652 | |
| 653 | def reset_fib(self, |
| 654 | vrf_id, |
| 655 | is_ipv6=0, |
| 656 | ): |
| 657 | """ Reset VRF (remove all routes etc.) request. |
| 658 | |
| 659 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 660 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 661 | """ |
| 662 | |
| 663 | return self.api( |
| 664 | self.papi.reset_fib, |
| 665 | {'vrf_id': vrf_id, |
| 666 | 'is_ipv6': is_ipv6, |
| 667 | } |
| 668 | ) |
| 669 | |
| 670 | def ip_dump(self, |
| 671 | is_ipv6=0, |
| 672 | ): |
| 673 | """ Return IP dump. |
| 674 | |
| 675 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 676 | """ |
| 677 | |
| 678 | return self.api( |
| 679 | self.papi.ip_dump, |
| 680 | {'is_ipv6': is_ipv6, |
| 681 | } |
| 682 | ) |
| 683 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 684 | def sw_interface_span_enable_disable( |
Ole Troan | 399ca1c | 2016-12-06 23:00:38 +0100 | [diff] [blame] | 685 | self, sw_if_index_from, sw_if_index_to, state=1): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 686 | """ |
| 687 | |
| 688 | :param sw_if_index_from: |
| 689 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 690 | :param state: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 691 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 692 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 693 | {'sw_if_index_from': sw_if_index_from, |
| 694 | 'sw_if_index_to': sw_if_index_to, |
| 695 | 'state': state}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 696 | |
| 697 | def gre_tunnel_add_del(self, |
| 698 | src_address, |
| 699 | dst_address, |
| 700 | outer_fib_id=0, |
| 701 | is_teb=0, |
| 702 | is_add=1, |
| 703 | is_ip6=0): |
| 704 | """ Add a GRE tunnel |
| 705 | |
| 706 | :param src_address: |
| 707 | :param dst_address: |
| 708 | :param outer_fib_id: (Default value = 0) |
| 709 | :param is_add: (Default value = 1) |
| 710 | :param is_ipv6: (Default value = 0) |
| 711 | :param is_teb: (Default value = 0) |
| 712 | """ |
| 713 | |
| 714 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 715 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 716 | {'is_add': is_add, |
| 717 | 'is_ipv6': is_ip6, |
| 718 | 'teb': is_teb, |
| 719 | 'src_address': src_address, |
| 720 | 'dst_address': dst_address, |
| 721 | 'outer_fib_id': outer_fib_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 722 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 723 | |
| 724 | def mpls_route_add_del( |
| 725 | self, |
| 726 | label, |
| 727 | eos, |
| 728 | next_hop_proto_is_ip4, |
| 729 | next_hop_address, |
| 730 | next_hop_sw_if_index=0xFFFFFFFF, |
| 731 | table_id=0, |
| 732 | next_hop_table_id=0, |
| 733 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 734 | next_hop_n_out_labels=0, |
| 735 | next_hop_out_label_stack=[], |
| 736 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 737 | create_vrf_if_needed=0, |
| 738 | is_resolve_host=0, |
| 739 | is_resolve_attached=0, |
| 740 | is_add=1, |
| 741 | is_drop=0, |
| 742 | is_multipath=0, |
| 743 | classify_table_index=0xFFFFFFFF, |
| 744 | is_classify=0, |
| 745 | not_last=0): |
| 746 | """ |
| 747 | |
| 748 | :param dst_address_length: |
| 749 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 750 | :param dst_address: |
| 751 | :param next_hop_address: |
| 752 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 753 | :param vrf_id: (Default value = 0) |
| 754 | :param lookup_in_vrf: (Default value = 0) |
| 755 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 756 | :param create_vrf_if_needed: (Default value = 0) |
| 757 | :param is_add: (Default value = 1) |
| 758 | :param is_drop: (Default value = 0) |
| 759 | :param is_ipv6: (Default value = 0) |
| 760 | :param is_local: (Default value = 0) |
| 761 | :param is_classify: (Default value = 0) |
| 762 | :param is_multipath: (Default value = 0) |
| 763 | :param is_resolve_host: (Default value = 0) |
| 764 | :param is_resolve_attached: (Default value = 0) |
| 765 | :param not_last: (Default value = 0) |
| 766 | :param next_hop_weight: (Default value = 1) |
| 767 | |
| 768 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 769 | |
| 770 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 771 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 772 | {'mr_label': label, |
| 773 | 'mr_eos': eos, |
| 774 | 'mr_table_id': table_id, |
| 775 | 'mr_classify_table_index': classify_table_index, |
| 776 | 'mr_create_table_if_needed': create_vrf_if_needed, |
| 777 | 'mr_is_add': is_add, |
| 778 | 'mr_is_classify': is_classify, |
| 779 | 'mr_is_multipath': is_multipath, |
| 780 | 'mr_is_resolve_host': is_resolve_host, |
| 781 | 'mr_is_resolve_attached': is_resolve_attached, |
| 782 | 'mr_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 783 | 'mr_next_hop_weight': next_hop_weight, |
| 784 | 'mr_next_hop': next_hop_address, |
| 785 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 786 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 787 | 'mr_next_hop_table_id': next_hop_table_id, |
| 788 | 'mr_next_hop_via_label': next_hop_via_label, |
| 789 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 790 | |
| 791 | def mpls_ip_bind_unbind( |
| 792 | self, |
| 793 | label, |
| 794 | dst_address, |
| 795 | dst_address_length, |
| 796 | table_id=0, |
| 797 | ip_table_id=0, |
| 798 | is_ip4=1, |
| 799 | create_vrf_if_needed=0, |
| 800 | is_bind=1): |
| 801 | """ |
| 802 | """ |
| 803 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 804 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 805 | {'mb_mpls_table_id': table_id, |
| 806 | 'mb_label': label, |
| 807 | 'mb_ip_table_id': ip_table_id, |
| 808 | 'mb_create_table_if_needed': create_vrf_if_needed, |
| 809 | 'mb_is_bind': is_bind, |
| 810 | 'mb_is_ip4': is_ip4, |
| 811 | 'mb_address_length': dst_address_length, |
| 812 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 813 | |
| 814 | def mpls_tunnel_add_del( |
| 815 | self, |
| 816 | tun_sw_if_index, |
| 817 | next_hop_proto_is_ip4, |
| 818 | next_hop_address, |
| 819 | next_hop_sw_if_index=0xFFFFFFFF, |
| 820 | next_hop_table_id=0, |
| 821 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 822 | next_hop_n_out_labels=0, |
| 823 | next_hop_out_label_stack=[], |
| 824 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 825 | create_vrf_if_needed=0, |
| 826 | is_add=1, |
| 827 | l2_only=0): |
| 828 | """ |
| 829 | |
| 830 | :param dst_address_length: |
| 831 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 832 | :param dst_address: |
| 833 | :param next_hop_address: |
| 834 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 835 | :param vrf_id: (Default value = 0) |
| 836 | :param lookup_in_vrf: (Default value = 0) |
| 837 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
| 838 | :param create_vrf_if_needed: (Default value = 0) |
| 839 | :param is_add: (Default value = 1) |
| 840 | :param is_drop: (Default value = 0) |
| 841 | :param is_ipv6: (Default value = 0) |
| 842 | :param is_local: (Default value = 0) |
| 843 | :param is_classify: (Default value = 0) |
| 844 | :param is_multipath: (Default value = 0) |
| 845 | :param is_resolve_host: (Default value = 0) |
| 846 | :param is_resolve_attached: (Default value = 0) |
| 847 | :param not_last: (Default value = 0) |
| 848 | :param next_hop_weight: (Default value = 1) |
| 849 | |
| 850 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 851 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 852 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 853 | {'mt_sw_if_index': tun_sw_if_index, |
| 854 | 'mt_is_add': is_add, |
| 855 | 'mt_l2_only': l2_only, |
| 856 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 857 | 'mt_next_hop_weight': next_hop_weight, |
| 858 | 'mt_next_hop': next_hop_address, |
| 859 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 860 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 861 | 'mt_next_hop_table_id': next_hop_table_id, |
| 862 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 863 | |
| 864 | def snat_interface_add_del_feature( |
| 865 | self, |
| 866 | sw_if_index, |
| 867 | is_inside=1, |
| 868 | is_add=1): |
| 869 | """Enable/disable S-NAT feature on the interface |
| 870 | |
| 871 | :param sw_if_index: Software index of the interface |
| 872 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 873 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 874 | """ |
| 875 | return self.api( |
| 876 | self.papi.snat_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 877 | {'is_add': is_add, |
| 878 | 'is_inside': is_inside, |
| 879 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 880 | |
| 881 | def snat_add_static_mapping( |
| 882 | self, |
| 883 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 884 | external_ip=0, |
| 885 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 886 | local_port=0, |
| 887 | external_port=0, |
| 888 | addr_only=1, |
| 889 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 890 | protocol=0, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 891 | is_add=1, |
| 892 | is_ip4=1): |
| 893 | """Add/delete S-NAT static mapping |
| 894 | |
| 895 | :param local_ip: Local IP address |
| 896 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 897 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 898 | :param local_port: Local port number (Default value = 0) |
| 899 | :param external_port: External port number (Default value = 0) |
| 900 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 901 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 902 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 903 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 904 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 905 | """ |
| 906 | return self.api( |
| 907 | self.papi.snat_add_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 908 | {'is_add': is_add, |
| 909 | 'is_ip4': is_ip4, |
| 910 | 'addr_only': addr_only, |
| 911 | 'local_ip_address': local_ip, |
| 912 | 'external_ip_address': external_ip, |
| 913 | 'local_port': local_port, |
| 914 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 915 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 916 | 'vrf_id': vrf_id, |
| 917 | 'protocol': protocol}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 918 | |
| 919 | def snat_add_address_range( |
| 920 | self, |
| 921 | first_ip_address, |
| 922 | last_ip_address, |
| 923 | is_add=1, |
| 924 | is_ip4=1): |
| 925 | """Add/del S-NAT address range |
| 926 | |
| 927 | :param first_ip_address: First IP address |
| 928 | :param last_ip_address: Last IP address |
| 929 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 930 | :param is_ip4: 1 if address type is IPv4 (Default value = 1) |
| 931 | """ |
| 932 | return self.api( |
| 933 | self.papi.snat_add_address_range, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 934 | {'is_ip4': is_ip4, |
| 935 | 'first_ip_address': first_ip_address, |
| 936 | 'last_ip_address': last_ip_address, |
| 937 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 938 | |
| 939 | def snat_address_dump(self): |
| 940 | """Dump S-NAT addresses |
| 941 | :return: Dictionary of S-NAT addresses |
| 942 | """ |
| 943 | return self.api(self.papi.snat_address_dump, {}) |
| 944 | |
| 945 | def snat_interface_dump(self): |
| 946 | """Dump interfaces with S-NAT feature |
| 947 | :return: Dictionary of interfaces with S-NAT feature |
| 948 | """ |
| 949 | return self.api(self.papi.snat_interface_dump, {}) |
| 950 | |
| 951 | def snat_static_mapping_dump(self): |
| 952 | """Dump S-NAT static mappings |
| 953 | :return: Dictionary of S-NAT static mappings |
| 954 | """ |
| 955 | return self.api(self.papi.snat_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 956 | |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 957 | def snat_show_config(self): |
| 958 | """Show S-NAT config |
| 959 | :return: S-NAT config parameters |
| 960 | """ |
| 961 | return self.api(self.papi.snat_show_config, {}) |
| 962 | |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 963 | def snat_add_interface_addr( |
| 964 | self, |
| 965 | sw_if_index, |
| 966 | is_add=1): |
| 967 | """Add/del S-NAT address from interface |
| 968 | |
| 969 | :param sw_if_index: Software index of the interface |
| 970 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 971 | """ |
| 972 | return self.api(self.papi.snat_add_del_interface_addr, |
| 973 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 974 | |
| 975 | def snat_interface_addr_dump(self): |
| 976 | """Dump S-NAT addresses interfaces |
| 977 | :return: Dictionary of S-NAT addresses interfaces |
| 978 | """ |
| 979 | return self.api(self.papi.snat_interface_addr_dump, {}) |
| 980 | |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 981 | def snat_ipfix( |
| 982 | self, |
| 983 | domain_id=1, |
| 984 | src_port=4739, |
| 985 | enable=1): |
| 986 | """Enable/disable S-NAT IPFIX logging |
| 987 | |
| 988 | :param domain_id: Observation domain ID (Default value = 1) |
| 989 | :param src_port: Source port number (Default value = 4739) |
| 990 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 991 | """ |
| 992 | return self.api( |
| 993 | self.papi.snat_ipfix_enable_disable, |
| 994 | {'domain_id': domain_id, |
| 995 | 'src_port': src_port, |
| 996 | 'enable': enable}) |
| 997 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 998 | def control_ping(self): |
| 999 | self.api(self.papi.control_ping) |
| 1000 | |
| 1001 | 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] | 1002 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 1003 | bfd_key_id=None, conf_key_id=None): |
| 1004 | if bfd_key_id is None: |
| 1005 | return self.api(self.papi.bfd_udp_add, |
| 1006 | { |
| 1007 | 'sw_if_index': sw_if_index, |
| 1008 | 'desired_min_tx': desired_min_tx, |
| 1009 | 'required_min_rx': required_min_rx, |
| 1010 | 'local_addr': local_addr, |
| 1011 | 'peer_addr': peer_addr, |
| 1012 | 'is_ipv6': is_ipv6, |
| 1013 | 'detect_mult': detect_mult, |
| 1014 | }) |
| 1015 | else: |
| 1016 | return self.api(self.papi.bfd_udp_add, |
| 1017 | { |
| 1018 | 'sw_if_index': sw_if_index, |
| 1019 | 'desired_min_tx': desired_min_tx, |
| 1020 | 'required_min_rx': required_min_rx, |
| 1021 | 'local_addr': local_addr, |
| 1022 | 'peer_addr': peer_addr, |
| 1023 | 'is_ipv6': is_ipv6, |
| 1024 | 'detect_mult': detect_mult, |
| 1025 | 'is_authenticated': 1, |
| 1026 | 'bfd_key_id': bfd_key_id, |
| 1027 | 'conf_key_id': conf_key_id, |
| 1028 | }) |
| 1029 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 1030 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 1031 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 1032 | return self.api(self.papi.bfd_udp_mod, |
| 1033 | { |
| 1034 | 'sw_if_index': sw_if_index, |
| 1035 | 'desired_min_tx': desired_min_tx, |
| 1036 | 'required_min_rx': required_min_rx, |
| 1037 | 'local_addr': local_addr, |
| 1038 | 'peer_addr': peer_addr, |
| 1039 | 'is_ipv6': is_ipv6, |
| 1040 | 'detect_mult': detect_mult, |
| 1041 | }) |
| 1042 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1043 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 1044 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 1045 | is_delayed=False): |
| 1046 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1047 | { |
| 1048 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1049 | 'local_addr': local_addr, |
| 1050 | 'peer_addr': peer_addr, |
| 1051 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1052 | 'is_delayed': 1 if is_delayed else 0, |
| 1053 | 'bfd_key_id': bfd_key_id, |
| 1054 | 'conf_key_id': conf_key_id, |
| 1055 | }) |
| 1056 | |
| 1057 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 1058 | is_ipv6=0, is_delayed=False): |
| 1059 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 1060 | { |
| 1061 | 'sw_if_index': sw_if_index, |
| 1062 | 'local_addr': local_addr, |
| 1063 | 'peer_addr': peer_addr, |
| 1064 | 'is_ipv6': is_ipv6, |
| 1065 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1066 | }) |
| 1067 | |
| 1068 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 1069 | return self.api(self.papi.bfd_udp_del, |
| 1070 | { |
| 1071 | 'sw_if_index': sw_if_index, |
| 1072 | 'local_addr': local_addr, |
| 1073 | 'peer_addr': peer_addr, |
| 1074 | 'is_ipv6': is_ipv6, |
| 1075 | }) |
| 1076 | |
| 1077 | def bfd_udp_session_dump(self): |
| 1078 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 1079 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1080 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 1081 | peer_addr, is_ipv6=0): |
| 1082 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1083 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1084 | 'sw_if_index': sw_if_index, |
| 1085 | 'local_addr': local_addr, |
| 1086 | 'peer_addr': peer_addr, |
| 1087 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1088 | }) |
| 1089 | |
| 1090 | def want_bfd_events(self, enable_disable=1): |
| 1091 | return self.api(self.papi.want_bfd_events, { |
| 1092 | 'enable_disable': enable_disable, |
| 1093 | 'pid': os.getpid(), |
| 1094 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1095 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 1096 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 1097 | return self.api(self.papi.bfd_auth_set_key, { |
| 1098 | 'conf_key_id': conf_key_id, |
| 1099 | 'auth_type': auth_type, |
| 1100 | 'key': key, |
| 1101 | 'key_len': len(key), |
| 1102 | }) |
| 1103 | |
| 1104 | def bfd_auth_del_key(self, conf_key_id): |
| 1105 | return self.api(self.papi.bfd_auth_del_key, { |
| 1106 | 'conf_key_id': conf_key_id, |
| 1107 | }) |
| 1108 | |
| 1109 | def bfd_auth_keys_dump(self): |
| 1110 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 1111 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1112 | def classify_add_del_table( |
| 1113 | self, |
| 1114 | is_add, |
| 1115 | mask, |
| 1116 | match_n_vectors=1, |
| 1117 | table_index=0xFFFFFFFF, |
| 1118 | nbuckets=2, |
| 1119 | memory_size=2097152, |
| 1120 | skip_n_vectors=0, |
| 1121 | next_table_index=0xFFFFFFFF, |
| 1122 | miss_next_index=0xFFFFFFFF, |
| 1123 | current_data_flag=0, |
| 1124 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1125 | """ |
| 1126 | :param is_add: |
| 1127 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 1128 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 1129 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1130 | :param nbuckets: (Default value = 2) |
| 1131 | :param memory_size: (Default value = 2097152) |
| 1132 | :param skip_n_vectors: (Default value = 0) |
| 1133 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 1134 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 1135 | :param current_data_flag: (Default value = 0) |
| 1136 | :param current_data_offset: (Default value = 0) |
| 1137 | """ |
| 1138 | |
| 1139 | return self.api( |
| 1140 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1141 | {'is_add': is_add, |
| 1142 | 'table_index': table_index, |
| 1143 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1144 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1145 | 'skip_n_vectors': skip_n_vectors, |
| 1146 | 'match_n_vectors': match_n_vectors, |
| 1147 | 'next_table_index': next_table_index, |
| 1148 | 'miss_next_index': miss_next_index, |
| 1149 | 'current_data_flag': current_data_flag, |
| 1150 | 'current_data_offset': current_data_offset, |
| 1151 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1152 | |
| 1153 | def classify_add_del_session( |
| 1154 | self, |
| 1155 | is_add, |
| 1156 | table_index, |
| 1157 | match, |
| 1158 | opaque_index=0xFFFFFFFF, |
| 1159 | hit_next_index=0xFFFFFFFF, |
| 1160 | advance=0, |
| 1161 | action=0, |
| 1162 | metadata=0): |
| 1163 | """ |
| 1164 | :param is_add: |
| 1165 | :param table_index: |
| 1166 | :param match: |
| 1167 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 1168 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 1169 | :param advance: (Default value = 0) |
| 1170 | :param action: (Default value = 0) |
| 1171 | :param metadata: (Default value = 0) |
| 1172 | """ |
| 1173 | |
| 1174 | return self.api( |
| 1175 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1176 | {'is_add': is_add, |
| 1177 | 'table_index': table_index, |
| 1178 | 'hit_next_index': hit_next_index, |
| 1179 | 'opaque_index': opaque_index, |
| 1180 | 'advance': advance, |
| 1181 | 'action': action, |
| 1182 | 'metadata': metadata, |
| 1183 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 1184 | |
| 1185 | def input_acl_set_interface( |
| 1186 | self, |
| 1187 | is_add, |
| 1188 | sw_if_index, |
| 1189 | ip4_table_index=0xFFFFFFFF, |
| 1190 | ip6_table_index=0xFFFFFFFF, |
| 1191 | l2_table_index=0xFFFFFFFF): |
| 1192 | """ |
| 1193 | :param is_add: |
| 1194 | :param sw_if_index: |
| 1195 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 1196 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 1197 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 1198 | """ |
| 1199 | |
| 1200 | return self.api( |
| 1201 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 1202 | {'sw_if_index': sw_if_index, |
| 1203 | 'ip4_table_index': ip4_table_index, |
| 1204 | 'ip6_table_index': ip6_table_index, |
| 1205 | 'l2_table_index': l2_table_index, |
| 1206 | 'is_add': is_add}) |
| 1207 | |
| 1208 | def set_ipfix_exporter( |
| 1209 | self, |
| 1210 | collector_address, |
| 1211 | src_address, |
| 1212 | path_mtu, |
| 1213 | template_interval, |
| 1214 | vrf_id=0, |
| 1215 | collector_port=4739, |
| 1216 | udp_checksum=0): |
| 1217 | return self.api( |
| 1218 | self.papi.set_ipfix_exporter, |
| 1219 | { |
| 1220 | 'collector_address': collector_address, |
| 1221 | 'collector_port': collector_port, |
| 1222 | 'src_address': src_address, |
| 1223 | 'vrf_id': vrf_id, |
| 1224 | 'path_mtu': path_mtu, |
| 1225 | 'template_interval': template_interval, |
| 1226 | 'udp_checksum': udp_checksum, |
| 1227 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 1228 | |
| 1229 | def dhcp_proxy_config(self, |
| 1230 | dhcp_server, |
| 1231 | dhcp_src_address, |
| 1232 | rx_table_id=0, |
| 1233 | server_table_id=0, |
| 1234 | is_add=1, |
| 1235 | is_ipv6=0, |
| 1236 | insert_circuit_id=0): |
| 1237 | return self.api( |
| 1238 | self.papi.dhcp_proxy_config_2, |
| 1239 | { |
| 1240 | 'rx_vrf_id': rx_table_id, |
| 1241 | 'server_vrf_id': server_table_id, |
| 1242 | 'is_ipv6': is_ipv6, |
| 1243 | 'is_add': is_add, |
| 1244 | 'insert_circuit_id': insert_circuit_id, |
| 1245 | 'dhcp_server': dhcp_server, |
| 1246 | 'dhcp_src_address': dhcp_src_address, |
| 1247 | }) |
| 1248 | |
| 1249 | def dhcp_proxy_set_vss(self, |
| 1250 | table_id, |
| 1251 | fib_id, |
| 1252 | oui, |
| 1253 | is_add=1, |
| 1254 | is_ip6=0): |
| 1255 | return self.api( |
| 1256 | self.papi.dhcp_proxy_set_vss, |
| 1257 | { |
| 1258 | 'tbl_id': table_id, |
| 1259 | 'fib_id': fib_id, |
| 1260 | 'is_ipv6': is_ip6, |
| 1261 | 'is_add': is_add, |
| 1262 | 'oui': oui, |
| 1263 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1264 | |
| 1265 | def ip_mroute_add_del(self, |
| 1266 | src_address, |
| 1267 | grp_address, |
| 1268 | grp_address_length, |
| 1269 | e_flags, |
| 1270 | next_hop_sw_if_index, |
| 1271 | i_flags, |
| 1272 | table_id=0, |
| 1273 | create_vrf_if_needed=0, |
| 1274 | is_add=1, |
| 1275 | is_ipv6=0, |
| 1276 | is_local=0): |
| 1277 | """ |
| 1278 | """ |
| 1279 | return self.api( |
| 1280 | self.papi.ip_mroute_add_del, |
| 1281 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 1282 | 'entry_flags': e_flags, |
| 1283 | 'itf_flags': i_flags, |
| 1284 | 'create_vrf_if_needed': create_vrf_if_needed, |
| 1285 | 'is_add': is_add, |
| 1286 | 'is_ipv6': is_ipv6, |
| 1287 | 'is_local': is_local, |
| 1288 | 'grp_address_length': grp_address_length, |
| 1289 | 'grp_address': grp_address, |
| 1290 | 'src_address': src_address}) |
| 1291 | |
| 1292 | def mfib_signal_dump(self): |
| 1293 | return self.api(self.papi.mfib_signal_dump, {}) |