blob: e8dae2c69ac3162678cd4010391cc294393f5764 [file] [log] [blame]
Jian Li6322a362016-10-31 00:57:19 +09001/*
2 * Copyright 2016-present 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 */
Jian Li5e505c62016-12-05 02:44:24 +090016package org.onosproject.lisp.ctl.impl;
Jian Li6322a362016-10-31 00:57:19 +090017
Jian Li712ec052016-11-22 03:23:54 +090018import org.apache.felix.scr.annotations.Activate;
Jian Li6322a362016-10-31 00:57:19 +090019import org.apache.felix.scr.annotations.Component;
Jian Li712ec052016-11-22 03:23:54 +090020import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Modified;
22import org.apache.felix.scr.annotations.Property;
Jian Li6322a362016-10-31 00:57:19 +090023import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
25import org.apache.felix.scr.annotations.Service;
Jian Li712ec052016-11-22 03:23:54 +090026import org.onlab.util.Tools;
27import org.onosproject.cfg.ComponentConfigService;
Jian Li6322a362016-10-31 00:57:19 +090028import org.onosproject.core.CoreService;
Jian Li5e505c62016-12-05 02:44:24 +090029import org.onosproject.lisp.ctl.LispController;
Jian Li712ec052016-11-22 03:23:54 +090030import org.onosproject.lisp.msg.authentication.LispAuthenticationConfig;
Jian Li6322a362016-10-31 00:57:19 +090031import org.onosproject.net.device.DeviceService;
Jian Li712ec052016-11-22 03:23:54 +090032import org.osgi.service.component.ComponentContext;
Jian Li6322a362016-10-31 00:57:19 +090033import org.slf4j.Logger;
34import org.slf4j.LoggerFactory;
35
Jian Li712ec052016-11-22 03:23:54 +090036import java.util.Dictionary;
37
38import static org.onlab.util.Tools.get;
39import static org.onlab.util.Tools.getIntegerProperty;
40
Jian Li6322a362016-10-31 00:57:19 +090041/**
42 * LISP controller initiation class.
43 */
44@Component(immediate = true)
45@Service
46public class LispControllerImpl implements LispController {
47
48 private static final String APP_ID = "org.onosproject.lisp-base";
49
50 private static final Logger log =
51 LoggerFactory.getLogger(LispControllerImpl.class);
52
Jian Li712ec052016-11-22 03:23:54 +090053 private static final String DEFAULT_LISP_AUTH_KEY = "onos";
54 private static final short DEFAULT_LISP_AUTH_KEY_ID = 1;
55
Jian Li6322a362016-10-31 00:57:19 +090056 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 protected CoreService coreService;
58
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 protected DeviceService deviceService;
61
Jian Li712ec052016-11-22 03:23:54 +090062 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
63 protected ComponentConfigService cfgService;
64
65 @Property(name = "lispAuthKey", value = DEFAULT_LISP_AUTH_KEY,
66 label = "Authentication key which is used to calculate authentication " +
67 "data for LISP control message; default value is onos")
68 protected String lispAuthKey = DEFAULT_LISP_AUTH_KEY;
69
70 @Property(name = "lispAuthKeyId", intValue = DEFAULT_LISP_AUTH_KEY_ID,
71 label = "Authentication key id which denotes the authentication method " +
72 "that ONOS uses to calculate the authentication data; " +
73 "1 denotes HMAC SHA1 encryption, 2 denotes HMAC SHA256 encryption; " +
74 "default value is 1")
75 protected int lispAuthKeyId = DEFAULT_LISP_AUTH_KEY_ID;
76
Jian Li6322a362016-10-31 00:57:19 +090077 private final LispControllerBootstrap bootstrap = new LispControllerBootstrap();
Jian Li712ec052016-11-22 03:23:54 +090078 private final LispAuthenticationConfig authConfig = LispAuthenticationConfig.getInstance();
Jian Li6322a362016-10-31 00:57:19 +090079
80 @Activate
Jian Li712ec052016-11-22 03:23:54 +090081 public void activate(ComponentContext context) {
82 cfgService.registerProperties(getClass());
Jian Li6322a362016-10-31 00:57:19 +090083 coreService.registerApplication(APP_ID);
Jian Li712ec052016-11-22 03:23:54 +090084 initAuthConfig(context.getProperties());
Jian Li6322a362016-10-31 00:57:19 +090085 bootstrap.start();
86 log.info("Started");
87 }
88
89 @Deactivate
90 public void deactivate() {
Jian Li712ec052016-11-22 03:23:54 +090091 cfgService.unregisterProperties(getClass(), false);
Jian Li6322a362016-10-31 00:57:19 +090092 bootstrap.stop();
93 log.info("Stopped");
94 }
Jian Li712ec052016-11-22 03:23:54 +090095
96 @Modified
97 public void modified(ComponentContext context) {
98 readComponentConfiguration(context);
99 }
100
101 /**
102 * Initializes authentication key and authentication method.
103 *
104 * @param properties a set of properties that contained in component context
105 */
106 private void initAuthConfig(Dictionary<?, ?> properties) {
107 authConfig.updateLispAuthKey(get(properties, "lispAuthKey"));
108 authConfig.updateLispAuthKeyId(getIntegerProperty(properties, "lispAuthKeyId"));
109 }
110
111 /**
112 * Extracts properties from the component configuration context.
113 *
114 * @param context the component context
115 */
116 private void readComponentConfiguration(ComponentContext context) {
117 Dictionary<?, ?> properties = context.getProperties();
118
119 String lispAuthKeyStr = Tools.get(properties, "lispAuthKey");
120 lispAuthKey = lispAuthKeyStr != null ? lispAuthKeyStr : DEFAULT_LISP_AUTH_KEY;
121 authConfig.updateLispAuthKey(lispAuthKey);
122 log.info("Configured. LISP authentication key is {}", lispAuthKey);
123
124 Integer lispAuthMethodInt = Tools.getIntegerProperty(properties, "lispAuthKeyId");
125 if (lispAuthMethodInt == null) {
126 lispAuthKeyId = DEFAULT_LISP_AUTH_KEY_ID;
127 log.info("LISP authentication method is not configured, default value is {}", lispAuthKeyId);
128 } else {
129 lispAuthKeyId = lispAuthMethodInt;
130 log.info("Configured. LISP authentication method is configured to {}", lispAuthKeyId);
131 }
132 authConfig.updateLispAuthKeyId(lispAuthKeyId);
133 }
Jian Li6322a362016-10-31 00:57:19 +0900134}