major modifications for v2.0 release

Release notes

1- Cloud server processing was simplified in the initial version, it is handled via cloudsim components now.

2- Cloud server manager, edge server manager, mobile device manager and vm allocation policy are used as abstract class in factory pattern to allow developers to use different business logic without modifying EdgeCloudSim source code.

3- The task and place types are no longer defined as enumeration. They are used as integer value in order to manipulate more place type without modifying enum variable.

4- Two sample applications (one of them is simple and the other one extended application) are added along with the corresponding matlab files to plot statistics.

5- Cloud server properties are added to the simulation settings file

6- New log items are added to simulation result files

7- Code refactoring is applied including the modification of comments
This commit is contained in:
Cagatay Sonmez
2018-09-10 14:22:27 +03:00
parent e01833bda6
commit d4545f009f
89 changed files with 10699 additions and 4689 deletions

View File

@@ -0,0 +1,131 @@
/*
* Title: EdgeCloudSim - Main Application
*
* Description: Main application for Sample App2
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.applications.sample_app2;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.core.CloudSim;
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;
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 ourput 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/sample_app2/config/default_config.properties";
applicationsFile = "scripts/sample_app2/config/applications.xml";
edgeDevicesFile = "scripts/sample_app2/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()/60 + " min (warm up period: "+ SS.getWarmUpPeriod()/60 +" min) - #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 SampleScenarioFactory(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));
}
}

View File

@@ -0,0 +1,163 @@
/*
* Title: EdgeCloudSim - Edge Orchestrator
*
* Description:
* SampleEdgeOrchestrator offloads tasks to proper server
* by considering WAN bandwidth and edge server utilization.
* After the target server is decided, the least loaded VM is selected.
* If the target server is a remote edge server, MAN is used.
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.applications.sample_app2;
import java.util.List;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.SimEvent;
import edu.boun.edgecloudsim.cloud_server.CloudVM;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.edge_orchestrator.EdgeOrchestrator;
import edu.boun.edgecloudsim.edge_server.EdgeVM;
import edu.boun.edgecloudsim.edge_client.CpuUtilizationModel_Custom;
import edu.boun.edgecloudsim.edge_client.Task;
import edu.boun.edgecloudsim.utils.SimLogger;
public class SampleEdgeOrchestrator extends EdgeOrchestrator {
private int numberOfHost; //used by load balancer
public SampleEdgeOrchestrator(String _policy, String _simScenario) {
super(_policy, _simScenario);
}
@Override
public void initialize() {
numberOfHost=SimSettings.getInstance().getNumOfEdgeHosts();
}
/*
* (non-Javadoc)
* @see edu.boun.edgecloudsim.edge_orchestrator.EdgeOrchestrator#getDeviceToOffload(edu.boun.edgecloudsim.edge_client.Task)
*
* It is assumed that the edge orchestrator app is running on the edge devices in a distributed manner
*/
@Override
public int getDeviceToOffload(Task task) {
int result = 0;
//RODO: return proper host ID
if(simScenario.equals("SINGLE_TIER")){
result = SimSettings.GENERIC_EDGE_DEVICE_ID;
}
else if(simScenario.equals("TWO_TIER_WITH_EO")){
//dummy task to simulate a task with 1 Mbit file size to upload and download
Task dummyTask = new Task(0, 0, 0, 0, 128, 128, new UtilizationModelFull(), new UtilizationModelFull(), new UtilizationModelFull());
double wanDelay = SimManager.getInstance().getNetworkModel().getUploadDelay(task.getMobileDeviceId(),
SimSettings.CLOUD_DATACENTER_ID, dummyTask /* 1 Mbit */);
double wanBW = (wanDelay == 0) ? 0 : (1 / wanDelay); /* Mbps */
double edgeUtilization = SimManager.getInstance().getEdgeServerManager().getAvgUtilization();
if(policy.equals("NETWORK_BASED")){
if(wanBW > 6)
result = SimSettings.CLOUD_DATACENTER_ID;
else
result = SimSettings.GENERIC_EDGE_DEVICE_ID;
}
else if(policy.equals("UTILIZATION_BASED")){
double utilization = edgeUtilization;
if(utilization > 80)
result = SimSettings.CLOUD_DATACENTER_ID;
else
result = SimSettings.GENERIC_EDGE_DEVICE_ID;
}
else if(policy.equals("HYBRID")){
double utilization = edgeUtilization;
if(wanBW > 6 && utilization > 80)
result = SimSettings.CLOUD_DATACENTER_ID;
else
result = SimSettings.GENERIC_EDGE_DEVICE_ID;
}
else {
SimLogger.printLine("Unknow edge orchestrator policy! Terminating simulation...");
System.exit(0);
}
}
else {
SimLogger.printLine("Unknow simulation scenario! Terminating simulation...");
System.exit(0);
}
return result;
}
@Override
public Vm getVmToOffload(Task task, int deviceId) {
Vm selectedVM = null;
if(deviceId == SimSettings.CLOUD_DATACENTER_ID){
//Select VM on cloud devices via Least Loaded algorithm!
double selectedVmCapacity = 0; //start with min value
List<Host> list = SimManager.getInstance().getCloudServerManager().getDatacenter().getHostList();
for (int hostIndex=0; hostIndex < list.size(); hostIndex++) {
List<CloudVM> vmArray = SimManager.getInstance().getCloudServerManager().getVmList(hostIndex);
for(int vmIndex=0; vmIndex<vmArray.size(); vmIndex++){
double requiredCapacity = ((CpuUtilizationModel_Custom)task.getUtilizationModelCpu()).predictUtilization(vmArray.get(vmIndex).getVmType());
double targetVmCapacity = (double)100 - vmArray.get(vmIndex).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
if(requiredCapacity <= targetVmCapacity && targetVmCapacity > selectedVmCapacity){
selectedVM = vmArray.get(vmIndex);
selectedVmCapacity = targetVmCapacity;
}
}
}
}
else if(deviceId == SimSettings.GENERIC_EDGE_DEVICE_ID){
//Select VM on edge devices via Least Loaded algorithm!
double selectedVmCapacity = 0; //start with min value
for(int hostIndex=0; hostIndex<numberOfHost; hostIndex++){
List<EdgeVM> vmArray = SimManager.getInstance().getEdgeServerManager().getVmList(hostIndex);
for(int vmIndex=0; vmIndex<vmArray.size(); vmIndex++){
double requiredCapacity = ((CpuUtilizationModel_Custom)task.getUtilizationModelCpu()).predictUtilization(vmArray.get(vmIndex).getVmType());
double targetVmCapacity = (double)100 - vmArray.get(vmIndex).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
if(requiredCapacity <= targetVmCapacity && targetVmCapacity > selectedVmCapacity){
selectedVM = vmArray.get(vmIndex);
selectedVmCapacity = targetVmCapacity;
}
}
}
}
else{
SimLogger.printLine("Unknown device id! The simulation has been terminated.");
System.exit(0);
}
return selectedVM;
}
@Override
public void processEvent(SimEvent arg0) {
// Nothing to do!
}
@Override
public void shutdownEntity() {
// Nothing to do!
}
@Override
public void startEntity() {
// Nothing to do!
}
}

