mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-11-02 17:21:05 +01:00
added unit tests
Change-Id: Ic743a05b907456e1414a9bc587696de631d3f382 commented the controller test class Change-Id: Id9afb0e60afb3839f65a41b04e7129db1010ca19 added OFChannelHandler tests Change-Id: I45169988f0e4242a6e1c0baf34b1104f53873bb7
This commit is contained in:
parent
09419517ef
commit
3b554cff3b
@ -44,7 +44,7 @@
|
||||
|
||||
<module name="Checker">
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${samedir}/suppressions.xml"/>
|
||||
<property name="file" value="${config_loc}/suppressions.xml"/>
|
||||
</module>
|
||||
<!--
|
||||
If you set the basedir property below, then all reported file
|
||||
|
||||
@ -174,7 +174,6 @@
|
||||
https://issues.jboss.org/browse/JASSIST-228 -->
|
||||
<argLine>-XX:MaxPermSize=256m -XX:-UseSplitVerifier</argLine>
|
||||
<redirectTestOutputToFile>false</redirectTestOutputToFile>
|
||||
<excludedGroups>net.onrc.onos.core.util.IntegrationTest</excludedGroups>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- TODO exec:java no longer used remove at some point? -->
|
||||
|
||||
@ -69,8 +69,6 @@ public interface IOFSwitch {
|
||||
|
||||
/**
|
||||
* Writes to the OFMessage to the output stream.
|
||||
* The message will be handed to the floodlightProvider for possible filtering
|
||||
* and processing by message listeners
|
||||
*
|
||||
* @param m
|
||||
* @param bc
|
||||
@ -80,8 +78,6 @@ public interface IOFSwitch {
|
||||
|
||||
/**
|
||||
* Writes the list of messages to the output stream.
|
||||
* The message will be handed to the floodlightProvider for possible filtering
|
||||
* and processing by message listeners.
|
||||
*
|
||||
* @param msglist
|
||||
* @param bc
|
||||
@ -333,8 +329,7 @@ public interface IOFSwitch {
|
||||
|
||||
/**
|
||||
* Add or modify a switch port. This is called by the core controller
|
||||
* code in response to a OFPortStatus message. It should not typically be
|
||||
* called by other floodlight applications.
|
||||
* code in response to a OFPortStatus message.
|
||||
*
|
||||
* OFPPR_MODIFY and OFPPR_ADD will be treated as equivalent. The OpenFlow
|
||||
* spec is not clear on whether portNames are portNumbers are considered
|
||||
@ -402,29 +397,6 @@ public interface IOFSwitch {
|
||||
public OrderedCollection<PortChangeEvent>
|
||||
setPorts(Collection<OFPortDesc> ports);
|
||||
|
||||
// XXX S The odd use of providing an API call to 'set ports' (above) would
|
||||
// logically suggest that there should be a way to delete or unset the ports.
|
||||
// Right now we forbid this. We should probably not use setPorts too.
|
||||
//
|
||||
// /**
|
||||
// * Delete a port for the switch. This is called by the core controller
|
||||
// * code in response to a OFPortStatus message. It should not typically be
|
||||
// * called by other floodlight applications.
|
||||
// *
|
||||
// * @param portNumber
|
||||
// */
|
||||
// public void deletePort(short portNumber);
|
||||
//
|
||||
// /**
|
||||
// * Delete a port for the switch. This is called by the core controller
|
||||
// * code in response to a OFPortStatus message. It should not typically be
|
||||
// * called by other floodlight applications.
|
||||
// *
|
||||
// * @param portName
|
||||
// */
|
||||
// public void deletePort(String portName);
|
||||
|
||||
|
||||
//*******************************************
|
||||
// IOFSwitch object attributes
|
||||
//************************
|
||||
|
||||
@ -127,7 +127,7 @@ public interface IDebugCounterService {
|
||||
/**
|
||||
* Flush all thread-local counter values (from the current thread)
|
||||
* to the global counter store. This method is not intended for use by any
|
||||
* module. It's typical usage is from floodlight core and it is meant
|
||||
* module. It's typical usage is from core and it is meant
|
||||
* to flush those counters that are updated in the packet-processing pipeline,
|
||||
* typically with the 'updateCounterNoFlush" methods in IDebugCounter.
|
||||
*/
|
||||
|
||||
@ -144,8 +144,8 @@ public class Controller {
|
||||
+ "activated: dpid {}. Found in activeMaster: {} "
|
||||
+ "Found in activeEqual: {}. Aborting ..", new Object[] {
|
||||
HexString.toHexString(dpid),
|
||||
(activeMasterSwitches.get(dpid) == null) ? 'Y' : 'N',
|
||||
(activeEqualSwitches.get(dpid) == null) ? 'Y' : 'N'});
|
||||
(activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y',
|
||||
(activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'});
|
||||
counters.switchWithSameDpidActivated.updateCounterWithFlush();
|
||||
return false;
|
||||
}
|
||||
@ -372,17 +372,13 @@ public class Controller {
|
||||
HexString.toHexString(dpidLong));
|
||||
return;
|
||||
}
|
||||
if (h.controlRequested) {
|
||||
if (registryService != null && h.controlRequested) {
|
||||
//TODO the above is not good for testing need to change controlrequest to method call.
|
||||
registryService.releaseControl(dpidLong);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ***************
|
||||
// IFloodlightProviderService
|
||||
// ***************
|
||||
|
||||
// FIXME: remove this method
|
||||
public Map<Long, IOFSwitch> getSwitches() {
|
||||
return getMasterSwitches();
|
||||
@ -472,11 +468,6 @@ public class Controller {
|
||||
}
|
||||
|
||||
|
||||
public void setAlwaysClearFlowsOnSwAdd(boolean value) {
|
||||
this.alwaysClearFlowsOnSwAdd = value;
|
||||
}
|
||||
|
||||
|
||||
public InstanceId getInstanceId() {
|
||||
return instanceId;
|
||||
}
|
||||
@ -587,15 +578,6 @@ public class Controller {
|
||||
this.counters = new Counters();
|
||||
this.multiCacheLock = new Object();
|
||||
|
||||
|
||||
String option = configParams.get("flushSwitchesOnReconnect");
|
||||
if (option != null && option.equalsIgnoreCase("true")) {
|
||||
this.setAlwaysClearFlowsOnSwActivate(true);
|
||||
log.info("Flush switches on reconnect -- Enabled.");
|
||||
} else {
|
||||
this.setAlwaysClearFlowsOnSwActivate(false);
|
||||
log.info("Flush switches on reconnect -- Disabled");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -819,12 +801,6 @@ public class Controller {
|
||||
// Utility methods
|
||||
// **************
|
||||
|
||||
|
||||
public void setAlwaysClearFlowsOnSwActivate(boolean value) {
|
||||
//this.alwaysClearFlowsOnSwActivate = value;
|
||||
// XXX S need to be a little more careful about this
|
||||
}
|
||||
|
||||
public Map<String, Long> getMemory() {
|
||||
Map<String, Long> m = new HashMap<String, Long>();
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
@ -785,7 +785,7 @@ class OFChannelHandler extends IdleStateAwareChannelHandler {
|
||||
* description stats message, we:
|
||||
* - use the switch driver to bind the switch and get an IOFSwitch instance
|
||||
* - setup the IOFSwitch instance
|
||||
* - add switch to FloodlightProvider(Controller) and send the initial role
|
||||
* - add switch controller and send the initial role
|
||||
* request to the switch.
|
||||
* Next state: WAIT_INITIAL_ROLE
|
||||
* In the typical case, where switches support role request messages
|
||||
|
||||
@ -0,0 +1,167 @@
|
||||
/**
|
||||
* Copyright 2011, Big Switch Networks, Inc.
|
||||
* Originally created by David Erickson, Stanford University
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
**/
|
||||
|
||||
package net.onrc.onos.of.ctl.internal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.onrc.onos.of.ctl.IOFSwitch;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class ControllerTest extends TestCase {
|
||||
|
||||
private Controller controller;
|
||||
private IOFSwitch sw;
|
||||
private OFChannelHandler h;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
sw = EasyMock.createMock(IOFSwitch.class);
|
||||
h = EasyMock.createMock(OFChannelHandler.class);
|
||||
controller = new Controller();
|
||||
ControllerRunThread t = new ControllerRunThread();
|
||||
t.start();
|
||||
/*
|
||||
* Making sure the thread is properly started before making calls
|
||||
* to controller class.
|
||||
*/
|
||||
Thread.sleep(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the base mocks used in these tests.
|
||||
*/
|
||||
private void startMocks() {
|
||||
EasyMock.replay(sw, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the mocks to a known state.
|
||||
* Automatically called after tests.
|
||||
*/
|
||||
@After
|
||||
private void resetMocks() {
|
||||
EasyMock.reset(sw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the controller instance.
|
||||
* @return the controller
|
||||
*/
|
||||
public Controller getController() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the controller's main loop so that updates are processed.
|
||||
*/
|
||||
protected class ControllerRunThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
controller.openFlowPort = 0; // Don't listen
|
||||
controller.activate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that we are able to add a switch that just connected.
|
||||
* If it already exists then this should fail
|
||||
*
|
||||
* @throws Exception error
|
||||
*/
|
||||
@Test
|
||||
public void testAddConnectedSwitches() throws Exception {
|
||||
startMocks();
|
||||
assertTrue(controller.addConnectedSwitch(0, h));
|
||||
assertFalse(controller.addConnectedSwitch(0, h));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add active master but cannot re-add active master.
|
||||
* @throws Exception an error occurred.
|
||||
*/
|
||||
@Test
|
||||
public void testAddActivatedMasterSwitch() throws Exception {
|
||||
startMocks();
|
||||
controller.addConnectedSwitch(0, h);
|
||||
assertTrue(controller.addActivatedMasterSwitch(0, sw));
|
||||
assertFalse(controller.addActivatedMasterSwitch(0, sw));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an activated switch can be added but cannot be re-added.
|
||||
*
|
||||
* @throws Exception an error occurred
|
||||
*/
|
||||
@Test
|
||||
public void testAddActivatedEqualSwitch() throws Exception {
|
||||
startMocks();
|
||||
controller.addConnectedSwitch(0, h);
|
||||
assertTrue(controller.addActivatedEqualSwitch(0, sw));
|
||||
assertFalse(controller.addActivatedEqualSwitch(0, sw));
|
||||
}
|
||||
|
||||
/**
|
||||
* Move an equal switch to master.
|
||||
* @throws Exception an error occurred
|
||||
*/
|
||||
@Test
|
||||
public void testTranstitionToMaster() throws Exception {
|
||||
startMocks();
|
||||
controller.addConnectedSwitch(0, h);
|
||||
controller.addActivatedEqualSwitch(0, sw);
|
||||
controller.transitionToMasterSwitch(0);
|
||||
assertNotNull(controller.getMasterSwitch(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Transition a master switch to equal state.
|
||||
* @throws Exception an error occurred
|
||||
*/
|
||||
@Test
|
||||
public void testTranstitionToEqual() throws Exception {
|
||||
startMocks();
|
||||
controller.addConnectedSwitch(0, h);
|
||||
controller.addActivatedMasterSwitch(0, sw);
|
||||
controller.transitionToEqualSwitch(0);
|
||||
assertNotNull(controller.getEqualSwitch(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the switch from the controller instance.
|
||||
* @throws Exception an error occurred
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveSwitch() throws Exception {
|
||||
sw.cancelAllStatisticsReplies();
|
||||
EasyMock.expectLastCall().once();
|
||||
sw.setConnected(false);
|
||||
EasyMock.expectLastCall().once();
|
||||
startMocks();
|
||||
controller.addConnectedSwitch(0, h);
|
||||
controller.addActivatedMasterSwitch(0, sw);
|
||||
controller.removeConnectedSwitch(0);
|
||||
assertNull(controller.getSwitch(0));
|
||||
EasyMock.verify(sw, h);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user