Browse Source

Limits anomaly label to packets with the deviating values

Andreas T. Meyer-Berg 4 years ago
parent
commit
7752ed62ee

+ 1 - 1
examples/classifier/KMeansClustering.java

@@ -20,7 +20,7 @@ public class KMeansClustering extends BasicPacketClassifier {
 	/**
 	 * Number of Clusters
 	 */
-	protected int NUMBER_OF_CLUSTERS = 16;
+	protected int NUMBER_OF_CLUSTERS = 17;
 	protected double[] stdv = new double[NUMBER_OF_CLUSTERS];
 	/**
 	 * Initializes the k means clusterer

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

@@ -114,7 +114,7 @@ public class ConnectionPerformance implements Connection {
 	@Override
 	public Collection<Packet> encapsulatePackages(Collection<Packet> packets) {
 		packets.forEach(p->{
-			p.setLabel((short) Math.max(label, p.getSource().getOwner().getLabel()));
+			p.setLabel((short) Math.max(Math.max(label, p.getLabel()), p.getSource().getOwner().getLabel()));
 		});
 		return packets;
 	}

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

@@ -361,10 +361,4 @@ public class Port implements Schedulable {
 			SimulationManager.scheduleEvent(this);
 		
 	}
-	
-	public static void main(String[] args) {
-		AbstractRealDistribution dist = new LaplaceDistribution(30, 50);
-		for(int i = 0; i<100; i++)
-			System.out.println(dist.sample());
-	}
 }

+ 16 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/protocols/MQTT_protocol.java

@@ -7,6 +7,8 @@ import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Random;
 
+import org.hamcrest.core.IsAnything;
+
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
@@ -168,7 +170,7 @@ public class MQTT_protocol implements Protocol {
 			 * Topic which should be subscribed to
 			 */
 			String newTopic = null;
-
+			
 			/**
 			 * Check if FloatCollector & not subscribed
 			 */
@@ -261,7 +263,10 @@ public class MQTT_protocol implements Protocol {
 			 */
 			String newValue = null;
 			boolean isBoolean = false;
-
+			/**
+			 * True if value anomaly (value = -1)
+			 */
+			boolean valueAnomaly = (device.getLabel()==(short)-1);
 			/**
 			 * Check if FloatSensor
 			 */
@@ -294,6 +299,9 @@ public class MQTT_protocol implements Protocol {
 				}else {
 					pubPacket = new MQTTpublishPacket(timestep, port, broker, newTopic, Float.parseFloat(newValue));
 				}
+				if(valueAnomaly) {
+					pubPacket.setLabel((short) 1);
+				}
 				/**
 				 * Send Packet
 				 */
@@ -331,6 +339,9 @@ public class MQTT_protocol implements Protocol {
 						}else {
 							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue));
 						}
+						if(valueAnomaly) {
+							pubPacket.setLabel((short) 1);
+						}
 						returnPackets.add(pubPacket);
 						if (p.getStatus() != Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE) {
 							returnPackets.add(
@@ -389,6 +400,9 @@ public class MQTT_protocol implements Protocol {
 						}else {
 							pubPacket = new MQTTpublishPacket(timestep, broker, p, newTopic, Float.parseFloat(newValue));
 						}
+						if(valueAnomaly) {
+							pubPacket.setLabel((short) 1);
+						}
 						returnPackets.add(pubPacket);
 						if (p.getStatus() != Port.CLOSED && delayBrokerToSub != Long.MAX_VALUE) {
 							returnPackets.add(

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

@@ -745,7 +745,7 @@ public class MenuBarNetworkExamples extends JMenu{
 			kitchenFridge.setFSmin(18);
 			kitchenFridge.setFSval(18.5f);
 			kitchenFridge.setFSmax(24);
-			kitchenFridge.setLabel((short)1);
+			kitchenFridge.setLabel((short)-1);//-1 Value anomaly
 			for(int i=27; i<28; i++)
 				sim.getSimulationManager().simulateTimeIntervall(hour*i, hour);
 			kitchenFridge.setFSmin(min);