[SDFAB-355] Revisit MeterService and north abstractions

Change-Id: I685cb90d53f8aa61017ecda9fa7ff842e58e2940
diff --git a/core/api/src/main/java/org/onosproject/net/meter/DefaultMeterRequest.java b/core/api/src/main/java/org/onosproject/net/meter/DefaultMeterRequest.java
index e6e2d1b..0dbd4f7 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/DefaultMeterRequest.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/DefaultMeterRequest.java
@@ -42,11 +42,14 @@
     private final DeviceId deviceId;
     private final Optional<MeterContext> context;
     private final Type op;
+    private final MeterScope scope;
+    private final Optional<Long> index;
 
     private DefaultMeterRequest(DeviceId deviceId, ApplicationId appId,
                                 Meter.Unit unit, boolean burst,
                                 Collection<Band> bands, MeterContext context,
-                                Type op, Annotations... annotations) {
+                                Type op, MeterScope scope, Optional<Long> index,
+                                Annotations... annotations) {
         super(annotations);
         this.deviceId = deviceId;
         this.appId = appId;
@@ -55,6 +58,8 @@
         this.bands = bands;
         this.context = Optional.ofNullable(context);
         this.op = op;
+        this.scope = scope;
+        this.index = index;
     }
 
     @Override
@@ -88,7 +93,15 @@
         return context;
     }
 
+    @Override
+    public MeterScope scope() {
+        return scope;
+    }
 
+    @Override
+    public Optional<Long> index() {
+        return index;
+    }
 
     public static Builder builder() {
         return new Builder();
@@ -102,6 +115,8 @@
                 .add("unit", unit)
                 .add("isBurst", burst)
                 .add("bands", bands)
+                .add("scope", scope)
+                .add("desired index", index.orElse(null))
                 .add("annotations", annotations())
                 .toString();
     }
@@ -114,9 +129,9 @@
         private Collection<Band> bands;
         private DeviceId deviceId;
         private MeterContext context;
-        private Optional<MeterId> desiredId = Optional.empty();
         private Annotations annotations;
-
+        private MeterScope scope = MeterScope.globalScope();
+        private Optional<Long> desiredIndex = Optional.empty();
 
         @Override
         public MeterRequest.Builder forDevice(DeviceId deviceId) {
@@ -131,19 +146,19 @@
         }
 
         @Override
-        public MeterRequest.Builder  withUnit(Meter.Unit unit) {
+        public MeterRequest.Builder withUnit(Meter.Unit unit) {
             this.unit = unit;
             return this;
         }
 
         @Override
-        public MeterRequest.Builder  burst() {
+        public MeterRequest.Builder burst() {
             this.burst = true;
             return this;
         }
 
         @Override
-        public MeterRequest.Builder  withBands(Collection<Band> bands) {
+        public MeterRequest.Builder withBands(Collection<Band> bands) {
             this.bands = ImmutableSet.copyOf(bands);
             return this;
         }
@@ -161,17 +176,29 @@
         }
 
         @Override
+        public MeterRequest.Builder withScope(MeterScope scope) {
+            this.scope = scope;
+            return this;
+        }
+
+        @Override
+        public MeterRequest.Builder withIndex(Long index) {
+            this.desiredIndex = Optional.ofNullable(index);
+            return this;
+        }
+
+        @Override
         public MeterRequest add() {
             validate();
-            return new DefaultMeterRequest(deviceId, appId, unit, burst, bands,
-                                           context, Type.ADD, annotations);
+            return new DefaultMeterRequest(deviceId, appId, unit, burst, bands, context,
+                                           Type.ADD, scope, desiredIndex, annotations);
         }
 
         @Override
         public MeterRequest remove() {
             validate();
-            return new DefaultMeterRequest(deviceId, appId, unit, burst, bands,
-                                           context, Type.REMOVE, annotations);
+            return new DefaultMeterRequest(deviceId, appId, unit, burst, bands, context,
+                                           Type.REMOVE, scope, desiredIndex, annotations);
         }
 
         private void validate() {
@@ -179,6 +206,9 @@
             checkNotNull(bands, "Must have bands.");
             checkArgument(!bands.isEmpty(), "Must have at least one band.");
             checkNotNull(appId, "Must have an application id");
+            if (desiredIndex.isPresent()) {
+                checkArgument(desiredIndex.get() >= 0, "Desired index cannot be negative");
+            }
         }