[ONOS-7051] Support for P4Runtime meters
Change-Id: Id71374af65aeb84b71636b4ec230dc6001a77a8b
diff --git a/core/api/src/main/java/org/onosproject/net/meter/DefaultMeter.java b/core/api/src/main/java/org/onosproject/net/meter/DefaultMeter.java
index 7be5e90..ad0256e 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/DefaultMeter.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/DefaultMeter.java
@@ -25,6 +25,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;
+import static org.onosproject.net.meter.MeterCellId.MeterCellType.INDEX;
/**
* A default implementation of a meter.
@@ -32,7 +33,7 @@
public final class DefaultMeter implements Meter, MeterEntry {
- private final MeterId id;
+ private final MeterCellId cellId;
private final ApplicationId appId;
private final Unit unit;
private final boolean burst;
@@ -45,11 +46,10 @@
private long packets;
private long bytes;
- private DefaultMeter(DeviceId deviceId, MeterId id, ApplicationId appId,
- Unit unit, boolean burst,
- Collection<Band> bands) {
+ private DefaultMeter(DeviceId deviceId, MeterCellId cellId, ApplicationId appId,
+ Unit unit, boolean burst, Collection<Band> bands) {
this.deviceId = deviceId;
- this.id = id;
+ this.cellId = cellId;
this.appId = appId;
this.unit = unit;
this.burst = burst;
@@ -63,7 +63,16 @@
@Override
public MeterId id() {
- return id;
+ // Workaround until we remove this method. Deprecated in 1.13.
+ // Should use meterCellId() instead.
+ return cellId.type() == INDEX
+ ? (MeterId) cellId
+ : MeterId.meterId((cellId.hashCode()));
+ }
+
+ @Override
+ public MeterCellId meterCellId() {
+ return cellId;
}
@Override
@@ -144,7 +153,7 @@
public String toString() {
return toStringHelper(this)
.add("device", deviceId)
- .add("id", id)
+ .add("cellId", cellId)
.add("appId", appId.name())
.add("unit", unit)
.add("isBurst", burst)
@@ -161,7 +170,7 @@
return false;
}
DefaultMeter that = (DefaultMeter) o;
- return Objects.equal(id, that.id) &&
+ return Objects.equal(cellId, that.cellId) &&
Objects.equal(appId, that.appId) &&
Objects.equal(unit, that.unit) &&
Objects.equal(deviceId, that.deviceId);
@@ -169,19 +178,18 @@
@Override
public int hashCode() {
- return Objects.hashCode(id, appId, unit, deviceId);
+ return Objects.hashCode(cellId, appId, unit, deviceId);
}
public static final class Builder implements Meter.Builder {
- private MeterId id;
+ private MeterCellId cellId;
private ApplicationId appId;
private Unit unit = Unit.KB_PER_SEC;
private boolean burst = false;
private Collection<Band> bands;
private DeviceId deviceId;
-
@Override
public Meter.Builder forDevice(DeviceId deviceId) {
this.deviceId = deviceId;
@@ -190,7 +198,13 @@
@Override
public Meter.Builder withId(MeterId id) {
- this.id = id;
+ this.withCellId(id);
+ return this;
+ }
+
+ @Override
+ public Meter.Builder withCellId(MeterCellId cellId) {
+ this.cellId = cellId;
return this;
}
@@ -224,8 +238,8 @@
checkNotNull(bands, "Must have bands.");
checkArgument(!bands.isEmpty(), "Must have at least one band.");
checkNotNull(appId, "Must have an application id");
- checkNotNull(id, "Must specify a meter id");
- return new DefaultMeter(deviceId, id, appId, unit, burst, bands);
+ checkArgument(cellId != null, "Must specify a cell id.");
+ return new DefaultMeter(deviceId, cellId, appId, unit, burst, bands);
}