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

Fix counters attribute name #639

Merged
merged 1 commit into from
Jun 5, 2017
Merged

Fix counters attribute name #639

merged 1 commit into from
Jun 5, 2017

Conversation

ChrisDodd
Copy link
Contributor

Fix (partly) issue #461

A good example why obfuscating string constants behind static constexpr "names" is a bad idea -- makes the code harder to read and maintain and makes it easier for bugs to creep in.

Arguably we should add a check for count calls on counters that are not named in the table attributes. Whether that should be an error or should implicitly add said counter attribute is unclear.

@ChrisDodd ChrisDodd requested a review from hanw May 16, 2017 00:59
@mihaibudiu
Copy link
Contributor

I will commit soon an example where the extra indirection is actually good: we had changed default_only to defaultonly in the spec, but not in the code.

A question you are raising is whether a table can have simultaneously both counters and direct counters; in that case you may need to use two different properties.

@mihaibudiu
Copy link
Contributor

Actually, maybe I am wrong, and counters do not need a table property at all.

@@ -400,7 +400,7 @@ ControlConverter::convertTable(const CFG::TableNode* node,
size = BMV2::TableAttributes::defaultTableSize;

result->emplace("max_size", size);
auto ctrs = table->properties->getProperty(BMV2::TableImplementation::directCounterName);
auto ctrs = table->properties->getProperty(BMV2::TableAttributes::countersName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can just delete these from TableImplementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only change I am requesting: removal of the unused constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting replacing them with string constant literals? Or something else?

@ChrisDodd
Copy link
Contributor Author

Arguably we should reorganize this code to not look at the table properties at all, but instead just look at the extern method calls in actions on the table.

@mihaibudiu
Copy link
Contributor

In this case you will also need to do some more checks, e.g., that counters are not shared between different tables or that method calls only occur in actions.

@ChrisDodd
Copy link
Contributor Author

We need those checks regardless, independent of how we recognize which table(s) a counter or meter is attached to.

@ChrisDodd ChrisDodd force-pushed the cdodd branch 3 times, most recently from 7f0231c to b1da71f Compare May 24, 2017 22:23
@ChrisDodd ChrisDodd force-pushed the cdodd branch 2 times, most recently from f825eaf to f2030e4 Compare May 30, 2017 23:36
@mihaibudiu
Copy link
Contributor

I don't think we need both TableImplementation::directCounterName and TableATtributes::countersName. One of them should be just deleted.

@ChrisDodd
Copy link
Contributor Author

They're different -- TableImplementation::directCounterName is "direct_counter" and TableAttributes::countersName is "counters" -- the "counters" table attribute refers to a list of externs that must be either "direct_counter" or "counter" instances (TableImplementation::directCounterName or TableImplementation::counterName).

Whether we need the "counters" attribute at all is another question -- or is mentioning the counters (with a method call in an action of the table) enough? At the moment we check that the method calls and the "counters" attribute are consistent, and give an error if they are not (I think).

@mihaibudiu
Copy link
Contributor

OK, then I guess what we need is this kind of documentation - that you just typed - in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants