Browse Source

AnomalyDetectors added + FloatSensorDevice fixed + added Base Network

camille.peto 4 years ago
parent
commit
5f0c42e129

+ 293 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/anomalydetectors/BaseAnomalyDetector.java

@@ -0,0 +1,293 @@
+/**
+ * 
+ */
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.anomalydetectors;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketSniffer;
+import weka.core.Attribute;
+import weka.core.DenseInstance;
+import weka.core.Instance;
+import weka.core.Instances;
+import weka.core.converters.ArffSaver;
+
+/**
+ * @author Camille Peto
+ *
+ */
+public abstract class BaseAnomalyDetector implements PacketSniffer {
+
+	/**
+	 * True, if instances should be used for training
+	 */
+	protected boolean training = true;
+	
+	/**
+	 * Attributes which should be taken into account
+	 */
+	protected ArrayList<Attribute> atts = new ArrayList<Attribute>();
+	
+	/**
+	 * Collected Packets
+	 */
+	protected Instances dataset;
+	
+	/**
+	 * Number of packets used for number of packets per second
+	 */
+	protected int NUMBER_OF_PACKETS = 30;
+	
+	/**
+	 * HashMap for calculating transmission delay
+	 */
+	protected HashMap<Link, LinkedList<Packet>> lastPackets = new HashMap<Link, LinkedList<Packet>>();
+	
+	protected HashMap<String,Integer> link_mappings = new HashMap<String, Integer>();
+
+	protected HashMap<String,Integer> source_mappings = new HashMap<String, Integer>();
+	
+	protected HashMap<String,Integer> destination_mappings = new HashMap<String, Integer>();
+	
+	protected HashMap<String,Integer> protocol_mappings = new HashMap<String, Integer>();
+	
+	public BaseAnomalyDetector() {
+		link_mappings.put("unknown", 0);
+		atts.add(new Attribute("Link-Name", false));
+		source_mappings.put("unknown", 0);
+		atts.add(new Attribute("Source-Device", false));
+		atts.add(new Attribute("Source-Port-number", false));
+		destination_mappings.put("unknown", 0);
+		atts.add(new Attribute("Destination-Device", false));
+		atts.add(new Attribute("Destination-Port-number", false));
+		protocol_mappings.put("unknown", 0);
+		atts.add(new Attribute("Protocol-name", false));
+		atts.add(new Attribute("Packets-per-second", false));
+		// Initialize data set
+		dataset = new Instances("Packets", atts, 100000);
+	}
+	
+	@Override
+	public void processPackets(HashMap<Link, LinkedList<Packet>> packets) {
+		if(training)
+			try {
+				training(packets);
+			} catch (Exception e) {
+				classify(packets);
+				//e.printStackTrace();
+			}
+	}
+	
+	public void classify(HashMap<Link, LinkedList<Packet>> packets) {
+		for (Iterator<Entry<Link, LinkedList<Packet>>> it = packets.entrySet().iterator(); it.hasNext();) {
+			/**
+			 * Link & its packets
+			 */
+			Entry<Link, LinkedList<Packet>> entry = it.next();
+			/**
+			 * Link the packets were captured on
+			 */
+			Link l = entry.getKey();
+			for (Iterator<Packet> itPacket = entry.getValue().iterator(); itPacket.hasNext();) {
+				/**
+				 * Packet which should be checked
+				 */
+				Packet packet = (Packet) itPacket.next();
+				/**
+				 * Instance Representation
+				 */
+				Instance packet_instance = packet2Instance(l, packet, dataset);
+				try {
+					/**
+					 * Try to classify (find appropriate cluster)
+					 */
+					classifyInstance(packet_instance);
+				} catch (Exception e) {
+					/**
+					 * Anomaly found
+					 */
+					System.out.println("Anomaly: "+packet.getTextualRepresentation());
+					//e.printStackTrace();
+				}
+			}
+		}
+	}
+	/**
+	 * Returns the instance representation of the given packet and link
+	 * @param link link the packet was sent on
+	 * @param packet packet which should be transformed
+	 * @param dataset distribution the packet is part of
+	 * @return instance representation
+	 */
+	protected Instance packet2Instance(Link link, Packet packet, Instances dataset) {
+		/**
+		 * Instance for the given Packet
+		 */
+		DenseInstance instance = new DenseInstance(dataset.numAttributes());
+		instance.setDataset(dataset);
+		
+		// link
+		instance.setValue(0, link == null ? 0 : stringToNumber(link_mappings, link.getName()));
+		
+		// source
+		if(packet.getSource()==null) {
+			instance.setValue(1, 0);
+			instance.setValue(2, Double.NEGATIVE_INFINITY);
+		}else if(packet.getSource().getOwner()==null){
+			instance.setValue(1, 0);
+			instance.setValue(2, packet.getSource().getPortNumber());
+		}else {
+			instance.setValue(1, stringToNumber(source_mappings, packet.getSource().getOwner().getName()));
+			instance.setValue(2, packet.getSource().getPortNumber());
+		}
+		
+		// Destination
+		if(packet.getDestination()==null) {
+			instance.setValue(3, 0);
+			instance.setValue(4, Double.NEGATIVE_INFINITY);
+		}else if(packet.getDestination().getOwner()==null){
+			instance.setValue(3, 0);
+			instance.setValue(4, packet.getDestination().getPortNumber());
+		}else {
+			instance.setValue(3, stringToNumber(destination_mappings, packet.getDestination().getOwner().getName()));
+			instance.setValue(4, packet.getDestination().getPortNumber());
+		}
+		
+		// Protocol name
+		instance.setValue(5, stringToNumber(protocol_mappings, packet.getProtocolName()));
+		
+		// Packets per second
+		instance.setValue(6, getEstimatedPacketsPerSecond(link, packet));
+		
+		return instance;
+	}
+	
+	/**
+	 * Transforms the String into an Number
+	 * @param map
+	 * @param s
+	 * @return
+	 */
+	double stringToNumber(HashMap<String, Integer> map, String s) {
+		Integer i = map.get(s);
+		if(i == null) {
+			int size = map.size();
+			map.put(s, size);
+			return size;
+		}else {
+			return i;
+		}
+	}
+	
+	/**
+	 * Estimates the current Packets per second (depending on the last 100 packets of the link)
+	 * @param link Link which should be checked
+	 * @param packet Packet which should investigated
+	 * @return estimated number of packets per second
+	 */
+	protected double getEstimatedPacketsPerSecond(Link link, Packet packet) {
+		/**
+		 * Packets used to calculated the packets per second
+		 */
+		LinkedList<Packet> list = lastPackets.get(link);
+		if(list == null) {
+			/**
+			 * Add list if not present
+			 */
+			list = new LinkedList<Packet>();
+			lastPackets.put(link, list);
+		}
+		if(list.isEmpty()) {
+			list.addLast(packet);
+			// Default 1 packet per second
+			return 1.0;
+		}
+		if(list.size() == NUMBER_OF_PACKETS){
+			list.removeFirst();	
+		}
+		list.addLast(packet);
+		/**
+		 * elapsed time in milliseconds since last packet
+		 */
+		long elapsed_time = packet.getTimestamp()-list.getFirst().getTimestamp()/list.size();
+		if(elapsed_time<=0)
+			return Double.POSITIVE_INFINITY;
+		/**
+		 * Return number of packets per second
+		 */
+		return 1000.0/elapsed_time;
+		
+	}
+	
+	@Override
+	public void setMode(boolean testing) {
+		training = !testing;
+		if(testing) {
+			try {
+				finishDataCollection();
+			} catch (Exception e) {
+				System.out.println("Clustering/Classifing failed");
+				e.printStackTrace();
+			}	
+		}
+	}
+
+	@Override
+	public boolean getMode() {
+		return !training;
+	}
+
+	/**
+	 * Collect the packets
+	 * 
+	 * @param packets packets to be learned
+	 */
+	protected void training(HashMap<Link, LinkedList<Packet>> packets) {
+		for (Iterator<Entry<Link, LinkedList<Packet>>> it = packets.entrySet().iterator(); it.hasNext();) {
+			Entry<Link, LinkedList<Packet>> entry = it.next();
+			/**
+			 * Link the packet was captured on
+			 */
+			Link l = entry.getKey();
+			for (Iterator<Packet> itPacket = entry.getValue().iterator(); itPacket.hasNext();) {
+				/**
+				 * Packets to be added to the dataset
+				 */
+				Packet packet = (Packet) itPacket.next();
+				dataset.add(packet2Instance(l, packet, dataset));
+			}
+		}
+	}
+	
+	/**
+	 * Finishes the collection and trains the clusterer on the collected packets
+	 * 
+	 * @throws Exception
+	 */
+	private void finishDataCollection() throws Exception{
+		/**
+		 * Build the clusterer for the given dataset
+		 */
+		/*ArffSaver saver = new ArffSaver();
+		saver.setInstances(dataset);
+		saver.setFile(new File("./data/test.arff"));
+		saver.writeBatch();
+		*/
+		trainModel(dataset);
+	}
+	
+	/**
+	 * Train the model using the given instances
+	 * @param instances training set, which should be learned
+	 */
+	public abstract void trainModel(Instances instances);
+	
+	public abstract void classifyInstance(Instance instance);
+}

