FIX: Set band.type in MeterStats to avoid nullpointer in meter related operations (e.g, removal).
Change-Id: I0ff8ee537f0e4f8068f494799ef72d282b33f471
diff --git a/core/api/src/main/java/org/onosproject/net/meter/DefaultBand.java b/core/api/src/main/java/org/onosproject/net/meter/DefaultBand.java
index b0ce738..9441897 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/DefaultBand.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/DefaultBand.java
@@ -17,6 +17,7 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
/**
* A default implementation for a Band.
@@ -128,9 +129,9 @@
@Override
public DefaultBand build() {
+ checkNotNull(type, "Band type can not be null");
checkArgument(type == Type.REMARK ^ prec == null,
"Only REMARK bands can have a precedence.");
-
return new DefaultBand(type, rate, burstSize, prec);
}
}
diff --git a/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java b/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
index 147e124..9c4ccab 100644
--- a/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
+++ b/providers/openflow/meter/src/main/java/org/onosproject/provider/of/meter/impl/OpenFlowMeterProvider.java
@@ -324,11 +324,11 @@
private Collection<Band> buildBands(List<OFMeterBandStats> bandStats) {
return bandStats.stream().map(stat -> {
- DefaultBand band = DefaultBand.builder().build();
+ DefaultBand band = ((DefaultBand.Builder) DefaultBand.builder().ofType(DefaultBand.Type.DROP)).build();
band.setBytes(stat.getByteBandCount().getValue());
band.setPackets(stat.getPacketBandCount().getValue());
return band;
- }).collect(Collectors.toSet());
+ }).collect(Collectors.toList());
}
private void signalMeterError(OFMeterModFailedErrorMsg meterError,