Tools or Resources to Convert P4 BMv2 Code to TNA Architecture

Hello everyone,

I am working on converting P4 code originally written for the BMv2 architecture to make it compatible with the TNA architecture. I would like to ask if there are any tools available that can help automate or facilitate this conversion process.

Thanks a lot.

There are parts of such a translation that I would consider easy to automate, e.g. replacing assignments to the standard_metadata egress_spec field with assignments to the corresponding TNA field for the output port (sorry, being lazy and not looking up its name right now). Or changing the signatures of the parsers and controls.

Then there are other parts that I would think would be very challenging to automate, and can be challenging even to pass the information from a person to another person. For that reason, and that I have never heard of one, I doubt there exists any tools like you describe.

That said, feel free to ask questions here about anything you are having difficulty with. Now that the Intel Tofino P4 compiler back end and other software is being released into open source, I believe it should be perfectly acceptable to discuss details of TNA and Tofino P4 compiler best practices in the open.

Dear @layal,

To add to @andyfingerhut answer and to put everyone in the right mindset, I would encourage you to think of a natural language first. In that case, P4 would be akin to an alphabet, where the actual language is the specific P4_16 architecture. So, you have the situation that you are probably quite familiar with, where many similar and dissimilar languages use the same basic alphabet (Latin, for example).

While having a common alphabet makes it easier for us to feel more comfortable in an unfamiliar country (such as being able to read the street names, international words such as “stop” or “toilet”, etc.), learning the language or translating between two languages that use such a common alphabet is a totally different matter.

Following the natural language analogy, we can say a couple of things with regards to translation:

  1. It is certainly much easier to learn a language that is related to your own (e.g. learning English while knowing German or Dutch, learning Portuguese while knowing Spanish or Italian, etc.) than to learn a completely different language (knowing English is not going to help you to learn Hungarian or Polish even though they all use Latin alphabet)
  2. It is also true that some simple words in some simple cases can be translated one-for-one
  3. It is also true that some other simple words cannot be translated one-for-one: sometimes a word exists in one language, but not the other, sometimes you need to know more context, etc.
  4. Note also, that due to differences in phonetics, even a familiar, “international” word might sound very differently (try to guess what can the Japanese word “sumahō” mean). In P4 world a very similar situation happens due to the differences in target capabilities.
  5. As for the translations of the sentences and full texts, things might get complicated very quickly, depending on how different (or close) the languages are, how their grammar is organized, etc. More often than not, if you translate things word-for-word, the result will make no sense at all. Languages have different grammar, different word order, different parts of speech with different properties and thus exactly the same idea often needs to be expressed in a very different overall manner.

Exactly the same can be said about translating programs between different P4 architectures. Compared to v1model architecture, TNA has a different structure (grammar). For example, it has an ingress parser and an egress deparser, both missing in v1model. As a result, features such as mirroring (cloning), resubmit and digests (to name a few) are expressed very differently.
At the same time, BMv2 is a much less restricted target: you can do any arithmetic anywhere, you can access the registers in all sorts of complicated ways that would not be possible on Tofino, etc., etc. Obviously, there are no restrictions in BMv2 regarding the length of the program (the number of stages), the table sizes, the number of hearers, the parsing timing, etc.

I hope that gives you some appreciation of the problem and the explanation why such tools do not exist yet and probably will not appear in the near future.

If you want to learn how to program in P4 for Tofino or Tofino2, I encourage you to attend Intel Connectivity Academy classes by P4ica, either in person or virtually.

Happy hacking,
Vladimir

Dear Vladimir,

Thank you for your email and the valuable information you’ve provided. As a PhD student with some understanding of P4, I’ve greatly benefited from your informative YouTube videos. I’m eager to deepen my knowledge, particularly regarding Tofino and the Tofino Native Architecture (TNA).

Could you please provide information on the cost of the relevant courses?

Thanks a lot.
Best regards,
Layal Ismail.

Hello Layal,

Please, visit https://p4ica.eventbrite.com

That’s where we announce all the training events and all tickets. Although, we do not currently have a live session scheduled, you can get access to the recordings of our earlier sessions via P4ica Archives event. You can start the course ICA-XFG-101 and then progress onto the Level-2 courses as needed.

If you have further questions about the courses, do not hesitate to reach out to academy@p4ica.com

Happy hacking,
Vladimir