p4-dev@lists.p4.org

list for questions/discussion of p4 programs and tools

View all threads

Way to concatenate two header fields two gather in P4

SG
Sahil Gupta
Sat, Feb 20, 2021 1:27 AM

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly
in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

Hi all, Assume I have 2 header fields of 16 bits each. (f1 and f2) I have a temporary variable, say temp of 32 bits. Can I concatenate two fields and store results in a temp variable directly in P4? Something like: temp = f1.f2; If not, any tricks for this concatenation function in P4? Thanks Sahil Gupta
MB
Mihai Budiu
Sat, Feb 20, 2021 1:29 AM

++ is the concatenation operator for bitstrings


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:27:21 PM
To: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] Way to concatenate two header fields two gather in P4

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

++ is the concatenation operator for bitstrings ________________________________ From: Sahil Gupta <sg5414@rit.edu> Sent: Friday, February 19, 2021 5:27:21 PM To: p4-dev <p4-dev@lists.p4.org> Subject: [P4-dev] Way to concatenate two header fields two gather in P4 Hi all, Assume I have 2 header fields of 16 bits each. (f1 and f2) I have a temporary variable, say temp of 32 bits. Can I concatenate two fields and store results in a temp variable directly in P4? Something like: temp = f1.f2; If not, any tricks for this concatenation function in P4? Thanks Sahil Gupta
SG
Sahil Gupta
Sat, Feb 20, 2021 1:30 AM

Sorry for miss spelled heading.
I hope someone from admin can edit it.
Correct heading: "Way to concatenate two header fields together in P4"

On Fri, Feb 19, 2021 at 8:27 PM Sahil Gupta sg5414@g.rit.edu wrote:

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly
in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

Sorry for miss spelled heading. I hope someone from admin can edit it. Correct heading: "Way to concatenate two header fields together in P4" On Fri, Feb 19, 2021 at 8:27 PM Sahil Gupta <sg5414@g.rit.edu> wrote: > Hi all, > > Assume I have 2 header fields of 16 bits each. (f1 and f2) > I have a temporary variable, say temp of 32 bits. > Can I concatenate two fields and store results in a temp variable directly > in P4? > > Something like: > temp = f1.f2; > > If not, any tricks for this concatenation function in P4? > > Thanks > Sahil Gupta > > >
SG
Sahil Gupta
Sat, Feb 20, 2021 1:31 AM

Thanks Mihai Budiu.
Any examples from the p4c or BMv2 repository where I can see this operator
in action?

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu mbudiu@vmware.com wrote:

++ is the concatenation operator for bitstrings


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:27:21 PM
To: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] Way to concatenate two header fields two gather in P4

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly
in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

Thanks Mihai Budiu. Any examples from the p4c or BMv2 repository where I can see this operator in action? Regards Sahil Gupta On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.com> wrote: > ++ is the concatenation operator for bitstrings > > ------------------------------ > *From:* Sahil Gupta <sg5414@rit.edu> > *Sent:* Friday, February 19, 2021 5:27:21 PM > *To:* p4-dev <p4-dev@lists.p4.org> > *Subject:* [P4-dev] Way to concatenate two header fields two gather in P4 > > Hi all, > > Assume I have 2 header fields of 16 bits each. (f1 and f2) > I have a temporary variable, say temp of 32 bits. > Can I concatenate two fields and store results in a temp variable directly > in P4? > > Something like: > temp = f1.f2; > > If not, any tricks for this concatenation function in P4? > > Thanks > Sahil Gupta > > >
SG
Sahil Gupta
Sat, Feb 20, 2021 1:35 AM

One more question.
Any way to store half the bits of the header?
Say field f is a 16 bit field.
Can I have something like:
temp = f1[0-8];

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:31 PM Sahil Gupta sg5414@g.rit.edu wrote:

Thanks Mihai Budiu.
Any examples from the p4c or BMv2 repository where I can see this operator
in action?

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu mbudiu@vmware.com wrote:

++ is the concatenation operator for bitstrings


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:27:21 PM
To: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] Way to concatenate two header fields two gather in P4

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable
directly in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

