This is an experimental project to transform graphs into P4 code
While teaching we realised that sometimes, initiating a new project in P4 was challenging for new students. Besides, having to check out header structures and write the structure in P4 made the process slightly longer than we wanted. Apart from this we saw that in some cases, there might be a reduced knowledge on how headers are parsed and which order they follow, even if students do generally remember to which layer a particular protocol or header belongs to. As a result we ended up drawing simple graphs to explain the steps of header parsing and describe how the parser should look like.
As a result, thought that we could design a process that started with drawing graphs and that could be later transformed into a full template of a P4 program, that autogenerates the headers, the parsing block the deparser and the skeleton for the rest of the program (as, for instance, the logic of the ingress or egress is tightly coupled to the functionality it provides and thus, difficult to express as a graph).
The process of designing this resulted in a mix of tools to create graphs in the browser, export it and transform it to a P4 project that has several blocks autogenerated. In particular the headers, parser and deparser are completely generated from the graph, leaving the rest to the programmer. We belive that this tools is useful for new students, developers with fair knowledge in networking and newcomers to the P4 world. The compendium of tools presented here let's programmers quickly create a parsing graph and obtain the equivalent P4 code, easing the process of creating a new P4 program. In the future, the tool is expected to be duplex, so it should be able to convert graphs into P4 code and P4 code into graphs (not considering, for now, anything else but headers, parsers and deparser.
This tool also includes a set of pre-defined blocks with well-known headers and parsing states that will ease the process for programmers. By importing this library in the online graphing tool, one can generate the parser from the pre-defined blocks we have created.
There is a somehow related project called P4-HLIR you can check. Although it is a much more complete and handy project, it targets P4_14 and does not support (AFAWK) graph to P4 translation.
Coming ...