Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 1 | /* |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 2 | Copyright 2015-present Open Networking Foundation |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 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 | */ |
alshabib | 6d52745 | 2016-06-01 18:00:47 -0700 | [diff] [blame] | 16 | package org.opencord.aaa; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 17 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 18 | import java.net.InetAddress; |
| 19 | import java.net.UnknownHostException; |
| 20 | import java.util.HashSet; |
| 21 | import java.util.Set; |
| 22 | |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 23 | import org.apache.commons.lang3.builder.ToStringBuilder; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 24 | import org.onosproject.core.ApplicationId; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 25 | import org.onosproject.net.ConnectPoint; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 26 | import org.onosproject.net.config.Config; |
| 27 | import org.onosproject.net.config.basics.BasicElementConfig; |
| 28 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 29 | import com.fasterxml.jackson.databind.JsonNode; |
| 30 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 31 | import com.google.common.collect.ImmutableSet; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 32 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Network config for the AAA app. |
| 35 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 36 | public class AaaConfig extends Config<ApplicationId> { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 37 | |
Jonathan Hart | f935b12 | 2018-07-11 16:16:02 -0700 | [diff] [blame] | 38 | private static final String RADIUS_HOST = "radiusHost"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 39 | private static final String RADIUS_IP = "radiusIp"; |
ke han | 1fe3b0e | 2017-02-28 09:50:20 +0800 | [diff] [blame] | 40 | private static final String RADIUS_SERVER_PORT = "radiusServerPort"; |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 41 | private static final String SESSION_CLEANUP_TIMER = "sessionCleanupTimer"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 42 | private static final String RADIUS_MAC = "radiusMac"; |
| 43 | private static final String NAS_IP = "nasIp"; |
| 44 | private static final String NAS_MAC = "nasMac"; |
| 45 | private static final String RADIUS_SECRET = "radiusSecret"; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 46 | private static final String RADIUS_VLAN_ID = "vlanId"; |
| 47 | private static final String RADIUS_VLAN_PRIORITY_BIT = "radiusPBit"; |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 48 | private static final String RADIUS_CONNECTION_TYPE = "radiusConnectionType"; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 49 | private static final String RADIUS_SERVER_CONNECTPOINTS = "radiusServerConnectPoints"; |
| 50 | // Which packet customizer to use |
| 51 | // "packetCustomizer" : "sample" -- Means use SamplePAcketCustomizer |
| 52 | // "packetCustomizer" : "default" -- No customization of packets |
| 53 | // if param is missing it is treated as default |
| 54 | // This class should be a subclass of PacketCustomizer |
| 55 | private static final String PACKET_CUSTOMIZER = "packetCustomizer"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 56 | |
| 57 | // RADIUS server IP address |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 58 | protected static final String DEFAULT_RADIUS_IP = "10.128.10.4"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 59 | |
| 60 | // RADIUS MAC address |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 61 | public static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 62 | |
| 63 | // NAS IP address |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 64 | public static final String DEFAULT_NAS_IP = "10.128.9.244"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 65 | |
| 66 | // NAS MAC address |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 67 | public static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 68 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 69 | // RADIUS server shared secret |
| 70 | protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; |
| 71 | |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 72 | // Radius Server UDP Port Number |
| 73 | protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812"; |
| 74 | |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 75 | // Time configured for triggering timeouts in AAA app |
| 76 | protected static final String DEFAULT_SESSION_CLEANUP_TIMER = "10"; |
| 77 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 78 | // Radius Server Vlan ID |
| 79 | protected static final String DEFAULT_RADIUS_VLAN_ID = "4093"; |
| 80 | |
| 81 | // Radius Sever P-Bit |
| 82 | protected static final String DEFAULT_RADIUS_VLAN_PRIORITY_BIT = "3"; |
| 83 | |
| 84 | // Whether to use socket or not to communicate with RADIUS Server |
| 85 | protected static final String DEFAULT_RADIUS_CONNECTION_TYPE = "socket"; |
| 86 | |
| 87 | // Packet Customizer Default value |
| 88 | protected static final String DEFAULT_PACKET_CUSTOMIZER = "default"; |
| 89 | |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 90 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 91 | * Gets the value of a string property, protecting for an empty JSON object. |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 92 | * |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 93 | * @param name name of the property |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 94 | * @param defaultValue default value if none has been specified |
| 95 | * @return String value if one os found, default value otherwise |
| 96 | */ |
| 97 | private String getStringProperty(String name, String defaultValue) { |
| 98 | if (object == null) { |
| 99 | return defaultValue; |
| 100 | } |
| 101 | return get(name, defaultValue); |
| 102 | } |
| 103 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Returns the NAS ip. |
| 106 | * |
| 107 | * @return ip address or null if not set |
| 108 | */ |
| 109 | public InetAddress nasIp() { |
| 110 | try { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 111 | return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 112 | } catch (UnknownHostException e) { |
| 113 | return null; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Sets the NAS ip. |
| 119 | * |
| 120 | * @param ip new ip address; null to clear |
| 121 | * @return self |
| 122 | */ |
| 123 | public BasicElementConfig nasIp(String ip) { |
| 124 | return (BasicElementConfig) setOrClear(NAS_IP, ip); |
| 125 | } |
| 126 | |
Jonathan Hart | f935b12 | 2018-07-11 16:16:02 -0700 | [diff] [blame] | 127 | public String radiusHostName() { |
| 128 | return getStringProperty(RADIUS_HOST, null); |
| 129 | } |
| 130 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Returns the RADIUS server ip. |
| 133 | * |
| 134 | * @return ip address or null if not set |
| 135 | */ |
| 136 | public InetAddress radiusIp() { |
| 137 | try { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 138 | return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 139 | } catch (UnknownHostException e) { |
| 140 | return null; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Sets the RADIUS server ip. |
| 146 | * |
| 147 | * @param ip new ip address; null to clear |
| 148 | * @return self |
| 149 | */ |
| 150 | public BasicElementConfig radiusIp(String ip) { |
| 151 | return (BasicElementConfig) setOrClear(RADIUS_IP, ip); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Returns the RADIUS MAC address. |
| 156 | * |
| 157 | * @return mac address or null if not set |
| 158 | */ |
| 159 | public String radiusMac() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 160 | return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Sets the RADIUS MAC address. |
| 165 | * |
| 166 | * @param mac new MAC address; null to clear |
| 167 | * @return self |
| 168 | */ |
| 169 | public BasicElementConfig radiusMac(String mac) { |
| 170 | return (BasicElementConfig) setOrClear(RADIUS_MAC, mac); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Returns the RADIUS MAC address. |
| 175 | * |
| 176 | * @return mac address or null if not set |
| 177 | */ |
| 178 | public String nasMac() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 179 | return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Sets the RADIUS MAC address. |
| 184 | * |
| 185 | * @param mac new MAC address; null to clear |
| 186 | * @return self |
| 187 | */ |
| 188 | public BasicElementConfig nasMac(String mac) { |
| 189 | return (BasicElementConfig) setOrClear(NAS_MAC, mac); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Returns the RADIUS secret. |
| 194 | * |
| 195 | * @return radius secret or null if not set |
| 196 | */ |
| 197 | public String radiusSecret() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 198 | return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Sets the RADIUS secret. |
| 203 | * |
| 204 | * @param secret new MAC address; null to clear |
| 205 | * @return self |
| 206 | */ |
| 207 | public BasicElementConfig radiusSecret(String secret) { |
| 208 | return (BasicElementConfig) setOrClear(RADIUS_SECRET, secret); |
| 209 | } |
| 210 | |
| 211 | /** |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 212 | * Returns the RADIUS server UDP port. |
| 213 | * |
| 214 | * @return radius server UDP port. |
| 215 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 216 | public short radiusServerUdpPort() { |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 217 | return Short.parseShort(getStringProperty(RADIUS_SERVER_PORT, DEFAULT_RADIUS_SERVER_PORT)); |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Sets the RADIUS port. |
| 222 | * |
| 223 | * @param port new RADIUS UDP port; -1 to clear |
| 224 | * @return self |
| 225 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 226 | public BasicElementConfig radiusServerUdpPort(short port) { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 227 | return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port); |
| 228 | } |
| 229 | |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 230 | /** |
| 231 | * Returns the RADIUS server vlan ID. |
| 232 | * |
| 233 | * @return Radius Server VLan id or default if not set |
| 234 | */ |
| 235 | public short radiusServerVlanId() { |
| 236 | return Short.parseShort(getStringProperty(RADIUS_VLAN_ID, DEFAULT_RADIUS_VLAN_ID)); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Returns the type of connection to use to communicate with the RADIUS Server. |
| 241 | * |
| 242 | * @return "socket" or "packet_out" |
| 243 | */ |
| 244 | public String radiusConnectionType() { |
| 245 | return getStringProperty(RADIUS_CONNECTION_TYPE, DEFAULT_RADIUS_CONNECTION_TYPE); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Returns the RADIUS server p-bit. |
| 250 | * |
| 251 | * @return Radius Server P-bit to use, default if not set |
| 252 | */ |
| 253 | public byte radiusServerPBit() { |
| 254 | return Byte.parseByte(getStringProperty(RADIUS_VLAN_PRIORITY_BIT, DEFAULT_RADIUS_VLAN_PRIORITY_BIT)); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Returns the PACKET CUSTOMIZER CLASS NAME. |
| 259 | * |
| 260 | * @return PACKET CUSTOMIZER, default if not set |
| 261 | */ |
| 262 | public String radiusPktCustomizer() { |
| 263 | return getStringProperty(PACKET_CUSTOMIZER, DEFAULT_PACKET_CUSTOMIZER); |
| 264 | } |
| 265 | |
| 266 | /** |
Shubham Sharma | 1e43c56 | 2019-06-19 14:18:12 +0000 | [diff] [blame] | 267 | * Returns the time configured for checking timeout . |
| 268 | * |
| 269 | * @return timerTimeout |
| 270 | */ |
| 271 | public int sessionCleanupTimer() { |
| 272 | return Integer |
| 273 | .parseInt(getStringProperty(SESSION_CLEANUP_TIMER, DEFAULT_SESSION_CLEANUP_TIMER)); |
| 274 | } |
| 275 | |
| 276 | /** |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 277 | * Returns the List of ConnectPoints to reach the Radius Server. |
| 278 | * |
| 279 | * @return List of ConnectPoints |
| 280 | */ |
| 281 | public Set<ConnectPoint> radiusServerConnectPoints() { |
| 282 | if (object == null) { |
| 283 | return new HashSet<ConnectPoint>(); |
| 284 | } |
| 285 | |
| 286 | if (!object.has(RADIUS_SERVER_CONNECTPOINTS)) { |
| 287 | return ImmutableSet.of(); |
| 288 | } |
| 289 | |
| 290 | ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder(); |
| 291 | ArrayNode arrayNode = (ArrayNode) object.path(RADIUS_SERVER_CONNECTPOINTS); |
| 292 | for (JsonNode jsonNode : arrayNode) { |
| 293 | String portName = jsonNode.asText(null); |
| 294 | if (portName == null) { |
| 295 | return null; |
| 296 | } |
| 297 | try { |
| 298 | builder.add(ConnectPoint.deviceConnectPoint(portName)); |
| 299 | } catch (IllegalArgumentException e) { |
| 300 | return null; |
| 301 | } |
| 302 | } |
| 303 | return builder.build(); |
| 304 | } |
Matt Jeanneret | 2ff1a78 | 2018-06-13 15:24:25 -0400 | [diff] [blame] | 305 | |
| 306 | @Override |
| 307 | public String toString() { |
| 308 | return ToStringBuilder.reflectionToString(this); |
| 309 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 310 | } |