Do not use Foo.toString() when logging
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / impl / OvsdbConnectionService.java
index fe473b9b3899c4fdd2c1a4f46bc8143f4e1bb872..f4455a076983946241c673eadfac8952b9720aeb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
+ * Copyright © 2014, 2017 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,
@@ -11,7 +11,6 @@ package org.opendaylight.ovsdb.lib.impl;
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -41,19 +40,23 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-import javax.annotation.Nullable;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
 import javax.net.ssl.SSLPeerUnverifiedException;
+import org.apache.aries.blueprint.annotation.service.Reference;
+import org.apache.aries.blueprint.annotation.service.Service;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.aaa.cert.api.ICertificateManager;
 import org.opendaylight.ovsdb.lib.OvsdbClient;
 import org.opendaylight.ovsdb.lib.OvsdbConnection;
@@ -84,44 +87,45 @@ import org.slf4j.LoggerFactory;
  * environment. Hence a single instance of the service will be active (via Service Registry in OSGi)
  * and a Singleton object in a non-OSGi environment.
  */
+@Singleton
+@Service(classes = OvsdbConnection.class)
 public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionService.class);
-
-    private static ThreadFactory passiveConnectionThreadFactory = new ThreadFactoryBuilder()
-            .setNameFormat("OVSDBPassiveConnServ-%d").build();
-    private static ScheduledExecutorService executorService
-            = Executors.newScheduledThreadPool(10, passiveConnectionThreadFactory);
-
-    private static ThreadFactory connectionNotifierThreadFactory = new ThreadFactoryBuilder()
-            .setNameFormat("OVSDBConnNotifSer-%d").build();
-    private static ExecutorService connectionNotifierService
-            = Executors.newCachedThreadPool(connectionNotifierThreadFactory);
-
-    private static Set<OvsdbConnectionListener> connectionListeners = Sets.newHashSet();
-    private static Map<OvsdbClient, Channel> connections = new ConcurrentHashMap<>();
-    private static OvsdbConnection connectionService;
-    private static AtomicBoolean singletonCreated = new AtomicBoolean(false);
     private static final int IDLE_READER_TIMEOUT = 30;
     private static final int READ_TIMEOUT = 180;
     private static final String OVSDB_RPC_TASK_TIMEOUT_PARAM = "ovsdb-rpc-task-timeout";
     private static final String USE_SSL = "use-ssl";
-    private static boolean useSSL = false;
-    private static ICertificateManager certManagerSrv = null;
+    private static final int RETRY_PERIOD = 100; // retry after 100 milliseconds
+
+    private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newScheduledThreadPool(10,
+            new ThreadFactoryBuilder().setNameFormat("OVSDBPassiveConnServ-%d").build());
 
-    private static int jsonRpcDecoderMaxFrameLength = 100000;
-    private static int listenerPort = 6640;
+    private static final ExecutorService CONNECTION_NOTIFIER_SERVICE = Executors
+            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("OVSDBConnNotifSer-%d").build());
 
     private static final StalePassiveConnectionService STALE_PASSIVE_CONNECTION_SERVICE =
-            new StalePassiveConnectionService(executorService);
+            new StalePassiveConnectionService((client) -> {
+                notifyListenerForPassiveConnection(client);
+                return null;
+            });
 
-    private static int retryPeriod = 100; // retry after 100 milliseconds
+    private static final Set<OvsdbConnectionListener> CONNECTION_LISTENERS = ConcurrentHashMap.newKeySet();
+    private static final Map<OvsdbClient, Channel> CONNECTIONS = new ConcurrentHashMap<>();
 
+    private volatile boolean useSSL = false;
+    private final ICertificateManager certManagerSrv;
 
