|
@@ -14,6 +14,11 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.util.PacketComparator;
|
|
*/
|
|
*/
|
|
public class ConnectionPrecision extends ConnectionPerformance {
|
|
public class ConnectionPrecision extends ConnectionPerformance {
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Packets which should be returned in the next time step
|
|
|
|
+ */
|
|
|
|
+ private LinkedList<Packet> outOfBoundsPackets = new LinkedList<Packet>();
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Initializes the connection, adds participants of the protocol
|
|
* Initializes the connection, adds participants of the protocol
|
|
*
|
|
*
|
|
@@ -38,9 +43,18 @@ public class ConnectionPrecision extends ConnectionPerformance {
|
|
*/
|
|
*/
|
|
long endTime = startTime+duration;
|
|
long endTime = startTime+duration;
|
|
|
|
|
|
- LinkedList<Packet> returnPackets=new LinkedList<Packet>();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * All packets which should be returned in this time step
|
|
|
|
+ */
|
|
|
|
+ LinkedList<Packet> returnPackets = new LinkedList<Packet>();
|
|
returnPackets.addAll(getTerminationPackages(startTime));
|
|
returnPackets.addAll(getTerminationPackages(startTime));
|
|
- startTime+=returnPackets.size();
|
|
|
|
|
|
+ startTime += returnPackets.size();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Add packets of the last time step
|
|
|
|
+ */
|
|
|
|
+ returnPackets.addAll(outOfBoundsPackets);
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Self Sorting LinkedList for consistency
|
|
* Self Sorting LinkedList for consistency
|
|
*/
|
|
*/
|
|
@@ -81,8 +95,8 @@ public class ConnectionPrecision extends ConnectionPerformance {
|
|
|
|
|
|
if(p.getStatus()==Port.SENDING){
|
|
if(p.getStatus()==Port.SENDING){
|
|
if(p.getLastTrigger()+p.getTriggerInterval()<endTime){
|
|
if(p.getLastTrigger()+p.getTriggerInterval()<endTime){
|
|
- //Generate first package in the simulation interval
|
|
|
|
- returnPackets.addAll(protocol.generateNextPakets(p, (long) (p.getLastTrigger()+p.getTriggerInterval()+p.getJitter()*(Math.random()-0.5)),Math.random()<packetLossRate));
|
|
|
|
|
|
+ //Generate first package in the simulation interval (not before startTime though)
|
|
|
|
+ returnPackets.addAll(protocol.generateNextPakets(p, Math.max((long) (p.getLastTrigger()+p.getTriggerInterval()+p.getJitter()*(Math.random()-0.5)),startTime),Math.random()<packetLossRate));
|
|
|
|
|
|
//Remove Ports, which won't simulate again during this time step
|
|
//Remove Ports, which won't simulate again during this time step
|
|
it.remove();
|
|
it.remove();
|
|
@@ -117,6 +131,29 @@ public class ConnectionPrecision extends ConnectionPerformance {
|
|
* Sort and return packages
|
|
* Sort and return packages
|
|
*/
|
|
*/
|
|
returnPackets.sort(new PacketComparator());
|
|
returnPackets.sort(new PacketComparator());
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Remove packets which are not being sent in this time interval
|
|
|
|
+ */
|
|
|
|
+ outOfBoundsPackets.clear();
|
|
|
|
+ /**
|
|
|
|
+ * Last package, which should be sent in the next time step
|
|
|
|
+ */
|
|
|
|
+ Packet last = returnPackets.isEmpty()? null : returnPackets.getLast();
|
|
|
|
+
|
|
|
|
+ while (last != null&&last.getTimestamp()>endTime) {
|
|
|
|
+ outOfBoundsPackets.addFirst(returnPackets.removeLast());
|
|
|
|
+ if(returnPackets.isEmpty())
|
|
|
|
+ break;
|
|
|
|
+ last = returnPackets.getLast();
|
|
|
|
+ }
|
|
|
|
+ if(!outOfBoundsPackets.isEmpty()||true){
|
|
|
|
+ System.out.println("Connection: "+name);
|
|
|
|
+ System.out.println("Returned: ");
|
|
|
|
+ returnPackets.forEach(p->System.out.println(p.getTextualRepresentation()));
|
|
|
|
+ System.out.println("Not returned:");
|
|
|
|
+ outOfBoundsPackets.forEach(p->System.out.println(p.getTextualRepresentation()));
|
|
|
|
+ }
|
|
return returnPackets;
|
|
return returnPackets;
|
|
}
|
|
}
|
|
|
|
|