diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitchBackend.java b/src/main/java/net/floodlightcontroller/core/IOFSwitchBackend.java index 045b8035a28083ae0f3b35cec0e649a874d0b3b7..75685c19a480c0bb4cb90bef48caa65d46023223 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitchBackend.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitchBackend.java @@ -27,7 +27,6 @@ import org.projectfloodlight.openflow.protocol.OFPortDesc; import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; import org.projectfloodlight.openflow.protocol.OFPortStatus; -import net.floodlightcontroller.core.internal.SwitchCounters; import net.floodlightcontroller.util.OrderedCollection; /** @@ -183,13 +182,4 @@ public interface IOFSwitchBackend extends IOFSwitch { * @return true if another viable master exists */ boolean hasAnotherMaster(); - - /** - * Retrieve the SwitchCounters from the switch. - * This is in IOFSwitchBackend as opposed to IOFSwitch to prevent - * modules from easily getting and messing with the counters. - * @return SwitchCounters - */ - SwitchCounters getCounters(); - } diff --git a/src/main/java/net/floodlightcontroller/core/OFConnection.java b/src/main/java/net/floodlightcontroller/core/OFConnection.java index e53c7dfd0c2c61eefd7d8e98f95d599da701d092..67d9953038be2627121be3b67c1fb3d111fe1b52 100644 --- a/src/main/java/net/floodlightcontroller/core/OFConnection.java +++ b/src/main/java/net/floodlightcontroller/core/OFConnection.java @@ -186,6 +186,7 @@ public class OFConnection implements IOFConnection, IOFConnectionBackend{ @Override public void disconnect() { this.channel.disconnect(); + this.counters.uninstallCounters(); } @Override diff --git a/src/main/java/net/floodlightcontroller/core/OFConnectionCounters.java b/src/main/java/net/floodlightcontroller/core/OFConnectionCounters.java index 403fb4bbda1c3bd0ec87c8423df624e45b69ab96..b88d55c29f0847ac3ea15b02060eab6dc15152ee 100644 --- a/src/main/java/net/floodlightcontroller/core/OFConnectionCounters.java +++ b/src/main/java/net/floodlightcontroller/core/OFConnectionCounters.java @@ -1,7 +1,9 @@ package net.floodlightcontroller.core; +import net.floodlightcontroller.core.internal.OFSwitchManager; import net.floodlightcontroller.debugcounter.IDebugCounter; import net.floodlightcontroller.debugcounter.IDebugCounterService; + import org.projectfloodlight.openflow.protocol.OFMessage; import org.projectfloodlight.openflow.protocol.OFType; import org.projectfloodlight.openflow.types.DatapathId; @@ -16,8 +18,9 @@ import org.slf4j.LoggerFactory; * @author Alok Shankar <alok@bigswitch.com> */ public class OFConnectionCounters { - public static final String COUNTER_MODULE = OFConnectionCounters.class.getPackage().getName(); - + public static final String COUNTER_MODULE = OFSwitchManager.class.getSimpleName(); + private static String dpidAndConnIdString; + private static IDebugCounterService debugCounterService; /** * Counters for open flow message types */ @@ -118,7 +121,10 @@ public class OFConnectionCounters { Preconditions.checkNotNull(auxId, "auxid must not be null"); String stringId = dpid.toString() +":" + auxId.toString(); + dpidAndConnIdString = stringId; String hierarchy = "/write"; + + debugCounterService = counters; // every level of the hierarchical counter has to be registered // even if they are not used @@ -441,6 +447,16 @@ public class OFConnectionCounters { stringId, OFType.TABLE_MOD.toString()); } + + /** + * Remove all counters from the IDebugCounterService. Should be done + * if the switch connection disconnects from the controller, in which case all + * the counters will be invalid. + * @return true if successful; false if counter hierarchy was not found + */ + public boolean uninstallCounters() { + return debugCounterService.removeCounterHierarchy(COUNTER_MODULE, dpidAndConnIdString); + } /** * Update Write Counters for Open flow messages diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitch.java b/src/main/java/net/floodlightcontroller/core/OFSwitch.java index 227ee3b1e654a1de2e640618917a8b9a57a6f11f..a184f8a0d380477b80afe33058e5b661fe310bb5 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitch.java @@ -39,7 +39,6 @@ import javax.annotation.Nonnull; import net.floodlightcontroller.core.annotations.LogMessageDoc; import net.floodlightcontroller.core.internal.IOFSwitchManager; -import net.floodlightcontroller.core.internal.SwitchCounters; import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.core.util.URIUtil; import net.floodlightcontroller.debugcounter.IDebugCounterService; @@ -115,8 +114,6 @@ public class OFSwitch implements IOFSwitchBackend { protected SwitchDescription description; - protected SwitchCounters counters; - private SwitchStatus status; public static final int OFSWITCH_APP_ID = ident(5); @@ -145,7 +142,6 @@ public class OFSwitch implements IOFSwitchBackend { this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; - this.counters = new SwitchCounters(debugCounterService, datapathId); // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); @@ -1108,18 +1104,4 @@ public class OFSwitch implements IOFSwitchBackend { } return false; } - - @Override - /** - * Retrieve the counters for incrementing and clearing. User modules - * should not have access to this method, nor should use it. The counters - * will be kept by the controller core. This method should only be used - * by "authorized" modules to perform bookkeeping. Unfortunately, this - * needs to be exposed to allow the Controller access to counters. - * If only there were a "friend" C++ equivalent in Java... - * @return the counters to be incremented or cleared. - */ - public SwitchCounters getCounters() { - return counters; - } } diff --git a/src/main/java/net/floodlightcontroller/core/internal/SwitchCounters.java b/src/main/java/net/floodlightcontroller/core/internal/SwitchCounters.java deleted file mode 100644 index a75751570a3477f1b082dce41afff1cc6fbdf594..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/internal/SwitchCounters.java +++ /dev/null @@ -1,109 +0,0 @@ -package net.floodlightcontroller.core.internal; - -import org.projectfloodlight.openflow.types.DatapathId; - -import net.floodlightcontroller.debugcounter.IDebugCounter; -import net.floodlightcontroller.debugcounter.IDebugCounterService; - -public class SwitchCounters { - - public final String moduleName = OFSwitchManager.class.getSimpleName(); - private IDebugCounterService debugCounterService; - private String dpidString; - public final IDebugCounter deviceAdded; - public final IDebugCounter deviceRemoved; - public final IDebugCounter portEnabled; - public final IDebugCounter portDisabled; - public final IDebugCounter portUp; - public final IDebugCounter portDown; - public final IDebugCounter packetIn; - public final IDebugCounter packetOut; - public final IDebugCounter flowAdded; - public final IDebugCounter flowRemoved; - - /** - * Maintains counters for a connected switch. The OFSwitchManager should be - * registered with the IDebugCounterService prior to adding a particular - * switch's counters. All switch counters will be housed under the umbrella - * of the OFSwitchManagerModule, where each switch's counters can be accessed - * by the DPID of that switch followed by the hierarchy of the counter: - * ofswitchmanagerservice/00:11:22:33:44:55:66:77/device-added - * ofswitchmanagerservice/88:99:AA:BB:CC:DD:EE:FF/port-down - * - * @param debugCounters - * @param dpid - */ - public SwitchCounters(IDebugCounterService debugCounters, DatapathId dpid) { - debugCounterService = debugCounters; - dpidString = dpid.toString(); - - /* Register the switch itself, although it's not a counter technically. - * An exception will be thrown if a sub-counter of the DPID is registered - * prior to the DPID itself. - */ - debugCounters.registerCounter(moduleName, dpidString, "Switch DPID base for counters"); - - deviceAdded = - debugCounters.registerCounter( - moduleName, dpidString + "/device-added", - "Device added to switch"); - - deviceRemoved = - debugCounters.registerCounter( - moduleName, dpidString + "/device-removed", - "Device removed from switch"); - - portEnabled = - debugCounters.registerCounter( - moduleName, dpidString + "/port-enabled", - "Port enabled on switch"); - - portDisabled = - debugCounters.registerCounter( - moduleName, dpidString + "/port-disabled", - "Port disabled on switch"); - - portUp = - debugCounters.registerCounter( - moduleName, dpidString + "/port-up", - "Port up on switch; device connected"); - - portDown = - debugCounters.registerCounter( - moduleName, dpidString + "/port-down", - "Port down on switch; device disconnected"); - - packetIn = - debugCounters.registerCounter( - moduleName, dpidString + "/packet-in", - "Packet in from switch"); - - packetOut = - debugCounters.registerCounter( - moduleName, dpidString + "/packet-out", - "Packet out to switch"); - - flowAdded = - debugCounters.registerCounter( - moduleName, dpidString + "/flow-added", - "Flow added to switch"); - flowRemoved = - debugCounters.registerCounter( - moduleName, dpidString + "/flow-removed", - "Flow removed from switch"); - } - - public String getPrefix(){ - return this.moduleName; - } - - /** - * Remove all counters from the IDebugCounterService. Should be done - * if the switch disconnects from the controller, in which case all - * the counters will be invalid. - * @return true if successful; false if switch was not found - */ - public boolean uninstallCounters() { - return debugCounterService.removeCounterHierarchy(moduleName, dpidString); - } -}