p4-dev@lists.p4.org

list for questions/discussion of p4 programs and tools

View all threads

Tuple and variable manipulation

FM
Francisco Machado
Fri, May 7, 2021 1:17 PM

Hi,

I am trying to implement a NAT without a controller. I am using Registers
to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change the
ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible to store
tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily, for example:
mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored
5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access
specific "parts" of the variable, and since I don't think I can use
tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one specific
    field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store flow
information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone could
send me some I'd appreciate it.

Thanks in advance,
Francisco Machado

Hi, I am trying to implement a NAT without a controller. I am using Registers to store flow information (5-tuple + NAT port). Then, in each side of the NAT I would access the register and change the ports and IP addresses accordingly. So, I have some questions regarding tuples, like is it possible to store tuples or lists in registers? I tried it but without success This would be great because then I could access fields easily, for example: mytuple[0] = hdr.tcp.srcPort I also tried this but, once again, without success. In previous work, I only needed to compare several flows, so I stored 5-tuples by concatenating them in a variable of 104 bytes. This worked because I only needed to compare them, now I need to access specific "parts" of the variable, and since I don't think I can use tuples/lists, my question regarding variables is: - How can I access only a specific number of bytes to retrieve one specific field? For example, I only pretend to read from byte 17 to 32. Also, do you recommend other, more appropriate, structures to store flow information? Or other strategies? I didn't find any examples/demos that worked with tuples, if someone could send me some I'd appreciate it. Thanks in advance, Francisco Machado
AF
Andy Fingerhut
Fri, May 7, 2021 1:46 PM

Here is part of an example program for the PSA architecture that gives one
way that you can semi-conveniently treat a long bit<80> value as "kind of
like a struct":
https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88

Some target devices may have smaller maximum limits than that on register
array element bit widths, and then the only choice is to figure out how to
break up a single register array into multiple narrower ones (each with the
same number of entries, typically).

Andy

On Fri, May 7, 2021 at 9:18 AM Francisco Machado <
franciscocmachado@gmail.com> wrote:

Hi,

I am trying to implement a NAT without a controller. I am using Registers
to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change the
ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible to store
tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily,
for example: mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored
5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access
specific "parts" of the variable, and since I don't think I can use
tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one
    specific field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store flow
information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone could
send me some I'd appreciate it.

Thanks in advance,
Francisco Machado


P4-dev mailing list -- p4-dev@lists.p4.org
To unsubscribe send an email to p4-dev-leave@lists.p4.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Here is part of an example program for the PSA architecture that gives one way that you can semi-conveniently treat a long bit<80> value as "kind of like a struct": https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88 Some target devices may have smaller maximum limits than that on register array element bit widths, and then the only choice is to figure out how to break up a single register array into multiple narrower ones (each with the same number of entries, typically). Andy On Fri, May 7, 2021 at 9:18 AM Francisco Machado < franciscocmachado@gmail.com> wrote: > Hi, > > I am trying to implement a NAT without a controller. I am using Registers > to store flow information (5-tuple + NAT port). > Then, in each side of the NAT I would access the register and change the > ports and IP addresses accordingly. > > So, I have some questions regarding tuples, like is it possible to store > tuples or lists in registers? I tried it but without success > This would be great because then I could access fields easily, > for example: mytuple[0] = hdr.tcp.srcPort > I also tried this but, once again, without success. > > In previous work, I only needed to compare several flows, so I stored > 5-tuples by concatenating them in a variable of 104 bytes. > This worked because I only needed to compare them, now I need to access > specific "parts" of the variable, and since I don't think I can use > tuples/lists, > my question regarding variables is: > - How can I access only a specific number of bytes to retrieve one > specific field? For example, I only pretend to read from byte 17 to 32. > > Also, do you recommend other, more appropriate, structures to store flow > information? Or other strategies? > I didn't find any examples/demos that worked with tuples, if someone could > send me some I'd appreciate it. > > Thanks in advance, > Francisco Machado > > _______________________________________________ > P4-dev mailing list -- p4-dev@lists.p4.org > To unsubscribe send an email to p4-dev-leave@lists.p4.org > %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
FM
Francisco Machado
Sat, May 8, 2021 4:44 PM

