diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java index c44fd02c54a047bdc64b8b75a49d30a005d1a414..d61f753ef634f3750ff6936dc5ddbc43606d4fad 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java @@ -18,7 +18,9 @@ package net.floodlightcontroller.core; import java.util.HashMap; + import java.util.List; +import java.util.Set; import java.util.Map; import net.floodlightcontroller.core.module.IFloodlightService; @@ -104,11 +106,40 @@ public interface IFloodlightProviderService extends public Map<OFType, List<IOFMessageListener>> getListeners(); /** - * Returns an unmodifiable map of all actively connected OpenFlow switches. This doesn't - * contain switches that are connected but the controller's in the slave role. - * @return the set of actively connected switches + * If the switch with the given DPID is known to any controller in the + * cluster, this method returns the associated IOFSwitch instance. As such + * the returned switches not necessarily connected or in master role for + * the local controller. + * + * Multiple calls to this method with the same DPID may return different + * IOFSwitch references. A caller must not store or otherwise rely on + * IOFSwitch references to be constant over the lifecycle of a switch. + * + * @param dpid the dpid of the switch to query + * @return the IOFSwitch instance associated with the dpid, null if no + * switch with the dpid is known to the cluster + */ + public IOFSwitch getSwitch(long dpid); + + /** + * Returns a snapshot of the set DPIDs for all known switches. + * + * The returned set is owned by the caller: the caller can modify it at + * will and changes to the known switches are not reflected in the returned + * set. The caller needs to call getAllSwitchDpids() if an updated + * version is needed. + * + * See {@link #getSwitch(long)} for what "known" switch is. + * @return the set of DPIDs of all known switches + */ + public Set<Long> getAllSwitchDpids(); + + /** + * Return a snapshot + * FIXME: asdf + * @return */ - public Map<Long, IOFSwitch> getSwitches(); + public Map<Long,IOFSwitch> getAllSwitchMap(); /** * Get the current role of the controller diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index 6fbf1b8ff9a7daa4a80605eaf5d7b96dd77102c9..3eb9f0da684b124e66c251a1cae1fe14059c5b46 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -45,7 +45,6 @@ import org.openflow.protocol.statistics.OFStatistics; public interface IOFSwitch { // Attribute keys public static final String SWITCH_DESCRIPTION_FUTURE = "DescriptionFuture"; - public static final String SWITCH_DESCRIPTION_DATA = "DescriptionData"; public static final String SWITCH_SUPPORTS_NX_ROLE = "supportsNxRole"; public static final String SWITCH_IS_CORE_SWITCH = "isCoreSwitch"; public static final String PROP_FASTWILDCARDS = "FastWildcards"; @@ -60,12 +59,12 @@ public interface IOFSwitch { UPLINK("uplink"), // uplink port (on a virtual switch) MANAGEMENT("management"), // for in-band management TUNNEL_LOOPBACK("tunnel-loopback"); - + private String value; OFPortType(String v) { value = v; } - + @Override public String toString() { return value; @@ -84,7 +83,7 @@ public interface IOFSwitch { /** * Set IFloodlightProviderService for this switch instance * Called immediately after instantiation - * + * * @param controller */ public void setFloodlightProvider(Controller controller); @@ -92,7 +91,7 @@ public interface IOFSwitch { /** * Set IThreadPoolService for this switch instance * Called immediately after instantiation - * + * * @param threadPool */ public void setThreadPoolService(IThreadPoolService threadPool); @@ -100,7 +99,7 @@ public interface IOFSwitch { /** * Set the netty Channel this switch instance is associated with * Called immediately after instantiation - * + * * @param channel */ public void setChannel(Channel channel); @@ -130,12 +129,12 @@ public interface IOFSwitch { * Writes to the OFMessage to the output stream, bypassing rate limiting. * The message will be handed to the floodlightProvider for possible filtering * and processing by message listeners - * @param m - * @param bc - * @throws IOException + * @param m + * @param bc + * @throws IOException */ - public void write(OFMessage m, FloodlightContext bc) throws IOException; - + public void write(OFMessage m, FloodlightContext bc) throws IOException; + /** * Writes the list of messages to the output stream, bypassing rate limiting. * The message will be handed to the floodlightProvider for possible filtering @@ -145,9 +144,9 @@ public interface IOFSwitch { * @throws IOException */ public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException; - + /** - * + * * @throws IOException */ public void disconnectOutputStream(); @@ -157,20 +156,25 @@ public interface IOFSwitch { * @return */ public int getBuffers(); - + public int getActions(); - + public int getCapabilities(); - + public byte getTables(); + /** + * @return a copy of the description statistics for this switch + */ + public OFDescriptionStatistics getDescriptionStatistics(); + /** * Set the OFFeaturesReply message returned by the switch during initial * handshake. * @param featuresReply */ public void setFeaturesReply(OFFeaturesReply featuresReply); - + /** * Get list of all enabled ports. This will typically be different from * the list of ports in the OFFeaturesReply, since that one is a static @@ -180,11 +184,11 @@ public interface IOFSwitch { * @return Unmodifiable list of ports not backed by the underlying collection */ public Collection<OFPhysicalPort> getEnabledPorts(); - + /** * Get list of the port numbers of all enabled ports. This will typically * be different from the list of ports in the OFFeaturesReply, since that - * one is a static snapshot of the ports at the time the switch connected + * one is a static snapshot of the ports at the time the switch connected * to the controller whereas this port list also reflects the port status * messages that have been received. * @return Unmodifiable list of ports not backed by the underlying collection @@ -199,7 +203,7 @@ public interface IOFSwitch { * @return port object */ public OFPhysicalPort getPort(short portNumber); - + /** * Retrieve the port object by the port name. The port object * is the one that reflects the port status updates that have been @@ -208,7 +212,7 @@ public interface IOFSwitch { * @return port object */ public OFPhysicalPort getPort(String portName); - + /** * 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 @@ -224,7 +228,7 @@ public interface IOFSwitch { * @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 @@ -232,14 +236,14 @@ public interface IOFSwitch { * @param portName */ public void deletePort(String portName); - + /** * Get list of all ports. This will typically be different from * the list of ports in the OFFeaturesReply, since that one is a static * snapshot of the ports at the time the switch connected to the controller * whereas this port list also reflects the port status messages that have * been received. - * @return Unmodifiable list of ports + * @return Unmodifiable list of ports */ public Collection<OFPhysicalPort> getPorts(); @@ -249,7 +253,7 @@ public interface IOFSwitch { * (not configured down nor link down nor in spanning tree blocking state) */ public boolean portEnabled(short portName); - + /** * @param portNumber * @return Whether a port is enabled per latest port status message @@ -275,13 +279,13 @@ public interface IOFSwitch { * @return */ public String getStringId(); - + /** * Get the IP Address for the switch * @return the inet address */ public SocketAddress getInetAddress(); - + /** * Retrieves attributes of this switch * @return @@ -306,18 +310,19 @@ public interface IOFSwitch { * * @param request statistics request * @return Future object wrapping OFStatisticsReply - * @throws IOException + * @throws IOException */ - public Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request) + public Future<List<OFStatistics>> queryStatistics(OFStatisticsRequest request) + throws IOException; - + /** * Returns a Future object that can be used to retrieve the asynchronous * OFStatisticsReply when it is available. * * @param request statistics request * @return Future object wrapping OFStatisticsReply - * @throws IOException + * @throws IOException */ public Future<OFFeaturesReply> querySwitchFeaturesReply() throws IOException; @@ -340,26 +345,26 @@ public interface IOFSwitch { * @return whether the switch is still disconnected */ public boolean isConnected(); - + /** * Set whether the switch is connected * Only call while holding modifySwitchLock * @param connected whether the switch is connected */ public void setConnected(boolean connected); - + /** * Get the current role of the controller for the switch * @return the role of the controller */ public Role getHARole(); - + /** * Set switch's HA role to role. The haRoleReplyReceived indicates * if a reply was received from the switch (error replies excluded). - * + * * If role is null, the switch should close the channel connection. - * + * * @param role * @param haRoleReplyReceived */ @@ -370,13 +375,13 @@ public interface IOFSwitch { * @param reply the reply to deliver */ public void deliverStatisticsReply(OFMessage reply); - + /** * Cancel the statistics reply with the given transaction ID * @param transactionId the transaction ID */ public void cancelStatisticsReply(int transactionId); - + /** * Cancel all statistics replies */ @@ -395,7 +400,7 @@ public interface IOFSwitch { * @return value for name */ Object getAttribute(String name); - + /** * Check if the given attribute is present and if so whether it is equal * to "other" @@ -432,7 +437,7 @@ public interface IOFSwitch { * false if there is no cache hit. */ public boolean updateBroadcastCache(Long entry, Short port); - + /** * Get the portBroadcastCacheHits * @return @@ -444,9 +449,9 @@ public interface IOFSwitch { * sending the stats. request to the switch. * @param request flow statistics request message * @param xid transaction id, must be obtained by using the getXid() API. - * @param caller the caller of the API. receive() callback of this + * @param caller the caller of the API. receive() callback of this * caller would be called when the reply from the switch is received. - * @return the transaction id for the message sent to the switch. The + * @return the transaction id for the message sent to the switch. The * transaction id can be used to match the response with the request. Note * that the transaction id is unique only within the scope of this switch. * @throws IOException @@ -464,7 +469,7 @@ public interface IOFSwitch { * Return a read lock that must be held while calling the listeners for * messages from the switch. Holding the read lock prevents the active * switch list from being modified out from under the listeners. - * @return + * @return */ public Lock getListenerReadLock(); @@ -482,12 +487,12 @@ public interface IOFSwitch { * specific types of switches *********************************************** */ - + /** * Set the SwitchProperties based on it's description * @param description */ - public void setSwitchProperties(OFDescriptionStatistics description); + public void setSwitchProperties(OFDescriptionStatistics description); /** * Return the type of OFPort @@ -495,7 +500,7 @@ public interface IOFSwitch { * @return */ public OFPortType getPortType(short port_num); - + /** * Can the port be turned on without forming a new loop? * @param port_num diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 308f170cb5ddefd3364c58f1d36108629ed46fb0..fc54fb1f2907d41c712361c6436742e8b15719d8 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -59,6 +59,7 @@ import org.openflow.protocol.OFPhysicalPort.OFPortState; import org.openflow.protocol.OFPort; import org.openflow.protocol.OFStatisticsRequest; import org.openflow.protocol.OFType; +import org.openflow.protocol.statistics.OFDescriptionStatistics; import org.openflow.protocol.statistics.OFStatistics; import org.openflow.util.HexString; import org.openflow.util.U16; @@ -113,6 +114,8 @@ public abstract class OFSwitchBase implements IOFSwitch { // Private members for throttling private boolean writeThrottleEnabled = false; + protected OFDescriptionStatistics description; + protected final static ThreadLocal<Map<IOFSwitch,List<OFMessage>>> local_msg_buffer = new ThreadLocal<Map<IOFSwitch,List<OFMessage>>>() { @Override @@ -140,6 +143,7 @@ public abstract class OFSwitchBase implements IOFSwitch { this.timedCache = new TimedCache<Long>(100, 5*1000 ); // 5 seconds interval this.listenerLock = new ReentrantReadWriteLock(); this.portBroadcastCacheHitMap = new ConcurrentHashMap<Short, AtomicLong>(); + this.description = new OFDescriptionStatistics(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, OFMatch.OFPFW_ALL); @@ -322,7 +326,8 @@ public abstract class OFSwitchBase implements IOFSwitch { @Override @JsonIgnore public Collection<OFPhysicalPort> getEnabledPorts() { - List<OFPhysicalPort> result = new ArrayList<OFPhysicalPort>(); + List<OFPhysicalPort> result = + new ArrayList<OFPhysicalPort>(portsByNumber.size()); for (OFPhysicalPort port : portsByNumber.values()) { if (portEnabled(port)) { result.add(port); @@ -334,7 +339,8 @@ public abstract class OFSwitchBase implements IOFSwitch { @Override @JsonIgnore public Collection<Short> getEnabledPortNumbers() { - List<Short> result = new ArrayList<Short>(); + List<Short> result = + new ArrayList<Short>(portsByNumber.size()); for (OFPhysicalPort port : portsByNumber.values()) { if (portEnabled(port)) { result.add(port.getPortNumber()); @@ -461,7 +467,7 @@ public abstract class OFSwitchBase implements IOFSwitch { } @Override - public Future<List<OFStatistics>> getStatistics(OFStatisticsRequest request) throws IOException { + public Future<List<OFStatistics>> queryStatistics(OFStatisticsRequest request) throws IOException { request.setXid(getNextTransactionId()); OFStatisticsFuture future = new OFStatisticsFuture(threadPool, this, request.getXid()); this.statsFutureMap.put(request.getXid(), future); @@ -720,6 +726,11 @@ public abstract class OFSwitchBase implements IOFSwitch { return tables; } + @Override + public OFDescriptionStatistics getDescriptionStatistics() { + return new OFDescriptionStatistics(description); + } + @Override public void setFloodlightProvider(Controller controller) { diff --git a/src/main/java/net/floodlightcontroller/core/SwitchSyncRepresentation.java b/src/main/java/net/floodlightcontroller/core/SwitchSyncRepresentation.java new file mode 100644 index 0000000000000000000000000000000000000000..2a8cbed2f143a1d11ae7c90c3a6cec148c14442d --- /dev/null +++ b/src/main/java/net/floodlightcontroller/core/SwitchSyncRepresentation.java @@ -0,0 +1,90 @@ +package net.floodlightcontroller.core; + +import java.util.ArrayList; + +import org.openflow.protocol.OFFeaturesReply; +import org.openflow.protocol.OFPhysicalPort; +import org.openflow.protocol.statistics.OFDescriptionStatistics; +import org.openflow.util.HexString; + +/** + * Represents a switch in the BigSync store. It works out nicely that we + * just need to store the FeaturesReply and the DescriptionStatistics in the + * store. + * @author gregor + * + */ +public class SwitchSyncRepresentation { + // Alaes, these can't be final since we need to de-serialize them from + // Jackson + private OFFeaturesReply featuresReply; + private OFDescriptionStatistics description; + + public SwitchSyncRepresentation() { + featuresReply = new OFFeaturesReply(); + description = new OFDescriptionStatistics(); + } + + public SwitchSyncRepresentation(IOFSwitch sw) { + description = sw.getDescriptionStatistics(); + featuresReply = new OFFeaturesReply(); + featuresReply.setDatapathId(sw.getId()); + featuresReply.setBuffers(sw.getBuffers()); + featuresReply.setTables(sw.getTables()); + featuresReply.setCapabilities(sw.getCapabilities()); + featuresReply.setActions(sw.getActions()); + featuresReply.setPorts(new ArrayList<OFPhysicalPort>(sw.getPorts())); + } + + public OFFeaturesReply getFeaturesReply() { + return featuresReply; + } + + public void setFeaturesReply(OFFeaturesReply featuresReply) { + this.featuresReply = featuresReply; + } + + public OFDescriptionStatistics getDescription() { + return description; + } + + public void setDescription(OFDescriptionStatistics description) { + this.description = description; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((featuresReply == null) ? 0 : featuresReply.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + SwitchSyncRepresentation other = (SwitchSyncRepresentation) obj; + if (description == null) { + if (other.description != null) return false; + } else if (!description.equals(other.description)) return false; + if (featuresReply == null) { + if (other.featuresReply != null) return false; + } else if (!featuresReply.equals(other.featuresReply)) return false; + return true; + } + + @Override + public String toString() { + String dpidString; + if (featuresReply == null) + dpidString = "?"; + else + dpidString = HexString.toHexString(featuresReply.getDatapathId()); + return "SwitchSyncRepresentation [DPID=" + dpidString + "]"; + } +} diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index 420f357e2ae6370bb85109e523194eb0a8ec6f70..c48a7f89c2397f3c166f242d93ad55e90f0d69ce 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -100,6 +100,8 @@ public class Controller implements IFloodlightProviderService, static final String ERROR_DATABASE = "The controller could not communicate with the system database."; + private static final String SWITCH_SYNC_STORE_NAME = + "net.floodlightcontroller.core.SwitchSyncStore"; protected BasicFactory factory; protected ConcurrentMap<OFType, @@ -112,7 +114,11 @@ public class Controller implements IFloodlightProviderService, // The activeSwitches map contains only those switches that are actively // being controlled by us -- it doesn't contain switches that are // in the slave role - protected ConcurrentHashMap<Long, IOFSwitch> activeSwitches; + private ConcurrentHashMap<Long, IOFSwitch> activeSwitches; + // The bigSyncSwitches maps contains the switches we have read from + // the BigSync store + private ConcurrentHashMap<Long, IOFSwitch> bigSyncSwitches; + // The controllerNodeIPsCache maps Controller IDs to their IP address. // It's only used by handleControllerNodeIPsChanged @@ -927,10 +933,50 @@ public class Controller implements IFloodlightProviderService, messageListeners.remove(type); } + // FIXME: remove this method + @Override + public Map<Long,IOFSwitch> getAllSwitchMap() { + if (bigSyncSwitches == null) + throw new AssertionError("bigSyncSwitches should never be null"); + if (activeSwitches == null) + throw new AssertionError("activeSwitches should never be null"); + // bigSyncSwitches will be empty after the master transition + Map<Long,IOFSwitch> switches = + new HashMap<Long, IOFSwitch>(bigSyncSwitches); + if (notifiedRole == Role.MASTER) + switches.putAll(activeSwitches); + return switches; + } + + @Override + public Set<Long> getAllSwitchDpids() { + if (bigSyncSwitches == null) + throw new AssertionError("bigSyncSwitches should never be null"); + if (activeSwitches == null) + throw new AssertionError("activeSwitches should never be null"); + // bigSyncSwitches will be empty after the master transition + Set<Long> dpids = new HashSet<Long>(bigSyncSwitches.keySet()); + if (notifiedRole == Role.MASTER) + dpids.addAll(activeSwitches.keySet()); + return dpids; + } + @Override - public Map<Long, IOFSwitch> getSwitches() { - if (activeSwitches == null) return null; - return Collections.unmodifiableMap(this.activeSwitches); + public IOFSwitch getSwitch(long dpid) { + if (bigSyncSwitches == null) + throw new AssertionError("bigSyncSwitches should never be null"); + if (activeSwitches == null) + throw new AssertionError("activeSwitches should never be null"); + + if (notifiedRole == Role.SLAVE) + return bigSyncSwitches.get(dpid); + // MASTER: if the switch is found in the active map return + // otherwise look up the switch in the bigSync map. The bigSync map + // wil be cleared after the transition is complete. + IOFSwitch sw = activeSwitches.get(dpid); + if (sw != null) + return sw; + return bigSyncSwitches.get(dpid); } @Override @@ -1217,6 +1263,7 @@ public class Controller implements IFloodlightProviderService, this.haListeners = new CopyOnWriteArraySet<IHAListener>(); this.driverRegistry = new NaiiveSwitchDriverRegistry(); this.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); + this.bigSyncSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); this.controllerNodeIPsCache = new HashMap<String, String>(); this.updates = new LinkedBlockingQueue<IUpdate>(); this.factory = BasicFactory.getInstance(); diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java index d924ce255353a5e67ccfefa9fa933c3c35d15cab..380f2950a0f996043550e409d74e17b11d52decf 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java @@ -1,7 +1,7 @@ /** -* Copyright 2012, Big Switch Networks, Inc. +* Copyright 2012, 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 @@ -28,11 +28,11 @@ import net.floodlightcontroller.core.OFSwitchBase; * This is the internal representation of an openflow switch. */ public class OFSwitchImpl extends OFSwitchBase { - + @Override @JsonIgnore public void setSwitchProperties(OFDescriptionStatistics description) { - // Nothing to do at the moment + this.description = new OFDescriptionStatistics(description); } @Override diff --git a/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java b/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java index 37e6c8402d8ed3ebf1b1caa6234fd4c6ef7f1513..c957e6356ba9833bb2b40e331881cccd528b40a1 100644 --- a/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import net.floodlightcontroller.core.IFloodlightProviderService; import org.openflow.protocol.OFFeaturesReply; @@ -37,21 +38,21 @@ import org.slf4j.LoggerFactory; * @author readams */ public class AllSwitchStatisticsResource extends SwitchResourceBase { - protected static Logger log = + protected static Logger log = LoggerFactory.getLogger(AllSwitchStatisticsResource.class); - + @Get("json") - public Map<String, Object> retrieve() { + public Map<String, Object> retrieve() { String statType = (String) getRequestAttributes().get("statType"); return retrieveInternal(statType); } - + public Map<String, Object> retrieveInternal(String statType) { HashMap<String, Object> model = new HashMap<String, Object>(); OFStatisticsType type = null; REQUESTTYPE rType = null; - + if (statType.equals("port")) { type = OFStatisticsType.PORT; rType = REQUESTTYPE.OFSTATS; @@ -75,12 +76,12 @@ public class AllSwitchStatisticsResource extends SwitchResourceBase { } else { return model; } - - IFloodlightProviderService floodlightProvider = + + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). - get(IFloodlightProviderService.class.getCanonicalName()); - Long[] switchDpids = floodlightProvider.getSwitches().keySet().toArray(new Long[0]); - List<GetConcurrentStatsThread> activeThreads = new ArrayList<GetConcurrentStatsThread>(switchDpids.length); + get(IFloodlightProviderService.class.getCanonicalName()); + Set<Long> switchDpids = floodlightProvider.getAllSwitchDpids(); + List<GetConcurrentStatsThread> activeThreads = new ArrayList<GetConcurrentStatsThread>(switchDpids.size()); List<GetConcurrentStatsThread> pendingRemovalThreads = new ArrayList<GetConcurrentStatsThread>(); GetConcurrentStatsThread t; for (Long l : switchDpids) { @@ -88,10 +89,10 @@ public class AllSwitchStatisticsResource extends SwitchResourceBase { activeThreads.add(t); t.start(); } - + // Join all the threads after the timeout. Set a hard timeout // of 12 seconds for the threads to finish. If the thread has not - // finished the switch has not replied yet and therefore we won't + // finished the switch has not replied yet and therefore we won't // add the switch's stats to the reply. for (int iSleepCycles = 0; iSleepCycles < 12; iSleepCycles++) { for (GetConcurrentStatsThread curThread : activeThreads) { @@ -104,19 +105,19 @@ public class AllSwitchStatisticsResource extends SwitchResourceBase { pendingRemovalThreads.add(curThread); } } - + // remove the threads that have completed the queries to the switches for (GetConcurrentStatsThread curThread : pendingRemovalThreads) { activeThreads.remove(curThread); } // clear the list so we don't try to double remove them pendingRemovalThreads.clear(); - + // if we are done finish early so we don't always get the worst case if (activeThreads.isEmpty()) { break; } - + // sleep for 1 s here try { Thread.sleep(1000); @@ -124,17 +125,17 @@ public class AllSwitchStatisticsResource extends SwitchResourceBase { log.error("Interrupted while waiting for statistics", e); } } - + return model; } - + protected class GetConcurrentStatsThread extends Thread { private List<OFStatistics> switchReply; private long switchId; private OFStatisticsType statType; private REQUESTTYPE requestType; private OFFeaturesReply featuresReply; - + public GetConcurrentStatsThread(long switchId, REQUESTTYPE requestType, OFStatisticsType statType) { this.switchId = switchId; this.requestType = requestType; @@ -142,19 +143,20 @@ public class AllSwitchStatisticsResource extends SwitchResourceBase { this.switchReply = null; this.featuresReply = null; } - + public List<OFStatistics> getStatisticsReply() { return switchReply; } - + public OFFeaturesReply getFeaturesReply() { return featuresReply; } - + public long getSwitchId() { return switchId; } - + + @Override public void run() { if ((requestType == REQUESTTYPE.OFSTATS) && (statType != null)) { switchReply = getSwitchStatistics(switchId, statType); diff --git a/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java b/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java index 454f566cf78fbf5fcf1ec73c705a59e99a0d83d4..3572fa887f6f32a9c21fab73d5370c945f672f5b 100644 --- a/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/ControllerSwitchesResource.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -35,18 +35,18 @@ import org.restlet.resource.ServerResource; * @author readams */ public class ControllerSwitchesResource extends ServerResource { - public static final String DPID_ERROR = - "Invalid Switch DPID: must be a 64-bit quantity, expressed in " + + public static final String DPID_ERROR = + "Invalid Switch DPID: must be a 64-bit quantity, expressed in " + "hex as AA:BB:CC:DD:EE:FF:00:11"; - + @Get("json") public Iterator<IOFSwitch> retrieve() { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); Long switchDPID = null; - + Form form = getQuery(); String dpid = form.getFirstValue("dpid", true); if (dpid != null) { @@ -58,16 +58,16 @@ public class ControllerSwitchesResource extends ServerResource { } } if (switchDPID != null) { - IOFSwitch sw = - floodlightProvider.getSwitches().get(switchDPID); + IOFSwitch sw = + floodlightProvider.getSwitch(switchDPID); if (sw != null) return Collections.singleton(sw).iterator(); return Collections.<IOFSwitch>emptySet().iterator(); } - final String dpidStartsWith = + final String dpidStartsWith = form.getFirstValue("dpid__startswith", true); - Iterator<IOFSwitch> switer = - floodlightProvider.getSwitches().values().iterator(); + Iterator<IOFSwitch> switer = + floodlightProvider.getAllSwitchMap().values().iterator(); if (dpidStartsWith != null) { return new FilterIterator<IOFSwitch>(switer) { @Override @@ -75,7 +75,7 @@ public class ControllerSwitchesResource extends ServerResource { return value.getStringId().startsWith(dpidStartsWith); } }; - } + } return switer; } } diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchCounterCategoriesResource.java b/src/main/java/net/floodlightcontroller/core/web/SwitchCounterCategoriesResource.java index f14d7062eb658f334f8b11108c5f9dfe6d5e20af..34aa2eaa763f2953fa6b03ad95a82c25683add11 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SwitchCounterCategoriesResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SwitchCounterCategoriesResource.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -37,19 +37,17 @@ import net.floodlightcontroller.counter.ICounterStoreService; public class SwitchCounterCategoriesResource extends CounterResourceBase { @Get("json") public Map<String, Object> retrieve() { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); HashMap<String,Object> model = new HashMap<String,Object>(); - + String switchID = (String) getRequestAttributes().get("switchId"); String counterName = (String) getRequestAttributes().get("counterName"); String layer = (String) getRequestAttributes().get("layer"); - Long[] switchDpids; if (switchID.equalsIgnoreCase("all")) { - switchDpids = floodlightProvider.getSwitches().keySet().toArray(new Long[0]); - for (Long dpid : switchDpids) { + for (Long dpid : floodlightProvider.getAllSwitchDpids()) { switchID = HexString.toHexString(dpid); getOneSwitchCounterCategoriesJson(model, switchID, counterName, layer); @@ -57,17 +55,17 @@ public class SwitchCounterCategoriesResource extends CounterResourceBase { } else { getOneSwitchCounterCategoriesJson(model, switchID, counterName, layer); } - + return model; } - + protected void getOneSwitchCounterCategoriesJson(Map<String, Object> model, String switchID, - String counterName, + String counterName, String layer) { - String fullCounterName = ""; + String fullCounterName = ""; NetworkLayer nl = NetworkLayer.L3; - + try { counterName = URLDecoder.decode(counterName, "UTF-8"); layer = URLDecoder.decode(layer, "UTF-8"); diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java b/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java index 188836d30d6ba65bcaf0e55ff81e2edc267ef465..34755ea083536a430652842a231fd22944e27552 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SwitchCounterResource.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -30,25 +30,23 @@ import net.floodlightcontroller.counter.ICounter; import net.floodlightcontroller.counter.ICounterStoreService; /** - * Get counters for a particular switch + * Get counters for a particular switch * @author readams */ public class SwitchCounterResource extends CounterResourceBase { @Get("json") public Map<String, Object> retrieve() { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); HashMap<String,Object> model = new HashMap<String,Object>(); - + String switchID = (String) getRequestAttributes().get("switchId"); String counterName = (String) getRequestAttributes().get("counterName"); - Long[] switchDpids; if (switchID.equalsIgnoreCase("all")) { - switchDpids = floodlightProvider.getSwitches().keySet().toArray(new Long[0]); getOneSwitchCounterJson(model, ICounterStoreService.CONTROLLER_NAME, counterName); - for (Long dpid : switchDpids) { + for (Long dpid : floodlightProvider.getAllSwitchDpids()) { switchID = HexString.toHexString(dpid); getOneSwitchCounterJson(model, switchID, counterName); @@ -58,14 +56,14 @@ public class SwitchCounterResource extends CounterResourceBase { } return model; } - - protected void getOneSwitchCounterJson(Map<String, Object> model, + + protected void getOneSwitchCounterJson(Map<String, Object> model, String switchID, String counterName) { - String fullCounterName = ""; - + String fullCounterName = ""; + try { counterName = URLDecoder.decode(counterName, "UTF-8"); - fullCounterName = + fullCounterName = switchID + ICounterStoreService.TitleDelimitor + counterName; } catch (UnsupportedEncodingException e) { //Just leave counterTitle undecoded if there is an issue - fail silently @@ -74,10 +72,10 @@ public class SwitchCounterResource extends CounterResourceBase { ICounter counter = this.counterStore.getCounter(fullCounterName); Map<String, Long> sample = new HashMap<String, Long> (); if (counter != null) { - sample.put(counter.getCounterDate().toString(), + sample.put(counter.getCounterDate().toString(), counter.getCounterValue().getLong()); model.put(switchID, sample); } } - + } diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java b/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java index 81f07bee01ad87ad5f04734df644c658135c77be..6b4a46318fb7dbac07fd628ed23fcc44b8fb146a 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java +++ b/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -49,31 +49,31 @@ import org.slf4j.LoggerFactory; */ public class SwitchResourceBase extends ServerResource { protected static Logger log = LoggerFactory.getLogger(SwitchResourceBase.class); - + public enum REQUESTTYPE { OFSTATS, OFFEATURES } - + @Override protected void doInit() throws ResourceException { super.doInit(); - + } - + @LogMessageDoc(level="ERROR", message="Failure retrieving statistics from switch {switch}", explanation="An error occurred while retrieving statistics" + "from the switch", recommendation=LogMessageDoc.CHECK_SWITCH + " " + LogMessageDoc.GENERIC_ACTION) - protected List<OFStatistics> getSwitchStatistics(long switchId, + protected List<OFStatistics> getSwitchStatistics(long switchId, OFStatisticsType statType) { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); - - IOFSwitch sw = floodlightProvider.getSwitches().get(switchId); + + IOFSwitch sw = floodlightProvider.getSwitch(switchId); Future<List<OFStatistics>> future; List<OFStatistics> values = null; if (sw != null) { @@ -100,12 +100,12 @@ public class SwitchResourceBase extends ServerResource { requestLength += specificReq.getLength(); } else if (statType == OFStatisticsType.PORT) { OFPortStatisticsRequest specificReq = new OFPortStatisticsRequest(); - specificReq.setPortNumber((short)OFPort.OFPP_NONE.getValue()); + specificReq.setPortNumber(OFPort.OFPP_NONE.getValue()); req.setStatistics(Collections.singletonList((OFStatistics)specificReq)); requestLength += specificReq.getLength(); } else if (statType == OFStatisticsType.QUEUE) { OFQueueStatisticsRequest specificReq = new OFQueueStatisticsRequest(); - specificReq.setPortNumber((short)OFPort.OFPP_ALL.getValue()); + specificReq.setPortNumber(OFPort.OFPP_ALL.getValue()); // LOOK! openflowj does not define OFPQ_ALL! pulled this from openflow.h // note that I haven't seen this work yet though... specificReq.setQueueId(0xffffffff); @@ -117,7 +117,7 @@ public class SwitchResourceBase extends ServerResource { } req.setLengthU(requestLength); try { - future = sw.getStatistics(req); + future = sw.queryStatistics(req); values = future.get(10, TimeUnit.SECONDS); } catch (Exception e) { log.error("Failure retrieving statistics from switch " + sw, e); @@ -129,13 +129,13 @@ public class SwitchResourceBase extends ServerResource { protected List<OFStatistics> getSwitchStatistics(String switchId, OFStatisticsType statType) { return getSwitchStatistics(HexString.toLong(switchId), statType); } - + protected OFFeaturesReply getSwitchFeaturesReply(long switchId) { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); - IOFSwitch sw = floodlightProvider.getSwitches().get(switchId); + IOFSwitch sw = floodlightProvider.getSwitch(switchId); Future<OFFeaturesReply> future; OFFeaturesReply featuresReply = null; if (sw != null) { diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java b/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java index 74a228eea5858a61cc50dee54aecdc310d5bd120..e6d66e2c24db29bad055be5d9a0132778e7ffe87 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java @@ -35,26 +35,26 @@ public class SwitchRoleResource extends ServerResource { @Get("json") public Object getRole() { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); String switchId = (String) getRequestAttributes().get("switchId"); - + RoleInfo roleInfo; - + if (switchId.equalsIgnoreCase("all")) { HashMap<String,RoleInfo> model = new HashMap<String,RoleInfo>(); - for (IOFSwitch sw: floodlightProvider.getSwitches().values()) { + for (IOFSwitch sw: floodlightProvider.getAllSwitchMap().values()) { switchId = sw.getStringId(); roleInfo = new RoleInfo(sw.getHARole(), null); model.put(switchId, roleInfo); } return model; } - + Long dpid = HexString.toLong(switchId); - IOFSwitch sw = floodlightProvider.getSwitches().get(dpid); + IOFSwitch sw = floodlightProvider.getSwitch(dpid); if (sw == null) return null; roleInfo = new RoleInfo(sw.getHARole(), null); diff --git a/src/main/java/net/floodlightcontroller/flowcache/PortDownReconciliation.java b/src/main/java/net/floodlightcontroller/flowcache/PortDownReconciliation.java index 7360b4f5af30eb2eb228d03cb38027ce920f259e..c222cfec335b87c15fa703667d9975ee88612568 100644 --- a/src/main/java/net/floodlightcontroller/flowcache/PortDownReconciliation.java +++ b/src/main/java/net/floodlightcontroller/flowcache/PortDownReconciliation.java @@ -1,6 +1,6 @@ /** - * Copyright 2012, Jason Parraga, Marist College - * + * Copyright 2012, Jason Parraga, Marist College + * * 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 @@ -64,7 +64,7 @@ import net.floodlightcontroller.topology.ITopologyService; * and remove them (specifically flows with an idle timeout that would not be * exhausted). Once the flows are deleted Floodlight will re-evaluate the path * the traffic should take with it's updated topology map. - * + * * @author Jason Parraga */ @@ -90,8 +90,7 @@ public class PortDownReconciliation implements IFloodlightModule, .equals(ILinkDiscovery.UpdateOperation.PORT_DOWN)) { // Get the switch ID for the OFMatchWithSwDpid object - long affectedSwitch = floodlightProvider.getSwitches() - .get(ldu.getSrc()) + long affectedSwitch = floodlightProvider.getSwitch(ldu.getSrc()) .getId(); // Create an OFMatchReconcile object @@ -181,7 +180,7 @@ public class PortDownReconciliation implements IFloodlightModule, /** * Base case for the reconciliation of flows. This is triggered at the * switch which is immediately affected by the PORT_DOWN event - * + * * @return the Command whether to STOP or Continue */ @Override @@ -197,8 +196,8 @@ public class PortDownReconciliation implements IFloodlightModule, // update the path to a switch if (ofmr.rcAction.equals(OFMatchReconcile.ReconcileAction.UPDATE_PATH)) { // Get the switch object from the OFMatchReconcile - IOFSwitch sw = floodlightProvider.getSwitches() - .get(ofmr.ofmWithSwDpid.getSwitchDataPathId()); + IOFSwitch sw = floodlightProvider + .getSwitch(ofmr.ofmWithSwDpid.getSwitchDataPathId()); // Map data structure that holds the invalid matches and the // ingress ports of those matches @@ -260,8 +259,7 @@ public class PortDownReconciliation implements IFloodlightModule, invalidBaseIngressAndMatch.getValue()); // Link a neighbor switch's invalid match // and outport to their Switch object - neighborSwitches.put(floodlightProvider.getSwitches() - .get(link.getSrc()), + neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } @@ -314,7 +312,7 @@ public class PortDownReconciliation implements IFloodlightModule, try { // System.out.println(sw.getStatistics(req)); - future = sw.getStatistics(req); + future = sw.queryStatistics(req); values = future.get(10, TimeUnit.SECONDS); if (values != null) { for (OFStatistics stat : values) { @@ -384,7 +382,7 @@ public class PortDownReconciliation implements IFloodlightModule, /** * Deletes flows with similar matches and output action ports on the * specified switch - * + * * @param sw * the switch to query flows on * @param match @@ -471,8 +469,7 @@ public class PortDownReconciliation implements IFloodlightModule, ingressPort.getValue()); // Link a neighbor switch's invalid match and // outport to their Switch object - neighborSwitches.put(floodlightProvider.getSwitches() - .get(link.getSrc()), + neighborSwitches.put(floodlightProvider.getSwitch(link.getSrc()), invalidNeighborOutportAndMatch); } } diff --git a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitchTable.java b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitchTable.java index 489bea7d508a4727b1f3beabd36bd744ad3a5bc4..2eb1b914f1bc501a449d954733317d229463114e 100644 --- a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitchTable.java +++ b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitchTable.java @@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory; public class LearningSwitchTable extends ServerResource { protected static Logger log = LoggerFactory.getLogger(LearningSwitchTable.class); - + protected Map<String, Object> formatTableEntry(MacVlanPair key, short port) { Map<String, Object> entry = new HashMap<String, Object>(); entry.put("mac", HexString.toHexString(key.mac)); @@ -43,7 +43,7 @@ public class LearningSwitchTable extends ServerResource { entry.put("port", port); return entry; } - + protected List<Map<String, Object>> getOneSwitchTable(Map<MacVlanPair, Short> switchMap) { List<Map<String, Object>> switchTable = new ArrayList<Map<String, Object>>(); for (Entry<MacVlanPair, Short> entry : switchMap.entrySet()) { @@ -51,16 +51,16 @@ public class LearningSwitchTable extends ServerResource { } return switchTable; } - + @Get("json") public Map<String, List<Map<String, Object>>> getSwitchTableJson() { - ILearningSwitchService lsp = + ILearningSwitchService lsp = (ILearningSwitchService)getContext().getAttributes(). get(ILearningSwitchService.class.getCanonicalName()); Map<IOFSwitch, Map<MacVlanPair,Short>> table = lsp.getTable(); Map<String, List<Map<String, Object>>> allSwitchTableJson = new HashMap<String, List<Map<String, Object>>>(); - + String switchId = (String) getRequestAttributes().get("switch"); if (switchId.toLowerCase().equals("all")) { for (IOFSwitch sw : table.keySet()) { @@ -68,18 +68,18 @@ public class LearningSwitchTable extends ServerResource { } } else { try { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); long dpid = HexString.toLong(switchId); - IOFSwitch sw = floodlightProvider.getSwitches().get(dpid); + IOFSwitch sw = floodlightProvider.getSwitch(dpid); allSwitchTableJson.put(HexString.toHexString(sw.getId()), getOneSwitchTable(table.get(sw))); } catch (NumberFormatException e) { log.error("Could not decode switch ID = " + switchId); setStatus(Status.CLIENT_ERROR_BAD_REQUEST); } } - + return allSwitchTableJson; } } diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java index 626804847d9d2bc97d508cb5583ca5e5df8a4617..cd6c39e23f6fe62ccbd600ca4d75e16918e9c028 100644 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java +++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java @@ -266,7 +266,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, public OFPacketOut generateLLDPMessage(long sw, short port, boolean isStandard, boolean isReverse) { - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); OFPhysicalPort ofpPort = iofSwitch.getPort(port); if (log.isTraceEnabled()) { @@ -595,7 +595,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, private Command handleLldp(LLDP lldp, long sw, short inPort, boolean isStandard, FloodlightContext cntx) { // If LLDP is suppressed on this port, ignore received packet as well - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (!isIncomingDiscoveryAllowed(sw, inPort, isStandard)) return Command.STOP; @@ -624,8 +624,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, && lldptlv.getValue()[2] == (byte) 0xe1 && lldptlv.getValue()[3] == 0x0) { ByteBuffer dpidBB = ByteBuffer.wrap(lldptlv.getValue()); - remoteSwitch = floodlightProvider.getSwitches() - .get(dpidBB.getLong(4)); + remoteSwitch = floodlightProvider.getSwitch(dpidBB.getLong(4)); } else if (lldptlv.getType() == 12 && lldptlv.getLength() == 8) { otherId = ByteBuffer.wrap(lldptlv.getValue()).getLong(); if (myId == otherId) myLLDP = true; @@ -790,7 +789,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, */ protected Command handlePortStatus(long sw, OFPortStatus ps) { - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) return Command.CONTINUE; if (log.isTraceEnabled()) { @@ -908,7 +907,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, return; } - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) return; if (autoPortFastFeature && iofSwitch.isFastPort(p)) { @@ -1100,7 +1099,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, private void generateSwitchPortStatusUpdate(long sw, short port) { UpdateOperation operation; - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) return; OFPhysicalPort ofp = iofSwitch.getPort(port); @@ -1155,7 +1154,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, return false; } - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) { return false; } @@ -1191,7 +1190,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, return false; } - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) { return false; } @@ -1253,7 +1252,7 @@ public class LinkDiscoveryManager implements IOFMessageListener, if (!isOutgoingDiscoveryAllowed(sw, port, isStandard, isReverse)) return; - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); OFPhysicalPort ofpPort = iofSwitch.getPort(port); if (log.isTraceEnabled()) { @@ -1293,10 +1292,9 @@ public class LinkDiscoveryManager implements IOFMessageListener, if (log.isTraceEnabled()) { log.trace("Sending LLDP packets out of all the enabled ports on switch {}"); } - Set<Long> switches = floodlightProvider.getSwitches().keySet(); // Send standard LLDPs - for (long sw : switches) { - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + for (long sw : floodlightProvider.getAllSwitchDpids()) { + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) continue; if (iofSwitch.getEnabledPorts() != null) { for (OFPhysicalPort ofp : iofSwitch.getEnabledPorts()) { @@ -1866,12 +1864,11 @@ public class LinkDiscoveryManager implements IOFMessageListener, return; } - Map<Long, IOFSwitch> switches = floodlightProvider.getSwitches(); ArrayList<IOFSwitch> updated_switches = new ArrayList<IOFSwitch>(); for (Object key : rowKeys) { Long swId = new Long(HexString.toLong((String) key)); - if (switches.containsKey(swId)) { - IOFSwitch sw = switches.get(swId); + IOFSwitch sw = floodlightProvider.getSwitch(swId); + if (sw != null) { boolean curr_status = sw.hasAttribute(IOFSwitch.SWITCH_IS_CORE_SWITCH); boolean new_status = false; IResultSet resultSet = null; diff --git a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java index 9be2079cf1aa2cf268cc14c6b5fa790439a7b3d8..6a6a0001570118018525f15d90f6240237c58708 100644 --- a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java +++ b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java @@ -1,7 +1,7 @@ /** - * Copyright 2011, Big Switch Networks, Inc. + * 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 @@ -63,26 +63,26 @@ import org.slf4j.LoggerFactory; * decision. */ @LogMessageCategory("Flow Programming") -public abstract class ForwardingBase +public abstract class ForwardingBase implements IOFMessageListener { - + protected static Logger log = LoggerFactory.getLogger(ForwardingBase.class); protected static int OFMESSAGE_DAMPER_CAPACITY = 10000; // TODO: find sweet spot - protected static int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms + protected static int OFMESSAGE_DAMPER_TIMEOUT = 250; // ms public static short FLOWMOD_DEFAULT_IDLE_TIMEOUT = 5; // in seconds public static short FLOWMOD_DEFAULT_HARD_TIMEOUT = 0; // infinite - + protected IFloodlightProviderService floodlightProvider; protected IDeviceService deviceManager; protected IRoutingService routingEngine; protected ITopologyService topology; protected ICounterStoreService counterStore; - + protected OFMessageDamper messageDamper; - + // for broadcast loop suppression protected boolean broadcastCacheFeature = true; public final int prime1 = 2633; // for hash calculation @@ -94,26 +94,26 @@ public abstract class ForwardingBase public static final int FORWARDING_APP_ID = 2; // TODO: This must be managed // by a global APP_ID class public long appCookie = AppCookie.makeCookie(FORWARDING_APP_ID, 0); - + // Comparator for sorting by SwitchCluster public Comparator<SwitchPort> clusterIdComparator = new Comparator<SwitchPort>() { @Override public int compare(SwitchPort d1, SwitchPort d2) { - Long d1ClusterId = + Long d1ClusterId = topology.getL2DomainId(d1.getSwitchDPID()); - Long d2ClusterId = + Long d2ClusterId = topology.getL2DomainId(d2.getSwitchDPID()); return d1ClusterId.compareTo(d2ClusterId); } }; - + /** * init data structures - * + * */ protected void init() { - messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY, + messageDamper = new OFMessageDamper(OFMESSAGE_DAMPER_CAPACITY, EnumSet.of(OFType.FLOW_MOD), OFMESSAGE_DAMPER_TIMEOUT); } @@ -136,7 +136,7 @@ public abstract class ForwardingBase /** * All subclasses must define this function if they want any specific * forwarding action - * + * * @param sw * Switch that the packet came in from * @param pi @@ -196,13 +196,13 @@ public abstract class ForwardingBase message="Failure writing flow mod", explanation="An I/O error occurred while writing a " + "flow modification to a switch", - recommendation=LogMessageDoc.CHECK_SWITCH) + recommendation=LogMessageDoc.CHECK_SWITCH) }) - public boolean pushRoute(Route route, OFMatch match, + public boolean pushRoute(Route route, OFMatch match, Integer wildcard_hints, OFPacketIn pi, long pinSwitch, - long cookie, + long cookie, FloodlightContext cntx, boolean reqeustFlowRemovedNotifn, boolean doFlush, @@ -231,7 +231,7 @@ public abstract class ForwardingBase for (int indx = switchPortList.size()-1; indx > 0; indx -= 2) { // indx and indx-1 will always have the same switch DPID. long switchDPID = switchPortList.get(indx).getNodeId(); - IOFSwitch sw = floodlightProvider.getSwitches().get(switchDPID); + IOFSwitch sw = floodlightProvider.getSwitch(switchDPID); if (sw == null) { if (log.isWarnEnabled()) { log.warn("Unable to push route, switch at DPID {} " + @@ -264,7 +264,7 @@ public abstract class ForwardingBase try { counterStore.updatePktOutFMCounterStoreLocal(sw, fm); if (log.isTraceEnabled()) { - log.trace("Pushing Route flowmod routeIndx={} " + + log.trace("Pushing Route flowmod routeIndx={} " + "sw={} inPort={} outPort={}", new Object[] {indx, sw, @@ -279,8 +279,8 @@ public abstract class ForwardingBase // Push the packet out the source switch if (sw.getId() == pinSwitch) { - // TODO: Instead of doing a packetOut here we could also - // send a flowMod with bufferId set.... + // TODO: Instead of doing a packetOut here we could also + // send a flowMod with bufferId set.... pushPacket(sw, pi, false, outPort, cntx); srcSwitchIncluded = true; } @@ -305,9 +305,9 @@ public abstract class ForwardingBase } return match.clone(); } - + /** - * Pushes a packet-out to a switch. If bufferId != BUFFER_ID_NONE we + * Pushes a packet-out to a switch. If bufferId != BUFFER_ID_NONE we * assume that the packetOut switch is the same as the packetIn switch * and we will use the bufferId. In this case the packet can be null * Caller needs to make sure that inPort and outPort differs @@ -331,45 +331,45 @@ public abstract class ForwardingBase message="Failure writing packet out", explanation="An I/O error occurred while writing a " + "packet out to a switch", - recommendation=LogMessageDoc.CHECK_SWITCH) + recommendation=LogMessageDoc.CHECK_SWITCH) }) /** * Pushes a packet-out to a switch. The assumption here is that * the packet-in was also generated from the same switch. Thus, if the input - * port of the packet-in and the outport are the same, the function will not + * port of the packet-in and the outport are the same, the function will not * push the packet-out. * @param sw switch that generated the packet-in, and from which packet-out is sent * @param pi packet-in - * @param useBufferId if true, use the bufferId from the packet in and - * do not add the packetIn's payload. If false set bufferId to - * BUFFER_ID_NONE and use the packetIn's payload + * @param useBufferId if true, use the bufferId from the packet in and + * do not add the packetIn's payload. If false set bufferId to + * BUFFER_ID_NONE and use the packetIn's payload * @param outport output port * @param cntx context of the packet */ - protected void pushPacket(IOFSwitch sw, OFPacketIn pi, - boolean useBufferId, + protected void pushPacket(IOFSwitch sw, OFPacketIn pi, + boolean useBufferId, short outport, FloodlightContext cntx) { if (pi == null) { return; } - // The assumption here is (sw) is the switch that generated the + // The assumption here is (sw) is the switch that generated the // packet-in. If the input port is the same as output port, then // the packet-out should be ignored. if (pi.getInPort() == outport) { if (log.isDebugEnabled()) { - log.debug("Attempting to do packet-out to the same " + - "interface as packet-in. Dropping packet. " + - " SrcSwitch={}, pi={}", + log.debug("Attempting to do packet-out to the same " + + "interface as packet-in. Dropping packet. " + + " SrcSwitch={}, pi={}", new Object[]{sw, pi}); return; } } if (log.isTraceEnabled()) { - log.trace("PacketOut srcSwitch={} pi={}", + log.trace("PacketOut srcSwitch={} pi={}", new Object[] {sw, pi}); } @@ -391,7 +391,7 @@ public abstract class ForwardingBase } else { po.setBufferId(OFPacketOut.BUFFER_ID_NONE); } - + if (po.getBufferId() == OFPacketOut.BUFFER_ID_NONE) { byte[] packetData = pi.getPacketData(); poLength += packetData.length; @@ -409,7 +409,7 @@ public abstract class ForwardingBase } } - + /** * Write packetout message to sw with output actions to one or more * output ports with inPort/outPorts passed in. @@ -431,15 +431,15 @@ public abstract class ForwardingBase while (j.hasNext()) { - actions.add(new OFActionOutput(j.next().shortValue(), + actions.add(new OFActionOutput(j.next().shortValue(), (short) 0)); } - OFPacketOut po = + OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory(). getMessage(OFType.PACKET_OUT); po.setActions(actions); - po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH * + po.setActionsLength((short) (OFActionOutput.MINIMUM_LENGTH * outPorts.size())); // set buffer-id to BUFFER_ID_NONE, and set in-port to OFPP_NONE @@ -447,7 +447,7 @@ public abstract class ForwardingBase po.setInPort(inPort); // data (note buffer_id is always BUFFER_ID_NONE) and length - short poLength = (short)(po.getActionsLength() + + short poLength = (short)(po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH); poLength += packetData.length; po.setPacketData(packetData); @@ -456,7 +456,7 @@ public abstract class ForwardingBase try { counterStore.updatePktOutFMCounterStoreLocal(sw, po); if (log.isTraceEnabled()) { - log.trace("write broadcast packet on switch-id={} " + + log.trace("write broadcast packet on switch-id={} " + "interfaces={} packet-out={}", new Object[] {sw.getId(), outPorts, po}); } @@ -466,8 +466,8 @@ public abstract class ForwardingBase log.error("Failure writing packet out", e); } } - - /** + + /** * @see packetOutMultiPort * Accepts a PacketIn instead of raw packet data. Note that the inPort * and switch can be different than the packet in switch/port @@ -479,8 +479,8 @@ public abstract class ForwardingBase FloodlightContext cntx) { packetOutMultiPort(pi.getPacketData(), sw, inPort, outPorts, cntx); } - - /** + + /** * @see packetOutMultiPort * Accepts an IPacket instead of raw packet data. Note that the inPort * and switch can be different than the packet in switch/port @@ -497,15 +497,15 @@ public abstract class ForwardingBase FloodlightContext cntx) { // Get the cluster id of the switch. // Get the hash of the Ethernet packet. - if (sw == null) return true; - + if (sw == null) return true; + // If the feature is disabled, always return false; if (!broadcastCacheFeature) return false; - Ethernet eth = + Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD); - + Long broadcastHash; broadcastHash = topology.getL2DomainId(sw.getId()) * prime1 + pi.getInPort() * prime2 + eth.hashCode(); @@ -519,7 +519,7 @@ public abstract class ForwardingBase protected boolean isInSwitchBroadcastCache(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) { if (sw == null) return true; - + // If the feature is disabled, always return false; if (!broadcastCacheFeature) return false; @@ -538,7 +538,7 @@ public abstract class ForwardingBase message="Failure writing deny flow mod", explanation="An I/O error occurred while writing a " + "deny flow mod to a switch", - recommendation=LogMessageDoc.CHECK_SWITCH) + recommendation=LogMessageDoc.CHECK_SWITCH) }) public static boolean blockHost(IFloodlightProviderService floodlightProvider, @@ -549,8 +549,8 @@ public abstract class ForwardingBase return false; } - IOFSwitch sw = - floodlightProvider.getSwitches().get(sw_tup.getSwitchDPID()); + IOFSwitch sw = + floodlightProvider.getSwitch(sw_tup.getSwitchDPID()); if (sw == null) return false; int inputPort = sw_tup.getPort(); log.debug("blockHost sw={} port={} mac={}", @@ -590,8 +590,8 @@ public abstract class ForwardingBase @Override public boolean isCallbackOrderingPrereq(OFType type, String name) { - return (type.equals(OFType.PACKET_IN) && - (name.equals("topology") || + return (type.equals(OFType.PACKET_IN) && + (name.equals("topology") || name.equals("devicemanager"))); } diff --git a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java index ee394ef9af49de7d2163e586558ba6188e807a41..5f911b88bf68be1ad8925139764a91ba0fd0749f 100644 --- a/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java +++ b/src/main/java/net/floodlightcontroller/staticflowentry/StaticFlowEntryPusher.java @@ -465,7 +465,7 @@ public class StaticFlowEntryPusher "static flow to a switch", recommendation=LogMessageDoc.CHECK_SWITCH) private void writeOFMessagesToSwitch(long dpid, List<OFMessage> messages) { - IOFSwitch ofswitch = floodlightProvider.getSwitches().get(dpid); + IOFSwitch ofswitch = floodlightProvider.getSwitch(dpid); if (ofswitch != null) { // is the switch connected try { if (log.isDebugEnabled()) { @@ -490,7 +490,7 @@ public class StaticFlowEntryPusher "static flow to a switch", recommendation=LogMessageDoc.CHECK_SWITCH) private void writeOFMessageToSwitch(long dpid, OFMessage message) { - IOFSwitch ofswitch = floodlightProvider.getSwitches().get(dpid); + IOFSwitch ofswitch = floodlightProvider.getSwitch(dpid); if (ofswitch != null) { // is the switch connected try { if (log.isDebugEnabled()) { @@ -511,8 +511,7 @@ public class StaticFlowEntryPusher * @param flowMod The OFFlowMod to write */ private void writeFlowModToSwitch(long dpid, OFFlowMod flowMod) { - Map<Long,IOFSwitch> switches = floodlightProvider.getSwitches(); - IOFSwitch ofSwitch = switches.get(dpid); + IOFSwitch ofSwitch = floodlightProvider.getSwitch(dpid); if (ofSwitch == null) { if (log.isDebugEnabled()) { log.debug("Not deleting key {} :: switch {} not connected", @@ -752,7 +751,7 @@ public class StaticFlowEntryPusher if (log.isDebugEnabled()) log.debug("Deleting all static flows on switch {}", HexString.toHexString(dpid)); - IOFSwitch sw = floodlightProvider.getSwitches().get(dpid); + IOFSwitch sw = floodlightProvider.getSwitch(dpid); if (sw == null) { log.warn("Tried to delete static flows for non-existant switch {}", HexString.toHexString(dpid)); diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java index 148055c35d5f645921e3fe4f3c9869a5ddf20ef3..fb6be3ff41da748db6fb46b4c4e6567620a9a717 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java @@ -272,7 +272,7 @@ public class TopologyManager implements if ((port & 0xff00) == 0xff00 && port != (short)0xfffe) return false; // Make sure that the port is enabled. - IOFSwitch sw = floodlightProvider.getSwitches().get(switchid); + IOFSwitch sw = floodlightProvider.getSwitch(switchid); if (sw == null) return false; return (sw.portEnabled(port)); } @@ -919,7 +919,7 @@ public class TopologyManager implements } for(long sid: switches) { - IOFSwitch sw = floodlightProvider.getSwitches().get(sid); + IOFSwitch sw = floodlightProvider.getSwitch(sid); if (sw == null) continue; Collection<Short> enabledPorts = sw.getEnabledPortNumbers(); if (enabledPorts == null) @@ -1377,7 +1377,7 @@ public class TopologyManager implements @Override public Set<Short> getPorts(long sw) { Set<Short> ports = new HashSet<Short>(); - IOFSwitch iofSwitch = floodlightProvider.getSwitches().get(sw); + IOFSwitch iofSwitch = floodlightProvider.getSwitch(sw); if (iofSwitch == null) return null; Collection<Short> ofpList = iofSwitch.getEnabledPortNumbers(); diff --git a/src/main/java/net/floodlightcontroller/topology/web/EnabledPortsResource.java b/src/main/java/net/floodlightcontroller/topology/web/EnabledPortsResource.java index 22c520c3e9f62bbcd5f49198f737e214bf97505a..af1467a2d5544d47290ce879191455ab7263be2d 100644 --- a/src/main/java/net/floodlightcontroller/topology/web/EnabledPortsResource.java +++ b/src/main/java/net/floodlightcontroller/topology/web/EnabledPortsResource.java @@ -36,14 +36,14 @@ public class EnabledPortsResource extends ServerResource { (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); - ITopologyService topology= + ITopologyService topology= (ITopologyService)getContext().getAttributes(). get(ITopologyService.class.getCanonicalName()); if (floodlightProvider == null || topology == null) return result; - Set<Long> switches = floodlightProvider.getSwitches().keySet(); + Set<Long> switches = floodlightProvider.getAllSwitchDpids(); if (switches == null) return result; for(long sw: switches) { diff --git a/src/main/java/net/floodlightcontroller/topology/web/SwitchClustersResource.java b/src/main/java/net/floodlightcontroller/topology/web/SwitchClustersResource.java index f52d27a0735e936fc8425c4a30e58a3b43517d21..6ba1704967f6b9351fa0b4ea261f618966e23e60 100644 --- a/src/main/java/net/floodlightcontroller/topology/web/SwitchClustersResource.java +++ b/src/main/java/net/floodlightcontroller/topology/web/SwitchClustersResource.java @@ -1,7 +1,7 @@ /** -* Copyright 2011, Big Switch Networks, Inc. +* 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 @@ -21,10 +21,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import net.floodlightcontroller.core.IFloodlightProviderService; -import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.topology.ITopologyService; import org.openflow.util.HexString; @@ -38,10 +36,10 @@ import org.restlet.resource.ServerResource; public class SwitchClustersResource extends ServerResource { @Get("json") public Map<String, List<String>> retrieve() { - IFloodlightProviderService floodlightProvider = + IFloodlightProviderService floodlightProvider = (IFloodlightProviderService)getContext().getAttributes(). get(IFloodlightProviderService.class.getCanonicalName()); - ITopologyService topology = + ITopologyService topology = (ITopologyService)getContext().getAttributes(). get(ITopologyService.class.getCanonicalName()); @@ -51,19 +49,19 @@ public class SwitchClustersResource extends ServerResource { if (queryType != null && "l2".equals(queryType)) { openflowDomain = false; } - + Map<String, List<String>> switchClusterMap = new HashMap<String, List<String>>(); - for (Entry<Long, IOFSwitch> entry : floodlightProvider.getSwitches().entrySet()) { - Long clusterDpid = + for (Long dpid: floodlightProvider.getAllSwitchDpids()) { + Long clusterDpid = (openflowDomain - ? topology.getOpenflowDomainId(entry.getValue().getId()) - :topology.getL2DomainId(entry.getValue().getId())); + ? topology.getOpenflowDomainId(dpid) + :topology.getL2DomainId(dpid)); List<String> switchesInCluster = switchClusterMap.get(HexString.toHexString(clusterDpid)); if (switchesInCluster != null) { - switchesInCluster.add(HexString.toHexString(entry.getKey())); + switchesInCluster.add(HexString.toHexString(dpid)); } else { List<String> l = new ArrayList<String>(); - l.add(HexString.toHexString(entry.getKey())); + l.add(HexString.toHexString(dpid)); switchClusterMap.put(HexString.toHexString(clusterDpid), l); } } diff --git a/src/main/java/org/openflow/protocol/statistics/OFDescriptionStatistics.java b/src/main/java/org/openflow/protocol/statistics/OFDescriptionStatistics.java index 86ad782d8b56a4dff1be90e6f3af503b282adb87..b2e334ff20719e900db01783835caf74942db9ee 100644 --- a/src/main/java/org/openflow/protocol/statistics/OFDescriptionStatistics.java +++ b/src/main/java/org/openflow/protocol/statistics/OFDescriptionStatistics.java @@ -1,7 +1,7 @@ /** * Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior * 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 @@ -35,6 +35,24 @@ public class OFDescriptionStatistics implements OFStatistics { protected String serialNumber; protected String datapathDescription; + + /** + * + */ + public OFDescriptionStatistics() { + } + + /** + * Copy constructor + */ + public OFDescriptionStatistics(OFDescriptionStatistics other) { + manufacturerDescription = other.manufacturerDescription; + hardwareDescription = other.hardwareDescription; + softwareDescription = other.softwareDescription; + serialNumber = other.serialNumber; + datapathDescription = other.datapathDescription; + } + /** * @return the manufacturerDescription */ diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index 20dc55d0e7b0ce746a6f987176f531f8a2644b09..eb629d7c591a1a04732cc35ca147bdbad8a4b117 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -326,15 +326,25 @@ public class ControllerTest extends FloodlightTestCase { @Test public void testAddSwitchWithExistingSwitch() throws Exception { - controller.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); + // Setup: add a switch to the controller IOFSwitch oldsw = createMock(IOFSwitch.class); expect(oldsw.getId()).andReturn(0L).anyTimes(); + replay(oldsw); + controller.addSwitch(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(); - controller.activeSwitches.put(0L, oldsw); IOFSwitch newsw = createMock(IOFSwitch.class); @@ -356,7 +366,7 @@ public class ControllerTest extends FloodlightTestCase { controller.addSwitch(newsw); verify(newsw, oldsw); - assertEquals(newsw, controller.activeSwitches.get(0L)); + assertEquals(newsw, controller.getSwitch(0L)); controller.processUpdateQueueForTesting(); verify(listener); } @@ -364,8 +374,6 @@ public class ControllerTest extends FloodlightTestCase { @Test public void testSwitchActivatedNoClearFM() throws Exception { - controller.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); - IOFSwitch sw = createMock(IOFSwitch.class); expect(sw.getId()).andReturn(0L).anyTimes(); expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes(); @@ -379,14 +387,13 @@ public class ControllerTest extends FloodlightTestCase { replay(sw); controller.switchActivated(sw); verify(sw); - assertEquals(sw, controller.activeSwitches.get(0L)); + assertEquals(sw, controller.getSwitch(0L)); controller.processUpdateQueueForTesting(); verify(listener); } @Test public void testSwitchActivatedClearFM() throws Exception { - controller.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); controller.setAlwaysClearFlowsOnSwAdd(true); IOFSwitch sw = createMock(IOFSwitch.class); @@ -404,7 +411,7 @@ public class ControllerTest extends FloodlightTestCase { replay(sw); controller.switchActivated(sw); verify(sw); - assertEquals(sw, controller.activeSwitches.get(0L)); + assertEquals(sw, controller.getSwitch(0L)); controller.processUpdateQueueForTesting(); verify(listener); } @@ -428,16 +435,12 @@ public class ControllerTest extends FloodlightTestCase { @Test public void testRemoveActiveSwitch() { IOFSwitch sw = createNiceMock(IOFSwitch.class); - boolean exceptionThrown = false; expect(sw.getId()).andReturn(1L).anyTimes(); replay(sw); - getController().activeSwitches.put(sw.getId(), sw); - try { - getController().getSwitches().remove(1L); - } catch (UnsupportedOperationException e) { - exceptionThrown = true; - } - assertTrue(exceptionThrown); + getController().addSwitch(sw); + assertEquals(sw, getController().getSwitch(1L)); + getController().getAllSwitchMap().remove(1L); + assertEquals(sw, getController().getSwitch(1L)); verify(sw); } diff --git a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java index bc6ccf7c9bb4e6f0aa20de9728954e5a750e38a1..5ae3eb8138983e15151ce72c20ab87e870fd3f19 100644 --- a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java +++ b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Set; +import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; @@ -121,8 +123,20 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro } @Override - public Map<Long, IOFSwitch> getSwitches() { - return this.switches; + public Map<Long,IOFSwitch> getAllSwitchMap() { + return Collections.unmodifiableMap(this.switches); + } + + @Override + public Set<Long> getAllSwitchDpids() { + // the contract for getAllSwitchDpids says the caller will own the + // returned set + return new HashSet<Long>(this.switches.keySet()); + } + + @Override + public IOFSwitch getSwitch(long dpid) { + return this.switches.get(dpid); } public void setSwitches(Map<Long, IOFSwitch> switches) { diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java index 2efb2cd5c684dd7a18888a9f3f8281bd7f1689aa..8ae1320f49fc75c7edde47e865c57ca79060da56 100644 --- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java +++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java @@ -974,7 +974,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { DefaultEntityClassifier.entityClass); // Get the listener and trigger the packet in - IOFSwitch switch1 = mockFloodlightProvider.getSwitches().get(1L); + IOFSwitch switch1 = mockFloodlightProvider.getSwitch(1L); mockFloodlightProvider.dispatchMessage(switch1, packetIn); // Verify the replay matched our expectations @@ -1031,7 +1031,7 @@ public class DeviceManagerImplTest extends FloodlightTestCase { // Start recording the replay on the mocks replay(mockTopology); // Get the listener and trigger the packet in - IOFSwitch switch5 = mockFloodlightProvider.getSwitches().get(5L); + IOFSwitch switch5 = mockFloodlightProvider.getSwitch(5L); mockFloodlightProvider. dispatchMessage(switch5, this.packetIn_1.setInPort((short)2)); diff --git a/src/test/java/net/floodlightcontroller/flowcache/PortDownReconciliationTest.java b/src/test/java/net/floodlightcontroller/flowcache/PortDownReconciliationTest.java index 8407ee3605e1ac650903c87a9c9e012adf29a027..9eb15be4fe2e86b199d2883ebbc2cc8ffe94c1be 100644 --- a/src/test/java/net/floodlightcontroller/flowcache/PortDownReconciliationTest.java +++ b/src/test/java/net/floodlightcontroller/flowcache/PortDownReconciliationTest.java @@ -180,7 +180,7 @@ public class PortDownReconciliationTest extends FloodlightTestCase { sw1 = EasyMock.createNiceMock(IOFSwitch.class); // Expect that the switch's ID is 1 expect(sw1.getId()).andReturn(1L).anyTimes(); - expect(sw1.getStatistics(req)).andReturn(results).once(); + expect(sw1.queryStatistics(req)).andReturn(results).once(); // Captures to hold resulting flowmod delete messages wc1 = new Capture<List<OFMessage>>(CaptureType.ALL); bc1 = new Capture<FloodlightContext>(CaptureType.ALL); @@ -193,7 +193,7 @@ public class PortDownReconciliationTest extends FloodlightTestCase { sw2 = EasyMock.createNiceMock(IOFSwitch.class); // Expect that the switch's ID is 2 expect(sw2.getId()).andReturn(2L).anyTimes(); - expect(sw2.getStatistics(req)).andReturn(results).once(); + expect(sw2.queryStatistics(req)).andReturn(results).once(); wc2 = new Capture<List<OFMessage>>(CaptureType.ALL); bc2 = new Capture<FloodlightContext>(CaptureType.ALL); // Capture the parameters passwed when sw1.write is invoked @@ -205,7 +205,7 @@ public class PortDownReconciliationTest extends FloodlightTestCase { sw3 = EasyMock.createNiceMock(IOFSwitch.class); // Expect that the switch's ID is 3 expect(sw3.getId()).andReturn(3L).anyTimes(); - expect(sw3.getStatistics(req)).andReturn(results).once(); + expect(sw3.queryStatistics(req)).andReturn(results).once(); wc3 = new Capture<List<OFMessage>>(CaptureType.ALL); bc3 = new Capture<FloodlightContext>(CaptureType.ALL); // Capture the parameters passwed when sw1.write is invoked @@ -217,7 +217,7 @@ public class PortDownReconciliationTest extends FloodlightTestCase { sw4 = EasyMock.createNiceMock(IOFSwitch.class); // Expect that the switch's ID is 4 expect(sw4.getId()).andReturn(4L).anyTimes(); - expect(sw4.getStatistics(req)).andReturn(results).once(); + expect(sw4.queryStatistics(req)).andReturn(results).once(); wc4 = new Capture<List<OFMessage>>(CaptureType.ALL); bc4 = new Capture<FloodlightContext>(CaptureType.ALL); // Capture the parameters passed when sw1.write is invoked diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java index 89e5420d21cc1676503488220c4ed45f2703e9aa..433b930be6c3b16973f14b02c7c714da47605529 100644 --- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java +++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java @@ -246,8 +246,8 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase { 0, 0); linkDiscovery.addOrUpdateLink(lt, info); - IOFSwitch sw1 = getMockFloodlightProvider().getSwitches().get(1L); - IOFSwitch sw2 = getMockFloodlightProvider().getSwitches().get(2L); + IOFSwitch sw1 = getMockFloodlightProvider().getSwitch(1L); + IOFSwitch sw2 = getMockFloodlightProvider().getSwitch(2L); // Mock up our expected behavior linkDiscovery.removedSwitch(sw1); verify(sw1, sw2); diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java index 113ff26fbbe50dbecad3e79ef0903c28f373242b..441f04650325976660161e6a51b200a4d71a06be 100644 --- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java +++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java @@ -44,54 +44,54 @@ import org.openflow.protocol.statistics.OFStatistics; /** * A mock implementation of IFOSwitch we use for {@link OFMessageDamper} - * + * * We need to mock equals() and hashCode() but alas, EasyMock doesn't support * this. Sigh. And of course this happens to be the interface with the most - * methods. + * methods. * @author gregor * */ public class OFMessageDamperMockSwitch implements IOFSwitch { OFMessage writtenMessage; FloodlightContext writtenContext; - + public OFMessageDamperMockSwitch() { reset(); } - + /* reset this mock. I.e., clear the stored message previously written */ public void reset() { writtenMessage = null; writtenContext = null; } - - /* assert that a message was written to this switch and that the - * written message and context matches the expected values + + /* assert that a message was written to this switch and that the + * written message and context matches the expected values * @param expected * @param expectedContext */ - public void assertMessageWasWritten(OFMessage expected, + public void assertMessageWasWritten(OFMessage expected, FloodlightContext expectedContext) { assertNotNull("No OFMessage was written", writtenMessage); assertEquals(expected, writtenMessage); assertEquals(expectedContext, writtenContext); } - + /* - * assert that no message was written + * assert that no message was written */ public void assertNoMessageWritten() { - assertNull("OFMessage was written but didn't expect one", + assertNull("OFMessage was written but didn't expect one", writtenMessage); - assertNull("There was a context but didn't expect one", + assertNull("There was a context but didn't expect one", writtenContext); } - + /* * use hashCode() and equals() from Object */ - - + + //------------------------------------------------------- // IOFSwitch: mocked methods @Override @@ -107,7 +107,7 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { throws IOException { write(msg, cntx); } - + //------------------------------------------------------- // IOFSwitch: not-implemented methods @@ -118,212 +118,212 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { } @Override - public void write(List<OFMessage> msglist, FloodlightContext bc) + public void write(List<OFMessage> msglist, FloodlightContext bc) throws IOException { assertTrue("Unexpected method call", false); } - + @Override public void disconnectOutputStream() { assertTrue("Unexpected method call", false); } - + @Override public void setFeaturesReply(OFFeaturesReply featuresReply) { assertTrue("Unexpected method call", false); } - + @Override public void setSwitchProperties(OFDescriptionStatistics description) { assertTrue("Unexpected method call", false); // TODO Auto-generated method stub } - + @Override public Collection<OFPhysicalPort> getEnabledPorts() { assertTrue("Unexpected method call", false); return null; } - + @Override public Collection<Short> getEnabledPortNumbers() { assertTrue("Unexpected method call", false); return null; } - + @Override public OFPhysicalPort getPort(short portNumber) { assertTrue("Unexpected method call", false); return null; } - + @Override public OFPhysicalPort getPort(String portName) { assertTrue("Unexpected method call", false); return null; } - + @Override public void setPort(OFPhysicalPort port) { assertTrue("Unexpected method call", false); } - + @Override public void deletePort(short portNumber) { assertTrue("Unexpected method call", false); } - + @Override public void deletePort(String portName) { assertTrue("Unexpected method call", false); } - + @Override public Collection<OFPhysicalPort> getPorts() { assertTrue("Unexpected method call", false); return null; } - + @Override public boolean portEnabled(short portName) { assertTrue("Unexpected method call", false); return false; } - + @Override public boolean portEnabled(String portName) { assertTrue("Unexpected method call", false); return false; } - + @Override public boolean portEnabled(OFPhysicalPort port) { assertTrue("Unexpected method call", false); return false; } - + @Override public long getId() { assertTrue("Unexpected method call", false); return 0; } - + @Override public String getStringId() { assertTrue("Unexpected method call", false); return null; } - + @Override public SocketAddress getInetAddress() { assertTrue("Unexpected method call", false); return null; } - + @Override public Map<Object, Object> getAttributes() { assertTrue("Unexpected method call", false); return null; } - + @Override public String getConnectedSince() { assertTrue("Unexpected method call", false); return null; } - + @Override public int getNextTransactionId() { assertTrue("Unexpected method call", false); return 0; } - + @Override public Future<List<OFStatistics>> - getStatistics(OFStatisticsRequest request) throws IOException { + queryStatistics(OFStatisticsRequest request) throws IOException { assertTrue("Unexpected method call", false); return null; } - + @Override public boolean isConnected() { assertTrue("Unexpected method call", false); return false; } - + @Override public void setConnected(boolean connected) { assertTrue("Unexpected method call", false); } - + @Override public Role getHARole() { assertTrue("Unexpected method call", false); return null; } - + @Override public void deliverStatisticsReply(OFMessage reply) { assertTrue("Unexpected method call", false); } - + @Override public void cancelStatisticsReply(int transactionId) { assertTrue("Unexpected method call", false); } - + @Override public void cancelAllStatisticsReplies() { assertTrue("Unexpected method call", false); } - + @Override public boolean hasAttribute(String name) { assertTrue("Unexpected method call", false); return false; } - + @Override public Object getAttribute(String name) { assertTrue("Unexpected method call", false); return null; } - + @Override public void setAttribute(String name, Object value) { assertTrue("Unexpected method call", false); } - + @Override public Object removeAttribute(String name) { assertTrue("Unexpected method call", false); return null; } - + @Override public void clearAllFlowMods() { assertTrue("Unexpected method call", false); } - + @Override public boolean updateBroadcastCache(Long entry, Short port) { assertTrue("Unexpected method call", false); return false; } - + @Override public Map<Short, Long> getPortBroadcastHits() { assertTrue("Unexpected method call", false); return null; } - + @Override public void sendStatsQuery(OFStatisticsRequest request, int xid, IOFMessageListener caller) throws IOException { assertTrue("Unexpected method call", false); } - + @Override public void flush() { assertTrue("Unexpected method call", false); @@ -375,19 +375,19 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { @Override public void setChannel(Channel channel) { // TODO Auto-generated method stub - + } @Override public void setFloodlightProvider(Controller controller) { // TODO Auto-generated method stub - + } @Override public void setThreadPoolService(IThreadPoolService threadPool) { // TODO Auto-generated method stub - + } @Override @@ -405,7 +405,7 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { @Override public void setHARole(Role role) { // TODO Auto-generated method stub - + } @Override @@ -432,4 +432,10 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { return false; } + @Override + public OFDescriptionStatistics getDescriptionStatistics() { + fail("Unexpected method call"); + return null; + } + }