-    public static OvsdbConnection getService() {
-        if (connectionService == null) {
-            connectionService = new OvsdbConnectionService();
-        }
-        return connectionService;
+    private volatile int jsonRpcDecoderMaxFrameLength = 100000;
+    private volatile Channel serverChannel;
+
+    private final AtomicBoolean singletonCreated = new AtomicBoolean(false);
+    private volatile String listenerIp = "0.0.0.0";
+    private volatile int listenerPort = 6640;
+
+    @Inject
+    public OvsdbConnectionService(@Reference(filter = "type=default-certificate-manager")
+                                              ICertificateManager certManagerSrv) {
+        this.certManagerSrv = certManagerSrv;
     }
 
     /**
@@ -135,15 +139,16 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                 LOG.error("Certificate Manager service is not available cannot establish the SSL communication.");
                 return null;
             }
-            return connectWithSsl(address, port, certManagerSrv.getServerContext());
+            return connectWithSsl(address, port, certManagerSrv);
         } else {
             return connectWithSsl(address, port, null /* SslContext */);
         }
     }
 
     @Override
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public OvsdbClient connectWithSsl(final InetAddress address, final int port,
-                               final SSLContext sslContext) {
+                               final ICertificateManager certificateManagerSrv) {
         try {
             Bootstrap bootstrap = new Bootstrap();
             bootstrap.group(new NioEventLoopGroup());
@@ -154,7 +159,8 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
             bootstrap.handler(new ChannelInitializer<SocketChannel>() {
                 @Override
                 public void initChannel(SocketChannel channel) throws Exception {
-                    if (sslContext != null) {
+                    if (certificateManagerSrv != null && certificateManagerSrv.getServerContext() != null) {
+                        SSLContext sslContext = certificateManagerSrv.getServerContext();
                         /* First add ssl handler if ssl context is given */
                         SSLEngine engine =
                             sslContext.createSSLEngine(address.toString(), port);
@@ -167,7 +173,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                             new StringEncoder(CharsetUtil.UTF_8),
                             new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0),
                             new ReadTimeoutHandler(READ_TIMEOUT),
-                            new ExceptionHandler());
+                            new ExceptionHandler(OvsdbConnectionService.this));
                 }
             });
 
@@ -176,6 +182,10 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
             return getChannelClient(channel, ConnectionType.ACTIVE, SocketConnectionType.SSL);
         } catch (InterruptedException e) {
             LOG.warn("Failed to connect {}:{}", address, port, e);
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding to address {}, port {}", address, port, throwable);
+            throw throwable;
         }
         return null;
     }
@@ -185,23 +195,26 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         if (client == null) {
             return;
         }
-        Channel channel = connections.get(client);
+        Channel channel = CONNECTIONS.get(client);
         if (channel != null) {
+            //It's an explicit disconnect from user, so no need to notify back
+            //to user about the disconnect.
+            client.setConnectionPublished(false);
             channel.disconnect();
         }
