+ paths=paths
+ )
+ return route
+
+ @staticmethod
+ def vpp_route_add(node, network, prefix_len, strict=True, **kwargs):
+ """Add route to the VPP node. Prefer multipath behavior.
+
+ :param node: VPP node.
+ :param network: Route destination network address.
+ :param prefix_len: Route destination network prefix length.
+ :param strict: If true, fail if address has host bits set.
+ :param kwargs: Optional key-value arguments:
+
+ gateway: Route gateway address. (str)
+ interface: Route interface. (str)
+ 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)
+ lookup_vrf: VRF table ID for lookup. (int)
+ multipath: Enable multipath routing. (bool) Default: True.
+ weight: Weight value for unequal cost multipath routing. (int)
+
+ :type node: dict
+ :type network: str
+ :type prefix_len: int
+ :type strict: bool
+ :type kwargs: dict
+ :raises RuntimeError: If the argument combination is not supported.
+ """
+ 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"