aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
Diffstat (limited to 'resources')
-rw-r--r--resources/libraries/python/InterfaceUtil.py9
-rw-r--r--resources/libraries/python/Routing.py9
-rw-r--r--resources/templates/vat/add_route.vat2
-rw-r--r--resources/templates/vat/set_fib_to_interface.vat2
-rwxr-xr-xresources/traffic_scripts/send_icmp_wait_for_reply.py94
5 files changed, 96 insertions, 20 deletions
diff --git a/resources/libraries/python/InterfaceUtil.py b/resources/libraries/python/InterfaceUtil.py
index 9ecdb7503a..f5f1ce314e 100644
--- a/resources/libraries/python/InterfaceUtil.py
+++ b/resources/libraries/python/InterfaceUtil.py
@@ -847,25 +847,30 @@ class InterfaceUtil(object):
interface_name=interface)
@staticmethod
- def assign_interface_to_fib_table(node, interface, table_id):
+ def assign_interface_to_fib_table(node, interface, table_id, ipv6=False):
"""Assign VPP interface to specific VRF/FIB table.
:param node: VPP node where the FIB and interface are located.
:param interface: Interface to be assigned to FIB.
:param table_id: VRF table ID.
+ :param ipv6: Assign to IPv6 table. Default False.
:type node: dict
:type interface: str or int
:type table_id: int
+ :type ipv6: bool
"""
if isinstance(interface, basestring):
sw_if_index = Topology.get_interface_sw_index(node, interface)
else:
sw_if_index = interface
+ ipv6 = 'ipv6' if ipv6 else ''
+
with VatTerminal(node) as vat:
vat.vat_terminal_exec_cmd_from_template("set_fib_to_interface.vat",
sw_index=sw_if_index,
- vrf=table_id)
+ vrf=table_id,
+ ipv6=ipv6)
@staticmethod
def set_linux_interface_mac(node, interface, mac, namespace=None):
diff --git a/resources/libraries/python/Routing.py b/resources/libraries/python/Routing.py
index 767fb3aff0..fbe7b60183 100644
--- a/resources/libraries/python/Routing.py
+++ b/resources/libraries/python/Routing.py
@@ -24,7 +24,7 @@ class Routing(object):
@staticmethod
def vpp_route_add(node, network, prefix_len, gateway=None,
interface=None, use_sw_index=True, resolve_attempts=10,
- count=1, vrf=None):
+ count=1, vrf=None, lookup_vrf=None):
"""Add route to the VPP node.
:param node: Node to add route on.
@@ -37,6 +37,7 @@ class Routing(object):
:param resolve_attempts: Resolve attempts IP route add parameter.
:param count: number of IP addresses to add starting from network IP
with same prefix (increment is 1). If None, then is not used.
+ :param lookup_vrf: VRF table ID for lookup.
:type node: dict
:type network: str
:type prefix_len: int
@@ -46,6 +47,7 @@ class Routing(object):
:type resolve_attempts: int
:type count: int
:type vrf: int
+ :type lookup_vrf: int
"""
if use_sw_index:
int_cmd = ('sw_if_index {}'.
@@ -63,6 +65,8 @@ class Routing(object):
vrf = 'vrf {}'.format(vrf) if vrf else ''
+ lookup_vrf = 'lookup-in-vrf {}'.format(lookup_vrf) if lookup_vrf else ''
+
with VatTerminal(node, json_param=False) as vat:
vat.vat_terminal_exec_cmd_from_template('add_route.vat',
network=network,
@@ -71,7 +75,8 @@ class Routing(object):
vrf=vrf,
interface=int_cmd,
resolve_attempts=rap,
- count=cnt)
+ count=cnt,
+ lookup_vrf=lookup_vrf)
@staticmethod
def add_fib_table(node, network, prefix_len, fib_id, place):
diff --git a/resources/templates/vat/add_route.vat b/resources/templates/vat/add_route.vat
index 6c7dfb09f0..9fe89526e6 100644
--- a/resources/templates/vat/add_route.vat
+++ b/resources/templates/vat/add_route.vat
@@ -1 +1 @@
-ip_add_del_route {network}/{prefix_length} {via} {vrf} {interface} {resolve_attempts} {count}
+ip_add_del_route {network}/{prefix_length} {via} {vrf} {interface} {resolve_attempts} {count} {lookup_vrf}
diff --git a/resources/templates/vat/set_fib_to_interface.vat b/resources/templates/vat/set_fib_to_interface.vat
index f0850c900b..09a97faf17 100644
--- a/resources/templates/vat/set_fib_to_interface.vat
+++ b/resources/templates/vat/set_fib_to_interface.vat
@@ -1 +1 @@
-sw_interface_set_table sw_if_index {sw_index} vrf {vrf} \ No newline at end of file
+sw_interface_set_table sw_if_index {sw_index} vrf {vrf} {ipv6} \ No newline at end of file
diff --git a/resources/traffic_scripts/send_icmp_wait_for_reply.py b/resources/traffic_scripts/send_icmp_wait_for_reply.py
index 3c8b71abc8..a77f15efc2 100755
--- a/resources/traffic_scripts/send_icmp_wait_for_reply.py
+++ b/resources/traffic_scripts/send_icmp_wait_for_reply.py
@@ -12,22 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Traffic script that sends an IP ICMPv4."""
+"""Traffic script that sends an IP ICMPv4 or ICMPv6."""
import sys
+import ipaddress
from scapy.layers.inet import ICMP, IP
+from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest
from scapy.all import Ether
from resources.libraries.python.PacketVerifier import RxQueue, TxQueue
from resources.libraries.python.TrafficScriptArg import TrafficScriptArg
-def is_icmp_reply(pkt):
+def is_icmp_reply(pkt, ipformat):
"""Return True if pkt is echo reply, else return False. If exception occurs
- return False."""
+ return False.
+
+ :param pkt: Packet.
+ :param ipformat: Dictionary of names to distinguish IPv4 and IPv6.
+ :type pkt: dict
+ :type ipformat: dict
+ :rtype: bool
+ """
+ #pylint: disable=bare-except
try:
- if pkt['IP']['ICMP'].type == 0: # 0 - echo-reply
+ if pkt[ipformat['IPType']][ipformat['ICMP_rep']].type == \
+ ipformat['Type']:
return True
else:
return False
@@ -35,16 +46,59 @@ def is_icmp_reply(pkt):
return False
-def address_check(request, reply):
+def address_check(request, reply, ipformat):
"""Compare request packet source address with reply destination address
- and vice versa. If exception occurs return False."""
+ and vice versa. If exception occurs return False.
+
+ :param request: Sent packet containing request.
+ :param reply: Received packet containing reply.
+ :param ipformat: Dictionary of names to distinguish IPv4 and IPv6.
+ :type request: dict
+ :type reply: dict
+ :type ipformat: dict
+ :rtype: bool
+ """
+ #pylint: disable=bare-except
try:
- return reply['IP'].src == request['IP'].dst \
- and reply['IP'].dst == request['IP'].src
+ r_src = reply[ipformat['IPType']].src == request[ipformat['IPType']].dst
+ r_dst = reply[ipformat['IPType']].dst == request[ipformat['IPType']].src
+ return r_src and r_dst
except:
return False
+def valid_ipv4(ip):
+ """Check if IP address has the correct IPv4 address format.
+
+ :param ip: IP address.
+ :type ip: str
+ :return: True in case of correct IPv4 address format,
+ otherwise return False.
+ :rtype: bool
+ """
+ try:
+ ipaddress.IPv4Address(unicode(ip))
+ return True
+ except (AttributeError, ipaddress.AddressValueError):
+ return False
+
+
+def valid_ipv6(ip):
+ """Check if IP address has the correct IPv6 address format.
+
+ :param ip: IP address.
+ :type ip: str
+ :return: True in case of correct IPv6 address format,
+ otherwise return False.
+ :rtype: bool
+ """
+ try:
+ ipaddress.IPv6Address(unicode(ip))
+ return True
+ except (AttributeError, ipaddress.AddressValueError):
+ return False
+
+
def main():
"""Send ICMP echo request and wait for ICMP echo reply. It ignores all other
packets."""
@@ -65,21 +119,33 @@ def main():
sent_packets = []
# Create empty ip ICMP packet
- icmp_request = (Ether(src=src_mac, dst=dst_mac) /
- IP(src=src_ip, dst=dst_ip) /
- ICMP())
+ if valid_ipv4(src_ip) and valid_ipv4(dst_ip):
+ icmp_request = (Ether(src=src_mac, dst=dst_mac) /
+ IP(src=src_ip, dst=dst_ip) /
+ ICMP())
+ ip_format = {'IPType': 'IP', 'ICMP_req': 'ICMP',
+ 'ICMP_rep': 'ICMP', 'Type': 0}
+ elif valid_ipv6(src_ip) and valid_ipv6(dst_ip):
+ icmp_request = (Ether(src=src_mac, dst=dst_mac) /
+ IPv6(src=src_ip, dst=dst_ip) /
+ ICMPv6EchoRequest())
+ ip_format = {'IPType': 'IPv6', 'ICMP_req': 'ICMPv6 Echo Request',
+ 'ICMP_rep': 'ICMPv6 Echo Reply', 'Type': 129}
+ else:
+ raise ValueError("IP not in correct format")
+
# Send created packet on the interface
sent_packets.append(icmp_request)
txq.send(icmp_request)
for _ in range(1000):
- icmp_reply = rxq.recv(wait_step)
+ icmp_reply = rxq.recv(wait_step, ignore=sent_packets)
if icmp_reply is None:
timeout -= wait_step
if timeout < 0:
raise RuntimeError("ICMP echo Rx timeout")
- elif is_icmp_reply(icmp_reply):
- if address_check(icmp_request, icmp_reply):
+ elif is_icmp_reply(icmp_reply, ip_format):
+ if address_check(icmp_request, icmp_reply, ip_format):
break
else:
raise RuntimeError("Max packet count limit reached")