Add distributed persistent store and manager for instance port

Change-Id: I9a4ba11a3e0fb494aedf9cb35c2e9a7a7bcbf5c7
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePort.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePort.java
index 606e214..53a8797 100644
--- a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePort.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePort.java
@@ -26,6 +26,33 @@
 public interface InstancePort {
 
     /**
+     * List of instance port states.
+     */
+    enum State {
+
+        /**
+         * Signifies that the given instance port is in active state.
+         */
+        ACTIVE,
+
+        /**
+         * Signifies that the given instance port is in inactive state due to
+         * host termination.
+         */
+        INACTIVE,
+
+        /**
+         * Signifies that the given instance port is in pending removal state.
+         */
+        PENDING_REMOVAL,
+
+        /**
+         * Signifies that the given instance port is in migrating state.
+         */
+        MIGRATING
+    }
+
+    /**
      * Returns the OpenStack network ID of the instance port.
      *
      * @return openstack network id
@@ -66,4 +93,88 @@
      * @return port number
      */
     PortNumber portNumber();
+
+    /**
+     * Returns the state of the instance port.
+     *
+     * @return state of port
+     */
+    State state();
+
+    /**
+     * Returns new instance port instance with given state.
+     *
+     * @param newState updated state
+     * @return updated instance port
+     */
+    InstancePort updateState(State newState);
+
+    /**
+     * Builder of new instance port.
+     */
+    interface Builder {
+
+        /**
+         * Builds an immutable instance port instance.
+         *
+         * @return instance port
+         */
+        InstancePort build();
+
+        /**
+         * Returns instance port builder with supplied network identifier.
+         *
+         * @param networkId network identifier
+         * @return instance port builder
+         */
+        Builder networkId(String networkId);
+
+        /**
+         * Returns instance port builder with supplied port identifier.
+         *
+         * @param portId port identifier
+         * @return instance port builder
+         */
+        Builder portId(String portId);
+
+        /**
+         * Returns instance port builder with supplied Mac Address.
+         *
+         * @param macAddress MAC address
+         * @return instance port builder
+         */
+        Builder macAddress(MacAddress macAddress);
+
+        /**
+         * Returns instance port builder with supplied IP Address.
+         *
+         * @param ipAddress IP address
+         * @return instance port builder
+         */
+        Builder ipAddress(IpAddress ipAddress);
+
+        /**
+         * Returns instance port builder with supplied Device identifier.
+         *
+         * @param deviceId device identifier
+         * @return instance port builder
+         */
+        Builder deviceId(DeviceId deviceId);
+
+        /**
+         * Returns instance port builder with supplied port number.
+         *
+         * @param portNumber port number
+         * @return instance port builder
+         */
+        Builder portNumber(PortNumber portNumber);
+
+        /**
+         * Returns instance port builder with supplied state.
+         *
+         * @param state state
+         * @return instance port builder
+         */
+        Builder state(State state);
+    }
 }
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortAdminService.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortAdminService.java
new file mode 100644
index 0000000..264e1ce
--- /dev/null
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortAdminService.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.openstacknetworking.api;
+
+/**
+ * Service for administering the inventory of OpenStack instance port.
+ */
+public interface InstancePortAdminService extends InstancePortService {
+
+    /**
+     * Creates an instance port with the given information.
+     *
+     * @param instancePort instance port
+     */
+    void createInstancePort(InstancePort instancePort);
+
+    /**
+     * Updates the instance port with the given information.
+     *
+     * @param instancePort the updated instance port
+     */
+    void updateInstancePort(InstancePort instancePort);
+
+    /**
+     * Removes the instance port with the given port identifier.
+     *
+     * @param portId port identifier
+     */
+    void removeInstancePort(String portId);
+
+    /**
+     * Clears the existing instance port.
+     */
+    void clear();
+}
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortEvent.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortEvent.java
index 4276cf2..434aa2d 100644
--- a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortEvent.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortEvent.java
@@ -50,7 +50,17 @@
         /**
          * Signifies that the instance is migration is ended.
          */
-        OPENSTACK_INSTANCE_MIGRATION_ENDED
+        OPENSTACK_INSTANCE_MIGRATION_ENDED,
+
+        /**
+         * Signifies that the instance is terminated.
+         */
+        OPENSTACK_INSTANCE_TERMINATED,
+
+        /**
+         * Signifies that the instance is restarted.
+         */
+        OPENSTACK_INSTANCE_RESTARTED,
     }
 
     /**
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortStore.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortStore.java
new file mode 100644
index 0000000..daf37ce
--- /dev/null
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortStore.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.openstacknetworking.api;
+
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of instance port; not intended for direct use.
+ */
+public interface InstancePortStore
+        extends Store<InstancePortEvent, InstancePortStoreDelegate> {
+
+    /**
+     * Creates a new instance port.
+     *
+     * @param port a new instance port
+     */
+    void createInstancePort(InstancePort port);
+
+    /**
+     * Updates the existing instance port.
+     *
+     * @param port the existing instance port
+     */
+    void updateInstancePort(InstancePort port);
+
+    /**
+     * Removes the existing instance port.
+     *
+     * @param portId instance port identifier
+     * @return the removed instance port
+     */
+    InstancePort removeInstancePort(String portId);
+
+    /**
+     * Obtains the existing instance port.
+     *
+     * @param portId instance port identifier
+     * @return queried instance port
+     */
+    InstancePort instancePort(String portId);
+
+    /**
+     * Obtains a collection of all of instance ports.
+     *
+     * @return a collection of all of instance ports
+     */
+    Set<InstancePort> instancePorts();
+
+    /**
+     * Removes all instance ports.
+     */
+    void clear();
+}
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortStoreDelegate.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortStoreDelegate.java
new file mode 100644
index 0000000..34924b8
--- /dev/null
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/api/InstancePortStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * 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.openstacknetworking.api;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Instance port store delegate abstraction.
+ */
+public interface InstancePortStoreDelegate extends StoreDelegate<InstancePortEvent> {
+}