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