Merge "Avoid calling the String constructor explicitly"
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / impl / BridgeConfigurationManagerImpl.java
index 08fd8d5c8303bde3850aca5278aee655c735c1a1..d59f53601734280d497669f225369496a3d40f84 100644 (file)
@@ -1,13 +1,14 @@
 /*
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
+
 package org.opendaylight.ovsdb.openstack.netvirt.impl;
 
-import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronNetwork;
 import org.opendaylight.ovsdb.openstack.netvirt.ConfigInterface;
 import org.opendaylight.ovsdb.openstack.netvirt.NetworkHandler;
 import org.opendaylight.ovsdb.openstack.netvirt.api.BridgeConfigurationManager;
@@ -18,8 +19,12 @@ import org.opendaylight.ovsdb.openstack.netvirt.api.OvsdbTables;
 import org.opendaylight.ovsdb.openstack.netvirt.api.Southbound;
 import org.opendaylight.ovsdb.utils.config.ConfigProperties;
 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeNetdev;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.DatapathTypeSystem;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagerEntry;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 
 import com.google.common.base.Preconditions;
@@ -28,11 +33,11 @@ import com.google.common.collect.Lists;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,7 +48,7 @@ import org.slf4j.LoggerFactory;
  * @author Sam Hague (shague@redhat.com)
  */
 public class BridgeConfigurationManagerImpl implements BridgeConfigurationManager, ConfigInterface {
-    private static final Logger LOGGER = LoggerFactory.getLogger(BridgeConfigurationManagerImpl.class);
+    private static final Logger LOG = LoggerFactory.getLogger(BridgeConfigurationManagerImpl.class);
 
     // The implementation for each of these services is resolved by the OSGi Service Manager
     private volatile ConfigurationService configurationService;
@@ -85,7 +90,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     public boolean isNodeTunnelReady(Node bridgeNode, Node ovsdbNode) {
         Preconditions.checkNotNull(configurationService);
         if (!southbound.isBridgeOnOvsdbNode(ovsdbNode, configurationService.getIntegrationBridgeName())) {
-            LOGGER.trace("isNodeTunnelReady: node: {}, {} missing",
+            LOG.trace("isNodeTunnelReady: node: {}, {} missing",
                     bridgeNode, configurationService.getIntegrationBridgeName());
             return false;
         }
@@ -99,14 +104,14 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
 
         final String brInt = configurationService.getIntegrationBridgeName();
         if (!southbound.isBridgeOnOvsdbNode(ovsdbNode, brInt)) {
-            LOGGER.trace("isNodeVlanReady: node: {}, {} missing", bridgeNode, brInt);
+            LOG.trace("isNodeVlanReady: node: {}, {} missing", bridgeNode, brInt);
             return false;
         }
 
         /* Check if physical device is added to br-int. */
         String phyNetName = getPhysicalInterfaceName(ovsdbNode, network.getProviderPhysicalNetwork());
         if (!isPortOnBridge(bridgeNode, phyNetName)) {
-            LOGGER.trace("isNodeVlanReady: node: {}, eth missing", bridgeNode);
+            LOG.trace("isNodeVlanReady: node: {}, eth missing", bridgeNode);
             return false;
         }
 
@@ -125,21 +130,9 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
             Preconditions.checkNotNull(portNameExt);
 
             if (southbound.isBridgeOnOvsdbNode(ovsdbNode, brExt)) {
-                //this would look better if used a method like isNetworkPatchCreated()
-                if (isPortOnBridge(bridgeNode, portNameInt)) {
-                    Node extBridgeNode = southbound.readBridgeNode(ovsdbNode, brExt);
-                    if (isPortOnBridge(extBridgeNode, portNameExt)) {
-                        ready = true;
-                    } else {
-                        LOGGER.trace("isNodeL3Ready: node: {}, {} missing",
-                                bridgeNode, portNameExt);
-                    }
-                } else {
-                    LOGGER.trace("isNodeL3Ready: node: {}, {} missing",
-                            bridgeNode, portNameInt);
-                }
+                ready = isNetworkPatchCreated(bridgeNode, southbound.readBridgeNode(ovsdbNode, brExt));
             } else {
-                LOGGER.trace("isNodeL3Ready: node: {}, {} missing",
+                LOG.trace("isNodeL3Ready: node: {}, {} missing",
                         bridgeNode, brExt);
             }
         } else {
@@ -155,7 +148,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
         try {
             createIntegrationBridge(ovsdbNode);
         } catch (Exception e) {
-            LOGGER.error("Error creating Integration Bridge on {}", ovsdbNode, e);
+            LOG.error("Error creating Integration Bridge on {}", ovsdbNode, e);
             return;
         }
 
@@ -164,7 +157,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
                 createExternalBridge(ovsdbNode);
             }
         } catch (Exception e) {
-            LOGGER.error("Error creating External Bridge on {}", ovsdbNode, e);
+            LOG.error("Error creating External Bridge on {}", ovsdbNode, e);
             return;
         }
         // this node is an ovsdb node so it doesn't have a bridge
@@ -182,7 +175,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
         Node ovsdbNode = southbound.readOvsdbNode(bridgeNode);
         if (ovsdbNode == null) {
             //this should never happen
-            LOGGER.error("createLocalNetwork could not find ovsdbNode from bridge node " + bridgeNode);
+            LOG.error("createLocalNetwork could not find ovsdbNode from bridge node " + bridgeNode);
             return false;
         }
         if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
@@ -190,7 +183,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
                 try {
                     isCreated = createBridges(bridgeNode, ovsdbNode, network);
                 } catch (Exception e) {
-                    LOGGER.error("Error creating internal vlan net network " + bridgeNode, e);
+                    LOG.error("Error creating internal vlan net network " + bridgeNode, e);
                 }
             } else {
                 isCreated = true;
@@ -201,7 +194,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
                 try {
                     isCreated = createBridges(bridgeNode, ovsdbNode, network);
                 } catch (Exception e) {
-                    LOGGER.error("Error creating internal vxlan/gre net network " + bridgeNode, e);
+                    LOG.error("Error creating internal vxlan/gre net network " + bridgeNode, e);
                 }
             } else {
                 isCreated = true;
@@ -210,6 +203,34 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
         return isCreated;
     }
 
+
+
+    @Override
+    public String getExternalInterfaceName (Node node, String extNetwork) {
+        String phyIf = null;
+        String providerMaps = southbound.getOtherConfig(node, OvsdbTables.OPENVSWITCH,
+                configurationService.getProviderMappingsKey());
+        if (providerMaps != null) {
+            for (String map : providerMaps.split(",")) {
+                String[] pair = map.split(":");
+                if (pair[0].equals(extNetwork)) {
+                    phyIf = pair[1];
+                    break;
+                }
+            }
+        }
+        if (phyIf == null) {
+            LOG.error("External interface not found for Node: {}, Network {}",
+                    node, extNetwork);
+        }
+        else {
+            LOG.info("External interface found for Node: {}, Network {} is {}",node,extNetwork,phyIf);
+        }
+        return phyIf;
+    }
+
+
+
     @Override
     public String getPhysicalInterfaceName (Node node, String physicalNetwork) {
         String phyIf = null;
@@ -230,8 +251,8 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
         }
 
         if (phyIf == null) {
-            LOGGER.error("Physical interface not found for Node: {}, Network {}",
-                         node, physicalNetwork);
+            LOG.error("Physical interface not found for Node: {}, Network {}",
+                    node, physicalNetwork);
         }
 
         return phyIf;
@@ -240,7 +261,6 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     @Override
     public List<String> getAllPhysicalInterfaceNames(Node node) {
         List<String> phyIfName = Lists.newArrayList();
-        String phyIf = null;
         String providerMaps = southbound.getOtherConfig(node, OvsdbTables.OPENVSWITCH,
                 configurationService.getProviderMappingsKey());
         if (providerMaps == null) {
@@ -260,7 +280,7 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Returns true if a patch port exists between the Integration Bridge and Network Bridge
      */
-    private boolean isNetworkPatchCreated(Node node, Node intBridge, Node netBridge) {
+    private boolean isNetworkPatchCreated(Node intBridge, Node netBridge) {
         Preconditions.checkNotNull(configurationService);
 
         boolean isPatchCreated = false;
@@ -279,21 +299,21 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Creates the Integration Bridge
      */
-    private boolean createIntegrationBridge(Node ovsdbNode) throws Exception {
+    private boolean createIntegrationBridge(Node ovsdbNode) {
         Preconditions.checkNotNull(configurationService);
 
         if (!addBridge(ovsdbNode, configurationService.getIntegrationBridgeName())) {
-            LOGGER.debug("Integration Bridge Creation failed");
+            LOG.debug("Integration Bridge Creation failed");
             return false;
         }
         return true;
     }
 
-    private boolean createExternalBridge(Node ovsdbNode) throws Exception {
+    private boolean createExternalBridge(Node ovsdbNode) {
         Preconditions.checkNotNull(configurationService);
 
         if (!addBridge(ovsdbNode, configurationService.getExternalBridgeName())) {
-            LOGGER.debug("External Bridge Creation failed");
+            LOG.debug("External Bridge Creation failed");
             return false;
         }
         return true;
@@ -354,22 +374,22 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
                 Interface br-int
                     type: internal
      */
-    private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) throws Exception {
+    private boolean createBridges(Node bridgeNode, Node ovsdbNode, NeutronNetwork network) {
         Preconditions.checkNotNull(configurationService);
         Preconditions.checkNotNull(networkingProviderManager);
 
-        LOGGER.debug("createBridges: node: {}, network type: {}", bridgeNode, network.getProviderNetworkType());
+        LOG.debug("createBridges: node: {}, network type: {}", bridgeNode, network.getProviderNetworkType());
 
         final String brInt = configurationService.getIntegrationBridgeName();
         if (! createIntegrationBridge(ovsdbNode)) {
-            LOGGER.debug("{} Bridge creation failed", brInt);
+            LOG.debug("{} Bridge creation failed", brInt);
             return false;
         }
 
         if (configurationService.isL3ForwardingEnabled()) {
             final String brExt = configurationService.getExternalBridgeName();
             if (! createExternalBridge(ovsdbNode)) {
-                LOGGER.error("{} Bridge creation failed", brExt);
+                LOG.error("{} Bridge creation failed", brExt);
                 return false;
             }
 
@@ -380,48 +400,55 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
             Preconditions.checkNotNull(portNameExt);
 
             if (!addPatchPort(bridgeNode, brInt, portNameInt, portNameExt)) {
-                LOGGER.error("Add Port {} to Bridge {} failed", portNameInt, brInt);
+                LOG.error("Add Port {} to Bridge {} failed", portNameInt, brInt);
                 return false;
             }
             Node extBridgeNode = southbound.readBridgeNode(ovsdbNode, brExt);
             Preconditions.checkNotNull(extBridgeNode);
             if (!addPatchPort(extBridgeNode, brExt, portNameExt, portNameInt)) {
-                LOGGER.error("Add Port {} to Bridge {} failed", portNameExt, brExt);
+                LOG.error("Add Port {} to Bridge {} failed", portNameExt, brExt);
                 return false;
             }
+            String extNetName = getExternalInterfaceName(extBridgeNode, brExt);
+            if ( extNetName != null) {
+                if (!addPortToBridge(extBridgeNode, brExt, extNetName)) {
+                    LOG.error("Add External Port {} to Bridge {} failed", extNetName, brExt);
+                    return false;
+                }
+            LOG.info("Add External Port {} to Ext Bridge {} success", extNetName, brExt);
+            }
         }
-
         /* For vlan network types add physical port to br-int. */
         if (network.getProviderNetworkType().equalsIgnoreCase(NetworkHandler.NETWORK_TYPE_VLAN)) {
             String phyNetName = this.getPhysicalInterfaceName(bridgeNode, network.getProviderPhysicalNetwork());
             if (!addPortToBridge(bridgeNode, brInt, phyNetName)) {
-                LOGGER.debug("Add Port {} to Bridge {} failed", phyNetName, brInt);
+                LOG.debug("Add Port {} to Bridge {} failed", phyNetName, brInt);
                 return false;
             }
         }
 
-        LOGGER.debug("createBridges: node: {}, status: success", bridgeNode);
+        LOG.info("createBridges: node: {}, status: success", bridgeNode);
         return true;
     }
 
     /**
      * Add a Port to a Bridge
      */
-    private boolean addPortToBridge (Node node, String bridgeName, String portName) throws Exception {
+    private boolean addPortToBridge (Node node, String bridgeName, String portName) {
         boolean rv = true;
 
         if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
             rv = southbound.addTerminationPoint(node, bridgeName, portName, null);
 
             if (rv) {
-                LOGGER.info("addPortToBridge: node: {}, bridge: {}, portname: {} status: success",
+                LOG.info("addPortToBridge: node: {}, bridge: {}, portname: {} status: success",
                         node.getNodeId().getValue(), bridgeName, portName);
             } else {
-                LOGGER.error("addPortToBridge: node: {}, bridge: {}, portname: {} status: FAILED",
+                LOG.error("addPortToBridge: node: {}, bridge: {}, portname: {} status: FAILED",
                         node.getNodeId().getValue(), bridgeName, portName);
             }
         } else {
-            LOGGER.trace("addPortToBridge: node: {}, bridge: {}, portname: {} status: not_needed",
+            LOG.trace("addPortToBridge: node: {}, bridge: {}, portname: {} status: not_needed",
                     node.getNodeId().getValue(), bridgeName, portName);
         }
 
@@ -431,21 +458,21 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Add a Patch Port to a Bridge
      */
-    private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) throws Exception {
+    private boolean addPatchPort (Node node, String bridgeName, String portName, String peerPortName) {
         boolean rv = true;
 
         if (southbound.extractTerminationPointAugmentation(node, portName) == null) {
             rv = southbound.addPatchTerminationPoint(node, bridgeName, portName, peerPortName);
 
             if (rv) {
-                LOGGER.info("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: success",
+                LOG.info("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: success",
                         node.getNodeId().getValue(), bridgeName, portName, peerPortName);
             } else {
-                LOGGER.error("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: FAILED",
+                LOG.error("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: FAILED",
                         node.getNodeId().getValue(), bridgeName, portName, peerPortName);
             }
         } else {
-            LOGGER.trace("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: not_needed",
+            LOG.trace("addPatchPort: node: {}, bridge: {}, portname: {} peer: {} status: not_needed",
                     node.getNodeId().getValue(), bridgeName, portName, peerPortName);
         }
 
@@ -455,38 +482,39 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     /**
      * Add Bridge to a Node
      */
-    private boolean addBridge(Node ovsdbNode, String bridgeName) throws Exception {
+    private boolean addBridge(Node ovsdbNode, String bridgeName) {
         boolean rv = true;
-        if (!southbound.isBridgeOnOvsdbNode(ovsdbNode, bridgeName)) {
-            rv = southbound.addBridge(ovsdbNode, bridgeName, getControllerTarget(ovsdbNode));
+        if ((!southbound.isBridgeOnOvsdbNode(ovsdbNode, bridgeName)) ||
+                (southbound.getBridgeFromConfig(ovsdbNode, bridgeName) == null)) {
+            Class<? extends DatapathTypeBase> dpType = null;
+            if (configurationService.isUserSpaceEnabled()) {
+                dpType = DatapathTypeNetdev.class;
+            }
+            rv = southbound.addBridge(ovsdbNode, bridgeName, getControllersFromOvsdbNode(ovsdbNode), dpType);
         }
         return rv;
     }
 
     private String getControllerIPAddress() {
-        InetAddress controllerIP = null;
-
         String addressString = ConfigProperties.getProperty(this.getClass(), "ovsdb.controller.address");
         if (addressString != null) {
             try {
-                controllerIP = InetAddress.getByName(addressString);
-                if (controllerIP != null) {
+                if (InetAddress.getByName(addressString) != null) {
                     return addressString;
                 }
             } catch (UnknownHostException e) {
-                LOGGER.error("Host {} is invalid", addressString);
+                LOG.error("Host {} is invalid", addressString);
             }
         }
 
         addressString = ConfigProperties.getProperty(this.getClass(), "of.address");
         if (addressString != null) {
             try {
-                controllerIP = InetAddress.getByName(addressString);
-                if (controllerIP != null) {
+                if (InetAddress.getByName(addressString) != null) {
                     return addressString;
                 }
             } catch (UnknownHostException e) {
-                LOGGER.error("Host {} is invalid", addressString);
+                LOG.error("Host {} is invalid", addressString);
             }
         }
 
@@ -494,67 +522,93 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
     }
 
     private short getControllerOFPort() {
-        Short defaultOpenFlowPort = Constants.OPENFLOW_PORT;
-        Short openFlowPort = defaultOpenFlowPort;
+        short openFlowPort = Constants.OPENFLOW_PORT;
         String portString = ConfigProperties.getProperty(this.getClass(), "of.listenPort");
         if (portString != null) {
             try {
-                openFlowPort = Short.decode(portString).shortValue();
+                openFlowPort = Short.parseShort(portString);
             } catch (NumberFormatException e) {
-                LOGGER.warn("Invalid port:{}, use default({})", portString,
+                LOG.warn("Invalid port:{}, use default({})", portString,
                         openFlowPort);
             }
         }
         return openFlowPort;
     }
 
-    private String getControllerTarget(Node node) {
-        String setControllerStr = null;
-        String controllerIpStr = null;
-        short openflowPort = Constants.OPENFLOW_PORT;
-        //Look at user configuration.
-        //TODO: In case we move to config subsystem to expose these user facing parameter,
-        // we will have to modify this code.
-
-        controllerIpStr = getControllerIPAddress();
+    private List<String> getControllersFromOvsdbNode(Node node) {
+        List<String> controllersStr = new ArrayList<>();
 
-        if(controllerIpStr == null){
-            // Check if ovsdb node has connection info
+        String controllerIpStr = getControllerIPAddress();
+        if (controllerIpStr != null) {
+            // If codepath makes it here, the ip address to be used was explicitly provided.
+            // Being so, also fetch openflowPort provided via ConfigProperties.
+            controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
+                    + ":" + controllerIpStr + ":" + getControllerOFPort());
+        } else {
+            // Check if ovsdb node has manager entries
             OvsdbNodeAugmentation ovsdbNodeAugmentation = southbound.extractOvsdbNode(node);
             if (ovsdbNodeAugmentation != null) {
-                ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
-                if(connectionInfo != null && connectionInfo.getLocalIp() != null) {
-                    controllerIpStr = new String(connectionInfo.getLocalIp().getValue());
-                }else{
-                    LOGGER.warn("Ovsdb Node does not contains connection info : {}",node);
+                List<ManagerEntry> managerEntries = ovsdbNodeAugmentation.getManagerEntry();
+                if (managerEntries != null && !managerEntries.isEmpty()) {
+                    for (ManagerEntry managerEntry : managerEntries) {
+                        if (managerEntry == null || managerEntry.getTarget() == null) {
+                            continue;
+                        }
+                        String[] tokens = managerEntry.getTarget().getValue().split(":");
+                        if (tokens.length == 3 && tokens[0].equalsIgnoreCase("tcp")) {
+                            controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
+                                    + ":" + tokens[1] + ":" + getControllerOFPort());
+                        } else if (tokens[0].equalsIgnoreCase("ptcp")) {
+                            ConnectionInfo connectionInfo = ovsdbNodeAugmentation.getConnectionInfo();
+                            if (connectionInfo != null && connectionInfo.getLocalIp() != null) {
+                                controllerIpStr = String.valueOf(connectionInfo.getLocalIp().getValue());
+                                controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
+                                        + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
+                            } else {
+                                LOG.warn("Ovsdb Node does not contain connection info: {}", node);
+                            }
+                        } else {
+                            LOG.trace("Skipping manager entry {} for node {}",
+                                    managerEntry.getTarget(), node.getNodeId().getValue());
+                        }
+                    }
+                } else {
+                    LOG.warn("Ovsdb Node does not contain manager entries : {}", node);
                 }
             }
-        }else {
-            openflowPort = getControllerOFPort();
         }
 
-        if(controllerIpStr == null) {
-            // Neither user provided ip nor ovsdb node has controller ip, Lets use local machine ip address
-            LOGGER.debug("Use local machine ip address as a OpenFlow Controller ip address");
+        if (controllersStr.isEmpty()) {
+            // Neither user provided ip nor ovsdb node has manager entries. Lets use local machine ip address.
+            LOG.debug("Use local machine ip address as a OpenFlow Controller ip address");
             controllerIpStr = getLocalControllerHostIpAddress();
+            if (controllerIpStr != null) {
+                controllersStr.add(Constants.OPENFLOW_CONNECTION_PROTOCOL
+                        + ":" + controllerIpStr + ":" + Constants.OPENFLOW_PORT);
+            }
         }
-        if(controllerIpStr != null){
-            LOGGER.debug("Targe OpenFlow Controller found : {}",controllerIpStr);
-            setControllerStr = Constants.OPENFLOW_CONNECTION_PROTOCOL + ":" + controllerIpStr + ":" + openflowPort;
-        }else {
-            LOGGER.warn("Failed to determine OpenFlow controller ip address");
+
+        if (controllersStr.isEmpty()) {
+            LOG.warn("Failed to determine OpenFlow controller ip address");
+        } else if (LOG.isDebugEnabled()) {
+            controllerIpStr = "";
+            for (String currControllerIpStr : controllersStr) {
+                controllerIpStr += " " + currControllerIpStr;
+            }
+            LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
         }
-        return setControllerStr;
+
+        return controllersStr;
     }
 
     private String getLocalControllerHostIpAddress() {
         String ipaddress = null;
         try{
             for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();ifaces.hasMoreElements();){
-                NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
+                NetworkInterface iface = ifaces.nextElement();
 
                 for (Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements();) {
-                    InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
+                    InetAddress inetAddr = inetAddrs.nextElement();
                     if (!inetAddr.isLoopbackAddress() && inetAddr.isSiteLocalAddress()) {
                         ipaddress = inetAddr.getHostAddress();
                         break;
@@ -562,13 +616,13 @@ public class BridgeConfigurationManagerImpl implements BridgeConfigurationManage
                 }
             }
         }catch (Exception e){
-            LOGGER.warn("Exception while fetching local host ip address ",e);
+            LOG.warn("Exception while fetching local host ip address ", e);
         }
         return ipaddress;
     }
 
     @Override
-    public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
+    public void setDependencies(ServiceReference serviceReference) {
         configurationService =
                 (ConfigurationService) ServiceHelper.getGlobalInstance(ConfigurationService.class, this);
         networkingProviderManager =