Inject the certificate manager in the constructor
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / impl / OvsdbConnectionService.java
1 /*
2  * Copyright © 2014, 2017 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.lib.impl;
10
11 import com.fasterxml.jackson.annotation.JsonInclude.Include;
12 import com.fasterxml.jackson.databind.DeserializationFeature;
13 import com.fasterxml.jackson.databind.ObjectMapper;
14 import com.google.common.util.concurrent.FutureCallback;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.ThreadFactoryBuilder;
18 import io.netty.bootstrap.Bootstrap;
19 import io.netty.bootstrap.ServerBootstrap;
20 import io.netty.channel.AdaptiveRecvByteBufAllocator;
21 import io.netty.channel.Channel;
22 import io.netty.channel.ChannelFuture;
23 import io.netty.channel.ChannelInitializer;
24 import io.netty.channel.ChannelOption;
25 import io.netty.channel.EventLoopGroup;
26 import io.netty.channel.nio.NioEventLoopGroup;
27 import io.netty.channel.socket.SocketChannel;
28 import io.netty.channel.socket.nio.NioServerSocketChannel;
29 import io.netty.channel.socket.nio.NioSocketChannel;
30 import io.netty.handler.codec.string.StringEncoder;
31 import io.netty.handler.logging.LogLevel;
32 import io.netty.handler.logging.LoggingHandler;
33 import io.netty.handler.ssl.SslHandler;
34 import io.netty.handler.timeout.IdleStateHandler;
35 import io.netty.handler.timeout.ReadTimeoutHandler;
36 import io.netty.util.CharsetUtil;
37 import java.net.InetAddress;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collection;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Map.Entry;
44 import java.util.Set;
45 import java.util.concurrent.ConcurrentHashMap;
46 import java.util.concurrent.ExecutorService;
47 import java.util.concurrent.Executors;
48 import java.util.concurrent.ScheduledExecutorService;
49 import java.util.concurrent.TimeUnit;
50 import java.util.concurrent.atomic.AtomicBoolean;
51 import javax.annotation.Nullable;
52 import javax.inject.Inject;
53 import javax.net.ssl.SSLContext;
54 import javax.net.ssl.SSLEngine;
55 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
56 import javax.net.ssl.SSLPeerUnverifiedException;
57 import org.opendaylight.aaa.cert.api.ICertificateManager;
58 import org.opendaylight.ovsdb.lib.OvsdbClient;
59 import org.opendaylight.ovsdb.lib.OvsdbConnection;
60 import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo.ConnectionType;
61 import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo.SocketConnectionType;
62 import org.opendaylight.ovsdb.lib.OvsdbConnectionListener;
63 import org.opendaylight.ovsdb.lib.jsonrpc.ExceptionHandler;
64 import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcDecoder;
65 import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcEndpoint;
66 import org.opendaylight.ovsdb.lib.jsonrpc.JsonRpcServiceBinderHandler;
67 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
70
71 /**
72  * OvsDBConnectionService provides OVSDB connection management functionality which includes
73  * both Active and Passive connections.
74  * From the Library perspective, Active OVSDB connections are those that are initiated from
75  * the Controller towards the ovsdb-manager.
76  * While Passive OVSDB connections are those that are initiated from the ovs towards
77  * the controller.
78  *
79  * <p>Applications that use OvsDBConnectionService can use the OvsDBConnection class' connect APIs
80  * to initiate Active connections and can listen to the asynchronous Passive connections via
81  * registerConnectionListener listener API.
82  *
83  * <p>The library is designed as Java modular component that can work in both OSGi and non-OSGi
84  * environment. Hence a single instance of the service will be active (via Service Registry in OSGi)
85  * and a Singleton object in a non-OSGi environment.
86  */
87 public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection {
88     private static final Logger LOG = LoggerFactory.getLogger(OvsdbConnectionService.class);
89     private static final int IDLE_READER_TIMEOUT = 30;
90     private static final int READ_TIMEOUT = 180;
91     private static final String OVSDB_RPC_TASK_TIMEOUT_PARAM = "ovsdb-rpc-task-timeout";
92     private static final String USE_SSL = "use-ssl";
93     private static final int RETRY_PERIOD = 100; // retry after 100 milliseconds
94
95     private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newScheduledThreadPool(10,
96             new ThreadFactoryBuilder().setNameFormat("OVSDBPassiveConnServ-%d").build());
97
98     private static final ExecutorService CONNECTION_NOTIFIER_SERVICE = Executors
99             .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("OVSDBConnNotifSer-%d").build());
100
101     private static final StalePassiveConnectionService STALE_PASSIVE_CONNECTION_SERVICE =
102             new StalePassiveConnectionService((client) -> {
103                 notifyListenerForPassiveConnection(client);
104                 return null;
105             });
106
107     private static final Set<OvsdbConnectionListener> CONNECTION_LISTENERS = ConcurrentHashMap.newKeySet();
108     private static final Map<OvsdbClient, Channel> CONNECTIONS = new ConcurrentHashMap<>();
109
110     private volatile boolean useSSL = false;
111     private final ICertificateManager certManagerSrv;
112
113     private volatile int jsonRpcDecoderMaxFrameLength = 100000;
114     private volatile Channel serverChannel;
115
116     private final AtomicBoolean singletonCreated = new AtomicBoolean(false);
117     private volatile String listenerIp = "0.0.0.0";
118     private volatile int listenerPort = 6640;
119
120     @Inject
121     public OvsdbConnectionService(ICertificateManager certManagerSrv) {
122         this.certManagerSrv = certManagerSrv;
123     }
124
125     /**
126      * If the SSL flag is enabled, the method internally will establish TLS communication using the default
127      * ODL certificateManager SSLContext and attributes.
128      */
129     @Override
130     public OvsdbClient connect(final InetAddress address, final int port) {
131         if (useSSL) {
132             if (certManagerSrv == null) {
133                 LOG.error("Certificate Manager service is not available cannot establish the SSL communication.");
134                 return null;
135             }
136             return connectWithSsl(address, port, certManagerSrv);
137         } else {
138             return connectWithSsl(address, port, null /* SslContext */);
139         }
140     }
141
142     @Override
143     public OvsdbClient connectWithSsl(final InetAddress address, final int port,
144                                final ICertificateManager certificateManagerSrv) {
145         try {
146             Bootstrap bootstrap = new Bootstrap();
147             bootstrap.group(new NioEventLoopGroup());
148             bootstrap.channel(NioSocketChannel.class);
149             bootstrap.option(ChannelOption.TCP_NODELAY, true);
150             bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
151
152             bootstrap.handler(new ChannelInitializer<SocketChannel>() {
153                 @Override
154                 public void initChannel(SocketChannel channel) throws Exception {
155                     if (certificateManagerSrv != null && certificateManagerSrv.getServerContext() != null) {
156                         SSLContext sslContext = certificateManagerSrv.getServerContext();
157                         /* First add ssl handler if ssl context is given */
158                         SSLEngine engine =
159                             sslContext.createSSLEngine(address.toString(), port);
160                         engine.setUseClientMode(true);
161                         channel.pipeline().addLast("ssl", new SslHandler(engine));
162                     }
163                     channel.pipeline().addLast(
164                             //new LoggingHandler(LogLevel.INFO),
165                             new JsonRpcDecoder(jsonRpcDecoderMaxFrameLength),
166                             new StringEncoder(CharsetUtil.UTF_8),
167                             new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0),
168                             new ReadTimeoutHandler(READ_TIMEOUT),
169                             new ExceptionHandler(OvsdbConnectionService.this));
170                 }
171             });
172
173             ChannelFuture future = bootstrap.connect(address, port).sync();
174             Channel channel = future.channel();
175             return getChannelClient(channel, ConnectionType.ACTIVE, SocketConnectionType.SSL);
176         } catch (InterruptedException e) {
177             LOG.warn("Failed to connect {}:{}", address, port, e);
178         }
179         return null;
180     }
181
182     @Override
183     public void disconnect(OvsdbClient client) {
184         if (client == null) {
185             return;
186         }
187         Channel channel = CONNECTIONS.get(client);
188         if (channel != null) {
189             //It's an explicit disconnect from user, so no need to notify back
190             //to user about the disconnect.
191             client.setConnectionPublished(false);
192             channel.disconnect();
193         }
194         CONNECTIONS.remove(client);
195     }
196
197     @Override
198     public void registerConnectionListener(OvsdbConnectionListener listener) {
199         LOG.info("registerConnectionListener: registering {}", listener.getClass().getSimpleName());
200         CONNECTION_LISTENERS.add(listener);
201         notifyAlreadyExistingConnectionsToListener(listener);
202     }
203
204     private void notifyAlreadyExistingConnectionsToListener(final OvsdbConnectionListener listener) {
205         for (final OvsdbClient client : getConnections()) {
206             CONNECTION_NOTIFIER_SERVICE.execute(() -> {
207                 LOG.trace("Connection {} notified to listener {}", client.getConnectionInfo(), listener);
208                 listener.connected(client);
209             });
210         }
211     }
212
213     @Override
214     public void unregisterConnectionListener(OvsdbConnectionListener listener) {
215         CONNECTION_LISTENERS.remove(listener);
216     }
217
218     private static OvsdbClient getChannelClient(Channel channel, ConnectionType type,
219         SocketConnectionType socketConnType) {
220         ObjectMapper objectMapper = new ObjectMapper();
221         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
222         objectMapper.setSerializationInclusion(Include.NON_NULL);
223
224         JsonRpcEndpoint factory = new JsonRpcEndpoint(objectMapper, channel);
225         JsonRpcServiceBinderHandler binderHandler = new JsonRpcServiceBinderHandler(factory);
226         binderHandler.setContext(channel);
227         channel.pipeline().addLast(binderHandler);
228
229         OvsdbRPC rpc = factory.getClient(channel, OvsdbRPC.class);
230         OvsdbClientImpl client = new OvsdbClientImpl(rpc, channel, type, socketConnType);
231         client.setConnectionPublished(true);
232         CONNECTIONS.put(client, channel);
233         ChannelFuture closeFuture = channel.closeFuture();
234         closeFuture.addListener(new ChannelConnectionHandler(client));
235         return client;
236     }
237
238     /**
239      * Method that initiates the Passive OVSDB channel listening functionality.
240      * By default the ovsdb passive connection will listen in port 6640 which can
241      * be overridden using the ovsdb.listenPort system property.
242      */
243     @Override
244     public synchronized boolean startOvsdbManager() {
245         final int ovsdbListenerPort = this.listenerPort;
246         final String ovsdbListenerIp = this.listenerIp;
247         if (!singletonCreated.getAndSet(true)) {
248             LOG.info("startOvsdbManager: Starting");
249             new Thread(() -> ovsdbManager(ovsdbListenerIp, ovsdbListenerPort)).start();
250             return true;
251         } else {
252             return false;
253         }
254     }
255
256     /**
257      * Method that initiates the Passive OVSDB channel listening functionality
258      * with ssl.By default the ovsdb passive connection will listen in port
259      * 6640 which can be overridden using the ovsdb.listenPort system property.
260      */
261     @Override
262     public synchronized boolean startOvsdbManagerWithSsl(final String ovsdbListenIp, final int ovsdbListenPort,
263                                                          final ICertificateManager certificateManagerSrv,
264                                                          String[] protocols, String[] cipherSuites) {
265         if (!singletonCreated.getAndSet(true)) {
266             new Thread(() -> ovsdbManagerWithSsl(ovsdbListenIp, ovsdbListenPort,
267                     certificateManagerSrv, protocols, cipherSuites)).start();
268             return true;
269         } else {
270             return false;
271         }
272     }
273
274     @Override
275     public synchronized boolean restartOvsdbManagerWithSsl(final String ovsdbListenIp,
276         final int ovsdbListenPort,
277         final ICertificateManager certificateManagerSrv,
278         final String[] protocols,
279         final String[] cipherSuites) {
280         if (singletonCreated.getAndSet(false) && serverChannel != null) {
281             serverChannel.close();
282             LOG.info("Server channel closed");
283         }
284         serverChannel = null;
285         return startOvsdbManagerWithSsl(ovsdbListenIp, ovsdbListenPort,
286             certificateManagerSrv, protocols, cipherSuites);
287     }
288
289     /**
290      * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
291      * passive connection handle channel callbacks.
292      * If the SSL flag is enabled, the method internally will establish TLS communication using the default
293      * ODL certificateManager SSLContext and attributes.
294      */
295     private void ovsdbManager(String ip, int port) {
296         if (useSSL) {
297             if (certManagerSrv == null) {
298                 LOG.error("Certificate Manager service is not available cannot establish the SSL communication.");
299                 return;
300             }
301             ovsdbManagerWithSsl(ip, port, certManagerSrv, certManagerSrv.getTlsProtocols(),
302                     certManagerSrv.getCipherSuites());
303         } else {
304             ovsdbManagerWithSsl(ip, port, null /* SslContext */, null, null);
305         }
306     }
307
308     /**
309      * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
310      * passive connection with Ssl and handle channel callbacks.
311      */
312     private void ovsdbManagerWithSsl(String ip, int port, final ICertificateManager certificateManagerSrv,
313                                             final String[] protocols, final String[] cipherSuites) {
314         EventLoopGroup bossGroup = new NioEventLoopGroup();
315         EventLoopGroup workerGroup = new NioEventLoopGroup();
316         try {
317             ServerBootstrap serverBootstrap = new ServerBootstrap();
318             serverBootstrap.group(bossGroup, workerGroup)
319                     .channel(NioServerSocketChannel.class)
320                     .option(ChannelOption.SO_BACKLOG, 100)
321                     .handler(new LoggingHandler(LogLevel.INFO))
322                     .childHandler(new ChannelInitializer<SocketChannel>() {
323                         @Override
324                         public void initChannel(SocketChannel channel) throws Exception {
325                             LOG.debug("New Passive channel created : {}", channel);
326                             if (certificateManagerSrv != null && certificateManagerSrv.getServerContext() != null) {
327                                 /* Add SSL handler first if SSL context is provided */
328                                 SSLContext sslContext = certificateManagerSrv.getServerContext();
329                                 SSLEngine engine = sslContext.createSSLEngine();
330                                 engine.setUseClientMode(false); // work in a server mode
331                                 engine.setNeedClientAuth(true); // need client authentication
332                                 if (protocols != null && protocols.length > 0) {
333                                     //Set supported protocols
334                                     engine.setEnabledProtocols(protocols);
335                                     LOG.debug("Supported ssl protocols {}",
336                                             Arrays.toString(engine.getSupportedProtocols()));
337                                     LOG.debug("Enabled ssl protocols {}",
338                                             Arrays.toString(engine.getEnabledProtocols()));
339                                 }
340                                 if (cipherSuites != null && cipherSuites.length > 0) {
341                                     //Set supported cipher suites
342                                     engine.setEnabledCipherSuites(cipherSuites);
343                                     LOG.debug("Enabled cipher suites {}",
344                                             Arrays.toString(engine.getEnabledCipherSuites()));
345                                 }
346                                 channel.pipeline().addLast("ssl", new SslHandler(engine));
347                             }
348
349                             channel.pipeline().addLast(
350                                  new JsonRpcDecoder(jsonRpcDecoderMaxFrameLength),
351                                  new StringEncoder(CharsetUtil.UTF_8),
352                                  new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0),
353                                  new ReadTimeoutHandler(READ_TIMEOUT),
354                                  new ExceptionHandler(OvsdbConnectionService.this));
355
356                             handleNewPassiveConnection(channel);
357                         }
358                     });
359             serverBootstrap.option(ChannelOption.TCP_NODELAY, true);
360             serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR,
361                     new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
362             // Start the server.
363             ChannelFuture channelFuture = serverBootstrap.bind(ip, port).sync();
364             Channel serverListenChannel = channelFuture.channel();
365             serverChannel = serverListenChannel;
366             // Wait until the server socket is closed.
367             serverListenChannel.closeFuture().sync();
368         } catch (InterruptedException e) {
369             LOG.error("Thread interrupted", e);
370         } finally {
371             // Shut down all event loops to terminate all threads.
372             bossGroup.shutdownGracefully();
373             workerGroup.shutdownGracefully();
374         }
375     }
376
377     private static void handleNewPassiveConnection(OvsdbClient client) {
378         ListenableFuture<List<String>> echoFuture = client.echo();
379         LOG.debug("Send echo message to probe the OVSDB switch {}",client.getConnectionInfo());
380         Futures.addCallback(echoFuture, new FutureCallback<List<String>>() {
381             @Override
382             public void onSuccess(@Nullable List<String> result) {
383                 LOG.debug("Probe was successful to OVSDB switch {}",client.getConnectionInfo());
384                 List<OvsdbClient> clientsFromSameNode = getPassiveClientsFromSameNode(client);
385                 if (clientsFromSameNode.size() == 0) {
386                     notifyListenerForPassiveConnection(client);
387                 } else {
388                     STALE_PASSIVE_CONNECTION_SERVICE.handleNewPassiveConnection(client, clientsFromSameNode);
389                 }
390             }
391
392             @Override
393             public void onFailure(Throwable failureException) {
394                 LOG.error("Probe failed to OVSDB switch. Disconnecting the channel {}", client.getConnectionInfo());
395                 client.disconnect();
396             }
397         }, CONNECTION_NOTIFIER_SERVICE);
398     }
399
400     private static void handleNewPassiveConnection(final Channel channel) {
401         if (!channel.isOpen()) {
402             LOG.warn("Channel {} is not open, skipped further processing of the connection.",channel);
403             return;
404         }
405         SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
406         if (sslHandler != null) {
407             class HandleNewPassiveSslRunner implements Runnable {
408                 private int retryTimes = 3;
409
410                 private void retry() {
411                     if (retryTimes > 0) {
412                         EXECUTOR_SERVICE.schedule(this,  RETRY_PERIOD, TimeUnit.MILLISECONDS);
413                     } else {
414                         LOG.debug("channel closed {}", channel);
415                         channel.disconnect();
416                     }
417                     retryTimes--;
418                 }
419
420                 @Override
421                 public void run() {
422                     HandshakeStatus status = sslHandler.engine().getHandshakeStatus();
423                     LOG.debug("Handshake status {}", status);
424                     switch (status) {
425                         case FINISHED:
426                         case NOT_HANDSHAKING:
427                             if (sslHandler.engine().getSession().getCipherSuite()
428                                     .equals("SSL_NULL_WITH_NULL_NULL")) {
429                                 // Not begin handshake yet. Retry later.
430                                 LOG.debug("handshake not begin yet {}", status);
431                                 retry();
432                             } else {
433                               //Check if peer is trusted before notifying listeners
434                                 try {
435                                     sslHandler.engine().getSession().getPeerCertificates();
436                                     //Handshake done. Notify listener.
437                                     OvsdbClient client = getChannelClient(channel, ConnectionType.PASSIVE,
438                                         SocketConnectionType.SSL);
439                                     handleNewPassiveConnection(client);
440                                 } catch (SSLPeerUnverifiedException e) {
441                                     //Trust manager is still checking peer certificate. Retry later
442                                     LOG.debug("Peer certifiacte is not verified yet {}", status);
443                                     retry();
444                                 }
445                             }
446                             break;
447
448                         case NEED_UNWRAP:
449                         case NEED_TASK:
450                             //Handshake still ongoing. Retry later.
451                             LOG.debug("handshake not done yet {}", status);
452                             retry();
453                             break;
454
455                         case NEED_WRAP:
456                             if (sslHandler.engine().getSession().getCipherSuite()
457                                     .equals("SSL_NULL_WITH_NULL_NULL")) {
458                                 /* peer not authenticated. No need to notify listener in this case. */
459                                 LOG.error("Ssl handshake fail. channel {}", channel);
460                                 channel.disconnect();
461                             } else {
462                                 /*
463                                  * peer is authenticated. Give some time to wait for completion.
464                                  * If status is still NEED_WRAP, client might already disconnect.
465                                  * This happens when the first time client connects to controller in two-way handshake.
466                                  * After obtaining controller certificate, client will disconnect and start
467                                  * new connection with controller certificate it obtained.
468                                  * In this case no need to do anything for the first connection attempt. Just skip
469                                  * since client will reconnect later.
470                                  */
471                                 LOG.debug("handshake not done yet {}", status);
472                                 retry();
473                             }
474                             break;
475
476                         default:
477                             LOG.error("unknown hadshake status {}", status);
478                     }
479                 }
480             }
481
482             EXECUTOR_SERVICE.schedule(new HandleNewPassiveSslRunner(),
483                     RETRY_PERIOD, TimeUnit.MILLISECONDS);
484         } else {
485             EXECUTOR_SERVICE.execute(() -> {
486                 OvsdbClient client = getChannelClient(channel, ConnectionType.PASSIVE,
487                     SocketConnectionType.NON_SSL);
488                 handleNewPassiveConnection(client);
489             });
490         }
491     }
492
493     public static void channelClosed(final OvsdbClient client) {
494         LOG.info("Connection closed {}", client.getConnectionInfo().toString());
495         CONNECTIONS.remove(client);
496         if (client.isConnectionPublished()) {
497             for (OvsdbConnectionListener listener : CONNECTION_LISTENERS) {
498                 listener.disconnected(client);
499             }
500         }
501         STALE_PASSIVE_CONNECTION_SERVICE.clientDisconnected(client);
502     }
503
504     @Override
505     public Collection<OvsdbClient> getConnections() {
506         return CONNECTIONS.keySet();
507     }
508
509     @Override
510     public void close() throws Exception {
511         LOG.info("OvsdbConnectionService closed");
512         JsonRpcEndpoint.close();
513     }
514
515     @Override
516     public OvsdbClient getClient(Channel channel) {
517         for (Entry<OvsdbClient, Channel> entry : CONNECTIONS.entrySet()) {
518             OvsdbClient client = entry.getKey();
519             Channel ctx = entry.getValue();
520             if (ctx.equals(channel)) {
521                 return client;
522             }
523         }
524         return null;
525     }
526
527     private static List<OvsdbClient> getPassiveClientsFromSameNode(OvsdbClient ovsdbClient) {
528         List<OvsdbClient> passiveClients = new ArrayList<>();
529         for (OvsdbClient client : CONNECTIONS.keySet()) {
530             if (!client.equals(ovsdbClient)
531                     && client.getConnectionInfo().getRemoteAddress()
532                             .equals(ovsdbClient.getConnectionInfo().getRemoteAddress())
533                     && client.getConnectionInfo().getType() == ConnectionType.PASSIVE) {
534                 passiveClients.add(client);
535             }
536         }
537         return passiveClients;
538     }
539
540     public static void notifyListenerForPassiveConnection(final OvsdbClient client) {
541         client.setConnectionPublished(true);
542         for (final OvsdbConnectionListener listener : CONNECTION_LISTENERS) {
543             CONNECTION_NOTIFIER_SERVICE.execute(() -> {
544                 LOG.trace("Connection {} notified to listener {}", client.getConnectionInfo(), listener);
545                 listener.connected(client);
546             });
547         }
548     }
549
550     public void setOvsdbRpcTaskTimeout(int timeout) {
551         JsonRpcEndpoint.setReaperInterval(timeout);
552     }
553
554     /**
555      * Set useSSL flag.
556      *
557      * @param flag boolean for using ssl
558      */
559     public void setUseSsl(boolean flag) {
560         useSSL = flag;
561     }
562
563     /**
564      * Blueprint property setter method. Blueprint call this method and set the value of json rpc decoder
565      * max frame length to the value configured for config option (json-rpc-decoder-max-frame-length) in
566      * the configuration file. This option is only configured at the  boot time of the controller. Any
567      * change at the run time will have no impact.
568      * @param maxFrameLength Max frame length (default : 100000)
569      */
570     public void setJsonRpcDecoderMaxFrameLength(int maxFrameLength) {
571         jsonRpcDecoderMaxFrameLength = maxFrameLength;
572         LOG.info("Json Rpc Decoder Max Frame Length set to : {}", jsonRpcDecoderMaxFrameLength);
573     }
574
575     public void setOvsdbListenerIp(String ip) {
576         LOG.info("OVSDB IP for listening connection is set to : {}", ip);
577         listenerIp = ip;
578     }
579
580     public void setOvsdbListenerPort(int portNumber) {
581         LOG.info("OVSDB port for listening connection is set to : {}", portNumber);
582         listenerPort = portNumber;
583     }
584
585     public void updateConfigParameter(Map<String, Object> configParameters) {
586         if (configParameters != null && !configParameters.isEmpty()) {
587             LOG.debug("Config parameters received : {}", configParameters.entrySet());
588             for (Map.Entry<String, Object> paramEntry : configParameters.entrySet()) {
589                 if (paramEntry.getKey().equalsIgnoreCase(OVSDB_RPC_TASK_TIMEOUT_PARAM)) {
590                     setOvsdbRpcTaskTimeout(Integer.parseInt((String)paramEntry.getValue()));
591                 } else if (paramEntry.getKey().equalsIgnoreCase(USE_SSL)) {
592                     useSSL = Boolean.parseBoolean(paramEntry.getValue().toString());
593                 }
594             }
595         }
596     }
597 }