The example was useful but I could not replicate it with v1model.p4.
I get the following error:

[--Werror=type-error] error: Array indexing [] applied to non-array type
bit<120>

Are types in v1model different from PSA?

Francisco

Andy Fingerhut andy.fingerhut@gmail.com escreveu no dia sexta, 7/05/2021
à(s) 14:46:

Here is part of an example program for the PSA architecture that gives one
way that you can semi-conveniently treat a long bit<80> value as "kind of
like a struct":
https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88

Some target devices may have smaller maximum limits than that on register
array element bit widths, and then the only choice is to figure out how to
break up a single register array into multiple narrower ones (each with the
same number of entries, typically).

Andy

On Fri, May 7, 2021 at 9:18 AM Francisco Machado <
franciscocmachado@gmail.com> wrote:

Hi,

I am trying to implement a NAT without a controller. I am using Registers
to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change the
ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible to store
tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily,
for example: mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored
5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access
specific "parts" of the variable, and since I don't think I can use
tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one
    specific field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store flow
information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone
could send me some I'd appreciate it.

Thanks in advance,
Francisco Machado


P4-dev mailing list -- p4-dev@lists.p4.org
To unsubscribe send an email to p4-dev-leave@lists.p4.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

The example was useful but I could not replicate it with v1model.p4. I get the following error: > [--Werror=type-error] error: Array indexing [] applied to non-array type > bit<120> Are types in v1model different from PSA? Francisco Andy Fingerhut <andy.fingerhut@gmail.com> escreveu no dia sexta, 7/05/2021 à(s) 14:46: > Here is part of an example program for the PSA architecture that gives one > way that you can semi-conveniently treat a long bit<80> value as "kind of > like a struct": > https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88 > > Some target devices may have smaller maximum limits than that on register > array element bit widths, and then the only choice is to figure out how to > break up a single register array into multiple narrower ones (each with the > same number of entries, typically). > > Andy > > On Fri, May 7, 2021 at 9:18 AM Francisco Machado < > franciscocmachado@gmail.com> wrote: > >> Hi, >> >> I am trying to implement a NAT without a controller. I am using Registers >> to store flow information (5-tuple + NAT port). >> Then, in each side of the NAT I would access the register and change the >> ports and IP addresses accordingly. >> >> So, I have some questions regarding tuples, like is it possible to store >> tuples or lists in registers? I tried it but without success >> This would be great because then I could access fields easily, >> for example: mytuple[0] = hdr.tcp.srcPort >> I also tried this but, once again, without success. >> >> In previous work, I only needed to compare several flows, so I stored >> 5-tuples by concatenating them in a variable of 104 bytes. >> This worked because I only needed to compare them, now I need to access >> specific "parts" of the variable, and since I don't think I can use >> tuples/lists, >> my question regarding variables is: >> - How can I access only a specific number of bytes to retrieve one >> specific field? For example, I only pretend to read from byte 17 to 32. >> >> Also, do you recommend other, more appropriate, structures to store flow >> information? Or other strategies? >> I didn't find any examples/demos that worked with tuples, if someone >> could send me some I'd appreciate it. >> >> Thanks in advance, >> Francisco Machado >> >> _______________________________________________ >> P4-dev mailing list -- p4-dev@lists.p4.org >> To unsubscribe send an email to p4-dev-leave@lists.p4.org >> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s > >
MB
Mihai Budiu
Sat, May 8, 2021 4:56 PM

You probably don't have a recent version of the compiler.


From: Francisco Machado franciscocmachado@gmail.com
Sent: Saturday, May 8, 2021 9:44:28 AM
To: Andy Fingerhut andy.fingerhut@gmail.com
Cc: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] Re: Tuple and variable manipulation

The example was useful but I could not replicate it with v1model.p4.
I get the following error:
[--Werror=type-error] error: Array indexing [] applied to non-array type bit<120>

Are types in v1model different from PSA?

Francisco

