Skip to content

Commit df9e24c

Browse files
[Thinkit] Remove ability to set P4Info.Fix issue with punt expectations. Add AclDeny to ingress security table and check if the packets get dropped. Update to push a SUT P4Info if given one.Remove if (!params.punt_action.has_value()) in acl_feature_test. Make rewrites explicit in ACL feature test.Add a test to match on src_mac in AclEgressTable
1 parent 3b3b08e commit df9e24c

File tree

2 files changed

+210
-51
lines changed

2 files changed

+210
-51
lines changed

tests/forwarding/acl_feature_test.cc

+203-47
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "glog/logging.h"
3030
#include "gmock/gmock.h"
3131
#include "gtest/gtest.h"
32+
#include "gutil/proto.h"
3233
#include "gutil/status.h" // IWYU pragma: keep
3334
#include "gutil/status.h"
3435
#include "gutil/status_matchers.h" // IWYU pragma: keep
@@ -38,6 +39,7 @@
3839
#include "p4/v1/p4runtime.pb.h"
3940
#include "p4_pdpi/ir.h"
4041
#include "p4_pdpi/ir.pb.h"
42+
#include "p4_pdpi/netaddr/mac_address.h"
4143
#include "p4_pdpi/p4_runtime_session.h"
4244
#include "p4_pdpi/p4_runtime_session_extras.h"
4345
#include "p4_pdpi/packetlib/packetlib.h"
@@ -80,25 +82,33 @@ absl::Status SetUpIngressAclForwardingAllPackets(
8082
}
8183

8284
// 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) {
8789
ProtoFixtureRepository repo;
8890

8991
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"))
94104
.RegisterValue("@ttl", "0x10")
95105
.RegisterValue("@decremented_ttl", "0x0f");
96106

97107
dvaas::PacketTestVector test_vector =
98108
repo.RegisterSnippetOrDie<packetlib::Header>("@ethernet", R"pb(
99109
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,
102112
ethertype: "0x0800" # Udp
103113
}
104114
)pb")
@@ -115,7 +125,7 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
115125
# payload_length: filled in automatically.
116126
protocol: "0x11"
117127
ipv4_source: "10.0.0.8"
118-
ipv4_destination: @dst_ip
128+
ipv4_destination: "10.0.0.1"
119129
}
120130
)pb")
121131
.RegisterSnippetOrDie<packetlib::Header>("@udp", R"pb(
@@ -133,8 +143,8 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
133143
"@output_packet", ParsePacketAndFillInComputedFields(repo, R"pb(
134144
headers: @ethernet {
135145
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
138148
}
139149
}
140150
headers: @ipv4 { ipv4_header { ttl: @decremented_ttl } }
@@ -148,7 +158,17 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
148158
}
149159
acceptable_outputs {
150160
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+
}
152172
}
153173
)pb");
154174

@@ -165,19 +185,16 @@ dvaas::PacketTestVector UdpPacket(std::string control_port,
165185

166186
// Helper routine to install L3 route
167187
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,
169191
std::optional<sai::PuntAction> punt_action) {
170192
std::vector<p4::v1::Entity> pi_entities;
171193
LOG(INFO) << "Installing L3 route";
172194

173195
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);
181198

182199
if (punt_action.has_value()) {
183200
entry_builder.AddEntryPuntingAllPackets(punt_action.value());
@@ -193,22 +210,35 @@ absl::Status InstallL3Route(pdpi::P4RuntimeSession* switch_session,
193210
}
194211

195212
TEST_P(AclFeatureTestFixture, AclDenyAction) {
213+
dvaas::PacketTestVector test_vector;
196214
const AclFeatureTestParams& params = GetParam();
215+
dvaas::DataplaneValidationParams dvaas_params = params.dvaas_params;
197216

198217
thinkit::MirrorTestbed& testbed =
199218
GetParam().mirror_testbed->GetMirrorTestbed();
200-
std::unique_ptr<pdpi::P4RuntimeSession> sut_p4rt_session,
201-
control_switch_p4rt_session;
202219

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+
}
208227

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));
211239
ASSERT_NE(sut_p4rt_session, nullptr);
240+
ASSERT_NE(control_switch_p4rt_session, nullptr);
241+
212242
ASSERT_OK_AND_ASSIGN(
213243
p4::v1::GetForwardingPipelineConfigResponse sut_config,
214244
pdpi::GetForwardingPipelineConfig(sut_p4rt_session.get()));
@@ -217,33 +247,159 @@ TEST_P(AclFeatureTestFixture, AclDenyAction) {
217247
ASSERT_OK_AND_ASSIGN(pdpi::IrP4Info sut_ir_p4info,
218248
pdpi::CreateIrP4Info(sut_config.config().p4info()));
219249

220-
ASSERT_OK(pdpi::ClearTableEntries(sut_p4rt_session.get()));
221-
222250
// Get control ports to test on.
223251
ASSERT_OK_AND_ASSIGN(
224252
auto gnmi_stub_control,
225253
GetParam().mirror_testbed->GetMirrorTestbed().Sut().CreateGnmiStub());
226254
ASSERT_OK_AND_ASSIGN(std::string control_port,
227255
pins_test::GetAnyUpInterfacePortId(*gnmi_stub_control));
228256

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+
229261
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));
231271

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
233313
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();
246315
}
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));
247403
}
248404

249405
} // namespace

tests/forwarding/acl_feature_test.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
#ifndef PINS_TESTS_FORWARDING_ACL_FEATURE_TEST_H_
1616
#define PINS_TESTS_FORWARDING_ACL_FEATURE_TEST_H_
1717

18+
#include <memory>
1819
#include <optional>
19-
#include <tuple>
20+
#include <string>
2021

2122
#include "dvaas/dataplane_validation.h"
22-
#include "dvaas/test_vector.h"
2323
#include "dvaas/test_vector.pb.h"
24-
#include "dvaas/validation_result.h"
24+
#include "gtest/gtest.h"
25+
#include "p4/config/v1/p4info.pb.h"
2526
#include "sai_p4/instantiations/google/test_tools/test_entries.h"
2627
#include "thinkit/mirror_testbed_fixture.h"
2728

@@ -31,7 +32,9 @@ struct AclFeatureTestParams {
3132
// Using a shared_ptr because parameterized tests require objects to be
3233
// copyable.
3334
std::shared_ptr<thinkit::MirrorTestbedInterface> mirror_testbed;
34-
std::optional<p4::config::v1::P4Info> p4info;
35+
// Pushed to the SUT if given, otherwise assumes the correct one is already
36+
// configured.
37+
std::optional<p4::config::v1::P4Info> sut_p4info;
3538
std::string test_name;
3639
// ACL action variant to test out different behavior
3740
std::optional<sai::PuntAction> punt_action;

0 commit comments

Comments
 (0)