Skip to content

Commit

Permalink
Annotate Frontend Counters with Min and Max Width (#329)
Browse files Browse the repository at this point in the history
* Added min_width and max_width for counters

* Test files changed with annotations added to the counters and indexing by a field
  • Loading branch information
evanches authored and ChrisDodd committed Feb 24, 2017
1 parent e83d11b commit 45d1b37
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 11,112 deletions.
8 changes: 7 additions & 1 deletion frontends/p4/fromv1.0/programStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName,
if (action_selector->mode)
annos = annos->addAnnotation("mode", new IR::StringLiteral(action_selector->mode));
if (action_selector->type)
annos = annos->addAnnotation("type", new IR::StringLiteral(action_selector->mode));
annos = annos->addAnnotation("type", new IR::StringLiteral(action_selector->type));
auto prop = new IR::Property(
Util::SourceInfo(), IR::ID(v1model.tableAttributes.tableImplementation.Id()),
annos, propvalue, false);
Expand Down Expand Up @@ -1483,6 +1483,12 @@ ProgramStructure::convert(const IR::CounterOrMeter* cm, cstring newName) {
auto kindarg = counterType(cm);
args->push_back(kindarg);
auto annos = addNameAnnotation(cm->name, cm->annotations);
if (auto *c = cm->to<IR::Counter>()) {
if (c->min_width >= 0)
annos = annos->addAnnotation("min_width", new IR::Constant(c->min_width));
if (c->max_width >= 0)
annos = annos->addAnnotation("max_width", new IR::Constant(c->max_width));
}
auto decl = new IR::Declaration_Instance(
Util::SourceInfo(), newName, annos, type, args, nullptr);
return decl;
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_14_samples/switch_20160226/acl.p4
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ header_type acl_metadata_t {
if_label : 15; /* if label for acls */
bd_label : 16; /* bd label for acls */
mirror_session_id : 10; /* mirror session id */
acl_stats_index : 32; /* acl stats index */
acl_stats_index : 16; /* acl stats index */
}
}
header_type qos_metadata_t {
Expand Down
69 changes: 0 additions & 69 deletions testdata/p4_14_samples_outputs/counter5-first.p4

This file was deleted.

2 changes: 1 addition & 1 deletion testdata/p4_14_samples_outputs/counter5-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t
}

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name("cntDum") counter(32w70000, CounterType.packets) cntDum_0;
@name("cntDum") @min_width(64) counter(32w70000, CounterType.packets) cntDum_0;
@name("act") action act_0(bit<9> port, bit<17> idx) {
standard_metadata.egress_spec = port;
cntDum_0.count((bit<32>)idx);
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_14_samples_outputs/counter5-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t
control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name("NoAction") action NoAction_0() {
}
@name("cntDum") counter(32w70000, CounterType.packets) cntDum;
@name("cntDum") @min_width(64) counter(32w70000, CounterType.packets) cntDum;
@name("act") action act_0(bit<9> port, bit<17> idx) {
standard_metadata.egress_spec = port;
cntDum.count((bit<32>)idx);
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4_14_samples_outputs/counter5.p4
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ control egress(inout headers hdr, inout metadata meta, inout standard_metadata_t
}

control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_t standard_metadata) {
@name("cntDum") counter(32w70000, CounterType.packets) cntDum;
@name("cntDum") @min_width(64) counter(32w70000, CounterType.packets) cntDum;
@name("act") action act(bit<9> port, bit<17> idx) {
standard_metadata.egress_spec = port;
cntDum.count((bit<32>)idx);
Expand Down
Loading

0 comments on commit 45d1b37

Please sign in to comment.