diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index e24973754c39c7d7db9849dc52b92885302c2cf1..e07e5781f6f9576adbae8defc0c6a6daf9444e48 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -28,6 +28,7 @@ import java.util.concurrent.locks.Lock; import net.floodlightcontroller.core.IFloodlightProviderService.Role; import net.floodlightcontroller.core.internal.Controller; +import net.floodlightcontroller.debugcounter.IDebugCounterService; import net.floodlightcontroller.threadpool.IThreadPoolService; import org.jboss.netty.channel.Channel; @@ -101,6 +102,13 @@ public interface IOFSwitch { */ public void setThreadPoolService(IThreadPoolService threadPool); + /** + * Set debug counter service for per-switch counters + * Called immediately after instantiation + * @param debugCounters + */ + public void setDebugCounterService(IDebugCounterService debugCounters); + /** * Set the netty Channel this switch instance is associated with * Called immediately after instantiation diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index 07005132d5fb5b33704ca04e3525c0dabbb45d69..053988d8d08f1f764f5e7f28a18631a2ed162ea0 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -43,6 +43,9 @@ import net.floodlightcontroller.core.internal.OFFeaturesReplyFuture; import net.floodlightcontroller.core.internal.OFStatisticsFuture; import net.floodlightcontroller.core.util.AppCookie; import net.floodlightcontroller.core.web.serializers.DPIDSerializer; +import net.floodlightcontroller.debugcounter.IDebugCounterService; +import net.floodlightcontroller.debugcounter.IDebugCounterService.CounterType; +import net.floodlightcontroller.debugcounter.NullDebugCounter; import net.floodlightcontroller.devicemanager.SwitchPort; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.routing.ForwardingBase; @@ -84,6 +87,7 @@ public abstract class OFSwitchBase implements IOFSwitch { protected ConcurrentMap<Object, Object> attributes; protected IFloodlightProviderService floodlightProvider; protected IThreadPoolService threadPool; + protected IDebugCounterService debugCounters; protected Date connectedSince; /* Switch features from initial featuresReply */ @@ -137,6 +141,8 @@ public abstract class OFSwitchBase implements IOFSwitch { protected OFDescriptionStatistics description; + private boolean debugCountersRegistered; + protected final static ThreadLocal<Map<IOFSwitch,List<OFMessage>>> local_msg_buffer = new ThreadLocal<Map<IOFSwitch,List<OFMessage>>>() { @Override @@ -245,7 +251,7 @@ public abstract class OFSwitchBase implements IOFSwitch { write(m, bc); } else { // Let logback duplicate filtering take care of excessive logs - // TODO Convert to counter and events + debugCounters.updateCounter(stringId + "-writeDrops"); log.warn("Drop throttled OF message to switch {}", this); } } @@ -257,8 +263,9 @@ public abstract class OFSwitchBase implements IOFSwitch { write(msglist, bc); } else { // Let logback duplicate filtering take care of excessive logs - // TODO Convert to counter and events - log.warn("Drop throttled OF message to switch {}", this); + debugCounters.updateCounter(stringId + "-writeDrops", + msglist.size()); + log.warn("Drop throttled OF messages to switch {}", this); } } @@ -560,6 +567,12 @@ public abstract class OFSwitchBase implements IOFSwitch { this.threadPool = tp; } + @Override + @JsonIgnore + public void setDebugCounterService(IDebugCounterService debugCounters) { + this.debugCounters = debugCounters; + } + @JsonIgnore @Override public boolean isConnected() { @@ -860,7 +873,7 @@ public abstract class OFSwitchBase implements IOFSwitch { OFMatch match = new OFMatch(); match.loadFromPacket(pin.getPacketData(), pin.getInPort()); if (ofMatchCache.update(match)) { - // TODO keep stats for dropped packets + debugCounters.updateCounter(stringId + "-pktinDrops"); return true; } @@ -902,6 +915,23 @@ public abstract class OFSwitchBase implements IOFSwitch { messageCountUniqueOFMatch = 0; log.info("Packet in rate is {}, enable throttling on {}", currentRate, this); + registerOverloadCounters(); + } + + private void registerOverloadCounters() { + if (debugCountersRegistered) { + return; + } + if (debugCounters == null) { + log.error("Debug Counter Service not found"); + debugCounters = new NullDebugCounter(); + debugCountersRegistered = true; + return; + } + debugCounters.registerCounter(stringId + "-pktinDrops", + "Packet in throttle drop count", CounterType.ALWAYS_COUNT); + debugCounters.registerCounter(stringId + "-writeDrops", + "Switch write throttle drop count", CounterType.ALWAYS_COUNT); } /** diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index 3d281b09f29e0c5424de538280a02322fb75c398..77a08713681c8ade17a467e6727a0b3736f19829 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -1454,6 +1454,10 @@ public class Controller implements IFloodlightProviderService, this.debugCounters = debugCounter; } + IDebugCounterService getDebugCounter() { + return this.debugCounters; + } + void setSyncService(ISyncService syncService) { this.syncService = syncService; } diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java b/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java index 744c964fc1390f97f7d8246ed72cd539a24d3bad..e00216e8d355def1978ea6e1666e8b19945f7d92 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFChannelHandler.java @@ -568,6 +568,7 @@ class OFChannelHandler h.sw.setChannel(h.channel); h.sw.setFloodlightProvider(h.controller); h.sw.setThreadPoolService(h.controller.getThreadPoolService()); + h.sw.setDebugCounterService(h.controller.getDebugCounter()); h.sw.setFeaturesReply(h.featuresReply); h.readPropertyFromStorage(); log.info("Switch {} bound to class {}, writeThrottle={}," + diff --git a/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java b/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java index 5d15c008c8f579239c654d29d7d8db0ff4d7a1dc..e32b202911519263046db8f82616891f512da1ff 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java @@ -64,6 +64,7 @@ import static org.junit.Assert.*; public class OFChannelHandlerTest { private Controller controller; private IThreadPoolService threadPool; + private IDebugCounterService debugCounterService; private OFChannelHandler handler; private Channel channel; private ChannelHandlerContext ctx; @@ -119,7 +120,7 @@ public class OFChannelHandlerTest { // TODO: should mock IDebugCounterService and make sure // the expected counters are updated. - IDebugCounterService debugCounterService = new DebugCounter(); + debugCounterService = new DebugCounter(); Controller.Counters counters = new Controller.Counters(); counters.createCounters(debugCounterService); @@ -516,6 +517,8 @@ public class OFChannelHandlerTest { expectLastCall().once(); sw.setThreadPoolService(threadPool); expectLastCall().once(); + sw.setDebugCounterService(debugCounterService); + expectLastCall().once(); sw.setFeaturesReply(featuresReply); expectLastCall().once(); sw.setConnected(true); @@ -530,6 +533,8 @@ public class OFChannelHandlerTest { // mock controller reset(controller); + expect(controller.getDebugCounter()).andReturn(debugCounterService) + .once(); controller.flushAll(); expectLastCall().once(); expect(controller.getThreadPoolService()) diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java index 06c6a6ce9b81f5bf949074e208a8f370f9beac76..c32c4ba338808cf765e0eaef5933ce9bbe72953b 100644 --- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java +++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java @@ -32,6 +32,7 @@ import net.floodlightcontroller.core.IOFMessageListener; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IFloodlightProviderService.Role; import net.floodlightcontroller.core.internal.Controller; +import net.floodlightcontroller.debugcounter.IDebugCounterService; import net.floodlightcontroller.threadpool.IThreadPoolService; import org.jboss.netty.channel.Channel; @@ -463,4 +464,9 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { return false; } + @Override + public void setDebugCounterService(IDebugCounterService debugCounters) { + // TODO Auto-generated method stub + } + }