Skip to content
Snippets Groups Projects
Commit 96f2ede6 authored by Ryan Izard's avatar Ryan Izard
Browse files

Changed methodology after realizing the counters are already defined in...

Changed methodology after realizing the counters are already defined in OFConnectionCounters, which makes more sense since switches can have multiple connections now. OFConnectionCounters now refactored to remove counters when a switch disconnects.
parent bf16fa2d
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
......@@ -186,6 +186,7 @@ public class OFConnection implements IOFConnection, IOFConnectionBackend{
@Override
public void disconnect() {
this.channel.disconnect();
this.counters.uninstallCounters();
}
@Override
......
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
......
......@@ -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;
}
}
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment