[ONOS-3659] Submit the modified content of onos-1.4 to onos-master.

Change-Id: Ibdb9897cde6bc7622276178a6087f02c49da2a48
diff --git a/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java b/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java
index 4188cee..18f8053 100644
--- a/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java
+++ b/apps/vtn/sfcmgr/src/test/java/org/onosproject/sfc/util/VtnRscManagerTestImpl.java
@@ -20,6 +20,7 @@
 import org.onlab.packet.MacAddress;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.Host;
 import org.onosproject.net.HostId;
 import org.onosproject.vtnrsc.SegmentationId;
 import org.onosproject.vtnrsc.TenantId;
@@ -69,4 +70,14 @@
     public DeviceId getSFToSFFMaping(VirtualPortId portId) {
         return DeviceId.deviceId("www.google.com");
     }
+
+    @Override
+    public void addDeviceIdOfOvsMap(VirtualPortId virtualPortId,
+                                    TenantId tenantId, DeviceId deviceId) {
+    }
+
+    @Override
+    public void removeDeviceIdOfOvsMap(Host host, TenantId tenantId,
+                                       DeviceId deviceId) {
+    }
 }
diff --git a/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/manager/impl/VTNManager.java b/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/manager/impl/VTNManager.java
index ac898d1..023bd05 100644
--- a/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/manager/impl/VTNManager.java
+++ b/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/manager/impl/VTNManager.java
@@ -19,6 +19,7 @@
 import static org.slf4j.LoggerFactory.getLogger;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -75,9 +76,12 @@
 import org.onosproject.net.host.HostListener;
 import org.onosproject.net.host.HostService;
 import org.onosproject.store.serializers.KryoNamespaces;
+import org.onosproject.store.service.ConsistentMap;
 import org.onosproject.store.service.EventuallyConsistentMap;
 import org.onosproject.store.service.LogicalClockService;
+import org.onosproject.store.service.Serializer;
 import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.Versioned;
 import org.onosproject.vtn.manager.VTNService;
 import org.onosproject.vtn.table.ArpService;
 import org.onosproject.vtn.table.ClassifierService;
@@ -188,7 +192,7 @@
     private final DeviceListener deviceListener = new InnerDeviceListener();
     private final VtnRscListener l3EventListener = new VtnL3EventListener();
 
-    private static String exPortName = "eth0";
+    private static final String EX_PORT_KEY = "exPortKey";
     private static final String IFACEID = "ifaceid";
     private static final String CONTROLLER_IP_KEY = "ipaddress";
     public static final String DRIVER_NAME = "onosfw";
@@ -198,6 +202,7 @@
     private static final String ROUTERINF_FLAG_OF_TENANT = "routerInfFlagOfTenant";
     private static final String HOSTS_OF_SUBNET = "hostsOfSubnet";
     private static final String EX_PORT_OF_DEVICE = "exPortOfDevice";
+    private static final String EX_PORT_MAP = "exPortMap";
     private static final String DEFAULT_IP = "0.0.0.0";
     private static final int SUBNET_NUM = 2;
 
@@ -207,6 +212,7 @@
     private EventuallyConsistentMap<SubnetId, Map<HostId, Host>> hostsOfSubnet;
     private EventuallyConsistentMap<TenantId, Boolean> routerInfFlagOfTenant;
     private EventuallyConsistentMap<DeviceId, Port> exPortOfDevice;
+    private static ConsistentMap<String, String> exPortMap;
 
     @Activate
     public void activate() {
@@ -275,6 +281,14 @@
                 .withTimestampProvider((k, v) -> clockService.getTimestamp())
                 .build();
 
+        exPortMap = storageService
+                .<String, String>consistentMapBuilder()
+                .withName(EX_PORT_MAP)
+                .withApplicationId(appId)
+                .withPurgeOnUninstall()
+                .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API)))
+                .build();
+
         log.info("Started");
     }
 
@@ -310,8 +324,11 @@
             config.driver(DRIVER_NAME);
             configService.applyConfig(deviceId, BasicDeviceConfig.class, config.node());
             // Add Bridge
-            VtnConfig.applyBridgeConfig(handler, dpid, exPortName);
-            log.info("A new ovs is created in node {}", localIp.toString());
+            Versioned<String> exPortVersioned = exPortMap.get(EX_PORT_KEY);
+            if (exPortVersioned != null) {
+                VtnConfig.applyBridgeConfig(handler, dpid, exPortVersioned.value());
+                log.info("A new ovs is created in node {}", localIp.toString());
+            }
             switchesOfController.put(localIp, true);
         }
         // Create tunnel in br-int on all controllers
