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:
- 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)
- It is also true that some simple words in some simple cases can be translated one-for-one
- 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.
- 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.
- 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