Jayasree Ghosh
Committed by Gerrit Code Review

ONOS-5214:Fix-For-Meter-WrongBandType-with-NPE-And-WrongUNITType-Issue


Change-Id: Ia7a56644ad55c458ef17f31b2cf7ec9b9210dd06
(cherry picked from commit 726839c5)
...@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; ...@@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
19 import org.onosproject.codec.CodecContext; 19 import org.onosproject.codec.CodecContext;
20 import org.onosproject.codec.JsonCodec; 20 import org.onosproject.codec.JsonCodec;
21 import org.onosproject.net.meter.Band; 21 import org.onosproject.net.meter.Band;
22 +import org.onosproject.net.meter.Band.Builder;
22 import org.onosproject.net.meter.DefaultBand; 23 import org.onosproject.net.meter.DefaultBand;
23 import org.slf4j.Logger; 24 import org.slf4j.Logger;
24 25
...@@ -65,38 +66,38 @@ public final class MeterBandCodec extends JsonCodec<Band> { ...@@ -65,38 +66,38 @@ public final class MeterBandCodec extends JsonCodec<Band> {
65 return null; 66 return null;
66 } 67 }
67 68
69 + Builder builder = DefaultBand.builder();
70 +
68 // parse rate 71 // parse rate
69 long rate = nullIsIllegal(json.get(RATE), RATE + MISSING_MEMBER_MESSAGE).asLong(); 72 long rate = nullIsIllegal(json.get(RATE), RATE + MISSING_MEMBER_MESSAGE).asLong();
73 + builder.withRate(rate);
70 74
71 // parse burst size 75 // parse burst size
72 long burstSize = nullIsIllegal(json.get(BURST_SIZE), BURST_SIZE + MISSING_MEMBER_MESSAGE).asLong(); 76 long burstSize = nullIsIllegal(json.get(BURST_SIZE), BURST_SIZE + MISSING_MEMBER_MESSAGE).asLong();
77 + builder.burstSize(burstSize);
73 78
74 // parse precedence 79 // parse precedence
75 Short precedence = null; 80 Short precedence = null;
76 81
77 // parse band type 82 // parse band type
78 String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); 83 String typeStr = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText();
79 - Band.Type type; 84 + Band.Type type = null;
80 switch (typeStr) { 85 switch (typeStr) {
81 case "DROP": 86 case "DROP":
82 type = Band.Type.DROP; 87 type = Band.Type.DROP;
88 + builder.ofType(type);
83 break; 89 break;
84 case "REMARK": 90 case "REMARK":
85 type = Band.Type.REMARK; 91 type = Band.Type.REMARK;
86 precedence = (short) nullIsIllegal(json.get(PREC), PREC + MISSING_MEMBER_MESSAGE).asInt(); 92 precedence = (short) nullIsIllegal(json.get(PREC), PREC + MISSING_MEMBER_MESSAGE).asInt();
93 + builder.ofType(type);
94 + builder.dropPrecedence(precedence);
87 break; 95 break;
88 default: 96 default:
89 - log.warn("The requested type {} is not defined for band.", typeStr); 97 + nullIsIllegal(type, "The requested type " + typeStr + " is not defined for band.");
90 - return null;
91 } 98 }
92 99
93 - Band band = DefaultBand.builder() 100 + Band band = builder.build();
94 - .ofType(type)
95 - .burstSize(burstSize)
96 - .withRate(rate)
97 - .dropPrecedence(precedence)
98 - .build();
99 -
100 return band; 101 return band;
101 } 102 }
102 } 103 }
......
...@@ -74,7 +74,7 @@ public final class MeterRequestCodec extends JsonCodec<MeterRequest> { ...@@ -74,7 +74,7 @@ public final class MeterRequestCodec extends JsonCodec<MeterRequest> {
74 74
75 // parse unit type 75 // parse unit type
76 String unit = nullIsIllegal(json.get(UNIT), UNIT + MISSING_MEMBER_MESSAGE).asText(); 76 String unit = nullIsIllegal(json.get(UNIT), UNIT + MISSING_MEMBER_MESSAGE).asText();
77 - Meter.Unit meterUnit; 77 + Meter.Unit meterUnit = null;
78 78
79 switch (unit) { 79 switch (unit) {
80 case "KB_PER_SEC": 80 case "KB_PER_SEC":
...@@ -84,8 +84,7 @@ public final class MeterRequestCodec extends JsonCodec<MeterRequest> { ...@@ -84,8 +84,7 @@ public final class MeterRequestCodec extends JsonCodec<MeterRequest> {
84 meterUnit = Meter.Unit.PKTS_PER_SEC; 84 meterUnit = Meter.Unit.PKTS_PER_SEC;
85 break; 85 break;
86 default: 86 default:
87 - log.warn("The requested unit {} is not defined for meter.", unit); 87 + nullIsIllegal(meterUnit, "The requested unit " + unit + " is not defined for meter.");
88 - return null;
89 } 88 }
90 89
91 // parse meter bands 90 // parse meter bands
......