MAX value positive, check value only in public constructor.
The max value originated a negative value.
Change-Id: I00ba9168e42edcf4ebb3f689151089097d9b69a7
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterId.java b/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
index c8eec46..22ef064 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
@@ -20,34 +20,47 @@
import static com.google.common.base.Preconditions.checkArgument;
/**
- * A representation of a meter id.
+ * A representation of a meter identifier.
* Uniquely identifies a meter in the scope of a single device.
+ * <p>
+ * The meter_id field uniquely identifies a meter within a switch. Meters are
+ * defined starting with meter_id=1 up to the maximum number of meters that the
+ * switch can support. The OpenFlow protocol also defines some additional
+ * virtual meters that can not be associated with flows:
*/
public final class MeterId extends Identifier<Long> {
- static final long MAX = 0xFFFF0000;
+ /** Flow meters can use any number up to MAX. */
+ public static final long MAX = 0xFFFF0000L;
- public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD);
- public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE);
- public static final MeterId ALL = new MeterId(0xFFFFFFFF);
+
+ /* The following are virtual meters as defined in openflow-spec-1.3 P. 58 */
+ /** Meter for slow datapath, if any. */
+ public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFDL);
+ /** Meter for controller connection. */
+ public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFEL);
+ /** Represents all meters for stat requests commands. */
+ public static final MeterId ALL = new MeterId(0xFFFFFFFFL);
+
private MeterId(long id) {
super(id);
- checkArgument(id >= MAX, "id cannot be larger than 0xFFFF0000");
}
@Override
public String toString() {
- return Long.toHexString(this.identifier);
+ return Long.toHexString(identifier);
}
/**
* Creates a new meter identifier.
*
- * @param id backing identifier value
+ * @param id the backing identifier value
* @return meter identifier
*/
public static MeterId meterId(long id) {
+ checkArgument(id > 0, "id cannot be negative nor 0");
+ checkArgument(id <= MAX, "id cannot be larger than {}", MAX);
return new MeterId(id);
}
}
diff --git a/core/common/src/test/java/org/onosproject/codec/impl/TrafficTreatmentCodecTest.java b/core/common/src/test/java/org/onosproject/codec/impl/TrafficTreatmentCodecTest.java
index 3a26a92..250b8bd 100644
--- a/core/common/src/test/java/org/onosproject/codec/impl/TrafficTreatmentCodecTest.java
+++ b/core/common/src/test/java/org/onosproject/codec/impl/TrafficTreatmentCodecTest.java
@@ -64,7 +64,7 @@
Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
- MeterId meterId = MeterId.meterId(0);
+ MeterId meterId = MeterId.meterId(1);
Instruction meter = Instructions.meterTraffic(meterId);
Instruction transition = Instructions.transition(1);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
diff --git a/core/common/src/test/resources/org/onosproject/codec/impl/TrafficTreatment.json b/core/common/src/test/resources/org/onosproject/codec/impl/TrafficTreatment.json
index c185905..40e4eea 100644
--- a/core/common/src/test/resources/org/onosproject/codec/impl/TrafficTreatment.json
+++ b/core/common/src/test/resources/org/onosproject/codec/impl/TrafficTreatment.json
@@ -11,11 +11,11 @@
},
{
"type": "METER",
- "meterId": "0"
+ "meterId": "1"
},
{
"type": "TABLE",
"tableId": "1"
}
]
-}
\ No newline at end of file
+}