Fix MRI exercise solutions for recent bmv2 versions

Starting with version 1.11, bmv2 conforms with the P4_16 spec and
push_front no longer marks new headers as valid. With this commit, we
add calls to setValid after calls to push_front. For people using older
bmv2 versions, this means that the new header will be marked valid twice
in a row, which should not be an issue.
This commit is contained in:
Antonin Bas 2018-04-14 16:57:57 -07:00
parent ce104fe2bc
commit e535f0429c
4 changed files with 20 additions and 0 deletions

View File

@ -193,6 +193,11 @@ control MyEgress(inout headers hdr,
action add_swtrace(switchID_t swid) { action add_swtrace(switchID_t swid) {
hdr.mri.count = hdr.mri.count + 1; hdr.mri.count = hdr.mri.count + 1;
hdr.swtraces.push_front(1); hdr.swtraces.push_front(1);
// According to the P4_16 spec, pushed elements are invalid, so we need
// to call setValid(). Older bmv2 versions would mark the new header(s)
// valid automatically (P4_14 behavior), but starting with version 1.11,
// bmv2 conforms with the P4_16 spec.
hdr.swtraces[0].setValid();
hdr.swtraces[0].swid = swid; hdr.swtraces[0].swid = swid;
hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth; hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth;

View File

@ -167,6 +167,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
action add_swid(switchID_t id) { action add_swid(switchID_t id) {
hdr.mri.count = hdr.mri.count + 1; hdr.mri.count = hdr.mri.count + 1;
hdr.swids.push_front(1); hdr.swids.push_front(1);
// According to the P4_16 spec, pushed elements are invalid, so we need
// to call setValid(). Older bmv2 versions would mark the new header(s)
// valid automatically (P4_14 behavior), but starting with version 1.11,
// bmv2 conforms with the P4_16 spec.
hdr.swids[0].setValid();
hdr.swids[0].swid = id; hdr.swids[0].swid = id;
hdr.ipv4.ihl = hdr.ipv4.ihl + 1; hdr.ipv4.ihl = hdr.ipv4.ihl + 1;

View File

@ -193,6 +193,11 @@ control MyEgress(inout headers hdr,
action add_swtrace(switchID_t swid) { action add_swtrace(switchID_t swid) {
hdr.mri.count = hdr.mri.count + 1; hdr.mri.count = hdr.mri.count + 1;
hdr.swtraces.push_front(1); hdr.swtraces.push_front(1);
// According to the P4_16 spec, pushed elements are invalid, so we need
// to call setValid(). Older bmv2 versions would mark the new header(s)
// valid automatically (P4_14 behavior), but starting with version 1.11,
// bmv2 conforms with the P4_16 spec.
hdr.swtraces[0].setValid();
hdr.swtraces[0].swid = swid; hdr.swtraces[0].swid = swid;
hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth; hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth;

View File

@ -193,6 +193,11 @@ control MyEgress(inout headers hdr,
action add_swtrace(switchID_t swid) { action add_swtrace(switchID_t swid) {
hdr.mri.count = hdr.mri.count + 1; hdr.mri.count = hdr.mri.count + 1;
hdr.swtraces.push_front(1); hdr.swtraces.push_front(1);
// According to the P4_16 spec, pushed elements are invalid, so we need
// to call setValid(). Older bmv2 versions would mark the new header(s)
// valid automatically (P4_14 behavior), but starting with version 1.11,
// bmv2 conforms with the P4_16 spec.
hdr.swtraces[0].setValid();
hdr.swtraces[0].swid = swid; hdr.swtraces[0].swid = swid;
hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth; hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth;