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

Psa Extern Development Guide #779

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

derek-so
Copy link
Contributor

Added a README to the docs detailing high level steps on how to develop externs for PSA Switch.

@codecov-io
Copy link

Codecov Report

Merging #779 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #779   +/-   ##
=======================================
  Coverage   74.32%   74.32%           
=======================================
  Files         115      115           
  Lines       10138    10138           
=======================================
  Hits         7535     7535           
  Misses       2603     2603

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 e90ae59...e6797b8. Read the comment docs.

@jafingerhut
Copy link
Contributor

Thanks for creating the PR.

It looks like a reasonable level of detail to me. I have not gone through the process myself before, so can't currently make any intelligent comments on whether it is correct.

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.

Sorry for the late review

@@ -0,0 +1,82 @@
# Implementing Externs in PSA Switch
Externs in PSA Switch are different than those in Simple Switch.
Simple Switch uses externs baked into the BMV2 model where as PSA Switch
Copy link
Member

Choose a reason for hiding this comment

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

whereas?

[Simple Switch](https://github.com/p4lang/behavioral-model/tree/master/src/bm_sim)
and the one in
[PSA Switch](https://github.com/p4lang/behavioral-model/tree/master/targets/psa_switch/externs).
The Simple Switch counter lives inside of `src/bm_sim` where as the
Copy link
Member

Choose a reason for hiding this comment

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

whereas?

@@ -0,0 +1,82 @@
# Implementing Externs in PSA Switch
Externs in PSA Switch are different than those in Simple Switch.
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 this would be more accurate as "The implementation of P4 externs in PSA Switch is different..."

what the expected JSON for externs should be. Next, read the changes
in the following [commit](https://github.com/p4lang/behavioral-model/pull/767).
It details all the changes made to support the counter extern in PSA.
It will also be useful to understand on a high level how P4 Runtime
Copy link
Member

Choose a reason for hiding this comment

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

s/P4 Runtime/P4Runtime

in the following [commit](https://github.com/p4lang/behavioral-model/pull/767).
It details all the changes made to support the counter extern in PSA.
It will also be useful to understand on a high level how P4 Runtime
interacts with PSA Switch. Briefly skimming `runtime_CLI.py` will do.
Copy link
Member

Choose a reason for hiding this comment

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

That is incorrect, runtime_CLI.py does not use P4Runtime. runtime_CLI.py uses the Thrift RPC service defined in https://github.com/p4lang/behavioral-model/blob/master/thrift_src/standard.thrift. P4Runtime is a gRPC service. It is implemented over the PI C library (https://github.com/p4lang/PI) which is then itself implemented (for bmv2) in this repository (https://github.com/p4lang/behavioral-model/tree/master/PI).
Both implementations converge at bm::RuntimeInterface (https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_sim/runtime_interface.h).

runtime_CLI --- Thrift service ---> Thrift service implementation --- RuntimeInterface ---> bmv2 built-in objects + target-specific objects
[any P4Runtime client] --- P4Runtime service ---> P4Runtime implementation (DeviceMgr) --- PI API ---> PI bmv2 implementation ---> RuntimeInterface ---> bmv2 built-in objects + target-specific objects

"Target-specific objects" include your PSA extern implementations (you added an override implementation of read_counters and write_counters to PSASwitch).

`BM_REGISTER_EXTERN_W_NAME_METHOD`.
5. Create an `import_yourExternNameHere` dummy method and call
it within `psa_switch.cpp`.
3. Provide P4 Runtime support if necessary. This means overriding
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. "P4 Runtime" is misleading. If you mean "P4Runtime", then it is incorrect. If you mean "P4 runtime", then it is better, but maybe could use some clarification.

* Did you remember to register the extern method? These must be done
by the programmer.
* P4 Runtime can't interact with my extern.
* Did you remember to override necessary methods in the P4 Runtime
Copy link
Member

Choose a reason for hiding this comment

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

bm::RuntimeInterface would be less misleading

The following process is meant to serve as a general guide on how
to develop new externs in PSA Switch.

1. Provide support for emitting the extern in p4c. Currently, only
Copy link
Member

Choose a reason for hiding this comment

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

Something that is worth mentioning because it explains the design we came up with: IIRC p4c is still generating "built-in" objects as part of the JSON (they are unused by PSASwitch) in order to make sure that runtime tools which consume the bmv2 JSON (such as the runtime_CLI) still work. This is temporary until such tools can be updated. Please correct me if I'm wrong.

Base automatically changed from master to main February 9, 2021 02:44
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.

None yet

4 participants