Committed by
Gerrit Code Review
Cleaned up AAA app now it's in the ONOS core.
Moved packets into the packet library, minor app cleanups and javadoc. Change-Id: I7ee04d09f82051fdb2a9bcfe577cb163661d5055
Showing
7 changed files
with
352 additions
and
234 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.aaa; | 16 | package org.onosproject.aaa; |
17 | 17 | ||
18 | import com.google.common.base.Strings; | 18 | import com.google.common.base.Strings; |
19 | +import com.google.common.collect.Maps; | ||
19 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
21 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -23,19 +24,20 @@ import org.apache.felix.scr.annotations.Modified; | ... | @@ -23,19 +24,20 @@ import org.apache.felix.scr.annotations.Modified; |
23 | import org.apache.felix.scr.annotations.Property; | 24 | import org.apache.felix.scr.annotations.Property; |
24 | import org.apache.felix.scr.annotations.Reference; | 25 | import org.apache.felix.scr.annotations.Reference; |
25 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
27 | +import org.onlab.packet.DeserializationException; | ||
28 | +import org.onlab.packet.EAP; | ||
29 | +import org.onlab.packet.EAPOL; | ||
30 | +import org.onlab.packet.EthType; | ||
26 | import org.onlab.packet.Ethernet; | 31 | import org.onlab.packet.Ethernet; |
27 | import org.onlab.packet.IPv4; | 32 | import org.onlab.packet.IPv4; |
28 | import org.onlab.packet.Ip4Address; | 33 | import org.onlab.packet.Ip4Address; |
29 | import org.onlab.packet.IpAddress; | 34 | import org.onlab.packet.IpAddress; |
30 | import org.onlab.packet.MacAddress; | 35 | import org.onlab.packet.MacAddress; |
36 | +import org.onlab.packet.RADIUS; | ||
37 | +import org.onlab.packet.RADIUSAttribute; | ||
31 | import org.onlab.packet.UDP; | 38 | import org.onlab.packet.UDP; |
32 | import org.onlab.packet.VlanId; | 39 | import org.onlab.packet.VlanId; |
33 | import org.onlab.util.Tools; | 40 | import org.onlab.util.Tools; |
34 | -import org.onosproject.aaa.packet.EAP; | ||
35 | -import org.onosproject.aaa.packet.EAPEthernet; | ||
36 | -import org.onosproject.aaa.packet.EAPOL; | ||
37 | -import org.onosproject.aaa.packet.RADIUS; | ||
38 | -import org.onosproject.aaa.packet.RADIUSAttribute; | ||
39 | import org.onosproject.cfg.ComponentConfigService; | 41 | import org.onosproject.cfg.ComponentConfigService; |
40 | import org.onosproject.core.ApplicationId; | 42 | import org.onosproject.core.ApplicationId; |
41 | import org.onosproject.core.CoreService; | 43 | import org.onosproject.core.CoreService; |
... | @@ -45,11 +47,9 @@ import org.onosproject.net.Host; | ... | @@ -45,11 +47,9 @@ import org.onosproject.net.Host; |
45 | import org.onosproject.net.PortNumber; | 47 | import org.onosproject.net.PortNumber; |
46 | import org.onosproject.net.flow.DefaultTrafficSelector; | 48 | import org.onosproject.net.flow.DefaultTrafficSelector; |
47 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 49 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
48 | -import org.onosproject.net.flow.FlowRuleService; | ||
49 | import org.onosproject.net.flow.TrafficSelector; | 50 | import org.onosproject.net.flow.TrafficSelector; |
50 | import org.onosproject.net.flow.TrafficTreatment; | 51 | import org.onosproject.net.flow.TrafficTreatment; |
51 | import org.onosproject.net.host.HostService; | 52 | import org.onosproject.net.host.HostService; |
52 | -import org.onosproject.net.intent.IntentService; | ||
53 | import org.onosproject.net.packet.DefaultOutboundPacket; | 53 | import org.onosproject.net.packet.DefaultOutboundPacket; |
54 | import org.onosproject.net.packet.InboundPacket; | 54 | import org.onosproject.net.packet.InboundPacket; |
55 | import org.onosproject.net.packet.OutboundPacket; | 55 | import org.onosproject.net.packet.OutboundPacket; |
... | @@ -57,7 +57,6 @@ import org.onosproject.net.packet.PacketContext; | ... | @@ -57,7 +57,6 @@ import org.onosproject.net.packet.PacketContext; |
57 | import org.onosproject.net.packet.PacketPriority; | 57 | import org.onosproject.net.packet.PacketPriority; |
58 | import org.onosproject.net.packet.PacketProcessor; | 58 | import org.onosproject.net.packet.PacketProcessor; |
59 | import org.onosproject.net.packet.PacketService; | 59 | import org.onosproject.net.packet.PacketService; |
60 | -import org.onosproject.net.topology.TopologyService; | ||
61 | import org.onosproject.xosintegration.VoltTenantService; | 60 | import org.onosproject.xosintegration.VoltTenantService; |
62 | import org.osgi.service.component.ComponentContext; | 61 | import org.osgi.service.component.ComponentContext; |
63 | import org.slf4j.Logger; | 62 | import org.slf4j.Logger; |
... | @@ -67,7 +66,6 @@ import java.net.UnknownHostException; | ... | @@ -67,7 +66,6 @@ import java.net.UnknownHostException; |
67 | import java.nio.ByteBuffer; | 66 | import java.nio.ByteBuffer; |
68 | import java.util.Collections; | 67 | import java.util.Collections; |
69 | import java.util.Dictionary; | 68 | import java.util.Dictionary; |
70 | -import java.util.HashMap; | ||
71 | import java.util.Iterator; | 69 | import java.util.Iterator; |
72 | import java.util.Map; | 70 | import java.util.Map; |
73 | import java.util.Optional; | 71 | import java.util.Optional; |
... | @@ -77,7 +75,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -77,7 +75,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
77 | 75 | ||
78 | 76 | ||
79 | /** | 77 | /** |
80 | - * AAA application for Onos. | 78 | + * AAA application for ONOS. |
81 | */ | 79 | */ |
82 | @Component(immediate = true) | 80 | @Component(immediate = true) |
83 | public class AAA { | 81 | public class AAA { |
... | @@ -86,21 +84,10 @@ public class AAA { | ... | @@ -86,21 +84,10 @@ public class AAA { |
86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
87 | protected CoreService coreService; | 85 | protected CoreService coreService; |
88 | 86 | ||
89 | - // topology information | ||
90 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
91 | - protected TopologyService topologyService; | ||
92 | - | ||
93 | // to receive Packet-in events that we'll respond to | 87 | // to receive Packet-in events that we'll respond to |
94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
95 | protected PacketService packetService; | 89 | protected PacketService packetService; |
96 | 90 | ||
97 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
98 | - protected FlowRuleService flowService; | ||
99 | - | ||
100 | - // to submit/withdraw intents for traffic manipulation | ||
101 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
102 | - protected IntentService intentService; | ||
103 | - | ||
104 | // end host information | 91 | // end host information |
105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 92 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
106 | protected HostService hostService; | 93 | protected HostService hostService; |
... | @@ -108,7 +95,6 @@ public class AAA { | ... | @@ -108,7 +95,6 @@ public class AAA { |
108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
109 | protected VoltTenantService voltTenantService; | 96 | protected VoltTenantService voltTenantService; |
110 | 97 | ||
111 | - | ||
112 | // for verbose output | 98 | // for verbose output |
113 | private final Logger log = getLogger(getClass()); | 99 | private final Logger log = getLogger(getClass()); |
114 | 100 | ||
... | @@ -130,13 +116,13 @@ public class AAA { | ... | @@ -130,13 +116,13 @@ public class AAA { |
130 | private static final int DEFAULT_RADIUS_UPLINK = 2; | 116 | private static final int DEFAULT_RADIUS_UPLINK = 2; |
131 | // RADIUS server shared secret | 117 | // RADIUS server shared secret |
132 | private static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; | 118 | private static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; |
133 | - //RADIUS MAC address | 119 | + // RADIUS MAC address |
134 | private static final String RADIUS_MAC_ADDRESS = "00:00:00:00:01:10"; | 120 | private static final String RADIUS_MAC_ADDRESS = "00:00:00:00:01:10"; |
135 | - //NAS MAC address | 121 | + // NAS MAC address |
136 | private static final String NAS_MAC_ADDRESS = "00:00:00:00:10:01"; | 122 | private static final String NAS_MAC_ADDRESS = "00:00:00:00:10:01"; |
137 | - //Radius Switch Id | 123 | + // Radius Switch Id |
138 | private static final String DEFAULT_RADIUS_SWITCH = "of:5e3e486e73000187"; | 124 | private static final String DEFAULT_RADIUS_SWITCH = "of:5e3e486e73000187"; |
139 | - //Radius Port Number | 125 | + // Radius Port Number |
140 | private static final String DEFAULT_RADIUS_PORT = "5"; | 126 | private static final String DEFAULT_RADIUS_PORT = "5"; |
141 | 127 | ||
142 | @Property(name = "radiusIpAddress", value = DEFAULT_RADIUS_IP, | 128 | @Property(name = "radiusIpAddress", value = DEFAULT_RADIUS_IP, |
... | @@ -221,13 +207,12 @@ public class AAA { | ... | @@ -221,13 +207,12 @@ public class AAA { |
221 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 207 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
222 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 208 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
223 | 209 | ||
224 | - selector.matchEthType(EAPEthernet.TYPE_PAE); | 210 | + selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort()); |
225 | packetService.requestPackets(selector.build(), | 211 | packetService.requestPackets(selector.build(), |
226 | PacketPriority.CONTROL, appId); | 212 | PacketPriority.CONTROL, appId); |
227 | 213 | ||
228 | // Instantiate the map of the state machines | 214 | // Instantiate the map of the state machines |
229 | - Map<String, StateMachine> stateMachines = new HashMap<String, StateMachine>(); | 215 | + stateMachineMap = Collections.synchronizedMap(Maps.newHashMap()); |
230 | - stateMachineMap = Collections.synchronizedMap(stateMachines); | ||
231 | 216 | ||
232 | hostService.startMonitoringIp(IpAddress.valueOf(radiusIpAddress)); | 217 | hostService.startMonitoringIp(IpAddress.valueOf(radiusIpAddress)); |
233 | 218 | ||
... | @@ -241,6 +226,38 @@ public class AAA { | ... | @@ -241,6 +226,38 @@ public class AAA { |
241 | processor = null; | 226 | processor = null; |
242 | } | 227 | } |
243 | 228 | ||
229 | + /** | ||
230 | + * Builds an EAPOL packet based on the given parameters. | ||
231 | + * | ||
232 | + * @param dstMac destination MAC address | ||
233 | + * @param srcMac source MAC address | ||
234 | + * @param eapolType EAPOL type | ||
235 | + * @param eap EAP payload | ||
236 | + * @return Ethernet frame | ||
237 | + */ | ||
238 | + private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, | ||
239 | + short vlan, byte eapolType, EAP eap) { | ||
240 | + | ||
241 | + Ethernet eth = new Ethernet(); | ||
242 | + eth.setDestinationMACAddress(dstMac.toBytes()); | ||
243 | + eth.setSourceMACAddress(srcMac.toBytes()); | ||
244 | + eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); | ||
245 | + if (vlan != Ethernet.VLAN_UNTAGGED) { | ||
246 | + eth.setVlanID(vlan); | ||
247 | + } | ||
248 | + //eapol header | ||
249 | + EAPOL eapol = new EAPOL(); | ||
250 | + eapol.setEapolType(eapolType); | ||
251 | + eapol.setPacketLength(eap.getLength()); | ||
252 | + | ||
253 | + //eap part | ||
254 | + eapol.setPayload(eap); | ||
255 | + | ||
256 | + eth.setPayload(eapol); | ||
257 | + eth.setPad(true); | ||
258 | + return eth; | ||
259 | + } | ||
260 | + | ||
244 | // our handler defined as a private inner class | 261 | // our handler defined as a private inner class |
245 | 262 | ||
246 | /** | 263 | /** |
... | @@ -256,22 +273,27 @@ public class AAA { | ... | @@ -256,22 +273,27 @@ public class AAA { |
256 | if (ethPkt == null) { | 273 | if (ethPkt == null) { |
257 | return; | 274 | return; |
258 | } | 275 | } |
259 | - //identify if incoming packet comes from supplicant (EAP) or RADIUS | 276 | + // identify if incoming packet comes from supplicant (EAP) or RADIUS |
260 | - switch (ethPkt.getEtherType()) { | 277 | + switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { |
261 | - case (short) 0x888e: | 278 | + case EAPOL: |
262 | - handleSupplicantPacket(ethPkt, context); | 279 | + handleSupplicantPacket(context.inPacket()); |
263 | break; | 280 | break; |
264 | - case 0x800: | 281 | + case IPV4: |
265 | IPv4 ipv4Packet = (IPv4) ethPkt.getPayload(); | 282 | IPv4 ipv4Packet = (IPv4) ethPkt.getPayload(); |
266 | Ip4Address srcIp = Ip4Address.valueOf(ipv4Packet.getSourceAddress()); | 283 | Ip4Address srcIp = Ip4Address.valueOf(ipv4Packet.getSourceAddress()); |
267 | Ip4Address radiusIp4Address = Ip4Address.valueOf(parsedRadiusIpAddress); | 284 | Ip4Address radiusIp4Address = Ip4Address.valueOf(parsedRadiusIpAddress); |
268 | if (srcIp.equals(radiusIp4Address) && ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) { | 285 | if (srcIp.equals(radiusIp4Address) && ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) { |
269 | // TODO: check for port as well when it's configurable | 286 | // TODO: check for port as well when it's configurable |
270 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); | 287 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
271 | - // RADIUS radiusPacket = (RADIUS) udpPacket.getPayload(); | 288 | + |
272 | byte[] datagram = udpPacket.getPayload().serialize(); | 289 | byte[] datagram = udpPacket.getPayload().serialize(); |
273 | - RADIUS radiusPacket = new RADIUS(); | 290 | + RADIUS radiusPacket; |
274 | - radiusPacket = (RADIUS) radiusPacket.deserialize(datagram, 0, datagram.length); | 291 | + try { |
292 | + radiusPacket = RADIUS.deserializer().deserialize(datagram, 0, datagram.length); | ||
293 | + } catch (DeserializationException e) { | ||
294 | + log.warn("Unable to deserialize RADIUS packet:", e); | ||
295 | + return; | ||
296 | + } | ||
275 | handleRadiusPacket(radiusPacket); | 297 | handleRadiusPacket(radiusPacket); |
276 | } | 298 | } |
277 | break; | 299 | break; |
... | @@ -282,33 +304,33 @@ public class AAA { | ... | @@ -282,33 +304,33 @@ public class AAA { |
282 | 304 | ||
283 | 305 | ||
284 | /** | 306 | /** |
285 | - * Handle PAE packets (supplicant). | 307 | + * Handles PAE packets (supplicant). |
286 | - * @param ethPkt Ethernet packet coming from the supplicant. | 308 | + * |
309 | + * @param inPacket Ethernet packet coming from the supplicant | ||
287 | */ | 310 | */ |
288 | - private void handleSupplicantPacket(Ethernet ethPkt, PacketContext context) { | 311 | + private void handleSupplicantPacket(InboundPacket inPacket) { |
312 | + Ethernet ethPkt = inPacket.parsed(); | ||
289 | // Where does it come from? | 313 | // Where does it come from? |
290 | MacAddress srcMAC = ethPkt.getSourceMAC(); | 314 | MacAddress srcMAC = ethPkt.getSourceMAC(); |
291 | 315 | ||
292 | - DeviceId deviceId = context.inPacket().receivedFrom().deviceId(); | 316 | + DeviceId deviceId = inPacket.receivedFrom().deviceId(); |
293 | - PortNumber portNumber = context.inPacket().receivedFrom().port(); | 317 | + PortNumber portNumber = inPacket.receivedFrom().port(); |
294 | String sessionId = deviceId.toString() + portNumber.toString(); | 318 | String sessionId = deviceId.toString() + portNumber.toString(); |
295 | StateMachine stateMachine = getStateMachine(sessionId); | 319 | StateMachine stateMachine = getStateMachine(sessionId); |
296 | - //Reserialize the data of the eth packet into our EAPOL format | 320 | + |
297 | - // this code will go once it is in the onos repository. | 321 | + EAPOL eapol = (EAPOL) ethPkt.getPayload(); |
298 | - byte[] bullshit = ethPkt.getPayload().serialize(); | ||
299 | - EAPOL eapol = (EAPOL) new EAPOL().deserialize(bullshit, 0, bullshit.length); | ||
300 | 322 | ||
301 | switch (eapol.getEapolType()) { | 323 | switch (eapol.getEapolType()) { |
302 | case EAPOL.EAPOL_START: | 324 | case EAPOL.EAPOL_START: |
303 | try { | 325 | try { |
304 | stateMachine.start(); | 326 | stateMachine.start(); |
305 | - stateMachine.supplicantConnectpoint = context.inPacket().receivedFrom(); | 327 | + stateMachine.supplicantConnectpoint = inPacket.receivedFrom(); |
306 | 328 | ||
307 | //send an EAP Request/Identify to the supplicant | 329 | //send an EAP Request/Identify to the supplicant |
308 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.getIdentifier(), EAP.ATTR_IDENTITY, null); | 330 | EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.getIdentifier(), EAP.ATTR_IDENTITY, null); |
309 | - Ethernet eth = EAPOL.buildEapolResponse(srcMAC, MacAddress.valueOf(1L), | 331 | + Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(1L), |
310 | - ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, | 332 | + ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, |
311 | - eapPayload); | 333 | + eapPayload); |
312 | stateMachine.supplicantAddress = srcMAC; | 334 | stateMachine.supplicantAddress = srcMAC; |
313 | stateMachine.vlanId = ethPkt.getVlanID(); | 335 | stateMachine.vlanId = ethPkt.getVlanID(); |
314 | 336 | ||
... | @@ -319,7 +341,7 @@ public class AAA { | ... | @@ -319,7 +341,7 @@ public class AAA { |
319 | 341 | ||
320 | break; | 342 | break; |
321 | case EAPOL.EAPOL_PACKET: | 343 | case EAPOL.EAPOL_PACKET: |
322 | - //check if this is a Response/Idenfity or a Response/TLS | 344 | + //check if this is a Response/Identify or a Response/TLS |
323 | EAP eapPacket = (EAP) eapol.getPayload(); | 345 | EAP eapPacket = (EAP) eapol.getPayload(); |
324 | 346 | ||
325 | byte dataType = eapPacket.getDataType(); | 347 | byte dataType = eapPacket.getDataType(); |
... | @@ -406,7 +428,8 @@ public class AAA { | ... | @@ -406,7 +428,8 @@ public class AAA { |
406 | } | 428 | } |
407 | 429 | ||
408 | /** | 430 | /** |
409 | - * Handle RADIUS packets. | 431 | + * Handles RADIUS packets. |
432 | + * | ||
410 | * @param radiusPacket RADIUS packet coming from the RADIUS server. | 433 | * @param radiusPacket RADIUS packet coming from the RADIUS server. |
411 | */ | 434 | */ |
412 | private void handleRadiusPacket(RADIUS radiusPacket) { | 435 | private void handleRadiusPacket(RADIUS radiusPacket) { |
... | @@ -416,7 +439,6 @@ public class AAA { | ... | @@ -416,7 +439,6 @@ public class AAA { |
416 | return; | 439 | return; |
417 | } | 440 | } |
418 | 441 | ||
419 | - byte[] eapMessage = null; | ||
420 | EAP eapPayload = new EAP(); | 442 | EAP eapPayload = new EAP(); |
421 | Ethernet eth = null; | 443 | Ethernet eth = null; |
422 | switch (radiusPacket.getCode()) { | 444 | switch (radiusPacket.getCode()) { |
... | @@ -424,18 +446,18 @@ public class AAA { | ... | @@ -424,18 +446,18 @@ public class AAA { |
424 | byte[] challengeState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE).getValue(); | 446 | byte[] challengeState = radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE).getValue(); |
425 | eapPayload = radiusPacket.decapsulateMessage(); | 447 | eapPayload = radiusPacket.decapsulateMessage(); |
426 | stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); | 448 | stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); |
427 | - eth = EAPOL.buildEapolResponse(stateMachine.supplicantAddress, | 449 | + eth = buildEapolResponse(stateMachine.supplicantAddress, |
428 | MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET, eapPayload); | 450 | MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET, eapPayload); |
429 | this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint); | 451 | this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint); |
430 | break; | 452 | break; |
431 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: | 453 | case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: |
432 | try { | 454 | try { |
433 | //send an EAPOL - Success to the supplicant. | 455 | //send an EAPOL - Success to the supplicant. |
434 | - eapMessage = | 456 | + byte[] eapMessage = |
435 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); | 457 | radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); |
436 | eapPayload = new EAP(); | 458 | eapPayload = new EAP(); |
437 | eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length); | 459 | eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length); |
438 | - eth = EAPOL.buildEapolResponse(stateMachine.supplicantAddress, | 460 | + eth = buildEapolResponse(stateMachine.supplicantAddress, |
439 | MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET, eapPayload); | 461 | MacAddress.valueOf(1L), stateMachine.vlanId, EAPOL.EAPOL_PACKET, eapPayload); |
440 | this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint); | 462 | this.sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint); |
441 | 463 | ||
... | @@ -539,10 +561,11 @@ public class AAA { | ... | @@ -539,10 +561,11 @@ public class AAA { |
539 | 561 | ||
540 | } | 562 | } |
541 | 563 | ||
542 | - | ||
543 | /** | 564 | /** |
544 | * Send the ethernet packet to the supplicant. | 565 | * Send the ethernet packet to the supplicant. |
566 | + * | ||
545 | * @param ethernetPkt the ethernet packet | 567 | * @param ethernetPkt the ethernet packet |
568 | + * @param connectPoint the connect point to send out | ||
546 | */ | 569 | */ |
547 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) { | 570 | private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) { |
548 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); | 571 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); | ... | ... |
1 | -/* | ||
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 | - */ | ||
16 | - | ||
17 | -package org.onosproject.aaa.packet; | ||
18 | - | ||
19 | -import org.onlab.packet.Deserializer; | ||
20 | -import org.onlab.packet.EthType; | ||
21 | -import org.onlab.packet.Ethernet; | ||
22 | -import org.onlab.packet.IPacket; | ||
23 | - | ||
24 | -import java.util.HashMap; | ||
25 | -import java.util.Map; | ||
26 | - | ||
27 | -/** | ||
28 | - * Created by jono on 5/19/15. | ||
29 | - */ | ||
30 | -public final class EAPEthernet extends Ethernet { | ||
31 | - | ||
32 | - public static final short TYPE_PAE = (short) 0x888e; | ||
33 | - | ||
34 | - private static final Map<Short, Deserializer<? extends IPacket>> ETHERTYPE_DESERIALIZER_MAP = | ||
35 | - new HashMap<>(); | ||
36 | - | ||
37 | - private EAPEthernet() { | ||
38 | - | ||
39 | - } | ||
40 | - | ||
41 | - static { | ||
42 | - for (EthType.EtherType ethType : EthType.EtherType.values()) { | ||
43 | - if (ethType.deserializer() != null) { | ||
44 | - ETHERTYPE_DESERIALIZER_MAP.put(ethType.ethType().toShort(), | ||
45 | - ethType.deserializer()); | ||
46 | - } | ||
47 | - } | ||
48 | - ETHERTYPE_DESERIALIZER_MAP.put((short) 0x888e, EAPOL.deserializer()); | ||
49 | - } | ||
50 | - | ||
51 | -} |
... | @@ -16,29 +16,30 @@ | ... | @@ -16,29 +16,30 @@ |
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | 18 | ||
19 | -package org.onosproject.aaa.packet; | 19 | +package org.onlab.packet; |
20 | - | ||
21 | -import org.onlab.packet.BasePacket; | ||
22 | -import org.onlab.packet.IPacket; | ||
23 | 20 | ||
24 | import java.nio.ByteBuffer; | 21 | import java.nio.ByteBuffer; |
25 | 22 | ||
23 | +import static org.onlab.packet.PacketUtils.checkHeaderLength; | ||
24 | +import static org.onlab.packet.PacketUtils.checkInput; | ||
26 | 25 | ||
27 | /** | 26 | /** |
28 | - * | 27 | + * EAP (Extensible Authentication Protocol) packet. |
29 | */ | 28 | */ |
30 | public class EAP extends BasePacket { | 29 | public class EAP extends BasePacket { |
30 | + private static final int HEADER_LENGTH = 4; | ||
31 | + | ||
31 | public static final short MIN_LEN = 0x4; | 32 | public static final short MIN_LEN = 0x4; |
32 | public static final short EAP_HDR_LEN_REQ_RESP = 5; | 33 | public static final short EAP_HDR_LEN_REQ_RESP = 5; |
33 | public static final short EAP_HDR_LEN_SUC_FAIL = 4; | 34 | public static final short EAP_HDR_LEN_SUC_FAIL = 4; |
34 | 35 | ||
35 | - /* EAP Code */ | 36 | + // EAP Code |
36 | public static final byte REQUEST = 0x1; | 37 | public static final byte REQUEST = 0x1; |
37 | public static final byte RESPONSE = 0x2; | 38 | public static final byte RESPONSE = 0x2; |
38 | public static final byte SUCCESS = 0x3; | 39 | public static final byte SUCCESS = 0x3; |
39 | public static final byte FAILURE = 0x4; | 40 | public static final byte FAILURE = 0x4; |
40 | 41 | ||
41 | - /* EAP Attribute Type */ | 42 | + // EAP Attribute Type |
42 | public static final byte ATTR_IDENTITY = 0x1; | 43 | public static final byte ATTR_IDENTITY = 0x1; |
43 | public static final byte ATTR_NOTIFICATION = 0x2; | 44 | public static final byte ATTR_NOTIFICATION = 0x2; |
44 | public static final byte ATTR_NAK = 0x3; | 45 | public static final byte ATTR_NAK = 0x3; |
... | @@ -55,7 +56,8 @@ public class EAP extends BasePacket { | ... | @@ -55,7 +56,8 @@ public class EAP extends BasePacket { |
55 | 56 | ||
56 | 57 | ||
57 | /** | 58 | /** |
58 | - * Get the EAP code. | 59 | + * Gets the EAP code. |
60 | + * | ||
59 | * @return EAP code | 61 | * @return EAP code |
60 | */ | 62 | */ |
61 | public byte getCode() { | 63 | public byte getCode() { |
... | @@ -64,7 +66,8 @@ public class EAP extends BasePacket { | ... | @@ -64,7 +66,8 @@ public class EAP extends BasePacket { |
64 | 66 | ||
65 | 67 | ||
66 | /** | 68 | /** |
67 | - * Set the EAP code. | 69 | + * Sets the EAP code. |
70 | + * | ||
68 | * @param code EAP code | 71 | * @param code EAP code |
69 | * @return this | 72 | * @return this |
70 | */ | 73 | */ |
... | @@ -74,7 +77,8 @@ public class EAP extends BasePacket { | ... | @@ -74,7 +77,8 @@ public class EAP extends BasePacket { |
74 | } | 77 | } |
75 | 78 | ||
76 | /** | 79 | /** |
77 | - * Get the EAP identifier. | 80 | + * Gets the EAP identifier. |
81 | + * | ||
78 | * @return EAP identifier | 82 | * @return EAP identifier |
79 | */ | 83 | */ |
80 | public byte getIdentifier() { | 84 | public byte getIdentifier() { |
... | @@ -82,7 +86,8 @@ public class EAP extends BasePacket { | ... | @@ -82,7 +86,8 @@ public class EAP extends BasePacket { |
82 | } | 86 | } |
83 | 87 | ||
84 | /** | 88 | /** |
85 | - * Set the EAP identifier. | 89 | + * Sets the EAP identifier. |
90 | + * | ||
86 | * @param identifier | 91 | * @param identifier |
87 | * @return this | 92 | * @return this |
88 | */ | 93 | */ |
... | @@ -92,7 +97,8 @@ public class EAP extends BasePacket { | ... | @@ -92,7 +97,8 @@ public class EAP extends BasePacket { |
92 | } | 97 | } |
93 | 98 | ||
94 | /** | 99 | /** |
95 | - * Get the get packet length. | 100 | + * Gets the get packet length. |
101 | + * | ||
96 | * @return packet length | 102 | * @return packet length |
97 | */ | 103 | */ |
98 | public short getLength() { | 104 | public short getLength() { |
... | @@ -100,7 +106,8 @@ public class EAP extends BasePacket { | ... | @@ -100,7 +106,8 @@ public class EAP extends BasePacket { |
100 | } | 106 | } |
101 | 107 | ||
102 | /** | 108 | /** |
103 | - * Set the packet length. | 109 | + * Sets the packet length. |
110 | + * | ||
104 | * @param length packet length | 111 | * @param length packet length |
105 | * @return this | 112 | * @return this |
106 | */ | 113 | */ |
... | @@ -110,7 +117,8 @@ public class EAP extends BasePacket { | ... | @@ -110,7 +117,8 @@ public class EAP extends BasePacket { |
110 | } | 117 | } |
111 | 118 | ||
112 | /** | 119 | /** |
113 | - * Get the data type. | 120 | + * Gets the data type. |
121 | + * | ||
114 | * @return data type | 122 | * @return data type |
115 | */ | 123 | */ |
116 | public byte getDataType() { | 124 | public byte getDataType() { |
... | @@ -118,7 +126,8 @@ public class EAP extends BasePacket { | ... | @@ -118,7 +126,8 @@ public class EAP extends BasePacket { |
118 | } | 126 | } |
119 | 127 | ||
120 | /** | 128 | /** |
121 | - * Set the data type. | 129 | + * Sets the data type. |
130 | + * | ||
122 | * @param type data type | 131 | * @param type data type |
123 | * @return this | 132 | * @return this |
124 | */ | 133 | */ |
... | @@ -128,7 +137,8 @@ public class EAP extends BasePacket { | ... | @@ -128,7 +137,8 @@ public class EAP extends BasePacket { |
128 | } | 137 | } |
129 | 138 | ||
130 | /** | 139 | /** |
131 | - * Get the EAP data. | 140 | + * Gets the EAP data. |
141 | + * | ||
132 | * @return EAP data | 142 | * @return EAP data |
133 | */ | 143 | */ |
134 | public byte[] getData() { | 144 | public byte[] getData() { |
... | @@ -136,7 +146,8 @@ public class EAP extends BasePacket { | ... | @@ -136,7 +146,8 @@ public class EAP extends BasePacket { |
136 | } | 146 | } |
137 | 147 | ||
138 | /** | 148 | /** |
139 | - * Set the EAP data. | 149 | + * Sets the EAP data. |
150 | + * | ||
140 | * @param data EAP data to be set | 151 | * @param data EAP data to be set |
141 | * @return this | 152 | * @return this |
142 | */ | 153 | */ |
... | @@ -146,7 +157,7 @@ public class EAP extends BasePacket { | ... | @@ -146,7 +157,7 @@ public class EAP extends BasePacket { |
146 | } | 157 | } |
147 | 158 | ||
148 | /** | 159 | /** |
149 | - * Default EAP constructor that set the EAP code to 0. | 160 | + * Default EAP constructor that sets the EAP code to 0. |
150 | */ | 161 | */ |
151 | public EAP() { | 162 | public EAP() { |
152 | this.code = 0; | 163 | this.code = 0; |
... | @@ -154,6 +165,7 @@ public class EAP extends BasePacket { | ... | @@ -154,6 +165,7 @@ public class EAP extends BasePacket { |
154 | 165 | ||
155 | /** | 166 | /** |
156 | * EAP constructor that initially sets all fields. | 167 | * EAP constructor that initially sets all fields. |
168 | + * | ||
157 | * @param code EAP code | 169 | * @param code EAP code |
158 | * @param identifier EAP identifier | 170 | * @param identifier EAP identifier |
159 | * @param type packet type | 171 | * @param type packet type |
... | @@ -172,10 +184,36 @@ public class EAP extends BasePacket { | ... | @@ -172,10 +184,36 @@ public class EAP extends BasePacket { |
172 | } | 184 | } |
173 | 185 | ||
174 | /** | 186 | /** |
175 | - * Serializes the packet, based on the code/type using the payload | 187 | + * Deserializer for EAP packets. |
176 | - * to compute its length. | 188 | + * |
177 | - * @return the serialized payload | 189 | + * @return deserializer |
178 | */ | 190 | */ |
191 | + public static Deserializer<EAP> deserializer() { | ||
192 | + return (data, offset, length) -> { | ||
193 | + checkInput(data, offset, length, HEADER_LENGTH); | ||
194 | + | ||
195 | + EAP eap = new EAP(); | ||
196 | + final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); | ||
197 | + eap.code = bb.get(); | ||
198 | + eap.identifier = bb.get(); | ||
199 | + eap.length = bb.getShort(); | ||
200 | + | ||
201 | + checkHeaderLength(length, HEADER_LENGTH + eap.length); | ||
202 | + | ||
203 | + int dataLength; | ||
204 | + if (eap.code == REQUEST || eap.code == RESPONSE) { | ||
205 | + eap.type = bb.get(); | ||
206 | + dataLength = eap.length - 5; | ||
207 | + } else { | ||
208 | + dataLength = eap.length - 4; | ||
209 | + } | ||
210 | + | ||
211 | + eap.data = new byte[dataLength]; | ||
212 | + bb.get(eap.data); | ||
213 | + return eap; | ||
214 | + }; | ||
215 | + } | ||
216 | + | ||
179 | @Override | 217 | @Override |
180 | public byte[] serialize() { | 218 | public byte[] serialize() { |
181 | final byte[] data = new byte[this.length]; | 219 | final byte[] data = new byte[this.length]; | ... | ... |
... | @@ -16,20 +16,15 @@ | ... | @@ -16,20 +16,15 @@ |
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | 18 | ||
19 | -package org.onosproject.aaa.packet; | 19 | +package org.onlab.packet; |
20 | - | ||
21 | -import org.onlab.packet.BasePacket; | ||
22 | -import org.onlab.packet.Deserializer; | ||
23 | -import org.onlab.packet.Ethernet; | ||
24 | -import org.onlab.packet.IPacket; | ||
25 | -import org.onlab.packet.MacAddress; | ||
26 | 20 | ||
27 | import java.nio.ByteBuffer; | 21 | import java.nio.ByteBuffer; |
28 | 22 | ||
23 | +import static org.onlab.packet.PacketUtils.checkHeaderLength; | ||
29 | import static org.onlab.packet.PacketUtils.checkInput; | 24 | import static org.onlab.packet.PacketUtils.checkInput; |
30 | 25 | ||
31 | /** | 26 | /** |
32 | - * | 27 | + * EAPOL (Extensible Authentication Protocol over LAN) header. |
33 | */ | 28 | */ |
34 | public class EAPOL extends BasePacket { | 29 | public class EAPOL extends BasePacket { |
35 | 30 | ||
... | @@ -37,7 +32,9 @@ public class EAPOL extends BasePacket { | ... | @@ -37,7 +32,9 @@ public class EAPOL extends BasePacket { |
37 | private byte eapolType; | 32 | private byte eapolType; |
38 | private short packetLength; | 33 | private short packetLength; |
39 | 34 | ||
40 | - /* EAPOL Packet Type */ | 35 | + private static final int HEADER_LENGTH = 4; |
36 | + | ||
37 | + // EAPOL Packet Type | ||
41 | public static final byte EAPOL_PACKET = 0x0; | 38 | public static final byte EAPOL_PACKET = 0x0; |
42 | public static final byte EAPOL_START = 0x1; | 39 | public static final byte EAPOL_START = 0x1; |
43 | public static final byte EAPOL_LOGOFF = 0x2; | 40 | public static final byte EAPOL_LOGOFF = 0x2; |
... | @@ -48,9 +45,9 @@ public class EAPOL extends BasePacket { | ... | @@ -48,9 +45,9 @@ public class EAPOL extends BasePacket { |
48 | (byte) 0x01, (byte) 0x80, (byte) 0xc2, (byte) 0x00, (byte) 0x00, (byte) 0x03 | 45 | (byte) 0x01, (byte) 0x80, (byte) 0xc2, (byte) 0x00, (byte) 0x00, (byte) 0x03 |
49 | }); | 46 | }); |
50 | 47 | ||
51 | - | ||
52 | /** | 48 | /** |
53 | - * Get version. | 49 | + * Gets the version. |
50 | + * | ||
54 | * @return version | 51 | * @return version |
55 | */ | 52 | */ |
56 | public byte getVersion() { | 53 | public byte getVersion() { |
... | @@ -58,7 +55,8 @@ public class EAPOL extends BasePacket { | ... | @@ -58,7 +55,8 @@ public class EAPOL extends BasePacket { |
58 | } | 55 | } |
59 | 56 | ||
60 | /** | 57 | /** |
61 | - * Set version. | 58 | + * Sets the version. |
59 | + * | ||
62 | * @param version EAPOL version | 60 | * @param version EAPOL version |
63 | * @return this | 61 | * @return this |
64 | */ | 62 | */ |
... | @@ -68,7 +66,8 @@ public class EAPOL extends BasePacket { | ... | @@ -68,7 +66,8 @@ public class EAPOL extends BasePacket { |
68 | } | 66 | } |
69 | 67 | ||
70 | /** | 68 | /** |
71 | - * Get type. | 69 | + * Gets the type. |
70 | + * | ||
72 | * @return EAPOL type | 71 | * @return EAPOL type |
73 | */ | 72 | */ |
74 | public byte getEapolType() { | 73 | public byte getEapolType() { |
... | @@ -76,7 +75,8 @@ public class EAPOL extends BasePacket { | ... | @@ -76,7 +75,8 @@ public class EAPOL extends BasePacket { |
76 | } | 75 | } |
77 | 76 | ||
78 | /** | 77 | /** |
79 | - * Set EAPOL type. | 78 | + * Sets the EAPOL type. |
79 | + * | ||
80 | * @param eapolType EAPOL type | 80 | * @param eapolType EAPOL type |
81 | * @return this | 81 | * @return this |
82 | */ | 82 | */ |
... | @@ -86,7 +86,8 @@ public class EAPOL extends BasePacket { | ... | @@ -86,7 +86,8 @@ public class EAPOL extends BasePacket { |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | - * Get packet length. | 89 | + * Gets the packet length. |
90 | + * | ||
90 | * @return packet length | 91 | * @return packet length |
91 | */ | 92 | */ |
92 | public short getPacketLength() { | 93 | public short getPacketLength() { |
... | @@ -94,7 +95,8 @@ public class EAPOL extends BasePacket { | ... | @@ -94,7 +95,8 @@ public class EAPOL extends BasePacket { |
94 | } | 95 | } |
95 | 96 | ||
96 | /** | 97 | /** |
97 | - * Set packet length. | 98 | + * Sets the packet length. |
99 | + * | ||
98 | * @param packetLen packet length | 100 | * @param packetLen packet length |
99 | * @return this | 101 | * @return this |
100 | */ | 102 | */ |
... | @@ -103,16 +105,14 @@ public class EAPOL extends BasePacket { | ... | @@ -103,16 +105,14 @@ public class EAPOL extends BasePacket { |
103 | return this; | 105 | return this; |
104 | } | 106 | } |
105 | 107 | ||
106 | - | ||
107 | - | ||
108 | /** | 108 | /** |
109 | * Serializes the packet, based on the code/type using the payload | 109 | * Serializes the packet, based on the code/type using the payload |
110 | * to compute its length. | 110 | * to compute its length. |
111 | + * | ||
111 | * @return this | 112 | * @return this |
112 | */ | 113 | */ |
113 | @Override | 114 | @Override |
114 | public byte[] serialize() { | 115 | public byte[] serialize() { |
115 | - | ||
116 | byte[] payloadData = null; | 116 | byte[] payloadData = null; |
117 | 117 | ||
118 | if (this.payload != null) { | 118 | if (this.payload != null) { |
... | @@ -120,15 +120,16 @@ public class EAPOL extends BasePacket { | ... | @@ -120,15 +120,16 @@ public class EAPOL extends BasePacket { |
120 | payloadData = this.payload.serialize(); | 120 | payloadData = this.payload.serialize(); |
121 | } | 121 | } |
122 | 122 | ||
123 | - //prepare the buffer to hold the version (1), packet type (1), packet length (2) and the eap payload. | 123 | + // prepare the buffer to hold the version (1), packet type (1), |
124 | - //if there is no payload, packet length is 0 | 124 | + // packet length (2) and the eap payload. |
125 | + // if there is no payload, packet length is 0 | ||
125 | byte[] data = new byte[4 + this.packetLength]; | 126 | byte[] data = new byte[4 + this.packetLength]; |
126 | final ByteBuffer bb = ByteBuffer.wrap(data); | 127 | final ByteBuffer bb = ByteBuffer.wrap(data); |
127 | bb.put(this.version); | 128 | bb.put(this.version); |
128 | bb.put(this.eapolType); | 129 | bb.put(this.eapolType); |
129 | bb.putShort(this.packetLength); | 130 | bb.putShort(this.packetLength); |
130 | 131 | ||
131 | - //put the EAP payload | 132 | + // put the EAP payload |
132 | if (payloadData != null) { | 133 | if (payloadData != null) { |
133 | bb.put(payloadData); | 134 | bb.put(payloadData); |
134 | } | 135 | } |
... | @@ -136,8 +137,6 @@ public class EAPOL extends BasePacket { | ... | @@ -136,8 +137,6 @@ public class EAPOL extends BasePacket { |
136 | return data; | 137 | return data; |
137 | } | 138 | } |
138 | 139 | ||
139 | - | ||
140 | - | ||
141 | @Override | 140 | @Override |
142 | public int hashCode() { | 141 | public int hashCode() { |
143 | final int prime = 3889; | 142 | final int prime = 3889; |
... | @@ -149,39 +148,13 @@ public class EAPOL extends BasePacket { | ... | @@ -149,39 +148,13 @@ public class EAPOL extends BasePacket { |
149 | } | 148 | } |
150 | 149 | ||
151 | /** | 150 | /** |
151 | + * Deserializer for EAPOL packets. | ||
152 | * | 152 | * |
153 | - * @param dstMac | 153 | + * @return deserializer |
154 | - * @param srcMac | ||
155 | - * @param eapolType | ||
156 | - * @param eap | ||
157 | - * @return Ethernet frame | ||
158 | */ | 154 | */ |
159 | - public static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, | ||
160 | - short vlan, byte eapolType, EAP eap) { | ||
161 | - | ||
162 | - Ethernet eth = new Ethernet(); | ||
163 | - eth.setDestinationMACAddress(dstMac.toBytes()); | ||
164 | - eth.setSourceMACAddress(srcMac.toBytes()); | ||
165 | - eth.setEtherType(EAPEthernet.TYPE_PAE); | ||
166 | - if (vlan != Ethernet.VLAN_UNTAGGED) { | ||
167 | - eth.setVlanID(vlan); | ||
168 | - } | ||
169 | - //eapol header | ||
170 | - EAPOL eapol = new EAPOL(); | ||
171 | - eapol.setEapolType(eapolType); | ||
172 | - eapol.setPacketLength(eap.getLength()); | ||
173 | - | ||
174 | - //eap part | ||
175 | - eapol.setPayload(eap); | ||
176 | - | ||
177 | - eth.setPayload(eapol); | ||
178 | - eth.setPad(true); | ||
179 | - return eth; | ||
180 | - } | ||
181 | - | ||
182 | public static Deserializer<EAPOL> deserializer() { | 155 | public static Deserializer<EAPOL> deserializer() { |
183 | return (data, offset, length) -> { | 156 | return (data, offset, length) -> { |
184 | - checkInput(data, offset, length, 0); | 157 | + checkInput(data, offset, length, HEADER_LENGTH); |
185 | 158 | ||
186 | EAPOL eapol = new EAPOL(); | 159 | EAPOL eapol = new EAPOL(); |
187 | final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); | 160 | final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); |
... | @@ -190,12 +163,14 @@ public class EAPOL extends BasePacket { | ... | @@ -190,12 +163,14 @@ public class EAPOL extends BasePacket { |
190 | eapol.setPacketLength(bb.getShort()); | 163 | eapol.setPacketLength(bb.getShort()); |
191 | 164 | ||
192 | if (eapol.packetLength > 0) { | 165 | if (eapol.packetLength > 0) { |
193 | - //deserialize the EAP Payload | 166 | + checkHeaderLength(length, HEADER_LENGTH + eapol.packetLength); |
194 | - eapol.payload = new EAP(); | 167 | + // deserialize the EAP Payload |
168 | + eapol.payload = EAP.deserializer().deserialize(data, | ||
169 | + bb.position(), bb.limit() - bb.position()); | ||
195 | 170 | ||
196 | - eapol.payload = eapol.payload.deserialize(data, bb.position(), length - 4); | ||
197 | eapol.payload.setParent(eapol); | 171 | eapol.payload.setParent(eapol); |
198 | } | 172 | } |
173 | + | ||
199 | return eapol; | 174 | return eapol; |
200 | }; | 175 | }; |
201 | } | 176 | } |
... | @@ -205,24 +180,20 @@ public class EAPOL extends BasePacket { | ... | @@ -205,24 +180,20 @@ public class EAPOL extends BasePacket { |
205 | final int length) { | 180 | final int length) { |
206 | final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); | 181 | final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); |
207 | 182 | ||
208 | - | 183 | + // deserialize the EAPOL header |
209 | - //deserialize the EAPOL header | ||
210 | this.version = bb.get(); | 184 | this.version = bb.get(); |
211 | this.eapolType = bb.get(); | 185 | this.eapolType = bb.get(); |
212 | this.packetLength = bb.getShort(); | 186 | this.packetLength = bb.getShort(); |
213 | 187 | ||
214 | if (this.packetLength > 0) { | 188 | if (this.packetLength > 0) { |
215 | - //deserialize the EAP Payload | 189 | + // deserialize the EAP Payload |
216 | this.payload = new EAP(); | 190 | this.payload = new EAP(); |
217 | 191 | ||
218 | this.payload = this.payload.deserialize(data, bb.position(), length - 4); | 192 | this.payload = this.payload.deserialize(data, bb.position(), length - 4); |
219 | this.payload.setParent(this); | 193 | this.payload.setParent(this); |
220 | } | 194 | } |
221 | 195 | ||
222 | - | ||
223 | return this; | 196 | return this; |
224 | } | 197 | } |
225 | - | ||
226 | - | ||
227 | } | 198 | } |
228 | 199 | ... | ... |
... | @@ -35,8 +35,9 @@ public class EthType { | ... | @@ -35,8 +35,9 @@ public class EthType { |
35 | VLAN(0x8100, "vlan", null), | 35 | VLAN(0x8100, "vlan", null), |
36 | BDDP(0x8942, "bddp", org.onlab.packet.LLDP.deserializer()), | 36 | BDDP(0x8942, "bddp", org.onlab.packet.LLDP.deserializer()), |
37 | MPLS_UNICAST(0x8847, "mpls_unicast", org.onlab.packet.MPLS.deserializer()), | 37 | MPLS_UNICAST(0x8847, "mpls_unicast", org.onlab.packet.MPLS.deserializer()), |
38 | - MPLS_MULTICAST(0x8848, "mpls_unicast", org.onlab.packet.MPLS.deserializer()); | 38 | + MPLS_MULTICAST(0x8848, "mpls_unicast", org.onlab.packet.MPLS.deserializer()), |
39 | - | 39 | + EAPOL(0x888e, "eapol", org.onlab.packet.EAPOL.deserializer()), |
40 | + UNKNOWN(0, "unknown", null); | ||
40 | 41 | ||
41 | 42 | ||
42 | private final EthType etherType; | 43 | private final EthType etherType; |
... | @@ -69,6 +70,15 @@ public class EthType { | ... | @@ -69,6 +70,15 @@ public class EthType { |
69 | return deserializer; | 70 | return deserializer; |
70 | } | 71 | } |
71 | 72 | ||
73 | + public static EtherType lookup(short etherType) { | ||
74 | + for (EtherType ethType : EtherType.values()) { | ||
75 | + if (ethType.ethType().toShort() == etherType) { | ||
76 | + return ethType; | ||
77 | + } | ||
78 | + } | ||
79 | + return UNKNOWN; | ||
80 | + } | ||
81 | + | ||
72 | } | 82 | } |
73 | 83 | ||
74 | 84 | ... | ... |
... | @@ -16,10 +16,8 @@ | ... | @@ -16,10 +16,8 @@ |
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | 18 | ||
19 | -package org.onosproject.aaa.packet; | 19 | +package org.onlab.packet; |
20 | 20 | ||
21 | -import org.onlab.packet.BasePacket; | ||
22 | -import org.onlab.packet.IPacket; | ||
23 | import org.slf4j.Logger; | 21 | import org.slf4j.Logger; |
24 | 22 | ||
25 | import javax.crypto.Mac; | 23 | import javax.crypto.Mac; |
... | @@ -30,25 +28,28 @@ import java.nio.ByteBuffer; | ... | @@ -30,25 +28,28 @@ import java.nio.ByteBuffer; |
30 | import java.security.SecureRandom; | 28 | import java.security.SecureRandom; |
31 | import java.util.ArrayList; | 29 | import java.util.ArrayList; |
32 | import java.util.Arrays; | 30 | import java.util.Arrays; |
31 | +import java.util.List; | ||
33 | 32 | ||
33 | +import static org.onlab.packet.PacketUtils.checkHeaderLength; | ||
34 | +import static org.onlab.packet.PacketUtils.checkInput; | ||
34 | import static org.slf4j.LoggerFactory.getLogger; | 35 | import static org.slf4j.LoggerFactory.getLogger; |
35 | 36 | ||
36 | /** | 37 | /** |
37 | - * | 38 | + * RADIUS packet. |
38 | */ | 39 | */ |
39 | public class RADIUS extends BasePacket { | 40 | public class RADIUS extends BasePacket { |
40 | protected byte code; | 41 | protected byte code; |
41 | protected byte identifier; | 42 | protected byte identifier; |
42 | protected short length = RADIUS_MIN_LENGTH; | 43 | protected short length = RADIUS_MIN_LENGTH; |
43 | protected byte[] authenticator = new byte[16]; | 44 | protected byte[] authenticator = new byte[16]; |
44 | - protected ArrayList<RADIUSAttribute> attributes = new ArrayList<>(); | 45 | + protected List<RADIUSAttribute> attributes = new ArrayList<>(); |
45 | 46 | ||
46 | - /* RADIUS parameters */ | 47 | + // RADIUS parameters |
47 | public static final short RADIUS_MIN_LENGTH = 20; | 48 | public static final short RADIUS_MIN_LENGTH = 20; |
48 | public static final short MAX_ATTR_VALUE_LENGTH = 253; | 49 | public static final short MAX_ATTR_VALUE_LENGTH = 253; |
49 | public static final short RADIUS_MAX_LENGTH = 4096; | 50 | public static final short RADIUS_MAX_LENGTH = 4096; |
50 | 51 | ||
51 | - /* RADIUS packet types */ | 52 | + // RADIUS packet types |
52 | public static final byte RADIUS_CODE_ACCESS_REQUEST = 0x01; | 53 | public static final byte RADIUS_CODE_ACCESS_REQUEST = 0x01; |
53 | public static final byte RADIUS_CODE_ACCESS_ACCEPT = 0x02; | 54 | public static final byte RADIUS_CODE_ACCESS_ACCEPT = 0x02; |
54 | public static final byte RADIUS_CODE_ACCESS_REJECT = 0x03; | 55 | public static final byte RADIUS_CODE_ACCESS_REJECT = 0x03; |
... | @@ -58,43 +59,92 @@ public class RADIUS extends BasePacket { | ... | @@ -58,43 +59,92 @@ public class RADIUS extends BasePacket { |
58 | 59 | ||
59 | private final Logger log = getLogger(getClass()); | 60 | private final Logger log = getLogger(getClass()); |
60 | 61 | ||
62 | + /** | ||
63 | + * Default constructor. | ||
64 | + */ | ||
61 | public RADIUS() { | 65 | public RADIUS() { |
62 | } | 66 | } |
63 | 67 | ||
68 | + /** | ||
69 | + * Constructs a RADIUS packet with the given code and identifier. | ||
70 | + * | ||
71 | + * @param code code | ||
72 | + * @param identifier identifier | ||
73 | + */ | ||
64 | public RADIUS(byte code, byte identifier) { | 74 | public RADIUS(byte code, byte identifier) { |
65 | this.code = code; | 75 | this.code = code; |
66 | this.identifier = identifier; | 76 | this.identifier = identifier; |
67 | } | 77 | } |
68 | 78 | ||
79 | + /** | ||
80 | + * Gets the code. | ||
81 | + * | ||
82 | + * @return code | ||
83 | + */ | ||
69 | public byte getCode() { | 84 | public byte getCode() { |
70 | return this.code; | 85 | return this.code; |
71 | } | 86 | } |
72 | 87 | ||
88 | + /** | ||
89 | + * Sets the code. | ||
90 | + * | ||
91 | + * @param code code | ||
92 | + */ | ||
73 | public void setCode(byte code) { | 93 | public void setCode(byte code) { |
74 | this.code = code; | 94 | this.code = code; |
75 | } | 95 | } |
76 | 96 | ||
97 | + /** | ||
98 | + * Gets the identifier. | ||
99 | + * | ||
100 | + * @return identifier | ||
101 | + */ | ||
77 | public byte getIdentifier() { | 102 | public byte getIdentifier() { |
78 | return this.identifier; | 103 | return this.identifier; |
79 | } | 104 | } |
80 | 105 | ||
106 | + /** | ||
107 | + * Sets the identifier. | ||
108 | + * | ||
109 | + * @param identifier identifier | ||
110 | + */ | ||
81 | public void setIdentifier(byte identifier) { | 111 | public void setIdentifier(byte identifier) { |
82 | this.identifier = identifier; | 112 | this.identifier = identifier; |
83 | } | 113 | } |
84 | 114 | ||
115 | + /** | ||
116 | + * Gets the authenticator. | ||
117 | + * | ||
118 | + * @return authenticator | ||
119 | + */ | ||
85 | public byte[] getAuthenticator() { | 120 | public byte[] getAuthenticator() { |
86 | return this.authenticator; | 121 | return this.authenticator; |
87 | } | 122 | } |
88 | 123 | ||
89 | - public void setAuthenticator(byte[] a) { | 124 | + /** |
90 | - this.authenticator = a; | 125 | + * Sets the authenticator. |
126 | + * | ||
127 | + * @param authenticator authenticator | ||
128 | + */ | ||
129 | + public void setAuthenticator(byte[] authenticator) { | ||
130 | + this.authenticator = authenticator; | ||
91 | } | 131 | } |
92 | 132 | ||
133 | + /** | ||
134 | + * Generates an authenticator code. | ||
135 | + * | ||
136 | + * @return the authenticator | ||
137 | + */ | ||
93 | public byte[] generateAuthCode() { | 138 | public byte[] generateAuthCode() { |
94 | new SecureRandom().nextBytes(this.authenticator); | 139 | new SecureRandom().nextBytes(this.authenticator); |
95 | return this.authenticator; | 140 | return this.authenticator; |
96 | } | 141 | } |
97 | 142 | ||
143 | + /** | ||
144 | + * Checks if the packet's code field is valid. | ||
145 | + * | ||
146 | + * @return whether the code is valid | ||
147 | + */ | ||
98 | public boolean isValidCode() { | 148 | public boolean isValidCode() { |
99 | return this.code == RADIUS_CODE_ACCESS_REQUEST || | 149 | return this.code == RADIUS_CODE_ACCESS_REQUEST || |
100 | this.code == RADIUS_CODE_ACCESS_ACCEPT || | 150 | this.code == RADIUS_CODE_ACCESS_ACCEPT || |
... | @@ -104,11 +154,17 @@ public class RADIUS extends BasePacket { | ... | @@ -104,11 +154,17 @@ public class RADIUS extends BasePacket { |
104 | this.code == RADIUS_CODE_ACCESS_CHALLENGE; | 154 | this.code == RADIUS_CODE_ACCESS_CHALLENGE; |
105 | } | 155 | } |
106 | 156 | ||
157 | + /** | ||
158 | + * Adds a message authenticator to the packet based on the given key. | ||
159 | + * | ||
160 | + * @param key key to generate message authenticator | ||
161 | + * @return the messgae authenticator RADIUS attribute | ||
162 | + */ | ||
107 | public RADIUSAttribute addMessageAuthenticator(String key) { | 163 | public RADIUSAttribute addMessageAuthenticator(String key) { |
108 | - /* Message-Authenticator = HMAC-MD5 (Type, Identifier, Length, Request Authenticator, Attributes) | 164 | + // Message-Authenticator = HMAC-MD5 (Type, Identifier, Length, |
109 | - When the message integrity check is calculated the signature string should be considered to be | 165 | + // Request Authenticator, Attributes) |
110 | - sixteen octets of zero. | 166 | + // When the message integrity check is calculated the signature string |
111 | - */ | 167 | + // should be considered to be sixteen octets of zero. |
112 | byte[] hashOutput = new byte[16]; | 168 | byte[] hashOutput = new byte[16]; |
113 | Arrays.fill(hashOutput, (byte) 0); | 169 | Arrays.fill(hashOutput, (byte) 0); |
114 | 170 | ||
... | @@ -136,6 +192,13 @@ public class RADIUS extends BasePacket { | ... | @@ -136,6 +192,13 @@ public class RADIUS extends BasePacket { |
136 | return authAttribute; | 192 | return authAttribute; |
137 | } | 193 | } |
138 | 194 | ||
195 | + /** | ||
196 | + * Checks the message authenticator in the packet with one generated from | ||
197 | + * the given key. | ||
198 | + * | ||
199 | + * @param key key to generate message authenticator | ||
200 | + * @return whether the message authenticators match or not | ||
201 | + */ | ||
139 | public boolean checkMessageAuthenticator(String key) { | 202 | public boolean checkMessageAuthenticator(String key) { |
140 | byte[] newHash = new byte[16]; | 203 | byte[] newHash = new byte[16]; |
141 | Arrays.fill(newHash, (byte) 0); | 204 | Arrays.fill(newHash, (byte) 0); |
... | @@ -156,8 +219,10 @@ public class RADIUS extends BasePacket { | ... | @@ -156,8 +219,10 @@ public class RADIUS extends BasePacket { |
156 | } | 219 | } |
157 | 220 | ||
158 | /** | 221 | /** |
159 | - * @param message | 222 | + * Encapsulates an EAP packet in this RADIUS packet. |
160 | - * EAP message object to be embedded in the RADIUS EAP-Message attributed | 223 | + * |
224 | + * @param message EAP message object to be embedded in the RADIUS | ||
225 | + * EAP-Message attributed | ||
161 | */ | 226 | */ |
162 | public void encapsulateMessage(EAP message) { | 227 | public void encapsulateMessage(EAP message) { |
163 | if (message.length <= MAX_ATTR_VALUE_LENGTH) { | 228 | if (message.length <= MAX_ATTR_VALUE_LENGTH) { |
... | @@ -193,6 +258,8 @@ public class RADIUS extends BasePacket { | ... | @@ -193,6 +258,8 @@ public class RADIUS extends BasePacket { |
193 | } | 258 | } |
194 | 259 | ||
195 | /** | 260 | /** |
261 | + * Decapsulates an EAP packet from the RADIUS packet. | ||
262 | + * | ||
196 | * @return An EAP object containing the reassembled EAP message | 263 | * @return An EAP object containing the reassembled EAP message |
197 | */ | 264 | */ |
198 | public EAP decapsulateMessage() { | 265 | public EAP decapsulateMessage() { |
... | @@ -212,8 +279,9 @@ public class RADIUS extends BasePacket { | ... | @@ -212,8 +279,9 @@ public class RADIUS extends BasePacket { |
212 | } | 279 | } |
213 | 280 | ||
214 | /** | 281 | /** |
215 | - * @param attrType | 282 | + * Gets a list of attributes from the RADIUS packet. |
216 | - * the type field of the required attributes | 283 | + * |
284 | + * @param attrType the type field of the required attributes | ||
217 | * @return List of the attributes that matches the type or an empty list if there is none | 285 | * @return List of the attributes that matches the type or an empty list if there is none |
218 | */ | 286 | */ |
219 | public ArrayList<RADIUSAttribute> getAttributeList(byte attrType) { | 287 | public ArrayList<RADIUSAttribute> getAttributeList(byte attrType) { |
... | @@ -227,8 +295,9 @@ public class RADIUS extends BasePacket { | ... | @@ -227,8 +295,9 @@ public class RADIUS extends BasePacket { |
227 | } | 295 | } |
228 | 296 | ||
229 | /** | 297 | /** |
230 | - * @param attrType | 298 | + * Gets an attribute from the RADIUS packet. |
231 | - * the type field of the required attribute | 299 | + * |
300 | + * @param attrType the type field of the required attribute | ||
232 | * @return the first attribute that matches the type or null if does not exist | 301 | * @return the first attribute that matches the type or null if does not exist |
233 | */ | 302 | */ |
234 | public RADIUSAttribute getAttribute(byte attrType) { | 303 | public RADIUSAttribute getAttribute(byte attrType) { |
... | @@ -241,10 +310,10 @@ public class RADIUS extends BasePacket { | ... | @@ -241,10 +310,10 @@ public class RADIUS extends BasePacket { |
241 | } | 310 | } |
242 | 311 | ||
243 | /** | 312 | /** |
244 | - * @param attrType | 313 | + * Sets an attribute in the RADIUS packet. |
245 | - * the type field of the attribute to set | 314 | + * |
246 | - * @param value | 315 | + * @param attrType the type field of the attribute to set |
247 | - * value to be set | 316 | + * @param value value to be set |
248 | * @return reference to the attribute object | 317 | * @return reference to the attribute object |
249 | */ | 318 | */ |
250 | public RADIUSAttribute setAttribute(byte attrType, byte[] value) { | 319 | public RADIUSAttribute setAttribute(byte attrType, byte[] value) { |
... | @@ -255,6 +324,13 @@ public class RADIUS extends BasePacket { | ... | @@ -255,6 +324,13 @@ public class RADIUS extends BasePacket { |
255 | return newAttribute; | 324 | return newAttribute; |
256 | } | 325 | } |
257 | 326 | ||
327 | + /** | ||
328 | + * Updates an attribute in the RADIUS packet. | ||
329 | + * | ||
330 | + * @param attrType the type field of the attribute to update | ||
331 | + * @param value the value to update to | ||
332 | + * @return reference to the attribute object | ||
333 | + */ | ||
258 | public RADIUSAttribute updateAttribute(byte attrType, byte[] value) { | 334 | public RADIUSAttribute updateAttribute(byte attrType, byte[] value) { |
259 | for (int i = 0; i < this.attributes.size(); i++) { | 335 | for (int i = 0; i < this.attributes.size(); i++) { |
260 | if (this.attributes.get(i).getType() == attrType) { | 336 | if (this.attributes.get(i).getType() == attrType) { |
... | @@ -268,6 +344,40 @@ public class RADIUS extends BasePacket { | ... | @@ -268,6 +344,40 @@ public class RADIUS extends BasePacket { |
268 | return null; | 344 | return null; |
269 | } | 345 | } |
270 | 346 | ||
347 | + /** | ||
348 | + * Deserializer for RADIUS packets. | ||
349 | + * | ||
350 | + * @return deserializer | ||
351 | + */ | ||
352 | + public static Deserializer<RADIUS> deserializer() { | ||
353 | + return (data, offset, length) -> { | ||
354 | + checkInput(data, offset, length, RADIUS_MIN_LENGTH); | ||
355 | + | ||
356 | + final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); | ||
357 | + RADIUS radius = new RADIUS(); | ||
358 | + radius.code = bb.get(); | ||
359 | + radius.identifier = bb.get(); | ||
360 | + radius.length = bb.getShort(); | ||
361 | + bb.get(radius.authenticator, 0, 16); | ||
362 | + | ||
363 | + checkHeaderLength(length, radius.length); | ||
364 | + | ||
365 | + int remainingLength = radius.length - RADIUS_MIN_LENGTH; | ||
366 | + while (remainingLength > 0 && bb.hasRemaining()) { | ||
367 | + | ||
368 | + RADIUSAttribute attr = new RADIUSAttribute(); | ||
369 | + attr.setType(bb.get()); | ||
370 | + attr.setLength(bb.get()); | ||
371 | + short attrLength = (short) (attr.length & 0xff); | ||
372 | + attr.value = new byte[attrLength - 2]; | ||
373 | + bb.get(attr.value, 0, attrLength - 2); | ||
374 | + radius.attributes.add(attr); | ||
375 | + remainingLength -= attr.length; | ||
376 | + } | ||
377 | + return radius; | ||
378 | + }; | ||
379 | + } | ||
380 | + | ||
271 | @Override | 381 | @Override |
272 | public byte[] serialize() { | 382 | public byte[] serialize() { |
273 | final byte[] data = new byte[this.length]; | 383 | final byte[] data = new byte[this.length]; | ... | ... |
... | @@ -16,16 +16,17 @@ | ... | @@ -16,16 +16,17 @@ |
16 | * | 16 | * |
17 | */ | 17 | */ |
18 | 18 | ||
19 | -package org.onosproject.aaa.packet; | 19 | +package org.onlab.packet; |
20 | - | ||
21 | -import java.nio.ByteBuffer; | ||
22 | 20 | ||
21 | +/** | ||
22 | + * An attribute in a RADIUS packet. | ||
23 | + */ | ||
23 | public class RADIUSAttribute { | 24 | public class RADIUSAttribute { |
24 | protected byte type; | 25 | protected byte type; |
25 | protected byte length; | 26 | protected byte length; |
26 | protected byte[] value; | 27 | protected byte[] value; |
27 | 28 | ||
28 | - /* RADIUS attribute types */ | 29 | + // RADIUS attribute types |
29 | public static final byte RADIUS_ATTR_USERNAME = 1; | 30 | public static final byte RADIUS_ATTR_USERNAME = 1; |
30 | public static final byte RADIUS_ATTR_NAS_IP = 4; | 31 | public static final byte RADIUS_ATTR_NAS_IP = 4; |
31 | public static final byte RADIUS_ATTR_NAS_PORT = 5; | 32 | public static final byte RADIUS_ATTR_NAS_PORT = 5; |
... | @@ -40,15 +41,30 @@ public class RADIUSAttribute { | ... | @@ -40,15 +41,30 @@ public class RADIUSAttribute { |
40 | public static final byte RADIUS_ATTR_MESSAGE_AUTH = 80; | 41 | public static final byte RADIUS_ATTR_MESSAGE_AUTH = 80; |
41 | public static final byte RADIUS_ATTR_NAS_PORT_ID = 87; | 42 | public static final byte RADIUS_ATTR_NAS_PORT_ID = 87; |
42 | 43 | ||
44 | + /** | ||
45 | + * Default constructor. | ||
46 | + */ | ||
43 | public RADIUSAttribute() { | 47 | public RADIUSAttribute() { |
44 | } | 48 | } |
45 | 49 | ||
50 | + /** | ||
51 | + * Constructs a RADIUS attribute with the give type, length and value. | ||
52 | + * | ||
53 | + * @param type type | ||
54 | + * @param length length | ||
55 | + * @param value value | ||
56 | + */ | ||
46 | public RADIUSAttribute(final byte type, final byte length, final byte[] value) { | 57 | public RADIUSAttribute(final byte type, final byte length, final byte[] value) { |
47 | this.type = type; | 58 | this.type = type; |
48 | this.length = length; | 59 | this.length = length; |
49 | this.value = value; | 60 | this.value = value; |
50 | } | 61 | } |
51 | 62 | ||
63 | + /** | ||
64 | + * Checks if the attribute type is valid. | ||
65 | + * | ||
66 | + * @return whether the type is valid or not | ||
67 | + */ | ||
52 | public boolean isValidType() { | 68 | public boolean isValidType() { |
53 | return this.type == RADIUS_ATTR_USERNAME || | 69 | return this.type == RADIUS_ATTR_USERNAME || |
54 | this.type == RADIUS_ATTR_NAS_IP || | 70 | this.type == RADIUS_ATTR_NAS_IP || |
... | @@ -64,6 +80,8 @@ public class RADIUSAttribute { | ... | @@ -64,6 +80,8 @@ public class RADIUSAttribute { |
64 | } | 80 | } |
65 | 81 | ||
66 | /** | 82 | /** |
83 | + * Gets the attribute type. | ||
84 | + * | ||
67 | * @return the type | 85 | * @return the type |
68 | */ | 86 | */ |
69 | public byte getType() { | 87 | public byte getType() { |
... | @@ -71,8 +89,9 @@ public class RADIUSAttribute { | ... | @@ -71,8 +89,9 @@ public class RADIUSAttribute { |
71 | } | 89 | } |
72 | 90 | ||
73 | /** | 91 | /** |
74 | - * @param type | 92 | + * Sets the attribute type. |
75 | - * the code to set | 93 | + * |
94 | + * @param type the code to set | ||
76 | * @return this | 95 | * @return this |
77 | */ | 96 | */ |
78 | public RADIUSAttribute setType(final byte type) { | 97 | public RADIUSAttribute setType(final byte type) { |
... | @@ -81,6 +100,8 @@ public class RADIUSAttribute { | ... | @@ -81,6 +100,8 @@ public class RADIUSAttribute { |
81 | } | 100 | } |
82 | 101 | ||
83 | /** | 102 | /** |
103 | + * Gets the attribute length. | ||
104 | + * | ||
84 | * @return the length | 105 | * @return the length |
85 | */ | 106 | */ |
86 | public byte getLength() { | 107 | public byte getLength() { |
... | @@ -88,8 +109,9 @@ public class RADIUSAttribute { | ... | @@ -88,8 +109,9 @@ public class RADIUSAttribute { |
88 | } | 109 | } |
89 | 110 | ||
90 | /** | 111 | /** |
91 | - * @param length | 112 | + * Sets the attribute length. |
92 | - * the length to set | 113 | + * |
114 | + * @param length the length to set | ||
93 | * @return this | 115 | * @return this |
94 | */ | 116 | */ |
95 | public RADIUSAttribute setLength(final byte length) { | 117 | public RADIUSAttribute setLength(final byte length) { |
... | @@ -98,6 +120,8 @@ public class RADIUSAttribute { | ... | @@ -98,6 +120,8 @@ public class RADIUSAttribute { |
98 | } | 120 | } |
99 | 121 | ||
100 | /** | 122 | /** |
123 | + * Gets the attribute value. | ||
124 | + * | ||
101 | * @return the value | 125 | * @return the value |
102 | */ | 126 | */ |
103 | public byte[] getValue() { | 127 | public byte[] getValue() { |
... | @@ -105,8 +129,9 @@ public class RADIUSAttribute { | ... | @@ -105,8 +129,9 @@ public class RADIUSAttribute { |
105 | } | 129 | } |
106 | 130 | ||
107 | /** | 131 | /** |
108 | - * @param value | 132 | + * Sets the attribute value. |
109 | - * the data to set | 133 | + * |
134 | + * @param value the data to set | ||
110 | * @return this | 135 | * @return this |
111 | */ | 136 | */ |
112 | public RADIUSAttribute setValue(final byte[] value) { | 137 | public RADIUSAttribute setValue(final byte[] value) { |
... | @@ -114,12 +139,4 @@ public class RADIUSAttribute { | ... | @@ -114,12 +139,4 @@ public class RADIUSAttribute { |
114 | return this; | 139 | return this; |
115 | } | 140 | } |
116 | 141 | ||
117 | - public byte[] serialize() { | ||
118 | - final byte[] data = new byte[this.length]; | ||
119 | - final ByteBuffer bb = ByteBuffer.wrap(data); | ||
120 | - bb.put(this.type); | ||
121 | - bb.put(this.length); | ||
122 | - bb.put(this.value); | ||
123 | - return data; | ||
124 | - } | ||
125 | } | 142 | } | ... | ... |
-
Please register or login to post a comment