diff --git a/.classpath b/.classpath deleted file mode 100644 index 4857be4..0000000 --- a/.classpath +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/build.gradle b/build.gradle index c009bd7..079c0fe 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,10 @@ plugins { id 'application' } -application { - mainClassName = 'fr.ntr.Main' +run { + args = ["5000", "2"] } +application { + mainClassName = 'fr.ntr.Main' +} \ No newline at end of file diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 92fad87..0a1170e 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -2,6 +2,7 @@ package fr.ntr; import java.util.ArrayList; import java.util.List; +import java.util.Random; import fr.ntr.scheduler.Scheduler; @@ -13,7 +14,7 @@ public class AccessPoint { */ private static int timeSlotNb; /** - * nombre de sous-porteuses + * Nombre de sous-porteuses */ private static int subCarrierNb; /** @@ -21,37 +22,75 @@ public class AccessPoint { */ private ResourceBlock[][] frame; /** - * reste pour la prochaine source + * Reste pour la prochaine source */ private double leftForNextSource; + /** + * Portée minimum et maximum de l'antenne + */ + private final double min, max; - public AccessPoint(Scheduler scheduler) { - this.users = new ArrayList(); + public AccessPoint(Scheduler scheduler, double min, double max) { + this.min = min; + this.max = max; + this.users = new ArrayList<>(); this.scheduler = scheduler; this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; } - public void startSimulation(int duration){ - + /** + * Lancer la simulation + * @param duration + */ + public void startSimulation(int duration, int nbUsers) { + for (int ticks = 0; ticks < duration; ++ticks) { + // Simulation + reset(); + init(nbUsers); + schedule(); + // traite les données et les enregistre dans un fichier + analyseData(); + } } /** * Génération du débit et des paquets */ - private void init(){ - + private void init(int nbUsers) { + double[] distance = { 200d, 500d }; + for (int i = 0; i < nbUsers; i++) { + User user = new User(distance[i], timeSlotNb, subCarrierNb); + user.generateBandwidth(); + user.createPackets(); + this.users.add(user); + } } - private void dataAnalysis(){ + private void schedule() { } - private void reset(){ + private void analyseData() { } - public int getFrameSize(){ + private void plotData() { + + } + + private void reset() { + + } + + public int getFrameSize() { return this.timeSlotNb * this.subCarrierNb; } -} \ No newline at end of file + + public ResourceBlock[][] getFrame() { + return frame; + } + public void setFrame(ResourceBlock[][] frame) { + this.frame = frame; + } +} diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index ff789fa..e8603aa 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,22 +1,30 @@ package fr.ntr; +import fr.ntr.scheduler.RoundRobin; + public class Main { + public static void main(String[] args) { - - /** - * nombre de ticks de la simulation - * -> durée de la simulation - */ - int numberOfTicks = 5000; - - /** - * nombre maximal d'utilisateurs dans le système - */ - int maximumLoad = 20; - - //TODO ajouter accès à AccessPoint - System.out.println("Hello World"); + if(args.length == 2) { + int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation + int maximumLoad; // Nombre maximal d'utilisateurs dans le système + try { + numberOfTicks = Integer.parseInt(args[0]); + maximumLoad = Integer.parseInt(args[1]); + System.out.println("ticks: " + numberOfTicks + ", users: " + maximumLoad); + } catch (NumberFormatException e) { + System.err.println("Cannot parse launch argument to integer"); + System.exit(1); + return; + } + AccessPoint accessPoint = new AccessPoint(new RoundRobin("round robin", 0), 0, 50); + accessPoint.startSimulation(numberOfTicks, maximumLoad); + } else { + System.err.println("Please give launch arguments"); + System.err.println("gradle run --args=\" \""); + System.exit(1); + } } } \ No newline at end of file diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index ad45b57..54581d4 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -10,16 +10,25 @@ public class User { private final List packetsToSend; private final List packetsSent; - public User(double distance) { + public User(double distance, int timeSlotNb, int subCarrierNb) { this.distance = distance; - this.bandwidthTable = new double[1][1]; // TODO: 03/03/2023 Changer valeurs + this.bandwidthTable = new double[timeSlotNb][subCarrierNb]; this.packetsToSend = new ArrayList<>(); this.packetsSent = new ArrayList<>(); } public void generateBandwidth() { - + double random = Math.random(); + for(int i = 0; i < bandwidthTable.length; i++) { + for(int j = 0; j < bandwidthTable[i].length; j++) { + double h = 8 * Math.sqrt(-2 * Math.log(1 - random)); + double gain = h * Math.pow(10, random*8/10) * Math.pow(1/this.distance, 3.5); + double spectralEfficiency = (43 * gain)/(15000*(-174)); + double mkn = Math.log1p(spectralEfficiency); + this.bandwidthTable[i][j] = mkn; + } + } } public void createPackets() { diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 0d19b57..331661f 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -1,26 +1,39 @@ package fr.ntr.scheduler; import java.util.List; -import java.util.Random; import fr.ntr.User; public class RoundRobin extends Scheduler { - private String name; - private int index; - - public RoundRobin(String name, int index) { - this.name = name; - this.index = index; - } - - @Override - public void scheduling() { - } - - //Ts = Time Slot - //Sp =sous porteuse - private void selectionUtilisateur(int Ts, int Sp, List Users) { - int random = new Random().nextInt(0, Users.size()-1); + private String name; + private int index; + + public RoundRobin(String name, int index) { + this.name = name; + this.index = index; + } + + /** + * Entry + * Return + */ + @Override + public void scheduling() { + index = 0; + + } + + /** + * Entry Time slot (int), Sous porteuse(int), and users ( List) + * Return the user in function of TS and SP selected + */ + private User UserSelection(int Ts, int Sp, List Users) { + for (int i = 0; i < Ts; i++) { + for (int j = 0; j < Sp; j++) { + index++; + } } + return Users.get(index%(Users.size() - 1)); + + } }