blob: 15b800fd979493a89744d16704bc7bf7d8deb840 [file] [log] [blame]
Renato Botelho do Coutoead1e532019-10-31 13:31:07 -05001#!/usr/bin/env python3
Steve Shin7957d6e2016-12-19 09:24:50 -08002
Paul Vinciguerra6e4c6ad2018-11-25 10:35:29 -08003import socket
4import unittest
Steve Shin7957d6e2016-12-19 09:24:50 -08005
Dave Wallace8800f732023-08-31 00:47:44 -04006from asfframework import VppTestRunner
7from scapy.packet import Raw
Steve Shin7957d6e2016-12-19 09:24:50 -08008
Steve Shin7957d6e2016-12-19 09:24:50 -08009from scapy.layers.l2 import Ether
Jan Gelety059d1d02018-07-03 13:58:24 +020010from scapy.layers.inet import IP, UDP, TCP
Ray Kinsellab8165b92021-09-22 11:24:06 +010011from template_classifier import TestClassifier, VarMask, VarMatch
Neale Ranns097fa662018-05-01 05:17:55 -070012from vpp_ip_route import VppIpRoute, VppRoutePath
13from vpp_ip import INVALID_INDEX
Benoît Ganneabb2a422021-09-30 13:41:00 +020014from vpp_papi import VppEnum
Steve Shin7957d6e2016-12-19 09:24:50 -080015
Klement Sekeradab231a2016-12-21 08:50:14 +010016
Jan Gelety059d1d02018-07-03 13:58:24 +020017# Tests split to different test case classes because of issue reported in
18# ticket VPP-1336
19class TestClassifierIP(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020020 """Classifier IP Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +020021
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -070022 @classmethod
23 def setUpClass(cls):
24 super(TestClassifierIP, cls).setUpClass()
25
26 @classmethod
27 def tearDownClass(cls):
28 super(TestClassifierIP, cls).tearDownClass()
29
Jan Gelety059d1d02018-07-03 13:58:24 +020030 def test_iacl_src_ip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020031 """Source IP iACL test
Steve Shin7957d6e2016-12-19 09:24:50 -080032
33 Test scenario for basic IP ACL with source IP
34 - Create IPv4 stream for pg0 -> pg1 interface.
Jan Gelety059d1d02018-07-03 13:58:24 +020035 - Create iACL with source IP address.
Steve Shin7957d6e2016-12-19 09:24:50 -080036 - Send and verify received packets on pg1 interface.
37 """
38
Jan Gelety059d1d02018-07-03 13:58:24 +020039 # Basic iACL testing with source IP
Steve Shin7957d6e2016-12-19 09:24:50 -080040 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
41 self.pg0.add_stream(pkts)
42
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020043 key = "ip_src"
44 self.create_classify_table(key, self.build_ip_mask(src_ip="ffffffff"))
Klement Sekeradab231a2016-12-21 08:50:14 +010045 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020046 self.acl_tbl_idx.get(key), self.build_ip_match(src_ip=self.pg0.remote_ip4)
47 )
Jan Gelety059d1d02018-07-03 13:58:24 +020048 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
49 self.acl_active_table = key
Steve Shin7957d6e2016-12-19 09:24:50 -080050
51 self.pg_enable_capture(self.pg_interfaces)
52 self.pg_start()
53
Klement Sekeradab231a2016-12-21 08:50:14 +010054 pkts = self.pg1.get_capture(len(pkts))
Steve Shin7957d6e2016-12-19 09:24:50 -080055 self.verify_capture(self.pg1, pkts)
Steve Shin7957d6e2016-12-19 09:24:50 -080056 self.pg0.assert_nothing_captured(remark="packets forwarded")
57 self.pg2.assert_nothing_captured(remark="packets forwarded")
58 self.pg3.assert_nothing_captured(remark="packets forwarded")
59
Jan Gelety059d1d02018-07-03 13:58:24 +020060 def test_iacl_dst_ip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020061 """Destination IP iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +020062
63 Test scenario for basic IP ACL with destination IP
64 - Create IPv4 stream for pg0 -> pg1 interface.
65 - Create iACL with destination IP address.
66 - Send and verify received packets on pg1 interface.
67 """
68
69 # Basic iACL testing with destination IP
70 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
71 self.pg0.add_stream(pkts)
72
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020073 key = "ip_dst"
74 self.create_classify_table(key, self.build_ip_mask(dst_ip="ffffffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +020075 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020076 self.acl_tbl_idx.get(key), self.build_ip_match(dst_ip=self.pg1.remote_ip4)
77 )
Jan Gelety059d1d02018-07-03 13:58:24 +020078 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
79 self.acl_active_table = key
80
81 self.pg_enable_capture(self.pg_interfaces)
82 self.pg_start()
83
84 pkts = self.pg1.get_capture(len(pkts))
85 self.verify_capture(self.pg1, pkts)
86 self.pg0.assert_nothing_captured(remark="packets forwarded")
87 self.pg2.assert_nothing_captured(remark="packets forwarded")
88 self.pg3.assert_nothing_captured(remark="packets forwarded")
89
90 def test_iacl_src_dst_ip(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +020091 """Source and destination IP iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +020092
93 Test scenario for basic IP ACL with source and destination IP
94 - Create IPv4 stream for pg0 -> pg1 interface.
95 - Create iACL with source and destination IP addresses.
96 - Send and verify received packets on pg1 interface.
97 """
98
99 # Basic iACL testing with source and destination IP
100 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
101 self.pg0.add_stream(pkts)
102
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200103 key = "ip"
Jan Gelety059d1d02018-07-03 13:58:24 +0200104 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200105 key, self.build_ip_mask(src_ip="ffffffff", dst_ip="ffffffff")
106 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200107 self.create_classify_session(
108 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200109 self.build_ip_match(src_ip=self.pg0.remote_ip4, dst_ip=self.pg1.remote_ip4),
110 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200111 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
112 self.acl_active_table = key
113
114 self.pg_enable_capture(self.pg_interfaces)
115 self.pg_start()
116
117 pkts = self.pg1.get_capture(len(pkts))
118 self.verify_capture(self.pg1, pkts)
119 self.pg0.assert_nothing_captured(remark="packets forwarded")
120 self.pg2.assert_nothing_captured(remark="packets forwarded")
121 self.pg3.assert_nothing_captured(remark="packets forwarded")
122
123
124class TestClassifierUDP(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200125 """Classifier UDP proto Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200126
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700127 @classmethod
128 def setUpClass(cls):
129 super(TestClassifierUDP, cls).setUpClass()
130
131 @classmethod
132 def tearDownClass(cls):
133 super(TestClassifierUDP, cls).tearDownClass()
134
Jan Gelety059d1d02018-07-03 13:58:24 +0200135 def test_iacl_proto_udp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200136 """UDP protocol iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200137
138 Test scenario for basic protocol ACL with UDP protocol
139 - Create IPv4 stream for pg0 -> pg1 interface.
140 - Create iACL with UDP IP protocol.
141 - Send and verify received packets on pg1 interface.
142 """
143
144 # Basic iACL testing with UDP protocol
145 pkts = self.create_stream(self.pg0, self.pg1, self.pg_if_packet_sizes)
146 self.pg0.add_stream(pkts)
147
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200148 key = "proto_udp"
149 self.create_classify_table(key, self.build_ip_mask(proto="ff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200150 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200151 self.acl_tbl_idx.get(key), self.build_ip_match(proto=socket.IPPROTO_UDP)
152 )
153 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200154 self.acl_active_table = key
155
156 self.pg_enable_capture(self.pg_interfaces)
157 self.pg_start()
158
159 pkts = self.pg1.get_capture(len(pkts))
160 self.verify_capture(self.pg1, pkts)
161 self.pg0.assert_nothing_captured(remark="packets forwarded")
162 self.pg2.assert_nothing_captured(remark="packets forwarded")
163 self.pg3.assert_nothing_captured(remark="packets forwarded")
164
165 def test_iacl_proto_udp_sport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200166 """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 IPv4 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 = "proto_udp_sport"
182 self.create_classify_table(key, self.build_ip_mask(proto="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_ip_match(proto=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 self.pg3.assert_nothing_captured(remark="packets forwarded")
198
199 def test_iacl_proto_udp_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200200 """UDP destination port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200201
202 Test scenario for basic protocol ACL with UDP and dport
203 - Create IPv4 stream for pg0 -> pg1 interface.
204 - Create iACL with UDP IP protocol and defined dport.
205 - Send and verify received packets on pg1 interface.
206 """
207
208 # Basic iACL testing with UDP and dport
209 dport = 427
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200210 pkts = self.create_stream(
211 self.pg0, self.pg1, self.pg_if_packet_sizes, UDP(sport=1234, dport=dport)
212 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200213 self.pg0.add_stream(pkts)
214
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200215 key = "proto_udp_dport"
216 self.create_classify_table(key, self.build_ip_mask(proto="ff", dst_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200217 self.create_classify_session(
218 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200219 self.build_ip_match(proto=socket.IPPROTO_UDP, dst_port=dport),
220 )
221 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200222 self.acl_active_table = key
223
224 self.pg_enable_capture(self.pg_interfaces)
225 self.pg_start()
226
227 pkts = self.pg1.get_capture(len(pkts))
228 self.verify_capture(self.pg1, pkts)
229 self.pg0.assert_nothing_captured(remark="packets forwarded")
230 self.pg2.assert_nothing_captured(remark="packets forwarded")
231 self.pg3.assert_nothing_captured(remark="packets forwarded")
232
233 def test_iacl_proto_udp_sport_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200234 """UDP source and destination ports iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200235
236 Test scenario for basic protocol ACL with UDP and sport and dport
237 - Create IPv4 stream for pg0 -> pg1 interface.
238 - Create iACL with UDP IP protocol and defined sport and dport.
239 - Send and verify received packets on pg1 interface.
240 """
241
242 # Basic iACL testing with UDP and sport and dport
243 sport = 13720
244 dport = 9080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200245 pkts = self.create_stream(
246 self.pg0, self.pg1, self.pg_if_packet_sizes, UDP(sport=sport, dport=dport)
247 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200248 self.pg0.add_stream(pkts)
249
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200250 key = "proto_udp_ports"
Jan Gelety059d1d02018-07-03 13:58:24 +0200251 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200252 key, self.build_ip_mask(proto="ff", src_port="ffff", dst_port="ffff")
253 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200254 self.create_classify_session(
255 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200256 self.build_ip_match(
257 proto=socket.IPPROTO_UDP, src_port=sport, dst_port=dport
258 ),
259 )
260 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200261 self.acl_active_table = key
262
263 self.pg_enable_capture(self.pg_interfaces)
264 self.pg_start()
265
266 pkts = self.pg1.get_capture(len(pkts))
267 self.verify_capture(self.pg1, pkts)
268 self.pg0.assert_nothing_captured(remark="packets forwarded")
269 self.pg2.assert_nothing_captured(remark="packets forwarded")
270 self.pg3.assert_nothing_captured(remark="packets forwarded")
271
272
273class TestClassifierTCP(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200274 """Classifier TCP proto Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200275
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700276 @classmethod
277 def setUpClass(cls):
278 super(TestClassifierTCP, cls).setUpClass()
279
280 @classmethod
281 def tearDownClass(cls):
282 super(TestClassifierTCP, cls).tearDownClass()
283
Jan Gelety059d1d02018-07-03 13:58:24 +0200284 def test_iacl_proto_tcp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200285 """TCP protocol iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200286
287 Test scenario for basic protocol ACL with TCP protocol
288 - Create IPv4 stream for pg0 -> pg1 interface.
289 - Create iACL with TCP IP protocol.
290 - Send and verify received packets on pg1 interface.
291 """
292
293 # Basic iACL testing with TCP protocol
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200294 pkts = self.create_stream(
295 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=1234, dport=5678)
296 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200297 self.pg0.add_stream(pkts)
298
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200299 key = "proto_tcp"
300 self.create_classify_table(key, self.build_ip_mask(proto="ff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200301 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200302 self.acl_tbl_idx.get(key), self.build_ip_match(proto=socket.IPPROTO_TCP)
303 )
304 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200305 self.acl_active_table = key
306
307 self.pg_enable_capture(self.pg_interfaces)
308 self.pg_start()
309
310 pkts = self.pg1.get_capture(len(pkts))
311 self.verify_capture(self.pg1, pkts, TCP)
312 self.pg0.assert_nothing_captured(remark="packets forwarded")
313 self.pg2.assert_nothing_captured(remark="packets forwarded")
314 self.pg3.assert_nothing_captured(remark="packets forwarded")
315
316 def test_iacl_proto_tcp_sport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200317 """TCP source port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200318
319 Test scenario for basic protocol ACL with TCP and sport
320 - Create IPv4 stream for pg0 -> pg1 interface.
321 - Create iACL with TCP IP protocol and defined sport.
322 - Send and verify received packets on pg1 interface.
323 """
324
325 # Basic iACL testing with TCP and sport
326 sport = 38
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200327 pkts = self.create_stream(
328 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=sport, dport=5678)
329 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200330 self.pg0.add_stream(pkts)
331
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200332 key = "proto_tcp_sport"
333 self.create_classify_table(key, self.build_ip_mask(proto="ff", src_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200334 self.create_classify_session(
335 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200336 self.build_ip_match(proto=socket.IPPROTO_TCP, src_port=sport),
337 )
338 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200339 self.acl_active_table = key
340
341 self.pg_enable_capture(self.pg_interfaces)
342 self.pg_start()
343
344 pkts = self.pg1.get_capture(len(pkts))
345 self.verify_capture(self.pg1, pkts, TCP)
346 self.pg0.assert_nothing_captured(remark="packets forwarded")
347 self.pg2.assert_nothing_captured(remark="packets forwarded")
348 self.pg3.assert_nothing_captured(remark="packets forwarded")
349
350 def test_iacl_proto_tcp_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200351 """TCP destination port iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200352
353 Test scenario for basic protocol ACL with TCP and dport
354 - Create IPv4 stream for pg0 -> pg1 interface.
355 - Create iACL with TCP IP protocol and defined dport.
356 - Send and verify received packets on pg1 interface.
357 """
358
359 # Basic iACL testing with TCP and dport
360 dport = 427
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200361 pkts = self.create_stream(
362 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=1234, dport=dport)
363 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200364 self.pg0.add_stream(pkts)
365
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200366 key = "proto_tcp_sport"
367 self.create_classify_table(key, self.build_ip_mask(proto="ff", dst_port="ffff"))
Jan Gelety059d1d02018-07-03 13:58:24 +0200368 self.create_classify_session(
369 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200370 self.build_ip_match(proto=socket.IPPROTO_TCP, dst_port=dport),
371 )
372 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200373 self.acl_active_table = key
374
375 self.pg_enable_capture(self.pg_interfaces)
376 self.pg_start()
377
378 pkts = self.pg1.get_capture(len(pkts))
379 self.verify_capture(self.pg1, pkts, TCP)
380 self.pg0.assert_nothing_captured(remark="packets forwarded")
381 self.pg2.assert_nothing_captured(remark="packets forwarded")
382 self.pg3.assert_nothing_captured(remark="packets forwarded")
383
384 def test_iacl_proto_tcp_sport_dport(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200385 """TCP source and destination ports iACL test
Jan Gelety059d1d02018-07-03 13:58:24 +0200386
387 Test scenario for basic protocol ACL with TCP and sport and dport
388 - Create IPv4 stream for pg0 -> pg1 interface.
389 - Create iACL with TCP IP protocol and defined sport and dport.
390 - Send and verify received packets on pg1 interface.
391 """
392
393 # Basic iACL testing with TCP and sport and dport
394 sport = 13720
395 dport = 9080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200396 pkts = self.create_stream(
397 self.pg0, self.pg1, self.pg_if_packet_sizes, TCP(sport=sport, dport=dport)
398 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200399 self.pg0.add_stream(pkts)
400
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200401 key = "proto_tcp_ports"
Jan Gelety059d1d02018-07-03 13:58:24 +0200402 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200403 key, self.build_ip_mask(proto="ff", src_port="ffff", dst_port="ffff")
404 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200405 self.create_classify_session(
406 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200407 self.build_ip_match(
408 proto=socket.IPPROTO_TCP, src_port=sport, dst_port=dport
409 ),
410 )
411 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Jan Gelety059d1d02018-07-03 13:58:24 +0200412 self.acl_active_table = key
413
414 self.pg_enable_capture(self.pg_interfaces)
415 self.pg_start()
416
417 pkts = self.pg1.get_capture(len(pkts))
418 self.verify_capture(self.pg1, pkts, TCP)
419 self.pg0.assert_nothing_captured(remark="packets forwarded")
420 self.pg2.assert_nothing_captured(remark="packets forwarded")
421 self.pg3.assert_nothing_captured(remark="packets forwarded")
422
423
424class TestClassifierIPOut(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200425 """Classifier output IP Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200426
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700427 @classmethod
428 def setUpClass(cls):
429 super(TestClassifierIPOut, cls).setUpClass()
430
431 @classmethod
432 def tearDownClass(cls):
433 super(TestClassifierIPOut, cls).tearDownClass()
434
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100435 def test_acl_ip_out(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200436 """Output IP ACL test
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100437
438 Test scenario for basic IP ACL with source IP
439 - Create IPv4 stream for pg1 -> pg0 interface.
440 - Create ACL with source IP address.
441 - Send and verify received packets on pg0 interface.
442 """
443
Jan Gelety059d1d02018-07-03 13:58:24 +0200444 # Basic oACL testing with source IP
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100445 pkts = self.create_stream(self.pg1, self.pg0, self.pg_if_packet_sizes)
446 self.pg1.add_stream(pkts)
447
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200448 key = "ip_out"
Jan Gelety059d1d02018-07-03 13:58:24 +0200449 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200450 key, self.build_ip_mask(src_ip="ffffffff"), data_offset=0
451 )
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100452 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200453 self.acl_tbl_idx.get(key), self.build_ip_match(src_ip=self.pg1.remote_ip4)
454 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200455 self.output_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
456 self.acl_active_table = key
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100457
458 self.pg_enable_capture(self.pg_interfaces)
459 self.pg_start()
460
461 pkts = self.pg0.get_capture(len(pkts))
462 self.verify_capture(self.pg0, pkts)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100463 self.pg1.assert_nothing_captured(remark="packets forwarded")
464 self.pg2.assert_nothing_captured(remark="packets forwarded")
465 self.pg3.assert_nothing_captured(remark="packets forwarded")
466
Jan Gelety059d1d02018-07-03 13:58:24 +0200467
468class TestClassifierMAC(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200469 """Classifier MAC Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200470
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700471 @classmethod
472 def setUpClass(cls):
473 super(TestClassifierMAC, cls).setUpClass()
474
475 @classmethod
476 def tearDownClass(cls):
477 super(TestClassifierMAC, cls).tearDownClass()
478
Steve Shin7957d6e2016-12-19 09:24:50 -0800479 def test_acl_mac(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200480 """MAC ACL test
Steve Shin7957d6e2016-12-19 09:24:50 -0800481
482 Test scenario for basic MAC ACL with source MAC
483 - Create IPv4 stream for pg0 -> pg2 interface.
484 - Create ACL with source MAC address.
485 - Send and verify received packets on pg2 interface.
486 """
487
Jan Gelety059d1d02018-07-03 13:58:24 +0200488 # Basic iACL testing with source MAC
Steve Shin7957d6e2016-12-19 09:24:50 -0800489 pkts = self.create_stream(self.pg0, self.pg2, self.pg_if_packet_sizes)
490 self.pg0.add_stream(pkts)
491
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200492 key = "mac"
Jan Gelety059d1d02018-07-03 13:58:24 +0200493 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200494 key, self.build_mac_mask(src_mac="ffffffffffff"), data_offset=-14
495 )
Klement Sekeradab231a2016-12-21 08:50:14 +0100496 self.create_classify_session(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200497 self.acl_tbl_idx.get(key), self.build_mac_match(src_mac=self.pg0.remote_mac)
498 )
Jan Gelety059d1d02018-07-03 13:58:24 +0200499 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
500 self.acl_active_table = key
Steve Shin7957d6e2016-12-19 09:24:50 -0800501
502 self.pg_enable_capture(self.pg_interfaces)
503 self.pg_start()
504
Klement Sekeradab231a2016-12-21 08:50:14 +0100505 pkts = self.pg2.get_capture(len(pkts))
Steve Shin7957d6e2016-12-19 09:24:50 -0800506 self.verify_capture(self.pg2, pkts)
Steve Shin7957d6e2016-12-19 09:24:50 -0800507 self.pg0.assert_nothing_captured(remark="packets forwarded")
508 self.pg1.assert_nothing_captured(remark="packets forwarded")
509 self.pg3.assert_nothing_captured(remark="packets forwarded")
510
Jan Gelety059d1d02018-07-03 13:58:24 +0200511
Ray Kinsellab8165b92021-09-22 11:24:06 +0100512class TestClassifierComplex(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200513 """Large & Nested Classifiers Test Cases"""
Ray Kinsellab8165b92021-09-22 11:24:06 +0100514
515 @classmethod
516 def setUpClass(cls):
517 super(TestClassifierComplex, cls).setUpClass()
518
519 @classmethod
520 def tearDownClass(cls):
521 super(TestClassifierComplex, cls).tearDownClass()
522
523 def test_iacl_large(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200524 """Large input ACL test
Ray Kinsellab8165b92021-09-22 11:24:06 +0100525
526 Test scenario for Large ACL matching on ethernet+ip+udp headers
527 - Create IPv4 stream for pg0 -> pg1 interface.
528 - Create large acl matching on ethernet+ip+udp header fields
529 - Send and verify received packets on pg1 interface.
530 """
531
532 # 40b offset = 80bytes - (sizeof(UDP/IP/ETH) + 4b)
533 # + 4b as build_ip_ma*() func, do not match against UDP Len & Chksum
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200534 msk = VarMask(offset=40, spec="ffff")
Ray Kinsellab8165b92021-09-22 11:24:06 +0100535 mth = VarMatch(offset=40, value=0x1234, length=2)
536
537 payload_msk = self.build_payload_mask([msk])
538 payload_match = self.build_payload_match([mth])
539
540 sport = 13720
541 dport = 9080
542
543 # 36b offset = 80bytes - (sizeof(UDP/IP/ETH))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200544 packet_ex = bytes.fromhex(("0" * 36) + "1234")
545 pkts = self.create_stream(
546 self.pg0,
547 self.pg1,
548 self.pg_if_packet_sizes,
549 UDP(sport=sport, dport=dport),
550 packet_ex,
551 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100552 self.pg0.add_stream(pkts)
553
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200554 key = "large_in"
Ray Kinsellab8165b92021-09-22 11:24:06 +0100555 self.create_classify_table(
556 key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200557 self.build_mac_mask(
558 src_mac="ffffffffffff", dst_mac="ffffffffffff", ether_type="ffff"
559 )
560 + self.build_ip_mask(
561 proto="ff",
562 src_ip="ffffffff",
563 dst_ip="ffffffff",
564 src_port="ffff",
565 dst_port="ffff",
566 )
567 + payload_msk,
568 data_offset=-14,
569 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100570
571 self.create_classify_session(
572 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200573 self.build_mac_match(
574 src_mac=self.pg0.remote_mac,
575 dst_mac=self.pg0.local_mac,
576 # ipv4 next header
577 ether_type="0800",
578 )
579 + self.build_ip_match(
580 proto=socket.IPPROTO_UDP,
581 src_ip=self.pg0.remote_ip4,
582 dst_ip=self.pg1.remote_ip4,
583 src_port=sport,
584 dst_port=dport,
585 )
586 + payload_match,
Ray Kinsellab8165b92021-09-22 11:24:06 +0100587 )
588
589 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
590 self.acl_active_table = key
591
592 self.pg_enable_capture(self.pg_interfaces)
593 self.pg_start()
594
595 pkts = self.pg1.get_capture(len(pkts))
596 self.verify_capture(self.pg1, pkts)
597 self.pg0.assert_nothing_captured(remark="packets forwarded")
598 self.pg2.assert_nothing_captured(remark="packets forwarded")
599 self.pg3.assert_nothing_captured(remark="packets forwarded")
600
601 def test_oacl_large(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200602 """Large output ACL test
Ray Kinsellab8165b92021-09-22 11:24:06 +0100603 Test scenario for Large ACL matching on ethernet+ip+udp headers
604 - Create IPv4 stream for pg1 -> pg0 interface.
605 - Create large acl matching on ethernet+ip+udp header fields
606 - Send and verify received packets on pg0 interface.
607 """
608
609 # 40b offset = 80bytes - (sizeof(UDP/IP/ETH) + 4b)
610 # + 4b as build_ip_ma*() func, do not match against UDP Len & Chksum
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200611 msk = VarMask(offset=40, spec="ffff")
Ray Kinsellab8165b92021-09-22 11:24:06 +0100612 mth = VarMatch(offset=40, value=0x1234, length=2)
613
614 payload_msk = self.build_payload_mask([msk])
615 payload_match = self.build_payload_match([mth])
616
617 sport = 13720
618 dport = 9080
619
620 # 36b offset = 80bytes - (sizeof(UDP/IP/ETH))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200621 packet_ex = bytes.fromhex(("0" * 36) + "1234")
622 pkts = self.create_stream(
623 self.pg1,
624 self.pg0,
625 self.pg_if_packet_sizes,
626 UDP(sport=sport, dport=dport),
627 packet_ex,
628 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100629 self.pg1.add_stream(pkts)
630
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200631 key = "large_out"
Ray Kinsellab8165b92021-09-22 11:24:06 +0100632 self.create_classify_table(
633 key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200634 self.build_mac_mask(
635 src_mac="ffffffffffff", dst_mac="ffffffffffff", ether_type="ffff"
636 )
637 + self.build_ip_mask(
638 proto="ff",
639 src_ip="ffffffff",
640 dst_ip="ffffffff",
641 src_port="ffff",
642 dst_port="ffff",
643 )
644 + payload_msk,
645 data_offset=-14,
646 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100647
648 self.create_classify_session(
649 self.acl_tbl_idx.get(key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200650 self.build_mac_match(
651 src_mac=self.pg0.local_mac,
652 dst_mac=self.pg0.remote_mac,
653 # ipv4 next header
654 ether_type="0800",
655 )
656 + self.build_ip_match(
657 proto=socket.IPPROTO_UDP,
658 src_ip=self.pg1.remote_ip4,
659 dst_ip=self.pg0.remote_ip4,
660 src_port=sport,
661 dst_port=dport,
662 )
663 + payload_match,
664 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100665
666 self.output_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
667 self.acl_active_table = key
668
669 self.pg_enable_capture(self.pg_interfaces)
670 self.pg_start()
671
672 pkts = self.pg0.get_capture(len(pkts))
673 self.verify_capture(self.pg0, pkts)
674 self.pg1.assert_nothing_captured(remark="packets forwarded")
675 self.pg2.assert_nothing_captured(remark="packets forwarded")
676 self.pg3.assert_nothing_captured(remark="packets forwarded")
677
678 def test_iacl_nested(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200679 """Nested input ACL test
Ray Kinsellab8165b92021-09-22 11:24:06 +0100680
681 Test scenario for Large ACL matching on ethernet+ip+udp headers
682 - Create IPv4 stream for pg0 -> pg1 interface.
683 - Create 1st classifier table, without any entries
684 - Create nested acl matching on ethernet+ip+udp header fields
685 - Send and verify received packets on pg1 interface.
686 """
687
688 sport = 13720
689 dport = 9080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200690 pkts = self.create_stream(
691 self.pg0, self.pg1, self.pg_if_packet_sizes, UDP(sport=sport, dport=dport)
692 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100693
694 self.pg0.add_stream(pkts)
695
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200696 subtable_key = "subtable_in"
Ray Kinsellab8165b92021-09-22 11:24:06 +0100697 self.create_classify_table(
698 subtable_key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200699 self.build_mac_mask(
700 src_mac="ffffffffffff", dst_mac="ffffffffffff", ether_type="ffff"
701 )
702 + self.build_ip_mask(
703 proto="ff",
704 src_ip="ffffffff",
705 dst_ip="ffffffff",
706 src_port="ffff",
707 dst_port="ffff",
708 ),
709 data_offset=-14,
710 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100711
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200712 key = "nested_in"
Ray Kinsellab8165b92021-09-22 11:24:06 +0100713 self.create_classify_table(
714 key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200715 self.build_mac_mask(
716 src_mac="ffffffffffff", dst_mac="ffffffffffff", ether_type="ffff"
717 )
718 + self.build_ip_mask(
719 proto="ff",
720 src_ip="ffffffff",
721 dst_ip="ffffffff",
722 src_port="ffff",
723 dst_port="ffff",
724 ),
725 next_table_index=self.acl_tbl_idx.get(subtable_key),
726 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100727
728 self.create_classify_session(
729 self.acl_tbl_idx.get(subtable_key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200730 self.build_mac_match(
731 src_mac=self.pg0.remote_mac,
732 dst_mac=self.pg0.local_mac,
733 # ipv4 next header
734 ether_type="0800",
735 )
736 + self.build_ip_match(
737 proto=socket.IPPROTO_UDP,
738 src_ip=self.pg0.remote_ip4,
739 dst_ip=self.pg1.remote_ip4,
740 src_port=sport,
741 dst_port=dport,
742 ),
743 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100744
745 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
746 self.acl_active_table = key
747
748 self.pg_enable_capture(self.pg_interfaces)
749 self.pg_start()
750
751 pkts = self.pg1.get_capture(len(pkts))
752 self.verify_capture(self.pg1, pkts)
753 self.pg0.assert_nothing_captured(remark="packets forwarded")
754 self.pg2.assert_nothing_captured(remark="packets forwarded")
755 self.pg3.assert_nothing_captured(remark="packets forwarded")
756
757 def test_oacl_nested(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200758 """Nested output ACL test
Ray Kinsellab8165b92021-09-22 11:24:06 +0100759
760 Test scenario for Large ACL matching on ethernet+ip+udp headers
761 - Create IPv4 stream for pg1 -> pg0 interface.
762 - Create 1st classifier table, without any entries
763 - Create nested acl matching on ethernet+ip+udp header fields
764 - Send and verify received packets on pg0 interface.
765 """
766
767 sport = 13720
768 dport = 9080
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200769 pkts = self.create_stream(
770 self.pg1, self.pg0, self.pg_if_packet_sizes, UDP(sport=sport, dport=dport)
771 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100772 self.pg1.add_stream(pkts)
773
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200774 subtable_key = "subtable_out"
Ray Kinsellab8165b92021-09-22 11:24:06 +0100775 self.create_classify_table(
776 subtable_key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200777 self.build_mac_mask(
778 src_mac="ffffffffffff", dst_mac="ffffffffffff", ether_type="ffff"
779 )
780 + self.build_ip_mask(
781 proto="ff",
782 src_ip="ffffffff",
783 dst_ip="ffffffff",
784 src_port="ffff",
785 dst_port="ffff",
786 ),
787 data_offset=-14,
788 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100789
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200790 key = "nested_out"
Ray Kinsellab8165b92021-09-22 11:24:06 +0100791 self.create_classify_table(
792 key,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200793 self.build_mac_mask(
794 src_mac="ffffffffffff", dst_mac="ffffffffffff", ether_type="ffff"
795 )
796 + self.build_ip_mask(
797 proto="ff",
798 src_ip="ffffffff",
799 dst_ip="ffffffff",
800 src_port="ffff",
801 dst_port="ffff",
802 ),
Ray Kinsellab8165b92021-09-22 11:24:06 +0100803 next_table_index=self.acl_tbl_idx.get(subtable_key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200804 data_offset=-14,
805 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100806
807 self.create_classify_session(
808 self.acl_tbl_idx.get(subtable_key),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200809 self.build_mac_match(
810 src_mac=self.pg0.local_mac,
811 dst_mac=self.pg0.remote_mac,
812 # ipv4 next header
813 ether_type="0800",
814 )
815 + self.build_ip_match(
816 proto=socket.IPPROTO_UDP,
817 src_ip=self.pg1.remote_ip4,
818 dst_ip=self.pg0.remote_ip4,
819 src_port=sport,
820 dst_port=dport,
821 ),
822 )
Ray Kinsellab8165b92021-09-22 11:24:06 +0100823
824 self.output_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
825 self.acl_active_table = key
826
827 self.pg_enable_capture(self.pg_interfaces)
828 self.pg_start()
829
830 pkts = self.pg0.get_capture(len(pkts))
831 self.verify_capture(self.pg0, pkts)
832 self.pg1.assert_nothing_captured(remark="packets forwarded")
833 self.pg2.assert_nothing_captured(remark="packets forwarded")
834 self.pg3.assert_nothing_captured(remark="packets forwarded")
835
836
Jan Gelety059d1d02018-07-03 13:58:24 +0200837class TestClassifierPBR(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200838 """Classifier PBR Test Case"""
Jan Gelety059d1d02018-07-03 13:58:24 +0200839
Paul Vinciguerra7f9b7f92019-03-12 19:23:27 -0700840 @classmethod
841 def setUpClass(cls):
842 super(TestClassifierPBR, cls).setUpClass()
843
844 @classmethod
845 def tearDownClass(cls):
846 super(TestClassifierPBR, cls).tearDownClass()
847
Steve Shin7957d6e2016-12-19 09:24:50 -0800848 def test_acl_pbr(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200849 """IP PBR test
Steve Shin7957d6e2016-12-19 09:24:50 -0800850
851 Test scenario for PBR with source IP
852 - Create IPv4 stream for pg0 -> pg3 interface.
853 - Configure PBR fib entry for packet forwarding.
854 - Send and verify received packets on pg3 interface.
855 """
856
857 # PBR testing with source IP
858 pkts = self.create_stream(self.pg0, self.pg3, self.pg_if_packet_sizes)
859 self.pg0.add_stream(pkts)
860
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200861 key = "pbr"
862 self.create_classify_table(key, self.build_ip_mask(src_ip="ffffffff"))
Steve Shin7957d6e2016-12-19 09:24:50 -0800863 pbr_option = 1
Neale Ranns13eaf3e2017-05-23 06:10:33 -0700864 # this will create the VRF/table in which we will insert the route
Klement Sekeradab231a2016-12-21 08:50:14 +0100865 self.create_classify_session(
Jan Gelety059d1d02018-07-03 13:58:24 +0200866 self.acl_tbl_idx.get(key),
Klement Sekeradab231a2016-12-21 08:50:14 +0100867 self.build_ip_match(src_ip=self.pg0.remote_ip4),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200868 pbr_option,
869 self.pbr_vrfid,
870 )
Neale Ranns13eaf3e2017-05-23 06:10:33 -0700871 self.assertTrue(self.verify_vrf(self.pbr_vrfid))
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200872 r = VppIpRoute(
873 self,
874 self.pg3.local_ip4,
875 24,
876 [VppRoutePath(self.pg3.remote_ip4, INVALID_INDEX)],
877 table_id=self.pbr_vrfid,
878 )
Neale Ranns097fa662018-05-01 05:17:55 -0700879 r.add_vpp_config()
880
Jan Gelety059d1d02018-07-03 13:58:24 +0200881 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key))
Steve Shin7957d6e2016-12-19 09:24:50 -0800882
883 self.pg_enable_capture(self.pg_interfaces)
884 self.pg_start()
885
Klement Sekeradab231a2016-12-21 08:50:14 +0100886 pkts = self.pg3.get_capture(len(pkts))
Steve Shin7957d6e2016-12-19 09:24:50 -0800887 self.verify_capture(self.pg3, pkts)
Jan Gelety059d1d02018-07-03 13:58:24 +0200888 self.input_acl_set_interface(self.pg0, self.acl_tbl_idx.get(key), 0)
Steve Shin7957d6e2016-12-19 09:24:50 -0800889 self.pg0.assert_nothing_captured(remark="packets forwarded")
890 self.pg1.assert_nothing_captured(remark="packets forwarded")
891 self.pg2.assert_nothing_captured(remark="packets forwarded")
892
Neale Ranns13eaf3e2017-05-23 06:10:33 -0700893 # remove the classify session and the route
Neale Ranns097fa662018-05-01 05:17:55 -0700894 r.remove_vpp_config()
Neale Ranns13eaf3e2017-05-23 06:10:33 -0700895 self.create_classify_session(
Jan Gelety059d1d02018-07-03 13:58:24 +0200896 self.acl_tbl_idx.get(key),
Neale Ranns13eaf3e2017-05-23 06:10:33 -0700897 self.build_ip_match(src_ip=self.pg0.remote_ip4),
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200898 pbr_option,
899 self.pbr_vrfid,
900 is_add=0,
901 )
Neale Ranns13eaf3e2017-05-23 06:10:33 -0700902
903 # and the table should be gone.
904 self.assertFalse(self.verify_vrf(self.pbr_vrfid))
Steve Shin7957d6e2016-12-19 09:24:50 -0800905
Benoît Ganneabb2a422021-09-30 13:41:00 +0200906
907class TestClassifierPunt(TestClassifier):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200908 """Classifier punt Test Case"""
Benoît Ganneabb2a422021-09-30 13:41:00 +0200909
910 @classmethod
911 def setUpClass(cls):
912 super(TestClassifierPunt, cls).setUpClass()
913
914 @classmethod
915 def tearDownClass(cls):
916 super(TestClassifierPunt, cls).tearDownClass()
917
918 def test_punt_udp(self):
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200919 """IPv4/UDP protocol punt ACL test
Benoît Ganneabb2a422021-09-30 13:41:00 +0200920
921 Test scenario for basic punt ACL with UDP protocol
922 - Create IPv4 stream for pg0 -> pg1 interface.
923 - Create punt ACL with UDP IP protocol.
924 - Send and verify received packets on pg1 interface.
925 """
926
927 sport = 6754
928 dport = 17923
929
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200930 key = "ip4_udp_punt"
Benoît Ganneabb2a422021-09-30 13:41:00 +0200931 self.create_classify_table(
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200932 key, self.build_ip_mask(src_ip="ffffffff", proto="ff", src_port="ffff")
933 )
Benoît Ganneabb2a422021-09-30 13:41:00 +0200934 table_index = self.acl_tbl_idx.get(key)
935 self.vapi.punt_acl_add_del(ip4_table_index=table_index)
936 self.acl_active_table = key
937
938 # punt udp packets to dport received on pg0 through pg1
939 self.vapi.set_punt(
940 is_add=1,
941 punt={
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200942 "type": VppEnum.vl_api_punt_type_t.PUNT_API_TYPE_L4,
943 "punt": {
944 "l4": {
945 "af": VppEnum.vl_api_address_family_t.ADDRESS_IP4,
946 "protocol": VppEnum.vl_api_ip_proto_t.IP_API_PROTO_UDP,
947 "port": dport,
948 }
949 },
950 },
951 )
952 self.vapi.ip_punt_redirect(
953 punt={
954 "rx_sw_if_index": self.pg0.sw_if_index,
955 "tx_sw_if_index": self.pg1.sw_if_index,
956 "nh": self.pg1.remote_ip4,
957 }
958 )
Benoît Ganneabb2a422021-09-30 13:41:00 +0200959
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200960 pkts = [
961 (
962 Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac)
963 / IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
964 / UDP(sport=sport, dport=dport)
965 / Raw("\x17" * 100)
966 )
967 ] * 2
Benoît Ganneabb2a422021-09-30 13:41:00 +0200968
969 # allow a session but not matching the stream: expect to drop
970 self.create_classify_session(
971 table_index,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200972 self.build_ip_match(
973 src_ip=self.pg0.remote_ip4,
974 proto=socket.IPPROTO_UDP,
975 src_port=sport + 10,
976 ),
977 )
Benoît Ganneabb2a422021-09-30 13:41:00 +0200978 self.send_and_assert_no_replies(self.pg0, pkts)
979
980 # allow a session matching the stream: expect to pass
981 self.create_classify_session(
982 table_index,
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200983 self.build_ip_match(
984 src_ip=self.pg0.remote_ip4, proto=socket.IPPROTO_UDP, src_port=sport
985 ),
986 )
Benoît Ganneabb2a422021-09-30 13:41:00 +0200987 self.send_and_expect_only(self.pg0, pkts, self.pg1)
988
Benoît Ganne7fc0ee72021-10-13 19:16:07 +0200989 # test dump api: ip4 is set, ip6 is not
990 r = self.vapi.punt_acl_get()
991 self.assertEqual(r.ip4_table_index, table_index)
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200992 self.assertEqual(r.ip6_table_index, 0xFFFFFFFF)
Benoît Ganne7fc0ee72021-10-13 19:16:07 +0200993
Benoît Ganneabb2a422021-09-30 13:41:00 +0200994 # cleanup
Klement Sekerad9b0c6f2022-04-26 19:02:15 +0200995 self.acl_active_table = ""
Benoît Ganneabb2a422021-09-30 13:41:00 +0200996 self.vapi.punt_acl_add_del(ip4_table_index=table_index, is_add=0)
997
Benoît Ganne7fc0ee72021-10-13 19:16:07 +0200998 # test dump api: nothing set
999 r = self.vapi.punt_acl_get()
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001000 self.assertEqual(r.ip4_table_index, 0xFFFFFFFF)
1001 self.assertEqual(r.ip6_table_index, 0xFFFFFFFF)
Benoît Ganne7fc0ee72021-10-13 19:16:07 +02001002
Benoît Ganneabb2a422021-09-30 13:41:00 +02001003
Klement Sekerad9b0c6f2022-04-26 19:02:15 +02001004if __name__ == "__main__":
Steve Shin7957d6e2016-12-19 09:24:50 -08001005 unittest.main(testRunner=VppTestRunner)