Skip to content

Commit 09d4b77

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 3f52760 commit 09d4b77

File tree

2 files changed

+201
-51
lines changed

2 files changed

+201
-51
lines changed

tests/forwarding/acl_feature_test.cc

+194-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,27 @@ 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

220+
// Initialize the connection, clear all entities, and (for the SUT) push
221+
// P4Info.
203222
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));
211231
ASSERT_NE(sut_p4rt_session, nullptr);
232+
ASSERT_NE(control_switch_p4rt_session, nullptr);
233+
212234
ASSERT_OK_AND_ASSIGN(
213235
p4::v1::GetForwardingPipelineConfigResponse sut_config,
214236
pdpi::GetForwardingPipelineConfig(sut_p4rt_session.get()));
@@ -217,33 +239,158 @@ TEST_P(AclFeatureTestFixture, AclDenyAction) {
217239
ASSERT_OK_AND_ASSIGN(pdpi::IrP4Info sut_ir_p4info,
218240
pdpi::CreateIrP4Info(sut_config.config().p4info()));
219241

220-
ASSERT_OK(pdpi::ClearTableEntries(sut_p4rt_session.get()));
221-
222242
// Get control ports to test on.
223243
ASSERT_OK_AND_ASSIGN(
224244
auto gnmi_stub_control,
225245
GetParam().mirror_testbed->GetMirrorTestbed().Sut().CreateGnmiStub());
226246
ASSERT_OK_AND_ASSIGN(std::string control_port,
227247
pins_test::GetAnyUpInterfacePortId(*gnmi_stub_control));
228248

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+
229253
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);
231257

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
233305
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();
246384
}
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));
247394
}
248395

249396
} // 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)