blob: a23e0e4786bdd61a8e2ee47d7075444fb87c0e21 [file] [log] [blame]
Ray Milkey57f2e142015-10-01 16:48:18 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkey57f2e142015-10-01 16:48:18 -07003 *
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 */
16package org.onosproject.aaa;
17
Ray Milkey57f2e142015-10-01 16:48:18 -070018import org.onosproject.core.ApplicationId;
19import org.onosproject.net.config.Config;
20import org.onosproject.net.config.basics.BasicElementConfig;
21
Jonathan Hartb92cc512015-11-16 23:05:21 -080022import java.net.InetAddress;
23import java.net.UnknownHostException;
24
Ray Milkey57f2e142015-10-01 16:48:18 -070025/**
26 * Network config for the AAA app.
27 */
Jonathan Hartb92cc512015-11-16 23:05:21 -080028public class AaaConfig extends Config<ApplicationId> {
Ray Milkey57f2e142015-10-01 16:48:18 -070029
30 private static final String RADIUS_IP = "radiusIp";
Ray Milkeyaf86fbf2015-10-06 15:41:30 -070031 private static final String RADIUS_SERVER_PORT = "1812";
Ray Milkey57f2e142015-10-01 16:48:18 -070032 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 Milkey4ed93692015-10-07 14:37:17 -070040 protected static final String DEFAULT_RADIUS_IP = "10.128.10.4";
Ray Milkey57f2e142015-10-01 16:48:18 -070041
42 // RADIUS MAC address
43 protected static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10";
44
45 // NAS IP address
Ray Milkey4ed93692015-10-07 14:37:17 -070046 protected static final String DEFAULT_NAS_IP = "10.128.9.244";
Ray Milkey57f2e142015-10-01 16:48:18 -070047
48 // NAS MAC address
49 protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01";
50
Ray Milkey57f2e142015-10-01 16:48:18 -070051 // 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 Milkeyaf86fbf2015-10-06 15:41:30 -070060 // 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 Milkey57f2e142015-10-01 16:48:18 -070078 /**
79 * Returns the NAS ip.
80 *
81 * @return ip address or null if not set
82 */
83 public InetAddress nasIp() {
84 try {
Ray Milkeyaf86fbf2015-10-06 15:41:30 -070085 return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP));
Ray Milkey57f2e142015-10-01 16:48:18 -070086 } 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 Milkeyaf86fbf2015-10-06 15:41:30 -0700108 return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP));
Ray Milkey57f2e142015-10-01 16:48:18 -0700109 } 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 Milkeyaf86fbf2015-10-06 15:41:30 -0700130 return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC);
Ray Milkey57f2e142015-10-01 16:48:18 -0700131 }
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 Milkeyaf86fbf2015-10-06 15:41:30 -0700149 return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC);
Ray Milkey57f2e142015-10-01 16:48:18 -0700150 }
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 Milkeyaf86fbf2015-10-06 15:41:30 -0700168 return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET);
Ray Milkey57f2e142015-10-01 16:48:18 -0700169 }
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 Milkeyaf86fbf2015-10-06 15:41:30 -0700187 return getStringProperty(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH);
Ray Milkey57f2e142015-10-01 16:48:18 -0700188 }
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 Milkeyaf86fbf2015-10-06 15:41:30 -0700206 return Integer.parseInt(getStringProperty(RADIUS_PORT, DEFAULT_RADIUS_PORT));
Ray Milkey57f2e142015-10-01 16:48:18 -0700207 }
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 Milkeyaf86fbf2015-10-06 15:41:30 -0700219 /**
220 * Returns the RADIUS server UDP port.
221 *
222 * @return radius server UDP port.
223 */
Jonathan Hartb92cc512015-11-16 23:05:21 -0800224 public short radiusServerUdpPort() {
Ray Milkeyaf86fbf2015-10-06 15:41:30 -0700225 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 Hartb92cc512015-11-16 23:05:21 -0800235 public BasicElementConfig radiusServerUdpPort(short port) {
Ray Milkeyaf86fbf2015-10-06 15:41:30 -0700236 return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port);
237 }
238
Ray Milkey57f2e142015-10-01 16:48:18 -0700239}