calcul temps de transmission de chaque paquet

This commit is contained in:
Remi Boure 2023-03-17 11:36:27 +01:00
parent b5691cb6d0
commit 6c51709f53
3 changed files with 51 additions and 13 deletions

View File

@ -66,7 +66,7 @@ public class AccessPoint {
// On regénère les sources toutes les 50-100 ms // On regénère les sources toutes les 50-100 ms
if(ticks % timeInterval == 0){ if(ticks % timeInterval == 0){
n = user.createPackets(n); n = user.createPackets(n, ticks);
timeInterval = 50 + new Random().nextInt(51); timeInterval = 50 + new Random().nextInt(51);
} }
} }

View File

@ -2,13 +2,39 @@ package fr.ntr;
public class Packets { public class Packets {
static final int packetSize = 100; static final int packetSize = 100;
private int creationTime; private int startTimeSending;
private int endTimeSending; private int endTimeSending;
private int durationSending;
private double bitsNumberRemaining; private double bitsNumberRemaining;
public Packets(int creationTime, int endTimeSending, double bitsNumberRemaining){ public Packets(int startTimeSending){
this.creationTime = creationTime; this.startTimeSending = startTimeSending;
}
public int getStartTimeSending() {
return startTimeSending;
}
public void setStartTimeSending(int startTimeSending) {
this.startTimeSending = startTimeSending;
}
public int getEndTimeSending() {
return endTimeSending;
}
public void setEndTimeSending(int endTimeSending) {
this.endTimeSending = endTimeSending; this.endTimeSending = endTimeSending;
this.bitsNumberRemaining = bitsNumberRemaining;
} }
public void setDurationSending(){
int durationSending = endTimeSending - startTimeSending;
this.durationSending = durationSending;
}
public int getDurationSending() {
return durationSending;
}
} }

View File

@ -33,22 +33,34 @@ public class User {
} }
} }
public int createPackets(int m) { /**
*
* @param m
* @param ticks qui va définir le temps auquel a été créé un paquet
* @return
*/
public int createPackets(int m, int ticks) {
Random random = new Random(); Random random = new Random();
int mbis = (int) random.nextDouble() * (2 * m); // On tire un nombre entre 0 et 2 * m
int mbis = random.nextInt(2 * (m + this.leftForNextSource));
// On calcule le nombre de paquets qu'on peut transmettre
int nbPacketsToSend = mbis / Packets.packetSize; int nbPacketsToSend = mbis / Packets.packetSize;
// On conserve le nombre de bits restants pour la prochaine génération
this.leftForNextSource = mbis % Packets.packetSize; this.leftForNextSource = mbis % Packets.packetSize;
// On crée les paquets
for(int i = 0; i < nbPacketsToSend; i++){ for(int i = 0; i < nbPacketsToSend; i++){
this.packetsToSend.add(new Packets(i, i, i)); // Voir pour les valeurs du contructeur Packets this.packetsToSend.add(new Packets(ticks));
} }
return mbis; return mbis;
} }
/** /**
* calculDélai * calcul délais de transmission des paquets
*/ */
public double calculateLatency() { public void computeTimeSending() {
return 0d; for(Packets p : packetsToSend){
p.setDurationSending();
}
} }
public double getDistance() { public double getDistance() {