|
@@ -43,15 +43,20 @@ public class SimpleConnection implements Connection {
|
|
|
* Transmission status of the connection
|
|
|
*/
|
|
|
private byte status = Connection.ACTIVE;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Probability of packet loss. (default: 0.0 -> no packets are lost. 1.0 -> all packets are lost)
|
|
|
+ */
|
|
|
+ private double packetLossProbability = 0.0;
|
|
|
|
|
|
/**
|
|
|
- * Creates a new connection between to SmartDevices on a given Link, which
|
|
|
+ * Creates a new connection between two SmartDevice Ports on a given Link, which
|
|
|
* communicate with a protocol p
|
|
|
*
|
|
|
* @param src
|
|
|
- * SmartDevice which is the source of this connection
|
|
|
+ * Port which is the source of this connection
|
|
|
* @param dest
|
|
|
- * SmartDevice which is the destination of this connection
|
|
|
+ * Port which is the destination of this connection
|
|
|
* @param link
|
|
|
* Link which connects {@code src} and {@code dest}
|
|
|
* @param p
|
|
@@ -75,16 +80,16 @@ public class SimpleConnection implements Connection {
|
|
|
if(status != ACTIVE)return list;
|
|
|
//Generate packets by source
|
|
|
if(source.getLastTrigger()+source.getTriggerInterval()<startTime && source.getStatus()==Port.SENDING){
|
|
|
- list.add(p.generateNextPaket(source, startTime));
|
|
|
+ list.add(p.generateNextPaket(source, startTime,Math.random()<packetLossProbability));
|
|
|
}
|
|
|
while(source.getLastTrigger()+source.getTriggerInterval()<startTime+duration &&source.getStatus()==Port.SENDING)
|
|
|
- list.add(p.generateNextPaket(source, source.getLastTrigger()+source.getTriggerInterval()));
|
|
|
+ list.add(p.generateNextPaket(source, source.getLastTrigger()+source.getTriggerInterval(),Math.random()<packetLossProbability));
|
|
|
|
|
|
if(destination.getLastTrigger()+destination.getTriggerInterval()<startTime && destination.getStatus()==Port.SENDING){
|
|
|
- list.add(p.generateNextPaket(destination, startTime));
|
|
|
+ list.add(p.generateNextPaket(destination, startTime,Math.random()<packetLossProbability));
|
|
|
}
|
|
|
while(destination.getLastTrigger()+destination.getTriggerInterval()<startTime+duration &&destination.getStatus()==Port.SENDING)
|
|
|
- list.add(p.generateNextPaket(destination, destination.getLastTrigger()+destination.getTriggerInterval()));
|
|
|
+ list.add(p.generateNextPaket(destination, destination.getLastTrigger()+destination.getTriggerInterval(),Math.random()<packetLossProbability));
|
|
|
|
|
|
list.sort((x,y) -> Long.compare(x.getTimestamp(),y.getTimestamp()));
|
|
|
return list;
|
|
@@ -147,4 +152,14 @@ public class SimpleConnection implements Connection {
|
|
|
this.status = status;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void setPacketLossProbability(double lossPercentage) {
|
|
|
+ packetLossProbability = lossPercentage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public double getPacketLossProbability() {
|
|
|
+ return packetLossProbability;
|
|
|
+ }
|
|
|
+
|
|
|
}
|