+ 52 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/anomalydetectors/DecisionTreeAnomalyDetector.java

@@ -0,0 +1,52 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.anomalydetectors;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import weka.classifiers.trees.J48;
+import weka.core.Instance;
+import weka.core.Instances;
+
+public class DecisionTreeAnomalyDetector extends BaseAnomalyDetector {
+
+	/**
+	 * Classifier
+	 */
+	private J48 decisionTree;
+	
+	/**
+	 * Try to classify the given packets and detect anomalies
+	 * @param packets packets to be classified
+	 */
+	@Override
+	public void classifyInstance(Instance instance) {
+		
+		try {
+			decisionTree.classifyInstance(instance);
+		} catch (Exception e) {
+			System.out.println("Decision Tree Instance classifing failed");
+			e.printStackTrace();
+		}
+				
+	}
+	
+	/**
+	 * Train the model using the given instances
+	 * @param instances training set, which should be learned
+	 * 
+	 */
+	@Override
+	public void trainModel(Instances instances) {
+		try {
+			
+			decisionTree.buildClassifier(instances);
+		} catch (Exception e) {
+			System.out.println("Decision Tree classifing failed");
+			e.printStackTrace();
+		}
+	}
+}

+ 66 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/anomalydetectors/KMeansAnomalyDetector.java

@@ -0,0 +1,66 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.anomalydetectors;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import weka.clusterers.SimpleKMeans;
+import weka.core.Instance;
+import weka.core.Instances;
+import weka.core.SelectedTag;
+
+public class KMeansAnomalyDetector extends BaseAnomalyDetector {
+
+	/**
+	 * Clusterer
+	 */
+	private SimpleKMeans clusterer;
+	
+	protected int NUMBER_OF_CLUSTERS = 34;
+	
+	public KMeansAnomalyDetector() {
+		super();
+		// Initialize Clusterer
+		clusterer = new SimpleKMeans();
+		clusterer.setSeed(42);
+		clusterer.setInitializationMethod(new SelectedTag(SimpleKMeans.FARTHEST_FIRST,SimpleKMeans.TAGS_SELECTION));
+		try {
+			clusterer.setNumClusters(NUMBER_OF_CLUSTERS);
+		} catch (Exception e) {
+			System.out.println("Error while building cluster");
+			e.printStackTrace();
+		}
+	}
+	/**
+	 * Try to classify the given packets and detect anomalies
+	 * @param packets packets to be classified
+	 */
+	@Override
+	public void classifyInstance(Instance instance) {
+		
+		try {
+			clusterer.clusterInstance(instance);
+		} catch (Exception e) {
+			System.out.println("Kmeans Instance clustering failed");
+			e.printStackTrace();
+		}
+				
+	}
+	
+	/**
+	 * Train the model using the given instances
+	 * @param instances training set, which should be learned
+	 */
+	@Override
+	public void trainModel(Instances instances) {
+		try {
+			clusterer.buildClusterer(instances);
+		} catch (Exception e) {
+			System.out.println("Kmeans clustering failed");
+			e.printStackTrace();
+		}
+	}
+}

+ 49 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/anomalydetectors/NNAnomalyDetector.java