One more question. Any way to store half the bits of the header? Say field f is a 16 bit field. Can I have something like: temp = f1[0-8]; Regards Sahil Gupta On Fri, Feb 19, 2021 at 8:31 PM Sahil Gupta <sg5414@g.rit.edu> wrote: > Thanks Mihai Budiu. > Any examples from the p4c or BMv2 repository where I can see this operator > in action? > > Regards > Sahil Gupta > > > On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.com> wrote: > >> ++ is the concatenation operator for bitstrings >> >> ------------------------------ >> *From:* Sahil Gupta <sg5414@rit.edu> >> *Sent:* Friday, February 19, 2021 5:27:21 PM >> *To:* p4-dev <p4-dev@lists.p4.org> >> *Subject:* [P4-dev] Way to concatenate two header fields two gather in P4 >> >> Hi all, >> >> Assume I have 2 header fields of 16 bits each. (f1 and f2) >> I have a temporary variable, say temp of 32 bits. >> Can I concatenate two fields and store results in a temp variable >> directly in P4? >> >> Something like: >> temp = f1.f2; >> >> If not, any tricks for this concatenation function in P4? >> >> Thanks >> Sahil Gupta >> >> >>
MB
Mihai Budiu
Sat, Feb 20, 2021 1:36 AM

The test cases for p4c are all in testdata/p4_16_samples. Grep for ++.


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:31:57 PM
To: Mihai Budiu mbudiu@vmware.com
Cc: p4-dev p4-dev@lists.p4.org
Subject: Re: [P4-dev] Way to concatenate two header fields two gather in P4

Thanks Mihai Budiu.
Any examples from the p4c or BMv2 repository where I can see this operator in action?

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.commailto:mbudiu@vmware.com> wrote:
++ is the concatenation operator for bitstrings


From: Sahil Gupta <sg5414@rit.edumailto:sg5414@rit.edu>
Sent: Friday, February 19, 2021 5:27:21 PM
To: p4-dev <p4-dev@lists.p4.orgmailto:p4-dev@lists.p4.org>
Subject: [P4-dev] Way to concatenate two header fields two gather in P4

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

The test cases for p4c are all in testdata/p4_16_samples. Grep for ++. ________________________________ From: Sahil Gupta <sg5414@rit.edu> Sent: Friday, February 19, 2021 5:31:57 PM To: Mihai Budiu <mbudiu@vmware.com> Cc: p4-dev <p4-dev@lists.p4.org> Subject: Re: [P4-dev] Way to concatenate two header fields two gather in P4 Thanks Mihai Budiu. Any examples from the p4c or BMv2 repository where I can see this operator in action? Regards Sahil Gupta On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.com<mailto:mbudiu@vmware.com>> wrote: ++ is the concatenation operator for bitstrings ________________________________ From: Sahil Gupta <sg5414@rit.edu<mailto:sg5414@rit.edu>> Sent: Friday, February 19, 2021 5:27:21 PM To: p4-dev <p4-dev@lists.p4.org<mailto:p4-dev@lists.p4.org>> Subject: [P4-dev] Way to concatenate two header fields two gather in P4 Hi all, Assume I have 2 header fields of 16 bits each. (f1 and f2) I have a temporary variable, say temp of 32 bits. Can I concatenate two fields and store results in a temp variable directly in P4? Something like: temp = f1.f2; If not, any tricks for this concatenation function in P4? Thanks Sahil Gupta
MB
Mihai Budiu
Sat, Feb 20, 2021 1:38 AM

You want to use the bitslice operator f1[8:0]
The official spec is here https://p4.org/p4-spec/docs/P4-16-v1.2.0.html


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:35:21 PM
To: Mihai Budiu mbudiu@vmware.com
Cc: p4-dev p4-dev@lists.p4.org
Subject: Re: [P4-dev] Way to concatenate two header fields two gather in P4

One more question.
Any way to store half the bits of the header?
Say field f is a 16 bit field.
Can I have something like:
temp = f1[0-8];

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:31 PM Sahil Gupta <sg5414@g.rit.edumailto:sg5414@g.rit.edu> wrote:
Thanks Mihai Budiu.
Any examples from the p4c or BMv2 repository where I can see this operator in action?

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.commailto:mbudiu@vmware.com> wrote:
++ is the concatenation operator for bitstrings


From: Sahil Gupta <sg5414@rit.edumailto:sg5414@rit.edu>
Sent: Friday, February 19, 2021 5:27:21 PM
To: p4-dev <p4-dev@lists.p4.orgmailto:p4-dev@lists.p4.org>
Subject: [P4-dev] Way to concatenate two header fields two gather in P4

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

