2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.store.cluster.messaging.impl;
18 import com.google.common.base.Strings;
19 import org.apache.felix.scr.annotations.Activate;
20 import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Deactivate;
22 import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service;
25 import org.onlab.netty.NettyMessaging;
26 import org.onosproject.cluster.ClusterDefinitionService;
27 import org.onosproject.cluster.ControllerNode;
28 import org.onosproject.store.cluster.messaging.Endpoint;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * Netty based MessagingService.
35 @Component(immediate = true, enabled = true)
37 public class NettyMessagingManager extends NettyMessaging {
39 private final Logger log = LoggerFactory.getLogger(getClass());
41 private static final short MIN_KS_LENGTH = 6;
43 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected ClusterDefinitionService clusterDefinitionService;
47 public void activate() throws Exception {
48 ControllerNode localNode = clusterDefinitionService.localNode();
50 super.start(new Endpoint(localNode.ip(), localNode.tcpPort()));
55 public void deactivate() throws Exception {
60 private void getTLSParameters() {
61 String tempString = System.getProperty("enableNettyTLS");
62 enableNettyTLS = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString);
63 log.info("enableNettyTLS = {}", enableNettyTLS);
65 ksLocation = System.getProperty("javax.net.ssl.keyStore");
66 if (Strings.isNullOrEmpty(ksLocation)) {
67 enableNettyTLS = TLS_DISABLED;
70 tsLocation = System.getProperty("javax.net.ssl.trustStore");
71 if (Strings.isNullOrEmpty(tsLocation)) {
72 enableNettyTLS = TLS_DISABLED;
75 ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray();
76 if (MIN_KS_LENGTH > ksPwd.length) {
77 enableNettyTLS = TLS_DISABLED;
80 tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray();
81 if (MIN_KS_LENGTH > tsPwd.length) {
82 enableNettyTLS = TLS_DISABLED;