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

**URL:** <https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148>\
**Category:** Site Feedback\
**Created:** [October 21, 2021, 11:08pm UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148 "2021-10-21T23:08:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vgurevich](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/vgurevich/32/23_2.png) [@vgurevich](https://forum.p4.org/u/vgurevich)\
**Post date:** [October 21, 2021, 11:08pm UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/1 "2021-10-21T23:08:08Z")

</div>

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](https://p4.org/wp-content/uploads/2021/05/Hero-img-1-1.png)?

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

Happy hacking

---

<div class="post-metadata">

**Author:** ![judysnow](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@judysnow](https://forum.p4.org/u/judysnow)\
**Post date:** [October 22, 2021, 12:17am UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/2 "2021-10-22T00:17:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ederollora](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/ederollora/32/21_2.png) [@ederollora](https://forum.p4.org/u/ederollora)\
**Post date:** [October 22, 2021, 12:29am UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/3 "2021-10-22T00:29:21Z")

</div>

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 ’ : ’ 🤔?
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 🙂

For further reference of the block 😀, here:

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

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

```

---

<div class="post-metadata">

**Author:** ![judysnow](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@judysnow](https://forum.p4.org/u/judysnow)\
**Post date:** [October 22, 2021, 12:39am UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/4 "2021-10-22T00:39:54Z")

</div>

Good catch on P4\_14 vs P4\_16 @ederollora !

---

<div class="post-metadata">

**Author:** ![vgurevich](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/vgurevich/32/23_2.png) [@vgurevich](https://forum.p4.org/u/vgurevich)\
**Post date:** [October 22, 2021, 12:47am UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/5 "2021-10-22T00:47:58Z")

</div>

@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 🙂

Hopefully, the site maintainers will do something relatively soon.

Happy hacking!

---

<div class="post-metadata">

**Author:** ![judysnow](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@judysnow](https://forum.p4.org/u/judysnow)\
**Post date:** [October 22, 2021, 12:58am UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/6 "2021-10-22T00:58:49Z")

</div>

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.

```auto
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();
    }
}

```

---

<div class="post-metadata">

**Author:** ![vgurevich](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/vgurevich/32/23_2.png) [@vgurevich](https://forum.p4.org/u/vgurevich)\
**Post date:** [October 22, 2021, 2:18am UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/7 "2021-10-22T02:18:02Z")

</div>

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 🙂

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!

---

<div class="post-metadata">

**Author:** ![judysnow](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@judysnow](https://forum.p4.org/u/judysnow)\
**Post date:** [October 22, 2021, 4:37pm UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/8 "2021-10-22T16:37:02Z")

</div>

Hi @vgurevich  
Thanks! I fixed the other place ([Learn « P4 – Language Consortium](https://p4.org/learn/)) 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

---

<div class="post-metadata">

**Author:** ![judysnow](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@judysnow](https://forum.p4.org/u/judysnow)\
**Post date:** [December 8, 2021, 11:12pm UTC](https://forum.p4.org/t/is-packet-the-bear-a-good-p4-programmer/148/9 "2021-12-08T23:12:09Z")

</div>

Packet is all fixed now! He’s even an emoji :packet:  
Just type packet with a : before and a : after.  
I wish his resolution/aspect ratio were better. If anyone has a better image, I’ll add it.
