Added dump of table entry ids in bmv2 protocol

Change-Id: I54534cfb2c6188c922b36a2f8eb8e5c0851bc681
diff --git a/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java b/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java
index d866c55..66229b0 100644
--- a/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java
+++ b/protocols/bmv2/src/main/java/org/onosproject/bmv2/ctl/Bmv2ThriftClient.java
@@ -90,6 +90,9 @@
             .expireAfterAccess(CLIENT_CACHE_TIMEOUT, TimeUnit.SECONDS)
             .removalListener(new ClientRemovalListener())
             .build(new ClientLoader());
+
+    private static final Bmv2TableDumpParser TABLE_DUMP_PARSER = new Bmv2TableDumpParser();
+
     private final Standard.Iface standardClient;
     private final SimpleSwitch.Iface simpleSwitchClient;
     private final TTransport transport;
@@ -391,6 +394,44 @@
     }
 
     @Override
+    public List<Long> getInstalledEntryIds(String tableName) throws Bmv2RuntimeException {
+
+        LOG.debug("Getting entry ids... > deviceId={}, tableName={}", deviceId, tableName);
+
+        try {
+            List<Long> entryIds = TABLE_DUMP_PARSER.getEntryIds(dumpTable(tableName));
+            LOG.debug("Entry ids retrieved! > deviceId={}, tableName={}, entryIdsCount={}",
+                      deviceId, tableName, entryIds.size());
+            return entryIds;
+        } catch (Bmv2TableDumpParser.Bmv2TableDumpParserException e) {
+            LOG.debug("Exception while retrieving entry ids: {} > deviceId={}, tableName={}",
+                      e, deviceId, tableName);
+            throw new Bmv2RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public int cleanupTable(String tableName) throws Bmv2RuntimeException {
+
+        LOG.debug("Starting table cleanup... > deviceId={}, tableName={}", deviceId, tableName);
+
+        List<Long> entryIds = getInstalledEntryIds(tableName);
+
+        int count = 0;
+        for (Long entryId : entryIds) {
+            try {
+                standardClient.bm_mt_delete_entry(CONTEXT_ID, tableName, entryId);
+                count++;
+            } catch (TException e) {
+                LOG.warn("Exception while deleting entry: {} > deviceId={}, tableName={}, entryId={}",
+                         e.toString(), deviceId, tableName, entryId);
+            }
+        }
+
+        return count;
+    }
+
+    @Override
     public void transmitPacket(int portNumber, ImmutableByteSequence packet) throws Bmv2RuntimeException {
 
         LOG.debug("Requesting packet transmission... > portNumber={}, packet={}", portNumber, packet);