[P4-dev] Queries related to primitives in json and bmv2 code

Hardik Soni hardik.soni at inria.fr
Wed Aug 9 10:24:36 EDT 2017


Hello, 

ok, I have the answer of Q1 but there is a follow up question. 
I forgot I took the same primitives.cpp as simple_switch. 
There was a separate file primitves.cpp 

Q1' : How does compiler know the opcode name of primitives for the target? 

Q5: I need information on direction of parameters for the primitives in json or BMV2. 
I meant is there a way to know if the parameter remains constant in the execution of primitive or gets modified. 
Any dirtiest hack would be fine for now. 

-Hardik 

----- Original Message -----

> From: "Hardik Soni" <hardik.soni at inria.fr>
> To: "p4-dev" <p4-dev at lists.p4.org>
> Sent: Wednesday, 9 August, 2017 3:41:56 PM
> Subject: [P4-dev] Queries related to primitives in json and bmv2 code

> Hello,

> Q1. What are the possible "op" values for primitives in context of following
> json snippet?
> I can see the macro, but where is the place where target writers invoke the
> macros?
> Is there a set of basic primitives already defined, lets say for BMV2 simple
> switch target?

> ...

> "primitives" : [
> {
> "op" : "assign",
> "parameters" : [

> ...

> Q2. Do primitives always have two parameters? Left expression and right
> expression?

> Following are the two cases of "assign" primitive.

> Case 1:

> {
> "op" : "assign",
> "parameters" : [
> {
> "type" : "field",
> "value" : ["ethernet", "srcAddr"]
> },
> {
> "type" : "field",
> "value" : ["ethernet", "dstAddr"]
> }
> ],
> "source_info" : {
> "filename" : "./input-p4s/dc.p4",
> "line" : 231,
> "column" : 8,
> "source_fragment" : "hdr.ethernet.srcAddr = hdr.ethernet.dstAddr"
> }
> },

> Case 2:

> {
> "op" : "assign",
> "parameters" : [
> {
> "type" : "field",
> "value" : ["ipv4", "ttl"]
> },
> {
> "type" : "expression",
> "value" : {
> "type" : "expression",
> "value" : {

> "op" : "&",

> "left" : {
> "type" : "expression",
> "value" : {
> "op" : "+",
> "left" : {

> "type" : "field",
> "value" : ["ipv4", "ttl"]

> },
> "right" : {
> "type" : "hexstr",

> "value" : "0xff"
> }
> }

> },
> "right" : {
> "type" : "hexstr",
> "value" : "0xff"
> }
> }
> }

> }
> ],
> "source_info" : {
> "filename" : "./input-p4s/dc.p4",
> "line" : 233,
> "column" : 8,
> "source_fragment" : "hdr.ipv4.ttl = hdr.ipv4.ttl - 1"
> }
> }

> Q3. In the function P4Objects::add_primitive_to_action(const Json::Value
> &cfg_primitive, ActionFn *action_fn)

> there is a comment for "expression" type.

> "// TODO(Antonin): should this make the field case (and other) obsolete

> // maybe if we can optimize this case "

> For future code, do you think all the primitives can be captured as
> expressions?

> Q4. Can I always conclude that the first parameter is left side of assignment
> operator and the second parameter is right side, given that __"op" :
> "assign"__?

> Best Regards,
> Hardik Soni

> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170809/a450d729/attachment-0002.html>


More information about the P4-dev mailing list