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 | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 30 | import org.onosproject.lisp.msg.authentication.LispAuthenticationConfig; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 31 | import org.onosproject.net.device.DeviceService; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 32 | import org.osgi.service.component.ComponentContext; |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 33 | import org.slf4j.Logger; |
| 34 | import org.slf4j.LoggerFactory; |
| 35 | |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 36 | import java.util.Dictionary; |
| 37 | |
| 38 | import static org.onlab.util.Tools.get; |
| 39 | import static org.onlab.util.Tools.getIntegerProperty; |
| 40 | |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 41 | /** |
| 42 | * LISP controller initiation class. |
| 43 | */ |
| 44 | @Component(immediate = true) |
| 45 | @Service |
| 46 | public 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 Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 53 | private static final String DEFAULT_LISP_AUTH_KEY = "onos"; |
| 54 | private static final short DEFAULT_LISP_AUTH_KEY_ID = 1; |
| 55 | |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 57 | protected CoreService coreService; |
| 58 | |
| 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 60 | protected DeviceService deviceService; |
| 61 | |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 62 | @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 Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 77 | private final LispControllerBootstrap bootstrap = new LispControllerBootstrap(); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 78 | private final LispAuthenticationConfig authConfig = LispAuthenticationConfig.getInstance(); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 79 | |
| 80 | @Activate |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 81 | public void activate(ComponentContext context) { |
| 82 | cfgService.registerProperties(getClass()); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 83 | coreService.registerApplication(APP_ID); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 84 | initAuthConfig(context.getProperties()); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 85 | bootstrap.start(); |
| 86 | log.info("Started"); |
| 87 | } |
| 88 | |
| 89 | @Deactivate |
| 90 | public void deactivate() { |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 91 | cfgService.unregisterProperties(getClass(), false); |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 92 | bootstrap.stop(); |
| 93 | log.info("Stopped"); |
| 94 | } |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 95 | |
| 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 Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 134 | } |