# How define the arp header in the P4 program

**URL:** <https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584>\
**Category:** Getting Started with P4\
**Created:** [January 3, 2023, 7:01pm UTC](https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584 "2023-01-03T19:01:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lululouisa](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Lululouisa](https://forum.p4.org/u/Lululouisa)\
**Post date:** [January 3, 2023, 7:01pm UTC](https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584/1 "2023-01-03T19:01:32Z")

</div>

Hi all, about the ARP flows, I am wondering how to define the header and parser part.  
According to [papers/parser.p4 at master · p4lang/papers · GitHub](https://github.com/p4lang/papers/blob/master/sosr15/DC.p4/includes/parser.p4), maybe I can directly use header arp\_rarp\_t and parser\_arp\_rarp. However, when I define them in my p4 program, there is undefined error about arp\_rarp\_ipv4. Therefore, what should I define the parameters in the header field and parser field for the arp flow.

Thank you.

---

<div class="post-metadata">

**Author:** ![DavideS](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/davides/32/120_2.png) [@DavideS](https://forum.p4.org/u/DavideS)\
**Post date:** [January 4, 2023, 8:39am UTC](https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584/2 "2023-01-04T08:39:33Z")

</div>

HI @Lululouisa ,

1. could you please chare your error and program?
2. here and example of P4 program, [tutorials/basic.p4 at master · p4lang/tutorials · GitHub](https://github.com/p4lang/tutorials/blob/master/exercises/basic/solution/basic.p4), in general you should define your header and then you can use it in the parser and in the ingress/egress pipeline. More in detail, [tutorials/basic.p4 at master · p4lang/tutorials · GitHub](https://github.com/p4lang/tutorials/blob/master/exercises/basic/solution/basic.p4#L60) here the parser check if the value of the ethernet type is IPV4 if yes the parser start to parse the IPv4 header. You have to do a similar things according to the ARP protocol specification

---

<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:** [January 6, 2023, 12:34pm UTC](https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584/3 "2023-01-06T12:34:38Z")

</div>

Hi @Lululouisa ,

I also believe you should add the exact output of your program and hopefully the content of your project in Github (or something like similar) so we can assess how to find the issue 🙂

I had some code around using ARP and I copy-pastedm some parts from my program so it might be useful to you:

```auto
header arp_t {
    bit<16> hrd; // Hardware Type
    bit<16> pro; // Protocol Type
    bit<8> hln; // Hardware Address Length
    bit<8> pln; // Protocol Address Length
    bit<16> op; // Opcode
    macAddr_t sha; // Sender Hardware Address
    ip4Addr_t spa; // Sender Protocol Address
    macAddr_t tha; // Target Hardware Address
    ip4Addr_t tpa; // Target Protocol Address
}

parser MyParser(packet_in packet,
                out headers hdr,
                inout metadata meta,
                inout standard_metadata_t standard_metadata) {

    state start {
        packet.extract(hdr.ethernet);
        transition select(hdr.ethernet.etherType) {
            TYPE_ARP: parse_arp;
            TYPE_IPV4: parse_ipv4;
            default: accept;
        }
    }

    state parse_arp {
        packet.extract(hdr.arp);
        transition accept;
    }

    ( . . . )
}

struct headers {
    ethernet_t ethernet;
    arp_t arp;
    ( . . . )
}

# Other parts of the P4 program are omitted

```

Cheers

---

<div class="post-metadata">

**Author:** ![Lululouisa](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Lululouisa](https://forum.p4.org/u/Lululouisa)\
**Post date:** [January 7, 2023, 8:43am UTC](https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584/4 "2023-01-07T08:43:46Z")

</div>

Hi @ederollora ,

thank you for sharing your code about ARP to me. It is really helpful for me.  
I didn’t push my program to GitHub, so I didn’t share my program when I asked the question this time. I would synchronize program next time and share them at the Forum so that we can understand my questions better.  
Thank you!

Louisa

---

<div class="post-metadata">

**Author:** ![Lululouisa](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Lululouisa](https://forum.p4.org/u/Lululouisa)\
**Post date:** [January 7, 2023, 8:47am UTC](https://forum.p4.org/t/how-define-the-arp-header-in-the-p4-program/584/5 "2023-01-07T08:47:34Z")

</div>

Hi @DavideS ,

thank you for response. And I am sorry that I didn’t share you exact error and program to describe my question. I would synchronize the program and questions next time.  
@ederollora inspires me with his solution. My question is solved now.

Thank you!

Louisa
