Browse Source

Adds Value Anomalies, some fixes & Improvements

* Removes Debug Prints during simulation
* Some negative trigger interval fixes
* Deactivates Anomaly Menu
* Minor Example Modifications (e.g. cold fridge)
Andreas T. Meyer-Berg 4 years ago
parent
commit
612fd3708c

+ 6 - 7
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Port.java

@@ -5,7 +5,6 @@ import java.util.Random;
 
 import org.apache.commons.math3.distribution.AbstractRealDistribution;
 import org.apache.commons.math3.distribution.LaplaceDistribution;
-import org.apache.commons.math3.distribution.NormalDistribution;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.distributionHandler.ConstantValueDistributionHandler;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
@@ -95,7 +94,7 @@ public class Port implements Schedulable {
 		owner = device;
 		connection = null;
 		triggerIntervalStat = new ConstantValueDistributionHandler(new Random().nextInt(1000)+1);
-		triggerInterval = triggerIntervalStat.sampleNextValue();
+		triggerInterval = Math.max(1, triggerIntervalStat.sampleNextValue());
 		//setTriggerInterval(new Random().nextInt(1000)+1);
 		lastTrigger = 0;
 		jitter = (short)(new Random().nextInt(5)+1);
@@ -115,7 +114,7 @@ public class Port implements Schedulable {
 		owner = device;
 		connection = null;
 		triggerIntervalStat = new ConstantValueDistributionHandler(triggerInterval);
-		this.triggerInterval = triggerIntervalStat.sampleNextValue();
+		this.triggerInterval = Math.max(1, triggerIntervalStat.sampleNextValue());
 		lastTrigger = 0;
 		jitter = 0;
 		currentJitter = (short)Math.round(Math.random()*jitter);
@@ -137,7 +136,7 @@ public class Port implements Schedulable {
 		owner = device;
 		connection = null;
 		triggerIntervalStat = new ConstantValueDistributionHandler(triggerInterval);
-		this.triggerInterval = triggerIntervalStat.sampleNextValue();
+		this.triggerInterval = Math.max(1, triggerIntervalStat.sampleNextValue());
 		this.lastTrigger = lastTrigger;
 		this.jitter = jitter;
 		currentJitter = (short)Math.round(Math.random()*jitter);
@@ -199,7 +198,7 @@ public class Port implements Schedulable {
 	public void setTriggerHandler(ProbabilityDistributionHandler triggerHandler){
 		this.triggerIntervalStat = triggerHandler;
 		boolean removed = SimulationManager.removeEvent(this);
-		this.triggerInterval = triggerHandler.sampleNextValue();
+		this.triggerInterval = Math.max(1, triggerHandler.sampleNextValue());
 		if(removed)
 			SimulationManager.scheduleEvent(this);
 	}
@@ -209,7 +208,7 @@ public class Port implements Schedulable {
 	 */
 	public void resampleTriggerInterval(){
 		boolean removed = SimulationManager.removeEvent(this);
-		this.triggerInterval = triggerIntervalStat.sampleNextValue();
+		this.triggerInterval = Math.max(triggerIntervalStat.sampleNextValue(),1);
 		if(removed)
 			SimulationManager.scheduleEvent(this);
 	}
@@ -356,7 +355,7 @@ public class Port implements Schedulable {
 		connection.getLink().addPackets(packets);
 		
 		//TODO: Sample next game
-		triggerInterval = triggerIntervalStat.sampleNextValue();
+		triggerInterval = Math.max(1,triggerIntervalStat.sampleNextValue());
 		
 		if(status==Port.SENDING && connection.getStatus()==Connection.ACTIVE)
 			SimulationManager.scheduleEvent(this);

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

@@ -147,7 +147,7 @@ public class SimulationManager extends Observable {
 			}
 			while(scheduler.hasNext(maxTime)){
 				Schedulable currentEvent = scheduler.getAndRemoveFirst();
-				System.out.println("Event time: "+currentEvent.getEventTime());
+				//System.out.println("Event time: "+currentEvent.getEventTime());
 				currentEvent.simulateEvent(currentEvent.getEventTime());
 			}
 			// Simulate SmartDevices - if they need some logic -> TODO: Insert as schedulable

+ 26 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarInsertAnomalies.java

@@ -15,6 +15,8 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PrecisionLink;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensor;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensor;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.SimpleProtocol;
 
 /**
@@ -44,6 +46,11 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
 	 */
 	private JMenu mnCrash;
 	
+	/**
+	 * Menu for Value Anomalies
+	 */
+	private JMenu mnValueAnomaly;
+	
 	/**
 	 * Create a new MenuBar for anomaly insertion
 	 * @param controller main Controller of the framework
@@ -63,12 +70,15 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
 		mnCrash = new JMenu("Crash Device");
 		this.add(mnCrash);
 		
+		mnValueAnomaly = new JMenu("Value Anomaly");
+		this.add(mnValueAnomaly);	
 	}
 	
 	@Override
 	public void update(Observable o, Object arg) {
 		mnDos.removeAll();
 		mnCrash.removeAll();
+		mnValueAnomaly.removeAll();
 		for(SmartDevice d : controller.getNetworkController().getVisibleSmartDevices()) {
 			JMenu mntmDosSource = new JMenu("Source: "+d.getName());
 			for(SmartDevice t: controller.getNetworkController().getVisibleSmartDevices()){
@@ -81,7 +91,23 @@ public class MenuBarInsertAnomalies extends JMenu implements Observer {
 			JMenuItem crashDevice = new JMenuItem(d.getName());
 			crashDevice.addActionListener(a->crashDevice(d));
 			mnCrash.add(crashDevice);
+			if(d instanceof BoolSensor) {
+				BoolSensor sensor = (BoolSensor)d;
+				JMenuItem itm = new JMenuItem(d.getName());
+				itm.addActionListener(a->sensor.setBSval(!sensor.getBSval()));
+			}else if(d instanceof FloatSensor) {
+				FloatSensor sensor = (FloatSensor)d;
+				JMenuItem itm = new JMenuItem(d.getName());
+				itm.addActionListener(a->{
+					sensor.setFSmax(100);
+					sensor.setFSval(80);
+				});
+				mnValueAnomaly.add(itm);
+			}
 		}
+		mnCrash.setEnabled(mnCrash.getMenuComponentCount()!=0);
+		mnDos.setEnabled(mnDos.getMenuComponentCount()!=0);
+		mnValueAnomaly.setEnabled(mnValueAnomaly.getMenuComponentCount()!=0);
 	}
 
 	/**

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

@@ -438,8 +438,10 @@ public class MenuBarNetworkExamples extends JMenu{
 		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);
@@ -507,8 +509,8 @@ public class MenuBarNetworkExamples extends JMenu{
 		kitchenFridge.setFSinfoName("home/kitchen/fridgeTemp");
 		networkController.addLinkToDevice(zigbee, kitchenFridge);
 		networkController.moveSmartDevice(kitchenFridge, 100, 600, 50);
-		kitchenFridge.setFSmin(15.0f);
-		kitchenFridge.setFSmax(32.0f);
+		kitchenFridge.setFSmin(-4.0f);
+		kitchenFridge.setFSmax(12.0f);
 		networkController.addSmartDevice(kitchenFridge);
 		Port pKitchenFridge = new Port(kitchenFridge, (short)1883, 15000);
 		pKitchenFridge.setStatus(Port.SENDING);