Andy Fingerhut <andy.fingerhut@gmail.commailto:andy.fingerhut@gmail.com> escreveu no dia sexta, 7/05/2021 à(s) 14:46:
Here is part of an example program for the PSA architecture that gives one way that you can semi-conveniently treat a long bit<80> value as "kind of like a struct": https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fp4-spec%2Fblob%2Fmain%2Fp4-16%2Fpsa%2Fexamples%2Fpsa-example-register2.p4%23L62-L88&data=04%7C01%7Cmbudiu%40vmware.com%7C20f46ebc7680444aabb308d91240af80%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637560891306811200%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=wUGc9u0jHbuzDefmUFfJIhc0yGki3WlKr6sm%2FbIUgQU%3D&reserved=0

Some target devices may have smaller maximum limits than that on register array element bit widths, and then the only choice is to figure out how to break up a single register array into multiple narrower ones (each with the same number of entries, typically).

Andy

On Fri, May 7, 2021 at 9:18 AM Francisco Machado <franciscocmachado@gmail.commailto:franciscocmachado@gmail.com> wrote:
Hi,

I am trying to implement a NAT without a controller. I am using Registers to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change the ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible to store tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily, for example: mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored 5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access specific "parts" of the variable, and since I don't think I can use tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one specific field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store flow information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone could send me some I'd appreciate it.

Thanks in advance,
Francisco Machado


P4-dev mailing list -- p4-dev@lists.p4.orgmailto:p4-dev@lists.p4.org
To unsubscribe send an email to p4-dev-leave@lists.p4.orgmailto:p4-dev-leave@lists.p4.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

You probably don't have a recent version of the compiler. ________________________________ From: Francisco Machado <franciscocmachado@gmail.com> Sent: Saturday, May 8, 2021 9:44:28 AM To: Andy Fingerhut <andy.fingerhut@gmail.com> Cc: p4-dev <p4-dev@lists.p4.org> Subject: [P4-dev] Re: Tuple and variable manipulation The example was useful but I could not replicate it with v1model.p4. I get the following error: [--Werror=type-error] error: Array indexing [] applied to non-array type bit<120> Are types in v1model different from PSA? Francisco Andy Fingerhut <andy.fingerhut@gmail.com<mailto:andy.fingerhut@gmail.com>> escreveu no dia sexta, 7/05/2021 à(s) 14:46: Here is part of an example program for the PSA architecture that gives one way that you can semi-conveniently treat a long bit<80> value as "kind of like a struct": https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88<https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fp4-spec%2Fblob%2Fmain%2Fp4-16%2Fpsa%2Fexamples%2Fpsa-example-register2.p4%23L62-L88&data=04%7C01%7Cmbudiu%40vmware.com%7C20f46ebc7680444aabb308d91240af80%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637560891306811200%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=wUGc9u0jHbuzDefmUFfJIhc0yGki3WlKr6sm%2FbIUgQU%3D&reserved=0> Some target devices may have smaller maximum limits than that on register array element bit widths, and then the only choice is to figure out how to break up a single register array into multiple narrower ones (each with the same number of entries, typically). Andy On Fri, May 7, 2021 at 9:18 AM Francisco Machado <franciscocmachado@gmail.com<mailto:franciscocmachado@gmail.com>> wrote: Hi, I am trying to implement a NAT without a controller. I am using Registers to store flow information (5-tuple + NAT port). Then, in each side of the NAT I would access the register and change the ports and IP addresses accordingly. So, I have some questions regarding tuples, like is it possible to store tuples or lists in registers? I tried it but without success This would be great because then I could access fields easily, for example: mytuple[0] = hdr.tcp.srcPort I also tried this but, once again, without success. In previous work, I only needed to compare several flows, so I stored 5-tuples by concatenating them in a variable of 104 bytes. This worked because I only needed to compare them, now I need to access specific "parts" of the variable, and since I don't think I can use tuples/lists, my question regarding variables is: - How can I access only a specific number of bytes to retrieve one specific field? For example, I only pretend to read from byte 17 to 32. Also, do you recommend other, more appropriate, structures to store flow information? Or other strategies? I didn't find any examples/demos that worked with tuples, if someone could send me some I'd appreciate it. Thanks in advance, Francisco Machado _______________________________________________ P4-dev mailing list -- p4-dev@lists.p4.org<mailto:p4-dev@lists.p4.org> To unsubscribe send an email to p4-dev-leave@lists.p4.org<mailto:p4-dev-leave@lists.p4.org> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s
FM
Francisco Machado
Sat, May 8, 2021 9:00 PM

