|
@@ -799,9 +799,27 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
/**
|
|
|
* 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
|
|
@@ -950,7 +968,9 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
*/
|
|
|
PacketCaptureController captureController = controller.getSimulationController().getPacketCaptureController();
|
|
|
//captureController.addLinkToCollector(collectorEM, zigbee);
|
|
|
- captureController.addLinkToCollector(collectorKNN, zigbee);
|
|
|
+ //captureController.addLinkToCollector(collectorKNN, zigbee);
|
|
|
+ captureController.addDeviceToCollector(collectorKNN, smartLight);
|
|
|
+ captureController.addDeviceToCollector(collectorKNN, heaterDevice);
|
|
|
//captureController.addLinkToCollector(collectorHC, zigbee);
|
|
|
captureController.addPacketCollector(collectorKNN);
|
|
|
//captureController.addPacketCollector(collectorEM);
|
|
@@ -960,17 +980,7 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
|
|
|
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);
|
|
|
- long endTime = 24*hour;
|
|
|
- sim.setEndTime(endTime);
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Training events
|
|
@@ -981,11 +991,10 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
*/
|
|
|
NormalDistribution lightDist = new NormalDistribution(hour/2, hour/4);
|
|
|
long eventTime = 0;
|
|
|
- while(eventTime < endTime + hour/2) {
|
|
|
+ while(eventTime < noAnomEnd) {
|
|
|
/**
|
|
|
* At least 1 second between events
|
|
|
*/
|
|
|
- eventTime+=Math.max(1000, Math.round(lightDist.sample()));
|
|
|
SimulationManager.scheduleEvent(new AbstractEvent(eventTime) {
|
|
|
|
|
|
@Override
|
|
@@ -994,6 +1003,7 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
smartLight.setTrueStatus(!smartLight.isTrueStatus());
|
|
|
}
|
|
|
});
|
|
|
+ eventTime+=Math.max(1000, Math.round(lightDist.sample()));
|
|
|
|
|
|
}
|
|
|
/**
|
|
@@ -1001,7 +1011,7 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
*/
|
|
|
NormalDistribution tempDist = new NormalDistribution(2*hour, hour/2);
|
|
|
eventTime = 0;
|
|
|
- while(eventTime < 27 * hour) {
|
|
|
+ while(eventTime < lightEnd) {
|
|
|
/**
|
|
|
* At least 1 second between events
|
|
|
*/
|
|
@@ -1019,8 +1029,10 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
}
|
|
|
|
|
|
System.out.println("Training:");//TODO
|
|
|
- for(int i=0; i<24; i++)
|
|
|
- sim.getSimulationManager().simulateTimeIntervall(i*hour, hour);
|
|
|
+ while(currentSimTime<endTime) {
|
|
|
+ sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
|
|
|
+ currentSimTime+=stepLength;
|
|
|
+ }
|
|
|
|
|
|
long new_time = System.currentTimeMillis();
|
|
|
long elapsed_time = new_time-currentTime;
|
|
@@ -1045,8 +1057,10 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
*/
|
|
|
snifferKNN.setCurrentScenario("NoAnomalies");
|
|
|
System.out.println("Test w/0 anomalies:");//TODO
|
|
|
- for(int i=24; i<26; i++)
|
|
|
- sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
|
|
|
+ while(currentSimTime<noAnomEnd) {
|
|
|
+ sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
|
|
|
+ currentSimTime+=stepLength;
|
|
|
+ }
|
|
|
|
|
|
new_time = System.currentTimeMillis();
|
|
|
elapsed_time = new_time-currentTime;
|
|
@@ -1061,8 +1075,10 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
System.out.println("Light Anomaly:");
|
|
|
smartLight.setTrueStatus(!smartLight.getBSval());
|
|
|
smartLight.setLabel((short)-1);
|
|
|
- for(int i=26; i<27; i++)
|
|
|
- sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
|
|
|
+ while(currentSimTime<lightEnd) {
|
|
|
+ sim.getSimulationManager().simulateTimeIntervall(currentSimTime, stepLength);
|
|
|
+ currentSimTime+=stepLength;
|
|
|
+ }
|
|
|
smartLight.setLabel((short)0);
|
|
|
smartLight.setBSval(smartLight.isTrueStatus());
|
|
|
|
|
@@ -1099,9 +1115,11 @@ public class MenuBarNetworkExamples extends JMenu{
|
|
|
System.out.println("Temperature Anomaly:");
|
|
|
heaterDevice.setFSval(21f);
|
|
|
heaterDevice.setTrueTemperature(34f);
|
|
|
- heaterDevice.setLabel((short)-1);//-1 Value anomaly
|
|
|
- for(int i=27; i<29; i++)
|
|
|
- sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
|
|
|
+ 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);
|