本文整理汇总了Java中net.floodlightcontroller.util.OrderedCollection.add方法的典型用法代码示例。如果您正苦于以下问题:Java OrderedCollection.add方法的具体用法?Java OrderedCollection.add怎么用?Java OrderedCollection.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.floodlightcontroller.util.OrderedCollection
的用法示例。
在下文中一共展示了OrderedCollection.add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handlePortStatusDelete
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Handle a OFPortStatus delete message for the given port.
* Updates the internal port maps/lists of this switch and returns
* the PortChangeEvents caused by the delete. If the given port
* exists as it, it will be deleted. If the name<->number for the
* given port is inconsistent with the ports stored by this switch
* the method will delete all ports with the number or name of the
* given port.
*
* This method will increment error/warn counters and log
*
* @param delPort the port from the port status message that should
* be deleted.
* @return ordered collection of port changes applied to this switch
*/
private OrderedCollection<PortChangeEvent>
handlePortStatusDelete(OFPortDesc delPort) {
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
lock.writeLock().lock();
try {
Map<OFPort,OFPortDesc> newPortByNumber =
new HashMap<OFPort, OFPortDesc>(portsByNumber);
OFPortDesc prevPort =
portsByNumber.get(delPort.getPortNo());
if (prevPort == null) {
// so such port. Do we have a port with the name?
prevPort = portsByName.get(delPort.getName());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNo());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
} else if (prevPort.getName().equals(delPort.getName())) {
// port exists with consistent name-number mapping
newPortByNumber.remove(delPort.getPortNo());
events.add(new PortChangeEvent(delPort,
PortChangeType.DELETE));
} else {
// port with same number exists but its name differs. This
// is weird. The best we can do is to delete the existing
// port(s) that have delPort's name and number.
newPortByNumber.remove(delPort.getPortNo());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
// is there another port that has delPort's name?
prevPort = portsByName.get(delPort.getName().toLowerCase());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNo());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
}
updatePortsWithNewPortsByNumber(newPortByNumber);
return events;
} finally {
lock.writeLock().unlock();
}
}
示例2: testPortStatusMessageMaster
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Test port status message handling while MASTER
*
*/
@Test
public void testPortStatusMessageMaster() throws Exception {
DatapathId dpid = featuresReply.getDatapathId();
testInitialMoveToMasterWithRole();
OFPortDesc portDesc = factory.buildPortDesc()
.setName("Port1")
.setPortNo(OFPort.of(1))
.build();
OFPortStatus.Builder portStatusBuilder = factory.buildPortStatus()
.setDesc(portDesc);
// The events we expect sw.handlePortStatus to return
// We'll just use the same list for all valid OFPortReasons and add
// arbitrary events for arbitrary ports that are not necessarily
// related to the port status message. Our goal
// here is not to return the correct set of events but the make sure
// that a) sw.handlePortStatus is called
// b) the list of events sw.handlePortStatus returns is sent
// as IOFSwitchListener notifications.
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
OFPortDesc.Builder pb = factory.buildPortDesc();
OFPortDesc p1 = pb.setName("eth1").setPortNo(OFPort.of(1)).build();
OFPortDesc p2 = pb.setName("eth2").setPortNo(OFPort.of(2)).build();
OFPortDesc p3 = pb.setName("eth3").setPortNo(OFPort.of(3)).build();
OFPortDesc p4 = pb.setName("eth4").setPortNo(OFPort.of(4)).build();
OFPortDesc p5 = pb.setName("eth5").setPortNo(OFPort.of(5)).build();
events.add(new PortChangeEvent(p1, PortChangeType.ADD));
events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
events.add(new PortChangeEvent(p3, PortChangeType.UP));
events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));
for (OFPortReason reason: OFPortReason.values()) {
OFPortStatus portStatus = portStatusBuilder.setReason(reason).build();
reset(sw);
expect(sw.getId()).andReturn(dpid).anyTimes();
expect(sw.processOFPortStatus(portStatus)).andReturn(events).once();
replay(sw);
reset(switchManager);
switchManager.notifyPortChanged(sw, p1, PortChangeType.ADD);
switchManager.notifyPortChanged(sw, p2, PortChangeType.DELETE);
switchManager.notifyPortChanged(sw, p3, PortChangeType.UP);
switchManager.notifyPortChanged(sw, p4, PortChangeType.DOWN);
switchManager.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
replay(switchManager);
switchHandler.processOFMessage(portStatus);
verify(sw);
}
}
示例3: testPortStatusMessageMaster
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Test port status message handling while MASTER
*
*/
@Test
public void testPortStatusMessageMaster() throws Exception {
DatapathId dpid = featuresReply.getDatapathId();
testInitialMoveToMasterWithRole();
OFPortDesc portDesc = factory.buildPortDesc()
.setName("Port1")
.setPortNo(OFPort.of(1))
.build();
OFPortStatus.Builder portStatusBuilder = factory.buildPortStatus()
.setDesc(portDesc);
// The events we expect sw.handlePortStatus to return
// We'll just use the same list for all valid OFPortReasons and add
// arbitrary events for arbitrary ports that are not necessarily
// related to the port status message. Our goal
// here is not to return the correct set of events but the make sure
// that a) sw.handlePortStatus is called
// b) the list of events sw.handlePortStatus returns is sent
// as IOFSwitchListener notifications.
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
OFPortDesc.Builder pb = factory.buildPortDesc();
OFPortDesc p1 = pb.setName("eth1").setPortNo(OFPort.of(1)).build();
OFPortDesc p2 = pb.setName("eth2").setPortNo(OFPort.of(2)).build();
OFPortDesc p3 = pb.setName("eth3").setPortNo(OFPort.of(3)).build();
OFPortDesc p4 = pb.setName("eth4").setPortNo(OFPort.of(4)).build();
OFPortDesc p5 = pb.setName("eth5").setPortNo(OFPort.of(5)).build();
events.add(new PortChangeEvent(p1, PortChangeType.ADD));
events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
events.add(new PortChangeEvent(p3, PortChangeType.UP));
events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));
for (OFPortReason reason: OFPortReason.values()) {
OFPortStatus portStatus = portStatusBuilder.setReason(reason).build();
reset(sw);
expect(sw.getId()).andReturn(dpid).anyTimes();
expect(sw.processOFPortStatus(portStatus)).andReturn(events).once();
replay(sw);
reset(switchManager);
switchManager.notifyPortChanged(sw, p1, PortChangeType.ADD);
switchManager.notifyPortChanged(sw, p2, PortChangeType.DELETE);
switchManager.notifyPortChanged(sw, p3, PortChangeType.UP);
switchManager.notifyPortChanged(sw, p4, PortChangeType.DOWN);
switchManager.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
replay(switchManager);
switchHandler.processOFMessage(portStatus);
verify(sw);
}
}
示例4: handlePortStatusDelete
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Handle a OFPortStatus delete message for the given port.
* Updates the internal port maps/lists of this switch and returns
* the PortChangeEvents caused by the delete. If the given port
* exists as it, it will be deleted. If the name<->number for the
* given port is inconsistent with the ports stored by this switch
* the method will delete all ports with the number or name of the
* given port.
*
* This method will increment error/warn counters and log
*
* @param delPort the port from the port status message that should
* be deleted.
* @return ordered collection of port changes applied to this switch
*/
private OrderedCollection<PortChangeEvent>
handlePortStatusDelete(ImmutablePort delPort) {
lock.writeLock().lock();
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
try {
Map<Short,ImmutablePort> newPortByNumber =
new HashMap<Short, ImmutablePort>(portsByNumber);
ImmutablePort prevPort =
portsByNumber.get(delPort.getPortNumber());
if (prevPort == null) {
// so such port. Do we have a port with the name?
prevPort = portsByName.get(delPort.getName());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNumber());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
} else if (prevPort.getName().equals(delPort.getName())) {
// port exists with consistent name-number mapping
newPortByNumber.remove(delPort.getPortNumber());
events.add(new PortChangeEvent(delPort,
PortChangeType.DELETE));
} else {
// port with same number exists but its name differs. This
// is weird. The best we can do is to delete the existing
// port(s) that have delPort's name and number.
newPortByNumber.remove(delPort.getPortNumber());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
// is there another port that has delPort's name?
prevPort = portsByName.get(delPort.getName().toLowerCase());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNumber());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
}
updatePortsWithNewPortsByNumber(newPortByNumber);
return events;
} finally {
lock.writeLock().unlock();
}
}
示例5: getSinglePortChanges
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Given a new or modified port newPort, returns the list of
* PortChangeEvents to "transform" the current ports stored by
* this switch to include / represent the new port. The ports stored
* by this switch are <b>NOT</b> updated.
*
* This method acquires the readlock and is thread-safe by itself.
* Most callers will need to acquire the write lock before calling
* this method though (if the caller wants to update the ports stored
* by this switch)
*
* @param newPort the new or modified port.
* @return the list of changes
*/
public OrderedCollection<PortChangeEvent>
getSinglePortChanges(ImmutablePort newPort) {
lock.readLock().lock();
try {
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
// Check if we have a port by the same number in our
// old map.
ImmutablePort prevPort =
portsByNumber.get(newPort.getPortNumber());
if (newPort.equals(prevPort)) {
// nothing has changed
return events;
}
if (prevPort != null &&
prevPort.getName().equals(newPort.getName())) {
// A simple modify of a exiting port
// A previous port with this number exists and it's name
// also matches the new port. Find the differences
if (prevPort.isEnabled() && !newPort.isEnabled()) {
events.add(new PortChangeEvent(newPort,
PortChangeType.DOWN));
} else if (!prevPort.isEnabled() && newPort.isEnabled()) {
events.add(new PortChangeEvent(newPort,
PortChangeType.UP));
} else {
events.add(new PortChangeEvent(newPort,
PortChangeType.OTHER_UPDATE));
}
return events;
}
if (prevPort != null) {
// There exists a previous port with the same port
// number but the port name is different (otherwise we would
// never have gotten here)
// Remove the port. Name-number mapping(s) have changed
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
// We now need to check if there exists a previous port sharing
// the same name as the new/updated port.
prevPort = portsByName.get(newPort.getName().toLowerCase());
if (prevPort != null) {
// There exists a previous port with the same port
// name but the port number is different (otherwise we
// never have gotten here).
// Remove the port. Name-number mapping(s) have changed
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
// We always need to add the new port. Either no previous port
// existed or we just deleted previous ports with inconsistent
// name-number mappings
events.add(new PortChangeEvent(newPort, PortChangeType.ADD));
return events;
} finally {
lock.readLock().unlock();
}
}
示例6: testPortStatusMessageMaster
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Test port status message handling while MASTER
*
*/
@Test
public void testPortStatusMessageMaster() throws Exception {
long dpid = featuresReply.getDatapathId();
testInitialMoveToMasterWithRole();
OFPhysicalPort p = new OFPhysicalPort();
p.setName("Port1");
p.setPortNumber((short)1);
OFPortStatus ps = (OFPortStatus)
BasicFactory.getInstance().getMessage(OFType.PORT_STATUS);
ps.setDesc(p);
// The events we expect sw.handlePortStatus to return
// We'll just use the same list for all valid OFPortReasons and add
// arbitrary events for arbitrary ports that are not necessarily
// related to the port status message. Our goal
// here is not to return the correct set of events but the make sure
// that a) sw.handlePortStatus is called
// b) the list of events sw.handlePortStatus returns is sent
// as IOFSwitchListener notifications.
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
ImmutablePort p1 = ImmutablePort.create("eth1", (short)1);
ImmutablePort p2 = ImmutablePort.create("eth2", (short)2);
ImmutablePort p3 = ImmutablePort.create("eth3", (short)3);
ImmutablePort p4 = ImmutablePort.create("eth4", (short)4);
ImmutablePort p5 = ImmutablePort.create("eth5", (short)5);
events.add(new PortChangeEvent(p1, PortChangeType.ADD));
events.add(new PortChangeEvent(p2, PortChangeType.DELETE));
events.add(new PortChangeEvent(p3, PortChangeType.UP));
events.add(new PortChangeEvent(p4, PortChangeType.DOWN));
events.add(new PortChangeEvent(p5, PortChangeType.OTHER_UPDATE));
for (OFPortReason reason: OFPortReason.values()) {
ps.setReason(reason.getReasonCode());
reset(sw);
expect(sw.inputThrottled(anyObject(OFMessage.class)))
.andReturn(false).anyTimes();
expect(sw.getId()).andReturn(dpid).anyTimes();
expect(sw.processOFPortStatus(ps)).andReturn(events).once();
replay(sw);
reset(controller);
controller.notifyPortChanged(sw, p1, PortChangeType.ADD);
controller.notifyPortChanged(sw, p2, PortChangeType.DELETE);
controller.notifyPortChanged(sw, p3, PortChangeType.UP);
controller.notifyPortChanged(sw, p4, PortChangeType.DOWN);
controller.notifyPortChanged(sw, p5, PortChangeType.OTHER_UPDATE);
sendMessageToHandlerNoControllerReset(
Collections.<OFMessage>singletonList(ps));
verify(sw);
verify(controller);
}
}
示例7: handlePortStatusDelete
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Handle a OFPortStatus delete message for the given port.
* Updates the internal port maps/lists of this switch and returns
* the PortChangeEvents caused by the delete. If the given port
* exists as it, it will be deleted. If the name<->number for the
* given port is inconsistent with the ports stored by this switch
* the method will delete all ports with the number or name of the
* given port.
*
* This method will increment error/warn counters and log
*
* @param delPort the port from the port status message that should
* be deleted.
* @return ordered collection of port changes applied to this switch
*/
private OrderedCollection<PortChangeEvent>
handlePortStatusDelete(OFPortDesc delPort) {
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
lock.writeLock().lock();
try {
Map<OFPort,OFPortDesc> newPortByNumber =
new HashMap<OFPort, OFPortDesc>(portsByNumber);
OFPortDesc prevPort =
portsByNumber.get(delPort.getPortNo());
if (prevPort == null) {
// so such port. Do we have a port with the name?
prevPort = portsByName.get(delPort.getName());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNo());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
} else if (prevPort.getName().equals(delPort.getName())) {
// port exists with consistent name-number mapping
newPortByNumber.remove(delPort.getPortNo());
events.add(new PortChangeEvent(delPort,
PortChangeType.DELETE));
} else {
// port with same number exists but its name differs. This
// is weird. The best we can do is to delete the existing
// port(s) that have delPort's name and number.
newPortByNumber.remove(delPort.getPortNo());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
// is there another port that has delPort's name?
prevPort = portsByName.get(delPort.getName().toLowerCase());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNo());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
}
updatePortsWithNewPortsByNumber(newPortByNumber);
return events;
} finally {
lock.writeLock().unlock();
}
}
示例8: handlePortStatusDelete
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Handle a OFPortStatus delete message for the given port. Updates the
* internal port maps/lists of this switch and returns the
* PortChangeEvents caused by the delete. If the given port exists as
* it, it will be deleted. If the name<->number for the given port is
* inconsistent with the ports stored by this switch the method will
* delete all ports with the number or name of the given port.
*
* This method will increment error/warn counters and log
*
* @param delPort the port from the port status message that should be
* deleted.
* @return ordered collection of port changes applied to this switch
*/
private OrderedCollection<PortChangeEvent> handlePortStatusDelete(
OFPortDesc delPort) {
lock.writeLock().lock();
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
try {
Map<Integer, OFPortDesc> newPortByNumber =
new HashMap<Integer, OFPortDesc>(portsByNumber);
OFPortDesc prevPort =
portsByNumber.get(delPort.getPortNo().getPortNumber());
if (prevPort == null) {
// so such port. Do we have a port with the name?
prevPort = portsByName.get(delPort.getName());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNo().getPortNumber());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
} else if (prevPort.getName().equals(delPort.getName())) {
// port exists with consistent name-number mapping
newPortByNumber.remove(delPort.getPortNo().getPortNumber());
events.add(new PortChangeEvent(delPort,
PortChangeType.DELETE));
} else {
// port with same number exists but its name differs. This
// is weird. The best we can do is to delete the existing
// port(s) that have delPort's name and number.
newPortByNumber.remove(delPort.getPortNo().getPortNumber());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
// is there another port that has delPort's name?
prevPort = portsByName.get(delPort.getName().toLowerCase());
if (prevPort != null) {
newPortByNumber.remove(prevPort.getPortNo().getPortNumber());
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
}
updatePortsWithNewPortsByNumber(newPortByNumber);
return events;
} finally {
lock.writeLock().unlock();
}
}
示例9: getSinglePortChanges
import net.floodlightcontroller.util.OrderedCollection; //导入方法依赖的package包/类
/**
* Given a new or modified port newPort, returns the list of
* PortChangeEvents to "transform" the current ports stored by this
* switch to include / represent the new port. The ports stored by this
* switch are <b>NOT</b> updated.
*
* This method acquires the readlock and is thread-safe by itself. Most
* callers will need to acquire the write lock before calling this
* method though (if the caller wants to update the ports stored by this
* switch)
*
* @param newPort the new or modified port.
* @return the list of changes
*/
public OrderedCollection<PortChangeEvent> getSinglePortChanges(
OFPortDesc newPort) {
lock.readLock().lock();
try {
OrderedCollection<PortChangeEvent> events =
new LinkedHashSetWrapper<PortChangeEvent>();
// Check if we have a port by the same number in our
// old map.
OFPortDesc prevPort =
portsByNumber.get(newPort.getPortNo().getPortNumber());
if (newPort.equals(prevPort)) {
// nothing has changed
return events;
}
if (prevPort != null &&
prevPort.getName().equals(newPort.getName())) {
// A simple modify of a existing port
// A previous port with this number exists and it's name
// also matches the new port. Find the differences
if (isEnabled(prevPort) && !isEnabled(newPort)) {
events.add(new PortChangeEvent(newPort,
PortChangeType.DOWN));
} else if (!isEnabled(prevPort) && isEnabled(newPort)) {
events.add(new PortChangeEvent(newPort,
PortChangeType.UP));
} else {
events.add(new PortChangeEvent(newPort,
PortChangeType.OTHER_UPDATE));
}
return events;
}
if (prevPort != null) {
// There exists a previous port with the same port
// number but the port name is different (otherwise we would
// never have gotten here)
// Remove the port. Name-number mapping(s) have changed
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
// We now need to check if there exists a previous port sharing
// the same name as the new/updated port.
prevPort = portsByName.get(newPort.getName().toLowerCase());
if (prevPort != null) {
// There exists a previous port with the same port
// name but the port number is different (otherwise we
// never have gotten here).
// Remove the port. Name-number mapping(s) have changed
events.add(new PortChangeEvent(prevPort,
PortChangeType.DELETE));
}
// We always need to add the new port. Either no previous port
// existed or we just deleted previous ports with inconsistent
// name-number mappings
events.add(new PortChangeEvent(newPort, PortChangeType.ADD));
return events;
} finally {
lock.readLock().unlock();
}
}