How can I update the p4c to a more recent compiler? I'm using

p4c 1.1.0-rc1 (SHA: 8742052)

Mihai Budiu mbudiu@vmware.com escreveu no dia sábado, 8/05/2021 à(s)
17:56:

You probably don't have a recent version of the compiler.


From: Francisco Machado franciscocmachado@gmail.com
Sent: Saturday, May 8, 2021 9:44:28 AM
To: Andy Fingerhut andy.fingerhut@gmail.com
Cc: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] Re: Tuple and variable manipulation

The example was useful but I could not replicate it with v1model.p4.
I get the following error:

[--Werror=type-error] error: Array indexing [] applied to non-array type
bit<120>

Are types in v1model different from PSA?

Francisco

Andy Fingerhut andy.fingerhut@gmail.com escreveu no dia sexta,
7/05/2021 à(s) 14:46:

Here is part of an example program for the PSA architecture that gives one
way that you can semi-conveniently treat a long bit<80> value as "kind of
like a struct":
https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fp4-spec%2Fblob%2Fmain%2Fp4-16%2Fpsa%2Fexamples%2Fpsa-example-register2.p4%23L62-L88&data=04%7C01%7Cmbudiu%40vmware.com%7C20f46ebc7680444aabb308d91240af80%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637560891306811200%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=wUGc9u0jHbuzDefmUFfJIhc0yGki3WlKr6sm%2FbIUgQU%3D&reserved=0

Some target devices may have smaller maximum limits than that on register
array element bit widths, and then the only choice is to figure out how to
break up a single register array into multiple narrower ones (each with the
same number of entries, typically).

Andy

On Fri, May 7, 2021 at 9:18 AM Francisco Machado <
franciscocmachado@gmail.com> wrote:

Hi,

I am trying to implement a NAT without a controller. I am using Registers
to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change the
ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible to store
tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily,
for example: mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored
5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access
specific "parts" of the variable, and since I don't think I can use
tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one
    specific field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store flow
information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone could
send me some I'd appreciate it.

Thanks in advance,
Francisco Machado


P4-dev mailing list -- p4-dev@lists.p4.org
To unsubscribe send an email to p4-dev-leave@lists.p4.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