@@ -0,0 +1,49 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.anomalydetectors;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import weka.classifiers.functions.MultilayerPerceptron;
+import weka.core.Instance;
+import weka.core.Instances;
+
+public class NNAnomalyDetector extends BaseAnomalyDetector {
+	/**
+	 * Classifier
+	 */
+	private MultilayerPerceptron mlp;
+	
+	/**
+	 * Try to classify the given packets and detect anomalies
+	 * @param packets packets to be classified
+	 */
+	@Override
+	public void classifyInstance(Instance instance) {
+		
+		try {
+			mlp.classifyInstance(instance);
+		} catch (Exception e) {
+			System.out.println("NN Instance classifing failed");
+			e.printStackTrace();
+		}
+				
+	}	
+	
+	/**
+	 * Train the model using the given instances
+	 * @param instances training set, which should be learned
+	 */
+	@Override
+	public void trainModel(Instances instances) {
+		try {
+			mlp.buildClassifier(instances);;
+		} catch (Exception e) {
+			System.out.println("NN classifing failed");
+			e.printStackTrace();
+		}
+	}
+}

+ 51 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/anomalydetectors/SVMAnomalyDetector.java

@@ -0,0 +1,51 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.anomalydetectors;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import weka.classifiers.functions.SMO;
+import weka.core.Instance;
+import weka.core.Instances;
+
+public class SVMAnomalyDetector extends BaseAnomalyDetector {
+
+
+	/**
+	 * Classifier
+	 */
+	private SMO svm;
+	
+	/**
+	 * Try to classify the given packets and detect anomalies
+	 * @param packets packets to be classified
+	 */
+	@Override
+	public void classifyInstance(Instance instance) {
+		
+		try {
+			svm.classifyInstance(instance);
+		} catch (Exception e) {
+			System.out.println("SVM Instance classifing failed");
+			e.printStackTrace();
+		}
+				
+	}		
+	
+	/**
+	 * Train the model using the given instances
+	 * @param instances training set, which should be learned
+	 */
+	@Override
+	public void trainModel(Instances instances) {
+		try {
+			svm.buildClassifier(instances);
+		} catch (Exception e) {
+			System.out.println("SVM classifing failed");
+			e.printStackTrace();
+		}
+	}
+}

+ 8 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/anomalydetectors/package-info.java

@@ -0,0 +1,8 @@
+/**
+ * 
+ */
+/**
+ * @author CamillesPC
+ *
+ */
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.anomalydetectors;

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/FloatSensorDevice.java

@@ -120,7 +120,7 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
 	public void simulateEvent(long time) {
 		updateData();
 		//Update again in 10 seconds
-		nextSimulationTime=time *10000;
+		nextSimulationTime=time +10000;
 		SimulationManager.scheduleEvent(this);
 	}
 	

+ 122 - 4
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarNetworkExamples.java

