Skip to content
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

Omit tables/actions with @hidden from p4runtime #476

Merged
merged 1 commit into from
Apr 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions control-plane/p4RuntimeSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ static bool isMetadataType(const IR::Type* type) {
return metadataAnnotation != nullptr;
}

/// @return true if @node has an @hidden annotation.
static bool isHidden(const IR::Node* node) {
if (!node->is<IR::IAnnotated>()) return false;
auto annotations = node->to<IR::IAnnotated>()->getAnnotations();
auto hiddenAnnotation = annotations->getSingle("hidden");
return hiddenAnnotation != nullptr;
}

/// @return a version of @name which has been sanitized for exposure to the
/// control plane.
static cstring controlPlaneName(const cstring& name) {
Expand Down Expand Up @@ -891,6 +899,8 @@ class P4RuntimeSerializer {
}

void addAction(const IR::P4Action* actionDeclaration) {
if (isHidden(actionDeclaration)) return;

auto name = controlPlaneName(actionDeclaration);
auto id = symbols.getId(P4RuntimeSymbolType::ACTION, name);
auto annotations = actionDeclaration->to<IR::IAnnotated>();
Expand Down Expand Up @@ -954,6 +964,8 @@ class P4RuntimeSerializer {
const std::vector<cstring>& actions,
const std::vector<MatchField>& matchFields,
bool supportsTimeout) {
if (isHidden(tableDeclaration)) return;

auto name = controlPlaneName(tableDeclaration);
auto annotations = tableDeclaration->to<IR::IAnnotated>();

Expand Down