sketching model elements for meter objects.

Change-Id: Ie9e8eb2af634f2f591089445d2258495285dcdd1
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..e434073
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/Band.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 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 eld in the
+         * IP header of the packets that exceed the band
+         * rate value.
+         */
+        REMARK
+    }
+
+    /**
+     * The rate at which this meter applies.
+     *
+     * @return the integer value of the rate
+     */
+    int rate();
+
+    /**
+     * The burst size at which the meter applies.
+     *
+     * @return the integer value of the size
+     */
+    int burst();
+
+
+}
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..afc4277
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/Meter.java
@@ -0,0 +1,74 @@
+/*
+ * 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 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
+    }
+
+    /**
+     * 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
+     */
+    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();
+
+}
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..70f65ef
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterFailReason.java
@@ -0,0 +1,42 @@
+/*
+ * 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
+}
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..b62db10
--- /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 for a given device.
+ */
+public final class MeterId {
+
+    static final long MAX = 0xFFFF0000;
+
+    private final int 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);
+
+    protected MeterId(int id) {
+        checkArgument(id <= MAX, "id cannot be larger than 0xFFFF0000");
+        this.id = id;
+    }
+
+    /**
+     * The integer representation of the meter id.
+     *
+     * @return an integer
+     */
+    int 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 id;
+    }
+
+    public static MeterId meterId(int id) {
+        return new MeterId(id);
+
+    }
+
+}
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..88cc44d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterOperation.java
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+/**
+ * Representation of an operation on the meter table.
+ */
+public class MeterOperation {
+
+    /**
+     * Tyoe of meter operation.
+     */
+    public enum Type {
+        ADD,
+        REMOVE,
+        MODIFY
+    }
+
+    private final Meter meter;
+    private final Type type;
+
+
+    public MeterOperation(Meter meter, Type type) {
+        this.meter = meter;
+        this.type = type;
+    }
+
+    /**
+     * Returns the type of operation.
+     *
+     * @return type
+     */
+    public Type type() {
+        return type;
+    }
+
+    /**
+     * Returns the meter.
+     *
+     * @return a meter
+     */
+    public Meter meter() {
+        return meter;
+    }
+
+    @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
index 038a317..4655e23 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterProvider.java
@@ -15,10 +15,34 @@
  */
 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..831c88a
--- /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 deviceId
+     * @param operation
+     */
+    void meterOperationFailed(DeviceId deviceId, 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/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 1c34f66..5c9940c 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
@@ -19,6 +19,9 @@
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.meter.MeterOperation;
+import org.onosproject.net.meter.MeterOperations;
 import org.onosproject.net.meter.MeterProvider;
 import org.onosproject.net.provider.AbstractProvider;
 import org.onosproject.net.provider.ProviderId;
@@ -45,4 +48,14 @@
     public OpenFlowMeterProvider() {
         super(new ProviderId("of", "org.onosproject.provider.meter"));
     }
+
+    @Override
+    public void performMeterOperation(DeviceId deviceId, MeterOperations meterOps) {
+
+    }
+
+    @Override
+    public void performMeterOperation(DeviceId deviceId, MeterOperation meterOp) {
+
+    }
 }