ONOS-5214:Fix-For-Meter-WrongBandType-with-NPE-And-WrongUNITType-Issue
Change-Id: Ia7a56644ad55c458ef17f31b2cf7ec9b9210dd06
(cherry picked from commit 726839c57f8a5df62c5d28ec205f128f417ffef7)
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/MeterBandCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/MeterBandCodec.java
index 586fb9c..a26063c 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/MeterBandCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/MeterBandCodec.java
@@ -19,6 +19,7 @@
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.meter.Band;
+import org.onosproject.net.meter.Band.Builder;
import org.onosproject.net.meter.DefaultBand;
import org.slf4j.Logger;
@@ -65,38 +66,38 @@
return null;
}
+ Builder builder = DefaultBand.builder();
+
// parse rate
long rate = nullIsIllegal(json.get(RATE), RATE + MISSING_MEMBER_MESSAGE).asLong();
+ builder.withRate(rate);
// parse burst size
long burstSize = nullIsIllegal(json.get(BURST_SIZE), BURST_SIZE + MISSING_MEMBER_MESSAGE).asLong();
+ builder.burstSize(burstSize);
// parse precedence
Short precedence = null;
// parse band type
String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
- Band.Type type;
+ Band.Type type = null;
switch (typeStr) {
case "DROP":
type = Band.Type.DROP;
+ builder.ofType(type);
break;
case "REMARK":
type = Band.Type.REMARK;
precedence = (short) nullIsIllegal(json.get(PREC), PREC + MISSING_MEMBER_MESSAGE).asInt();
+ builder.ofType(type);
+ builder.dropPrecedence(precedence);
break;
default:
- log.warn("The requested type {} is not defined for band.", typeStr);
- return null;
+ nullIsIllegal(type, "The requested type " + typeStr + " is not defined for band.");
}
- Band band = DefaultBand.builder()
- .ofType(type)
- .burstSize(burstSize)
- .withRate(rate)
- .dropPrecedence(precedence)
- .build();
-
+ Band band = builder.build();
return band;
}
}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/MeterRequestCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/MeterRequestCodec.java
index a92e96e..b64fd23 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/MeterRequestCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/MeterRequestCodec.java
@@ -74,7 +74,7 @@
// parse unit type
String unit = nullIsIllegal(json.get(UNIT), UNIT + MISSING_MEMBER_MESSAGE).asText();
- Meter.Unit meterUnit;
+ Meter.Unit meterUnit = null;
switch (unit) {
case "KB_PER_SEC":
@@ -84,8 +84,7 @@
meterUnit = Meter.Unit.PKTS_PER_SEC;
break;
default:
- log.warn("The requested unit {} is not defined for meter.", unit);
- return null;
+ nullIsIllegal(meterUnit, "The requested unit " + unit + " is not defined for meter.");
}
// parse meter bands