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