Committed by
Gerrit Code Review
FIX for ONOS-5260: METER AppID Display on GET, Precedence Range Issue
Change-Id: Ia82b8d70de0b5d824d808f9593ada64d3c1fbd09
Showing
7 changed files
with
32 additions
and
8 deletions
| ... | @@ -20,6 +20,10 @@ package org.onosproject.net.meter; | ... | @@ -20,6 +20,10 @@ package org.onosproject.net.meter; |
| 20 | */ | 20 | */ |
| 21 | public interface Band { | 21 | public interface Band { |
| 22 | 22 | ||
| 23 | + short MIN_PRECEDENCE = 0; | ||
| 24 | + short MAX_PRECEDENCE = 255; | ||
| 25 | + String ERR_MSG = "Precedence out of range"; | ||
| 26 | + | ||
| 23 | /** | 27 | /** |
| 24 | * Specifies the type of band. | 28 | * Specifies the type of band. |
| 25 | */ | 29 | */ | ... | ... |
| ... | @@ -34,6 +34,9 @@ public final class DefaultBand implements Band, BandEntry { | ... | @@ -34,6 +34,9 @@ public final class DefaultBand implements Band, BandEntry { |
| 34 | public DefaultBand(Type type, long rate, | 34 | public DefaultBand(Type type, long rate, |
| 35 | Long burstSize, Short prec) { | 35 | Long burstSize, Short prec) { |
| 36 | this.type = type; | 36 | this.type = type; |
| 37 | + if (type == Type.REMARK) { | ||
| 38 | + checkArgument(prec <= MAX_PRECEDENCE && prec >= MIN_PRECEDENCE, ERR_MSG); | ||
| 39 | + } | ||
| 37 | this.rate = rate; | 40 | this.rate = rate; |
| 38 | this.burstSize = burstSize; | 41 | this.burstSize = burstSize; |
| 39 | this.prec = prec; | 42 | this.prec = prec; | ... | ... |
| ... | @@ -35,6 +35,7 @@ public class DefaultMeterTest { | ... | @@ -35,6 +35,7 @@ public class DefaultMeterTest { |
| 35 | private Meter m1; | 35 | private Meter m1; |
| 36 | private Meter sameAsm1; | 36 | private Meter sameAsm1; |
| 37 | private Meter m2; | 37 | private Meter m2; |
| 38 | + private Meter m3; | ||
| 38 | 39 | ||
| 39 | @Before | 40 | @Before |
| 40 | public void setup() { | 41 | public void setup() { |
| ... | @@ -44,6 +45,12 @@ public class DefaultMeterTest { | ... | @@ -44,6 +45,12 @@ public class DefaultMeterTest { |
| 44 | .withRate(500) | 45 | .withRate(500) |
| 45 | .build(); | 46 | .build(); |
| 46 | 47 | ||
| 48 | + Band band1 = DefaultBand.builder() | ||
| 49 | + .ofType(Band.Type.REMARK) | ||
| 50 | + .withRate(500) | ||
| 51 | + .dropPrecedence((short) 1) | ||
| 52 | + .build(); | ||
| 53 | + | ||
| 47 | m1 = DefaultMeter.builder() | 54 | m1 = DefaultMeter.builder() |
| 48 | .forDevice(did("1")) | 55 | .forDevice(did("1")) |
| 49 | .fromApp(APP_ID) | 56 | .fromApp(APP_ID) |
| ... | @@ -68,13 +75,23 @@ public class DefaultMeterTest { | ... | @@ -68,13 +75,23 @@ public class DefaultMeterTest { |
| 68 | .withBands(Collections.singletonList(band)) | 75 | .withBands(Collections.singletonList(band)) |
| 69 | .build(); | 76 | .build(); |
| 70 | 77 | ||
| 78 | + m3 = DefaultMeter.builder() | ||
| 79 | + .forDevice(did("3")) | ||
| 80 | + .fromApp(APP_ID) | ||
| 81 | + .withId(MeterId.meterId(3)) | ||
| 82 | + .withUnit(Meter.Unit.KB_PER_SEC) | ||
| 83 | + .withBands(Collections.singletonList(band1)) | ||
| 84 | + .build(); | ||
| 85 | + | ||
| 86 | + | ||
| 71 | } | 87 | } |
| 72 | 88 | ||
| 73 | @Test | 89 | @Test |
| 74 | public void testEquality() { | 90 | public void testEquality() { |
| 75 | new EqualsTester() | 91 | new EqualsTester() |
| 76 | .addEqualityGroup(m1, sameAsm1) | 92 | .addEqualityGroup(m1, sameAsm1) |
| 77 | - .addEqualityGroup(m2).testEquals(); | 93 | + .addEqualityGroup(m2) |
| 94 | + .addEqualityGroup(m3).testEquals(); | ||
| 78 | } | 95 | } |
| 79 | 96 | ||
| 80 | @Test | 97 | @Test | ... | ... |
| ... | @@ -61,7 +61,7 @@ public final class MeterCodec extends JsonCodec<Meter> { | ... | @@ -61,7 +61,7 @@ public final class MeterCodec extends JsonCodec<Meter> { |
| 61 | .put(DEVICE_ID, meter.deviceId().toString()); | 61 | .put(DEVICE_ID, meter.deviceId().toString()); |
| 62 | 62 | ||
| 63 | if (meter.appId() != null) { | 63 | if (meter.appId() != null) { |
| 64 | - result.put(APP_ID, meter.appId().toString()); | 64 | + result.put(APP_ID, meter.appId().name()); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | if (meter.state() != null) { | 67 | if (meter.state() != null) { | ... | ... |
| ... | @@ -21,7 +21,7 @@ | ... | @@ -21,7 +21,7 @@ |
| 21 | }, | 21 | }, |
| 22 | "appId": { | 22 | "appId": { |
| 23 | "type": "string", | 23 | "type": "string", |
| 24 | - "example": "1" | 24 | + "example": "org.onosproject.rest" |
| 25 | }, | 25 | }, |
| 26 | "deviceId": { | 26 | "deviceId": { |
| 27 | "type": "string", | 27 | "type": "string", |
| ... | @@ -110,4 +110,4 @@ | ... | @@ -110,4 +110,4 @@ |
| 110 | } | 110 | } |
| 111 | } | 111 | } |
| 112 | } | 112 | } |
| 113 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 113 | +} | ... | ... |
| ... | @@ -34,7 +34,7 @@ | ... | @@ -34,7 +34,7 @@ |
| 34 | }, | 34 | }, |
| 35 | "appId": { | 35 | "appId": { |
| 36 | "type": "string", | 36 | "type": "string", |
| 37 | - "example": "1" | 37 | + "example": "org.onosproject.rest" |
| 38 | }, | 38 | }, |
| 39 | "deviceId": { | 39 | "deviceId": { |
| 40 | "type": "string", | 40 | "type": "string", |
| ... | @@ -126,4 +126,4 @@ | ... | @@ -126,4 +126,4 @@ |
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 129 | +} | ... | ... |
| ... | @@ -263,9 +263,9 @@ public class MetersResourceTest extends ResourceTest { | ... | @@ -263,9 +263,9 @@ public class MetersResourceTest extends ResourceTest { |
| 263 | 263 | ||
| 264 | // check application id | 264 | // check application id |
| 265 | final String jsonAppId = jsonMeter.get("appId").asString(); | 265 | final String jsonAppId = jsonMeter.get("appId").asString(); |
| 266 | - final String appId = meter.appId().toString(); | 266 | + final String appId = meter.appId().name(); |
| 267 | if (!jsonAppId.equals(appId)) { | 267 | if (!jsonAppId.equals(appId)) { |
| 268 | - reason = "appId " + meter.appId().toString(); | 268 | + reason = "appId " + meter.appId().name(); |
| 269 | return false; | 269 | return false; |
| 270 | } | 270 | } |
| 271 | 271 | ... | ... |
-
Please register or login to post a comment