|
@@ -1,14 +1,17 @@
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
|
|
|
|
|
|
|
|
+import java.util.Collection;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Representation of connection EndPoints, which allows configuration of timings
|
|
* Representation of connection EndPoints, which allows configuration of timings
|
|
* and if it reacts to incoming traffic or even triggers new connections.
|
|
* and if it reacts to incoming traffic or even triggers new connections.
|
|
*
|
|
*
|
|
* @author Andreas T. Meyer-Berg
|
|
* @author Andreas T. Meyer-Berg
|
|
*/
|
|
*/
|
|
-public class Port {
|
|
|
|
|
|
+public class Port implements Schedulable {
|
|
|
|
|
|
/**
|
|
/**
|
|
* A closed Port which does not react to incoming traffic
|
|
* A closed Port which does not react to incoming traffic
|
|
@@ -62,6 +65,11 @@ public class Port {
|
|
*/
|
|
*/
|
|
private short jitter;
|
|
private short jitter;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Current Jitter, updated after every simulation
|
|
|
|
+ */
|
|
|
|
+ private short currentJitter;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Port number of this Port.
|
|
* Port number of this Port.
|
|
*/
|
|
*/
|
|
@@ -78,7 +86,8 @@ public class Port {
|
|
connection = null;
|
|
connection = null;
|
|
setTriggerInterval(new Random().nextInt(1000)+1);
|
|
setTriggerInterval(new Random().nextInt(1000)+1);
|
|
lastTrigger = 0;
|
|
lastTrigger = 0;
|
|
- setTriggerInterval(new Random().nextInt(5)+1);
|
|
|
|
|
|
+ jitter = (short)(new Random().nextInt(5)+1);
|
|
|
|
+ currentJitter = (short)Math.round(Math.random()*jitter);
|
|
responseTime = 0;
|
|
responseTime = 0;
|
|
this.portNumber = portNumber;
|
|
this.portNumber = portNumber;
|
|
}
|
|
}
|
|
@@ -96,6 +105,7 @@ public class Port {
|
|
this.triggerInterval = triggerInterval;
|
|
this.triggerInterval = triggerInterval;
|
|
lastTrigger = 0;
|
|
lastTrigger = 0;
|
|
jitter = 0;
|
|
jitter = 0;
|
|
|
|
+ currentJitter = (short)Math.round(Math.random()*jitter);
|
|
responseTime = 0;
|
|
responseTime = 0;
|
|
this.portNumber = portNumber;
|
|
this.portNumber = portNumber;
|
|
}
|
|
}
|
|
@@ -116,6 +126,7 @@ public class Port {
|
|
this.triggerInterval = triggerInterval;
|
|
this.triggerInterval = triggerInterval;
|
|
this.lastTrigger = lastTrigger;
|
|
this.lastTrigger = lastTrigger;
|
|
this.jitter = jitter;
|
|
this.jitter = jitter;
|
|
|
|
+ currentJitter = (short)Math.round(Math.random()*jitter);
|
|
this.responseTime = responseTime;
|
|
this.responseTime = responseTime;
|
|
this.portNumber = portNumber;
|
|
this.portNumber = portNumber;
|
|
}
|
|
}
|
|
@@ -286,4 +297,22 @@ public class Port {
|
|
return connection.getLink().getTransmissionDelayFrom(owner, to.getOwner());
|
|
return connection.getLink().getTransmissionDelayFrom(owner, to.getOwner());
|
|
return Long.MAX_VALUE;
|
|
return Long.MAX_VALUE;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public long getEventTime() {
|
|
|
|
+ return lastTrigger+triggerInterval+currentJitter;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void simulateEvent() {
|
|
|
|
+ if(connection==null || connection.getProtocol()==null || connection.getLink()==null)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ Collection<Packet> packets = connection.getProtocol().generateNextPackets(this, getEventTime(), false);
|
|
|
|
+ //Packets encapsulate in Connection
|
|
|
|
+
|
|
|
|
+ //Encapsulate in Links
|
|
|
|
+ connection.getLink().addPackets(packets);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|