本文整理汇总了Java中net.floodlightcontroller.core.IOFSwitchListener.switchAdded方法的典型用法代码示例。如果您正苦于以下问题:Java IOFSwitchListener.switchAdded方法的具体用法?Java IOFSwitchListener.switchAdded怎么用?Java IOFSwitchListener.switchAdded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.core.IOFSwitchListener
的用法示例。
在下文中一共展示了IOFSwitchListener.switchAdded方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatch
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
@Override
public void dispatch() {
if (log.isTraceEnabled()) {
log.trace("Dispatching switch update {} {}", swId, switchUpdateType);
}
if (switchListeners != null) {
for (IOFSwitchListener listener : switchListeners) {
switch(switchUpdateType) {
case ADDED:
// don't count here. We have more specific
// counters before the update is created
listener.switchAdded(swId);
break;
case REMOVED:
// don't count here. We have more specific
// counters before the update is created
listener.switchRemoved(swId);
break;
case PORTCHANGED:
counters.switchPortChanged
.increment();
listener.switchPortChanged(swId, port, changeType);
break;
case ACTIVATED:
// don't count here. We have more specific
// counters before the update is created
listener.switchActivated(swId);
break;
case DEACTIVATED:
// ignore
break;
case OTHERCHANGE:
counters.switchOtherChange
.increment();
listener.switchChanged(swId);
break;
}
}
}
}
示例2: testNewSwitchActivated
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
@Test
/**
* Test switchActivated for a new switch, i.e., a switch that was not
* previously known to the controller cluser. We expect that all
* flow mods are cleared and we expect a switchAdded
*/
public void testNewSwitchActivated() throws Exception {
IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
setupSwitchForAddSwitch(sw, DATAPATH_ID_0, null, null);
// Ensure switch doesn't already exist
assertNull(switchManager.getSwitch(DATAPATH_ID_0));
// strict mock. Order of events matters!
IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class);
listener.switchAdded(DATAPATH_ID_0);
expectLastCall().once();
listener.switchActivated(DATAPATH_ID_0);
expectLastCall().once();
replay(listener);
switchManager.addOFSwitchListener(listener);
replay(sw);
switchManager.switchAdded(sw);
switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
verify(sw);
assertEquals(sw, switchManager.getSwitch(DATAPATH_ID_0));
controller.processUpdateQueueForTesting();
verify(listener);
}
示例3: dispatch
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
@Override
public void dispatch() {
if (log.isTraceEnabled()) {
log.trace("Dispatching switch update {} {}",
HexString.toHexString(swId), switchUpdateType);
}
if (switchListeners != null) {
for (IOFSwitchListener listener : switchListeners) {
switch(switchUpdateType) {
case ADDED:
// don't count here. We have more specific
// counters before the update is created
listener.switchAdded(swId);
break;
case REMOVED:
// don't count here. We have more specific
// counters before the update is created
listener.switchRemoved(swId);
break;
case PORTCHANGED:
counters.switchPortChanged.updateCounterWithFlush();
listener.switchPortChanged(swId, port, changeType);
break;
case ACTIVATED:
// don't count here. We have more specific
// counters before the update is created
listener.switchActivated(swId);
break;
case DEACTIVATED:
// ignore
break;
case OTHERCHANGE:
counters.switchOtherChange.updateCounterWithFlush();
listener.switchChanged(swId);
break;
}
}
}
}
示例4: testNewSwitchActivated
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
@Test
/**
* Test switchActivated for a new switch, i.e., a switch that was not
* previously known to the controller cluser. We expect that all
* flow mods are cleared and we expect a switchAdded
*/
public void testNewSwitchActivated() throws Exception {
// We set AlwaysClearFlowsOnSwActivate to false but we still
// expect a clearAllFlowMods() because the AlwaysClearFlowsOnSwActivate
// is only relevant if a switch that was previously known is activated!!
controller.setAlwaysClearFlowsOnSwActivate(false);
IOFSwitch sw = createMock(IOFSwitch.class);
setupSwitchForAddSwitch(sw, 0L, null, null);
sw.clearAllFlowMods();
expectLastCall().once();
// strict mock. Order of events matters!
IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class);
listener.switchAdded(0L);
expectLastCall().once();
listener.switchActivated(0L);
expectLastCall().once();
replay(listener);
controller.addOFSwitchListener(listener);
replay(sw);
controller.switchActivated(sw);
verify(sw);
assertEquals(sw, controller.getSwitch(0L));
controller.processUpdateQueueForTesting();
verify(listener);
SwitchSyncRepresentation storedSwitch = storeClient.getValue(0L);
assertEquals(createOFFeaturesReply(), storedSwitch.getFeaturesReply());
assertEquals(createOFDescriptionStatistics(),
storedSwitch.getDescription());
}
示例5: testAddSwitchRemoveSwitchStoreSlave
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
/**
* add switch to store then remove it again while slave.
* should get notification and switch should be added and then removed
*/
@Test
public void testAddSwitchRemoveSwitchStoreSlave() throws Exception {
doSetUp(Role.SLAVE);
IOFSwitchListener listener = createMock(IOFSwitchListener.class);
controller.addOFSwitchListener(listener);
//------
// Add switch
listener.switchAdded(1L);
expectLastCall().once();
replay(listener);
OFDescriptionStatistics desc = createOFDescriptionStatistics();
desc.setDatapathDescription("The Switch");
doAddSwitchToStore(1L, desc, null);
controller.processUpdateQueueForTesting();
verify(listener);
IOFSwitch sw = controller.getSwitch(1L);
assertNotNull("Switch should be present", sw);
assertEquals(1L, sw.getId());
assertFalse("Switch should be inactive", sw.isActive());
assertEquals("The Switch",
sw.getDescriptionStatistics().getDatapathDescription());
//------
// remove switch
reset(listener);
listener.switchRemoved(1L);
replay(listener);
doRemoveSwitchFromStore(1L);
controller.processUpdateQueueForTesting();
verify(listener);
assertNull("Switch should not exist anymore", controller.getSwitch(1L));
}
示例6: testSwitchActivatedWithAlreadyActiveSwitch
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
/**
* Try to activate a switch that's already active (which can happen if
* two different switches have the same DPIP or if a switch reconnects
* while the old TCP connection is still alive
*/
@Test
public void testSwitchActivatedWithAlreadyActiveSwitch() throws Exception {
SwitchDescription oldDescription = new SwitchDescription(
"", "", "", "", "Ye Olde Switch");
SwitchDescription newDescription = new SwitchDescription(
"", "", "", "", "The new Switch");
OFFeaturesReply featuresReply = createOFFeaturesReply(DATAPATH_ID_0);
// Setup: add a switch to the controller
IOFSwitchBackend oldsw = createMock(IOFSwitchBackend.class);
setupSwitchForAddSwitch(oldsw, DATAPATH_ID_0, oldDescription, featuresReply);
replay(oldsw);
switchManager.switchAdded(oldsw);
switchManager.switchStatusChanged(oldsw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
verify(oldsw);
// drain the queue, we don't care what's in it
controller.processUpdateQueueForTesting();
assertEquals(oldsw, switchManager.getSwitch(DATAPATH_ID_0));
// Now the actual test: add a new switch with the same dpid to
// the controller
reset(oldsw);
expect(oldsw.getId()).andReturn(DATAPATH_ID_0).anyTimes();
oldsw.cancelAllPendingRequests();
expectLastCall().once();
oldsw.disconnect();
expectLastCall().once();
IOFSwitchBackend newsw = createMock(IOFSwitchBackend.class);
setupSwitchForAddSwitch(newsw, DATAPATH_ID_0, newDescription, featuresReply);
// Strict mock. We need to get the removed notification before the
// add notification
IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class);
listener.switchRemoved(DATAPATH_ID_0);
listener.switchAdded(DATAPATH_ID_0);
listener.switchActivated(DATAPATH_ID_0);
replay(listener);
switchManager.addOFSwitchListener(listener);
replay(newsw, oldsw);
switchManager.switchAdded(newsw);
switchManager.switchStatusChanged(newsw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
verify(newsw, oldsw);
assertEquals(newsw, switchManager.getSwitch(DATAPATH_ID_0));
controller.processUpdateQueueForTesting();
verify(listener);
}
示例7: testAddSwitchToStoreMaster
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
/** (remotely) add switch to store and then remove while master. no-op */
@Test
public void testAddSwitchToStoreMaster() throws Exception {
IOFSwitchListener listener = createMock(IOFSwitchListener.class);
controller.addOFSwitchListener(listener);
replay(listener);
//--------------
// add switch
doAddSwitchToStore(1L, null, null);
controller.processUpdateQueueForTesting();
IOFSwitch sw = controller.getSwitch(1L);
assertNull("There shouldn't be a switch", sw);
verify(listener);
//--------------
// add a real switch
controller.setAlwaysClearFlowsOnSwActivate(true);
sw = createMock(IOFSwitch.class);
setupSwitchForAddSwitch(sw, 1L, null, null);
sw.clearAllFlowMods();
expectLastCall().once();
reset(listener);
listener.switchAdded(1L);
expectLastCall().once();
listener.switchActivated(1L);
expectLastCall().once();
replay(listener);
replay(sw);
controller.switchActivated(sw);
verify(sw);
assertEquals(sw, controller.getSwitch(1L));
controller.processUpdateQueueForTesting();
verify(listener);
//-----------
// remove switch from store.
reset(listener);
replay(listener);
doRemoveSwitchFromStore(1L);
controller.processUpdateQueueForTesting();
verify(listener);
assertEquals(sw, controller.getSwitch(1L));
}
示例8: testSwitchActivatedWithAlreadyActiveSwitch
import net.floodlightcontroller.core.IOFSwitchListener; //导入方法依赖的package包/类
/**
* Try to activate a switch that's already active (which can happen if
* two different switches have the same DPIP or if a switch reconnects
* while the old TCP connection is still alive
*/
@Test
public void testSwitchActivatedWithAlreadyActiveSwitch() throws Exception {
OFDescriptionStatistics oldDesc = createOFDescriptionStatistics();
oldDesc.setDatapathDescription("Ye Olde Switch");
OFDescriptionStatistics newDesc = createOFDescriptionStatistics();
newDesc.setDatapathDescription("The new Switch");
OFFeaturesReply featuresReply = createOFFeaturesReply();
// Setup: add a switch to the controller
IOFSwitch oldsw = createMock(IOFSwitch.class);
setupSwitchForAddSwitch(oldsw, 0L, oldDesc, featuresReply);
oldsw.clearAllFlowMods();
expectLastCall().once();
replay(oldsw);
controller.switchActivated(oldsw);
verify(oldsw);
// drain the queue, we don't care what's in it
controller.processUpdateQueueForTesting();
assertEquals(oldsw, controller.getSwitch(0L));
// Now the actual test: add a new switch with the same dpid to
// the controller
reset(oldsw);
expect(oldsw.getId()).andReturn(0L).anyTimes();
oldsw.cancelAllStatisticsReplies();
expectLastCall().once();
oldsw.disconnectOutputStream();
expectLastCall().once();
IOFSwitch newsw = createMock(IOFSwitch.class);
setupSwitchForAddSwitch(newsw, 0L, newDesc, featuresReply);
newsw.clearAllFlowMods();
expectLastCall().once();
// Strict mock. We need to get the removed notification before the
// add notification
IOFSwitchListener listener = createStrictMock(IOFSwitchListener.class);
listener.switchRemoved(0L);
listener.switchAdded(0L);
listener.switchActivated(0L);
replay(listener);
controller.addOFSwitchListener(listener);
replay(newsw, oldsw);
controller.switchActivated(newsw);
verify(newsw, oldsw);
assertEquals(newsw, controller.getSwitch(0L));
controller.processUpdateQueueForTesting();
verify(listener);
}