import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.HwvtepGlobalRemoveCommand;
import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.TransactionInvoker;
import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.OvsdbConnection;
import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
-import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
import org.opendaylight.ovsdb.lib.operations.Operation;
import org.opendaylight.ovsdb.lib.operations.OperationResult;
import org.opendaylight.ovsdb.lib.operations.Select;
private final HwvtepOperGlobalListener hwvtepOperGlobalListener;
private final Map<InstanceIdentifier<Node>, TransactionHistory> controllerTxHistory = new ConcurrentHashMap<>();
private final Map<InstanceIdentifier<Node>, TransactionHistory> deviceUpdateHistory = new ConcurrentHashMap<>();
+ private final OvsdbConnection ovsdbConnectionService;
public HwvtepConnectionManager(DataBroker db, TransactionInvoker txInvoker,
- EntityOwnershipService entityOwnershipService) {
+ EntityOwnershipService entityOwnershipService, OvsdbConnection ovsdbConnectionService) {
this.db = db;
this.txInvoker = txInvoker;
this.entityOwnershipService = entityOwnershipService;
this.hwvtepDeviceEntityOwnershipListener = new HwvtepDeviceEntityOwnershipListener(this,entityOwnershipService);
this.reconciliationManager = new ReconciliationManager(db);
this.hwvtepOperGlobalListener = new HwvtepOperGlobalListener(db, this);
+ this.ovsdbConnectionService = ovsdbConnectionService;
}
@Override
HwvtepGlobalAugmentation hwvtepGlobal) throws UnknownHostException, ConnectException {
LOG.info("Connecting to {}", HwvtepSouthboundUtil.connectionInfoToString(hwvtepGlobal.getConnectionInfo()));
InetAddress ip = HwvtepSouthboundMapper.createInetAddress(hwvtepGlobal.getConnectionInfo().getRemoteIp());
- OvsdbClient client = OvsdbConnectionService.getService()
+ OvsdbClient client = ovsdbConnectionService
.connect(ip, hwvtepGlobal.getConnectionInfo().getRemotePort().getValue());
if (client != null) {
putInstanceIdentifier(hwvtepGlobal.getConnectionInfo(), iid.firstIdentifierOf(Node.class));
public void init() {
LOG.info("HwvtepSouthboundProvider Session Initiated");
txInvoker = new TransactionInvokerImpl(dataBroker);
- cm = new HwvtepConnectionManager(dataBroker, txInvoker, entityOwnershipService);
+ cm = new HwvtepConnectionManager(dataBroker, txInvoker, entityOwnershipService, ovsdbConnection);
hwvtepDTListener = new HwvtepDataChangeListener(dataBroker, cm);
hwvtepReconciliationManager = new HwvtepReconciliationManager(dataBroker, cm);
//Register listener for entityOnwership changes
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.AdaptiveRecvByteBufAllocator;
* 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.
*/
-@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionService.class);
private static final int IDLE_READER_TIMEOUT = 30;
private static final StalePassiveConnectionService STALE_PASSIVE_CONNECTION_SERVICE =
new StalePassiveConnectionService(EXECUTOR_SERVICE);
- private static final OvsdbConnection CONNECTION_SERVICE = new OvsdbConnectionService();
-
private static final Set<OvsdbConnectionListener> CONNECTION_LISTENERS = ConcurrentHashMap.newKeySet();
private static final Map<OvsdbClient, Channel> CONNECTIONS = new ConcurrentHashMap<>();
- private static volatile boolean useSSL = false;
- private static volatile ICertificateManager certManagerSrv;
+ private volatile boolean useSSL = false;
+ private volatile ICertificateManager certManagerSrv;
- private static volatile int jsonRpcDecoderMaxFrameLength = 100000;
- private static volatile Channel serverChannel;
+ 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;
- public static OvsdbConnection getService() {
- return CONNECTION_SERVICE;
- }
-
/**
* If the SSL flag is enabled, the method internally will establish TLS communication using the default
* ODL certificateManager SSLContext and attributes.
new StringEncoder(CharsetUtil.UTF_8),
new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0),
new ReadTimeoutHandler(READ_TIMEOUT),
- new ExceptionHandler());
+ new ExceptionHandler(OvsdbConnectionService.this));
}
});
* 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(String ip, 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.");
* OVSDB Passive listening thread that uses Netty ServerBootstrap to open
* passive connection with Ssl and handle channel callbacks.
*/
- private static void ovsdbManagerWithSsl(String ip, int port, final ICertificateManager certificateManagerSrv,
+ private void ovsdbManagerWithSsl(String ip, int port, final ICertificateManager certificateManagerSrv,
final String[] protocols, final String[] cipherSuites) {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
new StringEncoder(CharsetUtil.UTF_8),
new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0),
new ReadTimeoutHandler(READ_TIMEOUT),
- new ExceptionHandler());
+ new ExceptionHandler(OvsdbConnectionService.this));
handleNewPassiveConnection(channel);
}
import io.netty.handler.timeout.ReadTimeoutException;
import java.io.IOException;
import org.opendaylight.ovsdb.lib.OvsdbClient;
+import org.opendaylight.ovsdb.lib.OvsdbConnection;
import org.opendaylight.ovsdb.lib.error.InvalidEncodingException;
-import org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(ExceptionHandler.class);
+ private final OvsdbConnection ovsdbConnectionService;
+
+ public ExceptionHandler(OvsdbConnection ovsdbConnectionService) {
+ this.ovsdbConnectionService = ovsdbConnectionService;
+ }
+
@Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (ctx.channel().isActive()) {
LOG.error("Exception occurred while processing connection pipeline", cause);
if ((cause instanceof InvalidEncodingException)
}
@Override
- public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
+ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof IdleStateEvent) {
LOG.debug("Get idle state event");
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.READER_IDLE) {
LOG.debug("Reader idle state. Send echo message to peer");
//Send echo message to peer
- OvsdbClient client =
- OvsdbConnectionService.getService().getClient(ctx.channel());
+ OvsdbClient client = ovsdbConnectionService.getClient(ctx.channel());
client.echo();
}
}
interface="org.opendaylight.aaa.cert.api.ICertificateManager"
odl:type="default-certificate-manager"/>
- <bean id="library" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
+ <!-- Notify OvsdbConnectionService with any change in the config properties value-->
+ <bean id="ovsdbConnectionService" class="org.opendaylight.ovsdb.lib.impl.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="jsonRpcDecoderMaxFrameLength" value="${json-rpc-decoder-max-frame-length}"/>
</bean>
- <!-- Notify OvsdbConnectionService with any change in the config properties value-->
- <bean id="ovsdbConnectionService" class="org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService">
- <cm:managed-properties persistent-id="org.opendaylight.ovsdb.library"
- update-strategy="component-managed"
- update-method="updateConfigParameter"/>
- <property name="certificatManager" ref="aaaCertificateManager"/>
- </bean>
-
<service ref="ovsdbConnectionService" interface="org.opendaylight.ovsdb.lib.OvsdbConnection"
odl:type="default" />
when(SouthboundMapper.createInetAddress(any(IpAddress.class))).thenReturn(ip);
PowerMockito.mockStatic(OvsdbConnectionService.class);
- when(OvsdbConnectionService.getService()).thenReturn(ovsdbConnection);
+// when(OvsdbConnectionService.getService()).thenReturn(ovsdbConnection);
PortNumber port = mock(PortNumber.class);
when(connectionInfo.getRemotePort()).thenReturn(port);
when(port.getValue()).thenReturn(8080);