From b9eb223e6469eea9ae5343b024c725322a3e7ebd Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Sat, 11 Mar 2023 12:04:22 +0100 Subject: [PATCH] =?UTF-8?q?g=C3=A9n=C3=A9ration=20des=20paquets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/ntr/AccessPoint.java | 18 +++++++++++++----- src/main/java/fr/ntr/User.java | 13 ++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index cf74f12..b6f49d6 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -58,16 +58,24 @@ public class AccessPoint { * Génération du débit et des paquets */ private void init(int nbUsers, int ticks) { - double n = 200; - double timeInterval = 50; + int n = 200; + int timeInterval = 50 + new Random().nextInt(50); + + // 2 groupes d'utilisateurs, proches et éloignés double[] distance = { 200d, 1000d }; for (int i = 0; i < distance.length; i++) { for(int j = 0; j < nbUsers; j++){ User user = new User(distance[i], timeSlotNb, subCarrierNb); - user.generateBandwidth(); - if(ticks % timeInterval){ - n = user.createPackets(n); + // On regénère le tableau de débits toutes les 50 ms + if(ticks % 50 == 0){ + user.generateBandwidth(); + } + + // On regénère les sources toutes les 50-100 ms + if(ticks % timeInterval == 0){ + n = user.createPackets(n); + timeInterval = 50 + new Random().nextInt(51); } this.users.add(user); } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 30df54d..8d62352 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -10,13 +10,14 @@ public class User { private final double[][] bandwidthTable; private final List packetsToSend; private final List packetsSent; + private int leftForNextSource; public User(double distance, int timeSlotNb, int subCarrierNb) { this.distance = distance; this.bandwidthTable = new double[timeSlotNb][subCarrierNb]; this.packetsToSend = new ArrayList<>(); this.packetsSent = new ArrayList<>(); - + this.leftForNextSource = 0; } public void generateBandwidth() { @@ -32,9 +33,15 @@ public class User { } } - public void createPackets(double m) { + public int createPackets(int m) { Random random = new Random(); - double mbis = random.nextDouble() * (2 * m); + int mbis = (int) random.nextDouble() * (2 * m); + int nbPacketsToSend = mbis / Packets.packetSize; + this.leftForNextSource = mbis % Packets.packetSize; + for(int i = 0; i < nbPacketsToSend; i++){ + this.packetsToSend.add(new Packets(i, i, i)); // Voir pour les valeurs du contructeur Packets + } + return mbis; } /**