View File

@@ -0,0 +1,399 @@
/*
* Title: EdgeCloudSim - Mobile Device Manager
*
* Description:
* Mobile Device Manager is one of the most important component
* in EdgeCloudSim. It is responsible for creating the tasks,
* submitting them to the related VM with respect to the
* Edge Orchestrator decision, and takes proper actions when
* the execution of the tasks are finished. It also feeds the
* SimLogger with the relevant results.
* SampleMobileDeviceManager sends tasks to the edge servers or
* cloud servers. The mobile devices use WAN if the tasks are
* offloaded to the edge servers. On the other hand, they use WLAN
* if the target server is an edge server. Finally, the mobile
* devices use MAN if they must be served by a remote edge server
* due to the congestion at their own location. In this case,
* they access the edge server via two hops where the packets
* must go through WLAN and MAN.
*
* If you want to use different topology, you should modify
* the flow implemented in this class.
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.applications.sample_app2;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.core.CloudSimTags;
import org.cloudbus.cloudsim.core.SimEvent;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.core.SimSettings.NETWORK_DELAY_TYPES;
import edu.boun.edgecloudsim.edge_client.CpuUtilizationModel_Custom;
import edu.boun.edgecloudsim.edge_client.MobileDeviceManager;
import edu.boun.edgecloudsim.edge_client.Task;
import edu.boun.edgecloudsim.edge_server.EdgeHost;
import edu.boun.edgecloudsim.edge_server.EdgeVM;
import edu.boun.edgecloudsim.network.NetworkModel;
import edu.boun.edgecloudsim.utils.EdgeTask;
import edu.boun.edgecloudsim.utils.Location;
import edu.boun.edgecloudsim.utils.SimLogger;
public class SampleMobileDeviceManager extends MobileDeviceManager {
private static final int BASE = 100000; //start from base in order not to conflict cloudsim tag!
private static final int UPDATE_MM1_QUEUE_MODEL = BASE + 1;
private static final int REQUEST_RECEIVED_BY_CLOUD = BASE + 2;
private static final int REQUEST_RECEIVED_BY_EDGE_DEVICE = BASE + 3;
private static final int REQUEST_RECEIVED_BY_REMOTE_EDGE_DEVICE = BASE + 4;
private static final int REQUEST_RECEIVED_BY_EDGE_DEVICE_TO_RELAY_NEIGHBOR = BASE + 5;
private static final int RESPONSE_RECEIVED_BY_MOBILE_DEVICE = BASE + 6;
private static final int RESPONSE_RECEIVED_BY_EDGE_DEVICE_TO_RELAY_MOBILE_DEVICE = BASE + 7;
private static final double MM1_QUEUE_MODEL_UPDATE_INTEVAL = 5; //seconds
private int taskIdCounter=0;
public SampleMobileDeviceManager() throws Exception{
}
@Override
public void initialize() {
}
@Override
public UtilizationModel getCpuUtilizationModel() {
return new CpuUtilizationModel_Custom();
}
@Override
public void startEntity() {
super.startEntity();
schedule(getId(), SimSettings.CLIENT_ACTIVITY_START_TIME +
MM1_QUEUE_MODEL_UPDATE_INTEVAL, UPDATE_MM1_QUEUE_MODEL);
}
/**
* Submit cloudlets to the created VMs.
*
* @pre $none
* @post $none
*/
protected void submitCloudlets() {
//do nothing!
}
/**
* Process a cloudlet return event.
*
* @param ev a SimEvent object
* @pre ev != $null
* @post $none
*/
protected void processCloudletReturn(SimEvent ev) {
NetworkModel networkModel = SimManager.getInstance().getNetworkModel();
Task task = (Task) ev.getData();
SimLogger.getInstance().taskExecuted(task.getCloudletId());
if(task.getAssociatedDatacenterId() == SimSettings.CLOUD_DATACENTER_ID){
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": task #" + task.getCloudletId() + " received from cloud");
double WanDelay = networkModel.getDownloadDelay(SimSettings.CLOUD_DATACENTER_ID, task.getMobileDeviceId(), task);
if(WanDelay > 0)
{
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock()+WanDelay);
if(task.getSubmittedLocation().getServingWlanId() == currentLocation.getServingWlanId())
{
networkModel.downloadStarted(task.getSubmittedLocation(), SimSettings.CLOUD_DATACENTER_ID);
SimLogger.getInstance().setDownloadDelay(task.getCloudletId(), WanDelay, NETWORK_DELAY_TYPES.WAN_DELAY);
schedule(getId(), WanDelay, RESPONSE_RECEIVED_BY_MOBILE_DEVICE, task);
}
else
{
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
}
}
else
{
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock(), NETWORK_DELAY_TYPES.WAN_DELAY);
}
}
else{
int nextEvent = RESPONSE_RECEIVED_BY_MOBILE_DEVICE;
int nextDeviceForNetworkModel = SimSettings.GENERIC_EDGE_DEVICE_ID;
NETWORK_DELAY_TYPES delayType = NETWORK_DELAY_TYPES.WLAN_DELAY;
double delay = networkModel.getDownloadDelay(task.getAssociatedHostId(), task.getMobileDeviceId(), task);
EdgeHost host = (EdgeHost)(SimManager.
getInstance().
getEdgeServerManager().
getDatacenterList().get(task.getAssociatedHostId()).
getHostList().get(0));
//if neighbor edge device is selected
if(host.getLocation().getServingWlanId() != task.getSubmittedLocation().getServingWlanId())
{
delay = networkModel.getDownloadDelay(SimSettings.GENERIC_EDGE_DEVICE_ID, SimSettings.GENERIC_EDGE_DEVICE_ID, task);
nextEvent = RESPONSE_RECEIVED_BY_EDGE_DEVICE_TO_RELAY_MOBILE_DEVICE;
nextDeviceForNetworkModel = SimSettings.GENERIC_EDGE_DEVICE_ID + 1;
delayType = NETWORK_DELAY_TYPES.MAN_DELAY;
}
if(delay > 0)
{
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock()+delay);
if(task.getSubmittedLocation().getServingWlanId() == currentLocation.getServingWlanId())
{
networkModel.downloadStarted(currentLocation, nextDeviceForNetworkModel);
SimLogger.getInstance().setDownloadDelay(task.getCloudletId(), delay, delayType);
schedule(getId(), delay, nextEvent, task);
}
else
{
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
}
}
else
{
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock(), delayType);
}
}
}
protected void processOtherEvent(SimEvent ev) {
if (ev == null) {
SimLogger.printLine(getName() + ".processOtherEvent(): " + "Error - an event is null! Terminating simulation...");
System.exit(0);
return;
}
NetworkModel networkModel = SimManager.getInstance().getNetworkModel();
switch (ev.getTag()) {
case UPDATE_MM1_QUEUE_MODEL:
{
((SampleNetworkModel)networkModel).updateMM1QueeuModel();
schedule(getId(), MM1_QUEUE_MODEL_UPDATE_INTEVAL, UPDATE_MM1_QUEUE_MODEL);
break;
}
case REQUEST_RECEIVED_BY_CLOUD:
{
Task task = (Task) ev.getData();
networkModel.uploadFinished(task.getSubmittedLocation(), SimSettings.CLOUD_DATACENTER_ID);
submitTaskToVm(task, SimSettings.VM_TYPES.CLOUD_VM);
break;
}
case REQUEST_RECEIVED_BY_EDGE_DEVICE:
{
Task task = (Task) ev.getData();
networkModel.uploadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID);
submitTaskToVm(task, SimSettings.VM_TYPES.EDGE_VM);
break;
}
case REQUEST_RECEIVED_BY_REMOTE_EDGE_DEVICE:
{
Task task = (Task) ev.getData();
networkModel.uploadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID+1);
submitTaskToVm(task, SimSettings.VM_TYPES.EDGE_VM);
break;
}
case REQUEST_RECEIVED_BY_EDGE_DEVICE_TO_RELAY_NEIGHBOR:
{
Task task = (Task) ev.getData();
networkModel.uploadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID);
double manDelay = networkModel.getUploadDelay(SimSettings.GENERIC_EDGE_DEVICE_ID, SimSettings.GENERIC_EDGE_DEVICE_ID, task);
if(manDelay>0){
networkModel.uploadStarted(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID+1);
SimLogger.getInstance().setUploadDelay(task.getCloudletId(), manDelay, NETWORK_DELAY_TYPES.MAN_DELAY);
schedule(getId(), manDelay, REQUEST_RECEIVED_BY_REMOTE_EDGE_DEVICE, task);
}
else
{
//SimLogger.printLine("Task #" + task.getCloudletId() + " cannot assign to any VM");
SimLogger.getInstance().rejectedDueToBandwidth(
task.getCloudletId(),
CloudSim.clock(),
SimSettings.VM_TYPES.EDGE_VM.ordinal(),
NETWORK_DELAY_TYPES.MAN_DELAY);
}
break;
}
case RESPONSE_RECEIVED_BY_EDGE_DEVICE_TO_RELAY_MOBILE_DEVICE:
{
Task task = (Task) ev.getData();
networkModel.downloadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID+1);
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": task #" + task.getCloudletId() + " received from edge");
double delay = networkModel.getDownloadDelay(task.getAssociatedHostId(), task.getMobileDeviceId(), task);
if(delay > 0)
{
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock()+delay);
if(task.getSubmittedLocation().getServingWlanId() == currentLocation.getServingWlanId())
{
networkModel.downloadStarted(currentLocation, SimSettings.GENERIC_EDGE_DEVICE_ID);
SimLogger.getInstance().setDownloadDelay(task.getCloudletId(), delay, NETWORK_DELAY_TYPES.WLAN_DELAY);
schedule(getId(), delay, RESPONSE_RECEIVED_BY_MOBILE_DEVICE, task);
}
else
{
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
}
}
else
{
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock(), NETWORK_DELAY_TYPES.WLAN_DELAY);
}
break;
}
case RESPONSE_RECEIVED_BY_MOBILE_DEVICE:
{
Task task = (Task) ev.getData();
if(task.getAssociatedDatacenterId() == SimSettings.CLOUD_DATACENTER_ID)
networkModel.downloadFinished(task.getSubmittedLocation(), SimSettings.CLOUD_DATACENTER_ID);
else
networkModel.downloadFinished(task.getSubmittedLocation(), SimSettings.GENERIC_EDGE_DEVICE_ID);
SimLogger.getInstance().taskEnded(task.getCloudletId(), CloudSim.clock());
break;
}
default:
SimLogger.printLine(getName() + ".processOtherEvent(): " + "Error - event unknown by this DatacenterBroker. Terminating simulation...");
System.exit(0);
break;
}
}
public void submitTask(EdgeTask edgeTask) {
int vmType=0;
int nextEvent=0;
int nextDeviceForNetworkModel;
NETWORK_DELAY_TYPES delayType;
double delay=0;
NetworkModel networkModel = SimManager.getInstance().getNetworkModel();
//create a task
Task task = createTask(edgeTask);
Location currentLocation = SimManager.getInstance().getMobilityModel().
getLocation(task.getMobileDeviceId(), CloudSim.clock());
//set location of the mobile device which generates this task
task.setSubmittedLocation(currentLocation);
//add related task to log list
SimLogger.getInstance().addLog(task.getCloudletId(),
task.getTaskType(),
(int)task.getCloudletLength(),
(int)task.getCloudletFileSize(),
(int)task.getCloudletOutputSize());
int nextHopId = SimManager.getInstance().getEdgeOrchestrator().getDeviceToOffload(task);
if(nextHopId == SimSettings.CLOUD_DATACENTER_ID){
delay = networkModel.getUploadDelay(task.getMobileDeviceId(), SimSettings.CLOUD_DATACENTER_ID, task);
vmType = SimSettings.VM_TYPES.CLOUD_VM.ordinal();
nextEvent = REQUEST_RECEIVED_BY_CLOUD;
delayType = NETWORK_DELAY_TYPES.WAN_DELAY;
nextDeviceForNetworkModel = SimSettings.CLOUD_DATACENTER_ID;
}
else {
delay = networkModel.getUploadDelay(task.getMobileDeviceId(), SimSettings.GENERIC_EDGE_DEVICE_ID, task);
vmType = SimSettings.VM_TYPES.EDGE_VM.ordinal();
nextEvent = REQUEST_RECEIVED_BY_EDGE_DEVICE;
delayType = NETWORK_DELAY_TYPES.WLAN_DELAY;
nextDeviceForNetworkModel = SimSettings.GENERIC_EDGE_DEVICE_ID;
}
if(delay>0){
Vm selectedVM = SimManager.getInstance().getEdgeOrchestrator().getVmToOffload(task, nextHopId);
if(selectedVM != null){
//set related host id
task.setAssociatedDatacenterId(nextHopId);
//set related host id
task.setAssociatedHostId(selectedVM.getHost().getId());
//set related vm id
task.setAssociatedVmId(selectedVM.getId());
//bind task to related VM
getCloudletList().add(task);
bindCloudletToVm(task.getCloudletId(), selectedVM.getId());
if(selectedVM instanceof EdgeVM){
EdgeHost host = (EdgeHost)(selectedVM.getHost());
//if neighbor edge device is selected
if(host.getLocation().getServingWlanId() != task.getSubmittedLocation().getServingWlanId()){
nextEvent = REQUEST_RECEIVED_BY_EDGE_DEVICE_TO_RELAY_NEIGHBOR;
}
}
networkModel.uploadStarted(currentLocation, nextDeviceForNetworkModel);
SimLogger.getInstance().taskStarted(task.getCloudletId(), CloudSim.clock());
SimLogger.getInstance().setUploadDelay(task.getCloudletId(), delay, delayType);
schedule(getId(), delay, nextEvent, task);
}
else{
//SimLogger.printLine("Task #" + task.getCloudletId() + " cannot assign to any VM");
SimLogger.getInstance().rejectedDueToVMCapacity(task.getCloudletId(), CloudSim.clock(), vmType);
}
}
else
{
//SimLogger.printLine("Task #" + task.getCloudletId() + " cannot assign to any VM");
SimLogger.getInstance().rejectedDueToBandwidth(task.getCloudletId(), CloudSim.clock(), vmType, delayType);
}
}
private void submitTaskToVm(Task task, SimSettings.VM_TYPES vmType) {
//SimLogger.printLine(CloudSim.clock() + ": Cloudlet#" + task.getCloudletId() + " is submitted to VM#" + task.getVmId());
schedule(getVmsToDatacentersMap().get(task.getVmId()), 0, CloudSimTags.CLOUDLET_SUBMIT, task);
SimLogger.getInstance().taskAssigned(task.getCloudletId(),
task.getAssociatedDatacenterId(),
task.getAssociatedHostId(),
task.getAssociatedVmId(),
vmType.ordinal());
}
private Task createTask(EdgeTask edgeTask){
UtilizationModel utilizationModel = new UtilizationModelFull(); /*UtilizationModelStochastic*/
UtilizationModel utilizationModelCPU = getCpuUtilizationModel();
Task task = new Task(edgeTask.mobileDeviceId, ++taskIdCounter,
edgeTask.length, edgeTask.pesNumber,
edgeTask.inputFileSize, edgeTask.outputFileSize,
utilizationModelCPU, utilizationModel, utilizationModel);
//set the owner of this task
task.setUserId(this.getId());
task.setTaskType(edgeTask.taskType);
if (utilizationModelCPU instanceof CpuUtilizationModel_Custom) {
((CpuUtilizationModel_Custom)utilizationModelCPU).setTask(task);
}
return task;
}
}