How can I update the p4c to a more recent compiler? I'm using > p4c 1.1.0-rc1 (SHA: 8742052) Mihai Budiu <mbudiu@vmware.com> escreveu no dia sábado, 8/05/2021 à(s) 17:56: > You probably don't have a recent version of the compiler. > > ------------------------------ > *From:* Francisco Machado <franciscocmachado@gmail.com> > *Sent:* Saturday, May 8, 2021 9:44:28 AM > *To:* Andy Fingerhut <andy.fingerhut@gmail.com> > *Cc:* p4-dev <p4-dev@lists.p4.org> > *Subject:* [P4-dev] Re: Tuple and variable manipulation > > The example was useful but I could not replicate it with v1model.p4. > I get the following error: > > [--Werror=type-error] error: Array indexing [] applied to non-array type > bit<120> > > > Are types in v1model different from PSA? > > Francisco > > > Andy Fingerhut <andy.fingerhut@gmail.com> escreveu no dia sexta, > 7/05/2021 à(s) 14:46: > > Here is part of an example program for the PSA architecture that gives one > way that you can semi-conveniently treat a long bit<80> value as "kind of > like a struct": > https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88 > <https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fp4lang%2Fp4-spec%2Fblob%2Fmain%2Fp4-16%2Fpsa%2Fexamples%2Fpsa-example-register2.p4%23L62-L88&data=04%7C01%7Cmbudiu%40vmware.com%7C20f46ebc7680444aabb308d91240af80%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637560891306811200%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&sdata=wUGc9u0jHbuzDefmUFfJIhc0yGki3WlKr6sm%2FbIUgQU%3D&reserved=0> > > Some target devices may have smaller maximum limits than that on register > array element bit widths, and then the only choice is to figure out how to > break up a single register array into multiple narrower ones (each with the > same number of entries, typically). > > Andy > > On Fri, May 7, 2021 at 9:18 AM Francisco Machado < > franciscocmachado@gmail.com> wrote: > > Hi, > > I am trying to implement a NAT without a controller. I am using Registers > to store flow information (5-tuple + NAT port). > Then, in each side of the NAT I would access the register and change the > ports and IP addresses accordingly. > > So, I have some questions regarding tuples, like is it possible to store > tuples or lists in registers? I tried it but without success > This would be great because then I could access fields easily, > for example: mytuple[0] = hdr.tcp.srcPort > I also tried this but, once again, without success. > > In previous work, I only needed to compare several flows, so I stored > 5-tuples by concatenating them in a variable of 104 bytes. > This worked because I only needed to compare them, now I need to access > specific "parts" of the variable, and since I don't think I can use > tuples/lists, > my question regarding variables is: > - How can I access only a specific number of bytes to retrieve one > specific field? For example, I only pretend to read from byte 17 to 32. > > Also, do you recommend other, more appropriate, structures to store flow > information? Or other strategies? > I didn't find any examples/demos that worked with tuples, if someone could > send me some I'd appreciate it. > > Thanks in advance, > Francisco Machado > > _______________________________________________ > P4-dev mailing list -- p4-dev@lists.p4.org > To unsubscribe send an email to p4-dev-leave@lists.p4.org > %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s > >
AF
Andy Fingerhut
Sat, May 8, 2021 10:57 PM

Another possible reason for the error you see is not because of a too-old
p4c compiler version, but because you tried to do a bit access like foo[5]
to access a single bit position.

If you want to do a bit slice to access a single bit position, you still
need to use the syntax foo[5:5] to give the most significant bit position,
and the least significant bit position, even of those are the same bit
position.

Andy

On Sat, May 8, 2021 at 12:45 PM Francisco Machado <
franciscocmachado@gmail.com> wrote:

The example was useful but I could not replicate it with v1model.p4.
I get the following error:

[--Werror=type-error] error: Array indexing [] applied to non-array type
bit<120>

Are types in v1model different from PSA?

Francisco

Andy Fingerhut andy.fingerhut@gmail.com escreveu no dia sexta,
7/05/2021 à(s) 14:46:

Here is part of an example program for the PSA architecture that gives
one way that you can semi-conveniently treat a long bit<80> value as "kind
of like a struct":
https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88

Some target devices may have smaller maximum limits than that on register
array element bit widths, and then the only choice is to figure out how to
break up a single register array into multiple narrower ones (each with the
same number of entries, typically).

Andy

On Fri, May 7, 2021 at 9:18 AM Francisco Machado <
franciscocmachado@gmail.com> wrote:

Hi,

I am trying to implement a NAT without a controller. I am using
Registers to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change the
ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible to store
tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily,
for example: mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored
5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access
specific "parts" of the variable, and since I don't think I can use
tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one
    specific field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store flow
information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone
could send me some I'd appreciate it.

Thanks in advance,
Francisco Machado


