added treatment support and conversion to an instruction
moved to meter api to onos-api
Change-Id: I0504f06fdc503953fa7696224d97edda43596d6e
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
index 06c49ba..2dad08b 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
@@ -28,6 +28,7 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
+import org.onosproject.net.meter.MeterId;
import java.util.Collections;
import java.util.List;
@@ -50,6 +51,7 @@
private static final DefaultTrafficTreatment EMPTY
= new DefaultTrafficTreatment(Collections.emptyList());
+ private final Instructions.MeterInstruction meter;
/**
* Creates a new traffic treatment from the specified list of instructions.
@@ -63,6 +65,7 @@
this.hasClear = false;
this.table = null;
this.meta = null;
+ this.meter = null;
}
/**
@@ -77,7 +80,8 @@
List<Instruction> immediate,
Instructions.TableTypeTransition table,
boolean clear,
- Instructions.MetadataInstruction meta) {
+ Instructions.MetadataInstruction meta,
+ Instructions.MeterInstruction meter) {
this.immediate = ImmutableList.copyOf(checkNotNull(immediate));
this.deferred = ImmutableList.copyOf(checkNotNull(deferred));
this.all = new ImmutableList.Builder<Instruction>()
@@ -87,6 +91,7 @@
this.table = table;
this.meta = meta;
this.hasClear = clear;
+ this.meter = meter;
}
@Override
@@ -119,6 +124,11 @@
return meta;
}
+ @Override
+ public Instructions.MeterInstruction metered() {
+ return meter;
+ }
+
/**
* Returns a new traffic treatment builder.
*
@@ -193,12 +203,16 @@
Instructions.MetadataInstruction meta;
+ Instructions.MeterInstruction meter;
+
List<Instruction> deferred = Lists.newLinkedList();
List<Instruction> immediate = Lists.newLinkedList();
List<Instruction> current = immediate;
+
+
// Creates a new builder
private Builder() {
}
@@ -233,6 +247,8 @@
case METADATA:
meta = (Instructions.MetadataInstruction) instruction;
break;
+ case METER:
+ meter = (Instructions.MeterInstruction) instruction;
default:
throw new IllegalArgumentException("Unknown instruction type: " +
instruction.type());
@@ -343,6 +359,11 @@
}
@Override
+ public TrafficTreatment.Builder meter(MeterId meterId) {
+ return add(Instructions.meterTraffic(meterId));
+ }
+
+ @Override
public Builder popVlan() {
return add(Instructions.popVlan());
}
@@ -420,7 +441,7 @@
// && table == null && !clear) {
// drop();
//}
- return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta);
+ return new DefaultTrafficTreatment(deferred, immediate, table, clear, meta, meter);
}
}
diff --git a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
index d125a9f..042aeaf 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
@@ -24,6 +24,7 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
+import org.onosproject.net.meter.MeterId;
import java.util.List;
@@ -75,6 +76,13 @@
Instructions.MetadataInstruction writeMetadata();
/**
+ * Returns the meter instruction if there is one.
+ *
+ * @return a meter instruction that may be null
+ */
+ Instructions.MeterInstruction metered();
+
+ /**
* Builder of traffic treatment entities.
*/
interface Builder {
@@ -243,6 +251,13 @@
*/
Builder group(GroupId groupId);
+ /**
+ * Sets a meter to be used by this flow.
+ *
+ * @param meterId a meter id
+ * @return a treatment builder
+ */
+ Builder meter(MeterId meterId);
/**
* Sets the next table type to transition to.
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
index 7496e97..6f2cac6 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instruction.java
@@ -40,6 +40,11 @@
GROUP,
/**
+ * Signifies that traffic should be metered according to a meter.
+ */
+ METER,
+
+ /**
* Signifies that the traffic should be modified in L0 way.
*/
L0MODIFICATION,
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index 3cacfa5..cd9ec96 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -34,6 +34,7 @@
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModTtlInstruction;
import org.onosproject.net.flow.instructions.L4ModificationInstruction.L4SubType;
import org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction;
+import org.onosproject.net.meter.MeterId;
import java.util.Objects;
@@ -81,6 +82,11 @@
return new GroupInstruction(groupId);
}
+ public static MeterInstruction meterTraffic(final MeterId meterId) {
+ checkNotNull(meterId, "meter id cannot be null");
+ return new MeterInstruction(meterId);
+ }
+
/**
* Creates a l0 modification.
*
@@ -528,6 +534,50 @@
}
/**
+ * A meter instruction.
+ */
+ public static final class MeterInstruction implements Instruction {
+ private final MeterId meterId;
+
+ private MeterInstruction(MeterId meterId) {
+ this.meterId = meterId;
+ }
+
+ public MeterId meterId() {
+ return meterId;
+ }
+
+ @Override
+ public Type type() {
+ return Type.METER;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(type().toString())
+ .add("meter ID", meterId.id()).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type().ordinal(), meterId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof MeterInstruction) {
+ MeterInstruction that = (MeterInstruction) obj;
+ return Objects.equals(meterId, that.meterId);
+
+ }
+ return false;
+ }
+ }
+
+ /**
* Transition instruction.
*/
public static class TableTypeTransition implements Instruction {
diff --git a/core/api/src/main/java/org/onosproject/net/meter/Band.java b/core/api/src/main/java/org/onosproject/net/meter/Band.java
new file mode 100644
index 0000000..2bfafad
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/Band.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+/**
+ * Represents a band used within a meter.
+ */
+public interface Band {
+
+ /**
+ * Specifies the type of band.
+ */
+ enum Type {
+ /**
+ * Simple rate limiter which drops packets
+ * when the rate is exceeded.
+ */
+ DROP,
+
+ /**
+ * defines a simple DiffServ policer that remark
+ * the drop precedence of the DSCP field in the
+ * IP header of the packets that exceed the band
+ * rate value.
+ */
+ REMARK
+ }
+
+ /**
+ * The rate at which this meter applies.
+ *
+ * @return the long value of the rate
+ */
+ long rate();
+
+ /**
+ * The burst size at which the meter applies.
+ *
+ * @return the long value of the size
+ */
+ long burst();
+
+ /**
+ * Only meaningful in the case of a REMARK band type.
+ * indicates by which amount the drop precedence of
+ * the packet should be increase if the band is exceeded.
+ *
+ * @return a short value
+ */
+ short dropPrecedence();
+
+ /**
+ * Signals the type of band to create.
+ *
+ * @return a band type
+ */
+ Type type();
+
+ /**
+ * Returns the packets seen by this band.
+ *
+ * @return a long value
+ */
+ long packets();
+
+ /**
+ * Return the bytes seen by this band.
+ *
+ * @return a byte counter
+ */
+ long bytes();
+
+ interface Builder {
+
+ /**
+ * Assigns a rate to this band. The units for this rate
+ * are defined in the encapsulating meter.
+ *
+ * @param rate a long value
+ * @return this
+ */
+ Builder withRate(long rate);
+
+ /**
+ * Assigns a burst size to this band. Only meaningful if
+ * the encapsulating meter is of burst type.
+ *
+ * @param burstSize a long value.
+ * @return this
+ */
+ Builder burstSize(long burstSize);
+
+ /**
+ * Assigns the drop precedence for this band. Only meaningful if
+ * the band is of REMARK type.
+ *
+ * @param prec a short value
+ * @return this
+ */
+ Builder dropPrecedence(short prec);
+
+ /**
+ * Assigns the @See Type of this band.
+ *
+ * @param type a band type
+ * @return this
+ */
+ Builder ofType(Type type);
+
+ /**
+ * Builds the band.
+ *
+ * @return a band
+ */
+ Band build();
+
+ }
+
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/BandEntry.java b/core/api/src/main/java/org/onosproject/net/meter/BandEntry.java
new file mode 100644
index 0000000..03145e9
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/BandEntry.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+/**
+ * Represents a stored band.
+ */
+public interface BandEntry extends Band {
+
+ /**
+ * Sets the number of packets seen by this band.
+ *
+ * @param packets a packet count
+ */
+ void setPackets(long packets);
+
+ /**
+ * Sets the number of bytes seen by this band.
+ *
+ * @param bytes a byte counter
+ */
+ void setBytes(long bytes);
+
+}
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
new file mode 100644
index 0000000..a3a4fc2
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/DefaultBand.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * A default implementation for a Band.
+ */
+public final class DefaultBand implements Band, BandEntry {
+
+ private final Type type;
+ private final long rate;
+ private final long burstSize;
+ private final short prec;
+ private long packets;
+ private long bytes;
+
+ public DefaultBand(Type type, long rate,
+ long burstSize, short prec) {
+ this.type = type;
+ this.rate = rate;
+ this.burstSize = burstSize;
+ this.prec = prec;
+ }
+
+ @Override
+ public long rate() {
+ return rate;
+ }
+
+ @Override
+ public long burst() {
+ return burstSize;
+ }
+
+ @Override
+ public short dropPrecedence() {
+ return prec;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public long packets() {
+ return packets;
+ }
+
+ @Override
+ public long bytes() {
+ return bytes;
+ }
+
+ @Override
+ public void setPackets(long packets) {
+ this.packets = packets;
+ }
+
+ @Override
+ public void setBytes(long bytes) {
+ this.bytes = bytes;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder implements Band.Builder {
+
+ private long rate;
+ private long burstSize;
+ private Short prec;
+ private Type type;
+
+ @Override
+ public Band.Builder withRate(long rate) {
+ this.rate = rate;
+ return this;
+ }
+
+ @Override
+ public Band.Builder burstSize(long burstSize) {
+ this.burstSize = burstSize;
+ return this;
+ }
+
+ @Override
+ public Band.Builder dropPrecedence(short prec) {
+ this.prec = prec;
+ return this;
+ }
+
+ @Override
+ public Band.Builder ofType(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public DefaultBand build() {
+ checkArgument(prec != null && type == Type.REMARK,
+ "Only REMARK bands can have a precendence.");
+
+ return new DefaultBand(type, rate, burstSize, prec);
+ }
+
+
+ }
+}
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
new file mode 100644
index 0000000..611a23e
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/DefaultMeter.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.DeviceId;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * A default implementation of a meter.
+ */
+public final class DefaultMeter implements Meter, MeterEntry {
+
+
+ private final MeterId id;
+ private final ApplicationId appId;
+ private final Unit unit;
+ private final boolean burst;
+ private final Collection<Band> bands;
+ private final DeviceId deviceId;
+
+ private MeterState state;
+ private long life;
+ private long refCount;
+ private long packets;
+ private long bytes;
+
+ private DefaultMeter(DeviceId deviceId, MeterId id, ApplicationId appId,
+ Unit unit, boolean burst,
+ Collection<Band> bands) {
+ this.deviceId = deviceId;
+ this.id = id;
+ this.appId = appId;
+ this.unit = unit;
+ this.burst = burst;
+ this.bands = bands;
+ }
+
+ @Override
+ public DeviceId deviceId() {
+ return deviceId;
+ }
+
+ @Override
+ public MeterId id() {
+ return id;
+ }
+
+ @Override
+ public ApplicationId appId() {
+ return appId;
+ }
+
+ @Override
+ public Unit unit() {
+ return unit;
+ }
+
+ @Override
+ public boolean isBurst() {
+ return burst;
+ }
+
+ @Override
+ public Collection<Band> bands() {
+ return bands;
+ }
+
+ @Override
+ public MeterState state() {
+ return state;
+ }
+
+ @Override
+ public long life() {
+ return life;
+ }
+
+ @Override
+ public long referenceCount() {
+ return refCount;
+ }
+
+ @Override
+ public long packetsSeen() {
+ return packets;
+ }
+
+ @Override
+ public long bytesSeen() {
+ return bytes;
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ @Override
+ public void setState(MeterState state) {
+ this.state = state;
+ }
+
+ @Override
+ public void setLife(long life) {
+ this.life = life;
+ }
+
+ @Override
+ public void setReferenceCount(long count) {
+ this.refCount = count;
+ }
+
+ @Override
+ public void setProcessedPackets(long packets) {
+ this.packets = packets;
+ }
+
+ @Override
+ public void setProcessedBytes(long bytes) {
+ this.bytes = bytes;
+ }
+
+ public static final class Builder implements Meter.Builder {
+
+ private MeterId id;
+ 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;
+ return this;
+ }
+
+ @Override
+ public Meter.Builder withId(long id) {
+ this.id = MeterId.meterId(id);
+ return this;
+ }
+
+ @Override
+ public Meter.Builder fromApp(ApplicationId appId) {
+ this.appId = appId;
+ return this;
+ }
+
+ @Override
+ public Meter.Builder withUnit(Unit unit) {
+ this.unit = unit;
+ return this;
+ }
+
+ @Override
+ public Meter.Builder burst() {
+ this.burst = true;
+ return this;
+ }
+
+ @Override
+ public Meter.Builder withBands(Collection<Band> bands) {
+ this.bands = Collections.unmodifiableCollection(bands);
+ return this;
+ }
+
+ @Override
+ public DefaultMeter build() {
+ checkNotNull(deviceId, "Must specify a device");
+ checkNotNull(bands, "Must have bands.");
+ checkArgument(bands.size() > 0, "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);
+ }
+
+
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/Meter.java b/core/api/src/main/java/org/onosproject/net/meter/Meter.java
new file mode 100644
index 0000000..5181c92
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/Meter.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.DeviceId;
+
+import java.util.Collection;
+
+/**
+ * Represents a generalized meter to be deployed on a device.
+ */
+public interface Meter {
+
+ enum Unit {
+ /**
+ * Packets per second.
+ */
+ PKTS_PER_SEC,
+
+ /**
+ * Kilo bits per second.
+ */
+ KB_PER_SEC
+ }
+
+ /**
+ * The target device for this meter.
+ *
+ * @return a device id
+ */
+ DeviceId deviceId();
+
+ /**
+ * This meters id.
+ *
+ * @return a meter id
+ */
+ MeterId id();
+
+ /**
+ * The id of the application which created this meter.
+ *
+ * @return an application id
+ */
+ ApplicationId appId();
+
+ /**
+ * The unit used within this meter.
+ *
+ * @return the unit
+ */
+ Unit unit();
+
+ /**
+ * Signals whether this meter applies to bursts only.
+ *
+ * @return a boolean
+ */
+ boolean isBurst();
+
+ /**
+ * The collection of bands to apply on the dataplane.
+ *
+ * @return a collection of bands.
+ */
+ Collection<Band> bands();
+
+ /**
+ * Fetches the state of this meter.
+ *
+ * @return a meter state
+ */
+ MeterState state();
+
+ /**
+ * The lifetime in seconds of this meter.
+ *
+ * @return number of seconds
+ */
+ long life();
+
+ /**
+ * The number of flows pointing to this meter.
+ *
+ * @return a reference count
+ */
+ long referenceCount();
+
+ /**
+ * Number of packets processed by this meter.
+ *
+ * @return a packet count
+ */
+ long packetsSeen();
+
+ /**
+ * Number of bytes processed by this meter.
+ *
+ * @return a byte count
+ */
+ long bytesSeen();
+
+ /**
+ * A meter builder.
+ */
+ interface Builder {
+
+ /**
+ * Assigns the target device for this meter.
+ *
+ * @param deviceId a device id
+ * @return this
+ */
+ Builder forDevice(DeviceId deviceId);
+
+ /**
+ * Assigns the id to this meter.
+ *
+ * @param id a long
+ * @return this
+ */
+ Builder withId(long id);
+
+ /**
+ * Assigns the application that built this meter.
+ *
+ * @param appId an application id
+ * @return this
+ */
+ Builder fromApp(ApplicationId appId);
+
+ /**
+ * Assigns the @See Unit to use for this meter.
+ * Defaults to kb/s
+ *
+ * @param unit a unit
+ * @return this
+ */
+ Builder withUnit(Unit unit);
+
+ /**
+ * Sets this meter as applicable to burst traffic only.
+ * Defaults to false.
+ *
+ * @return this
+ */
+ Builder burst();
+
+ /**
+ * Assigns bands to this meter. There must be at least one band.
+ *
+ * @param bands a collection of bands
+ * @return this
+ */
+ Builder withBands(Collection<Band> bands);
+
+ /**
+ * Builds the meter based on the specified parameters.
+ *
+ * @return a meter
+ */
+ Meter build();
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterContext.java b/core/api/src/main/java/org/onosproject/net/meter/MeterContext.java
new file mode 100644
index 0000000..005c41c
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterContext.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+/**
+ * A context permitting the application to be notified when the
+ * meter installation has been successful.
+ */
+public interface MeterContext {
+
+ /**
+ * Invoked on successful installation of the meter.
+ *
+ * @param op a meter
+ */
+ default void onSuccess(Meter op) {}
+
+ /**
+ * Invoked when error is encountered while installing a meter.
+ *
+ * @param op a meter
+ * @param reason the reason why it failed
+ */
+ default void onError(Meter op, MeterFailReason reason) {}
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterEntry.java b/core/api/src/main/java/org/onosproject/net/meter/MeterEntry.java
new file mode 100644
index 0000000..178a564
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterEntry.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+/**
+ * Represents a stored meter.
+ */
+public interface MeterEntry extends Meter {
+
+ /**
+ * Updates the state of this meter.
+ *
+ * @param state a meter state
+ */
+ void setState(MeterState state);
+
+ /**
+ * Set the amount of time the meter has existed in seconds.
+ *
+ * @param life number of seconds
+ */
+ void setLife(long life);
+
+ /**
+ * Sets the number of flows which are using this meter.
+ *
+ * @param count a reference count.
+ */
+ void setReferenceCount(long count);
+
+ /**
+ * Updates the number of packets seen by this meter.
+ *
+ * @param packets a packet count.
+ */
+ void setProcessedPackets(long packets);
+
+ /**
+ * Updates the number of bytes seen by the meter.
+ *
+ * @param bytes a byte counter.
+ */
+ void setProcessedBytes(long bytes);
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterEvent.java b/core/api/src/main/java/org/onosproject/net/meter/MeterEvent.java
new file mode 100644
index 0000000..72f0a53
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterEvent.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Entity that represents Meter events.
+ */
+public class MeterEvent extends AbstractEvent<MeterEvent.Type, Meter> {
+
+
+ public enum Type {
+ /**
+ * A meter addition was requested.
+ */
+ METER_ADD_REQ,
+
+ /**
+ * A meter removal was requested.
+ */
+ METER_REM_REQ
+ }
+
+
+ /**
+ * Creates an event of a given type and for the specified meter and the
+ * current time.
+ *
+ * @param type meter event type
+ * @param meter event subject
+ */
+ public MeterEvent(Type type, Meter meter) {
+ super(type, meter);
+ }
+
+ /**
+ * Creates an event of a given type and for the specified meter and time.
+ *
+ * @param type meter event type
+ * @param meter event subject
+ * @param time occurrence time
+ */
+ public MeterEvent(Type type, Meter meter, long time) {
+ super(type, meter, time);
+ }
+
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterFailReason.java b/core/api/src/main/java/org/onosproject/net/meter/MeterFailReason.java
new file mode 100644
index 0000000..8683e2a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterFailReason.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+/**
+ * Enum used to represent a meter failure condition.
+ */
+public enum MeterFailReason {
+ /**
+ * A meter with the same identifier already exists.
+ * Essentially a duplicate meter exists.
+ */
+ EXISTING_METER,
+
+ /**
+ * The device does not support any more meters.
+ */
+ OUT_OF_METERS,
+
+ /**
+ * The device does not support any more bands for this meter.
+ */
+ OUT_OF_BANDS,
+
+ /**
+ * The meter that was attempted to be modified is unknown.
+ */
+ UNKNOWN,
+
+ /**
+ * The operation for this meter installation timed out.
+ */
+ TIMEOUT,
+
+ /**
+ * Invalid meter definition.
+ */
+ INVALID_METER,
+
+ /**
+ * The target device is unknown.
+ */
+ UNKNOWN_DEVICE,
+
+ /**
+ * Unknown command.
+ */
+ UNKNOWN_COMMAND,
+
+ /**
+ * Unknown flags.
+ */
+ UNKNOWN_FLAGS,
+
+ /**
+ * Bad rate value.
+ */
+ BAD_RATE,
+
+ /**
+ * Bad burst size value.
+ */
+ BAD_BURST,
+
+ /**
+ * Bad band.
+ */
+ BAD_BAND,
+
+ /**
+ * Bad value value.
+ */
+ BAD_BAND_VALUE
+
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterId.java b/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
new file mode 100644
index 0000000..f479ac5
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterId.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+/**
+ * A representation of a meter id.
+ * Uniquely identifies a meter system wide.
+ */
+public final class MeterId {
+
+ static final long MAX = 0xFFFF0000;
+
+ private final long id;
+
+ public static final MeterId SLOWPATH = new MeterId(0xFFFFFFFD);
+ public static final MeterId CONTROLLER = new MeterId(0xFFFFFFFE);
+ public static final MeterId ALL = new MeterId(0xFFFFFFFF);
+
+ private MeterId(long id) {
+ checkArgument(id <= MAX, "id cannot be larger than 0xFFFF0000");
+ this.id = id;
+ }
+
+ /**
+ * The integer representation of the meter id.
+ *
+ * @return a long
+ */
+ public long id() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ MeterId meterId = (MeterId) o;
+
+ return id == meterId.id;
+
+ }
+
+ @Override
+ public int hashCode() {
+ return Long.hashCode(id);
+ }
+
+ public static MeterId meterId(long id) {
+ return new MeterId(id);
+
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterListener.java b/core/api/src/main/java/org/onosproject/net/meter/MeterListener.java
new file mode 100644
index 0000000..0a5e203
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Entity capable of receiving Meter related events.
+ */
+public interface MeterListener extends EventListener<MeterEvent> {
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterOperation.java b/core/api/src/main/java/org/onosproject/net/meter/MeterOperation.java
new file mode 100644
index 0000000..50e6fe9
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterOperation.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import com.google.common.base.MoreObjects;
+
+import java.util.Optional;
+
+/**
+ * Representation of an operation on the meter table.
+ */
+public class MeterOperation {
+
+ private final Optional<MeterContext> context;
+
+ /**
+ * Tyoe of meter operation.
+ */
+ public enum Type {
+ ADD,
+ REMOVE,
+ MODIFY
+ }
+
+ private final Meter meter;
+ private final Type type;
+
+
+ public MeterOperation(Meter meter, Type type, MeterContext context) {
+ this.meter = meter;
+ this.type = type;
+ this.context = Optional.ofNullable(context);
+ }
+
+ /**
+ * Returns the type of operation.
+ *
+ * @return type
+ */
+ public Type type() {
+ return type;
+ }
+
+ /**
+ * Returns the meter.
+ *
+ * @return a meter
+ */
+ public Meter meter() {
+ return meter;
+ }
+
+ /**
+ * Returns a context which allows application to
+ * be notified on the success value of this operation.
+ *
+ * @return a meter context
+ */
+ public Optional<MeterContext> context() {
+ return this.context;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("meter", meter)
+ .add("type", type)
+ .toString();
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterOperations.java b/core/api/src/main/java/org/onosproject/net/meter/MeterOperations.java
new file mode 100644
index 0000000..92b0c3a
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterOperations.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Immutable collection of meter operation to be used between
+ * core and provider layers of group subsystem.
+ *
+ */
+public final class MeterOperations {
+ private final List<MeterOperation> operations;
+
+ /**
+ * Creates a immutable list of meter operation.
+ *
+ * @param operations list of meter operation
+ */
+ public MeterOperations(List<MeterOperation> operations) {
+ this.operations = ImmutableList.copyOf(checkNotNull(operations));
+ }
+
+ /**
+ * Returns immutable list of Meter operation.
+ *
+ * @return list of Meter operation
+ */
+ public List<MeterOperation> operations() {
+ return operations;
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java b/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
new file mode 100644
index 0000000..4655e23
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.Provider;
+
+/**
+ * Abstraction of a Meter provider.
+ */
+public interface MeterProvider extends Provider {
+
+ /**
+ * Performs a batch of meter operation on the specified device with the
+ * specified parameters.
+ *
+ * @param deviceId device identifier on which the batch of group
+ * operations to be executed
+ * @param meterOps immutable list of meter operation
+ */
+ void performMeterOperation(DeviceId deviceId,
+ MeterOperations meterOps);
+
+
+ /**
+ * Performs a meter operation on the specified device with the
+ * specified parameters.
+ *
+ * @param deviceId device identifier on which the batch of group
+ * operations to be executed
+ * @param meterOp a meter operation
+ */
+ void performMeterOperation(DeviceId deviceId,
+ MeterOperation meterOp);
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterProviderRegistry.java b/core/api/src/main/java/org/onosproject/net/meter/MeterProviderRegistry.java
new file mode 100644
index 0000000..019ca19
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterProviderRegistry.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+
+import org.onosproject.net.provider.ProviderRegistry;
+
+/**
+ * Abstraction for a meter provider registry.
+ */
+public interface MeterProviderRegistry
+ extends ProviderRegistry<MeterProvider, MeterProviderService> {
+}
+
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterProviderService.java b/core/api/src/main/java/org/onosproject/net/meter/MeterProviderService.java
new file mode 100644
index 0000000..85c0c43
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterProviderService.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.provider.ProviderService;
+
+import java.util.Collection;
+
+/**
+ * Service through which meter providers can inject information
+ * into the core.
+ */
+public interface MeterProviderService extends ProviderService<MeterProvider> {
+
+ /**
+ * Notifies the core that a meter operaton failed for a
+ * specific reason.
+ * @param operation the failed operation
+ * @param reason the failure reason
+ */
+ void meterOperationFailed(MeterOperation operation,
+ MeterFailReason reason);
+
+ /**
+ * Pushes the collection of meters observed on the data plane as
+ * well as their associated statistics.
+ *
+ * @param deviceId a device id
+ * @param meterEntries a collection of meter entries
+ */
+ void pushMeterMetrics(DeviceId deviceId,
+ Collection<Meter> meterEntries);
+
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterService.java b/core/api/src/main/java/org/onosproject/net/meter/MeterService.java
new file mode 100644
index 0000000..eaa2a50
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterService.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.event.ListenerService;
+
+/**
+ * Service for add/updating and removing meters. Meters are
+ * are assigned to flow to rate limit them and provide a certain
+ * quality of service.
+ */
+public interface MeterService
+ extends ListenerService<MeterEvent, MeterListener> {
+
+ /**
+ * Adds a meter to the system and performs it installation.
+ *
+ * @param meter a meter.
+ */
+ void addMeter(MeterOperation meter);
+
+ /**
+ * Updates a meter by adding statistic information to the meter.
+ *
+ * @param meter an updated meter
+ */
+ void updateMeter(MeterOperation meter);
+
+ /**
+ * Remove a meter from the system and the dataplane.
+ *
+ * @param meter a meter to remove
+ */
+ void removeMeter(MeterOperation meter);
+
+ /**
+ * Fetch the meter by the meter id.
+ *
+ * @param id a meter id
+ * @return a meter
+ */
+ Meter getMeter(MeterId id);
+
+ /**
+ * Allocate a meter id which must be used to create the meter.
+ *
+ * @return a meter id
+ */
+ MeterId allocateMeterId();
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterState.java b/core/api/src/main/java/org/onosproject/net/meter/MeterState.java
new file mode 100644
index 0000000..3b93609
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterState.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+/**
+ * Represents the state of the meter as seen by the store.
+ */
+public enum MeterState {
+
+ /**
+ * The meter is in the process of being added.
+ */
+ PENDING_ADD,
+
+ /**
+ * THe meter has been added.
+ */
+ ADDED,
+
+ /**
+ * The meter is in the process of being removed.
+ */
+ PENDING_REMOVE,
+
+ /**
+ * The meter has been removed.
+ */
+ REMOVED,
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterStore.java b/core/api/src/main/java/org/onosproject/net/meter/MeterStore.java
new file mode 100644
index 0000000..c5d57d5
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterStore.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.store.Store;
+
+import java.util.Collection;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Entity that stores and distributed meter objects.
+ */
+public interface MeterStore extends Store<MeterEvent, MeterStoreDelegate> {
+
+ /**
+ * Adds a meter to the store.
+ *
+ * @param meter a meter
+ * @return a future indicating the result of the store operation
+ */
+ CompletableFuture<MeterStoreResult> storeMeter(Meter meter);
+
+ /**
+ * Deletes a meter from the store.
+ *
+ * @param meter a meter
+ * @return a future indicating the result of the store operation
+ */
+ CompletableFuture<MeterStoreResult> deleteMeter(Meter meter);
+
+ /**
+ * Updates a meter whose meter id is the same as the passed meter.
+ *
+ * @param meter a new meter
+ * @return a future indicating the result of the store operation
+ */
+ CompletableFuture<MeterStoreResult> updateMeter(Meter meter);
+
+ /**
+ * Updates a given meter's state with the provided state.
+ *
+ * @param meter a meter
+ */
+ void updateMeterState(Meter meter);
+
+ /**
+ * Obtains a meter matching the given meter id.
+ *
+ * @param meterId a meter id
+ * @return a meter
+ */
+ Meter getMeter(MeterId meterId);
+
+ /**
+ * Returns all meters stored in the store.
+ *
+ * @return a collection of meters
+ */
+ Collection<Meter> getAllMeters();
+
+ /**
+ * Update the store by deleting the failed meter.
+ * Notifies the delegate that the meter failed to allow it
+ * to nofity the app.
+ *
+ * @param op a failed meter operation
+ * @param reason a failure reason
+ */
+ void failedMeter(MeterOperation op, MeterFailReason reason);
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterStoreDelegate.java b/core/api/src/main/java/org/onosproject/net/meter/MeterStoreDelegate.java
new file mode 100644
index 0000000..9bfeb42
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Meter store delegate abstraction.
+ */
+public interface MeterStoreDelegate extends StoreDelegate<MeterEvent> {
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/MeterStoreResult.java b/core/api/src/main/java/org/onosproject/net/meter/MeterStoreResult.java
new file mode 100644
index 0000000..7a26746
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterStoreResult.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.meter;
+
+import java.util.Optional;
+
+/**
+ * An entity used to indicate whether the store operation passed.
+ */
+public final class MeterStoreResult {
+
+
+ private final Type type;
+ private final Optional<MeterFailReason> reason;
+
+ public enum Type {
+ SUCCESS,
+ FAIL
+ }
+
+ private MeterStoreResult(Type type, MeterFailReason reason) {
+ this.type = type;
+ this.reason = Optional.ofNullable(reason);
+ }
+
+ public Type type() {
+ return type;
+ }
+
+ public Optional<MeterFailReason> reason() {
+ return reason;
+ }
+
+ /**
+ * A successful store opertion.
+ *
+ * @return a meter store result
+ */
+ public static MeterStoreResult success() {
+ return new MeterStoreResult(Type.SUCCESS, null);
+ }
+
+ /**
+ * A failed store operation.
+ *
+ * @param reason a failure reason
+ * @return a meter store result
+ */
+ public static MeterStoreResult fail(MeterFailReason reason) {
+ return new MeterStoreResult(Type.FAIL, reason);
+ }
+
+}
diff --git a/core/api/src/main/java/org/onosproject/net/meter/package-info.java b/core/api/src/main/java/org/onosproject/net/meter/package-info.java
new file mode 100644
index 0000000..258634d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Flow meter model and related services.
+ */
+package org.onosproject.net.meter;
\ No newline at end of file