2 """ Container integration tests """
5 from framework import VppTestCase, VppTestRunner, running_extended_tests
6 from scapy.layers.l2 import Ether
7 from scapy.packet import Raw
8 from scapy.layers.inet import IP, UDP, TCP
9 from scapy.packet import Packet
10 from socket import inet_pton, AF_INET, AF_INET6
11 from scapy.layers.inet6 import IPv6, ICMPv6Unknown, ICMPv6EchoRequest
12 from scapy.layers.inet6 import ICMPv6EchoReply, IPv6ExtHdrRouting
13 from scapy.layers.inet6 import IPv6ExtHdrFragment
14 from pprint import pprint
15 from random import randint
16 from util import L4_Conn
20 # for now same as L4_Conn
24 @unittest.skipUnless(running_extended_tests, "part of extended tests")
25 class ContainerIntegrationTestCase(VppTestCase):
26 """ Container integration extended testcases """
30 super(ContainerIntegrationTestCase, cls).setUpClass()
32 cls.create_pg_interfaces(range(2))
33 for i in cls.pg_interfaces:
41 def tearDownClass(cls):
42 super(ContainerIntegrationTestCase, cls).tearDownClass()
45 """Run standard test teardown and log various show commands
47 super(ContainerIntegrationTestCase, self).tearDown()
49 def show_commands_at_teardown(self):
50 self.logger.info(self.vapi.cli("show ip arp"))
51 self.logger.info(self.vapi.cli("show ip6 neighbors"))
53 def run_basic_conn_test(self, af, acl_side):
54 """ Basic connectivity test """
55 conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242)
57 # the return packets should pass
60 def run_negative_conn_test(self, af, acl_side):
61 """ Packets with local spoofed address """
62 conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242)
64 p2 = conn1.send_through(0).command()
66 # If we asserted while waiting, it's good.
67 # the conn should have timed out.
69 self.assert_equal(p2, None, ": packet should have been dropped")
71 def test_0010_basic_conn_test(self):
72 """ IPv4 basic connectivity test """
73 self.run_basic_conn_test(AF_INET, 0)
75 def test_0011_basic_conn_test(self):
76 """ IPv6 basic connectivity test """
77 self.run_basic_conn_test(AF_INET6, 0)
79 def test_0050_loopback_prepare_test(self):
80 """ Create loopbacks overlapping with remote addresses """
81 self.create_loopback_interfaces(2)
83 intf = self.lo_interfaces[i]
85 intf.local_ip4 = self.pg_interfaces[i].remote_ip4
86 intf.local_ip4_prefix_len = 32
88 intf.local_ip6 = self.pg_interfaces[i].remote_ip6
89 intf.local_ip6_prefix_len = 128
92 def test_0110_basic_conn_test(self):
93 """ IPv4 local-spoof connectivity test """
94 self.run_negative_conn_test(AF_INET, 0)
96 def test_0111_basic_conn_test(self):
97 """ IPv6 local-spoof connectivity test """
98 self.run_negative_conn_test(AF_INET, 1)
100 def test_0200_basic_conn_test(self):
101 """ Configure container commands """
103 for addr in [self.pg_interfaces[i].remote_ip4,
104 self.pg_interfaces[i].remote_ip6]:
105 self.vapi.ppcli("ip container " + addr + " " +
106 self.pg_interfaces[i].name)
107 self.vapi.ppcli("stn rule address " + addr +
108 " interface " + self.pg_interfaces[i].name)
110 def test_0210_basic_conn_test(self):
111 """ IPv4 test after configuring container """
112 self.run_basic_conn_test(AF_INET, 0)
114 def test_0211_basic_conn_test(self):
115 """ IPv6 test after configuring container """
116 self.run_basic_conn_test(AF_INET, 1)
118 def test_0300_unconfigure_commands(self):
119 """ Unconfigure container commands """
121 for addr in [self.pg_interfaces[i].remote_ip4,
122 self.pg_interfaces[i].remote_ip6]:
123 self.vapi.ppcli("ip container " + addr + " " +
124 self.pg_interfaces[i].name +
126 self.vapi.ppcli("stn rule address " + addr +
127 " interface " + self.pg_interfaces[i].name +
130 def test_0410_spoof_test(self):
131 """ IPv4 local-spoof after unconfig test """
132 self.run_negative_conn_test(AF_INET, 0)
134 def test_0411_spoof_test(self):
135 """ IPv6 local-spoof after unconfig test """
136 self.run_negative_conn_test(AF_INET, 1)