Support VM resize and cold migration in openstack networking app

Change-Id: I46ecae7a1eb2bfe9a4093be6893e65db485b7f58
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/InstancePortManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/InstancePortManager.java
index 2383e62..0935f53 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/InstancePortManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/InstancePortManager.java
@@ -246,15 +246,34 @@
                         // first time to add instance
                         createInstancePort(instPort);
                     } else {
-                        // the instance was restarted
                         if (existingPort.state() == INACTIVE) {
-                            updateInstancePort(instPort);
+
+                            if (instPort.deviceId().equals(existingPort.deviceId())) {
+
+                                // VM RESTART case
+                                // if the ID of switch where VM is attached to is
+                                // identical, we can assume that the VM was
+                                // restarted in the same location;
+                                // note that the switch port number where VM is
+                                // attached can be varied per each restart
+                                updateInstancePort(instPort);
+                            } else {
+
+                                // VM COLD MIGRATION case
+                                // if the ID of switch where VM is attached to is
+                                // varied, we can assume that the VM was migrated
+                                // to a new location
+                                updateInstancePort(instPort.updateState(MIGRATING));
+                                InstancePort updated = instPort.updateState(MIGRATED);
+                                updateInstancePort(updated.updatePrevLocation(
+                                        existingPort.deviceId(), existingPort.portNumber()));
+                            }
                         }
                     }
                     break;
                 case HOST_REMOVED:
                     // we will remove instance port from persistent store,
-                    // only if we receive port removal signal from neutron
+                    // only if we receive port removal signal from neutron.
                     // by default, we update the instance port state to INACTIVE
                     // to indicate the instance is terminated
                     updateInstancePort(instPort.updateState(INACTIVE));