Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 16 | package org.onosproject.aaa; |
| 17 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.config.Config; |
| 20 | import org.onosproject.net.config.basics.BasicElementConfig; |
| 21 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 22 | import java.net.InetAddress; |
| 23 | import java.net.UnknownHostException; |
| 24 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 25 | /** |
| 26 | * Network config for the AAA app. |
| 27 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 28 | public class AaaConfig extends Config<ApplicationId> { |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 29 | |
| 30 | private static final String RADIUS_IP = "radiusIp"; |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 31 | private static final String RADIUS_SERVER_PORT = "1812"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 32 | private static final String RADIUS_MAC = "radiusMac"; |
| 33 | private static final String NAS_IP = "nasIp"; |
| 34 | private static final String NAS_MAC = "nasMac"; |
| 35 | private static final String RADIUS_SECRET = "radiusSecret"; |
| 36 | private static final String RADIUS_SWITCH = "radiusSwitch"; |
| 37 | private static final String RADIUS_PORT = "radiusPort"; |
| 38 | |
| 39 | // RADIUS server IP address |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 40 | protected static final String DEFAULT_RADIUS_IP = "10.128.10.4"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 41 | |
| 42 | // RADIUS MAC address |
| 43 | protected static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10"; |
| 44 | |
| 45 | // NAS IP address |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 46 | protected static final String DEFAULT_NAS_IP = "10.128.9.244"; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 47 | |
| 48 | // NAS MAC address |
| 49 | protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01"; |
| 50 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 51 | // RADIUS server shared secret |
| 52 | protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; |
| 53 | |
| 54 | // Radius Switch Id |
| 55 | protected static final String DEFAULT_RADIUS_SWITCH = "of:90e2ba82f97791e9"; |
| 56 | |
| 57 | // Radius Port Number |
| 58 | protected static final String DEFAULT_RADIUS_PORT = "129"; |
| 59 | |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 60 | // Radius Server UDP Port Number |
| 61 | protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812"; |
| 62 | |
| 63 | /** |
| 64 | * Gets the value of a string property, protecting for an empty |
| 65 | * JSON object. |
| 66 | * |
| 67 | * @param name name of the property |
| 68 | * @param defaultValue default value if none has been specified |
| 69 | * @return String value if one os found, default value otherwise |
| 70 | */ |
| 71 | private String getStringProperty(String name, String defaultValue) { |
| 72 | if (object == null) { |
| 73 | return defaultValue; |
| 74 | } |
| 75 | return get(name, defaultValue); |
| 76 | } |
| 77 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 78 | /** |
| 79 | * Returns the NAS ip. |
| 80 | * |
| 81 | * @return ip address or null if not set |
| 82 | */ |
| 83 | public InetAddress nasIp() { |
| 84 | try { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 85 | return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 86 | } catch (UnknownHostException e) { |
| 87 | return null; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Sets the NAS ip. |
| 93 | * |
| 94 | * @param ip new ip address; null to clear |
| 95 | * @return self |
| 96 | */ |
| 97 | public BasicElementConfig nasIp(String ip) { |
| 98 | return (BasicElementConfig) setOrClear(NAS_IP, ip); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the RADIUS server ip. |
| 103 | * |
| 104 | * @return ip address or null if not set |
| 105 | */ |
| 106 | public InetAddress radiusIp() { |
| 107 | try { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 108 | return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 109 | } catch (UnknownHostException e) { |
| 110 | return null; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Sets the RADIUS server ip. |
| 116 | * |
| 117 | * @param ip new ip address; null to clear |
| 118 | * @return self |
| 119 | */ |
| 120 | public BasicElementConfig radiusIp(String ip) { |
| 121 | return (BasicElementConfig) setOrClear(RADIUS_IP, ip); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Returns the RADIUS MAC address. |
| 126 | * |
| 127 | * @return mac address or null if not set |
| 128 | */ |
| 129 | public String radiusMac() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 130 | return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Sets the RADIUS MAC address. |
| 135 | * |
| 136 | * @param mac new MAC address; null to clear |
| 137 | * @return self |
| 138 | */ |
| 139 | public BasicElementConfig radiusMac(String mac) { |
| 140 | return (BasicElementConfig) setOrClear(RADIUS_MAC, mac); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Returns the RADIUS MAC address. |
| 145 | * |
| 146 | * @return mac address or null if not set |
| 147 | */ |
| 148 | public String nasMac() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 149 | return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Sets the RADIUS MAC address. |
| 154 | * |
| 155 | * @param mac new MAC address; null to clear |
| 156 | * @return self |
| 157 | */ |
| 158 | public BasicElementConfig nasMac(String mac) { |
| 159 | return (BasicElementConfig) setOrClear(NAS_MAC, mac); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Returns the RADIUS secret. |
| 164 | * |
| 165 | * @return radius secret or null if not set |
| 166 | */ |
| 167 | public String radiusSecret() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 168 | return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Sets the RADIUS secret. |
| 173 | * |
| 174 | * @param secret new MAC address; null to clear |
| 175 | * @return self |
| 176 | */ |
| 177 | public BasicElementConfig radiusSecret(String secret) { |
| 178 | return (BasicElementConfig) setOrClear(RADIUS_SECRET, secret); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Returns the ID of the RADIUS switch. |
| 183 | * |
| 184 | * @return radius switch ID or null if not set |
| 185 | */ |
| 186 | public String radiusSwitch() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 187 | return getStringProperty(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Sets the ID of the RADIUS switch. |
| 192 | * |
| 193 | * @param switchId new RADIUS switch ID; null to clear |
| 194 | * @return self |
| 195 | */ |
| 196 | public BasicElementConfig radiusSwitch(String switchId) { |
| 197 | return (BasicElementConfig) setOrClear(RADIUS_SWITCH, switchId); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Returns the RADIUS port. |
| 202 | * |
| 203 | * @return radius port or null if not set |
| 204 | */ |
| 205 | public long radiusPort() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 206 | return Integer.parseInt(getStringProperty(RADIUS_PORT, DEFAULT_RADIUS_PORT)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Sets the RADIUS port. |
| 211 | * |
| 212 | * @param port new RADIUS port; null to clear |
| 213 | * @return self |
| 214 | */ |
| 215 | public BasicElementConfig radiusPort(long port) { |
| 216 | return (BasicElementConfig) setOrClear(RADIUS_PORT, port); |
| 217 | } |
| 218 | |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 219 | /** |
| 220 | * Returns the RADIUS server UDP port. |
| 221 | * |
| 222 | * @return radius server UDP port. |
| 223 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 224 | public short radiusServerUdpPort() { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 225 | return Short.parseShort(getStringProperty(RADIUS_SERVER_PORT, |
| 226 | DEFAULT_RADIUS_SERVER_PORT)); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Sets the RADIUS port. |
| 231 | * |
| 232 | * @param port new RADIUS UDP port; -1 to clear |
| 233 | * @return self |
| 234 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 235 | public BasicElementConfig radiusServerUdpPort(short port) { |
Ray Milkey | 5d99bd1 | 2015-10-06 15:41:30 -0700 | [diff] [blame] | 236 | return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port); |
| 237 | } |
| 238 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 239 | } |