From b3201ff7a5388b1a08e26c5db1dcca318a1cf03a Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 31 Mar 2023 11:42:01 +0200 Subject: [PATCH] fix allocation --- src/main/java/fr/ntr/User.java | 2 +- src/main/java/fr/ntr/scheduler/Scheduler.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 5106ba0..70750d7 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -49,7 +49,7 @@ public class User { if(timeInterval == 0) { timeInterval = random.nextInt(2, 102); // On tire un nombre entre 0 et 2 * m - mbis = random.nextInt(1, 2 * m + 1) ; + mbis = random.nextInt(0, 2 * m + 1) ; } // On calcule le nombre de paquets qu'on peut transmettre diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index d19015f..29e2fe6 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -16,8 +16,17 @@ public abstract class Scheduler { protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) { if (userMax != null && !userMax.getPacketsToSend().isEmpty()) { Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1); - if(p.getBitsNumberRemaining() > 0){ + if(p.getBitsNumberRemaining() >= 0){ p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); + if(p.getBitsNumberRemaining() <= 0) { + if(ticks == 0){ + p.setDurationSending(1); + }else { + p.setDurationSending(ticks); + } + userMax.getPacketsSent().add(p); + userMax.getPacketsToSend().remove(p); + } } else { if(ticks == 0){ p.setDurationSending(1);