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,27 @@ 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
220
+ // Initialize the connection, clear all entities, and (for the SUT) push
221
+ // P4Info.
203
222
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 ));
208
-
209
- // Initialize the connection, clear table entries, and push GNMI
210
- // configuration (if given) for the SUT and Control switch.
223
+ std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
224
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
225
+ testbed.Sut (), /* gnmi_config=*/ std::nullopt, GetParam ().sut_p4info ));
226
+ ASSERT_OK_AND_ASSIGN (
227
+ std::unique_ptr<pdpi::P4RuntimeSession> control_switch_p4rt_session,
228
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
229
+ testbed.ControlSwitch (), /* gnmi_config=*/ std::nullopt,
230
+ /* p4info=*/ std::nullopt));
211
231
ASSERT_NE (sut_p4rt_session, nullptr );
232
+ ASSERT_NE (control_switch_p4rt_session, nullptr );
233
+
212
234
ASSERT_OK_AND_ASSIGN (
213
235
p4::v1::GetForwardingPipelineConfigResponse sut_config,
214
236
pdpi::GetForwardingPipelineConfig (sut_p4rt_session.get ()));
@@ -217,33 +239,158 @@ TEST_P(AclFeatureTestFixture, AclDenyAction) {
217
239
ASSERT_OK_AND_ASSIGN (pdpi::IrP4Info sut_ir_p4info,
218
240
pdpi::CreateIrP4Info (sut_config.config ().p4info ()));
219
241
220
- ASSERT_OK (pdpi::ClearTableEntries (sut_p4rt_session.get ()));
221
-
222
242
// Get control ports to test on.
223
243
ASSERT_OK_AND_ASSIGN (
224
244
auto gnmi_stub_control,
225
245
GetParam ().mirror_testbed ->GetMirrorTestbed ().Sut ().CreateGnmiStub ());
226
246
ASSERT_OK_AND_ASSIGN (std::string control_port,
227
247
pins_test::GetAnyUpInterfacePortId (*gnmi_stub_control));
228
248
249
+ // Since we don't care about the egress packet's source and destination mac,
250
+ // we use the default rewrite options.
251
+ const sai::NexthopRewriteOptions rewrite_options;
252
+
229
253
ASSERT_OK (InstallL3Route (sut_p4rt_session.get (), sut_ir_p4info, control_port,
230
- params.punt_action ));
254
+ rewrite_options, params.punt_action ));
255
+
256
+ test_vector = UdpPacket (control_port, rewrite_options, params.punt_action );
231
257
232
- // remove the skip
258
+ // Run test with custom packet test vector.
259
+ dvaas_params.packet_test_vector_override = {test_vector};
260
+ ASSERT_OK_AND_ASSIGN (
261
+ dvaas::ValidationResult validation_result,
262
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
263
+
264
+ // Log statistics and check that things succeeded.
265
+ validation_result.LogStatistics ();
266
+ EXPECT_OK (validation_result.HasSuccessRateOfAtLeast (1.0 ));
267
+
268
+ ASSERT_OK_AND_ASSIGN (sut_p4rt_session,
269
+ pdpi::P4RuntimeSession::Create (testbed.Sut ()));
270
+
271
+ // Install AclDeny
272
+ ASSERT_OK_AND_ASSIGN (auto proto_entry,
273
+ gutil::ParseTextProto<pdpi::IrTableEntry>(
274
+ R"pb( table_name: "acl_ingress_security_table"
275
+ priority: 1
276
+ action { name: "acl_deny" }
277
+ )pb" ));
278
+
279
+ EXPECT_OK (pdpi::InstallIrTableEntry (*sut_p4rt_session.get (), proto_entry));
280
+ for (dvaas::SwitchOutput& output :
281
+ *test_vector.mutable_acceptable_outputs ()) {
282
+ output.clear_packet_ins ();
283
+ output.clear_packets ();
284
+ }
285
+
286
+ dvaas_params.packet_test_vector_override = {test_vector};
287
+ ASSERT_OK_AND_ASSIGN (
288
+ dvaas::ValidationResult validation_result2,
289
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
290
+
291
+ // Log statistics and check that things succeeded.
292
+ validation_result2.LogStatistics ();
293
+ EXPECT_OK (validation_result2.HasSuccessRateOfAtLeast (1.0 ));
294
+ }
295
+
296
+ TEST_P (AclFeatureTestFixture, AclEgressTable) {
297
+ dvaas::PacketTestVector test_vector;
298
+ const AclFeatureTestParams& params = GetParam ();
299
+ dvaas::DataplaneValidationParams dvaas_params = params.dvaas_params ;
300
+ dvaas_params.artifact_prefix = " sanity_dvaas" ;
301
+ const netaddr::MacAddress output_src_mac (0x1 , 0x2 , 0x3 , 0x1 , 0x2 , 0x3 );
302
+
303
+ // we are not testing punt action in this test
304
+ // so skip for those variants
233
305
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 ));
306
+ GTEST_SKIP ();
307
+ }
308
+
309
+ thinkit::MirrorTestbed& testbed =
310
+ GetParam ().mirror_testbed ->GetMirrorTestbed ();
311
+
312
+
313
+ // Initialize the connection, clear all entities, and (for the SUT) push
314
+ // P4Info.
315
+ ASSERT_OK_AND_ASSIGN (
316
+ std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
317
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
318
+ testbed.Sut (), /* gnmi_config=*/ std::nullopt, GetParam ().sut_p4info ));
319
+ ASSERT_OK_AND_ASSIGN (
320
+ std::unique_ptr<pdpi::P4RuntimeSession> control_switch_p4rt_session,
321
+ pins_test::ConfigureSwitchAndReturnP4RuntimeSession (
322
+ testbed.ControlSwitch (), /* gnmi_config=*/ std::nullopt,
323
+ /* p4info=*/ std::nullopt));
324
+ ASSERT_NE (sut_p4rt_session, nullptr );
325
+ ASSERT_NE (control_switch_p4rt_session, nullptr );
326
+
327
+ ASSERT_OK_AND_ASSIGN (
328
+ p4::v1::GetForwardingPipelineConfigResponse sut_config,
329
+ pdpi::GetForwardingPipelineConfig (sut_p4rt_session.get ()));
330
+ ASSERT_OK (testbed.Environment ().StoreTestArtifact (
331
+ " sut_p4Info.textproto" , sut_config.config ().p4info ().DebugString ()));
332
+ ASSERT_OK_AND_ASSIGN (pdpi::IrP4Info sut_ir_p4info,
333
+ pdpi::CreateIrP4Info (sut_config.config ().p4info ()));
334
+
335
+ // Get control ports to test on.
336
+ ASSERT_OK_AND_ASSIGN (
337
+ auto gnmi_stub_control,
338
+ GetParam ().mirror_testbed ->GetMirrorTestbed ().Sut ().CreateGnmiStub ());
339
+ ASSERT_OK_AND_ASSIGN (std::string control_port,
340
+ pins_test::GetAnyUpInterfacePortId (*gnmi_stub_control));
341
+
342
+ const sai::NexthopRewriteOptions rewrite_options = {.src_mac_rewrite =
343
+ output_src_mac};
344
+
345
+ ASSERT_OK (InstallL3Route (sut_p4rt_session.get (), sut_ir_p4info, control_port,
346
+ rewrite_options, /* punt_action=*/ std::nullopt));
347
+
348
+ test_vector =
349
+ UdpPacket (control_port, rewrite_options, /* punt_action=*/ std::nullopt);
350
+
351
+ // Run test with custom packet test vector.
352
+ dvaas_params.packet_test_vector_override = {test_vector};
353
+ ASSERT_OK_AND_ASSIGN (
354
+ dvaas::ValidationResult validation_result,
355
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
356
+
357
+ // Log statistics and check that things succeeded.
358
+ validation_result.LogStatistics ();
359
+ EXPECT_OK (validation_result.HasSuccessRateOfAtLeast (1.0 ));
360
+
361
+ ASSERT_OK_AND_ASSIGN (sut_p4rt_session,
362
+ pdpi::P4RuntimeSession::Create (testbed.Sut ()));
363
+
364
+ // Install AclEgress Drop
365
+ ASSERT_OK_AND_ASSIGN (auto proto_entry,
366
+ gutil::ParseTextProto<pdpi::IrTableEntry>(
367
+ R"pb( table_name: "acl_egress_table"
368
+ priority: 1
369
+ matches {
370
+ name: "src_mac"
371
+ ternary {
372
+ value { mac: "01:02:03:01:02:03" }
373
+ mask { mac: "ff:ff:ff:ff:ff:ff" }
374
+ }
375
+ }
376
+ action { name: "acl_drop" }
377
+ )pb" ));
378
+
379
+ EXPECT_OK (pdpi::InstallIrTableEntry (*sut_p4rt_session.get (), proto_entry));
380
+
381
+ for (dvaas::SwitchOutput& output :
382
+ *test_vector.mutable_acceptable_outputs ()) {
383
+ output.clear_packets ();
246
384
}
385
+ dvaas_params.packet_test_vector_override = {test_vector};
386
+ dvaas_params.artifact_prefix = " real_test_dvaas" ;
387
+ ASSERT_OK_AND_ASSIGN (
388
+ dvaas::ValidationResult validation_result2,
389
+ GetParam ().dvaas ->ValidateDataplane (testbed, dvaas_params));
390
+
391
+ // Log statistics and check that things succeeded.
392
+ validation_result2.LogStatistics ();
393
+ EXPECT_OK (validation_result2.HasSuccessRateOfAtLeast (1.0 ));
247
394
}
248
395
249
396
} // namespace
0 commit comments