Skip to content

Commit 640bea8

Browse files
kishanpsdivyagayathri-hcl
authored andcommitted
[P4RT] Separate entry update -> AppDB parsing and DB installation.
1 parent 89e0d1d commit 640bea8

17 files changed

+1261
-927
lines changed

p4rt_app/p4runtime/BUILD.bazel

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ cc_library(
132132
srcs = ["p4runtime_impl.cc"],
133133
hdrs = ["p4runtime_impl.h"],
134134
deps = [
135+
":entity_update",
135136
":ir_translation",
136137
":p4info_verification",
137138
":p4runtime_read",
@@ -156,7 +157,6 @@ cc_library(
156157
"//p4rt_app/sonic:response_handler",
157158
"//p4rt_app/sonic:state_verification",
158159
"//p4rt_app/sonic:vrf_entry_translation",
159-
"//p4rt_app/sonic/adapters:table_adapter",
160160
"//p4rt_app/sonic/adapters:warm_boot_state_adapter",
161161
"//p4rt_app/utils:event_data_tracker",
162162
"//p4rt_app/utils:status_utility",
@@ -342,11 +342,11 @@ cc_library(
342342
srcs = ["resource_utilization.cc"],
343343
hdrs = ["resource_utilization.h"],
344344
deps = [
345+
":entity_update",
345346
"//gutil:collections",
346347
"//gutil:status",
347348
"//p4_pdpi:entity_keys",
348349
"//p4_pdpi:ir_cc_proto",
349-
"//p4rt_app/sonic:app_db_manager",
350350
"@com_github_google_glog//:glog",
351351
"@com_github_p4lang_p4runtime//:p4info_cc_proto",
352352
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
@@ -360,14 +360,14 @@ cc_test(
360360
name = "resource_utilization_test",
361361
srcs = ["resource_utilization_test.cc"],
362362
deps = [
363+
":entity_update",
363364
":resource_utilization",
364365
"//gutil:collections",
365366
"//gutil:status",
366367
"//gutil:status_matchers",
367368
"//p4_pdpi:entity_keys",
368369
"//p4_pdpi:ir",
369370
"//p4_pdpi:ir_cc_proto",
370-
"//p4rt_app/sonic:app_db_manager",
371371
"//sai_p4/instantiations/google:instantiations",
372372
"//sai_p4/instantiations/google:sai_p4info_cc",
373373
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
@@ -439,3 +439,14 @@ cc_test(
439439
"@com_google_googletest//:gtest_main",
440440
],
441441
)
442+
443+
cc_library(
444+
name = "entity_update",
445+
hdrs = ["entity_update.h"],
446+
deps = [
447+
"//p4_pdpi:entity_keys",
448+
"//p4_pdpi:ir_cc_proto",
449+
"//p4rt_app/sonic:app_db_manager",
450+
"@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
451+
],
452+
)

p4rt_app/p4runtime/entity_update.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifndef PINS_INFRA_P4RT_APP_P4RUNTIME_UPDATE_H_
15+
#define PINS_INFRA_P4RT_APP_P4RUNTIME_UPDATE_H_
16+
17+
#include <cstdint>
18+
#include <optional>
19+
#include <string>
20+
21+
#include "p4/v1/p4runtime.pb.h"
22+
#include "p4_pdpi/entity_keys.h"
23+
#include "p4_pdpi/ir.pb.h"
24+
#include "p4rt_app/sonic/app_db_manager.h"
25+
26+
namespace p4rt_app {
27+
28+
// This file defines data structures for managing individual update requests
29+
// from P4.
30+
31+
// Action profiles are used to model things like WCMP where we can have multiple
32+
// actions with different weights. Resource accounting can be measured either
33+
// against the total number of actions, or the sum total of all the action
34+
// weights.
35+
struct ActionProfileResources {
36+
std::string name;
37+
int32_t number_of_actions = 0;
38+
int64_t total_weight = 0;
39+
};
40+
41+
// Each table resource usually only counts as 1 (i.e. one table entry), but
42+
// depending on the table they may include an action profile (e.g. WCMP).
43+
struct TableResources {
44+
std::string name;
45+
std::optional<ActionProfileResources> action_profile;
46+
};
47+
48+
// This struct holds all the information needed to process a P4 update in P4RT.
49+
struct EntityUpdate {
50+
// The IR translation of the PI request.
51+
pdpi::IrEntity entry;
52+
53+
// Specifies if this request is an INSERT MODIFY or DELETE.
54+
p4::v1::Update::Type update_type;
55+
56+
// Normalized PI entities. Note this will be semantically the same as the
57+
// original request, but does not have to be syntactically the same.
58+
p4::v1::Entity pi_entity;
59+
60+
// A unique hash of the entries match fields. Used to identify duplicates and
61+
// any caching of entries.
62+
pdpi::EntityKey entity_key;
63+
64+
// The net utilization change for table entries with group actions. If the
65+
// update_type is an insert then this value will simply be the resources for
66+
// the entry. If the update_type is a modify then this value is the difference
67+
// between the new and old entries. If the update_type is a delete then this
68+
// value is the resources of the old entry.
69+
// Note: This is only relevant at the moment for tables with action profiles.
70+
TableResources resource_utilization_change;
71+
72+
// The AppDb format of for this update.
73+
sonic::AppDbUpdate app_db_update;
74+
75+
// A pointer to the response in the IrWriteResponse for this update.
76+
pdpi::IrUpdateStatus* status;
77+
};
78+
79+
} // namespace p4rt_app
80+
81+
#endif // PINS_INFRA_P4RT_APP_P4RUNTIME_UPDATE_H_

0 commit comments

Comments
 (0)