[P4-dev] Implementing externs

Antonin Bas antonin at barefootnetworks.com
Fri May 5 17:50:26 EDT 2017


Hi Rui,

It is possible to implement your own externs in bmv2. There are a few
examples in this file: https://github.com/p4lang/behavioral-model/blob/
master/tests/test_extern.cpp#L32. The JSON format also supports
instantiating extern objects, as you have observed. However, at this stage,
because of the lack of compiler support that Mihai pointed out, you cannot
simply extend v1model.p4 with your own externs. You would need to manually
edit the JSON file, which is not a very user-friendly experience, although
pretty straightforward.

Note that by extending v1model.p4, you de facto create a new architecture.
I think the legit way of doing this -if you're only interested in adding
some new externs- would be to write your own file my_arch.p4 like this:
#include <v1model.p4>
extern my_extern_type {
    // ...
}
and include it in your P4 programs

Best,

Antonin

On Fri, May 5, 2017 at 10:42 AM, Rui Miguel <rmiguel at lasige.di.fc.ul.pt>
wrote:

> Greetings!
>
> After briefly analyzing the JSON representation of an extern declaration,
> I'm wondering where to implement extern functionality. I imagine there's a
> C++ class that can be extended? Is it plausible to use the v1model.p4
> architecture along with an extern block declared in my header definitions
> file? (I suppose for hardware targets the P4 programmer shouldn't be
> declaring externs of his own, but is it legit to change v1model?)
>
> This comes after an attempt to study the project files, but for someone
> who isn't much into C++, compilers or the project itself, things look a tad
> cryptic overall.
>
> Thanks in advance,
> ~ Rui Miguel
> --
>
>
>
>
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170505/2a217e52/attachment-0002.html>


More information about the P4-dev mailing list