blob: 6a1ba58918239383d75555fede872b73aa12b04b [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Paul Vinciguerra661f91f2018-11-28 19:06:41 -08002from __future__ import print_function
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02003
Pavel Kotucek932f7412017-09-07 14:44:52 +02004"""ACL plugin - MACIP tests
5"""
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -08006import binascii
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -07007import ipaddress
Pavel Kotucek932f7412017-09-07 14:44:52 +02008import random
Paul Vinciguerraa279d9c2019-02-28 09:00:09 -08009from socket import inet_ntop, inet_pton, AF_INET, AF_INET6
10from struct import pack, unpack
Pavel Kotucek932f7412017-09-07 14:44:52 +020011import re
12import unittest
Jakub Grajciar2f8cd912020-03-27 06:55:06 +010013from ipaddress import ip_network, IPv4Network, IPv6Network
Pavel Kotucek932f7412017-09-07 14:44:52 +020014
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -070015import scapy.compat
Pavel Kotucek932f7412017-09-07 14:44:52 +020016from scapy.packet import Raw
17from scapy.layers.l2 import Ether
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020018from scapy.layers.inet import IP, UDP
Pavel Kotucek932f7412017-09-07 14:44:52 +020019from scapy.layers.inet6 import IPv6
20
Klement Sekerab23ffd72021-05-31 16:08:53 +020021from framework import VppTestCase, VppTestRunner
Pavel Kotucek932f7412017-09-07 14:44:52 +020022from vpp_lo_interface import VppLoInterface
Paul Vinciguerra95c0ca42019-03-28 13:07:00 -070023from vpp_l2 import L2_PORT_TYPE
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020024from vpp_sub_interface import (
25 L2_VTR_OP,
26 VppSubInterface,
27 VppDot1QSubint,
28 VppDot1ADSubint,
29)
30from vpp_acl import (
31 AclRule,
32 VppAcl,
33 VppAclInterface,
34 VppEtypeWhitelist,
35 VppMacipAclInterface,
36 VppMacipAcl,
37 MacipRule,
38)
Jakub Grajciar2f8cd912020-03-27 06:55:06 +010039from vpp_papi import MACAddress
Pavel Kotucek932f7412017-09-07 14:44:52 +020040
41
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020042class MethodHolder(VppTestCase):
Pavel Kotucek932f7412017-09-07 14:44:52 +020043 DEBUG = False
44
45 BRIDGED = True
46 ROUTED = False
47
48 IS_IP4 = False
49 IS_IP6 = True
50
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020051 DOT1AD = "dot1ad"
52 DOT1Q = "dot1q"
53 PERMIT_TAGS = True
54 DENY_TAGS = False
55
Pavel Kotucek932f7412017-09-07 14:44:52 +020056 # rule types
57 DENY = 0
58 PERMIT = 1
59
60 # ACL types
61 EXACT_IP = 1
62 SUBNET_IP = 2
63 WILD_IP = 3
64
65 EXACT_MAC = 1
66 WILD_MAC = 2
67 OUI_MAC = 3
68
69 ACLS = []
70
71 @classmethod
72 def setUpClass(cls):
73 """
74 Perform standard class setup (defined by class method setUpClass in
75 class VppTestCase) before running the test case, set test case related
76 variables and configure VPP.
77 """
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020078 super(MethodHolder, cls).setUpClass()
Pavel Kotucek932f7412017-09-07 14:44:52 +020079
80 cls.pg_if_packet_sizes = [64, 512, 1518, 9018] # packet sizes
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020081 cls.bd_id = 111
82 cls.remote_hosts_count = 200
Pavel Kotucek932f7412017-09-07 14:44:52 +020083
84 try:
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020085 # create 4 pg interfaces, 1 loopback interface
86 cls.create_pg_interfaces(range(4))
Klement Sekerab9ef2732018-06-24 22:49:33 +020087 cls.create_loopback_interfaces(1)
Pavel Kotucek932f7412017-09-07 14:44:52 +020088
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020089 # create 2 subinterfaces
90 cls.subifs = [
Jakub Grajciar2f8cd912020-03-27 06:55:06 +010091 VppDot1QSubint(cls, cls.pg1, 10),
92 VppDot1ADSubint(cls, cls.pg2, 20, 300, 400),
93 VppDot1QSubint(cls, cls.pg3, 30),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020094 VppDot1ADSubint(cls, cls.pg3, 40, 600, 700),
95 ]
Pavel Kotucek8daa80a2017-09-25 09:44:05 +020096
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020097 cls.subifs[0].set_vtr(L2_VTR_OP.L2_POP_1, inner=10, push1q=1)
98 cls.subifs[1].set_vtr(L2_VTR_OP.L2_POP_2, outer=300, inner=400, push1q=1)
99 cls.subifs[2].set_vtr(L2_VTR_OP.L2_POP_1, inner=30, push1q=1)
100 cls.subifs[3].set_vtr(L2_VTR_OP.L2_POP_2, outer=600, inner=700, push1q=1)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200101
Pavel Kotucek932f7412017-09-07 14:44:52 +0200102 cls.interfaces = list(cls.pg_interfaces)
103 cls.interfaces.extend(cls.lo_interfaces)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200104 cls.interfaces.extend(cls.subifs)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200105
106 for i in cls.interfaces:
107 i.admin_up()
108
109 # Create BD with MAC learning enabled and put interfaces to this BD
110 cls.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200111 rx_sw_if_index=cls.loop0.sw_if_index,
112 bd_id=cls.bd_id,
113 port_type=L2_PORT_TYPE.BVI,
114 )
Pavel Kotucek932f7412017-09-07 14:44:52 +0200115 cls.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200116 rx_sw_if_index=cls.pg0.sw_if_index, bd_id=cls.bd_id
117 )
Pavel Kotucek932f7412017-09-07 14:44:52 +0200118 cls.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200119 rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.bd_id
120 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200121 cls.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200122 rx_sw_if_index=cls.subifs[0].sw_if_index, bd_id=cls.bd_id
123 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200124 cls.vapi.sw_interface_set_l2_bridge(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200125 rx_sw_if_index=cls.subifs[1].sw_if_index, bd_id=cls.bd_id
126 )
Pavel Kotucek932f7412017-09-07 14:44:52 +0200127
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200128 # Configure IPv4/6 addresses on loop interface and routed interface
Pavel Kotucek932f7412017-09-07 14:44:52 +0200129 cls.loop0.config_ip4()
130 cls.loop0.config_ip6()
131 cls.pg2.config_ip4()
132 cls.pg2.config_ip6()
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200133 cls.pg3.config_ip4()
134 cls.pg3.config_ip6()
Pavel Kotucek932f7412017-09-07 14:44:52 +0200135
136 # Configure MAC address binding to IPv4 neighbors on loop0
137 cls.loop0.generate_remote_hosts(cls.remote_hosts_count)
138 # Modify host mac addresses to have different OUI parts
139 for i in range(2, cls.remote_hosts_count + 2):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200140 mac = cls.loop0.remote_hosts[i - 2]._mac.split(":")
Pavel Kotucek932f7412017-09-07 14:44:52 +0200141 mac[2] = format(int(mac[2], 16) + i, "02x")
142 cls.loop0.remote_hosts[i - 2]._mac = ":".join(mac)
143
144 cls.loop0.configure_ipv4_neighbors()
145 cls.loop0.configure_ipv6_neighbors()
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200146
147 # configure MAC address on pg3
148 cls.pg3.resolve_arp()
149 cls.pg3.resolve_ndp()
150
151 # configure MAC address on subifs
152 for i in cls.subifs:
153 i.config_ip4()
154 i.resolve_arp()
155 i.config_ip6()
156
Pavel Kotucek932f7412017-09-07 14:44:52 +0200157 # configure MAC address on pg2
158 cls.pg2.resolve_arp()
159 cls.pg2.resolve_ndp()
160
161 # Loopback BVI interface has remote hosts
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200162 # one half of hosts are behind pg0 second behind pg1,pg2,pg3 subifs
163 cls.pg0.remote_hosts = cls.loop0.remote_hosts[:100]
164 cls.subifs[0].remote_hosts = cls.loop0.remote_hosts[100:125]
165 cls.subifs[1].remote_hosts = cls.loop0.remote_hosts[125:150]
166 cls.subifs[2].remote_hosts = cls.loop0.remote_hosts[150:175]
167 cls.subifs[3].remote_hosts = cls.loop0.remote_hosts[175:]
Pavel Kotucek932f7412017-09-07 14:44:52 +0200168
169 except Exception:
juraj.linkes8e26f6d2018-09-19 14:59:43 +0200170 super(MethodHolder, cls).tearDownClass()
Pavel Kotucek932f7412017-09-07 14:44:52 +0200171 raise
172
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700173 @classmethod
174 def tearDownClass(cls):
175 super(MethodHolder, cls).tearDownClass()
176
Pavel Kotucek932f7412017-09-07 14:44:52 +0200177 def setUp(self):
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200178 super(MethodHolder, self).setUp()
Pavel Kotucek932f7412017-09-07 14:44:52 +0200179 self.reset_packet_infos()
Paul Vinciguerra90cf21b2019-03-13 09:23:05 -0700180
181 def show_commands_at_teardown(self):
182 self.logger.info(self.vapi.ppcli("show interface address"))
183 self.logger.info(self.vapi.ppcli("show hardware"))
184 self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl"))
185 self.logger.info(self.vapi.ppcli("sh acl-plugin macip interface"))
186 self.logger.info(self.vapi.ppcli("sh classify tables verbose"))
187 self.logger.info(self.vapi.ppcli("sh acl-plugin acl"))
188 self.logger.info(self.vapi.ppcli("sh acl-plugin interface"))
189 self.logger.info(self.vapi.ppcli("sh acl-plugin tables"))
190 # print(self.vapi.ppcli("show interface address"))
191 # print(self.vapi.ppcli("show hardware"))
192 # print(self.vapi.ppcli("sh acl-plugin macip interface"))
193 # print(self.vapi.ppcli("sh acl-plugin macip acl"))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200194
195 def macip_acl_dump_debug(self):
196 acls = self.vapi.macip_acl_dump()
197 if self.DEBUG:
198 for acl in acls:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100199 # print("ACL #"+str(acl.acl_index))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200200 for r in acl.r:
201 rule = "ACTION"
202 if r.is_permit == 1:
203 rule = "PERMIT"
204 elif r.is_permit == 0:
205 rule = "DENY "
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100206 """
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800207 print(" IP6" if r.is_ipv6 else " IP4",
208 rule,
209 binascii.hexlify(r.src_mac),
210 binascii.hexlify(r.src_mac_mask),
211 unpack('<16B', r.src_ip_addr),
212 r.src_ip_prefix_len)
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100213 """
Pavel Kotucek932f7412017-09-07 14:44:52 +0200214 return acls
215
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200216 def create_rules(
217 self, mac_type=EXACT_MAC, ip_type=EXACT_IP, acl_count=1, rules_count=None
218 ):
Pavel Kotucekc29940c2017-09-07 08:17:31 +0200219 acls = []
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700220 if rules_count is None:
221 rules_count = [1]
Pavel Kotucek932f7412017-09-07 14:44:52 +0200222 src_mac = int("220000dead00", 16)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200223 for acl in range(2, (acl_count + 1) * 2):
Pavel Kotucekc29940c2017-09-07 08:17:31 +0200224 rules = []
Pavel Kotucek932f7412017-09-07 14:44:52 +0200225 host = random.choice(self.loop0.remote_hosts)
226 is_ip6 = acl % 2
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200227 ip4 = host.ip4.split(".")
228 ip6 = list(unpack("<16B", inet_pton(AF_INET6, host.ip6)))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200229
230 if ip_type == self.EXACT_IP:
231 prefix_len4 = 32
232 prefix_len6 = 128
233 elif ip_type == self.WILD_IP:
234 ip4 = [0, 0, 0, 0]
235 ip6 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
236 prefix_len4 = 0
237 prefix_len6 = 0
snaramre2bb71512019-10-16 22:15:43 +0000238 rules_count[int((acl / 2) - 1)] = 1
Pavel Kotucek932f7412017-09-07 14:44:52 +0200239 else:
240 prefix_len4 = 24
241 prefix_len6 = 64
242
243 if mac_type == self.EXACT_MAC:
244 mask = "ff:ff:ff:ff:ff:ff"
245 elif mac_type == self.WILD_MAC:
246 mask = "00:00:00:00:00:00"
247 elif mac_type == self.OUI_MAC:
248 mask = "ff:ff:ff:00:00:00"
249 else:
250 mask = "ff:ff:ff:ff:ff:00"
251
252 ip = ip6 if is_ip6 else ip4
253 ip_len = prefix_len6 if is_ip6 else prefix_len4
254
snaramre2bb71512019-10-16 22:15:43 +0000255 for i in range(0, (rules_count[int((acl / 2) - 1)])):
Pavel Kotucek932f7412017-09-07 14:44:52 +0200256 src_mac += 16777217
257 if mac_type == self.WILD_MAC:
258 mac = "00:00:00:00:00:00"
259 elif mac_type == self.OUI_MAC:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200260 mac = (
261 ":".join(re.findall("..", "{:02x}".format(src_mac))[:3])
262 + ":00:00:00"
263 )
Pavel Kotucek932f7412017-09-07 14:44:52 +0200264 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200265 mac = ":".join(re.findall("..", "{:02x}".format(src_mac)))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200266
267 if ip_type == self.EXACT_IP:
268 ip4[3] = random.randint(100, 200)
269 ip6[15] = random.randint(100, 200)
270 elif ip_type == self.SUBNET_IP:
271 ip4[2] = random.randint(100, 200)
272 ip4[3] = 0
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100273 ip6[7] = random.randint(100, 200)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200274 ip6[15] = 0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200275 ip_pack = b""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200276 for j in range(0, len(ip)):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200277 ip_pack += pack("<B", int(ip[j]))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200278
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200279 rule = MacipRule(
280 is_permit=self.PERMIT,
281 src_prefix=ip_network((ip_pack, ip_len)),
282 src_mac=MACAddress(mac).packed,
283 src_mac_mask=MACAddress(mask).packed,
284 )
Pavel Kotucek932f7412017-09-07 14:44:52 +0200285 rules.append(rule)
286 if ip_type == self.WILD_IP:
287 break
288
Pavel Kotucekc29940c2017-09-07 08:17:31 +0200289 acls.append(rules)
290 src_mac += 1099511627776
291 return acls
292
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200293 def apply_macip_rules(self, acls):
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100294 macip_acls = []
Pavel Kotucekc29940c2017-09-07 08:17:31 +0200295 for acl in acls:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100296 macip_acl = VppMacipAcl(self, rules=acl)
297 macip_acl.add_vpp_config()
298 macip_acls.append(macip_acl)
299 return macip_acls
Pavel Kotucek932f7412017-09-07 14:44:52 +0200300
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200301 def verify_macip_acls(self, acl_count, rules_count, expected_count=2):
Pavel Kotucek932f7412017-09-07 14:44:52 +0200302 reply = self.macip_acl_dump_debug()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200303 for acl in range(2, (acl_count + 1) * 2):
304 self.assertEqual(reply[acl - 2].count, rules_count[acl // 2 - 1])
Pavel Kotucek932f7412017-09-07 14:44:52 +0200305
306 self.vapi.macip_acl_interface_get()
307
308 self.vapi.macip_acl_interface_add_del(sw_if_index=0, acl_index=0)
309 self.vapi.macip_acl_interface_add_del(sw_if_index=1, acl_index=1)
310
311 reply = self.vapi.macip_acl_interface_get()
312 self.assertEqual(reply.count, expected_count)
313
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200314 def create_stream(
315 self,
316 mac_type,
317 ip_type,
318 packet_count,
319 src_if,
320 dst_if,
321 traffic,
322 is_ip6,
323 tags=PERMIT_TAGS,
324 ):
Pavel Kotucek932f7412017-09-07 14:44:52 +0200325 # exact MAC and exact IP
326 # exact MAC and subnet of IPs
327 # exact MAC and wildcard IP
328 # wildcard MAC and exact IP
329 # wildcard MAC and subnet of IPs
330 # wildcard MAC and wildcard IP
331 # OUI restricted MAC and exact IP
332 # OUI restricted MAC and subnet of IPs
333 # OUI restricted MAC and wildcard IP
334
335 packets = []
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200336 macip_rules = []
337 acl_rules = []
Pavel Kotucek932f7412017-09-07 14:44:52 +0200338 ip_permit = ""
339 mac_permit = ""
340 dst_mac = ""
341 mac_rule = "00:00:00:00:00:00"
342 mac_mask = "00:00:00:00:00:00"
343 for p in range(0, packet_count):
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200344 remote_dst_index = p % len(dst_if.remote_hosts)
345 remote_dst_host = dst_if.remote_hosts[remote_dst_index]
Pavel Kotucek932f7412017-09-07 14:44:52 +0200346
347 dst_port = 1234 + p
348 src_port = 4321 + p
349 is_permit = self.PERMIT if p % 3 == 0 else self.DENY
350 denyMAC = True if not is_permit and p % 3 == 1 else False
351 denyIP = True if not is_permit and p % 3 == 2 else False
352 if not is_permit and ip_type == self.WILD_IP:
353 denyMAC = True
354 if not is_permit and mac_type == self.WILD_MAC:
355 denyIP = True
Pavel Kotucek057704e2017-09-14 09:50:52 +0200356
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200357 if traffic == self.BRIDGED:
Pavel Kotucek932f7412017-09-07 14:44:52 +0200358 if is_permit:
359 src_mac = remote_dst_host._mac
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200360 dst_mac = "de:ad:00:00:00:00"
Pavel Kotucek932f7412017-09-07 14:44:52 +0200361 src_ip4 = remote_dst_host.ip4
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200362 dst_ip4 = src_if.remote_ip4
Pavel Kotucek057704e2017-09-14 09:50:52 +0200363 src_ip6 = remote_dst_host.ip6
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200364 dst_ip6 = src_if.remote_ip6
Pavel Kotucek932f7412017-09-07 14:44:52 +0200365 ip_permit = src_ip6 if is_ip6 else src_ip4
366 mac_permit = src_mac
Pavel Kotucek932f7412017-09-07 14:44:52 +0200367 if denyMAC:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200368 mac = src_mac.split(":")
369 mac[0] = format(int(mac[0], 16) + 1, "02x")
Pavel Kotucek932f7412017-09-07 14:44:52 +0200370 src_mac = ":".join(mac)
371 if is_ip6:
372 src_ip6 = ip_permit
373 else:
374 src_ip4 = ip_permit
375 if denyIP:
376 if ip_type != self.WILD_IP:
377 src_mac = mac_permit
Pavel Kotucek932f7412017-09-07 14:44:52 +0200378 src_ip4 = remote_dst_host.ip4
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200379 dst_ip4 = src_if.remote_ip4
Pavel Kotucek057704e2017-09-14 09:50:52 +0200380 src_ip6 = remote_dst_host.ip6
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200381 dst_ip6 = src_if.remote_ip6
Pavel Kotucek057704e2017-09-14 09:50:52 +0200382 else:
383 if is_permit:
384 src_mac = remote_dst_host._mac
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200385 dst_mac = src_if.local_mac
386 src_ip4 = src_if.remote_ip4
Pavel Kotucek057704e2017-09-14 09:50:52 +0200387 dst_ip4 = remote_dst_host.ip4
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200388 src_ip6 = src_if.remote_ip6
Pavel Kotucek057704e2017-09-14 09:50:52 +0200389 dst_ip6 = remote_dst_host.ip6
390 ip_permit = src_ip6 if is_ip6 else src_ip4
391 mac_permit = src_mac
392 if denyMAC:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200393 mac = src_mac.split(":")
Pavel Kotucek057704e2017-09-14 09:50:52 +0200394 mac[0] = format(int(mac[0], 16) + 1, "02x")
395 src_mac = ":".join(mac)
396 if is_ip6:
397 src_ip6 = ip_permit
398 else:
399 src_ip4 = ip_permit
400 if denyIP:
401 src_mac = remote_dst_host._mac
402 if ip_type != self.WILD_IP:
403 src_mac = mac_permit
404 src_ip4 = remote_dst_host.ip4
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200405 dst_ip4 = src_if.remote_ip4
Pavel Kotucek057704e2017-09-14 09:50:52 +0200406 src_ip6 = remote_dst_host.ip6
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200407 dst_ip6 = src_if.remote_ip6
Pavel Kotucek932f7412017-09-07 14:44:52 +0200408
409 if is_permit:
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200410 info = self.create_packet_info(src_if, dst_if)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200411 payload = self.info_to_payload(info)
412 else:
413 payload = "to be blocked"
414
415 if mac_type == self.WILD_MAC:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200416 mac = src_mac.split(":")
Pavel Kotucek932f7412017-09-07 14:44:52 +0200417 for i in range(1, 5):
418 mac[i] = format(random.randint(0, 255), "02x")
419 src_mac = ":".join(mac)
420
421 # create packet
422 packet = Ether(src=src_mac, dst=dst_mac)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200423 ip_rule = src_ip6 if is_ip6 else src_ip4
Pavel Kotucek932f7412017-09-07 14:44:52 +0200424 if is_ip6:
425 if ip_type != self.EXACT_IP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200426 sub_ip = list(unpack("<16B", inet_pton(AF_INET6, ip_rule)))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200427 if ip_type == self.WILD_IP:
428 sub_ip[0] = random.randint(240, 254)
429 sub_ip[1] = random.randint(230, 239)
430 sub_ip[14] = random.randint(100, 199)
431 sub_ip[15] = random.randint(200, 255)
432 elif ip_type == self.SUBNET_IP:
433 if denyIP:
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700434 sub_ip[2] = int(sub_ip[2]) + 1
Pavel Kotucek932f7412017-09-07 14:44:52 +0200435 sub_ip[14] = random.randint(100, 199)
436 sub_ip[15] = random.randint(200, 255)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200437 packed_src_ip6 = b"".join([scapy.compat.chb(x) for x in sub_ip])
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700438 src_ip6 = inet_ntop(AF_INET6, packed_src_ip6)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200439 packet /= IPv6(src=src_ip6, dst=dst_ip6)
440 else:
441 if ip_type != self.EXACT_IP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200442 sub_ip = ip_rule.split(".")
Pavel Kotucek932f7412017-09-07 14:44:52 +0200443 if ip_type == self.WILD_IP:
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700444 sub_ip[0] = random.randint(1, 49)
445 sub_ip[1] = random.randint(50, 99)
446 sub_ip[2] = random.randint(100, 199)
447 sub_ip[3] = random.randint(200, 255)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200448 elif ip_type == self.SUBNET_IP:
449 if denyIP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200450 sub_ip[1] = int(sub_ip[1]) + 1
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700451 sub_ip[2] = random.randint(100, 199)
452 sub_ip[3] = random.randint(200, 255)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200453 src_ip4 = ".".join(["{!s}".format(x) for x in sub_ip])
Pavel Kotucek932f7412017-09-07 14:44:52 +0200454 packet /= IP(src=src_ip4, dst=dst_ip4, frag=0, flags=0)
455
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200456 packet /= UDP(sport=src_port, dport=dst_port) / Raw(payload)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200457
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200458 packet[Raw].load += b" mac:%s" % src_mac.encode("utf-8")
Pavel Kotucek932f7412017-09-07 14:44:52 +0200459
460 size = self.pg_if_packet_sizes[p % len(self.pg_if_packet_sizes)]
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200461 if isinstance(src_if, VppSubInterface):
462 size = size + 4
463 if isinstance(src_if, VppDot1QSubint):
464 if src_if is self.subifs[0]:
465 if tags == self.PERMIT_TAGS:
466 packet = src_if.add_dot1q_layer(packet, 10)
467 else:
468 packet = src_if.add_dot1q_layer(packet, 11)
469 else:
470 if tags == self.PERMIT_TAGS:
471 packet = src_if.add_dot1q_layer(packet, 30)
472 else:
473 packet = src_if.add_dot1q_layer(packet, 33)
474 elif isinstance(src_if, VppDot1ADSubint):
475 if src_if is self.subifs[1]:
476 if tags == self.PERMIT_TAGS:
477 packet = src_if.add_dot1ad_layer(packet, 300, 400)
478 else:
479 packet = src_if.add_dot1ad_layer(packet, 333, 444)
480 else:
481 if tags == self.PERMIT_TAGS:
482 packet = src_if.add_dot1ad_layer(packet, 600, 700)
483 else:
484 packet = src_if.add_dot1ad_layer(packet, 666, 777)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200485 self.extend_packet(packet, size)
486 packets.append(packet)
487
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200488 # create suitable MACIP rule
Pavel Kotucek932f7412017-09-07 14:44:52 +0200489 if mac_type == self.EXACT_MAC:
490 mac_rule = src_mac
491 mac_mask = "ff:ff:ff:ff:ff:ff"
492 elif mac_type == self.WILD_MAC:
493 mac_rule = "00:00:00:00:00:00"
494 mac_mask = "00:00:00:00:00:00"
495 elif mac_type == self.OUI_MAC:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200496 mac = src_mac.split(":")
497 mac[3] = mac[4] = mac[5] = "00"
Pavel Kotucek932f7412017-09-07 14:44:52 +0200498 mac_rule = ":".join(mac)
499 mac_mask = "ff:ff:ff:00:00:00"
500
501 if is_ip6:
502 if ip_type == self.WILD_IP:
503 ip = "0::0"
504 else:
Pavel Kotucek057704e2017-09-14 09:50:52 +0200505 ip = src_ip6
Pavel Kotucek932f7412017-09-07 14:44:52 +0200506 if ip_type == self.SUBNET_IP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200507 sub_ip = list(unpack("<16B", inet_pton(AF_INET6, ip)))
Pavel Kotucek932f7412017-09-07 14:44:52 +0200508 for i in range(8, 16):
509 sub_ip[i] = 0
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200510 packed_ip = b"".join([scapy.compat.chb(x) for x in sub_ip])
Paul Vinciguerraa7427ec2019-03-10 10:04:23 -0700511 ip = inet_ntop(AF_INET6, packed_ip)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200512 else:
513 if ip_type == self.WILD_IP:
514 ip = "0.0.0.0"
515 else:
Pavel Kotucek057704e2017-09-14 09:50:52 +0200516 ip = src_ip4
Pavel Kotucek932f7412017-09-07 14:44:52 +0200517 if ip_type == self.SUBNET_IP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200518 sub_ip = ip.split(".")
519 sub_ip[2] = sub_ip[3] = "0"
Pavel Kotucek932f7412017-09-07 14:44:52 +0200520 ip = ".".join(sub_ip)
521
522 prefix_len = 128 if is_ip6 else 32
523 if ip_type == self.WILD_IP:
524 prefix_len = 0
525 elif ip_type == self.SUBNET_IP:
526 prefix_len = 64 if is_ip6 else 16
527 ip_rule = inet_pton(AF_INET6 if is_ip6 else AF_INET, ip)
528
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200529 # create suitable ACL rule
530 if is_permit:
531 rule_l4_sport = packet[UDP].sport
532 rule_l4_dport = packet[UDP].dport
533 rule_family = AF_INET6 if packet.haslayer(IPv6) else AF_INET
534 rule_prefix_len = 128 if packet.haslayer(IPv6) else 32
535 rule_l3_layer = IPv6 if packet.haslayer(IPv6) else IP
536 if packet.haslayer(IPv6):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200537 rule_l4_proto = packet[UDP].overload_fields[IPv6]["nh"]
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200538 else:
539 rule_l4_proto = packet[IP].proto
540
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200541 src_network = ip_network((packet[rule_l3_layer].src, rule_prefix_len))
542 dst_network = ip_network((packet[rule_l3_layer].dst, rule_prefix_len))
543 acl_rule = AclRule(
544 is_permit=is_permit,
545 proto=rule_l4_proto,
546 src_prefix=src_network,
547 dst_prefix=dst_network,
548 sport_from=rule_l4_sport,
549 sport_to=rule_l4_sport,
550 dport_from=rule_l4_dport,
551 dport_to=rule_l4_dport,
552 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200553 acl_rules.append(acl_rule)
554
Pavel Kotucek932f7412017-09-07 14:44:52 +0200555 if mac_type == self.WILD_MAC and ip_type == self.WILD_IP and p > 0:
556 continue
557
558 if is_permit:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100559 macip_rule = MacipRule(
560 is_permit=is_permit,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200561 src_prefix=ip_network((ip_rule, prefix_len)),
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100562 src_mac=MACAddress(mac_rule).packed,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200563 src_mac_mask=MACAddress(mac_mask).packed,
564 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200565 macip_rules.append(macip_rule)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200566
567 # deny all other packets
568 if not (mac_type == self.WILD_MAC and ip_type == self.WILD_IP):
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100569 network = IPv6Network((0, 0)) if is_ip6 else IPv4Network((0, 0))
570 macip_rule = MacipRule(
571 is_permit=0,
572 src_prefix=network,
573 src_mac=MACAddress("00:00:00:00:00:00").packed,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200574 src_mac_mask=MACAddress("00:00:00:00:00:00").packed,
575 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200576 macip_rules.append(macip_rule)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200577
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100578 network = IPv6Network((0, 0)) if is_ip6 else IPv4Network((0, 0))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200579 acl_rule = AclRule(
580 is_permit=0,
581 src_prefix=network,
582 dst_prefix=network,
583 sport_from=0,
584 sport_to=0,
585 dport_from=0,
586 dport_to=0,
587 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200588 acl_rules.append(acl_rule)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200589 return {"stream": packets, "macip_rules": macip_rules, "acl_rules": acl_rules}
Pavel Kotucek932f7412017-09-07 14:44:52 +0200590
591 def verify_capture(self, stream, capture, is_ip6):
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200592 """
593 :param stream:
594 :param capture:
595 :param is_ip6:
596 :return:
597 """
598 # p_l3 = IPv6 if is_ip6 else IP
599 # if self.DEBUG:
600 # for p in stream:
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800601 # print(p[Ether].src, p[Ether].dst, p[p_l3].src, p[p_l3].dst)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200602 #
603 # acls = self.macip_acl_dump_debug()
Pavel Kotucek932f7412017-09-07 14:44:52 +0200604
605 # TODO : verify
606 # for acl in acls:
607 # for r in acl.r:
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800608 # print(binascii.hexlify(r.src_mac), \
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -0800609 # binascii.hexlify(r.src_mac_mask),\
Pavel Kotucek932f7412017-09-07 14:44:52 +0200610 # unpack('<16B', r.src_ip_addr), \
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800611 # r.src_ip_prefix_len)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200612 #
613 # for p in capture:
Paul Vinciguerra661f91f2018-11-28 19:06:41 -0800614 # print(p[Ether].src, p[Ether].dst, p[p_l3].src, p[p_l3].dst
615 # data = p[Raw].load.split(':',1)[1])
616 # print(p[p_l3].src, data)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200617
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200618 def run_traffic(
619 self,
620 mac_type,
621 ip_type,
622 traffic,
623 is_ip6,
624 packets,
625 do_not_expected_capture=False,
626 tags=None,
627 apply_rules=True,
628 isMACIP=True,
629 permit_tags=PERMIT_TAGS,
630 try_replace=False,
631 ):
Pavel Kotucek932f7412017-09-07 14:44:52 +0200632 self.reset_packet_infos()
633
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200634 if tags is None:
635 tx_if = self.pg0 if traffic == self.BRIDGED else self.pg3
636 rx_if = self.pg3 if traffic == self.BRIDGED else self.pg0
637 src_if = self.pg3
638 dst_if = self.loop0
639 else:
640 if tags == self.DOT1Q:
641 if traffic == self.BRIDGED:
642 tx_if = self.subifs[0]
643 rx_if = self.pg0
644 src_if = self.subifs[0]
645 dst_if = self.loop0
646 else:
647 tx_if = self.subifs[2]
648 rx_if = self.pg0
649 src_if = self.subifs[2]
650 dst_if = self.loop0
651 elif tags == self.DOT1AD:
652 if traffic == self.BRIDGED:
653 tx_if = self.subifs[1]
654 rx_if = self.pg0
655 src_if = self.subifs[1]
656 dst_if = self.loop0
657 else:
658 tx_if = self.subifs[3]
659 rx_if = self.pg0
660 src_if = self.subifs[3]
661 dst_if = self.loop0
662 else:
663 return
Pavel Kotucek932f7412017-09-07 14:44:52 +0200664
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200665 test_dict = self.create_stream(
666 mac_type,
667 ip_type,
668 packets,
669 src_if,
670 dst_if,
671 traffic,
672 is_ip6,
673 tags=permit_tags,
674 )
Pavel Kotucek932f7412017-09-07 14:44:52 +0200675
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200676 if apply_rules:
677 if isMACIP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200678 self.acl = VppMacipAcl(self, rules=test_dict["macip_rules"])
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200679 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200680 self.acl = VppAcl(self, rules=test_dict["acl_rules"])
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100681 self.acl.add_vpp_config()
Pavel Kotucek932f7412017-09-07 14:44:52 +0200682
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200683 if isMACIP:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100684 self.acl_if = VppMacipAclInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200685 self, sw_if_index=tx_if.sw_if_index, acls=[self.acl]
686 )
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100687 self.acl_if.add_vpp_config()
688
689 dump = self.acl_if.dump()
690 self.assertTrue(dump)
691 self.assertEqual(dump[0].acls[0], self.acl.acl_index)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200692 else:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100693 self.acl_if = VppAclInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200694 self, sw_if_index=tx_if.sw_if_index, n_input=1, acls=[self.acl]
695 )
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100696 self.acl_if.add_vpp_config()
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200697 else:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100698 if hasattr(self, "acl_if"):
699 self.acl_if.remove_vpp_config()
700 if try_replace and hasattr(self, "acl"):
Andrew Yourtchenkod7834912017-12-09 14:55:52 +0100701 if isMACIP:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200702 self.acl.modify_vpp_config(test_dict["macip_rules"])
Andrew Yourtchenkod7834912017-12-09 14:55:52 +0100703 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200704 self.acl.modify_vpp_config(test_dict["acl_rules"])
Pavel Kotucek932f7412017-09-07 14:44:52 +0200705
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200706 if not isinstance(src_if, VppSubInterface):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200707 tx_if.add_stream(test_dict["stream"])
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200708 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200709 tx_if.parent.add_stream(test_dict["stream"])
Pavel Kotucek932f7412017-09-07 14:44:52 +0200710 self.pg_enable_capture(self.pg_interfaces)
711 self.pg_start()
712
Pavel Kotucekc29940c2017-09-07 08:17:31 +0200713 if do_not_expected_capture:
714 rx_if.get_capture(0)
715 else:
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200716 if (
717 traffic == self.BRIDGED
718 and mac_type == self.WILD_MAC
719 and ip_type == self.WILD_IP
720 ):
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200721 capture = rx_if.get_capture(packets)
722 else:
723 capture = rx_if.get_capture(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200724 self.get_packet_count_for_if_idx(dst_if.sw_if_index)
725 )
726 self.verify_capture(test_dict["stream"], capture, is_ip6)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200727 if not isMACIP:
Jakub Grajciar2f8cd912020-03-27 06:55:06 +0100728 if hasattr(self, "acl_if"):
729 self.acl_if.remove_vpp_config()
730 if hasattr(self, "acl"):
731 self.acl.remove_vpp_config()
Pavel Kotucek932f7412017-09-07 14:44:52 +0200732
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200733 def run_test_acls(
734 self, mac_type, ip_type, acl_count, rules_count, traffic=None, ip=None
735 ):
736 self.apply_macip_rules(
737 self.create_rules(mac_type, ip_type, acl_count, rules_count)
738 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200739 self.verify_macip_acls(acl_count, rules_count)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200740
741 if traffic is not None:
742 self.run_traffic(self.EXACT_MAC, self.EXACT_IP, traffic, ip, 9)
743
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200744
745class TestMACIP_IP4(MethodHolder):
746 """MACIP with IP4 traffic"""
747
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700748 @classmethod
749 def setUpClass(cls):
750 super(TestMACIP_IP4, cls).setUpClass()
751
752 @classmethod
753 def tearDownClass(cls):
754 super(TestMACIP_IP4, cls).tearDownClass()
755
Pavel Kotucek057704e2017-09-14 09:50:52 +0200756 def test_acl_bridged_ip4_exactMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200757 """IP4 MACIP exactMAC|exactIP ACL bridged traffic"""
758 self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200759
Pavel Kotucek057704e2017-09-14 09:50:52 +0200760 def test_acl_bridged_ip4_exactMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200761 """IP4 MACIP exactMAC|subnetIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200762
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200763 self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200764
Pavel Kotucek057704e2017-09-14 09:50:52 +0200765 def test_acl_bridged_ip4_exactMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200766 """IP4 MACIP exactMAC|wildIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200767
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200768 self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200769
Pavel Kotucek057704e2017-09-14 09:50:52 +0200770 def test_acl_bridged_ip4_ouiMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200771 """IP4 MACIP ouiMAC|exactIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200772
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200773 self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP4, 3)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200774
Pavel Kotucek057704e2017-09-14 09:50:52 +0200775 def test_acl_bridged_ip4_ouiMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200776 """IP4 MACIP ouiMAC|subnetIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200777
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200778 self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200779
Pavel Kotucek057704e2017-09-14 09:50:52 +0200780 def test_acl_bridged_ip4_ouiMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200781 """IP4 MACIP ouiMAC|wildIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200782
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200783 self.run_traffic(self.OUI_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200784
Pavel Kotucek057704e2017-09-14 09:50:52 +0200785 def test_ac_bridgedl_ip4_wildMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200786 """IP4 MACIP wildcardMAC|exactIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200787
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200788 self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200789
Pavel Kotucek057704e2017-09-14 09:50:52 +0200790 def test_acl_bridged_ip4_wildMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200791 """IP4 MACIP wildcardMAC|subnetIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200792
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200793 self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200794
Pavel Kotucek057704e2017-09-14 09:50:52 +0200795 def test_acl_bridged_ip4_wildMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200796 """IP4 MACIP wildcardMAC|wildIP ACL bridged traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200797
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200798 self.run_traffic(self.WILD_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP4, 9)
Pavel Kotucek932f7412017-09-07 14:44:52 +0200799
Pavel Kotucek057704e2017-09-14 09:50:52 +0200800 def test_acl_routed_ip4_exactMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200801 """IP4 MACIP exactMAC|exactIP ACL routed traffic"""
802 self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200803
Pavel Kotucek057704e2017-09-14 09:50:52 +0200804 def test_acl_routed_ip4_exactMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200805 """IP4 MACIP exactMAC|subnetIP ACL routed traffic"""
806 self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200807
Pavel Kotucek057704e2017-09-14 09:50:52 +0200808 def test_acl_routed_ip4_exactMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200809 """IP4 MACIP exactMAC|wildIP ACL routed traffic"""
810 self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200811
Pavel Kotucek057704e2017-09-14 09:50:52 +0200812 def test_acl_routed_ip4_ouiMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200813 """IP4 MACIP ouiMAC|exactIP ACL routed traffic"""
Pavel Kotucek057704e2017-09-14 09:50:52 +0200814
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200815 self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200816
Pavel Kotucek057704e2017-09-14 09:50:52 +0200817 def test_acl_routed_ip4_ouiMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200818 """IP4 MACIP ouiMAC|subnetIP ACL routed traffic"""
Pavel Kotucek057704e2017-09-14 09:50:52 +0200819
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200820 self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200821
Pavel Kotucek057704e2017-09-14 09:50:52 +0200822 def test_acl_routed_ip4_ouiMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200823 """IP4 MACIP ouiMAC|wildIP ACL routed traffic"""
Pavel Kotucek057704e2017-09-14 09:50:52 +0200824
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200825 self.run_traffic(self.OUI_MAC, self.WILD_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200826
Pavel Kotucek057704e2017-09-14 09:50:52 +0200827 def test_acl_routed_ip4_wildMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200828 """IP4 MACIP wildcardMAC|exactIP ACL routed traffic"""
Pavel Kotucek057704e2017-09-14 09:50:52 +0200829
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200830 self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200831
Pavel Kotucek057704e2017-09-14 09:50:52 +0200832 def test_acl_routed_ip4_wildMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200833 """IP4 MACIP wildcardMAC|subnetIP ACL routed traffic"""
Pavel Kotucek057704e2017-09-14 09:50:52 +0200834
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200835 self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200836
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200837 def test_acl_routed_ip4_wildMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200838 """IP4 MACIP wildcardMAC|wildIP ACL"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200839
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200840 self.run_traffic(self.WILD_MAC, self.WILD_IP, self.ROUTED, self.IS_IP4, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200841
842 def test_acl_replace_traffic_ip4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200843 """MACIP replace ACL with IP4 traffic"""
844 self.run_traffic(
845 self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP4, 9, try_replace=True
846 )
847 self.run_traffic(
848 self.EXACT_MAC,
849 self.EXACT_IP,
850 self.BRIDGED,
851 self.IS_IP4,
852 9,
853 try_replace=True,
854 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200855
856
857class TestMACIP_IP6(MethodHolder):
858 """MACIP with IP6 traffic"""
859
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700860 @classmethod
861 def setUpClass(cls):
862 super(TestMACIP_IP6, cls).setUpClass()
863
864 @classmethod
865 def tearDownClass(cls):
866 super(TestMACIP_IP6, cls).tearDownClass()
867
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200868 def test_acl_bridged_ip6_exactMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200869 """IP6 MACIP exactMAC|exactIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200870
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200871 self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200872
873 def test_acl_bridged_ip6_exactMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200874 """IP6 MACIP exactMAC|subnetIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200875
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200876 self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200877
878 def test_acl_bridged_ip6_exactMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200879 """IP6 MACIP exactMAC|wildIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200880
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200881 self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200882
883 def test_acl_bridged_ip6_ouiMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200884 """IP6 MACIP oui_MAC|exactIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200885
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200886 self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200887
888 def test_acl_bridged_ip6_ouiMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200889 """IP6 MACIP ouiMAC|subnetIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200890
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200891 self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200892
893 def test_acl_bridged_ip6_ouiMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200894 """IP6 MACIP ouiMAC|wildIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200895
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200896 self.run_traffic(self.OUI_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200897
898 def test_acl_bridged_ip6_wildMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200899 """IP6 MACIP wildcardMAC|exactIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200900
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200901 self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200902
903 def test_acl_bridged_ip6_wildMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200904 """IP6 MACIP wildcardMAC|subnetIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200905
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200906 self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200907
908 def test_acl_bridged_ip6_wildMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200909 """IP6 MACIP wildcardMAC|wildIP ACL bridged traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200910
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200911 self.run_traffic(self.WILD_MAC, self.WILD_IP, self.BRIDGED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200912
913 def test_acl_routed_ip6_exactMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200914 """IP6 MACIP exactMAC|exactIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200915
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200916 self.run_traffic(self.EXACT_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200917
918 def test_acl_routed_ip6_exactMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200919 """IP6 MACIP exactMAC|subnetIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200920
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200921 self.run_traffic(self.EXACT_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200922
923 def test_acl_routed_ip6_exactMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200924 """IP6 MACIP exactMAC|wildIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200925
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200926 self.run_traffic(self.EXACT_MAC, self.WILD_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200927
928 def test_acl_routed_ip6_ouiMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200929 """IP6 MACIP ouiMAC|exactIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200930
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200931 self.run_traffic(self.OUI_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200932
933 def test_acl_routed_ip6_ouiMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200934 """IP6 MACIP ouiMAC|subnetIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200935
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200936 self.run_traffic(self.OUI_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200937
938 def test_acl_routed_ip6_ouiMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200939 """IP6 MACIP ouiMAC|wildIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200940
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200941 self.run_traffic(self.OUI_MAC, self.WILD_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200942
943 def test_acl_routed_ip6_wildMAC_exactIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200944 """IP6 MACIP wildcardMAC|exactIP ACL routed traffic"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200945
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200946 self.run_traffic(self.WILD_MAC, self.EXACT_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200947
Pavel Kotucek057704e2017-09-14 09:50:52 +0200948 def test_acl_routed_ip6_wildMAC_subnetIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200949 """IP6 MACIP wildcardMAC|subnetIP ACL routed traffic"""
Pavel Kotucek057704e2017-09-14 09:50:52 +0200950
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200951 self.run_traffic(self.WILD_MAC, self.SUBNET_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek057704e2017-09-14 09:50:52 +0200952
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200953 def test_acl_routed_ip6_wildMAC_wildIP(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200954 """IP6 MACIP wildcardMAC|wildIP ACL"""
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200955
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200956 self.run_traffic(self.WILD_MAC, self.WILD_IP, self.ROUTED, self.IS_IP6, 9)
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200957
958 def test_acl_replace_traffic_ip6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200959 """MACIP replace ACL with IP6 traffic"""
960 self.run_traffic(
961 self.OUI_MAC, self.SUBNET_IP, self.BRIDGED, self.IS_IP6, 9, try_replace=True
962 )
963 self.run_traffic(
964 self.EXACT_MAC,
965 self.EXACT_IP,
966 self.BRIDGED,
967 self.IS_IP6,
968 9,
969 try_replace=True,
970 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +0200971
972
973class TestMACIP(MethodHolder):
974 """MACIP Tests"""
975
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700976 @classmethod
977 def setUpClass(cls):
978 super(TestMACIP, cls).setUpClass()
979
980 @classmethod
981 def tearDownClass(cls):
982 super(TestMACIP, cls).tearDownClass()
983
Pavel Kotucek932f7412017-09-07 14:44:52 +0200984 def test_acl_1_2(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200985 """MACIP ACL with 2 entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200986
987 self.run_test_acls(self.EXACT_MAC, self.WILD_IP, 1, [2])
988
989 def test_acl_1_5(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200990 """MACIP ACL with 5 entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200991
992 self.run_test_acls(self.EXACT_MAC, self.SUBNET_IP, 1, [5])
993
994 def test_acl_1_10(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200995 """MACIP ACL with 10 entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +0200996
997 self.run_test_acls(self.EXACT_MAC, self.EXACT_IP, 1, [10])
998
999 def test_acl_1_20(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001000 """MACIP ACL with 20 entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001001
1002 self.run_test_acls(self.OUI_MAC, self.WILD_IP, 1, [20])
1003
1004 def test_acl_1_50(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001005 """MACIP ACL with 50 entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001006
1007 self.run_test_acls(self.OUI_MAC, self.SUBNET_IP, 1, [50])
1008
1009 def test_acl_1_100(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001010 """MACIP ACL with 100 entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001011
1012 self.run_test_acls(self.OUI_MAC, self.EXACT_IP, 1, [100])
1013
1014 def test_acl_2_X(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001015 """MACIP 2 ACLs each with 100+ entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001016
1017 self.run_test_acls(self.OUI_MAC, self.SUBNET_IP, 2, [100, 200])
1018
1019 def test_acl_10_X(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001020 """MACIP 10 ACLs each with 100+ entries"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001021
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001022 self.run_test_acls(
1023 self.EXACT_MAC,
1024 self.EXACT_IP,
1025 10,
1026 [100, 120, 140, 160, 180, 200, 210, 220, 230, 240],
1027 )
Pavel Kotucek932f7412017-09-07 14:44:52 +02001028
1029 def test_acl_10_X_traffic_ip4(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001030 """MACIP 10 ACLs each with 100+ entries with IP4 traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001031
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001032 self.run_test_acls(
1033 self.EXACT_MAC,
1034 self.EXACT_IP,
1035 10,
1036 [100, 120, 140, 160, 180, 200, 210, 220, 230, 240],
1037 self.BRIDGED,
1038 self.IS_IP4,
1039 )
Pavel Kotucek932f7412017-09-07 14:44:52 +02001040
1041 def test_acl_10_X_traffic_ip6(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001042 """MACIP 10 ACLs each with 100+ entries with IP6 traffic"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001043
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001044 self.run_test_acls(
1045 self.EXACT_MAC,
1046 self.EXACT_IP,
1047 10,
1048 [100, 120, 140, 160, 180, 200, 210, 220, 230, 240],
1049 self.BRIDGED,
1050 self.IS_IP6,
1051 )
Pavel Kotucek932f7412017-09-07 14:44:52 +02001052
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001053 def test_acl_replace(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001054 """MACIP replace ACL"""
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001055
1056 r1 = self.create_rules(acl_count=3, rules_count=[2, 2, 2])
1057 r2 = self.create_rules(mac_type=self.OUI_MAC, ip_type=self.SUBNET_IP)
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001058 macip_acls = self.apply_macip_rules(r1)
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001059
1060 acls_before = self.macip_acl_dump_debug()
1061
1062 # replace acls #2, #3 with new
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001063 macip_acls[2].modify_vpp_config(r2[0])
1064 macip_acls[3].modify_vpp_config(r2[1])
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001065
1066 acls_after = self.macip_acl_dump_debug()
1067
1068 # verify changes
1069 self.assertEqual(len(acls_before), len(acls_after))
1070 for acl1, acl2 in zip(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001071 acls_before[:2] + acls_before[4:], acls_after[:2] + acls_after[4:]
1072 ):
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001073 self.assertEqual(len(acl1), len(acl2))
1074
1075 self.assertEqual(len(acl1.r), len(acl2.r))
1076 for r1, r2 in zip(acl1.r, acl2.r):
1077 self.assertEqual(len(acl1.r), len(acl2.r))
1078 self.assertEqual(acl1.r, acl2.r)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001079 for acl1, acl2 in zip(acls_before[2:4], acls_after[2:4]):
Pavel Kotucekc29940c2017-09-07 08:17:31 +02001080 self.assertEqual(len(acl1), len(acl2))
1081
1082 self.assertNotEqual(len(acl1.r), len(acl2.r))
1083 for r1, r2 in zip(acl1.r, acl2.r):
1084 self.assertNotEqual(len(acl1.r), len(acl2.r))
1085 self.assertNotEqual(acl1.r, acl2.r)
1086
Pavel Kotucek932f7412017-09-07 14:44:52 +02001087 def test_delete_intf(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001088 """MACIP ACL delete intf with acl"""
Pavel Kotucek932f7412017-09-07 14:44:52 +02001089
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001090 intf_count = len(self.interfaces) + 1
Pavel Kotucek932f7412017-09-07 14:44:52 +02001091 intf = []
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001092 macip_alcs = self.apply_macip_rules(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001093 self.create_rules(acl_count=3, rules_count=[3, 5, 4])
1094 )
Pavel Kotucek932f7412017-09-07 14:44:52 +02001095
Klement Sekerabeaded52018-06-24 10:30:37 +02001096 intf.append(VppLoInterface(self))
1097 intf.append(VppLoInterface(self))
Pavel Kotucek932f7412017-09-07 14:44:52 +02001098
1099 sw_if_index0 = intf[0].sw_if_index
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001100 macip_acl_if0 = VppMacipAclInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001101 self, sw_if_index=sw_if_index0, acls=[macip_alcs[1]]
1102 )
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001103 macip_acl_if0.add_vpp_config()
Pavel Kotucek932f7412017-09-07 14:44:52 +02001104
1105 reply = self.vapi.macip_acl_interface_get()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001106 self.assertEqual(reply.count, intf_count + 1)
Pavel Kotucek932f7412017-09-07 14:44:52 +02001107 self.assertEqual(reply.acls[sw_if_index0], 1)
1108
1109 sw_if_index1 = intf[1].sw_if_index
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001110 macip_acl_if1 = VppMacipAclInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001111 self, sw_if_index=sw_if_index1, acls=[macip_alcs[0]]
1112 )
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001113 macip_acl_if1.add_vpp_config()
Pavel Kotucek932f7412017-09-07 14:44:52 +02001114
1115 reply = self.vapi.macip_acl_interface_get()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001116 self.assertEqual(reply.count, intf_count + 2)
Pavel Kotucek932f7412017-09-07 14:44:52 +02001117 self.assertEqual(reply.acls[sw_if_index1], 0)
1118
1119 intf[0].remove_vpp_config()
1120 reply = self.vapi.macip_acl_interface_get()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001121 self.assertEqual(reply.count, intf_count + 2)
Pavel Kotucek932f7412017-09-07 14:44:52 +02001122 self.assertEqual(reply.acls[sw_if_index0], 4294967295)
1123 self.assertEqual(reply.acls[sw_if_index1], 0)
1124
Klement Sekerabeaded52018-06-24 10:30:37 +02001125 intf.append(VppLoInterface(self))
1126 intf.append(VppLoInterface(self))
Pavel Kotucek932f7412017-09-07 14:44:52 +02001127 sw_if_index2 = intf[2].sw_if_index
1128 sw_if_index3 = intf[3].sw_if_index
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001129 macip_acl_if2 = VppMacipAclInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001130 self, sw_if_index=sw_if_index2, acls=[macip_alcs[1]]
1131 )
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001132 macip_acl_if2.add_vpp_config()
1133 macip_acl_if3 = VppMacipAclInterface(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001134 self, sw_if_index=sw_if_index3, acls=[macip_alcs[1]]
1135 )
Jakub Grajciar2f8cd912020-03-27 06:55:06 +01001136 macip_acl_if3.add_vpp_config()
Pavel Kotucek932f7412017-09-07 14:44:52 +02001137
1138 reply = self.vapi.macip_acl_interface_get()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001139 self.assertEqual(reply.count, intf_count + 3)
Pavel Kotucek932f7412017-09-07 14:44:52 +02001140 self.assertEqual(reply.acls[sw_if_index1], 0)
1141 self.assertEqual(reply.acls[sw_if_index2], 1)
1142 self.assertEqual(reply.acls[sw_if_index3], 1)
Andrew Yourtchenko563a8532018-03-23 15:23:15 +01001143 self.logger.info("MACIP ACL on multiple interfaces:")
1144 self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl"))
1145 self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl index 1234"))
1146 self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl index 1"))
1147 self.logger.info(self.vapi.ppcli("sh acl-plugin macip acl index 0"))
1148 self.logger.info(self.vapi.ppcli("sh acl-plugin macip interface"))
Pavel Kotucek932f7412017-09-07 14:44:52 +02001149
1150 intf[2].remove_vpp_config()
1151 intf[1].remove_vpp_config()
1152
1153 reply = self.vapi.macip_acl_interface_get()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001154 self.assertEqual(reply.count, intf_count + 3)
Pavel Kotucek932f7412017-09-07 14:44:52 +02001155 self.assertEqual(reply.acls[sw_if_index0], 4294967295)
1156 self.assertEqual(reply.acls[sw_if_index1], 4294967295)
1157 self.assertEqual(reply.acls[sw_if_index2], 4294967295)
1158 self.assertEqual(reply.acls[sw_if_index3], 1)
1159
1160 intf[3].remove_vpp_config()
1161 reply = self.vapi.macip_acl_interface_get()
1162
1163 self.assertEqual(len([x for x in reply.acls if x != 4294967295]), 0)
1164
Pavel Kotucek057704e2017-09-14 09:50:52 +02001165
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001166class TestACL_dot1q_bridged(MethodHolder):
1167 """ACL on dot1q bridged subinterfaces Tests"""
Pavel Kotucek057704e2017-09-14 09:50:52 +02001168
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001169 @classmethod
1170 def setUpClass(cls):
1171 super(TestACL_dot1q_bridged, cls).setUpClass()
1172
1173 @classmethod
1174 def tearDownClass(cls):
1175 super(TestACL_dot1q_bridged, cls).tearDownClass()
1176
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001177 def test_acl_bridged_ip4_subif_dot1q(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001178 """IP4 ACL SubIf Dot1Q bridged traffic"""
1179 self.run_traffic(
1180 self.EXACT_MAC,
1181 self.EXACT_IP,
1182 self.BRIDGED,
1183 self.IS_IP4,
1184 9,
1185 tags=self.DOT1Q,
1186 isMACIP=False,
1187 )
Pavel Kotucek057704e2017-09-14 09:50:52 +02001188
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001189 def test_acl_bridged_ip6_subif_dot1q(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001190 """IP6 ACL SubIf Dot1Q bridged traffic"""
1191 self.run_traffic(
1192 self.EXACT_MAC,
1193 self.EXACT_IP,
1194 self.BRIDGED,
1195 self.IS_IP6,
1196 9,
1197 tags=self.DOT1Q,
1198 isMACIP=False,
1199 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001200
1201
1202class TestACL_dot1ad_bridged(MethodHolder):
1203 """ACL on dot1ad bridged subinterfaces Tests"""
1204
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001205 @classmethod
1206 def setUpClass(cls):
1207 super(TestACL_dot1ad_bridged, cls).setUpClass()
1208
1209 @classmethod
1210 def tearDownClass(cls):
1211 super(TestACL_dot1ad_bridged, cls).tearDownClass()
1212
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001213 def test_acl_bridged_ip4_subif_dot1ad(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001214 """IP4 ACL SubIf Dot1AD bridged traffic"""
1215 self.run_traffic(
1216 self.EXACT_MAC,
1217 self.EXACT_IP,
1218 self.BRIDGED,
1219 self.IS_IP4,
1220 9,
1221 tags=self.DOT1AD,
1222 isMACIP=False,
1223 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001224
1225 def test_acl_bridged_ip6_subif_dot1ad(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001226 """IP6 ACL SubIf Dot1AD bridged traffic"""
1227 self.run_traffic(
1228 self.EXACT_MAC,
1229 self.EXACT_IP,
1230 self.BRIDGED,
1231 self.IS_IP6,
1232 9,
1233 tags=self.DOT1AD,
1234 isMACIP=False,
1235 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001236
1237
1238class TestACL_dot1q_routed(MethodHolder):
1239 """ACL on dot1q routed subinterfaces Tests"""
1240
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001241 @classmethod
1242 def setUpClass(cls):
1243 super(TestACL_dot1q_routed, cls).setUpClass()
1244
1245 @classmethod
1246 def tearDownClass(cls):
1247 super(TestACL_dot1q_routed, cls).tearDownClass()
1248
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001249 def test_acl_routed_ip4_subif_dot1q(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001250 """IP4 ACL SubIf Dot1Q routed traffic"""
1251 self.run_traffic(
1252 self.EXACT_MAC,
1253 self.EXACT_IP,
1254 self.ROUTED,
1255 self.IS_IP4,
1256 9,
1257 tags=self.DOT1Q,
1258 isMACIP=False,
1259 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001260
1261 def test_acl_routed_ip6_subif_dot1q(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001262 """IP6 ACL SubIf Dot1Q routed traffic"""
1263 self.run_traffic(
1264 self.EXACT_MAC,
1265 self.EXACT_IP,
1266 self.ROUTED,
1267 self.IS_IP6,
1268 9,
1269 tags=self.DOT1Q,
1270 isMACIP=False,
1271 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001272
1273 def test_acl_routed_ip4_subif_dot1q_deny_by_tags(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001274 """IP4 ACL SubIf wrong tags Dot1Q routed traffic"""
1275 self.run_traffic(
1276 self.EXACT_MAC,
1277 self.EXACT_IP,
1278 self.ROUTED,
1279 self.IS_IP4,
1280 9,
1281 True,
1282 tags=self.DOT1Q,
1283 isMACIP=False,
1284 permit_tags=self.DENY_TAGS,
1285 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001286
1287 def test_acl_routed_ip6_subif_dot1q_deny_by_tags(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001288 """IP6 ACL SubIf wrong tags Dot1Q routed traffic"""
1289 self.run_traffic(
1290 self.EXACT_MAC,
1291 self.EXACT_IP,
1292 self.ROUTED,
1293 self.IS_IP6,
1294 9,
1295 True,
1296 tags=self.DOT1Q,
1297 isMACIP=False,
1298 permit_tags=self.DENY_TAGS,
1299 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001300
1301
1302class TestACL_dot1ad_routed(MethodHolder):
1303 """ACL on dot1ad routed subinterfaces Tests"""
1304
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -07001305 @classmethod
1306 def setUpClass(cls):
1307 super(TestACL_dot1ad_routed, cls).setUpClass()
1308
1309 @classmethod
1310 def tearDownClass(cls):
1311 super(TestACL_dot1ad_routed, cls).tearDownClass()
1312
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001313 def test_acl_routed_ip6_subif_dot1ad(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001314 """IP6 ACL SubIf Dot1AD routed traffic"""
1315 self.run_traffic(
1316 self.EXACT_MAC,
1317 self.EXACT_IP,
1318 self.ROUTED,
1319 self.IS_IP6,
1320 9,
1321 tags=self.DOT1AD,
1322 isMACIP=False,
1323 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001324
1325 def test_acl_routed_ip4_subif_dot1ad(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001326 """IP4 ACL SubIf Dot1AD routed traffic"""
1327 self.run_traffic(
1328 self.EXACT_MAC,
1329 self.EXACT_IP,
1330 self.ROUTED,
1331 self.IS_IP4,
1332 9,
1333 tags=self.DOT1AD,
1334 isMACIP=False,
1335 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001336
1337 def test_acl_routed_ip6_subif_dot1ad_deny_by_tags(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001338 """IP6 ACL SubIf wrong tags Dot1AD routed traffic"""
1339 self.run_traffic(
1340 self.EXACT_MAC,
1341 self.EXACT_IP,
1342 self.ROUTED,
1343 self.IS_IP6,
1344 9,
1345 True,
1346 tags=self.DOT1AD,
1347 isMACIP=False,
1348 permit_tags=self.DENY_TAGS,
1349 )
Pavel Kotucek8daa80a2017-09-25 09:44:05 +02001350
1351 def test_acl_routed_ip4_subif_dot1ad_deny_by_tags(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001352 """IP4 ACL SubIf wrong tags Dot1AD routed traffic"""
1353 self.run_traffic(
1354 self.EXACT_MAC,
1355 self.EXACT_IP,
1356 self.ROUTED,
1357 self.IS_IP4,
1358 9,
1359 True,
1360 tags=self.DOT1AD,
1361 isMACIP=False,
1362 permit_tags=self.DENY_TAGS,
1363 )
Pavel Kotucek932f7412017-09-07 14:44:52 +02001364
1365
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001366if __name__ == "__main__":
Pavel Kotucek932f7412017-09-07 14:44:52 +02001367 unittest.main(testRunner=VppTestRunner)