2 """ Container integration tests """
5 from config import config
6 from framework import VppTestCase, VppTestRunner
7 from scapy.layers.l2 import Ether
8 from scapy.packet import Raw
9 from scapy.layers.inet import IP, UDP, TCP
10 from scapy.packet import Packet
11 from socket import inet_pton, AF_INET, AF_INET6
12 from scapy.layers.inet6 import IPv6, ICMPv6Unknown, ICMPv6EchoRequest
13 from scapy.layers.inet6 import ICMPv6EchoReply, IPv6ExtHdrRouting
14 from scapy.layers.inet6 import IPv6ExtHdrFragment
15 from pprint import pprint
16 from random import randint
17 from util import L4_Conn
21 # for now same as L4_Conn
25 @unittest.skipUnless(config.extended, "part of extended tests")
26 class ContainerIntegrationTestCase(VppTestCase):
27 """Container integration extended testcases"""
31 super(ContainerIntegrationTestCase, cls).setUpClass()
33 cls.create_pg_interfaces(range(2))
34 for i in cls.pg_interfaces:
42 def tearDownClass(cls):
43 super(ContainerIntegrationTestCase, cls).tearDownClass()
46 """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 neighbors"))
52 def run_basic_conn_test(self, af, acl_side):
53 """Basic connectivity test"""
54 conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242)
56 # the return packets should pass
59 def run_negative_conn_test(self, af, acl_side):
60 """Packets with local spoofed address"""
61 conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242)
63 p2 = conn1.send_through(0).command()
65 # If we asserted while waiting, it's good.
66 # the conn should have timed out.
68 self.assert_equal(p2, None, ": packet should have been dropped")
70 def test_0010_basic_conn_test(self):
71 """IPv4 basic connectivity test"""
72 self.run_basic_conn_test(AF_INET, 0)
74 def test_0011_basic_conn_test(self):
75 """IPv6 basic connectivity test"""
76 self.run_basic_conn_test(AF_INET6, 0)
78 def test_0050_loopback_prepare_test(self):
79 """Create loopbacks overlapping with remote addresses"""
80 self.create_loopback_interfaces(2)
82 intf = self.lo_interfaces[i]
84 intf.local_ip4 = self.pg_interfaces[i].remote_ip4
85 intf.local_ip4_prefix_len = 32
87 intf.local_ip6 = self.pg_interfaces[i].remote_ip6
88 intf.local_ip6_prefix_len = 128
91 def test_0110_basic_conn_test(self):
92 """IPv4 local-spoof connectivity test"""
93 self.run_negative_conn_test(AF_INET, 0)
95 def test_0111_basic_conn_test(self):
96 """IPv6 local-spoof connectivity test"""
97 self.run_negative_conn_test(AF_INET, 1)
99 def test_0200_basic_conn_test(self):
100 """Configure container commands"""
103 self.pg_interfaces[i].remote_ip4,
104 self.pg_interfaces[i].remote_ip6,
107 "ip container " + addr + " " + self.pg_interfaces[i].name
113 + self.pg_interfaces[i].name
116 def test_0210_basic_conn_test(self):
117 """IPv4 test after configuring container"""
118 self.run_basic_conn_test(AF_INET, 0)
120 def test_0211_basic_conn_test(self):
121 """IPv6 test after configuring container"""
122 self.run_basic_conn_test(AF_INET, 1)
124 def test_0300_unconfigure_commands(self):
125 """Unconfigure container commands"""
128 self.pg_interfaces[i].remote_ip4,
129 self.pg_interfaces[i].remote_ip6,
132 "ip container " + addr + " " + self.pg_interfaces[i].name + " del"
138 + self.pg_interfaces[i].name
142 def test_0410_spoof_test(self):
143 """IPv4 local-spoof after unconfig test"""
144 self.run_negative_conn_test(AF_INET, 0)
146 def test_0411_spoof_test(self):
147 """IPv6 local-spoof after unconfig test"""
148 self.run_negative_conn_test(AF_INET, 1)