From 5b0933bb94a39e4da85d66a695ae80ab9c308930 Mon Sep 17 00:00:00 2001
From: Ryan Izard <rizard@g.clemson.edu>
Date: Fri, 10 Oct 2014 08:28:01 -0400
Subject: [PATCH] Fixed some more unit tests. In the process, discovered some
 errors in more overridden equals(). Also, discovered I had inadvertently
 commented out an important few lines the routing module uses to set the
 ingress port of flows used in the route. Those lines are now ported and use
 MatchUtils to copy the Match properly.

---
 .../net/floodlightcontroller/core/Main.java   |   2 -
 .../core/web/AllSwitchStatisticsResource.java |  13 +-
 .../core/web/SwitchResourceBase.java          |  11 +-
 .../devicemanager/SwitchPort.java             |   4 +-
 .../internal/AttachmentPoint.java             |   4 +-
 .../internal/DeviceIterator.java              |   4 +-
 .../learningswitch/LearningSwitch.java        |  46 ++--
 .../loadbalancer/LoadBalancer.java            |   3 +-
 .../routing/ForwardingBase.java               |   9 +-
 .../floodlightcontroller/routing/Link.java    |   8 +-
 .../topology/Cluster.java                     |   2 +-
 .../topology/NodePortTuple.java               |   4 +-
 .../resources/floodlightdefault.properties    |   1 -
 .../core/internal/RoleManagerTest.java        | 106 ----------
 .../debugevent/DebugEventTest.java            | 197 +++++++++++++++---
 .../debugevent/EventTest.java                 |  98 +++++----
 .../internal/DeviceManagerImplTest.java       |  12 ++
 .../firewall/FirewallTest.java                |   1 -
 .../forwarding/ForwardingTest.java            |  13 +-
 .../learningswitch/LearningSwitchTest.java    |   8 +-
 .../internal/LinkDiscoveryManagerTest.java    |  26 ++-
 .../loadbalancer/LoadBalancerTest.java        |  21 +-
 .../staticflowentry/StaticFlowTests.java      |  11 +-
 .../topology/TopologyInstanceTest.java        |   6 +
 .../topology/TopologyManagerTest.java         |  62 +++---
 .../VirtualNetworkFilterTest.java             |   9 +-
 .../sdnplatform/sync/client/ClientTest.java   |  10 +
 .../sync/internal/BootstrapTest.java          |   7 +
 .../sync/internal/SyncManagerTest.java        |   7 +
 .../sync/internal/store/RemoteStoreTest.java  |   7 +
 30 files changed, 431 insertions(+), 281 deletions(-)

