Jayasree Ghosh
Committed by Gerrit Code Review

FIX for ONOS-5260: METER AppID Display on GET, Precedence Range Issue

Change-Id: Ia82b8d70de0b5d824d808f9593ada64d3c1fbd09
......@@ -20,6 +20,10 @@ package org.onosproject.net.meter;
*/
public interface Band {
short MIN_PRECEDENCE = 0;
short MAX_PRECEDENCE = 255;
String ERR_MSG = "Precedence out of range";
/**
* Specifies the type of band.
*/
......
......@@ -34,6 +34,9 @@ public final class DefaultBand implements Band, BandEntry {
public DefaultBand(Type type, long rate,
Long burstSize, Short prec) {
this.type = type;
if (type == Type.REMARK) {
checkArgument(prec <= MAX_PRECEDENCE && prec >= MIN_PRECEDENCE, ERR_MSG);
}
this.rate = rate;
this.burstSize = burstSize;
this.prec = prec;
......
......@@ -35,6 +35,7 @@ public class DefaultMeterTest {
private Meter m1;
private Meter sameAsm1;
private Meter m2;
private Meter m3;
@Before
public void setup() {
......@@ -44,6 +45,12 @@ public class DefaultMeterTest {
.withRate(500)
.build();
Band band1 = DefaultBand.builder()
.ofType(Band.Type.REMARK)
.withRate(500)
.dropPrecedence((short) 1)
.build();
m1 = DefaultMeter.builder()
.forDevice(did("1"))
.fromApp(APP_ID)
......@@ -68,13 +75,23 @@ public class DefaultMeterTest {
.withBands(Collections.singletonList(band))
.build();
m3 = DefaultMeter.builder()
.forDevice(did("3"))
.fromApp(APP_ID)
.withId(MeterId.meterId(3))
.withUnit(Meter.Unit.KB_PER_SEC)
.withBands(Collections.singletonList(band1))
.build();
}
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(m1, sameAsm1)
.addEqualityGroup(m2).testEquals();
.addEqualityGroup(m2)
.addEqualityGroup(m3).testEquals();
}
@Test
......
......@@ -61,7 +61,7 @@ public final class MeterCodec extends JsonCodec<Meter> {
.put(DEVICE_ID, meter.deviceId().toString());
if (meter.appId() != null) {
result.put(APP_ID, meter.appId().toString());
result.put(APP_ID, meter.appId().name());
}
if (meter.state() != null) {
......
......@@ -21,7 +21,7 @@
},
"appId": {
"type": "string",
"example": "1"
"example": "org.onosproject.rest"
},
"deviceId": {
"type": "string",
......
......@@ -34,7 +34,7 @@
},
"appId": {
"type": "string",
"example": "1"
"example": "org.onosproject.rest"
},
"deviceId": {
"type": "string",
......
......@@ -263,9 +263,9 @@ public class MetersResourceTest extends ResourceTest {
// check application id
final String jsonAppId = jsonMeter.get("appId").asString();
final String appId = meter.appId().toString();
final String appId = meter.appId().name();
if (!jsonAppId.equals(appId)) {
reason = "appId " + meter.appId().toString();
reason = "appId " + meter.appId().name();
return false;
}
......