aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_ip4.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_ip4.py')
-rw-r--r--test/test_ip4.py78
1 files changed, 60 insertions, 18 deletions
diff --git a/test/test_ip4.py b/test/test_ip4.py
index 48155a5a025..36a907a66df 100644
--- a/test/test_ip4.py
+++ b/test/test_ip4.py
@@ -2,24 +2,38 @@
import unittest
import socket
-from logging import *
from framework import VppTestCase, VppTestRunner
+from vpp_interface import VppInterface
from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint
from scapy.packet import Raw
-from scapy.layers.l2 import Ether, Dot1Q, ARP
+from scapy.layers.l2 import Ether, Dot1Q
from scapy.layers.inet import IP, UDP
class TestIPv4(VppTestCase):
""" IPv4 Test Case """
- @classmethod
- def setUpClass(cls):
- super(TestIPv4, cls).setUpClass()
-
def setUp(self):
+ """
+ Perform test setup before test case.
+
+ **Config:**
+ - create 3 pg interfaces
+ - untagged pg0 interface
+ - Dot1Q subinterface on pg1
+ - Dot1AD subinterface on pg2
+ - setup interfaces:
+ - put it into UP state
+ - set IPv4 addresses
+ - resolve neighbor address using ARP
+ - configure 200 fib entries
+
+ :ivar list interfaces: pg interfaces and subinterfaces.
+ :ivar dict flows: IPv4 packet flows in test.
+ :ivar list pg_if_packet_sizes: packet sizes in test.
+ """
super(TestIPv4, self).setUp()
# create 3 pg interfaces
@@ -49,16 +63,26 @@ class TestIPv4(VppTestCase):
i.config_ip4()
i.resolve_arp()
- # config 2M FIB enries
+ # config 2M FIB entries
self.config_fib_entries(200)
def tearDown(self):
+ """Run standard test teardown and log ``show ip arp``."""
super(TestIPv4, self).tearDown()
if not self.vpp_dead:
- info(self.vapi.cli("show ip arp"))
+ self.logger.info(self.vapi.cli("show ip arp"))
# info(self.vapi.cli("show ip fib")) # many entries
def config_fib_entries(self, count):
+ """For each interface add to the FIB table *count* routes to
+ "10.0.0.1/32" destination with interface's local address as next-hop
+ address.
+
+ :param int count: Number of FIB entries.
+
+ - *TODO:* check if the next-hop address shouldn't be remote address
+ instead of local address.
+ """
n_int = len(self.interfaces)
percent = 0
counter = 0.0
@@ -69,13 +93,18 @@ class TestIPv4(VppTestCase):
for j in range(count / n_int):
self.vapi.ip_add_del_route(
dest_addr, dest_addr_len, next_hop_address)
- counter = counter + 1
+ counter += 1
if counter / count * 100 > percent:
- info("Configure %d FIB entries .. %d%% done" %
- (count, percent))
- percent = percent + 1
+ self.logger.info("Configure %d FIB entries .. %d%% done" %
+ (count, percent))
+ percent += 1
def create_stream(self, src_if, packet_sizes):
+ """Create input packet stream for defined interface.
+
+ :param VppInterface src_if: Interface to create packet stream for.
+ :param list packet_sizes: Required packet sizes.
+ """
pkts = []
for i in range(0, 257):
dst_if = self.flows[src_if][i % 2]
@@ -95,7 +124,13 @@ class TestIPv4(VppTestCase):
return pkts
def verify_capture(self, dst_if, capture):
- info("Verifying capture on interface %s" % dst_if.name)
+ """Verify captured input packet stream for defined interface.
+
+ :param VppInterface dst_if: Interface to verify captured packet stream
+ for.
+ :param list capture: Captured packet stream.
+ """
+ self.logger.info("Verifying capture on interface %s" % dst_if.name)
last_info = dict()
for i in self.interfaces:
last_info[i.sw_if_index] = None
@@ -114,8 +149,8 @@ class TestIPv4(VppTestCase):
payload_info = self.payload_to_info(str(packet[Raw]))
packet_index = payload_info.index
self.assertEqual(payload_info.dst, dst_sw_if_index)
- debug("Got packet on port %s: src=%u (id=%u)" %
- (dst_if.name, payload_info.src, packet_index))
+ self.logger.debug("Got packet on port %s: src=%u (id=%u)" %
+ (dst_if.name, payload_info.src, packet_index))
next_info = self.get_next_packet_info_for_interface2(
payload_info.src, dst_sw_if_index,
last_info[payload_info.src])
@@ -129,8 +164,8 @@ class TestIPv4(VppTestCase):
self.assertEqual(udp.sport, saved_packet[UDP].sport)
self.assertEqual(udp.dport, saved_packet[UDP].dport)
except:
- error("Unexpected or invalid packet:")
- error(packet.show())
+ self.logger.error("Unexpected or invalid packet:")
+ self.logger.error(packet.show())
raise
for i in self.interfaces:
remaining_packet = self.get_next_packet_info_for_interface2(
@@ -141,7 +176,14 @@ class TestIPv4(VppTestCase):
(dst_if.name, i.name))
def test_fib(self):
- """ IPv4 FIB test """
+ """ IPv4 FIB test
+
+ Test scenario:
+
+ - Create IPv4 stream for pg0 interface
+ - Create IPv4 tagged streams for pg1's and pg2's subinterface.
+ - Send and verify received packets on each interface.
+ """
pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes)
self.pg0.add_stream(pkts)