Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 2 | """ Container integration tests """ |
| 3 | |
| 4 | import unittest |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 5 | from config import config |
| 6 | from framework import VppTestCase, VppTestRunner |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 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 |
| 18 | |
| 19 | |
| 20 | class Conn(L4_Conn): |
| 21 | # for now same as L4_Conn |
| 22 | pass |
| 23 | |
| 24 | |
Klement Sekera | b23ffd7 | 2021-05-31 16:08:53 +0200 | [diff] [blame] | 25 | @unittest.skipUnless(config.extended, "part of extended tests") |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 26 | class ContainerIntegrationTestCase(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 27 | """Container integration extended testcases""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 28 | |
| 29 | @classmethod |
Paul Vinciguerra | 56d68cb | 2018-11-27 05:53:35 -0800 | [diff] [blame] | 30 | def setUpClass(cls): |
| 31 | super(ContainerIntegrationTestCase, cls).setUpClass() |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 32 | # create pg0 and pg1 |
Paul Vinciguerra | 56d68cb | 2018-11-27 05:53:35 -0800 | [diff] [blame] | 33 | cls.create_pg_interfaces(range(2)) |
| 34 | for i in cls.pg_interfaces: |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 35 | i.admin_up() |
| 36 | i.config_ip4() |
| 37 | i.config_ip6() |
| 38 | i.resolve_arp() |
| 39 | i.resolve_ndp() |
| 40 | |
Paul Vinciguerra | 8d991d9 | 2019-01-25 14:05:48 -0800 | [diff] [blame] | 41 | @classmethod |
| 42 | def tearDownClass(cls): |
| 43 | super(ContainerIntegrationTestCase, cls).tearDownClass() |
| 44 | |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 45 | def tearDown(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 46 | """Run standard test teardown and log various show commands""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 47 | super(ContainerIntegrationTestCase, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 48 | |
| 49 | def show_commands_at_teardown(self): |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 50 | self.logger.info(self.vapi.cli("show ip neighbors")) |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 51 | |
| 52 | def run_basic_conn_test(self, af, acl_side): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 53 | """Basic connectivity test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 54 | conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242) |
| 55 | conn1.send_through(0) |
| 56 | # the return packets should pass |
| 57 | conn1.send_through(1) |
| 58 | |
| 59 | def run_negative_conn_test(self, af, acl_side): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 60 | """Packets with local spoofed address""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 61 | conn1 = Conn(self, self.pg0, self.pg1, af, UDP, 42001, 4242) |
| 62 | try: |
| 63 | p2 = conn1.send_through(0).command() |
| 64 | except: |
| 65 | # If we asserted while waiting, it's good. |
| 66 | # the conn should have timed out. |
| 67 | p2 = None |
| 68 | self.assert_equal(p2, None, ": packet should have been dropped") |
| 69 | |
| 70 | def test_0010_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 71 | """IPv4 basic connectivity test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 72 | self.run_basic_conn_test(AF_INET, 0) |
| 73 | |
| 74 | def test_0011_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 75 | """IPv6 basic connectivity test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 76 | self.run_basic_conn_test(AF_INET6, 0) |
| 77 | |
| 78 | def test_0050_loopback_prepare_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 79 | """Create loopbacks overlapping with remote addresses""" |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 80 | self.create_loopback_interfaces(2) |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 81 | for i in range(2): |
| 82 | intf = self.lo_interfaces[i] |
| 83 | intf.admin_up() |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 84 | intf.local_ip4 = self.pg_interfaces[i].remote_ip4 |
| 85 | intf.local_ip4_prefix_len = 32 |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 86 | intf.config_ip4() |
Jakub Grajciar | 053204a | 2019-03-18 13:17:53 +0100 | [diff] [blame] | 87 | intf.local_ip6 = self.pg_interfaces[i].remote_ip6 |
| 88 | intf.local_ip6_prefix_len = 128 |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 89 | intf.config_ip6() |
| 90 | |
| 91 | def test_0110_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 92 | """IPv4 local-spoof connectivity test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 93 | self.run_negative_conn_test(AF_INET, 0) |
| 94 | |
| 95 | def test_0111_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 96 | """IPv6 local-spoof connectivity test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 97 | self.run_negative_conn_test(AF_INET, 1) |
| 98 | |
| 99 | def test_0200_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 100 | """Configure container commands""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 101 | for i in range(2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 102 | for addr in [ |
| 103 | self.pg_interfaces[i].remote_ip4, |
| 104 | self.pg_interfaces[i].remote_ip6, |
| 105 | ]: |
| 106 | self.vapi.ppcli( |
| 107 | "ip container " + addr + " " + self.pg_interfaces[i].name |
| 108 | ) |
| 109 | self.vapi.ppcli( |
| 110 | "stn rule address " |
| 111 | + addr |
| 112 | + " interface " |
| 113 | + self.pg_interfaces[i].name |
| 114 | ) |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 115 | |
| 116 | def test_0210_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 117 | """IPv4 test after configuring container""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 118 | self.run_basic_conn_test(AF_INET, 0) |
| 119 | |
| 120 | def test_0211_basic_conn_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 121 | """IPv6 test after configuring container""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 122 | self.run_basic_conn_test(AF_INET, 1) |
| 123 | |
| 124 | def test_0300_unconfigure_commands(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 125 | """Unconfigure container commands""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 126 | for i in range(2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 127 | for addr in [ |
| 128 | self.pg_interfaces[i].remote_ip4, |
| 129 | self.pg_interfaces[i].remote_ip6, |
| 130 | ]: |
| 131 | self.vapi.ppcli( |
| 132 | "ip container " + addr + " " + self.pg_interfaces[i].name + " del" |
| 133 | ) |
| 134 | self.vapi.ppcli( |
| 135 | "stn rule address " |
| 136 | + addr |
| 137 | + " interface " |
| 138 | + self.pg_interfaces[i].name |
| 139 | + " del" |
| 140 | ) |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 141 | |
| 142 | def test_0410_spoof_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 143 | """IPv4 local-spoof after unconfig test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 144 | self.run_negative_conn_test(AF_INET, 0) |
| 145 | |
| 146 | def test_0411_spoof_test(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 147 | """IPv6 local-spoof after unconfig test""" |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 148 | self.run_negative_conn_test(AF_INET, 1) |