ソースを参照

Adds Sensor Label

* To MQTT Publish Packets
* To SmartSensors
* As Attribute for classifying
Andreas T. Meyer-Berg 3 年 前
コミット
3830cbd157

+ 11 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SensorLabel.java

@@ -0,0 +1,11 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+public interface SensorLabel {
+
+	/**
+	 * Returns float or Boolean encoded as string of the sensor measuring this device
+	 * 
+	 * @return float/boolean sensor value as string
+	 */
+	String getSensorLabel();
+}

+ 9 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartLight.java

@@ -2,15 +2,16 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
 
-public class SmartLight extends BoolSensorDevice {
+public class SmartLight extends BoolSensorDevice implements SensorLabel {
 
 	RoomStatus roomStatus;
 	private boolean trueStatus = false;
+	private SmartLightSensor sensor;
 	
-	public SmartLight(String name, RoomStatus roomStatus) {
+	public SmartLight(String name, RoomStatus roomStatus, SmartLightSensor sensor) {
 		super(name);
 		this.roomStatus = roomStatus;
-		
+		this.sensor = sensor;
 	}
 
 	@Override
@@ -34,4 +35,9 @@ public class SmartLight extends BoolSensorDevice {
 		roomStatus.setLightOn(trueStatus);
 	}
 
+	@Override
+	public String getSensorLabel() {
+		return "" + sensor.getBSval();
+	}
+
 }

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

@@ -4,7 +4,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
 
-public class SmartLightSensor extends BoolSensorDevice implements Schedulable {
+public class SmartLightSensor extends BoolSensorDevice implements Schedulable, SensorLabel {
 
 	long eventTime = -1000;
 	long updateInterval = 10000;
@@ -38,5 +38,9 @@ public class SmartLightSensor extends BoolSensorDevice implements Schedulable {
 		SimulationManager.scheduleEvent(this);
 
 	}
+	@Override
+	public String getSensorLabel() {
+		return "" + getBSval();
+	}
 
 }

+ 9 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartTemperatureProducer.java

@@ -2,16 +2,18 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
 
-public class SmartTemperatureProducer extends FloatSensorDevice {
+public class SmartTemperatureProducer extends FloatSensorDevice implements SensorLabel {
 	
 	
 	private RoomStatus roomStatus;
 	private float tempChangePerHour = 0;
 	private float trueTemperature = 10f;
+	private SmartTemperatureSensor sensor;
 	
-	public SmartTemperatureProducer(String name, RoomStatus room, int updateInterval) {
+	public SmartTemperatureProducer(String name, RoomStatus room, int updateInterval, SmartTemperatureSensor sensor) {
 		super(name, updateInterval);
 		roomStatus = room;
+		this.sensor = sensor;
 	}
 	
 	@Override
@@ -42,5 +44,10 @@ public class SmartTemperatureProducer extends FloatSensorDevice {
 		 */
 		tempChangePerHour = trueTemperature-roomStatus.getTemperature();
 	}
+
+	@Override
+	public String getSensorLabel() {
+		return "" + sensor.getFSval();
+	}
 	
 }

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

@@ -2,7 +2,7 @@ package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
 
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
 
-public class SmartTemperatureSensor extends FloatSensorDevice {
+public class SmartTemperatureSensor extends FloatSensorDevice implements SensorLabel {
 	
 	
 	private RoomStatus roomStatus;
@@ -20,5 +20,10 @@ public class SmartTemperatureSensor extends FloatSensorDevice {
 		 */
 		super.setFSval(roomStatus.getTemperature());
 	}
+
+	@Override
+	public String getSensorLabel() {
+		return "" + getFSval();
+	}
 	
 }

+ 18 - 6
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/MQTT_protocol.java

@@ -16,6 +16,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolCollector;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensor;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollector;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensor;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SensorLabel;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets.MQTT_packet;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.packets.MQTTpublishPacket;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.AbstractEvent;
@@ -260,6 +261,11 @@ public class MQTT_protocol implements Protocol {
 			 * Value which should be published
 			 */
 			String newValue = null;
+			/**
+			 * Value of the connected Sensor (as label)
+			 */
+			String newSensorValue = null;
+
 			boolean isBoolean = false;
 			/**
 			 * True if value anomaly (value = -1)
@@ -286,6 +292,12 @@ public class MQTT_protocol implements Protocol {
 					isBoolean = true;
 				}
 			}
+			
+			if(device instanceof SensorLabel) {
+				newSensorValue = ((SensorLabel)device).getSensorLabel();
+			}else {
+				newSensorValue=newValue;
+			}
 
 			if (newTopic != null) {
 				/**
@@ -293,9 +305,9 @@ public class MQTT_protocol implements Protocol {
 				 */
 				Packet  pubPacket = null;
 				if(isBoolean) {
-					pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Boolean.parseBoolean(newValue));
+					pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Boolean.parseBoolean(newValue), Boolean.parseBoolean(newSensorValue));
 				}else {
-					pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Float.parseFloat(newValue));
+					pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Float.parseFloat(newValue),  Float.parseFloat(newSensorValue));
 				}
 				if(valueAnomaly) {
 					pubPacket.setLabel((short) 1);
@@ -333,9 +345,9 @@ public class MQTT_protocol implements Protocol {
 						 * Packet Broker -> Subscriber
 						 */
 						if(isBoolean) {
-							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Boolean.parseBoolean(newValue));
+							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Boolean.parseBoolean(newValue), Boolean.parseBoolean(newSensorValue));
 						}else {
-							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue));
+							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue),  Float.parseFloat(newSensorValue));
 						}
 						if(valueAnomaly) {
 							pubPacket.setLabel((short) 1);
@@ -394,9 +406,9 @@ public class MQTT_protocol implements Protocol {
 						timestep += broker.getResponseTime();
 						
 						if(isBoolean) {
-							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Boolean.parseBoolean(newValue));
+							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Boolean.parseBoolean(newValue), Boolean.parseBoolean(newSensorValue));
 						}else {
-							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue));
+							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue),  Float.parseFloat(newSensorValue));
 						}
 						if(valueAnomaly) {
 							pubPacket.setLabel((short) 1);

+ 13 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/packets/MQTTpublishPacket.java

@@ -17,6 +17,7 @@ public class MQTTpublishPacket extends MQTT_packet {
 	 * Value of the packet
 	 */
 	private float value = 0;
+	private float sensorValue = 0;
 	/**
 	 * True if boolean
 	 */
@@ -30,10 +31,11 @@ public class MQTTpublishPacket extends MQTT_packet {
 	 * @param topic topic of the message
 	 * @param value value of the message
 	 */
-	public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, float value) {
+	public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, float value, float sensorValue) {
 		super(MQTT_packet.PUBLISH, timestamp, source, destination);
 		this.setTopic(topic);
 		this.setValue(value);
+		this.sensorValue = sensorValue;
 		setBoolean(false);
 		this.message = topic + ":"+ value;
 	}
@@ -46,10 +48,11 @@ public class MQTTpublishPacket extends MQTT_packet {
 	 * @param topic topic of the message
 	 * @param value value of the message
 	 */
-	public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, boolean value) {
+	public MQTTpublishPacket(long timestamp, Port source, Port destination, String topic, boolean value, boolean sensorValue) {
 		super(MQTT_packet.PUBLISH, timestamp, source, destination);
 		this.setTopic(topic);
 		this.setValue(value ? 1 : 0);
+		this.sensorValue = this.value;
 		setBoolean(true);
 		this.message = "Topic:"+topic + ":"+ value;
 	}
@@ -78,4 +81,12 @@ public class MQTTpublishPacket extends MQTT_packet {
 		this.topic = topic;
 	}
 
+	public float getSensorValue() {
+		return sensorValue;
+	}
+	
+	public void setSensorValue(float sensorValue) {
+		this.sensorValue = sensorValue;
+	}
+
 }

+ 8 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/evaluation/BasicPacketClassifier.java

@@ -184,11 +184,13 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
 		// Packets per second
 		instance.setValue(6, getEstimatedPacketsPerSecond(link, packet));
 		// MQTT Value
-		if(packet instanceof MQTTpublishPacket)
+		if(packet instanceof MQTTpublishPacket) {
 			instance.setValue(7, ((MQTTpublishPacket)packet).getValue());
-		else
+			instance.setValue(8, ((MQTTpublishPacket)packet).getSensorValue());
+		} else {
 			instance.setValue(7, -1);
-		
+			instance.setValue(8, -1);
+		}
 		return instance;
 	}
 	
@@ -265,6 +267,9 @@ public abstract class BasicPacketClassifier implements PacketSniffer {
 		atts.add(pps);
 		atts.add(new Attribute("PacketValue", false));
 		//atts.add(new Attribute("Anomaly", false));
+		
+		// TODO: Sensor Attribute, given as side channel information
+		atts.add(new Attribute("SensorValue", false));
 
 		/*
 		atts = new ArrayList<Attribute>();

+ 16 - 15
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarNetworkExamples.java

@@ -864,7 +864,7 @@ public class MenuBarNetworkExamples extends JMenu{
 		/*
 		 * Add Heater (every second update)
 		 */
-		SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 1000);
+		SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 1000, heatSensor);
 		heaterDevice.setFSinfoName("home/" + roomName + "/heaterTemp");
 		networkController.addLinkToDevice(zigbee, heaterDevice);
 		networkController.moveSmartDevice(heaterDevice, 300, 500, 50);
@@ -879,20 +879,6 @@ public class MenuBarNetworkExamples extends JMenu{
 		networkController.addDeviceToConnectionAndProtocol(pHeaterDevice, mqtt,1);
 		heaterDevice.setLabel((short) 0);
 		
-		/*
-		 * Add a light
-		 */
-		SmartLight smartLight = new SmartLight(roomName + " Light", room);
-		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);
 		
 		/*
 		 * Add light Sensor
@@ -909,6 +895,21 @@ public class MenuBarNetworkExamples extends JMenu{
 		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 
 		 */