2023-03-03 10:38:35 +01:00
|
|
|
package fr.ntr;
|
|
|
|
|
2023-03-24 09:05:44 +01:00
|
|
|
import java.io.File;
|
2023-03-17 10:55:45 +01:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
2023-03-03 11:28:16 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import fr.ntr.scheduler.Scheduler;
|
|
|
|
|
2023-03-03 10:38:35 +01:00
|
|
|
public class AccessPoint {
|
2023-03-31 08:27:43 +02:00
|
|
|
private final List<User> users;
|
|
|
|
private final Scheduler scheduler;
|
2023-03-03 11:47:53 +01:00
|
|
|
/**
|
|
|
|
* nombre de slots
|
|
|
|
*/
|
|
|
|
private static int timeSlotNb;
|
|
|
|
/**
|
2023-03-10 08:19:07 +01:00
|
|
|
* Nombre de sous-porteuses
|
2023-03-03 11:47:53 +01:00
|
|
|
*/
|
|
|
|
private static int subCarrierNb;
|
|
|
|
/**
|
|
|
|
* trame
|
|
|
|
*/
|
2023-03-31 08:27:43 +02:00
|
|
|
private final ResourceBlock[][] frame;
|
2023-03-17 20:31:42 +01:00
|
|
|
private FileOutputStream outputDataFile;
|
|
|
|
|
2023-03-03 11:28:16 +01:00
|
|
|
|
2023-03-31 08:27:43 +02:00
|
|
|
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
|
2023-03-17 11:11:26 +01:00
|
|
|
this.users = users;
|
2023-03-03 11:28:16 +01:00
|
|
|
this.scheduler = scheduler;
|
2023-03-17 10:45:55 +01:00
|
|
|
this.frame = frame;
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-06 17:48:22 +01:00
|
|
|
/**
|
|
|
|
* Lancer la simulation
|
|
|
|
* @param duration
|
|
|
|
*/
|
2023-03-17 20:31:42 +01:00
|
|
|
public void startSimulation(int duration) {
|
|
|
|
try{
|
2023-03-24 09:05:44 +01:00
|
|
|
this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true);
|
2023-03-28 09:35:26 +02:00
|
|
|
outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
|
2023-03-24 09:05:44 +01:00
|
|
|
} catch(IOException e) {
|
|
|
|
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
2023-03-17 20:31:42 +01:00
|
|
|
System.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-10 08:30:28 +01:00
|
|
|
for (int ticks = 0; ticks < duration; ++ticks) {
|
2023-03-06 17:48:22 +01:00
|
|
|
// Simulation
|
|
|
|
reset();
|
2023-03-17 09:43:32 +01:00
|
|
|
updateBandwidth(ticks);
|
2023-03-24 12:12:18 +01:00
|
|
|
schedule(ticks);
|
2023-03-06 17:48:22 +01:00
|
|
|
// traite les données et les enregistre dans un fichier
|
2023-03-17 10:55:45 +01:00
|
|
|
try {
|
2023-03-24 08:19:41 +01:00
|
|
|
analyseData(ticks);
|
2023-03-17 10:55:45 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Can't export data");
|
|
|
|
}
|
2023-03-06 17:48:22 +01:00
|
|
|
}
|
2023-03-24 12:12:18 +01:00
|
|
|
|
2023-03-31 11:01:00 +02:00
|
|
|
int totalBits = 0;
|
|
|
|
for(User u: this.users){
|
|
|
|
totalBits += u.totalbits;
|
|
|
|
}
|
|
|
|
System.out.println("total bits / nb users = "+ (((float)totalBits)/this.users.size()/10_000));
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-17 09:43:32 +01:00
|
|
|
private void updateBandwidth(int ticks) {
|
2023-03-30 09:33:28 +02:00
|
|
|
int m = 200;
|
2023-03-17 09:43:32 +01:00
|
|
|
for(User user : users) {
|
2023-03-30 09:33:28 +02:00
|
|
|
// On régénère les sources toutes les 50-100 ms
|
|
|
|
user.createPackets(m, ticks);
|
2023-03-17 10:29:36 +01:00
|
|
|
// On régénère le tableau de débits toutes les 50 ms
|
2023-03-17 09:43:32 +01:00
|
|
|
if(ticks % 50 == 0){
|
|
|
|
user.generateBandwidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 12:12:18 +01:00
|
|
|
private void schedule(int ticks) {
|
|
|
|
scheduler.scheduling(ticks);
|
2023-03-06 17:48:22 +01:00
|
|
|
}
|
|
|
|
|
2023-03-24 08:19:41 +01:00
|
|
|
private void analyseData(int tick) throws IOException {
|
2023-03-28 09:15:30 +02:00
|
|
|
double delayAverage = 0.0;
|
|
|
|
int nbPacketsSent = 0;
|
2023-03-28 08:32:26 +02:00
|
|
|
for(User u: this.users){
|
|
|
|
List<Packets> packets = u.getPacketsSent();
|
2023-03-28 09:15:30 +02:00
|
|
|
nbPacketsSent += packets.size();
|
2023-03-28 08:32:26 +02:00
|
|
|
for (Packets p: packets){
|
2023-03-28 09:15:30 +02:00
|
|
|
delayAverage += p.getDurationSending();
|
2023-03-28 08:32:26 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-28 09:15:30 +02:00
|
|
|
delayAverage = delayAverage/nbPacketsSent;
|
2023-03-17 20:31:42 +01:00
|
|
|
for(int i = 0; i < frame.length; i++) {
|
|
|
|
for(int j = 0; j < frame[i].length; j++) {
|
|
|
|
ResourceBlock ur = frame[i][j];
|
2023-03-24 08:19:41 +01:00
|
|
|
if(ur.getUser() != null) {
|
2023-03-28 09:15:30 +02:00
|
|
|
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n");
|
2023-03-24 08:19:41 +01:00
|
|
|
try{
|
|
|
|
outputDataFile.write(data.getBytes());
|
|
|
|
}catch(IOException e){
|
|
|
|
System.err.println("Cannot write the data in the output file");
|
|
|
|
System.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-17 11:04:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-10 08:30:28 +01:00
|
|
|
private void reset() {
|
2023-03-17 12:08:19 +01:00
|
|
|
for(int i = 0; i < timeSlotNb; i++) {
|
|
|
|
for(int j = 0; j < subCarrierNb; j++) {
|
2023-03-17 20:31:42 +01:00
|
|
|
frame[i][j] = new ResourceBlock(0.0);
|
2023-03-17 12:08:19 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
2023-03-03 12:12:18 +01:00
|
|
|
|
2023-03-10 08:30:28 +01:00
|
|
|
public ResourceBlock[][] getFrame() {
|
|
|
|
return frame;
|
|
|
|
}
|
2023-03-10 11:38:52 +01:00
|
|
|
|
|
|
|
public static int getTimeSlotNb() {
|
|
|
|
return timeSlotNb;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getSubCarrierNb() {
|
|
|
|
return subCarrierNb;
|
2023-03-10 08:30:28 +01:00
|
|
|
}
|
2023-03-31 08:27:43 +02:00
|
|
|
|
|
|
|
public static void setTimeSlotNb(int timeSlotNb) {
|
|
|
|
AccessPoint.timeSlotNb = timeSlotNb;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setSubCarrierNb(int subCarrierNb) {
|
|
|
|
AccessPoint.subCarrierNb = subCarrierNb;
|
|
|
|
}
|
2023-03-03 10:38:35 +01:00
|
|
|
}
|