Browse Source

Improves Ping package and protocol (more detail), Sets port as active

Andreas T. Meyer-Berg 6 years ago
parent
commit
d285ce9c39

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

@@ -81,6 +81,17 @@ public class Port {
 		this.portNumber = portNumber;
 	}
 	
+	public Port(SmartDevice device, short portNumber, long triggerInterval){
+		status = SENDING;
+		owner = device;
+		connection = null;
+		this.triggerInterval = triggerInterval;
+		lastTrigger = 0;
+		jitter = 1;
+		responseTime = 2;
+		this.portNumber = portNumber;
+	}
+	
 	
 	/**
 	 * @return the status

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

@@ -48,13 +48,13 @@ public class Ping_protocol implements Protocol {
 		if(port == sender && target != null){
 			packets.add(new Ping_packet(timestep, sender, target, Ping_packet.EchoRequest, sequence));
 			if(target.getStatus() >= Port.OPEN){
-				packets.add(new Ping_packet(timestep, target, sender, Ping_packet.EchoReply, sequence));
+				packets.add(new Ping_packet(timestep+target.getResponseTime()+(short)(target.getJitter()*Math.random()), target, sender, Ping_packet.EchoReply, sequence));
 			}
 		}
 		else if(port == target && sender != null){
 			packets.add(new Ping_packet(timestep, target, sender, Ping_packet.EchoRequest, sequence));
 			if(sender.getStatus() >= Port.OPEN){
-				packets.add(new Ping_packet(timestep, sender, target, Ping_packet.EchoReply, sequence));
+				packets.add(new Ping_packet(timestep+sender.getResponseTime()+(short)(sender.getJitter()*Math.random()), sender, target, Ping_packet.EchoReply, sequence));
 			}
 		}
 		return packets;

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

@@ -152,9 +152,9 @@ public class Ping_packet extends Packet {
 	 */
 	private String getType(){
 		if(type == EchoRequest)
-			return "Ping";
+			return "EchoRequest";
 		if(type == EchoReply)
-			return "Pong";
+			return "EchoReply";
 		return "unknown";
 	}
 	

+ 2 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationInteractor.java

@@ -429,8 +429,8 @@ public class VisualisationInteractor implements MouseInputListener,
 					+ " to " + connectionTo.getName());
 			l.addDevice(connectionFrom);
 			l.addDevice(connectionTo);
-			Port p1 = new Port(connectionFrom, (short) 1);
-			Port p2 = new Port(connectionTo, (short) 2);
+			Port p1 = new Port(connectionFrom, (short) 1,(long) (Math.random()*300+300));
+			Port p2 = new Port(connectionTo, (short) 2,(long) (Math.random()*300+300));
 			Connection c = new ConnectionPerformance(l, new SimpleProtocol(p1, p2));
 			c.addSmartDevice(p1);
 			c.addSmartDevice(p2);