blob: d61d7dcf8bf06b463eb4fcde1568bf88cb272fc5 [file] [log] [blame]
Thomas Vachuska58de4162015-09-10 16:15:33 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Madan Jampaniafeebbd2015-05-19 15:26:01 -070016package org.onosproject.store.cluster.messaging.impl;
17
JunHuy Lam39eb4292015-06-26 17:24:23 +090018import com.google.common.base.Strings;
Madan Jampaniec1df022015-10-13 21:23:03 -070019
Madan Jampaniafeebbd2015-05-19 15:26:01 -070020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
26import org.onlab.netty.NettyMessaging;
Madan Jampaniec1df022015-10-13 21:23:03 -070027import org.onosproject.cluster.ClusterMetadataService;
Madan Jampaniafeebbd2015-05-19 15:26:01 -070028import org.onosproject.cluster.ControllerNode;
29import org.onosproject.store.cluster.messaging.Endpoint;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33/**
34 * Netty based MessagingService.
35 */
36@Component(immediate = true, enabled = true)
37@Service
38public class NettyMessagingManager extends NettyMessaging {
39
40 private final Logger log = LoggerFactory.getLogger(getClass());
41
JunHuy Lam39eb4292015-06-26 17:24:23 +090042 private static final short MIN_KS_LENGTH = 6;
43
Madan Jampaniafeebbd2015-05-19 15:26:01 -070044 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Madan Jampaniec1df022015-10-13 21:23:03 -070045 protected ClusterMetadataService clusterMetadataService;
Madan Jampaniafeebbd2015-05-19 15:26:01 -070046
47 @Activate
48 public void activate() throws Exception {
Madan Jampaniec1df022015-10-13 21:23:03 -070049 ControllerNode localNode = clusterMetadataService.getLocalNode();
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080050 getTlsParameters();
Madan Jampaniafeebbd2015-05-19 15:26:01 -070051 super.start(new Endpoint(localNode.ip(), localNode.tcpPort()));
52 log.info("Started");
53 }
54
55 @Deactivate
56 public void deactivate() throws Exception {
57 super.stop();
58 log.info("Stopped");
59 }
JunHuy Lam39eb4292015-06-26 17:24:23 +090060
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080061 private void getTlsParameters() {
JunHuy Lam39eb4292015-06-26 17:24:23 +090062 String tempString = System.getProperty("enableNettyTLS");
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080063 enableNettyTls = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString);
64 log.info("enableNettyTLS = {}", enableNettyTls);
65 if (enableNettyTls) {
JunHuy Lam39eb4292015-06-26 17:24:23 +090066 ksLocation = System.getProperty("javax.net.ssl.keyStore");
67 if (Strings.isNullOrEmpty(ksLocation)) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080068 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090069 return;
70 }
71 tsLocation = System.getProperty("javax.net.ssl.trustStore");
72 if (Strings.isNullOrEmpty(tsLocation)) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080073 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090074 return;
75 }
76 ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
77 if (MIN_KS_LENGTH > ksPwd.length) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080078 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090079 return;
80 }
81 tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray();
82 if (MIN_KS_LENGTH > tsPwd.length) {
Jonathan Hartd9df7bd2015-11-10 17:10:25 -080083 enableNettyTls = TLS_DISABLED;
JunHuy Lam39eb4292015-06-26 17:24:23 +090084 return;
85 }
86 }
87 }
88}