Browse Source

Adds PerformanceTest Preset

Andreas T. Meyer-Berg 5 years ago
parent
commit
bbfad9148b

+ 33 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/Main.java

@@ -17,6 +17,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketCollector;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PrecisionLink;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
@@ -74,6 +75,7 @@ public class Main {
 	    //initializeTest();
 	    //initializeMQTTTest();
 	    //initializeUserStudy();
+		initializePerformanceTest();
 		//Test packetCapture
 	    //sim.getPacketCaptureController().addPacketCollector(new PacketCollector(new SimplePacketSniffer()));
 	    v = new MainFrame(controller);
@@ -84,11 +86,40 @@ public class Main {
 	    //testPackageCollection();
 	    
 	}
+	
+	private static void initializePerformanceTest(){
+		SmartDevice tic = new SmartDevice("Tic");
+		tic.setX(100);
+		tic.setY(100);
+		SmartDevice toc = new SmartDevice("Toc");
+		toc.setX(100);
+		toc.setY(250);
+		c.addSmartDevice(tic);
+		c.addSmartDevice(toc);
+		
+		Link l = new PrecisionLink("Channel");
+		c.addLink(l);
+		c.addLinkToDevice(l, tic);
+		c.addLinkToDevice(l, toc);
+
+		Port ticP = new Port(tic, (short)2, 200, (short)0, 0, (short)0);
+		Port tocP = new Port(toc, (short)3, 200, (short)0, -100, (short)0);
+		tic.addPort(ticP);
+		toc.addPort(tocP);
+		
+		Connection con = new ConnectionPrecision(l, new SimpleProtocol());
+		c.addConnection(con);
+		c.addConnectionToLink(con, l);
+		c.addDeviceToConnectionAndProtocol(ticP, con, 0);
+		c.addDeviceToConnectionAndProtocol(tocP, con, 1);
+		sim.setCurrentTime(-1);
+	}
+	
 	/**
 	 * Initializes a basic test Network, which contains a few SmartDevices, one Link and one Connection
 	 */
-	//@SuppressWarnings("unused")
-	public static void initializeUserStudy(){
+	@SuppressWarnings("unused")
+	private static void initializeUserStudy(){
 		/**
 		 * Preset one SmartDevice
 		 */

+ 29 - 3
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/Port.java

@@ -79,18 +79,44 @@ public class Port {
 		setTriggerInterval(new Random().nextInt(1000)+1);
 		lastTrigger = 0;
 		setTriggerInterval(new Random().nextInt(5)+1);
-		responseTime = 3;
+		responseTime = 0;
 		this.portNumber = portNumber;
 	}
 	
+	/**
+	 * Creates a new Port for the given Device with the specified PortNumber
+	 * @param device SmartDevice this port listens on
+	 * @param portNumber Number of the Port
+	 * @param triggerInterval frequency the port should trigger
+	 */
 	public Port(SmartDevice device, short portNumber, long triggerInterval){
 		status = SENDING;
 		owner = device;
 		connection = null;
 		this.triggerInterval = triggerInterval;
 		lastTrigger = 0;
-		jitter = 1;
-		responseTime = 2;
+		jitter = 0;
+		responseTime = 0;
+		this.portNumber = portNumber;
+	}
+	
+	/**
+	 * Creates a new Port for the given Device with the specified PortNumber
+	 * @param device SmartDevice this port listens on
+	 * @param portNumber Number of the Port
+	 * @param triggerInterval frequency the port should trigger
+	 * @param jitter Jitter
+	 * @param lastTrigger last time a packet was sent
+	 * @param responseTime response time
+	 */
+	public Port(SmartDevice device, short portNumber, long triggerInterval, short jitter, long lastTrigger, short responseTime){
+		status = SENDING;
+		owner = device;
+		connection = null;
+		this.triggerInterval = triggerInterval;
+		this.lastTrigger = lastTrigger;
+		this.jitter = jitter;
+		this.responseTime = responseTime;
 		this.portNumber = portNumber;
 	}
 	

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

@@ -57,7 +57,7 @@ public class SimpleProtocol implements Protocol {
 		if(p==null) return ret;
 		p.setLastTrigger(timestep);
 		if(packetLost)ret.add(new SimplePacket(timestep, p, p == source ? destination : source, "Lost"));
-		if(p == destination)
+		else if(p == destination)
 			ret.add(new SimplePacket(timestep, destination, source));
 		else
 			ret.add(new SimplePacket(timestep, source, destination));