12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133 |
- 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 org.apache.commons.math3.distribution.NormalDistribution;
- 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.RoomStatus;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
- 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.devices.SmartLight;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartLightSensor;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartTemperatureProducer;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartTemperatureSensor;
- 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.scheduler.AbstractEvent;
- 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;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.evaluation.SWCKMeansClustering;
- import de.tu_darmstadt.tk.SmartHomeNetworkSim.evaluation.SWCKMeansClusteringWithLabels;
- public class MenuBarNetworkExamples 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(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);
-
- /**
- * SWC example
- */
- JMenuItem mnSWCExample = new JMenuItem("SWC Example");
- mnSWCExample.addActionListener(a->createSWCExample(false));
- this.add(mnSWCExample);
-
- /**
- * SWC example + run
- */
- JMenuItem mnRunSWCExample = new JMenuItem("Run SWC Example");
- mnRunSWCExample.addActionListener(a->createSWCExample(true));
- this.add(mnRunSWCExample);
- }
- 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();
- }
- }
-
-
- /**
- * Creates the paper toy example, also simulates it, if run = true
- * @param run
- */
- @SuppressWarnings("unchecked")
- public void createSWCExample(boolean run){
- /**
- * Reset network, etc.
- */
- long hour = 60 * 60 * 1000;
- long endTime = 24*hour;
- long noAnomEnd = 26*hour;
- long lightEnd = 27*hour;
- long tempEnd = 28*hour;
- long stepLength=hour;
- long currentSimTime=0;
-
- SimulationController sim = controller.getSimulationController();
- if(run) {
- controller.getSimulationController().resetSimulation();
- controller.getNetworkController().deleteNetworkModel();
- /*
- * Simulate 24 hours
- */
- sim.setStartTime(0);
- sim.resetSimulation();
- sim.setStepDuration(hour);
- sim.setPrintPackets(false);
- sim.setEndTime(endTime);
- }
- /*
- * Main networking devices
- */
- SmartDevice smartHub = networkController.createSmartDevice("SmartHub", 400, 400, 50);
-
- /*
- * Links/Networks
- */
- Link zigbee = new PrecisionLink("ZigBee");
- networkController.addLink(zigbee);
-
- /*
- * Connect Devices to Links
- */
- networkController.addLinkToDevice(zigbee, smartHub);
-
-
- /*
- * Create MQTT Connection
- */
- Connection mqtt = new ConnectionPrecision();
- mqtt.setName("HomeAutomation (MQTT)");
- networkController.addConnectionToLink(mqtt, zigbee);
- mqtt.setProtocol(new MQTT_protocol());
- Port pBroker = new Port(smartHub, (short)1883);
- pBroker.setStatus(Port.OPEN);
- pBroker.setResponseTime((short)2);
- networkController.addDeviceToConnectionAndProtocol(pBroker, mqtt, 0);
- networkController.addConnection(mqtt);
- mqtt.setLabel((short) 0);
-
- /**
- * Room
- */
- String roomName = "Bedroom";
- RoomStatus room = new RoomStatus();
- room.setTemperature(19f);
- /*
- * Add some MQTT Devices
- */
-
- /**
- * Room Thermostat
- */
- SmartTemperatureSensor heatSensor = new SmartTemperatureSensor(roomName + " Thermostat", room);
- heatSensor.setFSinfoName("home/" + roomName + "/sensorTemp");
- networkController.addLinkToDevice(zigbee, heatSensor);
- networkController.moveSmartDevice(heatSensor, 300, 300, 50);
- heatSensor.setFSmin(19.0f);
- heatSensor.setFSmax(21.0f);
- heatSensor.setFSval(19.0f);
- networkController.addSmartDevice(heatSensor);
- Port pFloatSensor = new Port(heatSensor, (short)1883, 15000);
- pFloatSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
- pFloatSensor.setStatus(Port.SENDING);
- pFloatSensor.setLastTrigger(-357L);
- networkController.addDeviceToConnectionAndProtocol(pFloatSensor, mqtt,1);
- heatSensor.setLabel((short) 0);
- /*
- * Add Heater (every second update)
- */
- SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 500, heatSensor);
- heaterDevice.setFSinfoName("home/" + roomName + "/heaterTemp");
- networkController.addLinkToDevice(zigbee, heaterDevice);
- networkController.moveSmartDevice(heaterDevice, 300, 500, 50);
- heaterDevice.setFSmin(19.0f);
- heaterDevice.setFSmax(21.0f);
- heaterDevice.setFSval(19.0f);
- networkController.addSmartDevice(heaterDevice);
- Port pHeaterDevice = new Port(heaterDevice, (short)1883, 15000);
- pHeaterDevice.setStatus(Port.SENDING);
- pHeaterDevice.setTriggerHandler(new NormalDistributionHandler(15000, 500));
- pHeaterDevice.setLastTrigger(-1231L);
- networkController.addDeviceToConnectionAndProtocol(pHeaterDevice, mqtt,1);
- heaterDevice.setLabel((short) 0);
-
-
- /*
- * Add light Sensor
- */
- SmartLightSensor lightSensor = new SmartLightSensor(roomName + " LightSensor", room, 1000);
- lightSensor.setBSinfoName("home/" + roomName + "/light");
- networkController.addLinkToDevice(zigbee, lightSensor);
- networkController.moveSmartDevice(lightSensor, 500, 300, 50);
- networkController.addSmartDevice(lightSensor);
- Port pLightSensor = new Port(lightSensor, (short)1883, 15000);
- pLightSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
- pLightSensor.setStatus(Port.SENDING);
- pLightSensor.setLastTrigger(-1337L);
- networkController.addDeviceToConnectionAndProtocol(pLightSensor, mqtt,1);
- lightSensor.setLabel((short) 0);
-
- /*
- * Add a light
- */
- SmartLight smartLight = new SmartLight(roomName + " Light", room, lightSensor);
- smartLight.setBSinfoName("home/" + roomName + "/light");
- networkController.addLinkToDevice(zigbee, smartLight);
- networkController.moveSmartDevice(smartLight, 500, 500, 50);
- networkController.addSmartDevice(smartLight);
- Port pSmartLight = new Port(smartLight, (short)1883, 15000);
- pSmartLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
- pSmartLight.setStatus(Port.SENDING);
- pSmartLight.setLastTrigger(-1207L);
- networkController.addDeviceToConnectionAndProtocol(pSmartLight, mqtt,1);
- smartLight.setLabel((short) 0);
-
- /*
- * Update visualization
- */
- controller.notifyObservers();
-
- /**
- * Run only if run == true
- */
- if(!run)return;
- try {
- System.out.println("Check 1");//TODO
- /**
- * Instances of the packet Sniffers
- */
- SWCKMeansClusteringWithLabels snifferKNNwithLabels = new SWCKMeansClusteringWithLabels();
- SWCKMeansClustering snifferKNNnoLabels = new SWCKMeansClustering();
- PacketCollector collectorKNNwithLabels = new PacketCollector(snifferKNNwithLabels);
- PacketCollector collectorKNNnoLabels = new PacketCollector(snifferKNNnoLabels);
- //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(collectorKNN, zigbee);
- captureController.addDeviceToCollector(collectorKNNwithLabels, smartLight);
- captureController.addDeviceToCollector(collectorKNNwithLabels, heaterDevice);
- captureController.addPacketCollector(collectorKNNwithLabels);
- captureController.addDeviceToCollector(collectorKNNnoLabels, smartLight);
- captureController.addDeviceToCollector(collectorKNNnoLabels, heaterDevice);
- captureController.addPacketCollector(collectorKNNnoLabels);
- //captureController.addPacketCollector(collectorEM);
- //captureController.addPacketCollector(collectorHC);
- System.out.println("Check 3: created Controller");//TODO
-
- long currentTime = System.currentTimeMillis();
-
- /**
- * Training events
- */
- System.out.println("Create training events");
- /**
- * Light Events (random switch every 30min+-15min
- */
- NormalDistribution lightDist = new NormalDistribution(hour/2, hour/4);
- long eventTime = 0;
- while(eventTime < noAnomEnd) {
- /**
- * At least 1 second between events
- */
- SimulationManager.scheduleEvent(new AbstractEvent(eventTime) {
-
- @Override
- public void simulateEvent(long time) {
- smartLight.setBSval(!smartLight.isTrueStatus());
- smartLight.setTrueStatus(!smartLight.isTrueStatus());
- }
- });
- eventTime+=Math.max(1000, Math.round(lightDist.sample()));
-
- }
- /**
- * Heater Events (random switch every 2h +- 30min
- */
- NormalDistribution tempDist = new NormalDistribution(2*hour, hour/2);
- eventTime = 0;
- while(eventTime < lightEnd) {
- /**
- * At least 1 second between events
- */
- SimulationManager.scheduleEvent(new AbstractEvent(eventTime) {
-
- @Override
- public void simulateEvent(long time) {
- float newTemp = (float)(heaterDevice.getFSmin() + Math.random() * (heaterDevice.getFSmax()-heaterDevice.getFSmin()));
- heaterDevice.setFSval(newTemp);
- heaterDevice.setTrueTemperature(newTemp);
- }
- });
- eventTime+=Math.max(1000, Math.round(tempDist.sample()));
-
- }
-
- System.out.println("Training:");//TODO
- while(currentSimTime<endTime) {
- sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
- currentSimTime+=stepLength;
- }
-
- long new_time = System.currentTimeMillis();
- long elapsed_time = new_time-currentTime;
- System.out.println("Training data generation took: "+elapsed_time+"ms");
- currentTime = new_time;
-
- /*
- * Start Classifying
- */
- collectorKNNwithLabels.setMode(true);
- collectorKNNnoLabels.setMode(true);
- //collectorEM.setMode(true);
- //collectorHC.setMode(true);
- new_time = System.currentTimeMillis();
- elapsed_time = new_time-currentTime;
- System.out.println("Training of algorithm took: "+elapsed_time+"ms");
- currentTime = new_time;
-
-
-
- /*
- * Simulate/Test 2 hour without anomalies
- */
- snifferKNNwithLabels.setCurrentScenario("NoAnomalies");
- snifferKNNnoLabels.setCurrentScenario("NoAnomalies");
- System.out.println("Test w/0 anomalies:");//TODO
- while(currentSimTime<noAnomEnd) {
- sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
- currentSimTime+=stepLength;
- }
-
- new_time = System.currentTimeMillis();
- elapsed_time = new_time-currentTime;
- System.out.println("Test witout anomalies took: "+elapsed_time+"ms");
- currentTime = new_time;
-
- /**
- * Light Anomaly 1h
- * Light != Sensor
- */
- snifferKNNwithLabels.setCurrentScenario("LightAnomalies");
- snifferKNNnoLabels.setCurrentScenario("LightAnomalies");
- System.out.println("Light Anomaly:");
- smartLight.setTrueStatus(!smartLight.getBSval());
- smartLight.setLabel((short)-1);
- while(currentSimTime<lightEnd) {
- sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
- currentSimTime+=stepLength;
- }
- smartLight.setLabel((short)0);
- smartLight.setBSval(smartLight.isTrueStatus());
-
- new_time = System.currentTimeMillis();
- elapsed_time = new_time-currentTime;
- System.out.println("Anomaly generation & classification: "+elapsed_time+"ms");
- currentTime = new_time;
-
- /**
- * Schedule new light events
- */
- eventTime = 27 * hour;
- while(eventTime < 29 * hour) {
- /**
- * At least 1 second between events
- */
- SimulationManager.scheduleEvent(new AbstractEvent(eventTime) {
-
- @Override
- public void simulateEvent(long time) {
- smartLight.setBSval(!smartLight.isTrueStatus());
- smartLight.setTrueStatus(!smartLight.isTrueStatus());
- }
- });
-
- eventTime+=Math.max(1000, Math.round(lightDist.sample()));
-
- }
-
- /**
- * Temperature Anomaly 2h
- */
- snifferKNNwithLabels.setCurrentScenario("TemperatureAnomalies");
- snifferKNNnoLabels.setCurrentScenario("TemperatureAnomalies");
- System.out.println("Temperature Anomaly:");
- heaterDevice.setFSval(21f);
- heaterDevice.setTrueTemperature(34f);
- heaterDevice.setLabel((short)-1);//-1 Value anomaly
- while(currentSimTime<tempEnd) {
- sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
- currentSimTime+=stepLength;
- }
- heaterDevice.setFSval(21f);
- heaterDevice.setTrueTemperature(21f);
- heaterDevice.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();
- }
- }
- }
|