[P4-discuss] How to Get P4Switch ID

Antonin Bas antonin at barefootnetworks.com
Thu Oct 27 13:43:58 EDT 2016


Hi,

There is no built-in notion of a switch ID in P4. Therefore if your P4
dataplane needs a switch ID for any reason, you need to have the control
plane assign and provide a switch ID to it. You can do it by 1) writing the
switch ID to a table entry (IMO this what you should do in most cases) 2)
writing the switch ID to a stateful register.

For example, you can have the following P4 snippet:
table my_table {
    actions { copy_switch_id; }
}
action copy_switch_id(switch_id) {
    modify_field(local_metadata.switch_id, switch_id); // where local
metadata is defined somewhere
}

Your control plane can then set the default action for my_table to
copy_switch_id, with your chosen switch ID as the action parameter. When
using the bmv2 runtime CLI, it would look like this: table_set_default
my_table copy_switch_id <your switch ID>

Hope that helps.

On Wed, Oct 26, 2016 at 10:34 PM, <jingy at zju.edu.cn> wrote:

> Hello,
>   I new to P4.
>   When I write P4 codes, I face a problem. I want to implement a simple
> routing algorithm, so I need to get current switch ID to get the egress
> port.(The egress port is encoded locally).
>   How can I get switch ID in my P4 program?
>   Thanks!
>
> _______________________________________________
> P4-discuss mailing list
> P4-discuss at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-discuss_lists.p4.org
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-discuss_lists.p4.org/attachments/20161027/e914b43f/attachment-0002.html>


More information about the P4-discuss mailing list