[P4-dev] concat fields

David Hancock dhancock at cs.utah.edu
Thu Mar 31 23:27:20 EDT 2016


You can use bitshifts (<< or >>) in the primitive of your choice, e.g., 
modify_field or add_to_field.  So you could do:
   add_to_field(meta.fld, ipv4.protocol);
   add_to_field(meta.fld, tcp.dstPort << 8);
   add_to_field(meta.fld, tcp.srcPort << 24);
   add_to_field(meta.fld, ipv4.dstAddr << 40);
   add_to_field(meta.fld, ipv4.srcAddr << 72);

You could mash all these into one call if you want to; complex math 
expressions are supported.

Good luck,
David

On 03/31/2016 09:14 PM, Yuliang Li wrote:
> Hi Salvatore,
>
> Thank you for you detailed help! But I think my problem is a bit 
> different. I do not need to calculate hash on the 5-tuple. Instead, I 
> only need something to concatenate the 5-tuple into one. What I have 
> now are ipv4.srcAddr (32bits), ipv4.dstAddr (32bits), tcp.srcPort 
> (16bits), tcp.dstPort (16bits), ipv4.protocol(8bits). And I want to 
> have a metadata that is a concatenation of these 5 fields, which is 
> 104bits (32+32+16+16+8). Do you know how to do it?
>
> Thanks,
> Yuliang
>
> On Thu, Mar 31, 2016 at 6:40 PM, Salvatore Signorello 
> <salvatore.signorello at uni.lu <mailto:salvatore.signorello at uni.lu>> wrote:
>
>     Hi Yuliang,
>
>     you can use field list calculation (see sec. 4 "Checksums and
>     Hash-value generators" of the language specification). For
>     instance, you define a field list which is a structure containing
>     all the header fields you want to concat, like follows:
>
>     field_list tuple_fl {
>       headerX.a;
>       headerX.b;
>       headerX.c;
>       headerY.a;
>       headerY.b;
>     }
>
>     then you define a field list calculation which maps the result of
>     a function computed over a field list to an integer value, like
>     follows:
>
>     field_list_calculation tuple_xor {
>         input {
>             tuple_fl;
>         }
>         algorithm : xor16; // a list of the supported algorithms is
>     provided within the aforementioned sec. of the specification
>         output_width : 16;
>     }
>
>
>     Then, you need to copy the tuple_xor value first in a metadata and
>     later in a register by calling an action that could be defined
>     like follows:
>
>     action set_xor_value(base, count) {
>     modify_field_with_hash_based_offset(your_metadata.tuple_xor, base,
>     tuple_xor, ecmp_count);
>         register_write(register_name, index, your_metadata.tuple_xor)
>     }
>
>     While back, the operation above could not be performed in one
>     step, because the "modify_field_with_hash_based_offset" didn't
>     accept a register as 1st argument. Today, I'm not sure that this
>     is still the case.
>
>     Of course, finally, you also need a table that triggers the action
>     above.
>
>     There should be the flowlet switching example that performs a
>     similar operation at
>     https://github.com/p4lang/tutorials/tree/master/SIGCOMM_2015/flowlet_switching
>     <https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_p4lang_tutorials_tree_master_SIGCOMM-5F2015_flowlet-5Fswitching&d=CwMD-g&c=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI&r=-sjq3J2b6bOdupF1bsRuzQ&m=ts0opezTBCtHAf1xuCqwG-VjLs2x3v-lYVJKssygUK4&s=LpAPBumB-CdXnZLTj5b8CcykPe38Y-0wvXVG5DwQlbU&e=>
>
>     Hope that this helps,
>     Salvatore
>
>
>     On 04/01/2016 02:58 AM, Yuliang Li wrote:
>>     Hi,
>>
>>     I need to xor the 5-tuple of each packet into a register. So I
>>     need something like concat(srcip, dstip, srcport, dstport,
>>     protocol), and xor it to my register. Does anyone know how to do
>>     it in p4 data plane?
>>
>>     Thanks,
>>     Yuliang
>>
>>
>>     _______________________________________________
>>     P4-dev mailing list
>>     P4-dev at lists.p4.org <mailto:P4-dev at lists.p4.org>
>>     http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
>>     <https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.p4.org_mailman_listinfo_p4-2Ddev-5Flists.p4.org&d=CwMD-g&c=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI&r=-sjq3J2b6bOdupF1bsRuzQ&m=ts0opezTBCtHAf1xuCqwG-VjLs2x3v-lYVJKssygUK4&s=3xsoZ9rodNaRj0p6jLMCrX4sPLyzSpsq-lW5vSUR08k&e=>
>
>     -- 
>     Salvatore Signorello
>     PhD student of the SEDAN research group at SnT
>
>     Interdisciplinary Centre for Security, Reliability and Trust
>     University of Luxembourg
>     http://wwwen.uni.lu/snt/people/salvatore_signorello
>     <https://urldefense.proofpoint.com/v2/url?u=http-3A__wwwen.uni.lu_snt_people_salvatore-5Fsignorello&d=CwMD-g&c=clK7kQUTWtAVEOVIgvi0NU5BOUHhpN0H8p7CSfnc_gI&r=-sjq3J2b6bOdupF1bsRuzQ&m=ts0opezTBCtHAf1xuCqwG-VjLs2x3v-lYVJKssygUK4&s=vNfG0SW0_svxzN50IYWDky3b0L7GwLPBarxrshLWGsM&e=>
>
>
>
>
> _______________________________________________
> 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/20160331/ec292016/attachment-0002.html>


More information about the P4-dev mailing list