blob: 8836fa1dfe89d7f0f4c457e272a2ddc02edb889e [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Jan Gelety059d1d02018-07-03 13:58:24 +02002
3import unittest
4import socket
5import binascii
Jan Gelety059d1d02018-07-03 13:58:24 +02006
Dave Wallace8800f732023-08-31 00:47:44 -04007from asfframework import VppTestRunner
Jan Gelety059d1d02018-07-03 13:58:24 +02008
Dave Wallace8800f732023-08-31 00:47:44 -04009from scapy.layers.inet6 import UDP, TCP
Jakub Grajciar692bfc82019-08-27 10:16:44 +020010from template_classifier import TestClassifier
Jan Gelety059d1d02018-07-03 13:58:24 +020011
12
13class TestClassifierIP6(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020014 """Classifier IP6 Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +020015
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070016 @classmethod
17 def setUpClass(cls):
18 super(TestClassifierIP6, cls).setUpClass()
Jakub Grajciar692bfc82019-08-27 10:16:44 +020019 cls.af = socket.AF_INET6
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070020
21 @classmethod
22 def tearDownClass(cls):
23 super(TestClassifierIP6, cls).tearDownClass()
24
Jan Gelety059d1d02018-07-03 13:58:24 +020025 def test_iacl_src_ip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020026 """Source IP6 iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +020027
28 Test scenario for basic IP ACL with source IP
29 - Create IPv6 stream for pg0 -> pg1 interface.
30 - Create iACL with source IP address.
31 - Send and verify received packets on pg1 interface.
32 """
33
34 # Basic iACL testing with source IP
35 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
36 self.pg0.add_stream(pkts)
37
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020038 key = "ip6_src"
Jan Gelety059d1d02018-07-03 13:58:24 +020039 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020040 key, self.build_ip6_mask(src_ip="ffffffffffffffffffffffffffffffff")
41 )
Jan Gelety059d1d02018-07-03 13:58:24 +020042 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 self.acl_tbl_idx.get(key), self.build_ip6_match(src_ip=self.pg0.remote_ip6)
44 )
Jan Gelety059d1d02018-07-03 13:58:24 +020045 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
46 self.acl_active_table = key
47
48 self.pg_enable_capture(self.pg_interfaces)
49 self.pg_start()
50
51 pkts = self.pg1.get_capture(len(pkts))
52 self.verify_capture(self.pg1, pkts)
53 self.pg0.assert_nothing_captured(remark="packets forwarded")
54 self.pg2.assert_nothing_captured(remark="packets forwarded")
55
56 def test_iacl_dst_ip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020057 """Destination IP6 iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +020058
59 Test scenario for basic IP ACL with destination IP
60 - Create IPv6 stream for pg0 -> pg1 interface.
61 - Create iACL with destination IP address.
62 - Send and verify received packets on pg1 interface.
63 """
64
65 # Basic iACL testing with destination IP
66 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
67 self.pg0.add_stream(pkts)
68
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020069 key = "ip6_dst"
Jan Gelety059d1d02018-07-03 13:58:24 +020070 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020071 key, self.build_ip6_mask(dst_ip="ffffffffffffffffffffffffffffffff")
72 )
Jan Gelety059d1d02018-07-03 13:58:24 +020073 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020074 self.acl_tbl_idx.get(key), self.build_ip6_match(dst_ip=self.pg1.remote_ip6)
75 )
Jan Gelety059d1d02018-07-03 13:58:24 +020076 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
77 self.acl_active_table = key
78
79 self.pg_enable_capture(self.pg_interfaces)
80 self.pg_start()
81
82 pkts = self.pg1.get_capture(len(pkts))
83 self.verify_capture(self.pg1, pkts)
84 self.pg0.assert_nothing_captured(remark="packets forwarded")
85 self.pg2.assert_nothing_captured(remark="packets forwarded")
86
87 def test_iacl_src_dst_ip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020088 """Source and destination IP6 iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +020089
90 Test scenario for basic IP ACL with source and destination IP
91 - Create IPv4 stream for pg0 -> pg1 interface.
92 - Create iACL with source and destination IP addresses.
93 - Send and verify received packets on pg1 interface.
94 """
95
96 # Basic iACL testing with source and destination IP
97 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
98 self.pg0.add_stream(pkts)
99
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200100 key = "ip6"
Jan Gelety059d1d02018-07-03 13:58:24 +0200101 self.create_classify_table(
102 key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200103 self.build_ip6_mask(
104 src_ip="ffffffffffffffffffffffffffffffff",
105 dst_ip="ffffffffffffffffffffffffffffffff",
106 ),
107 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200108 self.create_classify_session(
109 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200110 self.build_ip6_match(
111 src_ip=self.pg0.remote_ip6, dst_ip=self.pg1.remote_ip6
112 ),
113 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200114 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
115 self.acl_active_table = key
116
117 self.pg_enable_capture(self.pg_interfaces)
118 self.pg_start()
119
120 pkts = self.pg1.get_capture(len(pkts))
121 self.verify_capture(self.pg1, pkts)
122 self.pg0.assert_nothing_captured(remark="packets forwarded")
123 self.pg2.assert_nothing_captured(remark="packets forwarded")
124
125
126# Tests split to different test case classes because of issue reported in
127# ticket VPP-1336
128class TestClassifierIP6UDP(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200129 """Classifier IP6 UDP proto Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200130
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700131 @classmethod
132 def setUpClass(cls):
133 super(TestClassifierIP6UDP, cls).setUpClass()
Jakub Grajciar692bfc82019-08-27 10:16:44 +0200134 cls.af = socket.AF_INET6
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700135
Jan Gelety059d1d02018-07-03 13:58:24 +0200136 def test_iacl_proto_udp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200137 """IP6 UDP protocol iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200138
139 Test scenario for basic protocol ACL with UDP protocol
140 - Create IPv6 stream for pg0 -> pg1 interface.
141 - Create iACL with UDP IP protocol.
142 - Send and verify received packets on pg1 interface.
143 """
144
145 # Basic iACL testing with UDP protocol
146 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
147 self.pg0.add_stream(pkts)
148
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200149 key = "nh_udp"
150 self.create_classify_table(key, self.build_ip6_mask(nh="ff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200151 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200152 self.acl_tbl_idx.get(key), self.build_ip6_match(nh=socket.IPPROTO_UDP)
153 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200154 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
155 self.acl_active_table = key
156
157 self.pg_enable_capture(self.pg_interfaces)
158 self.pg_start()
159
160 pkts = self.pg1.get_capture(len(pkts))
161 self.verify_capture(self.pg1, pkts)
162 self.pg0.assert_nothing_captured(remark="packets forwarded")
163 self.pg2.assert_nothing_captured(remark="packets forwarded")
164
165 def test_iacl_proto_udp_sport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200166 """IP6 UDP source port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200167
168 Test scenario for basic protocol ACL with UDP and sport
169 - Create IPv6 stream for pg0 -> pg1 interface.
170 - Create iACL with UDP IP protocol and defined sport.
171 - Send and verify received packets on pg1 interface.
172 """
173
174 # Basic iACL testing with UDP and sport
175 sport = 38
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200176 pkts = self.create_stream(
177 self.pg0, self.pg1, self.pg_if_packet_sizes, UDP(sport=sport, dport=5678)
178 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200179 self.pg0.add_stream(pkts)
180
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200181 key = "nh_udp_sport"
182 self.create_classify_table(key, self.build_ip6_mask(nh="ff", src_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200183 self.create_classify_session(
184 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200185 self.build_ip6_match(nh=socket.IPPROTO_UDP, src_port=sport),
186 )
187 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200188 self.acl_active_table = key
189
190 self.pg_enable_capture(self.pg_interfaces)
191 self.pg_start()
192
193 pkts = self.pg1.get_capture(len(pkts))
194 self.verify_capture(self.pg1, pkts)
195 self.pg0.assert_nothing_captured(remark="packets forwarded")
196 self.pg2.assert_nothing_captured(remark="packets forwarded")
197
198 def test_iacl_proto_udp_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200199 """IP6 UDP destination port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200200
201 Test scenario for basic protocol ACL with UDP and dport
202 - Create IPv6 stream for pg0 -> pg1 interface.
203 - Create iACL with UDP IP protocol and defined dport.
204 - Send and verify received packets on pg1 interface.
205 """
206
207 # Basic iACL testing with UDP and dport
208 dport = 427
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200209 pkts = self.create_stream(
210 self.pg0, self.pg1, self.pg_if_packet_sizes, UDP(sport=1234, dport=dport)
211 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200212 self.pg0.add_stream(pkts)
213
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200214 key = "nh_udp_dport"
215 self.create_classify_table(key, self.build_ip6_mask(nh="ff", dst_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200216 self.create_classify_session(
217 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200218 self.build_ip6_match(nh=socket.IPPROTO_UDP, dst_port=dport),
219 )
220 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200221 self.acl_active_table = key
222
223 self.pg_enable_capture(self.pg_interfaces)
224 self.pg_start()
225
226 pkts = self.pg1.get_capture(len(pkts))
227 self.verify_capture(self.pg1, pkts)
228 self.pg0.assert_nothing_captured(remark="packets forwarded")
229 self.pg2.assert_nothing_captured(remark="packets forwarded")
230
231 def test_iacl_proto_udp_sport_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200232 """IP6 UDP source and destination ports iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200233
234 Test scenario for basic protocol ACL with UDP and sport and dport
235 - Create IPv6 stream for pg0 -> pg1 interface.
236 - Create iACL with UDP IP protocol and defined sport and dport.
237 - Send and verify received packets on pg1 interface.
238 """
239
240 # Basic iACL testing with UDP and sport and dport
241 sport = 13720
242 dport = 9080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200243 pkts = self.create_stream(
244 self.pg0, self.pg1, self.pg_if_packet_sizes, UDP(sport=sport, dport=dport)
245 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200246 self.pg0.add_stream(pkts)
247
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200248 key = "nh_udp_ports"
Jan Gelety059d1d02018-07-03 13:58:24 +0200249 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200250 key, self.build_ip6_mask(nh="ff", src_port="ffff", dst_port="ffff")
251 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200252 self.create_classify_session(
253 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200254 self.build_ip6_match(nh=socket.IPPROTO_UDP, src_port=sport, dst_port=dport),
255 )
256 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200257 self.acl_active_table = key
258
259 self.pg_enable_capture(self.pg_interfaces)
260 self.pg_start()
261
262 pkts = self.pg1.get_capture(len(pkts))
263 self.verify_capture(self.pg1, pkts)
264 self.pg0.assert_nothing_captured(remark="packets forwarded")
265 self.pg2.assert_nothing_captured(remark="packets forwarded")
266
267
268class TestClassifierIP6TCP(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200269 """Classifier IP6 TCP proto Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200270
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700271 @classmethod
272 def setUpClass(cls):
273 super(TestClassifierIP6TCP, cls).setUpClass()
Jakub Grajciar692bfc82019-08-27 10:16:44 +0200274 cls.af = socket.AF_INET6
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700275
Jan Gelety059d1d02018-07-03 13:58:24 +0200276 def test_iacl_proto_tcp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200277 """IP6 TCP protocol iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200278
279 Test scenario for basic protocol ACL with TCP protocol
280 - Create IPv6 stream for pg0 -> pg1 interface.
281 - Create iACL with TCP IP protocol.
282 - Send and verify received packets on pg1 interface.
283 """
284
285 # Basic iACL testing with TCP protocol
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200286 pkts = self.create_stream(
287 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=1234, dport=5678)
288 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200289 self.pg0.add_stream(pkts)
290
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200291 key = "nh_tcp"
292 self.create_classify_table(key, self.build_ip6_mask(nh="ff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200293 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200294 self.acl_tbl_idx.get(key), self.build_ip6_match(nh=socket.IPPROTO_TCP)
295 )
296 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200297 self.acl_active_table = key
298
299 self.pg_enable_capture(self.pg_interfaces)
300 self.pg_start()
301
302 pkts = self.pg1.get_capture(len(pkts))
303 self.verify_capture(self.pg1, pkts, TCP)
304 self.pg0.assert_nothing_captured(remark="packets forwarded")
305 self.pg2.assert_nothing_captured(remark="packets forwarded")
306
307 def test_iacl_proto_tcp_sport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200308 """IP6 TCP source port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200309
310 Test scenario for basic protocol ACL with TCP and sport
311 - Create IPv6 stream for pg0 -> pg1 interface.
312 - Create iACL with TCP IP protocol and defined sport.
313 - Send and verify received packets on pg1 interface.
314 """
315
316 # Basic iACL testing with TCP and sport
317 sport = 38
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200318 pkts = self.create_stream(
319 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=sport, dport=5678)
320 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200321 self.pg0.add_stream(pkts)
322
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200323 key = "nh_tcp_sport"
324 self.create_classify_table(key, self.build_ip6_mask(nh="ff", src_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200325 self.create_classify_session(
326 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200327 self.build_ip6_match(nh=socket.IPPROTO_TCP, src_port=sport),
328 )
329 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200330 self.acl_active_table = key
331
332 self.pg_enable_capture(self.pg_interfaces)
333 self.pg_start()
334
335 pkts = self.pg1.get_capture(len(pkts))
336 self.verify_capture(self.pg1, pkts, TCP)
337 self.pg0.assert_nothing_captured(remark="packets forwarded")
338 self.pg2.assert_nothing_captured(remark="packets forwarded")
339
340 def test_iacl_proto_tcp_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200341 """IP6 TCP destination port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200342
343 Test scenario for basic protocol ACL with TCP and dport
344 - Create IPv6 stream for pg0 -> pg1 interface.
345 - Create iACL with TCP IP protocol and defined dport.
346 - Send and verify received packets on pg1 interface.
347 """
348
349 # Basic iACL testing with TCP and dport
350 dport = 427
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200351 pkts = self.create_stream(
352 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=1234, dport=dport)
353 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200354 self.pg0.add_stream(pkts)
355
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200356 key = "nh_tcp_dport"
357 self.create_classify_table(key, self.build_ip6_mask(nh="ff", dst_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200358 self.create_classify_session(
359 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200360 self.build_ip6_match(nh=socket.IPPROTO_TCP, dst_port=dport),
361 )
362 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200363 self.acl_active_table = key
364
365 self.pg_enable_capture(self.pg_interfaces)
366 self.pg_start()
367
368 pkts = self.pg1.get_capture(len(pkts))
369 self.verify_capture(self.pg1, pkts, TCP)
370 self.pg0.assert_nothing_captured(remark="packets forwarded")
371 self.pg2.assert_nothing_captured(remark="packets forwarded")
372
373 def test_iacl_proto_tcp_sport_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200374 """IP6 TCP source and destination ports iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200375
376 Test scenario for basic protocol ACL with TCP and sport and dport
377 - Create IPv6 stream for pg0 -> pg1 interface.
378 - Create iACL with TCP IP protocol and defined sport and dport.
379 - Send and verify received packets on pg1 interface.
380 """
381
382 # Basic iACL testing with TCP and sport and dport
383 sport = 13720
384 dport = 9080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200385 pkts = self.create_stream(
386 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=sport, dport=dport)
387 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200388 self.pg0.add_stream(pkts)
389
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200390 key = "nh_tcp_ports"
Jan Gelety059d1d02018-07-03 13:58:24 +0200391 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200392 key, self.build_ip6_mask(nh="ff", src_port="ffff", dst_port="ffff")
393 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200394 self.create_classify_session(
395 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200396 self.build_ip6_match(nh=socket.IPPROTO_TCP, src_port=sport, dst_port=dport),
397 )
398 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200399 self.acl_active_table = key
400
401 self.pg_enable_capture(self.pg_interfaces)
402 self.pg_start()
403
404 pkts = self.pg1.get_capture(len(pkts))
405 self.verify_capture(self.pg1, pkts, TCP)
406 self.pg0.assert_nothing_captured(remark="packets forwarded")
407 self.pg2.assert_nothing_captured(remark="packets forwarded")
408
409
410class TestClassifierIP6Out(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200411 """Classifier output IP6 Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200412
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700413 @classmethod
414 def setUpClass(cls):
415 super(TestClassifierIP6Out, cls).setUpClass()
Jakub Grajciar692bfc82019-08-27 10:16:44 +0200416 cls.af = socket.AF_INET6
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700417
Jan Gelety059d1d02018-07-03 13:58:24 +0200418 def test_acl_ip_out(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200419 """Output IP6 ACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200420
421 Test scenario for basic IP ACL with source IP
422 - Create IPv6 stream for pg1 -> pg0 interface.
423 - Create ACL with source IP address.
424 - Send and verify received packets on pg0 interface.
425 """
426
427 # Basic oACL testing with source IP
428 pkts = self.create_stream(self.pg1, self.pg0, self.pg_if_packet_sizes)
429 self.pg1.add_stream(pkts)
430
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200431 key = "ip6_out"
Jan Gelety059d1d02018-07-03 13:58:24 +0200432 self.create_classify_table(
433 key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200434 self.build_ip6_mask(src_ip="ffffffffffffffffffffffffffffffff"),
435 data_offset=0,
436 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200437 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200438 self.acl_tbl_idx.get(key), self.build_ip6_match(src_ip=self.pg1.remote_ip6)
439 )
440 self.output_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200441 self.acl_active_table = key
442
443 self.pg_enable_capture(self.pg_interfaces)
444 self.pg_start()
445
446 pkts = self.pg0.get_capture(len(pkts))
447 self.verify_capture(self.pg0, pkts)
448 self.pg1.assert_nothing_captured(remark="packets forwarded")
449 self.pg2.assert_nothing_captured(remark="packets forwarded")
450
451
452class TestClassifierIP6MAC(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200453 """Classifier IP6 MAC Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200454
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700455 @classmethod
456 def setUpClass(cls):
457 super(TestClassifierIP6MAC, cls).setUpClass()
Jakub Grajciar692bfc82019-08-27 10:16:44 +0200458 cls.af = socket.AF_INET6
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700459
Jan Gelety059d1d02018-07-03 13:58:24 +0200460 def test_acl_mac(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200461 """IP6 MAC iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200462
463 Test scenario for basic MAC ACL with source MAC
464 - Create IPv6 stream for pg0 -> pg2 interface.
465 - Create ACL with source MAC address.
466 - Send and verify received packets on pg2 interface.
467 """
468
469 # Basic iACL testing with source MAC
470 pkts = self.create_stream(self.pg0, self.pg2, self.pg_if_packet_sizes)
471 self.pg0.add_stream(pkts)
472
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200473 key = "mac"
Jan Gelety059d1d02018-07-03 13:58:24 +0200474 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200475 key, self.build_mac_mask(src_mac="ffffffffffff"), data_offset=-14
476 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200477 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200478 self.acl_tbl_idx.get(key), self.build_mac_match(src_mac=self.pg0.remote_mac)
479 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200480 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
481 self.acl_active_table = key
482
483 self.pg_enable_capture(self.pg_interfaces)
484 self.pg_start()
485
486 pkts = self.pg2.get_capture(len(pkts))
487 self.verify_capture(self.pg2, pkts)
488 self.pg0.assert_nothing_captured(remark="packets forwarded")
489 self.pg1.assert_nothing_captured(remark="packets forwarded")
490
491
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200492if __name__ == "__main__":
Jan Gelety059d1d02018-07-03 13:58:24 +0200493 unittest.main(testRunner=VppTestRunner)