diff --git a/src/main/java/net/floodlightcontroller/core/Main.java b/src/main/java/net/floodlightcontroller/core/Main.java
index 0bda3c0c5..c437a9347 100644
--- a/src/main/java/net/floodlightcontroller/core/Main.java
+++ b/src/main/java/net/floodlightcontroller/core/Main.java
@@ -59,8 +59,6 @@ public class Main {
 			FloodlightModuleLoader fml = new FloodlightModuleLoader();
 			try {
 				IFloodlightModuleContext moduleContext = fml.loadModulesFromConfig(settings.getModuleFile());
-				// @Ryan TODO This should probably be implemented and run as a normal service for consistency;
-				// although, it does need all modules to be loaded and their prior to running.
 				IRestApiService restApi = moduleContext.getServiceImpl(IRestApiService.class);
 				restApi.run(); 
 			} catch (FloodlightModuleConfigFileNotFoundException e) {
diff --git a/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java b/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java
index 72e7698b3..18bfcc3c0 100644
--- a/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java
+++ b/src/main/java/net/floodlightcontroller/core/web/AllSwitchStatisticsResource.java
@@ -41,14 +41,15 @@ import org.slf4j.LoggerFactory;
 public class AllSwitchStatisticsResource extends SwitchResourceBase {
     protected static Logger log =
         LoggerFactory.getLogger(AllSwitchStatisticsResource.class);
-
+    
     @Get("json")
     public Map<String, Object> retrieve() {
         String statType = (String) getRequestAttributes().get(CoreWebRoutable.STR_STAT_TYPE);
+        
         return retrieveInternal(statType);
     }
 
-    public Map<String, Object> retrieveInternal(String statType) {
+    private Map<String, Object> retrieveInternal(String statType) {
         HashMap<String, Object> model = new HashMap<String, Object>();
 
         OFStatsType type = null;
@@ -85,10 +86,10 @@ public class AllSwitchStatisticsResource extends SwitchResourceBase {
         default:
         	return model;
         }
-
-        IOFSwitchService switchService =
-                (IOFSwitchService) getContext().getAttributes().
-                    get(IOFSwitchService.class.getCanonicalName());
+                
+        IOFSwitchService switchService = (IOFSwitchService) getContext().getAttributes().
+                get(IOFSwitchService.class.getCanonicalName());
+        
         Set<DatapathId> switchDpids = switchService.getAllSwitchDpids();
         List<GetConcurrentStatsThread> activeThreads = new ArrayList<GetConcurrentStatsThread>(switchDpids.size());
         List<GetConcurrentStatsThread> pendingRemovalThreads = new ArrayList<GetConcurrentStatsThread>();
diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java b/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java
index 99b4d2d83..75e990835 100644
--- a/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java
+++ b/src/main/java/net/floodlightcontroller/core/web/SwitchResourceBase.java
@@ -61,6 +61,13 @@ public class SwitchResourceBase extends ServerResource {
 
 	}
 
+	/**
+	 * Use for requests that originate from the REST server that use their context to get a
+	 * reference to the switch service.
+	 * @param switchId
+	 * @param statType
+	 * @return
+	 */
 	@SuppressWarnings("unchecked")
 	@LogMessageDoc(level="ERROR",
 	message="Failure retrieving statistics from switch {switch}",
@@ -70,9 +77,7 @@ public class SwitchResourceBase extends ServerResource {
 					LogMessageDoc.GENERIC_ACTION)
 	protected List<OFStatsReply> getSwitchStatistics(DatapathId switchId,
 			OFStatsType statType) {
-		IOFSwitchService switchService =
-				(IOFSwitchService) getContext().getAttributes().
-				get(IOFSwitchService.class.getCanonicalName());
+		IOFSwitchService switchService = (IOFSwitchService) getContext().getAttributes().get(IOFSwitchService.class.getCanonicalName());
 
 		IOFSwitch sw = switchService.getSwitch(switchId);
 		ListenableFuture<?> future;
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java b/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java
index 8648e8901..abede26af 100644
--- a/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java
+++ b/src/main/java/net/floodlightcontroller/devicemanager/SwitchPort.java
@@ -128,8 +128,8 @@ public class SwitchPort {
         if (getClass() != obj.getClass()) return false;
         SwitchPort other = (SwitchPort) obj;
         if (errorStatus != other.errorStatus) return false;
-        if (port != other.port) return false;
-        if (switchDPID != other.switchDPID) return false;
+        if (!port.equals(other.port)) return false;
+        if (!switchDPID.equals(other.switchDPID)) return false;
         return true;
     }
 
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/AttachmentPoint.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/AttachmentPoint.java
index da7490f1e..122bb1d4a 100644
--- a/src/main/java/net/floodlightcontroller/devicemanager/internal/AttachmentPoint.java
+++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/AttachmentPoint.java
@@ -112,9 +112,9 @@ public class AttachmentPoint {
         if (getClass() != obj.getClass())
             return false;
         AttachmentPoint other = (AttachmentPoint) obj;
-        if (port.getPortNumber() != other.port.getPortNumber())
+        if (!port.equals(other.port))
             return false;
-        if (sw.getLong() != other.sw.getLong())
+        if (!sw.equals(other.sw))
             return false;
         return true;
     }
diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceIterator.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceIterator.java
index 7d4d0c35a..796a6170d 100644
--- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceIterator.java
+++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceIterator.java
@@ -120,11 +120,11 @@ public class DeviceIterator extends FilterIterator<Device> {
             match = false;
             for (SwitchPort sp : sps) {
                 if (switchDPID != null) {
-                    if (switchDPID.getLong() != sp.getSwitchDPID().getLong())
+                    if (!switchDPID.equals(sp.getSwitchDPID()))
                         return false;
                 }
                 if (switchPort != null) {
-                    if (switchPort.getPortNumber() != sp.getPort().getPortNumber())
+                    if (!switchPort.equals(sp.getPort()))
                         return false;
                 }
                 match = true;
diff --git a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java
index 7e347294c..288369cb5 100644
--- a/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java
+++ b/src/main/java/net/floodlightcontroller/learningswitch/LearningSwitch.java
@@ -390,10 +390,10 @@ public class LearningSwitch
      */
     private Command processPacketInMessage(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
         // Read in packet data headers by using OFMatch
-        Match.Builder mb = pi.getMatch().createBuilder();
-        MacAddress sourceMac = mb.get(MatchField.ETH_SRC);
-        MacAddress destMac = mb.get(MatchField.ETH_DST);
-        OFVlanVidMatch vlan = mb.get(MatchField.VLAN_VID);
+        Match m = pi.getMatch();
+        MacAddress sourceMac = m.get(MatchField.ETH_SRC);
+        MacAddress destMac = m.get(MatchField.ETH_DST);
+        OFVlanVidMatch vlan = m.get(MatchField.VLAN_VID);
         if ((destMac.getLong() & 0xfffffffffff0L) == 0x0180c2000000L) {
             if (log.isTraceEnabled()) {
                 log.trace("ignoring packet addressed to 802.1D/Q reserved addr: switch {} vlan {} dest MAC {}",
@@ -415,7 +415,7 @@ public class LearningSwitch
             //     from port map whenever a flow expires, so you would still see
             //     a lot of floods.
             this.writePacketOutForPacketIn(sw, pi, OFPort.FLOOD);
-        } else if (outPort.equals(mb.get(MatchField.IN_PORT))) {
+        } else if (outPort.equals(m.get(MatchField.IN_PORT))) {
             log.trace("ignoring packet that arrived on same port as learned destination:"
                     + " switch {} vlan {} dest MAC {} port {}",
                     new Object[]{ sw, vlan, destMac.toString(), outPort.getPortNumber() });
@@ -430,29 +430,29 @@ public class LearningSwitch
             // FIXME: current HP switches ignore DL_SRC and DL_DST fields, so we have to match on
             // NW_SRC and NW_DST as well
             // We write FlowMods with Buffer ID none then explicitly PacketOut the buffered packet
-            this.pushPacket(sw, mb.build(), pi, outPort);
-            this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, mb.build(), outPort);
+            this.pushPacket(sw, m, pi, outPort);
+            this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, m, outPort);
             if (LEARNING_SWITCH_REVERSE_FLOW) {
-            	Match.Builder mb2 = mb.build().createBuilder();
-            	mb2.setExact(MatchField.ETH_SRC, mb.get(MatchField.ETH_DST))                         
-            	.setExact(MatchField.ETH_DST, mb.get(MatchField.ETH_SRC))                         
-            	.setExact(MatchField.IPV4_SRC, mb.get(MatchField.IPV4_DST))                         
-            	.setExact(MatchField.IPV4_DST, mb.get(MatchField.IPV4_SRC));
-            	if (mb.get(MatchField.IP_PROTO).equals(IpProtocol.TCP)) {
-            		mb2.setExact(MatchField.TCP_SRC, mb.get(MatchField.TCP_DST))
-            		.setExact(MatchField.TCP_DST, mb.get(MatchField.TCP_SRC));
-            	} else if (mb.get(MatchField.IP_PROTO).equals(IpProtocol.UDP)) {
-            		mb2.setExact(MatchField.UDP_SRC, mb.get(MatchField.UDP_DST))
-            		.setExact(MatchField.UDP_DST, mb.get(MatchField.UDP_SRC));
-            	} else if (mb.get(MatchField.IP_PROTO).equals(IpProtocol.SCTP)) {
-            		mb2.setExact(MatchField.SCTP_SRC, mb.get(MatchField.SCTP_DST))
-            		.setExact(MatchField.SCTP_DST, mb.get(MatchField.SCTP_SRC));
+            	Match.Builder mb2 = m.createBuilder();
+            	mb2.setExact(MatchField.ETH_SRC, m.get(MatchField.ETH_DST))                         
+            	.setExact(MatchField.ETH_DST, m.get(MatchField.ETH_SRC))                         
+            	.setExact(MatchField.IPV4_SRC, m.get(MatchField.IPV4_DST))                         
+            	.setExact(MatchField.IPV4_DST, m.get(MatchField.IPV4_SRC));
+            	if (m.get(MatchField.IP_PROTO).equals(IpProtocol.TCP)) {
+            		mb2.setExact(MatchField.TCP_SRC, m.get(MatchField.TCP_DST))
+            		.setExact(MatchField.TCP_DST, m.get(MatchField.TCP_SRC));
+            	} else if (m.get(MatchField.IP_PROTO).equals(IpProtocol.UDP)) {
+            		mb2.setExact(MatchField.UDP_SRC, m.get(MatchField.UDP_DST))
+            		.setExact(MatchField.UDP_DST, m.get(MatchField.UDP_SRC));
+            	} else if (m.get(MatchField.IP_PROTO).equals(IpProtocol.SCTP)) {
+            		mb2.setExact(MatchField.SCTP_SRC, m.get(MatchField.SCTP_DST))
+            		.setExact(MatchField.SCTP_DST, m.get(MatchField.SCTP_SRC));
             	} else {
-            		log.debug("In writing reverse LS flow, could not determine L4 proto (was int " + mb.get(MatchField.IP_PROTO).getIpProtocolNumber() + ")");
+            		log.debug("In writing reverse LS flow, could not determine L4 proto (was int " + m.get(MatchField.IP_PROTO).getIpProtocolNumber() + ")");
             	}
             	mb2.setExact(MatchField.IN_PORT, outPort);
 
-            	this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, mb2.build(), mb.get(MatchField.IN_PORT));
+            	this.writeFlowMod(sw, OFFlowModCommand.ADD, OFBufferId.NO_BUFFER, mb2.build(), m.get(MatchField.IN_PORT));
             }
         }
         return Command.CONTINUE;
diff --git a/src/main/java/net/floodlightcontroller/loadbalancer/LoadBalancer.java b/src/main/java/net/floodlightcontroller/loadbalancer/LoadBalancer.java
index 1309a555b..79e31c67a 100644
--- a/src/main/java/net/floodlightcontroller/loadbalancer/LoadBalancer.java
+++ b/src/main/java/net/floodlightcontroller/loadbalancer/LoadBalancer.java
@@ -29,6 +29,7 @@ import java.util.Map;
 
 import org.projectfloodlight.openflow.protocol.OFFlowMod;
 import org.projectfloodlight.openflow.protocol.match.Match;
+import org.projectfloodlight.openflow.protocol.match.MatchField;
 import org.projectfloodlight.openflow.protocol.OFMessage;
 import org.projectfloodlight.openflow.protocol.OFPacketIn;
 import org.projectfloodlight.openflow.protocol.OFPacketOut;
@@ -289,7 +290,7 @@ public class LoadBalancer implements IFloodlightModule,
                         arpRequest.getSenderProtocolAddress()));
                 
         // push ARP reply out
-        pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ZERO, pi.getInPort(), cntx, true);
+        pushPacket(arpReply, sw, OFBufferId.NO_BUFFER, OFPort.ZERO, pi.getMatch().get(MatchField.IN_PORT), cntx, true);
         log.debug("proxy ARP reply pushed as {}", IPv4.fromIPv4Address(vips.get(vipId).address));
         
         return;
diff --git a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java
index 878db1c99..11e6909b9 100644
--- a/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java
+++ b/src/main/java/net/floodlightcontroller/routing/ForwardingBase.java
@@ -43,6 +43,7 @@ import net.floodlightcontroller.routing.IRoutingDecision;
 import net.floodlightcontroller.routing.Route;
 import net.floodlightcontroller.topology.ITopologyService;
 import net.floodlightcontroller.topology.NodePortTuple;
+import net.floodlightcontroller.util.MatchUtils;
 import net.floodlightcontroller.util.OFMessageDamper;
 import net.floodlightcontroller.util.TimedCache;
 
@@ -248,18 +249,18 @@ public abstract class ForwardingBase implements IOFMessageListener {
 			
 			OFActionOutput.Builder aob = sw.getOFFactory().actions().buildOutput();
 			List<OFAction> actions = new ArrayList<OFAction>();	
-			//Match.Builder mb = match.createBuilder();
+			Match.Builder mb = MatchUtils.createRetentiveBuilder(match);
 
 			// set input and output ports on the switch
 			OFPort outPort = switchPortList.get(indx).getPortId();
-			//OFPort inPort = switchPortList.get(indx - 1).getPortId();
-			//mb.setExact(MatchField.IN_PORT, inPort);
+			OFPort inPort = switchPortList.get(indx - 1).getPortId();
+			mb.setExact(MatchField.IN_PORT, inPort);
 			aob.setPort(outPort);
 			aob.setMaxLen(Integer.MAX_VALUE);
 			actions.add(aob.build());
 			
 			// compile
-			fmb.setMatch(match) //mb.build()
+			fmb.setMatch(mb.build()) // was match w/o modifying input port
 			.setActions(actions)
 			.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
 			.setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT)
diff --git a/src/main/java/net/floodlightcontroller/routing/Link.java b/src/main/java/net/floodlightcontroller/routing/Link.java
index a2f125f5a..3282bb676 100755
--- a/src/main/java/net/floodlightcontroller/routing/Link.java
+++ b/src/main/java/net/floodlightcontroller/routing/Link.java
@@ -100,13 +100,13 @@ public class Link implements Comparable<Link> {
         if (getClass() != obj.getClass())
             return false;
         Link other = (Link) obj;
-        if (dst != other.dst)
+        if (!dst.equals(other.dst))
             return false;
-        if (dstPort != other.dstPort)
+        if (!dstPort.equals(other.dstPort))
             return false;
-        if (src != other.src)
+        if (!src.equals(other.src))
             return false;
-        if (srcPort != other.srcPort)
+        if (!srcPort.equals(other.srcPort))
             return false;
         return true;
     }
diff --git a/src/main/java/net/floodlightcontroller/topology/Cluster.java b/src/main/java/net/floodlightcontroller/topology/Cluster.java
index f896410fd..a9be8a36c 100644
--- a/src/main/java/net/floodlightcontroller/topology/Cluster.java
+++ b/src/main/java/net/floodlightcontroller/topology/Cluster.java
@@ -81,7 +81,7 @@ public class Cluster {
             return false;
 
         Cluster other = (Cluster) obj;
-        return (this.id == other.id);
+        return (this.id.equals(other.id));
     }
     
     public String toString() {
diff --git a/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java b/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java
index 758e50a92..6fbf87f4a 100644
--- a/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java
+++ b/src/main/java/net/floodlightcontroller/topology/NodePortTuple.java
@@ -83,9 +83,9 @@ public class NodePortTuple implements Comparable<NodePortTuple> {
         if (getClass() != obj.getClass())
             return false;
         NodePortTuple other = (NodePortTuple) obj;
-        if (nodeId != other.nodeId)
+        if (!nodeId.equals(other.nodeId))
             return false;
-        if (portId != other.portId)
+        if (!portId.equals(other.portId))
             return false;
         return true;
     }
diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties
index b9da2671a..8ba99cf65 100644
--- a/src/main/resources/floodlightdefault.properties
+++ b/src/main/resources/floodlightdefault.properties
@@ -4,7 +4,6 @@ net.floodlightcontroller.storage.memory.MemoryStorageSource,\
 net.floodlightcontroller.core.internal.FloodlightProvider,\
 net.floodlightcontroller.threadpool.ThreadPool,\
 net.floodlightcontroller.debugcounter.DebugCounterServiceImpl,\
-net.floodlightcontroller.restserver.RestApiServer,\
 net.floodlightcontroller.perfmon.PktInProcessingTime,\
 net.floodlightcontroller.debugevent.DebugEventService,\
 net.floodlightcontroller.staticflowentry.StaticFlowEntryPusher,\
diff --git a/src/test/java/net/floodlightcontroller/core/internal/RoleManagerTest.java b/src/test/java/net/floodlightcontroller/core/internal/RoleManagerTest.java
index 861574b29..526c8e237 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/RoleManagerTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/RoleManagerTest.java
@@ -32,26 +32,19 @@ import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.reset;
 import static org.easymock.EasyMock.verify;
 
-import java.util.HashMap;
 
 import org.junit.After;
 
 import net.floodlightcontroller.core.HARole;
-import net.floodlightcontroller.core.IOFSwitch;
-import net.floodlightcontroller.core.IOFSwitchBackend;
 import net.floodlightcontroller.core.IShutdownService;
 import net.floodlightcontroller.core.internal.Controller.IUpdate;
-import net.floodlightcontroller.core.test.MockSwitchManager;
 import net.floodlightcontroller.debugcounter.IDebugCounterService;
 import net.floodlightcontroller.debugcounter.MockDebugCounterService;
-import org.projectfloodlight.openflow.types.DatapathId;
 
 public class RoleManagerTest extends FloodlightTestCase {
     private Controller controller;
     private RoleManager roleManager;
 
-    private static DatapathId DATAPATH_ID_1 = DatapathId.of(1);
-
     @Override
     @Before
     public void setUp() throws Exception {
@@ -134,103 +127,4 @@ public class RoleManagerTest extends FloodlightTestCase {
 
         roleManager.setRole(role, "test");
     }
-
-
-    @Test
-    public void testNotifyFollower() throws Exception {
-        // Set by default
-        assertTrue(roleManager.getRole() == HARole.ACTIVE);
-
-        reset(controller);
-        controller.addUpdateToQueue(anyObject(IUpdate.class));
-        expectLastCall().anyTimes();
-        replay(controller);
-
-        // Test ACTIVE
-        roleManager.notify();
-
-        assertTrue(roleManager.getRole() == HARole.STANDBY);
-
-        // Test STANDBY
-        roleManager.notify();
-
-        assertTrue(roleManager.getRole() == HARole.STANDBY);
-
-    }
-
-    @Test
-    public void testNotifyLeaderNoMaster() {
-        doSetUp(HARole.STANDBY);
-
-        // Another master does NOT exist
-        setupSwitchesForNotifyLeader(false);
-
-        roleManager.notify();
-
-        assertTrue(roleManager.getRole() == HARole.ACTIVE);
-    }
-
-    @Test
-    public void testNotifyLeaderAnotherMaster() {
-        doSetUp(HARole.STANDBY);
-
-        // Another master exists
-        setupSwitchesForNotifyLeader(true);
-
-        roleManager.notify();
-
-        assertTrue(roleManager.getRole() == HARole.STANDBY);
-    }
-
-    @Test
-    public void testNotifyLeaderSplitBrainProtection() throws Exception {
-        doSetUp(HARole.STANDBY);
-
-        /* Split brain protection should not allow a controller to become ACTIVE
-         * if another ACTIVE controller exists in the cluster.
-         */
-        setupSwitchesForNotifyLeader(true);
-
-        roleManager.notify();
-
-        assertTrue(roleManager.getRole() == HARole.STANDBY);
-
-        /* At this point if the leader in the split brain scenario goes down,
-        * the controller connections should be updated to reflect that and
-        * leader notification should succeed as no other ACTIVE controller exists.
-        */
-        setupSwitchesForNotifyLeader(false);
-
-        /* Since the roleManager has already been notified, the controller connections
-         * should prompt an update.
-         */
-        roleManager.notifyControllerConnectionUpdate();
-
-        assertTrue(roleManager.getRole() == HARole.ACTIVE);
-    }
-
-    /**
-     * Helper to setup switches to test NotifyLeader scenarios.
-     * @param hasAnotherMaster whether or not the switches should have another master
-     */
-    public void setupSwitchesForNotifyLeader(boolean hasAnotherMaster) {
-        reset(controller);
-        // Setup switches with another master
-        MockSwitchManager switchManager = new MockSwitchManager();
-
-        IOFSwitchBackend sw1 = createMock(IOFSwitchBackend.class);
-        reset(sw1);
-        expect(sw1.hasAnotherMaster()).andReturn(hasAnotherMaster).anyTimes();
-        replay(sw1);
-
-        HashMap<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch> ();
-        switches.put(DATAPATH_ID_1, sw1);
-        switchManager.setSwitches(switches);
-
-        expect(controller.getSwitchService()).andReturn(switchManager).once();
-        controller.addUpdateToQueue(anyObject(IUpdate.class));
-        expectLastCall().anyTimes();
-        replay(controller);
-
-    }
 }
\ No newline at end of file
diff --git a/src/test/java/net/floodlightcontroller/debugevent/DebugEventTest.java b/src/test/java/net/floodlightcontroller/debugevent/DebugEventTest.java
index 0c296ef4b..aa2acfaea 100644
--- a/src/test/java/net/floodlightcontroller/debugevent/DebugEventTest.java
+++ b/src/test/java/net/floodlightcontroller/debugevent/DebugEventTest.java
@@ -1,24 +1,42 @@
 package net.floodlightcontroller.debugevent;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.easymock.EasyMock.anyObject;
+
+import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import net.floodlightcontroller.core.IShutdownListener;
+import net.floodlightcontroller.core.IShutdownService;
+import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.debugevent.DebugEventResource.EventInfoResource;
+import net.floodlightcontroller.debugevent.EventResource.Metadata;
 import net.floodlightcontroller.debugevent.IDebugEventService.EventColumn;
 import net.floodlightcontroller.debugevent.IDebugEventService.EventFieldType;
 import net.floodlightcontroller.debugevent.IDebugEventService.EventType;
+import org.projectfloodlight.openflow.types.DatapathId;
 import net.floodlightcontroller.test.FloodlightTestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DebugEventTest extends FloodlightTestCase {
-    Event debugEvent;
+    DebugEventService debugEvent;
     protected static Logger log = LoggerFactory.getLogger(DebugEventTest.class);
 
     @Override
     @Before
     public void setUp() throws Exception {
-        debugEvent = new Event(System.currentTimeMillis(), 0, "test", null, 0);
-
+        debugEvent = new DebugEventService();
+        FloodlightModuleContext fmc = new FloodlightModuleContext();
+        IShutdownService shutdownService =
+                EasyMock.createMock(IShutdownService.class);
+        shutdownService.registerShutdownListener(anyObject(IShutdownListener.class));
+        EasyMock.expectLastCall().once();
+        EasyMock.replay(shutdownService);
+        fmc.addService(IShutdownService.class, shutdownService);
+        debugEvent.startUp(fmc);
+        EasyMock.verify(shutdownService);
     }
 
 
@@ -27,12 +45,20 @@ public class DebugEventTest extends FloodlightTestCase {
         assertEquals(0, debugEvent.currentEvents.size());
         IEventCategory<SwitchyEvent> event1 = null;
         IEventCategory<PacketyEvent> event2 = null;
-        event1 = debugEvent.registerEvent("dbgevtest", "switchevent",
-                                           "switchtest", EventType.ALWAYS_LOG,
-                                           SwitchyEvent.class, 100);
-        event2 = debugEvent.registerEvent("dbgevtest", "pktinevent",
-                                           "pktintest", EventType.ALWAYS_LOG,
-                                           PacketyEvent.class, 100);
+        event1 = debugEvent.buildEvent(SwitchyEvent.class)
+                .setModuleName("dbgevtest")
+                .setEventName("switchevent")
+                .setEventType(EventType.ALWAYS_LOG)
+                .setBufferCapacity(100)
+                .setAckable(false)
+                .register();
+        event2 = debugEvent.buildEvent(PacketyEvent.class)
+                .setModuleName("dbgevtest")
+                .setEventName("pktinevent")
+                .setEventType(EventType.ALWAYS_LOG)
+                .setBufferCapacity(100)
+                .setAckable(false)
+                .register();
 
         assertEquals(2, debugEvent.currentEvents.size());
         assertTrue(null != debugEvent.moduleEvents.get("dbgevtest").
@@ -47,40 +73,40 @@ public class DebugEventTest extends FloodlightTestCase {
         assertEquals(true, debugEvent.containsModuleEventName("dbgevtest","switchevent"));
         assertEquals(true, debugEvent.containsModuleEventName("dbgevtest","pktinevent"));
 
-        assertEquals(0, debugEvent.allEvents[eventId1].eventBuffer.size());
-        assertEquals(0, debugEvent.allEvents[eventId2].eventBuffer.size());
+        assertEquals(0, debugEvent.allEvents.get(eventId1).circularEventBuffer.size());
+        assertEquals(0, debugEvent.allEvents.get(eventId2).circularEventBuffer.size());
 
         // update is immediately flushed to global store
-        event1.updateEventWithFlush(new SwitchyEvent(1L, "connected"));
-        assertEquals(1, debugEvent.allEvents[eventId1].eventBuffer.size());
+        event1.newEventWithFlush(new SwitchyEvent(DatapathId.of(1L), "connected"));
+        assertEquals(1, debugEvent.allEvents.get(eventId1).circularEventBuffer.size());
 
         // update is flushed only when flush is explicitly called
-        event2.updateEventNoFlush(new PacketyEvent(1L, 24L));
-        assertEquals(0, debugEvent.allEvents[eventId2].eventBuffer.size());
+        event2.newEventNoFlush(new PacketyEvent(DatapathId.of(1L), 24L));
+        assertEquals(0, debugEvent.allEvents.get(eventId2).circularEventBuffer.size());
 
         debugEvent.flushEvents();
-        assertEquals(1, debugEvent.allEvents[eventId1].eventBuffer.size());
-        assertEquals(1, debugEvent.allEvents[eventId2].eventBuffer.size());
+        assertEquals(1, debugEvent.allEvents.get(eventId1).circularEventBuffer.size());
+        assertEquals(1, debugEvent.allEvents.get(eventId2).circularEventBuffer.size());
 
-        DebugEventInfo de = debugEvent.getSingleEventHistory("dbgevtest","switchevent", 100);
+        EventInfoResource de = debugEvent.getSingleEventHistory("dbgevtest","switchevent", 100);
         assertEquals(1, de.events.size());
-        assertEquals(true, de.events.get(0).get("dpid").equals("00:00:00:00:00:00:00:01"));
-        assertEquals(true, de.events.get(0).get("reason").equals("connected"));
+        assertTrue(de.events.get(0).getDataFields().contains(new Metadata("dpid", "00:00:00:00:00:00:00:01")));
+        assertTrue(de.events.get(0).getDataFields().contains(new Metadata("reason", "connected")));
 
-        DebugEventInfo de2 = debugEvent.getSingleEventHistory("dbgevtest","pktinevent", 100);
+        EventInfoResource de2 = debugEvent.getSingleEventHistory("dbgevtest","pktinevent", 100);
         assertEquals(1, de2.events.size());
-        assertEquals(true, de2.events.get(0).get("dpid").equals("00:00:00:00:00:00:00:01"));
-        assertEquals(true, de2.events.get(0).get("srcMac").equals("00:00:00:00:00:18"));
+        assertTrue(de2.events.get(0).getDataFields().contains(new Metadata("dpid", "00:00:00:00:00:00:00:01")));
+        assertTrue(de2.events.get(0).getDataFields().contains(new Metadata("srcMac", "00:00:00:00:00:18")));
     }
 
     public class SwitchyEvent {
         @EventColumn(name = "dpid", description = EventFieldType.DPID)
-        long dpid;
+        DatapathId dpid;
 
         @EventColumn(name = "reason", description = EventFieldType.STRING)
         String reason;
 
-        public SwitchyEvent(long dpid, String reason) {
+        public SwitchyEvent(DatapathId dpid, String reason) {
             this.dpid = dpid;
             this.reason = reason;
         }
@@ -88,14 +114,121 @@ public class DebugEventTest extends FloodlightTestCase {
 
     public class PacketyEvent {
         @EventColumn(name = "dpid", description = EventFieldType.DPID)
-        long dpid;
+        DatapathId dpid;
 
         @EventColumn(name = "srcMac", description = EventFieldType.MAC)
         long mac;
 
-        public PacketyEvent(long dpid, long mac) {
+        public PacketyEvent(DatapathId dpid, long mac) {
             this.dpid = dpid;
             this.mac = mac;
         }
-    } 
-}
+    }
+
+    public class IntEvent {
+        @EventColumn(name = "index", description = EventFieldType.PRIMITIVE)
+        int index;
+
+        public IntEvent(int i) {
+            this.index = i;
+        }
+
+        @Override
+        public String toString() {
+            return String.valueOf(index);
+        }
+    }
+
+    @Test
+    public void testEventCyclesWithFlush() throws Exception {
+        IEventCategory<IntEvent> ev = null;
+        ev = debugEvent.buildEvent(IntEvent.class)
+                .setModuleName("test")
+                .setEventName("int")
+                .setEventDescription("just a test")
+                .setEventType(EventType.ALWAYS_LOG)
+                .setBufferCapacity(20)
+                .setAckable(false)
+                .register();
+
+        for (int i=0; i<20; i++)
+            ev.newEventWithFlush(new IntEvent(i));
+        int i=19;
+        EventInfoResource dei = debugEvent.getSingleEventHistory("test","int", 100);
+        for (EventResource m : dei.events) {
+            assertTrue(m.getDataFields().get(0).getEventData().equals(String.valueOf(i)));
+            i--;
+        }
+        for (int j= 500; j<550; j++)
+            ev.newEventWithFlush(new IntEvent(j));
+        int k=549;
+        dei = debugEvent.getSingleEventHistory("test","int", 100);
+        for (EventResource m : dei.events) {
+            //log.info("{}", m.get("index"));
+            assertTrue(m.getDataFields().get(0).getEventData().equals(String.valueOf(k)));
+            k--;
+        }
+    }
+
+
+    @Test
+    public void testEventCyclesNoFlush() throws Exception {
+        IEventCategory<IntEvent> ev = null;
+        ev = debugEvent.buildEvent(IntEvent.class)
+                .setModuleName("test")
+                .setEventName("int")
+                .setEventDescription("just a test")
+                .setEventType(EventType.ALWAYS_LOG)
+                .setBufferCapacity(20)
+                .setAckable(false)
+                .register();
+
+        // flushes when local buffer fills up
+        for (int i=0; i<20; i++)
+            ev.newEventNoFlush(new IntEvent(i));
+        int i=19;
+        EventInfoResource dei = debugEvent.getSingleEventHistory("test","int", 0);
+        for (EventResource m : dei.events) {
+            assertTrue(m.getDataFields().get(0).getEventData().equals(String.valueOf(i)));
+            i--;
+        }
+        //log.info("done with first bunch");
+        // flushes when local buffer fills up or when flushEvents is explicitly called
+        for (int j= 500; j<550; j++) {
+            ev.newEventNoFlush(new IntEvent(j));
+            //if (j == 515)
+                //debugEvent.flushEvents();
+        }
+        debugEvent.flushEvents();
+
+        int k=549;
+        dei = debugEvent.getSingleEventHistory("test","int", 100);
+        for (EventResource m : dei.events) {
+            //log.info("{}", m.get("index"));
+            assertTrue(m.getDataFields().get(0).getEventData().equals(String.valueOf(k)));
+            k--;
+        }
+    }
+
+    @Test
+    public void testAckEvent() throws Exception{
+        IEventCategory<IntEvent> ev = null;
+        ev = debugEvent.buildEvent(IntEvent.class)
+                .setModuleName("test")
+                .setEventName("ack")
+                .setEventDescription("just a test")
+                .setEventType(EventType.ALWAYS_LOG)
+                .setBufferCapacity(20)
+                .setAckable(false)
+                .register();
+        //create a single event
+        IntEvent e = new IntEvent(10);
+        ev.newEventWithFlush(e);
+        EventInfoResource dei = debugEvent.getSingleEventHistory("test","ack", 1);
+        debugEvent.setAck(dei.getEventId(),
+                          dei.getEvents().get(0).getEventInstanceId(),
+                          true);
+        dei = debugEvent.getSingleEventHistory("test","ack", 1);
+        assertTrue(dei.getEvents().get(0).isAcked());
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/net/floodlightcontroller/debugevent/EventTest.java b/src/test/java/net/floodlightcontroller/debugevent/EventTest.java
index 8ee0661cf..03d1cd2c8 100644
--- a/src/test/java/net/floodlightcontroller/debugevent/EventTest.java
+++ b/src/test/java/net/floodlightcontroller/debugevent/EventTest.java
@@ -1,15 +1,20 @@
 package net.floodlightcontroller.debugevent;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
+import java.util.Date;
+import org.junit.Test;
+import net.floodlightcontroller.debugevent.Event;
+import net.floodlightcontroller.debugevent.EventResource;
+import net.floodlightcontroller.debugevent.EventResource.EventResourceBuilder;
+import net.floodlightcontroller.debugevent.EventResource.Metadata;
 import net.floodlightcontroller.debugevent.IDebugEventService.EventColumn;
 import net.floodlightcontroller.debugevent.IDebugEventService.EventFieldType;
-
-import org.junit.Test;
+import org.projectfloodlight.openflow.types.DatapathId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -20,40 +25,63 @@ public class EventTest {
     public void testFormat() {
         River r = new River("ganges", 42);
 
-        Event e = new Event(1, 32, "test", new RiverEvent(1L, (short)10, true, "big river", 5, 4L, r), 0);
-
-        Map<String, String> expected = new HashMap<String, String>();
-        expected.put("dpid", "00:00:00:00:00:00:00:01");
-        expected.put("portId", "10");
-        expected.put("valid", "true");
-        expected.put("desc", "big river");
-        expected.put("ip", "0.0.0.5");
-        expected.put("mac", "00:00:00:00:00:04");
-        expected.put("obj", "ganges/42");
-
-        //log.info("{} \n expected {}", e.getFormattedEvent(RiverEvent.class, "test"), expected);
-        for (Entry<String, String> elem : expected.entrySet())
-            assertEquals(elem.getValue(),
-                         e.getFormattedEvent(RiverEvent.class, "test").get(elem.getKey()));
+        Event e = new Event(1L, 32, "test",
+                      new RiverEvent(DatapathId.of(1L), (short)10, true, "big river", 5, 4L, r), 10L);
+
+        EventResourceBuilder edb = new EventResourceBuilder();
+        edb.dataFields.add(new Metadata("dpid", "00:00:00:00:00:00:00:01"));
+        edb.dataFields.add(new Metadata("portId", "10"));
+        edb.dataFields.add(new Metadata("valid", "true"));
+        edb.dataFields.add(new Metadata("desc", "big river"));
+        edb.dataFields.add(new Metadata("ip", "0.0.0.5"));
+        edb.dataFields.add(new Metadata("mac", "00:00:00:00:00:04"));
+        edb.dataFields.add(new Metadata("obj", "ganges/42"));
+        edb.setThreadId(e.getThreadId());
+        edb.setThreadName(e.getThreadName());
+        edb.setTimeStamp(e.getTimeMs());
+        edb.setModuleEventName("test");
+        EventResource ed = edb.build();
+
+        // check Event.getFormattedEvent()
+        assertTrue(ed.equals(e.getFormattedEvent(RiverEvent.class, "test")));
 
         // ensure timestamp comes in ISO8601 time
-        assertEquals("1969-12-31T16:00:00.001-0800",
-                     e.getFormattedEvent(RiverEvent.class, "test2").get("Timestamp")); //1L
+        // e.g.: 1969-12-31T16:00:00.001-08:00
+        Pattern pat =
+                Pattern.compile("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}[+-]\\d{2}:\\d{2}");
+        Date t1 = e.getFormattedEvent(RiverEvent.class, "test2").getTimestamp();
+        Matcher m1 = pat.matcher(t1.toString());
+        assertTrue(m1.matches());
 
         // ensure that cached value is not returned for incorrect class
-        for (Entry<String, String> elem : expected.entrySet())
-            assertFalse(elem.getValue().equals(
-                            e.getFormattedEvent(River.class, "test").get(elem.getKey())));
-
-        assertEquals("null event data or event-class does not match event-data",
-                     e.getFormattedEvent(River.class, "test").get("Error"));
-        assertEquals("null event data or event-class does not match event-data",
-                     e.getFormattedEvent(null, "test").get("Error"));
+        assertFalse(ed.equals(e.getFormattedEvent(River.class, "test")));
+
+        assertTrue(e.getFormattedEvent(River.class, "test").getDataFields().
+                   contains(new Metadata("Error",
+                   "null event data or event-class does not match event-data")));
+        assertTrue(e.getFormattedEvent(null, "test").getDataFields().contains(
+          new Metadata("Error",
+                   "null event data or event-class does not match event-data")));
+    }
+
+    @Test
+    public void testIncorrectAnnotation() {
+        Event e = new Event(1L, 32, "test",
+                            new LakeEvent(199), 11L); // dpid cannot be int
+        assertTrue(e.getFormattedEvent(LakeEvent.class, "test").getDataFields()
+          .contains(new Metadata("Error",
+                             "java.lang.Integer cannot be cast to org.projectfloodlight.openflow.types.DatapathId")));
+
+        Event e2 = new Event(1L, 32, "test",
+                            new LakeEvent2(199), 12L); // mac cannot be int
+        assertTrue(e2.getFormattedEvent(LakeEvent2.class, "test").getDataFields()
+                   .contains(new Metadata("Error",
+                                      "java.lang.Integer cannot be cast to java.lang.Long")));
     }
 
     class RiverEvent  {
         @EventColumn(name = "dpid", description = EventFieldType.DPID)
-        long dpid;
+        DatapathId dpid;
 
         @EventColumn(name = "portId", description = EventFieldType.PRIMITIVE)
         short srcPort;
@@ -75,7 +103,7 @@ public class EventTest {
 
         // Instances of RiverEvent ensure that that any internal object
         // (eg. River instances) has been copied before it is given to DebugEvents.
-        public RiverEvent(long dpid, short srcPort, boolean isValid,
+        public RiverEvent(DatapathId dpid, short srcPort, boolean isValid,
                             String desc, int ip, long mac, River passedin) {
             this.dpid = dpid;
             this.srcPort = srcPort;
@@ -127,5 +155,5 @@ public class EventTest {
         public LakeEvent2(int mac) {
             this.mac = mac;
         }
-    } 
-}
+    }
+}
\ No newline at end of file
diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java
index df61c28e3..c539be22b 100644
--- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java
+++ b/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImplTest.java
@@ -57,6 +57,12 @@ import net.floodlightcontroller.core.HARole;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.module.FloodlightModuleException;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
+import net.floodlightcontroller.debugcounter.DebugCounterServiceImpl;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.DebugEventService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.devicemanager.IDevice;
 import net.floodlightcontroller.devicemanager.IDeviceListener;
 import net.floodlightcontroller.devicemanager.IDeviceService;
@@ -123,6 +129,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
 	DeviceManagerImpl deviceManager;
 	MemoryStorageSource storageSource;
 	FlowReconcileManager flowReconcileMgr;
+	IDebugCounterService debugCounterService;
+	IDebugEventService debugEventService;
 
 	private IOFSwitch makeSwitchMock(DatapathId id) {
 		IOFSwitch mockSwitch = createMock(IOFSwitch.class);
@@ -173,6 +181,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
 		fmc.addService(IThreadPoolService.class, tp);
 		mockFloodlightProvider = getMockFloodlightProvider();
 		mockFloodlightProvider.setRole(initialRole, "");
+		debugCounterService = new MockDebugCounterService();
+		debugEventService = new MockDebugEventService();
 
 
 		deviceManager = new DeviceManagerImpl();
@@ -187,6 +197,8 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
 		fmc.addService(IEntityClassifierService.class, entityClassifier);
 		fmc.addService(ITopologyService.class, topology);
 		fmc.addService(ISyncService.class, syncService);
+		fmc.addService(IDebugCounterService.class, debugCounterService);
+		fmc.addService(IDebugEventService.class, debugEventService);
 		tp.init(fmc);
 		restApi.init(fmc);
 		storageSource.init(fmc);
diff --git a/src/test/java/net/floodlightcontroller/firewall/FirewallTest.java b/src/test/java/net/floodlightcontroller/firewall/FirewallTest.java
index 6e5f4a57b..b643349f0 100644
--- a/src/test/java/net/floodlightcontroller/firewall/FirewallTest.java
+++ b/src/test/java/net/floodlightcontroller/firewall/FirewallTest.java
@@ -93,7 +93,6 @@ public class FirewallTest extends FloodlightTestCase {
         DatapathId dpid = DatapathId.of(TestSwitch1DPID);
         sw = EasyMock.createNiceMock(IOFSwitch.class);
         expect(sw.getId()).andReturn(dpid).anyTimes();
-        expect(sw.getId().toString()).andReturn(TestSwitch1DPID).anyTimes();
         replay(sw);
         // Load the switch map
         Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>();
diff --git a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java
index 9dec8e671..b63921396 100644
--- a/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java
+++ b/src/test/java/net/floodlightcontroller/forwarding/ForwardingTest.java
@@ -31,6 +31,10 @@ import net.floodlightcontroller.core.IFloodlightProviderService;
 import net.floodlightcontroller.core.IOFSwitch;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.devicemanager.internal.DefaultEntityClassifier;
 import net.floodlightcontroller.devicemanager.test.MockDeviceManager;
 import net.floodlightcontroller.devicemanager.IDevice;
@@ -146,6 +150,8 @@ public class ForwardingTest extends FloodlightTestCase {
         fmc.addService(IFlowReconcileService.class, flowReconcileMgr);
         fmc.addService(IEntityClassifierService.class, entityClassifier);
         fmc.addService(ISyncService.class, mockSyncService);
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
 
         topology.addListener(anyObject(ITopologyListener.class));
         expectLastCall().anyTimes();
@@ -170,14 +176,10 @@ public class ForwardingTest extends FloodlightTestCase {
         sw1 = EasyMock.createMock(IOFSwitch.class);
         expect(sw1.getId()).andReturn(DatapathId.of(1L)).anyTimes();
         expect(sw1.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
-        expect(sw1.getId().toString())
-                .andReturn(DatapathId.of(1L).toString()).anyTimes();
 
         sw2 = EasyMock.createMock(IOFSwitch.class);
         expect(sw2.getId()).andReturn(DatapathId.of(2L)).anyTimes();
         expect(sw2.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
-        expect(sw2.getId().toString())
-                .andReturn(DatapathId.of(2L).toString()).anyTimes();
 
         expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
 
@@ -212,7 +214,6 @@ public class ForwardingTest extends FloodlightTestCase {
         testPacketSerialized = testPacket.serialize();
         packetIn = factory.buildPacketIn()
                         .setBufferId(OFBufferId.NO_BUFFER)
-                        .setInPort(OFPort.of(1))
                         .setData(testPacketSerialized)
                         .setReason(OFPacketInReason.NO_MATCH)
                         .build();
@@ -222,7 +223,6 @@ public class ForwardingTest extends FloodlightTestCase {
         poactions.add(factory.actions().output(OFPort.of(3), Integer.MAX_VALUE));
         packetOut = factory.buildPacketOut()
         		.setBufferId(this.packetIn.getBufferId())
-        		.setInPort(this.packetIn.getInPort())
         		.setActions(poactions)
         		.setData(testPacketSerialized)
         		.build();
@@ -232,7 +232,6 @@ public class ForwardingTest extends FloodlightTestCase {
         poactions.add(factory.actions().output(OFPort.FLOOD, Integer.MAX_VALUE));
         packetOutFlooded = factory.buildPacketOut()
         		.setBufferId(this.packetIn.getBufferId())
-        		.setInPort(this.packetIn.getInPort())
         		.setActions(poactions)
         		.setData(testPacketSerialized)
         		.build();
diff --git a/src/test/java/net/floodlightcontroller/learningswitch/LearningSwitchTest.java b/src/test/java/net/floodlightcontroller/learningswitch/LearningSwitchTest.java
index f0bf807fd..cfcd202ce 100644
--- a/src/test/java/net/floodlightcontroller/learningswitch/LearningSwitchTest.java
+++ b/src/test/java/net/floodlightcontroller/learningswitch/LearningSwitchTest.java
@@ -124,10 +124,13 @@ public class LearningSwitchTest extends FloodlightTestCase {
         // Build the PacketIn
         this.packetIn = factory.buildPacketIn()
             .setBufferId(OFBufferId.NO_BUFFER)
-            .setInPort(OFPort.of(1))
             .setData(this.testPacketSerialized)
             .setReason(OFPacketInReason.NO_MATCH)
             .build();
+        
+        this.learningSwitch = new LearningSwitch();
+        this.mockFloodlightProvider.addOFMessageListener(OFType.PACKET_IN, learningSwitch);
+
     }
 
     @Test
@@ -136,13 +139,12 @@ public class LearningSwitchTest extends FloodlightTestCase {
         OFPacketOut po = factory.buildPacketOut()
             .setActions(Arrays.asList((OFAction)factory.actions().output(OFPort.FLOOD, Integer.MAX_VALUE)))
             .setBufferId(OFBufferId.NO_BUFFER)
-            .setInPort(OFPort.of(1))
             .setData(this.testPacketSerialized)
 	        .build();
 
         // Mock up our expected behavior
         IOFSwitch mockSwitch = createMock(IOFSwitch.class);
-        expect(mockSwitch.getId().toString()).andReturn("00:11:22:33:44:55:66:77").anyTimes();
+        expect(mockSwitch.getId()).andReturn(DatapathId.of("00:11:22:33:44:55:66:77")).anyTimes();
         mockSwitch.write(po, null);
 
         // Start recording the replay on the mocks
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
index b2ba0f446..08a490373 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
+++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
@@ -30,6 +30,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -38,8 +39,13 @@ import net.floodlightcontroller.core.FloodlightContext;
 import net.floodlightcontroller.core.IFloodlightProviderService;
 import net.floodlightcontroller.core.IListener.Command;
 import net.floodlightcontroller.core.IOFSwitch;
+import net.floodlightcontroller.core.internal.IOFSwitchService;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryListener;
 import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
 import net.floodlightcontroller.linkdiscovery.LinkInfo;
@@ -70,6 +76,7 @@ import org.projectfloodlight.openflow.protocol.OFMessage;
 import org.projectfloodlight.openflow.protocol.OFPacketIn;
 import org.projectfloodlight.openflow.protocol.OFPacketInReason;
 import org.projectfloodlight.openflow.protocol.OFPortDesc;
+import org.projectfloodlight.openflow.protocol.OFPortFeatures;
 import org.projectfloodlight.openflow.protocol.OFVersion;
 import org.projectfloodlight.openflow.types.DatapathId;
 import org.projectfloodlight.openflow.types.MacAddress;
@@ -127,6 +134,8 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
         ldm = new TestLinkDiscoveryManager();
         TopologyManager routingEngine = new TopologyManager();
         ldm.linkDiscoveryAware = new ArrayList<ILinkDiscoveryListener>();
+        IDebugCounterService debugCounterService = new MockDebugCounterService();
+        IDebugEventService debugEventService = new MockDebugEventService();
         MockThreadPoolService tp = new MockThreadPoolService();
         RestApiServer restApi = new RestApiServer();
         cntx.addService(IRestApiService.class, restApi);
@@ -136,6 +145,9 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
         cntx.addService(ITopologyService.class, ldm);
         cntx.addService(IStorageSourceService.class, new MemoryStorageSource());
         cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
+        cntx.addService(IDebugCounterService.class, debugCounterService);
+        cntx.addService(IDebugEventService.class, debugEventService);
+        cntx.addService(IOFSwitchService.class, getMockSwitchService());
         restApi.init(cntx);
         tp.init(cntx);
         routingEngine.init(cntx);
@@ -170,8 +182,8 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
         // check invariants hold
         assertNotNull(linkDiscovery.switchLinks.get(lt.getSrc()));
         assertTrue(linkDiscovery.switchLinks.get(lt.getSrc()).contains(lt));
-        assertNotNull(linkDiscovery.portLinks.get(srcNpt));
-        assertTrue(linkDiscovery.portLinks.get(srcNpt).contains(lt));
+        assertNotNull(linkDiscovery.getPortLinks().get(srcNpt));
+        assertTrue(linkDiscovery.getPortLinks().get(srcNpt).contains(lt));
         assertNotNull(linkDiscovery.portLinks.get(dstNpt));
         assertTrue(linkDiscovery.portLinks.get(dstNpt).contains(lt));
         assertTrue(linkDiscovery.links.containsKey(lt));
@@ -290,7 +302,7 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
 
         Link lt = new Link(DatapathId.of(1L), OFPort.of(1), DatapathId.of(2L), OFPort.of(1));
         NodePortTuple srcNpt = new NodePortTuple(DatapathId.of(1L), OFPort.of(1));
-        NodePortTuple dstNpt = new NodePortTuple(DatapathId.of(2L), OFPort.of(2));
+        NodePortTuple dstNpt = new NodePortTuple(DatapathId.of(2L), OFPort.of(1));
 
         LinkInfo info;
 
@@ -422,15 +434,15 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
     @Test
     public void testSwitchAdded() throws Exception {
         LinkDiscoveryManager linkDiscovery = getLinkDiscoveryManager();
+        linkDiscovery.switchService = getMockSwitchService();
         Capture<OFMessage> wc;
         Set<OFPort> qPorts;
         OFPortDesc ofpp = OFFactories.getFactory(OFVersion.OF_13).buildPortDesc()
         .setName("eth4242")
         .setPortNo(OFPort.of(4242))
         .setHwAddr(MacAddress.of("5c:16:c7:00:00:01"))
-        .setCurr(null)
+        .setCurr(new HashSet<OFPortFeatures>()) // random
         .build();
-        OFPort p1 = ofpp.getPortNo();
         IOFSwitch sw1 = createMockSwitch(1L);
 
         // Set switch map in floodlightProvider.
@@ -449,7 +461,8 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
 
         // Expect switch to return those ports.
         expect(sw1.getEnabledPortNumbers()).andReturn(ports).anyTimes();
-        expect(sw1.getPort(OFPort.of(EasyMock.anyShort())).getPortNo()).andReturn(p1).anyTimes();
+        expect(sw1.getPort(OFPort.of(EasyMock.anyInt()))).andReturn(ofpp).anyTimes();
+        expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
         sw1.write(capture(wc));
         expectLastCall().anyTimes();
         replay(sw1);
@@ -499,7 +512,6 @@ public class LinkDiscoveryManagerTest extends FloodlightTestCase {
         // build out input packet
         pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
                 .setBufferId(OFBufferId.NO_BUFFER)
-                .setInPort(OFPort.of(1))
                 .setData(testPacketSerialized)
                 .setReason(OFPacketInReason.NO_MATCH)
                 .build();
diff --git a/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java b/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java
index a78460f5d..ce8f03904 100644
--- a/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java
+++ b/src/test/java/net/floodlightcontroller/loadbalancer/LoadBalancerTest.java
@@ -51,6 +51,7 @@ import org.projectfloodlight.openflow.types.OFPort;
 import org.projectfloodlight.openflow.types.U64;
 import org.projectfloodlight.openflow.protocol.OFPacketInReason;
 import org.projectfloodlight.openflow.protocol.action.OFAction;
+import org.projectfloodlight.openflow.protocol.match.MatchField;
 import org.projectfloodlight.openflow.util.HexString;
 import org.projectfloodlight.openflow.types.DatapathId;
 import org.sdnplatform.sync.ISyncService;
@@ -59,8 +60,13 @@ import org.sdnplatform.sync.test.MockSyncService;
 import net.floodlightcontroller.core.FloodlightContext;
 import net.floodlightcontroller.core.IFloodlightProviderService;
 import net.floodlightcontroller.core.IOFSwitch;
+import net.floodlightcontroller.core.internal.IOFSwitchService;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.devicemanager.IDeviceService;
 import net.floodlightcontroller.devicemanager.IEntityClassifierService;
 import net.floodlightcontroller.devicemanager.internal.DefaultEntityClassifier;
@@ -103,7 +109,8 @@ public class LoadBalancerTest extends FloodlightTestCase {
 	protected PoolsResource poolsResource;
 	protected MembersResource membersResource;
 	private MockSyncService mockSyncService;
-
+	protected IDebugCounterService debugCounterService;
+	protected IDebugEventService debugEventService;
 	protected LBVip vip1, vip2;
 	protected LBPool pool1, pool2, pool3;
 	protected LBMember member1, member2, member3, member4;
@@ -127,6 +134,8 @@ public class LoadBalancerTest extends FloodlightTestCase {
 		sfp = new StaticFlowEntryPusher();
 		storage = new MemoryStorageSource(); //dependency for sfp
 		mockSyncService = new MockSyncService();
+		debugCounterService = new MockDebugCounterService();
+		debugEventService = new MockDebugEventService();
 
 		fmc.addService(IRestApiService.class, restApi);
 		fmc.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
@@ -140,6 +149,9 @@ public class LoadBalancerTest extends FloodlightTestCase {
 		fmc.addService(ILoadBalancerService.class, lb);
 		fmc.addService(IStorageSourceService.class, storage);
 		fmc.addService(ISyncService.class, mockSyncService);
+		fmc.addService(IDebugCounterService.class, debugCounterService);
+		fmc.addService(IDebugEventService.class, debugEventService);
+		fmc.addService(IOFSwitchService.class, getMockSwitchService());
 
 		lb.init(fmc);
 		getMockFloodlightProvider().init(fmc);
@@ -430,8 +442,8 @@ public class LoadBalancerTest extends FloodlightTestCase {
 
 		sw1 = EasyMock.createNiceMock(IOFSwitch.class);
 		expect(sw1.getId()).andReturn(DatapathId.of(1L)).anyTimes();
-		expect(sw1.getId().toString()).andReturn("00:00:00:00:00:01").anyTimes();
 		expect(sw1.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
+		expect(sw1.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
 		sw1.write(capture(wc1));
 		expectLastCall().anyTimes();
 		sw1.flush();
@@ -464,7 +476,6 @@ public class LoadBalancerTest extends FloodlightTestCase {
 		replay(topology);
 
 
-
 		// Build arp packets
 		arpRequest1 = new Ethernet()
 		.setSourceMACAddress("00:00:00:00:00:01")
@@ -487,8 +498,8 @@ public class LoadBalancerTest extends FloodlightTestCase {
 		arpRequest1Serialized = arpRequest1.serialize();
 
 		arpRequestPacketIn1 = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
+				.setMatch(OFFactories.getFactory(OFVersion.OF_13).buildMatch().setExact(MatchField.IN_PORT, OFPort.of(1)).build())
 				.setBufferId(OFBufferId.NO_BUFFER)
-				.setInPort(OFPort.of(1))
 				.setData(arpRequest1Serialized)
 				.setReason(OFPacketInReason.NO_MATCH)
 				.build();
@@ -519,7 +530,7 @@ public class LoadBalancerTest extends FloodlightTestCase {
 		arpReply1Serialized = arpReply1.serialize();
 
 		List<OFAction> poactions = new ArrayList<OFAction>();
-		poactions.add(OFFactories.getFactory(OFVersion.OF_13).actions().output(arpRequestPacketIn1.getInPort(), (short) 0xffff));
+		poactions.add(OFFactories.getFactory(OFVersion.OF_13).actions().output(arpRequestPacketIn1.getMatch().get(MatchField.IN_PORT), (short) 0xffff));
 		arpReplyPacketOut1 = OFFactories.getFactory(OFVersion.OF_13).buildPacketOut()
 				.setBufferId(OFBufferId.NO_BUFFER)
 				.setInPort(OFPort.ANY)
diff --git a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java
index cf73d87a6..dc9354e2e 100644
--- a/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java
+++ b/src/test/java/net/floodlightcontroller/staticflowentry/StaticFlowTests.java
@@ -39,11 +39,19 @@ import org.projectfloodlight.openflow.types.OFPort;
 import org.projectfloodlight.openflow.protocol.action.OFAction;
 import org.projectfloodlight.openflow.util.HexString;
 
+import com.sun.org.apache.bcel.internal.generic.GETSTATIC;
+
 import net.floodlightcontroller.core.FloodlightContext;
 import net.floodlightcontroller.core.IFloodlightProviderService;
 import net.floodlightcontroller.core.IOFSwitch;
+import net.floodlightcontroller.core.internal.IOFSwitchService;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockFloodlightProvider;
+import net.floodlightcontroller.core.test.MockSwitchManager;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.test.FloodlightTestCase;
 import net.floodlightcontroller.util.FlowModUtils;
 import net.floodlightcontroller.util.MatchUtils;
@@ -135,7 +143,7 @@ public class StaticFlowTests extends FloodlightTestCase {
         Match match;
         TestRule3.put(COLUMN_DL_DST, "00:20:30:40:50:60");
         TestRule3.put(COLUMN_DL_VLAN, 4096);
-        match = MatchUtils.fromString("dl_dst=00:20:30:40:50:60,dl_vlan=4096", factory.getVersion());
+        match = MatchUtils.fromString("dl_dst=00:20:30:40:50:60,dl_vlan=96", factory.getVersion());
         // setup actions
         TestRule3.put(COLUMN_ACTIONS, "output=controller");
         List<OFAction> actions = new LinkedList<OFAction>();
@@ -200,6 +208,7 @@ public class StaticFlowTests extends FloodlightTestCase {
 
         FloodlightModuleContext fmc = new FloodlightModuleContext();
         fmc.addService(IStorageSourceService.class, storage);
+        fmc.addService(IOFSwitchService.class, getMockSwitchService());
 
         MockFloodlightProvider mockFloodlightProvider = getMockFloodlightProvider();
         Map<DatapathId, IOFSwitch> switchMap = new HashMap<DatapathId, IOFSwitch>();
diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java
index d05013cbc..a8542b2ea 100644
--- a/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java
+++ b/src/test/java/net/floodlightcontroller/topology/TopologyInstanceTest.java
@@ -27,6 +27,10 @@ import net.floodlightcontroller.core.IFloodlightProviderService;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockFloodlightProvider;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.linkdiscovery.ILinkDiscovery;
 import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
@@ -60,6 +64,8 @@ public class TopologyInstanceTest {
         mockFloodlightProvider = new MockFloodlightProvider();
         fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
         fmc.addService(ILinkDiscoveryService.class, linkDiscovery);
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
         MockThreadPoolService tp = new MockThreadPoolService();
         topologyManager  = new TopologyManager();
         fmc.addService(IThreadPoolService.class, tp);
diff --git a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java
index 2ff76ee51..905acbb05 100644
--- a/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java
+++ b/src/test/java/net/floodlightcontroller/topology/TopologyManagerTest.java
@@ -20,6 +20,10 @@ import static org.junit.Assert.*;
 import net.floodlightcontroller.core.IFloodlightProviderService;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.linkdiscovery.ILinkDiscovery;
 import net.floodlightcontroller.test.FloodlightTestCase;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
@@ -43,6 +47,8 @@ public class TopologyManagerTest extends FloodlightTestCase {
         super.setUp();
         fmc = new FloodlightModuleContext();
         fmc.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
         MockThreadPoolService tp = new MockThreadPoolService();
         fmc.addService(IThreadPoolService.class, tp);
         tm  = new TopologyManager();
@@ -53,30 +59,30 @@ public class TopologyManagerTest extends FloodlightTestCase {
 
     @Test
     public void testBasic1() throws Exception {
-        tm.addOrUpdateLink(DatapathId.of(1), OFPort.of((short)1), DatapathId.of(2), OFPort.of((short)1), ILinkDiscovery.LinkType.DIRECT_LINK);
+        tm.addOrUpdateLink(DatapathId.of(1), OFPort.of(1), DatapathId.of(2), OFPort.of(1), ILinkDiscovery.LinkType.DIRECT_LINK);
         assertTrue(tm.getSwitchPorts().size() == 2);  // for two nodes.
-        assertTrue(tm.getSwitchPorts().get((long)1).size()==1);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
         assertTrue(tm.getSwitchPortLinks().size()==2);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
         assertTrue(tm.getTunnelPorts().size()==0);
 
-        tm.addOrUpdateLink(DatapathId.of(1), OFPort.of((short)2), DatapathId.of(2), OFPort.of((short)2), ILinkDiscovery.LinkType.MULTIHOP_LINK);
+        tm.addOrUpdateLink(DatapathId.of(1), OFPort.of(2), DatapathId.of(2), OFPort.of(2), ILinkDiscovery.LinkType.MULTIHOP_LINK);
         assertTrue(tm.getSwitchPorts().size() == 2);  // for two nodes.
-        assertTrue(tm.getSwitchPorts().get((long)1).size()==2);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==2);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==2);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==2);
         assertTrue(tm.getSwitchPortLinks().size()==4);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==2);
         assertTrue(tm.getTunnelPorts().size()==0);
 
-        tm.removeLink(DatapathId.of(1), OFPort.of((short)2), DatapathId.of(2), OFPort.of((short)2));
-        assertTrue(tm.getSwitchPorts().get((long)1).size()==1);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==1);
+        tm.removeLink(DatapathId.of(1), OFPort.of(2), DatapathId.of(2), OFPort.of(2));
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
         assertTrue(tm.getSwitchPorts().size() == 2);
         assertTrue(tm.getSwitchPortLinks().size()==2);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
 
-        tm.removeLink(DatapathId.of(1), OFPort.of((short)1), DatapathId.of(2), OFPort.of((short)1));
+        tm.removeLink(DatapathId.of(1), OFPort.of(1), DatapathId.of(2), OFPort.of(1));
         assertTrue(tm.getSwitchPorts().size() == 0);
         assertTrue(tm.getSwitchPortLinks().size()==0);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
@@ -84,41 +90,41 @@ public class TopologyManagerTest extends FloodlightTestCase {
 
     @Test
     public void testBasic2() throws Exception {
-        tm.addOrUpdateLink(DatapathId.of(1), OFPort.of((short)1), DatapathId.of(2), OFPort.of((short)1), ILinkDiscovery.LinkType.DIRECT_LINK);
-        tm.addOrUpdateLink(DatapathId.of(2), OFPort.of((short)2), DatapathId.of(3), OFPort.of((short)1), ILinkDiscovery.LinkType.MULTIHOP_LINK);
+        tm.addOrUpdateLink(DatapathId.of(1), OFPort.of(1), DatapathId.of(2), OFPort.of(1), ILinkDiscovery.LinkType.DIRECT_LINK);
+        tm.addOrUpdateLink(DatapathId.of(2), OFPort.of(2), DatapathId.of(3), OFPort.of(1), ILinkDiscovery.LinkType.MULTIHOP_LINK);
         assertTrue(tm.getSwitchPorts().size() == 3);  // for two nodes.
-        assertTrue(tm.getSwitchPorts().get((long)1).size()==1);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==2);
-        assertTrue(tm.getSwitchPorts().get((long)3).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==2);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(3)).size()==1);
         assertTrue(tm.getSwitchPortLinks().size()==4);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==2);
 
-        tm.removeLink(DatapathId.of(1), OFPort.of((short)1), DatapathId.of(2), OFPort.of((short)1));
+        tm.removeLink(DatapathId.of(1), OFPort.of(1), DatapathId.of(2), OFPort.of(1));
         assertTrue(tm.getSwitchPorts().size() == 2);
-        assertTrue(tm.getSwitchPorts().get((long)1) == null);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==1);
-        assertTrue(tm.getSwitchPorts().get((long)3).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)) == null);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(3)).size()==1);
         assertTrue(tm.getSwitchPortLinks().size()==2);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==2);
 
         // nonexistent link // no null pointer exceptions.
-        tm.removeLink(DatapathId.of(3), OFPort.of((short)1), DatapathId.of(2), OFPort.of((short)2));
+        tm.removeLink(DatapathId.of(3), OFPort.of(1), DatapathId.of(2), OFPort.of(2));
         assertTrue(tm.getSwitchPorts().size() == 2);
-        assertTrue(tm.getSwitchPorts().get((long)1) == null);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==1);
-        assertTrue(tm.getSwitchPorts().get((long)3).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1)) == null);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(3)).size()==1);
         assertTrue(tm.getSwitchPortLinks().size()==2);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==2);
 
-        tm.removeLink(DatapathId.of(3), OFPort.of((short)2), DatapathId.of(1), OFPort.of((short)2));
+        tm.removeLink(DatapathId.of(3), OFPort.of(2), DatapathId.of(1), OFPort.of(2));
         assertTrue(tm.getSwitchPorts().size() == 2);
-        assertTrue(tm.getSwitchPorts().get((long)1)==null);
-        assertTrue(tm.getSwitchPorts().get((long)2).size()==1);
-        assertTrue(tm.getSwitchPorts().get((long)3).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(1))==null);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(2)).size()==1);
+        assertTrue(tm.getSwitchPorts().get(DatapathId.of(3)).size()==1);
         assertTrue(tm.getSwitchPortLinks().size()==2);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==2);
 
-        tm.removeLink(DatapathId.of(2), OFPort.of((short)2), DatapathId.of(3), OFPort.of((short)1));
+        tm.removeLink(DatapathId.of(2), OFPort.of(2), DatapathId.of(3), OFPort.of(1));
         assertTrue(tm.getSwitchPorts().size() == 0);  // for two nodes.
         assertTrue(tm.getSwitchPortLinks().size()==0);
         assertTrue(tm.getPortBroadcastDomainLinks().size()==0);
diff --git a/src/test/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilterTest.java b/src/test/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilterTest.java
index 2eafde236..466776fce 100644
--- a/src/test/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilterTest.java
+++ b/src/test/java/net/floodlightcontroller/virtualnetwork/VirtualNetworkFilterTest.java
@@ -45,6 +45,10 @@ import net.floodlightcontroller.core.IOFSwitch;
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
 import net.floodlightcontroller.core.test.MockThreadPoolService;
 import net.floodlightcontroller.core.test.PacketFactory;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.devicemanager.IDeviceService;
 import net.floodlightcontroller.devicemanager.IEntityClassifierService;
 import net.floodlightcontroller.devicemanager.internal.DefaultEntityClassifier;
@@ -124,6 +128,8 @@ public class VirtualNetworkFilterTest extends FloodlightTestCase {
         fmc.addService(IEntityClassifierService.class, entityClassifier);
         fmc.addService(ITopologyService.class, topology);
         fmc.addService(ISyncService.class, mockSyncService);
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
         tps.init(fmc);
         frm.init(fmc);
         deviceService.init(fmc);
@@ -167,7 +173,6 @@ public class VirtualNetworkFilterTest extends FloodlightTestCase {
         mac1ToMac2PacketIntestPacketSerialized = mac1ToMac2PacketIntestPacket.serialize();
         mac1ToMac2PacketIn = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
                         .setBufferId(OFBufferId.NO_BUFFER)
-                        .setInPort(OFPort.of(1))
                         .setData(mac1ToMac2PacketIntestPacketSerialized)
                         .setReason(OFPacketInReason.NO_MATCH)
                         .build();
@@ -188,7 +193,6 @@ public class VirtualNetworkFilterTest extends FloodlightTestCase {
         mac1ToMac4PacketIntestPacketSerialized = mac1ToMac4PacketIntestPacket.serialize(); 
         mac1ToMac4PacketIn = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
                     .setBufferId(OFBufferId.NO_BUFFER)
-                    .setInPort(OFPort.of(1))
                     .setData(mac1ToMac4PacketIntestPacketSerialized)
                     .setReason(OFPacketInReason.NO_MATCH)
                     .build();
@@ -209,7 +213,6 @@ public class VirtualNetworkFilterTest extends FloodlightTestCase {
         mac1ToGwPacketIntestPacketSerialized = mac1ToGwPacketIntestPacket.serialize();
         mac1ToGwPacketIn =  OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
                     .setBufferId(OFBufferId.NO_BUFFER)
-                    .setInPort(OFPort.of(1))
                     .setData(mac1ToGwPacketIntestPacketSerialized)
                     .setReason(OFPacketInReason.NO_MATCH)
                     .build();
diff --git a/src/test/java/org/sdnplatform/sync/client/ClientTest.java b/src/test/java/org/sdnplatform/sync/client/ClientTest.java
index a4182ad38..bd6476577 100644
--- a/src/test/java/org/sdnplatform/sync/client/ClientTest.java
+++ b/src/test/java/org/sdnplatform/sync/client/ClientTest.java
@@ -8,10 +8,15 @@ import java.io.PrintStream;
 import java.util.ArrayList;
 
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
 import net.floodlightcontroller.threadpool.ThreadPool;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -30,6 +35,7 @@ public class ClientTest {
     protected SyncManager syncManager;
     protected final static ObjectMapper mapper = new ObjectMapper();
     protected String nodeString;
+    protected IDebugCounterService debugCounterService;
     ArrayList<Node> nodes;
     ThreadPool tp;
 
@@ -51,11 +57,15 @@ public class ClientTest {
         nodes.add(new Node("localhost", 40101, (short)1, (short)1));
         nodeString = mapper.writeValueAsString(nodes);
         
+        debugCounterService = new MockDebugCounterService();
+        
         tp = new ThreadPool();
         syncManager = new SyncManager();
         
         FloodlightModuleContext fmc = new FloodlightModuleContext();
         fmc.addService(IThreadPoolService.class, tp);
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
         
         fmc.addConfigParam(syncManager, "nodes", nodeString);
         fmc.addConfigParam(syncManager, "thisNode", ""+1);
diff --git a/src/test/java/org/sdnplatform/sync/internal/BootstrapTest.java b/src/test/java/org/sdnplatform/sync/internal/BootstrapTest.java
index d04cdaa4b..4aeb57ac9 100644
--- a/src/test/java/org/sdnplatform/sync/internal/BootstrapTest.java
+++ b/src/test/java/org/sdnplatform/sync/internal/BootstrapTest.java
@@ -2,7 +2,12 @@ package org.sdnplatform.sync.internal;
 
 import java.io.File;
 import java.util.ArrayList;
+
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
 import net.floodlightcontroller.threadpool.ThreadPool;
 
@@ -59,6 +64,8 @@ public class BootstrapTest {
             syncManagers.add(syncManager);
 
             fmc.addService(IThreadPoolService.class, tp);
+            fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+            fmc.addService(IDebugEventService.class, new MockDebugEventService());
             String dbPath = 
                     new File(dbFolder.getRoot(), 
                              "server" + i).getAbsolutePath();
diff --git a/src/test/java/org/sdnplatform/sync/internal/SyncManagerTest.java b/src/test/java/org/sdnplatform/sync/internal/SyncManagerTest.java
index c9201b479..5bb874c26 100644
--- a/src/test/java/org/sdnplatform/sync/internal/SyncManagerTest.java
+++ b/src/test/java/org/sdnplatform/sync/internal/SyncManagerTest.java
@@ -13,11 +13,16 @@ import java.util.List;
 import java.util.Map.Entry;
 
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
 import net.floodlightcontroller.threadpool.ThreadPool;
 
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -68,6 +73,8 @@ public class SyncManagerTest {
                                     SyncManager syncManager, Node thisNode)
             throws Exception {        
         fmc.addService(IThreadPoolService.class, tp);
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
         fmc.addConfigParam(syncManager, "configProviders", 
                            PropertyCCProvider.class.getName());
         fmc.addConfigParam(syncManager, "nodes", nodeString);
diff --git a/src/test/java/org/sdnplatform/sync/internal/store/RemoteStoreTest.java b/src/test/java/org/sdnplatform/sync/internal/store/RemoteStoreTest.java
index 1ee7f8eef..9ee89bae4 100644
--- a/src/test/java/org/sdnplatform/sync/internal/store/RemoteStoreTest.java
+++ b/src/test/java/org/sdnplatform/sync/internal/store/RemoteStoreTest.java
@@ -4,10 +4,15 @@ import java.util.ArrayList;
 import java.util.List;
 
 import net.floodlightcontroller.core.module.FloodlightModuleContext;
+import net.floodlightcontroller.debugcounter.IDebugCounterService;
+import net.floodlightcontroller.debugcounter.MockDebugCounterService;
+import net.floodlightcontroller.debugevent.IDebugEventService;
+import net.floodlightcontroller.debugevent.MockDebugEventService;
 import net.floodlightcontroller.threadpool.IThreadPoolService;
 import net.floodlightcontroller.threadpool.ThreadPool;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+
 import org.junit.After;
 import org.junit.Before;
 import org.sdnplatform.sync.ISyncService.Scope;
@@ -33,6 +38,8 @@ public class RemoteStoreTest extends AbstractStoreT<ByteArray,byte[]> {
         remoteSyncManager = new RemoteSyncManager();
 
         fmc.addService(IThreadPoolService.class, tp);
+        fmc.addService(IDebugCounterService.class, new MockDebugCounterService());
+        fmc.addService(IDebugEventService.class, new MockDebugEventService());
         fmc.addConfigParam(syncManager, "persistenceEnabled", "false");
         
         tp.init(fmc);
-- 
GitLab