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