p4lang / behavioral-model

The reference P4 software switch
Apache License 2.0
536 stars 328 forks source link

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

Open MaoJianwei opened 7 years ago

MaoJianwei commented 7 years ago

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, 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 commented 7 years ago

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 commented 7 years ago

ok, desire to see proceeding, thank you