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

[P4Testgen] Add an option to selectively ignore control plane elements. #4417

Merged
merged 4 commits into from
Feb 29, 2024

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Feb 12, 2024

This PR adds an option to skip generating control plane configurations for specified control plane elements. The input is a comma-separated list of the fully-qualified control-plane name. For example, "ingress.acl_table,ingress.fwd_table".

Currently, skipping is only supported for P4 tables, but could be extended to any element. Registers, Meters, Parser Value sets...

@fruffy fruffy added the p4tools Topics related to the P4Tools back end label Feb 12, 2024
@fruffy fruffy force-pushed the fruffy/testgen_library_api branch 4 times, most recently from 7ab31fa to 94feeaf Compare February 13, 2024 01:05
Base automatically changed from fruffy/testgen_library_api to main February 13, 2024 02:59
@fruffy fruffy force-pushed the fruffy/ignore_control_plane_elements branch 2 times, most recently from e8e922b to 0a84e2d Compare February 13, 2024 12:39
@fruffy fruffy requested review from smolkaj and jonathan-dilorenzo and removed request for smolkaj February 13, 2024 13:31
@fruffy fruffy force-pushed the fruffy/ignore_control_plane_elements branch from 0a84e2d to 986ec6b Compare February 15, 2024 12:46
backends/p4tools/modules/testgen/options.h Show resolved Hide resolved
// If the table is in the set of entities to skip, we set it immutable.
// P4Testgen will not add a control plane entry for this table.
if (TestgenOptions::get().skippedControlPlaneEntities.count(properties.tableName) != 0U) {
properties.tableIsImmutable = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkTableImmutability is setting this property based on what's passed in instead? I guess not technically part of this PR, but not a great way to go... Can you just make it 'IsTableImmutable' and then set the property in the same way you do here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation for checkTableImmutability is this one:

void checkTableImmutability(const IR::P4Table &table, TableProperties &properties) {
    bool isConstant = false;
    const auto *entriesAnnotation = table.properties->getProperty("entries");
    if (entriesAnnotation != nullptr) {
        isConstant = entriesAnnotation->isConstant;
    }
    // Also check if the table is invisible to the control plane.
    // This also implies that it cannot be modified.
    properties.tableIsImmutable = isConstant || table.getAnnotation("hidden") != nullptr;
    const auto *defaultAction = table.properties->getProperty("default_action");
    CHECK_NULL(defaultAction);
    properties.defaultIsImmutable = defaultAction->isConstant;
}

It also sets defaultIsImmutable. The main reason the function was constructed this way is because other extensions may pass in an extended TableProperties class. For example, TofinoTableProperties.

The implementation can definitely be improved, I can try to refactor this in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. Ok. I would defer to you on how clear the implementation is versus the breadth that it needs to support. Looks pretty fine to me tbh. It just threw me off that they were setting the same value and looked totally different.

backends/p4tools/modules/testgen/options.cpp Outdated Show resolved Hide resolved

TEST(P4TestgenControlPlaneFilterTest, FiltersControlPlaneEntities) {
std::stringstream streamTest;
streamTest << R"p4(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you make these manually every time... But would it be worth just having a function that returns something like this for all of your tests?

Regardless, you're probably better off putting this in a function here and then calling it in multiple tests. It would make it more natural to test e.g. what happens if you're given a non-existent control plane entity. Or one that isn't supported yet?

It looks like it would just be ignored effectively. Is that what you want to have happen? Do you want to do greater validation and give an Unimplemented error or an InvalidArgument error depending on the situation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you make these manually every time... But would it be worth just having a function that returns something like this for all of your tests?

Yes! I thought about this, but I figured I should wait until have more clarity on the test patterns, e.g., what elements and headers I keep reusing.

It looks like it would just be ignored effectively. Is that what you want to have happen?

So this was intentional. Mostly because P4Testgen currently does not have a collection of valid control-plane elements. I first would need to create that collection in a target-independent manner (since BMv2 has different control-plane elements to Tofino or the DPDK-target), then perform the lookup. Presumably I could do this with a P4Info, but again not every extension uses that either.

It would be nice to have that validation, but it will require some work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It seems fine to skip the validation (I think that's fairly typical), but I would prefer to have some tests with those cases showing that nothing catastrophic happens at least. I think that's the only change I really would want to see.

And again, I would recommend doing it (at least locally in this file) by factoring out the P4 program creating to a function that you call in ~4 different test cases (showing that it works with 1 or multiple tables, and the behavior with a not-yet-supported and non-existent entity).

@fruffy fruffy force-pushed the fruffy/ignore_control_plane_elements branch 4 times, most recently from 99a164c to 9ddb6ea Compare February 22, 2024 01:42
ASSERT_TRUE(testListOpt.has_value());
auto testList = testListOpt.value();
ASSERT_EQ(testList.size(), 2);
const auto *testWithDrop = testList[0]->checkedTo<P4Tools::P4Testgen::Bmv2::ProtobufIrTest>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be clear why you always expect the drop one to be first? Seems like an implementation detail? Probably better to loop through them and check that at least one is a drop and at least one exercises NoAction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to implement something here. Any way to use a lambda in Protobuf matchers? Currently I need to convert the entire vector to strings before passing them to the matchers.

@fruffy fruffy force-pushed the fruffy/ignore_control_plane_elements branch from 2914c04 to b1ca94c Compare February 29, 2024 14:12
@fruffy fruffy added this pull request to the merge queue Feb 29, 2024
Merged via the queue into main with commit 979c90e Feb 29, 2024
17 checks passed
@fruffy fruffy deleted the fruffy/ignore_control_plane_elements branch February 29, 2024 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4tools Topics related to the P4Tools back end
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants