Ray Milkey
Committed by Gerrit Code Review

Unit tests for the OpenFlow controller class

Change-Id: I14a6e2810ec15edfccb309ab94dabe96670f4026
...@@ -94,7 +94,7 @@ public class Controller { ...@@ -94,7 +94,7 @@ public class Controller {
94 protected String tsLocation; 94 protected String tsLocation;
95 protected char[] ksPwd; 95 protected char[] ksPwd;
96 protected char[] tsPwd; 96 protected char[] tsPwd;
97 - private SSLEngine serverSSLEngine; 97 + protected SSLEngine serverSSLEngine;
98 98
99 // Perf. related configuration 99 // Perf. related configuration
100 protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; 100 protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024;
......
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 +package org.onosproject.openflow;
17 +
18 +import java.util.Map;
19 +import java.util.Set;
20 +
21 +import org.onosproject.net.driver.Behaviour;
22 +import org.onosproject.net.driver.Driver;
23 +import org.onosproject.net.driver.DriverData;
24 +import org.onosproject.net.driver.DriverHandler;
25 +import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
26 +
27 +/**
28 + * Created by ray on 11/4/15.
29 + */
30 +public class DriverAdapter implements Driver {
31 + @Override
32 + public String name() {
33 + return null;
34 + }
35 +
36 + @Override
37 + public Driver parent() {
38 + return null;
39 + }
40 +
41 + @Override
42 + public String manufacturer() {
43 + return null;
44 + }
45 +
46 + @Override
47 + public String hwVersion() {
48 + return null;
49 + }
50 +
51 + @Override
52 + public String swVersion() {
53 + return null;
54 + }
55 +
56 + @Override
57 + public Set<Class<? extends Behaviour>> behaviours() {
58 + return null;
59 + }
60 +
61 + @Override
62 + public Class<? extends Behaviour> implementation(Class<? extends Behaviour> behaviour) {
63 + return null;
64 + }
65 +
66 + @Override
67 + public boolean hasBehaviour(Class<? extends Behaviour> behaviourClass) {
68 + return true;
69 + }
70 +
71 + @Override
72 + public <T extends Behaviour> T createBehaviour(DriverData data, Class<T> behaviourClass) {
73 + return null;
74 + }
75 +
76 + @SuppressWarnings("unchecked")
77 + @Override
78 + public <T extends Behaviour> T createBehaviour(DriverHandler handler, Class<T> behaviourClass) {
79 + if (behaviourClass == OpenFlowSwitchDriver.class) {
80 + return (T) new OpenflowSwitchDriverAdapter();
81 + }
82 + return null;
83 + }
84 +
85 + @Override
86 + public Map<String, String> properties() {
87 + return null;
88 + }
89 +
90 + @Override
91 + public Driver merge(Driver other) {
92 + return null;
93 + }
94 +
95 + @Override
96 + public Set<String> keys() {
97 + return null;
98 + }
99 +
100 + @Override
101 + public String value(String key) {
102 + return null;
103 + }
104 +}
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 +package org.onosproject.openflow;
17 +
18 +import java.util.Set;
19 +
20 +import org.onosproject.net.DeviceId;
21 +import org.onosproject.net.driver.Behaviour;
22 +import org.onosproject.net.driver.Driver;
23 +import org.onosproject.net.driver.DriverHandler;
24 +import org.onosproject.net.driver.DriverService;
25 +
26 +/**
27 + * Created by ray on 11/4/15.
28 + */
29 +public class DriverServiceAdapter implements DriverService {
30 + @Override
31 + public Set<Driver> getDrivers() {
32 + return null;
33 + }
34 +
35 + @Override
36 + public Set<Driver> getDrivers(Class<? extends Behaviour> withBehaviour) {
37 + return null;
38 + }
39 +
40 + @Override
41 + public Driver getDriver(String mfr, String hw, String sw) {
42 + return null;
43 + }
44 +
45 + @Override
46 + public Driver getDriver(DeviceId deviceId) {
47 + return null;
48 + }
49 +
50 + @Override
51 + public DriverHandler createHandler(DeviceId deviceId, String... credentials) {
52 + return null;
53 + }
54 +
55 + @Override
56 + public Driver getDriver(String driverName) {
57 + return null;
58 + }
59 +}
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 +package org.onosproject.openflow;
17 +
18 +import java.util.Set;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
22 +import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
23 +import org.projectfloodlight.openflow.protocol.OFStatsType;
24 +import org.projectfloodlight.openflow.protocol.OFType;
25 +import org.projectfloodlight.openflow.protocol.OFVersion;
26 +
27 +import com.google.common.hash.PrimitiveSink;
28 +
29 +/**
30 + * Created by ray on 11/4/15.
31 + */
32 +public class OFDescStatsReplyAdapter implements OFDescStatsReply {
33 + @Override
34 + public OFVersion getVersion() {
35 + return null;
36 + }
37 +
38 + @Override
39 + public OFType getType() {
40 + return null;
41 + }
42 +
43 + @Override
44 + public long getXid() {
45 + return 0;
46 + }
47 +
48 + @Override
49 + public OFStatsType getStatsType() {
50 + return null;
51 + }
52 +
53 + @Override
54 + public Set<OFStatsReplyFlags> getFlags() {
55 + return null;
56 + }
57 +
58 + @Override
59 + public String getMfrDesc() {
60 + return null;
61 + }
62 +
63 + @Override
64 + public String getHwDesc() {
65 + return null;
66 + }
67 +
68 + @Override
69 + public String getSwDesc() {
70 + return null;
71 + }
72 +
73 + @Override
74 + public String getSerialNum() {
75 + return null;
76 + }
77 +
78 + @Override
79 + public String getDpDesc() {
80 + return null;
81 + }
82 +
83 + @Override
84 + public void writeTo(ChannelBuffer channelBuffer) {
85 +
86 + }
87 +
88 + @Override
89 + public Builder createBuilder() {
90 + return null;
91 + }
92 +
93 + @Override
94 + public void putTo(PrimitiveSink sink) {
95 +
96 + }
97 +}
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 +package org.onosproject.openflow;
17 +
18 +import java.util.List;
19 +
20 +import org.jboss.netty.channel.Channel;
21 +import org.onosproject.net.Device;
22 +import org.onosproject.net.driver.DriverData;
23 +import org.onosproject.net.driver.DriverHandler;
24 +import org.onosproject.openflow.controller.Dpid;
25 +import org.onosproject.openflow.controller.RoleState;
26 +import org.onosproject.openflow.controller.driver.OpenFlowAgent;
27 +import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
28 +import org.onosproject.openflow.controller.driver.RoleHandler;
29 +import org.onosproject.openflow.controller.driver.SwitchStateException;
30 +import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
31 +import org.projectfloodlight.openflow.protocol.OFErrorMsg;
32 +import org.projectfloodlight.openflow.protocol.OFFactories;
33 +import org.projectfloodlight.openflow.protocol.OFFactory;
34 +import org.projectfloodlight.openflow.protocol.OFFeaturesReply;
35 +import org.projectfloodlight.openflow.protocol.OFMessage;
36 +import org.projectfloodlight.openflow.protocol.OFPortDesc;
37 +import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
38 +import org.projectfloodlight.openflow.protocol.OFVersion;
39 +
40 +/**
41 + * Testing adapter for the OpenFlow switch driver class.
42 + */
43 +public class OpenflowSwitchDriverAdapter implements OpenFlowSwitchDriver {
44 + @Override
45 + public void setAgent(OpenFlowAgent agent) {
46 +
47 + }
48 +
49 + @Override
50 + public void setRoleHandler(RoleHandler roleHandler) {
51 +
52 + }
53 +
54 + @Override
55 + public void reassertRole() {
56 +
57 + }
58 +
59 + @Override
60 + public boolean handleRoleError(OFErrorMsg error) {
61 + return false;
62 + }
63 +
64 + @Override
65 + public void handleNiciraRole(OFMessage m) throws SwitchStateException {
66 +
67 + }
68 +
69 + @Override
70 + public void handleRole(OFMessage m) throws SwitchStateException {
71 +
72 + }
73 +
74 + @Override
75 + public boolean connectSwitch() {
76 + return false;
77 + }
78 +
79 + @Override
80 + public boolean activateMasterSwitch() {
81 + return false;
82 + }
83 +
84 + @Override
85 + public boolean activateEqualSwitch() {
86 + return false;
87 + }
88 +
89 + @Override
90 + public void transitionToEqualSwitch() {
91 +
92 + }
93 +
94 + @Override
95 + public void transitionToMasterSwitch() {
96 +
97 + }
98 +
99 + @Override
100 + public void removeConnectedSwitch() {
101 +
102 + }
103 +
104 + @Override
105 + public void setPortDescReply(OFPortDescStatsReply portDescReply) {
106 +
107 + }
108 +
109 + @Override
110 + public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) {
111 +
112 + }
113 +
114 + @Override
115 + public void setFeaturesReply(OFFeaturesReply featuresReply) {
116 +
117 + }
118 +
119 + @Override
120 + public void setSwitchDescription(OFDescStatsReply desc) {
121 +
122 + }
123 +
124 + @Override
125 + public int getNextTransactionId() {
126 + return 0;
127 + }
128 +
129 + @Override
130 + public void setOFVersion(OFVersion ofV) {
131 +
132 + }
133 +
134 + @Override
135 + public void setTableFull(boolean full) {
136 +
137 + }
138 +
139 + @Override
140 + public void setChannel(Channel channel) {
141 +
142 + }
143 +
144 + @Override
145 + public void setConnected(boolean connected) {
146 +
147 + }
148 +
149 + @Override
150 + public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) {
151 +
152 + }
153 +
154 + @Override
155 + public Boolean supportNxRole() {
156 + return true;
157 + }
158 +
159 + @Override
160 + public void startDriverHandshake() {
161 +
162 + }
163 +
164 + @Override
165 + public boolean isDriverHandshakeComplete() {
166 + return false;
167 + }
168 +
169 + @Override
170 + public void processDriverHandshakeMessage(OFMessage m) {
171 +
172 + }
173 +
174 + @Override
175 + public void sendRoleRequest(OFMessage message) {
176 +
177 + }
178 +
179 + @Override
180 + public void sendHandshakeMessage(OFMessage message) {
181 +
182 + }
183 +
184 + @Override
185 + public DriverHandler handler() {
186 + return null;
187 + }
188 +
189 + @Override
190 + public void setHandler(DriverHandler handler) {
191 +
192 + }
193 +
194 + @Override
195 + public DriverData data() {
196 + return null;
197 + }
198 +
199 + @Override
200 + public void setData(DriverData data) {
201 +
202 + }
203 +
204 + @Override
205 + public void sendMsg(OFMessage msg) {
206 +
207 + }
208 +
209 + @Override
210 + public void sendMsg(List<OFMessage> msgs) {
211 +
212 + }
213 +
214 + @Override
215 + public void handleMessage(OFMessage fromSwitch) {
216 +
217 + }
218 +
219 + @Override
220 + public void setRole(RoleState role) {
221 +
222 + }
223 +
224 + @Override
225 + public RoleState getRole() {
226 + return null;
227 + }
228 +
229 + @Override
230 + public List<OFPortDesc> getPorts() {
231 + return null;
232 + }
233 +
234 + @Override
235 + public OFFactory factory() {
236 + // return what-ever triggers requestPending = true
237 + return OFFactories.getFactory(OFVersion.OF_10);
238 + }
239 +
240 + @Override
241 + public String getStringId() {
242 + return "100";
243 + }
244 +
245 + @Override
246 + public long getId() {
247 + return 0;
248 + }
249 +
250 + @Override
251 + public String manufacturerDescription() {
252 + return null;
253 + }
254 +
255 + @Override
256 + public String datapathDescription() {
257 + return null;
258 + }
259 +
260 + @Override
261 + public String hardwareDescription() {
262 + return null;
263 + }
264 +
265 + @Override
266 + public String softwareDescription() {
267 + return null;
268 + }
269 +
270 + @Override
271 + public String serialNumber() {
272 + return null;
273 + }
274 +
275 + @Override
276 + public boolean isConnected() {
277 + return false;
278 + }
279 +
280 + @Override
281 + public void disconnectSwitch() {
282 +
283 + }
284 +
285 + @Override
286 + public void returnRoleReply(RoleState requested, RoleState response) {
287 +
288 + }
289 +
290 + @Override
291 + public Device.Type deviceType() {
292 + return Device.Type.SWITCH;
293 + }
294 +
295 + @Override
296 + public String channelId() {
297 + return null;
298 + }
299 +}
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 +package org.onosproject.openflow.controller.impl;
17 +
18 +import java.io.File;
19 +import java.io.IOException;
20 +import java.util.Dictionary;
21 +import java.util.Hashtable;
22 +import java.util.Map;
23 +import java.util.stream.IntStream;
24 +
25 +import org.junit.Before;
26 +import org.junit.Test;
27 +import org.onlab.junit.TestTools;
28 +import org.onlab.util.ItemNotFoundException;
29 +import org.onosproject.net.DeviceId;
30 +import org.onosproject.net.driver.Driver;
31 +import org.onosproject.openflow.DriverAdapter;
32 +import org.onosproject.openflow.DriverServiceAdapter;
33 +import org.onosproject.openflow.OFDescStatsReplyAdapter;
34 +import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
35 +import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
36 +import org.slf4j.Logger;
37 +import org.slf4j.LoggerFactory;
38 +
39 +import com.google.common.io.Files;
40 +
41 +import static com.google.common.io.ByteStreams.toByteArray;
42 +import static com.google.common.io.Files.write;
43 +import static org.hamcrest.MatcherAssert.assertThat;
44 +import static org.hamcrest.Matchers.hasItem;
45 +import static org.hamcrest.Matchers.is;
46 +import static org.hamcrest.Matchers.lessThan;
47 +import static org.hamcrest.Matchers.not;
48 +import static org.hamcrest.Matchers.notNullValue;
49 +import static org.hamcrest.Matchers.nullValue;
50 +
51 +/**
52 + * Unit tests for the OpenFlow controller class.
53 + */
54 +public class ControllerTest {
55 +
56 + Controller controller;
57 + protected static final Logger log = LoggerFactory.getLogger(ControllerTest.class);
58 +
59 + static final File TEST_DIR = Files.createTempDir();
60 +
61 + /*
62 + * Writes the necessary file for the tests in the temporary directory
63 + */
64 + static File stageTestResource(String name) throws IOException {
65 + File file = new File(TEST_DIR, name);
66 + byte[] bytes = toByteArray(ControllerTest.class.getResourceAsStream(name));
67 + write(bytes, file);
68 + return file;
69 + }
70 +
71 + class MockDriverService extends DriverServiceAdapter {
72 + static final int NO_SUCH_DRIVER_ID = 1;
73 + static final int ITEM_NOT_FOUND_DRIVER_ID = 2;
74 + static final int DRIVER_EXISTS_ID = 3;
75 +
76 + static final String BASE_DRIVER_NAME = "of:000000000000000";
77 +
78 + static final String NO_SUCH_DRIVER = BASE_DRIVER_NAME
79 + + NO_SUCH_DRIVER_ID;
80 + static final String ITEM_NOT_FOUND_DRIVER = BASE_DRIVER_NAME
81 + + ITEM_NOT_FOUND_DRIVER_ID;
82 + static final String DRIVER_EXISTS = BASE_DRIVER_NAME
83 + + DRIVER_EXISTS_ID;
84 +
85 + @Override
86 + public Driver getDriver(DeviceId deviceId) {
87 + switch (deviceId.toString()) {
88 + case NO_SUCH_DRIVER:
89 + return null;
90 + case ITEM_NOT_FOUND_DRIVER:
91 + throw new ItemNotFoundException();
92 + case DRIVER_EXISTS:
93 + return new DriverAdapter();
94 + default:
95 + throw new AssertionError();
96 + }
97 + }
98 + }
99 +
100 + /**
101 + * Creates and initializes a new controller.
102 + */
103 + @Before
104 + public void setUp() {
105 + controller = new Controller();
106 + Dictionary<String, String> properties = new Hashtable<>();
107 + properties.put("openflowPorts",
108 + Integer.toString(TestTools.findAvailablePort(0)));
109 + controller.setConfigParams(properties);
110 + }
111 +
112 + /**
113 + * Tests fetching a driver that does not exist.
114 + */
115 + @Test
116 + public void switchInstanceNotFoundTest() {
117 + controller.start(null, new MockDriverService());
118 + OpenFlowSwitchDriver driver =
119 + controller.getOFSwitchInstance(MockDriverService.NO_SUCH_DRIVER_ID,
120 + null,
121 + null);
122 + assertThat(driver, nullValue());
123 + controller.stop();
124 + }
125 +
126 + /**
127 + * Tests fetching a driver that throws an ItemNotFoundException.
128 + */
129 + @Test
130 + public void switchItemNotFoundTest() {
131 + controller.start(null, new MockDriverService());
132 + OFDescStatsReply stats =
133 + new OFDescStatsReplyAdapter();
134 + OpenFlowSwitchDriver driver =
135 + controller.getOFSwitchInstance(MockDriverService.ITEM_NOT_FOUND_DRIVER_ID,
136 + stats,
137 + null);
138 + assertThat(driver, nullValue());
139 + controller.stop();
140 + }
141 +
142 + /**
143 + * Tests fetching a driver that throws an ItemNotFoundException.
144 + */
145 + @Test
146 + public void driverExistsTest() {
147 + controller.start(null, new MockDriverService());
148 + OFDescStatsReply stats =
149 + new OFDescStatsReplyAdapter();
150 + OpenFlowSwitchDriver driver =
151 + controller.getOFSwitchInstance(MockDriverService.DRIVER_EXISTS_ID,
152 + stats,
153 + null);
154 + assertThat(driver, notNullValue());
155 + controller.stop();
156 + }
157 +
158 + /**
159 + * Tests configuring the controller.
160 + */
161 + @Test
162 + public void testConfiguration() {
163 + Dictionary<String, String> properties = new Hashtable<>();
164 + properties.put("openflowPorts", "1,2,3,4,5");
165 + properties.put("workerThreads", "5");
166 +
167 + controller.setConfigParams(properties);
168 + IntStream.rangeClosed(1, 5)
169 + .forEach(i -> assertThat(controller.openFlowPorts, hasItem(i)));
170 + assertThat(controller.workerThreads, is(5));
171 + }
172 +
173 + /**
174 + * Tests the SSL/TLS methods in the controller.
175 + */
176 + @Test
177 + public void testSsl() throws IOException {
178 + File keystore = stageTestResource("ControllerTestKeystore.jks");
179 + String keystoreName = keystore.getAbsolutePath();
180 +
181 + System.setProperty("enableOFTLS", Boolean.toString(Boolean.TRUE));
182 + System.setProperty("javax.net.ssl.keyStore", keystoreName);
183 + System.setProperty("javax.net.ssl.trustStore", keystoreName);
184 + System.setProperty("javax.net.ssl.keyStorePassword", "password");
185 + System.setProperty("javax.net.ssl.trustStorePassword", "password");
186 + Dictionary<String, String> properties = new Hashtable<>();
187 + properties.put("openflowPorts",
188 + Integer.toString(TestTools.findAvailablePort(0)));
189 + properties.put("workerThreads", "0");
190 +
191 + controller.setConfigParams(properties);
192 + controller.start(null, new MockDriverService());
193 +
194 + assertThat(controller.serverSSLEngine, notNullValue());
195 +
196 + controller.stop();
197 + boolean removed = keystore.delete();
198 + if (!removed) {
199 + log.warn("Could not remove temporary file");
200 + }
201 + }
202 +
203 + /**
204 + * Tests controll utility health methods.
205 + */
206 + @Test
207 + public void testHealth() {
208 + Map<String, Long> memory = controller.getMemory();
209 + assertThat(memory.size(), is(2));
210 + assertThat(memory.get("total"), is(not(0)));
211 + assertThat(memory.get("free"), is(not(0)));
212 +
213 + long startTime = controller.getSystemStartTime();
214 + assertThat(startTime, lessThan(System.currentTimeMillis()));
215 +
216 + long upTime = controller.getSystemUptime();
217 + assertThat(upTime, lessThan(30L * 1000));
218 + }
219 +}
...@@ -15,35 +15,21 @@ ...@@ -15,35 +15,21 @@
15 */ 15 */
16 package org.onosproject.openflow.controller.impl; 16 package org.onosproject.openflow.controller.impl;
17 17
18 -import org.jboss.netty.channel.Channel; 18 +import java.io.IOException;
19 +
19 import org.junit.After; 20 import org.junit.After;
20 import org.junit.Before; 21 import org.junit.Before;
21 import org.junit.Test; 22 import org.junit.Test;
22 -import org.onosproject.net.Device; 23 +import org.onosproject.openflow.OpenflowSwitchDriverAdapter;
23 -import org.onosproject.net.driver.DriverData;
24 -import org.onosproject.net.driver.DriverHandler;
25 -import org.onosproject.openflow.controller.Dpid;
26 import org.onosproject.openflow.controller.RoleState; 24 import org.onosproject.openflow.controller.RoleState;
27 -import org.onosproject.openflow.controller.driver.OpenFlowAgent;
28 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; 25 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
29 -import org.onosproject.openflow.controller.driver.RoleHandler;
30 import org.onosproject.openflow.controller.driver.RoleRecvStatus; 26 import org.onosproject.openflow.controller.driver.RoleRecvStatus;
31 import org.onosproject.openflow.controller.driver.RoleReplyInfo; 27 import org.onosproject.openflow.controller.driver.RoleReplyInfo;
32 import org.onosproject.openflow.controller.driver.SwitchStateException; 28 import org.onosproject.openflow.controller.driver.SwitchStateException;
33 import org.projectfloodlight.openflow.protocol.OFDescStatsReply; 29 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
34 -import org.projectfloodlight.openflow.protocol.OFErrorMsg;
35 -import org.projectfloodlight.openflow.protocol.OFFactories;
36 -import org.projectfloodlight.openflow.protocol.OFFactory;
37 import org.projectfloodlight.openflow.protocol.OFFeaturesReply; 30 import org.projectfloodlight.openflow.protocol.OFFeaturesReply;
38 -import org.projectfloodlight.openflow.protocol.OFMessage;
39 -import org.projectfloodlight.openflow.protocol.OFPortDesc;
40 -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
41 -import org.projectfloodlight.openflow.protocol.OFVersion;
42 import org.projectfloodlight.openflow.types.U64; 31 import org.projectfloodlight.openflow.types.U64;
43 32
44 -import java.io.IOException;
45 -import java.util.List;
46 -
47 import static org.junit.Assert.assertEquals; 33 import static org.junit.Assert.assertEquals;
48 import static org.onosproject.openflow.controller.RoleState.MASTER; 34 import static org.onosproject.openflow.controller.RoleState.MASTER;
49 import static org.onosproject.openflow.controller.RoleState.SLAVE; 35 import static org.onosproject.openflow.controller.RoleState.SLAVE;
...@@ -103,25 +89,12 @@ public class RoleManagerTest { ...@@ -103,25 +89,12 @@ public class RoleManagerTest {
103 } 89 }
104 } 90 }
105 91
106 - private class TestSwitchDriver implements OpenFlowSwitchDriver { 92 + private class TestSwitchDriver extends OpenflowSwitchDriverAdapter {
107 93
108 RoleState failed = null; 94 RoleState failed = null;
109 RoleState current = null; 95 RoleState current = null;
110 96
111 @Override 97 @Override
112 - public void sendMsg(OFMessage msg) {
113 - }
114 -
115 - @Override
116 - public void sendMsg(List<OFMessage> msgs) {
117 - }
118 -
119 -
120 - @Override
121 - public void handleMessage(OFMessage fromSwitch) {
122 - }
123 -
124 - @Override
125 public void setRole(RoleState role) { 98 public void setRole(RoleState role) {
126 current = role; 99 current = role;
127 } 100 }
...@@ -132,143 +105,6 @@ public class RoleManagerTest { ...@@ -132,143 +105,6 @@ public class RoleManagerTest {
132 } 105 }
133 106
134 @Override 107 @Override
135 - public List<OFPortDesc> getPorts() {
136 - return null;
137 - }
138 -
139 - @Override
140 - public OFFactory factory() {
141 - // return what-ever triggers requestPending = true
142 - return OFFactories.getFactory(OFVersion.OF_10);
143 - }
144 -
145 - @Override
146 - public String getStringId() {
147 - return "100";
148 - }
149 -
150 - @Override
151 - public long getId() {
152 - return 0;
153 - }
154 -
155 - @Override
156 - public String manufacturerDescription() {
157 - return null;
158 - }
159 -
160 - @Override
161 - public String datapathDescription() {
162 - return null;
163 - }
164 -
165 - @Override
166 - public String hardwareDescription() {
167 - return null;
168 - }
169 -
170 - @Override
171 - public String softwareDescription() {
172 - return null;
173 - }
174 -
175 - @Override
176 - public String serialNumber() {
177 - return null;
178 - }
179 -
180 - @Override
181 - public void disconnectSwitch() {
182 - }
183 -
184 - @Override
185 - public Device.Type deviceType() {
186 - return Device.Type.SWITCH;
187 - }
188 -
189 - @Override
190 - public void setAgent(OpenFlowAgent agent) {
191 - }
192 -
193 - @Override
194 - public void setRoleHandler(RoleHandler roleHandler) {
195 - }
196 -
197 - @Override
198 - public void reassertRole() {
199 - }
200 -
201 - @Override
202 - public boolean handleRoleError(OFErrorMsg error) {
203 - return false;
204 - }
205 -
206 - @Override
207 - public void handleNiciraRole(OFMessage m) throws SwitchStateException {
208 - }
209 -
210 - @Override
211 - public void handleRole(OFMessage m) throws SwitchStateException {
212 - }
213 -
214 - @Override
215 - public void startDriverHandshake() {
216 - }
217 -
218 - @Override
219 - public boolean isDriverHandshakeComplete() {
220 - return false;
221 - }
222 -
223 - @Override
224 - public void processDriverHandshakeMessage(OFMessage m) {
225 - }
226 -
227 - @Override
228 - public void sendRoleRequest(OFMessage message) {
229 -
230 - }
231 -
232 - @Override
233 - public void sendHandshakeMessage(OFMessage message) {
234 - }
235 -
236 - @Override
237 - public boolean connectSwitch() {
238 - return false;
239 - }
240 -
241 - @Override
242 - public boolean activateMasterSwitch() {
243 - return false;
244 - }
245 -
246 - @Override
247 - public boolean activateEqualSwitch() {
248 - return false;
249 - }
250 -
251 - @Override
252 - public void transitionToEqualSwitch() {
253 - }
254 -
255 - @Override
256 - public void transitionToMasterSwitch() {
257 - }
258 -
259 - @Override
260 - public void removeConnectedSwitch() {
261 - }
262 -
263 - @Override
264 - public void setPortDescReply(OFPortDescStatsReply portDescReply) {
265 - }
266 -
267 - @Override
268 - public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) {
269 - }
270 -
271 - @Override
272 public void setFeaturesReply(OFFeaturesReply featuresReply) { 108 public void setFeaturesReply(OFFeaturesReply featuresReply) {
273 } 109 }
274 110
...@@ -282,37 +118,6 @@ public class RoleManagerTest { ...@@ -282,37 +118,6 @@ public class RoleManagerTest {
282 } 118 }
283 119
284 @Override 120 @Override
285 - public Boolean supportNxRole() {
286 - return true;
287 - }
288 -
289 - @Override
290 - public void setOFVersion(OFVersion ofV) {
291 - }
292 -
293 - @Override
294 - public void setTableFull(boolean full) {
295 - }
296 -
297 - @Override
298 - public void setChannel(Channel channel) {
299 - }
300 -
301 - @Override
302 - public void setConnected(boolean connected) {
303 - }
304 -
305 - @Override
306 - public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) {
307 -
308 - }
309 -
310 - @Override
311 - public boolean isConnected() {
312 - return false;
313 - }
314 -
315 - @Override
316 public void returnRoleReply(RoleState requested, RoleState response) { 121 public void returnRoleReply(RoleState requested, RoleState response) {
317 failed = requested; 122 failed = requested;
318 } 123 }
...@@ -321,25 +126,5 @@ public class RoleManagerTest { ...@@ -321,25 +126,5 @@ public class RoleManagerTest {
321 public String channelId() { 126 public String channelId() {
322 return "1.2.3.4:1"; 127 return "1.2.3.4:1";
323 } 128 }
324 -
325 - @Override
326 - public DriverHandler handler() {
327 - return null;
328 - }
329 -
330 - @Override
331 - public void setHandler(DriverHandler handler) {
332 -
333 - }
334 -
335 - @Override
336 - public DriverData data() {
337 - return null;
338 - }
339 -
340 - @Override
341 - public void setData(DriverData data) {
342 -
343 - }
344 } 129 }
345 } 130 }
......
...@@ -20,6 +20,7 @@ import com.google.common.io.Files; ...@@ -20,6 +20,7 @@ import com.google.common.io.Files;
20 20
21 import java.io.File; 21 import java.io.File;
22 import java.io.IOException; 22 import java.io.IOException;
23 +import java.net.ServerSocket;
23 import java.util.List; 24 import java.util.List;
24 import java.util.Random; 25 import java.util.Random;
25 26
...@@ -207,4 +208,20 @@ public final class TestTools { ...@@ -207,4 +208,20 @@ public final class TestTools {
207 } 208 }
208 } 209 }
209 210
211 + /*
212 + * Finds an available port that a test can bind to.
213 + */
214 + public static int findAvailablePort(int defaultPort) {
215 + try {
216 + ServerSocket socket = new ServerSocket(0);
217 + socket.setReuseAddress(true);
218 + int port = socket.getLocalPort();
219 + socket.close();
220 + return port;
221 + } catch (IOException ex) {
222 + return defaultPort;
223 + }
224 + }
225 +
226 +
210 } 227 }
......