-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a P4Info API to the control-plane folder and P4Tools. #4381
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor nits, otherwise looks great to me!
P4InfoMaps(const P4InfoMaps &) = default; | ||
P4InfoMaps(P4InfoMaps &&) = default; | ||
P4InfoMaps &operator=(const P4InfoMaps &) = default; | ||
P4InfoMaps &operator=(P4InfoMaps &&) = default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: lines 50-53 are automatically generated by the compiler, right? So at least at Google, we tend to omit them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do, this code is also auotgenerated by my development environment.
|
||
/// Looks up the P4Runtime id for the given control plane name in the pre-computed P4Runtime-ID | ||
/// map. @returns std::nullopt if the name is not in the map. | ||
[[nodiscard]] std::optional<uint64_t> lookupP4RuntimeId(cstring controlPlaneName) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "lookup" -> "lookUp"?
"lookup" to me is a noun or perhaps adjective, "look up" is the verb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto once more below.
// In case things change down the road. | ||
static_assert(std::is_convertible_v<p4rt_id_t, uint32_t> && | ||
std::is_same_v<p4rt_id_t, uint32_t>); | ||
return x >= y ? static_cast<uint64_t>(x) * x + x + y : x + static_cast<uint64_t>(y) * y; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to wiki?
uint64_t szudzikPairing(p4rt_id_t x, p4rt_id_t y); | ||
|
||
/// This object maps P4 control plane names to their P4Runtime IDs and vice versa. | ||
/// It uses the P4Info object to populate the maps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we're additionally introducing new unique IDs for certain objects that do not have unique IDs in P4Runtime / the P4info? Can we document that?
control-plane/p4infoApi.h
Outdated
namespace P4::ControlPlaneAPI { | ||
|
||
/// Generic meta function which searches an object by @name in the given range | ||
/// and @returns the P4Runtime representation, or std::nullopt if none is found. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to return a null pointer, not std::nullopt. Update documetnation?
Ditto one more time for the other overload
test/gtest/p4runtime.cpp
Outdated
ASSERT_TRUE(myDirectCounter1 != nullptr); | ||
EXPECT_EQ(unsigned(P4Ids::DIRECT_COUNTER), myDirectCounter1->preamble().id() >> 24); | ||
EXPECT_EQ(myDirectCounter1->preamble().id(), myTable1->direct_resource_ids(0)); | ||
} | ||
// checks that myDirectCounter2 with the right ID prefix | ||
{ | ||
auto *myTable2 = findTable(*test, "myTable2"); | ||
auto myTable2 = findP4RuntimeTable(*test->p4Info, "myTable2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Here and always, would recommend auto* over auto for pointers, as before.
94dd67a
to
cbc581b
Compare
This PR adds an API to look up P4Runtime objects in the P4Info file. Unlike the
P4RuntimeSymbolTable
, which needs to be explicitly initialized, this API only requires the corresponding P4Info file to look up objects. Additionally, it is possible to look up an object using its ID. This API was partially moved out of thep4runtime.cpp
gtest. It seemed generally useful. The API is also tested using this file.P4RuntimeMaps
is a simple class to cache these pairings of ID and control-plane name. It is constructed from the provided P4Runtime file. For elements such as parameters or matches, which may depend on a parent table, we compute a unique combination of the parameter id and the table parent id using a pairing function (http://szudzik.com/ElegantPairing.pdf).