-        connections.remove(client);
+        CONNECTIONS.remove(client);
     }
 
     @Override
     public void registerConnectionListener(OvsdbConnectionListener listener) {
         LOG.info("registerConnectionListener: registering {}", listener.getClass().getSimpleName());
-        connectionListeners.add(listener);
+        CONNECTION_LISTENERS.add(listener);
         notifyAlreadyExistingConnectionsToListener(listener);
     }
 
     private void notifyAlreadyExistingConnectionsToListener(final OvsdbConnectionListener listener) {
         for (final OvsdbClient client : getConnections()) {
-            connectionNotifierService.submit(() -> {
+            CONNECTION_NOTIFIER_SERVICE.execute(() -> {
                 LOG.trace("Connection {} notified to listener {}", client.getConnectionInfo(), listener);
                 listener.connected(client);
             });
@@ -210,7 +223,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
 
     @Override
     public void unregisterConnectionListener(OvsdbConnectionListener listener) {
-        connectionListeners.remove(listener);
+        CONNECTION_LISTENERS.remove(listener);
     }
 
     private static OvsdbClient getChannelClient(Channel channel, ConnectionType type,
@@ -227,7 +240,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         OvsdbRPC rpc = factory.getClient(channel, OvsdbRPC.class);
         OvsdbClientImpl client = new OvsdbClientImpl(rpc, channel, type, socketConnType);
         client.setConnectionPublished(true);
-        connections.put(client, channel);
+        CONNECTIONS.put(client, channel);
         ChannelFuture closeFuture = channel.closeFuture();
         closeFuture.addListener(new ChannelConnectionHandler(client));
         return client;
@@ -241,14 +254,10 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     @Override
     public synchronized boolean startOvsdbManager() {
         final int ovsdbListenerPort = this.listenerPort;
+        final String ovsdbListenerIp = this.listenerIp;
         if (!singletonCreated.getAndSet(true)) {
             LOG.info("startOvsdbManager: Starting");
-            new Thread() {
-                @Override
-                public void run() {
-                    ovsdbManager(ovsdbListenerPort);
-                }
-            }.start();
+            new Thread(() -> ovsdbManager(ovsdbListenerIp, ovsdbListenerPort)).start();
             return true;
         } else {
             return false;
@@ -261,37 +270,49 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
      * 6640 which can be overridden using the ovsdb.listenPort system property.
      */
     @Override
-    public synchronized boolean startOvsdbManagerWithSsl(final int ovsdbListenPort,
-                                     final SSLContext sslContext, String[] protocols, String[] cipherSuites) {
+    public synchronized boolean startOvsdbManagerWithSsl(final String ovsdbListenIp, final int ovsdbListenPort,
+                                                         final ICertificateManager certificateManagerSrv,
+                                                         String[] protocols, String[] cipherSuites) {
         if (!singletonCreated.getAndSet(true)) {
-            new Thread() {
-                @Override
-                public void run() {
-                    ovsdbManagerWithSsl(ovsdbListenPort, sslContext, protocols, cipherSuites);
-                }
-            }.start();
+            new Thread(() -> ovsdbManagerWithSsl(ovsdbListenIp, ovsdbListenPort,
+                    certificateManagerSrv, protocols, cipherSuites)).start();
             return true;
         } else {
             return false;
         }
     }
 
+    @Override
+    public synchronized boolean restartOvsdbManagerWithSsl(final String ovsdbListenIp,
+        final int ovsdbListenPort,
+        final ICertificateManager certificateManagerSrv,
+        final String[] protocols,
+        final String[] cipherSuites) {
+        if (singletonCreated.getAndSet(false) && serverChannel != null) {
+            serverChannel.close();
+            LOG.info("Server channel closed");
+        }
+        serverChannel = null;
+        return startOvsdbManagerWithSsl(ovsdbListenIp, ovsdbListenPort,
+            certificateManagerSrv, protocols, cipherSuites);
+    }
+
     /**
      * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
      * passive connection handle channel callbacks.
      * If the SSL flag is enabled, the method internally will establish TLS communication using the default
      * ODL certificateManager SSLContext and attributes.
      */
-    private static void ovsdbManager(int port) {
+    private void ovsdbManager(String ip, int port) {
         if (useSSL) {
             if (certManagerSrv == null) {
                 LOG.error("Certificate Manager service is not available cannot establish the SSL communication.");
                 return;
             }
-            ovsdbManagerWithSsl(port, certManagerSrv.getServerContext(), certManagerSrv.getTlsProtocols(),
+            ovsdbManagerWithSsl(ip, port, certManagerSrv, certManagerSrv.getTlsProtocols(),
                     certManagerSrv.getCipherSuites());
         } else {
-            ovsdbManagerWithSsl(port, null /* SslContext */, null, null);
+            ovsdbManagerWithSsl(ip, port, null /* SslContext */, null, null);
         }
     }
 
@@ -299,8 +320,9 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
      * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
      * passive connection with Ssl and handle channel callbacks.
      */
-    private static void ovsdbManagerWithSsl(int port, final SSLContext sslContext, final String[] protocols,
-            final String[] cipherSuites) {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void ovsdbManagerWithSsl(String ip, int port, final ICertificateManager certificateManagerSrv,
+                                            final String[] protocols, final String[] cipherSuites) {
         EventLoopGroup bossGroup = new NioEventLoopGroup();
         EventLoopGroup workerGroup = new NioEventLoopGroup();
         try {
@@ -313,8 +335,9 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                         @Override
                         public void initChannel(SocketChannel channel) throws Exception {
                             LOG.debug("New Passive channel created : {}", channel);
-                            if (sslContext != null) {
+                            if (certificateManagerSrv != null && certificateManagerSrv.getServerContext() != null) {
                                 /* Add SSL handler first if SSL context is provided */
+                                SSLContext sslContext = certificateManagerSrv.getServerContext();
                                 SSLEngine engine = sslContext.createSSLEngine();
                                 engine.setUseClientMode(false); // work in a server mode
                                 engine.setNeedClientAuth(true); // need client authentication
@@ -340,7 +363,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                                  new StringEncoder(CharsetUtil.UTF_8),
                                  new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0),
                                  new ReadTimeoutHandler(READ_TIMEOUT),
-                                 new ExceptionHandler());
+                                 new ExceptionHandler(OvsdbConnectionService.this));
 
                             handleNewPassiveConnection(channel);
                         }
@@ -349,12 +372,17 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
             serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR,
                     new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
             // Start the server.
-            ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
+            ChannelFuture channelFuture = serverBootstrap.bind(ip, port).sync();
             Channel serverListenChannel = channelFuture.channel();
+            serverChannel = serverListenChannel;
             // Wait until the server socket is closed.
             serverListenChannel.closeFuture().sync();
         } catch (InterruptedException e) {
             LOG.error("Thread interrupted", e);
+        } catch (Throwable throwable) {
+            // sync() re-throws exceptions declared as Throwable, so the compiler doesn't see them
+            LOG.error("Error while binding to address {}, port {}", ip, port, throwable);
+            throw throwable;
         } finally {
             // Shut down all event loops to terminate all threads.
             bossGroup.shutdownGracefully();
@@ -382,7 +410,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                 LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo());
                 client.disconnect();
             }
-        }, connectionNotifierService);
+        }, CONNECTION_NOTIFIER_SERVICE);
     }
 
     private static void handleNewPassiveConnection(final Channel channel) {
@@ -393,14 +421,16 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
         if (sslHandler != null) {
             class HandleNewPassiveSslRunner implements Runnable {
-                public SslHandler sslHandler;
-                public final Channel channel;
-                private int retryTimes;
-
-                HandleNewPassiveSslRunner(Channel channel, SslHandler sslHandler) {
-                    this.channel = channel;
-                    this.sslHandler = sslHandler;
-                    this.retryTimes = 3;
+                private int retryTimes = 3;
+
+                private void retry() {
+                    if (retryTimes > 0) {
+                        EXECUTOR_SERVICE.schedule(this,  RETRY_PERIOD, TimeUnit.MILLISECONDS);
+                    } else {
+                        LOG.debug("channel closed {}", channel);
+                        channel.disconnect();
+                    }
+                    retryTimes--;
                 }
 
                 @Override
@@ -414,7 +444,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                                     .equals("SSL_NULL_WITH_NULL_NULL")) {
                                 // Not begin handshake yet. Retry later.
                                 LOG.debug("handshake not begin yet {}", status);
-                                executorService.schedule(this, retryPeriod, TimeUnit.MILLISECONDS);
+                                retry();
                             } else {
                               //Check if peer is trusted before notifying listeners
                                 try {
@@ -426,7 +456,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                                 } catch (SSLPeerUnverifiedException e) {
                                     //Trust manager is still checking peer certificate. Retry later
                                     LOG.debug("Peer certifiacte is not verified yet {}", status);
-                                    executorService.schedule(this, retryPeriod, TimeUnit.MILLISECONDS);
+                                    retry();
                                 }
                             }
                             break;
@@ -435,7 +465,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                         case NEED_TASK:
                             //Handshake still ongoing. Retry later.
                             LOG.debug("handshake not done yet {}", status);
-                            executorService.schedule(this,  retryPeriod, TimeUnit.MILLISECONDS);
+                            retry();
                             break;
 
                         case NEED_WRAP:
@@ -443,6 +473,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                                     .equals("SSL_NULL_WITH_NULL_NULL")) {
                                 /* peer not authenticated. No need to notify listener in this case. */
                                 LOG.error("Ssl handshake fail. channel {}", channel);
+                                channel.disconnect();
                             } else {
                                 /*
                                  * peer is authenticated. Give some time to wait for completion.
@@ -454,12 +485,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                                  * since client will reconnect later.
                                  */
                                 LOG.debug("handshake not done yet {}", status);
-                                if (retryTimes > 0) {
-                                    executorService.schedule(this,  retryPeriod, TimeUnit.MILLISECONDS);
-                                } else {
-                                    LOG.debug("channel closed {}", channel);
-                                }
-                                retryTimes--;
+                                retry();
                             }
                             break;
 
@@ -469,10 +495,10 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
                 }
             }
 
-            executorService.schedule(new HandleNewPassiveSslRunner(channel, sslHandler),
-                    retryPeriod, TimeUnit.MILLISECONDS);
+            EXECUTOR_SERVICE.schedule(new HandleNewPassiveSslRunner(),
+                    RETRY_PERIOD, TimeUnit.MILLISECONDS);
         } else {
-            executorService.execute(() -> {
+            EXECUTOR_SERVICE.execute(() -> {
                 OvsdbClient client = getChannelClient(channel, ConnectionType.PASSIVE,
                     SocketConnectionType.NON_SSL);
                 handleNewPassiveConnection(client);
@@ -481,10 +507,10 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     }
 
     public static void channelClosed(final OvsdbClient client) {
-        LOG.info("Connection closed {}", client.getConnectionInfo().toString());
-        connections.remove(client);
+        LOG.info("Connection closed {}", client.getConnectionInfo());
+        CONNECTIONS.remove(client);
         if (client.isConnectionPublished()) {
-            for (OvsdbConnectionListener listener : connectionListeners) {
+            for (OvsdbConnectionListener listener : CONNECTION_LISTENERS) {
                 listener.disconnected(client);
             }
         }
@@ -493,7 +519,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
 
     @Override
     public Collection<OvsdbClient> getConnections() {
-        return connections.keySet();
+        return CONNECTIONS.keySet();
     }
 
     @Override
@@ -504,8 +530,9 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
 
     @Override
     public OvsdbClient getClient(Channel channel) {
-        for (OvsdbClient client : connections.keySet()) {
-            Channel ctx = connections.get(client);
+        for (Entry<OvsdbClient, Channel> entry : CONNECTIONS.entrySet()) {
+            OvsdbClient client = entry.getKey();
+            Channel ctx = entry.getValue();
             if (ctx.equals(channel)) {
                 return client;
             }
@@ -515,7 +542,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
 
     private static List<OvsdbClient> getPassiveClientsFromSameNode(OvsdbClient ovsdbClient) {
         List<OvsdbClient> passiveClients = new ArrayList<>();
-        for (OvsdbClient client : connections.keySet()) {
+        for (OvsdbClient client : CONNECTIONS.keySet()) {
             if (!client.equals(ovsdbClient)
                     && client.getConnectionInfo().getRemoteAddress()
                             .equals(ovsdbClient.getConnectionInfo().getRemoteAddress())
@@ -528,8 +555,8 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
 
     public static void notifyListenerForPassiveConnection(final OvsdbClient client) {
         client.setConnectionPublished(true);
-        for (final OvsdbConnectionListener listener : connectionListeners) {
-            connectionNotifierService.submit(() -> {
+        for (final OvsdbConnectionListener listener : CONNECTION_LISTENERS) {
+            CONNECTION_NOTIFIER_SERVICE.execute(() -> {
                 LOG.trace("Connection {} notified to listener {}", client.getConnectionInfo(), listener);
                 listener.connected(client);
             });
@@ -549,15 +576,6 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         useSSL = flag;
     }
 
-    /**
-     * Set default Certificate manager service.
-     *
-     * @param certificateManagerSrv reference
-     */
-    public void setCertificatManager(ICertificateManager certificateManagerSrv) {
-        certManagerSrv = certificateManagerSrv;
-    }
-
     /**
      * Blueprint property setter method. Blueprint call this method and set the value of json rpc decoder
      * max frame length to the value configured for config option (json-rpc-decoder-max-frame-length) in
@@ -570,6 +588,11 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
     }
 
+    public void setOvsdbListenerIp(String ip) {
+        LOG.info("OVSDB IP for listening connection is set to : {}", ip);
+        listenerIp = ip;
+    }
+
     public void setOvsdbListenerPort(int portNumber) {
         LOG.info("OVSDB port for listening connection is set to : {}", portNumber);
         listenerPort = portNumber;