Skip to content

Conversation

usha1830
Copy link
Contributor

This PR adds support for PNA extern "mirror_packet"

extern void mirror_packet(MirrorSlotId_t mirror_slot_id,
                          MirrorSessionId_t mirror_session_id);

This translates to mirror instruction in dpdk
mirror <SLOT_ID> <SESSON_ID>
If the arguments are constants, they should be moved to Metadata as the mirror instruction in dpdk does not support immediate values as operands.

Added a valid test and a few negative tests.
Negative tests are added for the following:

  • Mirror session id 0 is reserved by the architecture, and must not be used by a P4 developer
  • Invoking mirror_packet(x) is supported from control blocks other than Main control
  • Passing incorrect number of arguments
  • Passing non-constant arguments

@@ -765,6 +765,33 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) {
} else {
::error("%1%: unhandled function", s);
}
} else if (a->method->name == "mirror_packet") {
auto slot_id = a->expr->arguments->at(0)->expression;
Copy link
Contributor

Choose a reason for hiding this comment

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

first you should check that there are exactly 2 arguments and give an error otherwise (probably a modelError).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No of arguments mismatch is caught by the frontend, I also added a test for that.
I can add the check to be on the safer side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a check.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is true, but you are assuming the users have loaded the correct pna file. But users can modify the pna file or load by mistake v1model.p4 instead of pna. Also, pna may change as time goes on. In these cases the compiler should not crash.

const IR::Expression *session_idexpr = session_id;
// mirror instruction supports only metadata as operands, move any constant arguments
// to metadata fields
if (slot_id->is<IR::Constant>()){
Copy link
Contributor

Choose a reason for hiding this comment

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

no space before {

auto tmpMember = new IR::Member(new IR::PathExpression("m"), tmpName);
add_instr(new IR::DpdkMovStatement(tmpMember, slot_id));
slot_idexpr = tmpMember;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

are you sure that anything that is not a constant will work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Frontend rejects the program if the arguments to mirror_packet are not compile-time constants. Updated the code to assert on this condition.

@usha1830
Copy link
Contributor Author

@mbudiu-vmw I have updated the code as per you comments. Please let me know if anything else is required.

@mihaibudiu mihaibudiu merged commit 810cb1b into p4lang:main Mar 16, 2022
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