Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1 | import fnmatch |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 2 | import os |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 3 | import time |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 4 | from collections import deque |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 5 | |
Paul Vinciguerra | 6c74617 | 2018-11-26 09:57:21 -0800 | [diff] [blame] | 6 | from six import moves |
Paul Vinciguerra | 8467919 | 2019-01-13 11:33:52 -0800 | [diff] [blame] | 7 | from vpp_papi import VPP, mac_pton |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 8 | from hook import Hook |
Paul Vinciguerra | f0cbcea | 2018-12-06 09:32:45 -0800 | [diff] [blame] | 9 | from vpp_l2 import L2_PORT_TYPE |
Paul Vinciguerra | 00671cf | 2018-11-25 12:47:04 -0800 | [diff] [blame] | 10 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 11 | # from vnet/vnet/mpls/mpls_types.h |
| 12 | MPLS_IETF_MAX_LABEL = 0xfffff |
| 13 | MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1 |
| 14 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 15 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 16 | class L2_VTR_OP: |
Eyal Bari | 284293a | 2017-06-06 14:18:55 +0300 | [diff] [blame] | 17 | L2_DISABLED = 0 |
| 18 | L2_PUSH_1 = 1 |
| 19 | L2_PUSH_2 = 2 |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 20 | L2_POP_1 = 3 |
Eyal Bari | 284293a | 2017-06-06 14:18:55 +0300 | [diff] [blame] | 21 | L2_POP_2 = 4 |
| 22 | L2_TRANSLATE_1_1 = 5 |
| 23 | L2_TRANSLATE_1_2 = 6 |
| 24 | L2_TRANSLATE_2_1 = 7 |
| 25 | L2_TRANSLATE_2_2 = 8 |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 26 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 27 | |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 28 | class QOS_SOURCE: |
| 29 | EXT = 0 |
| 30 | VLAN = 1 |
| 31 | MPLS = 2 |
| 32 | IP = 3 |
| 33 | |
| 34 | |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 35 | class SYSLOG_SEVERITY: |
| 36 | EMERG = 0 |
| 37 | ALERT = 1 |
| 38 | CRIT = 2 |
| 39 | ERR = 3 |
| 40 | WARN = 4 |
| 41 | NOTICE = 5 |
| 42 | INFO = 6 |
| 43 | DBG = 7 |
| 44 | |
| 45 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 46 | class UnexpectedApiReturnValueError(Exception): |
| 47 | """ exception raised when the API return value is unexpected """ |
| 48 | pass |
| 49 | |
| 50 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 51 | class VppPapiProvider(object): |
| 52 | """VPP-api provider using vpp-papi |
| 53 | |
| 54 | @property hook: hook object providing before and after api/cli hooks |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 55 | """ |
| 56 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 57 | _zero, _negative = range(2) |
| 58 | |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 59 | def __init__(self, name, shm_prefix, test_class, read_timeout): |
Klement Sekera | 277b89c | 2016-10-28 13:20:27 +0200 | [diff] [blame] | 60 | self.hook = Hook("vpp-papi-provider") |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 61 | self.name = name |
| 62 | self.shm_prefix = shm_prefix |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 63 | self.test_class = test_class |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 64 | self._expect_api_retval = self._zero |
| 65 | self._expect_stack = [] |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 66 | |
Klement Sekera | b8c72a4 | 2018-11-08 11:21:39 +0100 | [diff] [blame] | 67 | install_dir = os.getenv('VPP_INSTALL_PATH') |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 68 | |
Paul Vinciguerra | 04575c5 | 2019-01-13 10:26:05 -0800 | [diff] [blame] | 69 | # Vapi requires 'VPP_API_DIR', not set when run from Makefile. |
| 70 | if 'VPP_API_DIR' not in os.environ: |
| 71 | os.environ['VPP_API_DIR'] = os.getenv('VPP_INSTALL_PATH') |
| 72 | |
| 73 | self.vpp = VPP(logger=test_class.logger, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 74 | read_timeout=read_timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 75 | self._events = deque() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 76 | |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 77 | def __enter__(self): |
| 78 | return self |
| 79 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 80 | def assert_negative_api_retval(self): |
| 81 | """ Expect API failure - used with with, e.g.: |
| 82 | with self.vapi.assert_negative_api_retval(): |
| 83 | self.vapi.<api call expected to fail> |
| 84 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 85 | self._expect_stack.append(self._expect_api_retval) |
| 86 | self._expect_api_retval = self._negative |
| 87 | return self |
| 88 | |
Klement Sekera | 7d6afb3 | 2018-11-08 11:52:04 +0100 | [diff] [blame] | 89 | def assert_zero_api_retval(self): |
| 90 | """ Expect API success - used with with, e.g.: |
| 91 | with self.vapi.assert_negative_api_retval(): |
| 92 | self.vapi.<api call expected to succeed> |
| 93 | |
| 94 | note: this is useful only inside another with block |
| 95 | as success is the default expected value |
| 96 | """ |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 97 | self._expect_stack.append(self._expect_api_retval) |
| 98 | self._expect_api_retval = self._zero |
| 99 | return self |
| 100 | |
| 101 | def __exit__(self, exc_type, exc_value, traceback): |
| 102 | self._expect_api_retval = self._expect_stack.pop() |
| 103 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 104 | def register_hook(self, hook): |
| 105 | """Replace hook registration with new hook |
| 106 | |
| 107 | :param hook: |
| 108 | |
| 109 | """ |
| 110 | self.hook = hook |
| 111 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 112 | def collect_events(self): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 113 | """ Collect all events from the internal queue and clear the queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 114 | e = self._events |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 115 | self._events = deque() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 116 | return e |
| 117 | |
| 118 | def wait_for_event(self, timeout, name=None): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 119 | """ Wait for and return next event. """ |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 120 | if name: |
Klement Sekera | acb9b8e | 2017-02-14 02:55:31 +0100 | [diff] [blame] | 121 | self.test_class.logger.debug("Expecting event '%s' within %ss", |
| 122 | name, timeout) |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 123 | else: |
| 124 | self.test_class.logger.debug("Expecting event within %ss", |
| 125 | timeout) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 126 | if self._events: |
| 127 | self.test_class.logger.debug("Not waiting, event already queued") |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 128 | limit = time.time() + timeout |
| 129 | while time.time() < limit: |
| 130 | if self._events: |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 131 | e = self._events.popleft() |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 132 | if name and type(e).__name__ != name: |
| 133 | raise Exception( |
| 134 | "Unexpected event received: %s, expected: %s" % |
| 135 | (type(e).__name__, name)) |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 136 | self.test_class.logger.debug("Returning event %s:%s" % |
| 137 | (name, e)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 138 | return e |
| 139 | time.sleep(0) # yield |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 140 | raise Exception("Event did not occur within timeout") |
| 141 | |
| 142 | def __call__(self, name, event): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 143 | """ Enqueue event in the internal event queue. """ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 144 | # FIXME use the name instead of relying on type(e).__name__ ? |
| 145 | # FIXME #2 if this throws, it is eaten silently, Ole? |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 146 | self.test_class.logger.debug("New event: %s: %s" % (name, event)) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 147 | self._events.append(event) |
| 148 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 149 | def connect(self): |
| 150 | """Connect the API to VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 151 | self.vpp.connect(self.name, self.shm_prefix) |
| 152 | self.papi = self.vpp.api |
| 153 | self.vpp.register_event_callback(self) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 154 | |
| 155 | def disconnect(self): |
| 156 | """Disconnect the API from VPP""" |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 157 | self.vpp.disconnect() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 158 | |
| 159 | def api(self, api_fn, api_args, expected_retval=0): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 160 | """ Call API function and check it's return value. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 161 | Call the appropriate hooks before and after the API call |
| 162 | |
| 163 | :param api_fn: API function to call |
| 164 | :param api_args: tuple of API function arguments |
| 165 | :param expected_retval: Expected return value (Default value = 0) |
| 166 | :returns: reply from the API |
| 167 | |
| 168 | """ |
| 169 | self.hook.before_api(api_fn.__name__, api_args) |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 170 | reply = api_fn(**api_args) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 171 | if self._expect_api_retval == self._negative: |
| 172 | if hasattr(reply, 'retval') and reply.retval >= 0: |
| 173 | msg = "API call passed unexpectedly: expected negative "\ |
| 174 | "return value instead of %d in %s" % \ |
Paul Vinciguerra | 6c74617 | 2018-11-26 09:57:21 -0800 | [diff] [blame] | 175 | (reply.retval, moves.reprlib.repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 176 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 177 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 178 | elif self._expect_api_retval == self._zero: |
| 179 | if hasattr(reply, 'retval') and reply.retval != expected_retval: |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 180 | msg = "API call failed, expected %d return value instead "\ |
| 181 | "of %d in %s" % (expected_retval, reply.retval, |
Paul Vinciguerra | 6c74617 | 2018-11-26 09:57:21 -0800 | [diff] [blame] | 182 | moves.reprlib.repr(reply)) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 183 | self.test_class.logger.info(msg) |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 184 | raise UnexpectedApiReturnValueError(msg) |
Klement Sekera | e0545ef | 2017-01-25 08:00:40 +0100 | [diff] [blame] | 185 | else: |
| 186 | raise Exception("Internal error, unexpected value for " |
| 187 | "self._expect_api_retval %s" % |
| 188 | self._expect_api_retval) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 189 | self.hook.after_api(api_fn.__name__, api_args) |
| 190 | return reply |
| 191 | |
| 192 | def cli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 193 | """ Execute a CLI, calling the before/after hooks appropriately. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 194 | |
| 195 | :param cli: CLI to execute |
| 196 | :returns: CLI output |
| 197 | |
| 198 | """ |
| 199 | self.hook.before_cli(cli) |
| 200 | cli += '\n' |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 201 | r = self.papi.cli_inband(cmd=cli) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 202 | self.hook.after_cli(cli) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 203 | if hasattr(r, 'reply'): |
Ole Troan | 413f4a5 | 2018-11-28 11:36:05 +0100 | [diff] [blame] | 204 | return r.reply |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 205 | |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 206 | def ppcli(self, cli): |
Klement Sekera | e4504c6 | 2016-12-08 10:16:41 +0100 | [diff] [blame] | 207 | """ Helper method to print CLI command in case of info logging level. |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 208 | |
| 209 | :param cli: CLI to execute |
| 210 | :returns: CLI output |
| 211 | """ |
Ed Warnicke | b8ff5d6 | 2016-11-28 13:59:22 -0600 | [diff] [blame] | 212 | return cli + "\n" + str(self.cli(cli)) |
Jan | 49c0fca | 2016-10-26 15:44:27 +0200 | [diff] [blame] | 213 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 214 | def show_version(self): |
| 215 | """ """ |
Klement Sekera | 7112c54 | 2017-03-01 09:53:19 +0100 | [diff] [blame] | 216 | return self.api(self.papi.show_version, {}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 217 | |
| 218 | def pg_create_interface(self, pg_index): |
| 219 | """ |
| 220 | |
| 221 | :param pg_index: |
| 222 | |
| 223 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 224 | return self.api(self.papi.pg_create_interface, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 225 | {"interface_id": pg_index}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 226 | |
| 227 | def sw_interface_dump(self, filter=None): |
| 228 | """ |
| 229 | |
| 230 | :param filter: (Default value = None) |
| 231 | |
| 232 | """ |
| 233 | if filter is not None: |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 234 | args = {"name_filter_valid": 1, "name_filter": filter} |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 235 | else: |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 236 | args = {} |
| 237 | return self.api(self.papi.sw_interface_dump, args) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 238 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 239 | 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] | 240 | """ Set the IPvX Table-id for the Interface |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 241 | |
| 242 | :param sw_if_index: |
| 243 | :param is_ipv6: |
| 244 | :param table_id: |
| 245 | |
| 246 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 247 | return self.api(self.papi.sw_interface_set_table, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 248 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6, |
| 249 | 'vrf_id': table_id}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 250 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 251 | def sw_interface_get_table(self, sw_if_index, is_ipv6): |
| 252 | """ Get the IPvX Table-id for the Interface |
| 253 | |
| 254 | :param sw_if_index: |
| 255 | :param is_ipv6: |
| 256 | :return table_id |
| 257 | |
| 258 | """ |
| 259 | return self.api(self.papi.sw_interface_get_table, |
| 260 | {'sw_if_index': sw_if_index, 'is_ipv6': is_ipv6}) |
| 261 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 262 | def sw_interface_add_del_address(self, sw_if_index, addr, addr_len, |
| 263 | is_ipv6=0, is_add=1, del_all=0): |
| 264 | """ |
| 265 | |
| 266 | :param addr: param is_ipv6: (Default value = 0) |
| 267 | :param sw_if_index: |
| 268 | :param addr_len: |
| 269 | :param is_ipv6: (Default value = 0) |
| 270 | :param is_add: (Default value = 1) |
| 271 | :param del_all: (Default value = 0) |
| 272 | |
| 273 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 274 | return self.api(self.papi.sw_interface_add_del_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 275 | {'sw_if_index': sw_if_index, |
| 276 | 'is_add': is_add, |
| 277 | 'is_ipv6': is_ipv6, |
| 278 | 'del_all': del_all, |
| 279 | 'address_length': addr_len, |
| 280 | 'address': addr}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 281 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 282 | def ip_address_dump(self, sw_if_index, is_ipv6=0): |
| 283 | return self.api(self.papi.ip_address_dump, |
| 284 | {'sw_if_index': sw_if_index, |
| 285 | 'is_ipv6': is_ipv6}) |
| 286 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 287 | def sw_interface_set_unnumbered(self, sw_if_index, ip_sw_if_index, |
| 288 | is_add=1): |
| 289 | """ Set the Interface to be unnumbered |
| 290 | |
| 291 | :param is_add: (Default value = 1) |
| 292 | :param sw_if_index - interface That will be unnumbered |
| 293 | :param ip_sw_if_index - interface with an IP addres |
| 294 | |
| 295 | """ |
| 296 | return self.api(self.papi.sw_interface_set_unnumbered, |
| 297 | {'sw_if_index': ip_sw_if_index, |
| 298 | 'unnumbered_sw_if_index': sw_if_index, |
| 299 | 'is_add': is_add}) |
| 300 | |
Neale Ranns | 404d88e | 2018-08-08 06:37:33 -0700 | [diff] [blame] | 301 | def ip_unnumbered_dump(self, sw_if_index=0xffffffff): |
| 302 | return self.api(self.papi.ip_unnumbered_dump, |
| 303 | {'sw_if_index': sw_if_index}) |
| 304 | |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 305 | def sw_interface_enable_disable_mpls(self, sw_if_index, |
| 306 | is_enable=1): |
| 307 | """ |
| 308 | Enable/Disable MPLS on the interface |
| 309 | :param sw_if_index: |
| 310 | :param is_enable: (Default value = 1) |
| 311 | |
| 312 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 313 | return self.api(self.papi.sw_interface_set_mpls_enable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 314 | {'sw_if_index': sw_if_index, |
| 315 | 'enable': is_enable}) |
Neale Ranns | 8fe8cc2 | 2016-11-01 10:05:08 +0000 | [diff] [blame] | 316 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 317 | def sw_interface_ra_suppress(self, sw_if_index, suppress=1): |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 318 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 319 | {'sw_if_index': sw_if_index, |
| 320 | 'suppress': suppress}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 321 | |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 322 | def set_ip_flow_hash(self, |
| 323 | table_id, |
| 324 | src=1, |
| 325 | dst=1, |
| 326 | sport=1, |
| 327 | dport=1, |
| 328 | proto=1, |
| 329 | reverse=0, |
| 330 | is_ip6=0): |
| 331 | return self.api(self.papi.set_ip_flow_hash, |
| 332 | {'vrf_id': table_id, |
| 333 | 'src': src, |
| 334 | 'dst': dst, |
| 335 | 'dport': dport, |
| 336 | 'sport': sport, |
| 337 | 'proto': proto, |
| 338 | 'reverse': reverse, |
| 339 | 'is_ipv6': is_ip6}) |
| 340 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 341 | def ip6_nd_proxy(self, ip, sw_if_index, is_del=0): |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 342 | return self.api(self.papi.ip6nd_proxy_add_del, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 343 | {'ip': ip, |
Neale Ranns | 3f844d0 | 2017-02-18 00:03:54 -0800 | [diff] [blame] | 344 | 'sw_if_index': sw_if_index, |
| 345 | 'is_del': is_del}) |
| 346 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 347 | def ip6_sw_interface_ra_config(self, sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 348 | no, |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 349 | suppress, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 350 | send_unicast): |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 351 | return self.api(self.papi.sw_interface_ip6nd_ra_config, |
| 352 | {'sw_if_index': sw_if_index, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 353 | 'is_no': no, |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 354 | 'suppress': suppress, |
| 355 | 'send_unicast': send_unicast}) |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 356 | |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 357 | def ip6_sw_interface_ra_prefix(self, |
| 358 | sw_if_index, |
| 359 | address, |
| 360 | address_length, |
| 361 | use_default=0, |
| 362 | no_advertise=0, |
| 363 | off_link=0, |
| 364 | no_autoconfig=0, |
| 365 | no_onlink=0, |
| 366 | is_no=0, |
| 367 | val_lifetime=0xffffffff, |
| 368 | pref_lifetime=0xffffffff): |
| 369 | return self.api(self.papi.sw_interface_ip6nd_ra_prefix, |
| 370 | {'sw_if_index': sw_if_index, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 371 | 'prefix': { |
| 372 | 'address': address, |
| 373 | 'address_length': address_length, |
| 374 | }, |
Neale Ranns | 87df12d | 2017-02-18 08:16:41 -0800 | [diff] [blame] | 375 | 'use_default': use_default, |
| 376 | 'no_advertise': no_advertise, |
| 377 | 'off_link': off_link, |
| 378 | 'no_autoconfig': no_autoconfig, |
| 379 | 'no_onlink': no_onlink, |
| 380 | 'is_no': is_no, |
| 381 | 'val_lifetime': val_lifetime, |
| 382 | 'pref_lifetime': pref_lifetime}) |
| 383 | |
Neale Ranns | 7515228 | 2017-01-09 01:00:45 -0800 | [diff] [blame] | 384 | def ip6_sw_interface_enable_disable(self, sw_if_index, enable): |
| 385 | """ |
| 386 | Enable/Disable An interface for IPv6 |
| 387 | """ |
| 388 | return self.api(self.papi.sw_interface_ip6_enable_disable, |
| 389 | {'sw_if_index': sw_if_index, |
| 390 | 'enable': enable}) |
| 391 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 392 | def vxlan_add_del_tunnel( |
| 393 | self, |
| 394 | src_addr, |
| 395 | dst_addr, |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 396 | mcast_sw_if_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 397 | is_add=1, |
| 398 | is_ipv6=0, |
| 399 | encap_vrf_id=0, |
| 400 | decap_next_index=0xFFFFFFFF, |
Jon Loeliger | 3d460bd | 2018-02-01 16:36:12 -0600 | [diff] [blame] | 401 | vni=0, |
| 402 | instance=0xFFFFFFFF): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 403 | """ |
| 404 | |
| 405 | :param dst_addr: |
| 406 | :param src_addr: |
| 407 | :param is_add: (Default value = 1) |
| 408 | :param is_ipv6: (Default value = 0) |
| 409 | :param encap_vrf_id: (Default value = 0) |
| 410 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 411 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 412 | :param vni: (Default value = 0) |
Jon Loeliger | 3d460bd | 2018-02-01 16:36:12 -0600 | [diff] [blame] | 413 | :param instance: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 414 | |
| 415 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 416 | return self.api(self.papi.vxlan_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 417 | {'is_add': is_add, |
| 418 | 'is_ipv6': is_ipv6, |
| 419 | 'src_address': src_addr, |
| 420 | 'dst_address': dst_addr, |
| 421 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 422 | 'encap_vrf_id': encap_vrf_id, |
| 423 | 'decap_next_index': decap_next_index, |
Jon Loeliger | 3d460bd | 2018-02-01 16:36:12 -0600 | [diff] [blame] | 424 | 'vni': vni, |
| 425 | 'instance': instance}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 426 | |
Marco Varlese | b598f1d | 2017-09-19 14:25:28 +0200 | [diff] [blame] | 427 | def geneve_add_del_tunnel( |
| 428 | self, |
| 429 | local_addr, |
| 430 | remote_addr, |
| 431 | mcast_sw_if_index=0xFFFFFFFF, |
| 432 | is_add=1, |
| 433 | is_ipv6=0, |
| 434 | encap_vrf_id=0, |
| 435 | decap_next_index=0xFFFFFFFF, |
| 436 | vni=0): |
| 437 | """ |
| 438 | |
| 439 | :param remote_addr: |
| 440 | :param local_addr: |
| 441 | :param is_add: (Default value = 1) |
| 442 | :param is_ipv6: (Default value = 0) |
| 443 | :param encap_vrf_id: (Default value = 0) |
| 444 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 445 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 446 | :param vni: (Default value = 0) |
| 447 | |
| 448 | """ |
| 449 | return self.api(self.papi.geneve_add_del_tunnel, |
| 450 | {'is_add': is_add, |
| 451 | 'is_ipv6': is_ipv6, |
| 452 | 'local_address': local_addr, |
| 453 | 'remote_address': remote_addr, |
| 454 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 455 | 'encap_vrf_id': encap_vrf_id, |
| 456 | 'decap_next_index': decap_next_index, |
| 457 | 'vni': vni}) |
| 458 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 459 | def bridge_domain_add_del(self, bd_id, flood=1, uu_flood=1, forward=1, |
| 460 | learn=1, arp_term=0, is_add=1): |
| 461 | """Create/delete bridge domain. |
| 462 | |
| 463 | :param int bd_id: Bridge domain index. |
| 464 | :param int flood: Enable/disable bcast/mcast flooding in the BD. |
| 465 | (Default value = 1) |
| 466 | :param int uu_flood: Enable/disable unknown unicast flood in the BD. |
| 467 | (Default value = 1) |
| 468 | :param int forward: Enable/disable forwarding on all interfaces in |
| 469 | the BD. (Default value = 1) |
| 470 | :param int learn: Enable/disable learning on all interfaces in the BD. |
| 471 | (Default value = 1) |
| 472 | :param int arp_term: Enable/disable arp termination in the BD. |
| 473 | (Default value = 1) |
| 474 | :param int is_add: Add or delete flag. (Default value = 1) |
| 475 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 476 | return self.api(self.papi.bridge_domain_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 477 | {'bd_id': bd_id, |
| 478 | 'flood': flood, |
| 479 | 'uu_flood': uu_flood, |
| 480 | 'forward': forward, |
| 481 | 'learn': learn, |
| 482 | 'arp_term': arp_term, |
| 483 | 'is_add': is_add}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 484 | |
Eyal Bari | c86e592 | 2017-07-02 18:33:16 +0300 | [diff] [blame] | 485 | def bd_ip_mac_add_del(self, bd_id, mac, ip, is_ipv6=0, is_add=1): |
| 486 | return self.api(self.papi.bd_ip_mac_add_del, |
| 487 | {'bd_id': bd_id, |
| 488 | 'is_add': is_add, |
Neale Ranns | 4d5b917 | 2018-10-24 02:57:49 -0700 | [diff] [blame] | 489 | 'ip': ip, |
| 490 | 'mac': mac}) |
Eyal Bari | c86e592 | 2017-07-02 18:33:16 +0300 | [diff] [blame] | 491 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 492 | def bd_ip_mac_dump(self, bd_id): |
| 493 | return self.api(self.papi.bd_ip_mac_dump, |
| 494 | {'bd_id': bd_id}) |
| 495 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 496 | def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"): |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 497 | return self.api(self.papi.want_ip4_arp_events, |
| 498 | {'enable_disable': enable_disable, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 499 | 'ip': ip, |
Eyal Bari | 2019748 | 2017-09-13 12:29:08 +0300 | [diff] [blame] | 500 | 'pid': os.getpid(), }) |
| 501 | |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 502 | def want_ip6_nd_events(self, enable_disable=1, ip="::"): |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 503 | return self.api(self.papi.want_ip6_nd_events, |
| 504 | {'enable_disable': enable_disable, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 505 | 'ip': ip, |
Eyal Bari | c125ecc | 2017-09-20 11:29:17 +0300 | [diff] [blame] | 506 | 'pid': os.getpid(), }) |
| 507 | |
Juraj Sloboda | 4b9669d | 2018-01-15 10:39:21 +0100 | [diff] [blame] | 508 | def want_ip6_ra_events(self, enable_disable=1): |
| 509 | return self.api(self.papi.want_ip6_ra_events, |
| 510 | {'enable_disable': enable_disable, |
| 511 | 'pid': os.getpid(), }) |
| 512 | |
| 513 | def ip6nd_send_router_solicitation(self, sw_if_index, irt=1, mrt=120, |
| 514 | mrc=0, mrd=0): |
| 515 | return self.api(self.papi.ip6nd_send_router_solicitation, |
| 516 | {'irt': irt, |
| 517 | 'mrt': mrt, |
| 518 | 'mrc': mrc, |
| 519 | 'mrd': mrd, |
| 520 | 'sw_if_index': sw_if_index}) |
| 521 | |
Juraj Sloboda | c037423 | 2018-02-01 15:18:49 +0100 | [diff] [blame] | 522 | def ip6_nd_address_autoconfig(self, sw_if_index, enable, |
| 523 | install_default_routes): |
| 524 | return self.api(self.papi.ip6_nd_address_autoconfig, |
| 525 | {'sw_if_index': sw_if_index, |
| 526 | 'enable': enable, |
| 527 | 'install_default_routes': install_default_routes}) |
| 528 | |
Juraj Sloboda | b3f9050 | 2018-10-04 15:15:16 +0200 | [diff] [blame] | 529 | def want_interface_events(self, enable_disable=1): |
| 530 | return self.api(self.papi.want_interface_events, |
| 531 | {'enable_disable': enable_disable, |
| 532 | 'pid': os.getpid(), }) |
| 533 | |
Eyal Bari | 24db0ec | 2017-09-27 21:43:51 +0300 | [diff] [blame] | 534 | def want_macs_learn_events(self, enable_disable=1, scan_delay=0, |
| 535 | max_macs_in_event=0, learn_limit=0): |
| 536 | return self.api(self.papi.want_l2_macs_events, |
| 537 | {'enable_disable': enable_disable, |
| 538 | 'scan_delay': scan_delay, |
| 539 | 'max_macs_in_event': max_macs_in_event, |
| 540 | 'learn_limit': learn_limit, |
| 541 | 'pid': os.getpid(), }) |
| 542 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 543 | def want_dhcp6_reply_events(self, enable_disable=1): |
| 544 | return self.api(self.papi.want_dhcp6_reply_events, |
| 545 | {'enable_disable': enable_disable, |
| 546 | 'pid': os.getpid()}) |
| 547 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 548 | def want_dhcp6_pd_reply_events(self, enable_disable=1): |
| 549 | return self.api(self.papi.want_dhcp6_pd_reply_events, |
| 550 | {'enable_disable': enable_disable, |
| 551 | 'pid': os.getpid()}) |
| 552 | |
| 553 | def dhcp6_clients_enable_disable(self, enable=1): |
| 554 | return self.api(self.papi.dhcp6_clients_enable_disable, |
| 555 | {'enable': enable}) |
| 556 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 557 | def dhcp6_send_client_message(self, msg_type, sw_if_index, T1, T2, |
| 558 | addresses, server_index=0xFFFFFFFF, |
| 559 | irt=0, mrt=0, mrc=1, mrd=0, stop=0, |
| 560 | ): |
| 561 | return self.api(self.papi.dhcp6_send_client_message, |
| 562 | {'sw_if_index': sw_if_index, |
| 563 | 'server_index': server_index, |
| 564 | 'irt': irt, |
| 565 | 'mrt': mrt, |
| 566 | 'mrc': mrc, |
| 567 | 'mrd': mrd, |
| 568 | 'stop': stop, |
| 569 | 'msg_type': msg_type, |
| 570 | 'T1': T1, |
| 571 | 'T2': T2, |
| 572 | 'n_addresses': len(addresses), |
| 573 | 'addresses': addresses}) |
| 574 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 575 | def dhcp6_pd_send_client_message(self, msg_type, sw_if_index, T1, T2, |
| 576 | prefixes, server_index=0xFFFFFFFF, |
| 577 | irt=0, mrt=0, mrc=1, mrd=0, stop=0, |
| 578 | ): |
| 579 | return self.api(self.papi.dhcp6_pd_send_client_message, |
| 580 | {'sw_if_index': sw_if_index, |
| 581 | 'server_index': server_index, |
| 582 | 'irt': irt, |
| 583 | 'mrt': mrt, |
| 584 | 'mrc': mrc, |
| 585 | 'mrd': mrd, |
| 586 | 'stop': stop, |
| 587 | 'msg_type': msg_type, |
| 588 | 'T1': T1, |
| 589 | 'T2': T2, |
| 590 | 'n_prefixes': len(prefixes), |
| 591 | 'prefixes': prefixes}) |
| 592 | |
Juraj Sloboda | dd3b8f7 | 2018-05-04 14:20:06 +0200 | [diff] [blame] | 593 | def dhcp6_client_enable_disable(self, sw_if_index, prefix_group='', |
| 594 | enable=1): |
| 595 | return self.api(self.papi.dhcp6_client_enable_disable, |
| 596 | {'sw_if_index': sw_if_index, |
| 597 | 'enable': enable}) |
| 598 | |
Juraj Sloboda | 81119e8 | 2018-05-25 14:02:20 +0200 | [diff] [blame] | 599 | def dhcp6_pd_client_enable_disable(self, sw_if_index, prefix_group='', |
| 600 | enable=1): |
| 601 | return self.api(self.papi.dhcp6_pd_client_enable_disable, |
| 602 | {'sw_if_index': sw_if_index, |
| 603 | 'prefix_group': prefix_group, |
| 604 | 'enable': enable}) |
| 605 | |
| 606 | def ip6_add_del_address_using_prefix(self, sw_if_index, address, |
| 607 | prefix_length, prefix_group, |
| 608 | is_add=1): |
| 609 | return self.api(self.papi.ip6_add_del_address_using_prefix, |
| 610 | {'sw_if_index': sw_if_index, |
| 611 | 'prefix_group': prefix_group, |
| 612 | 'address': address, |
| 613 | 'prefix_length': prefix_length, |
| 614 | 'is_add': is_add}) |
| 615 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 616 | def l2fib_add_del(self, mac, bd_id, sw_if_index, is_add=1, static_mac=0, |
| 617 | filter_mac=0, bvi_mac=0): |
| 618 | """Create/delete L2 FIB entry. |
| 619 | |
| 620 | :param str mac: MAC address to create FIB entry for. |
| 621 | :param int bd_id: Bridge domain index. |
| 622 | :param int sw_if_index: Software interface index of the interface. |
| 623 | :param int is_add: Add or delete flag. (Default value = 1) |
| 624 | :param int static_mac: Set to 1 to create static MAC entry. |
| 625 | (Default value = 0) |
| 626 | :param int filter_mac: Set to 1 to drop packet that's source or |
| 627 | destination MAC address contains defined MAC address. |
| 628 | (Default value = 0) |
| 629 | :param int bvi_mac: Set to 1 to create entry that points to BVI |
| 630 | interface. (Default value = 0) |
| 631 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 632 | return self.api(self.papi.l2fib_add_del, |
Ole Troan | 8006c6a | 2018-12-17 12:02:26 +0100 | [diff] [blame] | 633 | {'mac': mac, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 634 | 'bd_id': bd_id, |
| 635 | 'sw_if_index': sw_if_index, |
| 636 | 'is_add': is_add, |
| 637 | 'static_mac': static_mac, |
| 638 | 'filter_mac': filter_mac, |
| 639 | 'bvi_mac': bvi_mac}) |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 640 | |
Eyal Bari | 93b503e | 2017-05-15 10:13:15 +0300 | [diff] [blame] | 641 | def l2fib_flush_int(self, sw_if_index): |
| 642 | """Flush L2 FIB entries for sw_if_index. |
| 643 | |
| 644 | :param int sw_if_index: Software interface index of the interface. |
| 645 | """ |
| 646 | return self.api(self.papi.l2fib_flush_int, |
| 647 | {'sw_if_index': sw_if_index}) |
| 648 | |
| 649 | def l2fib_flush_bd(self, bd_id): |
| 650 | """Flush L2 FIB entries for bd_id. |
| 651 | |
| 652 | :param int sw_if_index: Bridge Domain id. |
| 653 | """ |
| 654 | return self.api(self.papi.l2fib_flush_bd, |
| 655 | {'bd_id': bd_id}) |
| 656 | |
| 657 | def l2fib_flush_all(self): |
| 658 | """Flush all L2 FIB. |
| 659 | """ |
| 660 | return self.api(self.papi.l2fib_flush_all, {}) |
| 661 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 662 | def l2_fib_table_dump(self, bd_id): |
| 663 | """ Dump the L2 FIB """ |
| 664 | return self.api(self.papi.l2_fib_table_dump, |
| 665 | {'bd_id': bd_id}) |
| 666 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 667 | def sw_interface_set_l2_bridge(self, sw_if_index, bd_id, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 668 | shg=0, port_type=L2_PORT_TYPE.NORMAL, |
| 669 | enable=1): |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 670 | """Add/remove interface to/from bridge domain. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 671 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 672 | :param int sw_if_index: Software interface index of the interface. |
| 673 | :param int bd_id: Bridge domain index. |
| 674 | :param int shg: Split-horizon group index. (Default value = 0) |
| 675 | :param int bvi: Set interface as a bridge group virtual interface. |
| 676 | (Default value = 0) |
| 677 | :param int enable: Add or remove interface. (Default value = 1) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 678 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 679 | return self.api(self.papi.sw_interface_set_l2_bridge, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 680 | {'rx_sw_if_index': sw_if_index, |
| 681 | 'bd_id': bd_id, |
| 682 | 'shg': shg, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 683 | 'port_type': port_type, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 684 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 685 | |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 686 | def bridge_flags(self, bd_id, is_set, feature_bitmap): |
Chris Luke | d042194 | 2018-04-10 15:19:54 -0400 | [diff] [blame] | 687 | """Enable/disable required feature of the bridge domain with defined |
| 688 | ID. |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 689 | |
| 690 | :param int bd_id: Bridge domain ID. |
| 691 | :param int is_set: Set to 1 to enable, set to 0 to disable the feature. |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 692 | :param int flags: Bitmap value of the feature to be set: |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 693 | - learn (1 << 0), |
| 694 | - forward (1 << 1), |
| 695 | - flood (1 << 2), |
| 696 | - uu-flood (1 << 3) or |
| 697 | - arp-term (1 << 4). |
| 698 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 699 | return self.api(self.papi.bridge_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 700 | {'bd_id': bd_id, |
| 701 | 'is_set': is_set, |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 702 | 'flags': feature_bitmap}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 703 | |
| 704 | def bridge_domain_dump(self, bd_id=0): |
| 705 | """ |
| 706 | |
| 707 | :param int bd_id: Bridge domain ID. (Default value = 0 => dump of all |
| 708 | existing bridge domains returned) |
| 709 | :return: Dictionary of bridge domain(s) data. |
| 710 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 711 | return self.api(self.papi.bridge_domain_dump, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 712 | {'bd_id': bd_id}) |
Jan | 00dad12 | 2016-11-29 10:04:53 +0100 | [diff] [blame] | 713 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 714 | def sw_interface_set_l2_xconnect(self, rx_sw_if_index, tx_sw_if_index, |
| 715 | enable): |
| 716 | """Create or delete unidirectional cross-connect from Tx interface to |
| 717 | Rx interface. |
| 718 | |
Jan | 4af521d | 2016-11-15 17:05:00 +0100 | [diff] [blame] | 719 | :param int rx_sw_if_index: Software interface index of Rx interface. |
| 720 | :param int tx_sw_if_index: Software interface index of Tx interface. |
| 721 | :param int enable: Create cross-connect if equal to 1, delete |
| 722 | cross-connect if equal to 0. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 723 | |
| 724 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 725 | return self.api(self.papi.sw_interface_set_l2_xconnect, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 726 | {'rx_sw_if_index': rx_sw_if_index, |
| 727 | 'tx_sw_if_index': tx_sw_if_index, |
| 728 | 'enable': enable}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 729 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 730 | def sw_interface_set_l2_tag_rewrite( |
| 731 | self, |
| 732 | sw_if_index, |
| 733 | vtr_oper, |
| 734 | push=0, |
| 735 | tag1=0, |
| 736 | tag2=0): |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 737 | """L2 interface vlan tag rewrite configure request |
| 738 | :param client_index - opaque cookie to identify the sender |
| 739 | :param context - sender context, to match reply w/ request |
| 740 | :param sw_if_index - interface the operation is applied to |
| 741 | :param vtr_op - Choose from l2_vtr_op_t enum values |
| 742 | :param push_dot1q - first pushed flag dot1q id set, else dot1ad |
| 743 | :param tag1 - Needed for any push or translate vtr op |
| 744 | :param tag2 - Needed for any push 2 or translate x-2 vtr ops |
| 745 | |
| 746 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 747 | return self.api(self.papi.l2_interface_vlan_tag_rewrite, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 748 | {'sw_if_index': sw_if_index, |
| 749 | 'vtr_op': vtr_oper, |
| 750 | 'push_dot1q': push, |
| 751 | 'tag1': tag1, |
| 752 | 'tag2': tag2}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 753 | |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 754 | def sw_interface_set_l2_emulation( |
| 755 | self, |
| 756 | sw_if_index, |
| 757 | enable=1): |
| 758 | """L2 Emulation |
| 759 | :param sw_if_index - interface the operation is applied to |
| 760 | |
| 761 | """ |
| 762 | return self.api(self.papi.l2_emulation, |
| 763 | {'sw_if_index': sw_if_index, |
| 764 | 'enable': enable}) |
| 765 | |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 766 | def sw_interface_set_ip_directed_broadcast( |
| 767 | self, |
| 768 | sw_if_index, |
| 769 | enable=1): |
| 770 | """IP Directed broadcast |
| 771 | :param sw_if_index - interface the operation is applied to |
| 772 | |
| 773 | """ |
| 774 | return self.api(self.papi.sw_interface_set_ip_directed_broadcast, |
| 775 | {'sw_if_index': sw_if_index, |
| 776 | 'enable': enable}) |
| 777 | |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 778 | def sw_interface_set_flags(self, sw_if_index, admin_up_down): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 779 | """ |
| 780 | |
| 781 | :param admin_up_down: |
| 782 | :param sw_if_index: |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 783 | |
| 784 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 785 | return self.api(self.papi.sw_interface_set_flags, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 786 | {'sw_if_index': sw_if_index, |
Neale Ranns | a07bd70 | 2017-08-07 07:53:49 -0700 | [diff] [blame] | 787 | 'admin_up_down': admin_up_down}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 788 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 789 | def sw_interface_set_mtu(self, sw_if_index, mtu=[0, 0, 0, 0]): |
Neale Ranns | ffd78d1 | 2018-02-09 06:05:16 -0800 | [diff] [blame] | 790 | """ |
| 791 | :param sw_if_index: |
| 792 | :param mtu: |
| 793 | |
| 794 | """ |
| 795 | return self.api(self.papi.sw_interface_set_mtu, |
| 796 | {'sw_if_index': sw_if_index, |
| 797 | 'mtu': mtu}) |
| 798 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 799 | def sw_interface_set_promiscuous(self, sw_if_index, enable): |
| 800 | """ |
| 801 | :param sw_if_index: |
| 802 | :param enable: |
| 803 | |
| 804 | """ |
| 805 | return self.api(self.papi.sw_interface_set_promiscuous, |
| 806 | {'sw_if_index': sw_if_index, |
| 807 | 'enable': enable}) |
| 808 | |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 809 | def sw_interface_set_mac_address(self, sw_if_index, mac): |
| 810 | return self.api(self.papi.sw_interface_set_mac_address, |
| 811 | {'sw_if_index': sw_if_index, |
| 812 | 'mac_address': mac}) |
| 813 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 814 | def create_subif(self, sw_if_index, sub_id, outer_vlan, inner_vlan, |
| 815 | no_tags=0, one_tag=0, two_tags=0, dot1ad=0, exact_match=0, |
| 816 | default_sub=0, outer_vlan_id_any=0, inner_vlan_id_any=0): |
| 817 | """Create subinterface |
| 818 | from vpe.api: set dot1ad = 0 for dot1q, set dot1ad = 1 for dot1ad |
| 819 | |
| 820 | :param sub_id: param inner_vlan: |
| 821 | :param sw_if_index: |
| 822 | :param outer_vlan: |
| 823 | :param inner_vlan: |
| 824 | :param no_tags: (Default value = 0) |
| 825 | :param one_tag: (Default value = 0) |
| 826 | :param two_tags: (Default value = 0) |
| 827 | :param dot1ad: (Default value = 0) |
| 828 | :param exact_match: (Default value = 0) |
| 829 | :param default_sub: (Default value = 0) |
| 830 | :param outer_vlan_id_any: (Default value = 0) |
| 831 | :param inner_vlan_id_any: (Default value = 0) |
| 832 | |
| 833 | """ |
| 834 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 835 | self.papi.create_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 836 | {'sw_if_index': sw_if_index, |
| 837 | 'sub_id': sub_id, |
| 838 | 'no_tags': no_tags, |
| 839 | 'one_tag': one_tag, |
| 840 | 'two_tags': two_tags, |
| 841 | 'dot1ad': dot1ad, |
| 842 | 'exact_match': exact_match, |
| 843 | 'default_sub': default_sub, |
| 844 | 'outer_vlan_id_any': outer_vlan_id_any, |
| 845 | 'inner_vlan_id_any': inner_vlan_id_any, |
| 846 | 'outer_vlan_id': outer_vlan, |
| 847 | 'inner_vlan_id': inner_vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 848 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 849 | def create_p2pethernet_subif(self, sw_if_index, remote_mac, subif_id): |
| 850 | """Create p2p ethernet subinterface |
| 851 | |
| 852 | :param sw_if_index: main (parent) interface |
| 853 | :param remote_mac: client (remote) mac address |
| 854 | |
| 855 | """ |
| 856 | return self.api( |
| 857 | self.papi.p2p_ethernet_add, |
| 858 | {'parent_if_index': sw_if_index, |
| 859 | 'remote_mac': remote_mac, |
| 860 | 'subif_id': subif_id}) |
| 861 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 862 | def delete_subif(self, sw_if_index): |
| 863 | """Delete subinterface |
| 864 | |
| 865 | :param sw_if_index: |
| 866 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 867 | return self.api(self.papi.delete_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 868 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 869 | |
Pavel Kotucek | 15ac81c | 2017-06-20 14:00:26 +0200 | [diff] [blame] | 870 | def delete_p2pethernet_subif(self, sw_if_index, remote_mac): |
| 871 | """Delete p2p ethernet subinterface |
| 872 | |
| 873 | :param sw_if_index: main (parent) interface |
| 874 | :param remote_mac: client (remote) mac address |
| 875 | |
| 876 | """ |
| 877 | return self.api( |
| 878 | self.papi.p2p_ethernet_del, |
| 879 | {'parent_if_index': sw_if_index, |
| 880 | 'remote_mac': remote_mac}) |
| 881 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 882 | def create_vlan_subif(self, sw_if_index, vlan): |
| 883 | """ |
| 884 | |
| 885 | :param vlan: |
| 886 | :param sw_if_index: |
| 887 | |
| 888 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 889 | return self.api(self.papi.create_vlan_subif, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 890 | {'sw_if_index': sw_if_index, |
| 891 | 'vlan_id': vlan}) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 892 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 893 | def create_loopback(self, mac=''): |
| 894 | """ |
| 895 | |
| 896 | :param mac: (Optional) |
| 897 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 898 | return self.api(self.papi.create_loopback, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 899 | {'mac_address': mac}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 900 | |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 901 | def delete_loopback(self, sw_if_index): |
| 902 | return self.api(self.papi.delete_loopback, |
| 903 | {'sw_if_index': sw_if_index, }) |
| 904 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 905 | def ip_table_add_del(self, |
| 906 | table_id, |
| 907 | is_add=1, |
| 908 | is_ipv6=0): |
| 909 | """ |
| 910 | |
| 911 | :param table_id |
| 912 | :param is_add: (Default value = 1) |
| 913 | :param is_ipv6: (Default value = 0) |
| 914 | |
| 915 | """ |
| 916 | |
| 917 | return self.api( |
| 918 | self.papi.ip_table_add_del, |
| 919 | {'table_id': table_id, |
| 920 | 'is_add': is_add, |
| 921 | 'is_ipv6': is_ipv6}) |
| 922 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 923 | def ip_add_del_route( |
| 924 | self, |
| 925 | dst_address, |
| 926 | dst_address_length, |
| 927 | next_hop_address, |
| 928 | next_hop_sw_if_index=0xFFFFFFFF, |
| 929 | table_id=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 930 | next_hop_table_id=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 931 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 932 | next_hop_n_out_labels=0, |
| 933 | next_hop_out_label_stack=[], |
| 934 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 935 | next_hop_id=0xFFFFFFFF, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 936 | is_resolve_host=0, |
| 937 | is_resolve_attached=0, |
| 938 | classify_table_index=0xFFFFFFFF, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 939 | is_add=1, |
| 940 | is_drop=0, |
Juraj Sloboda | 86a2c57 | 2016-10-27 10:44:25 +0200 | [diff] [blame] | 941 | is_unreach=0, |
| 942 | is_prohibit=0, |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 943 | is_ipv6=0, |
| 944 | is_local=0, |
| 945 | is_classify=0, |
| 946 | is_multipath=0, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 947 | is_dvr=0, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 948 | is_udp_encap=0, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 949 | is_source_lookup=0): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 950 | """ |
| 951 | |
| 952 | :param dst_address_length: |
| 953 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 954 | :param dst_address: |
| 955 | :param next_hop_address: |
| 956 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 957 | :param vrf_id: (Default value = 0) |
| 958 | :param lookup_in_vrf: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 959 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 960 | :param is_add: (Default value = 1) |
| 961 | :param is_drop: (Default value = 0) |
| 962 | :param is_ipv6: (Default value = 0) |
| 963 | :param is_local: (Default value = 0) |
| 964 | :param is_classify: (Default value = 0) |
| 965 | :param is_multipath: (Default value = 0) |
| 966 | :param is_resolve_host: (Default value = 0) |
| 967 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 968 | :param is_dvr: (Default value = 0) |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 969 | :param is_source_lookup: (Default value = 0) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 970 | :param next_hop_weight: (Default value = 1) |
| 971 | |
| 972 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 973 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 974 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 975 | self.papi.ip_add_del_route, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 976 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 977 | 'table_id': table_id, |
| 978 | 'classify_table_index': classify_table_index, |
| 979 | 'next_hop_table_id': next_hop_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 980 | 'is_add': is_add, |
| 981 | 'is_drop': is_drop, |
| 982 | 'is_unreach': is_unreach, |
| 983 | 'is_prohibit': is_prohibit, |
| 984 | 'is_ipv6': is_ipv6, |
| 985 | 'is_local': is_local, |
| 986 | 'is_classify': is_classify, |
| 987 | 'is_multipath': is_multipath, |
| 988 | 'is_resolve_host': is_resolve_host, |
| 989 | 'is_resolve_attached': is_resolve_attached, |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 990 | 'is_dvr': is_dvr, |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 991 | 'is_source_lookup': is_source_lookup, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 992 | 'is_udp_encap': is_udp_encap, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 993 | 'next_hop_weight': next_hop_weight, |
| 994 | 'dst_address_length': dst_address_length, |
| 995 | 'dst_address': dst_address, |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 996 | 'next_hop_id': next_hop_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 997 | 'next_hop_address': next_hop_address, |
| 998 | 'next_hop_n_out_labels': next_hop_n_out_labels, |
| 999 | 'next_hop_via_label': next_hop_via_label, |
| 1000 | 'next_hop_out_label_stack': next_hop_out_label_stack}) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1001 | |
Matej Klotton | 16a14cd | 2016-12-07 15:09:13 +0100 | [diff] [blame] | 1002 | def ip_fib_dump(self): |
| 1003 | return self.api(self.papi.ip_fib_dump, {}) |
| 1004 | |
Jan Gelety | 057bb8c | 2016-12-20 17:32:45 +0100 | [diff] [blame] | 1005 | def ip6_fib_dump(self): |
| 1006 | return self.api(self.papi.ip6_fib_dump, {}) |
| 1007 | |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1008 | def ip_neighbor_add_del(self, |
| 1009 | sw_if_index, |
| 1010 | mac_address, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1011 | ip_address, |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1012 | is_add=1, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1013 | flags=0): |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1014 | """ Add neighbor MAC to IPv4 or IPv6 address. |
| 1015 | |
| 1016 | :param sw_if_index: |
| 1017 | :param mac_address: |
| 1018 | :param dst_address: |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1019 | :param is_add: (Default value = 1) |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1020 | :param flags: (Default value = 0/NONE) |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1021 | """ |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1022 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1023 | self.papi.ip_neighbor_add_del, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1024 | { |
| 1025 | 'is_add': is_add, |
| 1026 | 'neighbor': { |
| 1027 | 'sw_if_index': sw_if_index, |
| 1028 | 'flags': flags, |
| 1029 | 'mac_address': mac_address, |
| 1030 | 'ip_address': ip_address |
| 1031 | } |
| 1032 | } |
Matej Klotton | 0178d52 | 2016-11-04 11:11:44 +0100 | [diff] [blame] | 1033 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 1034 | |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 1035 | def ip_neighbor_dump(self, |
| 1036 | sw_if_index, |
| 1037 | is_ipv6=0): |
| 1038 | """ Return IP neighbor dump. |
| 1039 | |
| 1040 | :param sw_if_index: |
| 1041 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1042 | """ |
| 1043 | |
| 1044 | return self.api( |
| 1045 | self.papi.ip_neighbor_dump, |
| 1046 | {'is_ipv6': is_ipv6, |
| 1047 | 'sw_if_index': sw_if_index |
| 1048 | } |
| 1049 | ) |
| 1050 | |
| 1051 | def proxy_arp_add_del(self, |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1052 | low, |
| 1053 | hi, |
| 1054 | table_id=0, |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 1055 | is_add=1): |
| 1056 | """ Config Proxy Arp Range. |
| 1057 | |
| 1058 | :param low_address: Start address in the rnage to Proxy for |
| 1059 | :param hi_address: End address in the rnage to Proxy for |
| 1060 | :param vrf_id: The VRF/table in which to proxy |
| 1061 | """ |
| 1062 | |
| 1063 | return self.api( |
| 1064 | self.papi.proxy_arp_add_del, |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 1065 | {'proxy': |
| 1066 | { |
Neale Ranns | 3702930 | 2018-08-10 05:30:06 -0700 | [diff] [blame] | 1067 | 'table_id': table_id, |
| 1068 | 'low': low, |
| 1069 | 'hi': hi, |
Neale Ranns | 0053de6 | 2018-05-22 08:40:52 -0700 | [diff] [blame] | 1070 | }, |
| 1071 | 'is_add': is_add}) |
Neale Ranns | 39f9d8b | 2017-02-16 21:57:05 -0800 | [diff] [blame] | 1072 | |
| 1073 | def proxy_arp_intfc_enable_disable(self, |
| 1074 | sw_if_index, |
| 1075 | is_enable=1): |
| 1076 | """ Enable/Disable an interface for proxy ARP requests |
| 1077 | |
| 1078 | :param sw_if_index: Interface |
| 1079 | :param enable_disable: Enable/Disable |
| 1080 | """ |
| 1081 | |
| 1082 | return self.api( |
| 1083 | self.papi.proxy_arp_intfc_enable_disable, |
| 1084 | {'sw_if_index': sw_if_index, |
| 1085 | 'enable_disable': is_enable |
| 1086 | } |
| 1087 | ) |
| 1088 | |
Jan | e546d3b | 2016-12-08 13:10:03 +0100 | [diff] [blame] | 1089 | def reset_vrf(self, |
| 1090 | vrf_id, |
| 1091 | is_ipv6=0, |
| 1092 | ): |
| 1093 | """ Reset VRF (remove all routes etc.) request. |
| 1094 | |
| 1095 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 1096 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1097 | """ |
| 1098 | |
| 1099 | return self.api( |
| 1100 | self.papi.reset_vrf, |
| 1101 | {'vrf_id': vrf_id, |
| 1102 | 'is_ipv6': is_ipv6, |
| 1103 | } |
| 1104 | ) |
| 1105 | |
| 1106 | def reset_fib(self, |
| 1107 | vrf_id, |
| 1108 | is_ipv6=0, |
| 1109 | ): |
| 1110 | """ Reset VRF (remove all routes etc.) request. |
| 1111 | |
| 1112 | :param int vrf_id: ID of the FIB table / VRF to reset. |
| 1113 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1114 | """ |
| 1115 | |
| 1116 | return self.api( |
| 1117 | self.papi.reset_fib, |
| 1118 | {'vrf_id': vrf_id, |
| 1119 | 'is_ipv6': is_ipv6, |
| 1120 | } |
| 1121 | ) |
| 1122 | |
| 1123 | def ip_dump(self, |
| 1124 | is_ipv6=0, |
| 1125 | ): |
| 1126 | """ Return IP dump. |
| 1127 | |
| 1128 | :param int is_ipv6: 1 for IPv6 neighbor, 0 for IPv4. (Default = 0) |
| 1129 | """ |
| 1130 | |
| 1131 | return self.api( |
| 1132 | self.papi.ip_dump, |
| 1133 | {'is_ipv6': is_ipv6, |
| 1134 | } |
| 1135 | ) |
| 1136 | |
Klement Sekera | 7bb873a | 2016-11-18 07:38:42 +0100 | [diff] [blame] | 1137 | def sw_interface_span_enable_disable( |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 1138 | self, sw_if_index_from, sw_if_index_to, state=1, is_l2=0): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 1139 | """ |
| 1140 | |
| 1141 | :param sw_if_index_from: |
| 1142 | :param sw_if_index_to: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 1143 | :param state: |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 1144 | :param is_l2: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 1145 | """ |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1146 | return self.api(self.papi.sw_interface_span_enable_disable, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1147 | {'sw_if_index_from': sw_if_index_from, |
| 1148 | 'sw_if_index_to': sw_if_index_to, |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 1149 | 'state': state, |
| 1150 | 'is_l2': is_l2, |
| 1151 | }) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1152 | |
| 1153 | def gre_tunnel_add_del(self, |
| 1154 | src_address, |
| 1155 | dst_address, |
| 1156 | outer_fib_id=0, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1157 | tunnel_type=0, |
| 1158 | instance=0xFFFFFFFF, |
| 1159 | session_id=0, |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1160 | is_add=1, |
| 1161 | is_ip6=0): |
| 1162 | """ Add a GRE tunnel |
| 1163 | |
| 1164 | :param src_address: |
| 1165 | :param dst_address: |
| 1166 | :param outer_fib_id: (Default value = 0) |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1167 | :param tunnel_type: (Default value = 0) |
| 1168 | :param instance: (Default value = 0xFFFFFFFF) |
| 1169 | :param session_id: (Defalt value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1170 | :param is_add: (Default value = 1) |
| 1171 | :param is_ipv6: (Default value = 0) |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1172 | """ |
| 1173 | |
| 1174 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1175 | self.papi.gre_add_del_tunnel, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1176 | {'is_add': is_add, |
| 1177 | 'is_ipv6': is_ip6, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1178 | 'tunnel_type': tunnel_type, |
| 1179 | 'instance': instance, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1180 | 'src_address': src_address, |
| 1181 | 'dst_address': dst_address, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 1182 | 'outer_fib_id': outer_fib_id, |
| 1183 | 'session_id': session_id} |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 1184 | ) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1185 | |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 1186 | def udp_encap_add(self, |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 1187 | src_ip, |
| 1188 | dst_ip, |
| 1189 | src_port, |
| 1190 | dst_port, |
| 1191 | table_id=0): |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1192 | """ Add a GRE tunnel |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1193 | :param src_ip: |
| 1194 | :param dst_ip: |
| 1195 | :param src_port: |
| 1196 | :param dst_port: |
| 1197 | :param outer_fib_id: (Default value = 0) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1198 | """ |
| 1199 | |
| 1200 | return self.api( |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 1201 | self.papi.udp_encap_add, |
| 1202 | { |
| 1203 | 'udp_encap': { |
Neale Ranns | d0df49f | 2018-08-08 01:06:40 -0700 | [diff] [blame] | 1204 | 'src_ip': src_ip, |
| 1205 | 'dst_ip': dst_ip, |
| 1206 | 'src_port': src_port, |
| 1207 | 'dst_port': dst_port, |
| 1208 | 'table_id': table_id |
| 1209 | } |
| 1210 | }) |
| 1211 | |
| 1212 | def udp_encap_del(self, id): |
| 1213 | return self.api(self.papi.udp_encap_del, {'id': id}) |
Neale Ranns | 810086d | 2017-11-05 16:26:46 -0800 | [diff] [blame] | 1214 | |
| 1215 | def udp_encap_dump(self): |
| 1216 | return self.api(self.papi.udp_encap_dump, {}) |
| 1217 | |
Neale Ranns | 43b1f44 | 2018-03-20 01:47:35 -0700 | [diff] [blame] | 1218 | def want_udp_encap_stats(self, enable=1): |
| 1219 | return self.api(self.papi.want_udp_encap_stats, |
| 1220 | {'enable': enable, |
| 1221 | 'pid': os.getpid()}) |
| 1222 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1223 | def mpls_fib_dump(self): |
| 1224 | return self.api(self.papi.mpls_fib_dump, {}) |
| 1225 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 1226 | def mpls_table_add_del( |
| 1227 | self, |
| 1228 | table_id, |
| 1229 | is_add=1): |
| 1230 | """ |
| 1231 | |
| 1232 | :param table_id |
| 1233 | :param is_add: (Default value = 1) |
| 1234 | |
| 1235 | """ |
| 1236 | |
| 1237 | return self.api( |
| 1238 | self.papi.mpls_table_add_del, |
| 1239 | {'mt_table_id': table_id, |
| 1240 | 'mt_is_add': is_add}) |
| 1241 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1242 | def mpls_route_add_del( |
| 1243 | self, |
| 1244 | label, |
| 1245 | eos, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1246 | next_hop_proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1247 | next_hop_address, |
| 1248 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1249 | table_id=0, |
| 1250 | next_hop_table_id=0, |
| 1251 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1252 | next_hop_n_out_labels=0, |
| 1253 | next_hop_out_label_stack=[], |
| 1254 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1255 | is_resolve_host=0, |
| 1256 | is_resolve_attached=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1257 | is_interface_rx=0, |
| 1258 | is_rpf_id=0, |
| 1259 | is_multicast=0, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1260 | is_add=1, |
| 1261 | is_drop=0, |
| 1262 | is_multipath=0, |
| 1263 | classify_table_index=0xFFFFFFFF, |
Marek Gradzki | 0164a06 | 2017-10-13 10:22:59 +0200 | [diff] [blame] | 1264 | is_classify=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1265 | """ |
| 1266 | |
| 1267 | :param dst_address_length: |
| 1268 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1269 | :param dst_address: |
| 1270 | :param next_hop_address: |
| 1271 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1272 | :param vrf_id: (Default value = 0) |
| 1273 | :param lookup_in_vrf: (Default value = 0) |
| 1274 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1275 | :param is_add: (Default value = 1) |
| 1276 | :param is_drop: (Default value = 0) |
| 1277 | :param is_ipv6: (Default value = 0) |
| 1278 | :param is_local: (Default value = 0) |
| 1279 | :param is_classify: (Default value = 0) |
| 1280 | :param is_multipath: (Default value = 0) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1281 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1282 | :param is_resolve_host: (Default value = 0) |
| 1283 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1284 | :param next_hop_weight: (Default value = 1) |
| 1285 | |
| 1286 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1287 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1288 | self.papi.mpls_route_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1289 | {'mr_label': label, |
| 1290 | 'mr_eos': eos, |
| 1291 | 'mr_table_id': table_id, |
| 1292 | 'mr_classify_table_index': classify_table_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1293 | 'mr_is_add': is_add, |
| 1294 | 'mr_is_classify': is_classify, |
| 1295 | 'mr_is_multipath': is_multipath, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1296 | 'mr_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1297 | 'mr_is_resolve_host': is_resolve_host, |
| 1298 | 'mr_is_resolve_attached': is_resolve_attached, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1299 | 'mr_is_interface_rx': is_interface_rx, |
| 1300 | 'mr_is_rpf_id': is_rpf_id, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 1301 | 'mr_next_hop_proto': next_hop_proto, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1302 | 'mr_next_hop_weight': next_hop_weight, |
| 1303 | 'mr_next_hop': next_hop_address, |
| 1304 | 'mr_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1305 | 'mr_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1306 | 'mr_next_hop_table_id': next_hop_table_id, |
| 1307 | 'mr_next_hop_via_label': next_hop_via_label, |
| 1308 | 'mr_next_hop_out_label_stack': next_hop_out_label_stack}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1309 | |
| 1310 | def mpls_ip_bind_unbind( |
| 1311 | self, |
| 1312 | label, |
| 1313 | dst_address, |
| 1314 | dst_address_length, |
| 1315 | table_id=0, |
| 1316 | ip_table_id=0, |
| 1317 | is_ip4=1, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1318 | is_bind=1): |
| 1319 | """ |
| 1320 | """ |
| 1321 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1322 | self.papi.mpls_ip_bind_unbind, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1323 | {'mb_mpls_table_id': table_id, |
| 1324 | 'mb_label': label, |
| 1325 | 'mb_ip_table_id': ip_table_id, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1326 | 'mb_is_bind': is_bind, |
| 1327 | 'mb_is_ip4': is_ip4, |
| 1328 | 'mb_address_length': dst_address_length, |
| 1329 | 'mb_address': dst_address}) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1330 | |
| 1331 | def mpls_tunnel_add_del( |
| 1332 | self, |
| 1333 | tun_sw_if_index, |
| 1334 | next_hop_proto_is_ip4, |
| 1335 | next_hop_address, |
| 1336 | next_hop_sw_if_index=0xFFFFFFFF, |
| 1337 | next_hop_table_id=0, |
| 1338 | next_hop_weight=1, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1339 | next_hop_n_out_labels=0, |
| 1340 | next_hop_out_label_stack=[], |
| 1341 | next_hop_via_label=MPLS_LABEL_INVALID, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1342 | is_add=1, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1343 | l2_only=0, |
| 1344 | is_multicast=0): |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1345 | """ |
| 1346 | |
| 1347 | :param dst_address_length: |
| 1348 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1349 | :param dst_address: |
| 1350 | :param next_hop_address: |
| 1351 | :param next_hop_sw_if_index: (Default value = 0xFFFFFFFF) |
| 1352 | :param vrf_id: (Default value = 0) |
| 1353 | :param lookup_in_vrf: (Default value = 0) |
| 1354 | :param classify_table_index: (Default value = 0xFFFFFFFF) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1355 | :param is_add: (Default value = 1) |
| 1356 | :param is_drop: (Default value = 0) |
| 1357 | :param is_ipv6: (Default value = 0) |
| 1358 | :param is_local: (Default value = 0) |
| 1359 | :param is_classify: (Default value = 0) |
| 1360 | :param is_multipath: (Default value = 0) |
| 1361 | :param is_resolve_host: (Default value = 0) |
| 1362 | :param is_resolve_attached: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1363 | :param next_hop_weight: (Default value = 1) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1364 | :param is_multicast: (Default value = 0) |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1365 | |
| 1366 | """ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 1367 | return self.api( |
Ole Troan | 7e3a875 | 2016-12-05 10:27:09 +0100 | [diff] [blame] | 1368 | self.papi.mpls_tunnel_add_del, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1369 | {'mt_sw_if_index': tun_sw_if_index, |
| 1370 | 'mt_is_add': is_add, |
| 1371 | 'mt_l2_only': l2_only, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1372 | 'mt_is_multicast': is_multicast, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1373 | 'mt_next_hop_proto_is_ip4': next_hop_proto_is_ip4, |
| 1374 | 'mt_next_hop_weight': next_hop_weight, |
| 1375 | 'mt_next_hop': next_hop_address, |
| 1376 | 'mt_next_hop_n_out_labels': next_hop_n_out_labels, |
| 1377 | 'mt_next_hop_sw_if_index': next_hop_sw_if_index, |
| 1378 | 'mt_next_hop_table_id': next_hop_table_id, |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 1379 | 'mt_next_hop_via_label': next_hop_via_label, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1380 | 'mt_next_hop_out_label_stack': next_hop_out_label_stack}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1381 | |
Neale Ranns | f5fa5ae | 2018-09-26 05:07:25 -0700 | [diff] [blame] | 1382 | def mpls_tunnel_dump(self, sw_if_index=0xffffffff): |
| 1383 | return self.api(self.papi.mpls_tunnel_dump, |
| 1384 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 6a30b5f | 2018-09-25 07:22:36 -0700 | [diff] [blame] | 1385 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1386 | def nat44_interface_add_del_feature( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1387 | self, |
| 1388 | sw_if_index, |
| 1389 | is_inside=1, |
| 1390 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1391 | """Enable/disable NAT44 feature on the interface |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1392 | |
| 1393 | :param sw_if_index: Software index of the interface |
| 1394 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1395 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1396 | """ |
| 1397 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1398 | self.papi.nat44_interface_add_del_feature, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1399 | {'is_add': is_add, |
| 1400 | 'is_inside': is_inside, |
| 1401 | 'sw_if_index': sw_if_index}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1402 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1403 | def nat44_interface_add_del_output_feature( |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1404 | self, |
| 1405 | sw_if_index, |
| 1406 | is_inside=1, |
| 1407 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1408 | """Enable/disable NAT44 output feature on the interface |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1409 | |
| 1410 | :param sw_if_index: Software index of the interface |
| 1411 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 1412 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1413 | """ |
| 1414 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1415 | self.papi.nat44_interface_add_del_output_feature, |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1416 | {'is_add': is_add, |
| 1417 | 'is_inside': is_inside, |
| 1418 | 'sw_if_index': sw_if_index}) |
| 1419 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1420 | def nat44_add_del_static_mapping( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1421 | self, |
| 1422 | local_ip, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1423 | external_ip=0, |
| 1424 | external_sw_if_index=0xFFFFFFFF, |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1425 | local_port=0, |
| 1426 | external_port=0, |
| 1427 | addr_only=1, |
| 1428 | vrf_id=0, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1429 | protocol=0, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1430 | twice_nat=0, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1431 | self_twice_nat=0, |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1432 | out2in_only=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1433 | tag="", |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1434 | is_add=1): |
| 1435 | """Add/delete NAT44 static mapping |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1436 | |
| 1437 | :param local_ip: Local IP address |
| 1438 | :param external_ip: External IP address |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1439 | :param external_sw_if_index: External interface instead of IP address |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1440 | :param local_port: Local port number (Default value = 0) |
| 1441 | :param external_port: External port number (Default value = 0) |
| 1442 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1443 | :param vrf_id: VRF ID |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1444 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1445 | :param twice_nat: 1 if translate external host address and port |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1446 | :param self_twice_nat: 1 if translate external host address and port |
| 1447 | whenever external host address equals |
| 1448 | local address of internal host |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1449 | :param out2in_only: if 1 rule is matching only out2in direction |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1450 | :param tag: Opaque string tag |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1451 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1452 | """ |
| 1453 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1454 | self.papi.nat44_add_del_static_mapping, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1455 | {'is_add': is_add, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1456 | 'addr_only': addr_only, |
| 1457 | 'local_ip_address': local_ip, |
| 1458 | 'external_ip_address': external_ip, |
| 1459 | 'local_port': local_port, |
| 1460 | 'external_port': external_port, |
Matus Fabian | 36532bd | 2017-01-23 23:42:28 -0800 | [diff] [blame] | 1461 | 'external_sw_if_index': external_sw_if_index, |
Matus Fabian | 09d96f4 | 2017-02-02 01:43:00 -0800 | [diff] [blame] | 1462 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1463 | 'protocol': protocol, |
Matus Fabian | e82488f | 2018-01-18 03:38:45 -0800 | [diff] [blame] | 1464 | 'twice_nat': twice_nat, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1465 | 'self_twice_nat': self_twice_nat, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1466 | 'out2in_only': out2in_only, |
| 1467 | 'tag': tag}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1468 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1469 | def nat44_add_del_identity_mapping( |
| 1470 | self, |
| 1471 | ip='0', |
| 1472 | sw_if_index=0xFFFFFFFF, |
| 1473 | port=0, |
| 1474 | addr_only=1, |
| 1475 | vrf_id=0, |
| 1476 | protocol=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1477 | tag='', |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1478 | is_add=1): |
| 1479 | """Add/delete NAT44 identity mapping |
| 1480 | |
| 1481 | :param ip: IP address (Default value = 0) |
| 1482 | :param sw_if_index: Interface instead of IP address |
| 1483 | :param port: Port number (Default value = 0) |
| 1484 | :param addr_only: 1 if address only mapping, 0 if address and port |
| 1485 | :param vrf_id: VRF ID |
| 1486 | :param protocol: IP protocol (Default value = 0) |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1487 | :param tag: Opaque string tag |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1488 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1489 | """ |
| 1490 | return self.api( |
| 1491 | self.papi.nat44_add_del_identity_mapping, |
| 1492 | {'is_add': is_add, |
| 1493 | 'addr_only': addr_only, |
| 1494 | 'ip_address': ip, |
| 1495 | 'port': port, |
| 1496 | 'sw_if_index': sw_if_index, |
| 1497 | 'vrf_id': vrf_id, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1498 | 'tag': tag, |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1499 | 'protocol': protocol}) |
| 1500 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1501 | def nat44_add_del_address_range( |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1502 | self, |
| 1503 | first_ip_address, |
| 1504 | last_ip_address, |
| 1505 | is_add=1, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1506 | vrf_id=0xFFFFFFFF, |
| 1507 | twice_nat=0): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1508 | """Add/del NAT44 address range |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1509 | |
| 1510 | :param first_ip_address: First IP address |
| 1511 | :param last_ip_address: Last IP address |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1512 | :param vrf_id: VRF id for the address range |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1513 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1514 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1515 | """ |
| 1516 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1517 | self.papi.nat44_add_del_address_range, |
| 1518 | {'first_ip_address': first_ip_address, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1519 | 'last_ip_address': last_ip_address, |
Juraj Sloboda | eab38d9 | 2017-03-06 19:55:21 -0800 | [diff] [blame] | 1520 | 'vrf_id': vrf_id, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1521 | 'twice_nat': twice_nat, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1522 | 'is_add': is_add}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1523 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1524 | def nat44_address_dump(self): |
| 1525 | """Dump NAT44 addresses |
| 1526 | :return: Dictionary of NAT44 addresses |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1527 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1528 | return self.api(self.papi.nat44_address_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1529 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1530 | def nat44_interface_dump(self): |
| 1531 | """Dump interfaces with NAT44 feature |
| 1532 | :return: Dictionary of interfaces with NAT44 feature |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1533 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1534 | return self.api(self.papi.nat44_interface_dump, {}) |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1535 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1536 | def nat44_interface_output_feature_dump(self): |
| 1537 | """Dump interfaces with NAT44 output feature |
| 1538 | :return: Dictionary of interfaces with NAT44 output feature |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1539 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1540 | return self.api(self.papi.nat44_interface_output_feature_dump, {}) |
Matus Fabian | 93d84c9 | 2017-07-19 08:06:01 -0700 | [diff] [blame] | 1541 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1542 | def nat44_static_mapping_dump(self): |
| 1543 | """Dump NAT44 static mappings |
| 1544 | :return: Dictionary of NAT44 static mappings |
Matus Fabian | de88675 | 2016-12-07 03:38:19 -0800 | [diff] [blame] | 1545 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1546 | return self.api(self.papi.nat44_static_mapping_dump, {}) |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1547 | |
Matus Fabian | ab7a805 | 2017-11-28 04:29:41 -0800 | [diff] [blame] | 1548 | def nat44_identity_mapping_dump(self): |
| 1549 | """Dump NAT44 identity mappings |
| 1550 | :return: Dictionary of NAT44 identity mappings |
| 1551 | """ |
| 1552 | return self.api(self.papi.nat44_identity_mapping_dump, {}) |
| 1553 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1554 | def nat_show_config(self): |
| 1555 | """Show NAT plugin config |
| 1556 | :return: NAT plugin config parameters |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1557 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1558 | return self.api(self.papi.nat_show_config, {}) |
Matus Fabian | 9902fcd | 2016-12-21 23:58:46 -0800 | [diff] [blame] | 1559 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1560 | def nat44_add_interface_addr( |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1561 | self, |
| 1562 | sw_if_index, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1563 | twice_nat=0, |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1564 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1565 | """Add/del NAT44 address from interface |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1566 | |
| 1567 | :param sw_if_index: Software index of the interface |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1568 | :param twice_nat: twice NAT address for extenal hosts |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1569 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1570 | """ |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1571 | return self.api( |
| 1572 | self.papi.nat44_add_del_interface_addr, |
| 1573 | {'is_add': is_add, |
| 1574 | 'sw_if_index': sw_if_index, |
| 1575 | 'twice_nat': twice_nat}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1576 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1577 | def nat44_interface_addr_dump(self): |
| 1578 | """Dump NAT44 addresses interfaces |
| 1579 | :return: Dictionary of NAT44 addresses interfaces |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1580 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1581 | return self.api(self.papi.nat44_interface_addr_dump, {}) |
Matus Fabian | 8bf68e8 | 2017-01-12 04:24:35 -0800 | [diff] [blame] | 1582 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1583 | def nat_ipfix( |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1584 | self, |
| 1585 | domain_id=1, |
| 1586 | src_port=4739, |
| 1587 | enable=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1588 | """Enable/disable NAT IPFIX logging |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1589 | |
| 1590 | :param domain_id: Observation domain ID (Default value = 1) |
| 1591 | :param src_port: Source port number (Default value = 4739) |
| 1592 | :param enable: 1 if enable, 0 if disable (Default value = 1) |
| 1593 | """ |
| 1594 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1595 | self.papi.nat_ipfix_enable_disable, |
Matus Fabian | eea28d7 | 2017-01-13 04:15:54 -0800 | [diff] [blame] | 1596 | {'domain_id': domain_id, |
| 1597 | 'src_port': src_port, |
| 1598 | 'enable': enable}) |
| 1599 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1600 | def nat44_user_session_dump( |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1601 | self, |
| 1602 | ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1603 | vrf_id): |
| 1604 | """Dump NAT44 user's sessions |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1605 | |
| 1606 | :param ip_address: ip adress of the user to be dumped |
| 1607 | :param cpu_index: cpu_index on which the user is |
| 1608 | :param vrf_id: VRF ID |
| 1609 | :return: Dictionary of S-NAT sessions |
| 1610 | """ |
| 1611 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1612 | self.papi.nat44_user_session_dump, |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1613 | {'ip_address': ip_address, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1614 | 'vrf_id': vrf_id}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1615 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1616 | def nat44_user_dump(self): |
| 1617 | """Dump NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1618 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1619 | :return: Dictionary of NAT44 users |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1620 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1621 | return self.api(self.papi.nat44_user_dump, {}) |
magalik | 23caa88 | 2017-02-08 23:25:45 -0800 | [diff] [blame] | 1622 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1623 | def nat44_add_del_lb_static_mapping( |
| 1624 | self, |
| 1625 | external_addr, |
| 1626 | external_port, |
| 1627 | protocol, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1628 | twice_nat=0, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1629 | self_twice_nat=0, |
Matus Fabian | 240b5ef | 2018-01-11 04:09:17 -0800 | [diff] [blame] | 1630 | out2in_only=0, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1631 | tag='', |
Matus Fabian | ea5b5be | 2018-09-03 05:02:23 -0700 | [diff] [blame] | 1632 | affinity=0, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1633 | local_num=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 1634 | locals=[], |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1635 | is_add=1): |
| 1636 | """Add/delete NAT44 load balancing static mapping |
| 1637 | |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1638 | :param twice_nat: 1 if translate external host address and port |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1639 | :param tag: Opaque string tag |
Matus Fabian | ea5b5be | 2018-09-03 05:02:23 -0700 | [diff] [blame] | 1640 | :param affinity: if 0 disabled, otherwise client IP affinity timeout |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1641 | :param is_add - 1 if add, 0 if delete |
| 1642 | """ |
| 1643 | return self.api( |
| 1644 | self.papi.nat44_add_del_lb_static_mapping, |
| 1645 | {'is_add': is_add, |
| 1646 | 'external_addr': external_addr, |
| 1647 | 'external_port': external_port, |
| 1648 | 'protocol': protocol, |
Matus Fabian | b932d26 | 2017-12-18 05:38:24 -0800 | [diff] [blame] | 1649 | 'twice_nat': twice_nat, |
Juraj Sloboda | 1e5c07d | 2018-04-10 13:51:54 +0200 | [diff] [blame] | 1650 | 'self_twice_nat': self_twice_nat, |
Matus Fabian | 240b5ef | 2018-01-11 04:09:17 -0800 | [diff] [blame] | 1651 | 'out2in_only': out2in_only, |
Matus Fabian | 5f22499 | 2018-01-25 21:59:16 -0800 | [diff] [blame] | 1652 | 'tag': tag, |
Matus Fabian | ea5b5be | 2018-09-03 05:02:23 -0700 | [diff] [blame] | 1653 | 'affinity': affinity, |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1654 | 'local_num': local_num, |
| 1655 | 'locals': locals}) |
| 1656 | |
Matus Fabian | b686508 | 2018-12-06 03:11:09 -0800 | [diff] [blame] | 1657 | def nat44_lb_static_mapping_add_del_local( |
| 1658 | self, |
| 1659 | external_addr, |
| 1660 | external_port, |
| 1661 | local_addr, |
| 1662 | local_port, |
| 1663 | protocol, |
| 1664 | probability, |
| 1665 | vrf_id=0, |
| 1666 | is_add=1): |
| 1667 | """Add/delete NAT44 load-balancing static mapping rule backend |
| 1668 | |
| 1669 | :param external_addr: external IPv4 address of the servic |
| 1670 | :param external_port: external L4 port number of the service |
| 1671 | :param local_addr: IPv4 address of the internal node |
| 1672 | :param local_port: L4 port number of the internal node |
| 1673 | :param protocol: IP protocol number |
| 1674 | :param probability: probability of the internal node |
| 1675 | :param vrf_id: VRF id of the internal node |
| 1676 | :param is_add: 1 if add, 0 if delete |
| 1677 | """ |
| 1678 | return self.api( |
| 1679 | self.papi.nat44_lb_static_mapping_add_del_local, |
| 1680 | {'is_add': is_add, |
| 1681 | 'external_addr': external_addr, |
| 1682 | 'external_port': external_port, |
| 1683 | 'local': { |
| 1684 | 'addr': local_addr, |
| 1685 | 'port': local_port, |
| 1686 | 'probability': probability, |
| 1687 | 'vrf_id': vrf_id}, |
| 1688 | 'protocol': protocol}) |
| 1689 | |
Matus Fabian | 704018c | 2017-09-04 02:17:18 -0700 | [diff] [blame] | 1690 | def nat44_lb_static_mapping_dump(self): |
| 1691 | """Dump NAT44 load balancing static mappings |
| 1692 | |
| 1693 | :return: Dictionary of NAT44 load balancing static mapping |
| 1694 | """ |
| 1695 | return self.api(self.papi.nat44_lb_static_mapping_dump, {}) |
| 1696 | |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1697 | def nat44_del_session( |
| 1698 | self, |
| 1699 | addr, |
| 1700 | port, |
| 1701 | protocol, |
| 1702 | vrf_id=0, |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 1703 | is_in=1, |
| 1704 | ext_host_address=None, |
| 1705 | ext_host_port=0): |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1706 | """Delete NAT44 session |
| 1707 | |
| 1708 | :param addr: IPv4 address |
| 1709 | :param por: port number |
| 1710 | :param protocol: IP protocol number |
| 1711 | :param vrf_id: VRF ID |
| 1712 | :param is_in: 1 if inside network addres and port pari, 0 if outside |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 1713 | :param ext_host_address: external host IPv4 address |
| 1714 | :param ext_host_port: external host port |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1715 | """ |
Matus Fabian | 70a26ac | 2018-05-14 06:20:28 -0700 | [diff] [blame] | 1716 | if ext_host_address is None: |
| 1717 | return self.api( |
| 1718 | self.papi.nat44_del_session, |
| 1719 | {'address': addr, |
| 1720 | 'port': port, |
| 1721 | 'protocol': protocol, |
| 1722 | 'vrf_id': vrf_id, |
| 1723 | 'is_in': is_in}) |
| 1724 | else: |
| 1725 | return self.api( |
| 1726 | self.papi.nat44_del_session, |
| 1727 | {'address': addr, |
| 1728 | 'port': port, |
| 1729 | 'protocol': protocol, |
| 1730 | 'vrf_id': vrf_id, |
| 1731 | 'is_in': is_in, |
| 1732 | 'ext_host_valid': 1, |
| 1733 | 'ext_host_address': ext_host_address, |
| 1734 | 'ext_host_port': ext_host_port}) |
Matus Fabian | 5ba86f7 | 2017-10-26 03:37:38 -0700 | [diff] [blame] | 1735 | |
Juraj Sloboda | 7b92979 | 2017-11-23 13:20:48 +0100 | [diff] [blame] | 1736 | def nat44_forwarding_enable_disable( |
| 1737 | self, |
| 1738 | enable): |
| 1739 | """Enable/disable forwarding for NAT44 |
| 1740 | |
| 1741 | :param enable: 1 for enable, 0 for disable |
| 1742 | """ |
| 1743 | return self.api( |
| 1744 | self.papi.nat44_forwarding_enable_disable, |
| 1745 | {'enable': enable}) |
| 1746 | |
Matus Fabian | efcd1e9 | 2017-08-15 06:59:19 -0700 | [diff] [blame] | 1747 | def nat_set_reass( |
| 1748 | self, |
| 1749 | timeout=2, |
| 1750 | max_reass=1024, |
| 1751 | max_frag=5, |
| 1752 | drop_frag=0, |
| 1753 | is_ip6=0): |
| 1754 | """Set NAT virtual fragmentation reassembly |
| 1755 | |
| 1756 | :param timeout: reassembly timeout (Default 2sec) |
| 1757 | :param max_reass: maximum concurrent reassemblies (Default 1024) |
| 1758 | :param max_frag: maximum fragmets per reassembly (Default 5) |
| 1759 | :param drop_frag: if 0 translate fragments, otherwise drop fragments |
| 1760 | :param is_ip6: 1 if IPv6, 0 if IPv4 |
| 1761 | """ |
| 1762 | return self.api( |
| 1763 | self.papi.nat_set_reass, |
| 1764 | {'timeout': timeout, |
| 1765 | 'max_reass': max_reass, |
| 1766 | 'max_frag': max_frag, |
| 1767 | 'drop_frag': drop_frag, |
| 1768 | 'is_ip6': is_ip6}) |
| 1769 | |
| 1770 | def nat_get_reass(self): |
| 1771 | """Get NAT virtual fragmentation reassembly configuration |
| 1772 | |
| 1773 | :return: NAT virtual fragmentation reassembly configuration |
| 1774 | """ |
| 1775 | return self.api(self.papi.nat_get_reass, {}) |
| 1776 | |
| 1777 | def nat_reass_dump(self): |
| 1778 | """Dump NAT virtual fragmentation reassemblies |
| 1779 | |
| 1780 | :return: Dictionary of NAT virtual fragmentation reassemblies |
| 1781 | """ |
| 1782 | return self.api(self.papi.nat_reass_dump, {}) |
| 1783 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1784 | def nat_det_add_del_map( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1785 | self, |
| 1786 | in_addr, |
| 1787 | in_plen, |
| 1788 | out_addr, |
| 1789 | out_plen, |
| 1790 | is_add=1): |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1791 | """Add/delete deterministic NAT mapping |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1792 | |
| 1793 | :param is_add - 1 if add, 0 if delete |
| 1794 | :param in_addr - inside IP address |
| 1795 | :param in_plen - inside IP address prefix length |
| 1796 | :param out_addr - outside IP address |
| 1797 | :param out_plen - outside IP address prefix length |
| 1798 | """ |
| 1799 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1800 | self.papi.nat_det_add_del_map, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1801 | {'is_add': is_add, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1802 | 'is_nat44': 1, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1803 | 'in_addr': in_addr, |
| 1804 | 'in_plen': in_plen, |
| 1805 | 'out_addr': out_addr, |
| 1806 | 'out_plen': out_plen}) |
| 1807 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1808 | def nat_det_forward( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1809 | self, |
| 1810 | in_addr): |
| 1811 | """Get outside address and port range from inside address |
| 1812 | |
| 1813 | :param in_addr - inside IP address |
| 1814 | """ |
| 1815 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1816 | self.papi.nat_det_forward, |
| 1817 | {'in_addr': in_addr, |
| 1818 | 'is_nat44': 1}) |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1819 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1820 | def nat_det_reverse( |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1821 | self, |
| 1822 | out_addr, |
| 1823 | out_port): |
| 1824 | """Get inside address from outside address and port |
| 1825 | |
| 1826 | :param out_addr - outside IP address |
| 1827 | :param out_port - outside port |
| 1828 | """ |
| 1829 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1830 | self.papi.nat_det_reverse, |
Matus Fabian | 066f034 | 2017-02-10 03:48:01 -0800 | [diff] [blame] | 1831 | {'out_addr': out_addr, |
| 1832 | 'out_port': out_port}) |
| 1833 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1834 | def nat_det_map_dump(self): |
| 1835 | """Dump deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1836 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1837 | :return: Dictionary of deterministic NAT mappings |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1838 | """ |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1839 | return self.api(self.papi.nat_det_map_dump, {}) |
Martin | 17a75cb | 2017-03-08 05:53:20 -0800 | [diff] [blame] | 1840 | |
Matus Fabian | 878c646 | 2018-08-23 00:33:35 -0700 | [diff] [blame] | 1841 | def nat_set_timeouts( |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1842 | self, |
| 1843 | udp=300, |
| 1844 | tcp_established=7440, |
| 1845 | tcp_transitory=240, |
| 1846 | icmp=60): |
Matus Fabian | 878c646 | 2018-08-23 00:33:35 -0700 | [diff] [blame] | 1847 | """Set values of timeouts for NAT sessions (in seconds) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1848 | |
| 1849 | :param udp - UDP timeout (Default value = 300) |
| 1850 | :param tcp_established - TCP established timeout (Default value = 7440) |
| 1851 | :param tcp_transitory - TCP transitory timeout (Default value = 240) |
| 1852 | :param icmp - ICMP timeout (Default value = 60) |
| 1853 | """ |
| 1854 | return self.api( |
Matus Fabian | 878c646 | 2018-08-23 00:33:35 -0700 | [diff] [blame] | 1855 | self.papi.nat_set_timeouts, |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1856 | {'udp': udp, |
| 1857 | 'tcp_established': tcp_established, |
| 1858 | 'tcp_transitory': tcp_transitory, |
| 1859 | 'icmp': icmp}) |
| 1860 | |
Matus Fabian | 878c646 | 2018-08-23 00:33:35 -0700 | [diff] [blame] | 1861 | def nat_get_timeouts(self): |
| 1862 | """Get values of timeouts for NAT sessions |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1863 | |
Matus Fabian | 878c646 | 2018-08-23 00:33:35 -0700 | [diff] [blame] | 1864 | :return: Timeouts for NAT sessions (in seconds) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1865 | """ |
Matus Fabian | 878c646 | 2018-08-23 00:33:35 -0700 | [diff] [blame] | 1866 | return self.api(self.papi.nat_get_timeouts, {}) |
Matus Fabian | 6a0946f | 2017-04-12 03:36:13 -0700 | [diff] [blame] | 1867 | |
Matus Fabian | 5d28c7a | 2018-09-04 03:55:45 -0700 | [diff] [blame] | 1868 | def nat_set_addr_and_port_alloc_alg( |
| 1869 | self, |
| 1870 | alg=0, |
| 1871 | psid_offset=0, |
| 1872 | psid_length=0, |
| 1873 | psid=0, |
| 1874 | start_port=0, |
| 1875 | end_port=0): |
| 1876 | """Set address and port assignment algorithm |
| 1877 | |
| 1878 | :param alg: algorithm: 0 - default, 1 - MAP-E, 2 - port range |
| 1879 | :param psid_offset: number of offset bits (valid only for MAP-E alg) |
| 1880 | :param psid_length: length of PSID (valid only for MAP-E alg) |
| 1881 | :param psid: Port Set Identifier value (valid only for MAP-E alg) |
| 1882 | :param start_port: beginning of the port range |
| 1883 | :param end_port: end of the port range |
| 1884 | """ |
| 1885 | return self.api( |
| 1886 | self.papi.nat_set_addr_and_port_alloc_alg, |
| 1887 | {'alg': alg, |
| 1888 | 'psid_offset': psid_offset, |
| 1889 | 'psid_length': psid_length, |
| 1890 | 'psid': psid, |
| 1891 | 'start_port': start_port, |
| 1892 | 'end_port': end_port}) |
| 1893 | |
| 1894 | def nat_get_addr_and_port_alloc_alg(self): |
| 1895 | """Get address and port assignment algorithm""" |
| 1896 | return self.api(self.papi.nat_get_addr_and_port_alloc_alg, {}) |
| 1897 | |
Matus Fabian | bb4e022 | 2018-09-13 02:36:25 -0700 | [diff] [blame] | 1898 | def nat_set_mss_clamping(self, enable=0, mss_value=1500): |
| 1899 | """Set TCP MSS rewriting configuration |
| 1900 | |
| 1901 | :param enable: disable(0)/enable(1) MSS rewriting feature |
| 1902 | :param mss_value: MSS value to be used for MSS rewriting |
| 1903 | """ |
| 1904 | return self.api( |
| 1905 | self.papi.nat_set_mss_clamping, |
| 1906 | {'enable': enable, 'mss_value': mss_value}) |
| 1907 | |
| 1908 | def nat_get_mss_clamping(self): |
| 1909 | """Get TCP MSS rewriting configuration""" |
| 1910 | return self.api(self.papi.nat_get_mss_clamping, {}) |
| 1911 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1912 | def nat_det_close_session_out( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1913 | self, |
| 1914 | out_addr, |
| 1915 | out_port, |
| 1916 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1917 | ext_port): |
| 1918 | """Close deterministic NAT session using outside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1919 | |
| 1920 | :param out_addr - outside IP address |
| 1921 | :param out_port - outside port |
| 1922 | :param ext_addr - external host IP address |
| 1923 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1924 | """ |
| 1925 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1926 | self.papi.nat_det_close_session_out, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1927 | {'out_addr': out_addr, |
| 1928 | 'out_port': out_port, |
| 1929 | 'ext_addr': ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1930 | 'ext_port': ext_port}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1931 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1932 | def nat_det_close_session_in( |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1933 | self, |
| 1934 | in_addr, |
| 1935 | in_port, |
| 1936 | ext_addr, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1937 | ext_port): |
| 1938 | """Close deterministic NAT session using inside address and port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1939 | |
| 1940 | :param in_addr - inside IP address |
| 1941 | :param in_port - inside port |
| 1942 | :param ext_addr - external host IP address |
| 1943 | :param ext_port - external host port |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1944 | """ |
| 1945 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1946 | self.papi.nat_det_close_session_in, |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1947 | {'in_addr': in_addr, |
| 1948 | 'in_port': in_port, |
| 1949 | 'ext_addr': ext_addr, |
| 1950 | 'ext_port': ext_port, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1951 | 'is_nat44': 1}) |
Martin Gálik | 6bc8c64 | 2017-04-19 01:12:27 -0700 | [diff] [blame] | 1952 | |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1953 | def nat_det_session_dump( |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1954 | self, |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1955 | user_addr): |
| 1956 | """Dump deterministic NAT sessions belonging to a user |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1957 | |
| 1958 | :param user_addr - inside IP address of the user |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1959 | :return: Dictionary of deterministic NAT sessions |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1960 | """ |
| 1961 | return self.api( |
Matus Fabian | 2ba92e3 | 2017-08-21 07:05:03 -0700 | [diff] [blame] | 1962 | self.papi.nat_det_session_dump, |
| 1963 | {'is_nat44': 1, |
Martin Gálik | 9806eae | 2017-04-25 01:25:08 -0700 | [diff] [blame] | 1964 | 'user_addr': user_addr}) |
| 1965 | |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 1966 | def nat64_add_del_pool_addr_range( |
| 1967 | self, |
| 1968 | start_addr, |
| 1969 | end_addr, |
| 1970 | vrf_id=0xFFFFFFFF, |
| 1971 | is_add=1): |
| 1972 | """Add/del address range to NAT64 pool |
| 1973 | |
| 1974 | :param start_addr: First IP address |
| 1975 | :param end_addr: Last IP address |
| 1976 | :param vrf_id: VRF id for the address range |
| 1977 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 1978 | """ |
| 1979 | return self.api( |
| 1980 | self.papi.nat64_add_del_pool_addr_range, |
| 1981 | {'start_addr': start_addr, |
| 1982 | 'end_addr': end_addr, |
| 1983 | 'vrf_id': vrf_id, |
| 1984 | 'is_add': is_add}) |
| 1985 | |
| 1986 | def nat64_pool_addr_dump(self): |
| 1987 | """Dump NAT64 pool addresses |
| 1988 | :return: Dictionary of NAT64 pool addresses |
| 1989 | """ |
| 1990 | return self.api(self.papi.nat64_pool_addr_dump, {}) |
| 1991 | |
| 1992 | def nat64_add_del_interface( |
| 1993 | self, |
| 1994 | sw_if_index, |
| 1995 | is_inside=1, |
| 1996 | is_add=1): |
| 1997 | """Enable/disable NAT64 feature on the interface |
| 1998 | :param sw_if_index: Index of the interface |
| 1999 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 2000 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2001 | """ |
| 2002 | return self.api( |
| 2003 | self.papi.nat64_add_del_interface, |
| 2004 | {'sw_if_index': sw_if_index, |
| 2005 | 'is_inside': is_inside, |
| 2006 | 'is_add': is_add}) |
| 2007 | |
| 2008 | def nat64_interface_dump(self): |
| 2009 | """Dump interfaces with NAT64 feature |
| 2010 | :return: Dictionary of interfaces with NAT64 feature |
| 2011 | """ |
| 2012 | return self.api(self.papi.nat64_interface_dump, {}) |
| 2013 | |
| 2014 | def nat64_add_del_static_bib( |
| 2015 | self, |
| 2016 | in_ip, |
| 2017 | out_ip, |
| 2018 | in_port, |
| 2019 | out_port, |
| 2020 | protocol, |
| 2021 | vrf_id=0, |
| 2022 | is_add=1): |
| 2023 | """Add/delete S-NAT static BIB entry |
| 2024 | |
| 2025 | :param in_ip: Inside IPv6 address |
| 2026 | :param out_ip: Outside IPv4 address |
| 2027 | :param in_port: Inside port number |
| 2028 | :param out_port: Outside port number |
| 2029 | :param protocol: IP protocol |
| 2030 | :param vrf_id: VRF ID (Default value = 0) |
| 2031 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2032 | """ |
| 2033 | return self.api( |
| 2034 | self.papi.nat64_add_del_static_bib, |
| 2035 | {'i_addr': in_ip, |
| 2036 | 'o_addr': out_ip, |
| 2037 | 'i_port': in_port, |
| 2038 | 'o_port': out_port, |
| 2039 | 'vrf_id': vrf_id, |
| 2040 | 'proto': protocol, |
| 2041 | 'is_add': is_add}) |
| 2042 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 2043 | def nat64_bib_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 2044 | """Dump NAT64 BIB |
| 2045 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 2046 | :param protocol: IP protocol (Default value = 255, all BIBs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 2047 | :returns: Dictionary of NAT64 BIB entries |
| 2048 | """ |
| 2049 | return self.api(self.papi.nat64_bib_dump, {'proto': protocol}) |
| 2050 | |
| 2051 | def nat64_set_timeouts(self, udp=300, icmp=60, tcp_trans=240, tcp_est=7440, |
| 2052 | tcp_incoming_syn=6): |
| 2053 | """Set values of timeouts for NAT64 (in seconds) |
| 2054 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 2055 | :param udpi: UDP timeout (Default value = 300) |
| 2056 | :param icmp: ICMP timeout (Default value = 60) |
| 2057 | :param tcp_trans: TCP transitory timeout (Default value = 240) |
| 2058 | :param tcp_est: TCP established timeout (Default value = 7440) |
| 2059 | :param tcp_incoming_syn: TCP incoming SYN timeout (Default value = 6) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 2060 | """ |
| 2061 | return self.api( |
| 2062 | self.papi.nat64_set_timeouts, |
| 2063 | {'udp': udp, |
| 2064 | 'icmp': icmp, |
| 2065 | 'tcp_trans': tcp_trans, |
| 2066 | 'tcp_est': tcp_est, |
| 2067 | 'tcp_incoming_syn': tcp_incoming_syn}) |
| 2068 | |
| 2069 | def nat64_get_timeouts(self): |
| 2070 | """Get values of timeouts for NAT64 |
| 2071 | |
| 2072 | :return: Timeouts for NAT64 (in seconds) |
| 2073 | """ |
| 2074 | return self.api(self.papi.nat64_get_timeouts, {}) |
| 2075 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 2076 | def nat64_st_dump(self, protocol=255): |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 2077 | """Dump NAT64 session table |
| 2078 | |
Matus Fabian | ab9a59c | 2017-08-16 05:37:36 -0700 | [diff] [blame] | 2079 | :param protocol: IP protocol (Default value = 255, all STs) |
Matus Fabian | 06596c5 | 2017-06-06 04:53:28 -0700 | [diff] [blame] | 2080 | :returns: Dictionary of NAT64 sesstion table entries |
| 2081 | """ |
| 2082 | return self.api(self.papi.nat64_st_dump, {'proto': protocol}) |
| 2083 | |
Matus Fabian | 428dc91 | 2017-06-21 06:15:18 -0700 | [diff] [blame] | 2084 | def nat64_add_del_prefix(self, prefix, plen, vrf_id=0, is_add=1): |
| 2085 | """Add/del NAT64 prefix |
| 2086 | |
| 2087 | :param prefix: NAT64 prefix |
| 2088 | :param plen: NAT64 prefix length |
| 2089 | :param vrf_id: VRF id of tenant (Default 0) |
| 2090 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2091 | """ |
| 2092 | return self.api( |
| 2093 | self.papi.nat64_add_del_prefix, |
| 2094 | {'prefix': prefix, |
| 2095 | 'prefix_len': plen, |
| 2096 | 'vrf_id': vrf_id, |
| 2097 | 'is_add': is_add}) |
| 2098 | |
| 2099 | def nat64_prefix_dump(self): |
| 2100 | """Dump NAT64 prefix |
| 2101 | |
| 2102 | :returns: Dictionary of NAT64 prefixes |
| 2103 | """ |
| 2104 | return self.api(self.papi.nat64_prefix_dump, {}) |
| 2105 | |
Matus Fabian | 0938dcf | 2017-11-08 01:59:38 -0800 | [diff] [blame] | 2106 | def nat64_add_interface_addr( |
| 2107 | self, |
| 2108 | sw_if_index, |
| 2109 | is_add=1): |
| 2110 | """Add/del NAT64 address from interface |
| 2111 | |
| 2112 | :param sw_if_index: Software index of the interface |
| 2113 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2114 | """ |
| 2115 | return self.api(self.papi.nat64_add_del_interface_addr, |
| 2116 | {'is_add': is_add, 'sw_if_index': sw_if_index}) |
| 2117 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 2118 | def dslite_set_aftr_addr(self, ip6, ip4): |
| 2119 | """Set DS-Lite AFTR addresses |
| 2120 | |
| 2121 | :param ip4: IPv4 address |
| 2122 | :param ip6: IPv6 address |
| 2123 | """ |
| 2124 | return self.api( |
| 2125 | self.papi.dslite_set_aftr_addr, |
| 2126 | {'ip4_addr': ip4, |
| 2127 | 'ip6_addr': ip6}) |
| 2128 | |
Juraj Sloboda | c5c6a33 | 2018-01-09 16:08:32 +0100 | [diff] [blame] | 2129 | def dslite_set_b4_addr(self, ip6, ip4): |
| 2130 | """Set DS-Lite B4 IPv6 address |
| 2131 | |
| 2132 | :param ip4: IPv4 address |
| 2133 | :param ip6: IPv6 address |
| 2134 | """ |
| 2135 | return self.api( |
| 2136 | self.papi.dslite_set_b4_addr, |
| 2137 | {'ip4_addr': ip4, |
| 2138 | 'ip6_addr': ip6}) |
| 2139 | |
Matus Fabian | 8ebe625 | 2017-11-06 05:04:53 -0800 | [diff] [blame] | 2140 | def dslite_add_del_pool_addr_range( |
| 2141 | self, |
| 2142 | start_addr, |
| 2143 | end_addr, |
| 2144 | is_add=1): |
| 2145 | """Add/del address range to DS-Lite pool |
| 2146 | |
| 2147 | :param start_addr: First IP address |
| 2148 | :param end_addr: Last IP address |
| 2149 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2150 | """ |
| 2151 | return self.api( |
| 2152 | self.papi.dslite_add_del_pool_addr_range, |
| 2153 | {'start_addr': start_addr, |
| 2154 | 'end_addr': end_addr, |
| 2155 | 'is_add': is_add}) |
| 2156 | |
Matus Fabian | f2a23cc | 2018-01-22 03:41:53 -0800 | [diff] [blame] | 2157 | def nat66_add_del_interface( |
| 2158 | self, |
| 2159 | sw_if_index, |
| 2160 | is_inside=1, |
| 2161 | is_add=1): |
| 2162 | """Enable/disable NAT66 feature on the interface |
| 2163 | :param sw_if_index: Index of the interface |
| 2164 | :param is_inside: 1 if inside, 0 if outside (Default value = 1) |
| 2165 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2166 | """ |
| 2167 | return self.api( |
| 2168 | self.papi.nat66_add_del_interface, |
| 2169 | {'sw_if_index': sw_if_index, |
| 2170 | 'is_inside': is_inside, |
| 2171 | 'is_add': is_add}) |
| 2172 | |
| 2173 | def nat66_add_del_static_mapping( |
| 2174 | self, |
| 2175 | in_ip, |
| 2176 | out_ip, |
| 2177 | vrf_id=0, |
| 2178 | is_add=1): |
| 2179 | """Add/delete NAT66 static mapping |
| 2180 | |
| 2181 | :param in_ip: Inside IPv6 address |
| 2182 | :param out_ip: Outside IPv6 address |
| 2183 | :param vrf_id: VRF ID (Default value = 0) |
| 2184 | :param is_add: 1 if add, 0 if delete (Default value = 1) |
| 2185 | """ |
| 2186 | return self.api( |
| 2187 | self.papi.nat66_add_del_static_mapping, |
| 2188 | {'local_ip_address': in_ip, |
| 2189 | 'external_ip_address': out_ip, |
| 2190 | 'vrf_id': vrf_id, |
| 2191 | 'is_add': is_add}) |
| 2192 | |
| 2193 | def nat66_interface_dump(self): |
| 2194 | """Dump interfaces with NAT66 feature |
| 2195 | :return: Dictionary of interfaces with NAT66 feature |
| 2196 | """ |
| 2197 | return self.api(self.papi.nat66_interface_dump, {}) |
| 2198 | |
| 2199 | def nat66_static_mapping_dump(self): |
| 2200 | """Dump NAT66 static mappings |
| 2201 | :return: Dictionary of NAT66 static mappings |
| 2202 | """ |
| 2203 | return self.api(self.papi.nat66_static_mapping_dump, {}) |
| 2204 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2205 | def control_ping(self): |
| 2206 | self.api(self.papi.control_ping) |
| 2207 | |
| 2208 | 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] | 2209 | detect_mult, local_addr, peer_addr, is_ipv6=0, |
| 2210 | bfd_key_id=None, conf_key_id=None): |
| 2211 | if bfd_key_id is None: |
| 2212 | return self.api(self.papi.bfd_udp_add, |
| 2213 | { |
| 2214 | 'sw_if_index': sw_if_index, |
| 2215 | 'desired_min_tx': desired_min_tx, |
| 2216 | 'required_min_rx': required_min_rx, |
| 2217 | 'local_addr': local_addr, |
| 2218 | 'peer_addr': peer_addr, |
| 2219 | 'is_ipv6': is_ipv6, |
| 2220 | 'detect_mult': detect_mult, |
| 2221 | }) |
| 2222 | else: |
| 2223 | return self.api(self.papi.bfd_udp_add, |
| 2224 | { |
| 2225 | 'sw_if_index': sw_if_index, |
| 2226 | 'desired_min_tx': desired_min_tx, |
| 2227 | 'required_min_rx': required_min_rx, |
| 2228 | 'local_addr': local_addr, |
| 2229 | 'peer_addr': peer_addr, |
| 2230 | 'is_ipv6': is_ipv6, |
| 2231 | 'detect_mult': detect_mult, |
| 2232 | 'is_authenticated': 1, |
| 2233 | 'bfd_key_id': bfd_key_id, |
| 2234 | 'conf_key_id': conf_key_id, |
| 2235 | }) |
| 2236 | |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 2237 | def bfd_udp_mod(self, sw_if_index, desired_min_tx, required_min_rx, |
| 2238 | detect_mult, local_addr, peer_addr, is_ipv6=0): |
| 2239 | return self.api(self.papi.bfd_udp_mod, |
| 2240 | { |
| 2241 | 'sw_if_index': sw_if_index, |
| 2242 | 'desired_min_tx': desired_min_tx, |
| 2243 | 'required_min_rx': required_min_rx, |
| 2244 | 'local_addr': local_addr, |
| 2245 | 'peer_addr': peer_addr, |
| 2246 | 'is_ipv6': is_ipv6, |
| 2247 | 'detect_mult': detect_mult, |
| 2248 | }) |
| 2249 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2250 | def bfd_udp_auth_activate(self, sw_if_index, local_addr, peer_addr, |
| 2251 | is_ipv6=0, bfd_key_id=None, conf_key_id=None, |
| 2252 | is_delayed=False): |
| 2253 | return self.api(self.papi.bfd_udp_auth_activate, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2254 | { |
| 2255 | 'sw_if_index': sw_if_index, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2256 | 'local_addr': local_addr, |
| 2257 | 'peer_addr': peer_addr, |
| 2258 | 'is_ipv6': is_ipv6, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2259 | 'is_delayed': 1 if is_delayed else 0, |
| 2260 | 'bfd_key_id': bfd_key_id, |
| 2261 | 'conf_key_id': conf_key_id, |
| 2262 | }) |
| 2263 | |
| 2264 | def bfd_udp_auth_deactivate(self, sw_if_index, local_addr, peer_addr, |
| 2265 | is_ipv6=0, is_delayed=False): |
| 2266 | return self.api(self.papi.bfd_udp_auth_deactivate, |
| 2267 | { |
| 2268 | 'sw_if_index': sw_if_index, |
| 2269 | 'local_addr': local_addr, |
| 2270 | 'peer_addr': peer_addr, |
| 2271 | 'is_ipv6': is_ipv6, |
| 2272 | 'is_delayed': 1 if is_delayed else 0, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2273 | }) |
| 2274 | |
| 2275 | def bfd_udp_del(self, sw_if_index, local_addr, peer_addr, is_ipv6=0): |
| 2276 | return self.api(self.papi.bfd_udp_del, |
| 2277 | { |
| 2278 | 'sw_if_index': sw_if_index, |
| 2279 | 'local_addr': local_addr, |
| 2280 | 'peer_addr': peer_addr, |
| 2281 | 'is_ipv6': is_ipv6, |
| 2282 | }) |
| 2283 | |
| 2284 | def bfd_udp_session_dump(self): |
| 2285 | return self.api(self.papi.bfd_udp_session_dump, {}) |
| 2286 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2287 | def bfd_udp_session_set_flags(self, admin_up_down, sw_if_index, local_addr, |
| 2288 | peer_addr, is_ipv6=0): |
| 2289 | return self.api(self.papi.bfd_udp_session_set_flags, { |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2290 | 'admin_up_down': admin_up_down, |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2291 | 'sw_if_index': sw_if_index, |
| 2292 | 'local_addr': local_addr, |
| 2293 | 'peer_addr': peer_addr, |
| 2294 | 'is_ipv6': is_ipv6, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 2295 | }) |
| 2296 | |
| 2297 | def want_bfd_events(self, enable_disable=1): |
| 2298 | return self.api(self.papi.want_bfd_events, { |
| 2299 | 'enable_disable': enable_disable, |
| 2300 | 'pid': os.getpid(), |
| 2301 | }) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2302 | |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 2303 | def bfd_auth_set_key(self, conf_key_id, auth_type, key): |
| 2304 | return self.api(self.papi.bfd_auth_set_key, { |
| 2305 | 'conf_key_id': conf_key_id, |
| 2306 | 'auth_type': auth_type, |
| 2307 | 'key': key, |
| 2308 | 'key_len': len(key), |
| 2309 | }) |
| 2310 | |
| 2311 | def bfd_auth_del_key(self, conf_key_id): |
| 2312 | return self.api(self.papi.bfd_auth_del_key, { |
| 2313 | 'conf_key_id': conf_key_id, |
| 2314 | }) |
| 2315 | |
| 2316 | def bfd_auth_keys_dump(self): |
| 2317 | return self.api(self.papi.bfd_auth_keys_dump, {}) |
| 2318 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 2319 | def bfd_udp_set_echo_source(self, sw_if_index): |
| 2320 | return self.api(self.papi.bfd_udp_set_echo_source, |
| 2321 | {'sw_if_index': sw_if_index}) |
| 2322 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 2323 | def bfd_udp_del_echo_source(self): |
| 2324 | return self.api(self.papi.bfd_udp_del_echo_source, {}) |
| 2325 | |
Matus Fabian | 2d3c7b9 | 2018-10-02 03:22:18 -0700 | [diff] [blame] | 2326 | def bfd_udp_get_echo_source(self): |
| 2327 | return self.api(self.papi.bfd_udp_get_echo_source, {}) |
| 2328 | |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2329 | def classify_add_del_table( |
| 2330 | self, |
| 2331 | is_add, |
| 2332 | mask, |
| 2333 | match_n_vectors=1, |
| 2334 | table_index=0xFFFFFFFF, |
| 2335 | nbuckets=2, |
| 2336 | memory_size=2097152, |
| 2337 | skip_n_vectors=0, |
| 2338 | next_table_index=0xFFFFFFFF, |
| 2339 | miss_next_index=0xFFFFFFFF, |
| 2340 | current_data_flag=0, |
| 2341 | current_data_offset=0): |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2342 | """ |
| 2343 | :param is_add: |
| 2344 | :param mask: |
Klement Sekera | da505f6 | 2017-01-04 12:58:53 +0100 | [diff] [blame] | 2345 | :param match_n_vectors: (Default value = 1) |
Matej Klotton | 8d8a1da | 2016-12-22 11:06:56 +0100 | [diff] [blame] | 2346 | :param table_index: (Default value = 0xFFFFFFFF) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2347 | :param nbuckets: (Default value = 2) |
| 2348 | :param memory_size: (Default value = 2097152) |
| 2349 | :param skip_n_vectors: (Default value = 0) |
| 2350 | :param next_table_index: (Default value = 0xFFFFFFFF) |
| 2351 | :param miss_next_index: (Default value = 0xFFFFFFFF) |
| 2352 | :param current_data_flag: (Default value = 0) |
| 2353 | :param current_data_offset: (Default value = 0) |
| 2354 | """ |
| 2355 | |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 2356 | mask_len = ((len(mask) - 1) / 16 + 1) * 16 |
| 2357 | mask = mask + '\0' * (mask_len - len(mask)) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2358 | return self.api( |
| 2359 | self.papi.classify_add_del_table, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2360 | {'is_add': is_add, |
| 2361 | 'table_index': table_index, |
| 2362 | 'nbuckets': nbuckets, |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2363 | 'memory_size': memory_size, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2364 | 'skip_n_vectors': skip_n_vectors, |
| 2365 | 'match_n_vectors': match_n_vectors, |
| 2366 | 'next_table_index': next_table_index, |
| 2367 | 'miss_next_index': miss_next_index, |
| 2368 | 'current_data_flag': current_data_flag, |
| 2369 | 'current_data_offset': current_data_offset, |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 2370 | 'mask_len': mask_len, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2371 | 'mask': mask}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2372 | |
| 2373 | def classify_add_del_session( |
| 2374 | self, |
| 2375 | is_add, |
| 2376 | table_index, |
| 2377 | match, |
| 2378 | opaque_index=0xFFFFFFFF, |
| 2379 | hit_next_index=0xFFFFFFFF, |
| 2380 | advance=0, |
| 2381 | action=0, |
| 2382 | metadata=0): |
| 2383 | """ |
| 2384 | :param is_add: |
| 2385 | :param table_index: |
| 2386 | :param match: |
| 2387 | :param opaque_index: (Default value = 0xFFFFFFFF) |
| 2388 | :param hit_next_index: (Default value = 0xFFFFFFFF) |
| 2389 | :param advance: (Default value = 0) |
| 2390 | :param action: (Default value = 0) |
| 2391 | :param metadata: (Default value = 0) |
| 2392 | """ |
| 2393 | |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 2394 | match_len = ((len(match) - 1) / 16 + 1) * 16 |
| 2395 | match = match + '\0' * (match_len - len(match)) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2396 | return self.api( |
| 2397 | self.papi.classify_add_del_session, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2398 | {'is_add': is_add, |
| 2399 | 'table_index': table_index, |
| 2400 | 'hit_next_index': hit_next_index, |
| 2401 | 'opaque_index': opaque_index, |
| 2402 | 'advance': advance, |
| 2403 | 'action': action, |
| 2404 | 'metadata': metadata, |
Juraj Sloboda | 7528245 | 2018-06-12 14:20:49 +0200 | [diff] [blame] | 2405 | 'match_len': match_len, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2406 | 'match': match}) |
Steve Shin | 7957d6e | 2016-12-19 09:24:50 -0800 | [diff] [blame] | 2407 | |
| 2408 | def input_acl_set_interface( |
| 2409 | self, |
| 2410 | is_add, |
| 2411 | sw_if_index, |
| 2412 | ip4_table_index=0xFFFFFFFF, |
| 2413 | ip6_table_index=0xFFFFFFFF, |
| 2414 | l2_table_index=0xFFFFFFFF): |
| 2415 | """ |
| 2416 | :param is_add: |
| 2417 | :param sw_if_index: |
| 2418 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2419 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2420 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2421 | """ |
| 2422 | |
| 2423 | return self.api( |
| 2424 | self.papi.input_acl_set_interface, |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2425 | {'sw_if_index': sw_if_index, |
| 2426 | 'ip4_table_index': ip4_table_index, |
| 2427 | 'ip6_table_index': ip6_table_index, |
| 2428 | 'l2_table_index': l2_table_index, |
| 2429 | 'is_add': is_add}) |
| 2430 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 2431 | def output_acl_set_interface( |
| 2432 | self, |
| 2433 | is_add, |
| 2434 | sw_if_index, |
| 2435 | ip4_table_index=0xFFFFFFFF, |
| 2436 | ip6_table_index=0xFFFFFFFF, |
| 2437 | l2_table_index=0xFFFFFFFF): |
| 2438 | """ |
| 2439 | :param is_add: |
| 2440 | :param sw_if_index: |
| 2441 | :param ip4_table_index: (Default value = 0xFFFFFFFF) |
| 2442 | :param ip6_table_index: (Default value = 0xFFFFFFFF) |
| 2443 | :param l2_table_index: (Default value = 0xFFFFFFFF) |
| 2444 | """ |
| 2445 | |
| 2446 | return self.api( |
| 2447 | self.papi.output_acl_set_interface, |
| 2448 | {'sw_if_index': sw_if_index, |
| 2449 | 'ip4_table_index': ip4_table_index, |
| 2450 | 'ip6_table_index': ip6_table_index, |
| 2451 | 'l2_table_index': l2_table_index, |
| 2452 | 'is_add': is_add}) |
| 2453 | |
Klement Sekera | 77fabdb | 2017-01-02 07:46:14 +0100 | [diff] [blame] | 2454 | def set_ipfix_exporter( |
| 2455 | self, |
| 2456 | collector_address, |
| 2457 | src_address, |
| 2458 | path_mtu, |
| 2459 | template_interval, |
| 2460 | vrf_id=0, |
| 2461 | collector_port=4739, |
| 2462 | udp_checksum=0): |
| 2463 | return self.api( |
| 2464 | self.papi.set_ipfix_exporter, |
| 2465 | { |
| 2466 | 'collector_address': collector_address, |
| 2467 | 'collector_port': collector_port, |
| 2468 | 'src_address': src_address, |
| 2469 | 'vrf_id': vrf_id, |
| 2470 | 'path_mtu': path_mtu, |
| 2471 | 'template_interval': template_interval, |
| 2472 | 'udp_checksum': udp_checksum, |
| 2473 | }) |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2474 | |
| 2475 | def dhcp_proxy_config(self, |
| 2476 | dhcp_server, |
| 2477 | dhcp_src_address, |
| 2478 | rx_table_id=0, |
| 2479 | server_table_id=0, |
| 2480 | is_add=1, |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2481 | is_ipv6=0): |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2482 | return self.api( |
Neale Ranns | 20a175a | 2017-02-14 07:28:41 -0800 | [diff] [blame] | 2483 | self.papi.dhcp_proxy_config, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2484 | { |
| 2485 | 'rx_vrf_id': rx_table_id, |
| 2486 | 'server_vrf_id': server_table_id, |
| 2487 | 'is_ipv6': is_ipv6, |
| 2488 | 'is_add': is_add, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2489 | 'dhcp_server': dhcp_server, |
| 2490 | 'dhcp_src_address': dhcp_src_address, |
| 2491 | }) |
| 2492 | |
| 2493 | def dhcp_proxy_set_vss(self, |
| 2494 | table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2495 | vss_type=255, |
| 2496 | vpn_ascii_id="", |
| 2497 | oui=0, |
| 2498 | vpn_index=0, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2499 | is_add=1, |
| 2500 | is_ip6=0): |
| 2501 | return self.api( |
| 2502 | self.papi.dhcp_proxy_set_vss, |
| 2503 | { |
| 2504 | 'tbl_id': table_id, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2505 | 'vss_type': vss_type, |
| 2506 | 'vpn_ascii_id': vpn_ascii_id, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2507 | 'oui': oui, |
John Lo | 70bfcaf | 2017-11-14 13:19:26 -0500 | [diff] [blame] | 2508 | 'vpn_index': vpn_index, |
| 2509 | 'is_add': is_add, |
| 2510 | 'is_ipv6': is_ip6, |
Neale Ranns | fca0c24 | 2017-01-13 07:57:46 -0800 | [diff] [blame] | 2511 | }) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2512 | |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 2513 | def dhcp_client_dump(self): |
| 2514 | return self.api(self.papi.dhcp_client_dump, {}) |
| 2515 | |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2516 | def dhcp_client(self, |
| 2517 | sw_if_index, |
| 2518 | hostname, |
Neale Ranns | 51822bf | 2017-07-18 09:26:53 -0700 | [diff] [blame] | 2519 | client_id='', |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2520 | is_add=1, |
Neale Ranns | 54c6dc4 | 2018-01-17 10:29:10 -0800 | [diff] [blame] | 2521 | set_broadcast_flag=1, |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2522 | want_dhcp_events=0): |
| 2523 | return self.api( |
| 2524 | self.papi.dhcp_client_config, |
| 2525 | { |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2526 | 'is_add': is_add, |
Neale Ranns | daff178 | 2018-05-16 04:12:18 -0700 | [diff] [blame] | 2527 | 'client': { |
| 2528 | 'sw_if_index': sw_if_index, |
| 2529 | 'hostname': hostname, |
| 2530 | 'id': client_id, |
| 2531 | 'want_dhcp_event': want_dhcp_events, |
| 2532 | 'set_broadcast_flag': set_broadcast_flag, |
| 2533 | 'pid': os.getpid()} |
Neale Ranns | a2fbf6b | 2017-07-18 08:23:32 -0700 | [diff] [blame] | 2534 | }) |
| 2535 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2536 | def ip_mroute_add_del(self, |
| 2537 | src_address, |
| 2538 | grp_address, |
| 2539 | grp_address_length, |
| 2540 | e_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2541 | next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2542 | next_hop_sw_if_index, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 2543 | next_hop_address, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2544 | i_flags, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2545 | bier_imp=0, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2546 | rpf_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2547 | table_id=0, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2548 | is_add=1, |
| 2549 | is_ipv6=0, |
| 2550 | is_local=0): |
| 2551 | """ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2552 | IP Multicast Route add/del |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2553 | """ |
| 2554 | return self.api( |
| 2555 | self.papi.ip_mroute_add_del, |
| 2556 | {'next_hop_sw_if_index': next_hop_sw_if_index, |
| 2557 | 'entry_flags': e_flags, |
| 2558 | 'itf_flags': i_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 2559 | 'table_id': table_id, |
| 2560 | 'rpf_id': rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2561 | 'is_add': is_add, |
| 2562 | 'is_ipv6': is_ipv6, |
| 2563 | 'is_local': is_local, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2564 | 'bier_imp': bier_imp, |
| 2565 | 'next_hop_afi': next_hop_afi, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2566 | 'grp_address_length': grp_address_length, |
| 2567 | 'grp_address': grp_address, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 2568 | 'src_address': src_address, |
| 2569 | 'nh_address': next_hop_address}) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2570 | |
| 2571 | def mfib_signal_dump(self): |
| 2572 | return self.api(self.papi.mfib_signal_dump, {}) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 2573 | |
| 2574 | def ip_mfib_dump(self): |
| 2575 | return self.api(self.papi.ip_mfib_dump, {}) |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2576 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 2577 | def ip6_mfib_dump(self): |
| 2578 | return self.api(self.papi.ip6_mfib_dump, {}) |
| 2579 | |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2580 | def lisp_enable_disable(self, is_enabled): |
| 2581 | return self.api( |
| 2582 | self.papi.lisp_enable_disable, |
| 2583 | { |
| 2584 | 'is_en': is_enabled, |
| 2585 | }) |
| 2586 | |
| 2587 | def lisp_locator_set(self, |
| 2588 | ls_name, |
| 2589 | is_add=1): |
| 2590 | return self.api( |
| 2591 | self.papi.lisp_add_del_locator_set, |
| 2592 | { |
| 2593 | 'is_add': is_add, |
| 2594 | 'locator_set_name': ls_name |
| 2595 | }) |
| 2596 | |
| 2597 | def lisp_locator_set_dump(self): |
| 2598 | return self.api(self.papi.lisp_locator_set_dump, {}) |
| 2599 | |
| 2600 | def lisp_locator(self, |
| 2601 | ls_name, |
| 2602 | sw_if_index, |
| 2603 | priority=1, |
| 2604 | weight=1, |
| 2605 | is_add=1): |
| 2606 | return self.api( |
| 2607 | self.papi.lisp_add_del_locator, |
| 2608 | { |
| 2609 | 'is_add': is_add, |
| 2610 | 'locator_set_name': ls_name, |
| 2611 | 'sw_if_index': sw_if_index, |
| 2612 | 'priority': priority, |
| 2613 | 'weight': weight |
| 2614 | }) |
| 2615 | |
| 2616 | def lisp_locator_dump(self, is_index_set, ls_name=None, ls_index=0): |
| 2617 | return self.api( |
| 2618 | self.papi.lisp_locator_dump, |
| 2619 | { |
| 2620 | 'is_index_set': is_index_set, |
| 2621 | 'ls_name': ls_name, |
| 2622 | 'ls_index': ls_index, |
| 2623 | }) |
| 2624 | |
| 2625 | def lisp_local_mapping(self, |
| 2626 | ls_name, |
| 2627 | eid_type, |
| 2628 | eid, |
| 2629 | prefix_len, |
| 2630 | vni=0, |
| 2631 | key_id=0, |
| 2632 | key="", |
| 2633 | is_add=1): |
| 2634 | return self.api( |
| 2635 | self.papi.lisp_add_del_local_eid, |
| 2636 | { |
| 2637 | 'locator_set_name': ls_name, |
| 2638 | 'is_add': is_add, |
| 2639 | 'eid_type': eid_type, |
| 2640 | 'eid': eid, |
| 2641 | 'prefix_len': prefix_len, |
| 2642 | 'vni': vni, |
| 2643 | 'key_id': key_id, |
| 2644 | 'key': key |
| 2645 | }) |
| 2646 | |
| 2647 | def lisp_eid_table_dump(self, |
| 2648 | eid_set=0, |
| 2649 | prefix_length=0, |
| 2650 | vni=0, |
| 2651 | eid_type=0, |
| 2652 | eid=None, |
| 2653 | filter_opt=0): |
| 2654 | return self.api( |
| 2655 | self.papi.lisp_eid_table_dump, |
| 2656 | { |
| 2657 | 'eid_set': eid_set, |
| 2658 | 'prefix_length': prefix_length, |
| 2659 | 'vni': vni, |
| 2660 | 'eid_type': eid_type, |
| 2661 | 'eid': eid, |
| 2662 | 'filter': filter_opt, |
| 2663 | }) |
| 2664 | |
| 2665 | def lisp_remote_mapping(self, |
| 2666 | eid_type, |
| 2667 | eid, |
| 2668 | eid_prefix_len=0, |
| 2669 | vni=0, |
Ole Troan | 895b6e8 | 2017-10-20 13:28:20 +0200 | [diff] [blame] | 2670 | rlocs=[], |
Filip Tehlar | 770e89e | 2017-01-31 10:39:16 +0100 | [diff] [blame] | 2671 | rlocs_num=0, |
| 2672 | is_src_dst=0, |
| 2673 | is_add=1): |
| 2674 | return self.api( |
| 2675 | self.papi.lisp_add_del_remote_mapping, |
| 2676 | { |
| 2677 | 'is_add': is_add, |
| 2678 | 'eid_type': eid_type, |
| 2679 | 'eid': eid, |
| 2680 | 'eid_len': eid_prefix_len, |
| 2681 | 'rloc_num': rlocs_num, |
| 2682 | 'rlocs': rlocs, |
| 2683 | 'vni': vni, |
| 2684 | 'is_src_dst': is_src_dst, |
| 2685 | }) |
| 2686 | |
| 2687 | def lisp_adjacency(self, |
| 2688 | leid, |
| 2689 | reid, |
| 2690 | leid_len, |
| 2691 | reid_len, |
| 2692 | eid_type, |
| 2693 | is_add=1, |
| 2694 | vni=0): |
| 2695 | return self.api( |
| 2696 | self.papi.lisp_add_del_adjacency, |
| 2697 | { |
| 2698 | 'is_add': is_add, |
| 2699 | 'vni': vni, |
| 2700 | 'eid_type': eid_type, |
| 2701 | 'leid': leid, |
| 2702 | 'reid': reid, |
| 2703 | 'leid_len': leid_len, |
| 2704 | 'reid_len': reid_len, |
| 2705 | }) |
| 2706 | |
| 2707 | def lisp_adjacencies_get(self, vni=0): |
| 2708 | return self.api( |
| 2709 | self.papi.lisp_adjacencies_get, |
| 2710 | { |
| 2711 | 'vni': vni |
| 2712 | }) |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2713 | |
| 2714 | def map_add_domain(self, |
| 2715 | ip6_prefix, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2716 | ip6_src, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2717 | ip4_prefix, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2718 | ea_bits_len=0, |
| 2719 | psid_offset=0, |
| 2720 | psid_length=0, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2721 | mtu=1280): |
Jon Loeliger | fc7344f | 2018-12-20 11:47:30 -0600 | [diff] [blame] | 2722 | |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2723 | return self.api( |
| 2724 | self.papi.map_add_domain, |
| 2725 | { |
| 2726 | 'ip6_prefix': ip6_prefix, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2727 | 'ip4_prefix': ip4_prefix, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2728 | 'ip6_src': ip6_src, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2729 | 'ea_bits_len': ea_bits_len, |
| 2730 | 'psid_offset': psid_offset, |
| 2731 | 'psid_length': psid_length, |
Neale Ranns | 8082380 | 2017-02-20 18:23:41 -0800 | [diff] [blame] | 2732 | 'mtu': mtu |
| 2733 | }) |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2734 | |
Jon Loeliger | fc7344f | 2018-12-20 11:47:30 -0600 | [diff] [blame] | 2735 | def map_if_enable_disable(self, is_enable, sw_if_index, is_translation): |
| 2736 | return self.api( |
| 2737 | self.papi.map_if_enable_disable, |
| 2738 | { |
| 2739 | 'is_enable': is_enable, |
| 2740 | 'sw_if_index': sw_if_index, |
| 2741 | 'is_translation': is_translation, |
| 2742 | }) |
| 2743 | |
| 2744 | def map_param_set_tcp(self, tcp_mss): |
| 2745 | return self.api( |
| 2746 | self.papi.map_param_set_tcp, |
| 2747 | { |
| 2748 | 'tcp_mss': tcp_mss, |
| 2749 | }) |
| 2750 | |
Hongjun Ni | ef486b1 | 2017-04-12 19:21:16 +0800 | [diff] [blame] | 2751 | def gtpu_add_del_tunnel( |
| 2752 | self, |
| 2753 | src_addr, |
| 2754 | dst_addr, |
| 2755 | is_add=1, |
| 2756 | is_ipv6=0, |
| 2757 | mcast_sw_if_index=0xFFFFFFFF, |
| 2758 | encap_vrf_id=0, |
| 2759 | decap_next_index=0xFFFFFFFF, |
| 2760 | teid=0): |
| 2761 | """ |
| 2762 | |
| 2763 | :param is_add: (Default value = 1) |
| 2764 | :param is_ipv6: (Default value = 0) |
| 2765 | :param src_addr: |
| 2766 | :param dst_addr: |
| 2767 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2768 | :param encap_vrf_id: (Default value = 0) |
| 2769 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2770 | :param teid: (Default value = 0) |
| 2771 | |
| 2772 | """ |
| 2773 | return self.api(self.papi.gtpu_add_del_tunnel, |
| 2774 | {'is_add': is_add, |
| 2775 | 'is_ipv6': is_ipv6, |
| 2776 | 'src_address': src_addr, |
| 2777 | 'dst_address': dst_addr, |
| 2778 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2779 | 'encap_vrf_id': encap_vrf_id, |
| 2780 | 'decap_next_index': decap_next_index, |
| 2781 | 'teid': teid}) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 2782 | |
| 2783 | def vxlan_gpe_add_del_tunnel( |
| 2784 | self, |
| 2785 | src_addr, |
| 2786 | dst_addr, |
| 2787 | mcast_sw_if_index=0xFFFFFFFF, |
| 2788 | is_add=1, |
| 2789 | is_ipv6=0, |
| 2790 | encap_vrf_id=0, |
| 2791 | decap_vrf_id=0, |
| 2792 | protocol=3, |
| 2793 | vni=0): |
| 2794 | """ |
| 2795 | |
| 2796 | :param local: |
| 2797 | :param remote: |
| 2798 | :param is_add: (Default value = 1) |
| 2799 | :param is_ipv6: (Default value = 0) |
| 2800 | :param encap_vrf_id: (Default value = 0) |
| 2801 | :param decap_vrf_id: (Default value = 0) |
| 2802 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2803 | :param protocol: (Default value = 3) |
| 2804 | :param vni: (Default value = 0) |
| 2805 | |
| 2806 | """ |
| 2807 | return self.api(self.papi.vxlan_gpe_add_del_tunnel, |
| 2808 | {'is_add': is_add, |
| 2809 | 'is_ipv6': is_ipv6, |
| 2810 | 'local': src_addr, |
| 2811 | 'remote': dst_addr, |
| 2812 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2813 | 'encap_vrf_id': encap_vrf_id, |
| 2814 | 'decap_vrf_id': decap_vrf_id, |
| 2815 | 'protocol': protocol, |
| 2816 | 'vni': vni}) |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2817 | |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2818 | def vxlan_gbp_tunnel_add_del( |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 2819 | self, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2820 | src, |
| 2821 | dst, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 2822 | mcast_sw_if_index=0xFFFFFFFF, |
| 2823 | is_add=1, |
| 2824 | is_ipv6=0, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2825 | encap_table_id=0, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 2826 | vni=0, |
| 2827 | instance=0xFFFFFFFF): |
| 2828 | """ |
| 2829 | |
| 2830 | :param dst_addr: |
| 2831 | :param src_addr: |
| 2832 | :param is_add: (Default value = 1) |
| 2833 | :param is_ipv6: (Default value = 0) |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2834 | :param encap_table_id: (Default value = 0) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 2835 | :param decap_next_index: (Default value = 0xFFFFFFFF) |
| 2836 | :param mcast_sw_if_index: (Default value = 0xFFFFFFFF) |
| 2837 | :param vni: (Default value = 0) |
| 2838 | :param instance: (Default value = 0xFFFFFFFF) |
| 2839 | |
| 2840 | """ |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2841 | return self.api(self.papi.vxlan_gbp_tunnel_add_del, |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 2842 | {'is_add': is_add, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2843 | 'tunnel': { |
| 2844 | 'src': src, |
| 2845 | 'dst': dst, |
| 2846 | 'mcast_sw_if_index': mcast_sw_if_index, |
| 2847 | 'encap_table_id': encap_table_id, |
Neale Ranns | 79a05f5 | 2018-09-11 07:39:43 -0700 | [diff] [blame] | 2848 | 'vni': vni, |
| 2849 | 'instance': instance}}) |
| 2850 | |
| 2851 | def vxlan_gbp_tunnel_dump(self, sw_if_index=0xffffffff): |
| 2852 | return self.api(self.papi.vxlan_gbp_tunnel_dump, |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 2853 | {'sw_if_index': sw_if_index, |
| 2854 | '_no_type_conversion': True}) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 2855 | |
Hongjun Ni | 62f9cdd | 2017-07-04 20:11:57 +0800 | [diff] [blame] | 2856 | def pppoe_add_del_session( |
| 2857 | self, |
| 2858 | client_ip, |
| 2859 | client_mac, |
| 2860 | session_id=0, |
| 2861 | is_add=1, |
| 2862 | is_ipv6=0, |
| 2863 | decap_vrf_id=0): |
| 2864 | """ |
| 2865 | |
| 2866 | :param is_add: (Default value = 1) |
| 2867 | :param is_ipv6: (Default value = 0) |
| 2868 | :param client_ip: |
| 2869 | :param session_id: (Default value = 0) |
| 2870 | :param client_mac: |
| 2871 | :param decap_vrf_id: (Default value = 0) |
| 2872 | |
| 2873 | """ |
| 2874 | return self.api(self.papi.pppoe_add_del_session, |
| 2875 | {'is_add': is_add, |
| 2876 | 'is_ipv6': is_ipv6, |
| 2877 | 'session_id': session_id, |
| 2878 | 'client_ip': client_ip, |
| 2879 | 'decap_vrf_id': decap_vrf_id, |
| 2880 | 'client_mac': client_mac}) |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2881 | |
Neale Ranns | 7c922dc | 2018-08-30 06:12:27 -0700 | [diff] [blame] | 2882 | def sr_mpls_policy_add(self, bsid, weight, type, segments): |
| 2883 | return self.api(self.papi.sr_mpls_policy_add, |
| 2884 | {'bsid': bsid, |
| 2885 | 'weight': weight, |
| 2886 | 'type': type, |
| 2887 | 'n_segments': len(segments), |
| 2888 | 'segments': segments}) |
| 2889 | |
| 2890 | def sr_mpls_policy_del(self, bsid): |
| 2891 | return self.api(self.papi.sr_mpls_policy_del, |
| 2892 | {'bsid': bsid}) |
| 2893 | |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2894 | def sr_localsid_add_del(self, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2895 | localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2896 | behavior, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2897 | nh_addr4, |
| 2898 | nh_addr6, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2899 | is_del=0, |
| 2900 | end_psp=0, |
| 2901 | sw_if_index=0xFFFFFFFF, |
| 2902 | vlan_index=0, |
| 2903 | fib_table=0, |
| 2904 | ): |
| 2905 | """ Add/del IPv6 SR local-SID. |
| 2906 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2907 | :param localsid: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2908 | :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; |
| 2909 | :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2910 | :param nh_addr4: |
| 2911 | :param nh_addr6: |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2912 | :param is_del: (Default value = 0) |
| 2913 | :param end_psp: (Default value = 0) |
| 2914 | :param sw_if_index: (Default value = 0xFFFFFFFF) |
| 2915 | :param vlan_index: (Default value = 0) |
| 2916 | :param fib_table: (Default value = 0) |
| 2917 | """ |
| 2918 | return self.api( |
| 2919 | self.papi.sr_localsid_add_del, |
| 2920 | {'is_del': is_del, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2921 | 'localsid': localsid, |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2922 | 'end_psp': end_psp, |
| 2923 | 'behavior': behavior, |
| 2924 | 'sw_if_index': sw_if_index, |
| 2925 | 'vlan_index': vlan_index, |
| 2926 | 'fib_table': fib_table, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 2927 | 'nh_addr4': nh_addr4, |
| 2928 | 'nh_addr6': nh_addr6 |
Kris Michielsen | 9107443 | 2017-06-22 13:00:20 +0200 | [diff] [blame] | 2929 | } |
| 2930 | ) |
| 2931 | |
| 2932 | def sr_policy_add( |
| 2933 | self, |
| 2934 | bsid_addr, |
| 2935 | weight=1, |
| 2936 | is_encap=1, |
| 2937 | type=0, |
| 2938 | fib_table=0, |
| 2939 | n_segments=0, |
| 2940 | segments=[]): |
| 2941 | """ |
| 2942 | :param bsid_addr: bindingSID of the SR Policy |
| 2943 | :param weight: weight of the sid list. optional. (default: 1) |
| 2944 | :param is_encap: (bool) whether SR policy should Encap or SRH insert \ |
| 2945 | (default: Encap) |
| 2946 | :param type: type/behavior of the SR policy. (default or spray) \ |
| 2947 | (default: default) |
| 2948 | :param fib_table: VRF where to install the FIB entry for the BSID \ |
| 2949 | (default: 0) |
| 2950 | :param n_segments: number of segments \ |
| 2951 | (default: 0) |
| 2952 | :param segments: a vector of IPv6 address composing the segment list \ |
| 2953 | (default: []) |
| 2954 | """ |
| 2955 | return self.api( |
| 2956 | self.papi.sr_policy_add, |
| 2957 | {'bsid_addr': bsid_addr, |
| 2958 | 'weight': weight, |
| 2959 | 'is_encap': is_encap, |
| 2960 | 'type': type, |
| 2961 | 'fib_table': fib_table, |
| 2962 | 'n_segments': n_segments, |
| 2963 | 'segments': segments |
| 2964 | } |
| 2965 | ) |
| 2966 | |
| 2967 | def sr_policy_del( |
| 2968 | self, |
| 2969 | bsid_addr, |
| 2970 | sr_policy_index=0): |
| 2971 | """ |
| 2972 | :param bsid: bindingSID of the SR Policy |
| 2973 | :param sr_policy_index: index of the sr policy (default: 0) |
| 2974 | """ |
| 2975 | return self.api( |
| 2976 | self.papi.sr_policy_del, |
| 2977 | {'bsid_addr': bsid_addr, |
| 2978 | 'sr_policy_index': sr_policy_index |
| 2979 | }) |
| 2980 | |
| 2981 | def sr_steering_add_del( |
| 2982 | self, |
| 2983 | is_del, |
| 2984 | bsid_addr, |
| 2985 | sr_policy_index, |
| 2986 | table_id, |
| 2987 | prefix_addr, |
| 2988 | mask_width, |
| 2989 | sw_if_index, |
| 2990 | traffic_type): |
| 2991 | """ |
| 2992 | Steer traffic L2 and L3 traffic through a given SR policy |
| 2993 | |
| 2994 | :param is_del: delete or add |
| 2995 | :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) |
| 2996 | :param sr_policy: is the index of the SR Policy (alt to bsid) |
| 2997 | :param table_id: is the VRF where to install the FIB entry for the BSID |
| 2998 | :param prefix_addr: is the IPv4/v6 address for L3 traffic type |
| 2999 | :param mask_width: is the mask for L3 traffic type |
| 3000 | :param sw_if_index: is the incoming interface for L2 traffic |
| 3001 | :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) |
| 3002 | """ |
| 3003 | return self.api( |
| 3004 | self.papi.sr_steering_add_del, |
| 3005 | {'is_del': is_del, |
| 3006 | 'bsid_addr': bsid_addr, |
| 3007 | 'sr_policy_index': sr_policy_index, |
| 3008 | 'table_id': table_id, |
| 3009 | 'prefix_addr': prefix_addr, |
| 3010 | 'mask_width': mask_width, |
| 3011 | 'sw_if_index': sw_if_index, |
| 3012 | 'traffic_type': traffic_type |
| 3013 | }) |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 3014 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 3015 | def acl_add_replace(self, acl_index, r, tag='', |
| 3016 | expected_retval=0): |
| 3017 | """Add/replace an ACL |
| 3018 | :param int acl_index: ACL index to replace, 2^32-1 to create new ACL. |
| 3019 | :param acl_rule r: ACL rules array. |
| 3020 | :param str tag: symbolic tag (description) for this ACL. |
| 3021 | :param int count: number of rules. |
| 3022 | """ |
| 3023 | return self.api(self.papi.acl_add_replace, |
| 3024 | {'acl_index': acl_index, |
| 3025 | 'r': r, |
| 3026 | 'count': len(r), |
| 3027 | 'tag': tag}, |
| 3028 | expected_retval=expected_retval) |
| 3029 | |
Andrew Yourtchenko | 987abe9 | 2017-09-27 13:50:31 +0200 | [diff] [blame] | 3030 | def acl_del(self, acl_index, expected_retval=0): |
| 3031 | """ |
| 3032 | |
| 3033 | :param acl_index: |
| 3034 | :return: |
| 3035 | """ |
| 3036 | return self.api(self.papi.acl_del, |
| 3037 | {'acl_index': acl_index}, |
| 3038 | expected_retval=expected_retval) |
| 3039 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 3040 | def acl_interface_set_acl_list(self, sw_if_index, n_input, acls, |
| 3041 | expected_retval=0): |
| 3042 | return self.api(self.papi.acl_interface_set_acl_list, |
| 3043 | {'sw_if_index': sw_if_index, |
| 3044 | 'count': len(acls), |
| 3045 | 'n_input': n_input, |
| 3046 | 'acls': acls}, |
| 3047 | expected_retval=expected_retval) |
| 3048 | |
Andrew Yourtchenko | c43b3f9 | 2018-02-06 17:42:32 +0100 | [diff] [blame] | 3049 | def acl_interface_set_etype_whitelist(self, sw_if_index, |
| 3050 | n_input, whitelist, |
| 3051 | expected_retval=0): |
| 3052 | return self.api(self.papi.acl_interface_set_etype_whitelist, |
| 3053 | {'sw_if_index': sw_if_index, |
| 3054 | 'count': len(whitelist), |
| 3055 | 'n_input': n_input, |
| 3056 | 'whitelist': whitelist}, |
| 3057 | expected_retval=expected_retval) |
| 3058 | |
Pavel Kotucek | 8daa80a | 2017-09-25 09:44:05 +0200 | [diff] [blame] | 3059 | def acl_interface_add_del(self, |
| 3060 | sw_if_index, |
| 3061 | acl_index, |
| 3062 | is_add=1): |
| 3063 | """ Add/Delete ACL to/from interface |
| 3064 | |
| 3065 | :param sw_if_index: |
| 3066 | :param acl_index: |
| 3067 | :param is_add: (Default value = 1) |
| 3068 | """ |
| 3069 | |
| 3070 | return self.api(self.papi.acl_interface_add_del, |
| 3071 | {'is_add': is_add, |
| 3072 | 'is_input': 1, |
| 3073 | 'sw_if_index': sw_if_index, |
| 3074 | 'acl_index': acl_index}) |
| 3075 | |
Andrew Yourtchenko | 51d2651 | 2017-09-14 18:26:36 +0200 | [diff] [blame] | 3076 | def acl_dump(self, acl_index, expected_retval=0): |
| 3077 | return self.api(self.papi.acl_dump, |
| 3078 | {'acl_index': acl_index}, |
| 3079 | expected_retval=expected_retval) |
| 3080 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 3081 | def acl_interface_list_dump(self, sw_if_index=0xFFFFFFFF, |
| 3082 | expected_retval=0): |
| 3083 | return self.api(self.papi.acl_interface_list_dump, |
| 3084 | {'sw_if_index': sw_if_index}, |
| 3085 | expected_retval=expected_retval) |
| 3086 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 3087 | def macip_acl_add(self, rules, tag=""): |
| 3088 | """ Add MACIP acl |
| 3089 | |
| 3090 | :param rules: list of rules for given acl |
| 3091 | :param tag: acl tag |
| 3092 | """ |
| 3093 | |
| 3094 | return self.api(self.papi.macip_acl_add, |
| 3095 | {'r': rules, |
| 3096 | 'count': len(rules), |
| 3097 | 'tag': tag}) |
| 3098 | |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 3099 | def macip_acl_add_replace(self, rules, acl_index=0xFFFFFFFF, tag=""): |
| 3100 | """ Add MACIP acl |
| 3101 | |
| 3102 | :param rules: list of rules for given acl |
| 3103 | :param tag: acl tag |
| 3104 | """ |
| 3105 | |
Pavel Kotucek | c29940c | 2017-09-07 08:17:31 +0200 | [diff] [blame] | 3106 | return self.api(self.papi.macip_acl_add_replace, |
| 3107 | {'acl_index': acl_index, |
| 3108 | 'r': rules, |
Pavel Kotucek | 932f741 | 2017-09-07 14:44:52 +0200 | [diff] [blame] | 3109 | 'count': len(rules), |
| 3110 | 'tag': tag}) |
| 3111 | |
| 3112 | def macip_acl_del(self, acl_index): |
| 3113 | """ |
| 3114 | |
| 3115 | :param acl_index: |
| 3116 | :return: |
| 3117 | """ |
| 3118 | return self.api(self.papi.macip_acl_del, |
| 3119 | {'acl_index': acl_index}) |
| 3120 | |
| 3121 | def macip_acl_interface_add_del(self, |
| 3122 | sw_if_index, |
| 3123 | acl_index, |
| 3124 | is_add=1): |
| 3125 | """ Add MACIP acl to interface |
| 3126 | |
| 3127 | :param sw_if_index: |
| 3128 | :param acl_index: |
| 3129 | :param is_add: (Default value = 1) |
| 3130 | """ |
| 3131 | |
| 3132 | return self.api(self.papi.macip_acl_interface_add_del, |
| 3133 | {'is_add': is_add, |
| 3134 | 'sw_if_index': sw_if_index, |
| 3135 | 'acl_index': acl_index}) |
| 3136 | |
| 3137 | def macip_acl_interface_get(self): |
| 3138 | """ Return interface acls dump |
| 3139 | """ |
| 3140 | return self.api( |
| 3141 | self.papi.macip_acl_interface_get, {}) |
| 3142 | |
| 3143 | def macip_acl_dump(self, acl_index=4294967295): |
| 3144 | """ Return MACIP acl dump |
| 3145 | """ |
| 3146 | |
| 3147 | return self.api( |
| 3148 | self.papi.macip_acl_dump, {'acl_index': acl_index}) |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 3149 | |
| 3150 | def policer_add_del(self, |
| 3151 | name, |
| 3152 | cir, |
| 3153 | eir, |
| 3154 | cb, |
| 3155 | eb, |
| 3156 | is_add=1, |
| 3157 | rate_type=0, |
| 3158 | round_type=0, |
| 3159 | ptype=0, |
| 3160 | color_aware=0, |
| 3161 | conform_action_type=1, |
| 3162 | conform_dscp=0, |
| 3163 | exceed_action_type=0, |
| 3164 | exceed_dscp=0, |
| 3165 | violate_action_type=0, |
| 3166 | violate_dscp=0): |
| 3167 | return self.api(self.papi.policer_add_del, |
| 3168 | {'name': name, |
| 3169 | 'cir': cir, |
| 3170 | 'eir': eir, |
| 3171 | 'cb': cb, |
| 3172 | 'eb': eb, |
| 3173 | 'is_add': is_add, |
| 3174 | 'rate_type': rate_type, |
| 3175 | 'round_type': round_type, |
| 3176 | 'type': ptype, |
| 3177 | 'color_aware': color_aware, |
| 3178 | 'conform_action_type': conform_action_type, |
| 3179 | 'conform_dscp': conform_dscp, |
| 3180 | 'exceed_action_type': exceed_action_type, |
| 3181 | 'exceed_dscp': exceed_dscp, |
| 3182 | 'violate_action_type': violate_action_type, |
| 3183 | 'violate_dscp': violate_dscp}) |
| 3184 | |
| 3185 | def ip_punt_police(self, |
| 3186 | policer_index, |
| 3187 | is_ip6=0, |
| 3188 | is_add=1): |
| 3189 | return self.api(self.papi.ip_punt_police, |
| 3190 | {'policer_index': policer_index, |
| 3191 | 'is_add': is_add, |
| 3192 | 'is_ip6': is_ip6}) |
| 3193 | |
| 3194 | def ip_punt_redirect(self, |
| 3195 | rx_sw_if_index, |
| 3196 | tx_sw_if_index, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 3197 | address, |
Neale Ranns | d91c1db | 2017-07-31 02:30:50 -0700 | [diff] [blame] | 3198 | is_add=1): |
| 3199 | return self.api(self.papi.ip_punt_redirect, |
Pavel Kotucek | 609e121 | 2018-11-27 09:59:44 +0100 | [diff] [blame] | 3200 | {'punt': {'rx_sw_if_index': rx_sw_if_index, |
| 3201 | 'tx_sw_if_index': tx_sw_if_index, |
| 3202 | 'nh': address}, |
| 3203 | 'is_add': is_add}) |
| 3204 | |
| 3205 | def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0): |
| 3206 | return self.api(self.papi.ip_punt_redirect_dump, |
| 3207 | {'sw_if_index': sw_if_index, |
| 3208 | 'is_ipv6': is_ipv6}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3209 | |
| 3210 | def bier_table_add_del(self, |
| 3211 | bti, |
| 3212 | mpls_label, |
| 3213 | is_add=1): |
| 3214 | """ BIER Table add/del """ |
| 3215 | return self.api( |
| 3216 | self.papi.bier_table_add_del, |
| 3217 | {'bt_tbl_id': {"bt_set": bti.set_id, |
| 3218 | "bt_sub_domain": bti.sub_domain_id, |
| 3219 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 3220 | 'bt_label': mpls_label, |
| 3221 | 'bt_is_add': is_add}) |
| 3222 | |
| 3223 | def bier_table_dump(self): |
| 3224 | return self.api(self.papi.bier_table_dump, {}) |
| 3225 | |
| 3226 | def bier_route_add_del(self, |
| 3227 | bti, |
| 3228 | bp, |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 3229 | paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 3230 | is_add=1, |
| 3231 | is_replace=0): |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3232 | """ BIER Route add/del """ |
| 3233 | return self.api( |
| 3234 | self.papi.bier_route_add_del, |
| 3235 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 3236 | "bt_sub_domain": bti.sub_domain_id, |
| 3237 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 3238 | 'br_bp': bp, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 3239 | 'br_n_paths': len(paths), |
| 3240 | 'br_paths': paths, |
Neale Ranns | ef90ed0 | 2018-09-13 08:45:12 -0700 | [diff] [blame] | 3241 | 'br_is_add': is_add, |
| 3242 | 'br_is_replace': is_replace}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3243 | |
| 3244 | def bier_route_dump(self, bti): |
| 3245 | return self.api( |
| 3246 | self.papi.bier_route_dump, |
| 3247 | {'br_tbl_id': {"bt_set": bti.set_id, |
| 3248 | "bt_sub_domain": bti.sub_domain_id, |
| 3249 | "bt_hdr_len_id": bti.hdr_len_id}}) |
| 3250 | |
| 3251 | def bier_imp_add(self, |
| 3252 | bti, |
| 3253 | src, |
| 3254 | ibytes, |
| 3255 | is_add=1): |
| 3256 | """ BIER Imposition Add """ |
| 3257 | return self.api( |
| 3258 | self.papi.bier_imp_add, |
| 3259 | {'bi_tbl_id': {"bt_set": bti.set_id, |
| 3260 | "bt_sub_domain": bti.sub_domain_id, |
| 3261 | "bt_hdr_len_id": bti.hdr_len_id}, |
| 3262 | 'bi_src': src, |
| 3263 | 'bi_n_bytes': len(ibytes), |
| 3264 | 'bi_bytes': ibytes}) |
| 3265 | |
| 3266 | def bier_imp_del(self, bi_index): |
| 3267 | """ BIER Imposition del """ |
| 3268 | return self.api( |
| 3269 | self.papi.bier_imp_del, |
| 3270 | {'bi_index': bi_index}) |
| 3271 | |
| 3272 | def bier_imp_dump(self): |
| 3273 | return self.api(self.papi.bier_imp_dump, {}) |
| 3274 | |
| 3275 | def bier_disp_table_add_del(self, |
| 3276 | bdti, |
| 3277 | is_add=1): |
| 3278 | """ BIER Disposition Table add/del """ |
| 3279 | return self.api( |
| 3280 | self.papi.bier_disp_table_add_del, |
| 3281 | {'bdt_tbl_id': bdti, |
| 3282 | 'bdt_is_add': is_add}) |
| 3283 | |
| 3284 | def bier_disp_table_dump(self): |
| 3285 | return self.api(self.papi.bier_disp_table_dump, {}) |
| 3286 | |
| 3287 | def bier_disp_entry_add_del(self, |
| 3288 | bdti, |
| 3289 | bp, |
| 3290 | payload_proto, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 3291 | next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3292 | next_hop, |
| 3293 | next_hop_tbl_id=0, |
| 3294 | next_hop_rpf_id=~0, |
| 3295 | next_hop_is_ip4=1, |
| 3296 | is_add=1): |
| 3297 | """ BIER Route add/del """ |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 3298 | lstack = [] |
| 3299 | while (len(lstack) < 16): |
| 3300 | lstack.append({}) |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3301 | return self.api( |
| 3302 | self.papi.bier_disp_entry_add_del, |
| 3303 | {'bde_tbl_id': bdti, |
| 3304 | 'bde_bp': bp, |
| 3305 | 'bde_payload_proto': payload_proto, |
| 3306 | 'bde_n_paths': 1, |
| 3307 | 'bde_paths': [{'next_hop': next_hop, |
| 3308 | 'table_id': next_hop_tbl_id, |
Neale Ranns | f051072 | 2018-01-31 11:35:41 -0800 | [diff] [blame] | 3309 | 'afi': next_hop_afi, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3310 | 'rpf_id': next_hop_rpf_id, |
| 3311 | 'n_labels': 0, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 3312 | 'label_stack': lstack}], |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 3313 | 'bde_is_add': is_add}) |
| 3314 | |
| 3315 | def bier_disp_entry_dump(self, bdti): |
| 3316 | return self.api( |
| 3317 | self.papi.bier_disp_entry_dump, |
| 3318 | {'bde_tbl_id': bdti}) |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 3319 | |
| 3320 | def add_node_next(self, node_name, next_name): |
| 3321 | """ Set the next node for a given node request |
| 3322 | |
| 3323 | :param node_name: |
| 3324 | :param next_name: |
| 3325 | """ |
| 3326 | return self.api(self.papi.add_node_next, |
| 3327 | {'node_name': node_name, |
| 3328 | 'next_name': next_name}) |
Florin Coras | 3ea6ce2 | 2017-12-11 09:09:05 -0800 | [diff] [blame] | 3329 | |
| 3330 | def session_enable_disable(self, is_enabled): |
| 3331 | return self.api( |
| 3332 | self.papi.session_enable_disable, |
| 3333 | {'is_enable': is_enabled}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3334 | |
| 3335 | def ipsec_spd_add_del(self, spd_id, is_add=1): |
| 3336 | """ SPD add/del - Wrapper to add or del ipsec SPD |
| 3337 | Sample CLI : 'ipsec spd add 1' |
| 3338 | |
| 3339 | :param spd_id - SPD ID to be created in the vpp . mandatory |
| 3340 | :param is_add - create (1) or delete(0) SPD (Default 1 - add) . |
| 3341 | optional |
| 3342 | :returns: reply from the API |
| 3343 | """ |
| 3344 | return self.api( |
| 3345 | self.papi.ipsec_spd_add_del, { |
| 3346 | 'spd_id': spd_id, 'is_add': is_add}) |
| 3347 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 3348 | def ipsec_spds_dump(self): |
| 3349 | return self.api(self.papi.ipsec_spds_dump, {}) |
| 3350 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3351 | def ipsec_interface_add_del_spd(self, spd_id, sw_if_index, is_add=1): |
| 3352 | """ IPSEC interface SPD add/del - \ |
| 3353 | Wrapper to associate/disassociate SPD to interface in VPP |
| 3354 | Sample CLI : 'set interface ipsec spd GigabitEthernet0/6/0 1' |
| 3355 | |
| 3356 | :param spd_id - SPD ID to associate with the interface . mandatory |
| 3357 | :param sw_if_index - Interface Index which needs to ipsec \ |
| 3358 | association mandatory |
| 3359 | :param is_add - add(1) or del(0) association with interface \ |
| 3360 | (Default 1 - add) . optional |
| 3361 | :returns: reply from the API |
| 3362 | """ |
| 3363 | return self.api( |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 3364 | self.papi.ipsec_interface_add_del_spd, |
| 3365 | {'spd_id': spd_id, 'sw_if_index': sw_if_index, 'is_add': is_add}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3366 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 3367 | def ipsec_spd_interface_dump(self, spd_index=None): |
| 3368 | return self.api(self.papi.ipsec_spd_interface_dump, |
| 3369 | {'spd_index': spd_index if spd_index else 0, |
| 3370 | 'spd_index_valid': 1 if spd_index else 0}) |
| 3371 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3372 | def ipsec_sad_add_del_entry(self, |
| 3373 | sad_id, |
| 3374 | spi, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3375 | integrity_algorithm, |
| 3376 | integrity_key, |
| 3377 | crypto_algorithm, |
| 3378 | crypto_key, |
| 3379 | protocol, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3380 | tunnel_src_address='', |
| 3381 | tunnel_dst_address='', |
Ole Troan | e0d2bd6 | 2018-06-22 22:36:46 +0200 | [diff] [blame] | 3382 | is_tunnel=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 3383 | is_tunnel_ipv6=0, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3384 | is_add=1, |
Neale Ranns | de84727 | 2018-11-28 01:38:34 -0800 | [diff] [blame] | 3385 | udp_encap=0, |
| 3386 | use_anti_replay=0, |
| 3387 | use_extended_sequence_number=0): |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3388 | """ IPSEC SA add/del |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3389 | :param sad_id: security association ID |
| 3390 | :param spi: security param index of the SA in decimal |
| 3391 | :param integrity_algorithm: |
| 3392 | :param integrity_key: |
| 3393 | :param crypto_algorithm: |
| 3394 | :param crypto_key: |
| 3395 | :param protocol: AH(0) or ESP(1) protocol |
| 3396 | :param tunnel_src_address: tunnel mode outer src address |
| 3397 | :param tunnel_dst_address: tunnel mode outer dst address |
| 3398 | :param is_add: |
| 3399 | :param is_tunnel: |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3400 | :** reference /vpp/src/vnet/ipsec/ipsec.h file for enum values of |
| 3401 | crypto and ipsec algorithms |
| 3402 | """ |
| 3403 | return self.api( |
| 3404 | self.papi.ipsec_sad_add_del_entry, |
| 3405 | {'sad_id': sad_id, |
| 3406 | 'spi': spi, |
| 3407 | 'tunnel_src_address': tunnel_src_address, |
| 3408 | 'tunnel_dst_address': tunnel_dst_address, |
| 3409 | 'protocol': protocol, |
| 3410 | 'integrity_algorithm': integrity_algorithm, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3411 | 'integrity_key_length': len(integrity_key), |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3412 | 'integrity_key': integrity_key, |
| 3413 | 'crypto_algorithm': crypto_algorithm, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3414 | 'crypto_key_length': len(crypto_key) if crypto_key is not None |
| 3415 | else 0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3416 | 'crypto_key': crypto_key, |
| 3417 | 'is_add': is_add, |
Klement Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 3418 | 'is_tunnel': is_tunnel, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 3419 | 'is_tunnel_ipv6': is_tunnel_ipv6, |
Neale Ranns | de84727 | 2018-11-28 01:38:34 -0800 | [diff] [blame] | 3420 | 'udp_encap': udp_encap, |
| 3421 | 'use_extended_sequence_number': use_extended_sequence_number, |
| 3422 | 'use_anti_replay': use_anti_replay}) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3423 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 3424 | def ipsec_sa_dump(self, sa_id=None): |
| 3425 | return self.api(self.papi.ipsec_sa_dump, |
| 3426 | {'sa_id': sa_id if sa_id else 0xffffffff}) |
| 3427 | |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3428 | def ipsec_spd_add_del_entry(self, |
| 3429 | spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3430 | sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3431 | local_address_start, |
| 3432 | local_address_stop, |
| 3433 | remote_address_start, |
| 3434 | remote_address_stop, |
| 3435 | local_port_start=0, |
| 3436 | local_port_stop=65535, |
| 3437 | remote_port_start=0, |
| 3438 | remote_port_stop=65535, |
| 3439 | protocol=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3440 | policy=0, |
| 3441 | priority=100, |
| 3442 | is_outbound=1, |
| 3443 | is_add=1, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 3444 | is_ipv6=0, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3445 | is_ip_any=0): |
| 3446 | """ IPSEC policy SPD add/del - |
| 3447 | Wrapper to configure ipsec SPD policy entries in VPP |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3448 | :param spd_id: SPD ID for the policy |
| 3449 | :param local_address_start: local-ip-range start address |
| 3450 | :param local_address_stop : local-ip-range stop address |
| 3451 | :param remote_address_start: remote-ip-range start address |
| 3452 | :param remote_address_stop : remote-ip-range stop address |
| 3453 | :param local_port_start: (Default value = 0) |
| 3454 | :param local_port_stop: (Default value = 65535) |
| 3455 | :param remote_port_start: (Default value = 0) |
| 3456 | :param remote_port_stop: (Default value = 65535) |
| 3457 | :param protocol: Any(0), AH(51) & ESP(50) protocol (Default value = 0) |
| 3458 | :param sa_id: Security Association ID for mapping it to SPD |
| 3459 | :param policy: bypass(0), discard(1), resolve(2) or protect(3) action |
| 3460 | (Default value = 0) |
| 3461 | :param priority: value for the spd action (Default value = 100) |
| 3462 | :param is_outbound: flag for inbound(0) or outbound(1) |
| 3463 | (Default value = 1) |
| 3464 | :param is_add: (Default value = 1) |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3465 | """ |
| 3466 | return self.api( |
| 3467 | self.papi.ipsec_spd_add_del_entry, |
| 3468 | {'spd_id': spd_id, |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3469 | 'sa_id': sa_id, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3470 | 'local_address_start': local_address_start, |
| 3471 | 'local_address_stop': local_address_stop, |
| 3472 | 'remote_address_start': remote_address_start, |
| 3473 | 'remote_address_stop': remote_address_stop, |
| 3474 | 'local_port_start': local_port_start, |
| 3475 | 'local_port_stop': local_port_stop, |
| 3476 | 'remote_port_start': remote_port_start, |
| 3477 | 'remote_port_stop': remote_port_stop, |
| 3478 | 'is_add': is_add, |
| 3479 | 'protocol': protocol, |
| 3480 | 'policy': policy, |
| 3481 | 'priority': priority, |
| 3482 | 'is_outbound': is_outbound, |
Klement Sekera | 611864f | 2018-09-26 11:19:00 +0200 | [diff] [blame] | 3483 | 'is_ipv6': is_ipv6, |
“mystarrocks” | 23f0c45 | 2017-12-11 07:11:51 -0800 | [diff] [blame] | 3484 | 'is_ip_any': is_ip_any}) |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 3485 | |
Neale Ranns | 311124e | 2019-01-24 04:52:25 -0800 | [diff] [blame] | 3486 | def ipsec_spd_dump(self, spd_id, sa_id=0xffffffff): |
| 3487 | return self.api(self.papi.ipsec_spd_dump, |
| 3488 | {'spd_id': spd_id, |
| 3489 | 'sa_id': sa_id}) |
| 3490 | |
Klement Sekera | 31da2e3 | 2018-06-24 22:49:55 +0200 | [diff] [blame] | 3491 | def ipsec_tunnel_if_add_del(self, local_ip, remote_ip, local_spi, |
| 3492 | remote_spi, crypto_alg, local_crypto_key, |
| 3493 | remote_crypto_key, integ_alg, local_integ_key, |
| 3494 | remote_integ_key, is_add=1, esn=0, |
| 3495 | anti_replay=1, renumber=0, show_instance=0): |
| 3496 | return self.api( |
| 3497 | self.papi.ipsec_tunnel_if_add_del, |
| 3498 | {'local_ip': local_ip, 'remote_ip': remote_ip, |
| 3499 | 'local_spi': local_spi, 'remote_spi': remote_spi, |
| 3500 | 'crypto_alg': crypto_alg, |
| 3501 | 'local_crypto_key_len': len(local_crypto_key), |
| 3502 | 'local_crypto_key': local_crypto_key, |
| 3503 | 'remote_crypto_key_len': len(remote_crypto_key), |
| 3504 | 'remote_crypto_key': remote_crypto_key, 'integ_alg': integ_alg, |
| 3505 | 'local_integ_key_len': len(local_integ_key), |
| 3506 | 'local_integ_key': local_integ_key, |
| 3507 | 'remote_integ_key_len': len(remote_integ_key), |
| 3508 | 'remote_integ_key': remote_integ_key, 'is_add': is_add, |
| 3509 | 'esn': esn, 'anti_replay': anti_replay, 'renumber': renumber, |
| 3510 | 'show_instance': show_instance |
| 3511 | }) |
| 3512 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 3513 | def ipsec_select_backend(self, protocol, index): |
| 3514 | return self.api(self.papi.ipsec_select_backend, |
| 3515 | {'protocol': protocol, 'index': index}) |
| 3516 | |
| 3517 | def ipsec_backend_dump(self): |
| 3518 | return self.api(self.papi.ipsec_backend_dump, {}) |
| 3519 | |
Florin Coras | b795bd0 | 2017-12-14 11:30:48 -0800 | [diff] [blame] | 3520 | def app_namespace_add(self, |
| 3521 | namespace_id, |
| 3522 | ip4_fib_id=0, |
| 3523 | ip6_fib_id=0, |
| 3524 | sw_if_index=0xFFFFFFFF, |
| 3525 | secret=0): |
| 3526 | return self.api( |
| 3527 | self.papi.app_namespace_add_del, |
| 3528 | {'secret': secret, |
| 3529 | 'sw_if_index': sw_if_index, |
| 3530 | 'ip4_fib_id': ip4_fib_id, |
| 3531 | 'ip6_fib_id': ip6_fib_id, |
| 3532 | 'namespace_id': namespace_id, |
| 3533 | 'namespace_id_len': len(namespace_id)}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 3534 | |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 3535 | def punt_socket_register(self, port, pathname, protocol=0x11, |
| 3536 | header_version=1, is_ip4=1): |
| 3537 | """ Register punt socket """ |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 3538 | return self.api(self.papi.punt_socket_register, |
Pavel Kotucek | e88865d | 2018-11-28 07:42:11 +0100 | [diff] [blame] | 3539 | {'header_version': header_version, |
| 3540 | 'punt': {'ipv': is_ip4, |
| 3541 | 'l4_protocol': protocol, |
| 3542 | 'l4_port': port}, |
| 3543 | 'pathname': pathname}) |
| 3544 | |
| 3545 | def punt_socket_deregister(self, port, protocol=0x11, is_ip4=1): |
| 3546 | """ Unregister punt socket """ |
| 3547 | return self.api(self.papi.punt_socket_deregister, |
| 3548 | {'punt': {'ipv': is_ip4, |
| 3549 | 'l4_protocol': protocol, |
| 3550 | 'l4_port': port}}) |
| 3551 | |
| 3552 | def punt_socket_dump(self, is_ip6=1): |
| 3553 | """ Dump punt socket""" |
| 3554 | return self.api(self.papi.punt_socket_dump, |
| 3555 | {'is_ipv6': is_ip6}) |
Klement Sekera | 75e7d13 | 2017-09-20 08:26:30 +0200 | [diff] [blame] | 3556 | |
| 3557 | def ip_reassembly_set(self, timeout_ms, max_reassemblies, |
| 3558 | expire_walk_interval_ms, is_ip6=0): |
| 3559 | """ Set IP reassembly parameters """ |
| 3560 | return self.api(self.papi.ip_reassembly_set, |
| 3561 | {'is_ip6': is_ip6, |
| 3562 | 'timeout_ms': timeout_ms, |
| 3563 | 'expire_walk_interval_ms': expire_walk_interval_ms, |
| 3564 | 'max_reassemblies': max_reassemblies}) |
| 3565 | |
| 3566 | def ip_reassembly_get(self, is_ip6=0): |
| 3567 | """ Get IP reassembly parameters """ |
| 3568 | return self.api(self.papi.ip_reassembly_get, {'is_ip6': is_ip6}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3569 | |
Klement Sekera | 4c53313 | 2018-02-22 11:41:12 +0100 | [diff] [blame] | 3570 | def ip_reassembly_enable_disable(self, sw_if_index, enable_ip4=False, |
| 3571 | enable_ip6=False): |
| 3572 | """ Enable/disable IP reassembly """ |
| 3573 | return self.api(self.papi.ip_reassembly_enable_disable, |
| 3574 | {'sw_if_index': sw_if_index, |
| 3575 | 'enable_ip4': 1 if enable_ip4 else 0, |
| 3576 | 'enable_ip6': 1 if enable_ip6 else 0, |
| 3577 | }) |
| 3578 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3579 | def gbp_endpoint_add(self, sw_if_index, ips, mac, epg, flags, |
| 3580 | tun_src, tun_dst): |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 3581 | """ GBP endpoint Add """ |
| 3582 | return self.api(self.papi.gbp_endpoint_add, |
| 3583 | {'endpoint': { |
| 3584 | 'sw_if_index': sw_if_index, |
| 3585 | 'ips': ips, |
| 3586 | 'n_ips': len(ips), |
| 3587 | 'mac': mac, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3588 | 'epg_id': epg, |
| 3589 | 'flags': flags, |
| 3590 | 'tun': { |
| 3591 | 'src': tun_src, |
| 3592 | 'dst': tun_dst, |
| 3593 | }}}) |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 3594 | |
| 3595 | def gbp_endpoint_del(self, handle): |
| 3596 | """ GBP endpoint Del """ |
| 3597 | return self.api(self.papi.gbp_endpoint_del, |
| 3598 | {'handle': handle}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3599 | |
| 3600 | def gbp_endpoint_dump(self): |
| 3601 | """ GBP endpoint Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 3602 | return self.api(self.papi.gbp_endpoint_dump, |
| 3603 | {'_no_type_conversion': True}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3604 | |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3605 | def gbp_endpoint_group_add(self, epg, sclass, bd, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3606 | rd, uplink_sw_if_index): |
| 3607 | """ GBP endpoint group Add """ |
| 3608 | return self.api(self.papi.gbp_endpoint_group_add, |
| 3609 | {'epg': |
| 3610 | { |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3611 | 'uplink_sw_if_index': uplink_sw_if_index, |
| 3612 | 'bd_id': bd, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3613 | 'rd_id': rd, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3614 | 'epg_id': epg, |
| 3615 | 'sclass': sclass |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3616 | }}) |
| 3617 | |
| 3618 | def gbp_endpoint_group_del(self, epg): |
| 3619 | """ GBP endpoint group Del """ |
| 3620 | return self.api(self.papi.gbp_endpoint_group_del, |
| 3621 | {'epg_id': epg}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3622 | |
| 3623 | def gbp_endpoint_group_dump(self): |
| 3624 | """ GBP endpoint group Dump """ |
| 3625 | return self.api(self.papi.gbp_endpoint_group_dump, {}) |
| 3626 | |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 3627 | def gbp_bridge_domain_add(self, bd_id, flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3628 | bvi_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3629 | uu_fwd_sw_if_index, |
| 3630 | bm_flood_sw_if_index): |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3631 | """ GBP bridge-domain Add """ |
| 3632 | return self.api(self.papi.gbp_bridge_domain_add, |
| 3633 | {'bd': |
| 3634 | { |
Neale Ranns | c29c0af | 2018-11-07 04:21:12 -0800 | [diff] [blame] | 3635 | 'flags': flags, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3636 | 'bvi_sw_if_index': bvi_sw_if_index, |
| 3637 | 'uu_fwd_sw_if_index': uu_fwd_sw_if_index, |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 3638 | 'bm_flood_sw_if_index': bm_flood_sw_if_index, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3639 | 'bd_id': bd_id |
| 3640 | }}) |
| 3641 | |
| 3642 | def gbp_bridge_domain_del(self, bd_id): |
| 3643 | """ GBP bridge-domain Del """ |
| 3644 | return self.api(self.papi.gbp_bridge_domain_del, |
| 3645 | {'bd_id': bd_id}) |
| 3646 | |
| 3647 | def gbp_bridge_domain_dump(self): |
| 3648 | """ GBP Bridge Domain Dump """ |
| 3649 | return self.api(self.papi.gbp_bridge_domain_dump, {}) |
| 3650 | |
| 3651 | def gbp_route_domain_add(self, rd_id, |
| 3652 | ip4_table_id, |
| 3653 | ip6_table_id, |
| 3654 | ip4_uu_sw_if_index, |
| 3655 | ip6_uu_sw_if_index): |
| 3656 | """ GBP route-domain Add """ |
| 3657 | return self.api(self.papi.gbp_route_domain_add, |
| 3658 | {'rd': |
| 3659 | { |
| 3660 | 'ip4_table_id': ip4_table_id, |
| 3661 | 'ip6_table_id': ip6_table_id, |
| 3662 | 'ip4_uu_sw_if_index': ip4_uu_sw_if_index, |
| 3663 | 'ip6_uu_sw_if_index': ip6_uu_sw_if_index, |
| 3664 | 'rd_id': rd_id |
| 3665 | }}) |
| 3666 | |
| 3667 | def gbp_route_domain_del(self, rd_id): |
| 3668 | """ GBP route-domain Del """ |
| 3669 | return self.api(self.papi.gbp_route_domain_del, |
| 3670 | {'rd_id': rd_id}) |
| 3671 | |
| 3672 | def gbp_route_domain_dump(self): |
| 3673 | """ GBP Route Domain Dump """ |
| 3674 | return self.api(self.papi.gbp_route_domain_dump, {}) |
| 3675 | |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3676 | def gbp_recirc_add_del(self, is_add, sw_if_index, epg, is_ext): |
| 3677 | """ GBP recirc Add/Del """ |
| 3678 | return self.api(self.papi.gbp_recirc_add_del, |
| 3679 | {'is_add': is_add, |
| 3680 | 'recirc': { |
| 3681 | 'is_ext': is_ext, |
| 3682 | 'sw_if_index': sw_if_index, |
| 3683 | 'epg_id': epg}}) |
| 3684 | |
| 3685 | def gbp_recirc_dump(self): |
| 3686 | """ GBP recirc Dump """ |
| 3687 | return self.api(self.papi.gbp_recirc_dump, {}) |
| 3688 | |
Neale Ranns | b6a4795 | 2018-11-21 05:44:35 -0800 | [diff] [blame] | 3689 | def gbp_ext_itf_add_del(self, is_add, sw_if_index, bd_id, rd_id): |
| 3690 | """ GBP recirc Add/Del """ |
| 3691 | return self.api(self.papi.gbp_ext_itf_add_del, |
| 3692 | {'is_add': is_add, |
| 3693 | 'ext_itf': { |
| 3694 | 'sw_if_index': sw_if_index, |
| 3695 | 'bd_id': bd_id, |
| 3696 | 'rd_id': rd_id}}) |
| 3697 | |
| 3698 | def gbp_ext_itf_dump(self): |
| 3699 | """ GBP recirc Dump """ |
| 3700 | return self.api(self.papi.gbp_ext_itf_dump, {}) |
| 3701 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3702 | def gbp_subnet_add_del(self, is_add, rd_id, |
| 3703 | prefix, type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3704 | sw_if_index=0xffffffff, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3705 | epg_id=0xffff): |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3706 | """ GBP Subnet Add/Del """ |
| 3707 | return self.api(self.papi.gbp_subnet_add_del, |
| 3708 | {'is_add': is_add, |
| 3709 | 'subnet': { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3710 | 'type': type, |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3711 | 'sw_if_index': sw_if_index, |
| 3712 | 'epg_id': epg_id, |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 3713 | 'prefix': prefix, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3714 | 'rd_id': rd_id}}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3715 | |
| 3716 | def gbp_subnet_dump(self): |
| 3717 | """ GBP Subnet Dump """ |
Ole Troan | 0bcad32 | 2018-12-11 13:04:01 +0100 | [diff] [blame] | 3718 | return self.api(self.papi.gbp_subnet_dump, |
| 3719 | {'_no_type_conversion': True}) |
Neale Ranns | 25b0494 | 2018-04-04 09:34:50 -0700 | [diff] [blame] | 3720 | |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3721 | def gbp_contract_add_del(self, is_add, src_epg, dst_epg, acl_index, |
| 3722 | rules, allowed_ethertypes): |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3723 | """ GBP contract Add/Del """ |
| 3724 | return self.api(self.papi.gbp_contract_add_del, |
| 3725 | {'is_add': is_add, |
| 3726 | 'contract': { |
| 3727 | 'acl_index': acl_index, |
| 3728 | 'src_epg': src_epg, |
Neale Ranns | 13a08cc | 2018-11-07 09:25:54 -0800 | [diff] [blame] | 3729 | 'dst_epg': dst_epg, |
| 3730 | 'n_rules': len(rules), |
Neale Ranns | 1c17e2e | 2018-12-20 12:03:59 -0800 | [diff] [blame] | 3731 | 'rules': rules, |
| 3732 | 'n_ether_types': len(allowed_ethertypes), |
| 3733 | 'allowed_ethertypes': allowed_ethertypes}}) |
Neale Ranns | bc27d1b | 2018-02-05 01:13:38 -0800 | [diff] [blame] | 3734 | |
| 3735 | def gbp_contract_dump(self): |
| 3736 | """ GBP contract Dump """ |
| 3737 | return self.api(self.papi.gbp_contract_dump, {}) |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3738 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 3739 | def gbp_endpoint_learn_set_inactive_threshold(self, threshold): |
| 3740 | """ GBP set inactive threshold """ |
| 3741 | return self.api(self.papi.gbp_endpoint_learn_set_inactive_threshold, |
| 3742 | {'threshold': threshold}) |
| 3743 | |
| 3744 | def gbp_vxlan_tunnel_add(self, vni, bd_rd_id, mode): |
| 3745 | """ GBP VXLAN tunnel add """ |
| 3746 | return self.api(self.papi.gbp_vxlan_tunnel_add, |
| 3747 | { |
| 3748 | 'tunnel': { |
| 3749 | 'vni': vni, |
| 3750 | 'mode': mode, |
| 3751 | 'bd_rd_id': bd_rd_id |
| 3752 | } |
| 3753 | }) |
| 3754 | |
| 3755 | def gbp_vxlan_tunnel_del(self, vni): |
| 3756 | """ GBP VXLAN tunnel del """ |
| 3757 | return self.api(self.papi.gbp_vxlan_tunnel_del, |
| 3758 | { |
| 3759 | 'vni': vni, |
| 3760 | }) |
| 3761 | |
| 3762 | def gbp_vxlan_tunnel_dump(self): |
| 3763 | """ GBP VXLAN tunnel add/del """ |
| 3764 | return self.api(self.papi.gbp_vxlan_tunnel_dump, {}) |
| 3765 | |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 3766 | def ipip_6rd_add_tunnel(self, ip6_table_id, ip6_prefix, ip6_prefix_len, |
| 3767 | ip4_table_id, ip4_prefix, ip4_prefix_len, ip4_src, |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3768 | security_check): |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3769 | """ 6RD tunnel Add """ |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3770 | return self.api(self.papi.ipip_6rd_add_tunnel, |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 3771 | {'ip4_table_id': ip4_table_id, |
| 3772 | 'ip6_table_id': ip6_table_id, |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3773 | 'ip6_prefix': ip6_prefix, |
| 3774 | 'ip6_prefix_len': ip6_prefix_len, |
| 3775 | 'ip4_prefix': ip4_prefix, |
| 3776 | 'ip4_prefix_len': ip4_prefix_len, |
| 3777 | 'ip4_src': ip4_src, |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3778 | 'security_check': security_check}) |
| 3779 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3780 | def ipip_6rd_del_tunnel(self, sw_if_index): |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3781 | """ 6RD tunnel Delete """ |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3782 | return self.api(self.papi.ipip_6rd_del_tunnel, |
| 3783 | {'sw_if_index': sw_if_index}) |
| 3784 | |
| 3785 | def ipip_add_tunnel(self, src_address, dst_address, is_ipv6=1, |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 3786 | instance=0xFFFFFFFF, table_id=0, tc_tos=0): |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3787 | """ IPIP tunnel Add/Del """ |
| 3788 | return self.api(self.papi.ipip_add_tunnel, |
| 3789 | {'is_ipv6': is_ipv6, |
| 3790 | 'instance': instance, |
| 3791 | 'src_address': src_address, |
| 3792 | 'dst_address': dst_address, |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 3793 | 'table_id': table_id, |
Ole Troan | d57f636 | 2018-05-24 13:21:43 +0200 | [diff] [blame] | 3794 | 'tc_tos': tc_tos}) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 3795 | |
| 3796 | def ipip_del_tunnel(self, sw_if_index): |
| 3797 | """ IPIP tunnel Delete """ |
| 3798 | return self.api(self.papi.ipip_del_tunnel, |
Ole Troan | 6ee4051 | 2018-02-12 18:14:39 +0100 | [diff] [blame] | 3799 | {'sw_if_index': sw_if_index}) |
Neale Ranns | 039cbfe | 2018-02-27 03:45:38 -0800 | [diff] [blame] | 3800 | |
| 3801 | def qos_egress_map_update(self, id, outputs): |
| 3802 | """ QOS egress map update """ |
| 3803 | return self.api(self.papi.qos_egress_map_update, |
| 3804 | {'map_id': id, |
| 3805 | 'rows': outputs}) |
| 3806 | |
| 3807 | def qos_egress_map_delete(self, id): |
| 3808 | """ QOS egress map delete """ |
| 3809 | return self.api(self.papi.qos_egress_map_delete, |
| 3810 | {'map_id': id}) |
| 3811 | |
| 3812 | def qos_mark_enable_disable(self, sw_if_index, |
| 3813 | output_source, |
| 3814 | map_id, |
| 3815 | enable): |
| 3816 | """ QOS Mark Enable/Disable """ |
| 3817 | return self.api(self.papi.qos_mark_enable_disable, |
| 3818 | {'map_id': map_id, |
| 3819 | 'sw_if_index': sw_if_index, |
| 3820 | 'output_source': output_source, |
| 3821 | 'enable': enable}) |
| 3822 | |
| 3823 | def qos_record_enable_disable(self, sw_if_index, input_source, enable): |
| 3824 | """ IP QoS recording Enble/Disable """ |
| 3825 | return self.api(self.papi.qos_record_enable_disable, |
| 3826 | {'sw_if_index': sw_if_index, |
| 3827 | 'input_source': input_source, |
| 3828 | 'enable': enable}) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3829 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3830 | def igmp_enable_disable(self, sw_if_index, enable, host): |
| 3831 | """ Enable/disable IGMP on a given interface """ |
| 3832 | return self.api(self.papi.igmp_enable_disable, |
| 3833 | {'enable': enable, |
| 3834 | 'mode': host, |
| 3835 | 'sw_if_index': sw_if_index}) |
| 3836 | |
Jakub Grajciar | 97748ca | 2018-10-04 11:05:35 +0200 | [diff] [blame] | 3837 | def igmp_proxy_device_add_del(self, vrf_id, sw_if_index, add): |
| 3838 | """ Add/del IGMP proxy device """ |
| 3839 | return self.api(self.papi.igmp_proxy_device_add_del, |
| 3840 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 3841 | 'add': add}) |
| 3842 | |
| 3843 | def igmp_proxy_device_add_del_interface(self, vrf_id, sw_if_index, add): |
| 3844 | """ Add/del interface to/from IGMP proxy device """ |
| 3845 | return self.api(self.papi.igmp_proxy_device_add_del_interface, |
| 3846 | {'vrf_id': vrf_id, 'sw_if_index': sw_if_index, |
| 3847 | 'add': add}) |
| 3848 | |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3849 | def igmp_listen(self, filter, sw_if_index, saddrs, gaddr): |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3850 | """ Listen for new (S,G) on specified interface |
| 3851 | |
| 3852 | :param enable: add/del |
| 3853 | :param sw_if_index: interface sw index |
| 3854 | :param saddr: source ip4 addr |
| 3855 | :param gaddr: group ip4 addr |
| 3856 | """ |
| 3857 | return self.api(self.papi.igmp_listen, |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3858 | { |
| 3859 | 'group': |
| 3860 | { |
| 3861 | 'filter': filter, |
| 3862 | 'sw_if_index': sw_if_index, |
| 3863 | 'n_srcs': len(saddrs), |
| 3864 | 'saddrs': saddrs, |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 3865 | 'gaddr': gaddr |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3866 | } |
| 3867 | }) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3868 | |
| 3869 | def igmp_dump(self, sw_if_index=None): |
| 3870 | """ Dump all (S,G) interface configurations """ |
| 3871 | if sw_if_index is None: |
Neale Ranns | 947ea62 | 2018-06-07 23:48:20 -0700 | [diff] [blame] | 3872 | sw_if_index = 0xffffffff |
| 3873 | return self.api(self.papi.igmp_dump, |
| 3874 | {'sw_if_index': sw_if_index}) |
Jakub Grajciar | 7b867a8 | 2017-12-08 16:28:42 +0100 | [diff] [blame] | 3875 | |
| 3876 | def igmp_clear_interface(self, sw_if_index): |
| 3877 | """ Remove all (S,G)s from specified interface |
| 3878 | doesn't send IGMP report! |
| 3879 | """ |
| 3880 | return self.api( |
| 3881 | self.papi.igmp_clear_interface, { |
| 3882 | 'sw_if_index': sw_if_index}) |
| 3883 | |
| 3884 | def want_igmp_events(self, enable=1): |
| 3885 | return self.api(self.papi.want_igmp_events, {'enable': enable, |
| 3886 | 'pid': os.getpid()}) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 3887 | |
| 3888 | def bond_create( |
| 3889 | self, |
| 3890 | mode, |
| 3891 | lb, |
| 3892 | use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 3893 | mac_address='', |
| 3894 | interface_id=0xFFFFFFFF): |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 3895 | """ |
| 3896 | :param mode: mode |
| 3897 | :param lb: load balance |
| 3898 | :param use_custom_mac: use custom mac |
| 3899 | :param mac_address: mac address |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 3900 | :param interface_id: custom interface ID |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 3901 | """ |
| 3902 | return self.api( |
| 3903 | self.papi.bond_create, |
| 3904 | {'mode': mode, |
| 3905 | 'lb': lb, |
| 3906 | 'use_custom_mac': use_custom_mac, |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 3907 | 'mac_address': mac_address, |
| 3908 | 'id': interface_id |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 3909 | }) |
| 3910 | |
| 3911 | def bond_delete( |
| 3912 | self, |
| 3913 | sw_if_index): |
| 3914 | """ |
| 3915 | :param sw_if_index: interface the operation is applied to |
| 3916 | """ |
| 3917 | return self.api(self.papi.bond_delete, |
| 3918 | {'sw_if_index': sw_if_index}) |
| 3919 | |
| 3920 | def bond_enslave( |
| 3921 | self, |
| 3922 | sw_if_index, |
| 3923 | bond_sw_if_index, |
| 3924 | is_passive, |
| 3925 | is_long_timeout): |
| 3926 | """ |
| 3927 | :param sw_if_index: slave sw_if_index |
| 3928 | :param bond_sw_if_index: bond sw_if_index |
| 3929 | :param is_passive: is passive lacp speaker |
| 3930 | :param is_long_time: 90 seconds timeout instead of 3 seconds timeout |
| 3931 | """ |
| 3932 | return self.api( |
| 3933 | self.papi.bond_enslave, |
| 3934 | {'sw_if_index': sw_if_index, |
| 3935 | 'bond_sw_if_index': bond_sw_if_index, |
| 3936 | 'is_passive': is_passive, |
| 3937 | 'is_long_timeout': is_long_timeout |
| 3938 | }) |
| 3939 | |
| 3940 | def bond_detach_slave( |
| 3941 | self, |
| 3942 | sw_if_index): |
| 3943 | """ |
| 3944 | :param sw_if_index: slave interface the operation is applied to |
| 3945 | """ |
| 3946 | return self.api(self.papi.bond_detach_slave, |
| 3947 | {'sw_if_index': sw_if_index}) |
| 3948 | |
| 3949 | def sw_interface_slave_dump( |
| 3950 | self, |
| 3951 | sw_if_index): |
| 3952 | """ |
| 3953 | :param sw_if_index: bond sw_if_index |
| 3954 | """ |
| 3955 | return self.api(self.papi.sw_interface_slave_dump, |
| 3956 | {'sw_if_index': sw_if_index}) |
| 3957 | |
| 3958 | def sw_interface_bond_dump( |
| 3959 | self): |
| 3960 | """ |
| 3961 | |
| 3962 | """ |
| 3963 | return self.api(self.papi.sw_interface_bond_dump, |
| 3964 | {}) |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 3965 | |
| 3966 | def create_vhost_user_if( |
| 3967 | self, |
| 3968 | is_server, |
| 3969 | sock_filename, |
| 3970 | renumber, |
Mohsin Kazmi | ee2e58f | 2018-08-21 16:07:03 +0200 | [diff] [blame] | 3971 | disable_mrg_rxbuf, |
| 3972 | disable_indirect_desc, |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 3973 | custom_dev_instance, |
| 3974 | use_custom_mac, |
| 3975 | mac_address, |
| 3976 | tag=''): |
| 3977 | """ |
| 3978 | :param is_server: is server |
| 3979 | :param sock_filename: socket name |
| 3980 | :param renumber: renumber |
Mohsin Kazmi | ee2e58f | 2018-08-21 16:07:03 +0200 | [diff] [blame] | 3981 | :param disable_mrg_rxbuf: disable mergable rx buffers |
| 3982 | :param disable_indirect_desc: disable indirect descriptors |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 3983 | :param custom_dev_instance: custom dev instance |
| 3984 | :param use_custom_mac: use custom mac |
| 3985 | :param mac_address: mac address |
Mohsin Kazmi | ee2e58f | 2018-08-21 16:07:03 +0200 | [diff] [blame] | 3986 | :param tag: tag (default '') |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 3987 | """ |
| 3988 | return self.api( |
| 3989 | self.papi.create_vhost_user_if, |
| 3990 | {'is_server': is_server, |
| 3991 | 'sock_filename': sock_filename, |
| 3992 | 'renumber': renumber, |
Mohsin Kazmi | ee2e58f | 2018-08-21 16:07:03 +0200 | [diff] [blame] | 3993 | 'disable_mrg_rxbuf': disable_mrg_rxbuf, |
| 3994 | 'disable_indirect_desc': disable_indirect_desc, |
Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame] | 3995 | 'custom_dev_instance': custom_dev_instance, |
| 3996 | 'use_custom_mac': use_custom_mac, |
| 3997 | 'mac_address': mac_address, |
| 3998 | 'tag': tag |
| 3999 | }) |
| 4000 | |
| 4001 | def delete_vhost_user_if( |
| 4002 | self, |
| 4003 | sw_if_index): |
| 4004 | """ |
| 4005 | :param sw_if_index: interface the operation is applied to |
| 4006 | """ |
| 4007 | return self.api(self.papi.delete_vhost_user_if, |
| 4008 | {'sw_if_index': sw_if_index, }) |
| 4009 | |
| 4010 | def sw_interface_vhost_user_dump( |
| 4011 | self): |
| 4012 | """ |
| 4013 | |
| 4014 | """ |
| 4015 | return self.api(self.papi.sw_interface_vhost_user_dump, |
| 4016 | {}) |
Andrew Yourtchenko | 669d07d | 2017-11-17 14:38:18 +0100 | [diff] [blame] | 4017 | |
| 4018 | def abf_policy_add_del(self, is_add, policy): |
| 4019 | return self.api( |
| 4020 | self.papi.abf_policy_add_del, |
| 4021 | {'is_add': is_add, |
| 4022 | 'policy': policy}) |
| 4023 | |
| 4024 | def abf_itf_attach_add_del(self, is_add, attach): |
| 4025 | return self.api( |
| 4026 | self.papi.abf_itf_attach_add_del, |
| 4027 | {'is_add': is_add, |
| 4028 | 'attach': attach}) |
| 4029 | |
| 4030 | def abf_policy_dump(self): |
| 4031 | return self.api( |
| 4032 | self.papi.abf_policy_dump, {}) |
| 4033 | |
| 4034 | def abf_itf_attach_dump(self): |
| 4035 | return self.api( |
| 4036 | self.papi.abf_itf_attach_dump, {}) |
Neale Ranns | 17ff3c1 | 2018-07-04 10:24:24 -0700 | [diff] [blame] | 4037 | |
| 4038 | def pipe_create(self, is_specified, user_instance): |
| 4039 | return self.api(self.papi.pipe_create, |
| 4040 | {'is_specified': is_specified, |
| 4041 | 'user_instance': user_instance}) |
| 4042 | |
| 4043 | def pipe_delete(self, parent_sw_if_index): |
| 4044 | return self.api(self.papi.pipe_delete, |
| 4045 | {'parent_sw_if_index': parent_sw_if_index}) |
| 4046 | |
| 4047 | def pipe_dump(self): |
| 4048 | return self.api(self.papi.pipe_dump, {}) |
Jakub Grajciar | b1be2a0 | 2018-09-19 13:36:16 +0200 | [diff] [blame] | 4049 | |
| 4050 | def memif_create( |
| 4051 | self, |
| 4052 | role, |
| 4053 | mode, |
| 4054 | rx_queues=None, |
| 4055 | tx_queues=None, |
| 4056 | _id=None, |
| 4057 | socket_id=None, |
| 4058 | secret=None, |
| 4059 | ring_size=None, |
| 4060 | buffer_size=None, |
| 4061 | hw_addr=None): |
| 4062 | return self.api(self.papi.memif_create, |
| 4063 | {'role': role, |
| 4064 | 'mode': mode, |
| 4065 | 'rx_queues': rx_queues, |
| 4066 | 'tx_queues': tx_queues, |
| 4067 | 'id': _id, |
| 4068 | 'socket_id': socket_id, |
| 4069 | 'secret': secret, |
| 4070 | 'ring_size': ring_size, |
| 4071 | 'buffer_size': buffer_size, |
| 4072 | 'hw_addr': hw_addr}) |
| 4073 | |
| 4074 | def memif_delete(self, sw_if_index): |
| 4075 | return self.api(self.papi.memif_delete, {'sw_if_index': sw_if_index}) |
| 4076 | |
| 4077 | def memif_dump(self): |
| 4078 | return self.api(self.papi.memif_dump, {}) |
| 4079 | |
| 4080 | def memif_socket_filename_add_del( |
| 4081 | self, is_add, socket_id, socket_filename): |
| 4082 | return self.api( |
| 4083 | self.papi.memif_socket_filename_add_del, |
| 4084 | {'is_add': is_add, |
| 4085 | 'socket_id': socket_id, |
| 4086 | 'socket_filename': socket_filename}) |
| 4087 | |
| 4088 | def memif_socket_filename_dump(self): |
| 4089 | return self.api(self.papi.memif_socket_filename_dump, {}) |
Neale Ranns | d1e68ab | 2018-10-01 01:42:13 -0700 | [diff] [blame] | 4090 | |
| 4091 | def svs_table_add_del(self, af, table_id, is_add=1): |
| 4092 | return self.api(self.papi.svs_table_add_del, |
| 4093 | { |
| 4094 | 'table_id': table_id, |
| 4095 | 'is_add': is_add, |
| 4096 | 'af': af, |
| 4097 | }) |
| 4098 | |
| 4099 | def svs_route_add_del(self, table_id, prefix, src_table_id, is_add=1): |
| 4100 | return self.api(self.papi.svs_route_add_del, |
| 4101 | { |
| 4102 | 'table_id': table_id, |
| 4103 | 'source_table_id': src_table_id, |
| 4104 | 'prefix': prefix, |
| 4105 | 'is_add': is_add, |
| 4106 | }) |
| 4107 | |
| 4108 | def svs_enable_disable(self, af, table_id, sw_if_index, is_enable=1): |
| 4109 | return self.api(self.papi.svs_enable_disable, |
| 4110 | { |
| 4111 | 'af': af, |
| 4112 | 'table_id': table_id, |
| 4113 | 'sw_if_index': sw_if_index, |
| 4114 | 'is_enable': is_enable, |
| 4115 | }) |
| 4116 | |
| 4117 | def svs_dump(self): |
| 4118 | return self.api(self.papi.svs_dump, {}) |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 4119 | |
| 4120 | def syslog_set_sender( |
| 4121 | self, |
| 4122 | collector, |
| 4123 | src, |
| 4124 | collector_port=514, |
| 4125 | vrf_id=0, |
| 4126 | max_msg_size=480): |
| 4127 | """Set syslog sender configuration |
| 4128 | |
| 4129 | :param collector: colector IP address |
| 4130 | :param src: source IP address |
| 4131 | :param collector_port: collector UDP port (Default value = 514) |
| 4132 | :param vrf_id: VRF id (Default value = 0) |
| 4133 | :param max_msg_size: maximum message length (Default value = 480) |
| 4134 | """ |
| 4135 | return self.api(self.papi.syslog_set_sender, |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 4136 | {'collector_address': collector, |
| 4137 | 'src_address': src, |
Matus Fabian | b4515b4 | 2018-11-19 04:25:32 -0800 | [diff] [blame] | 4138 | 'collector_port': collector_port, |
| 4139 | 'vrf_id': vrf_id, |
| 4140 | 'max_msg_size': max_msg_size}) |
| 4141 | |
| 4142 | def syslog_get_sender(self): |
| 4143 | """Return syslog sender configuration""" |
| 4144 | return self.api(self.papi.syslog_get_sender, {}) |
| 4145 | |
| 4146 | def syslog_set_filter(self, severity): |
| 4147 | """Set syslog filter parameters |
| 4148 | |
| 4149 | :param severity: severity filter (specified severity and greater match) |
| 4150 | """ |
| 4151 | return self.api(self.papi.syslog_set_filter, {'severity': severity}) |
| 4152 | |
| 4153 | def syslog_get_filter(self): |
| 4154 | """Return syslog filter parameters""" |
| 4155 | return self.api(self.papi.syslog_get_filter, {}) |