Skip to content

Commit

Permalink
[P4_symbolic] Enable secure connection for p4rt_route_test. Migrate p…
Browse files Browse the repository at this point in the history
…rogram to new SAI API for setting VRFs. update comments to use inclusive naming from github and p4.org Add route_metadata field and initializing logic to reflect the changes in SAI-P4 code. Remove program-specific structs mixed in with the generic API. (#626)



Co-authored-by: smolkaj <[email protected]>
Co-authored-by: kishanps <[email protected]>
Co-authored-by: kheradmandG <[email protected]>
  • Loading branch information
4 people authored Oct 19, 2024
1 parent 1ce0f49 commit 33cca1a
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 366 deletions.
2 changes: 1 addition & 1 deletion gutil/io.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion gutil/io.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions p4_fuzzer/fuzzer_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,13 @@ TEST_P(FuzzTest, P4rtWriteAndCheckNoInternalErrors) {
ASSERT_OK_AND_ASSIGN(
const pdpi::IrTableDefinition& table,
gutil::FindOrStatus(info.tables_by_id(), table_id));
// TODO: acl_lookup_table has a resource limit problem.
// TODO: acl_pre_ingress_table has a resource limit
// problem.
// TODO: router_interface_table, ipv4_table and
// ipv6_table all have resource limit problems.
// TODO: wcmp_group_table has a resource limit problem.
if (!(mask_known_failures &&
(table.preamble().alias() == "acl_lookup_table" ||
(table.preamble().alias() == "acl_pre_ingress_table" ||
table.preamble().alias() == "router_interface_table" ||
table.preamble().alias() == "ipv4_table" ||
table.preamble().alias() == "ipv6_table" ||
Expand Down
6 changes: 3 additions & 3 deletions p4_symbolic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ cc_binary(
],
deps = [
":parser",
"//gutil:io",
"//gutil:status",
"//p4_symbolic/bmv2",
"//p4_symbolic/sai:parser",
"//p4_symbolic/symbolic",
"//p4_symbolic/util",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/flags:usage",
Expand All @@ -45,15 +45,15 @@ cc_library(
srcs = ["parser.cc"],
hdrs = ["parser.h"],
deps = [
"//gutil:proto",
"//gutil:io",
"//gutil:proto",
"//gutil:status",
"//p4_pdpi:ir_cc_proto",
"//p4_symbolic/bmv2",
"//p4_symbolic/ir",
"//p4_symbolic/ir:ir_cc_proto",
"//p4_symbolic/ir:pdpi_driver",
"//p4_symbolic/symbolic",
"//p4_symbolic/util",
"@com_google_absl//absl/types:span",
],
)
Expand Down
4 changes: 2 additions & 2 deletions p4_symbolic/bmv2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ cc_library(
],
deps = [
":bmv2_cc_proto",
"//gutil:io",
"//gutil:status",
"//p4_symbolic/util",
"@com_google_protobuf//:protobuf",
],
)
Expand All @@ -55,8 +55,8 @@ cc_binary(
srcs = ["test.cc"],
deps = [
":bmv2",
"//gutil:io",
"//gutil:status",
"//p4_symbolic/util",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/flags:usage",
Expand Down
4 changes: 2 additions & 2 deletions p4_symbolic/bmv2/bmv2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#include <string>

#include "google/protobuf/util/json_util.h"
#include "gutil/io.h"
#include "gutil/status.h"
#include "p4_symbolic/util/io.h"

namespace p4_symbolic {
namespace bmv2 {

absl::StatusOr<P4Program> ParseBmv2JsonFile(const std::string &json_path) {
ASSIGN_OR_RETURN(std::string json, util::ReadFile(json_path));
ASSIGN_OR_RETURN(std::string json, gutil::ReadFile(json_path));
return ParseBmv2JsonString(json);
}

Expand Down
8 changes: 3 additions & 5 deletions p4_symbolic/bmv2/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include "absl/strings/str_format.h"
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/json_util.h"
#include "gutil/io.h"
#include "gutil/status.h"
#include "p4_symbolic/bmv2/bmv2.h"
#include "p4_symbolic/util/io.h"

ABSL_FLAG(std::string, bmv2, "", "The path to the bmv2 json file (required)");
ABSL_FLAG(std::string, protobuf, "",
Expand All @@ -55,8 +55,7 @@ absl::Status Test() {
p4_symbolic::bmv2::ParseBmv2JsonFile(bmv2_path.c_str()));

// Dumping protobuf.
RETURN_IF_ERROR(
p4_symbolic::util::WriteFile(bmv2.DebugString(), protobuf_path.c_str()));
RETURN_IF_ERROR(gutil::WriteFile(bmv2.DebugString(), protobuf_path.c_str()));

// Dumping JSON.
google::protobuf::util::JsonPrintOptions dumping_options;
Expand All @@ -68,8 +67,7 @@ absl::Status Test() {
RETURN_IF_ERROR(
gutil::ToAbslStatus(google::protobuf::util::MessageToJsonString(
bmv2, &json_output_str, dumping_options)));
RETURN_IF_ERROR(
p4_symbolic::util::WriteFile(json_output_str, json_path.c_str()));
RETURN_IF_ERROR(gutil::WriteFile(json_output_str, json_path.c_str()));

return absl::OkStatus();
}
Expand Down
2 changes: 1 addition & 1 deletion p4_symbolic/ir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ cc_library(
],
deps = [
":ir_cc_proto",
"//gutil:io",
"//gutil:status",
"//p4_pdpi:ir",
"//p4_pdpi:ir_cc_proto",
"//p4_symbolic/util",
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
Expand Down
4 changes: 2 additions & 2 deletions p4_symbolic/ir/ir.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Additionally, some types of expressions and statements are unsupported, these
// are described in the relevant sections of this file.
// See the bmv2 JSON format reference for more information:
// https://github.com/p4lang/behavioral-model/blob/master/docs/JSON_format.md
// https://github.com/p4lang/behavioral-model/blob/main/docs/JSON_format.md

syntax = "proto3";

Expand All @@ -51,7 +51,7 @@ message P4Program {

// TODO: If needed in the future, action calls can be added here, for
// action calls that are not wrapped in other control constructs.
// https://github.com/p4lang/behavioral-model/blob/master/docs/JSON_format.md#pipelines
// https://github.com/p4lang/behavioral-model/blob/main/docs/JSON_format.md#pipelines
}

// A header type definition.
Expand Down
2 changes: 1 addition & 1 deletion p4_symbolic/ir/table_entries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "gutil/io.h"
#include "gutil/status.h"
#include "p4/v1/p4runtime.pb.h"
#include "p4_pdpi/ir.h"
#include "p4_pdpi/ir.pb.h"
#include "p4_symbolic/util/io.h"

namespace p4_symbolic {
namespace ir {
Expand Down
5 changes: 2 additions & 3 deletions p4_symbolic/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "gutil/io.h"
#include "gutil/status.h"
#include "p4_symbolic/bmv2/bmv2.h"
#include "p4_symbolic/parser.h"
#include "p4_symbolic/sai/parser.h"
#include "p4_symbolic/symbolic/symbolic.h"
#include "p4_symbolic/util/io.h"

ABSL_FLAG(std::string, p4info, "",
"The path to the p4info protobuf file (required)");
Expand Down Expand Up @@ -173,8 +173,7 @@ absl::Status ParseAndEvaluate() {

// Debugging.
if (!debug_path.empty()) {
RETURN_IF_ERROR(
p4_symbolic::util::WriteFile(debug_smt_formula, debug_path));
RETURN_IF_ERROR(gutil::WriteFile(debug_smt_formula, debug_path));
}

return absl::OkStatus();
Expand Down
4 changes: 2 additions & 2 deletions p4_symbolic/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include "p4_symbolic/parser.h"

#include "gutil/io.h"
#include "gutil/proto.h"
#include "p4_symbolic/bmv2/bmv2.h"
#include "p4_symbolic/ir/ir.h"
#include "p4_symbolic/ir/pdpi_driver.h"
#include "p4_symbolic/util/io.h"

namespace p4_symbolic {

Expand Down Expand Up @@ -58,7 +58,7 @@ absl::StatusOr<symbolic::Dataplane> ParseToIr(
const std::string &bmv2_json_path, const std::string &p4info_path,
absl::Span<const p4::v1::TableEntry> table_entries) {
// Parse bmv2 json file into our initial bmv2 protobuf.
ASSIGN_OR_RETURN(std::string bmv2_json, util::ReadFile(bmv2_json_path));
ASSIGN_OR_RETURN(std::string bmv2_json, gutil::ReadFile(bmv2_json_path));

// Parse p4info file into pdpi format.
ASSIGN_OR_RETURN(pdpi::IrP4Info p4info,
Expand Down
5 changes: 5 additions & 0 deletions p4_symbolic/sai/fields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ absl::StatusOr<SaiFields> GetSaiFields(const SymbolicPerPacketState& state) {
.admit_to_l3 = get_metadata_field("admit_to_l3"),
.vrf_id = get_metadata_field("vrf_id"),
.mirror_session_id_valid = get_metadata_field("mirror_session_id_valid"),
.ingress_port = get_metadata_field("ingress_port"),
.route_metadata = get_metadata_field("route_metadata"),
};
auto standard_metadata = V1ModelStandardMetadata{
.ingress_port = get_field("standard_metadata.ingress_port"),
};

if (!errors.empty()) {
Expand Down
10 changes: 8 additions & 2 deletions p4_symbolic/sai/fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ struct SaiLocalMetadata {
z3::expr vrf_id;
// TODO: add `packet_rewrites` fields.
z3::expr mirror_session_id_valid;
// TODO: add `mirror*` fields.
// TODO: Add `color` field.
z3::expr ingress_port;
z3::expr route_metadata;
};

// Symbolic version of `struct standard_metadata_t` in v1model.p4
// TODO: Add missing fields, as needed.
struct V1ModelStandardMetadata {
z3::expr ingress_port;
};

struct SaiFields {
Expand Down
5 changes: 0 additions & 5 deletions p4_symbolic/symbolic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cc_library(
"control.cc",
"guarded_map.cc",
"operators.cc",
"packet.cc",
"symbolic.cc",
"table.cc",
"util.cc",
Expand All @@ -39,7 +38,6 @@ cc_library(
"control.h",
"guarded_map.h",
"operators.h",
"packet.h",
"symbolic.h",
"table.h",
"util.h",
Expand All @@ -59,10 +57,7 @@ cc_library(
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
"@com_github_z3prover_z3//:api",
"@com_gnu_gmp//:gmp",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/cleanup",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
Expand Down
76 changes: 0 additions & 76 deletions p4_symbolic/symbolic/packet.cc

This file was deleted.

40 changes: 0 additions & 40 deletions p4_symbolic/symbolic/packet.h

This file was deleted.

Loading

0 comments on commit 33cca1a

Please sign in to comment.