package net.floodlightcontroller.nfvtest.nfvcorestructure;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.Map;
 
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFType;
import org.projectfloodlight.openflow.types.MacAddress;
 
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 net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.userauth.UserAuthException;
import java.util.concurrent.TimeUnit;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.xfer.FileSystemFile;
import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.xml.sax.*;
import org.w3c.dom.*;
 
public class NFVTest implements IOFMessageListener, IFloodlightModule {
 
	protected IFloodlightProviderService floodlightProvider;
	protected Set<Long> macAddresses;
	protected static Logger logger;
	
	@Override
	public String getName() {
	    return NFVTest.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(NFVTest.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 = 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;
     }
 
}
@@ -1016,518 +1016,424 @@
 net.
-schmizz.sshj.SSHClien
+floodlightcontroller.packet.IPacke
 t;%0A
+%0A
 import 
-net.schmizz.sshj.connection.channel.direct.Session;%0Aimport net.schmizz.sshj.userauth.UserAuthException;%0Aimport java.util.concurrent.TimeUnit;%0Aimport net.schmizz.sshj.common.IOUtils;%0Aimport net.schmizz.sshj.xfer.FileSystemFile;%0Aimport java.io.File;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport javax.xml.parsers.*;%0Aimport javax.xml.transform.*;%0Aimport javax.xml.transform.dom.*;%0Aimport javax.xml.transform.stream.*;%0Aimport org.xml.sax.*;%0Aimport org.w3c.dom.*;
+org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport net.floodlightcontroller.packet.ARP;%0Aimport net.floodlightcontroller.packet.Ethernet;%0Aimport net.floodlightcontroller.packet.ICMP;%0Aimport net.floodlightcontroller.packet.IPacket;%0Aimport net.floodlightcontroller.packet.IPv4;%0Aimport net.floodlightcontroller.packet.TCP;%0Aimport net.floodlightcontroller.packet.UDP;%0A%0A
 %0A %0Ap
@@ -3465,16 +3465,439 @@
 YLOAD);%0A
+         IPacket pkt = eth.getPayload(); %0A         %0A         if( pkt instanceof ARP)%7B%0A        %09 logger.info(%22received an arp packet, from %7B%7D, on switch %7B%7D%22, %0A        %09%09%09      eth.getSourceMACAddress(), sw.getId().toString());%0A         %7D%0A         if( pkt instanceof ICMP)%7B%0A        %09 logger.info(%22received an icmp packet, from %7B%7D, on switch %7B%7D%22,%0A        %09%09%09      eth.getSourceMACAddress(), sw.getId().toString());%0A         %7D%0A
   %0A     

test sdn