Skip to content

Commit b7be7b7

Browse files
kishanpsbibhuprasad-hcl
authored andcommitted
[Comb] Migrate from the ordered_map in PDPI to GUtil.
Signed-off-by: Bibhuprasad Singh <bibhuprasad@google.com> Signed-off-by: bibhuprasad-hcl <bibhuprasad.singh@hcltech.com>
1 parent 67b12a1 commit b7be7b7

33 files changed

+111
-141
lines changed

dvaas/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ cc_test(
122122
":dvaas_detective",
123123
":dvaas_detective_cc_proto",
124124
":test_vector_cc_proto",
125-
"//p4_pdpi/internal:ordered_map",
126125
"//p4_pdpi/packetlib:packetlib_cc_proto",
127126
"@com_google_absl//absl/container:flat_hash_map",
128127
"@com_google_absl//absl/status",
129128
"@com_google_googletest//:gtest_main",
129+
"@com_google_gutil//gutil:ordered_map",
130130
"@com_google_gutil//gutil:proto",
131131
"@com_google_gutil//gutil:testing",
132132
"@com_google_gutil//gutil:status_matchers",

dvaas/dvaas_detective_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
#include "gmock/gmock.h"
3636
#include "gtest/gtest.h"
3737
#include "gutil/proto.h"
38+
#include "gutil/ordered_map.h"
3839
#include "gutil/status_matchers.h"
3940
#include "gutil/testing.h"
40-
#include "p4_pdpi/internal/ordered_map.h"
4141
#include "p4_pdpi/packetlib/packetlib.pb.h"
4242
#include "yggdrasil_decision_forests/dataset/data_spec.pb.h"
4343
#include "yggdrasil_decision_forests/model/decision_tree/decision_tree.h"

p4_fuzzer/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ cc_library(
3131
"//p4_pdpi:ir",
3232
"//p4_pdpi:ir_cc_proto",
3333
"//p4_pdpi:translation_options",
34-
"//p4_pdpi/internal:ordered_map",
3534
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
3635
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
3736
"@com_google_absl//absl/container:btree",
@@ -46,6 +45,7 @@ cc_library(
4645
"@com_google_absl//absl/types:span",
4746
"@com_google_protobuf//:protobuf",
4847
"@com_google_gutil//gutil:collections",
48+
"@com_google_gutil//gutil:ordered_map",
4949
"@com_google_gutil//gutil:proto",
5050
"@com_google_gutil//gutil:status",
5151
],
@@ -147,7 +147,6 @@ cc_library(
147147
"//p4_pdpi:ir_cc_proto",
148148
"//p4_pdpi:ir_properties",
149149
"//p4_pdpi:references",
150-
"//p4_pdpi/internal:ordered_map",
151150
"//p4_pdpi/netaddr:ipv6_address",
152151
"//p4_pdpi/string_encodings:byte_string",
153152
"//p4_pdpi/utils:ir",
@@ -175,6 +174,7 @@ cc_library(
175174
"@com_google_absl//absl/types:span",
176175
"@com_google_protobuf//:protobuf",
177176
"@com_google_gutil//gutil:collections",
177+
"@com_google_gutil//gutil:ordered_map",
178178
"@com_google_gutil//gutil:proto",
179179
"@com_google_gutil//gutil:status",
180180
],
@@ -297,7 +297,6 @@ cc_library(
297297
":switch_state",
298298
"//lib/p4rt:p4rt_port",
299299
"//p4_pdpi:ir_cc_proto",
300-
"//p4_pdpi/internal:ordered_map",
301300
"//p4_pdpi/testing:test_p4info_cc",
302301
"//sai_p4/instantiations/google:sai_p4info_cc",
303302
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
@@ -306,6 +305,7 @@ cc_library(
306305
"@com_google_absl//absl/status",
307306
"@com_google_absl//absl/status:statusor",
308307
"@com_google_absl//absl/strings",
308+
"@com_google_gutil//gutil:ordered_map",
309309
],
310310
)
311311

p4_fuzzer/constraints.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "absl/strings/string_view.h"
2727
#include "absl/strings/substitute.h"
2828
#include "gutil/collections.h"
29+
#include "gutil/ordered_map.h"
2930
#include "gutil/status.h"
3031
#include "p4/config/v1/p4info.pb.h"
3132
#include "p4/v1/p4runtime.pb.h"
@@ -40,7 +41,6 @@
4041
#include "p4_fuzzer/fuzz_util.h"
4142
#include "p4_fuzzer/fuzzer_config.h"
4243
#include "p4_fuzzer/switch_state.h"
43-
#include "p4_pdpi/internal/ordered_map.h"
4444
#include "p4_pdpi/ir.pb.h"
4545
#include "p4_pdpi/ir_properties.h"
4646

@@ -199,7 +199,7 @@ absl::StatusOr<TableEntry> FuzzValidConstrainedTableEntry(
199199

200200
// Fuzz all skipped keys normally.
201201
for (const auto& [name, match_field_def] :
202-
Ordered(table.match_fields_by_name())) {
202+
gutil::AsOrderedView(table.match_fields_by_name())) {
203203
ASSIGN_OR_RETURN(std::string fully_qualified_name,
204204
GetFullyQualifiedMatchFieldName(table, match_field_def));
205205
if (IsDisabledForFuzzing(config, fully_qualified_name)) {

p4_fuzzer/fuzz_util.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "google/protobuf/repeated_field.h"
4141
#include "google/protobuf/repeated_ptr_field.h"
4242
#include "gutil/collections.h"
43+
#include "gutil/ordered_map.h"
4344
#include "gutil/proto.h"
4445
#include "gutil/status.h"
4546
#include "lib/p4rt/p4rt_port.h"
@@ -53,7 +54,6 @@
5354
#include "p4_fuzzer/switch_state.h"
5455
#include "p4_pdpi/built_ins.h"
5556
#include "p4_pdpi/entity_keys.h"
56-
#include "p4_pdpi/internal/ordered_map.h"
5757
#include "p4_pdpi/ir.pb.h"
5858
#include "p4_pdpi/netaddr/ipv6_address.h"
5959
#include "p4_pdpi/references.h"
@@ -65,6 +65,7 @@ namespace p4_fuzzer {
6565
using ::absl::gntohll;
6666

6767
using ::absl::Uniform;
68+
using ::gutil::AsOrderedView;
6869
using ::p4::v1::Action;
6970
using ::p4::v1::Entity;
7071
using ::p4::v1::FieldMatch;
@@ -566,7 +567,7 @@ std::vector<uint32_t> GetMandatoryMatchTableIds(const FuzzerConfig& config) {
566567
std::vector<uint32_t> table_ids;
567568

568569
for (const IrTableDefinition& table : AllValidTablesForP4RtRole(config)) {
569-
for (auto& [match_id, match] : Ordered(table.match_fields_by_id())) {
570+
for (auto& [match_id, match] : AsOrderedView(table.match_fields_by_id())) {
570571
if (match.match_field().match_type() ==
571572
p4::config::v1::MatchField::EXACT) {
572573
table_ids.push_back(table.preamble().id());
@@ -582,7 +583,7 @@ std::vector<uint32_t> GetMandatoryMatchTableIds(const FuzzerConfig& config) {
582583
std::vector<uint32_t> GetDifferentRoleTableIds(const FuzzerConfig& config) {
583584
std::vector<uint32_t> table_ids;
584585

585-
for (auto& [key, table] : Ordered(config.GetIrP4Info().tables_by_id())) {
586+
for (auto& [key, table] : AsOrderedView(config.GetIrP4Info().tables_by_id())) {
586587
if (table.role() == config.GetRole()) continue;
587588
table_ids.push_back(key);
588589
}
@@ -1016,7 +1017,7 @@ struct VariableWithReferences {
10161017
absl::StatusOr<p4::config::v1::ActionProfile> GetActionProfile(
10171018
const pdpi::IrP4Info& ir_info, int table_id) {
10181019
for (const auto& [id, action_profile_definition] :
1019-
Ordered(ir_info.action_profiles_by_id())) {
1020+
AsOrderedView(ir_info.action_profiles_by_id())) {
10201021
if (action_profile_definition.has_action_profile()) {
10211022
// Does the action profile apply to the given table?
10221023
auto& action_profile = action_profile_definition.action_profile();
@@ -1034,7 +1035,7 @@ const std::vector<IrTableDefinition> AllValidTablesForP4RtRole(
10341035
const FuzzerConfig& config) {
10351036
std::vector<IrTableDefinition> tables;
10361037

1037-
for (auto& [key, table] : Ordered(config.GetIrP4Info().tables_by_id())) {
1038+
for (auto& [key, table] : AsOrderedView(config.GetIrP4Info().tables_by_id())) {
10381039
// Tables with the wrong role can't be modified by the controller.
10391040
if (table.role() != config.GetRole()) continue;
10401041
// Tables without actions cannot have valid table entries.
@@ -1070,7 +1071,7 @@ const std::vector<pdpi::IrMatchFieldDefinition> AllValidMatchFields(
10701071
std::vector<pdpi::IrMatchFieldDefinition> match_fields;
10711072

10721073
for (const auto& [_, match_field_info] :
1073-
Ordered(table.match_fields_by_id())) {
1074+
AsOrderedView(table.match_fields_by_id())) {
10741075
// Skip deprecated, unused, and disallowed fields.
10751076
const absl::StatusOr<std::string> fully_qualified_match_field =
10761077
GetFullyQualifiedMatchFieldName(table, match_field_info);
@@ -1366,7 +1367,7 @@ absl::StatusOr<p4::v1::Action> FuzzAction(
13661367
action.set_action_id(ir_action_info.preamble().id());
13671368

13681369
for (auto& [param_name, ir_param] :
1369-
Ordered(ir_action_info.params_by_name())) {
1370+
AsOrderedView(ir_action_info.params_by_name())) {
13701371
p4::v1::Action::Param* param = action.add_params();
13711372
param->set_param_id(ir_param.param().id());
13721373
ASSIGN_OR_RETURN(

p4_fuzzer/mutation.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,27 @@
1313
// limitations under the License.
1414
#include "p4_fuzzer/mutation.h"
1515

16+
#include <cstdint>
17+
#include <string>
18+
#include <vector>
19+
1620
#include "absl/algorithm/container.h"
21+
#include "absl/log/log.h"
22+
#include "absl/random/random.h"
1723
#include "absl/status/status.h"
1824
#include "gutil/collections.h"
25+
#include "gutil/ordered_map.h"
26+
#include "gutil/status.h"
1927
#include "p4/v1/p4runtime.pb.h"
2028
#include "p4_fuzzer/fuzz_util.h"
2129
#include "p4_fuzzer/fuzzer_config.h"
22-
#include "p4_pdpi/internal/ordered_map.h"
30+
#include "p4_fuzzer/switch_state.h"
2331

2432
namespace p4_fuzzer {
2533

2634
using ::absl::BitGen;
2735
using ::absl::Uniform;
36+
using ::gutil::AsOrderedView;
2837
using ::p4::v1::TableEntry;
2938

3039
namespace {
@@ -45,7 +54,7 @@ const std::vector<uint32_t> AllTableIds(const FuzzerConfig& config) {
4554
std::vector<uint32_t> table_ids;
4655

4756
for (auto& [table_id, table_def] :
48-
Ordered(config.GetIrP4Info().tables_by_id())) {
57+
AsOrderedView(config.GetIrP4Info().tables_by_id())) {
4958
table_ids.push_back(table_id);
5059
}
5160

@@ -57,7 +66,7 @@ const std::vector<uint32_t> AllActionIds(const FuzzerConfig& config) {
5766
std::vector<uint32_t> action_ids;
5867

5968
for (auto& [action_id, action_def] :
60-
Ordered(config.GetIrP4Info().actions_by_id())) {
69+
AsOrderedView(config.GetIrP4Info().actions_by_id())) {
6170
action_ids.push_back(action_id);
6271
}
6372

@@ -71,7 +80,7 @@ const std::vector<uint32_t> AllMatchFieldIds(const FuzzerConfig& config,
7180
std::vector<uint32_t> match_ids;
7281

7382
for (auto& [match_id, match_def] :
74-
Ordered(gutil::FindOrDie(config.GetIrP4Info().tables_by_id(), table_id)
83+
AsOrderedView(gutil::FindOrDie(config.GetIrP4Info().tables_by_id(), table_id)
7584
.match_fields_by_id())) {
7685
match_ids.push_back(match_id);
7786
}

p4_fuzzer/switch_state.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
#include "absl/types/span.h"
3535
#include "google/protobuf/util/message_differencer.h"
3636
#include "gutil/collections.h"
37+
#include "gutil/ordered_map.h"
3738
#include "gutil/proto.h"
3839
#include "gutil/status.h"
3940
#include "p4/config/v1/p4info.pb.h"
4041
#include "p4/v1/p4runtime.pb.h"
4142
#include "p4_pdpi/built_ins.h"
4243
#include "p4_pdpi/entity_keys.h"
43-
#include "p4_pdpi/internal/ordered_map.h"
4444
#include "p4_pdpi/ir.h"
4545
#include "p4_pdpi/ir.pb.h"
4646
#include "p4_pdpi/translation_options.h"
@@ -926,7 +926,7 @@ std::string SwitchState::SwitchStateSummary() const {
926926
if (ordered_tables_.empty()) return std::string("EmptyState()");
927927
std::string res = "";
928928
// Ordered is used to get a deterministic order for the summary.
929-
for (const auto& [table_id, table] : Ordered(ordered_tables_)) {
929+
for (const auto& [table_id, table] : gutil::AsOrderedView(ordered_tables_)) {
930930
const pdpi::IrTableDefinition& table_definition =
931931
FindOrDie(ir_p4info_.tables_by_id(), table_id);
932932
const std::string& table_name = table_definition.preamble().alias();

p4_fuzzer/test_utils.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@
1616
#include <string>
1717

1818
#include "absl/status/status.h"
19+
#include "absl/strings/str_cat.h"
1920
#include "absl/status/statusor.h"
2021
#include "absl/strings/substitute.h"
22+
#include "gutil/ordered_map.h"
2123
#include "gutil/status.h"
2224
#include "lib/p4rt/p4rt_port.h"
2325
#include "p4/config/v1/p4info.pb.h"
2426
#include "p4/v1/p4runtime.pb.h"
2527
#include "p4_fuzzer/fuzzer_config.h"
2628
#include "p4_fuzzer/switch_state.h"
27-
#include "p4_pdpi/internal/ordered_map.h"
2829
#include "p4_pdpi/ir.pb.h"
2930

3031
namespace p4_fuzzer {
32+
33+
using ::gutil::AsOrderedView;
34+
3135
absl::StatusOr<FuzzerTestState> ConstructFuzzerTestState(
3236
const p4::config::v1::P4Info& info, const std::string& role) {
3337
ASSIGN_OR_RETURN(
@@ -52,7 +56,7 @@ GetAMatchFieldDefinitionWithMatchType(
5256
const pdpi::IrTableDefinition& table_definition,
5357
p4::config::v1::MatchField::MatchType match_type) {
5458
for (const auto& [unused, match_field] :
55-
Ordered(table_definition.match_fields_by_id())) {
59+
AsOrderedView(table_definition.match_fields_by_id())) {
5660
if (match_field.match_field().match_type() == match_type) {
5761
return match_field;
5862
}
@@ -67,7 +71,7 @@ absl::StatusOr<pdpi::IrTableDefinition> GetATableDefinitionWithMatchType(
6771
const FuzzerTestState& fuzzer_state,
6872
p4::config::v1::MatchField::MatchType match_type) {
6973
for (const auto& [unused, table] :
70-
Ordered(fuzzer_state.config.GetIrP4Info().tables_by_id())) {
74+
AsOrderedView(fuzzer_state.config.GetIrP4Info().tables_by_id())) {
7175
if (GetAMatchFieldDefinitionWithMatchType(table, match_type).ok()) {
7276
return table;
7377
}
@@ -79,7 +83,7 @@ absl::StatusOr<pdpi::IrTableDefinition> GetATableDefinitionWithMatchType(
7983

8084
absl::StatusOr<pdpi::IrTableDefinition> GetAOneShotTableDefinition(
8185
const pdpi::IrP4Info& info) {
82-
for (const auto& [unused, table] : Ordered(info.tables_by_id())) {
86+
for (const auto& [unused, table] : AsOrderedView(info.tables_by_id())) {
8387
if (table.uses_oneshot()) {
8488
return table;
8589
}

p4_pdpi/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ cc_library(
9696
deps = [
9797
":built_ins",
9898
":ir_cc_proto",
99-
"//p4_pdpi/internal:ordered_map",
10099
"//p4_pdpi/utils:annotation_parser",
101100
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
102101
"@com_google_absl//absl/container:btree",
@@ -107,6 +106,7 @@ cc_library(
107106
"@com_google_absl//absl/strings:string_view",
108107
"@com_google_protobuf//:protobuf",
109108
"@com_google_gutil//gutil:collections",
109+
"@com_google_gutil//gutil:ordered_map",
110110
"@com_google_gutil//gutil:status",
111111
],
112112
)
@@ -205,7 +205,6 @@ cc_library(
205205
":ir",
206206
":ir_cc_proto",
207207
":translation_options",
208-
"//p4_pdpi/internal:ordered_map",
209208
"//p4_pdpi/string_encodings:hex_string",
210209
"//p4_pdpi/utils:ir",
211210
"@com_github_grpc_grpc//:grpc++",
@@ -221,6 +220,7 @@ cc_library(
221220
"@com_google_googleapis//google/rpc:status_cc_proto",
222221
"@com_google_protobuf//:protobuf",
223222
"@com_google_gutil//gutil:collections",
223+
"@com_google_gutil//gutil:ordered_map",
224224
"@com_google_gutil//gutil:proto",
225225
"@com_google_gutil//gutil:status",
226226
],
@@ -254,12 +254,12 @@ cc_library(
254254
deps = [
255255
":ir_cc_proto",
256256
":pd",
257-
"//p4_pdpi/internal:ordered_map",
258257
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
259258
"@com_google_absl//absl/container:flat_hash_set",
260259
"@com_google_absl//absl/status:statusor",
261260
"@com_google_absl//absl/strings",
262261
"@com_google_gutil//gutil:collections",
262+
"@com_google_gutil//gutil:ordered_map",
263263
"@com_google_gutil//gutil:status",
264264
],
265265
)

p4_pdpi/internal/BUILD.bazel

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)