[P4-dev] P4 Slice and EBPF backend

hemant at mnkcg.com hemant at mnkcg.com
Sat Aug 26 19:46:28 EDT 2017


I am using a modified EBPF backend to shoehorn P4 Slice code into this
backend.  I have modified this file:
"p4c/testdata/p4_16_samples/switch_ebpf.p4" as follows:

 

Added new struct below.

 

struct Token
{
    bit<64>    data;
};

 

Added the new struct as member of Headers_t

 

struct Headers_t
{
    Ethernet_h ethernet;
    IPv4_h     ipv4;
    Token      token;
}

 

Added one line to the control below for use of token.data.

 

control pipe(inout Headers_t headers, out bool pass)
{
    action Reject(IPv4Address add)
    {
        pass = false;
        headers.ipv4.srcAddr = add;
        headers.token.data[63:32] = add;
    }

.

 

I have modified p4c/backends/ebpf/codeGen.h and .cpp.  The .cpp has added
this function and thus the modification to the .h file is obvious.

 

bool CodeGenInspector::preorder(const IR::Slice* expression) {
    int h = expression->getH();
    int l = expression->getL();
  
    std::cout << expression->toString() << h << " " << l  << "\n";    
    builder->append(expression->toString());
    return true;
}

 

When I use p4c-ebpf on switch_ebpf.p4, I see the printed output from code in
the preorder Slice and the preorder AssigmentStatement functions showing
correct text for this line of P4 code:

 

headers.token.data[63:32] = add;

 

However, the output file from p4c-ebpf adds extra text after the sliced
data.  The text is shown in highlight below.

 

headers.token.data[63:32]headers.token.data6332 = value->u.Reject.add;     

 

I am missing something related to adding support for P4 Slice in this
backend.  I know the bmv2 supports Slice but I wanted to experiment with the
LHS and RHS of a Slice statement in the backend.  Since EBPF is a simpler
backend, I have used it with my modifications.  I see EBPF backend uses an
Inspector for a visitor.  I think, to work with a Slice, we would need a
Modifier visitor so that one could modify the LHS or RHS of the Slice
statement with a text of one's choice.  I don't want to use multiple
inheritance for codeGen with Inspector and Modifier.   

 

Thanks,

 

Hemant

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170826/4510e96e/attachment-0002.html>


More information about the P4-dev mailing list