29
29
#include " glog/logging.h"
30
30
#include " gmock/gmock.h"
31
31
#include " gtest/gtest.h"
32
+ #include " gutil/proto.h"
32
33
#include " gutil/status.h" // IWYU pragma: keep
33
34
#include " gutil/status.h"
34
35
#include " gutil/status_matchers.h" // IWYU pragma: keep
38
39
#include " p4/v1/p4runtime.pb.h"
39
40
#include " p4_pdpi/ir.h"
40
41
#include " p4_pdpi/ir.pb.h"
42
+ #include " p4_pdpi/netaddr/mac_address.h"
41
43
#include " p4_pdpi/p4_runtime_session.h"
42
44
#include " p4_pdpi/p4_runtime_session_extras.h"
43
45
#include " p4_pdpi/packetlib/packetlib.h"
@@ -80,25 +82,33 @@ absl::Status SetUpIngressAclForwardingAllPackets(
80
82
}
81
83
82
84
// Helper function to build a UDP packet
83
- dvaas::PacketTestVector UdpPacket (std::string control_port,
84
- absl::string_view dst_mac ,
85
- absl::string_view dst_ip ,
86
- std::optional<sai::PuntAction> punt_action) {
85
+ dvaas::PacketTestVector UdpPacket (
86
+ absl::string_view egress_port ,
87
+ const sai::NexthopRewriteOptions& rewrite_options ,
88
+ std::optional<sai::PuntAction> punt_action) {
87
89
ProtoFixtureRepository repo;
88
90
89
91
repo.RegisterValue (" @payload" , dvaas::MakeTestPacketTagFromUniqueId (1 ))
90
- .RegisterValue (" @ingress_port" , control_port)
91
- .RegisterValue (" @egress_port" , control_port)
92
- .RegisterValue (" @dst_ip" , dst_ip)
93
- .RegisterValue (" @dst_mac" , dst_mac)
92
+ .RegisterValue (" @ingress_port" , egress_port)
93
+ .RegisterValue (" @egress_port" , egress_port)
94
+ .RegisterValue (" @ingress_dst_mac" , " 00:aa:bb:cc:cc:dd" )
95
+ .RegisterValue (" @ingress_src_mac" , " 00:00:22:22:00:00" )
96
+ .RegisterValue (" @egress_dst_mac" ,
97
+ (rewrite_options.dst_mac_rewrite .has_value ()
98
+ ? rewrite_options.dst_mac_rewrite ->ToString ()
99
+ : " @ingress_dst_mac" ))
100
+ .RegisterValue (" @egress_src_mac" ,
101
+ (rewrite_options.src_mac_rewrite .has_value ()
102
+ ? rewrite_options.src_mac_rewrite ->ToString ()
103
+ : " @ingress_src_mac" ))
94
104
.RegisterValue (" @ttl" , " 0x10" )
95
105
.RegisterValue (" @decremented_ttl" , " 0x0f" );
96
106
97
107
dvaas::PacketTestVector test_vector =
98
108
repo.RegisterSnippetOrDie <packetlib::Header>(" @ethernet" , R"pb(
99
109
ethernet_header {
100
- ethernet_destination: @dst_mac ,
101
- ethernet_source: "00:00:22:22:00:00"
110
+ ethernet_destination: @ingress_dst_mac ,
111
+ ethernet_source: @ingress_src_mac,
102
112
ethertype: "0x0800" # Udp
103
113
}
104
114
)pb" )
@@ -115,7 +125,7 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
115
125
# payload_length: filled in automatically.
116
126
protocol: "0x11"
117
127
ipv4_source: "10.0.0.8"
118
- ipv4_destination: @dst_ip
128
+ ipv4_destination: "10.0.0.1"
119
129
}
120
130
)pb" )
121
131
.RegisterSnippetOrDie <packetlib::Header>(" @udp" , R"pb(
@@ -133,8 +143,8 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
133
143
" @output_packet" , ParsePacketAndFillInComputedFields (repo, R"pb(
134
144
headers: @ethernet {
135
145
ethernet_header {
136
- ethernet_destination: "02:03:04:05:06:07"
137
- ethernet_source: "00:01:02:03:04:05"
146
+ ethernet_destination: @egress_dst_mac
147
+ ethernet_source: @egress_src_mac
138
148
}
139
149
}
140
150
headers: @ipv4 { ipv4_header { ttl: @decremented_ttl } }
@@ -148,7 +158,17 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
148
158
}
149
159
acceptable_outputs {
150
160
packets { port: @egress_port parsed: @output_packet }
151
- packet_ins { parsed: @output_packet }
161
+ packet_ins {
162
+ metadata {
163
+ name: "ingress_port"
164
+ value: { str: @ingress_port }
165
+ }
166
+ metadata {
167
+ name: "target_egress_port"
168
+ value: { str: @egress_port }
169
+ }
170
+ parsed: @input_packet
171
+ }
152
172
}
153
173
)pb" );
154
174
@@ -165,19 +185,16 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
165
185
166
186
// Helper routine to install L3 route
167
187
absl::Status InstallL3Route (pdpi::P4RuntimeSession* switch_session,
168
- pdpi::IrP4Info ir_p4info, std::string given_port,
188
+ const pdpi::IrP4Info& ir_p4info,
189
+ absl::string_view egress_port,
190
+ const sai::NexthopRewriteOptions& rewrite_options,
169
191
std::optional<sai::PuntAction> punt_action) {
170
192
std::vector<p4::v1::Entity> pi_entities;
171
193
LOG (INFO) << " Installing L3 route" ;
172
194
173
195
sai::EntryBuilder entry_builder =
174
- sai::EntryBuilder ()
175
- .AddVrfEntry (" vrf-1" )
176
- .AddPreIngressAclEntryAssigningVrfForGivenIpType (
177
- " vrf-1" , sai::IpVersion::kIpv4 )
178
- .AddDefaultRouteForwardingAllPacketsToGivenPort (
179
- given_port, sai::IpVersion::kIpv4 , " vrf-1" )
180
- .AddEntryAdmittingAllPacketsToL3 ();
196
+ sai::EntryBuilder ().AddEntriesForwardingIpPacketsToGivenPort (
197
+ egress_port, sai::IpVersion::kIpv4And6 , rewrite_options);
181
198
182
199
if (punt_action.has_value ()) {
183
200
entry_builder.AddEntryPuntingAllPackets (punt_action.value ());
@@ -193,22 +210,35 @@ absl::Status InstallL3Route(pdpi::P4RuntimeSession* switch_session,
193
210
}
194
211
195
212
TEST_P (AclFeatureTestFixture, AclDenyAction) {
213
+ dvaas::PacketTestVector test_vector;
196
214
const AclFeatureTestParams& params = GetParam ();
215
+ dvaas::DataplaneValidationParams dvaas_params = params.dvaas_params ;
197
216
198
217
thinkit::MirrorTestbed& testbed =
199
218
GetParam ().mirror_testbed ->GetMirrorTestbed ();
200
- std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
201
- control_switch_p4rt_session;
202
219
203
- ASSERT_OK_AND_ASSIGN (
204
- std::tie (sut_p4rt_session, control_switch_p4rt_session),
205
- pins_test::ConfigureSwitchPairAndReturnP4RuntimeSessionPair (
206
- testbed.Sut (), testbed.ControlSwitch (), std::nullopt,
207
- GetParam ().p4info ));
220
+ if (params.punt_action == sai::PuntAction::kTrap ) {
221
+ testbed.Environment ().SetTestCaseID (" bbff38be-2da4-40fb-b895-8a44c5e7e909" );
222
+ } else if (params.punt_action == sai::PuntAction::kCopy ) {
223
+ testbed.Environment ().SetTestCaseID (" b0d0353f-21d5-4863-82fb-2b1b3239147b" );
224
+ } else {
225
+ testbed.Environment ().SetTestCaseID (" 6debdcf9-8079-461f-ad4f-4bbe67f8279e" );
226
+ }
208
227
209
- // Initialize the connection, clear table entries, and push GNMI
210
- // configuration (if given) for the SUT and Control switch.
228
+ // Initialize the connection, clear all entities, and (for the SUT) push
229
+ // P4Info.
230
+ ASSERT_OK_AND_ASSIGN (
231
+ std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
232
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
233
+ testbed.Sut (), /* gnmi_config=*/ std::nullopt, GetParam ().sut_p4info ));
234
+ ASSERT_OK_AND_ASSIGN (
235
+ std::unique_ptr<pdpi::P4RuntimeSession> control_switch_p4rt_session,
236
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
237
+ testbed.ControlSwitch (), /* gnmi_config=*/ std::nullopt,
238
+ /* p4info=*/ std::nullopt));
211
239
ASSERT_NE (sut_p4rt_session, nullptr );
240
+ ASSERT_NE (control_switch_p4rt_session, nullptr );
241
+
212
242
ASSERT_OK_AND_ASSIGN (
213
243
p4::v1::GetForwardingPipelineConfigResponse sut_config,
214
244
pdpi::GetForwardingPipelineConfig (sut_p4rt_session.get ()));
@@ -217,33 +247,159 @@ TEST_P(AclFeatureTestFixture, AclDenyAction) {
217
247
ASSERT_OK_AND_ASSIGN (pdpi::IrP4Info sut_ir_p4info,
218
248
pdpi::CreateIrP4Info (sut_config.config ().p4info ()));
219
249
220
- ASSERT_OK (pdpi::ClearTableEntries (sut_p4rt_session.get ()));
221
-
222
250
// Get control ports to test on.
223
251
ASSERT_OK_AND_ASSIGN (
224
252
auto gnmi_stub_control,
225
253
GetParam ().mirror_testbed ->GetMirrorTestbed ().Sut ().CreateGnmiStub ());
226
254
ASSERT_OK_AND_ASSIGN (std::string control_port,
227
255
pins_test::GetAnyUpInterfacePortId (*gnmi_stub_control));
228
256
257
+ // Since we don't care about the egress packet's source and destination mac,
258
+ // we use the default rewrite options.
259
+ const sai::NexthopRewriteOptions rewrite_options;
260
+
229
261
ASSERT_OK (InstallL3Route (sut_p4rt_session.get (), sut_ir_p4info, control_port,
230
- params.punt_action ));
262
+ rewrite_options, params.punt_action ));
263
+
264
+ test_vector = UdpPacket (control_port, rewrite_options, params.punt_action );
265
+
266
+ // Run test with custom packet test vector.
267
+ dvaas_params.packet_test_vector_override = {test_vector};
268
+ ASSERT_OK_AND_ASSIGN (
269
+ dvaas::ValidationResult validation_result,
270
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
231
271
232
- // remove the skip
272
+ // Log statistics and check that things succeeded.
273
+ validation_result.LogStatistics ();
274
+ EXPECT_OK (validation_result.HasSuccessRateOfAtLeast (1.0 ));
275
+
276
+ ASSERT_OK_AND_ASSIGN (sut_p4rt_session,
277
+ pdpi::P4RuntimeSession::Create (testbed.Sut ()));
278
+
279
+ // Install AclDeny
280
+ ASSERT_OK_AND_ASSIGN (auto proto_entry,
281
+ gutil::ParseTextProto<pdpi::IrTableEntry>(
282
+ R"pb( table_name: "acl_ingress_security_table"
283
+ priority: 1
284
+ action { name: "acl_deny" }
285
+ )pb" ));
286
+
287
+ EXPECT_OK (pdpi::InstallIrTableEntry (*sut_p4rt_session.get (), proto_entry));
288
+ for (dvaas::SwitchOutput& output :
289
+ *test_vector.mutable_acceptable_outputs ()) {
290
+ output.clear_packet_ins ();
291
+ output.clear_packets ();
292
+ }
293
+
294
+ dvaas_params.packet_test_vector_override = {test_vector};
295
+ ASSERT_OK_AND_ASSIGN (
296
+ dvaas::ValidationResult validation_result2,
297
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
298
+
299
+ // Log statistics and check that things succeeded.
300
+ validation_result2.LogStatistics ();
301
+ EXPECT_OK (validation_result2.HasSuccessRateOfAtLeast (1.0 ));
302
+ }
303
+
304
+ TEST_P (AclFeatureTestFixture, AclEgressTable) {
305
+ dvaas::PacketTestVector test_vector;
306
+ const AclFeatureTestParams& params = GetParam ();
307
+ dvaas::DataplaneValidationParams dvaas_params = params.dvaas_params ;
308
+ dvaas_params.artifact_prefix = " sanity_dvaas" ;
309
+ const netaddr::MacAddress output_src_mac (0x1 , 0x2 , 0x3 , 0x1 , 0x2 , 0x3 );
310
+
311
+ // we are not testing punt action in this test
312
+ // so skip for those variants
233
313
if (params.punt_action .has_value ()) {
234
- // Run test with custom packet test vector.
235
- dvaas::DataplaneValidationParams dvaas_params = params.dvaas_params ;
236
- dvaas_params.packet_test_vector_override = {
237
- UdpPacket (control_port, /* dst_mac=*/ " 00:aa:bb:cc:cc:dd" ,
238
- /* dst_ip=*/ " 10.0.0.1" , params.punt_action )};
239
- ASSERT_OK_AND_ASSIGN (
240
- dvaas::ValidationResult validation_result,
241
- GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
242
-
243
- // Log statistics and check that things succeeded.
244
- validation_result.LogStatistics ();
245
- EXPECT_OK (validation_result.HasSuccessRateOfAtLeast (1.0 ));
314
+ GTEST_SKIP ();
246
315
}
316
+
317
+ thinkit::MirrorTestbed& testbed =
318
+ GetParam ().mirror_testbed ->GetMirrorTestbed ();
319
+
320
+ testbed.Environment ().SetTestCaseID (" bd227847-c285-49c3-b138-b7a0fbd9cf03" );
321
+
322
+ // Initialize the connection, clear all entities, and (for the SUT) push
323
+ // P4Info.
324
+ ASSERT_OK_AND_ASSIGN (
325
+ std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
326
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
327
+ testbed.Sut (), /* gnmi_config=*/ std::nullopt, GetParam ().sut_p4info ));
328
+ ASSERT_OK_AND_ASSIGN (
329
+ std::unique_ptr<pdpi::P4RuntimeSession> control_switch_p4rt_session,
330
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
331
+ testbed.ControlSwitch (), /* gnmi_config=*/ std::nullopt,
332
+ /* p4info=*/ std::nullopt));
333
+ ASSERT_NE (sut_p4rt_session, nullptr );
334
+ ASSERT_NE (control_switch_p4rt_session, nullptr );
335
+
336
+ ASSERT_OK_AND_ASSIGN (
337
+ p4::v1::GetForwardingPipelineConfigResponse sut_config,
338
+ pdpi::GetForwardingPipelineConfig (sut_p4rt_session.get ()));
339
+ ASSERT_OK (testbed.Environment ().StoreTestArtifact (
340
+ " sut_p4Info.textproto" , sut_config.config ().p4info ().DebugString ()));
341
+ ASSERT_OK_AND_ASSIGN (pdpi::IrP4Info sut_ir_p4info,
342
+ pdpi::CreateIrP4Info (sut_config.config ().p4info ()));
343
+
344
+ // Get control ports to test on.
345
+ ASSERT_OK_AND_ASSIGN (
346
+ auto gnmi_stub_control,
347
+ GetParam ().mirror_testbed ->GetMirrorTestbed ().Sut ().CreateGnmiStub ());
348
+ ASSERT_OK_AND_ASSIGN (std::string control_port,
349
+ pins_test::GetAnyUpInterfacePortId (*gnmi_stub_control));
350
+
351
+ const sai::NexthopRewriteOptions rewrite_options = {.src_mac_rewrite =
352
+ output_src_mac};
353
+
354
+ ASSERT_OK (InstallL3Route (sut_p4rt_session.get (), sut_ir_p4info, control_port,
355
+ rewrite_options, /* punt_action=*/ std::nullopt));
356
+
357
+ test_vector =
358
+ UdpPacket (control_port, rewrite_options, /* punt_action=*/ std::nullopt);
359
+
360
+ // Run test with custom packet test vector.
361
+ dvaas_params.packet_test_vector_override = {test_vector};
362
+ ASSERT_OK_AND_ASSIGN (
363
+ dvaas::ValidationResult validation_result,
364
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
365
+
366
+ // Log statistics and check that things succeeded.
367
+ validation_result.LogStatistics ();
368
+ EXPECT_OK (validation_result.HasSuccessRateOfAtLeast (1.0 ));
369
+
370
+ ASSERT_OK_AND_ASSIGN (sut_p4rt_session,
371
+ pdpi::P4RuntimeSession::Create (testbed.Sut ()));
372
+
373
+ // Install AclEgress Drop
374
+ ASSERT_OK_AND_ASSIGN (auto proto_entry,
375
+ gutil::ParseTextProto<pdpi::IrTableEntry>(
376
+ R"pb( table_name: "acl_egress_table"
377
+ priority: 1
378
+ matches {
379
+ name: "src_mac"
380
+ ternary {
381
+ value { mac: "01:02:03:01:02:03" }
382
+ mask { mac: "ff:ff:ff:ff:ff:ff" }
383
+ }
384
+ }
385
+ action { name: "acl_drop" }
386
+ )pb" ));
387
+
388
+ EXPECT_OK (pdpi::InstallIrTableEntry (*sut_p4rt_session.get (), proto_entry));
389
+
390
+ for (dvaas::SwitchOutput& output :
391
+ *test_vector.mutable_acceptable_outputs ()) {
392
+ output.clear_packets ();
393
+ }
394
+ dvaas_params.packet_test_vector_override = {test_vector};
395
+ dvaas_params.artifact_prefix = " real_test_dvaas" ;
396
+ ASSERT_OK_AND_ASSIGN (
397
+ dvaas::ValidationResult validation_result2,
398
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
399
+
400
+ // Log statistics and check that things succeeded.
401
+ validation_result2.LogStatistics ();
402
+ EXPECT_OK (validation_result2.HasSuccessRateOfAtLeast (1.0 ));
247
403
}
248
404
249
405
} // namespace
0 commit comments