blob: 8ffdf002274139b55c6ce2c0877c97c762225c62 [file] [log] [blame]
Ray Milkeyfcb623d2015-10-01 16:48:18 -07001/*
Brian O'Connor4e33be22017-08-03 22:45:46 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkeyfcb623d2015-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 */
alshabib6d527452016-06-01 18:00:47 -070016package org.opencord.aaa;
Ray Milkeyfcb623d2015-10-01 16:48:18 -070017
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ArrayNode;
20
21import com.google.common.collect.ImmutableSet;
22
Ray Milkeyfcb623d2015-10-01 16:48:18 -070023import org.onosproject.core.ApplicationId;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010024import org.onosproject.net.ConnectPoint;
Ray Milkeyfcb623d2015-10-01 16:48:18 -070025import org.onosproject.net.config.Config;
26import org.onosproject.net.config.basics.BasicElementConfig;
27
Jonathan Hart092dfb22015-11-16 23:05:21 -080028import java.net.InetAddress;
29import java.net.UnknownHostException;
30
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010031import java.util.HashSet;
32import java.util.Set;
33
Ray Milkeyfcb623d2015-10-01 16:48:18 -070034/**
35 * Network config for the AAA app.
36 */
Jonathan Hart092dfb22015-11-16 23:05:21 -080037public class AaaConfig extends Config<ApplicationId> {
Ray Milkeyfcb623d2015-10-01 16:48:18 -070038
39 private static final String RADIUS_IP = "radiusIp";
ke han1fe3b0e2017-02-28 09:50:20 +080040 private static final String RADIUS_SERVER_PORT = "radiusServerPort";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070041 private static final String RADIUS_MAC = "radiusMac";
42 private static final String NAS_IP = "nasIp";
43 private static final String NAS_MAC = "nasMac";
44 private static final String RADIUS_SECRET = "radiusSecret";
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010045 private static final String RADIUS_VLAN_ID = "vlanId";
46 private static final String RADIUS_VLAN_PRIORITY_BIT = "radiusPBit";
47 private static final String RADIUS_CONNECTION_TYPE = "radiusConnectionType";
48 private static final String RADIUS_SERVER_CONNECTPOINTS = "radiusServerConnectPoints";
49 // Which packet customizer to use
50 // "packetCustomizer" : "sample" -- Means use SamplePAcketCustomizer
51 // "packetCustomizer" : "default" -- No customization of packets
52 // if param is missing it is treated as default
53 // This class should be a subclass of PacketCustomizer
54 private static final String PACKET_CUSTOMIZER = "packetCustomizer";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070055
56 // RADIUS server IP address
Ray Milkey967776a2015-10-07 14:37:17 -070057 protected static final String DEFAULT_RADIUS_IP = "10.128.10.4";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070058
59 // RADIUS MAC address
60 protected static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10";
61
62 // NAS IP address
Ray Milkey967776a2015-10-07 14:37:17 -070063 protected static final String DEFAULT_NAS_IP = "10.128.9.244";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070064
65 // NAS MAC address
66 protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01";
67
Ray Milkeyfcb623d2015-10-01 16:48:18 -070068 // RADIUS server shared secret
69 protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret";
70
Ray Milkey5d99bd12015-10-06 15:41:30 -070071 // Radius Server UDP Port Number
72 protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812";
73
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010074 // Radius Server Vlan ID
75 protected static final String DEFAULT_RADIUS_VLAN_ID = "4093";
76
77 // Radius Sever P-Bit
78 protected static final String DEFAULT_RADIUS_VLAN_PRIORITY_BIT = "3";
79
80 // Whether to use socket or not to communicate with RADIUS Server
81 protected static final String DEFAULT_RADIUS_CONNECTION_TYPE = "socket";
82
83 // Packet Customizer Default value
84 protected static final String DEFAULT_PACKET_CUSTOMIZER = "default";
85
86
Ray Milkey5d99bd12015-10-06 15:41:30 -070087 /**
88 * Gets the value of a string property, protecting for an empty
89 * JSON object.
90 *
91 * @param name name of the property
92 * @param defaultValue default value if none has been specified
93 * @return String value if one os found, default value otherwise
94 */
95 private String getStringProperty(String name, String defaultValue) {
96 if (object == null) {
97 return defaultValue;
98 }
99 return get(name, defaultValue);
100 }
101
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700102 /**
103 * Returns the NAS ip.
104 *
105 * @return ip address or null if not set
106 */
107 public InetAddress nasIp() {
108 try {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700109 return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP));
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700110 } catch (UnknownHostException e) {
111 return null;
112 }
113 }
114
115 /**
116 * Sets the NAS ip.
117 *
118 * @param ip new ip address; null to clear
119 * @return self
120 */
121 public BasicElementConfig nasIp(String ip) {
122 return (BasicElementConfig) setOrClear(NAS_IP, ip);
123 }
124
125 /**
126 * Returns the RADIUS server ip.
127 *
128 * @return ip address or null if not set
129 */
130 public InetAddress radiusIp() {
131 try {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700132 return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP));
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700133 } catch (UnknownHostException e) {
134 return null;
135 }
136 }
137
138 /**
139 * Sets the RADIUS server ip.
140 *
141 * @param ip new ip address; null to clear
142 * @return self
143 */
144 public BasicElementConfig radiusIp(String ip) {
145 return (BasicElementConfig) setOrClear(RADIUS_IP, ip);
146 }
147
148 /**
149 * Returns the RADIUS MAC address.
150 *
151 * @return mac address or null if not set
152 */
153 public String radiusMac() {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700154 return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700155 }
156
157 /**
158 * Sets the RADIUS MAC address.
159 *
160 * @param mac new MAC address; null to clear
161 * @return self
162 */
163 public BasicElementConfig radiusMac(String mac) {
164 return (BasicElementConfig) setOrClear(RADIUS_MAC, mac);
165 }
166
167 /**
168 * Returns the RADIUS MAC address.
169 *
170 * @return mac address or null if not set
171 */
172 public String nasMac() {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700173 return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700174 }
175
176 /**
177 * Sets the RADIUS MAC address.
178 *
179 * @param mac new MAC address; null to clear
180 * @return self
181 */
182 public BasicElementConfig nasMac(String mac) {
183 return (BasicElementConfig) setOrClear(NAS_MAC, mac);
184 }
185
186 /**
187 * Returns the RADIUS secret.
188 *
189 * @return radius secret or null if not set
190 */
191 public String radiusSecret() {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700192 return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700193 }
194
195 /**
196 * Sets the RADIUS secret.
197 *
198 * @param secret new MAC address; null to clear
199 * @return self
200 */
201 public BasicElementConfig radiusSecret(String secret) {
202 return (BasicElementConfig) setOrClear(RADIUS_SECRET, secret);
203 }
204
205 /**
Ray Milkey5d99bd12015-10-06 15:41:30 -0700206 * Returns the RADIUS server UDP port.
207 *
208 * @return radius server UDP port.
209 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800210 public short radiusServerUdpPort() {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700211 return Short.parseShort(getStringProperty(RADIUS_SERVER_PORT,
212 DEFAULT_RADIUS_SERVER_PORT));
213 }
214
215 /**
216 * Sets the RADIUS port.
217 *
218 * @param port new RADIUS UDP port; -1 to clear
219 * @return self
220 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800221 public BasicElementConfig radiusServerUdpPort(short port) {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700222 return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port);
223 }
224
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100225 /**
226 * Returns the RADIUS server vlan ID.
227 *
228 * @return Radius Server VLan id or default if not set
229 */
230 public short radiusServerVlanId() {
231 return Short.parseShort(getStringProperty(RADIUS_VLAN_ID, DEFAULT_RADIUS_VLAN_ID));
232 }
233
234 /**
235 * Returns the type of connection to use to communicate with the RADIUS Server.
236 *
237 * @return "socket" or "packet_out"
238 */
239 public String radiusConnectionType() {
240 return getStringProperty(RADIUS_CONNECTION_TYPE, DEFAULT_RADIUS_CONNECTION_TYPE);
241 }
242
243 /**
244 * Returns the RADIUS server p-bit.
245 *
246 * @return Radius Server P-bit to use, default if not set
247 */
248 public byte radiusServerPBit() {
249 return Byte.parseByte(getStringProperty(RADIUS_VLAN_PRIORITY_BIT, DEFAULT_RADIUS_VLAN_PRIORITY_BIT));
250 }
251
252 /**
253 * Returns the PACKET CUSTOMIZER CLASS NAME.
254 *
255 * @return PACKET CUSTOMIZER, default if not set
256 */
257 public String radiusPktCustomizer() {
258 return getStringProperty(PACKET_CUSTOMIZER, DEFAULT_PACKET_CUSTOMIZER);
259 }
260
261 /**
262 * Returns the List of ConnectPoints to reach the Radius Server.
263 *
264 * @return List of ConnectPoints
265 */
266 public Set<ConnectPoint> radiusServerConnectPoints() {
267 if (object == null) {
268 return new HashSet<ConnectPoint>();
269 }
270
271 if (!object.has(RADIUS_SERVER_CONNECTPOINTS)) {
272 return ImmutableSet.of();
273 }
274
275 ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
276 ArrayNode arrayNode = (ArrayNode) object.path(RADIUS_SERVER_CONNECTPOINTS);
277 for (JsonNode jsonNode : arrayNode) {
278 String portName = jsonNode.asText(null);
279 if (portName == null) {
280 return null;
281 }
282 try {
283 builder.add(ConnectPoint.deviceConnectPoint(portName));
284 } catch (IllegalArgumentException e) {
285 return null;
286 }
287 }
288 return builder.build();
289 }
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700290}