Skip to content

Commit e535f04

Browse files
committed
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.
1 parent ce104fe commit e535f04

4 files changed

Lines changed: 20 additions & 0 deletions

File tree

  • P4D2_2017_Fall/exercises/mri/solution
  • P4D2_2017_Spring/exercises/mri/solution
  • P4D2_2018_East/exercises/mri/solution
  • SIGCOMM_2017/exercises/mri/solution

P4D2_2017_Fall/exercises/mri/solution/mri.p4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ control MyEgress(inout headers hdr,
193193
action add_swtrace(switchID_t swid) {
194194
hdr.mri.count = hdr.mri.count + 1;
195195
hdr.swtraces.push_front(1);
196+
// According to the P4_16 spec, pushed elements are invalid, so we need
197+
// to call setValid(). Older bmv2 versions would mark the new header(s)
198+
// valid automatically (P4_14 behavior), but starting with version 1.11,
199+
// bmv2 conforms with the P4_16 spec.
200+
hdr.swtraces[0].setValid();
196201
hdr.swtraces[0].swid = swid;
197202
hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth;
198203

P4D2_2017_Spring/exercises/mri/solution/mri.p4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
167167
action add_swid(switchID_t id) {
168168
hdr.mri.count = hdr.mri.count + 1;
169169
hdr.swids.push_front(1);
170+
// According to the P4_16 spec, pushed elements are invalid, so we need
171+
// to call setValid(). Older bmv2 versions would mark the new header(s)
172+
// valid automatically (P4_14 behavior), but starting with version 1.11,
173+
// bmv2 conforms with the P4_16 spec.
174+
hdr.swids[0].setValid();
170175
hdr.swids[0].swid = id;
171176

172177
hdr.ipv4.ihl = hdr.ipv4.ihl + 1;

P4D2_2018_East/exercises/mri/solution/mri.p4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ control MyEgress(inout headers hdr,
193193
action add_swtrace(switchID_t swid) {
194194
hdr.mri.count = hdr.mri.count + 1;
195195
hdr.swtraces.push_front(1);
196+
// According to the P4_16 spec, pushed elements are invalid, so we need
197+
// to call setValid(). Older bmv2 versions would mark the new header(s)
198+
// valid automatically (P4_14 behavior), but starting with version 1.11,
199+
// bmv2 conforms with the P4_16 spec.
200+
hdr.swtraces[0].setValid();
196201
hdr.swtraces[0].swid = swid;
197202
hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth;
198203

SIGCOMM_2017/exercises/mri/solution/mri.p4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ control MyEgress(inout headers hdr,
193193
action add_swtrace(switchID_t swid) {
194194
hdr.mri.count = hdr.mri.count + 1;
195195
hdr.swtraces.push_front(1);
196+
// According to the P4_16 spec, pushed elements are invalid, so we need
197+
// to call setValid(). Older bmv2 versions would mark the new header(s)
198+
// valid automatically (P4_14 behavior), but starting with version 1.11,
199+
// bmv2 conforms with the P4_16 spec.
200+
hdr.swtraces[0].setValid();
196201
hdr.swtraces[0].swid = swid;
197202
hdr.swtraces[0].qdepth = (qdepth_t)standard_metadata.deq_qdepth;
198203

0 commit comments

Comments
 (0)