How define the arp header in the P4 program

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, 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.

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, 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 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
1 Like

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 :slight_smile:

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

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

1 Like

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

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