2023-03-03 10:38:35 +01:00
|
|
|
package fr.ntr;
|
|
|
|
|
2023-03-17 10:55:45 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
2023-03-03 12:12:18 +01:00
|
|
|
import java.util.ArrayList;
|
2023-03-03 11:28:16 +01:00
|
|
|
import java.util.List;
|
2023-03-06 17:48:22 +01:00
|
|
|
import java.util.Random;
|
2023-03-03 11:28:16 +01:00
|
|
|
|
|
|
|
import fr.ntr.scheduler.Scheduler;
|
|
|
|
|
2023-03-03 10:38:35 +01:00
|
|
|
public class AccessPoint {
|
2023-03-10 10:50:46 +01:00
|
|
|
private List<User> users;
|
2023-03-03 11:28:16 +01:00
|
|
|
private 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
|
|
|
|
*/
|
|
|
|
private ResourceBlock[][] frame;
|
|
|
|
/**
|
2023-03-10 08:19:07 +01:00
|
|
|
* Reste pour la prochaine source
|
2023-03-03 11:47:53 +01:00
|
|
|
*/
|
|
|
|
private double leftForNextSource;
|
2023-03-06 17:48:22 +01:00
|
|
|
/**
|
2023-03-10 08:19:07 +01:00
|
|
|
* Portée minimum et maximum de l'antenne
|
2023-03-06 17:48:22 +01:00
|
|
|
*/
|
|
|
|
private final double min, max;
|
2023-03-03 11:28:16 +01:00
|
|
|
|
2023-03-17 11:38:31 +01:00
|
|
|
private Random random = new Random();
|
|
|
|
|
2023-03-03 11:28:16 +01:00
|
|
|
|
2023-03-17 11:11:26 +01:00
|
|
|
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, int timeSlotNb, int subCarrierNb, double min, double max) {
|
2023-03-06 17:48:22 +01:00
|
|
|
this.min = min;
|
|
|
|
this.max = max;
|
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;
|
|
|
|
this.timeSlotNb = timeSlotNb;
|
|
|
|
this.subCarrierNb = subCarrierNb;
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-06 17:48:22 +01:00
|
|
|
/**
|
|
|
|
* Lancer la simulation
|
|
|
|
* @param duration
|
|
|
|
*/
|
2023-03-10 08:30:28 +01:00
|
|
|
public void startSimulation(int duration, int nbUsers) {
|
|
|
|
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-06 17:48:22 +01:00
|
|
|
schedule();
|
|
|
|
// traite les données et les enregistre dans un fichier
|
2023-03-17 10:55:45 +01:00
|
|
|
try {
|
|
|
|
analyseData();
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Can't export data");
|
|
|
|
}
|
2023-03-06 17:48:22 +01:00
|
|
|
}
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-17 09:43:32 +01:00
|
|
|
private void updateBandwidth(int ticks) {
|
|
|
|
int n = 200;
|
2023-03-17 10:29:36 +01:00
|
|
|
int timeInterval = 50 + random.nextInt(51);
|
2023-03-17 09:43:32 +01:00
|
|
|
for(User user : users) {
|
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-17 10:29:36 +01:00
|
|
|
// On régénère les sources toutes les 50-100 ms
|
2023-03-17 09:43:32 +01:00
|
|
|
if(ticks % timeInterval == 0){
|
2023-03-17 10:29:36 +01:00
|
|
|
timeInterval = 50 + random.nextInt(51);
|
2023-03-17 11:36:27 +01:00
|
|
|
n = user.createPackets(n, ticks);
|
2023-03-17 09:43:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 12:12:18 +01:00
|
|
|
/**
|
|
|
|
* Génération du débit et des paquets
|
|
|
|
*/
|
2023-03-17 09:43:32 +01:00
|
|
|
private void init(int nbUsers) {
|
2023-03-11 12:04:22 +01:00
|
|
|
// 2 groupes d'utilisateurs, proches et éloignés
|
2023-03-10 10:50:46 +01:00
|
|
|
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);
|
|
|
|
this.users.add(user);
|
|
|
|
}
|
2023-03-06 17:48:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 08:30:28 +01:00
|
|
|
private void schedule() {
|
2023-03-17 09:48:38 +01:00
|
|
|
scheduler.scheduling();
|
2023-03-06 17:48:22 +01:00
|
|
|
}
|
|
|
|
|
2023-03-17 10:55:45 +01:00
|
|
|
private void analyseData() throws IOException {
|
2023-03-17 11:04:32 +01:00
|
|
|
try(FileOutputStream file = new FileOutputStream("data.csv", true)) {
|
|
|
|
for(int i = 0; i < frame.length; i++) {
|
|
|
|
for(int j = 0; j < frame[i].length; j++) {
|
|
|
|
ResourceBlock ur = frame[i][j];
|
2023-03-17 11:18:48 +01:00
|
|
|
String data = (i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n");
|
|
|
|
System.out.println("data: " + data);
|
|
|
|
file.write(data.getBytes());
|
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 plotData() {
|
2023-03-03 11:28:16 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-03-10 08:30:28 +01:00
|
|
|
private void reset() {
|
2023-03-17 09:57:17 +01:00
|
|
|
this.frame = new ResourceBlock[timeSlotNb][subCarrierNb];
|
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 int getFrameSize() {
|
2023-03-03 12:12:18 +01:00
|
|
|
return this.timeSlotNb * this.subCarrierNb;
|
|
|
|
}
|
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-03 10:38:35 +01:00
|
|
|
}
|