Ray Milkey
Committed by Gerrit Code Review

More AAA refactoring

- parameterize the UDP port of the RADIUS server
- clean up some unused constants
- refactor config code to reduce repetitive code

Change-Id: I797dabd12c8ccd522f1ab0812c2b03da7264f2c0
...@@ -112,6 +112,9 @@ public class AAA { ...@@ -112,6 +112,9 @@ public class AAA {
112 // RADIUS port number 112 // RADIUS port number
113 protected long radiusPort; 113 protected long radiusPort;
114 114
115 + // RADIUS server TCP port number
116 + protected short radiusServerPort;
117 +
115 // our application-specific event handler 118 // our application-specific event handler
116 private ReactivePacketProcessor processor = new ReactivePacketProcessor(); 119 private ReactivePacketProcessor processor = new ReactivePacketProcessor();
117 120
...@@ -206,8 +209,8 @@ public class AAA { ...@@ -206,8 +209,8 @@ public class AAA {
206 TrafficSelector radSelector = DefaultTrafficSelector.builder() 209 TrafficSelector radSelector = DefaultTrafficSelector.builder()
207 .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) 210 .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
208 .matchIPProtocol(IPv4.PROTOCOL_UDP) 211 .matchIPProtocol(IPv4.PROTOCOL_UDP)
209 - .matchUdpDst(TpPort.tpPort(1812)) 212 + .matchUdpDst(TpPort.tpPort(radiusServerPort))
210 - .matchUdpSrc(TpPort.tpPort(1812)) 213 + .matchUdpSrc(TpPort.tpPort(radiusServerPort))
211 .build(); 214 .build();
212 packetService.requestPackets(radSelector, CONTROL, appId); 215 packetService.requestPackets(radSelector, CONTROL, appId);
213 } 216 }
...@@ -223,8 +226,8 @@ public class AAA { ...@@ -223,8 +226,8 @@ public class AAA {
223 TrafficSelector radSelector = DefaultTrafficSelector.builder() 226 TrafficSelector radSelector = DefaultTrafficSelector.builder()
224 .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) 227 .matchEthType(EthType.EtherType.IPV4.ethType().toShort())
225 .matchIPProtocol(IPv4.PROTOCOL_UDP) 228 .matchIPProtocol(IPv4.PROTOCOL_UDP)
226 - .matchUdpDst(TpPort.tpPort(1812)) 229 + .matchUdpDst(TpPort.tpPort(radiusServerPort))
227 - .matchUdpSrc(TpPort.tpPort(1812)) 230 + .matchUdpSrc(TpPort.tpPort(radiusServerPort))
228 .build(); 231 .build();
229 packetService.cancelPackets(radSelector, CONTROL, appId); 232 packetService.cancelPackets(radSelector, CONTROL, appId);
230 } 233 }
...@@ -452,8 +455,8 @@ public class AAA { ...@@ -452,8 +455,8 @@ public class AAA {
452 IPv4 ip4Packet = new IPv4(); 455 IPv4 ip4Packet = new IPv4();
453 Ethernet ethPkt = new Ethernet(); 456 Ethernet ethPkt = new Ethernet();
454 radiusMessage.setParent(udp); 457 radiusMessage.setParent(udp);
455 - udp.setDestinationPort((short) 1812); 458 + udp.setDestinationPort(radiusServerPort);
456 - udp.setSourcePort((short) 1812); // TODO: make this configurable 459 + udp.setSourcePort(radiusServerPort);
457 udp.setPayload(radiusMessage); 460 udp.setPayload(radiusMessage);
458 udp.setParent(ip4Packet); 461 udp.setParent(ip4Packet);
459 ip4Packet.setSourceAddress(AAA.this.nasIpAddress.getHostAddress()); 462 ip4Packet.setSourceAddress(AAA.this.nasIpAddress.getHostAddress());
...@@ -524,15 +527,9 @@ public class AAA { ...@@ -524,15 +527,9 @@ public class AAA {
524 if (newCfg.radiusPort() != -1) { 527 if (newCfg.radiusPort() != -1) {
525 radiusPort = newCfg.radiusPort(); 528 radiusPort = newCfg.radiusPort();
526 } 529 }
527 - 530 + if (newCfg.radiusServerUDPPort() != -1) {
528 - log.info("AAA app configuration:"); 531 + radiusServerPort = newCfg.radiusServerUDPPort();
529 - log.info("NAS IP is {}", nasIpAddress); 532 + }
530 - log.info("RADIUS IP is {}", radiusIpAddress);
531 - log.info("NAS MAC is {}", nasMacAddress);
532 - log.info("RADIUS MAC is {}", radiusMacAddress);
533 - log.info("RADIUS secret is {}", radiusSecret);
534 - log.info("RADIUS switch is {}", radiusSwitch);
535 - log.info("RADIUS port is {}", radiusPort);
536 } 533 }
537 534
538 @Override 535 @Override
......
...@@ -28,6 +28,7 @@ import org.onosproject.net.config.basics.BasicElementConfig; ...@@ -28,6 +28,7 @@ import org.onosproject.net.config.basics.BasicElementConfig;
28 public class AAAConfig extends Config<ApplicationId> { 28 public class AAAConfig extends Config<ApplicationId> {
29 29
30 private static final String RADIUS_IP = "radiusIp"; 30 private static final String RADIUS_IP = "radiusIp";
31 + private static final String RADIUS_SERVER_PORT = "1812";
31 private static final String RADIUS_MAC = "radiusMac"; 32 private static final String RADIUS_MAC = "radiusMac";
32 private static final String NAS_IP = "nasIp"; 33 private static final String NAS_IP = "nasIp";
33 private static final String NAS_MAC = "nasMac"; 34 private static final String NAS_MAC = "nasMac";
...@@ -47,9 +48,6 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -47,9 +48,6 @@ public class AAAConfig extends Config<ApplicationId> {
47 // NAS MAC address 48 // NAS MAC address
48 protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01"; 49 protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01";
49 50
50 - // RADIUS uplink port
51 - protected static final int DEFAULT_RADIUS_UPLINK = 2;
52 -
53 // RADIUS server shared secret 51 // RADIUS server shared secret
54 protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; 52 protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret";
55 53
...@@ -59,6 +57,24 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -59,6 +57,24 @@ public class AAAConfig extends Config<ApplicationId> {
59 // Radius Port Number 57 // Radius Port Number
60 protected static final String DEFAULT_RADIUS_PORT = "129"; 58 protected static final String DEFAULT_RADIUS_PORT = "129";
61 59
60 + // 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 +
62 /** 78 /**
63 * Returns the NAS ip. 79 * Returns the NAS ip.
64 * 80 *
...@@ -66,10 +82,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -66,10 +82,7 @@ public class AAAConfig extends Config<ApplicationId> {
66 */ 82 */
67 public InetAddress nasIp() { 83 public InetAddress nasIp() {
68 try { 84 try {
69 - if (object == null) { 85 + return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP));
70 - return InetAddress.getByName(DEFAULT_NAS_IP);
71 - }
72 - return InetAddress.getByName(get(NAS_IP, DEFAULT_NAS_IP));
73 } catch (UnknownHostException e) { 86 } catch (UnknownHostException e) {
74 return null; 87 return null;
75 } 88 }
...@@ -92,10 +105,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -92,10 +105,7 @@ public class AAAConfig extends Config<ApplicationId> {
92 */ 105 */
93 public InetAddress radiusIp() { 106 public InetAddress radiusIp() {
94 try { 107 try {
95 - if (object == null) { 108 + return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP));
96 - return InetAddress.getByName(DEFAULT_RADIUS_IP);
97 - }
98 - return InetAddress.getByName(get(RADIUS_IP, DEFAULT_RADIUS_IP));
99 } catch (UnknownHostException e) { 109 } catch (UnknownHostException e) {
100 return null; 110 return null;
101 } 111 }
...@@ -117,10 +127,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -117,10 +127,7 @@ public class AAAConfig extends Config<ApplicationId> {
117 * @return mac address or null if not set 127 * @return mac address or null if not set
118 */ 128 */
119 public String radiusMac() { 129 public String radiusMac() {
120 - if (object == null) { 130 + return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC);
121 - return DEFAULT_RADIUS_MAC;
122 - }
123 - return get(RADIUS_MAC, DEFAULT_RADIUS_MAC);
124 } 131 }
125 132
126 /** 133 /**
...@@ -139,10 +146,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -139,10 +146,7 @@ public class AAAConfig extends Config<ApplicationId> {
139 * @return mac address or null if not set 146 * @return mac address or null if not set
140 */ 147 */
141 public String nasMac() { 148 public String nasMac() {
142 - if (object == null) { 149 + return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC);
143 - return DEFAULT_NAS_MAC;
144 - }
145 - return get(NAS_MAC, DEFAULT_NAS_MAC);
146 } 150 }
147 151
148 /** 152 /**
...@@ -161,10 +165,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -161,10 +165,7 @@ public class AAAConfig extends Config<ApplicationId> {
161 * @return radius secret or null if not set 165 * @return radius secret or null if not set
162 */ 166 */
163 public String radiusSecret() { 167 public String radiusSecret() {
164 - if (object == null) { 168 + return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET);
165 - return DEFAULT_RADIUS_SECRET;
166 - }
167 - return get(RADIUS_SECRET, DEFAULT_RADIUS_SECRET);
168 } 169 }
169 170
170 /** 171 /**
...@@ -183,10 +184,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -183,10 +184,7 @@ public class AAAConfig extends Config<ApplicationId> {
183 * @return radius switch ID or null if not set 184 * @return radius switch ID or null if not set
184 */ 185 */
185 public String radiusSwitch() { 186 public String radiusSwitch() {
186 - if (object == null) { 187 + return getStringProperty(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH);
187 - return DEFAULT_RADIUS_SWITCH;
188 - }
189 - return get(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH);
190 } 188 }
191 189
192 /** 190 /**
...@@ -205,10 +203,7 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -205,10 +203,7 @@ public class AAAConfig extends Config<ApplicationId> {
205 * @return radius port or null if not set 203 * @return radius port or null if not set
206 */ 204 */
207 public long radiusPort() { 205 public long radiusPort() {
208 - if (object == null) { 206 + return Integer.parseInt(getStringProperty(RADIUS_PORT, DEFAULT_RADIUS_PORT));
209 - return Integer.parseInt(DEFAULT_RADIUS_PORT);
210 - }
211 - return Integer.parseInt(get(RADIUS_PORT, "-1"));
212 } 207 }
213 208
214 /** 209 /**
...@@ -221,4 +216,24 @@ public class AAAConfig extends Config<ApplicationId> { ...@@ -221,4 +216,24 @@ public class AAAConfig extends Config<ApplicationId> {
221 return (BasicElementConfig) setOrClear(RADIUS_PORT, port); 216 return (BasicElementConfig) setOrClear(RADIUS_PORT, port);
222 } 217 }
223 218
219 + /**
220 + * Returns the RADIUS server UDP port.
221 + *
222 + * @return radius server UDP port.
223 + */
224 + public short radiusServerUDPPort() {
225 + 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 + */
235 + public BasicElementConfig radiusServerUDPPort(short port) {
236 + return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port);
237 + }
238 +
224 } 239 }
......
...@@ -495,11 +495,6 @@ public class AAATest { ...@@ -495,11 +495,6 @@ public class AAATest {
495 assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED)); 495 assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED));
496 } 496 }
497 497
498 -
499 - private static final String RADIUS_SECRET = "radiusSecret";
500 - private static final String RADIUS_SWITCH = "radiusSwitch";
501 - private static final String RADIUS_PORT = "radiusPort";
502 -
503 /** 498 /**
504 * Tests the default configuration. 499 * Tests the default configuration.
505 */ 500 */
......