p4-dev@lists.p4.org

list for questions/discussion of p4 programs and tools

View all threads

register store and retrieve varbit

GC
Ganesh C S
Mon, Sep 13, 2021 7:44 PM

Hi,

I would like to store and retrieve varbit to and from a register. Any
suggestions appreciated?

PS: Below is a short snippet illustrating what I am trying to accomplish.

regs
Ganesh

Code snippet
header hdr {
...
varbit<8> vbit;
}
...
register <varbit<8>,int> reg;
reg.write(hdr.vbit,1);
...
varbit<8> tmp = reg.read(1);

Hi, I would like to store and retrieve varbit to and from a register. Any suggestions appreciated? PS: Below is a short snippet illustrating what I am trying to accomplish. regs Ganesh Code snippet header hdr { ... varbit<8> vbit; } ... register <varbit<8>,int> reg; reg.write(hdr.vbit,1); ... varbit<8> tmp = reg.read(1);
MB
Mihai Budiu
Mon, Sep 13, 2021 7:59 PM

As far as I know the language will let you do that just fine.
But I suspect few target architectures will actually support that.
It should be doable on a software switch, but likely not on an ASIC.

Mihai

From: Ganesh C S ch.sa.ganesh@gmail.com
Sent: Monday, September 13, 2021 12:45 PM
To: p4-dev p4-dev@lists.p4.org
Subject: [P4-dev] register store and retrieve varbit

Hi,

I would like to store and retrieve varbit to and from a register. Any suggestions appreciated?

PS: Below is a short snippet illustrating what I am trying to accomplish.

regs
Ganesh

Code snippet
header hdr {
...
varbit<8> vbit;
}
...
register <varbit<8>,int> reg;
reg.write(hdr.vbit,1);
...
varbit<8> tmp = reg.read(1);

As far as I know the language will let you do that just fine. But I suspect few target architectures will actually support that. It should be doable on a software switch, but likely not on an ASIC. Mihai From: Ganesh C S <ch.sa.ganesh@gmail.com> Sent: Monday, September 13, 2021 12:45 PM To: p4-dev <p4-dev@lists.p4.org> Subject: [P4-dev] register store and retrieve varbit Hi, I would like to store and retrieve varbit to and from a register. Any suggestions appreciated? PS: Below is a short snippet illustrating what I am trying to accomplish. regs Ganesh Code snippet header hdr { ... varbit<8> vbit; } ... register <varbit<8>,int> reg; reg.write(hdr.vbit,1); ... varbit<8> tmp = reg.read(1);
AF
Andy Fingerhut
Sun, Sep 19, 2021 12:05 AM

I would recommend that you would have more success on more P4 targets if,
instead of parsing a varbit field, you created multiple fixed length header
definitions and parsed those instead, and then write whatever fields from
the fixed length header(s) that you actually parsed in a particular packet
to a P4 register.

See this section of an article I wrote a while back giving some
examples/advice in this area:
https://github.com/jafingerhut/p4-guide/tree/master/variable-length-header#alternate-approach-use-multiple-fixed-length-headers

Andy

On Mon, Sep 13, 2021 at 3:45 PM Ganesh C S ch.sa.ganesh@gmail.com wrote:

Hi,

I would like to store and retrieve varbit to and from a register. Any
suggestions appreciated?

PS: Below is a short snippet illustrating what I am trying to accomplish.

regs
Ganesh

Code snippet
header hdr {
...
varbit<8> vbit;
}
...
register <varbit<8>,int> reg;
reg.write(hdr.vbit,1);
...
varbit<8> tmp = reg.read(1);


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

I would recommend that you would have more success on more P4 targets if, instead of parsing a varbit field, you created multiple fixed length header definitions and parsed those instead, and then write whatever fields from the fixed length header(s) that you actually parsed in a particular packet to a P4 register. See this section of an article I wrote a while back giving some examples/advice in this area: https://github.com/jafingerhut/p4-guide/tree/master/variable-length-header#alternate-approach-use-multiple-fixed-length-headers Andy On Mon, Sep 13, 2021 at 3:45 PM Ganesh C S <ch.sa.ganesh@gmail.com> wrote: > Hi, > > I would like to store and retrieve varbit to and from a register. Any > suggestions appreciated? > > PS: Below is a short snippet illustrating what I am trying to accomplish. > > regs > Ganesh > > Code snippet > header hdr { > ... > varbit<8> vbit; > } > ... > register <varbit<8>,int> reg; > reg.write(hdr.vbit,1); > ... > varbit<8> tmp = reg.read(1); > > > _______________________________________________ > 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
GC
Ganesh C S
Sun, Sep 19, 2021 12:32 AM

Thanks Mihai and Andy for the suggestions.

I am trying to work around the limitation.

Let me see if it works out.

Regs
Ganesh

On Sat, Sep 18, 2021, 5:06 PM Andy Fingerhut andy.fingerhut@gmail.com
wrote:

I would recommend that you would have more success on more P4 targets if,
instead of parsing a varbit field, you created multiple fixed length header
definitions and parsed those instead, and then write whatever fields from
the fixed length header(s) that you actually parsed in a particular packet
to a P4 register.

See this section of an article I wrote a while back giving some
examples/advice in this area:
https://github.com/jafingerhut/p4-guide/tree/master/variable-length-header#alternate-approach-use-multiple-fixed-length-headers

Andy

On Mon, Sep 13, 2021 at 3:45 PM Ganesh C S ch.sa.ganesh@gmail.com wrote:

Hi,

I would like to store and retrieve varbit to and from a register. Any
suggestions appreciated?

PS: Below is a short snippet illustrating what I am trying to accomplish.

regs
Ganesh

Code snippet
header hdr {
...
varbit<8> vbit;
}
...
register <varbit<8>,int> reg;
reg.write(hdr.vbit,1);
...
varbit<8> tmp = reg.read(1);


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

Thanks Mihai and Andy for the suggestions. I am trying to work around the limitation. Let me see if it works out. Regs Ganesh On Sat, Sep 18, 2021, 5:06 PM Andy Fingerhut <andy.fingerhut@gmail.com> wrote: > I would recommend that you would have more success on more P4 targets if, > instead of parsing a varbit field, you created multiple fixed length header > definitions and parsed those instead, and then write whatever fields from > the fixed length header(s) that you actually parsed in a particular packet > to a P4 register. > > See this section of an article I wrote a while back giving some > examples/advice in this area: > https://github.com/jafingerhut/p4-guide/tree/master/variable-length-header#alternate-approach-use-multiple-fixed-length-headers > > Andy > > > On Mon, Sep 13, 2021 at 3:45 PM Ganesh C S <ch.sa.ganesh@gmail.com> wrote: > >> Hi, >> >> I would like to store and retrieve varbit to and from a register. Any >> suggestions appreciated? >> >> PS: Below is a short snippet illustrating what I am trying to accomplish. >> >> regs >> Ganesh >> >> Code snippet >> header hdr { >> ... >> varbit<8> vbit; >> } >> ... >> register <varbit<8>,int> reg; >> reg.write(hdr.vbit,1); >> ... >> varbit<8> tmp = reg.read(1); >> >> >> _______________________________________________ >> 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 > >
GC
Ganesh C S
Wed, Sep 22, 2021 8:22 PM
  1. I tried the below approach and it is working fine..

header h1Byte { bit<8> h;}
header h2Byte { bit<16> h;}
...

This involves log size headers with 13 headers we can cover a really long
8k jumbo. Based on the actual length, the corresponding headers will be
extracted. For example, for a binary length of 0b00101010 headers of length
2, 4 and 6 bytes. Now, I am able to parse out and deparse a variable length
data using this approach.

  1. I am planning to check out a header union with all possible lengths (1,
    2, 3, 4 and up to MTU bytes)

