import org.opendaylight.ovsdb.lib.jsonrpc.ExceptionHandler;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcDecoder;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcEndpoint;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* and a Singleton object in a non-OSGi environment.
*/
@Singleton
+@Component(service = OvsdbConnection.class, configurationPid = "org.opendaylight.ovsdb.library")
+@Designate(ocd = OvsdbConnectionService.Configuration.class)
public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
+ @ObjectClassDefinition
+ public @interface Configuration {
+ @AttributeDefinition
+ String ovsdb$_$listener$_$ip() default DEFAULT_LISTENER_IP;
+ @AttributeDefinition(min = "1", max = "65535")
+ int ovsdb$_$listener$_$port() default DEFAULT_LISTENER_PORT;
+ @AttributeDefinition
+ int ovsdb$_$rpc$_$task$_$timeout() default DEFAULT_RPC_TASK_TIMEOUT;
+ @AttributeDefinition
+ boolean use$_$ssl() default false;
+ @AttributeDefinition
+ int json$_$rpc$_$decoder$_$max$_$frame$_$length() default DEFAULT_JSON_RPC_DECODER_MAX_FRAME_LENGTH;
+ }
+
private class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {
@Override
public void initChannel(final SocketChannel channel) throws Exception {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionService.class);
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 final int RETRY_PERIOD = 100; // retry after 100 milliseconds
+ private static final String DEFAULT_LISTENER_IP = "0.0.0.0";
+ private static final int DEFAULT_LISTENER_PORT = 6640;
+ private static final int DEFAULT_RPC_TASK_TIMEOUT = 1000;
+ private static final int DEFAULT_JSON_RPC_DECODER_MAX_FRAME_LENGTH = 100000;
private static final StringEncoder UTF8_ENCODER = new StringEncoder(StandardCharsets.UTF_8);
return null;
});
+ // FIXME: these should not be static
private static final Set<OvsdbConnectionListener> CONNECTION_LISTENERS = ConcurrentHashMap.newKeySet();
private static final Map<OvsdbClient, Channel> CONNECTIONS = new ConcurrentHashMap<>();
private final NettyBootstrapFactory bootstrapFactory;
-
- private volatile boolean useSSL = false;
private final ICertificateManager certManagerSrv;
- private volatile int jsonRpcDecoderMaxFrameLength = 100000;
- private volatile Channel serverChannel;
+ private final boolean useSSL;
+ private final int jsonRpcDecoderMaxFrameLength;
private final AtomicBoolean singletonCreated = new AtomicBoolean(false);
- private volatile String listenerIp = "0.0.0.0";
- private volatile int listenerPort = 6640;
+ private volatile Channel serverChannel;
+
+ private final String listenerIp;
+ private final int listenerPort;
@Inject
public OvsdbConnectionService(final NettyBootstrapFactory bootstrapFactory,
final ICertificateManager certManagerSrv) {
+ this(bootstrapFactory, certManagerSrv, DEFAULT_LISTENER_IP, DEFAULT_LISTENER_PORT, DEFAULT_RPC_TASK_TIMEOUT,
+ false, DEFAULT_JSON_RPC_DECODER_MAX_FRAME_LENGTH);
+ }
+
+ @Activate
+ public OvsdbConnectionService(@Reference final NettyBootstrapFactory bootstrapFactory,
+ @Reference(target = "(type=default-certificate-manager)") final ICertificateManager certManagerSrv,
+ final Configuration configuration) {
+ this(bootstrapFactory, certManagerSrv, configuration.ovsdb$_$listener$_$ip(),
+ configuration.ovsdb$_$listener$_$port(), configuration.ovsdb$_$rpc$_$task$_$timeout(),
+ configuration.use$_$ssl(), configuration.json$_$rpc$_$decoder$_$max$_$frame$_$length());
+ }
+
+ public OvsdbConnectionService(final NettyBootstrapFactory bootstrapFactory,
+ final ICertificateManager certManagerSrv, final String listenerIp, final int listenerPort,
+ final int ovsdbRpcTaskTimeout, final boolean useSSL, final int jsonRpcDecoderMaxFrameLength) {
this.bootstrapFactory = requireNonNull(bootstrapFactory);
- this.certManagerSrv = certManagerSrv;
+ this.certManagerSrv = requireNonNull(certManagerSrv);
+ this.listenerIp = requireNonNull(listenerIp);
+ this.listenerPort = listenerPort;
+ this.useSSL = useSSL;
+ this.jsonRpcDecoderMaxFrameLength = jsonRpcDecoderMaxFrameLength;
+
+ // FIXME: static state!
+ JsonRpcEndpoint.setReaperInterval(ovsdbRpcTaskTimeout);
+ LOG.info("OVSDB IP for listening connection is set to : {}", listenerIp);
+ LOG.info("OVSDB port for listening connection is set to : {}", listenerPort);
+ LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
}
/**
* OVSDB Passive listening thread that uses Netty ServerBootstrap to open
* passive connection with Ssl and handle channel callbacks.
*/
- @SuppressWarnings("checkstyle:IllegalCatch")
private void ovsdbManagerWithSsl(final String ip, final int port, final ServerChannelInitializer channelHandler) {
bootstrapFactory.newServer()
.handler(new LoggingHandler(LogLevel.INFO))
});
}
}
-
- public void setOvsdbRpcTaskTimeout(final int timeout) {
- JsonRpcEndpoint.setReaperInterval(timeout);
- }
-
- /**
- * Set useSSL flag.
- *
- * @param flag boolean for using ssl
- */
- public void setUseSsl(final boolean flag) {
- useSSL = flag;
- }
-
- /**
- * 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
- * the configuration file. This option is only configured at the boot time of the controller. Any
- * change at the run time will have no impact.
- * @param maxFrameLength Max frame length (default : 100000)
- */
- public void setJsonRpcDecoderMaxFrameLength(final int maxFrameLength) {
- jsonRpcDecoderMaxFrameLength = maxFrameLength;
- LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
- }
-
- public void setOvsdbListenerIp(final String ip) {
- LOG.info("OVSDB IP for listening connection is set to : {}", ip);
- listenerIp = ip;
- }
-
- public void setOvsdbListenerPort(final int portNumber) {
- LOG.info("OVSDB port for listening connection is set to : {}", portNumber);
- listenerPort = portNumber;
- }
-
- public void updateConfigParameter(final Map<String, Object> configParameters) {
- if (configParameters != null && !configParameters.isEmpty()) {
- LOG.debug("Config parameters received : {}", configParameters.entrySet());
- for (Map.Entry<String, Object> paramEntry : configParameters.entrySet()) {
- if (paramEntry.getKey().equalsIgnoreCase(OVSDB_RPC_TASK_TIMEOUT_PARAM)) {
- setOvsdbRpcTaskTimeout(Integer.parseInt((String)paramEntry.getValue()));
- } else if (paramEntry.getKey().equalsIgnoreCase(USE_SSL)) {
- useSSL = Boolean.parseBoolean(paramEntry.getValue().toString());
- }
- }
- }
- }
}
+++ /dev/null
-/*
- * 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.ovsdb.lib.impl;
-
-import java.util.Map;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class OvsdbConnectionServiceConfigurator {
-
- private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionServiceConfigurator.class);
-
- private static final String JSON_RPC_DECODER_MAX_FRAME_LENGTH_PARAM = "json-rpc-decoder-max-frame-length";
- private static final String USE_SSL_PARAM = "use-ssl";
- private static final String OVSDB_RPC_TASK_TIMEOUT_PARAM = "ovsdb-rpc-task-timeout";
- private static final String OVSDB_LISTENER_PORT_PARAM = "ovsdb-listener-port";
- private final OvsdbConnectionService ovsdbconnection;
-
- public OvsdbConnectionServiceConfigurator(OvsdbConnectionService ovsdbconnection) {
- this.ovsdbconnection = ovsdbconnection;
- }
-
- public void setOvsdbRpcTaskTimeout(int timeout) {
- ovsdbconnection.setOvsdbRpcTaskTimeout(timeout);
- }
-
- public void setUseSsl(boolean flag) {
- ovsdbconnection.setUseSsl(flag);
- }
-
- public void setJsonRpcDecoderMaxFrameLength(int maxFrameLength) {
- ovsdbconnection.setJsonRpcDecoderMaxFrameLength(maxFrameLength);
- }
-
- public void setOvsdbListenerIp(String ip) {
- ovsdbconnection.setOvsdbListenerIp(ip);
- }
-
- public void setOvsdbListenerPort(int portNumber) {
- ovsdbconnection.setOvsdbListenerPort(portNumber);
- }
-
- public void updateConfigParameter(Map<String, Object> configParameters) {
- if (configParameters != null && !configParameters.isEmpty()) {
- LOG.debug("Config parameters received : {}", configParameters.entrySet());
- for (Map.Entry<String, Object> paramEntry : configParameters.entrySet()) {
- if (paramEntry.getKey().equalsIgnoreCase(OVSDB_RPC_TASK_TIMEOUT_PARAM)) {
- ovsdbconnection.setOvsdbRpcTaskTimeout(Integer.parseInt((String) paramEntry.getValue()));
- } else if (paramEntry.getKey().equalsIgnoreCase(USE_SSL_PARAM)) {
- ovsdbconnection.setUseSsl(Boolean.parseBoolean(paramEntry.getValue().toString()));
- }
-
- }
- }
- }
-}
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">
-
- <!-- Read default values at startup and inject to OvsdbConnectionService-->
- <cm:property-placeholder persistent-id="org.opendaylight.ovsdb.library" update-strategy="none">
- <!-- Setting default values, in case library.cfg file is not present
- 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"/>
- <cm:property name="json-rpc-decoder-max-frame-length" value="100000"/>
- </cm:default-properties>
- </cm:property-placeholder>
-
- <!-- Notify OvsdbConnectionService with any change in the config properties value-->
- <bean id="ovsdbConnectionServiceConfigurator" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionServiceConfigurator">
- <argument ref="ovsdbConnectionService"/>
- <cm:managed-properties persistent-id="org.opendaylight.ovsdb.library"
- update-strategy="component-managed"
- update-method="updateConfigParameter"/>
- <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}"/>
- <property name="jsonRpcDecoderMaxFrameLength" value="${json-rpc-decoder-max-frame-length}"/>
- </bean>
-
- <reference id="certificateManager" interface="org.opendaylight.aaa.cert.api.ICertificateManager"
- filter="type=default-certificate-manager"/>
- <reference id="nettyBootstrapFactory" interface="org.opendaylight.ovsdb.lib.impl.NettyBootstrapFactory"/>
-
- <bean id="ovsdbConnectionService" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
- <argument ref="nettyBootstrapFactory"/>
- <argument ref="certificateManager"/>
- </bean>
-
- <service ref="ovsdbConnectionService" interface="org.opendaylight.ovsdb.lib.OvsdbConnection"/>
-</blueprint>
-#********************************************************************************************
-# 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.
#Set Json Rpc decoder max frame length value. If the OVSDB node contains large configurations
#that can cause connection related issue while reading the configuration from the OVSDB node
#database. Increasing the max frame lenge helps resolve the issue. Please see following bug
-#report for more details ( https://bugs.opendaylight.org/show_bug.cgi?id=2732 &
-#https://bugs.opendaylight.org/show_bug.cgi?id=2487). Default value set to 100000.
+#report for more details ( https://jira.opendaylight.org/browse/OVSDB-140 &
+#https://jira.opendaylight.org/browse/OVSDB-134). Default value set to 100000.
json-rpc-decoder-max-frame-length = 100000
-
-#********************************************************************************************
-# Run Time Configuration *
-# Config knob changes doesn't require controller resart *
-#********************************************************************************************
#Timeout value (in millisecond) after which OVSDB rpc task will be cancelled.Default value is
#set to 1000ms, please uncomment and override the value if requires.Changing the value don't
#require controller restart.
ovsdb-rpc-task-timeout = 1000
-