Committed by
Gerrit Code Review
AAA App refactoring
- optimized lookup of state machines - modified getter/setter method names to match ONOS project standards - made StateMachine local members private and add accesor methods - added unit tests for StateMachine lookups Change-Id: I5704ddc4d8b1b3c887be1262f2edd78965e4a8bf
Showing
3 changed files
with
98 additions
and
20 deletions
This diff is collapsed. Click to expand it.
... | @@ -18,13 +18,16 @@ | ... | @@ -18,13 +18,16 @@ |
18 | 18 | ||
19 | package org.onosproject.aaa; | 19 | package org.onosproject.aaa; |
20 | 20 | ||
21 | +import java.util.BitSet; | ||
22 | +import java.util.Map; | ||
23 | + | ||
21 | import org.onlab.packet.MacAddress; | 24 | import org.onlab.packet.MacAddress; |
22 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
23 | import org.onosproject.xosintegration.VoltTenant; | 26 | import org.onosproject.xosintegration.VoltTenant; |
24 | import org.onosproject.xosintegration.VoltTenantService; | 27 | import org.onosproject.xosintegration.VoltTenantService; |
25 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
26 | 29 | ||
27 | -import java.util.BitSet; | 30 | +import com.google.common.collect.Maps; |
28 | 31 | ||
29 | import static org.slf4j.LoggerFactory.getLogger; | 32 | import static org.slf4j.LoggerFactory.getLogger; |
30 | 33 | ||
... | @@ -58,9 +61,9 @@ class StateMachine { | ... | @@ -58,9 +61,9 @@ class StateMachine { |
58 | private byte[] requestAuthenticator; | 61 | private byte[] requestAuthenticator; |
59 | 62 | ||
60 | // Supplicant connectivity info | 63 | // Supplicant connectivity info |
61 | - protected ConnectPoint supplicantConnectpoint; | 64 | + private ConnectPoint supplicantConnectpoint; |
62 | - protected MacAddress supplicantAddress; | 65 | + private MacAddress supplicantAddress; |
63 | - protected short vlanId; | 66 | + private short vlanId; |
64 | 67 | ||
65 | private String sessionId = null; | 68 | private String sessionId = null; |
66 | 69 | ||
... | @@ -109,8 +112,28 @@ class StateMachine { | ... | @@ -109,8 +112,28 @@ class StateMachine { |
109 | 112 | ||
110 | private int currentState = STATE_IDLE; | 113 | private int currentState = STATE_IDLE; |
111 | 114 | ||
115 | + // Maps of state machines. Each state machine is represented by an | ||
116 | + // unique identifier on the switch: dpid + port number | ||
117 | + private static Map<String, StateMachine> sessionIdMap; | ||
118 | + private static Map<Integer, StateMachine> identifierMap; | ||
112 | 119 | ||
113 | - /** | 120 | + public static void initializeMaps() { |
121 | + sessionIdMap = Maps.newConcurrentMap(); | ||
122 | + identifierMap = Maps.newConcurrentMap(); | ||
123 | + } | ||
124 | + | ||
125 | + public static void destroyMaps() { | ||
126 | + sessionIdMap = null; | ||
127 | + identifierMap = null; | ||
128 | + } | ||
129 | + | ||
130 | + public static StateMachine lookupStateMachineById(byte identifier) { | ||
131 | + return identifierMap.get((int) identifier); | ||
132 | + } | ||
133 | + | ||
134 | + public static StateMachine lookupStateMachineBySessionId(String sessionId) { | ||
135 | + return sessionIdMap.get(sessionId); | ||
136 | + } /** | ||
114 | * State Machine Constructor. | 137 | * State Machine Constructor. |
115 | * | 138 | * |
116 | * @param sessionId session Id represented by the switch dpid + port number | 139 | * @param sessionId session Id represented by the switch dpid + port number |
... | @@ -120,15 +143,69 @@ class StateMachine { | ... | @@ -120,15 +143,69 @@ class StateMachine { |
120 | log.info("Creating a new state machine for {}", sessionId); | 143 | log.info("Creating a new state machine for {}", sessionId); |
121 | this.sessionId = sessionId; | 144 | this.sessionId = sessionId; |
122 | this.voltService = voltService; | 145 | this.voltService = voltService; |
146 | + sessionIdMap.put(sessionId, this); | ||
147 | + } | ||
123 | 148 | ||
149 | + /** | ||
150 | + * Gets the connect point for the supplicant side. | ||
151 | + * | ||
152 | + * @return supplicant connect point | ||
153 | + */ | ||
154 | + public ConnectPoint supplicantConnectpoint() { | ||
155 | + return supplicantConnectpoint; | ||
156 | + } | ||
157 | + | ||
158 | + /** | ||
159 | + * Sets the supplicant side connect point. | ||
160 | + * | ||
161 | + * @param supplicantConnectpoint supplicant select point. | ||
162 | + */ | ||
163 | + public void setSupplicantConnectpoint(ConnectPoint supplicantConnectpoint) { | ||
164 | + this.supplicantConnectpoint = supplicantConnectpoint; | ||
124 | } | 165 | } |
125 | 166 | ||
126 | /** | 167 | /** |
127 | - * Get the client id that is requesting for access. | 168 | + * Gets the MAC address of the supplicant. |
169 | + * | ||
170 | + * @return supplicant MAC address | ||
171 | + */ | ||
172 | + public MacAddress supplicantAddress() { | ||
173 | + return supplicantAddress; | ||
174 | + } | ||
175 | + | ||
176 | + /** | ||
177 | + * Sets the supplicant MAC address. | ||
178 | + * | ||
179 | + * @param supplicantAddress new supplicant MAC address | ||
180 | + */ | ||
181 | + public void setSupplicantAddress(MacAddress supplicantAddress) { | ||
182 | + this.supplicantAddress = supplicantAddress; | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Gets the client's Vlan ID. | ||
187 | + * | ||
188 | + * @return client vlan ID | ||
189 | + */ | ||
190 | + public short vlanId() { | ||
191 | + return vlanId; | ||
192 | + } | ||
193 | + | ||
194 | + /** | ||
195 | + * Sets the client's vlan ID. | ||
196 | + * | ||
197 | + * @param vlanId new client vlan ID | ||
198 | + */ | ||
199 | + public void setVlanId(short vlanId) { | ||
200 | + this.vlanId = vlanId; | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * Gets the client id that is requesting for access. | ||
128 | * | 205 | * |
129 | * @return The client id. | 206 | * @return The client id. |
130 | */ | 207 | */ |
131 | - public String getSessionId() { | 208 | + public String sessionId() { |
132 | return this.sessionId; | 209 | return this.sessionId; |
133 | } | 210 | } |
134 | 211 | ||
... | @@ -178,11 +255,11 @@ class StateMachine { | ... | @@ -178,11 +255,11 @@ class StateMachine { |
178 | } | 255 | } |
179 | 256 | ||
180 | /** | 257 | /** |
181 | - * Get the challenge EAP identifier set by the RADIUS. | 258 | + * Gets the challenge EAP identifier set by the RADIUS. |
182 | * | 259 | * |
183 | * @return The challenge EAP identifier. | 260 | * @return The challenge EAP identifier. |
184 | */ | 261 | */ |
185 | - protected byte getChallengeIdentifier() { | 262 | + protected byte challengeIdentifier() { |
186 | return this.challengeIdentifier; | 263 | return this.challengeIdentifier; |
187 | } | 264 | } |
188 | 265 | ||
... | @@ -198,11 +275,11 @@ class StateMachine { | ... | @@ -198,11 +275,11 @@ class StateMachine { |
198 | } | 275 | } |
199 | 276 | ||
200 | /** | 277 | /** |
201 | - * Get the challenge state set by the RADIUS. | 278 | + * Gets the challenge state set by the RADIUS. |
202 | * | 279 | * |
203 | * @return The challenge state. | 280 | * @return The challenge state. |
204 | */ | 281 | */ |
205 | - protected byte[] getChallengeState() { | 282 | + protected byte[] challengeState() { |
206 | return this.challengeState; | 283 | return this.challengeState; |
207 | } | 284 | } |
208 | 285 | ||
... | @@ -217,16 +294,16 @@ class StateMachine { | ... | @@ -217,16 +294,16 @@ class StateMachine { |
217 | 294 | ||
218 | 295 | ||
219 | /** | 296 | /** |
220 | - * Get the username. | 297 | + * Gets the username. |
221 | * | 298 | * |
222 | * @return The requestAuthenticator. | 299 | * @return The requestAuthenticator. |
223 | */ | 300 | */ |
224 | - protected byte[] getReqeustAuthenticator() { | 301 | + protected byte[] requestAuthenticator() { |
225 | return this.requestAuthenticator; | 302 | return this.requestAuthenticator; |
226 | } | 303 | } |
227 | 304 | ||
228 | /** | 305 | /** |
229 | - * Set the username. | 306 | + * Sets the authenticator. |
230 | * | 307 | * |
231 | * @param authenticator The username sent to the RADIUS upon access request. | 308 | * @param authenticator The username sent to the RADIUS upon access request. |
232 | */ | 309 | */ |
... | @@ -236,11 +313,11 @@ class StateMachine { | ... | @@ -236,11 +313,11 @@ class StateMachine { |
236 | 313 | ||
237 | 314 | ||
238 | /** | 315 | /** |
239 | - * Get the username. | 316 | + * Gets the username. |
240 | * | 317 | * |
241 | * @return The username. | 318 | * @return The username. |
242 | */ | 319 | */ |
243 | - protected byte[] getUsername() { | 320 | + protected byte[] username() { |
244 | return this.username; | 321 | return this.username; |
245 | } | 322 | } |
246 | 323 | ||
... | @@ -249,7 +326,7 @@ class StateMachine { | ... | @@ -249,7 +326,7 @@ class StateMachine { |
249 | * | 326 | * |
250 | * @return The state machine identifier. | 327 | * @return The state machine identifier. |
251 | */ | 328 | */ |
252 | - public byte getIdentifier() { | 329 | + public byte identifier() { |
253 | return (byte) this.identifier; | 330 | return (byte) this.identifier; |
254 | } | 331 | } |
255 | 332 | ||
... | @@ -284,6 +361,7 @@ class StateMachine { | ... | @@ -284,6 +361,7 @@ class StateMachine { |
284 | //move to the next state | 361 | //move to the next state |
285 | next(TRANSITION_START); | 362 | next(TRANSITION_START); |
286 | createIdentifier(); | 363 | createIdentifier(); |
364 | + identifierMap.put(identifier, this); | ||
287 | } | 365 | } |
288 | 366 | ||
289 | /** | 367 | /** |
... | @@ -349,16 +427,16 @@ class StateMachine { | ... | @@ -349,16 +427,16 @@ class StateMachine { |
349 | } | 427 | } |
350 | 428 | ||
351 | /** | 429 | /** |
352 | - * Get the current state. | 430 | + * Gets the current state. |
353 | * | 431 | * |
354 | * @return The current state. Could be STATE_IDLE, STATE_STARTED, STATE_PENDING, STATE_AUTHORIZED, | 432 | * @return The current state. Could be STATE_IDLE, STATE_STARTED, STATE_PENDING, STATE_AUTHORIZED, |
355 | * STATE_UNAUTHORIZED. | 433 | * STATE_UNAUTHORIZED. |
356 | */ | 434 | */ |
357 | - public int getState() { | 435 | + public int state() { |
358 | return currentState; | 436 | return currentState; |
359 | } | 437 | } |
360 | 438 | ||
361 | - | 439 | + @Override |
362 | public String toString() { | 440 | public String toString() { |
363 | return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" + | 441 | return ("sessionId: " + this.sessionId) + "\t" + ("identifier: " + this.identifier) + "\t" + |
364 | ("state: " + this.currentState); | 442 | ("state: " + this.currentState); | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment