blob: 4124e80f64a40ceb44b09be81ff8801aa1d9922c [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;
Matt Jeanneret2ff1a782018-06-13 15:24:25 -040020import org.apache.commons.lang3.builder.ToStringBuilder;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010021
22import com.google.common.collect.ImmutableSet;
23
Ray Milkeyfcb623d2015-10-01 16:48:18 -070024import org.onosproject.core.ApplicationId;
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010025import org.onosproject.net.ConnectPoint;
Ray Milkeyfcb623d2015-10-01 16:48:18 -070026import org.onosproject.net.config.Config;
27import org.onosproject.net.config.basics.BasicElementConfig;
28
Jonathan Hart092dfb22015-11-16 23:05:21 -080029import java.net.InetAddress;
30import java.net.UnknownHostException;
31
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010032import java.util.HashSet;
33import java.util.Set;
34
Ray Milkeyfcb623d2015-10-01 16:48:18 -070035/**
36 * Network config for the AAA app.
37 */
Jonathan Hart092dfb22015-11-16 23:05:21 -080038public class AaaConfig extends Config<ApplicationId> {
Ray Milkeyfcb623d2015-10-01 16:48:18 -070039
Jonathan Hartf935b122018-07-11 16:16:02 -070040 private static final String RADIUS_HOST = "radiusHost";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070041 private static final String RADIUS_IP = "radiusIp";
ke han1fe3b0e2017-02-28 09:50:20 +080042 private static final String RADIUS_SERVER_PORT = "radiusServerPort";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070043 private static final String RADIUS_MAC = "radiusMac";
44 private static final String NAS_IP = "nasIp";
45 private static final String NAS_MAC = "nasMac";
46 private static final String RADIUS_SECRET = "radiusSecret";
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010047 private static final String RADIUS_VLAN_ID = "vlanId";
48 private static final String RADIUS_VLAN_PRIORITY_BIT = "radiusPBit";
49 private static final String RADIUS_CONNECTION_TYPE = "radiusConnectionType";
50 private static final String RADIUS_SERVER_CONNECTPOINTS = "radiusServerConnectPoints";
51 // Which packet customizer to use
52 // "packetCustomizer" : "sample" -- Means use SamplePAcketCustomizer
53 // "packetCustomizer" : "default" -- No customization of packets
54 // if param is missing it is treated as default
55 // This class should be a subclass of PacketCustomizer
56 private static final String PACKET_CUSTOMIZER = "packetCustomizer";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070057
58 // RADIUS server IP address
Ray Milkey967776a2015-10-07 14:37:17 -070059 protected static final String DEFAULT_RADIUS_IP = "10.128.10.4";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070060
61 // RADIUS MAC address
62 protected static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10";
63
64 // NAS IP address
Ray Milkey967776a2015-10-07 14:37:17 -070065 protected static final String DEFAULT_NAS_IP = "10.128.9.244";
Ray Milkeyfcb623d2015-10-01 16:48:18 -070066
67 // NAS MAC address
68 protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01";
69
Ray Milkeyfcb623d2015-10-01 16:48:18 -070070 // RADIUS server shared secret
71 protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret";
72
Ray Milkey5d99bd12015-10-06 15:41:30 -070073 // Radius Server UDP Port Number
74 protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812";
75
Amit Ghoshc9ac1e52017-07-28 12:31:18 +010076 // Radius Server Vlan ID
77 protected static final String DEFAULT_RADIUS_VLAN_ID = "4093";
78
79 // Radius Sever P-Bit
80 protected static final String DEFAULT_RADIUS_VLAN_PRIORITY_BIT = "3";
81
82 // Whether to use socket or not to communicate with RADIUS Server
83 protected static final String DEFAULT_RADIUS_CONNECTION_TYPE = "socket";
84
85 // Packet Customizer Default value
86 protected static final String DEFAULT_PACKET_CUSTOMIZER = "default";
87
88
Ray Milkey5d99bd12015-10-06 15:41:30 -070089 /**
90 * Gets the value of a string property, protecting for an empty
91 * JSON object.
92 *
93 * @param name name of the property
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 Milkeyfcb623d2015-10-01 16:48:18 -0700104 /**
105 * Returns the NAS ip.
106 *
107 * @return ip address or null if not set
108 */
109 public InetAddress nasIp() {
110 try {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700111 return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP));
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700112 } 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 Hartf935b122018-07-11 16:16:02 -0700127 public String radiusHostName() {
128 return getStringProperty(RADIUS_HOST, null);
129 }
130
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700131 /**
132 * Returns the RADIUS server ip.
133 *
134 * @return ip address or null if not set
135 */
136 public InetAddress radiusIp() {
137 try {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700138 return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP));
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700139 } 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 Milkey5d99bd12015-10-06 15:41:30 -0700160 return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700161 }
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 Milkey5d99bd12015-10-06 15:41:30 -0700179 return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700180 }
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 Milkey5d99bd12015-10-06 15:41:30 -0700198 return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET);
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700199 }
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 Milkey5d99bd12015-10-06 15:41:30 -0700212 * Returns the RADIUS server UDP port.
213 *
214 * @return radius server UDP port.
215 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800216 public short radiusServerUdpPort() {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700217 return Short.parseShort(getStringProperty(RADIUS_SERVER_PORT,
218 DEFAULT_RADIUS_SERVER_PORT));
219 }
220
221 /**
222 * Sets the RADIUS port.
223 *
224 * @param port new RADIUS UDP port; -1 to clear
225 * @return self
226 */
Jonathan Hart092dfb22015-11-16 23:05:21 -0800227 public BasicElementConfig radiusServerUdpPort(short port) {
Ray Milkey5d99bd12015-10-06 15:41:30 -0700228 return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port);
229 }
230
Amit Ghoshc9ac1e52017-07-28 12:31:18 +0100231 /**
232 * Returns the RADIUS server vlan ID.
233 *
234 * @return Radius Server VLan id or default if not set
235 */
236 public short radiusServerVlanId() {
237 return Short.parseShort(getStringProperty(RADIUS_VLAN_ID, DEFAULT_RADIUS_VLAN_ID));
238 }
239
240 /**
241 * Returns the type of connection to use to communicate with the RADIUS Server.
242 *
243 * @return "socket" or "packet_out"
244 */
245 public String radiusConnectionType() {
246 return getStringProperty(RADIUS_CONNECTION_TYPE, DEFAULT_RADIUS_CONNECTION_TYPE);
247 }
248
249 /**
250 * Returns the RADIUS server p-bit.
251 *
252 * @return Radius Server P-bit to use, default if not set
253 */
254 public byte radiusServerPBit() {
255 return Byte.parseByte(getStringProperty(RADIUS_VLAN_PRIORITY_BIT, DEFAULT_RADIUS_VLAN_PRIORITY_BIT));
256 }
257
258 /**
259 * Returns the PACKET CUSTOMIZER CLASS NAME.
260 *
261 * @return PACKET CUSTOMIZER, default if not set
262 */
263 public String radiusPktCustomizer() {
264 return getStringProperty(PACKET_CUSTOMIZER, DEFAULT_PACKET_CUSTOMIZER);
265 }
266
267 /**
268 * Returns the List of ConnectPoints to reach the Radius Server.
269 *
270 * @return List of ConnectPoints
271 */
272 public Set<ConnectPoint> radiusServerConnectPoints() {
273 if (object == null) {
274 return new HashSet<ConnectPoint>();
275 }
276
277 if (!object.has(RADIUS_SERVER_CONNECTPOINTS)) {
278 return ImmutableSet.of();
279 }
280
281 ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
282 ArrayNode arrayNode = (ArrayNode) object.path(RADIUS_SERVER_CONNECTPOINTS);
283 for (JsonNode jsonNode : arrayNode) {
284 String portName = jsonNode.asText(null);
285 if (portName == null) {
286 return null;
287 }
288 try {
289 builder.add(ConnectPoint.deviceConnectPoint(portName));
290 } catch (IllegalArgumentException e) {
291 return null;
292 }
293 }
294 return builder.build();
295 }
Matt Jeanneret2ff1a782018-06-13 15:24:25 -0400296
297 @Override
298 public String toString() {
299 return ToStringBuilder.reflectionToString(this);
300 }
Ray Milkeyfcb623d2015-10-01 16:48:18 -0700301}