-
Notifications
You must be signed in to change notification settings - Fork 334
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
extern implementaion #697
Comments
|
In a recent Slack channel for p4, it was asked about crypto extern development for public and private key crypto. I don't fully understand what code to change in the behavioral-model, but here are code changes to v1model.p4 and partial changes to behavioral-model. Let's first agree if (a) we should add crypto API to v1model.p4, and then (b) agree about the API which is included below.
The behavioral-model partial changes are:
|
Copy of a reply I made on P4 Slack: I do not know if there is interest in adding extern functions to v1model for encryption, but I do think there is value in having an article explaining the steps to add such an extern to both p4c and simple_switch, in a public Github repo, with diff files that can be applied to the currently latest p4c and behavioral-model repo code, so that the occasional person who asks how to do this can learn from a working example. Instructions on how to make simple extensions like that seem likely to help more people than giving them another built-in thing. |
Regarding need, not only is inter-data center traffic encrypted, even intra-data center trafifc is. I have done what I could. Now, anyone familiar with the behavioral-model should complete the code. On code completion, we will also have an example of how a new extern is added to simple_switch and also support for crypto. |
If this is about adding a new extern to v1model.p4, I do not believe this is the best forum to discuss this. Furthermore, I don't think it is likely that new functionality will be added to v1model. The charter for the architecture was to provide feature-parity with the P4_14 abstract switch model. Pretty much all changes to v1model in the last couple years fall in the category of "bug fixes". You can still bring this up at the LDWG, but I doubt there will be too much interest. I'm not sure something like this should even be part of a future release of PSA. Even if encryption is becoming ubiquitous in data centers, it is not supported by switching chips and I doubt it is handled at the ToR. There could be interest on the NIC side however. @jafingerhut I don't know if you are still having meetings for "PNA". I agree with Andy that a complete guide on how to add a custom extern to v1model for the sake of experimentation, along with a running example, would be very welcome. I don't have time to tackle this myself at the moment, but I would be happy to review it. I recommend making it clear in the guide that by adding a new extern to v1model, you effectively define a new architecture - my-v1model. However, the bmv2 compiler backend will still be able to compile the program and generate a "correct" JSON that can be consumed by simple_switch: either by a modified simple_switch binary that includes an implementation for the extern, or by the original simple_switch binary and the use of the |
No problem if v1model.p4 is not changed and a guide is published. Routing (Cisco CPP) and NIC ascis already combine 100G crypto. A switch could use switching asic and Marvell Nitrox for crypto. The crypto is still configured by switching asic. |
I don't know what you mean by "The crypto is still configured by switching asic." I think I see your point however. The problem is that a function like this is unlikely to get incorporated into something like PSA IMO, which aims to be portable. If you need to combine a switching ASIC and a separate processor for encryption / decryption, I think you can either 1) describe a new architecture that will work for your specific hardware combination, or 2) use a PSA program for the switching ASIC and steer traffic to the security processor by sending it to the appropriate port. |
The switching asic is configured by a cpu on the switch. An ACL is configured in switching asic to encrypt/decrypt traffic to/from certain ports and send/receive traffic to/from the Nitrox (crypto engine) bus. If 2) is used, then no crypto externs are needed. |
RSA asymmetric crypto is best implemented using gmp because gmp includes mpz_powm. However, the behavioral-model uses Bignum. If I use GMP, I will have to add gmp support to https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_sim/data.h I have a repo that has developed RSA crypto and tested for encrypt and decrypt. It should be quick to add this C code as C++ code into tests_extern.cpp and complete API for encrypt and decrypt. But first, I'd have to add gmp support to data.h or develop power and modulus combined operation in Bignum. |
Look at https://github.com/p4lang/behavioral-model/blob/master/include/bm/bm_sim/bignum.h, you can get the mpz_t object by calling |
I think we can close this issue now that Sa Pham in the P4 Slack channel found an implementation of an extern with simple_switch. See https://github.com/uni-tue-kn/p4-macsec
https://github.com/uni-tue-kn/p4-macsec/blob/master/p4/p4/basic.p4#L178
I think the code is a good example to learn instructions on how to develop a new extern with simple_switch. Another question: Since the implementation has not changed v1model.p4, would the community consider incorporating the code in behavioral-model and simple_switch? Then we could issue a PR and review the code. |
It's a new extern type and therefore technically a new architecture, so I'd rather not have non-v1model extern types enabled by default in simple_switch. What we could do is place some "useful" externs in a separate library and document how to load it at runtime into bmv2 using I feel like at the moment a good place for something like this would be under
Having one "crypto" extern in that list of extern examples sounds like the right thing to do. |
Appreciate the expedited reply. I like However, I'd also like sample P4 code using the extern to also be added someplace so that P4 newbies are helped. Maybe, we can strick the P4 code in the same example directory. Also, notice that the macsec repo has mirrored the behavioral-model p4/target directory and changed code. https://github.com/uni-tue-kn/p4-macsec/tree/master/p4/target |
Do we need any more discussion such as in a LDWG meeting or is there consensus to create a new directory called |
One of the motivations for P4_16 was specifically that externs could be defined and added to an architecture, without changing the language definition. Adding example externs to behavioral-model, that do not change the current definition of the v1model architecture, but new README instructions state clearly how to compile and run a modified version of simple_switch or simple_switch_grpc with the new example externs enabled, on top of what v1model provides, impacts neither the P4_16 language, nor the current v1model definition. |
@jafingerhut thanks for your input. I think we could create a PR to add the new directory to the behavioral-model - this is minor work. Later we can add a crypto extern example under the new directory with another PR. |
I don't see much value in having a PR that simply creates the directory, with no examples in it. Why not simply create the directory when there is a first working example? |
Ok, sounds good. |
A PR has been issued. Please see |
A simple example of extern is available in the following path: Thereafter, incorporate the new extern .cpp file into appropriate Makefile.xx. See below:
|
I think the notes I added today suffice to guide new folks for how to add a new extern to simple_switch. Let's try to close this issue. |
@antoninbas No pressure, but do you perhaps know what commands one can run to compile the proposed new .cpp file in the PR on an Ubuntu 16.04 Linux system, and then what command line options should be added to a simple_switch/simple_switch_grpc command line, to make these new externs work? I'd be happy to test them and add a README to this example code given such commands, I'm just not sure I want to experiment and dig to find those commands. |
@hesingh I think the goal should be to leave behind something that we can point people to when they ask how to add externs, preferably with as many step-by-step instructions as we can provide. Otherwise, they are just going to ask again (yes, I know some will ask again even with the step-by-step instructions, but at least it will not be because we didn't write them down). |
@jafingerhut Ok, understood. Here is a start at step-by-step instructions.
884e01b#diff-5ae8a8504eb56bc8167d4b69469ed7e8R66
884e01b#diff-73004d69b350a529df2cf8a92fcd13d9L34
Also see, this checkin to the behavioral-model repo that shows code changes for the example given above. |
I have completed editing the step-by-step instructions. Please review - thanks. |
Tactically, I think the step-by-step instructions, which are complete, could be added to README for behavioral-model. |
Wherever the step-by-step instructions are added, I think they should be not for PSA, but for this crypto example that is part of this PR, added to simple_switch. I would want to show people a fully functional example, preferably -- the PSA implementation is not that yet. |
Ok - thanks. Since the authors of macsec have not replied to the Issue, I have abandoned porting their symmetric crypto code to the PR. I would have to spend lot of time with that code, especially since the Slack channel first asked for asymmetric crypto. Now, I am writing my asymmetric crypto code for the PR. This would be a complete example for extern with simple_switch. |
Note: I don't think there is any need for a new extern to do something useful or correct according to some standard somewhere. Whatever the current crypto code happens to do is probably good enough for an example. One of the points of an example is just to show how to make something work, even if it is not exactly what any one person wants to add as a new extern. I'd be happy with an example extern that had at least one |
Hi, in the v1model.p4 https://github.com/p4lang/p4c/blob/master/p4include/v1model.p4, I found that there are just some extern declarations.
The text was updated successfully, but these errors were encountered: