[ONOS-8093] Purge Meter API

Change-Id: I8e5a6826793b9f17d7115e241a12e3a2972b38a9
(cherry picked from commit 4e4084cd6ded060616a5afa7d3af427715cfc2d0)
diff --git a/apps/virtual/app/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkMeterManager.java b/apps/virtual/app/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkMeterManager.java
index 2cce14c..9ec530b 100644
--- a/apps/virtual/app/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkMeterManager.java
+++ b/apps/virtual/app/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkMeterManager.java
@@ -216,6 +216,11 @@
         // Do nothing
     }
 
+    @Override
+    public void purgeMeters(DeviceId deviceId) {
+        // Do nothing
+    }
+
     private class InternalMeterProviderService
             extends AbstractVirtualProviderService<VirtualMeterProvider>
             implements VirtualMeterProviderService {
diff --git a/cli/src/main/java/org/onosproject/cli/net/WipeOutCommand.java b/cli/src/main/java/org/onosproject/cli/net/WipeOutCommand.java
index 7bfd6b9..868566c 100644
--- a/cli/src/main/java/org/onosproject/cli/net/WipeOutCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/WipeOutCommand.java
@@ -35,6 +35,7 @@
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.Key;
 import org.onosproject.net.link.LinkAdminService;
+import org.onosproject.net.meter.MeterService;
 import org.onosproject.net.region.RegionAdminService;
 import org.onosproject.ui.UiExtensionService;
 import org.onosproject.ui.UiTopoLayoutService;
@@ -71,6 +72,7 @@
         wipeOutHosts();
         wipeOutFlows();
         wipeOutGroups();
+        wipeOutMeters();
         wipeOutDevices();
         wipeOutLinks();
         wipeOutNetworkConfig();
@@ -132,6 +134,15 @@
         }
     }
 
+    private void wipeOutMeters() {
+        print("Wiping meters");
+        MeterService meterService = get(MeterService.class);
+        DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
+        for (Device device : deviceAdminService.getDevices()) {
+            meterService.purgeMeters(device.id());
+        }
+    }
+
     private void wipeOutHosts() {
         print("Wiping hosts");
         HostAdminService hostAdminService = get(HostAdminService.class);
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
index 560d94e..991715c 100644
--- a/core/api/src/main/java/org/onosproject/net/meter/MeterService.java
+++ b/core/api/src/main/java/org/onosproject/net/meter/MeterService.java
@@ -84,4 +84,13 @@
      * @param meterId the id to be freed
      */
     void freeMeterId(DeviceId deviceId, MeterId meterId);
+
+    /**
+     * Purges all the meters on the specified device.
+     * @param deviceId device identifier
+     */
+    default void purgeMeters(DeviceId deviceId){
+        //Default implementation does nothing
+    }
+
 }
diff --git a/core/api/src/test/java/org/onosproject/net/meter/MeterServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/meter/MeterServiceAdapter.java
index 26def99..cc55672 100644
--- a/core/api/src/test/java/org/onosproject/net/meter/MeterServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/meter/MeterServiceAdapter.java
@@ -60,6 +60,11 @@
     }
 
     @Override
+    public void purgeMeters(DeviceId deviceId) {
+
+    }
+
+    @Override
     public void addListener(MeterListener listener) {
 
     }
diff --git a/core/net/src/main/java/org/onosproject/net/meter/impl/MeterManager.java b/core/net/src/main/java/org/onosproject/net/meter/impl/MeterManager.java
index 03f4889..1979c61 100644
--- a/core/net/src/main/java/org/onosproject/net/meter/impl/MeterManager.java
+++ b/core/net/src/main/java/org/onosproject/net/meter/impl/MeterManager.java
@@ -298,6 +298,12 @@
         store.freeMeterId(deviceId, meterId);
     }
 
+    @Override
+    public void purgeMeters(DeviceId deviceId) {
+        // We delegate direclty to the store
+        store.purgeMeter(deviceId);
+    }
+
     private class InternalMeterProviderService
             extends AbstractProviderService<MeterProvider>
             implements MeterProviderService {