@@ -330,8 +347,6 @@
         if (mastershipService.isLocalMaster(controllerDeviceId)) {
             switchesOfController.remove(dstIpAddress);
         }
-        // remove tunnel in br-int on other controllers
-        programTunnelConfig(controllerDeviceId, dstIpAddress, null);
     }
 
     @Override
@@ -357,6 +372,7 @@
             log.error("The ifaceId of Host is null");
             return;
         }
+        programSffAndClassifierHost(host, Objective.Operation.ADD);
         // apply L2 openflow rules
         applyHostMonitoredL2Rules(host, Objective.Operation.ADD);
         // apply L3 openflow rules
@@ -374,6 +390,7 @@
             log.error("The ifaceId of Host is null");
             return;
         }
+        programSffAndClassifierHost(host, Objective.Operation.REMOVE);
         // apply L2 openflow rules
         applyHostMonitoredL2Rules(host, Objective.Operation.REMOVE);
         // apply L3 openflow rules
@@ -463,6 +480,22 @@
         }
     }
 
+    private void programSffAndClassifierHost(Host host, Objective.Operation type) {
+        DeviceId deviceId = host.location().deviceId();
+        String ifaceId = host.annotations().value(IFACEID);
+        VirtualPortId virtualPortId = VirtualPortId.portId(ifaceId);
+        VirtualPort virtualPort = virtualPortService.getPort(virtualPortId);
+        if (virtualPort == null) {
+            virtualPort = VtnData.getPort(vPortStore, virtualPortId);
+        }
+        TenantId tenantId = virtualPort.tenantId();
+        if (Objective.Operation.ADD == type) {
+            vtnRscService.addDeviceIdOfOvsMap(virtualPortId, tenantId, deviceId);
+        } else if (Objective.Operation.REMOVE == type) {
+            vtnRscService.removeDeviceIdOfOvsMap(host, tenantId, deviceId);
+        }
+    }
+
     private void applyHostMonitoredL2Rules(Host host, Objective.Operation type) {
         DeviceId deviceId = host.location().deviceId();
         if (!mastershipService.isLocalMaster(deviceId)) {
@@ -971,7 +1004,9 @@
         Port exPort = null;
         for (Port port : ports) {
             String portName = port.annotations().value(AnnotationKeys.PORT_NAME);
-            if (portName != null && portName.equals(exPortName)) {
+            Versioned<String> exPortVersioned = exPortMap.get(EX_PORT_KEY);
+            if (portName != null && exPortVersioned != null && portName.
+                    equals(exPortVersioned.value())) {
                 exPort = port;
                 break;
             }
@@ -1071,6 +1106,6 @@
     }
 
     public static void setExPortName(String name) {
-        exPortName = name;
+        exPortMap.put(EX_PORT_KEY, name);
     }
 }
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java
index ce9bb21f..91e149a 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/floatingip/impl/FloatingIpManager.java
@@ -176,23 +176,11 @@
         boolean result = true;
         for (FloatingIp floatingIp : floatingIps) {
             verifyFloatingIpData(floatingIp);
-            if (floatingIp.portId() != null) {
-                floatingIpStore.put(floatingIp.id(), floatingIp);
-                if (!floatingIpStore.containsKey(floatingIp.id())) {
-                    log.debug("The floating Ip is created failed whose identifier is {}",
-                              floatingIp.id().toString());
-                    result = false;
-                }
-            } else {
-                FloatingIp oldFloatingIp = floatingIpStore.get(floatingIp.id());
-                if (oldFloatingIp != null) {
-                    floatingIpStore.remove(floatingIp.id(), oldFloatingIp);
-                    if (floatingIpStore.containsKey(floatingIp.id())) {
-                        log.debug("The floating Ip is created failed whose identifier is {}",
-                                  floatingIp.id().toString());
-                        result = false;
-                    }
-                }
+            floatingIpStore.put(floatingIp.id(), floatingIp);
+            if (!floatingIpStore.containsKey(floatingIp.id())) {
+                log.debug("The floating Ip is created failed whose identifier is {}",
+                          floatingIp.id().toString());
+                result = false;
             }
         }
         return result;
@@ -204,23 +192,11 @@
         boolean result = true;
         for (FloatingIp floatingIp : floatingIps) {
             verifyFloatingIpData(floatingIp);
-            if (floatingIp.portId() != null) {
-                floatingIpStore.put(floatingIp.id(), floatingIp);
-                if (!floatingIpStore.containsKey(floatingIp.id())) {
-                    log.debug("The floating Ip is updated failed whose identifier is {}",
-                              floatingIp.id().toString());
-                    result = false;
-                }
-            } else {
-                FloatingIp oldFloatingIp = floatingIpStore.get(floatingIp.id());
-                if (oldFloatingIp != null) {
-                    floatingIpStore.remove(floatingIp.id(), oldFloatingIp);
-                    if (floatingIpStore.containsKey(floatingIp.id())) {
-                        log.debug("The floating Ip is updated failed whose identifier is {}",
-                                  floatingIp.id().toString());
-                        result = false;
-                    }
-                }
+            floatingIpStore.put(floatingIp.id(), floatingIp);
+            if (!floatingIpStore.containsKey(floatingIp.id())) {
+                log.debug("The floating Ip is updated failed whose identifier is {}",
+                          floatingIp.id().toString());
+                result = false;
             }
         }
         return result;
@@ -238,6 +214,11 @@
                                                    "FloatingIP ID doesn't exist");
             }
             FloatingIp floatingIp = floatingIpStore.get(floatingIpId);
+            if (floatingIp.portId() != null) {
+                log.debug("The floating Ip is uesd by the port whose identifier is {}",
+                          floatingIp.portId().toString());
+                return false;
+            }
             floatingIpStore.remove(floatingIpId, floatingIp);
             if (floatingIpStore.containsKey(floatingIpId)) {
                 log.debug("The floating Ip is deleted failed whose identifier is {}",
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java
index bc9f4e6..4c68d76 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/VtnRscService.java
@@ -21,6 +21,7 @@
 import org.onosproject.event.ListenerService;
 import org.onosproject.net.Device;
 import org.onosproject.net.DeviceId;
+import org.onosproject.net.Host;
 import org.onosproject.net.HostId;
 import org.onosproject.vtnrsc.SegmentationId;
 import org.onosproject.vtnrsc.TenantId;
@@ -79,4 +80,24 @@
      * @return device identifier
      */
     DeviceId getSFToSFFMaping(VirtualPortId portId);
+
+    /**
+     * Adds specify Device identifier to Service Function Forward OvsMap
+     * or Classifier OvsMap.
+     *
+     * @param virtualPortId the VirtualPort identifier
+     * @param tenantId the tenant identifier
+     * @param deviceId the device identifier
+     */
+    void addDeviceIdOfOvsMap(VirtualPortId virtualPortId, TenantId tenantId, DeviceId deviceId);
+
+    /**
+     * Removes specify Device identifier from Service Function Forward OvsMap
+     * or Classifier OvsMap.
+     *
+     * @param host Host
+     * @param tenantId the tenant identifier
+     * @param deviceId the device identifier
+     */
+    void removeDeviceIdOfOvsMap(Host host, TenantId tenantId, DeviceId deviceId);
 }
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java
index 6781b60..e2d1904 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/service/impl/VtnRscManager.java
@@ -37,16 +37,19 @@
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Host;
 import org.onosproject.net.HostId;
-import org.onosproject.net.host.HostEvent;
-import org.onosproject.net.host.HostListener;
-import org.onosproject.net.host.HostService;
 import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.host.HostService;
 import org.onosproject.store.serializers.KryoNamespaces;
 import org.onosproject.store.service.EventuallyConsistentMap;
 import org.onosproject.store.service.LogicalClockService;
 import org.onosproject.store.service.StorageService;
 import org.onosproject.vtnrsc.FixedIp;
 import org.onosproject.vtnrsc.FloatingIp;
+import org.onosproject.vtnrsc.FlowClassifier;
+import org.onosproject.vtnrsc.PortChain;
+import org.onosproject.vtnrsc.PortPair;
+import org.onosproject.vtnrsc.PortPairGroup;
+import org.onosproject.vtnrsc.PortPairId;
 import org.onosproject.vtnrsc.Router;
 import org.onosproject.vtnrsc.RouterInterface;
 import org.onosproject.vtnrsc.SegmentationId;
@@ -55,17 +58,24 @@
 import org.onosproject.vtnrsc.TenantId;
 import org.onosproject.vtnrsc.VirtualPort;
 import org.onosproject.vtnrsc.VirtualPortId;
-import org.onosproject.vtnrsc.PortPair;
-import org.onosproject.vtnrsc.PortPairId;
-import org.onosproject.vtnrsc.PortPairGroup;
-import org.onosproject.vtnrsc.FlowClassifier;
-import org.onosproject.vtnrsc.PortChain;
 import org.onosproject.vtnrsc.event.VtnRscEvent;
 import org.onosproject.vtnrsc.event.VtnRscEventFeedback;
 import org.onosproject.vtnrsc.event.VtnRscListener;
 import org.onosproject.vtnrsc.floatingip.FloatingIpEvent;
 import org.onosproject.vtnrsc.floatingip.FloatingIpListener;
 import org.onosproject.vtnrsc.floatingip.FloatingIpService;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierEvent;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener;
+import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
+import org.onosproject.vtnrsc.portchain.PortChainEvent;
+import org.onosproject.vtnrsc.portchain.PortChainListener;
+import org.onosproject.vtnrsc.portchain.PortChainService;
+import org.onosproject.vtnrsc.portpair.PortPairEvent;
+import org.onosproject.vtnrsc.portpair.PortPairListener;
+import org.onosproject.vtnrsc.portpair.PortPairService;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupEvent;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
 import org.onosproject.vtnrsc.router.RouterEvent;
 import org.onosproject.vtnrsc.router.RouterListener;
 import org.onosproject.vtnrsc.router.RouterService;
@@ -76,18 +86,6 @@
 import org.onosproject.vtnrsc.subnet.SubnetService;
 import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
 import org.onosproject.vtnrsc.virtualport.VirtualPortService;
-import org.onosproject.vtnrsc.portpair.PortPairEvent;
-import org.onosproject.vtnrsc.portpair.PortPairListener;
-import org.onosproject.vtnrsc.portpair.PortPairService;
-import org.onosproject.vtnrsc.portpairgroup.PortPairGroupEvent;
-import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
-import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
-import org.onosproject.vtnrsc.flowclassifier.FlowClassifierEvent;
-import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener;
-import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService;
-import org.onosproject.vtnrsc.portchain.PortChainEvent;
-import org.onosproject.vtnrsc.portchain.PortChainListener;
-import org.onosproject.vtnrsc.portchain.PortChainService;
 import org.slf4j.Logger;
 
 /**
@@ -105,7 +103,6 @@
     protected LogicalClockService clockService;
 
     private final Logger log = getLogger(getClass());
-    private HostListener hostListener = new InnerHostListener();
     private FloatingIpListener floatingIpListener = new InnerFloatingIpListener();
     private RouterListener routerListener = new InnerRouterListener();
     private RouterInterfaceListener routerInterfaceListener = new InnerRouterInterfaceListener();
@@ -120,11 +117,11 @@
 
     private static final String IFACEID = "ifaceid";
     private static final String RUNNELOPTOPOIC = "tunnel-ops-ids";
-    private static final String LISTENER_NOT_NULL = "listener cannot be null";
     private static final String EVENT_NOT_NULL = "event cannot be null";
     private static final String TENANTID_NOT_NULL = "tenantId cannot be null";
     private static final String DEVICEID_NOT_NULL = "deviceId cannot be null";
-    private static final String OVSMAP_NOT_NULL = "ovsMap cannot be null";
+    private static final String VIRTUALPORTID_NOT_NULL = "virtualPortId cannot be null";
+    private static final String HOST_NOT_NULL = "host cannot be null";
     private static final String L3VNIMAP = "l3vniMap";
     private static final String CLASSIFIEROVSMAP = "classifierOvsMap";
     private static final String SFFOVSMAP = "sffOvsMap";
@@ -157,7 +154,6 @@
     @Activate
     public void activate() {
         eventDispatcher.addSink(VtnRscEvent.class, listenerRegistry);
-        hostService.addListener(hostListener);
         floatingIpService.addListener(floatingIpListener);
         routerService.addListener(routerListener);
         routerInterfaceService.addListener(routerInterfaceListener);
@@ -191,7 +187,6 @@
     @Deactivate
     public void deactivate() {
         eventDispatcher.removeSink(VtnRscEvent.class);
-        hostService.removeListener(hostListener);
         floatingIpService.removeListener(floatingIpListener);
         routerService.removeListener(routerListener);
         routerInterfaceService.removeListener(routerInterfaceListener);
@@ -220,37 +215,6 @@
         return l3vni;
     }
 
-    private class InnerHostListener implements HostListener {
-
-        @Override
-        public void event(HostEvent event) {
-            checkNotNull(event, EVENT_NOT_NULL);
-            Host host = event.subject();
-            String ifaceId = host.annotations().value(IFACEID);
-            if (ifaceId == null) {
-                log.error("The ifaceId of Host is null");
-                return;
-            }
-            VirtualPortId hPortId = VirtualPortId.portId(ifaceId);
-            TenantId tenantId = virtualPortService.getPort(hPortId).tenantId();
-            DeviceId deviceId = host.location().deviceId();
-            if (HostEvent.Type.HOST_ADDED == event.type()) {
-                if (isServiceFunction(hPortId)) {
-                    addDeviceIdOfOvsMap(tenantId, deviceId, sffOvsMap);
-                } else {
-                    addDeviceIdOfOvsMap(tenantId, deviceId, classifierOvsMap);
-                }
-            } else if (HostEvent.Type.HOST_REMOVED == event.type()) {
-                if (isLastSFHostOfTenant(host, deviceId, tenantId)) {
-                    removeDeviceIdOfOvsMap(tenantId, deviceId, sffOvsMap);
-                }
-                if (isLastClassifierHostOfTenant(host, deviceId, tenantId)) {
-                    removeDeviceIdOfOvsMap(tenantId, deviceId, classifierOvsMap);
-                }
-            }
-        }
-    }
-
     private class InnerFloatingIpListener implements FloatingIpListener {
 
         @Override
@@ -466,6 +430,32 @@
         return null;
     }
 
+    @Override
+    public void addDeviceIdOfOvsMap(VirtualPortId virtualPortId,
+                                    TenantId tenantId, DeviceId deviceId) {
+        checkNotNull(virtualPortId, VIRTUALPORTID_NOT_NULL);
+        checkNotNull(tenantId, TENANTID_NOT_NULL);
+        checkNotNull(deviceId, DEVICEID_NOT_NULL);
+        if (isServiceFunction(virtualPortId)) {
+            addDeviceIdToSpecificMap(tenantId, deviceId, sffOvsMap);
+        } else {
+            addDeviceIdToSpecificMap(tenantId, deviceId, classifierOvsMap);
+        }
+    }
+
+    @Override
+    public void removeDeviceIdOfOvsMap(Host host, TenantId tenantId, DeviceId deviceId) {
+        checkNotNull(host, HOST_NOT_NULL);
+        checkNotNull(tenantId, TENANTID_NOT_NULL);
+        checkNotNull(deviceId, DEVICEID_NOT_NULL);
+        if (isLastSFHostOfTenant(host, deviceId, tenantId)) {
+            removeDeviceIdToSpecificMap(tenantId, deviceId, sffOvsMap);
+        }
+        if (isLastClassifierHostOfTenant(host, deviceId, tenantId)) {
+            removeDeviceIdToSpecificMap(tenantId, deviceId, classifierOvsMap);
+        }
+    }
+
     /**
      * Checks whether the last Service Function host of a specific tenant in
      * this device.
@@ -477,11 +467,7 @@
      */
     private boolean isLastSFHostOfTenant(Host host, DeviceId deviceId,
                                          TenantId tenantId) {
-        checkNotNull(host, "host cannot be null");
-        checkNotNull(deviceId, DEVICEID_NOT_NULL);
-        checkNotNull(tenantId, TENANTID_NOT_NULL);
         Set<Host> hostSet = hostService.getConnectedHosts(deviceId);
-        Set<Host> sfcHostSet = new HashSet<Host>();
         if (hostSet != null) {
             for (Host h : hostSet) {
                 String ifaceId = h.annotations().value(IFACEID);
@@ -490,15 +476,14 @@
                     if (virtualPortService.getPort(hPortId).tenantId().tenantId()
                             .equals(tenantId.tenantId())
                             && isServiceFunction(hPortId)) {
-                        sfcHostSet.add(h);
+                        if (!h.equals(host)) {
+                            return false;
+                        }
                     }
                 }
             }
         }
-        if (sfcHostSet.size() == 1 && sfcHostSet.contains(host)) {
-            return true;
-        }
-        return false;
+        return true;
     }
 
     /**
@@ -512,11 +497,7 @@
      */
     private boolean isLastClassifierHostOfTenant(Host host, DeviceId deviceId,
                                                  TenantId tenantId) {
-        checkNotNull(host, "host cannot be null");
-        checkNotNull(deviceId, DEVICEID_NOT_NULL);
-        checkNotNull(tenantId, TENANTID_NOT_NULL);
         Set<Host> hostSet = hostService.getConnectedHosts(deviceId);
-        Set<Host> sfcHostSet = new HashSet<Host>();
         if (hostSet != null) {
             for (Host h : hostSet) {
                 String ifaceId = h.annotations().value(IFACEID);
@@ -525,15 +506,14 @@
                     if (virtualPortService.getPort(hPortId).tenantId().tenantId()
                             .equals(tenantId.tenantId())
                             && !isServiceFunction(hPortId)) {
-                        sfcHostSet.add(h);
+                        if (!h.equals(host)) {
+                            return false;
+                        }
                     }
                 }
             }
         }
-        if (sfcHostSet.size() == 1 && sfcHostSet.contains(host)) {
-            return true;
-        }
-        return false;
+        return true;
     }
 
     /**
@@ -543,12 +523,9 @@
      * @param deviceId the device identifier
      * @param ovsMap the instance of map to store device identifier
      */
-    private void addDeviceIdOfOvsMap(TenantId tenantId,
+    private void addDeviceIdToSpecificMap(TenantId tenantId,
                                      DeviceId deviceId,
                                      EventuallyConsistentMap<TenantId, Set<DeviceId>> ovsMap) {
-        checkNotNull(tenantId, TENANTID_NOT_NULL);
-        checkNotNull(deviceId, DEVICEID_NOT_NULL);
-        checkNotNull(ovsMap, OVSMAP_NOT_NULL);
         if (ovsMap.containsKey(tenantId)) {
             Set<DeviceId> deviceIdSet = ovsMap.get(tenantId);
             deviceIdSet.add(deviceId);
@@ -567,14 +544,11 @@
      * @param deviceId the device identifier
      * @param ovsMap the instance of map to store device identifier
      */
-    private void removeDeviceIdOfOvsMap(TenantId tenantId,
+    private void removeDeviceIdToSpecificMap(TenantId tenantId,
                                         DeviceId deviceId,
                                         EventuallyConsistentMap<TenantId, Set<DeviceId>> ovsMap) {
-        checkNotNull(tenantId, TENANTID_NOT_NULL);
-        checkNotNull(deviceId, DEVICEID_NOT_NULL);
-        checkNotNull(ovsMap, OVSMAP_NOT_NULL);
         Set<DeviceId> deviceIdSet = ovsMap.get(tenantId);
-        if (deviceIdSet.size() > 1) {
+        if (deviceIdSet != null && deviceIdSet.size() > 1) {
             deviceIdSet.remove(deviceId);
             ovsMap.put(tenantId, deviceIdSet);
         } else {
diff --git a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
index f7e97d5..982217e 100644
--- a/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
+++ b/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FloatingIpWebResource.java
@@ -70,6 +70,7 @@
             .getLogger(FloatingIpWebResource.class);
     public static final String CREATE_FAIL = "Floating IP is failed to create!";
     public static final String UPDATE_FAIL = "Floating IP is failed to update!";
+    public static final String DELETE_FAIL = "Floating IP is failed to delete!";
     public static final String GET_FAIL = "Floating IP is failed to get!";
     public static final String NOT_EXIST = "Floating IP does not exist!";
     public static final String DELETE_SUCCESS = "Floating IP delete success!";
@@ -157,7 +158,11 @@
         try {
             FloatingIpId floatingIpId = FloatingIpId.of(id);
             Set<FloatingIpId> floatingIpIds = Sets.newHashSet(floatingIpId);
-            get(FloatingIpService.class).removeFloatingIps(floatingIpIds);
+            Boolean result = nullIsNotFound(get(FloatingIpService.class)
+                    .removeFloatingIps(floatingIpIds), DELETE_FAIL);
+            if (!result) {
+                return Response.status(CONFLICT).entity(DELETE_FAIL).build();
+            }
             return Response.status(NO_CONTENT).entity(DELETE_SUCCESS).build();
         } catch (Exception e) {
             return Response.status(NOT_FOUND).entity(e.getMessage()).build();