Make OVSDB Listener IP configurable 64/72864/1
authorVishal Thapar <vthapar@redhat.com>
Tue, 12 Jun 2018 06:31:38 +0000 (12:01 +0530)
committerVishal Thapar <vthapar@redhat.com>
Tue, 12 Jun 2018 08:25:30 +0000 (13:55 +0530)
JIRA: OVSDB-464
Change-Id: I11a852f497eab655e17d4a2c230f319282424283
Signed-off-by: Vishal Thapar <vthapar@redhat.com>
library/impl/src/main/java/org/opendaylight/ovsdb/lib/OvsdbConnection.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java
library/impl/src/main/resources/initial/library.cfg
library/impl/src/main/resources/org/opendaylight/blueprint/library.xml

index 517c499f53453fa9fec45da72998e6e16143029a..b323a014047508007ae3b38c60f1f98d23c1300b 100644 (file)
@@ -59,7 +59,8 @@ public interface OvsdbConnection {
     /**
      * Method to start ovsdb server for passive connection with SSL.
      */
-    boolean startOvsdbManagerWithSsl(int ovsdbListenPort,
+    boolean startOvsdbManagerWithSsl(String ovsdbListenIp,
+                                     int ovsdbListenPort,
                                      ICertificateManager certificateManagerSrv,
                                      String[] protocols, String[] cipherSuites);
 
@@ -67,7 +68,8 @@ public interface OvsdbConnection {
      * Method to restart ovsdb server for passive connection with SSL and user
      * specifies protocols and cipher suites.
      */
-    boolean restartOvsdbManagerWithSsl(int ovsdbListenPort,
+    boolean restartOvsdbManagerWithSsl(String ovsdbListenIp,
+                                       int ovsdbListenPort,
                                        ICertificateManager certificateManagerSrv,
                                        String[] protocols,
                                        String[] cipherSuites);
index 18c65e4c8d5978b53ae4ece76ff214397eead321..375f2f863a7ab3215623ee75ce89a1ffd872811a 100644 (file)
@@ -114,6 +114,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private static volatile Channel serverChannel;
 
     private final AtomicBoolean singletonCreated = new AtomicBoolean(false);
+    private volatile String listenerIp = "0.0.0.0";
     private volatile int listenerPort = 6640;
 
     public static OvsdbConnection getService() {
@@ -241,9 +242,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(() -> ovsdbManager(ovsdbListenerPort)).start();
+            new Thread(() -> ovsdbManager(ovsdbListenerIp, ovsdbListenerPort)).start();
             return true;
         } else {
             return false;
@@ -256,11 +258,11 @@ 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,
+    public synchronized boolean startOvsdbManagerWithSsl(final String ovsdbListenIp, final int ovsdbListenPort,
                                                          final ICertificateManager certificateManagerSrv,
                                                          String[] protocols, String[] cipherSuites) {
         if (!singletonCreated.getAndSet(true)) {
-            new Thread(() -> ovsdbManagerWithSsl(ovsdbListenPort,
+            new Thread(() -> ovsdbManagerWithSsl(ovsdbListenIp, ovsdbListenPort,
                     certificateManagerSrv, protocols, cipherSuites)).start();
             return true;
         } else {
@@ -269,7 +271,8 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     }
 
     @Override
-    public synchronized boolean restartOvsdbManagerWithSsl(final int ovsdbListenPort,
+    public synchronized boolean restartOvsdbManagerWithSsl(final String ovsdbListenIp,
+        final int ovsdbListenPort,
         final ICertificateManager certificateManagerSrv,
         final String[] protocols,
         final String[] cipherSuites) {
@@ -278,7 +281,8 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
             LOG.info("Server channel closed");
         }
         serverChannel = null;
-        return startOvsdbManagerWithSsl(ovsdbListenPort, certificateManagerSrv, protocols, cipherSuites);
+        return startOvsdbManagerWithSsl(ovsdbListenIp, ovsdbListenPort,
+            certificateManagerSrv, protocols, cipherSuites);
     }
 
     /**
@@ -287,16 +291,16 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
      * 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 static 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, certManagerSrv.getTlsProtocols(),
+            ovsdbManagerWithSsl(ip, port, certManagerSrv, certManagerSrv.getTlsProtocols(),
                     certManagerSrv.getCipherSuites());
         } else {
-            ovsdbManagerWithSsl(port, null /* SslContext */, null, null);
+            ovsdbManagerWithSsl(ip, port, null /* SslContext */, null, null);
         }
     }
 
@@ -304,7 +308,7 @@ 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 ICertificateManager certificateManagerSrv,
+    private static void ovsdbManagerWithSsl(String ip, int port, final ICertificateManager certificateManagerSrv,
                                             final String[] protocols, final String[] cipherSuites) {
         EventLoopGroup bossGroup = new NioEventLoopGroup();
         EventLoopGroup workerGroup = new NioEventLoopGroup();
@@ -355,7 +359,7 @@ 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.
@@ -576,6 +580,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;
index f8033b5a0f6614ce414ded4e4022d918a0c7ce18..fce90c040ed6b0c95f6d0594a9cc0dd324e7a9f6 100644 (file)
@@ -2,6 +2,10 @@
 #                               Boot Time Configuration                                     *
 #                   Config knob changes will require controller restart                     *
 #********************************************************************************************
+#Ovsdb plugin's (OVS, HwVtep) support both active and passive connections. OVSDB library by
+#default listens on all IPs for switch initiated connections. Use following config
+#knob for changing this default IP.
+ovsdb-listener-ip = 0.0.0.0
 
 #Ovsdb plugin's (OVS, HwVtep) support both active and passive connections. OVSDB library by
 #default listens on port 6640 for switch initiated connection. Please use following config
index 8ec994caa457e97f02ff820691a497054ddee632..d23f2148639f53f09e04b09610bf6b5c42c7426a 100644 (file)
@@ -10,6 +10,7 @@
     or config property is commented out. This will be overridden if user
     specify the property in library.cfg file-->
     <cm:default-properties>
+      <cm:property name="ovsdb-listener-ip" value="0.0.0.0"/>
       <cm:property name="ovsdb-listener-port" value="6640"/>
       <cm:property name="ovsdb-rpc-task-timeout" value="1000"/>
       <cm:property name="use-ssl" value="false"/>
@@ -22,6 +23,7 @@
         odl:type="default-certificate-manager"/>
 
   <bean id="library" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
+    <property name="ovsdbListenerIp" value="${ovsdb-listener-ip}"/>
     <property name="ovsdbListenerPort" value="${ovsdb-listener-port}"/>
     <property name="ovsdbRpcTaskTimeout" value="${ovsdb-rpc-task-timeout}"/>
     <property name="useSsl" value="${use-ssl}"/>