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

Hardik Soni hardik.soni at inria.fr
Wed Aug 9 09:41:56 EDT 2017


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 

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


More information about the P4-dev mailing list