本文整理汇总了Java中net.floodlightcontroller.util.OrderedCollection类的典型用法代码示例。如果您正苦于以下问题:Java OrderedCollection类的具体用法?Java OrderedCollection怎么用?Java OrderedCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OrderedCollection类属于net.floodlightcontroller.util包,在下文中一共展示了OrderedCollection类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processOFPortStatus
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
@Override
public OrderedCollection<PortChangeEvent> processOFPortStatus(OFPortStatus ps) {
OrderedCollection<PortChangeEvent> events = super.processOFPortStatus(ps);
for (PortChangeEvent e : events) {
switch (e.type) {
case DELETE:
case DOWN:
log.debug("processOFPortStatus: sw {} Port {} DOWN",
getStringId(), e.port.getPortNo().getPortNumber());
removePortFromGroups(PortNumber.uint32(
e.port.getPortNo().getPortNumber()));
break;
case UP:
log.debug("processOFPortStatus: sw {} Port {} UP",
getStringId(), e.port.getPortNo().getPortNumber());
addPortToGroups(PortNumber.uint32(
e.port.getPortNo().getPortNumber()));
}
}
return events;
}
示例2: 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();
}
}
示例3: handlePortStatusMessage
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
/**
* Handle a OFPortStatus message, update the internal data structures
* that store ports and return the list of OFChangeEvents.
*
* This method will increment error/warn counters and log
*
* @param ps
* @return
*/
@SuppressFBWarnings(value="SF_SWITCH_FALLTHROUGH")
public OrderedCollection<PortChangeEvent> handlePortStatusMessage(OFPortStatus ps) {
if (ps == null) {
throw new NullPointerException("OFPortStatus message must " +
"not be null");
}
lock.writeLock().lock();
try {
OFPortDesc port = ps.getDesc();
OFPortReason reason = ps.getReason();
if (reason == null) {
throw new IllegalArgumentException("Unknown PortStatus " +
"reason code " + ps.getReason());
}
if (log.isDebugEnabled()) {
log.debug("Handling OFPortStatus: {} for {}",
reason, String.format("%s (%d)", port.getName(), port.getPortNo().getPortNumber()));
}
if (reason == OFPortReason.DELETE)
return handlePortStatusDelete(port);
// We handle ADD and MODIFY the same way. Since OpenFlow
// doesn't specify what uniquely identifies a port the
// notion of ADD vs. MODIFY can also be hazy. So we just
// compare the new port to the existing ones.
Map<OFPort,OFPortDesc> newPortByNumber =
new HashMap<OFPort, OFPortDesc>(portsByNumber);
OrderedCollection<PortChangeEvent> events = getSinglePortChanges(port);
for (PortChangeEvent e: events) {
switch(e.type) {
case DELETE:
newPortByNumber.remove(e.port.getPortNo());
break;
case ADD:
if (reason != OFPortReason.ADD) {
// weird case
}
// fall through
case DOWN:
case OTHER_UPDATE:
case UP:
// update or add the port in the map
newPortByNumber.put(e.port.getPortNo(), e.port);
break;
}
}
updatePortsWithNewPortsByNumber(newPortByNumber);
return events;
} finally {
lock.writeLock().unlock();
}
}
示例4:
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
@Override
public OrderedCollection<PortChangeEvent>
processOFPortStatus(OFPortStatus ps) {
return portManager.handlePortStatusMessage(ps);
}
示例5: 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);
}
}
示例6: 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);
}
}
示例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(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();
}
}
示例8: handlePortStatusMessage
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
/**
* Handle a OFPortStatus message, update the internal data structures
* that store ports and return the list of OFChangeEvents.
*
* This method will increment error/warn counters and log
*
* @param ps
* @return
*/
public OrderedCollection<PortChangeEvent> handlePortStatusMessage(OFPortStatus ps) {
if (ps == null) {
throw new NullPointerException("OFPortStatus message must " +
"not be null");
}
lock.writeLock().lock();
try {
ImmutablePort port =
ImmutablePort.fromOFPhysicalPort(ps.getDesc());
OFPortReason reason = OFPortReason.fromReasonCode(ps.getReason());
if (reason == null) {
throw new IllegalArgumentException("Unknown PortStatus " +
"reason code " + ps.getReason());
}
if (log.isDebugEnabled()) {
log.debug("Handling OFPortStatus: {} for {}",
reason, port.toBriefString());
}
if (reason == OFPortReason.OFPPR_DELETE)
return handlePortStatusDelete(port);
// We handle ADD and MODIFY the same way. Since OpenFlow
// doesn't specify what uniquely identifies a port the
// notion of ADD vs. MODIFY can also be hazy. So we just
// compare the new port to the existing ones.
Map<Short,ImmutablePort> newPortByNumber =
new HashMap<Short, ImmutablePort>(portsByNumber);
OrderedCollection<PortChangeEvent> events = getSinglePortChanges(port);
for (PortChangeEvent e: events) {
switch(e.type) {
case DELETE:
newPortByNumber.remove(e.port.getPortNumber());
break;
case ADD:
if (reason != OFPortReason.OFPPR_ADD) {
// weird case
}
// fall through
case DOWN:
case OTHER_UPDATE:
case UP:
// update or add the port in the map
newPortByNumber.put(e.port.getPortNumber(), e.port);
break;
}
}
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(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();
}
}
示例10: processOFPortStatus
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
@Override
@JsonIgnore
public OrderedCollection<PortChangeEvent>
processOFPortStatus(OFPortStatus ps) {
return portManager.handlePortStatusMessage(ps);
}
示例11: comparePorts
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
@Override
public OrderedCollection<PortChangeEvent>
comparePorts(Collection<ImmutablePort> ports) {
return portManager.comparePorts(ports);
}
示例12: setPorts
import net.floodlightcontroller.util.OrderedCollection; //导入依赖的package包/类
@Override
@JsonIgnore
public OrderedCollection<PortChangeEvent>
setPorts(Collection<ImmutablePort> ports) {
return portManager.updatePorts(ports);
}
示例13: 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);
}
}