diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 20a6b4b..cab58b8 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -1,28 +1,13 @@ package fr.ntr; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Random; - -import fr.ntr.scheduler.Scheduler; public class AccessPoint { - /** - * nombre de slots - */ - private static int timeSlotNb; - /** - * Nombre de sous-porteuses - */ - private static int subCarrierNb; private final Cell cell1; private final Cell cell2; - private FileOutputStream outputDataFile; - private final List cellList; public AccessPoint(Cell cell1, Cell cell2){ @@ -38,14 +23,6 @@ public class AccessPoint { * @param duration */ public void startSimulation(int duration, List users) { - try{ - this.outputDataFile = new FileOutputStream("export" + File.separator + users.size() + ".csv", true); - outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes()); - } catch(IOException e) { - System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); - System.exit(1); - return; - } for (int ticks = 0; ticks < duration; ++ticks) { // Simulation cell1.reset(); @@ -58,7 +35,8 @@ public class AccessPoint { computeInterference(); // traite les données et les enregistre dans un fichier try { - analyseData(ticks, users); + cell1.analyseData(ticks, users); + cell2.analyseData(ticks, users); } catch (IOException e) { System.out.println("Can't export data"); } @@ -92,32 +70,4 @@ public class AccessPoint { } } } - - private void analyseData(int tick, List users) throws IOException { - /* double delayAverage = 0.0; - int nbPacketsSent = 0; - for(User u: users){ - List packets = u.getPacketsSent(); - nbPacketsSent += packets.size(); - for (Packets p: packets){ - delayAverage += p.getDurationSending(); - } - } - delayAverage = delayAverage/nbPacketsSent; - for(int i = 0; i < frame.length; i++) { - for(int j = 0; j < frame[i].length; j++) { - ResourceBlock ur = frame[i][j]; - if(ur.getUser() != null) { - String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n"); - try{ - outputDataFile.write(data.getBytes()); - }catch(IOException e){ - System.err.println("Cannot write the data in the output file"); - System.exit(1); - return; - } - } - } - } */ - } } diff --git a/src/main/java/fr/ntr/Cell.java b/src/main/java/fr/ntr/Cell.java index 5d5800d..741d043 100644 --- a/src/main/java/fr/ntr/Cell.java +++ b/src/main/java/fr/ntr/Cell.java @@ -2,6 +2,9 @@ package fr.ntr; import fr.ntr.scheduler.Scheduler; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.List; import java.util.Random; @@ -24,10 +27,21 @@ public class Cell { * Trame */ private final ResourceBlock[][] frame; - public Cell(Scheduler scheduler, ResourceBlock[][] frame, List users) { + private final FileOutputStream outputDataFile; + + public Cell(Scheduler scheduler, ResourceBlock[][] frame, List users, String filename) { this.users = users; this.scheduler = scheduler; this.frame = frame; + FileOutputStream output = null; + try{ + output = new FileOutputStream(filename, true); + output.write("tick;x;y;user;bandwidth;delay;\n".getBytes()); + } catch(IOException e) { + System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); + System.exit(1); + } + this.outputDataFile = output; } public void updateBandwidth(int ticks) { @@ -57,6 +71,34 @@ public class Cell { scheduler.scheduling(tick); } + public void analyseData(int tick, List users) throws IOException { + double delayAverage = 0.0; + int nbPacketsSent = 0; + for(User u: users){ + List packets = u.getPacketsSent(); + nbPacketsSent += packets.size(); + for (Packets p: packets){ + delayAverage += p.getDurationSending(); + } + } + delayAverage = delayAverage/nbPacketsSent; + for(int i = 0; i < frame.length; i++) { + for(int j = 0; j < frame[i].length; j++) { + ResourceBlock ur = frame[i][j]; + if(ur.getUser() != null) { + String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n"); + try{ + outputDataFile.write(data.getBytes()); + }catch(IOException e){ + System.err.println("Cannot write the data in the output file"); + System.exit(1); + return; + } + } + } + } + } + public ResourceBlock[][] getFrame() { return frame; } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index a6a6c32..9d9631f 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -59,8 +59,8 @@ public class Main { Scheduler schedulerCell1 = new RoundRobin(frame, users); Scheduler schedulerCell2 = new RoundRobin(frame, users); - Cell cell1 = new Cell(schedulerCell1, frame, users); - Cell cell2 = new Cell(schedulerCell2, frame, users); + Cell cell1 = new Cell(schedulerCell1, frame, users, "export" + File.separator + users.size() + "_cell1" + ".csv"); + Cell cell2 = new Cell(schedulerCell2, frame, users, "export" + File.separator + users.size() + "_cell2" + ".csv"); AccessPoint accessPoint = new AccessPoint(cell1, cell2); executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users)); }