Bug 7836 - Make OVSDB southbound plugin listener port configurable 47/52147/1
authorAnil Vishnoi <vishnoianil@gmail.com>
Wed, 22 Feb 2017 07:40:26 +0000 (23:40 -0800)
committerAnil Vishnoi <vishnoianil@gmail.com>
Wed, 22 Feb 2017 07:44:26 +0000 (23:44 -0800)
Change-Id: Ic59cb1af40de46e150bb09ec584f362755ed7e62
Signed-off-by: Anil Vishnoi <vishnoianil@gmail.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java
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
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/SouthboundProvider.java

index 79f8a83f007a33988061195e9bb3ad6284c28134..0a2660d0c5a0e4ea22d775d3bf1da7e1e8cc78d7 100644 (file)
@@ -94,7 +94,7 @@ public class HwvtepSouthboundProvider implements AutoCloseable {
                 EntityOwnershipState ownershipState = ownershipStateOpt.get();
                 if (ownershipState.hasOwner() && !ownershipState.isOwner()) {
                     ovsdbConnection.registerConnectionListener(cm);
-                    ovsdbConnection.startOvsdbManager(HwvtepSouthboundConstants.DEFAULT_OVSDB_PORT);
+                    ovsdbConnection.startOvsdbManager();
                 }
             }
         } catch (CandidateAlreadyRegisteredException e) {
@@ -155,7 +155,7 @@ public class HwvtepSouthboundProvider implements AutoCloseable {
             LOG.info("*This* instance of HWVTEP southbound provider is set as a SLAVE instance");
         }
         ovsdbConnection.registerConnectionListener(cm);
-        ovsdbConnection.startOvsdbManager(HwvtepSouthboundConstants.DEFAULT_OVSDB_PORT);
+        ovsdbConnection.startOvsdbManager();
     }
 
     private class HwvtepsbPluginInstanceEntityOwnershipListener implements EntityOwnershipListener {
index adbe99bbf6ce6a089abb0d1b9fe54fc52f2af7fa..fed57bf3e7fc78ffe336980df10cf64c17c91ed1 100644 (file)
@@ -55,7 +55,7 @@ public interface OvsdbConnection {
     /**
      * Method to start ovsdb server for passive connection.
      */
-    boolean startOvsdbManager(final int ovsdbListenPort);
+    boolean startOvsdbManager();
 
     /**
      * Method to start ovsdb server for passive connection with SSL.
index 47462f0e115ade5e42acbd471489e999ec9ff787..8ca188a5a9d48aae6112ce4174d1447956d8c963 100644 (file)
@@ -48,6 +48,7 @@ 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.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
@@ -99,7 +100,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private static Set<OvsdbConnectionListener> connectionListeners = Sets.newHashSet();
     private static Map<OvsdbClient, Channel> connections = new ConcurrentHashMap<>();
     private static OvsdbConnection connectionService;
-    private static volatile boolean singletonCreated = false;
+    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";
@@ -108,6 +109,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     private static ICertificateManager certManagerSrv = null;
 
     private static int jsonRpcDecoderMaxFrameLength = 100000;
+    private static int listenerPort = 6640;
 
     private static final StalePassiveConnectionService STALE_PASSIVE_CONNECTION_SERVICE =
             new StalePassiveConnectionService(executorService);
@@ -240,16 +242,16 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
      * be overridden using the ovsdb.listenPort system property.
      */
     @Override
-    public synchronized boolean startOvsdbManager(final int ovsdbListenPort) {
-        if (!singletonCreated) {
+    public synchronized boolean startOvsdbManager() {
+        final int ovsdbListenerPort = this.listenerPort;
+        if (!singletonCreated.getAndSet(true)) {
             LOG.info("startOvsdbManager: Starting");
             new Thread() {
                 @Override
                 public void run() {
-                    ovsdbManager(ovsdbListenPort);
+                    ovsdbManager(ovsdbListenerPort);
                 }
             }.start();
-            singletonCreated = true;
             return true;
         } else {
             return false;
@@ -264,14 +266,13 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
     @Override
     public synchronized boolean startOvsdbManagerWithSsl(final int ovsdbListenPort,
                                      final SSLContext sslContext, String[] protocols, String[] cipherSuites) {
-        if (!singletonCreated) {
+        if (!singletonCreated.getAndSet(true)) {
             new Thread() {
                 @Override
                 public void run() {
                     ovsdbManagerWithSsl(ovsdbListenPort, sslContext, protocols, cipherSuites);
                 }
             }.start();
-            singletonCreated = true;
             return true;
         } else {
             return false;
@@ -578,6 +579,11 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
         LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
     }
 
+    public void setOvsdbListenerPort(int portNumber) {
+        LOG.info("OVSDB port for listening connection is set to : {}", portNumber);
+        listenerPort = portNumber;
+    }
+
     public void updateConfigParameter(Map<String, Object> configParameters) {
         LOG.debug("Config parameters received : {}", configParameters.entrySet());
         if (configParameters != null && !configParameters.isEmpty()) {
index 784c38be8bb0e307a00e604d5fddd6ab12710947..f8033b5a0f6614ce414ded4e4022d918a0c7ce18 100644 (file)
@@ -3,6 +3,11 @@
 #                   Config knob changes will require controller restart                     *
 #********************************************************************************************
 
+#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
+#knob for changing this default port.
+ovsdb-listener-port = 6640
+
 #This flag will be enforced across all the connection's (passive and active) if set to true
 use-ssl = false
 
index 365aafa1282504001dcde9315899341d0df51e0e..8ec994caa457e97f02ff820691a497054ddee632 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-port" value="6640"/>
       <cm:property name="ovsdb-rpc-task-timeout" value="1000"/>
       <cm:property name="use-ssl" value="false"/>
       <cm:property name="json-rpc-decoder-max-frame-length" value="100000"/>
@@ -21,6 +22,7 @@
         odl:type="default-certificate-manager"/>
 
   <bean id="library" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
+    <property name="ovsdbListenerPort" value="${ovsdb-listener-port}"/>
     <property name="ovsdbRpcTaskTimeout" value="${ovsdb-rpc-task-timeout}"/>
     <property name="useSsl" value="${use-ssl}"/>
     <property name="certificatManager" ref="aaaCertificateManager"/>
index d4a342884210094cbcef1b056034e0180c247b31..e2b30876151eaed40d885c1f1844c9852032e903 100644 (file)
@@ -93,7 +93,7 @@ public class SouthboundProvider implements AutoCloseable {
                 EntityOwnershipState ownershipState = ownershipStateOpt.get();
                 if (ownershipState.hasOwner() && !ownershipState.isOwner()) {
                     ovsdbConnection.registerConnectionListener(cm);
-                    ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
+                    ovsdbConnection.startOvsdbManager();
                     LOG.info("*This* instance of OVSDB southbound provider is set as a SLAVE instance");
                 }
             }
@@ -143,7 +143,7 @@ public class SouthboundProvider implements AutoCloseable {
             LOG.info("*This* instance of OVSDB southbound provider is set as a SLAVE instance");
         }
         ovsdbConnection.registerConnectionListener(cm);
-        ovsdbConnection.startOvsdbManager(SouthboundConstants.DEFAULT_OVSDB_PORT);
+        ovsdbConnection.startOvsdbManager();
     }
 
     private class SouthboundPluginInstanceEntityOwnershipListener implements EntityOwnershipListener {