Ari Saha
Committed by Gerrit Code Review

ONOS AAA app: Authentication and Authorization logic.

Change-Id: I36eb889eeab38edf12377c13e780a147551459a4
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.aaa" origin="ATT" version="${project.version}"
18 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
19 + features="${project.artifactId}">
20 + <description>${project.description}</description>
21 + <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact>
22 + <artifact>mvn:${project.groupId}/onos-app-xos-integration/${project.version}</artifact>
23 + <bundle>mvn:com.sun.jersey/jersey-client/1.19</bundle>
24 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
19 + <feature name="${project.artifactId}" version="${project.version}"
20 + description="${project.description}">
21 + <feature>onos-api</feature>
22 + <bundle>mvn:com.sun.jersey/jersey-client/1.19</bundle>
23 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
24 + <bundle>mvn:${project.groupId}/onos-app-xos-integration/${project.version}</bundle>
25 + </feature>
26 +</features>
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 +
23 + <parent>
24 + <groupId>org.onosproject</groupId>
25 + <artifactId>onos-apps</artifactId>
26 + <version>1.3.0-SNAPSHOT</version>
27 + <relativePath>../pom.xml</relativePath>
28 + </parent>
29 +
30 + <artifactId>onos-app-aaa</artifactId>
31 + <packaging>bundle</packaging>
32 +
33 + <description>ONOS authentication application</description>
34 +
35 + <properties>
36 + <onos.app.name>org.onosproject.aaa</onos.app.name>
37 + </properties>
38 +
39 + <dependencies>
40 + <dependency>
41 + <groupId>org.osgi</groupId>
42 + <artifactId>org.osgi.compendium</artifactId>
43 + </dependency>
44 +
45 + <dependency>
46 + <groupId>org.onosproject</groupId>
47 + <artifactId>onlab-junit</artifactId>
48 + <scope>test</scope>
49 + </dependency>
50 +
51 + <dependency>
52 + <groupId>org.onosproject</groupId>
53 + <artifactId>onos-api</artifactId>
54 + <version>${project.version}</version>
55 + </dependency>
56 +
57 + <dependency>
58 + <groupId>org.onosproject</groupId>
59 + <artifactId>onlab-osgi</artifactId>
60 + <version>${project.version}</version>
61 + </dependency>
62 +
63 + <dependency>
64 + <groupId>org.apache.felix</groupId>
65 + <artifactId>org.apache.felix.scr.annotations</artifactId>
66 + </dependency>
67 +
68 + <dependency>
69 + <groupId>org.onosproject</groupId>
70 + <artifactId>onos-app-xos-integration</artifactId>
71 + <version>${project.version}</version>
72 + </dependency>
73 + </dependencies>
74 +
75 +
76 + <build>
77 + <plugins>
78 + <plugin>
79 + <groupId>org.apache.felix</groupId>
80 + <artifactId>maven-bundle-plugin</artifactId>
81 + </plugin>
82 +
83 + <plugin>
84 + <groupId>org.apache.felix</groupId>
85 + <artifactId>maven-scr-plugin</artifactId>
86 + </plugin>
87 + <plugin>
88 + <groupId>org.onosproject</groupId>
89 + <artifactId>onos-maven-plugin</artifactId>
90 + </plugin>
91 + </plugins>
92 + </build>
93 +</project>
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +/*
2 + * Copyright 2014 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 +/**
18 + * AAA implmentation.
19 + */
20 +package org.onosproject.aaa;
1 +/*
2 + *
3 + * * Copyright 2015 AT&T Foundry
4 + * *
5 + * * Licensed under the Apache License, Version 2.0 (the "License");
6 + * * you may not use this file except in compliance with the License.
7 + * * You may obtain a copy of the License at
8 + * *
9 + * * http://www.apache.org/licenses/LICENSE-2.0
10 + * *
11 + * * Unless required by applicable law or agreed to in writing, software
12 + * * distributed under the License is distributed on an "AS IS" BASIS,
13 + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * * See the License for the specific language governing permissions and
15 + * * limitations under the License.
16 + *
17 + */
18 +
19 +package org.onosproject.aaa.packet;
20 +
21 +import org.onlab.packet.BasePacket;
22 +import org.onlab.packet.IPacket;
23 +
24 +import java.nio.ByteBuffer;
25 +
26 +
27 +/**
28 + *
29 + */
30 +public class EAP extends BasePacket {
31 + 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_SUC_FAIL = 4;
34 +
35 + /* EAP Code */
36 + public static final byte REQUEST = 0x1;
37 + public static final byte RESPONSE = 0x2;
38 + public static final byte SUCCESS = 0x3;
39 + public static final byte FAILURE = 0x4;
40 +
41 + /* EAP Attribute Type */
42 + public static final byte ATTR_IDENTITY = 0x1;
43 + public static final byte ATTR_NOTIFICATION = 0x2;
44 + public static final byte ATTR_NAK = 0x3;
45 + public static final byte ATTR_MD5 = 0x4;
46 + public static final byte ATTR_OTP = 0x5;
47 + public static final byte ATTR_GTC = 0x6;
48 + public static final byte ATTR_TLS = 0xd;
49 +
50 + protected byte code;
51 + protected byte identifier;
52 + protected short length;
53 + protected byte type;
54 + protected byte[] data;
55 +
56 +
57 + /**
58 + * Get the EAP code.
59 + * @return EAP code
60 + */
61 + public byte getCode() {
62 + return this.code;
63 + }
64 +
65 +
66 + /**
67 + * Set the EAP code.
68 + * @param code EAP code
69 + * @return this
70 + */
71 + public EAP setCode(final byte code) {
72 + this.code = code;
73 + return this;
74 + }
75 +
76 + /**
77 + * Get the EAP identifier.
78 + * @return EAP identifier
79 + */
80 + public byte getIdentifier() {
81 + return this.identifier;
82 + }
83 +
84 + /**
85 + * Set the EAP identifier.
86 + * @param identifier
87 + * @return this
88 + */
89 + public EAP setIdentifier(final byte identifier) {
90 + this.identifier = identifier;
91 + return this;
92 + }
93 +
94 + /**
95 + * Get the get packet length.
96 + * @return packet length
97 + */
98 + public short getLength() {
99 + return this.length;
100 + }
101 +
102 + /**
103 + * Set the packet length.
104 + * @param length packet length
105 + * @return this
106 + */
107 + public EAP setLength(final short length) {
108 + this.length = length;
109 + return this;
110 + }
111 +
112 + /**
113 + * Get the data type.
114 + * @return data type
115 + */
116 + public byte getDataType() {
117 + return this.type;
118 + }
119 +
120 + /**
121 + * Set the data type.
122 + * @param type data type
123 + * @return this
124 + */
125 + public EAP setDataType(final byte type) {
126 + this.type = type;
127 + return this;
128 + }
129 +
130 + /**
131 + * Get the EAP data.
132 + * @return EAP data
133 + */
134 + public byte[] getData() {
135 + return this.data;
136 + }
137 +
138 + /**
139 + * Set the EAP data.
140 + * @param data EAP data to be set
141 + * @return this
142 + */
143 + public EAP setData(final byte[] data) {
144 + this.data = data;
145 + return this;
146 + }
147 +
148 + /**
149 + * Default EAP constructor that set the EAP code to 0.
150 + */
151 + public EAP() {
152 + this.code = 0;
153 + }
154 +
155 + /**
156 + * EAP constructor that initially sets all fields.
157 + * @param code EAP code
158 + * @param identifier EAP identifier
159 + * @param type packet type
160 + * @param data EAP data
161 + */
162 + public EAP(byte code, byte identifier, byte type, byte[] data) {
163 + this.code = code;
164 + this.identifier = identifier;
165 + if (this.code == REQUEST || this.code == RESPONSE) {
166 + this.length = (short) (5 + (data == null ? 0 : data.length));
167 + this.type = type;
168 + } else {
169 + this.length = (short) (4 + (data == null ? 0 : data.length));
170 + }
171 + this.data = data;
172 + }
173 +
174 + /**
175 + * Serializes the packet, based on the code/type using the payload
176 + * to compute its length.
177 + * @return the serialized payload
178 + */
179 + @Override
180 + public byte[] serialize() {
181 + final byte[] data = new byte[this.length];
182 +
183 + final ByteBuffer bb = ByteBuffer.wrap(data);
184 + bb.put(this.code);
185 + bb.put(this.identifier);
186 + bb.putShort(this.length);
187 + if (this.code == REQUEST || this.code == RESPONSE) {
188 + bb.put(this.type);
189 + }
190 + if (this.data != null) {
191 + bb.put(this.data);
192 + }
193 + return data;
194 + }
195 +
196 + @Override
197 + public IPacket deserialize(final byte[] data, final int offset,
198 + final int length) {
199 + final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
200 + this.code = bb.get();
201 + this.identifier = bb.get();
202 + this.length = bb.getShort();
203 +
204 + int dataLength;
205 + if (this.code == REQUEST || this.code == RESPONSE) {
206 + this.type = bb.get();
207 + dataLength = this.length - 5;
208 + } else {
209 + dataLength = this.length - 4;
210 + }
211 + this.data = new byte[dataLength];
212 + bb.get(this.data);
213 + return this;
214 + }
215 +
216 + @Override
217 + public int hashCode() {
218 + final int prime = 3889;
219 + int result = super.hashCode();
220 + result = prime * result + this.code;
221 + result = prime * result + this.identifier;
222 + result = prime * result + this.length;
223 + result = prime * result + this.type;
224 + return result;
225 + }
226 +}
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.ARP;
20 +import org.onlab.packet.Ethernet;
21 +import org.onlab.packet.IPv4;
22 +import org.onlab.packet.IPv6;
23 +import org.onlab.packet.LLDP;
24 +
25 +/**
26 + * Created by jono on 5/19/15.
27 + */
28 +public final class EAPEthernet extends Ethernet {
29 +
30 + public static final short TYPE_PAE = (short) 0x888e;
31 +
32 + private EAPEthernet() {
33 +
34 + }
35 +
36 + static {
37 + Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_ARP, ARP.class);
38 + org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_RARP, ARP.class);
39 + org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_IPV4, IPv4.class);
40 + org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_IPV6, IPv6.class);
41 + org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_LLDP, LLDP.class);
42 + org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(org.onlab.packet.Ethernet.TYPE_BSN, LLDP.class);
43 + org.onlab.packet.Ethernet.ETHER_TYPE_CLASS_MAP.put(TYPE_PAE, EAPOL.class);
44 + }
45 +}
1 +/*
2 + *
3 + * * Copyright 2015 AT&T Foundry
4 + * *
5 + * * Licensed under the Apache License, Version 2.0 (the "License");
6 + * * you may not use this file except in compliance with the License.
7 + * * You may obtain a copy of the License at
8 + * *
9 + * * http://www.apache.org/licenses/LICENSE-2.0
10 + * *
11 + * * Unless required by applicable law or agreed to in writing, software
12 + * * distributed under the License is distributed on an "AS IS" BASIS,
13 + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * * See the License for the specific language governing permissions and
15 + * * limitations under the License.
16 + *
17 + */
18 +
19 +package org.onosproject.aaa.packet;
20 +
21 +import org.onlab.packet.BasePacket;
22 +import org.onlab.packet.Ethernet;
23 +import org.onlab.packet.IPacket;
24 +import org.onlab.packet.MacAddress;
25 +
26 +import java.nio.ByteBuffer;
27 +
28 +/**
29 + *
30 + */
31 +public class EAPOL extends BasePacket {
32 +
33 + private byte version = 0x01;
34 + private byte eapolType;
35 + private short packetLength;
36 +
37 + /* EAPOL Packet Type */
38 + public static final byte EAPOL_PACKET = 0x0;
39 + public static final byte EAPOL_START = 0x1;
40 + public static final byte EAPOL_LOGOFF = 0x2;
41 + public static final byte EAPOL_KEY = 0x3;
42 + public static final byte EAPOL_ASF = 0x4;
43 +
44 + public static final MacAddress PAE_GROUP_ADDR = MacAddress.valueOf(new byte[] {
45 + (byte) 0x01, (byte) 0x80, (byte) 0xc2, (byte) 0x00, (byte) 0x00, (byte) 0x03
46 + });
47 +
48 +
49 + /**
50 + * Get version.
51 + * @return version
52 + */
53 + public byte getVersion() {
54 + return this.version;
55 + }
56 +
57 + /**
58 + * Set version.
59 + * @param version EAPOL version
60 + * @return this
61 + */
62 + public EAPOL setVersion(final byte version) {
63 + this.version = version;
64 + return this;
65 + }
66 +
67 + /**
68 + * Get type.
69 + * @return EAPOL type
70 + */
71 + public byte getEapolType() {
72 + return this.eapolType;
73 + }
74 +
75 + /**
76 + * Set EAPOL type.
77 + * @param eapolType EAPOL type
78 + * @return this
79 + */
80 + public EAPOL setEapolType(final byte eapolType) {
81 + this.eapolType = eapolType;
82 + return this;
83 + }
84 +
85 + /**
86 + * Get packet length.
87 + * @return packet length
88 + */
89 + public short getPacketLength() {
90 + return this.packetLength;
91 + }
92 +
93 + /**
94 + * Set packet length.
95 + * @param packetLen packet length
96 + * @return this
97 + */
98 + public EAPOL setPacketLength(final short packetLen) {
99 + this.packetLength = packetLen;
100 + return this;
101 + }
102 +
103 +
104 +
105 + /**
106 + * Serializes the packet, based on the code/type using the payload
107 + * to compute its length.
108 + * @return this
109 + */
110 + @Override
111 + public byte[] serialize() {
112 +
113 + byte[] payloadData = null;
114 +
115 + if (this.payload != null) {
116 + this.payload.setParent(this);
117 + payloadData = this.payload.serialize();
118 + }
119 +
120 + //prepare the buffer to hold the version (1), packet type (1), packet length (2) and the eap payload.
121 + //if there is no payload, packet length is 0
122 + byte[] data = new byte[4 + this.packetLength];
123 + final ByteBuffer bb = ByteBuffer.wrap(data);
124 + bb.put(this.version);
125 + bb.put(this.eapolType);
126 + bb.putShort(this.packetLength);
127 +
128 + //put the EAP payload
129 + if (payloadData != null) {
130 + bb.put(payloadData);
131 + }
132 +
133 + return data;
134 + }
135 +
136 + @Override
137 + public IPacket deserialize(final byte[] data, final int offset,
138 + final int length) {
139 + final ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
140 +
141 +
142 + //deserialize the EAPOL header
143 + this.version = bb.get();
144 + this.eapolType = bb.get();
145 + this.packetLength = bb.getShort();
146 +
147 + if (this.packetLength > 0) {
148 + //deserialize the EAP Payload
149 + this.payload = new EAP();
150 +
151 + this.payload = this.payload.deserialize(data, bb.position(), length - 4);
152 + this.payload.setParent(this);
153 + }
154 +
155 +
156 + return this;
157 + }
158 +
159 + @Override
160 + public int hashCode() {
161 + final int prime = 3889;
162 + int result = super.hashCode();
163 + result = prime * result + this.version;
164 + result = prime * result + this.eapolType;
165 + result = prime * result + this.packetLength;
166 + return result;
167 + }
168 +
169 + /**
170 + *
171 + * @param dstMac
172 + * @param srcMac
173 + * @param eapolType
174 + * @param eap
175 + * @return Ethernet frame
176 + */
177 + public static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac,
178 + short vlan, byte eapolType, EAP eap) {
179 +
180 + Ethernet eth = new Ethernet();
181 + eth.setDestinationMACAddress(dstMac.toBytes());
182 + eth.setSourceMACAddress(srcMac.toBytes());
183 + eth.setEtherType(EAPEthernet.TYPE_PAE);
184 + if (vlan != Ethernet.VLAN_UNTAGGED) {
185 + eth.setVlanID(vlan);
186 + }
187 + //eapol header
188 + EAPOL eapol = new EAPOL();
189 + eapol.setEapolType(eapolType);
190 + eapol.setPacketLength(eap.getLength());
191 +
192 + //eap part
193 + eapol.setPayload(eap);
194 +
195 + eth.setPayload(eapol);
196 + eth.setPad(true);
197 + return eth;
198 + }
199 +}
200 +
This diff is collapsed. Click to expand it.
1 +/*
2 + *
3 + * * Copyright 2015 AT&T Foundry
4 + * *
5 + * * Licensed under the Apache License, Version 2.0 (the "License");
6 + * * you may not use this file except in compliance with the License.
7 + * * You may obtain a copy of the License at
8 + * *
9 + * * http://www.apache.org/licenses/LICENSE-2.0
10 + * *
11 + * * Unless required by applicable law or agreed to in writing, software
12 + * * distributed under the License is distributed on an "AS IS" BASIS,
13 + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * * See the License for the specific language governing permissions and
15 + * * limitations under the License.
16 + *
17 + */
18 +
19 +package org.onosproject.aaa.packet;
20 +
21 +import java.nio.ByteBuffer;
22 +
23 +public class RADIUSAttribute {
24 + protected byte type;
25 + protected byte length;
26 + protected byte[] value;
27 +
28 + /* RADIUS attribute types */
29 + 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_PORT = 5;
32 + public static final byte RADIUS_ATTR_FRAMED_MTU = 12;
33 + public static final byte RADIUS_ATTR_STATE = 24;
34 + public static final byte RADIUS_ATTR_VENDOR_SPECIFIC = 26;
35 + public static final byte RADIUS_ATTR_CALLING_STATION_ID = 31;
36 + public static final byte RADIUS_ATTR_NAS_ID = 32;
37 + public static final byte RADIUS_ATTR_ACCT_SESSION_ID = 44;
38 + public static final byte RADIUS_ATTR_NAS_PORT_TYPE = 61;
39 + public static final byte RADIUS_ATTR_EAP_MESSAGE = 79;
40 + public static final byte RADIUS_ATTR_MESSAGE_AUTH = 80;
41 + public static final byte RADIUS_ATTR_NAS_PORT_ID = 87;
42 +
43 + public RADIUSAttribute() {
44 + }
45 +
46 + public RADIUSAttribute(final byte type, final byte length, final byte[] value) {
47 + this.type = type;
48 + this.length = length;
49 + this.value = value;
50 + }
51 +
52 + public boolean isValidType() {
53 + return this.type == RADIUS_ATTR_USERNAME ||
54 + this.type == RADIUS_ATTR_NAS_IP ||
55 + this.type == RADIUS_ATTR_NAS_PORT ||
56 + this.type == RADIUS_ATTR_VENDOR_SPECIFIC ||
57 + this.type == RADIUS_ATTR_CALLING_STATION_ID ||
58 + this.type == RADIUS_ATTR_NAS_ID ||
59 + this.type == RADIUS_ATTR_ACCT_SESSION_ID ||
60 + this.type == RADIUS_ATTR_NAS_PORT_TYPE ||
61 + this.type == RADIUS_ATTR_EAP_MESSAGE ||
62 + this.type == RADIUS_ATTR_MESSAGE_AUTH ||
63 + this.type == RADIUS_ATTR_NAS_PORT_ID;
64 + }
65 +
66 + /**
67 + * @return the type
68 + */
69 + public byte getType() {
70 + return this.type;
71 + }
72 +
73 + /**
74 + * @param type
75 + * the code to set
76 + * @return this
77 + */
78 + public RADIUSAttribute setType(final byte type) {
79 + this.type = type;
80 + return this;
81 + }
82 +
83 + /**
84 + * @return the length
85 + */
86 + public byte getLength() {
87 + return this.length;
88 + }
89 +
90 + /**
91 + * @param length
92 + * the length to set
93 + * @return this
94 + */
95 + public RADIUSAttribute setLength(final byte length) {
96 + this.length = length;
97 + return this;
98 + }
99 +
100 + /**
101 + * @return the value
102 + */
103 + public byte[] getValue() {
104 + return this.value;
105 + }
106 +
107 + /**
108 + * @param value
109 + * the data to set
110 + * @return this
111 + */
112 + public RADIUSAttribute setValue(final byte[] value) {
113 + this.value = value;
114 + return this;
115 + }
116 +
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 +}
1 +/*
2 + * Copyright 2014 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 +package org.onosproject.aaa;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +
22 +/**
23 + * Set of tests of the ONOS application component.
24 + */
25 +public class AAATest {
26 +
27 + private AAA aaa;
28 +
29 + @Before
30 + public void setUp() {
31 +
32 + }
33 +
34 + @After
35 + public void tearDown() {
36 + }
37 +
38 + @Test
39 + public void basics() {
40 +
41 + }
42 +
43 +}
1 +/*
2 + *
3 + * Copyright 2015 AT&T Foundry
4 + *
5 + * Licensed under the Apache License, Version 2.0 (the "License");
6 + * you may not use this file except in compliance with the License.
7 + * You may obtain a copy of the License at
8 + *
9 + * http://www.apache.org/licenses/LICENSE-2.0
10 + *
11 + * Unless required by applicable law or agreed to in writing, software
12 + * distributed under the License is distributed on an "AS IS" BASIS,
13 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * See the License for the specific language governing permissions and
15 + * limitations under the License.
16 + *
17 + */
18 +package org.onosproject.aaa;
19 +
20 +import org.junit.After;
21 +import org.junit.Assert;
22 +import org.junit.Before;
23 +import org.junit.Test;
24 +
25 +
26 +public class StateMachineTest {
27 + StateMachine stateMachine = null;
28 +
29 + @Before
30 + public void setUp() {
31 + System.out.println("Set Up.");
32 + StateMachine.bitSet.clear();
33 + stateMachine = new StateMachine("session0", null);
34 + }
35 +
36 + @After
37 + public void tearDown() {
38 + System.out.println("Tear Down.");
39 + StateMachine.bitSet.clear();
40 + stateMachine = null;
41 + }
42 +
43 + @Test
44 + /**
45 + * Test all the basic inputs from state to state: IDLE -> STARTED -> PENDING -> AUTHORIZED -> IDLE
46 + */
47 + public void basic() throws StateMachineException {
48 + System.out.println("======= BASIC =======.");
49 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
50 +
51 + stateMachine.start();
52 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_STARTED);
53 +
54 + stateMachine.requestAccess();
55 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
56 +
57 + stateMachine.authorizeAccess();
58 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
59 +
60 + stateMachine.logoff();
61 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
62 + }
63 +
64 + @Test
65 + /**
66 + * Test all inputs from an IDLE state (starting with the ones that are not impacting the current state)
67 + */
68 + public void testIdleState() throws StateMachineException {
69 + System.out.println("======= IDLE STATE TEST =======.");
70 + stateMachine.requestAccess();
71 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
72 +
73 + stateMachine.authorizeAccess();
74 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
75 +
76 + stateMachine.denyAccess();
77 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
78 +
79 + stateMachine.logoff();
80 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
81 +
82 + stateMachine.start();
83 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_STARTED);
84 + }
85 +
86 + @Test
87 + /**
88 + * Test all inputs from an STARTED state (starting with the ones that are not impacting the current state)
89 + */
90 + public void testStartedState() throws StateMachineException {
91 + System.out.println("======= STARTED STATE TEST =======.");
92 + stateMachine.start();
93 +
94 + stateMachine.authorizeAccess();
95 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_STARTED);
96 +
97 + stateMachine.denyAccess();
98 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_STARTED);
99 +
100 + stateMachine.logoff();
101 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_STARTED);
102 +
103 + stateMachine.start();
104 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_STARTED);
105 +
106 + stateMachine.requestAccess();
107 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
108 + }
109 +
110 + @Test
111 + /**
112 + * Test all inputs from a PENDING state (starting with the ones that are not impacting the current state).
113 + * The next valid state for this test is AUTHORIZED
114 + */
115 + public void testPendingStateToAuthorized() throws StateMachineException {
116 + System.out.println("======= PENDING STATE TEST (AUTHORIZED) =======.");
117 + stateMachine.start();
118 + stateMachine.requestAccess();
119 +
120 + stateMachine.logoff();
121 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
122 +
123 + stateMachine.start();
124 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
125 +
126 + stateMachine.requestAccess();
127 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
128 +
129 + stateMachine.authorizeAccess();
130 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
131 +
132 + stateMachine.denyAccess();
133 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
134 + }
135 +
136 + @Test
137 + /**
138 + * Test all inputs from an PENDING state (starting with the ones that are not impacting the current state).
139 + * The next valid state for this test is UNAUTHORIZED
140 + */
141 + public void testPendingStateToUnauthorized() throws StateMachineException {
142 + System.out.println("======= PENDING STATE TEST (DENIED) =======.");
143 + stateMachine.start();
144 + stateMachine.requestAccess();
145 +
146 + stateMachine.logoff();
147 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
148 +
149 + stateMachine.start();
150 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
151 +
152 + stateMachine.requestAccess();
153 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_PENDING);
154 +
155 + stateMachine.denyAccess();
156 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_UNAUTHORIZED);
157 +
158 + stateMachine.authorizeAccess();
159 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_UNAUTHORIZED);
160 + }
161 +
162 + @Test
163 + /**
164 + * Test all inputs from an AUTHORIZED state (starting with the ones that are not impacting the current state).
165 + */
166 + public void testAuthorizedState() throws StateMachineException {
167 + System.out.println("======= AUTHORIZED STATE TEST =======.");
168 + stateMachine.start();
169 + stateMachine.requestAccess();
170 + stateMachine.authorizeAccess();
171 +
172 + stateMachine.start();
173 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
174 +
175 + stateMachine.requestAccess();
176 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
177 +
178 + stateMachine.authorizeAccess();
179 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
180 +
181 + stateMachine.denyAccess();
182 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_AUTHORIZED);
183 +
184 + stateMachine.logoff();
185 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
186 + }
187 +
188 + @Test
189 + /**
190 + * Test all inputs from an UNAUTHORIZED state (starting with the ones that are not impacting the current state).
191 + */
192 + public void testUnauthorizedState() throws StateMachineException {
193 + System.out.println("======= UNAUTHORIZED STATE TEST =======.");
194 + stateMachine.start();
195 + stateMachine.requestAccess();
196 + stateMachine.denyAccess();
197 +
198 + stateMachine.start();
199 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_UNAUTHORIZED);
200 +
201 + stateMachine.requestAccess();
202 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_UNAUTHORIZED);
203 +
204 + stateMachine.authorizeAccess();
205 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_UNAUTHORIZED);
206 +
207 + stateMachine.denyAccess();
208 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_UNAUTHORIZED);
209 +
210 + stateMachine.logoff();
211 + Assert.assertEquals(stateMachine.getState(), StateMachine.STATE_IDLE);
212 + }
213 +
214 +
215 + @Test
216 + public void testIdentifierAvailability() throws StateMachineException {
217 + System.out.println("======= IDENTIFIER TEST =======.");
218 + byte identifier = stateMachine.getIdentifier();
219 + System.out.println("State: " + stateMachine.getState());
220 + System.out.println("Identifier: " + Byte.toUnsignedInt(identifier));
221 + Assert.assertEquals(-1, identifier);
222 + stateMachine.start();
223 +
224 +
225 + StateMachine sm247 = null;
226 + StateMachine sm3 = null;
227 +
228 +
229 + //create 255 others state machines
230 + for (int i = 1; i <= 255; i++) {
231 + StateMachine sm = new StateMachine("session" + i, null);
232 + sm.start();
233 + byte id = sm.getIdentifier();
234 + Assert.assertEquals(i, Byte.toUnsignedInt(id));
235 + if (i == 3) {
236 + sm3 = sm;
237 + System.out.println("SM3: " + sm3.toString());
238 + }
239 + if (i == 247) {
240 + sm247 = sm;
241 + System.out.println("SM247: " + sm247.toString());
242 + }
243 + }
244 +
245 + //simulate the state machine for a specific session and logoff so we can free up a spot for an identifier
246 + //let's choose identifier 247 then we free up 3
247 + sm247.requestAccess();
248 + sm247.authorizeAccess();
249 + sm247.logoff();
250 + sm247 = null;
251 +
252 + sm3.requestAccess();
253 + sm3.authorizeAccess();
254 + sm3.logoff();
255 + sm3 = null;
256 +
257 + StateMachine otherSM3 = new StateMachine("session3b", null);
258 + otherSM3.start();
259 + otherSM3.requestAccess();
260 + byte id3 = otherSM3.getIdentifier();
261 + Assert.assertEquals(3, Byte.toUnsignedInt(id3));
262 +
263 + StateMachine otherSM247 = new StateMachine("session247b", null);
264 + otherSM247.start();
265 + otherSM247.requestAccess();
266 + byte id247 = otherSM247.getIdentifier();
267 + Assert.assertEquals(247, Byte.toUnsignedInt(id247));
268 +
269 + }
270 +}
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
32 <description>ONOS sample applications</description> 32 <description>ONOS sample applications</description>
33 33
34 <modules> 34 <modules>
35 + <module>aaa</module>
35 <module>fwd</module> 36 <module>fwd</module>
36 <module>mobility</module> 37 <module>mobility</module>
37 <module>proxyarp</module> 38 <module>proxyarp</module>
......