Added meter support to P4info to java tool
Change-Id: Ic5ff5a680199d78d7f7725ff18dc05d7ce1151c3
(cherry picked from commit 1edc0bd3fdc82d26da619c8ba6cb4c90d57d87f0)
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
index 36d9f25..484ef5a 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
@@ -19,6 +19,7 @@
import org.onosproject.net.pi.model.PiActionId;
import org.onosproject.net.pi.model.PiActionParamId;
import org.onosproject.net.pi.model.PiActionProfileId;
+import org.onosproject.net.pi.model.PiMeterId;
import org.onosproject.net.pi.model.PiPacketMetadataId;
import org.onosproject.net.pi.model.PiCounterId;
import org.onosproject.net.pi.model.PiMatchFieldId;
@@ -343,4 +344,9 @@
PiPacketMetadataId.of("ingress_port");
public static final PiPacketMetadataId EGRESS_PORT =
PiPacketMetadataId.of("egress_port");
+ // Meter IDs
+ public static final PiMeterId FABRIC_INGRESS_BNG_INGRESS_DOWNSTREAM_M_BESTEFF =
+ PiMeterId.of("FabricIngress.bng_ingress.downstream.m_besteff");
+ public static final PiMeterId FABRIC_INGRESS_BNG_INGRESS_DOWNSTREAM_M_PRIO =
+ PiMeterId.of("FabricIngress.bng_ingress.downstream.m_prio");
}
\ No newline at end of file
diff --git a/tools/dev/bin/onos-gen-p4-constants b/tools/dev/bin/onos-gen-p4-constants
index 2f67201..5f1cb28 100755
--- a/tools/dev/bin/onos-gen-p4-constants
+++ b/tools/dev/bin/onos-gen-p4-constants
@@ -26,6 +26,7 @@
import org.onosproject.net.pi.model.PiActionId;
import org.onosproject.net.pi.model.PiActionParamId;
import org.onosproject.net.pi.model.PiActionProfileId;
+import org.onosproject.net.pi.model.PiMeterId;
import org.onosproject.net.pi.model.PiPacketMetadataId;
import org.onosproject.net.pi.model.PiCounterId;
import org.onosproject.net.pi.model.PiMatchFieldId;
@@ -73,6 +74,9 @@
PI_PKT_META_ID = 'PiPacketMetadataId'
PI_PKT_META_ID_CST = 'PiPacketMetadataId.of("%s")'
+PI_METER_ID = 'PiMeterId'
+PI_METER_ID_CST = 'PiMeterId.of("%s")'
+
HF_VAR_PREFIX = 'HDR_'
@@ -86,6 +90,7 @@
action_params = set()
action_profiles = set()
packet_metadata = set()
+ meters = set()
# https://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-snake-case
def convert_camel_to_all_caps(self, name):
@@ -124,6 +129,8 @@
for cpm in p4info.controller_packet_metadata:
for mta in cpm.metadata:
self.packet_metadata.add(mta.name)
+ for mtr in p4info.meters:
+ self.meters.add(mtr.preamble.name)
def const_line(self, name, type, constructor):
var_name = self.convert_camel_to_all_caps(name)
@@ -184,7 +191,13 @@
if len(self.packet_metadata) is not 0:
lines.append(' // Packet Metadata IDs')
for pmeta in self.packet_metadata:
- lines.append(self.const_line(pmeta, PI_PKT_META_ID, PI_PKT_META_ID_CST))
+ if not pmeta.startswith("_"):
+ lines.append(self.const_line(pmeta, PI_PKT_META_ID, PI_PKT_META_ID_CST))
+
+ if len(self.meters) is not 0:
+ lines.append(' // Meter IDs')
+ for mtr in self.meters:
+ lines.append(self.const_line(mtr, PI_METER_ID, PI_METER_ID_CST))
lines.append(CLASS_CLOSE)
# end of class