[P4-dev] Question about simple-switch v1model digest

Antonin Bas antonin at barefootnetworks.com
Thu Jul 27 20:32:51 EDT 2017


Hi,

If you believe there is an issue with generate_digest support in the p4c
compiler, I recommend opening an issue there (https://github.com/p4lang/p4c
).

Thanks,

Antonin

On Wed, Jul 26, 2017 at 6:47 AM, Yitzchak M. Gottlieb <
ygottlieb at vencorelabs.com> wrote:

> In order to better understand the P4 language and the behavioral model,
> I've tried to translate the l2_switch.p4 into P4-16 and execute that in the
> simple_switch model.  The program is attached below. I'm using the latest
> P4c (master from yesterday) and compiling with:
>
> p4c -v -b bmv2-ss-p4org l2_switch.p4
>
> I've noticed an oddity that if I have the call to the extern digest() only
> once, the simple switch does not send it to the learning client, but will
> if I have it twice.  I suspect that the reason is that the JSON file has
> the parameters to digest as:
>
>         {
>           "op" : "generate_digest",
>           "parameters" : [
>             {
>               "type" : "hexstr",
>               "value" : "0x00000001"
>             },
>             {
>               "type" : "hexstr",
>               "value" : "0x0"
>             }
>           ]
>         },
>
> specifically that the second parameter is 0 and that the second parameter
> is taken as the learn_id in primitives.cpp:165.  In simple_switch.cpp:377,
> learn_id == 0 is taken to mean no learning.
>
> Did I misunderstand how to use the digest function?  Did I make an even
> more fundamental mistake?
>
> Thank you, in advance, for your help.
>
> Zuki
>
> --
> Yitzchak M. Gottlieb
> ygottlieb at vencorelabs.com
>
> l2_switch.p4:
>
> #include <v1model.p4>
>
> header ethernet_t {
>    bit<48> dstAddr;
>    bit<48> srcAddr;
>    bit<16> etherType;
> }
>
> struct headers_t {
>    ethernet_t ethernet;
> };
>
> struct learn_t {
>   bit<48> srcAddr;
>   bit<9> ingress_port;
> }
>
> struct metadata_t {
>   learn_t learn;
> };
>
> parser L2Parser(packet_in b, out headers_t headers, inout metadata_t meta,
>                 inout standard_metadata_t standard_metadata)
> {
>   state start {
>     b.extract(headers.ethernet);
>     transition accept;
>   }
> }
>
> control L2VerifyChecksum(in headers_t hdr, inout metadata_t meta)
> {
>   apply {}
>
>
> control L2Ingress(inout headers_t headers, inout metadata_t meta,
>                 inout standard_metadata_t standard_metadata)
> {
>
>   action nop() {}
>   action mac_learn() {
>     meta.learn.srcAddr = headers.ethernet.srcAddr;
>     meta.learn.ingress_port = standard_metadata.ingress_port;
>     // Need a duplicate so learn_id gets set properly in json
>     digest(1, meta.learn);
>     digest(1, meta.learn);
>   }
>
>   table smac {
>     key = { headers.ethernet.srcAddr : exact; }
>     actions = { nop;
>                 mac_learn; }
>     size = 512;
>     default_action = mac_learn;
>   }
>
>   action broadcast() {
>     standard_metadata.mcast_grp = 1;
>   }
>
>   action forward(bit<9> port) {
>     //standard_metadata.egress_port = port;
>     standard_metadata.egress_spec = port;
>   }
>
>   table dmac {
>     key = { headers.ethernet.dstAddr: exact; }
>     actions = { forward; broadcast; }
>     size = 512;
>     default_action = broadcast;
>   }
>
>   apply {
>     smac.apply();
>     dmac.apply();
>   }
> }
>
> control L2Egress(inout headers_t hdr,
>                  inout metadata_t meta,
>                  inout standard_metadata_t standard_metadata)
> {
>   apply {}
> }
>
>
> control L2ComputeChecksum(inout headers_t hdr,
>                           inout metadata_t meta)
> {
>   apply{}
> }
>
> control L2Deparser(packet_out b, in headers_t hdr)
> {
>   apply{
>     b.emit(hdr.ethernet);
>   }
> }
>
> V1Switch(L2Parser(),
>          L2VerifyChecksum(),
>          L2Ingress(),
>          L2Egress(),
>          L2ComputeChecksum(),
>          L2Deparser()) main;
>
>
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170727/2a6903a5/attachment-0002.html>


More information about the P4-dev mailing list