Refactor DistributedPacketStore to store packet requests in a ConsistentMultimap

Change-Id: Ia4a93c47fee726009673e99609b2f8800807e675
diff --git a/core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMultimap.java b/core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMultimap.java
index 600af28..c14b187 100644
--- a/core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMultimap.java
+++ b/core/api/src/main/java/org/onosproject/store/primitives/DefaultConsistentMultimap.java
@@ -86,11 +86,21 @@
     }
 
     @Override
+    public Versioned<Collection<? extends V>> putAndGet(K key, V value) {
+        return complete(asyncMultimap.putAndGet(key, value));
+    }
+
+    @Override
     public boolean remove(K key, V value) {
         return complete(asyncMultimap.remove(key, value));
     }
 
     @Override
+    public Versioned<Collection<? extends V>> removeAndGet(K key, V value) {
+        return complete(asyncMultimap.removeAndGet(key, value));
+    }
+
+    @Override
     public boolean removeAll(K key, Collection<? extends V> values) {
         return complete(asyncMultimap.removeAll(key, values));
     }
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java
index 12b4645..94943b8 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java
@@ -104,6 +104,19 @@
     CompletableFuture<Boolean> put(K key, V value);
 
     /**
+     * If the key-value pair does not already exist adds either the key value
+     * pair or the value to the set of values associated with the key and
+     * returns the updated value, if the key-value pair already exists then behavior
+     * is implementation specific with some implementations allowing duplicates
+     * and others ignoring put requests for existing entries.
+     *
+     * @param key the key to add
+     * @param value the value to add
+     * @return a future to be completed with the updated values
+     */
+    CompletableFuture<Versioned<Collection<? extends V>>> putAndGet(K key, V value);
+
+    /**
      * Removes the key-value pair with the specified values if it exists. In
      * implementations that allow duplicates which matching entry will be
      * removed is undefined.
@@ -116,6 +129,17 @@
     CompletableFuture<Boolean> remove(K key, V value);
 
     /**
+     * Removes the key-value pair with the specified values if it exists. In
+     * implementations that allow duplicates which matching entry will be
+     * removed is undefined.
+     *
+     * @param key the key of the pair to be removed
+     * @param value the value of the pair to be removed
+     * @return a future to be completed with the updated values
+     */
+    CompletableFuture<Versioned<Collection<? extends V>>> removeAndGet(K key, V value);
+
+    /**
      * Removes the key-value pairs with the specified key and values if they
      * exist. In implementations that allow duplicates each instance of a key
      * will remove one matching entry, which one is not defined. Equivalent to
diff --git a/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimap.java b/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimap.java
index bdbbee0..99045a8 100644
--- a/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimap.java
@@ -91,6 +91,19 @@
     boolean put(K key, V value);
 
     /**
+     * If the key-value pair does not already exist adds either the key value
+     * pair or the value to the set of values associated with the key and
+     * returns the updated value, if the key-value pair already exists then behavior
+     * is implementation specific with some implementations allowing duplicates
+     * and others ignoring put requests for existing entries.
+     *
+     * @param key the key to add
+     * @param value the value to add
+     * @return the updated values
+     */
+    Versioned<Collection<? extends V>> putAndGet(K key, V value);
+
+    /**
      * Removes the key-value pair with the specified values if it exists. In
      * implementations that allow duplicates which matching entry will be
      * removed is undefined.
@@ -102,6 +115,17 @@
     boolean remove(K key, V value);
 
     /**
+     * Removes the key-value pair with the specified values if it exists. In
+     * implementations that allow duplicates which matching entry will be
+     * removed is undefined.
+     *
+     * @param key the key of the pair to be removed
+     * @param value the value of the pair to be removed
+     * @return the updated values
+     */
+    Versioned<Collection<? extends V>> removeAndGet(K key, V value);
+
+    /**
      * Removes the key-value pairs with the specified key and values if they
      * exist. In implementations that allow duplicates each instance of a key
      * will remove one matching entry, which one is not defined. Equivalent to
diff --git a/core/api/src/test/java/org/onosproject/store/service/TestConsistentMultimap.java b/core/api/src/test/java/org/onosproject/store/service/TestConsistentMultimap.java
index a97337e..08be2e4 100644
--- a/core/api/src/test/java/org/onosproject/store/service/TestConsistentMultimap.java
+++ b/core/api/src/test/java/org/onosproject/store/service/TestConsistentMultimap.java
@@ -76,11 +76,23 @@
     }
 
     @Override
+    public Versioned<Collection<? extends V>> putAndGet(K key, V value) {
+        innermap.put(key, version(value));
+        return (Versioned<Collection<? extends V>>) innermap.get(key);
+    }
+
+    @Override
     public boolean remove(K key, V value) {
         return innermap.remove(key, value);
     }
 
     @Override
+    public Versioned<Collection<? extends V>> removeAndGet(K key, V value) {
+        innermap.remove(key, value);
+        return (Versioned<Collection<? extends V>>) innermap.get(key);
+    }
+
+    @Override
     public boolean removeAll(K key, Collection<? extends V> values) {
         return false;
     }