Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The T of register<T>, Can not support Struct or header, but just bit<>? (simple_switch) #440

Open
MaoJianwei opened this issue Sep 15, 2017 · 2 comments

Comments

@MaoJianwei
Copy link

MaoJianwei commented Sep 15, 2017

When I declare neighber as a Struct or a header, it will fail while running simple_switch, as follow:

mao@mao-vm:~/maoP4/testbmv2/techTest$ sudo simple_switch -L 'trace' --log-file ~/maoP4/mao.log --log-flush -i 0@ens192 -i 1@ens224 ~/maoP4/testbmv2/techTest/output.file
Thrift port was not specified, will use 9090
Calling target program-options parser
Adding interface ens192 as port 0
Adding interface ens224 as port 1
Thrift server was started
simple_switch: ../../include/bm/bm_sim/actions.h:327: T bm::ActionParam::to(bm::ActionEngineState*) const [with T = bm::Field&]: Assertion `tag == ActionParam::FIELD' failed.
Aborted (core dumped)
mao@mao-vm:~/maoP4/testbmv2/techTest$ 

Declare is:

struct neighbor {
	bit<20> label;
}

OR

header neighbor {
	bit<20> label;
}

register<neighbor>(10) maoReg;

Read and write register in Ingress control, by:


// simplified code, P4-16

apply {
    neighbor regVal;
    maoReg.read(regVal, 1);
    regVal.label = regVal.label + 1;
    maoReg.write(1, regVal);
}

If I declare register<bit<20>>(10) maoReg;, and modify Read and Write call respectively, it will work well.

The architecture model, <v1model.p4> has:

extern register<T> {
    register(bit<32> size);
    void read(out T result, in bit<32> index);
    void write(in bit<32> index, in T value);
}

In my understanding, T can be anything including typical data-type, structure, header, etc.
Is that right?

@antoninbas
Copy link
Member

I recommend opening an issue with the p4c compiler once again. The backend should probably reject your program as bmv2 currently does not support compound types in registers.
The backend could also generate JSON that goes around this limitation, using masking and shifting when doing reads / writes.
That being said, I will leave this issue open in case there is a desire to add native support for this in bmv2 in the future.

@MaoJianwei
Copy link
Author

ok, desire to see proceeding, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants