[P4-dev] Manipulating Table Entries in P4 program.

Mihai Budiu mbudiu at vmware.com
Tue Oct 16 11:55:28 EDT 2018


I am not sure which aspect you want me to elaborate on.
If you look at the ebpf_model.p4 file, it contains a declaration of arrays of counters which can be directly incremented by the dataplane. That is a form of state that can be manipulated directly in the dataplane, but it only works when you compile P4 to ebpf.

Here is a small program that does that.

#include <ebpf_model.p4>
#include <core.p4>

#include "ebpf_headers.p4"

struct Headers_t {
    Ethernet_h ethernet;
    IPv4_h     ipv4;
}

parser prs(packet_in p, out Headers_t headers) {
    state start {
        p.extract(headers.ethernet);
        transition select(headers.ethernet.etherType) {
            16w0x800 : ip;
            default : reject;
        }
    }

    state ip {
        p.extract(headers.ipv4);
        transition accept;
    }
}

control pipe(inout Headers_t headers, out bool pass) {
    CounterArray(32w10, true) counters;

    apply {
        if (headers.ipv4.isValid()) {
            counters.increment((bit<32>)headers.ipv4.dstAddr);
            pass = true;
        } else
            pass = false;
    }
}

ebpfFilter(prs(), pipe()) main;

Mihai

From: Kamal Bhatt <Kamal.Bhatt at stordis.com>
Sent: Tuesday, October 16, 2018 6:47 AM
To: Mihai Budiu <mbudiu at vmware.com>; p4-dev at lists.p4.org
Subject: RE: Manipulating Table Entries in P4 program.

Forgot to add p4-dev.

From: Kamal Bhatt
Sent: 16 October 2018 15:45
To: 'Mihai Budiu' <mbudiu at vmware.com<mailto:mbudiu at vmware.com>>
Subject: RE: Manipulating Table Entries in P4 program.

Thanks Mihai,
Please can you elaborate a bit more on that, Perhaps with the help of some code or so.

Thanks.
From: Mihai Budiu <mbudiu at vmware.com<mailto:mbudiu at vmware.com>>
Sent: 15 October 2018 17:37
To: Kamal Bhatt <Kamal.Bhatt at stordis.com<mailto:Kamal.Bhatt at stordis.com>>; p4-dev at lists.p4.org<mailto:p4-dev at lists.p4.org>
Subject: RE: Manipulating Table Entries in P4 program.

Standard P4 does not have any means for the data plane to change tables.
However, various architectures can provide extensions to enable this behavior if the hardware supports it.

In the v1model counters and registers are closest to what you want.

Mihai

From: P4-dev <p4-dev-bounces at lists.p4.org<mailto:p4-dev-bounces at lists.p4.org>> On Behalf Of Kamal Bhatt
Sent: Monday, October 15, 2018 8:28 AM
To: p4-dev at lists.p4.org<mailto:p4-dev at lists.p4.org>
Subject: [P4-dev] Manipulating Table Entries in P4 program.

Hello Everyone,
Although performing CRUD operations on the table entries is the responsibility of control plane, Still curious about if it is possible to do it in data plane in our P4 program as well.
For example, If I need to remove an entry from the table on receiving a specific flag in packet.

Thanks,
Kamal Bhatt.


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


More information about the P4-dev mailing list