View File

@@ -0,0 +1,432 @@
/*
* Title: EdgeCloudSim - Network Model
*
* Description:
* SampleNetworkModel uses
* -> the result of an empirical study for the WLAN and WAN delays
* The experimental network model is developed
* by taking measurements from the real life deployments.
*
* -> MMPP/MMPP/1 queue model for MAN delay
* MAN delay is observed via a single server queue model with
* Markov-modulated Poisson process (MMPP) arrivals.
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.applications.sample_app2;
import org.cloudbus.cloudsim.core.CloudSim;
import edu.boun.edgecloudsim.core.SimManager;
import edu.boun.edgecloudsim.core.SimSettings;
import edu.boun.edgecloudsim.edge_client.Task;
import edu.boun.edgecloudsim.network.NetworkModel;
import edu.boun.edgecloudsim.utils.Location;
import edu.boun.edgecloudsim.utils.SimLogger;
public class SampleNetworkModel extends NetworkModel {
public static enum NETWORK_TYPE {WLAN, LAN};
public static enum LINK_TYPE {DOWNLOAD, UPLOAD};
public static double MAN_BW = 1300*1024; //Kbps
@SuppressWarnings("unused")
private int manClients;
private int[] wanClients;
private int[] wlanClients;
private double lastMM1QueeuUpdateTime;
private double ManPoissonMeanForDownload; //seconds
private double ManPoissonMeanForUpload; //seconds
private double avgManTaskInputSize; //bytes
private double avgManTaskOutputSize; //bytes
//record last n task statistics during MM1_QUEUE_MODEL_UPDATE_INTEVAL seconds to simulate mmpp/m/1 queue model
private double totalManTaskInputSize;
private double totalManTaskOutputSize;
private double numOfManTaskForDownload;
private double numOfManTaskForUpload;
public static final double[] experimentalWlanDelay = {
/*1 Client*/ 88040.279 /*(Kbps)*/,
/*2 Clients*/ 45150.982 /*(Kbps)*/,
/*3 Clients*/ 30303.641 /*(Kbps)*/,
/*4 Clients*/ 27617.211 /*(Kbps)*/,
/*5 Clients*/ 24868.616 /*(Kbps)*/,
/*6 Clients*/ 22242.296 /*(Kbps)*/,
/*7 Clients*/ 20524.064 /*(Kbps)*/,
/*8 Clients*/ 18744.889 /*(Kbps)*/,
/*9 Clients*/ 17058.827 /*(Kbps)*/,
/*10 Clients*/ 15690.455 /*(Kbps)*/,
/*11 Clients*/ 14127.744 /*(Kbps)*/,
/*12 Clients*/ 13522.408 /*(Kbps)*/,
/*13 Clients*/ 13177.631 /*(Kbps)*/,
/*14 Clients*/ 12811.330 /*(Kbps)*/,
/*15 Clients*/ 12584.387 /*(Kbps)*/,
/*15 Clients*/ 12135.161 /*(Kbps)*/,
/*16 Clients*/ 11705.638 /*(Kbps)*/,
/*17 Clients*/ 11276.116 /*(Kbps)*/,
/*18 Clients*/ 10846.594 /*(Kbps)*/,
/*19 Clients*/ 10417.071 /*(Kbps)*/,
/*20 Clients*/ 9987.549 /*(Kbps)*/,
/*21 Clients*/ 9367.587 /*(Kbps)*/,
/*22 Clients*/ 8747.625 /*(Kbps)*/,
/*23 Clients*/ 8127.663 /*(Kbps)*/,
/*24 Clients*/ 7907.701 /*(Kbps)*/,
/*25 Clients*/ 7887.739 /*(Kbps)*/,
/*26 Clients*/ 7690.831 /*(Kbps)*/,
/*27 Clients*/ 7393.922 /*(Kbps)*/,
/*28 Clients*/ 7297.014 /*(Kbps)*/,
/*29 Clients*/ 7100.106 /*(Kbps)*/,
/*30 Clients*/ 6903.197 /*(Kbps)*/,
/*31 Clients*/ 6701.986 /*(Kbps)*/,
/*32 Clients*/ 6500.776 /*(Kbps)*/,
/*33 Clients*/ 6399.565 /*(Kbps)*/,
/*34 Clients*/ 6098.354 /*(Kbps)*/,
/*35 Clients*/ 5897.143 /*(Kbps)*/,
/*36 Clients*/ 5552.127 /*(Kbps)*/,
/*37 Clients*/ 5207.111 /*(Kbps)*/,
/*38 Clients*/ 4862.096 /*(Kbps)*/,
/*39 Clients*/ 4517.080 /*(Kbps)*/,
/*40 Clients*/ 4172.064 /*(Kbps)*/,
/*41 Clients*/ 4092.922 /*(Kbps)*/,
/*42 Clients*/ 4013.781 /*(Kbps)*/,
/*43 Clients*/ 3934.639 /*(Kbps)*/,
/*44 Clients*/ 3855.498 /*(Kbps)*/,
/*45 Clients*/ 3776.356 /*(Kbps)*/,
/*46 Clients*/ 3697.215 /*(Kbps)*/,
/*47 Clients*/ 3618.073 /*(Kbps)*/,
/*48 Clients*/ 3538.932 /*(Kbps)*/,
/*49 Clients*/ 3459.790 /*(Kbps)*/,
/*50 Clients*/ 3380.649 /*(Kbps)*/,
/*51 Clients*/ 3274.611 /*(Kbps)*/,
/*52 Clients*/ 3168.573 /*(Kbps)*/,
/*53 Clients*/ 3062.536 /*(Kbps)*/,
/*54 Clients*/ 2956.498 /*(Kbps)*/,
/*55 Clients*/ 2850.461 /*(Kbps)*/,
/*56 Clients*/ 2744.423 /*(Kbps)*/,
/*57 Clients*/ 2638.386 /*(Kbps)*/,
/*58 Clients*/ 2532.348 /*(Kbps)*/,
/*59 Clients*/ 2426.310 /*(Kbps)*/,
/*60 Clients*/ 2320.273 /*(Kbps)*/,
/*61 Clients*/ 2283.828 /*(Kbps)*/,
/*62 Clients*/ 2247.383 /*(Kbps)*/,
/*63 Clients*/ 2210.939 /*(Kbps)*/,
/*64 Clients*/ 2174.494 /*(Kbps)*/,
/*65 Clients*/ 2138.049 /*(Kbps)*/,
/*66 Clients*/ 2101.604 /*(Kbps)*/,
/*67 Clients*/ 2065.160 /*(Kbps)*/,
/*68 Clients*/ 2028.715 /*(Kbps)*/,
/*69 Clients*/ 1992.270 /*(Kbps)*/,
/*70 Clients*/ 1955.825 /*(Kbps)*/,
/*71 Clients*/ 1946.788 /*(Kbps)*/,
/*72 Clients*/ 1937.751 /*(Kbps)*/,
/*73 Clients*/ 1928.714 /*(Kbps)*/,
/*74 Clients*/ 1919.677 /*(Kbps)*/,
/*75 Clients*/ 1910.640 /*(Kbps)*/,
/*76 Clients*/ 1901.603 /*(Kbps)*/,
/*77 Clients*/ 1892.566 /*(Kbps)*/,
/*78 Clients*/ 1883.529 /*(Kbps)*/,
/*79 Clients*/ 1874.492 /*(Kbps)*/,
/*80 Clients*/ 1865.455 /*(Kbps)*/,
/*81 Clients*/ 1833.185 /*(Kbps)*/,
/*82 Clients*/ 1800.915 /*(Kbps)*/,
/*83 Clients*/ 1768.645 /*(Kbps)*/,
/*84 Clients*/ 1736.375 /*(Kbps)*/,
/*85 Clients*/ 1704.106 /*(Kbps)*/,
/*86 Clients*/ 1671.836 /*(Kbps)*/,
/*87 Clients*/ 1639.566 /*(Kbps)*/,
/*88 Clients*/ 1607.296 /*(Kbps)*/,
/*89 Clients*/ 1575.026 /*(Kbps)*/,
/*90 Clients*/ 1542.756 /*(Kbps)*/,
/*91 Clients*/ 1538.544 /*(Kbps)*/,
/*92 Clients*/ 1534.331 /*(Kbps)*/,
/*93 Clients*/ 1530.119 /*(Kbps)*/,
/*94 Clients*/ 1525.906 /*(Kbps)*/,
/*95 Clients*/ 1521.694 /*(Kbps)*/,
/*96 Clients*/ 1517.481 /*(Kbps)*/,
/*97 Clients*/ 1513.269 /*(Kbps)*/,
/*98 Clients*/ 1509.056 /*(Kbps)*/,
/*99 Clients*/ 1504.844 /*(Kbps)*/,
/*100 Clients*/ 1500.631 /*(Kbps)*/
};
public static final double[] experimentalWanDelay = {
/*1 Client*/ 20703.973 /*(Kbps)*/,
/*2 Clients*/ 12023.957 /*(Kbps)*/,
/*3 Clients*/ 9887.785 /*(Kbps)*/,
/*4 Clients*/ 8915.775 /*(Kbps)*/,
/*5 Clients*/ 8259.277 /*(Kbps)*/,
/*6 Clients*/ 7560.574 /*(Kbps)*/,
/*7 Clients*/ 7262.140 /*(Kbps)*/,
/*8 Clients*/ 7155.361 /*(Kbps)*/,
/*9 Clients*/ 7041.153 /*(Kbps)*/,
/*10 Clients*/ 6994.595 /*(Kbps)*/,
/*11 Clients*/ 6653.232 /*(Kbps)*/,
/*12 Clients*/ 6111.868 /*(Kbps)*/,
/*13 Clients*/ 5570.505 /*(Kbps)*/,
/*14 Clients*/ 5029.142 /*(Kbps)*/,
/*15 Clients*/ 4487.779 /*(Kbps)*/,
/*16 Clients*/ 3899.729 /*(Kbps)*/,
/*17 Clients*/ 3311.680 /*(Kbps)*/,
/*18 Clients*/ 2723.631 /*(Kbps)*/,
/*19 Clients*/ 2135.582 /*(Kbps)*/,
/*20 Clients*/ 1547.533 /*(Kbps)*/,
/*21 Clients*/ 1500.252 /*(Kbps)*/,
/*22 Clients*/ 1452.972 /*(Kbps)*/,
/*23 Clients*/ 1405.692 /*(Kbps)*/,
/*24 Clients*/ 1358.411 /*(Kbps)*/,
/*25 Clients*/ 1311.131 /*(Kbps)*/
};
public SampleNetworkModel(int _numberOfMobileDevices, String _simScenario) {
super(_numberOfMobileDevices, _simScenario);
}
@Override
public void initialize() {
wanClients = new int[SimSettings.getInstance().getNumOfEdgeDatacenters()]; //we have one access point for each datacenter
wlanClients = new int[SimSettings.getInstance().getNumOfEdgeDatacenters()]; //we have one access point for each datacenter
int numOfApp = SimSettings.getInstance().getTaskLookUpTable().length;
SimSettings SS = SimSettings.getInstance();
for(int taskIndex=0; taskIndex<numOfApp; taskIndex++) {
if(SS.getTaskLookUpTable()[taskIndex][0] == 0) {
SimLogger.printLine("Usage percantage of task " + taskIndex + " is 0! Terminating simulation...");
System.exit(0);
}
else{
double weight = SS.getTaskLookUpTable()[taskIndex][0]/(double)100;
//assume half of the tasks use the MAN at the beginning
ManPoissonMeanForDownload += ((SS.getTaskLookUpTable()[taskIndex][2])*weight) * 4;
ManPoissonMeanForUpload = ManPoissonMeanForDownload;
avgManTaskInputSize += SS.getTaskLookUpTable()[taskIndex][5]*weight;
avgManTaskOutputSize += SS.getTaskLookUpTable()[taskIndex][6]*weight;
}
}
ManPoissonMeanForDownload = ManPoissonMeanForDownload/numOfApp;
ManPoissonMeanForUpload = ManPoissonMeanForUpload/numOfApp;
avgManTaskInputSize = avgManTaskInputSize/numOfApp;
avgManTaskOutputSize = avgManTaskOutputSize/numOfApp;
lastMM1QueeuUpdateTime = SimSettings.CLIENT_ACTIVITY_START_TIME;
totalManTaskOutputSize = 0;
numOfManTaskForDownload = 0;
totalManTaskInputSize = 0;
numOfManTaskForUpload = 0;
}
/**
* source device is always mobile device in our simulation scenarios!
*/
@Override
public double getUploadDelay(int sourceDeviceId, int destDeviceId, Task task) {
double delay = 0;
//special case for man communication
if(sourceDeviceId == destDeviceId && sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID){
return delay = getManUploadDelay();
}
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(sourceDeviceId,CloudSim.clock());
//mobile device to cloud server
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID){
delay = getWanUploadDelay(accessPointLocation, task.getCloudletFileSize());
}
//mobile device to edge device (wifi access point)
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID) {
delay = getWlanUploadDelay(accessPointLocation, task.getCloudletFileSize());
}
return delay;
}
/**
* destination device is always mobile device in our simulation scenarios!
*/
@Override
public double getDownloadDelay(int sourceDeviceId, int destDeviceId, Task task) {
double delay = 0;
//special case for man communication
if(sourceDeviceId == destDeviceId && sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID){
return delay = getManDownloadDelay();
}
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(destDeviceId,CloudSim.clock());
//cloud server to mobile device
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID){
delay = getWanDownloadDelay(accessPointLocation, task.getCloudletOutputSize());
}
//edge device (wifi access point) to mobile device
else{
delay = getWlanDownloadDelay(accessPointLocation, task.getCloudletOutputSize());
}
return delay;
}
@Override
public void uploadStarted(Location accessPointLocation, int destDeviceId) {
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]++;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]++;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients++;
else {
SimLogger.printLine("Error - unknown device id in uploadStarted(). Terminating simulation...");
System.exit(0);
}
}
@Override
public void uploadFinished(Location accessPointLocation, int destDeviceId) {
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]--;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]--;
else if (destDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients--;
else {
SimLogger.printLine("Error - unknown device id in uploadFinished(). Terminating simulation...");
System.exit(0);
}
}
@Override
public void downloadStarted(Location accessPointLocation, int sourceDeviceId) {
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]++;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]++;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients++;
else {
SimLogger.printLine("Error - unknown device id in downloadStarted(). Terminating simulation...");
System.exit(0);
}
}
@Override
public void downloadFinished(Location accessPointLocation, int sourceDeviceId) {
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID)
wanClients[accessPointLocation.getServingWlanId()]--;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID)
wlanClients[accessPointLocation.getServingWlanId()]--;
else if(sourceDeviceId == SimSettings.GENERIC_EDGE_DEVICE_ID+1)
manClients--;
else {
SimLogger.printLine("Error - unknown device id in downloadFinished(). Terminating simulation...");
System.exit(0);
}
}
private double getWlanDownloadDelay(Location accessPointLocation, double dataSize) {
int numOfWlanUser = wlanClients[accessPointLocation.getServingWlanId()];
double taskSizeInKb = dataSize * (double)8; //KB to Kb
double result=0;
if(numOfWlanUser < experimentalWlanDelay.length)
result = taskSizeInKb /*Kb*/ / (experimentalWlanDelay[numOfWlanUser] * (double) 3 ) /*Kbps*/; //802.11ac is around 3 times faster than 802.11n
//System.out.println("--> " + numOfWlanUser + " user, " + taskSizeInKb + " KB, " +result + " sec");
return result;
}
//wlan upload and download delay is symmetric in this model
private double getWlanUploadDelay(Location accessPointLocation, double dataSize) {
return getWlanDownloadDelay(accessPointLocation, dataSize);
}
private double getWanDownloadDelay(Location accessPointLocation, double dataSize) {
int numOfWanUser = wanClients[accessPointLocation.getServingWlanId()];
double taskSizeInKb = dataSize * (double)8; //KB to Kb
double result=0;
if(numOfWanUser < experimentalWanDelay.length)
result = taskSizeInKb /*Kb*/ / (experimentalWanDelay[numOfWanUser]) /*Kbps*/;
//System.out.println("--> " + numOfWanUser + " user, " + taskSizeInKb + " KB, " +result + " sec");
return result;
}
//wan upload and download delay is symmetric in this model
private double getWanUploadDelay(Location accessPointLocation, double dataSize) {
return getWanDownloadDelay(accessPointLocation, dataSize);
}
private double calculateMM1(double propogationDelay, double bandwidth /*Kbps*/, double PoissonMean, double avgTaskSize /*KB*/, int deviceCount){
double mu=0, lamda=0;
avgTaskSize = avgTaskSize * 8; //convert from KB to Kb
lamda = ((double)1/(double)PoissonMean); //task per seconds
mu = bandwidth /*Kbps*/ / avgTaskSize /*Kb*/; //task per seconds
double result = (double)1 / (mu-lamda*(double)deviceCount);
if(result < 0)
return 0;
result += propogationDelay;
return (result > 15) ? 0 : result;
}
private double getManDownloadDelay() {
double result = calculateMM1(SimSettings.getInstance().getInternalLanDelay(),
MAN_BW,
ManPoissonMeanForDownload,
avgManTaskOutputSize,
numberOfMobileDevices);
totalManTaskOutputSize += avgManTaskOutputSize;
numOfManTaskForDownload++;
//System.out.println("--> " + SimManager.getInstance().getNumOfMobileDevice() + " user, " +result + " sec");
return result;
}
private double getManUploadDelay() {
double result = calculateMM1(SimSettings.getInstance().getInternalLanDelay(),
MAN_BW,
ManPoissonMeanForUpload,
avgManTaskInputSize,
numberOfMobileDevices);
totalManTaskInputSize += avgManTaskInputSize;
numOfManTaskForUpload++;
//System.out.println(CloudSim.clock() + " -> " + SimManager.getInstance().getNumOfMobileDevice() + " user, " + result + " sec");
return result;
}
public void updateMM1QueeuModel(){
double lastInterval = CloudSim.clock() - lastMM1QueeuUpdateTime;
lastMM1QueeuUpdateTime = CloudSim.clock();
if(numOfManTaskForDownload != 0){
ManPoissonMeanForDownload = lastInterval / (numOfManTaskForDownload / (double)numberOfMobileDevices);
avgManTaskOutputSize = totalManTaskOutputSize / numOfManTaskForDownload;
}
if(numOfManTaskForUpload != 0){
ManPoissonMeanForUpload = lastInterval / (numOfManTaskForUpload / (double)numberOfMobileDevices);
avgManTaskInputSize = totalManTaskInputSize / numOfManTaskForUpload;
}
totalManTaskOutputSize = 0;
numOfManTaskForDownload = 0;
totalManTaskInputSize = 0;
numOfManTaskForUpload = 0;
}
}

