blob: 0d1bdf0812e0102cd4e989df2af9ee1f1a2f14bc [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 Li7ccc3a82016-12-09 01:30:56 +090030import org.onosproject.lisp.ctl.LispMessageListener;
31import org.onosproject.lisp.ctl.LispRouter;
32import org.onosproject.lisp.ctl.LispRouterId;
33import org.onosproject.lisp.ctl.LispRouterListener;
Jian Li712ec052016-11-22 03:23:54 +090034import org.onosproject.lisp.msg.authentication.LispAuthenticationConfig;
Jian Li6322a362016-10-31 00:57:19 +090035import org.onosproject.net.device.DeviceService;
Jian Li712ec052016-11-22 03:23:54 +090036import org.osgi.service.component.ComponentContext;
Jian Li6322a362016-10-31 00:57:19 +090037import org.slf4j.Logger;
38import org.slf4j.LoggerFactory;
39
Jian Li712ec052016-11-22 03:23:54 +090040import java.util.Dictionary;
41
42import static org.onlab.util.Tools.get;
43import static org.onlab.util.Tools.getIntegerProperty;
44
Jian Li6322a362016-10-31 00:57:19 +090045/**
46 * LISP controller initiation class.
47 */
48@Component(immediate = true)
49@Service
50public class LispControllerImpl implements LispController {
51
52 private static final String APP_ID = "org.onosproject.lisp-base";
53
54 private static final Logger log =
55 LoggerFactory.getLogger(LispControllerImpl.class);
56
Jian Li712ec052016-11-22 03:23:54 +090057 private static final String DEFAULT_LISP_AUTH_KEY = "onos";
58 private static final short DEFAULT_LISP_AUTH_KEY_ID = 1;
59
Jian Li6322a362016-10-31 00:57:19 +090060 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 protected CoreService coreService;
62
63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 protected DeviceService deviceService;
65
Jian Li712ec052016-11-22 03:23:54 +090066 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 protected ComponentConfigService cfgService;
68
69 @Property(name = "lispAuthKey", value = DEFAULT_LISP_AUTH_KEY,
70 label = "Authentication key which is used to calculate authentication " +
71 "data for LISP control message; default value is onos")
72 protected String lispAuthKey = DEFAULT_LISP_AUTH_KEY;
73
74 @Property(name = "lispAuthKeyId", intValue = DEFAULT_LISP_AUTH_KEY_ID,
75 label = "Authentication key id which denotes the authentication method " +
76 "that ONOS uses to calculate the authentication data; " +
77 "1 denotes HMAC SHA1 encryption, 2 denotes HMAC SHA256 encryption; " +
78 "default value is 1")
79 protected int lispAuthKeyId = DEFAULT_LISP_AUTH_KEY_ID;
80
Jian Li6322a362016-10-31 00:57:19 +090081 private final LispControllerBootstrap bootstrap = new LispControllerBootstrap();
Jian Li712ec052016-11-22 03:23:54 +090082 private final LispAuthenticationConfig authConfig = LispAuthenticationConfig.getInstance();
Jian Li6322a362016-10-31 00:57:19 +090083
84 @Activate
Jian Li712ec052016-11-22 03:23:54 +090085 public void activate(ComponentContext context) {
86 cfgService.registerProperties(getClass());
Jian Li6322a362016-10-31 00:57:19 +090087 coreService.registerApplication(APP_ID);
Jian Li712ec052016-11-22 03:23:54 +090088 initAuthConfig(context.getProperties());
Jian Li6322a362016-10-31 00:57:19 +090089 bootstrap.start();
90 log.info("Started");
91 }
92
93 @Deactivate
94 public void deactivate() {
Jian Li712ec052016-11-22 03:23:54 +090095 cfgService.unregisterProperties(getClass(), false);
Jian Li6322a362016-10-31 00:57:19 +090096 bootstrap.stop();
97 log.info("Stopped");
98 }
Jian Li712ec052016-11-22 03:23:54 +090099
100 @Modified
101 public void modified(ComponentContext context) {
102 readComponentConfiguration(context);
103 }
104
105 /**
106 * Initializes authentication key and authentication method.
107 *
108 * @param properties a set of properties that contained in component context
109 */
110 private void initAuthConfig(Dictionary<?, ?> properties) {
111 authConfig.updateLispAuthKey(get(properties, "lispAuthKey"));
112 authConfig.updateLispAuthKeyId(getIntegerProperty(properties, "lispAuthKeyId"));
113 }
114
115 /**
116 * Extracts properties from the component configuration context.
117 *
118 * @param context the component context
119 */
120 private void readComponentConfiguration(ComponentContext context) {
121 Dictionary<?, ?> properties = context.getProperties();
122
123 String lispAuthKeyStr = Tools.get(properties, "lispAuthKey");
124 lispAuthKey = lispAuthKeyStr != null ? lispAuthKeyStr : DEFAULT_LISP_AUTH_KEY;
125 authConfig.updateLispAuthKey(lispAuthKey);
126 log.info("Configured. LISP authentication key is {}", lispAuthKey);
127
128 Integer lispAuthMethodInt = Tools.getIntegerProperty(properties, "lispAuthKeyId");
129 if (lispAuthMethodInt == null) {
130 lispAuthKeyId = DEFAULT_LISP_AUTH_KEY_ID;
131 log.info("LISP authentication method is not configured, default value is {}", lispAuthKeyId);
132 } else {
133 lispAuthKeyId = lispAuthMethodInt;
134 log.info("Configured. LISP authentication method is configured to {}", lispAuthKeyId);
135 }
136 authConfig.updateLispAuthKeyId(lispAuthKeyId);
137 }
Jian Li7ccc3a82016-12-09 01:30:56 +0900138
139 @Override
140 public Iterable<LispRouter> getRouters() {
141 return null;
142 }
143
144 @Override
145 public LispRouter getRouter(LispRouterId routerId) {
146 return null;
147 }
148
149 @Override
150 public void addRouterListener(LispRouterListener listener) {
151
152 }
153
154 @Override
155 public void removeRouterListener(LispRouterListener listener) {
156
157 }
158
159 @Override
160 public void addMessageListener(LispMessageListener listener) {
161
162 }
163
164 @Override
165 public void removeMessageListener(LispMessageListener listener) {
166
167 }
Jian Li6322a362016-10-31 00:57:19 +0900168}