-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix for issue #1478 * Remove table size when it is not needed
- Loading branch information
Mihai Budiu
committed
Sep 21, 2018
1 parent
675cbec
commit 473980f
Showing
11 changed files
with
395 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2018 VMware, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#ifndef _MIDEND_CHECKSIZE_H_ | ||
#define _MIDEND_CHECKSIZE_H_ | ||
|
||
#include "ir/ir.h" | ||
|
||
namespace P4 { | ||
|
||
/// Checks some possible misuses of the table size property | ||
class CheckTableSize : public Modifier { | ||
public: | ||
CheckTableSize() { setName("CheckTableSize"); } | ||
bool preorder(IR::P4Table* table) override { | ||
auto size = table->getSizeProperty(); | ||
if (size == nullptr) | ||
return false; | ||
|
||
bool deleteSize = false; | ||
auto key = table->getKey(); | ||
if (key == nullptr) { | ||
if (size->value != 1) { | ||
::warning("%1%: Size specified for table without keys", size); | ||
deleteSize = true; | ||
} | ||
} | ||
auto entries = table->properties->getProperty(IR::TableProperties::entriesPropertyName); | ||
if (entries != nullptr && entries->isConstant) { | ||
::warning("%1%: Size specified for table with constant entries", size); | ||
deleteSize = true; | ||
} | ||
if (deleteSize) { | ||
auto props = IR::IndexedVector<IR::Property>(table->properties->properties); | ||
props.removeByName(IR::TableProperties::sizePropertyName); | ||
table->properties = new IR::TableProperties(table->properties->srcInfo, props); | ||
} | ||
return false; | ||
} | ||
}; | ||
|
||
} // namespace P4 | ||
|
||
#endif /* _MIDEND_CHECKSIZE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <core.p4> | ||
#include <v1model.p4> | ||
|
||
header hdr {} | ||
|
||
struct Headers {} | ||
|
||
struct Meta {} | ||
|
||
parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
control vrfy(inout Headers h, inout Meta m) { apply {} } | ||
control update(inout Headers h, inout Meta m) { apply {} } | ||
|
||
control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { apply {} } | ||
|
||
control deparser(packet_out b, in Headers h) { apply {} } | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
table t1 { | ||
size = 3; | ||
actions = { NoAction; } | ||
const default_action = NoAction; | ||
} | ||
table t2 { | ||
key = { sm.ingress_port: exact; } | ||
actions = { NoAction; } | ||
const entries = { | ||
0 : NoAction(); | ||
} | ||
size = 10; | ||
} | ||
apply { t1.apply(); t2.apply(); } | ||
} | ||
|
||
V1Switch(p(), vrfy(), ingress(), egress(), update(), deparser()) main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <core.p4> | ||
#include <v1model.p4> | ||
|
||
header hdr { | ||
} | ||
|
||
struct Headers { | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
control vrfy(inout Headers h, inout Meta m) { | ||
apply { | ||
} | ||
} | ||
|
||
control update(inout Headers h, inout Meta m) { | ||
apply { | ||
} | ||
} | ||
|
||
control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
apply { | ||
} | ||
} | ||
|
||
control deparser(packet_out b, in Headers h) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
table t1 { | ||
size = 3; | ||
actions = { | ||
NoAction(); | ||
} | ||
const default_action = NoAction(); | ||
} | ||
table t2 { | ||
key = { | ||
sm.ingress_port: exact @name("sm.ingress_port") ; | ||
} | ||
actions = { | ||
NoAction(); | ||
} | ||
const entries = { | ||
9w0 : NoAction(); | ||
|
||
} | ||
|
||
size = 10; | ||
default_action = NoAction(); | ||
} | ||
apply { | ||
t1.apply(); | ||
t2.apply(); | ||
} | ||
} | ||
|
||
V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <core.p4> | ||
#include <v1model.p4> | ||
|
||
header hdr { | ||
} | ||
|
||
struct Headers { | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
control vrfy(inout Headers h, inout Meta m) { | ||
apply { | ||
} | ||
} | ||
|
||
control update(inout Headers h, inout Meta m) { | ||
apply { | ||
} | ||
} | ||
|
||
control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
apply { | ||
} | ||
} | ||
|
||
control deparser(packet_out b, in Headers h) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
@name(".NoAction") action NoAction_0() { | ||
} | ||
@name(".NoAction") action NoAction_3() { | ||
} | ||
@name("ingress.t1") table t1 { | ||
size = 3; | ||
actions = { | ||
NoAction_0(); | ||
} | ||
const default_action = NoAction_0(); | ||
} | ||
@name("ingress.t2") table t2 { | ||
key = { | ||
sm.ingress_port: exact @name("sm.ingress_port") ; | ||
} | ||
actions = { | ||
NoAction_3(); | ||
} | ||
const entries = { | ||
9w0 : NoAction_3(); | ||
|
||
} | ||
|
||
size = 10; | ||
default_action = NoAction_3(); | ||
} | ||
apply { | ||
t1.apply(); | ||
t2.apply(); | ||
} | ||
} | ||
|
||
V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <core.p4> | ||
#include <v1model.p4> | ||
|
||
header hdr { | ||
} | ||
|
||
struct Headers { | ||
} | ||
|
||
struct Meta { | ||
} | ||
|
||
parser p(packet_in b, out Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
control vrfy(inout Headers h, inout Meta m) { | ||
apply { | ||
} | ||
} | ||
|
||
control update(inout Headers h, inout Meta m) { | ||
apply { | ||
} | ||
} | ||
|
||
control egress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
apply { | ||
} | ||
} | ||
|
||
control deparser(packet_out b, in Headers h) { | ||
apply { | ||
} | ||
} | ||
|
||
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) { | ||
@name(".NoAction") action NoAction_0() { | ||
} | ||
@name(".NoAction") action NoAction_3() { | ||
} | ||
@name("ingress.t1") table t1 { | ||
size = 3; | ||
actions = { | ||
NoAction_0(); | ||
} | ||
const default_action = NoAction_0(); | ||
} | ||
@name("ingress.t2") table t2 { | ||
key = { | ||
sm.ingress_port: exact @name("sm.ingress_port") ; | ||
} | ||
actions = { | ||
NoAction_3(); | ||
} | ||
const entries = { | ||
9w0 : NoAction_3(); | ||
|
||
} | ||
|
||
size = 10; | ||
default_action = NoAction_3(); | ||
} | ||
apply { | ||
t1.apply(); | ||
t2.apply(); | ||
} | ||
} | ||
|
||
V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main; | ||
|
Oops, something went wrong.