Is Packet-the-Bear a good P4 programmer :)

It is just me who feels that our beloved Packet is going to experience a bunch of compilation problems with the code he has on his terminal?

I can see at least 3 distinct errors there. How many do you see?

Happy hacking

1 Like

Let’s see:

  1. There is a space in 2048 for the size; also a : instead of = (does that count as 1 or 2 mistakes?)
  2. Doesn’t the table have to be inside the control structure?
  3. The drop and route actions aren’t defined…but perhaps they default?
  4. No input arguments for ingress()…but perhaps they default?
1 Like

If you consider this to be P4_16.

  1. no hdr (or equivalent) before ipv4 key
  2. size number is wrong (the space)
  3. size should be ’ = ’ and not ’ : ’ :thinking:?
  4. table should be declared inside control

You could also consider no arguments for control or no action declared. But that could be ignored just not to be too specific.

If you consider this as P4_14 (I used less times):

  1. should be reads instead of key, plus remove all ’ = ’
  2. should be apply(routing) instead of the control block apply and the apply() method from the table.

Funny enough size : seems to be correct for P4_14 and table declaration too, right?

It seems to have correct things from P4_14 and P4_16, a weird mix :slight_smile:

For further reference of the block :grinning:, here:

table routing{
    key = { ipv4.dstAddr : lpm; }
    actions = { drop; route; }
    size : 204 8;
}

control ingress () {
    apply{
        routing.apply();
    }
}

Good catch on P4_14 vs P4_16 @ederollora !

@judysnow @ederollora

Looks like we are in a general agreement!

I decided not to count ipv4.dst_addr not having hdr. in front as a bug, since I could not really tell what are the types of the arguments passed to ingress() control. I usually spell out all the parameters to the parsers/controls in my slides only once, in the very beginning, since they take way too much space. So, one can imaging an ingress control that is being passed just the IPv4 header :slight_smile:

Hopefully, the site maintainers will do something relatively soon.

Happy hacking!

How does this look @vgurevich ? Luckily, I’m one of the maintainers, so I’ll fix it! I don’t think I’ll have room for the header and action definitions.

header ipv4 {
    bit<32> dstAddr;
}
action drop() {}
action route() {}
control ingress () {
    table routing {
        key = { ipv4.dstAddr : lpm; }
        actions = { drop; route; }
        size = 2048;
    }
    apply{
        routing.apply();
    }
}

Dear @judysnow – thank you for taking care of that.

To follow the initial layout and spirit of the code, I’d do the same thing as you proposed and leave the header definition and the actions out of the picture – just start at control ingress().

Also, even though the language allows it, more often than not actions are defined inside the same control as the table and not in the global scope anyway, so leaving them out will eliminate additional questions :slight_smile:

Also, I noted that the same code fragment is used in at least one other place (“Ready to Try P4?”), so you might want to watch out for that.

Happy hacking!

Hi @vgurevich
Thanks! I fixed the other place (Learn « P4 – Language Consortium) last night, but I have to get an artist-type person to fix the image. I don’t even have the source for it.
judy