You want to use the bitslice operator f1[8:0] The official spec is here https://p4.org/p4-spec/docs/P4-16-v1.2.0.html ________________________________ From: Sahil Gupta <sg5414@rit.edu> Sent: Friday, February 19, 2021 5:35:21 PM To: Mihai Budiu <mbudiu@vmware.com> Cc: p4-dev <p4-dev@lists.p4.org> Subject: Re: [P4-dev] Way to concatenate two header fields two gather in P4 One more question. Any way to store half the bits of the header? Say field f is a 16 bit field. Can I have something like: temp = f1[0-8]; Regards Sahil Gupta On Fri, Feb 19, 2021 at 8:31 PM Sahil Gupta <sg5414@g.rit.edu<mailto:sg5414@g.rit.edu>> wrote: Thanks Mihai Budiu. Any examples from the p4c or BMv2 repository where I can see this operator in action? Regards Sahil Gupta On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.com<mailto:mbudiu@vmware.com>> wrote: ++ is the concatenation operator for bitstrings ________________________________ From: Sahil Gupta <sg5414@rit.edu<mailto:sg5414@rit.edu>> Sent: Friday, February 19, 2021 5:27:21 PM To: p4-dev <p4-dev@lists.p4.org<mailto:p4-dev@lists.p4.org>> Subject: [P4-dev] Way to concatenate two header fields two gather in P4 Hi all, Assume I have 2 header fields of 16 bits each. (f1 and f2) I have a temporary variable, say temp of 32 bits. Can I concatenate two fields and store results in a temp variable directly in P4? Something like: temp = f1.f2; If not, any tricks for this concatenation function in P4? Thanks Sahil Gupta
SG
Sahil Gupta
Sat, Feb 20, 2021 1:57 AM

Thanks Mihai Budiu.

On Fri, Feb 19, 2021 at 8:38 PM Mihai Budiu mbudiu@vmware.com wrote:

You want to use the bitslice operator f1[8:0]
The official spec is here https://p4.org/p4-spec/docs/P4-16-v1.2.0.html


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:35:21 PM
To: Mihai Budiu mbudiu@vmware.com
Cc: p4-dev p4-dev@lists.p4.org
Subject: Re: [P4-dev] Way to concatenate two header fields two gather
in P4

One more question.
Any way to store half the bits of the header?
Say field f is a 16 bit field.
Can I have something like:
temp = f1[0-8];

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:31 PM Sahil Gupta sg5414@g.rit.edu wrote:

Thanks Mihai Budiu.
Any examples from the p4c or BMv2 repository where I can see this operator
in action?

Regards
Sahil Gupta

On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu mbudiu@vmware.com wrote:

++ is the concatenation operator for bitstrings


From: Sahil Gupta sg5414@rit.edu
Sent: Friday, February 19, 2021 5:27:21 PM
To: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] Way to concatenate two header fields two gather in P4

Hi all,

Assume I have 2 header fields of 16 bits each. (f1 and f2)
I have a temporary variable, say temp of 32 bits.
Can I concatenate two fields and store results in a temp variable directly
in P4?

Something like:
temp = f1.f2;

If not, any tricks for this concatenation function in P4?

Thanks
Sahil Gupta

Thanks Mihai Budiu. ☺ On Fri, Feb 19, 2021 at 8:38 PM Mihai Budiu <mbudiu@vmware.com> wrote: > You want to use the bitslice operator f1[8:0] > The official spec is here https://p4.org/p4-spec/docs/P4-16-v1.2.0.html > > ------------------------------ > *From:* Sahil Gupta <sg5414@rit.edu> > *Sent:* Friday, February 19, 2021 5:35:21 PM > *To:* Mihai Budiu <mbudiu@vmware.com> > *Cc:* p4-dev <p4-dev@lists.p4.org> > *Subject:* Re: [P4-dev] Way to concatenate two header fields two gather > in P4 > > One more question. > Any way to store half the bits of the header? > Say field f is a 16 bit field. > Can I have something like: > temp = f1[0-8]; > > Regards > Sahil Gupta > > > On Fri, Feb 19, 2021 at 8:31 PM Sahil Gupta <sg5414@g.rit.edu> wrote: > > Thanks Mihai Budiu. > Any examples from the p4c or BMv2 repository where I can see this operator > in action? > > Regards > Sahil Gupta > > > On Fri, Feb 19, 2021 at 8:29 PM Mihai Budiu <mbudiu@vmware.com> wrote: > > ++ is the concatenation operator for bitstrings > > ------------------------------ > *From:* Sahil Gupta <sg5414@rit.edu> > *Sent:* Friday, February 19, 2021 5:27:21 PM > *To:* p4-dev <p4-dev@lists.p4.org> > *Subject:* [P4-dev] Way to concatenate two header fields two gather in P4 > > Hi all, > > Assume I have 2 header fields of 16 bits each. (f1 and f2) > I have a temporary variable, say temp of 32 bits. > Can I concatenate two fields and store results in a temp variable directly > in P4? > > Something like: > temp = f1.f2; > > If not, any tricks for this concatenation function in P4? > > Thanks > Sahil Gupta > > >