blob: 2f7496a51260edc1f79200df44481938ca21b0c4 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -07002""" Container integration tests """
3
4import unittest
Klement Sekerab23ffd72021-05-31 16:08:53 +02005from config import config
Dave Wallace8800f732023-08-31 00:47:44 -04006from framework import VppTestCase
7from asfframework import VppTestRunner
8from scapy.layers.inet import UDP
9from socket import AF_INET, AF_INET6
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070010from util import L4_Conn
11
12
13class Conn(L4_Conn):
14 # for now same as L4_Conn
15 pass
16
17
Klement Sekerab23ffd72021-05-31 16:08:53 +020018@unittest.skipUnless(config.extended, "part of extended tests")
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070019class ContainerIntegrationTestCase(VppTestCase):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020020 """Container integration extended testcases"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070021
22 @classmethod
Paul Vinciguerra56d68cb2018-11-27 05:53:35 -080023 def setUpClass(cls):
24 super(ContainerIntegrationTestCase, cls).setUpClass()
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070025 # create pg0 and pg1
Paul Vinciguerra56d68cb2018-11-27 05:53:35 -080026 cls.create_pg_interfaces(range(2))
27 for i in cls.pg_interfaces:
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070028 i.admin_up()
29 i.config_ip4()
30 i.config_ip6()
31 i.resolve_arp()
32 i.resolve_ndp()
33
Paul Vinciguerra8d991d92019-01-25 14:05:48 -080034 @classmethod
35 def tearDownClass(cls):
36 super(ContainerIntegrationTestCase, cls).tearDownClass()
37
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070038 def tearDown(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020039 """Run standard test teardown and log various show commands"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070040 super(ContainerIntegrationTestCase, self).tearDown()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -070041
42 def show_commands_at_teardown(self):
Neale Rannscbe25aa2019-09-30 10:53:31 +000043 self.logger.info(self.vapi.cli("show ip neighbors"))
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070044
45 def run_basic_conn_test(self, af, acl_side):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020046 """Basic connectivity test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070047 conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242)
48 conn1.send_through(0)
49 # the return packets should pass
50 conn1.send_through(1)
51
52 def run_negative_conn_test(self, af, acl_side):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020053 """Packets with local spoofed address"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070054 conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242)
55 try:
56 p2 = conn1.send_through(0).command()
57 except:
58 # If we asserted while waiting, it's good.
59 # the conn should have timed out.
60 p2 = None
61 self.assert_equal(p2, None, ": packet should have been dropped")
62
63 def test_0010_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020064 """IPv4 basic connectivity test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070065 self.run_basic_conn_test(AF_INET, 0)
66
67 def test_0011_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020068 """IPv6 basic connectivity test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070069 self.run_basic_conn_test(AF_INET6, 0)
70
71 def test_0050_loopback_prepare_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020072 """Create loopbacks overlapping with remote addresses"""
Klement Sekerab9ef2732018-06-24 22:49:33 +020073 self.create_loopback_interfaces(2)
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070074 for i in range(2):
75 intf = self.lo_interfaces[i]
76 intf.admin_up()
Jakub Grajciar053204a2019-03-18 13:17:53 +010077 intf.local_ip4 = self.pg_interfaces[i].remote_ip4
78 intf.local_ip4_prefix_len = 32
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070079 intf.config_ip4()
Jakub Grajciar053204a2019-03-18 13:17:53 +010080 intf.local_ip6 = self.pg_interfaces[i].remote_ip6
81 intf.local_ip6_prefix_len = 128
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070082 intf.config_ip6()
83
84 def test_0110_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020085 """IPv4 local-spoof connectivity test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070086 self.run_negative_conn_test(AF_INET, 0)
87
88 def test_0111_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020089 """IPv6 local-spoof connectivity test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070090 self.run_negative_conn_test(AF_INET, 1)
91
92 def test_0200_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020093 """Configure container commands"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -070094 for i in range(2):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020095 for addr in [
96 self.pg_interfaces[i].remote_ip4,
97 self.pg_interfaces[i].remote_ip6,
98 ]:
99 self.vapi.ppcli(
100 "ip container " + addr + " " + self.pg_interfaces[i].name
101 )
102 self.vapi.ppcli(
103 "stn rule address "
104 + addr
105 + " interface "
106 + self.pg_interfaces[i].name
107 )
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700108
109 def test_0210_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200110 """IPv4 test after configuring container"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700111 self.run_basic_conn_test(AF_INET, 0)
112
113 def test_0211_basic_conn_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200114 """IPv6 test after configuring container"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700115 self.run_basic_conn_test(AF_INET, 1)
116
117 def test_0300_unconfigure_commands(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200118 """Unconfigure container commands"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700119 for i in range(2):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200120 for addr in [
121 self.pg_interfaces[i].remote_ip4,
122 self.pg_interfaces[i].remote_ip6,
123 ]:
124 self.vapi.ppcli(
125 "ip container " + addr + " " + self.pg_interfaces[i].name + " del"
126 )
127 self.vapi.ppcli(
128 "stn rule address "
129 + addr
130 + " interface "
131 + self.pg_interfaces[i].name
132 + " del"
133 )
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700134
135 def test_0410_spoof_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200136 """IPv4 local-spoof after unconfig test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700137 self.run_negative_conn_test(AF_INET, 0)
138
139 def test_0411_spoof_test(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200140 """IPv6 local-spoof after unconfig test"""
Andrew Yourtchenko5f3fcb92017-10-25 05:50:37 -0700141 self.run_negative_conn_test(AF_INET, 1)