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