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

Change "private" v1model standard_metadata fields to BMv2 packet regi… #768

Merged
merged 6 commits into from
Apr 25, 2019
Merged

Change "private" v1model standard_metadata fields to BMv2 packet regi… #768

merged 6 commits into from
Apr 25, 2019

Conversation

jafingerhut
Copy link
Contributor

…sters

Remove the use of the following 4 fields from BMv2 simple_switch and
simple_switch_grpc. They no longer need to be in the BMv2 JSON file
for such programs, and clone, recirculate, resubmit, and digest
operations are still able to work without them there, because they are
now stored in a BMv2 "packet register", similar to how the packet
length field currently is.

  • clone_spec
  • resubmit_flag
  • recirculate_flag
  • lf_field_list

…sters

Remove the use of the following 4 fields from BMv2 simple_switch and
simple_switch_grpc.  They no longer need to be in the BMv2 JSON file
for such programs, and clone, recirculate, resubmit, and digest
operations are still able to work without them there, because they are
now stored in a BMv2 "packet register", similar to how the packet
length field currently is.

+ clone_spec
+ resubmit_flag
+ recirculate_flag
+ lf_field_list
@jafingerhut
Copy link
Contributor Author

A first draft of modifying simple_switch and simple_switch_grpc so that they no longer access clone_spec, lf_field_list, resubmit_flag, and recirculate_flag in the BMv2 JSON file, and those fields thus need not be in the JSON file at all in order for the corresponding features to work.

If any of this looks like bad C++, it probably is. Let me know what I've done badly, and hopefully I will learn.

@jafingerhut
Copy link
Contributor Author

jafingerhut commented Apr 23, 2019

Forgot to mention: I have run all of the p4c automated tests on my local dev machine with this modified version of simple_switch, and except for clone-bmv2.p4 they all pass. That test appears fairly old, and has no STF test, so could probably be removed.

I also got all of those tests to pass when run with some slightly different changes that continued to maintain the fields the old way and the new way simultaneously, and crashed the program if the values ever differed when they were read in order to be used. That gives me pretty high assurance that it behaves identically with the old way of doing things.

@codecov-io
Copy link

codecov-io commented Apr 23, 2019

Codecov Report

Merging #768 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #768      +/-   ##
==========================================
+ Coverage   74.32%   74.33%   +<.01%     
==========================================
  Files         115      115              
  Lines       10136    10136              
==========================================
+ Hits         7534     7535       +1     
+ Misses       2602     2601       -1
Impacted Files Coverage Δ
include/bm/bm_sim/packet.h 100% <ø> (ø) ⬆️
src/bm_sim/learning.cpp 82.06% <0%> (+0.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d5ff720...009302c. Read the comment docs.

Copy link
Member

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

design looks sound to me

targets/simple_switch/register_access.h Outdated Show resolved Hide resolved
targets/simple_switch/register_access.h Outdated Show resolved Hide resolved
targets/simple_switch/register_access.h Outdated Show resolved Hide resolved
targets/simple_switch/simple_switch.cpp Outdated Show resolved Hide resolved
include/bm/bm_sim/packet.h Outdated Show resolved Hide resolved
f_clone_spec.add(f_clone_spec, clone_spec);
void operator ()(const Data &mirror_session_id, const Data &field_list_id) {
auto &packet = get_packet();
// Assume mirror_session_id < (1u << 15) so that we can use most
Copy link
Member

Choose a reason for hiding this comment

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

Could we enforce this when the control-plane creates a session here: https://github.com/p4lang/behavioral-model/blob/master/targets/simple_switch/simple_switch.cpp#L78, i.e. log an error and return false is the session id is >= (1 << 15)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this

targets/simple_switch/register_access.h Outdated Show resolved Hide resolved
Also add range checking on mirror session id values when control plane
tries to add or delete one.
Copy link
Member

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -75,13 +76,23 @@ class SimpleSwitch::MirroringSessions {
bool add_session(mirror_id_t mirror_id,
const MirroringSessionConfig &config) {
Lock lock(mutex);
sessions_map[mirror_id] = config;
return true;
if (0 <= mirror_id && mirror_id <= RegisterAccess::MAX_MIRROR_SESSION_ID) {
Copy link
Member

Choose a reason for hiding this comment

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

you must be the kind of person that uses 100[array] for array access :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only in an obfuscated code contest :) But I'm missing what about that code change was odd enough to make you think that?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's just a mater of habit, I never write 0 <= x instead of x >= 0, so my brain was frozen for a second.

@antoninbas antoninbas merged commit 7cd8d68 into p4lang:master Apr 25, 2019
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.

3 participants