@@ -86,10 +86,17 @@ public class MenuBarNetworkExamples extends JMenu{
 		/**
 		 * MQTT example
 		 */
-		JMenuItem mnMQTT = new JMenuItem("MQTT Example");
-		mnMQTT.addActionListener(a->initializeMQTTTest());
-		this.add(mnMQTT);
+		JMenuItem mnMQTT_A = new JMenuItem("MQTT Example");
+		mnMQTT_A.addActionListener(a->initializeMQTTTest_A());
+		this.add(mnMQTT_A);
 		
+		/**
+		 * MQTT example
+		 */
+		JMenuItem mnMQTT = new JMenuItem("MQTT Base Network");
+		mnMQTT.addActionListener(a->initializeMQTTBaseNetwork());
+		this.add(mnMQTT);
+
 		/**
 		 * Small Network Test
 		 */
@@ -293,7 +300,7 @@ public class MenuBarNetworkExamples extends JMenu{
 	/**
 	 * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
 	 */
-	private void initializeMQTTTest(){
+	private void initializeMQTTTest_A(){
 		SimpleLink link = new SimpleLink("WIFI");
 		link.setFixedDelay(5);
 		
@@ -425,6 +432,117 @@ public class MenuBarNetworkExamples extends JMenu{
 		}
 	}
 	
+	private void initializeMQTTBaseNetwork(){
+		SimpleLink link = new SimpleLink("WIFI");
+		link.setFixedDelay(5);
+		short portNumber = 0;
+
+		//Setup Smarthome Hub
+		SmartDevice broker = new SmartDevice("Hub (Broker)");
+		broker.setX((int)(settingsController.getWidth()/2));
+		broker.setY((int)(settingsController.getHeight()/2));
+		networkController.addSmartDevice(broker);
+		
+		Port brokerPort = new Port(broker, portNumber, 987);
+		brokerPort.setLastTrigger(0);
+		brokerPort.setStatus(Port.OPEN);		
+		broker.addPort(brokerPort);
+		
+		link.addDevice(broker);
+		broker.addLink(link);
+		
+		Protocol protocol = new MQTT_protocol(brokerPort);
+		
+		Connection con = new ConnectionPrecision(link, protocol);
+		con.setPacketLossProbability(0.01);//1% Packet loss probability
+		con.addSmartDevice(brokerPort);
+		brokerPort.setConnection(con);
+		con.setStatus(Connection.ACTIVE);
+		networkController.addLink(link);
+		link.addConnection(con);
+		networkController.addConnection(con);
+
+		//Add Thermostat (only publishes measured roomtemparature)
+		FloatSensorDevice thermostat = new FloatSensorDevice("Thermostat (Pub)");	
+		thermostat.setFSinfoName("temperature");
+		thermostat.setFSval(24);
+		thermostat.setX((int) settingsController.getWidth()*2/4);
+		thermostat.setY((int) settingsController.getHeight()/4);
+		thermostat.addLink(link);
+		link.addDevice(thermostat);
+
+		Port pthermostat = new Port(thermostat,++portNumber, 100+(int)(Math.random()*900));
+		pthermostat.setLastTrigger(0);
+		pthermostat.setJitter((short) (Math.random()*50));
+		pthermostat.setStatus(Port.SENDING);
+		pthermostat.setConnection(con);
+		protocol.addDeviceOfRole(pthermostat, 2);
+		con.addSmartDevice(pthermostat);
+		thermostat.addPort(pthermostat);
+
+		networkController.addSmartDevice(thermostat);
+
+		//Add Smart heater (only subscribes)
+		FloatCollectorDevice smartHeater = new FloatCollectorDevice("Heater (Sub)");	
+		smartHeater.setFCinfoName("temperature");
+		smartHeater.setX((int) settingsController.getWidth()*4/6);
+		smartHeater.setY((int) settingsController.getHeight()*4/6);
+		link.addDevice(smartHeater);
+		smartHeater.addLink(link);
+			
+		Port pSmartHeater = new Port(smartHeater,++portNumber,100+(int)(Math.random()*900));
+		pSmartHeater.setLastTrigger(0);
+		pSmartHeater.setJitter((short) (Math.random()*50));
+		pSmartHeater.setStatus(Port.SENDING);
+		pSmartHeater.setConnection(con);
+		protocol.addDeviceOfRole(pSmartHeater, 3);
+		con.addSmartDevice(pSmartHeater);
+		smartHeater.addPort(pSmartHeater);
+		
+		networkController.addSmartDevice(smartHeater);
+
+		//Add smart light  (subscriber)
+		BoolCollectorDevice light_sub = new BoolCollectorDevice("Light (Sub)");	
+		light_sub.setBCinfoName("LightOn");
+		light_sub.setX((int) settingsController.getWidth()/6);
+		light_sub.setY((int) settingsController.getHeight()/4);
+		light_sub.addLink(link);
+		link.addDevice(light_sub);
+
+		Port plight_sub = new Port(light_sub,++portNumber, 100+(int)(Math.random()*900));
+		plight_sub.setLastTrigger(0);
+		plight_sub.setJitter((short) (Math.random()*50));
+		plight_sub.setStatus(Port.SENDING);
+		plight_sub.setConnection(con);
+		protocol.addDeviceOfRole(plight_sub,3);
+		con.addSmartDevice(plight_sub);
+		light_sub.addPort(plight_sub);
+
+		networkController.addSmartDevice(light_sub);
+
+		//Add smart light (publisher)
+		BoolSensorDevice light_pub = new BoolSensorDevice("Light (Pub)");	
+		light_pub.setBSinfoName("LightOn");
+		light_pub.setBSval(false);
+		light_pub.setX((int) settingsController.getWidth()/4);
+		light_pub.setY((int) settingsController.getHeight()/4);
+		light_pub.addLink(link);
+		link.addDevice(light_pub);
+
+		Port plight_pub = new Port(light_pub,++portNumber, 100+(int)(Math.random()*900));
+		plight_pub.setLastTrigger(0);
+		plight_pub.setJitter((short) (Math.random()*50));
+		plight_pub.setStatus(Port.SENDING);
+		plight_pub.setConnection(con);
+		protocol.addDeviceOfRole(plight_pub, 2);
+		con.addSmartDevice(plight_pub);
+		light_pub.addPort(plight_pub);
+
+		networkController.addSmartDevice(light_pub);
+		  
+		controller.notifyObservers();
+	}
+	
 	/**
 	 * Creates the paper toy example, also simulates it, if run = true
 	 * @param run

+ 767 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarNetworkExamples_old.java

@@ -0,0 +1,767 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.menuBar;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map.Entry;
+
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ExampleAnomalyController;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ImportController;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.PacketCaptureController;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionPerformance;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionPrecision;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketCollector;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketSniffer;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PrecisionLink;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolCollectorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollectorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.distributionHandler.NormalDistributionHandler;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.CountingMetric;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.Manipulation_RandomMove;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
+
+public class MenuBarNetworkExamples_old extends JMenu{
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Controller controller
+	 */
+	private Controller controller;
+	
+	/**
+	 * Controller for editing the network
+	 */
+	private NetworkController networkController;
+	
+	/**
+	 * Controller to insert anomalies
+	 */
+	private ExampleAnomalyController anomalyController;
+	
+	/**
+	 * Controller for configuration of the program
+	 */
+	private SettingsController settingsController;
+	
+	/**
+	 * SimulationController for running the simulation
+	 */
+	private SimulationController simulationController;
+
+	/**
+	 * Creates the JMenu for network examples in the MenuBar
+	 * @param controller controller to create examples
+	 */
+	public MenuBarNetworkExamples_old(Controller controller) {
+		super("Create example Network");
+		
+		this.controller = controller;
+		this.networkController = controller.getNetworkController();
+		this.anomalyController = networkController.getAnomalyController();
+		this.settingsController = controller.getSettingsController();
+		this.simulationController = controller.getSimulationController();
+		
+		/**
+		 * MQTT example
+		 */
+		JMenuItem mnMQTT = new JMenuItem("MQTT Example");
+		mnMQTT.addActionListener(a->initializeMQTTTest());
+		this.add(mnMQTT);
+		
+		/**
+		 * Small Network Test
+		 */
+		JMenuItem mnTest = new JMenuItem("Network Example");
+		mnTest.addActionListener(a->initializeTest());
+		this.add(mnTest);
+		
+		/**
+		 * Performance Comparison Example
+		 */
+		JMenuItem mnPerformance = new JMenuItem("Performane Evaluation Preset");
+		mnPerformance.addActionListener(a->initializePerformanceTest());
+		this.add(mnPerformance);
+		
+		/**
+		 * User Study Preset
+		 */
+		JMenuItem mnUserStudy = new JMenuItem("User Study Preset");
+		mnUserStudy.addActionListener(a->initializeUserStudy());
+		this.add(mnUserStudy);
+		
+		/**
+		 * Packet Collection example
+		 */
+		JMenuItem mnPacketCollectionExmample = new JMenuItem("Packet Collection Example");
+		mnPacketCollectionExmample.addActionListener(a->testPackageCollection());
+		this.add(mnPacketCollectionExmample);
+		
+		/**
+		 * Paper example
+		 */
+		JMenuItem mnPaperExample = new JMenuItem("Paper Example");
+		mnPaperExample.addActionListener(a->createPaperExample(false));
+		this.add(mnPaperExample);
+		
+		/**
+		 * Paper example + run
+		 */
+		JMenuItem mnRunPaperExample = new JMenuItem("Run Paper Example");
+		mnRunPaperExample.addActionListener(a->createPaperExample(true));
+		this.add(mnRunPaperExample);
+	}
+
+	private void initializePerformanceTest(){
+		SmartDevice tic = new SmartDevice("Tic");
+		tic.setX(100);
+		tic.setY(100);
+		SmartDevice toc = new SmartDevice("Toc");
+		toc.setX(100);
+		toc.setY(250);
+		networkController.addSmartDevice(tic);
+		networkController.addSmartDevice(toc);
+		
+		Link l = new PrecisionLink("Channel");
+		networkController.addLink(l);
+		networkController.addLinkToDevice(l, tic);
+		networkController.addLinkToDevice(l, toc);
+
+		Port ticP = new Port(tic, (short)2, 200, (short)0, 0, (short)0);
+		Port tocP = new Port(toc, (short)3, 200, (short)0, -100, (short)0);
+		tic.addPort(ticP);
+		toc.addPort(tocP);
+		
+		Connection con = new ConnectionPrecision(l, new SimpleProtocol());
+		networkController.addConnection(con);
+		networkController.addConnectionToLink(con, l);
+		networkController.addDeviceToConnectionAndProtocol(ticP, con, 0);
+		networkController.addDeviceToConnectionAndProtocol(tocP, con, 1);
+		
+		simulationController.setStepDuration(100000000);
+		simulationController.setEndTime(1000000000);
+		controller.notifyObservers();
+	}
+	
+	/**
+	 * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
+	 */
+	private void initializeUserStudy(){
+		/**
+		 * Preset one SmartDevice
+		 */
+		SmartDevice A = new SmartDevice("Homestation");
+		A.setX(200);
+		A.setY(200);
+		networkController.addSmartDevice(A);
+		/**
+		 * Packagecollector, which is registered at the Device
+		 */
+		PacketCollector collector = new PacketCollector(new CountingMetric());
+		simulationController.getPacketCaptureController().addPacketCollector(collector);
+		simulationController.getPacketCaptureController().addDeviceToCollector(collector, A);
+		simulationController.setPrintPackets(true);
+		controller.notifyObservers();
+	}
+	
+	/**
+	 * Test package collectors
+	 */
+	private void testPackageCollection() {
+		if(networkController.getSmartDevices().size()<3)
+			return;
+		simulationController.addAlgorithm(new Manipulation_RandomMove(), controller);
+	    PacketCollector collector = new PacketCollector();
+	    simulationController.getSimulationManager().getPacketCollectionManager().addPacketCollector(collector);
+	    
+	    System.out.println("Collector 0-500 - nothing collected:");
+	    simulationController.getSimulationManager().simulateTimeIntervall(0, 500);
+	    HashMap<Link, LinkedList<Packet>> map = collector.getPackets();
+	    for(Entry<Link, LinkedList<Packet>> e:map.entrySet()){
+	    	System.out.println("Link: "+e.getKey().getName());
+	    	for(Packet p : e.getValue())
+	    		System.out.println(p.getTextualRepresentation());
+	    }
+	    
+	    System.out.println("");
+	    System.out.println("");
+	    Iterator<SmartDevice> it = networkController.getSmartDevices().iterator();
+	    it.next();
+	    
+	    SmartDevice d = it.next();
+	    collector.addDevice(d);
+	    SmartDevice f = it.next();
+	    collector.addDevice(f);
+	    System.out.println("Collector 500-1000 - "+d.getName()+" & "+f.getName()+" collected:");
+	    simulationController.getSimulationManager().simulateTimeIntervall(500, 500);
+	    map = collector.getPackets();
+	    for(Entry<Link, LinkedList<Packet>> e:map.entrySet()){
+	    	System.out.println("Link: "+e.getKey().getName());
+	    	for(Packet p : e.getValue())
+	    		System.out.println(p.getTextualRepresentation());
+	    }
+
+	    System.out.println("");
+	    System.out.println("");
+	    
+	    Link l = networkController.getLinks().iterator().next();
+	    collector.addLink(l);
+	    System.out.println("Collector 2000-3000 - "+l+" collected:");
+	    simulationController.getSimulationManager().simulateTimeIntervall(1000, 500);
+	    map = collector.getPackets();
+	    for(Entry<Link, LinkedList<Packet>> e:map.entrySet()){
+	    	System.out.println("Link: "+e.getKey().getName());
+	    	for(Packet p : e.getValue())
+	    		System.out.println(p.getTextualRepresentation());
+	    }
+	    simulationController.resetSimulation();
+		controller.notifyObservers();
+	}
+	
+	/**
+	 * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
+	 */
+	private void initializeTest(){
+		SmartDevice A = null, B = null, C = null;
+		for(int i = 0; i<5; i++){
+			A = new SmartDevice("SmartTV"+i);		
+			A.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			A.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			B = new SmartDevice("SmartDoor"+i);
+			B.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			B.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			C = new SmartDevice("SmartLight"+i);
+			C.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			C.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+		
+			networkController.addSmartDevice(A);
+			networkController.addSmartDevice(B);
+			networkController.addSmartDevice(C);
+		}
+		
+		Link link = new SimpleLink("SimpleWifi");
+		link.addDevice(A);
+		link.addDevice(B);
+		link.addDevice(C);
+		A.addLink(link);
+		B.addLink(link);
+		C.addLink(link);
+		
+		Port a = new Port(A, (short) 1, 68);
+		a.setLastTrigger(0);
+		a.setStatus(Port.SENDING);
+		A.addPort(a);
+		Port b = new Port(B, (short) 2, 102);
+		b.setStatus(Port.SENDING);
+		B.addPort(b);
+		
+		Connection s = new ConnectionPerformance(link, new SimpleProtocol(a, b));
+		s.setPacketLossProbability(0.01);//1% Packet loss probability
+		a.setConnection(s);
+		b.setConnection(s);
+		s.addSmartDevice(a);
+		s.addSmartDevice(b);
+
+		link.addConnection(s);
+		
+		networkController.addLink(link);
+		networkController.addConnection(s);
+		controller.notifyObservers();
+	}
+	
+	/**
+	 * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
+	 */
+	private void initializeMQTTTest(){
+		SimpleLink link = new SimpleLink("WIFI");
+		link.setFixedDelay(5);
+		
+		SmartDevice broker = new SmartDevice("MQTT-Broker");
+		broker.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+		broker.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+		networkController.addSmartDevice(broker);
+		
+		Port brokerPort = new Port(broker, (short) 0, 987);
+		brokerPort.setLastTrigger(0);
+		brokerPort.setStatus(Port.OPEN);		
+		broker.addPort(brokerPort);
+		
+		link.addDevice(broker);
+		broker.addLink(link);
+		
+		Protocol protocol = new MQTT_protocol(brokerPort);
+		
+		Connection con = new ConnectionPrecision(link, protocol);
+		con.setPacketLossProbability(0.01);//1% Packet loss probability
+		con.addSmartDevice(brokerPort);
+		brokerPort.setConnection(con);
+		con.setStatus(Connection.ACTIVE);
+		networkController.addLink(link);
+		link.addConnection(con);
+		networkController.addConnection(con);
+		
+		SmartDevice A = null, A1 = null, A2 = null, B = null, C = null;
+		Port aP,a1P,a2P,bP,cP;
+		for(int i = 0; i<3; i++){
+			FloatSensorDevice aS = new FloatSensorDevice("SmartThermostat"+i+"(Pub)");	
+			aS.setFSinfoName("room"+i+"/temperature");
+			A=aS;
+			A.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			A.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(A);
+			A.addLink(link);
+			
+			aP = new Port(A,((short) (3*i+1)),100+(int)(Math.random()*900));
+			aP.setLastTrigger(0);
+			aP.setJitter((short) (Math.random()*50));
+			aP.setStatus(Port.SENDING);
+			aP.setConnection(con);
+			protocol.addDeviceOfRole(aP, 2);
+			con.addSmartDevice(aP);
+			A.addPort(aP);
+			
+			networkController.addSmartDevice(A);
+			
+			
+			FloatCollectorDevice aS1 = new FloatCollectorDevice("SmartAirCondition"+i+"(Sub)");	
+			aS1.setFCinfoName("room"+i+"/temperature");
+			A1=aS1;
+			A1.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			A1.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(A1);
+			A1.addLink(link);
+			
+			a1P = new Port(A1,((short) (3*i+1)),100+(int)(Math.random()*900));
+			a1P.setLastTrigger(0);
+			a1P.setJitter((short) (Math.random()*50));
+			a1P.setStatus(Port.SENDING);
+			a1P.setConnection(con);
+			protocol.addDeviceOfRole(a1P, 3);
+			con.addSmartDevice(a1P);
+			A1.addPort(a1P);
+			
+			networkController.addSmartDevice(A1);
+			
+			
+			FloatCollectorDevice aS2 = new FloatCollectorDevice("SmartHeater"+i+"(Sub)");	
+			aS2.setFCinfoName("room"+i+"/temperature");
+			A2=aS2;
+			A2.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			A2.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(A2);
+			A2.addLink(link);
+			
+			a2P = new Port(A2,((short) (3*i+1)),100+(int)(Math.random()*900));
+			a2P.setLastTrigger(0);
+			a2P.setJitter((short) (Math.random()*50));
+			a2P.setStatus(Port.SENDING);
+			a2P.setConnection(con);
+			protocol.addDeviceOfRole(a2P, 3);
+			con.addSmartDevice(a2P);
+			A2.addPort(a2P);
+			
+			networkController.addSmartDevice(A2);
+			
+			
+			
+			
+			B = new BoolSensorDevice("SmartDoor"+i+"(Pub)");
+			((BoolSensorDevice)B).setBSinfoName("room"+i+"/DoorOpen");
+			B.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			B.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(B);
+			B.addLink(link);
+			
+			bP = new Port(B,((short) (3*i+2)),10+(int)(Math.random()*190));
+			bP.setLastTrigger(0);
+			bP.setJitter((short) (Math.random()*50));
+			bP.setStatus(Port.SENDING);
+			bP.setConnection(con);
+			protocol.addDeviceOfRole(bP, 2);
+			con.addSmartDevice(bP);
+			B.addPort(bP);
+			
+			networkController.addSmartDevice(B);
+			
+			C = new BoolCollectorDevice("SmartDoorStatusLight"+i+"(Sub)");
+			((BoolCollectorDevice)C).setBCinfoName("room"+i+"/DoorOpen");
+			C.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			C.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
+			link.addDevice(C);
+			C.addLink(link);
+			
+			cP = new Port(C,((short) (3*i+1)), 50+(int)(Math.random()*450));
+			cP.setLastTrigger(0);
+			cP.setJitter((short) (Math.random()*50));
+			cP.setStatus(Port.SENDING);
+			cP.setConnection(con);
+			protocol.addDeviceOfRole(cP, 3);
+			con.addSmartDevice(cP);
+			C.addPort(cP);
+			
+			networkController.addSmartDevice(C);
+			controller.notifyObservers();
+		}
+	}
+	
+	/**
+	 * Creates the paper toy example, also simulates it, if run = true
+	 * @param run
+	 */
+	@SuppressWarnings("unchecked")
+	public void createPaperExample(boolean run){
+		/**
+		 * Reset network, etc.
+		 */
+		if(run) {
+			controller.getSimulationController().resetSimulation();
+			controller.getNetworkController().deleteNetworkModel();
+		}
+		/*
+		 * Main networking devices 
+		 */
+		SmartDevice router = networkController.createSmartDevice("Wifi-Router", 500, 100, 50);
+		SmartDevice zigBeeRouter = networkController.createSmartDevice("ZigBee-Router", 500, 300, 50);
+		SmartDevice broker = networkController.createSmartDevice("SmartHub", 500, 500, 50);
+		
+		/*
+		 * Links/Networks
+		 */
+		Link wifi = new PrecisionLink("Wifi");
+		networkController.addLink(wifi);
+		Link zigbee = new PrecisionLink("ZigBee");
+		networkController.addLink(zigbee);
+		
+		/*
+		 * Connect Devices to Links
+		 */
+		networkController.addLinkToDevice(wifi, router);
+		networkController.addLinkToDevice(wifi, zigBeeRouter);
+		networkController.addLinkToDevice(zigbee, zigBeeRouter);
+		networkController.addLinkToDevice(zigbee, broker);
+		
+		/*
+		 * Internet Access Connection 
+		 */
+		Connection inetAcces = new ConnectionPrecision();
+		inetAcces.setName("Cloud  Access");
+		networkController.addConnectionToLink(inetAcces, wifi);
+		inetAcces.setProtocol(new SimpleProtocol());
+		Port pRouter = new Port(router, (short)80, 500L);
+		pRouter.setTriggerHandler(new NormalDistributionHandler(500, 100));
+		networkController.addDeviceToConnectionAndProtocol(pRouter, inetAcces, 0);
+		Port pZigBee = new Port(zigBeeRouter, (short)80, 1000L);
+		pZigBee.setTriggerHandler(new NormalDistributionHandler(1000, 300));
+		networkController.addDeviceToConnectionAndProtocol(pRouter, inetAcces, 0);
+		networkController.addDeviceToConnectionAndProtocol(pZigBee, inetAcces, 1);
+		networkController.addConnection(inetAcces);
+		
+		/*
+		 * ZigbeeRouter -> Broker ? 
+		 */
+		Connection homeAutomationInternetAccess = new ConnectionPrecision();
+		homeAutomationInternetAccess.setName("Home Automation Webinterface");
+		networkController.addConnectionToLink(homeAutomationInternetAccess, zigbee);
+		homeAutomationInternetAccess.setProtocol(new SimpleProtocol());
+		Port pBrokerWebInterface = new Port(broker, (short)80);
+		pBrokerWebInterface.setTriggerHandler(new NormalDistributionHandler(2000, 500));
+		pBrokerWebInterface.setStatus(Port.SENDING);
+		pBrokerWebInterface.setResponseTime((short)2);
+		pBrokerWebInterface.setLastTrigger(-284L);
+		networkController.addDeviceToConnectionAndProtocol(pBrokerWebInterface, homeAutomationInternetAccess, 0);
+		networkController.addConnection(homeAutomationInternetAccess);
+		Port pRouterWebInterface = new Port(zigBeeRouter, (short)80);
+		pRouterWebInterface.setTriggerHandler(new NormalDistributionHandler(5000, 3000));
+		pRouterWebInterface.setStatus(Port.SENDING);
+		pRouterWebInterface.setResponseTime((short)2);
+		pRouterWebInterface.setLastTrigger(-142L);
+		networkController.addDeviceToConnectionAndProtocol(pRouterWebInterface, homeAutomationInternetAccess, 1);
+		networkController.addConnection(homeAutomationInternetAccess);
+		
+		
+		/*
+		 * Create MQTT Connection
+		 */
+		Connection mqtt = new ConnectionPrecision();
+		mqtt.setName("Automation (MQTT)");
+		networkController.addConnectionToLink(mqtt, zigbee);
+		mqtt.setProtocol(new MQTT_protocol());
+		Port pBroker = new Port(broker, (short)1883);
+		pBroker.setStatus(Port.OPEN);
+		pBroker.setResponseTime((short)2);
+		networkController.addDeviceToConnectionAndProtocol(pBroker, mqtt, 0);
+		networkController.addConnection(mqtt);
+		
+		/*
+		 * Add some MQTT Devices
+		 */
+		
+		/**
+		 * Kitchen Thermostat
+		 */
+		FloatSensorDevice floatSensor = new FloatSensorDevice("Kitchen Thermostat");
+		floatSensor.setFSinfoName("home/kitchen/temperature");
+		networkController.addLinkToDevice(zigbee, floatSensor);
+		networkController.moveSmartDevice(floatSensor, 300, 500, 50);
+		floatSensor.setFSmin(15.0f);
+		floatSensor.setFSmax(32.0f);
+		networkController.addSmartDevice(floatSensor);
+		Port pFloatSensor = new Port(floatSensor, (short)1883, 15000);
+		pFloatSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
+		pFloatSensor.setStatus(Port.SENDING);
+		pFloatSensor.setLastTrigger(-357L);
+		networkController.addDeviceToConnectionAndProtocol(pFloatSensor, mqtt,1);
+		
+		/*
+		 * Add Fridge
+		 */
+		FloatSensorDevice kitchenFridge = new FloatSensorDevice("Smart Fridge");
+		kitchenFridge.setFSinfoName("home/kitchen/fridgeTemp");
+		networkController.addLinkToDevice(zigbee, kitchenFridge);
+		networkController.moveSmartDevice(kitchenFridge, 100, 600, 50);
+		kitchenFridge.setFSmin(-6.0f);
+		kitchenFridge.setFSmax(-4.0f);
+		networkController.addSmartDevice(kitchenFridge);
+		Port pKitchenFridge = new Port(kitchenFridge, (short)1883, 15000);
+		pKitchenFridge.setStatus(Port.SENDING);
+		pKitchenFridge.setTriggerHandler(new NormalDistributionHandler(15000, 500));
+		pKitchenFridge.setLastTrigger(-1231L);
+		networkController.addDeviceToConnectionAndProtocol(pKitchenFridge, mqtt,1);
+		
+		
+		/*
+		 * Add some kitchen lights
+		 */
+		BoolSensorDevice kitchenLight = new BoolSensorDevice("Kitchen Light");
+		kitchenLight.setBSinfoName("home/kitchen/light");
+		networkController.addLinkToDevice(zigbee, kitchenLight);
+		networkController.moveSmartDevice(kitchenLight, 250, 400, 50);
+		networkController.addSmartDevice(kitchenLight);
+		Port pKitchenLight = new Port(kitchenLight, (short)1883, 15000);
+		pKitchenLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
+		pKitchenLight.setStatus(Port.SENDING);
+		pKitchenLight.setLastTrigger(-1207L);
+		networkController.addDeviceToConnectionAndProtocol(pKitchenLight, mqtt,1);
+		
+		//TODO Further devices & Connections
+		
+		/*
+		 * Bedroom
+		 */
+		BoolSensorDevice sleepingRoomLight = new BoolSensorDevice("Bedroom Light");
+		sleepingRoomLight.setBSinfoName("home/bedroom/light");
+		networkController.addLinkToDevice(zigbee, sleepingRoomLight);
+		networkController.moveSmartDevice(sleepingRoomLight, 750, 400, 50);
+		networkController.addSmartDevice(sleepingRoomLight);
+		Port pBedroomLight = new Port(sleepingRoomLight, (short)1883, 15000);
+		pBedroomLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
+		pBedroomLight.setStatus(Port.SENDING);
+		pBedroomLight.setLastTrigger(-1337L);
+		networkController.addDeviceToConnectionAndProtocol(pBedroomLight, mqtt,1);
+		
+		/*
+		 * Bedroom Thermostat
+		 */
+		FloatSensorDevice bedroomThermostat = new FloatSensorDevice("Bedroom Thermostat");
+		bedroomThermostat.setFSinfoName("home/bedroom/temperature");
+		networkController.addLinkToDevice(zigbee, bedroomThermostat);
+		networkController.moveSmartDevice(bedroomThermostat, 700, 500, 50);
+		bedroomThermostat.setFSmin(15.0f);
+		bedroomThermostat.setFSmax(32.0f);
+		networkController.addSmartDevice(bedroomThermostat);
+		Port pBedroomThermostat = new Port(bedroomThermostat, (short)1883, 15000);
+		pBedroomThermostat.setTriggerHandler(new NormalDistributionHandler(15000, 500));
+		pBedroomThermostat.setStatus(Port.SENDING);
+		pBedroomThermostat.setLastTrigger(-820L);
+		networkController.addDeviceToConnectionAndProtocol(pBedroomThermostat, mqtt,1);
+		
+		
+		/*
+		 * Bedroom Info Screen
+		 */
+		FloatCollectorDevice bedroomInfoScreen = new FloatCollectorDevice("Information Panel");
+		bedroomInfoScreen.setFCinfoName("home/kitchen/fridgeTemp");
+		networkController.addLinkToDevice(zigbee, bedroomInfoScreen);
+		networkController.moveSmartDevice(bedroomInfoScreen, 900, 600, 50);
+		networkController.addSmartDevice(bedroomInfoScreen);
+		Port pBedroomInfo = new Port(bedroomInfoScreen, (short)1883, 15000);
+		pBedroomInfo.setStatus(Port.SENDING);
+		pBedroomInfo.setTriggerHandler(new NormalDistributionHandler(15000, 500));
+		pBedroomInfo.setLastTrigger(-666L);
+		networkController.addDeviceToConnectionAndProtocol(pBedroomInfo, mqtt,1);
+		/* 
+		 * Update visualization 
+		 */
+		controller.notifyObservers();
+		
+		/**
+		 * Run only if run == true
+		 */
+		if(!run)return;
+		try {
+			System.out.println("Check 1");//TODO
+			/**
+			 * Instances of the packet Sniffers
+			 */
+			PacketSniffer snifferEM = null, snifferKNN = null, snifferHC = null;
+			/*
+			 * Import Example PacketSniffer algorithms
+			 */
+			Class<? extends PacketSniffer> em = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/EMClustering.java"));
+			snifferEM = em.newInstance();
+			Class<? extends PacketSniffer> knn = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/KMeansClustering.java"));
+			snifferKNN = knn.newInstance();
+			Class<? extends PacketSniffer> hc = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/HierarchicalClustering.java"));
+			snifferHC = hc.newInstance();
+
+			System.out.println("Check 2: Imported");//TODO
+			/*
+			 * Create collectors
+			 */
+			PacketCollector collectorKNN = new PacketCollector(snifferKNN);
+			//PacketCollector collectorEM = new PacketCollector(snifferEM);
+			//PacketCollector collectorHC = new PacketCollector(snifferHC);
+			
+			/*
+			 * Capture both links on all collectors
+			 */
+			PacketCaptureController captureController = controller.getSimulationController().getPacketCaptureController();
+			//captureController.addLinkToCollector(collectorEM, zigbee);
+			//captureController.addLinkToCollector(collectorEM, wifi);
+			captureController.addLinkToCollector(collectorKNN, zigbee);
+			captureController.addLinkToCollector(collectorKNN, wifi);
+			//captureController.addLinkToCollector(collectorHC, zigbee);
+			//captureController.addLinkToCollector(collectorHC, wifi);
+			captureController.addPacketCollector(collectorKNN);
+			//captureController.addPacketCollector(collectorEM);
+			//captureController.addPacketCollector(collectorHC);
+
+			System.out.println("Check 3: created Controller");//TODO
+			
+			long currentTime = System.currentTimeMillis();
+			
+			long hour = 60 * 60 * 1000;
+			/*
+			 * Simulate 24 hours
+			 */
+			SimulationController sim = controller.getSimulationController();
+			sim.setStartTime(0);
+			sim.resetSimulation();
+			sim.setStepDuration(hour);
+			sim.setPrintPackets(false);
+			sim.setEndTime(24*hour);
+
+			kitchenFridge.setFSmin(-6f);
+			kitchenFridge.setFSmax(-4f);
+			kitchenFridge.setFSval(-5f);
+			System.out.println("Training:");//TODO
+			for(int i=0; i<24; i++)
+				sim.getSimulationManager().simulateTimeIntervall(i*hour, hour);
+			
+			long new_time = System.currentTimeMillis();
+			long elapsed_time = new_time-currentTime;
+			System.out.println("Training data generation: "+elapsed_time+"ms");
+			currentTime = new_time;
+			
+			collectorKNN.setMode(true);
+			//collectorEM.setMode(true);
+			//collectorHC.setMode(true);
+			new_time = System.currentTimeMillis();
+			elapsed_time = new_time-currentTime;
+			System.out.println("Training of algorithm: "+elapsed_time+"ms");
+			currentTime = new_time;
+			
+			
+			
+			/*
+			 * Simulate/Test 1 hour without anomalies
+			 */
+
+			System.out.println("Test w/0 anomalies:");//TODO
+			for(int i=24; i<25; i++)
+				sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
+			
+			new_time = System.currentTimeMillis();
+			elapsed_time = new_time-currentTime;
+			System.out.println("Training data generation: "+elapsed_time+"ms");
+			currentTime = new_time;
+			
+			System.out.println("DDoS:");
+			/**
+			 * 1 hour DDoS
+			 */
+			Connection ddos = anomalyController.openDDosCreationMenu(broker, new LinkedList<SmartDevice>(zigbee.getDevices()));	
+			for(int i=25; i<26; i++)
+				sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
+			networkController.deleteConnection(ddos);
+			
+			new_time = System.currentTimeMillis();
+			elapsed_time = new_time-currentTime;
+			System.out.println("DDoS generation & classification: "+elapsed_time+"ms");
+			currentTime = new_time;
+			
+			System.out.println("DoS:");
+			/**
+			 * 1 hour DoS
+			 */
+			Connection dos = anomalyController.runDosAttack(kitchenLight, kitchenFridge);
+			for(int i=26; i<27; i++)
+				sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
+			networkController.deleteConnection(dos);
+			
+			new_time = System.currentTimeMillis();
+			elapsed_time = new_time-currentTime;
+			System.out.println("DoS generation & classification: "+elapsed_time+"ms");
+			currentTime = new_time;
+			
+			/**
+			 * Value Anomaly 1h
+			 */
+			System.out.println("Value Anomalies:");
+			float min = kitchenFridge.getFSmin();
+			float max = kitchenFridge.getFSmax();
+			float val = kitchenFridge.getFSval();
+			kitchenFridge.setFSmin(18);
+			kitchenFridge.setFSval(18.5f);
+			kitchenFridge.setFSmax(24);
+			kitchenFridge.setLabel((short)-1);//-1 Value anomaly
+			for(int i=27; i<28; i++)
+				sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
+			kitchenFridge.setFSmin(min);
+			kitchenFridge.setFSmax(max);
+			kitchenFridge.setFSval(val);
+			kitchenFridge.setLabel((short)0);
+			
+			new_time = System.currentTimeMillis();
+			elapsed_time = new_time-currentTime;
+			System.out.println("Anomaly generation & classification: "+elapsed_time+"ms");
+			currentTime = new_time;
+			
+			System.out.println("Testing completed");
+		} catch(Exception e) {
+			System.out.println("WARNING: Testing failed: ");
+			e.printStackTrace();
+		}
+	}
+}