[P4-dev] detect port status changes in the dataplane?

Antonin Bas antonin at barefootnetworks.com
Fri Jul 7 15:25:18 EDT 2017

Hi Rohan,

The <dest_field> would be the metadata field were you want to write the
port status (I imagine it would be 0 for down and 1 for up). In other words
query_port_status(<dest_field>, <port_number>) is logically equivalent to
something like <dest_field> = port_status(<port_number>).
This thread covers how to define your own primitive actions:

However, I am not convinced that your approach is sound. I am not sure what
your end goal is exactly. If you are looking at routing protocols, the port
status information provided by bmv2 may not be sufficient. You usually want
to use something like BFD to detect link failures.

On Thu, Jul 6, 2017 at 2:00 AM, Roshan Se <roshan.sedar at student.uclouvain.be
> wrote:

> Hi Antonin,
> Could you give bit more information on this : query_port_status(<dest
> field>, <port number>)?
> What do you mean <dest_field> here?
> I'd like to give it a try to implement failure status detection in
> simple_switch.
> Thanks,
> Roshan.
> On 2017-06-27 19:51, Antonin Bas wrote:
>> Hi,
>> There is no mechanism in the P4 v1model to query port status. This is the
>> architecture (to use the P4_16 terminology) which bmv2 simple_switch tries
>> to support, so the short answer to your question is no. There is however a
>> mechanism to send port status updates to the control plane.
>> AFAIK, the Portable Switch Architecture (PSA), which aims to replace
>> v1model as the de facto architecture to write portable P4 programs, will
>> not include such a mechanism either.
>> That being said, bmv2 itself is supposed to be a framework for
>> implementing various P4_16 architectures. So were you inclined to define
>> your own architecture and include an extern type that enables you to query
>> the status of a port, it should not be too hard to implement your
>> architecture using the bmv2 C++ library. The major issue I see here is that
>> the p4c compiler bmv2 backend is still a work in progress and doesn't
>> support arbitrary architectures with arbitrary externs at this stage. So
>> you would not be able to compile your programs easily. Once the backend is
>> more stable (which IMO means once the backend supports PSA), you should be
>> able to do what you are trying to do with some amount of work.
>> If you are using P4_14 and the legacy compiler for bmv2 (
>> https://github.com/p4lang/p4c-bm), it may be much easier to achieve
>> support for this. You would simply need to define your own primitive action
>> and implement it in C++ in bmv2 simple_switch. Your primitive action could
>> look like this: query_port_status(<dest field>, <port number>). Now the C++
>> implementation may not be trivial, as you would need to get a handler on
>> the bmv2 PortMonitor object, but that wouldn't be too hard either. If you
>> are interested in trying this, there should be quite a few email threads on
>> the mailing list that cover how to add a custom primitive action to the
>> P4_14 compiler and implement it in bmv2.
>> Thanks,
>> Antonin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170707/8fe9e47d/attachment-0002.html>

More information about the P4-dev mailing list