MenuBarNetworkExamples.java 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.menuBar;
  2. import java.io.File;
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.LinkedList;
  6. import java.util.Map.Entry;
  7. import javax.swing.JMenu;
  8. import javax.swing.JMenuItem;
  9. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
  10. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ExampleAnomalyController;
  11. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ImportController;
  12. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController;
  13. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.PacketCaptureController;
  14. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController;
  15. import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SimulationController;
  16. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
  17. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionPerformance;
  18. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.ConnectionPrecision;
  19. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
  20. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
  21. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketCollector;
  22. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketSniffer;
  23. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
  24. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PrecisionLink;
  25. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
  26. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
  27. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
  28. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolCollectorDevice;
  29. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensorDevice;
  30. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollectorDevice;
  31. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensorDevice;
  32. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartLight;
  33. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartLightSensor;
  34. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartTemperatureProducer;
  35. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartTemperatureSensor;
  36. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.distributionHandler.NormalDistributionHandler;
  37. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
  38. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.CountingMetric;
  39. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.Manipulation_RandomMove;
  40. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleLink;
  41. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
  42. public class MenuBarNetworkExamples extends JMenu{
  43. /**
  44. *
  45. */
  46. private static final long serialVersionUID = 1L;
  47. /**
  48. * Controller controller
  49. */
  50. private Controller controller;
  51. /**
  52. * Controller for editing the network
  53. */
  54. private NetworkController networkController;
  55. /**
  56. * Controller to insert anomalies
  57. */
  58. private ExampleAnomalyController anomalyController;
  59. /**
  60. * Controller for configuration of the program
  61. */
  62. private SettingsController settingsController;
  63. /**
  64. * SimulationController for running the simulation
  65. */
  66. private SimulationController simulationController;
  67. /**
  68. * Creates the JMenu for network examples in the MenuBar
  69. * @param controller controller to create examples
  70. */
  71. public MenuBarNetworkExamples(Controller controller) {
  72. super("Create example Network");
  73. this.controller = controller;
  74. this.networkController = controller.getNetworkController();
  75. this.anomalyController = networkController.getAnomalyController();
  76. this.settingsController = controller.getSettingsController();
  77. this.simulationController = controller.getSimulationController();
  78. /**
  79. * MQTT example
  80. */
  81. JMenuItem mnMQTT = new JMenuItem("MQTT Example");
  82. mnMQTT.addActionListener(a->initializeMQTTTest());
  83. this.add(mnMQTT);
  84. /**
  85. * Small Network Test
  86. */
  87. JMenuItem mnTest = new JMenuItem("Network Example");
  88. mnTest.addActionListener(a->initializeTest());
  89. this.add(mnTest);
  90. /**
  91. * Performance Comparison Example
  92. */
  93. JMenuItem mnPerformance = new JMenuItem("Performane Evaluation Preset");
  94. mnPerformance.addActionListener(a->initializePerformanceTest());
  95. this.add(mnPerformance);
  96. /**
  97. * User Study Preset
  98. */
  99. JMenuItem mnUserStudy = new JMenuItem("User Study Preset");
  100. mnUserStudy.addActionListener(a->initializeUserStudy());
  101. this.add(mnUserStudy);
  102. /**
  103. * Packet Collection example
  104. */
  105. JMenuItem mnPacketCollectionExmample = new JMenuItem("Packet Collection Example");
  106. mnPacketCollectionExmample.addActionListener(a->testPackageCollection());
  107. this.add(mnPacketCollectionExmample);
  108. /**
  109. * Paper example
  110. */
  111. JMenuItem mnPaperExample = new JMenuItem("Paper Example");
  112. mnPaperExample.addActionListener(a->createPaperExample(false));
  113. this.add(mnPaperExample);
  114. /**
  115. * Paper example + run
  116. */
  117. JMenuItem mnRunPaperExample = new JMenuItem("Run Paper Example");
  118. mnRunPaperExample.addActionListener(a->createPaperExample(true));
  119. this.add(mnRunPaperExample);
  120. /**
  121. * SWC example
  122. */
  123. JMenuItem mnSWCExample = new JMenuItem("SWC Example");
  124. mnSWCExample.addActionListener(a->createSWCExample(false));
  125. this.add(mnSWCExample);
  126. /**
  127. * SWC example + run
  128. */
  129. JMenuItem mnRunSWCExample = new JMenuItem("Run SWC Example");
  130. mnRunSWCExample.addActionListener(a->createSWCExample(true));
  131. this.add(mnRunSWCExample);
  132. }
  133. private void initializePerformanceTest(){
  134. SmartDevice tic = new SmartDevice("Tic");
  135. tic.setX(100);
  136. tic.setY(100);
  137. SmartDevice toc = new SmartDevice("Toc");
  138. toc.setX(100);
  139. toc.setY(250);
  140. networkController.addSmartDevice(tic);
  141. networkController.addSmartDevice(toc);
  142. Link l = new PrecisionLink("Channel");
  143. networkController.addLink(l);
  144. networkController.addLinkToDevice(l, tic);
  145. networkController.addLinkToDevice(l, toc);
  146. Port ticP = new Port(tic, (short)2, 200, (short)0, 0, (short)0);
  147. Port tocP = new Port(toc, (short)3, 200, (short)0, -100, (short)0);
  148. tic.addPort(ticP);
  149. toc.addPort(tocP);
  150. Connection con = new ConnectionPrecision(l, new SimpleProtocol());
  151. networkController.addConnection(con);
  152. networkController.addConnectionToLink(con, l);
  153. networkController.addDeviceToConnectionAndProtocol(ticP, con, 0);
  154. networkController.addDeviceToConnectionAndProtocol(tocP, con, 1);
  155. simulationController.setStepDuration(100000000);
  156. simulationController.setEndTime(1000000000);
  157. controller.notifyObservers();
  158. }
  159. /**
  160. * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
  161. */
  162. private void initializeUserStudy(){
  163. /**
  164. * Preset one SmartDevice
  165. */
  166. SmartDevice A = new SmartDevice("Homestation");
  167. A.setX(200);
  168. A.setY(200);
  169. networkController.addSmartDevice(A);
  170. /**
  171. * Packagecollector, which is registered at the Device
  172. */
  173. PacketCollector collector = new PacketCollector(new CountingMetric());
  174. simulationController.getPacketCaptureController().addPacketCollector(collector);
  175. simulationController.getPacketCaptureController().addDeviceToCollector(collector, A);
  176. simulationController.setPrintPackets(true);
  177. controller.notifyObservers();
  178. }
  179. /**
  180. * Test package collectors
  181. */
  182. private void testPackageCollection() {
  183. if(networkController.getSmartDevices().size()<3)
  184. return;
  185. simulationController.addAlgorithm(new Manipulation_RandomMove(), controller);
  186. PacketCollector collector = new PacketCollector();
  187. simulationController.getSimulationManager().getPacketCollectionManager().addPacketCollector(collector);
  188. System.out.println("Collector 0-500 - nothing collected:");
  189. simulationController.getSimulationManager().simulateTimeIntervall(0, 500);
  190. HashMap<Link, LinkedList<Packet>> map = collector.getPackets();
  191. for(Entry<Link, LinkedList<Packet>> e:map.entrySet()){
  192. System.out.println("Link: "+e.getKey().getName());
  193. for(Packet p : e.getValue())
  194. System.out.println(p.getTextualRepresentation());
  195. }
  196. System.out.println("");
  197. System.out.println("");
  198. Iterator<SmartDevice> it = networkController.getSmartDevices().iterator();
  199. it.next();
  200. SmartDevice d = it.next();
  201. collector.addDevice(d);
  202. SmartDevice f = it.next();
  203. collector.addDevice(f);
  204. System.out.println("Collector 500-1000 - "+d.getName()+" & "+f.getName()+" collected:");
  205. simulationController.getSimulationManager().simulateTimeIntervall(500, 500);
  206. map = collector.getPackets();
  207. for(Entry<Link, LinkedList<Packet>> e:map.entrySet()){
  208. System.out.println("Link: "+e.getKey().getName());
  209. for(Packet p : e.getValue())
  210. System.out.println(p.getTextualRepresentation());
  211. }
  212. System.out.println("");
  213. System.out.println("");
  214. Link l = networkController.getLinks().iterator().next();
  215. collector.addLink(l);
  216. System.out.println("Collector 2000-3000 - "+l+" collected:");
  217. simulationController.getSimulationManager().simulateTimeIntervall(1000, 500);
  218. map = collector.getPackets();
  219. for(Entry<Link, LinkedList<Packet>> e:map.entrySet()){
  220. System.out.println("Link: "+e.getKey().getName());
  221. for(Packet p : e.getValue())
  222. System.out.println(p.getTextualRepresentation());
  223. }
  224. simulationController.resetSimulation();
  225. controller.notifyObservers();
  226. }
  227. /**
  228. * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
  229. */
  230. private void initializeTest(){
  231. SmartDevice A = null, B = null, C = null;
  232. for(int i = 0; i<5; i++){
  233. A = new SmartDevice("SmartTV"+i);
  234. A.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  235. A.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  236. B = new SmartDevice("SmartDoor"+i);
  237. B.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  238. B.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  239. C = new SmartDevice("SmartLight"+i);
  240. C.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  241. C.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  242. networkController.addSmartDevice(A);
  243. networkController.addSmartDevice(B);
  244. networkController.addSmartDevice(C);
  245. }
  246. Link link = new SimpleLink("SimpleWifi");
  247. link.addDevice(A);
  248. link.addDevice(B);
  249. link.addDevice(C);
  250. A.addLink(link);
  251. B.addLink(link);
  252. C.addLink(link);
  253. Port a = new Port(A, (short) 1, 68);
  254. a.setLastTrigger(0);
  255. a.setStatus(Port.SENDING);
  256. A.addPort(a);
  257. Port b = new Port(B, (short) 2, 102);
  258. b.setStatus(Port.SENDING);
  259. B.addPort(b);
  260. Connection s = new ConnectionPerformance(link, new SimpleProtocol(a, b));
  261. s.setPacketLossProbability(0.01);//1% Packet loss probability
  262. a.setConnection(s);
  263. b.setConnection(s);
  264. s.addSmartDevice(a);
  265. s.addSmartDevice(b);
  266. link.addConnection(s);
  267. networkController.addLink(link);
  268. networkController.addConnection(s);
  269. controller.notifyObservers();
  270. }
  271. /**
  272. * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
  273. */
  274. private void initializeMQTTTest(){
  275. SimpleLink link = new SimpleLink("WIFI");
  276. link.setFixedDelay(5);
  277. SmartDevice broker = new SmartDevice("MQTT-Broker");
  278. broker.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  279. broker.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  280. networkController.addSmartDevice(broker);
  281. Port brokerPort = new Port(broker, (short) 0, 987);
  282. brokerPort.setLastTrigger(0);
  283. brokerPort.setStatus(Port.OPEN);
  284. broker.addPort(brokerPort);
  285. link.addDevice(broker);
  286. broker.addLink(link);
  287. Protocol protocol = new MQTT_protocol(brokerPort);
  288. Connection con = new ConnectionPrecision(link, protocol);
  289. con.setPacketLossProbability(0.01);//1% Packet loss probability
  290. con.addSmartDevice(brokerPort);
  291. brokerPort.setConnection(con);
  292. con.setStatus(Connection.ACTIVE);
  293. networkController.addLink(link);
  294. link.addConnection(con);
  295. networkController.addConnection(con);
  296. SmartDevice A = null, A1 = null, A2 = null, B = null, C = null;
  297. Port aP,a1P,a2P,bP,cP;
  298. for(int i = 0; i<3; i++){
  299. FloatSensorDevice aS = new FloatSensorDevice("SmartThermostat"+i+"(Pub)");
  300. aS.setFSinfoName("room"+i+"/temperature");
  301. A=aS;
  302. A.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  303. A.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  304. link.addDevice(A);
  305. A.addLink(link);
  306. aP = new Port(A,((short) (3*i+1)),100+(int)(Math.random()*900));
  307. aP.setLastTrigger(0);
  308. aP.setJitter((short) (Math.random()*50));
  309. aP.setStatus(Port.SENDING);
  310. aP.setConnection(con);
  311. protocol.addDeviceOfRole(aP, 2);
  312. con.addSmartDevice(aP);
  313. A.addPort(aP);
  314. networkController.addSmartDevice(A);
  315. FloatCollectorDevice aS1 = new FloatCollectorDevice("SmartAirCondition"+i+"(Sub)");
  316. aS1.setFCinfoName("room"+i+"/temperature");
  317. A1=aS1;
  318. A1.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  319. A1.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  320. link.addDevice(A1);
  321. A1.addLink(link);
  322. a1P = new Port(A1,((short) (3*i+1)),100+(int)(Math.random()*900));
  323. a1P.setLastTrigger(0);
  324. a1P.setJitter((short) (Math.random()*50));
  325. a1P.setStatus(Port.SENDING);
  326. a1P.setConnection(con);
  327. protocol.addDeviceOfRole(a1P, 3);
  328. con.addSmartDevice(a1P);
  329. A1.addPort(a1P);
  330. networkController.addSmartDevice(A1);
  331. FloatCollectorDevice aS2 = new FloatCollectorDevice("SmartHeater"+i+"(Sub)");
  332. aS2.setFCinfoName("room"+i+"/temperature");
  333. A2=aS2;
  334. A2.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  335. A2.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  336. link.addDevice(A2);
  337. A2.addLink(link);
  338. a2P = new Port(A2,((short) (3*i+1)),100+(int)(Math.random()*900));
  339. a2P.setLastTrigger(0);
  340. a2P.setJitter((short) (Math.random()*50));
  341. a2P.setStatus(Port.SENDING);
  342. a2P.setConnection(con);
  343. protocol.addDeviceOfRole(a2P, 3);
  344. con.addSmartDevice(a2P);
  345. A2.addPort(a2P);
  346. networkController.addSmartDevice(A2);
  347. B = new BoolSensorDevice("SmartDoor"+i+"(Pub)");
  348. ((BoolSensorDevice)B).setBSinfoName("room"+i+"/DoorOpen");
  349. B.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  350. B.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  351. link.addDevice(B);
  352. B.addLink(link);
  353. bP = new Port(B,((short) (3*i+2)),10+(int)(Math.random()*190));
  354. bP.setLastTrigger(0);
  355. bP.setJitter((short) (Math.random()*50));
  356. bP.setStatus(Port.SENDING);
  357. bP.setConnection(con);
  358. protocol.addDeviceOfRole(bP, 2);
  359. con.addSmartDevice(bP);
  360. B.addPort(bP);
  361. networkController.addSmartDevice(B);
  362. C = new BoolCollectorDevice("SmartDoorStatusLight"+i+"(Sub)");
  363. ((BoolCollectorDevice)C).setBCinfoName("room"+i+"/DoorOpen");
  364. C.setX((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  365. C.setY((int)(Math.random()*settingsController.getWidth()-2*settingsController.getDeviceVisualizationRadius())+settingsController.getDeviceVisualizationRadius());
  366. link.addDevice(C);
  367. C.addLink(link);
  368. cP = new Port(C,((short) (3*i+1)), 50+(int)(Math.random()*450));
  369. cP.setLastTrigger(0);
  370. cP.setJitter((short) (Math.random()*50));
  371. cP.setStatus(Port.SENDING);
  372. cP.setConnection(con);
  373. protocol.addDeviceOfRole(cP, 3);
  374. con.addSmartDevice(cP);
  375. C.addPort(cP);
  376. networkController.addSmartDevice(C);
  377. controller.notifyObservers();
  378. }
  379. }
  380. /**
  381. * Creates the paper toy example, also simulates it, if run = true
  382. * @param run
  383. */
  384. @SuppressWarnings("unchecked")
  385. public void createPaperExample(boolean run){
  386. /**
  387. * Reset network, etc.
  388. */
  389. if(run) {
  390. controller.getSimulationController().resetSimulation();
  391. controller.getNetworkController().deleteNetworkModel();
  392. }
  393. /*
  394. * Main networking devices
  395. */
  396. SmartDevice router = networkController.createSmartDevice("Wifi-Router", 500, 100, 50);
  397. SmartDevice zigBeeRouter = networkController.createSmartDevice("ZigBee-Router", 500, 300, 50);
  398. SmartDevice broker = networkController.createSmartDevice("SmartHub", 500, 500, 50);
  399. /*
  400. * Links/Networks
  401. */
  402. Link wifi = new PrecisionLink("Wifi");
  403. networkController.addLink(wifi);
  404. Link zigbee = new PrecisionLink("ZigBee");
  405. networkController.addLink(zigbee);
  406. /*
  407. * Connect Devices to Links
  408. */
  409. networkController.addLinkToDevice(wifi, router);
  410. networkController.addLinkToDevice(wifi, zigBeeRouter);
  411. networkController.addLinkToDevice(zigbee, zigBeeRouter);
  412. networkController.addLinkToDevice(zigbee, broker);
  413. /*
  414. * Internet Access Connection
  415. */
  416. Connection inetAcces = new ConnectionPrecision();
  417. inetAcces.setName("Cloud Access");
  418. networkController.addConnectionToLink(inetAcces, wifi);
  419. inetAcces.setProtocol(new SimpleProtocol());
  420. Port pRouter = new Port(router, (short)80, 500L);
  421. pRouter.setTriggerHandler(new NormalDistributionHandler(500, 100));
  422. networkController.addDeviceToConnectionAndProtocol(pRouter, inetAcces, 0);
  423. Port pZigBee = new Port(zigBeeRouter, (short)80, 1000L);
  424. pZigBee.setTriggerHandler(new NormalDistributionHandler(1000, 300));
  425. networkController.addDeviceToConnectionAndProtocol(pRouter, inetAcces, 0);
  426. networkController.addDeviceToConnectionAndProtocol(pZigBee, inetAcces, 1);
  427. networkController.addConnection(inetAcces);
  428. /*
  429. * ZigbeeRouter -> Broker ?
  430. */
  431. Connection homeAutomationInternetAccess = new ConnectionPrecision();
  432. homeAutomationInternetAccess.setName("Home Automation Webinterface");
  433. networkController.addConnectionToLink(homeAutomationInternetAccess, zigbee);
  434. homeAutomationInternetAccess.setProtocol(new SimpleProtocol());
  435. Port pBrokerWebInterface = new Port(broker, (short)80);
  436. pBrokerWebInterface.setTriggerHandler(new NormalDistributionHandler(2000, 500));
  437. pBrokerWebInterface.setStatus(Port.SENDING);
  438. pBrokerWebInterface.setResponseTime((short)2);
  439. pBrokerWebInterface.setLastTrigger(-284L);
  440. networkController.addDeviceToConnectionAndProtocol(pBrokerWebInterface, homeAutomationInternetAccess, 0);
  441. networkController.addConnection(homeAutomationInternetAccess);
  442. Port pRouterWebInterface = new Port(zigBeeRouter, (short)80);
  443. pRouterWebInterface.setTriggerHandler(new NormalDistributionHandler(5000, 3000));
  444. pRouterWebInterface.setStatus(Port.SENDING);
  445. pRouterWebInterface.setResponseTime((short)2);
  446. pRouterWebInterface.setLastTrigger(-142L);
  447. networkController.addDeviceToConnectionAndProtocol(pRouterWebInterface, homeAutomationInternetAccess, 1);
  448. networkController.addConnection(homeAutomationInternetAccess);
  449. /*
  450. * Create MQTT Connection
  451. */
  452. Connection mqtt = new ConnectionPrecision();
  453. mqtt.setName("Automation (MQTT)");
  454. networkController.addConnectionToLink(mqtt, zigbee);
  455. mqtt.setProtocol(new MQTT_protocol());
  456. Port pBroker = new Port(broker, (short)1883);
  457. pBroker.setStatus(Port.OPEN);
  458. pBroker.setResponseTime((short)2);
  459. networkController.addDeviceToConnectionAndProtocol(pBroker, mqtt, 0);
  460. networkController.addConnection(mqtt);
  461. /*
  462. * Add some MQTT Devices
  463. */
  464. /**
  465. * Kitchen Thermostat
  466. */
  467. FloatSensorDevice floatSensor = new FloatSensorDevice("Kitchen Thermostat");
  468. floatSensor.setFSinfoName("home/kitchen/temperature");
  469. networkController.addLinkToDevice(zigbee, floatSensor);
  470. networkController.moveSmartDevice(floatSensor, 300, 500, 50);
  471. floatSensor.setFSmin(15.0f);
  472. floatSensor.setFSmax(32.0f);
  473. networkController.addSmartDevice(floatSensor);
  474. Port pFloatSensor = new Port(floatSensor, (short)1883, 15000);
  475. pFloatSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  476. pFloatSensor.setStatus(Port.SENDING);
  477. pFloatSensor.setLastTrigger(-357L);
  478. networkController.addDeviceToConnectionAndProtocol(pFloatSensor, mqtt,1);
  479. /*
  480. * Add Fridge
  481. */
  482. FloatSensorDevice kitchenFridge = new FloatSensorDevice("Smart Fridge");
  483. kitchenFridge.setFSinfoName("home/kitchen/fridgeTemp");
  484. networkController.addLinkToDevice(zigbee, kitchenFridge);
  485. networkController.moveSmartDevice(kitchenFridge, 100, 600, 50);
  486. kitchenFridge.setFSmin(-6.0f);
  487. kitchenFridge.setFSmax(-4.0f);
  488. networkController.addSmartDevice(kitchenFridge);
  489. Port pKitchenFridge = new Port(kitchenFridge, (short)1883, 15000);
  490. pKitchenFridge.setStatus(Port.SENDING);
  491. pKitchenFridge.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  492. pKitchenFridge.setLastTrigger(-1231L);
  493. networkController.addDeviceToConnectionAndProtocol(pKitchenFridge, mqtt,1);
  494. /*
  495. * Add some kitchen lights
  496. */
  497. BoolSensorDevice kitchenLight = new BoolSensorDevice("Kitchen Light");
  498. kitchenLight.setBSinfoName("home/kitchen/light");
  499. networkController.addLinkToDevice(zigbee, kitchenLight);
  500. networkController.moveSmartDevice(kitchenLight, 250, 400, 50);
  501. networkController.addSmartDevice(kitchenLight);
  502. Port pKitchenLight = new Port(kitchenLight, (short)1883, 15000);
  503. pKitchenLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  504. pKitchenLight.setStatus(Port.SENDING);
  505. pKitchenLight.setLastTrigger(-1207L);
  506. networkController.addDeviceToConnectionAndProtocol(pKitchenLight, mqtt,1);
  507. //TODO Further devices & Connections
  508. /*
  509. * Bedroom
  510. */
  511. BoolSensorDevice sleepingRoomLight = new BoolSensorDevice("Bedroom Light");
  512. sleepingRoomLight.setBSinfoName("home/bedroom/light");
  513. networkController.addLinkToDevice(zigbee, sleepingRoomLight);
  514. networkController.moveSmartDevice(sleepingRoomLight, 750, 400, 50);
  515. networkController.addSmartDevice(sleepingRoomLight);
  516. Port pBedroomLight = new Port(sleepingRoomLight, (short)1883, 15000);
  517. pBedroomLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  518. pBedroomLight.setStatus(Port.SENDING);
  519. pBedroomLight.setLastTrigger(-1337L);
  520. networkController.addDeviceToConnectionAndProtocol(pBedroomLight, mqtt,1);
  521. /*
  522. * Bedroom Thermostat
  523. */
  524. FloatSensorDevice bedroomThermostat = new FloatSensorDevice("Bedroom Thermostat");
  525. bedroomThermostat.setFSinfoName("home/bedroom/temperature");
  526. networkController.addLinkToDevice(zigbee, bedroomThermostat);
  527. networkController.moveSmartDevice(bedroomThermostat, 700, 500, 50);
  528. bedroomThermostat.setFSmin(15.0f);
  529. bedroomThermostat.setFSmax(32.0f);
  530. networkController.addSmartDevice(bedroomThermostat);
  531. Port pBedroomThermostat = new Port(bedroomThermostat, (short)1883, 15000);
  532. pBedroomThermostat.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  533. pBedroomThermostat.setStatus(Port.SENDING);
  534. pBedroomThermostat.setLastTrigger(-820L);
  535. networkController.addDeviceToConnectionAndProtocol(pBedroomThermostat, mqtt,1);
  536. /*
  537. * Bedroom Info Screen
  538. */
  539. FloatCollectorDevice bedroomInfoScreen = new FloatCollectorDevice("Information Panel");
  540. bedroomInfoScreen.setFCinfoName("home/kitchen/fridgeTemp");
  541. networkController.addLinkToDevice(zigbee, bedroomInfoScreen);
  542. networkController.moveSmartDevice(bedroomInfoScreen, 900, 600, 50);
  543. networkController.addSmartDevice(bedroomInfoScreen);
  544. Port pBedroomInfo = new Port(bedroomInfoScreen, (short)1883, 15000);
  545. pBedroomInfo.setStatus(Port.SENDING);
  546. pBedroomInfo.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  547. pBedroomInfo.setLastTrigger(-666L);
  548. networkController.addDeviceToConnectionAndProtocol(pBedroomInfo, mqtt,1);
  549. /*
  550. * Update visualization
  551. */
  552. controller.notifyObservers();
  553. /**
  554. * Run only if run == true
  555. */
  556. if(!run)return;
  557. try {
  558. System.out.println("Check 1");//TODO
  559. /**
  560. * Instances of the packet Sniffers
  561. */
  562. PacketSniffer snifferEM = null, snifferKNN = null, snifferHC = null;
  563. /*
  564. * Import Example PacketSniffer algorithms
  565. */
  566. Class<? extends PacketSniffer> em = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/EMClustering.java"));
  567. snifferEM = em.newInstance();
  568. Class<? extends PacketSniffer> knn = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/KMeansClustering.java"));
  569. snifferKNN = knn.newInstance();
  570. Class<? extends PacketSniffer> hc = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/HierarchicalClustering.java"));
  571. snifferHC = hc.newInstance();
  572. System.out.println("Check 2: Imported");//TODO
  573. /*
  574. * Create collectors
  575. */
  576. PacketCollector collectorKNN = new PacketCollector(snifferKNN);
  577. //PacketCollector collectorEM = new PacketCollector(snifferEM);
  578. //PacketCollector collectorHC = new PacketCollector(snifferHC);
  579. /*
  580. * Capture both links on all collectors
  581. */
  582. PacketCaptureController captureController = controller.getSimulationController().getPacketCaptureController();
  583. //captureController.addLinkToCollector(collectorEM, zigbee);
  584. //captureController.addLinkToCollector(collectorEM, wifi);
  585. captureController.addLinkToCollector(collectorKNN, zigbee);
  586. captureController.addLinkToCollector(collectorKNN, wifi);
  587. //captureController.addLinkToCollector(collectorHC, zigbee);
  588. //captureController.addLinkToCollector(collectorHC, wifi);
  589. captureController.addPacketCollector(collectorKNN);
  590. //captureController.addPacketCollector(collectorEM);
  591. //captureController.addPacketCollector(collectorHC);
  592. System.out.println("Check 3: created Controller");//TODO
  593. long currentTime = System.currentTimeMillis();
  594. long hour = 60 * 60 * 1000;
  595. /*
  596. * Simulate 24 hours
  597. */
  598. SimulationController sim = controller.getSimulationController();
  599. sim.setStartTime(0);
  600. sim.resetSimulation();
  601. sim.setStepDuration(hour);
  602. sim.setPrintPackets(false);
  603. sim.setEndTime(24*hour);
  604. kitchenFridge.setFSmin(-6f);
  605. kitchenFridge.setFSmax(-4f);
  606. kitchenFridge.setFSval(-5f);
  607. System.out.println("Training:");//TODO
  608. for(int i=0; i<24; i++)
  609. sim.getSimulationManager().simulateTimeIntervall(i*hour, hour);
  610. long new_time = System.currentTimeMillis();
  611. long elapsed_time = new_time-currentTime;
  612. System.out.println("Training data generation: "+elapsed_time+"ms");
  613. currentTime = new_time;
  614. collectorKNN.setMode(true);
  615. //collectorEM.setMode(true);
  616. //collectorHC.setMode(true);
  617. new_time = System.currentTimeMillis();
  618. elapsed_time = new_time-currentTime;
  619. System.out.println("Training of algorithm: "+elapsed_time+"ms");
  620. currentTime = new_time;
  621. /*
  622. * Simulate/Test 1 hour without anomalies
  623. */
  624. System.out.println("Test w/0 anomalies:");//TODO
  625. for(int i=24; i<25; i++)
  626. sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
  627. new_time = System.currentTimeMillis();
  628. elapsed_time = new_time-currentTime;
  629. System.out.println("Training data generation: "+elapsed_time+"ms");
  630. currentTime = new_time;
  631. System.out.println("DDoS:");
  632. /**
  633. * 1 hour DDoS
  634. */
  635. Connection ddos = anomalyController.openDDosCreationMenu(broker, new LinkedList<SmartDevice>(zigbee.getDevices()));
  636. for(int i=25; i<26; i++)
  637. sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
  638. networkController.deleteConnection(ddos);
  639. new_time = System.currentTimeMillis();
  640. elapsed_time = new_time-currentTime;
  641. System.out.println("DDoS generation & classification: "+elapsed_time+"ms");
  642. currentTime = new_time;
  643. System.out.println("DoS:");
  644. /**
  645. * 1 hour DoS
  646. */
  647. Connection dos = anomalyController.runDosAttack(kitchenLight, kitchenFridge);
  648. for(int i=26; i<27; i++)
  649. sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
  650. networkController.deleteConnection(dos);
  651. new_time = System.currentTimeMillis();
  652. elapsed_time = new_time-currentTime;
  653. System.out.println("DoS generation & classification: "+elapsed_time+"ms");
  654. currentTime = new_time;
  655. /**
  656. * Value Anomaly 1h
  657. */
  658. System.out.println("Value Anomalies:");
  659. float min = kitchenFridge.getFSmin();
  660. float max = kitchenFridge.getFSmax();
  661. float val = kitchenFridge.getFSval();
  662. kitchenFridge.setFSmin(18);
  663. kitchenFridge.setFSval(18.5f);
  664. kitchenFridge.setFSmax(24);
  665. kitchenFridge.setLabel((short)-1);//-1 Value anomaly
  666. for(int i=27; i<28; i++)
  667. sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
  668. kitchenFridge.setFSmin(min);
  669. kitchenFridge.setFSmax(max);
  670. kitchenFridge.setFSval(val);
  671. kitchenFridge.setLabel((short)0);
  672. new_time = System.currentTimeMillis();
  673. elapsed_time = new_time-currentTime;
  674. System.out.println("Anomaly generation & classification: "+elapsed_time+"ms");
  675. currentTime = new_time;
  676. System.out.println("Testing completed");
  677. } catch(Exception e) {
  678. System.out.println("WARNING: Testing failed: ");
  679. e.printStackTrace();
  680. }
  681. }
  682. /**
  683. * Creates the paper toy example, also simulates it, if run = true
  684. * @param run
  685. */
  686. @SuppressWarnings("unchecked")
  687. public void createSWCExample(boolean run){
  688. /**
  689. * Reset network, etc.
  690. */
  691. if(run) {
  692. controller.getSimulationController().resetSimulation();
  693. controller.getNetworkController().deleteNetworkModel();
  694. }
  695. /*
  696. * Main networking devices
  697. */
  698. SmartDevice smartHub = networkController.createSmartDevice("SmartHub", 400, 400, 50);
  699. /*
  700. * Links/Networks
  701. */
  702. Link zigbee = new PrecisionLink("ZigBee");
  703. networkController.addLink(zigbee);
  704. /*
  705. * Connect Devices to Links
  706. */
  707. networkController.addLinkToDevice(zigbee, smartHub);
  708. /*
  709. * Create MQTT Connection
  710. */
  711. Connection mqtt = new ConnectionPrecision();
  712. mqtt.setName("HomeAutomation (MQTT)");
  713. networkController.addConnectionToLink(mqtt, zigbee);
  714. mqtt.setProtocol(new MQTT_protocol());
  715. Port pBroker = new Port(smartHub, (short)1883);
  716. pBroker.setStatus(Port.OPEN);
  717. pBroker.setResponseTime((short)2);
  718. networkController.addDeviceToConnectionAndProtocol(pBroker, mqtt, 0);
  719. networkController.addConnection(mqtt);
  720. /**
  721. * Room
  722. */
  723. String roomName = "Bedroom";
  724. RoomStatus room = new RoomStatus();
  725. room.setTemperature(19f);
  726. /*
  727. * Add some MQTT Devices
  728. */
  729. /**
  730. * Room Thermostat
  731. */
  732. SmartTemperatureSensor floatSensor = new SmartTemperatureSensor(roomName + " Thermostat", room);
  733. floatSensor.setFSinfoName("home/" + roomName + "/sensorTemp");
  734. networkController.addLinkToDevice(zigbee, floatSensor);
  735. networkController.moveSmartDevice(floatSensor, 300, 300, 50);
  736. floatSensor.setFSmin(19.0f);
  737. floatSensor.setFSmax(21.0f);
  738. floatSensor.setFSval(19.0f);
  739. networkController.addSmartDevice(floatSensor);
  740. Port pFloatSensor = new Port(floatSensor, (short)1883, 15000);
  741. pFloatSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  742. pFloatSensor.setStatus(Port.SENDING);
  743. pFloatSensor.setLastTrigger(-357L);
  744. networkController.addDeviceToConnectionAndProtocol(pFloatSensor, mqtt,1);
  745. /*
  746. * Add Heater (every second update)
  747. */
  748. SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 1000);
  749. heaterDevice.setFSinfoName("home/" + roomName + "/heaterTemp");
  750. networkController.addLinkToDevice(zigbee, heaterDevice);
  751. networkController.moveSmartDevice(heaterDevice, 300, 500, 50);
  752. heaterDevice.setFSmin(19.0f);
  753. heaterDevice.setFSmax(21.0f);
  754. heaterDevice.setFSval(19.0f);
  755. networkController.addSmartDevice(heaterDevice);
  756. Port pHeaterDevice = new Port(heaterDevice, (short)1883, 15000);
  757. pHeaterDevice.setStatus(Port.SENDING);
  758. pHeaterDevice.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  759. pHeaterDevice.setLastTrigger(-1231L);
  760. networkController.addDeviceToConnectionAndProtocol(pHeaterDevice, mqtt,1);
  761. /*
  762. * Add a light
  763. */
  764. SmartLight smartLight = new SmartLight(roomName + " Light", room);
  765. smartLight.setBSinfoName("home/" + roomName + "/light");
  766. networkController.addLinkToDevice(zigbee, smartLight);
  767. networkController.moveSmartDevice(smartLight, 500, 500, 50);
  768. networkController.addSmartDevice(smartLight);
  769. Port pSmartLight = new Port(smartLight, (short)1883, 15000);
  770. pSmartLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  771. pSmartLight.setStatus(Port.SENDING);
  772. pSmartLight.setLastTrigger(-1207L);
  773. networkController.addDeviceToConnectionAndProtocol(pSmartLight, mqtt,1);
  774. /*
  775. * Add light Sensor
  776. */
  777. SmartLightSensor lightSensor = new SmartLightSensor(roomName + " LightSensor", room, 10000);
  778. lightSensor.setBSinfoName("home/" + roomName + "/light");
  779. networkController.addLinkToDevice(zigbee, lightSensor);
  780. networkController.moveSmartDevice(lightSensor, 500, 300, 50);
  781. networkController.addSmartDevice(lightSensor);
  782. Port pLightSensor = new Port(lightSensor, (short)1883, 15000);
  783. pLightSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
  784. pLightSensor.setStatus(Port.SENDING);
  785. pLightSensor.setLastTrigger(-1337L);
  786. networkController.addDeviceToConnectionAndProtocol(pLightSensor, mqtt,1);
  787. /*
  788. * Update visualization
  789. */
  790. controller.notifyObservers();
  791. /**
  792. * Run only if run == true
  793. */
  794. if(!run)return;
  795. try {
  796. System.out.println("Check 1");//TODO
  797. /**
  798. * Instances of the packet Sniffers
  799. */
  800. PacketSniffer snifferEM = null, snifferKNN = null, snifferHC = null;
  801. /*
  802. * Import Example PacketSniffer algorithms
  803. */
  804. /*
  805. Class<? extends PacketSniffer> em = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/EMClustering.java"));
  806. snifferEM = em.newInstance();
  807. Class<? extends PacketSniffer> hc = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/HierarchicalClustering.java"));
  808. snifferHC = hc.newInstance();*/
  809. Class<? extends PacketSniffer> knn = (Class<? extends PacketSniffer>) ImportController.importJavaClass(new File("examples/classifier/KMeansClustering.java"));
  810. snifferKNN = knn.newInstance();
  811. System.out.println("Check 2: Imported");//TODO
  812. /*
  813. * Create collectors
  814. */
  815. PacketCollector collectorKNN = new PacketCollector(snifferKNN);
  816. //PacketCollector collectorEM = new PacketCollector(snifferEM);
  817. //PacketCollector collectorHC = new PacketCollector(snifferHC);
  818. /*
  819. * Capture both links on all collectors
  820. */
  821. PacketCaptureController captureController = controller.getSimulationController().getPacketCaptureController();
  822. //captureController.addLinkToCollector(collectorEM, zigbee);
  823. captureController.addLinkToCollector(collectorKNN, zigbee);
  824. //captureController.addLinkToCollector(collectorHC, zigbee);
  825. captureController.addPacketCollector(collectorKNN);
  826. //captureController.addPacketCollector(collectorEM);
  827. //captureController.addPacketCollector(collectorHC);
  828. System.out.println("Check 3: created Controller");//TODO
  829. long currentTime = System.currentTimeMillis();
  830. long hour = 60 * 60 * 1000;
  831. /*
  832. * Simulate 24 hours
  833. */
  834. SimulationController sim = controller.getSimulationController();
  835. sim.setStartTime(0);
  836. sim.resetSimulation();
  837. sim.setStepDuration(hour);
  838. sim.setPrintPackets(false);
  839. sim.setEndTime(24*hour);
  840. heaterDevice.setFSmin(19f);
  841. heaterDevice.setFSmax(23f);
  842. heaterDevice.setFSval(20f);
  843. System.out.println("Training:");//TODO
  844. for(int i=0; i<24; i++)
  845. sim.getSimulationManager().simulateTimeIntervall(i*hour, hour);
  846. long new_time = System.currentTimeMillis();
  847. long elapsed_time = new_time-currentTime;
  848. System.out.println("Training data generation took: "+elapsed_time+"ms");
  849. currentTime = new_time;
  850. /*
  851. * Start Classifying
  852. */
  853. collectorKNN.setMode(true);
  854. //collectorEM.setMode(true);
  855. //collectorHC.setMode(true);
  856. new_time = System.currentTimeMillis();
  857. elapsed_time = new_time-currentTime;
  858. System.out.println("Training of algorithm took: "+elapsed_time+"ms");
  859. currentTime = new_time;
  860. /*
  861. * Simulate/Test 1 hour without anomalies
  862. */
  863. System.out.println("Test w/0 anomalies:");//TODO
  864. for(int i=24; i<25; i++)
  865. sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
  866. new_time = System.currentTimeMillis();
  867. elapsed_time = new_time-currentTime;
  868. System.out.println("Test witout anomalies took: "+elapsed_time+"ms");
  869. currentTime = new_time;
  870. /**
  871. * Light != Sensor
  872. * Value Anomaly 1h
  873. * TODO: Do more complex Anomaly Scenario
  874. */
  875. System.out.println("Value Anomalies:");
  876. float min = heaterDevice.getFSmin();
  877. float max = heaterDevice.getFSmax();
  878. float val = heaterDevice.getFSval();
  879. heaterDevice.setFSmin(18);
  880. heaterDevice.setFSval(18.5f);
  881. heaterDevice.setFSmax(24);
  882. heaterDevice.setLabel((short)-1);//-1 Value anomaly
  883. for(int i=25; i<26; i++)
  884. sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
  885. heaterDevice.setFSmin(min);
  886. heaterDevice.setFSmax(max);
  887. heaterDevice.setFSval(val);
  888. heaterDevice.setLabel((short)0);
  889. new_time = System.currentTimeMillis();
  890. elapsed_time = new_time-currentTime;
  891. System.out.println("Anomaly generation & classification: "+elapsed_time+"ms");
  892. currentTime = new_time;
  893. System.out.println("Testing completed");
  894. } catch(Exception e) {
  895. System.out.println("WARNING: Testing failed: ");
  896. e.printStackTrace();
  897. }
  898. }
  899. }