from resources.libraries.python.Constants import Constants
from resources.libraries.python.InterfaceUtil import InterfaceUtil
+from resources.libraries.python.IPAddress import IPAddress
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
MPLS_LABEL_INVALID = MPLS_IETF_MAX_LABEL + 1
-class AddressFamily(IntEnum):
- """IP address family."""
- ADDRESS_IP4 = 0
- ADDRESS_IP6 = 1
-
-
class FibPathType(IntEnum):
"""FIB path types."""
FIB_PATH_TYPE_NORMAL = 0
FIB_PATH_NH_PROTO_BIER = 4
+class IpDscp(IntEnum):
+ """DSCP code points."""
+ IP_API_DSCP_CS0 = 0,
+ IP_API_DSCP_CS1 = 8,
+ IP_API_DSCP_AF11 = 10,
+ IP_API_DSCP_AF12 = 12,
+ IP_API_DSCP_AF13 = 14,
+ IP_API_DSCP_CS2 = 16,
+ IP_API_DSCP_AF21 = 18,
+ IP_API_DSCP_AF22 = 20,
+ IP_API_DSCP_AF23 = 22,
+ IP_API_DSCP_CS3 = 24,
+ IP_API_DSCP_AF31 = 26,
+ IP_API_DSCP_AF32 = 28,
+ IP_API_DSCP_AF33 = 30,
+ IP_API_DSCP_CS4 = 32,
+ IP_API_DSCP_AF41 = 34,
+ IP_API_DSCP_AF42 = 36,
+ IP_API_DSCP_AF43 = 38,
+ IP_API_DSCP_CS5 = 40,
+ IP_API_DSCP_EF = 46,
+ IP_API_DSCP_CS6 = 48,
+ IP_API_DSCP_CS7 = 50
+
+
class IPUtil:
"""Common IP utilities"""
PapiSocketExecutor.run_cli_cmd(node, u"show ip6 fib")
PapiSocketExecutor.run_cli_cmd(node, u"show ip6 fib summary")
+ @staticmethod
+ def vpp_get_ip_table_summary(node):
+ """Get IPv4 FIB table summary on a VPP node.
+
+ :param node: VPP node.
+ :type node: dict
+ """
+ PapiSocketExecutor.run_cli_cmd(node, u"show ip fib summary")
+
+ @staticmethod
+ def vpp_get_ip_table(node):
+ """Get IPv4 FIB table on a VPP node.
+
+ :param node: VPP node.
+ :type node: dict
+ """
+ PapiSocketExecutor.run_cli_cmd(node, u"show ip fib")
+
@staticmethod
def vpp_get_ip_tables_prefix(node, address):
"""Get dump of all IP FIB tables on a VPP node.
return None
@staticmethod
- def set_linux_interface_up(node, interface):
+ def set_linux_interface_up(
+ node, interface, namespace=None):
"""Set the specified interface up.
-
:param node: VPP/TG node.
:param interface: Interface in namespace.
+ :param namespace: Execute command in namespace. Optional
:type node: dict
:type interface: str
+ :type namespace: str
:raises RuntimeError: If the interface could not be set up.
"""
- cmd = f"ip link set {interface} up"
+ if namespace is not None:
+ cmd = f"ip netns exec {namespace} ip link set dev {interface} up"
+ else:
+ cmd = f"ip link set dev {interface} up"
exec_cmd_no_error(node, cmd, timeout=30, sudo=True)
+
@staticmethod
def set_linux_interface_ip(
node, interface, ip_addr, prefix, namespace=None):
with PapiSocketExecutor(node) as papi_exec:
papi_exec.add(cmd, **args).get_reply(err_msg)
- @staticmethod
- def union_addr(ip_addr):
- """Creates union IP address.
-
- :param ip_addr: IPv4 or IPv6 address.
- :type ip_addr: IPv4Address or IPv6Address
- :returns: Union IP address.
- :rtype: dict
- """
- return dict(ip6=ip_addr.packed) if ip_addr.version == 6 \
- else dict(ip4=ip_addr.packed)
-
- @staticmethod
- def create_ip_address_object(ip_addr):
- """Create IP address object.
-
- :param ip_addr: IPv4 or IPv6 address
- :type ip_addr: IPv4Address or IPv6Address
- :returns: IP address object.
- :rtype: dict
- """
- return dict(
- af=getattr(
- AddressFamily, u"ADDRESS_IP6" if ip_addr.version == 6
- else u"ADDRESS_IP4"
- ).value,
- un=IPUtil.union_addr(ip_addr)
- )
-
@staticmethod
def create_prefix_object(ip_addr, addr_len):
"""Create prefix object.
:param ip_addr: IPv4 or IPv6 address.
- :para, addr_len: Length of IP address.
+ :param addr_len: Length of IP address.
:type ip_addr: IPv4Address or IPv6Address
:type addr_len: int
:returns: Prefix object.
:rtype: dict
"""
- addr = IPUtil.create_ip_address_object(ip_addr)
+ addr = IPAddress.create_ip_address_object(ip_addr)
return dict(
len=int(addr_len),
paths = list()
n_hop = dict(
- address=IPUtil.union_addr(ip_address(gateway)) if gateway else 0,
+ address=IPAddress.union_addr(ip_address(gateway)) if gateway else 0,
via_label=MPLS_LABEL_INVALID,
obj_id=Constants.BITWISE_NON_ZERO
)