[P4-dev] Extern functions

cs.lev cs.lev at gmx.com
Thu Nov 8 09:30:37 EST 2018


Dear All,

Recently, I have been dealing with implementing an extern function in
bmv2 (and add modifications to the compiler as well), however I did not
find any useful information about this (even in the specification at
p4.org).
So, I started to analyze the source code and try to figure out how to
start the whole process. By means of Jeferson Santiago da Silva's help
and repositories (https://github.com/engjefersonsantiago/), I have
realized that basically there are two ways to implement an extern: 
 - purely adding new features to the primitives.cpp
 - defining an extern as a proper 'external library' with separated
source files, etc.

Between these ways, I could only make/reproduce the first (probably
simpler) approach, however I cannot claim that I completely understood
every changes I have made. After some point, I did not have time to go
deeper and understand some special data structures (e.g., in data.h).

Anyway, I could manage to implement a simple extern function that can
print out the values of a variable to the standard output (i.e., to
log-console).
I have created a new repository (https://github.com/cslev/p4extern)
where these basic instructions are collected. I hope that this
repository can help others implementing their own externs or at least
give some hints for the first steps.

Please have a look, try out, and feel free to comment (especially on
the second approach).
If there is/was already a tutorial on this that I have slipped over,
please let me know as well ;)

Cheers,
cslev 



More information about the P4-dev mailing list