birbnetes basics added
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
package edu.boun.edgecloudsim.applications.birbnetes;
|
||||
|
||||
import edu.boun.edgecloudsim.cloud_server.CloudServerManager;
|
||||
import edu.boun.edgecloudsim.cloud_server.DefaultCloudServerManager;
|
||||
import edu.boun.edgecloudsim.edge_client.DefaultMobileDeviceManager;
|
||||
import edu.boun.edgecloudsim.edge_client.MobileDeviceManager;
|
||||
import edu.boun.edgecloudsim.edge_client.mobile_processing_unit.DefaultMobileServerManager;
|
||||
import edu.boun.edgecloudsim.edge_client.mobile_processing_unit.MobileServerManager;
|
||||
import edu.boun.edgecloudsim.edge_orchestrator.BasicEdgeOrchestrator;
|
||||
import edu.boun.edgecloudsim.edge_orchestrator.EdgeOrchestrator;
|
||||
import edu.boun.edgecloudsim.edge_server.DefaultEdgeServerManager;
|
||||
import edu.boun.edgecloudsim.edge_server.EdgeServerManager;
|
||||
import edu.boun.edgecloudsim.mobility.MobilityModel;
|
||||
import edu.boun.edgecloudsim.mobility.StationaryMobility;
|
||||
import edu.boun.edgecloudsim.network.MM1Queue;
|
||||
import edu.boun.edgecloudsim.network.NetworkModel;
|
||||
import edu.boun.edgecloudsim.task_generator.IdleActiveLoadGenerator;
|
||||
import edu.boun.edgecloudsim.task_generator.LoadGeneratorModel;
|
||||
|
||||
public class BirbnetesScenarioFactory implements edu.boun.edgecloudsim.core.ScenarioFactory {
|
||||
private int numOfMobileDevice;
|
||||
private double simulationTime;
|
||||
private String orchestratorPolicy;
|
||||
private String simScenario;
|
||||
|
||||
BirbnetesScenarioFactory(int _numOfMobileDevice,
|
||||
double _simulationTime,
|
||||
String _orchestratorPolicy,
|
||||
String _simScenario){
|
||||
orchestratorPolicy = _orchestratorPolicy;
|
||||
numOfMobileDevice = _numOfMobileDevice;
|
||||
simulationTime = _simulationTime;
|
||||
simScenario = _simScenario;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadGeneratorModel getLoadGeneratorModel() {
|
||||
return new IdleActiveLoadGenerator(numOfMobileDevice, simulationTime, simScenario);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdgeOrchestrator getEdgeOrchestrator() {
|
||||
return new BasicEdgeOrchestrator(orchestratorPolicy, simScenario);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobilityModel getMobilityModel() {
|
||||
return new StationaryMobility(numOfMobileDevice,simulationTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkModel getNetworkModel() {
|
||||
return new MM1Queue(numOfMobileDevice, simScenario);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdgeServerManager getEdgeServerManager() {
|
||||
return new DefaultEdgeServerManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudServerManager getCloudServerManager() {
|
||||
return new DefaultCloudServerManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileDeviceManager getMobileDeviceManager() throws Exception {
|
||||
return new DefaultMobileDeviceManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MobileServerManager getMobileServerManager() {
|
||||
return new DefaultMobileServerManager();
|
||||
}
|
||||
}
|
121
src/edu/boun/edgecloudsim/applications/birbnetes/MainApp.java
Normal file
121
src/edu/boun/edgecloudsim/applications/birbnetes/MainApp.java
Normal file
@ -0,0 +1,121 @@
|
||||
package edu.boun.edgecloudsim.applications.birbnetes;
|
||||
|
||||
import edu.boun.edgecloudsim.core.ScenarioFactory;
|
||||
import edu.boun.edgecloudsim.core.SimManager;
|
||||
import edu.boun.edgecloudsim.core.SimSettings;
|
||||
import edu.boun.edgecloudsim.utils.SimLogger;
|
||||
import edu.boun.edgecloudsim.utils.SimUtils;
|
||||
import org.cloudbus.cloudsim.Log;
|
||||
import org.cloudbus.cloudsim.core.CloudSim;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class MainApp {
|
||||
|
||||
/**
|
||||
* Creates main() to run this example
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
//disable console output of cloudsim library
|
||||
Log.disable();
|
||||
|
||||
//enable console output and file output of this application
|
||||
SimLogger.enablePrintLog();
|
||||
|
||||
int iterationNumber = 1;
|
||||
String configFile = "";
|
||||
String outputFolder = "";
|
||||
String edgeDevicesFile = "";
|
||||
String applicationsFile = "";
|
||||
if (args.length == 5){
|
||||
configFile = args[0];
|
||||
edgeDevicesFile = args[1];
|
||||
applicationsFile = args[2];
|
||||
outputFolder = args[3];
|
||||
iterationNumber = Integer.parseInt(args[4]);
|
||||
}
|
||||
else{
|
||||
SimLogger.printLine("Simulation setting file, output folder and iteration number are not provided! Using default ones...");
|
||||
configFile = "scripts/birbnetes/config/default_config.properties";
|
||||
applicationsFile = "scripts/birbnetes/config/applications.xml";
|
||||
edgeDevicesFile = "scripts/birbnetes/config/edge_devices.xml";
|
||||
outputFolder = "sim_results/ite" + iterationNumber;
|
||||
}
|
||||
|
||||
//load settings from configuration file
|
||||
SimSettings SS = SimSettings.getInstance();
|
||||
if(SS.initialize(configFile, edgeDevicesFile, applicationsFile) == false){
|
||||
SimLogger.printLine("cannot initialize simulation settings!");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if(SS.getFileLoggingEnabled()){
|
||||
SimLogger.enableFileLog();
|
||||
SimUtils.cleanOutputFolder(outputFolder);
|
||||
}
|
||||
|
||||
DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
||||
Date SimulationStartDate = Calendar.getInstance().getTime();
|
||||
String now = df.format(SimulationStartDate);
|
||||
SimLogger.printLine("Simulation started at " + now);
|
||||
SimLogger.printLine("----------------------------------------------------------------------");
|
||||
|
||||
for(int j=SS.getMinNumOfMobileDev(); j<=SS.getMaxNumOfMobileDev(); j+=SS.getMobileDevCounterSize())
|
||||
{
|
||||
for(int k=0; k<SS.getSimulationScenarios().length; k++)
|
||||
{
|
||||
for(int i=0; i<SS.getOrchestratorPolicies().length; i++)
|
||||
{
|
||||
String simScenario = SS.getSimulationScenarios()[k];
|
||||
String orchestratorPolicy = SS.getOrchestratorPolicies()[i];
|
||||
Date ScenarioStartDate = Calendar.getInstance().getTime();
|
||||
now = df.format(ScenarioStartDate);
|
||||
|
||||
SimLogger.printLine("Scenario started at " + now);
|
||||
SimLogger.printLine("Scenario: " + simScenario + " - Policy: " + orchestratorPolicy + " - #iteration: " + iterationNumber);
|
||||
SimLogger.printLine("Duration: " + SS.getSimulationTime()/3600 + " hour(s) - Poisson: " + SS.getTaskLookUpTable()[0][2] + " - #devices: " + j);
|
||||
SimLogger.getInstance().simStarted(outputFolder,"SIMRESULT_" + simScenario + "_" + orchestratorPolicy + "_" + j + "DEVICES");
|
||||
|
||||
try
|
||||
{
|
||||
// First step: Initialize the CloudSim package. It should be called
|
||||
// before creating any entities.
|
||||
int num_user = 2; // number of grid users
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
boolean trace_flag = false; // mean trace events
|
||||
|
||||
// Initialize the CloudSim library
|
||||
CloudSim.init(num_user, calendar, trace_flag, 0.01);
|
||||
|
||||
// Generate EdgeCloudsim Scenario Factory
|
||||
ScenarioFactory sampleFactory = new BirbnetesScenarioFactory(j,SS.getSimulationTime(), orchestratorPolicy, simScenario);
|
||||
|
||||
// Generate EdgeCloudSim Simulation Manager
|
||||
SimManager manager = new SimManager(sampleFactory, j, simScenario, orchestratorPolicy);
|
||||
|
||||
// Start simulation
|
||||
manager.startSimulation();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
SimLogger.printLine("The simulation has been terminated due to an unexpected error");
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
Date ScenarioEndDate = Calendar.getInstance().getTime();
|
||||
now = df.format(ScenarioEndDate);
|
||||
SimLogger.printLine("Scenario finished at " + now + ". It took " + SimUtils.getTimeDifference(ScenarioStartDate,ScenarioEndDate));
|
||||
SimLogger.printLine("----------------------------------------------------------------------");
|
||||
}//End of orchestrators loop
|
||||
}//End of scenarios loop
|
||||
}//End of mobile devices loop
|
||||
|
||||
Date SimulationEndDate = Calendar.getInstance().getTime();
|
||||
now = df.format(SimulationEndDate);
|
||||
SimLogger.printLine("Simulation finished at " + now + ". It took " + SimUtils.getTimeDifference(SimulationStartDate,SimulationEndDate));
|
||||
}
|
||||
}
|
110
src/edu/boun/edgecloudsim/mobility/StationaryMobility.java
Normal file
110
src/edu/boun/edgecloudsim/mobility/StationaryMobility.java
Normal file
@ -0,0 +1,110 @@
|
||||
package edu.boun.edgecloudsim.mobility;
|
||||
|
||||
import edu.boun.edgecloudsim.core.SimSettings;
|
||||
import edu.boun.edgecloudsim.utils.Location;
|
||||
import edu.boun.edgecloudsim.utils.SimLogger;
|
||||
import edu.boun.edgecloudsim.utils.SimUtils;
|
||||
import org.apache.commons.math3.distribution.ExponentialDistribution;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class StationaryMobility extends MobilityModel {
|
||||
private List<TreeMap<Double, Location>> treeMapArray;
|
||||
|
||||
public StationaryMobility(int _numberOfMobileDevices, double _simulationTime) {
|
||||
super(_numberOfMobileDevices, _simulationTime);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
treeMapArray = new ArrayList<TreeMap<Double, Location>>();
|
||||
|
||||
ExponentialDistribution[] expRngList = new ExponentialDistribution[SimSettings.getInstance().getNumOfEdgeDatacenters()];
|
||||
|
||||
//create random number generator for each place
|
||||
Document doc = SimSettings.getInstance().getEdgeDevicesDocument();
|
||||
NodeList datacenterList = doc.getElementsByTagName("datacenter");
|
||||
for (int i = 0; i < datacenterList.getLength(); i++) {
|
||||
Node datacenterNode = datacenterList.item(i);
|
||||
Element datacenterElement = (Element) datacenterNode;
|
||||
Element location = (Element)datacenterElement.getElementsByTagName("location").item(0);
|
||||
String attractiveness = location.getElementsByTagName("attractiveness").item(0).getTextContent();
|
||||
int placeTypeIndex = Integer.parseInt(attractiveness);
|
||||
|
||||
expRngList[i] = new ExponentialDistribution(SimSettings.getInstance().getMobilityLookUpTable()[placeTypeIndex]);
|
||||
}
|
||||
|
||||
//initialize tree maps and position of mobile devices
|
||||
for(int i=0; i<numberOfMobileDevices; i++) {
|
||||
treeMapArray.add(i, new TreeMap<Double, Location>());
|
||||
|
||||
int randDatacenterId = SimUtils.getRandomNumber(0, SimSettings.getInstance().getNumOfEdgeDatacenters()-1);
|
||||
Node datacenterNode = datacenterList.item(randDatacenterId);
|
||||
Element datacenterElement = (Element) datacenterNode;
|
||||
Element location = (Element)datacenterElement.getElementsByTagName("location").item(0);
|
||||
String attractiveness = location.getElementsByTagName("attractiveness").item(0).getTextContent();
|
||||
int placeTypeIndex = Integer.parseInt(attractiveness);
|
||||
int wlan_id = Integer.parseInt(location.getElementsByTagName("wlan_id").item(0).getTextContent());
|
||||
int x_pos = Integer.parseInt(location.getElementsByTagName("x_pos").item(0).getTextContent());
|
||||
int y_pos = Integer.parseInt(location.getElementsByTagName("y_pos").item(0).getTextContent());
|
||||
|
||||
//start locating user shortly after the simulation started (e.g. 10 seconds)
|
||||
treeMapArray.get(i).put(SimSettings.CLIENT_ACTIVITY_START_TIME, new Location(placeTypeIndex, wlan_id, x_pos, y_pos));
|
||||
}
|
||||
|
||||
for(int i=0; i<numberOfMobileDevices; i++) {
|
||||
TreeMap<Double, Location> treeMap = treeMapArray.get(i);
|
||||
|
||||
while(treeMap.lastKey() < SimSettings.getInstance().getSimulationTime()) {
|
||||
boolean placeFound = false;
|
||||
int currentLocationId = treeMap.lastEntry().getValue().getServingWlanId();
|
||||
double waitingTime = expRngList[currentLocationId].sample();
|
||||
|
||||
while(placeFound == false){
|
||||
int newDatacenterId = SimUtils.getRandomNumber(0, SimSettings.getInstance().getNumOfEdgeDatacenters()-1);
|
||||
if(newDatacenterId != currentLocationId){
|
||||
placeFound = true;
|
||||
Node datacenterNode = datacenterList.item(newDatacenterId);
|
||||
Element datacenterElement = (Element) datacenterNode;
|
||||
Element location = (Element)datacenterElement.getElementsByTagName("location").item(0);
|
||||
String attractiveness = location.getElementsByTagName("attractiveness").item(0).getTextContent();
|
||||
int placeTypeIndex = Integer.parseInt(attractiveness);
|
||||
int wlan_id = Integer.parseInt(location.getElementsByTagName("wlan_id").item(0).getTextContent());
|
||||
int x_pos = Integer.parseInt(location.getElementsByTagName("x_pos").item(0).getTextContent());
|
||||
int y_pos = Integer.parseInt(location.getElementsByTagName("y_pos").item(0).getTextContent());
|
||||
|
||||
treeMap.put(treeMap.lastKey()+waitingTime, new Location(placeTypeIndex, wlan_id, x_pos, y_pos));
|
||||
}
|
||||
}
|
||||
if(!placeFound){
|
||||
SimLogger.printLine("impossible is occurred! location cannot be assigned to the device!");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation(int deviceId, double time) {
|
||||
TreeMap<Double, Location> treeMap = treeMapArray.get(deviceId);
|
||||
|
||||
Map.Entry<Double, Location> e = treeMap.floorEntry(0.0);
|
||||
|
||||
if(e == null){
|
||||
SimLogger.printLine("impossible is occurred! no location is found for the device '" + deviceId + "' at " + time);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
return e.getValue();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user