[P4-dev] target IP address

Antonin Bas antonin at barefootnetworks.com
Mon Jul 27 14:54:55 EDT 2015

If you are implementing a L3 switch and want to assign IP address to your
interfaces at runtime, you need to use a table, you cannot do this with a
if condition in the control flow (unless your IP addresses are static and
can be hard coded in the P4 program). The table would look like this:

table ip_match_iface {
  reads {
    ipv4.dstAddr : exact;
  actions {
  size: 128;

action set_match_iface() {
  modify_field(my_metadata.match_iface, 1); // where
my_metadata.match_iface has to be defined by you

You can then populate the table at runtime with your IP addresses and test
the value of my_metadata.match_iface in the control flow.
Assuming you are using the CLI, the commands to populate the table would
look like this:

add_entry ip_match_iface set_match_iface
add_entry ip_match_iface set_match_iface



On Mon, Jul 27, 2015 at 10:46 AM, brian fiegen <brianfiegen at gmail.com>

> I'm using the compiled behavioral models from the p4factory distro so
> that's the context for the following questions.
> Is there a way I can tell my target that it has a specific IP address
> (akin to a loopback)?  Is there a way I can then test against this value
> like "if (my_loop == ipv4.dst_address) { do-stuff })"?
> Thanks
> _______________________________________________
> P4-dev mailing list
> P4-dev at p4.org
> Listinfo - http://mail.p4.org/mailman/listinfo/p4-dev_p4.org
> Archives - http://mail.p4.org/pipermail/p4-dev_p4.org/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20150727/bf9a8de9/attachment-0001.html>

More information about the P4-dev mailing list