Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 2 | """ACL IRB Test Case HLD: |
| 3 | |
| 4 | **config** |
| 5 | - L2 MAC learning enabled in l2bd |
| 6 | - 2 routed interfaces untagged, bvi (Bridge Virtual Interface) |
| 7 | - 2 bridged interfaces in l2bd with bvi |
| 8 | |
| 9 | **test** |
| 10 | - sending ip4 eth pkts between routed interfaces |
| 11 | - 2 routed interfaces |
| 12 | - 2 bridged interfaces |
| 13 | |
| 14 | - 64B, 512B, 1518B, 9200B (ether_size) |
| 15 | |
| 16 | - burst of pkts per interface |
| 17 | - 257pkts per burst |
| 18 | - routed pkts hitting different FIB entries |
| 19 | - bridged pkts hitting different MAC entries |
| 20 | |
| 21 | **verify** |
| 22 | - all packets received correctly |
| 23 | |
| 24 | """ |
| 25 | |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 26 | import copy |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 27 | import unittest |
| 28 | from socket import inet_pton, AF_INET, AF_INET6 |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 29 | from random import choice, shuffle |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 30 | from pprint import pprint |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 31 | from ipaddress import ip_network |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 32 | |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 33 | import scapy.compat |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 34 | from scapy.packet import Raw |
| 35 | from scapy.layers.l2 import Ether |
| 36 | from scapy.layers.inet import IP, UDP, ICMP, TCP |
| 37 | from scapy.layers.inet6 import IPv6, ICMPv6Unknown, ICMPv6EchoRequest |
| 38 | from scapy.layers.inet6 import ICMPv6EchoReply, IPv6ExtHdrRouting |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 39 | from scapy.layers.inet6 import IPv6ExtHdrFragment |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 40 | |
| 41 | from framework import VppTestCase, VppTestRunner |
Paul Vinciguerra | 95c0ca4 | 2019-03-28 13:07:00 -0700 | [diff] [blame] | 42 | from vpp_l2 import L2_PORT_TYPE |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 43 | import time |
| 44 | |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 45 | from vpp_acl import AclRule, VppAcl, VppAclInterface |
| 46 | |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 47 | |
juraj.linkes | 8e26f6d | 2018-09-19 14:59:43 +0200 | [diff] [blame] | 48 | class TestACLpluginL2L3(VppTestCase): |
| 49 | """TestACLpluginL2L3 Test Case""" |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 50 | |
| 51 | @classmethod |
| 52 | def setUpClass(cls): |
| 53 | """ |
| 54 | #. Create BD with MAC learning enabled and put interfaces to this BD. |
| 55 | #. Configure IPv4 addresses on loopback interface and routed interface. |
| 56 | #. Configure MAC address binding to IPv4 neighbors on loop0. |
| 57 | #. Configure MAC address on pg2. |
| 58 | #. Loopback BVI interface has remote hosts, one half of hosts are |
| 59 | behind pg0 second behind pg1. |
| 60 | """ |
juraj.linkes | 8e26f6d | 2018-09-19 14:59:43 +0200 | [diff] [blame] | 61 | super(TestACLpluginL2L3, cls).setUpClass() |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 62 | |
| 63 | cls.pg_if_packet_sizes = [64, 512, 1518, 9018] # packet sizes |
| 64 | cls.bd_id = 10 |
| 65 | cls.remote_hosts_count = 250 |
| 66 | |
| 67 | # create 3 pg interfaces, 1 loopback interface |
| 68 | cls.create_pg_interfaces(range(3)) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 69 | cls.create_loopback_interfaces(1) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 70 | |
| 71 | cls.interfaces = list(cls.pg_interfaces) |
| 72 | cls.interfaces.extend(cls.lo_interfaces) |
| 73 | |
| 74 | for i in cls.interfaces: |
| 75 | i.admin_up() |
| 76 | |
| 77 | # Create BD with MAC learning enabled and put interfaces to this BD |
| 78 | cls.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 79 | rx_sw_if_index=cls.loop0.sw_if_index, |
| 80 | bd_id=cls.bd_id, |
| 81 | port_type=L2_PORT_TYPE.BVI, |
| 82 | ) |
| 83 | cls.vapi.sw_interface_set_l2_bridge( |
| 84 | rx_sw_if_index=cls.pg0.sw_if_index, bd_id=cls.bd_id |
| 85 | ) |
| 86 | cls.vapi.sw_interface_set_l2_bridge( |
| 87 | rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.bd_id |
| 88 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 89 | |
| 90 | # Configure IPv4 addresses on loopback interface and routed interface |
| 91 | cls.loop0.config_ip4() |
| 92 | cls.loop0.config_ip6() |
| 93 | cls.pg2.config_ip4() |
| 94 | cls.pg2.config_ip6() |
| 95 | |
| 96 | # Configure MAC address binding to IPv4 neighbors on loop0 |
| 97 | cls.loop0.generate_remote_hosts(cls.remote_hosts_count) |
| 98 | cls.loop0.configure_ipv4_neighbors() |
| 99 | cls.loop0.configure_ipv6_neighbors() |
| 100 | # configure MAC address on pg2 |
| 101 | cls.pg2.resolve_arp() |
| 102 | cls.pg2.resolve_ndp() |
| 103 | |
| 104 | cls.WITHOUT_EH = False |
| 105 | cls.WITH_EH = True |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 106 | cls.STATELESS_ICMP = False |
| 107 | cls.STATEFUL_ICMP = True |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 108 | |
| 109 | # Loopback BVI interface has remote hosts, one half of hosts are behind |
| 110 | # pg0 second behind pg1 |
| 111 | half = cls.remote_hosts_count // 2 |
| 112 | cls.pg0.remote_hosts = cls.loop0.remote_hosts[:half] |
| 113 | cls.pg1.remote_hosts = cls.loop0.remote_hosts[half:] |
Andrew Yourtchenko | c02924e | 2019-08-15 12:26:17 +0000 | [diff] [blame] | 114 | reply = cls.vapi.papi.acl_stats_intf_counters_enable(enable=1) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 115 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 116 | @classmethod |
| 117 | def tearDownClass(cls): |
Andrew Yourtchenko | c02924e | 2019-08-15 12:26:17 +0000 | [diff] [blame] | 118 | reply = cls.vapi.papi.acl_stats_intf_counters_enable(enable=0) |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 119 | super(TestACLpluginL2L3, cls).tearDownClass() |
| 120 | |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 121 | def tearDown(self): |
| 122 | """Run standard test teardown and log ``show l2patch``, |
| 123 | ``show l2fib verbose``,``show bridge-domain <bd_id> detail``, |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 124 | ``show ip neighbors``. |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 125 | """ |
juraj.linkes | 8e26f6d | 2018-09-19 14:59:43 +0200 | [diff] [blame] | 126 | super(TestACLpluginL2L3, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 127 | |
| 128 | def show_commands_at_teardown(self): |
| 129 | self.logger.info(self.vapi.cli("show l2patch")) |
| 130 | self.logger.info(self.vapi.cli("show classify tables")) |
| 131 | self.logger.info(self.vapi.cli("show l2fib verbose")) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 132 | self.logger.info(self.vapi.cli("show bridge-domain %s detail" % self.bd_id)) |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 133 | self.logger.info(self.vapi.cli("show ip neighbors")) |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 134 | cmd = "show acl-plugin sessions verbose 1" |
| 135 | self.logger.info(self.vapi.cli(cmd)) |
| 136 | self.logger.info(self.vapi.cli("show acl-plugin acl")) |
| 137 | self.logger.info(self.vapi.cli("show acl-plugin interface")) |
| 138 | self.logger.info(self.vapi.cli("show acl-plugin tables")) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 139 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 140 | def create_stream( |
| 141 | self, |
| 142 | src_ip_if, |
| 143 | dst_ip_if, |
| 144 | reverse, |
| 145 | packet_sizes, |
| 146 | is_ip6, |
| 147 | expect_blocked, |
| 148 | expect_established, |
| 149 | add_extension_header, |
| 150 | icmp_stateful=False, |
| 151 | ): |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 152 | pkts = [] |
| 153 | rules = [] |
| 154 | permit_rules = [] |
| 155 | permit_and_reflect_rules = [] |
| 156 | total_packet_count = 8 |
| 157 | for i in range(0, total_packet_count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 158 | modulo = (i // 2) % 2 |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 159 | icmp_type_delta = i % 2 |
| 160 | icmp_code = i |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 161 | is_udp_packet = modulo == 0 |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 162 | if is_udp_packet and icmp_stateful: |
| 163 | continue |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 164 | is_reflectable_icmp = ( |
| 165 | icmp_stateful and icmp_type_delta == 0 and not is_udp_packet |
| 166 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 167 | is_reflected_icmp = is_reflectable_icmp and expect_established |
| 168 | can_reflect_this_packet = is_udp_packet or is_reflectable_icmp |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 169 | is_permit = i % 2 |
| 170 | remote_dst_index = i % len(dst_ip_if.remote_hosts) |
| 171 | remote_dst_host = dst_ip_if.remote_hosts[remote_dst_index] |
| 172 | if is_permit == 1: |
| 173 | info = self.create_packet_info(src_ip_if, dst_ip_if) |
| 174 | payload = self.info_to_payload(info) |
| 175 | else: |
| 176 | to_be_blocked = False |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 177 | if expect_blocked and not expect_established: |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 178 | to_be_blocked = True |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 179 | if not can_reflect_this_packet: |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 180 | to_be_blocked = True |
| 181 | if to_be_blocked: |
| 182 | payload = "to be blocked" |
| 183 | else: |
| 184 | info = self.create_packet_info(src_ip_if, dst_ip_if) |
| 185 | payload = self.info_to_payload(info) |
| 186 | if reverse: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 187 | dst_mac = "de:ad:00:00:00:00" |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 188 | src_mac = remote_dst_host._mac |
| 189 | dst_ip6 = src_ip_if.remote_ip6 |
| 190 | src_ip6 = remote_dst_host.ip6 |
| 191 | dst_ip4 = src_ip_if.remote_ip4 |
| 192 | src_ip4 = remote_dst_host.ip4 |
| 193 | dst_l4 = 1234 + i |
| 194 | src_l4 = 4321 + i |
| 195 | else: |
| 196 | dst_mac = src_ip_if.local_mac |
| 197 | src_mac = src_ip_if.remote_mac |
| 198 | src_ip6 = src_ip_if.remote_ip6 |
| 199 | dst_ip6 = remote_dst_host.ip6 |
| 200 | src_ip4 = src_ip_if.remote_ip4 |
| 201 | dst_ip4 = remote_dst_host.ip4 |
| 202 | src_l4 = 1234 + i |
| 203 | dst_l4 = 4321 + i |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 204 | if is_reflected_icmp: |
| 205 | icmp_type_delta = 1 |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 206 | |
| 207 | # default ULP should be something we do not use in tests |
| 208 | ulp_l4 = TCP(sport=src_l4, dport=dst_l4) |
| 209 | # potentially a chain of protocols leading to ULP |
| 210 | ulp = ulp_l4 |
| 211 | |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 212 | if is_udp_packet: |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 213 | if is_ip6: |
| 214 | ulp_l4 = UDP(sport=src_l4, dport=dst_l4) |
| 215 | if add_extension_header: |
| 216 | # prepend some extension headers |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 217 | ulp = ( |
| 218 | IPv6ExtHdrRouting() |
| 219 | / IPv6ExtHdrRouting() |
| 220 | / IPv6ExtHdrFragment(offset=0, m=1) |
| 221 | / ulp_l4 |
| 222 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 223 | # uncomment below to test invalid ones |
| 224 | # ulp = IPv6ExtHdrRouting(len = 200) / ulp_l4 |
| 225 | else: |
| 226 | ulp = ulp_l4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 227 | p = ( |
| 228 | Ether(dst=dst_mac, src=src_mac) |
| 229 | / IPv6(src=src_ip6, dst=dst_ip6) |
| 230 | / ulp |
| 231 | / Raw(payload) |
| 232 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 233 | else: |
| 234 | ulp_l4 = UDP(sport=src_l4, dport=dst_l4) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 235 | # IPv4 does not allow extension headers, |
| 236 | # but we rather make it a first fragment |
| 237 | flags = 1 if add_extension_header else 0 |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 238 | ulp = ulp_l4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 239 | p = ( |
| 240 | Ether(dst=dst_mac, src=src_mac) |
| 241 | / IP(src=src_ip4, dst=dst_ip4, frag=0, flags=flags) |
| 242 | / ulp |
| 243 | / Raw(payload) |
| 244 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 245 | elif modulo == 1: |
| 246 | if is_ip6: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 247 | ulp_l4 = ICMPv6Unknown(type=128 + icmp_type_delta, code=icmp_code) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 248 | ulp = ulp_l4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 249 | p = ( |
| 250 | Ether(dst=dst_mac, src=src_mac) |
| 251 | / IPv6(src=src_ip6, dst=dst_ip6) |
| 252 | / ulp |
| 253 | / Raw(payload) |
| 254 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 255 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 256 | ulp_l4 = ICMP(type=8 - 8 * icmp_type_delta, code=icmp_code) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 257 | ulp = ulp_l4 |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 258 | p = ( |
| 259 | Ether(dst=dst_mac, src=src_mac) |
| 260 | / IP(src=src_ip4, dst=dst_ip4) |
| 261 | / ulp |
| 262 | / Raw(payload) |
| 263 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 264 | |
| 265 | if i % 2 == 1: |
| 266 | info.data = p.copy() |
| 267 | size = packet_sizes[(i // 2) % len(packet_sizes)] |
| 268 | self.extend_packet(p, size) |
| 269 | pkts.append(p) |
| 270 | |
| 271 | rule_family = AF_INET6 if p.haslayer(IPv6) else AF_INET |
| 272 | rule_prefix_len = 128 if p.haslayer(IPv6) else 32 |
| 273 | rule_l3_layer = IPv6 if p.haslayer(IPv6) else IP |
| 274 | |
| 275 | if p.haslayer(UDP): |
| 276 | rule_l4_sport = p[UDP].sport |
| 277 | rule_l4_dport = p[UDP].dport |
| 278 | else: |
| 279 | if p.haslayer(ICMP): |
| 280 | rule_l4_sport = p[ICMP].type |
| 281 | rule_l4_dport = p[ICMP].code |
| 282 | else: |
| 283 | rule_l4_sport = p[ICMPv6Unknown].type |
| 284 | rule_l4_dport = p[ICMPv6Unknown].code |
| 285 | if p.haslayer(IPv6): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 286 | rule_l4_proto = ulp_l4.overload_fields[IPv6]["nh"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 287 | else: |
| 288 | rule_l4_proto = p[IP].proto |
| 289 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 290 | new_rule = AclRule( |
| 291 | is_permit=is_permit, |
| 292 | proto=rule_l4_proto, |
| 293 | src_prefix=ip_network((p[rule_l3_layer].src, rule_prefix_len)), |
| 294 | dst_prefix=ip_network((p[rule_l3_layer].dst, rule_prefix_len)), |
| 295 | sport_from=rule_l4_sport, |
| 296 | sport_to=rule_l4_sport, |
| 297 | dport_from=rule_l4_dport, |
| 298 | dport_to=rule_l4_dport, |
| 299 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 300 | |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 301 | rules.append(new_rule) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 302 | new_rule_permit = copy.copy(new_rule) |
| 303 | new_rule_permit.is_permit = 1 |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 304 | permit_rules.append(new_rule_permit) |
| 305 | |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 306 | new_rule_permit_and_reflect = copy.copy(new_rule) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 307 | if can_reflect_this_packet: |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 308 | new_rule_permit_and_reflect.is_permit = 2 |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 309 | else: |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 310 | new_rule_permit_and_reflect.is_permit = is_permit |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 311 | |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 312 | permit_and_reflect_rules.append(new_rule_permit_and_reflect) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 313 | self.logger.info("create_stream pkt#%d: %s" % (i, payload)) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 314 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 315 | return { |
| 316 | "stream": pkts, |
| 317 | "rules": rules, |
| 318 | "permit_rules": permit_rules, |
| 319 | "permit_and_reflect_rules": permit_and_reflect_rules, |
| 320 | } |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 321 | |
| 322 | def verify_capture(self, dst_ip_if, src_ip_if, capture, reverse): |
| 323 | last_info = dict() |
| 324 | for i in self.interfaces: |
| 325 | last_info[i.sw_if_index] = None |
| 326 | |
| 327 | dst_ip_sw_if_index = dst_ip_if.sw_if_index |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 328 | |
| 329 | for packet in capture: |
| 330 | l3 = IP if packet.haslayer(IP) else IPv6 |
| 331 | ip = packet[l3] |
| 332 | if packet.haslayer(UDP): |
| 333 | l4 = UDP |
| 334 | else: |
| 335 | if packet.haslayer(ICMP): |
| 336 | l4 = ICMP |
| 337 | else: |
| 338 | l4 = ICMPv6Unknown |
| 339 | |
| 340 | # Scapy IPv6 stuff is too smart for its own good. |
| 341 | # So we do this and coerce the ICMP into unknown type |
| 342 | if packet.haslayer(UDP): |
Paul Vinciguerra | a7427ec | 2019-03-10 10:04:23 -0700 | [diff] [blame] | 343 | data = scapy.compat.raw(packet[UDP][Raw]) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 344 | else: |
| 345 | if l3 == IP: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 346 | data = scapy.compat.raw( |
| 347 | ICMP(scapy.compat.raw(packet[l3].payload))[Raw] |
| 348 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 349 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 350 | data = scapy.compat.raw( |
| 351 | ICMPv6Unknown(scapy.compat.raw(packet[l3].payload)).msgbody |
| 352 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 353 | udp_or_icmp = packet[l3].payload |
Andrew Yourtchenko | e5468b3 | 2019-03-14 12:54:36 +0100 | [diff] [blame] | 354 | data_obj = Raw(data) |
| 355 | # FIXME: make framework believe we are on object |
| 356 | payload_info = self.payload_to_info(data_obj) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 357 | packet_index = payload_info.index |
| 358 | |
| 359 | self.assertEqual(payload_info.dst, dst_ip_sw_if_index) |
| 360 | |
| 361 | next_info = self.get_next_packet_info_for_interface2( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 362 | payload_info.src, dst_ip_sw_if_index, last_info[payload_info.src] |
| 363 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 364 | last_info[payload_info.src] = next_info |
| 365 | self.assertTrue(next_info is not None) |
| 366 | self.assertEqual(packet_index, next_info.index) |
| 367 | saved_packet = next_info.data |
| 368 | self.assertTrue(next_info is not None) |
| 369 | |
| 370 | # MAC: src, dst |
| 371 | if not reverse: |
| 372 | self.assertEqual(packet.src, dst_ip_if.local_mac) |
| 373 | host = dst_ip_if.host_by_mac(packet.dst) |
| 374 | |
| 375 | # IP: src, dst |
| 376 | # self.assertEqual(ip.src, src_ip_if.remote_ip4) |
| 377 | if saved_packet is not None: |
| 378 | self.assertEqual(ip.src, saved_packet[l3].src) |
| 379 | self.assertEqual(ip.dst, saved_packet[l3].dst) |
| 380 | if l4 == UDP: |
| 381 | self.assertEqual(udp_or_icmp.sport, saved_packet[l4].sport) |
| 382 | self.assertEqual(udp_or_icmp.dport, saved_packet[l4].dport) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 383 | # self.assertEqual(ip.dst, host.ip4) |
| 384 | |
| 385 | # UDP: |
| 386 | |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 387 | def applied_acl_shuffle(self, acl_if): |
| 388 | saved_n_input = acl_if.n_input |
| 389 | # TOTO: maybe copy each one?? |
| 390 | saved_acls = acl_if.acls |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 391 | |
| 392 | # now create a list of all the rules in all ACLs |
| 393 | all_rules = [] |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 394 | for old_acl in saved_acls: |
| 395 | for rule in old_acl.rules: |
| 396 | all_rules.append(rule) |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 397 | |
| 398 | # Add a few ACLs made from shuffled rules |
| 399 | shuffle(all_rules) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 400 | acl1 = VppAcl(self, rules=all_rules[::2], tag="shuffle 1. acl") |
| 401 | acl1.add_vpp_config() |
| 402 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 403 | shuffle(all_rules) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 404 | acl2 = VppAcl(self, rules=all_rules[::3], tag="shuffle 2. acl") |
| 405 | acl2.add_vpp_config() |
| 406 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 407 | shuffle(all_rules) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 408 | acl3 = VppAcl(self, rules=all_rules[::2], tag="shuffle 3. acl") |
| 409 | acl3.add_vpp_config() |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 410 | |
| 411 | # apply the shuffle ACLs in front |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 412 | input_acls = [acl1, acl2] |
| 413 | output_acls = [acl1, acl2] |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 414 | |
| 415 | # add the currently applied ACLs |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 416 | n_input = acl_if.n_input |
| 417 | input_acls.extend(saved_acls[:n_input]) |
| 418 | output_acls.extend(saved_acls[n_input:]) |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 419 | |
| 420 | # and the trailing shuffle ACL(s) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 421 | input_acls.extend([acl3]) |
| 422 | output_acls.extend([acl3]) |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 423 | |
| 424 | # set the interface ACL list to the result |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 425 | acl_if.n_input = len(input_acls) |
| 426 | acl_if.acls = input_acls + output_acls |
| 427 | acl_if.add_vpp_config() |
| 428 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 429 | # change the ACLs a few times |
| 430 | for i in range(1, 10): |
| 431 | shuffle(all_rules) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 432 | acl1.modify_vpp_config(all_rules[:: 1 + (i % 2)]) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 433 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 434 | shuffle(all_rules) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 435 | acl2.modify_vpp_config(all_rules[:: 1 + (i % 3)]) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 436 | |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 437 | shuffle(all_rules) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 438 | acl3.modify_vpp_config(all_rules[:: 1 + (i % 5)]) |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 439 | |
| 440 | # restore to how it was before and clean up |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 441 | acl_if.n_input = saved_n_input |
| 442 | acl_if.acls = saved_acls |
| 443 | acl_if.add_vpp_config() |
| 444 | |
| 445 | acl1.remove_vpp_config() |
| 446 | acl2.remove_vpp_config() |
| 447 | acl3.remove_vpp_config() |
Andrew Yourtchenko | 0e89dfc | 2018-03-23 09:34:29 +0100 | [diff] [blame] | 448 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 449 | def create_acls_for_a_stream(self, stream_dict, test_l2_action, is_reflect): |
| 450 | r = stream_dict["rules"] |
| 451 | r_permit = stream_dict["permit_rules"] |
| 452 | r_permit_reflect = stream_dict["permit_and_reflect_rules"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 453 | r_action = r_permit_reflect if is_reflect else r |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 454 | action_acl = VppAcl(self, rules=r_action, tag="act. acl") |
| 455 | action_acl.add_vpp_config() |
| 456 | permit_acl = VppAcl(self, rules=r_permit, tag="perm. acl") |
| 457 | permit_acl.add_vpp_config() |
| 458 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 459 | return { |
| 460 | "L2": action_acl if test_l2_action else permit_acl, |
| 461 | "L3": permit_acl if test_l2_action else action_acl, |
| 462 | "permit": permit_acl, |
| 463 | "action": action_acl, |
| 464 | } |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 465 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 466 | def apply_acl_ip46_x_to_y( |
| 467 | self, bridged_to_routed, test_l2_deny, is_ip6, is_reflect, add_eh |
| 468 | ): |
| 469 | """Apply the ACLs""" |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 470 | self.reset_packet_infos() |
| 471 | stream_dict = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 472 | self.pg2, |
| 473 | self.loop0, |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 474 | bridged_to_routed, |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 475 | self.pg_if_packet_sizes, |
| 476 | is_ip6, |
| 477 | not is_reflect, |
| 478 | False, |
| 479 | add_eh, |
| 480 | ) |
| 481 | stream = stream_dict["stream"] |
| 482 | acl_idx = self.create_acls_for_a_stream(stream_dict, test_l2_deny, is_reflect) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 483 | n_input_l3 = 0 if bridged_to_routed else 1 |
| 484 | n_input_l2 = 1 if bridged_to_routed else 0 |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 485 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 486 | acl_if_pg2 = VppAclInterface( |
| 487 | self, |
| 488 | sw_if_index=self.pg2.sw_if_index, |
| 489 | n_input=n_input_l3, |
| 490 | acls=[acl_idx["L3"]], |
| 491 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 492 | acl_if_pg2.add_vpp_config() |
| 493 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 494 | acl_if_pg0 = VppAclInterface( |
| 495 | self, |
| 496 | sw_if_index=self.pg0.sw_if_index, |
| 497 | n_input=n_input_l2, |
| 498 | acls=[acl_idx["L2"]], |
| 499 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 500 | acl_if_pg0.add_vpp_config() |
| 501 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 502 | acl_if_pg1 = VppAclInterface( |
| 503 | self, |
| 504 | sw_if_index=self.pg1.sw_if_index, |
| 505 | n_input=n_input_l2, |
| 506 | acls=[acl_idx["L2"]], |
| 507 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 508 | acl_if_pg1.add_vpp_config() |
| 509 | |
| 510 | self.applied_acl_shuffle(acl_if_pg0) |
| 511 | self.applied_acl_shuffle(acl_if_pg1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 512 | return {"L2": acl_idx["L2"], "L3": acl_idx["L3"]} |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 513 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 514 | def apply_acl_ip46_both_directions_reflect( |
| 515 | self, primary_is_bridged_to_routed, reflect_on_l2, is_ip6, add_eh, stateful_icmp |
| 516 | ): |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 517 | primary_is_routed_to_bridged = not primary_is_bridged_to_routed |
| 518 | self.reset_packet_infos() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 519 | stream_dict_fwd = self.create_stream( |
| 520 | self.pg2, |
| 521 | self.loop0, |
| 522 | primary_is_bridged_to_routed, |
| 523 | self.pg_if_packet_sizes, |
| 524 | is_ip6, |
| 525 | False, |
| 526 | False, |
| 527 | add_eh, |
| 528 | stateful_icmp, |
| 529 | ) |
| 530 | acl_idx_fwd = self.create_acls_for_a_stream( |
| 531 | stream_dict_fwd, reflect_on_l2, True |
| 532 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 533 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 534 | stream_dict_rev = self.create_stream( |
| 535 | self.pg2, |
| 536 | self.loop0, |
| 537 | not primary_is_bridged_to_routed, |
| 538 | self.pg_if_packet_sizes, |
| 539 | is_ip6, |
| 540 | True, |
| 541 | True, |
| 542 | add_eh, |
| 543 | stateful_icmp, |
| 544 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 545 | # We want the primary action to be "deny" rather than reflect |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 546 | acl_idx_rev = self.create_acls_for_a_stream( |
| 547 | stream_dict_rev, reflect_on_l2, False |
| 548 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 549 | |
| 550 | if primary_is_bridged_to_routed: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 551 | inbound_l2_acl = acl_idx_fwd["L2"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 552 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 553 | inbound_l2_acl = acl_idx_rev["L2"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 554 | |
| 555 | if primary_is_routed_to_bridged: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 556 | outbound_l2_acl = acl_idx_fwd["L2"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 557 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 558 | outbound_l2_acl = acl_idx_rev["L2"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 559 | |
| 560 | if primary_is_routed_to_bridged: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 561 | inbound_l3_acl = acl_idx_fwd["L3"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 562 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 563 | inbound_l3_acl = acl_idx_rev["L3"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 564 | |
| 565 | if primary_is_bridged_to_routed: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 566 | outbound_l3_acl = acl_idx_fwd["L3"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 567 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 568 | outbound_l3_acl = acl_idx_rev["L3"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 569 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 570 | acl_if_pg2 = VppAclInterface( |
| 571 | self, |
| 572 | sw_if_index=self.pg2.sw_if_index, |
| 573 | n_input=1, |
| 574 | acls=[inbound_l3_acl, outbound_l3_acl], |
| 575 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 576 | acl_if_pg2.add_vpp_config() |
| 577 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 578 | acl_if_pg0 = VppAclInterface( |
| 579 | self, |
| 580 | sw_if_index=self.pg0.sw_if_index, |
| 581 | n_input=1, |
| 582 | acls=[inbound_l2_acl, outbound_l2_acl], |
| 583 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 584 | acl_if_pg0.add_vpp_config() |
| 585 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 586 | acl_if_pg1 = VppAclInterface( |
| 587 | self, |
| 588 | sw_if_index=self.pg1.sw_if_index, |
| 589 | n_input=1, |
| 590 | acls=[inbound_l2_acl, outbound_l2_acl], |
| 591 | ) |
Jakub Grajciar | 2f8cd91 | 2020-03-27 06:55:06 +0100 | [diff] [blame] | 592 | acl_if_pg1.add_vpp_config() |
| 593 | |
| 594 | self.applied_acl_shuffle(acl_if_pg0) |
| 595 | self.applied_acl_shuffle(acl_if_pg2) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 596 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 597 | def apply_acl_ip46_routed_to_bridged( |
| 598 | self, test_l2_deny, is_ip6, is_reflect, add_eh |
| 599 | ): |
| 600 | return self.apply_acl_ip46_x_to_y( |
| 601 | False, test_l2_deny, is_ip6, is_reflect, add_eh |
| 602 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 603 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 604 | def apply_acl_ip46_bridged_to_routed( |
| 605 | self, test_l2_deny, is_ip6, is_reflect, add_eh |
| 606 | ): |
| 607 | return self.apply_acl_ip46_x_to_y( |
| 608 | True, test_l2_deny, is_ip6, is_reflect, add_eh |
| 609 | ) |
Andrew Yourtchenko | c02924e | 2019-08-15 12:26:17 +0000 | [diff] [blame] | 610 | |
| 611 | def verify_acl_packet_count(self, acl_idx, packet_count): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 612 | matches = self.statistics.get_counter("/acl/%d/matches" % acl_idx) |
Andrew Yourtchenko | c02924e | 2019-08-15 12:26:17 +0000 | [diff] [blame] | 613 | self.logger.info("stat seg for ACL %d: %s" % (acl_idx, repr(matches))) |
| 614 | total_count = 0 |
Andrew Yourtchenko | 270f523 | 2020-11-25 14:42:54 +0000 | [diff] [blame] | 615 | for m in matches: |
| 616 | for p in m: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 617 | total_count = total_count + p["packets"] |
Andrew Yourtchenko | c02924e | 2019-08-15 12:26:17 +0000 | [diff] [blame] | 618 | self.assertEqual(total_count, packet_count) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 619 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 620 | def run_traffic_ip46_x_to_y( |
| 621 | self, |
| 622 | bridged_to_routed, |
| 623 | test_l2_deny, |
| 624 | is_ip6, |
| 625 | is_reflect, |
| 626 | is_established, |
| 627 | add_eh, |
| 628 | stateful_icmp=False, |
| 629 | ): |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 630 | self.reset_packet_infos() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 631 | stream_dict = self.create_stream( |
| 632 | self.pg2, |
| 633 | self.loop0, |
| 634 | bridged_to_routed, |
| 635 | self.pg_if_packet_sizes, |
| 636 | is_ip6, |
| 637 | not is_reflect, |
| 638 | is_established, |
| 639 | add_eh, |
| 640 | stateful_icmp, |
| 641 | ) |
| 642 | stream = stream_dict["stream"] |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 643 | |
| 644 | tx_if = self.pg0 if bridged_to_routed else self.pg2 |
| 645 | rx_if = self.pg2 if bridged_to_routed else self.pg0 |
| 646 | |
| 647 | tx_if.add_stream(stream) |
| 648 | self.pg_enable_capture(self.pg_interfaces) |
| 649 | self.pg_start() |
| 650 | packet_count = self.get_packet_count_for_if_idx(self.loop0.sw_if_index) |
| 651 | rcvd1 = rx_if.get_capture(packet_count) |
| 652 | self.verify_capture(self.loop0, self.pg2, rcvd1, bridged_to_routed) |
Andrew Yourtchenko | c02924e | 2019-08-15 12:26:17 +0000 | [diff] [blame] | 653 | return len(stream) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 654 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 655 | def run_traffic_ip46_routed_to_bridged( |
| 656 | self, |
| 657 | test_l2_deny, |
| 658 | is_ip6, |
| 659 | is_reflect, |
| 660 | is_established, |
| 661 | add_eh, |
| 662 | stateful_icmp=False, |
| 663 | ): |
| 664 | return self.run_traffic_ip46_x_to_y( |
| 665 | False, |
| 666 | test_l2_deny, |
| 667 | is_ip6, |
| 668 | is_reflect, |
| 669 | is_established, |
| 670 | add_eh, |
| 671 | stateful_icmp, |
| 672 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 673 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 674 | def run_traffic_ip46_bridged_to_routed( |
| 675 | self, |
| 676 | test_l2_deny, |
| 677 | is_ip6, |
| 678 | is_reflect, |
| 679 | is_established, |
| 680 | add_eh, |
| 681 | stateful_icmp=False, |
| 682 | ): |
| 683 | return self.run_traffic_ip46_x_to_y( |
| 684 | True, |
| 685 | test_l2_deny, |
| 686 | is_ip6, |
| 687 | is_reflect, |
| 688 | is_established, |
| 689 | add_eh, |
| 690 | stateful_icmp, |
| 691 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 692 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 693 | def run_test_ip46_routed_to_bridged(self, test_l2_deny, is_ip6, is_reflect, add_eh): |
| 694 | acls = self.apply_acl_ip46_routed_to_bridged( |
| 695 | test_l2_deny, is_ip6, is_reflect, add_eh |
| 696 | ) |
| 697 | pkts = self.run_traffic_ip46_routed_to_bridged( |
| 698 | test_l2_deny, is_ip6, is_reflect, False, add_eh |
| 699 | ) |
| 700 | self.verify_acl_packet_count(acls["L3"].acl_index, pkts) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 701 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 702 | def run_test_ip46_bridged_to_routed(self, test_l2_deny, is_ip6, is_reflect, add_eh): |
| 703 | acls = self.apply_acl_ip46_bridged_to_routed( |
| 704 | test_l2_deny, is_ip6, is_reflect, add_eh |
| 705 | ) |
| 706 | pkts = self.run_traffic_ip46_bridged_to_routed( |
| 707 | test_l2_deny, is_ip6, is_reflect, False, add_eh |
| 708 | ) |
| 709 | self.verify_acl_packet_count(acls["L2"].acl_index, pkts) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 710 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 711 | def run_test_ip46_routed_to_bridged_and_back( |
| 712 | self, test_l2_action, is_ip6, add_eh, stateful_icmp=False |
| 713 | ): |
| 714 | self.apply_acl_ip46_both_directions_reflect( |
| 715 | False, test_l2_action, is_ip6, add_eh, stateful_icmp |
| 716 | ) |
| 717 | self.run_traffic_ip46_routed_to_bridged( |
| 718 | test_l2_action, is_ip6, True, False, add_eh, stateful_icmp |
| 719 | ) |
| 720 | self.run_traffic_ip46_bridged_to_routed( |
| 721 | test_l2_action, is_ip6, False, True, add_eh, stateful_icmp |
| 722 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 723 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 724 | def run_test_ip46_bridged_to_routed_and_back( |
| 725 | self, test_l2_action, is_ip6, add_eh, stateful_icmp=False |
| 726 | ): |
| 727 | self.apply_acl_ip46_both_directions_reflect( |
| 728 | True, test_l2_action, is_ip6, add_eh, stateful_icmp |
| 729 | ) |
| 730 | self.run_traffic_ip46_bridged_to_routed( |
| 731 | test_l2_action, is_ip6, True, False, add_eh, stateful_icmp |
| 732 | ) |
| 733 | self.run_traffic_ip46_routed_to_bridged( |
| 734 | test_l2_action, is_ip6, False, True, add_eh, stateful_icmp |
| 735 | ) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 736 | |
| 737 | def test_0000_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 738 | """ACL plugin prepare""" |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 739 | if not self.vpp_dead: |
| 740 | cmd = "set acl-plugin session timeout udp idle 2000" |
| 741 | self.logger.info(self.vapi.ppcli(cmd)) |
| 742 | # uncomment to not skip past the routing header |
| 743 | # and watch the EH tests fail |
| 744 | # self.logger.info(self.vapi.ppcli( |
| 745 | # "set acl-plugin skip-ipv6-extension-header 43 0")) |
| 746 | # uncomment to test the session limit (stateful tests will fail) |
| 747 | # self.logger.info(self.vapi.ppcli( |
| 748 | # "set acl-plugin session table max-entries 1")) |
| 749 | # new datapath is the default, but just in case |
| 750 | # self.logger.info(self.vapi.ppcli( |
| 751 | # "set acl-plugin l2-datapath new")) |
| 752 | # If you want to see some tests fail, uncomment the next line |
| 753 | # self.logger.info(self.vapi.ppcli( |
| 754 | # "set acl-plugin l2-datapath old")) |
| 755 | |
| 756 | def test_0001_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 757 | """ACL IPv6 routed -> bridged, L2 ACL deny""" |
| 758 | self.run_test_ip46_routed_to_bridged(True, True, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 759 | |
| 760 | def test_0002_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 761 | """ACL IPv6 routed -> bridged, L3 ACL deny""" |
| 762 | self.run_test_ip46_routed_to_bridged(False, True, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 763 | |
| 764 | def test_0003_ip4_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 765 | """ACL IPv4 routed -> bridged, L2 ACL deny""" |
| 766 | self.run_test_ip46_routed_to_bridged(True, False, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 767 | |
| 768 | def test_0004_ip4_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 769 | """ACL IPv4 routed -> bridged, L3 ACL deny""" |
| 770 | self.run_test_ip46_routed_to_bridged(False, False, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 771 | |
| 772 | def test_0005_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 773 | """ACL IPv6 bridged -> routed, L2 ACL deny""" |
| 774 | self.run_test_ip46_bridged_to_routed(True, True, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 775 | |
| 776 | def test_0006_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 777 | """ACL IPv6 bridged -> routed, L3 ACL deny""" |
| 778 | self.run_test_ip46_bridged_to_routed(False, True, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 779 | |
| 780 | def test_0007_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 781 | """ACL IPv4 bridged -> routed, L2 ACL deny""" |
| 782 | self.run_test_ip46_bridged_to_routed(True, False, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 783 | |
| 784 | def test_0008_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 785 | """ACL IPv4 bridged -> routed, L3 ACL deny""" |
| 786 | self.run_test_ip46_bridged_to_routed(False, False, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 787 | |
| 788 | # Stateful ACL tests |
| 789 | def test_0101_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 790 | """ACL IPv6 routed -> bridged, L2 ACL permit+reflect""" |
| 791 | self.run_test_ip46_routed_to_bridged_and_back(True, True, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 792 | |
| 793 | def test_0102_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 794 | """ACL IPv6 bridged -> routed, L2 ACL permit+reflect""" |
| 795 | self.run_test_ip46_bridged_to_routed_and_back(True, True, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 796 | |
| 797 | def test_0103_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 798 | """ACL IPv4 routed -> bridged, L2 ACL permit+reflect""" |
| 799 | self.run_test_ip46_routed_to_bridged_and_back(True, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 800 | |
| 801 | def test_0104_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 802 | """ACL IPv4 bridged -> routed, L2 ACL permit+reflect""" |
| 803 | self.run_test_ip46_bridged_to_routed_and_back(True, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 804 | |
| 805 | def test_0111_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 806 | """ACL IPv6 routed -> bridged, L3 ACL permit+reflect""" |
| 807 | self.run_test_ip46_routed_to_bridged_and_back(False, True, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 808 | |
| 809 | def test_0112_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 810 | """ACL IPv6 bridged -> routed, L3 ACL permit+reflect""" |
| 811 | self.run_test_ip46_bridged_to_routed_and_back(False, True, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 812 | |
| 813 | def test_0113_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 814 | """ACL IPv4 routed -> bridged, L3 ACL permit+reflect""" |
| 815 | self.run_test_ip46_routed_to_bridged_and_back(False, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 816 | |
| 817 | def test_0114_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 818 | """ACL IPv4 bridged -> routed, L3 ACL permit+reflect""" |
| 819 | self.run_test_ip46_bridged_to_routed_and_back(False, False, self.WITHOUT_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 820 | |
| 821 | # A block of tests with extension headers |
| 822 | |
| 823 | def test_1001_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 824 | """ACL IPv6+EH routed -> bridged, L2 ACL deny""" |
| 825 | self.run_test_ip46_routed_to_bridged(True, True, False, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 826 | |
| 827 | def test_1002_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 828 | """ACL IPv6+EH routed -> bridged, L3 ACL deny""" |
| 829 | self.run_test_ip46_routed_to_bridged(False, True, False, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 830 | |
| 831 | def test_1005_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 832 | """ACL IPv6+EH bridged -> routed, L2 ACL deny""" |
| 833 | self.run_test_ip46_bridged_to_routed(True, True, False, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 834 | |
| 835 | def test_1006_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 836 | """ACL IPv6+EH bridged -> routed, L3 ACL deny""" |
| 837 | self.run_test_ip46_bridged_to_routed(False, True, False, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 838 | |
| 839 | def test_1101_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 840 | """ACL IPv6+EH routed -> bridged, L2 ACL permit+reflect""" |
| 841 | self.run_test_ip46_routed_to_bridged_and_back(True, True, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 842 | |
| 843 | def test_1102_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 844 | """ACL IPv6+EH bridged -> routed, L2 ACL permit+reflect""" |
| 845 | self.run_test_ip46_bridged_to_routed_and_back(True, True, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 846 | |
| 847 | def test_1111_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 848 | """ACL IPv6+EH routed -> bridged, L3 ACL permit+reflect""" |
| 849 | self.run_test_ip46_routed_to_bridged_and_back(False, True, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 850 | |
| 851 | def test_1112_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 852 | """ACL IPv6+EH bridged -> routed, L3 ACL permit+reflect""" |
| 853 | self.run_test_ip46_bridged_to_routed_and_back(False, True, self.WITH_EH) |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 854 | |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 855 | # IPv4 with "MF" bit set |
| 856 | |
| 857 | def test_1201_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 858 | """ACL IPv4+MF routed -> bridged, L2 ACL deny""" |
| 859 | self.run_test_ip46_routed_to_bridged(True, False, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 860 | |
| 861 | def test_1202_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 862 | """ACL IPv4+MF routed -> bridged, L3 ACL deny""" |
| 863 | self.run_test_ip46_routed_to_bridged(False, False, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 864 | |
| 865 | def test_1205_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 866 | """ACL IPv4+MF bridged -> routed, L2 ACL deny""" |
| 867 | self.run_test_ip46_bridged_to_routed(True, False, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 868 | |
| 869 | def test_1206_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 870 | """ACL IPv4+MF bridged -> routed, L3 ACL deny""" |
| 871 | self.run_test_ip46_bridged_to_routed(False, False, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 872 | |
| 873 | def test_1301_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 874 | """ACL IPv4+MF routed -> bridged, L2 ACL permit+reflect""" |
| 875 | self.run_test_ip46_routed_to_bridged_and_back(True, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 876 | |
| 877 | def test_1302_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 878 | """ACL IPv4+MF bridged -> routed, L2 ACL permit+reflect""" |
| 879 | self.run_test_ip46_bridged_to_routed_and_back(True, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 880 | |
| 881 | def test_1311_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 882 | """ACL IPv4+MF routed -> bridged, L3 ACL permit+reflect""" |
| 883 | self.run_test_ip46_routed_to_bridged_and_back(False, False, self.WITH_EH) |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 884 | |
| 885 | def test_1312_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 886 | """ACL IPv4+MF bridged -> routed, L3 ACL permit+reflect""" |
| 887 | self.run_test_ip46_bridged_to_routed_and_back(False, False, self.WITH_EH) |
| 888 | |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 889 | # Stateful ACL tests with stateful ICMP |
| 890 | |
| 891 | def test_1401_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 892 | """IPv6 routed -> bridged, L2 ACL permit+reflect, ICMP reflect""" |
| 893 | self.run_test_ip46_routed_to_bridged_and_back( |
| 894 | True, True, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 895 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 896 | |
| 897 | def test_1402_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 898 | """IPv6 bridged -> routed, L2 ACL permit+reflect, ICMP reflect""" |
| 899 | self.run_test_ip46_bridged_to_routed_and_back( |
| 900 | True, True, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 901 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 902 | |
| 903 | def test_1403_ip4_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 904 | """IPv4 routed -> bridged, L2 ACL permit+reflect, ICMP reflect""" |
| 905 | self.run_test_ip46_routed_to_bridged_and_back( |
| 906 | True, False, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 907 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 908 | |
| 909 | def test_1404_ip4_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 910 | """IPv4 bridged -> routed, L2 ACL permit+reflect, ICMP reflect""" |
| 911 | self.run_test_ip46_bridged_to_routed_and_back( |
| 912 | True, False, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 913 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 914 | |
| 915 | def test_1411_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 916 | """IPv6 routed -> bridged, L3 ACL permit+reflect, ICMP reflect""" |
| 917 | self.run_test_ip46_routed_to_bridged_and_back( |
| 918 | False, True, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 919 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 920 | |
| 921 | def test_1412_ip6_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 922 | """IPv6 bridged -> routed, L3 ACL permit+reflect, ICMP reflect""" |
| 923 | self.run_test_ip46_bridged_to_routed_and_back( |
| 924 | False, True, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 925 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 926 | |
| 927 | def test_1413_ip4_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 928 | """IPv4 routed -> bridged, L3 ACL permit+reflect, ICMP reflect""" |
| 929 | self.run_test_ip46_routed_to_bridged_and_back( |
| 930 | False, False, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 931 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 932 | |
| 933 | def test_1414_ip4_irb_1(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 934 | """IPv4 bridged -> routed, L3 ACL permit+reflect, ICMP reflect""" |
| 935 | self.run_test_ip46_bridged_to_routed_and_back( |
| 936 | False, False, self.WITHOUT_EH, self.STATEFUL_ICMP |
| 937 | ) |
Andrew Yourtchenko | fae8337 | 2018-09-26 21:03:06 +0200 | [diff] [blame] | 938 | |
Andrew Yourtchenko | d1b0564 | 2017-04-04 14:10:40 +0000 | [diff] [blame] | 939 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 940 | if __name__ == "__main__": |
Andrew Yourtchenko | d2a59be | 2017-03-21 10:31:55 +0100 | [diff] [blame] | 941 | unittest.main(testRunner=VppTestRunner) |