P4-dev mailing list -- p4-dev@lists.p4.org
To unsubscribe send an email to p4-dev-leave@lists.p4.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Another possible reason for the error you see is not because of a too-old p4c compiler version, but because you tried to do a bit access like foo[5] to access a single bit position. If you want to do a bit slice to access a single bit position, you still need to use the syntax foo[5:5] to give the most significant bit position, and the least significant bit position, even of those are the same bit position. Andy On Sat, May 8, 2021 at 12:45 PM Francisco Machado < franciscocmachado@gmail.com> wrote: > The example was useful but I could not replicate it with v1model.p4. > I get the following error: > >> [--Werror=type-error] error: Array indexing [] applied to non-array type >> bit<120> > > > Are types in v1model different from PSA? > > Francisco > > > Andy Fingerhut <andy.fingerhut@gmail.com> escreveu no dia sexta, > 7/05/2021 à(s) 14:46: > >> Here is part of an example program for the PSA architecture that gives >> one way that you can semi-conveniently treat a long bit<80> value as "kind >> of like a struct": >> https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88 >> >> Some target devices may have smaller maximum limits than that on register >> array element bit widths, and then the only choice is to figure out how to >> break up a single register array into multiple narrower ones (each with the >> same number of entries, typically). >> >> Andy >> >> On Fri, May 7, 2021 at 9:18 AM Francisco Machado < >> franciscocmachado@gmail.com> wrote: >> >>> Hi, >>> >>> I am trying to implement a NAT without a controller. I am using >>> Registers to store flow information (5-tuple + NAT port). >>> Then, in each side of the NAT I would access the register and change the >>> ports and IP addresses accordingly. >>> >>> So, I have some questions regarding tuples, like is it possible to store >>> tuples or lists in registers? I tried it but without success >>> This would be great because then I could access fields easily, >>> for example: mytuple[0] = hdr.tcp.srcPort >>> I also tried this but, once again, without success. >>> >>> In previous work, I only needed to compare several flows, so I stored >>> 5-tuples by concatenating them in a variable of 104 bytes. >>> This worked because I only needed to compare them, now I need to access >>> specific "parts" of the variable, and since I don't think I can use >>> tuples/lists, >>> my question regarding variables is: >>> - How can I access only a specific number of bytes to retrieve one >>> specific field? For example, I only pretend to read from byte 17 to 32. >>> >>> Also, do you recommend other, more appropriate, structures to store flow >>> information? Or other strategies? >>> I didn't find any examples/demos that worked with tuples, if someone >>> could send me some I'd appreciate it. >>> >>> Thanks in advance, >>> Francisco Machado >>> >>> _______________________________________________ >>> P4-dev mailing list -- p4-dev@lists.p4.org >>> To unsubscribe send an email to p4-dev-leave@lists.p4.org >>> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s >> >>
FM
Francisco Machado
Sun, May 9, 2021 9:37 PM

This was the problem.. thank you for the help.

Another possible reason for the error you see is not because of a too-old
p4c compiler version, but because you tried to do a bit access like foo[5]
to access a single bit position.

Andy Fingerhut andy.fingerhut@gmail.com escreveu no dia sábado, 8/05/2021
à(s) 23:57:

Another possible reason for the error you see is not because of a too-old
p4c compiler version, but because you tried to do a bit access like foo[5]
to access a single bit position.

If you want to do a bit slice to access a single bit position, you still
need to use the syntax foo[5:5] to give the most significant bit position,
and the least significant bit position, even of those are the same bit
position.

Andy

On Sat, May 8, 2021 at 12:45 PM Francisco Machado <
franciscocmachado@gmail.com> wrote:

The example was useful but I could not replicate it with v1model.p4.
I get the following error:

[--Werror=type-error] error: Array indexing [] applied to non-array type
bit<120>

Are types in v1model different from PSA?

Francisco

Andy Fingerhut andy.fingerhut@gmail.com escreveu no dia sexta,
7/05/2021 à(s) 14:46:

Here is part of an example program for the PSA architecture that gives
one way that you can semi-conveniently treat a long bit<80> value as "kind
of like a struct":
https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88

Some target devices may have smaller maximum limits than that on
register array element bit widths, and then the only choice is to figure
out how to break up a single register array into multiple narrower ones
(each with the same number of entries, typically).

Andy

On Fri, May 7, 2021 at 9:18 AM Francisco Machado <
franciscocmachado@gmail.com> wrote:

Hi,

I am trying to implement a NAT without a controller. I am using
Registers to store flow information (5-tuple + NAT port).
Then, in each side of the NAT I would access the register and change
the ports and IP addresses accordingly.

So, I have some questions regarding tuples, like is it possible
to store tuples or lists in registers? I tried it but without success
This would be great because then I could access fields easily,
for example: mytuple[0] = hdr.tcp.srcPort
I also tried this but, once again, without success.