header union varlen { //
bit<8> len1Byte;
bit<16> len2Byte;
....
}

Anyone tried this approach. Any suggestions on which of these is better in
terms of resource utilization?

regs
Ganesh

On Sat, Sep 18, 2021 at 5:32 PM Ganesh C S ch.sa.ganesh@gmail.com wrote:

Thanks Mihai and Andy for the suggestions.

I am trying to work around the limitation.

Let me see if it works out.

Regs
Ganesh

On Sat, Sep 18, 2021, 5:06 PM Andy Fingerhut andy.fingerhut@gmail.com
wrote:

I would recommend that you would have more success on more P4 targets if,
instead of parsing a varbit field, you created multiple fixed length header
definitions and parsed those instead, and then write whatever fields from
the fixed length header(s) that you actually parsed in a particular packet
to a P4 register.

See this section of an article I wrote a while back giving some
examples/advice in this area:
https://github.com/jafingerhut/p4-guide/tree/master/variable-length-header#alternate-approach-use-multiple-fixed-length-headers

Andy

On Mon, Sep 13, 2021 at 3:45 PM Ganesh C S ch.sa.ganesh@gmail.com
wrote:

Hi,

I would like to store and retrieve varbit to and from a register. Any
suggestions appreciated?

PS: Below is a short snippet illustrating what I am trying to accomplish.

regs
Ganesh

Code snippet
header hdr {
...
varbit<8> vbit;
}
...
register <varbit<8>,int> reg;
reg.write(hdr.vbit,1);
...
varbit<8> tmp = reg.read(1);


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

1. I tried the below approach and it is working fine.. header h1Byte { bit<8> h;} header h2Byte { bit<16> h;} ... This involves log size headers with 13 headers we can cover a really long 8k jumbo. Based on the actual length, the corresponding headers will be extracted. For example, for a binary length of 0b00101010 headers of length 2, 4 and 6 bytes. Now, I am able to parse out and deparse a variable length data using this approach. 2. I am planning to check out a header union with all possible lengths (1, 2, 3, 4 and up to MTU bytes) header union varlen { // bit<8> len1Byte; bit<16> len2Byte; .... } Anyone tried this approach. Any suggestions on which of these is better in terms of resource utilization? regs Ganesh On Sat, Sep 18, 2021 at 5:32 PM Ganesh C S <ch.sa.ganesh@gmail.com> wrote: > Thanks Mihai and Andy for the suggestions. > > I am trying to work around the limitation. > > Let me see if it works out. > > Regs > Ganesh > > > > On Sat, Sep 18, 2021, 5:06 PM Andy Fingerhut <andy.fingerhut@gmail.com> > wrote: > >> I would recommend that you would have more success on more P4 targets if, >> instead of parsing a varbit field, you created multiple fixed length header >> definitions and parsed those instead, and then write whatever fields from >> the fixed length header(s) that you actually parsed in a particular packet >> to a P4 register. >> >> See this section of an article I wrote a while back giving some >> examples/advice in this area: >> https://github.com/jafingerhut/p4-guide/tree/master/variable-length-header#alternate-approach-use-multiple-fixed-length-headers >> >> Andy >> >> >> On Mon, Sep 13, 2021 at 3:45 PM Ganesh C S <ch.sa.ganesh@gmail.com> >> wrote: >> >>> Hi, >>> >>> I would like to store and retrieve varbit to and from a register. Any >>> suggestions appreciated? >>> >>> PS: Below is a short snippet illustrating what I am trying to accomplish. >>> >>> regs >>> Ganesh >>> >>> Code snippet >>> header hdr { >>> ... >>> varbit<8> vbit; >>> } >>> ... >>> register <varbit<8>,int> reg; >>> reg.write(hdr.vbit,1); >>> ... >>> varbit<8> tmp = reg.read(1); >>> >>> >>> _______________________________________________ >>> 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 >> >>