Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

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.slf4j.Logger;
import org.slf4j.LoggerFactory;

protected IFloodlightProviderService floodlightProvider;


protected Set<Long> macAddresses;
protected static Logger logger;

@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 String getName() {
return MACTracker.class.getSimpleName();
}

@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 = eth.getSourceMACAddress().getLong();


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

**********************************************
src/main/resources/META-
INF/services/net.floodlightcontroller.core.module.IFloodlightModule ==>
net.floodlightcontroller.mactracker.MACTracker
src/main/resources/floodlightdefault.properties ==> floodlight.modules = <leave
the default list of modules in place>,
net.floodlightcontroller.mactracker.MACTracker

You might also like