In previous work, I only needed to compare several flows, so I stored
5-tuples by concatenating them in a variable of 104 bytes.
This worked because I only needed to compare them, now I need to access
specific "parts" of the variable, and since I don't think I can use
tuples/lists,
my question regarding variables is:

  • How can I access only a specific number of bytes to retrieve one
    specific field? For example, I only pretend to read from byte 17 to 32.

Also, do you recommend other, more appropriate, structures to store
flow information? Or other strategies?
I didn't find any examples/demos that worked with tuples, if someone
could send me some I'd appreciate it.

Thanks in advance,
Francisco Machado


P4-dev mailing list -- p4-dev@lists.p4.org
To unsubscribe send an email to p4-dev-leave@lists.p4.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

This was the problem.. thank you for the help. > Another possible reason for the error you see is not because of a too-old > p4c compiler version, but because you tried to do a bit access like foo[5] > to access a single bit position. Andy Fingerhut <andy.fingerhut@gmail.com> escreveu no dia sábado, 8/05/2021 à(s) 23:57: > Another possible reason for the error you see is not because of a too-old > p4c compiler version, but because you tried to do a bit access like foo[5] > to access a single bit position. > > If you want to do a bit slice to access a single bit position, you still > need to use the syntax foo[5:5] to give the most significant bit position, > and the least significant bit position, even of those are the same bit > position. > > Andy > > > On Sat, May 8, 2021 at 12:45 PM Francisco Machado < > franciscocmachado@gmail.com> wrote: > >> The example was useful but I could not replicate it with v1model.p4. >> I get the following error: >> >>> [--Werror=type-error] error: Array indexing [] applied to non-array type >>> bit<120> >> >> >> Are types in v1model different from PSA? >> >> Francisco >> >> >> Andy Fingerhut <andy.fingerhut@gmail.com> escreveu no dia sexta, >> 7/05/2021 à(s) 14:46: >> >>> Here is part of an example program for the PSA architecture that gives >>> one way that you can semi-conveniently treat a long bit<80> value as "kind >>> of like a struct": >>> https://github.com/p4lang/p4-spec/blob/main/p4-16/psa/examples/psa-example-register2.p4#L62-L88 >>> >>> Some target devices may have smaller maximum limits than that on >>> register array element bit widths, and then the only choice is to figure >>> out how to break up a single register array into multiple narrower ones >>> (each with the same number of entries, typically). >>> >>> Andy >>> >>> On Fri, May 7, 2021 at 9:18 AM Francisco Machado < >>> franciscocmachado@gmail.com> wrote: >>> >>>> Hi, >>>> >>>> I am trying to implement a NAT without a controller. I am using >>>> Registers to store flow information (5-tuple + NAT port). >>>> Then, in each side of the NAT I would access the register and change >>>> the ports and IP addresses accordingly. >>>> >>>> So, I have some questions regarding tuples, like is it possible >>>> to store tuples or lists in registers? I tried it but without success >>>> This would be great because then I could access fields easily, >>>> for example: mytuple[0] = hdr.tcp.srcPort >>>> I also tried this but, once again, without success. >>>> >>>> In previous work, I only needed to compare several flows, so I stored >>>> 5-tuples by concatenating them in a variable of 104 bytes. >>>> This worked because I only needed to compare them, now I need to access >>>> specific "parts" of the variable, and since I don't think I can use >>>> tuples/lists, >>>> my question regarding variables is: >>>> - How can I access only a specific number of bytes to retrieve one >>>> specific field? For example, I only pretend to read from byte 17 to 32. >>>> >>>> Also, do you recommend other, more appropriate, structures to store >>>> flow information? Or other strategies? >>>> I didn't find any examples/demos that worked with tuples, if someone >>>> could send me some I'd appreciate it. >>>> >>>> Thanks in advance, >>>> Francisco Machado >>>> >>>> _______________________________________________ >>>> P4-dev mailing list -- p4-dev@lists.p4.org >>>> To unsubscribe send an email to p4-dev-leave@lists.p4.org >>>> %(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s >>> >>>