-# Copyright (c) 2021 Cisco and/or its affiliates.
-# Copyright (c) 2021 PANTHEON.tech s.r.o.
+# Copyright (c) 2023 Cisco and/or its affiliates.
+# Copyright (c) 2023 PANTHEON.tech s.r.o.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
from resources.libraries.python.PapiExecutor import PapiSocketExecutor
from resources.libraries.python.ssh import exec_cmd_no_error, exec_cmd
from resources.libraries.python.topology import Topology
-from resources.libraries.python.VatExecutor import VatExecutor
from resources.libraries.python.Namespaces import Namespaces
return f"{self._value.network_address}/{self._prefix_len}"
elif self._format == u"addr":
return f"{self._value.network_address}"
- else:
- raise RuntimeError(f"Unsupported format {self._format}")
+
+ raise RuntimeError(f"Unsupported format {self._format}")
class IPUtil:
:type ip_addr: str
:type prefix_length: int
:type namespace: str
- :rtype boolean
+ :rtype: boolean
:raises RuntimeError: Request fails.
"""
ip_addr_with_prefix = f"{ip_addr}/{prefix_length}"
vrf: VRF table ID. (int)
count: number of IP addresses to add starting from network IP (int)
local: The route is local with same prefix (increment is 1).
- If None, then is not used. (bool)
+ If None, then is not used. (bool)
lookup_vrf: VRF table ID for lookup. (int)
weight: Weight value for unequal cost multipath routing. (int)
(Multipath value enters at higher level.)
vrf: VRF table ID. (int)
count: number of IP addresses to add starting from network IP (int)
local: The route is local with same prefix (increment is 1 network)
- If None, then is not used. (bool)
+ If None, then is not used. (bool)
lookup_vrf: VRF table ID for lookup. (int)
multipath: Enable multipath routing. (bool) Default: True.
weight: Weight value for unequal cost multipath routing. (int)
"""
count = kwargs.get(u"count", 1)
- if count > 100:
- if not kwargs.get(u"multipath", True):
- raise RuntimeError(u"VAT exec supports only multipath behavior")
- gateway = kwargs.get(u"gateway", u"")
- interface = kwargs.get(u"interface", u"")
- local = kwargs.get(u"local", u"")
- if interface:
- interface = InterfaceUtil.vpp_get_interface_name(
- node, InterfaceUtil.get_interface_index(
- node, interface
- )
- )
- vrf = kwargs.get(u"vrf", None)
- trailers = list()
- if vrf:
- trailers.append(f"table {vrf}")
- if gateway:
- trailers.append(f"via {gateway}")
- if interface:
- trailers.append(interface)
- elif interface:
- trailers.append(f"via {interface}")
- if local:
- if gateway or interface:
- raise RuntimeError(u"Unsupported combination with local.")
- trailers.append(u"local")
- trailer = u" ".join(trailers)
- command_parts = [u"exec ip route add", u"network goes here"]
- if trailer:
- command_parts.append(trailer)
- netiter = NetworkIncrement(
- ip_network(f"{network}/{prefix_len}", strict=strict),
- format=u"slash"
- )
- tmp_filename = u"/tmp/routes.config"
- with open(tmp_filename, u"w") as tmp_file:
- for _ in range(count):
- command_parts[1] = netiter.inc_fmt()
- print(u" ".join(command_parts), file=tmp_file)
- VatExecutor().execute_script(
- tmp_filename, node, timeout=1800, json_out=False,
- copy_on_execute=True, history=False
- )
- os.remove(tmp_filename)
- return
-
cmd = u"ip_route_add_del"
args = dict(
is_add=True,
ip_network(f"{network}/{prefix_len}", strict=strict),
format=u"addr"
)
- with PapiSocketExecutor(node) as papi_exec:
+ with PapiSocketExecutor(node, is_async=True) as papi_exec:
for i in range(count):
args[u"route"] = IPUtil.compose_vpp_route_structure(
node, netiter.inc_fmt(), prefix_len, **kwargs