package net.floodlightcontroller.mactracker;

import java.util.Collection;
import java.util.Map;

import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFType;

import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;

import net.floodlightcontroller.core.IFloodlightProviderService;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.Set;
import net.floodlightcontroller.packet.Ethernet;
import org.openflow.util.HexString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MACTracker implements IOFMessageListener, IFloodlightModule
{
    protected IFloodlightProviderService floodlightProvider;
    protected Set macAddresses;
    protected static Logger logger;

    @Override
    public String getName()
    {
        return MACTracker.class.getSimpleName();
    }

    @Override
    public boolean isCallbackOrderingPrereq(OFType type, String name)
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isCallbackOrderingPostreq(OFType type, String name)
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Collection<Class<? extends IFloodlightService>> getModuleServices()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Collection<Class<? extends IFloodlightService>> getModuleDependencies()
    {
        Collection<Class<? extends IFloodlightService>> l = new ArrayList<Class<? extends IFloodlightService>>();
        l.add(IFloodlightProviderService.class);
        return l;
    }

    @Override
    public void init(FloodlightModuleContext context) throws FloodlightModuleException
    {
        floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
        macAddresses = new ConcurrentSkipListSet<Long>();
        logger = LoggerFactory.getLogger(MACTracker.class);
    }

    @Override
    public void startUp(FloodlightModuleContext context)
    {
        floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
    }

    @Override
    public net.floodlightcontroller.core.IListener.Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx)
    {
        Ethernet eth = IFloodlightProviderService.bcStore.get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD);

        Long sourceMACHash = Ethernet.toLong(eth.getSourceMACAddress());
        if (!macAddresses.contains(sourceMACHash))
        {
            macAddresses.add(sourceMACHash);
            logger.info("MAC Address: {} seen on switch: {}", HexString.toHexString(sourceMACHash), sw.getId());
        }
        return Command.CONTINUE;
    }
}

@@ -1152,32 +1152,88 @@
 getName()%0A    %7B%0A
+        logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D getName%22);%0A
         return M
@@ -1261,24 +1261,24 @@
 mpleName();%0A
-
     %7D%0A%0A    @
@@ -1374,42 +1374,72 @@
     
-// TODO Auto-generated method stub
+logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D isCallbackOrderingPrereq%22);
 %0A   
@@ -1567,42 +1567,73 @@
     
-// TODO Auto-generated method stub
+logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D isCallbackOrderingPostreq%22);
 %0A   
@@ -1769,42 +1769,65 @@
     
-// TODO Auto-generated method stub
+logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D getModuleServices%22);
 %0A   
@@ -1973,42 +1973,63 @@
     
-// TODO Auto-generated method stub
+logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D getServiceImpls%22);
 %0A   
@@ -2148,32 +2148,102 @@
 dencies()%0A    %7B%0A
+        logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D getModuleDependencies%22);%0A
         Collecti
@@ -2517,24 +2517,77 @@
 ption%0A    %7B%0A
+        logger.info(%22%5BDebugInfo%5D%5BMACTracker%5D init%22);%0A
         floo
@@ -2855,32 +2855,87 @@
  context)%0A    %7B%0A
+        logger.info(%22%5BDebugInfo%5D%5BMACTracker%5DstartUp%22);%0A
         floodlig
@@ -3434,16 +3434,16 @@
 CHash);%0A
-
         
@@ -3459,16 +3459,39 @@
 r.info(%22
+%5BDebugInfo%5D%5BMACTracker%5D
 MAC Addr

Add debug info.