[P4-dev] Change field value in execution time (p4-14)

Vladimir Gurevich vladimir.gurevich at barefootnetworks.com
Tue Apr 4 12:27:17 EDT 2017

Hello Fábio,

The typical way to solve your problem is to create a table that will copy
the action data (supplied by the control plane) into the metadata and then
use that metadata to choose a particular processing algorithm.

Here is a simple example in P4_14, abbreviated for clarity.

header_type my_metadata_t {
    fields {
        my_mode : 1;

metadata my_metadata_t my_metadata;

action set_mode(mode) {
   modify_field(my_metadata.my_mode, mode);

table select_mode {
    actions {

control ingress {
    if (my_metadata.mode == 0) {
    } else {

The idea here is that tables hold state that can be retrieved and used by
the data plane program. However, it is the control plane that configures
that state. In the example above, all you need to do to choose the
processing mode on the fly is to set the default action for the table
"select_mode" to be either set_mode(0) or set_mode(1). You can do that by
using the CLI (e.g. simple_switch_CLI) or by calling the autogenerated APIs
from your control plane program.

Note, that this approach is quite flexible. For example you to choose
processing mode on a per-port basis: all you need to do is to make sure
table "select_mode" is amended to match on the ingress port. The
possibilities are endless.

Happy hacking,

On Tue, Apr 4, 2017 at 6:31 AM, Fábio Pereira <fpereira at lasige.di.fc.ul.pt>

> Hello everyone,
> I would like to have a switch with two operation modes. The active mode
> would depend on the value of a P4 field. Right now, in order to achieve
> this, I have to shutdown the switch, generate the new json (from the P4
> file with the operation-mode field updated) and feed it to a new switch. Is
> there a way to change the field value in execution time? Or in alternative,
> to generate a new json and feed it back to the running switch executable
> (i.e. without having to restart it)?
> Thanks,
> Fábio Pereira
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org

*Vladimir Gurevich*

*Barefoot Networks*
*Technical Lead, Customer Engineering*
Email: vag at barefootnetworks.com
Phone: (408) 833-4505
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170404/8175373e/attachment-0002.html>

More information about the P4-dev mailing list