Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 1 | /* |
| 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 Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 16 | package org.onosproject.lisp.ctl.impl; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 17 | |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Component; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Modified; |
| 22 | import org.apache.felix.scr.annotations.Property; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 26 | import org.onlab.util.Tools; |
| 27 | import org.onosproject.cfg.ComponentConfigService; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 28 | import org.onosproject.core.CoreService; |
Jian Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 29 | import org.onosproject.lisp.ctl.LispController; |
Jian Li | 7ccc3a8 | 2016-12-09 01:30:56 +0900 | [diff] [blame^] | 30 | import org.onosproject.lisp.ctl.LispMessageListener; |
| 31 | import org.onosproject.lisp.ctl.LispRouter; |
| 32 | import org.onosproject.lisp.ctl.LispRouterId; |
| 33 | import org.onosproject.lisp.ctl.LispRouterListener; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 34 | import org.onosproject.lisp.msg.authentication.LispAuthenticationConfig; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceService; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 36 | import org.osgi.service.component.ComponentContext; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 37 | import org.slf4j.Logger; |
| 38 | import org.slf4j.LoggerFactory; |
| 39 | |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 40 | import java.util.Dictionary; |
| 41 | |
| 42 | import static org.onlab.util.Tools.get; |
| 43 | import static org.onlab.util.Tools.getIntegerProperty; |
| 44 | |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 45 | /** |
| 46 | * LISP controller initiation class. |
| 47 | */ |
| 48 | @Component(immediate = true) |
| 49 | @Service |
| 50 | public 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 Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 57 | private static final String DEFAULT_LISP_AUTH_KEY = "onos"; |
| 58 | private static final short DEFAULT_LISP_AUTH_KEY_ID = 1; |
| 59 | |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 61 | protected CoreService coreService; |
| 62 | |
| 63 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 64 | protected DeviceService deviceService; |
| 65 | |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 66 | @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 Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 81 | private final LispControllerBootstrap bootstrap = new LispControllerBootstrap(); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 82 | private final LispAuthenticationConfig authConfig = LispAuthenticationConfig.getInstance(); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 83 | |
| 84 | @Activate |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 85 | public void activate(ComponentContext context) { |
| 86 | cfgService.registerProperties(getClass()); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 87 | coreService.registerApplication(APP_ID); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 88 | initAuthConfig(context.getProperties()); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 89 | bootstrap.start(); |
| 90 | log.info("Started"); |
| 91 | } |
| 92 | |
| 93 | @Deactivate |
| 94 | public void deactivate() { |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 95 | cfgService.unregisterProperties(getClass(), false); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 96 | bootstrap.stop(); |
| 97 | log.info("Stopped"); |
| 98 | } |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 99 | |
| 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 Li | 7ccc3a8 | 2016-12-09 01:30:56 +0900 | [diff] [blame^] | 138 | |
| 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 Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 168 | } |