View File

@@ -0,0 +1,76 @@
/*
* Title: EdgeCloudSim - Scenario Factory
*
* Description: Sample scenario factory providing the default
* instances of required abstract classes
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
*/
package edu.boun.edgecloudsim.applications.sample_app2;
import edu.boun.edgecloudsim.cloud_server.CloudServerManager;
import edu.boun.edgecloudsim.cloud_server.DefaultCloudServerManager;
import edu.boun.edgecloudsim.core.ScenarioFactory;
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.edge_client.MobileDeviceManager;
import edu.boun.edgecloudsim.mobility.MobilityModel;
import edu.boun.edgecloudsim.mobility.NomadicMobility;
import edu.boun.edgecloudsim.task_generator.IdleActiveLoadGenerator;
import edu.boun.edgecloudsim.task_generator.LoadGeneratorModel;
import edu.boun.edgecloudsim.network.NetworkModel;
public class SampleScenarioFactory implements ScenarioFactory {
private int numOfMobileDevice;
private double simulationTime;
private String orchestratorPolicy;
private String simScenario;
SampleScenarioFactory(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 SampleEdgeOrchestrator(orchestratorPolicy, simScenario);
}
@Override
public MobilityModel getMobilityModel() {
return new NomadicMobility(numOfMobileDevice,simulationTime);
}
@Override
public NetworkModel getNetworkModel() {
return new SampleNetworkModel(numOfMobileDevice, simScenario);
}
@Override
public EdgeServerManager getEdgeServerManager() {
return new DefaultEdgeServerManager();
}
@Override
public CloudServerManager getCloudServerManager() {
return new DefaultCloudServerManager();
}
@Override
public MobileDeviceManager getMobileDeviceManager() throws Exception {
return new SampleMobileDeviceManager();
}
}