initial commit of EdgeCloudSim
EdgeCloudSim with default network model, mobility model, load generator model, edge orchestrator, and VM CPU utilization model
This commit is contained in:
commit
19c4b9de40
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# OS X
|
||||||
|
.DS_Store*
|
||||||
|
Icon?
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
Thumbs.db
|
||||||
|
ehthumbs.db
|
||||||
|
Desktop.ini
|
||||||
|
|
||||||
|
# Linux
|
||||||
|
.directory
|
||||||
|
*~
|
||||||
|
|
||||||
|
# bin folder
|
||||||
|
bin
|
||||||
|
|
||||||
|
# eclipse's files
|
||||||
|
.settings
|
||||||
|
.classpath
|
||||||
|
.project
|
63
config/applications.xml
Normal file
63
config/applications.xml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<applications>
|
||||||
|
<application name="FACE_REC_APP">
|
||||||
|
<usage_percentage>100</usage_percentage>
|
||||||
|
<prob_cloud_selection>10</prob_cloud_selection>
|
||||||
|
<poisson_interarrival>3</poisson_interarrival>
|
||||||
|
<active_period>45</active_period>
|
||||||
|
<idle_period>15</idle_period>
|
||||||
|
<data_upload>1500</data_upload>
|
||||||
|
<data_download>16</data_download>
|
||||||
|
<task_length>1500</task_length>
|
||||||
|
<required_core>2</required_core>
|
||||||
|
<vm_utilization>10</vm_utilization>
|
||||||
|
</application>
|
||||||
|
<application name="HEALTH_APP">
|
||||||
|
<usage_percentage>0</usage_percentage>
|
||||||
|
<prob_cloud_selection>0</prob_cloud_selection>
|
||||||
|
<poisson_interarrival>0</poisson_interarrival>
|
||||||
|
<active_period>0</active_period>
|
||||||
|
<idle_period>0</idle_period>
|
||||||
|
<data_upload>0</data_upload>
|
||||||
|
<data_download>0</data_download>
|
||||||
|
<task_length>0</task_length>
|
||||||
|
<required_core>0</required_core>
|
||||||
|
<vm_utilization>0</vm_utilization>
|
||||||
|
</application>
|
||||||
|
<application name="HEAVY_COMP_APP">
|
||||||
|
<usage_percentage>0</usage_percentage>
|
||||||
|
<prob_cloud_selection>0</prob_cloud_selection>
|
||||||
|
<poisson_interarrival>0</poisson_interarrival>
|
||||||
|
<active_period>0</active_period>
|
||||||
|
<idle_period>0</idle_period>
|
||||||
|
<data_upload>0</data_upload>
|
||||||
|
<data_download>0</data_download>
|
||||||
|
<task_length>0</task_length>
|
||||||
|
<required_core>0</required_core>
|
||||||
|
<vm_utilization>0</vm_utilization>
|
||||||
|
</application>
|
||||||
|
<application name="VIDEO_GAME_APP">
|
||||||
|
<usage_percentage>0</usage_percentage>
|
||||||
|
<prob_cloud_selection>0</prob_cloud_selection>
|
||||||
|
<poisson_interarrival>0</poisson_interarrival>
|
||||||
|
<active_period>0</active_period>
|
||||||
|
<idle_period>0</idle_period>
|
||||||
|
<data_upload>0</data_upload>
|
||||||
|
<data_download>0</data_download>
|
||||||
|
<task_length>0</task_length>
|
||||||
|
<required_core>0</required_core>
|
||||||
|
<vm_utilization>0</vm_utilization>
|
||||||
|
</application>
|
||||||
|
<application name="SIMPLE_SERVICE_APP">
|
||||||
|
<usage_percentage>0</usage_percentage>
|
||||||
|
<prob_cloud_selection>0</prob_cloud_selection>
|
||||||
|
<poisson_interarrival>0</poisson_interarrival>
|
||||||
|
<active_period>0</active_period>
|
||||||
|
<idle_period>0</idle_period>
|
||||||
|
<data_upload>0</data_upload>
|
||||||
|
<data_download>0</data_download>
|
||||||
|
<task_length>0</task_length>
|
||||||
|
<required_core>0</required_core>
|
||||||
|
<vm_utilization>0</vm_utilization>
|
||||||
|
</application>
|
||||||
|
</applications>
|
24
config/default_config.properties
Normal file
24
config/default_config.properties
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#default config file
|
||||||
|
simulation_time=2
|
||||||
|
warm_up_period=1200
|
||||||
|
vm_load_check_interval=30
|
||||||
|
vm_location_check_interval=30
|
||||||
|
deep_file_log_enabled=false
|
||||||
|
|
||||||
|
min_number_of_mobile_devices=50
|
||||||
|
max_number_of_mobile_devices=250
|
||||||
|
mobile_device_counter_size=25
|
||||||
|
|
||||||
|
wan_propogation_delay=0.1
|
||||||
|
lan_internal_delay=0.004
|
||||||
|
wlan_bandwidth=300
|
||||||
|
wan_bandwidth=20
|
||||||
|
gsm_bandwidth=10
|
||||||
|
|
||||||
|
mips_for_cloud=20000
|
||||||
|
|
||||||
|
task_provisioning=NEXT_FIT
|
||||||
|
|
||||||
|
attractiveness_L1_mean_waiting_time=60
|
||||||
|
attractiveness_L2_mean_waiting_time=30
|
||||||
|
attractiveness_L3_mean_waiting_time=15
|
647
config/edge_devices.xml
Normal file
647
config/edge_devices.xml
Normal file
@ -0,0 +1,647 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<edge_devices>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>1</x_pos>
|
||||||
|
<y_pos>1</y_pos>
|
||||||
|
<wlan_id>0</wlan_id>
|
||||||
|
<attractiveness>1</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>2</x_pos>
|
||||||
|
<y_pos>2</y_pos>
|
||||||
|
<wlan_id>1</wlan_id>
|
||||||
|
<attractiveness>1</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>3</x_pos>
|
||||||
|
<y_pos>3</y_pos>
|
||||||
|
<wlan_id>2</wlan_id>
|
||||||
|
<attractiveness>2</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>4</x_pos>
|
||||||
|
<y_pos>4</y_pos>
|
||||||
|
<wlan_id>3</wlan_id>
|
||||||
|
<attractiveness>2</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>5</x_pos>
|
||||||
|
<y_pos>5</y_pos>
|
||||||
|
<wlan_id>4</wlan_id>
|
||||||
|
<attractiveness>2</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>6</x_pos>
|
||||||
|
<y_pos>6</y_pos>
|
||||||
|
<wlan_id>5</wlan_id>
|
||||||
|
<attractiveness>2</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>7</x_pos>
|
||||||
|
<y_pos>7</y_pos>
|
||||||
|
<wlan_id>6</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>8</x_pos>
|
||||||
|
<y_pos>8</y_pos>
|
||||||
|
<wlan_id>7</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>9</x_pos>
|
||||||
|
<y_pos>9</y_pos>
|
||||||
|
<wlan_id>8</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>10</x_pos>
|
||||||
|
<y_pos>10</y_pos>
|
||||||
|
<wlan_id>9</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>11</x_pos>
|
||||||
|
<y_pos>11</y_pos>
|
||||||
|
<wlan_id>10</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>12</x_pos>
|
||||||
|
<y_pos>12</y_pos>
|
||||||
|
<wlan_id>11</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>13</x_pos>
|
||||||
|
<y_pos>13</y_pos>
|
||||||
|
<wlan_id>12</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
<datacenter arch="x86" os="Linux" vmm="Xen">
|
||||||
|
<costPerBw>0.1</costPerBw>
|
||||||
|
<costPerSec>3.0</costPerSec>
|
||||||
|
<costPerMem>0.05</costPerMem>
|
||||||
|
<costPerStorage>0.1</costPerStorage>
|
||||||
|
<location>
|
||||||
|
<x_pos>14</x_pos>
|
||||||
|
<y_pos>14</y_pos>
|
||||||
|
<wlan_id>13</wlan_id>
|
||||||
|
<attractiveness>3</attractiveness>
|
||||||
|
</location>
|
||||||
|
<hosts>
|
||||||
|
<host>
|
||||||
|
<core>8</core>
|
||||||
|
<mips>4000</mips>
|
||||||
|
<ram>8000</ram>
|
||||||
|
<storage>200000</storage>
|
||||||
|
<VMs>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
<VM vmm="Xen">
|
||||||
|
<core>2</core>
|
||||||
|
<mips>1000</mips>
|
||||||
|
<ram>2000</ram>
|
||||||
|
<storage>50000</storage>
|
||||||
|
</VM>
|
||||||
|
</VMs>
|
||||||
|
</host>
|
||||||
|
</hosts>
|
||||||
|
</datacenter>
|
||||||
|
</edge_devices>
|
BIN
lib/cloudsim-4.0.jar
Normal file
BIN
lib/cloudsim-4.0.jar
Normal file
Binary file not shown.
BIN
lib/commons-math3-3.6.1.jar
Normal file
BIN
lib/commons-math3-3.6.1.jar
Normal file
Binary file not shown.
4
scripts/compile.sh
Normal file
4
scripts/compile.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm -rf ../bin
|
||||||
|
mkdir ../bin
|
||||||
|
javac -classpath "../lib/cloudsim-4.0.jar:../lib/commons-math3-3.6.1.jar" -sourcepath ../src ../src/edu/boun/edgecloudsim/sample_application/mainApp.java -d ../bin
|
59
scripts/run_scenarios.sh
Normal file
59
scripts/run_scenarios.sh
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$#" -ne 2 ]; then
|
||||||
|
echo "Missing arguments! Please provide number of parallel processes and number of iterations."
|
||||||
|
echo "Usage: '$0 4 10'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
re='^[0-9]+$'
|
||||||
|
if ! [[ $1 =~ $re ]] ; then
|
||||||
|
echo "$1 is not an integer! Please provide number of parallel processes."
|
||||||
|
echo "Usage: '$0 4 10'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [[ $2 =~ $re ]] ; then
|
||||||
|
echo "$1 is not an integer! Please provide number of iterations."
|
||||||
|
echo "Usage: '$0 4 10'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
script_root_path="$(dirname "$(readlink -f "$0")")"
|
||||||
|
root_out_folder=${script_root_path}/output
|
||||||
|
num_of_processes=$1
|
||||||
|
iterationNumber=$2
|
||||||
|
process_counter=0
|
||||||
|
|
||||||
|
date=$(date '+%d-%m-%Y_%H-%M')
|
||||||
|
simulation_out_folder=${root_out_folder}/${date}
|
||||||
|
mkdir -p $simulation_out_folder
|
||||||
|
|
||||||
|
simulations=$(cat ${script_root_path}/simulation.list)
|
||||||
|
|
||||||
|
rm -rf ${script_root_path}/tmp_runner*
|
||||||
|
|
||||||
|
for sim_args in $simulations
|
||||||
|
do
|
||||||
|
scenario_name=$(echo $sim_args | cut -d ';' -f1)
|
||||||
|
edge_devices_file=$(echo $sim_args | cut -d ';' -f2)
|
||||||
|
applications_file=$(echo $sim_args | cut -d ';' -f3)
|
||||||
|
for (( i=1; i<=$iterationNumber; i++ ))
|
||||||
|
do
|
||||||
|
process_id=$(($process_counter % $num_of_processes))
|
||||||
|
process_counter=$(($process_counter + 1))
|
||||||
|
|
||||||
|
echo "${script_root_path}/runner.sh $simulation_out_folder $scenario_name $edge_devices_file $applications_file ${i}" >> "${simulation_out_folder}/tmp_runner${process_id}.sh"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
#num_of_cores=$(grep -c ^processor /proc/cpuinfo)
|
||||||
|
|
||||||
|
for (( i=0; i<$num_of_processes; i++ ))
|
||||||
|
do
|
||||||
|
chmod +x ${simulation_out_folder}/tmp_runner${i}.sh
|
||||||
|
${simulation_out_folder}/tmp_runner${i}.sh &
|
||||||
|
|
||||||
|
# pid=$!
|
||||||
|
# cpu=$(($i % $num_of_cores))
|
||||||
|
# taskset -cp $cpu,$cpu $pid
|
||||||
|
done
|
18
scripts/runner.sh
Normal file
18
scripts/runner.sh
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
script_root_path="$(dirname "$(readlink -f "$0")")"
|
||||||
|
simulation_out_folder=$1
|
||||||
|
scenario_name=$2
|
||||||
|
edge_devices_file=$3
|
||||||
|
applications_file=$4
|
||||||
|
iteration_number=$5
|
||||||
|
|
||||||
|
scenario_out_folder=${simulation_out_folder}/${scenario_name}/ite${iteration_number}
|
||||||
|
scenario_conf_file=${script_root_path}/../config/${scenario_name}.properties
|
||||||
|
scenario_edge_devices_file=${script_root_path}/../config/${edge_devices_file}
|
||||||
|
scenario_applications_file=${script_root_path}/../config/${applications_file}
|
||||||
|
|
||||||
|
mkdir -p $scenario_out_folder
|
||||||
|
java -classpath '../bin:../lib/cloudsim-4.0.jar:../lib/commons-math3-3.6.1.jar' edu.boun.edgecloudsim.sample_application.mainApp $scenario_conf_file $scenario_edge_devices_file $scenario_applications_file $scenario_out_folder $iteration_number > ${scenario_out_folder}.log
|
||||||
|
tar -czf ${scenario_out_folder}.tar.gz -C $simulation_out_folder/${scenario_name} ite${iteration_number}
|
||||||
|
rm -rf $scenario_out_folder
|
1
scripts/simulation.list
Normal file
1
scripts/simulation.list
Normal file
@ -0,0 +1 @@
|
|||||||
|
default_config;edge_devices.xml;applications.xml
|
57
src/edu/boun/edgecloudsim/core/ScenarioFactory.java
Normal file
57
src/edu/boun/edgecloudsim/core/ScenarioFactory.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Scenarion Factory interface
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* ScenarioFactory responsible for providing customizable components
|
||||||
|
* such as Network Model, Mobility Model, Edge Orchestrator.
|
||||||
|
* This interface is very critical for using custom models on EdgeCloudSim
|
||||||
|
* This interface should be implemented by EdgeCloudSim users
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.core;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.Host;
|
||||||
|
import org.cloudbus.cloudsim.UtilizationModel;
|
||||||
|
import org.cloudbus.cloudsim.VmAllocationPolicy;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.edge_orchestrator.EdgeOrchestrator;
|
||||||
|
import edu.boun.edgecloudsim.mobility.MobilityModel;
|
||||||
|
import edu.boun.edgecloudsim.task_generator.LoadGeneratorModel;
|
||||||
|
import edu.boun.edgecloudsim.network.NetworkModel;
|
||||||
|
|
||||||
|
public interface ScenarioFactory {
|
||||||
|
/**
|
||||||
|
* provides abstract Load Generator Model
|
||||||
|
*/
|
||||||
|
public LoadGeneratorModel getLoadGeneratorModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides abstract Edge Orchestrator
|
||||||
|
*/
|
||||||
|
public EdgeOrchestrator getEdgeOrchestrator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides abstract Mobility Model
|
||||||
|
*/
|
||||||
|
public MobilityModel getMobilityModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides abstract Network Model
|
||||||
|
*/
|
||||||
|
public NetworkModel getNetworkModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides abstract CPU Utilization Model
|
||||||
|
*/
|
||||||
|
public UtilizationModel getCpuUtilizationModel(SimSettings.APP_TYPES _taskType);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides abstract Vm Allocation Policy
|
||||||
|
*/
|
||||||
|
public VmAllocationPolicy getVmAllocationPolicy(List<? extends Host> list, int dataCenterIndex);
|
||||||
|
}
|
200
src/edu/boun/edgecloudsim/core/SimManager.java
Normal file
200
src/edu/boun/edgecloudsim/core/SimManager.java
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Simulation Manager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* SimManager is an singleton class providing many abstract classeses such as
|
||||||
|
* Network Model, Mobility Model, Edge Orchestrator to other modules
|
||||||
|
* Critical simulation related information would be gathered via this class
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.core;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.Log;
|
||||||
|
import org.cloudbus.cloudsim.core.CloudSim;
|
||||||
|
import org.cloudbus.cloudsim.core.SimEntity;
|
||||||
|
import org.cloudbus.cloudsim.core.SimEvent;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.edge_orchestrator.EdgeOrchestrator;
|
||||||
|
import edu.boun.edgecloudsim.edge_server.EdgeServerManager;
|
||||||
|
import edu.boun.edgecloudsim.edge_server.VmAllocationPolicy_Custom;
|
||||||
|
import edu.boun.edgecloudsim.edge_client.MobileDeviceManager;
|
||||||
|
import edu.boun.edgecloudsim.mobility.MobilityModel;
|
||||||
|
import edu.boun.edgecloudsim.task_generator.LoadGeneratorModel;
|
||||||
|
import edu.boun.edgecloudsim.network.NetworkModel;
|
||||||
|
import edu.boun.edgecloudsim.utils.EdgeTask;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimLogger;
|
||||||
|
|
||||||
|
public class SimManager extends SimEntity {
|
||||||
|
private static final int CREATE_TASK = 0;
|
||||||
|
private static final int CHECK_ALL_VM = 1;
|
||||||
|
private static final int GET_LOAD_LOG = 2;
|
||||||
|
private static final int PRINT_PROGRESS = 3;
|
||||||
|
private static final int STOP_SIMULATION = 4;
|
||||||
|
|
||||||
|
private int numOfMobileDevice;
|
||||||
|
private NetworkModel networkModel;
|
||||||
|
private MobilityModel mobilityModel;
|
||||||
|
private ScenarioFactory scenarioFactory;
|
||||||
|
private EdgeOrchestrator edgeOrchestrator;
|
||||||
|
private EdgeServerManager edgeServerManager;
|
||||||
|
private LoadGeneratorModel loadGeneratorModel;
|
||||||
|
private MobileDeviceManager mobileDeviceManager;
|
||||||
|
|
||||||
|
private static SimManager instance = null;
|
||||||
|
|
||||||
|
public SimManager(ScenarioFactory _scenarioFactory, int _numOfMobileDevice, SimSettings.SCENARIO_TYPES _simScenario) throws Exception {
|
||||||
|
super("SimManager");
|
||||||
|
scenarioFactory = _scenarioFactory;
|
||||||
|
numOfMobileDevice = _numOfMobileDevice;
|
||||||
|
|
||||||
|
SimLogger.print("Creating tasks...");
|
||||||
|
loadGeneratorModel = scenarioFactory.getLoadGeneratorModel();
|
||||||
|
loadGeneratorModel.initializeModel();
|
||||||
|
SimLogger.printLine("Done, ");
|
||||||
|
|
||||||
|
SimLogger.print("Creating device locations...");
|
||||||
|
mobilityModel = scenarioFactory.getMobilityModel();
|
||||||
|
mobilityModel.initialize();
|
||||||
|
SimLogger.printLine("Done.");
|
||||||
|
|
||||||
|
//Generate network model
|
||||||
|
networkModel = scenarioFactory.getNetworkModel();
|
||||||
|
networkModel.initialize();
|
||||||
|
|
||||||
|
//Generate edge orchestrator
|
||||||
|
edgeOrchestrator = scenarioFactory.getEdgeOrchestrator();
|
||||||
|
edgeOrchestrator.initialize();
|
||||||
|
|
||||||
|
//Create Physical Servers
|
||||||
|
edgeServerManager = new EdgeServerManager();
|
||||||
|
|
||||||
|
//Create Client Manager
|
||||||
|
mobileDeviceManager = new MobileDeviceManager();
|
||||||
|
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SimManager getInstance(){
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggering CloudSim to start simulation
|
||||||
|
*/
|
||||||
|
public void startSimulation() throws Exception{
|
||||||
|
//Starts the simulation
|
||||||
|
SimLogger.print(super.getName()+" is starting...");
|
||||||
|
|
||||||
|
//Start Edge Servers & Generate VMs
|
||||||
|
edgeServerManager.startDatacenters();
|
||||||
|
edgeServerManager.createVmList(mobileDeviceManager.getId());
|
||||||
|
|
||||||
|
CloudSim.startSimulation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScenarioFactory getScenarioFactory(){
|
||||||
|
return scenarioFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumOfMobileDevice(){
|
||||||
|
return numOfMobileDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkModel getNetworkModel(){
|
||||||
|
return networkModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobilityModel getMobilityModel(){
|
||||||
|
return mobilityModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EdgeOrchestrator getEdgeOrchestrator(){
|
||||||
|
return edgeOrchestrator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EdgeServerManager getLocalServerManager(){
|
||||||
|
return edgeServerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobileDeviceManager getMobileDeviceManager(){
|
||||||
|
return mobileDeviceManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startEntity() {
|
||||||
|
for(int i=0; i<edgeServerManager.getDatacenterList().size(); i++)
|
||||||
|
mobileDeviceManager.submitVmList(edgeServerManager.getVmList(i));
|
||||||
|
|
||||||
|
//Creation of tasks are scheduled here!
|
||||||
|
for(int i=0; i< loadGeneratorModel.getTaskList().size(); i++)
|
||||||
|
schedule(getId(), loadGeneratorModel.getTaskList().get(i).startTime, CREATE_TASK, loadGeneratorModel.getTaskList().get(i));
|
||||||
|
|
||||||
|
//Periodic event loops starts from here!
|
||||||
|
schedule(getId(), 5, CHECK_ALL_VM);
|
||||||
|
schedule(getId(), SimSettings.getInstance().getSimulationTime()/100, PRINT_PROGRESS);
|
||||||
|
schedule(getId(), SimSettings.getInstance().getVmLoadLogInterval(), GET_LOAD_LOG);
|
||||||
|
schedule(getId(), SimSettings.getInstance().getSimulationTime(), STOP_SIMULATION);
|
||||||
|
|
||||||
|
SimLogger.printLine("Done.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void processEvent(SimEvent ev) {
|
||||||
|
synchronized(this){
|
||||||
|
switch (ev.getTag()) {
|
||||||
|
case CREATE_TASK:
|
||||||
|
try {
|
||||||
|
EdgeTask edgeTask = (EdgeTask) ev.getData();
|
||||||
|
mobileDeviceManager.submitTask(edgeTask);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CHECK_ALL_VM:
|
||||||
|
int totalNumOfVm = SimSettings.getInstance().getNumOfEdgeVMs();
|
||||||
|
if(VmAllocationPolicy_Custom.getCreatedVmNum() != totalNumOfVm){
|
||||||
|
SimLogger.printLine("All VMs cannot be created! Terminating simulation...");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GET_LOAD_LOG:
|
||||||
|
SimLogger.getInstance().addVmUtilizationLog(CloudSim.clock(),edgeServerManager.getAvgUtilization());
|
||||||
|
schedule(getId(), SimSettings.getInstance().getVmLoadLogInterval(), GET_LOAD_LOG);
|
||||||
|
break;
|
||||||
|
case PRINT_PROGRESS:
|
||||||
|
int progress = (int)((CloudSim.clock()*100)/SimSettings.getInstance().getSimulationTime());
|
||||||
|
if(progress % 10 == 0)
|
||||||
|
SimLogger.print(Integer.toString(progress));
|
||||||
|
else
|
||||||
|
SimLogger.print(".");
|
||||||
|
if(CloudSim.clock() < SimSettings.getInstance().getSimulationTime())
|
||||||
|
schedule(getId(), SimSettings.getInstance().getSimulationTime()/100, PRINT_PROGRESS);
|
||||||
|
break;
|
||||||
|
case STOP_SIMULATION:
|
||||||
|
SimLogger.printLine("100");
|
||||||
|
CloudSim.terminateSimulation();
|
||||||
|
try {
|
||||||
|
SimLogger.getInstance().simStopped();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.printLine(getName() + ": unknown event type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdownEntity() {
|
||||||
|
edgeServerManager.terminateDatacenters();
|
||||||
|
}
|
||||||
|
}
|
490
src/edu/boun/edgecloudsim/core/SimSettings.java
Normal file
490
src/edu/boun/edgecloudsim/core/SimSettings.java
Normal file
@ -0,0 +1,490 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Simulation Settings class
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* SimSettings provides system wide simulation settings. It is a
|
||||||
|
* singleton class and provides all necessary information to other modules.
|
||||||
|
* If you need to use another simulation setting variable in your
|
||||||
|
* config file, add related getter methot in this class.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.core;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.utils.SimLogger;
|
||||||
|
|
||||||
|
public class SimSettings {
|
||||||
|
private static SimSettings instance = null;
|
||||||
|
private Document edgeDevicesDoc = null;
|
||||||
|
|
||||||
|
//enumarations for the scenarion, VM, appplication, and place.
|
||||||
|
//if you want to add different types on your config file,
|
||||||
|
//you may modify current types or add new types here.
|
||||||
|
public static enum VM_TYPES { EDGE_VM, CLOUD_VM }
|
||||||
|
public static enum APP_TYPES { FACE_REC_APP, HEALTH_APP, HEAVY_COMP_APP, VIDEO_GAME_APP, SIMPLE_SERVICE_APP }
|
||||||
|
public static enum PLACE_TYPES { ATTRACTIVENESS_L1, ATTRACTIVENESS_L2, ATTRACTIVENESS_L3 }
|
||||||
|
public static enum SCENARIO_TYPES { SINGLE_TIER, TWO_TIER, TWO_TIER_WITH_EO }
|
||||||
|
|
||||||
|
//predifined ID for cloud components.
|
||||||
|
public static int CLOUD_DATACENTER_ID = 1000;
|
||||||
|
public static int CLOUD_HOST_ID = CLOUD_DATACENTER_ID + 1;
|
||||||
|
public static int CLOUD_VM_ID = CLOUD_DATACENTER_ID + 2;
|
||||||
|
|
||||||
|
//delimiter for output file.
|
||||||
|
public static String DELIMITER = ";";
|
||||||
|
|
||||||
|
private double SIMULATION_TIME; //hours unit in properties file
|
||||||
|
private double WARM_UP_PERIOD; //seconds unit in properties file
|
||||||
|
private double INTERVAL_TO_GET_VM_LOAD_LOG; //seconds unit in properties file
|
||||||
|
private double INTERVAL_TO_GET_VM_LOCATION_LOG; //seconds unit in properties file
|
||||||
|
private boolean DEEP_FILE_LOG_ENABLED; //used for each success failed task
|
||||||
|
|
||||||
|
private int MIN_NUM_OF_MOBILE_DEVICES;
|
||||||
|
private int MAX_NUM_OF_MOBILE_DEVICES;
|
||||||
|
private int MOBILE_DEVICE_COUNTER_SIZE;
|
||||||
|
|
||||||
|
private int NUM_OF_EDGE_DATACENTERS;
|
||||||
|
private int NUM_OF_EDGE_HOSTS;
|
||||||
|
private int NUM_OF_EDGE_VMS;
|
||||||
|
|
||||||
|
private double WAN_PROPOGATION_DELAY; //seconds unit in properties file
|
||||||
|
private double LAN_INTERNAL_DELAY; //seconds unit in properties file
|
||||||
|
private int BANDWITH_WLAN; //Mbps unit in properties file
|
||||||
|
private int BANDWITH_WAN; //Mbps unit in properties file
|
||||||
|
private int BANDWITH_GSM; //Mbps unit in properties file
|
||||||
|
|
||||||
|
private int MIPS_FOR_CLOUD; //MIPS
|
||||||
|
|
||||||
|
private String ORCHESTRATOR_POLICY;
|
||||||
|
|
||||||
|
// mean waiting time (minute) is stored for each place types
|
||||||
|
private double[] mobilityLookUpTable;
|
||||||
|
|
||||||
|
// following values are stored for each applications defined in applications.xml
|
||||||
|
// [0] usage percentage (%)
|
||||||
|
// [1] prob. of selecting cloud (%)
|
||||||
|
// [2] poisson mean (sec)
|
||||||
|
// [3] active period (sec)
|
||||||
|
// [4] idle period (sec)
|
||||||
|
// [5] avg data upload (KB)
|
||||||
|
// [6] avg data download (KB)
|
||||||
|
// [7] avg task length (MI)
|
||||||
|
// [8] required # of cores
|
||||||
|
// [9] vm utilization (%)
|
||||||
|
private double[][] taskLookUpTable = new double[APP_TYPES.values().length][10];
|
||||||
|
|
||||||
|
private SimSettings() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SimSettings getInstance() {
|
||||||
|
if(instance == null) {
|
||||||
|
instance = new SimSettings();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads configuration file and stores information to local variables
|
||||||
|
* @param propertiesFile
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean initialize(String propertiesFile, String edgeDevicesFile, String applicationsFile){
|
||||||
|
boolean result = false;
|
||||||
|
InputStream input = null;
|
||||||
|
try {
|
||||||
|
input = new FileInputStream(propertiesFile);
|
||||||
|
|
||||||
|
// load a properties file
|
||||||
|
Properties prop = new Properties();
|
||||||
|
prop.load(input);
|
||||||
|
|
||||||
|
SIMULATION_TIME = 3600 * Double.parseDouble(prop.getProperty("simulation_time")); //hours
|
||||||
|
WARM_UP_PERIOD = Double.parseDouble(prop.getProperty("warm_up_period")); //seconds
|
||||||
|
INTERVAL_TO_GET_VM_LOAD_LOG = Double.parseDouble(prop.getProperty("vm_load_check_interval")); //seconds
|
||||||
|
INTERVAL_TO_GET_VM_LOCATION_LOG = Double.parseDouble(prop.getProperty("vm_location_check_interval")); //seconds
|
||||||
|
DEEP_FILE_LOG_ENABLED = Boolean.parseBoolean(prop.getProperty("deep_file_log_enabled"));
|
||||||
|
|
||||||
|
MIN_NUM_OF_MOBILE_DEVICES = Integer.parseInt(prop.getProperty("min_number_of_mobile_devices"));
|
||||||
|
MAX_NUM_OF_MOBILE_DEVICES = Integer.parseInt(prop.getProperty("max_number_of_mobile_devices"));
|
||||||
|
MOBILE_DEVICE_COUNTER_SIZE = Integer.parseInt(prop.getProperty("mobile_device_counter_size"));
|
||||||
|
|
||||||
|
WAN_PROPOGATION_DELAY = Double.parseDouble(prop.getProperty("wan_propogation_delay"));
|
||||||
|
LAN_INTERNAL_DELAY = Double.parseDouble(prop.getProperty("lan_internal_delay"));
|
||||||
|
BANDWITH_WLAN = 1000 * Integer.parseInt(prop.getProperty("wlan_bandwidth"));
|
||||||
|
BANDWITH_WAN = 1000 * Integer.parseInt(prop.getProperty("wan_bandwidth"));
|
||||||
|
BANDWITH_GSM = 1000 * Integer.parseInt(prop.getProperty("gsm_bandwidth"));
|
||||||
|
|
||||||
|
//It is assumed that
|
||||||
|
//-Storage and RAM are unlimited in cloud
|
||||||
|
//-Each task is executed with maximum capacity (as if there is no task in the cloud)
|
||||||
|
MIPS_FOR_CLOUD = Integer.parseInt(prop.getProperty("mips_for_cloud"));
|
||||||
|
|
||||||
|
ORCHESTRATOR_POLICY = prop.getProperty("task_provisioning");
|
||||||
|
|
||||||
|
//avg waiting time in a place (min)
|
||||||
|
double place1_mean_waiting_time = Double.parseDouble(prop.getProperty("attractiveness_L1_mean_waiting_time"));
|
||||||
|
double place2_mean_waiting_time = Double.parseDouble(prop.getProperty("attractiveness_L2_mean_waiting_time"));
|
||||||
|
double place3_mean_waiting_time = Double.parseDouble(prop.getProperty("attractiveness_L3_mean_waiting_time"));
|
||||||
|
|
||||||
|
//mean waiting time (minute)
|
||||||
|
mobilityLookUpTable = new double[]{
|
||||||
|
place1_mean_waiting_time, //ATTRACTIVENESS_L1
|
||||||
|
place2_mean_waiting_time, //ATTRACTIVENESS_L2
|
||||||
|
place3_mean_waiting_time //ATTRACTIVENESS_L3
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (input != null) {
|
||||||
|
try {
|
||||||
|
input.close();
|
||||||
|
result = true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parseApplicatinosXML(applicationsFile);
|
||||||
|
parseEdgeDevicesXML(edgeDevicesFile);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the parsed XML document for edge_devices.xml
|
||||||
|
*/
|
||||||
|
public Document getEdgeDevicesDocument(){
|
||||||
|
return edgeDevicesDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns simulation time (in hours unit) from properties file
|
||||||
|
*/
|
||||||
|
public double getSimulationTime()
|
||||||
|
{
|
||||||
|
return SIMULATION_TIME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns warm up period (in seconds unit) from properties file
|
||||||
|
*/
|
||||||
|
public double getWarmUpPeriod()
|
||||||
|
{
|
||||||
|
return WARM_UP_PERIOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns VM utilization log collection interval (in seconds unit) from properties file
|
||||||
|
*/
|
||||||
|
public double getVmLoadLogInterval()
|
||||||
|
{
|
||||||
|
return INTERVAL_TO_GET_VM_LOAD_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns VM location log collection interval (in seconds unit) from properties file
|
||||||
|
*/
|
||||||
|
public double getVmLocationLogInterval()
|
||||||
|
{
|
||||||
|
return INTERVAL_TO_GET_VM_LOCATION_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns deep statistics logging status from properties file
|
||||||
|
*/
|
||||||
|
public boolean getDeepFileLoggingEnabled()
|
||||||
|
{
|
||||||
|
return DEEP_FILE_LOG_ENABLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns WAN propogation delay (in second unit) from properties file
|
||||||
|
*/
|
||||||
|
public double getWanPropogationDelay()
|
||||||
|
{
|
||||||
|
return WAN_PROPOGATION_DELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns internal LAN propogation delay (in second unit) from properties file
|
||||||
|
*/
|
||||||
|
public double getInternalLanDelay()
|
||||||
|
{
|
||||||
|
return LAN_INTERNAL_DELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns WLAN bandwidth (in Mbps unit) from properties file
|
||||||
|
*/
|
||||||
|
public int getWlanBandwidth()
|
||||||
|
{
|
||||||
|
return BANDWITH_WLAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns WAN bandwidth (in Mbps unit) from properties file
|
||||||
|
*/
|
||||||
|
public int getWanBandwidth()
|
||||||
|
{
|
||||||
|
return BANDWITH_WAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns GSM bandwidth (in Mbps unit) from properties file
|
||||||
|
*/
|
||||||
|
public int getGsmBandwidth()
|
||||||
|
{
|
||||||
|
return BANDWITH_GSM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the minimum number of the mobile devices used in the simulation
|
||||||
|
*/
|
||||||
|
public int getMinNumOfMobileDev()
|
||||||
|
{
|
||||||
|
return MIN_NUM_OF_MOBILE_DEVICES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the maximunm number of the mobile devices used in the simulation
|
||||||
|
*/
|
||||||
|
public int getMaxNumOfMobileDev()
|
||||||
|
{
|
||||||
|
return MAX_NUM_OF_MOBILE_DEVICES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the number of increase on mobile devices
|
||||||
|
* while iterating from min to max mobile device
|
||||||
|
*/
|
||||||
|
public int getMobileDevCounterSize()
|
||||||
|
{
|
||||||
|
return MOBILE_DEVICE_COUNTER_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the number of edge datacenters
|
||||||
|
*/
|
||||||
|
public int getNumOfEdgeDatacenters()
|
||||||
|
{
|
||||||
|
return NUM_OF_EDGE_DATACENTERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the number of edge hosts running on the datacenters
|
||||||
|
*/
|
||||||
|
public int getNumOfEdgeHosts()
|
||||||
|
{
|
||||||
|
return NUM_OF_EDGE_HOSTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the number of edge VMs running on the hosts
|
||||||
|
*/
|
||||||
|
public int getNumOfEdgeVMs()
|
||||||
|
{
|
||||||
|
return NUM_OF_EDGE_VMS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns MIPS of the central cloud
|
||||||
|
*/
|
||||||
|
public int getMipsForCloud()
|
||||||
|
{
|
||||||
|
return MIPS_FOR_CLOUD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns orchestrator policy as string
|
||||||
|
*/
|
||||||
|
public String getOrchestratorPolicy()
|
||||||
|
{
|
||||||
|
return ORCHESTRATOR_POLICY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns mobility characteristic within an array
|
||||||
|
* the result includes mean waiting time (minute) or each place type
|
||||||
|
*/
|
||||||
|
public double[] getMobilityLookUpTable()
|
||||||
|
{
|
||||||
|
return mobilityLookUpTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns application characteristic within two dimensional array
|
||||||
|
* the result includes the following values for each application type
|
||||||
|
* [0] usage percentage (%)
|
||||||
|
* [1] prob. of selecting cloud (%)
|
||||||
|
* [2] poisson mean (sec)
|
||||||
|
* [3] active period (sec)
|
||||||
|
* [4] idle period (sec)
|
||||||
|
* [5] avg data upload (KB)
|
||||||
|
* [6] avg data download (KB)
|
||||||
|
* [7] avg task length (MI)
|
||||||
|
* [8] required # of cores
|
||||||
|
* [9] vm utilization (%)
|
||||||
|
*/
|
||||||
|
public double[][] getTaskLookUpTable()
|
||||||
|
{
|
||||||
|
return taskLookUpTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void isAttribtuePresent(Element element, String key) {
|
||||||
|
String value = element.getAttribute(key);
|
||||||
|
if (value.isEmpty() || value == null){
|
||||||
|
throw new IllegalArgumentException("Attribure '" + key + "' is not found in '" + element.getNodeName() +"'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void isElementPresent(Element element, String key) {
|
||||||
|
try {
|
||||||
|
String value = element.getElementsByTagName(key).item(0).getTextContent();
|
||||||
|
if (value.isEmpty() || value == null){
|
||||||
|
throw new IllegalArgumentException("Element '" + key + "' is not found in '" + element.getNodeName() +"'");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException("Element '" + key + "' is not found in '" + element.getNodeName() +"'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseApplicatinosXML(String filePath)
|
||||||
|
{
|
||||||
|
Document doc = null;
|
||||||
|
try {
|
||||||
|
File devicesFile = new File(filePath);
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
doc = dBuilder.parse(devicesFile);
|
||||||
|
doc.getDocumentElement().normalize();
|
||||||
|
|
||||||
|
NodeList appList = doc.getElementsByTagName("application");
|
||||||
|
for (int i = 0; i < appList.getLength(); i++) {
|
||||||
|
Node appNode = appList.item(i);
|
||||||
|
|
||||||
|
Element appElement = (Element) appNode;
|
||||||
|
isAttribtuePresent(appElement, "name");
|
||||||
|
isElementPresent(appElement, "usage_percentage");
|
||||||
|
isElementPresent(appElement, "prob_cloud_selection");
|
||||||
|
isElementPresent(appElement, "poisson_interarrival");
|
||||||
|
isElementPresent(appElement, "active_period");
|
||||||
|
isElementPresent(appElement, "idle_period");
|
||||||
|
isElementPresent(appElement, "data_upload");
|
||||||
|
isElementPresent(appElement, "data_download");
|
||||||
|
isElementPresent(appElement, "task_length");
|
||||||
|
isElementPresent(appElement, "required_core");
|
||||||
|
isElementPresent(appElement, "vm_utilization");
|
||||||
|
|
||||||
|
String appName = appElement.getAttribute("name");
|
||||||
|
SimSettings.APP_TYPES appType = APP_TYPES.valueOf(appName);
|
||||||
|
double usage_percentage = Double.parseDouble(appElement.getElementsByTagName("usage_percentage").item(0).getTextContent());
|
||||||
|
double prob_cloud_selection = Double.parseDouble(appElement.getElementsByTagName("prob_cloud_selection").item(0).getTextContent());
|
||||||
|
double poisson_interarrival = Double.parseDouble(appElement.getElementsByTagName("poisson_interarrival").item(0).getTextContent());
|
||||||
|
double active_period = Double.parseDouble(appElement.getElementsByTagName("active_period").item(0).getTextContent());
|
||||||
|
double idle_period = Double.parseDouble(appElement.getElementsByTagName("idle_period").item(0).getTextContent());
|
||||||
|
double data_upload = Double.parseDouble(appElement.getElementsByTagName("data_upload").item(0).getTextContent());
|
||||||
|
double data_download = Double.parseDouble(appElement.getElementsByTagName("data_download").item(0).getTextContent());
|
||||||
|
double task_length = Double.parseDouble(appElement.getElementsByTagName("task_length").item(0).getTextContent());
|
||||||
|
double required_core = Double.parseDouble(appElement.getElementsByTagName("required_core").item(0).getTextContent());
|
||||||
|
double vm_utilization = Double.parseDouble(appElement.getElementsByTagName("vm_utilization").item(0).getTextContent());
|
||||||
|
|
||||||
|
taskLookUpTable[appType.ordinal()][0] = usage_percentage; //usage percentage (%)
|
||||||
|
taskLookUpTable[appType.ordinal()][1] = prob_cloud_selection; //prob. of selecting cloud (%)
|
||||||
|
taskLookUpTable[appType.ordinal()][2] = poisson_interarrival; //poisson mean (sec)
|
||||||
|
taskLookUpTable[appType.ordinal()][3] = active_period; //active period (sec)
|
||||||
|
taskLookUpTable[appType.ordinal()][4] = idle_period; //idle period (sec)
|
||||||
|
taskLookUpTable[appType.ordinal()][5] = data_upload; //avg data upload (KB)
|
||||||
|
taskLookUpTable[appType.ordinal()][6] = data_download; //avg data download (KB)
|
||||||
|
taskLookUpTable[appType.ordinal()][7] = task_length; //avg task length (MI)
|
||||||
|
taskLookUpTable[appType.ordinal()][8] = required_core; //required # of core
|
||||||
|
taskLookUpTable[appType.ordinal()][9] = vm_utilization; //vm utilization (%)
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
SimLogger.printLine("Edge Devices XML cannot be parsed! Terminating simulation...");
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseEdgeDevicesXML(String filePath)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
File devicesFile = new File(filePath);
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
edgeDevicesDoc = dBuilder.parse(devicesFile);
|
||||||
|
edgeDevicesDoc.getDocumentElement().normalize();
|
||||||
|
|
||||||
|
NodeList datacenterList = edgeDevicesDoc.getElementsByTagName("datacenter");
|
||||||
|
for (int i = 0; i < datacenterList.getLength(); i++) {
|
||||||
|
NUM_OF_EDGE_DATACENTERS++;
|
||||||
|
Node datacenterNode = datacenterList.item(i);
|
||||||
|
|
||||||
|
Element datacenterElement = (Element) datacenterNode;
|
||||||
|
isAttribtuePresent(datacenterElement, "arch");
|
||||||
|
isAttribtuePresent(datacenterElement, "os");
|
||||||
|
isAttribtuePresent(datacenterElement, "vmm");
|
||||||
|
isElementPresent(datacenterElement, "costPerBw");
|
||||||
|
isElementPresent(datacenterElement, "costPerSec");
|
||||||
|
isElementPresent(datacenterElement, "costPerMem");
|
||||||
|
isElementPresent(datacenterElement, "costPerStorage");
|
||||||
|
|
||||||
|
Element location = (Element)datacenterElement.getElementsByTagName("location").item(0);
|
||||||
|
isElementPresent(location, "attractiveness");
|
||||||
|
isElementPresent(location, "wlan_id");
|
||||||
|
isElementPresent(location, "x_pos");
|
||||||
|
isElementPresent(location, "y_pos");
|
||||||
|
|
||||||
|
NodeList hostList = datacenterElement.getElementsByTagName("host");
|
||||||
|
for (int j = 0; j < hostList.getLength(); j++) {
|
||||||
|
NUM_OF_EDGE_HOSTS++;
|
||||||
|
Node hostNode = hostList.item(j);
|
||||||
|
|
||||||
|
Element hostElement = (Element) hostNode;
|
||||||
|
isElementPresent(hostElement, "core");
|
||||||
|
isElementPresent(hostElement, "mips");
|
||||||
|
isElementPresent(hostElement, "ram");
|
||||||
|
isElementPresent(hostElement, "storage");
|
||||||
|
|
||||||
|
NodeList vmList = hostElement.getElementsByTagName("VM");
|
||||||
|
for (int k = 0; k < vmList.getLength(); k++) {
|
||||||
|
NUM_OF_EDGE_VMS++;
|
||||||
|
Node vmNode = vmList.item(k);
|
||||||
|
|
||||||
|
Element vmElement = (Element) vmNode;
|
||||||
|
isAttribtuePresent(vmElement, "vmm");
|
||||||
|
isElementPresent(vmElement, "core");
|
||||||
|
isElementPresent(vmElement, "mips");
|
||||||
|
isElementPresent(vmElement, "ram");
|
||||||
|
isElementPresent(vmElement, "storage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
SimLogger.printLine("Edge Devices XML cannot be parsed! Terminating simulation...");
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Custom VM Cpu Utilization Model
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* CpuUtilizationModel_Custom implements UtilizationModel and used for
|
||||||
|
* VM CPU utilization model. In CloudSim, the CPU utilization of the VM
|
||||||
|
* is a simple counter. We provide more realistic utilization model
|
||||||
|
* which decide CPU utilization of each application by using the
|
||||||
|
* values defined in the applications.xml file. For those who wants to
|
||||||
|
* add another VM Cpu Utilization Model to EdgeCloudSim should provide
|
||||||
|
* another concreate instance of UtilizationModel via ScenarioFactory
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_client;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.UtilizationModel;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
|
||||||
|
public class CpuUtilizationModel_Custom implements UtilizationModel {
|
||||||
|
private SimSettings.APP_TYPES taskType;
|
||||||
|
|
||||||
|
public CpuUtilizationModel_Custom(SimSettings.APP_TYPES _taskType){
|
||||||
|
taskType=_taskType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see cloudsim.power.UtilizationModel#getUtilization(double)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double getUtilization(double time) {
|
||||||
|
return SimSettings.getInstance().getTaskLookUpTable()[taskType.ordinal()][9];
|
||||||
|
}
|
||||||
|
|
||||||
|
public double predictUtilization(SimSettings.VM_TYPES _vmType){
|
||||||
|
return SimSettings.getInstance().getTaskLookUpTable()[taskType.ordinal()][9];
|
||||||
|
}
|
||||||
|
}
|
258
src/edu/boun/edgecloudsim/edge_client/MobileDeviceManager.java
Normal file
258
src/edu/boun/edgecloudsim/edge_client/MobileDeviceManager.java
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Mobile Device Manager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* MobileDeviceManager is responsible for submitting the tasks to the related
|
||||||
|
* device by using the Edge Orchestrator. It also takes proper actions
|
||||||
|
* when the execution of the tasks are finished.
|
||||||
|
* By default, MobileDeviceManager sends tasks to the edge servers or
|
||||||
|
* cloud servers. If you want to use different topology, for example
|
||||||
|
* MAN edge server, you should modify the flow defined in this class.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_client;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.DatacenterBroker;
|
||||||
|
import org.cloudbus.cloudsim.Cloudlet;
|
||||||
|
import org.cloudbus.cloudsim.UtilizationModel;
|
||||||
|
import org.cloudbus.cloudsim.UtilizationModelFull;
|
||||||
|
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.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 MobileDeviceManager extends DatacenterBroker {
|
||||||
|
private static final int BASE = 100000; //start from base in order not to conflict cloudsim tag!
|
||||||
|
private static final int REQUEST_RECEIVED_BY_CLOUD = BASE + 1;
|
||||||
|
private static final int REQUEST_PROCESSED_BY_CLOUD = BASE + 2;
|
||||||
|
private static final int REQUEST_RECIVED_BY_EDGE_DEVICE = BASE + 3;
|
||||||
|
private static final int RESPONSE_RECEIVED_BY_MOBILE_DEVICE = BASE + 4;
|
||||||
|
private int taskIdCounter=0;
|
||||||
|
|
||||||
|
public MobileDeviceManager() throws Exception {
|
||||||
|
super("Global_Broker");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
|
||||||
|
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock());
|
||||||
|
if(task.getSubmittedLocation().equals(currentLocation))
|
||||||
|
{
|
||||||
|
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + task.getCloudletId() + " received");
|
||||||
|
double WlanDelay = networkModel.getDownloadDelay(task.getAssociatedHostId(), task.getMobileDeviceId());
|
||||||
|
if(WlanDelay > 0)
|
||||||
|
{
|
||||||
|
schedule(getId(), WlanDelay, RESPONSE_RECEIVED_BY_MOBILE_DEVICE, task);
|
||||||
|
SimLogger.getInstance().downloadStarted(task.getCloudletId(), WlanDelay);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//SimLogger.printLine("task cannot be finished due to mobility of user!");
|
||||||
|
//SimLogger.printLine("device: " +task.getMobileDeviceId()+" - submitted " + task.getSubmissionTime() + " @ " + task.getSubmittedLocation().getXPos() + " handled " + CloudSim.clock() + " @ " + currentLocation.getXPos());
|
||||||
|
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 REQUEST_RECEIVED_BY_CLOUD:
|
||||||
|
{
|
||||||
|
Task task = (Task) ev.getData();
|
||||||
|
|
||||||
|
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock());
|
||||||
|
|
||||||
|
task.setSubmittedLocation(currentLocation);
|
||||||
|
task.setAssociatedHostId(SimSettings.CLOUD_HOST_ID);
|
||||||
|
|
||||||
|
SimLogger.getInstance().uploaded(task.getCloudletId(),
|
||||||
|
SimSettings.CLOUD_DATACENTER_ID,
|
||||||
|
SimSettings.CLOUD_HOST_ID,
|
||||||
|
SimSettings.CLOUD_VM_ID,
|
||||||
|
SimSettings.VM_TYPES.CLOUD_VM.ordinal());
|
||||||
|
|
||||||
|
//calculate computational delay in cloud
|
||||||
|
double ComputationDelay = (double)task.getCloudletLength() / (double)SimSettings.getInstance().getMipsForCloud();
|
||||||
|
|
||||||
|
schedule(getId(), ComputationDelay, REQUEST_PROCESSED_BY_CLOUD, task);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case REQUEST_PROCESSED_BY_CLOUD:
|
||||||
|
{
|
||||||
|
Task task = (Task) ev.getData();
|
||||||
|
|
||||||
|
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock());
|
||||||
|
|
||||||
|
if(task.getSubmittedLocation().equals(currentLocation))
|
||||||
|
{
|
||||||
|
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + task.getCloudletId() + " received");
|
||||||
|
double WanDelay = networkModel.getDownloadDelay(SimSettings.CLOUD_DATACENTER_ID, task.getMobileDeviceId());
|
||||||
|
if(WanDelay > 0)
|
||||||
|
{
|
||||||
|
schedule(getId(), WanDelay, RESPONSE_RECEIVED_BY_MOBILE_DEVICE, task);
|
||||||
|
SimLogger.getInstance().downloadStarted(task.getCloudletId(), WanDelay);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SimLogger.getInstance().failedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//SimLogger.printLine("task cannot be finished due to mobility of user!");
|
||||||
|
//SimLogger.printLine("device: " +task.getMobileDeviceId()+" - submitted " + task.getSubmissionTime() + " @ " + task.getSubmittedLocation().getXPos() + " handled " + CloudSim.clock() + " @ " + currentLocation.getXPos());
|
||||||
|
SimLogger.getInstance().failedDueToMobility(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case REQUEST_RECIVED_BY_EDGE_DEVICE:
|
||||||
|
{
|
||||||
|
Task task = (Task) ev.getData();
|
||||||
|
|
||||||
|
Location currentLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(),CloudSim.clock());
|
||||||
|
|
||||||
|
//select a VM
|
||||||
|
EdgeVM selectedVM = SimManager.getInstance().getEdgeOrchestrator().selectVm(task);
|
||||||
|
|
||||||
|
if(selectedVM != null){
|
||||||
|
//save task info
|
||||||
|
task.setSubmittedLocation(currentLocation);
|
||||||
|
task.setAssociatedHostId(selectedVM.getHost().getId());
|
||||||
|
|
||||||
|
//bind task to related VM
|
||||||
|
getCloudletList().add(task);
|
||||||
|
bindCloudletToVm(task.getCloudletId(),selectedVM.getId());
|
||||||
|
|
||||||
|
//SimLogger.printLine(CloudSim.clock() + ": Cloudlet#" + task.getCloudletId() + " is submitted to VM#" + task.getVmId());
|
||||||
|
sendNow(getVmsToDatacentersMap().get(task.getVmId()), CloudSimTags.CLOUDLET_SUBMIT, task);
|
||||||
|
|
||||||
|
SimLogger.getInstance().uploaded(task.getCloudletId(),
|
||||||
|
selectedVM.getHost().getDatacenter().getId(),
|
||||||
|
selectedVM.getHost().getId(),
|
||||||
|
selectedVM.getId(),
|
||||||
|
selectedVM.getVmType().ordinal());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//SimLogger.printLine("Task #" + task.getCloudletId() + " cannot assign to any VM");
|
||||||
|
SimLogger.getInstance().rejectedDueToVMCapacity(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case RESPONSE_RECEIVED_BY_MOBILE_DEVICE:
|
||||||
|
{
|
||||||
|
Cloudlet cloudlet = (Cloudlet) ev.getData();
|
||||||
|
//SimLogger.printLine(CloudSim.clock() + ": " + getName() + ": Cloudlet " + cloudlet.getCloudletId() + " is received");
|
||||||
|
SimLogger.getInstance().downloaded(cloudlet.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) {
|
||||||
|
NetworkModel networkModel = SimManager.getInstance().getNetworkModel();
|
||||||
|
|
||||||
|
//create a task
|
||||||
|
Task task = createTask(edgeTask);
|
||||||
|
|
||||||
|
//add related task to log list
|
||||||
|
SimLogger.getInstance().addLog(CloudSim.clock(),
|
||||||
|
task.getCloudletId(),
|
||||||
|
task.getTaskType().ordinal(),
|
||||||
|
(int)task.getCloudletLength(),
|
||||||
|
(int)task.getCloudletFileSize(),
|
||||||
|
(int)task.getCloudletOutputSize());
|
||||||
|
|
||||||
|
if(edgeTask.requireCloud){
|
||||||
|
double WanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(),SimSettings.CLOUD_DATACENTER_ID);
|
||||||
|
if(WanDelay>0){
|
||||||
|
schedule(getId(), WanDelay, REQUEST_RECEIVED_BY_CLOUD, task);
|
||||||
|
SimLogger.getInstance().uploadStarted(task.getCloudletId(),WanDelay);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//SimLogger.printLine("Task #" + task.getCloudletId() + " cannot assign to any VM");
|
||||||
|
SimLogger.getInstance().rejectedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
double WlanDelay = networkModel.getUploadDelay(task.getMobileDeviceId(),0);
|
||||||
|
if(WlanDelay > 0){
|
||||||
|
schedule(getId(), WlanDelay, REQUEST_RECIVED_BY_EDGE_DEVICE, task);
|
||||||
|
SimLogger.getInstance().uploadStarted(task.getCloudletId(),WlanDelay);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SimLogger.getInstance().rejectedDueToBandwidth(task.getCloudletId(), CloudSim.clock());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task createTask(EdgeTask edgeTask){
|
||||||
|
UtilizationModel utilizationModel = new UtilizationModelFull(); /*UtilizationModelStochastic*/
|
||||||
|
UtilizationModel utilizationModelCPU = SimManager.getInstance().getScenarioFactory().getCpuUtilizationModel(edgeTask.taskType);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void taskEnded(){
|
||||||
|
clearDatacenters();
|
||||||
|
finishExecution();
|
||||||
|
}
|
||||||
|
}
|
66
src/edu/boun/edgecloudsim/edge_client/Task.java
Normal file
66
src/edu/boun/edgecloudsim/edge_client/Task.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Task
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Task adds app type, task submission location, mobile device id and host id
|
||||||
|
* information to CloudSim's Cloudlet class.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_client;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.Cloudlet;
|
||||||
|
import org.cloudbus.cloudsim.UtilizationModel;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.utils.Location;
|
||||||
|
|
||||||
|
public class Task extends Cloudlet {
|
||||||
|
private SimSettings.APP_TYPES type;
|
||||||
|
private Location submittedLocation;
|
||||||
|
private int mobileDeviceId;
|
||||||
|
private int hostIndex;
|
||||||
|
|
||||||
|
public Task(int _mobileDeviceId, int cloudletId, long cloudletLength, int pesNumber,
|
||||||
|
long cloudletFileSize, long cloudletOutputSize,
|
||||||
|
UtilizationModel utilizationModelCpu,
|
||||||
|
UtilizationModel utilizationModelRam,
|
||||||
|
UtilizationModel utilizationModelBw) {
|
||||||
|
super(cloudletId, cloudletLength, pesNumber, cloudletFileSize,
|
||||||
|
cloudletOutputSize, utilizationModelCpu, utilizationModelRam,
|
||||||
|
utilizationModelBw);
|
||||||
|
|
||||||
|
mobileDeviceId = _mobileDeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setSubmittedLocation(Location _submittedLocation){
|
||||||
|
submittedLocation =_submittedLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssociatedHostId(int _hostIndex){
|
||||||
|
hostIndex=_hostIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTaskType(SimSettings.APP_TYPES _type){
|
||||||
|
type=_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMobileDeviceId(){
|
||||||
|
return mobileDeviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getSubmittedLocation(){
|
||||||
|
return submittedLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAssociatedHostId(){
|
||||||
|
return hostIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimSettings.APP_TYPES getTaskType(){
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,199 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Basic Edge Orchestrator implementation
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* BasicEdgeOrchestrator implements basic algorithms which are
|
||||||
|
* first/next/best/worst/random fit algorithms while assigning
|
||||||
|
* requests to the edge devices.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_orchestrator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.core.CloudSim;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimManager;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings.SCENARIO_TYPES;
|
||||||
|
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.Location;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimUtils;
|
||||||
|
|
||||||
|
public class BasicEdgeOrchestrator extends EdgeOrchestrator {
|
||||||
|
private int numberOfHost; //used by load balancer
|
||||||
|
private int lastSelectedHostIndex; //used by load balancer
|
||||||
|
private int[] lastSelectedVmIndexes; //used by each host individually
|
||||||
|
|
||||||
|
public BasicEdgeOrchestrator(String _policy,
|
||||||
|
SCENARIO_TYPES _simScenario) {
|
||||||
|
super(_policy, _simScenario);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
numberOfHost=SimSettings.getInstance().getNumOfEdgeHosts();
|
||||||
|
|
||||||
|
lastSelectedHostIndex = -1;
|
||||||
|
lastSelectedVmIndexes = new int[numberOfHost];
|
||||||
|
for(int i=0; i<numberOfHost; i++)
|
||||||
|
lastSelectedVmIndexes[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EdgeVM selectVm(Task task) {
|
||||||
|
if(simScenario == SimSettings.SCENARIO_TYPES.TWO_TIER_WITH_EO)
|
||||||
|
return selectVmOnLoadBalancer(task);
|
||||||
|
else
|
||||||
|
return selectVmOnHost(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EdgeVM selectVmOnHost(Task task){
|
||||||
|
EdgeVM selectedVM = null;
|
||||||
|
|
||||||
|
Location deviceLocation = SimManager.getInstance().getMobilityModel().getLocation(task.getMobileDeviceId(), CloudSim.clock());
|
||||||
|
//in our scenasrio, serving wlan ID is equal to the host id
|
||||||
|
//because there is only one host in one place
|
||||||
|
int relatedHostId=deviceLocation.getServingWlanId();
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().getVmList(relatedHostId);
|
||||||
|
|
||||||
|
if(policy.equalsIgnoreCase("RANDOM_FIT")){
|
||||||
|
int randomIndex = SimUtils.getRandomNumber(0, vmArray.size()-1);
|
||||||
|
double requiredCapacity = ((CpuUtilizationModel_Custom)task.getUtilizationModelCpu()).predictUtilization(vmArray.get(randomIndex).getVmType());
|
||||||
|
double targetVmCapacity = (double)100 - vmArray.get(randomIndex).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
|
||||||
|
if(requiredCapacity <= targetVmCapacity)
|
||||||
|
selectedVM = vmArray.get(randomIndex);
|
||||||
|
}
|
||||||
|
else if(policy.equalsIgnoreCase("WORST_FIT")){
|
||||||
|
double selectedVmCapacity = 0; //start with min value
|
||||||
|
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(policy.equalsIgnoreCase("BEST_FIT")){
|
||||||
|
double selectedVmCapacity = 101; //start with max value
|
||||||
|
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(policy.equalsIgnoreCase("FIRST_FIT")){
|
||||||
|
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){
|
||||||
|
selectedVM = vmArray.get(vmIndex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(policy.equalsIgnoreCase("NEXT_FIT")){
|
||||||
|
int tries = 0;
|
||||||
|
while(tries < vmArray.size()){
|
||||||
|
lastSelectedVmIndexes[relatedHostId] = (lastSelectedVmIndexes[relatedHostId]+1) % vmArray.size();
|
||||||
|
double requiredCapacity = ((CpuUtilizationModel_Custom)task.getUtilizationModelCpu()).predictUtilization(vmArray.get(lastSelectedVmIndexes[relatedHostId]).getVmType());
|
||||||
|
double targetVmCapacity = (double)100 - vmArray.get(lastSelectedVmIndexes[relatedHostId]).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
|
||||||
|
if(requiredCapacity <= targetVmCapacity){
|
||||||
|
selectedVM = vmArray.get(lastSelectedVmIndexes[relatedHostId]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tries++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedVM;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EdgeVM selectVmOnLoadBalancer(Task task){
|
||||||
|
EdgeVM selectedVM = null;
|
||||||
|
|
||||||
|
if(policy.equalsIgnoreCase("RANDOM_FIT")){
|
||||||
|
int randomHostIndex = SimUtils.getRandomNumber(0, numberOfHost-1);
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().getVmList(randomHostIndex);
|
||||||
|
int randomIndex = SimUtils.getRandomNumber(0, vmArray.size()-1);
|
||||||
|
|
||||||
|
double requiredCapacity = ((CpuUtilizationModel_Custom)task.getUtilizationModelCpu()).predictUtilization(vmArray.get(randomIndex).getVmType());
|
||||||
|
double targetVmCapacity = (double)100 - vmArray.get(randomIndex).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
|
||||||
|
if(requiredCapacity <= targetVmCapacity)
|
||||||
|
selectedVM = vmArray.get(randomIndex);
|
||||||
|
}
|
||||||
|
else if(policy.equalsIgnoreCase("WORST_FIT")){
|
||||||
|
double selectedVmCapacity = 0; //start with min value
|
||||||
|
for(int hostIndex=0; hostIndex<numberOfHost; hostIndex++){
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().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(policy.equalsIgnoreCase("BEST_FIT")){
|
||||||
|
double selectedVmCapacity = 101; //start with max value
|
||||||
|
for(int hostIndex=0; hostIndex<numberOfHost; hostIndex++){
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().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(policy.equalsIgnoreCase("FIRST_FIT")){
|
||||||
|
for(int hostIndex=0; hostIndex<numberOfHost; hostIndex++){
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().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){
|
||||||
|
selectedVM = vmArray.get(vmIndex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(policy.equalsIgnoreCase("NEXT_FIT")){
|
||||||
|
int hostCheckCounter = 0;
|
||||||
|
while(selectedVM == null && hostCheckCounter < numberOfHost){
|
||||||
|
int tries = 0;
|
||||||
|
lastSelectedHostIndex = (lastSelectedHostIndex+1) % numberOfHost;
|
||||||
|
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().getVmList(lastSelectedHostIndex);
|
||||||
|
while(tries < vmArray.size()){
|
||||||
|
lastSelectedVmIndexes[lastSelectedHostIndex] = (lastSelectedVmIndexes[lastSelectedHostIndex]+1) % vmArray.size();
|
||||||
|
double requiredCapacity = ((CpuUtilizationModel_Custom)task.getUtilizationModelCpu()).predictUtilization(vmArray.get(lastSelectedVmIndexes[lastSelectedHostIndex]).getVmType());
|
||||||
|
double targetVmCapacity = (double)100 - vmArray.get(lastSelectedVmIndexes[lastSelectedHostIndex]).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
|
||||||
|
if(requiredCapacity <= targetVmCapacity){
|
||||||
|
selectedVM = vmArray.get(lastSelectedVmIndexes[lastSelectedHostIndex]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tries++;
|
||||||
|
}
|
||||||
|
|
||||||
|
hostCheckCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedVM;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Edge Orchestrator
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* EdgeOrchestrator is an abstract class which is used for selecting VM
|
||||||
|
* for each client requests. For those who wants to add a custom
|
||||||
|
* Edge Orchestrator to EdgeCloudSim should extend this class and provide
|
||||||
|
* a concreate instance via ScenarioFactory
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_orchestrator;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.edge_server.EdgeVM;
|
||||||
|
import edu.boun.edgecloudsim.edge_client.Task;
|
||||||
|
|
||||||
|
public abstract class EdgeOrchestrator {
|
||||||
|
protected String policy;
|
||||||
|
protected SimSettings.SCENARIO_TYPES simScenario;
|
||||||
|
|
||||||
|
public EdgeOrchestrator(String _policy, SimSettings.SCENARIO_TYPES _simScenario){
|
||||||
|
policy = _policy;
|
||||||
|
simScenario = _simScenario;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* initialize edge orchestrator if needed
|
||||||
|
*/
|
||||||
|
public abstract void initialize();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns proper VM from the related edge orchestrator point of view
|
||||||
|
*/
|
||||||
|
public abstract EdgeVM selectVm(Task task);
|
||||||
|
}
|
40
src/edu/boun/edgecloudsim/edge_server/EdgeHost.java
Normal file
40
src/edu/boun/edgecloudsim/edge_server/EdgeHost.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - EdgeHost
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* EdgeHost adds location information over CloudSim's Host class
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_server;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.Host;
|
||||||
|
import org.cloudbus.cloudsim.Pe;
|
||||||
|
import org.cloudbus.cloudsim.VmScheduler;
|
||||||
|
import org.cloudbus.cloudsim.provisioners.BwProvisioner;
|
||||||
|
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.utils.Location;
|
||||||
|
|
||||||
|
public class EdgeHost extends Host {
|
||||||
|
private Location location;
|
||||||
|
|
||||||
|
public EdgeHost(int id, RamProvisioner ramProvisioner,
|
||||||
|
BwProvisioner bwProvisioner, long storage,
|
||||||
|
List<? extends Pe> peList, VmScheduler vmScheduler) {
|
||||||
|
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlace(Location _location){
|
||||||
|
location=_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation(){
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
}
|
224
src/edu/boun/edgecloudsim/edge_server/EdgeServerManager.java
Normal file
224
src/edu/boun/edgecloudsim/edge_server/EdgeServerManager.java
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Edge Server Manager
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* EdgeServerManager is responsible for creating datacenters, hosts and VMs.
|
||||||
|
* It also provides the list of VMs running on the hosts.
|
||||||
|
* This information is critical for the edge orchestrator.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
|
||||||
|
import org.cloudbus.cloudsim.Datacenter;
|
||||||
|
import org.cloudbus.cloudsim.DatacenterCharacteristics;
|
||||||
|
import org.cloudbus.cloudsim.Host;
|
||||||
|
import org.cloudbus.cloudsim.Pe;
|
||||||
|
import org.cloudbus.cloudsim.Storage;
|
||||||
|
import org.cloudbus.cloudsim.VmAllocationPolicy;
|
||||||
|
import org.cloudbus.cloudsim.VmSchedulerSpaceShared;
|
||||||
|
import org.cloudbus.cloudsim.core.CloudSim;
|
||||||
|
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
|
||||||
|
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
|
||||||
|
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimManager;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.utils.Location;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimUtils;
|
||||||
|
|
||||||
|
public class EdgeServerManager {
|
||||||
|
private List<Datacenter> localDatacenters;
|
||||||
|
private List<List<EdgeVM>> vmList;
|
||||||
|
private int hostIdCounter;
|
||||||
|
|
||||||
|
public EdgeServerManager() {
|
||||||
|
localDatacenters=new ArrayList<Datacenter>();
|
||||||
|
vmList = new ArrayList<List<EdgeVM>>();
|
||||||
|
hostIdCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EdgeVM> getVmList(int hostId){
|
||||||
|
return vmList.get(hostId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Datacenter> getDatacenterList(){
|
||||||
|
return localDatacenters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startDatacenters() throws Exception{
|
||||||
|
//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;
|
||||||
|
localDatacenters.add(createDatacenter(i, datacenterElement));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createVmList(int brockerId){
|
||||||
|
int hostCounter=0;
|
||||||
|
int vmCounter=0;
|
||||||
|
|
||||||
|
//Create VMs for each hosts
|
||||||
|
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;
|
||||||
|
NodeList hostNodeList = datacenterElement.getElementsByTagName("host");
|
||||||
|
for (int j = 0; j < hostNodeList.getLength(); j++) {
|
||||||
|
|
||||||
|
vmList.add(hostCounter, new ArrayList<EdgeVM>());
|
||||||
|
|
||||||
|
Node hostNode = hostNodeList.item(j);
|
||||||
|
Element hostElement = (Element) hostNode;
|
||||||
|
NodeList vmNodeList = hostElement.getElementsByTagName("VM");
|
||||||
|
for (int k = 0; k < vmNodeList.getLength(); k++) {
|
||||||
|
Node vmNode = vmNodeList.item(k);
|
||||||
|
Element vmElement = (Element) vmNode;
|
||||||
|
|
||||||
|
String vmm = vmElement.getAttribute("vmm");
|
||||||
|
int numOfCores = Integer.parseInt(vmElement.getElementsByTagName("core").item(0).getTextContent());
|
||||||
|
double mips = Double.parseDouble(vmElement.getElementsByTagName("mips").item(0).getTextContent());
|
||||||
|
int ram = Integer.parseInt(vmElement.getElementsByTagName("ram").item(0).getTextContent());
|
||||||
|
long storage = Long.parseLong(vmElement.getElementsByTagName("storage").item(0).getTextContent());
|
||||||
|
long bandwidth = SimSettings.getInstance().getWlanBandwidth() / (hostNodeList.getLength()+vmNodeList.getLength());
|
||||||
|
|
||||||
|
//VM Parameters
|
||||||
|
EdgeVM vm = new EdgeVM(vmCounter, brockerId, mips, numOfCores, ram, bandwidth, storage, vmm, new CloudletSchedulerTimeShared());
|
||||||
|
vm.setVmType(SimSettings.VM_TYPES.EDGE_VM);
|
||||||
|
vmList.get(hostCounter).add(vm);
|
||||||
|
vmCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
hostCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void terminateDatacenters(){
|
||||||
|
for (Datacenter datacenter : localDatacenters) {
|
||||||
|
datacenter.shutdownEntity();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//average utilization of all VMs
|
||||||
|
public double getAvgUtilization(){
|
||||||
|
double totalUtilization = 0;
|
||||||
|
double vmCounter = 0;
|
||||||
|
|
||||||
|
// for each datacenter...
|
||||||
|
for(int i= 0; i<localDatacenters.size(); i++) {
|
||||||
|
List<? extends Host> list = localDatacenters.get(i).getHostList();
|
||||||
|
// for each host...
|
||||||
|
for (int j=0; j < list.size(); j++) {
|
||||||
|
Host host = list.get(j);
|
||||||
|
List<EdgeVM> vmArray = SimManager.getInstance().getLocalServerManager().getVmList(host.getId());
|
||||||
|
//for each vm...
|
||||||
|
for(int vmIndex=0; vmIndex<vmArray.size(); vmIndex++){
|
||||||
|
totalUtilization += vmArray.get(vmIndex).getCloudletScheduler().getTotalUtilizationOfCpu(CloudSim.clock());
|
||||||
|
vmCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalUtilization / vmCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Datacenter createDatacenter(int index, Element datacenterElement) throws Exception{
|
||||||
|
String arch = datacenterElement.getAttribute("arch");
|
||||||
|
String os = datacenterElement.getAttribute("os");
|
||||||
|
String vmm = datacenterElement.getAttribute("vmm");
|
||||||
|
double costPerBw = Double.parseDouble(datacenterElement.getElementsByTagName("costPerBw").item(0).getTextContent());
|
||||||
|
double costPerSec = Double.parseDouble(datacenterElement.getElementsByTagName("costPerSec").item(0).getTextContent());
|
||||||
|
double costPerMem = Double.parseDouble(datacenterElement.getElementsByTagName("costPerMem").item(0).getTextContent());
|
||||||
|
double costPerStorage = Double.parseDouble(datacenterElement.getElementsByTagName("costPerStorage").item(0).getTextContent());
|
||||||
|
|
||||||
|
List<EdgeHost> hostList=createHosts(datacenterElement);
|
||||||
|
|
||||||
|
String name = "Datacenter_" + Integer.toString(index);
|
||||||
|
double time_zone = 3.0; // time zone this resource located
|
||||||
|
LinkedList<Storage> storageList = new LinkedList<Storage>(); //we are not adding SAN devices by now
|
||||||
|
|
||||||
|
// 5. Create a DatacenterCharacteristics object that stores the
|
||||||
|
// properties of a data center: architecture, OS, list of
|
||||||
|
// Machines, allocation policy: time- or space-shared, time zone
|
||||||
|
// and its price (G$/Pe time unit).
|
||||||
|
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
|
||||||
|
arch, os, vmm, hostList, time_zone, costPerSec, costPerMem, costPerStorage, costPerBw);
|
||||||
|
|
||||||
|
|
||||||
|
// 6. Finally, we need to create a PowerDatacenter object.
|
||||||
|
Datacenter datacenter = null;
|
||||||
|
|
||||||
|
VmAllocationPolicy vm_policy = SimManager.getInstance().getScenarioFactory().getVmAllocationPolicy(hostList,index);
|
||||||
|
datacenter = new Datacenter(name, characteristics, vm_policy, storageList, 0);
|
||||||
|
|
||||||
|
return datacenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<EdgeHost> createHosts(Element datacenterElement){
|
||||||
|
|
||||||
|
// Here are the steps needed to create a PowerDatacenter:
|
||||||
|
// 1. We need to create a list to store one or more Machines
|
||||||
|
List<EdgeHost> hostList = new ArrayList<EdgeHost>();
|
||||||
|
|
||||||
|
Element location = (Element)datacenterElement.getElementsByTagName("location").item(0);
|
||||||
|
String attractiveness = location.getElementsByTagName("attractiveness").item(0).getTextContent();
|
||||||
|
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());
|
||||||
|
SimSettings.PLACE_TYPES placeType = SimUtils.stringToPlace(attractiveness);
|
||||||
|
|
||||||
|
NodeList hostNodeList = datacenterElement.getElementsByTagName("host");
|
||||||
|
for (int j = 0; j < hostNodeList.getLength(); j++) {
|
||||||
|
Node hostNode = hostNodeList.item(j);
|
||||||
|
|
||||||
|
Element hostElement = (Element) hostNode;
|
||||||
|
int numOfCores = Integer.parseInt(hostElement.getElementsByTagName("core").item(0).getTextContent());
|
||||||
|
double mips = Double.parseDouble(hostElement.getElementsByTagName("mips").item(0).getTextContent());
|
||||||
|
int ram = Integer.parseInt(hostElement.getElementsByTagName("ram").item(0).getTextContent());
|
||||||
|
long storage = Long.parseLong(hostElement.getElementsByTagName("storage").item(0).getTextContent());
|
||||||
|
long bandwidth = SimSettings.getInstance().getWlanBandwidth() / hostNodeList.getLength();
|
||||||
|
|
||||||
|
// 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
|
||||||
|
// create a list to store these PEs before creating
|
||||||
|
// a Machine.
|
||||||
|
List<Pe> peList = new ArrayList<Pe>();
|
||||||
|
|
||||||
|
// 3. Create PEs and add these into the list.
|
||||||
|
//for a quad-core machine, a list of 4 PEs is required:
|
||||||
|
for(int i=0; i<numOfCores; i++){
|
||||||
|
peList.add(new Pe(i, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
|
||||||
|
}
|
||||||
|
|
||||||
|
//4. Create Hosts with its id and list of PEs and add them to the list of machines
|
||||||
|
EdgeHost host = new EdgeHost(
|
||||||
|
hostIdCounter,
|
||||||
|
new RamProvisionerSimple(ram),
|
||||||
|
new BwProvisionerSimple(bandwidth), //kbps
|
||||||
|
storage,
|
||||||
|
peList,
|
||||||
|
new VmSchedulerSpaceShared(peList)
|
||||||
|
);
|
||||||
|
|
||||||
|
host.setPlace(new Location(placeType, wlan_id, x_pos, y_pos));
|
||||||
|
hostList.add(host);
|
||||||
|
hostIdCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hostList;
|
||||||
|
}
|
||||||
|
}
|
34
src/edu/boun/edgecloudsim/edge_server/EdgeVM.java
Normal file
34
src/edu/boun/edgecloudsim/edge_server/EdgeVM.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - EdgeVM
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* EdgeVM adds vm type information over CloudSim's VM class
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_server;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.CloudletScheduler;
|
||||||
|
import org.cloudbus.cloudsim.Vm;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
|
||||||
|
public class EdgeVM extends Vm {
|
||||||
|
private SimSettings.VM_TYPES type;
|
||||||
|
|
||||||
|
public EdgeVM(int id, int userId, double mips, int numberOfPes, int ram,
|
||||||
|
long bw, long size, String vmm, CloudletScheduler cloudletScheduler) {
|
||||||
|
super(id, userId, mips, numberOfPes, ram, bw, size, vmm, cloudletScheduler);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVmType(SimSettings.VM_TYPES _type){
|
||||||
|
type=_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimSettings.VM_TYPES getVmType(){
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Custom Vm Allocation Policy
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* VmAllocationPolicy_Custom implements VmAllocationPolicy to decide which.
|
||||||
|
* VM is created on which host locatied on the datacenters. For those
|
||||||
|
* who wants to add another Vm Allocation Policy to EdgeCloudSim should
|
||||||
|
* provide another concreate instance of VmAllocationPolicy via ScenarioFactory
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.edge_server;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.Host;
|
||||||
|
import org.cloudbus.cloudsim.Log;
|
||||||
|
import org.cloudbus.cloudsim.Vm;
|
||||||
|
import org.cloudbus.cloudsim.VmAllocationPolicy;
|
||||||
|
import org.cloudbus.cloudsim.core.CloudSim;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Same as VmAllocationPolicySimple.
|
||||||
|
*/
|
||||||
|
public class VmAllocationPolicy_Custom extends VmAllocationPolicy {
|
||||||
|
/** The vm table. */
|
||||||
|
private Map<String, Host> vmTable;
|
||||||
|
private static int createdVmNum;
|
||||||
|
private int DataCenterIndex;
|
||||||
|
|
||||||
|
public VmAllocationPolicy_Custom(List<? extends Host> list, int _DataCenterIndex) {
|
||||||
|
super(list);
|
||||||
|
|
||||||
|
setVmTable(new HashMap<String, Host>());
|
||||||
|
DataCenterIndex=_DataCenterIndex;
|
||||||
|
createdVmNum = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allocateHostForVm(Vm vm) {
|
||||||
|
boolean result = false;
|
||||||
|
|
||||||
|
if (!getVmTable().containsKey(vm.getUid())) { // if this vm was not created
|
||||||
|
boolean vmFound = false;
|
||||||
|
int vmCounter = 0;
|
||||||
|
int hostIndex = 0;
|
||||||
|
int dataCenterIndex = 0;
|
||||||
|
|
||||||
|
//find proper datacenter id and host id for this VM
|
||||||
|
Document doc = SimSettings.getInstance().getEdgeDevicesDocument();
|
||||||
|
NodeList datacenterList = doc.getElementsByTagName("datacenter");
|
||||||
|
for (int i = 0; (!vmFound && i < datacenterList.getLength()); i++) {
|
||||||
|
Node datacenterNode = datacenterList.item(i);
|
||||||
|
Element datacenterElement = (Element) datacenterNode;
|
||||||
|
NodeList hostNodeList = datacenterElement.getElementsByTagName("host");
|
||||||
|
for (int j = 0; (!vmFound && j < hostNodeList.getLength()); j++) {
|
||||||
|
Node hostNode = hostNodeList.item(j);
|
||||||
|
Element hostElement = (Element) hostNode;
|
||||||
|
NodeList vmNodeList = hostElement.getElementsByTagName("VM");
|
||||||
|
for (int k = 0; (!vmFound && k < vmNodeList.getLength()); k++) {
|
||||||
|
|
||||||
|
if(vmCounter == vm.getId()){
|
||||||
|
dataCenterIndex = i;
|
||||||
|
hostIndex = j;
|
||||||
|
vmFound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
vmCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(vmFound && dataCenterIndex == DataCenterIndex && hostIndex < getHostList().size()){
|
||||||
|
Host host = getHostList().get(hostIndex);
|
||||||
|
result = host.vmCreate(vm);
|
||||||
|
|
||||||
|
if (result) { // if vm were succesfully created in the host
|
||||||
|
getVmTable().put(vm.getUid(), host);
|
||||||
|
createdVmNum++;
|
||||||
|
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),CloudSim.clock());
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allocateHostForVm(Vm vm, Host host) {
|
||||||
|
if (host.vmCreate(vm)) { // if vm has been succesfully created in the host
|
||||||
|
getVmTable().put(vm.getUid(), host);
|
||||||
|
createdVmNum++;
|
||||||
|
|
||||||
|
Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to the host #" + host.getId(),CloudSim.clock());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> optimizeAllocation(
|
||||||
|
List<? extends Vm> vmList) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deallocateHostForVm(Vm vm) {
|
||||||
|
Host host = getVmTable().remove(vm.getUid());
|
||||||
|
if (host != null) {
|
||||||
|
host.vmDestroy(vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Host getHost(Vm vm) {
|
||||||
|
return getVmTable().get(vm.getUid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Host getHost(int vmId, int userId) {
|
||||||
|
return getVmTable().get(Vm.getUid(userId, vmId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCreatedVmNum(){
|
||||||
|
return createdVmNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the vm table.
|
||||||
|
*
|
||||||
|
* @return the vm table
|
||||||
|
*/
|
||||||
|
public Map<String, Host> getVmTable() {
|
||||||
|
return vmTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the vm table.
|
||||||
|
*
|
||||||
|
* @param vmTable the vm table
|
||||||
|
*/
|
||||||
|
protected void setVmTable(Map<String, Host> vmTable) {
|
||||||
|
this.vmTable = vmTable;
|
||||||
|
}
|
||||||
|
}
|
36
src/edu/boun/edgecloudsim/mobility/MobilityModel.java
Normal file
36
src/edu/boun/edgecloudsim/mobility/MobilityModel.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Mobility Model
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* MobilityModel is an abstract class which is used for calculating the
|
||||||
|
* location of each mobile devices with respect to the time. For those who
|
||||||
|
* wants to add a custom Mobility Model to EdgeCloudSim should extend
|
||||||
|
* this class and provide a concreate instance via ScenarioFactory
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.mobility;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.utils.Location;
|
||||||
|
|
||||||
|
public abstract class MobilityModel {
|
||||||
|
protected int numberOfMobileDevices;
|
||||||
|
protected double simulationTime;
|
||||||
|
|
||||||
|
public MobilityModel(int _numberOfMobileDevices, double _simulationTime){
|
||||||
|
numberOfMobileDevices=_numberOfMobileDevices;
|
||||||
|
simulationTime=_simulationTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* calculate location of the devices according to related mobility model
|
||||||
|
*/
|
||||||
|
public abstract void initialize();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns location of a device at a certain time
|
||||||
|
*/
|
||||||
|
public abstract Location getLocation(int deviceId, double time);
|
||||||
|
}
|
123
src/edu/boun/edgecloudsim/mobility/NomadicMobility.java
Normal file
123
src/edu/boun/edgecloudsim/mobility/NomadicMobility.java
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Nomadic Mobility model implementation
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* MobilityModel implements basic nomadic mobility model where the
|
||||||
|
* place of the devices are changed from time to time instead of a
|
||||||
|
* continuous location update.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.mobility;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.utils.Location;
|
||||||
|
import edu.boun.edgecloudsim.utils.PoissonDistr;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimLogger;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimUtils;
|
||||||
|
|
||||||
|
public class NomadicMobility extends MobilityModel {
|
||||||
|
private List<TreeMap<Double, Location>> treeMapArray;
|
||||||
|
|
||||||
|
public NomadicMobility(int _numberOfMobileDevices, double _simulationTime) {
|
||||||
|
super(_numberOfMobileDevices, _simulationTime);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
treeMapArray = new ArrayList<TreeMap<Double, Location>>();
|
||||||
|
|
||||||
|
PoissonDistr[] poissonRngList = new PoissonDistr[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();
|
||||||
|
SimSettings.PLACE_TYPES placeType = SimUtils.stringToPlace(attractiveness);
|
||||||
|
|
||||||
|
poissonRngList[i] = new PoissonDistr(SimSettings.getInstance().getMobilityLookUpTable()[placeType.ordinal()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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();
|
||||||
|
SimSettings.PLACE_TYPES placeType = SimUtils.stringToPlace(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 from 10th seconds
|
||||||
|
treeMapArray.get(i).put((double)10, new Location(placeType, 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 = poissonRngList[currentLocationId].sample() * 60;
|
||||||
|
|
||||||
|
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();
|
||||||
|
SimSettings.PLACE_TYPES placeType = SimUtils.stringToPlace(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(placeType, wlan_id, x_pos, y_pos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!placeFound){
|
||||||
|
SimLogger.printLine("impossible is occured! location cannot be assigned to the device!");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getLocation(int deviceId, double time) {
|
||||||
|
TreeMap<Double, Location> treeMap = treeMapArray.get(deviceId);
|
||||||
|
|
||||||
|
Entry<Double, Location> e = treeMap.floorEntry(time);
|
||||||
|
|
||||||
|
if(e == null){
|
||||||
|
SimLogger.printLine("impossible is occured! no location is found for the device!");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
186
src/edu/boun/edgecloudsim/network/MM1Queue.java
Normal file
186
src/edu/boun/edgecloudsim/network/MM1Queue.java
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - M/M/1 Queue model implementation
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* MM1Queue implements M/M/1 Queue model for WLAN and WAN communication
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.network;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.core.CloudSim;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimManager;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.edge_server.EdgeHost;
|
||||||
|
import edu.boun.edgecloudsim.utils.Location;
|
||||||
|
|
||||||
|
public class MM1Queue extends NetworkModel {
|
||||||
|
private double WlanPoissonMean; //seconds
|
||||||
|
private double WanPoissonMean; //seconds
|
||||||
|
private double avgTaskInputSize; //bytes
|
||||||
|
private double avgTaskOutputSize; //bytes
|
||||||
|
private int maxNumOfClientsInPlace;
|
||||||
|
|
||||||
|
public MM1Queue(int _numberOfMobileDevices) {
|
||||||
|
super(_numberOfMobileDevices);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
WlanPoissonMean=0;
|
||||||
|
WanPoissonMean=0;
|
||||||
|
avgTaskInputSize=0;
|
||||||
|
avgTaskOutputSize=0;
|
||||||
|
maxNumOfClientsInPlace=0;
|
||||||
|
|
||||||
|
//Calculate interarrival time and task sizes
|
||||||
|
double numOfTaskType = 0;
|
||||||
|
SimSettings SS = SimSettings.getInstance();
|
||||||
|
for (SimSettings.APP_TYPES taskType : SimSettings.APP_TYPES.values()) {
|
||||||
|
double weight = SS.getTaskLookUpTable()[taskType.ordinal()][0]/(double)100;
|
||||||
|
if(weight != 0) {
|
||||||
|
WlanPoissonMean += (SS.getTaskLookUpTable()[taskType.ordinal()][2])*weight;
|
||||||
|
|
||||||
|
double percentageOfCloudCommunication = SS.getTaskLookUpTable()[taskType.ordinal()][1];
|
||||||
|
WanPoissonMean += (WlanPoissonMean)*((double)100/percentageOfCloudCommunication)*weight;
|
||||||
|
|
||||||
|
avgTaskInputSize += SS.getTaskLookUpTable()[taskType.ordinal()][5]*weight;
|
||||||
|
|
||||||
|
avgTaskOutputSize += SS.getTaskLookUpTable()[taskType.ordinal()][6]*weight;
|
||||||
|
|
||||||
|
numOfTaskType++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WlanPoissonMean = WlanPoissonMean/numOfTaskType;
|
||||||
|
avgTaskInputSize = avgTaskInputSize/numOfTaskType;
|
||||||
|
avgTaskOutputSize = avgTaskOutputSize/numOfTaskType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* source device is always mobile device in our simulation scenarios!
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double getUploadDelay(int sourceDeviceId, int destDeviceId) {
|
||||||
|
double delay = 0;
|
||||||
|
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(sourceDeviceId,CloudSim.clock());
|
||||||
|
|
||||||
|
//if destination device is the cloud datacenter, both wan and wlan delay should be considered
|
||||||
|
if(destDeviceId == SimSettings.CLOUD_DATACENTER_ID){
|
||||||
|
double wlanDelay = getWlanUploadDelay(accessPointLocation, CloudSim.clock());
|
||||||
|
double wanDelay = getWanUploadDelay(accessPointLocation, CloudSim.clock() + wlanDelay);
|
||||||
|
if(wlanDelay > 0 && wanDelay >0)
|
||||||
|
delay = wlanDelay + wanDelay;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
delay = getWlanUploadDelay(accessPointLocation, CloudSim.clock());
|
||||||
|
|
||||||
|
//all requests are send to edge orchestrator first than redirected related VM
|
||||||
|
delay += (SimSettings.getInstance().getInternalLanDelay() * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* destination device is always mobile device in our simulation scenarios!
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double getDownloadDelay(int sourceDeviceId, int destDeviceId) {
|
||||||
|
double delay = 0;
|
||||||
|
Location accessPointLocation = SimManager.getInstance().getMobilityModel().getLocation(destDeviceId,CloudSim.clock());
|
||||||
|
|
||||||
|
//if source device is the cloud datacenter, both wan and wlan delay should be considered
|
||||||
|
if(sourceDeviceId == SimSettings.CLOUD_DATACENTER_ID){
|
||||||
|
double wlanDelay = getWlanDownloadDelay(accessPointLocation, CloudSim.clock());
|
||||||
|
double wanDelay = getWanDownloadDelay(accessPointLocation, CloudSim.clock() + wlanDelay);
|
||||||
|
if(wlanDelay > 0 && wanDelay >0)
|
||||||
|
delay = wlanDelay + wanDelay;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
delay = getWlanDownloadDelay(accessPointLocation, CloudSim.clock());
|
||||||
|
|
||||||
|
EdgeHost host = (EdgeHost)(SimManager.
|
||||||
|
getInstance().
|
||||||
|
getLocalServerManager().
|
||||||
|
getDatacenterList().get(sourceDeviceId).
|
||||||
|
getHostList().get(0));
|
||||||
|
|
||||||
|
//if source device id is the edge server which is located in another location, add internal lan delay
|
||||||
|
//in our scenasrio, serving wlan ID is equal to the host id, because there is only one host in one place
|
||||||
|
if(host.getLocation().getServingWlanId() != accessPointLocation.getServingWlanId())
|
||||||
|
delay += (SimSettings.getInstance().getInternalLanDelay() * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxNumOfClientsInPlace(){
|
||||||
|
return maxNumOfClientsInPlace;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getDeviceCount(Location deviceLocation, double time){
|
||||||
|
int deviceCount = 0;
|
||||||
|
|
||||||
|
for(int i=0; i<numberOfMobileDevices; i++) {
|
||||||
|
Location location = SimManager.getInstance().getMobilityModel().getLocation(i,time);
|
||||||
|
if(location.equals(deviceLocation))
|
||||||
|
deviceCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//record max number of client just for debugging
|
||||||
|
if(maxNumOfClientsInPlace<deviceCount)
|
||||||
|
maxNumOfClientsInPlace = deviceCount;
|
||||||
|
|
||||||
|
return deviceCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double calculateMM1(double propogationDelay, int bandwidth /*Kbps*/, double PoissonMean, double avgTaskSize /*KB*/, int deviceCount){
|
||||||
|
double Bps=0, mu=0, lamda=0;
|
||||||
|
|
||||||
|
avgTaskSize = avgTaskSize * (double)1000; //convert from KB to Byte
|
||||||
|
|
||||||
|
Bps = bandwidth * (double)1000 / (double)8; //convert from Kbps to Byte per seconds
|
||||||
|
lamda = ((double)1/(double)PoissonMean); //task per seconds
|
||||||
|
mu = Bps / avgTaskSize ; //task per seconds
|
||||||
|
double result = (double)1 / (mu-lamda*(double)deviceCount);
|
||||||
|
|
||||||
|
return result + propogationDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getWlanDownloadDelay(Location accessPointLocation, double time) {
|
||||||
|
return calculateMM1(0,
|
||||||
|
SimSettings.getInstance().getWlanBandwidth(),
|
||||||
|
WlanPoissonMean,
|
||||||
|
avgTaskOutputSize,
|
||||||
|
getDeviceCount(accessPointLocation, time));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getWlanUploadDelay(Location accessPointLocation, double time) {
|
||||||
|
return calculateMM1(0,
|
||||||
|
SimSettings.getInstance().getWlanBandwidth(),
|
||||||
|
WlanPoissonMean,
|
||||||
|
avgTaskInputSize,
|
||||||
|
getDeviceCount(accessPointLocation, time));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getWanDownloadDelay(Location accessPointLocation, double time) {
|
||||||
|
return calculateMM1(SimSettings.getInstance().getWanPropogationDelay(),
|
||||||
|
SimSettings.getInstance().getWanBandwidth(),
|
||||||
|
WanPoissonMean,
|
||||||
|
avgTaskOutputSize,
|
||||||
|
getDeviceCount(accessPointLocation, time));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getWanUploadDelay(Location accessPointLocation, double time) {
|
||||||
|
return calculateMM1(SimSettings.getInstance().getWanPropogationDelay(),
|
||||||
|
SimSettings.getInstance().getWanBandwidth(),
|
||||||
|
WanPoissonMean,
|
||||||
|
avgTaskInputSize,
|
||||||
|
getDeviceCount(accessPointLocation, time));
|
||||||
|
}
|
||||||
|
}
|
37
src/edu/boun/edgecloudsim/network/NetworkModel.java
Normal file
37
src/edu/boun/edgecloudsim/network/NetworkModel.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Network Model
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* NetworkModel is an abstract class which is used for calculating the
|
||||||
|
* network delay from device to device. For those who wants to add a
|
||||||
|
* custom Network Model to EdgeCloudSim should extend this class and
|
||||||
|
* provide a concreate instance via ScenarioFactory
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.network;
|
||||||
|
|
||||||
|
public abstract class NetworkModel {
|
||||||
|
protected int numberOfMobileDevices;
|
||||||
|
|
||||||
|
public NetworkModel(int _numberOfMobileDevices){
|
||||||
|
numberOfMobileDevices=_numberOfMobileDevices;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializes costom network model
|
||||||
|
*/
|
||||||
|
public abstract void initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculates the upload delay from source to destination device
|
||||||
|
*/
|
||||||
|
public abstract double getUploadDelay(int sourceDeviceId, int destDeviceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculates the download delay from source to destination device
|
||||||
|
*/
|
||||||
|
public abstract double getDownloadDelay(int sourceDeviceId, int destDeviceId);
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Sample Scenario Factory
|
||||||
|
*
|
||||||
|
* Description: Sample 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.sample_application;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.cloudbus.cloudsim.Host;
|
||||||
|
import org.cloudbus.cloudsim.UtilizationModel;
|
||||||
|
import org.cloudbus.cloudsim.VmAllocationPolicy;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.ScenarioFactory;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings.APP_TYPES;
|
||||||
|
import edu.boun.edgecloudsim.edge_orchestrator.BasicEdgeOrchestrator;
|
||||||
|
import edu.boun.edgecloudsim.edge_orchestrator.EdgeOrchestrator;
|
||||||
|
import edu.boun.edgecloudsim.edge_server.VmAllocationPolicy_Custom;
|
||||||
|
import edu.boun.edgecloudsim.edge_client.CpuUtilizationModel_Custom;
|
||||||
|
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.MM1Queue;
|
||||||
|
import edu.boun.edgecloudsim.network.NetworkModel;
|
||||||
|
|
||||||
|
public class SampleScenarioFactory implements ScenarioFactory {
|
||||||
|
private int numOfMobileDevice;
|
||||||
|
private double simulationTime;
|
||||||
|
private String orchestratorPolicy;
|
||||||
|
private SimSettings.SCENARIO_TYPES simScenario;
|
||||||
|
|
||||||
|
SampleScenarioFactory(int _numOfMobileDevice,
|
||||||
|
double _simulationTime,
|
||||||
|
String _orchestratorPolicy,
|
||||||
|
SimSettings.SCENARIO_TYPES _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 NomadicMobility(numOfMobileDevice,simulationTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NetworkModel getNetworkModel() {
|
||||||
|
return new MM1Queue(numOfMobileDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VmAllocationPolicy getVmAllocationPolicy(List<? extends Host> hostList, int dataCenterIndex) {
|
||||||
|
return new VmAllocationPolicy_Custom(hostList,dataCenterIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UtilizationModel getCpuUtilizationModel(APP_TYPES _taskType) {
|
||||||
|
return new CpuUtilizationModel_Custom(_taskType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
121
src/edu/boun/edgecloudsim/sample_application/mainApp.java
Normal file
121
src/edu/boun/edgecloudsim/sample_application/mainApp.java
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Sample Application
|
||||||
|
*
|
||||||
|
* Description: Sample application for EdgeCloudSim
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.sample_application;
|
||||||
|
|
||||||
|
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();
|
||||||
|
SimLogger.enableFileLog();
|
||||||
|
|
||||||
|
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...");
|
||||||
|
String configName = "default_config";
|
||||||
|
configFile = "config/" + configName + ".properties";
|
||||||
|
applicationsFile = "config/applications.xml";
|
||||||
|
edgeDevicesFile = "config/edge_devices.xml";
|
||||||
|
outputFolder = "D:/" + configName + "/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(SimLogger.isFileLogEnabled())
|
||||||
|
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 (SimSettings.SCENARIO_TYPES scenario : SimSettings.SCENARIO_TYPES.values())
|
||||||
|
{
|
||||||
|
Date ScenarioStartDate = Calendar.getInstance().getTime();
|
||||||
|
now = df.format(ScenarioStartDate);
|
||||||
|
|
||||||
|
SimLogger.printLine("Scenario started at " + now);
|
||||||
|
SimLogger.printLine(scenario + "(" + SS.getOrchestratorPolicy() + ")" + " - duration: " + SS.getSimulationTime()/3600 + " hour(s) - poisson: " + SS.getTaskLookUpTable()[0][2] + " - #devices: " + j + " - ite: " + iterationNumber);
|
||||||
|
SimLogger.getInstance().simStarted(outputFolder,"SIMRESULT_" + scenario + "_" + 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);
|
||||||
|
|
||||||
|
ScenarioFactory sampleFactory = new SampleScenarioFactory(j,SS.getSimulationTime(), SS.getOrchestratorPolicy(), scenario);
|
||||||
|
|
||||||
|
SimManager manager = new SimManager(sampleFactory, j, scenario);
|
||||||
|
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 SCENARIO_TYPES loop
|
||||||
|
}//End of NUMBER_OF_MOBILE_DEVICE loop
|
||||||
|
|
||||||
|
Date SimulationEndDate = Calendar.getInstance().getTime();
|
||||||
|
now = df.format(SimulationEndDate);
|
||||||
|
SimLogger.printLine("Simulation finished at " + now + ". It took " + SimUtils.getTimeDifference(SimulationStartDate,SimulationEndDate));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Idle/Active Load Generator implementation
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* IdleActiveLoadGenerator implements basic load generator model where the
|
||||||
|
* mobile devices generate task in active period and waits in idle period.
|
||||||
|
* Task interarrival time (load generation period), Idle and active periods
|
||||||
|
* are defined in the configuration file.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.task_generator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.apache.commons.math3.distribution.ExponentialDistribution;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings.APP_TYPES;
|
||||||
|
import edu.boun.edgecloudsim.utils.EdgeTask;
|
||||||
|
import edu.boun.edgecloudsim.utils.PoissonDistr;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimLogger;
|
||||||
|
import edu.boun.edgecloudsim.utils.SimUtils;
|
||||||
|
|
||||||
|
public class IdleActiveLoadGenerator extends LoadGeneratorModel{
|
||||||
|
|
||||||
|
public IdleActiveLoadGenerator(int _numberOfMobileDevices, double _simulationTime, SimSettings.SCENARIO_TYPES _simScenario) {
|
||||||
|
super(_numberOfMobileDevices, _simulationTime, _simScenario);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeModel() {
|
||||||
|
taskList = new ArrayList<EdgeTask>();
|
||||||
|
|
||||||
|
//exponential number generator for file input size, file output size and task length
|
||||||
|
PoissonDistr[][] poissonRngList = new PoissonDistr[SimSettings.APP_TYPES.values().length][3];
|
||||||
|
|
||||||
|
//create random number generator for each place
|
||||||
|
for(int i=0; i<SimSettings.APP_TYPES.values().length; i++) {
|
||||||
|
if(SimSettings.getInstance().getTaskLookUpTable()[i][0] ==0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
poissonRngList[i][0] = new PoissonDistr(SimSettings.getInstance().getTaskLookUpTable()[i][5]);
|
||||||
|
poissonRngList[i][1] = new PoissonDistr(SimSettings.getInstance().getTaskLookUpTable()[i][6]);
|
||||||
|
poissonRngList[i][2] = new PoissonDistr(SimSettings.getInstance().getTaskLookUpTable()[i][7]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Each mobile device utilizes an app type (task type)
|
||||||
|
for(int i=0; i<numberOfMobileDevices; i++) {
|
||||||
|
APP_TYPES randomTaskType = null;
|
||||||
|
double taskTypeSelector = SimUtils.getRandomDoubleNumber(0,100);
|
||||||
|
double taskTypePercentage = 0;
|
||||||
|
for (SimSettings.APP_TYPES taskType : SimSettings.APP_TYPES.values()) {
|
||||||
|
taskTypePercentage += SimSettings.getInstance().getTaskLookUpTable()[taskType.ordinal()][0];
|
||||||
|
if(taskTypeSelector <= taskTypePercentage){
|
||||||
|
randomTaskType = taskType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(randomTaskType == null){
|
||||||
|
SimLogger.printLine("Impossible is occured! no random task type!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double poissonMean = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType.ordinal()][2];
|
||||||
|
double activePeriod = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType.ordinal()][3];
|
||||||
|
double idlePeriod = SimSettings.getInstance().getTaskLookUpTable()[randomTaskType.ordinal()][4];
|
||||||
|
double activePeriodStartTime = SimUtils.getRandomDoubleNumber(10, 10+activePeriod); //start from 10th seconds
|
||||||
|
double virtualTime = activePeriodStartTime; //start from 10th seconds
|
||||||
|
|
||||||
|
ExponentialDistribution rng = new ExponentialDistribution(poissonMean);
|
||||||
|
while(virtualTime < simulationTime) {
|
||||||
|
double interval = rng.sample();
|
||||||
|
|
||||||
|
if(interval <= 0){
|
||||||
|
SimLogger.printLine("Impossible is occured! interval is " + interval + " for device " + i + " time " + virtualTime);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//SimLogger.printLine(virtualTime + " -> " + interval + " for device " + i + " time ");
|
||||||
|
virtualTime += interval;
|
||||||
|
|
||||||
|
if(virtualTime > activePeriodStartTime + activePeriod){
|
||||||
|
activePeriodStartTime = activePeriodStartTime + activePeriod + idlePeriod;
|
||||||
|
virtualTime = activePeriodStartTime;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean requireCloud = false;
|
||||||
|
if(simScenario != SimSettings.SCENARIO_TYPES.SINGLE_TIER){
|
||||||
|
//decide to use cloud or cloudlet VM
|
||||||
|
int CloudVmPicker = SimUtils.getRandomNumber(0, 100);
|
||||||
|
|
||||||
|
if(CloudVmPicker <= SimSettings.getInstance().getTaskLookUpTable()[randomTaskType.ordinal()][1])
|
||||||
|
requireCloud = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
taskList.add(new EdgeTask(i,randomTaskType, virtualTime, requireCloud, poissonRngList));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Load Generator Model
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* LoadGeneratorModel is an abstract class which is used for
|
||||||
|
* deciding task generation pattern via a task list. For those who
|
||||||
|
* wants to add a custom Load Generator Model to EdgeCloudSim should
|
||||||
|
* extend this class and provide a concreate instance via ScenarioFactory
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.task_generator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.utils.EdgeTask;
|
||||||
|
|
||||||
|
public abstract class LoadGeneratorModel {
|
||||||
|
protected List<EdgeTask> taskList;
|
||||||
|
protected int numberOfMobileDevices;
|
||||||
|
protected double simulationTime;
|
||||||
|
protected SimSettings.SCENARIO_TYPES simScenario;
|
||||||
|
|
||||||
|
public LoadGeneratorModel(int _numberOfMobileDevices, double _simulationTime, SimSettings.SCENARIO_TYPES _simScenario){
|
||||||
|
numberOfMobileDevices=_numberOfMobileDevices;
|
||||||
|
simulationTime=_simulationTime;
|
||||||
|
simScenario=_simScenario;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* each task has a virtual start time
|
||||||
|
* it will be used while generating task
|
||||||
|
*/
|
||||||
|
public List<EdgeTask> getTaskList() {
|
||||||
|
return taskList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* fill task list according to related task generation model
|
||||||
|
*/
|
||||||
|
public abstract void initializeModel();
|
||||||
|
}
|
36
src/edu/boun/edgecloudsim/utils/EdgeTask.java
Normal file
36
src/edu/boun/edgecloudsim/utils/EdgeTask.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - EdgeTask
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* A custom class used in Load Generator Model to store tasks information
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.utils;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings.APP_TYPES;
|
||||||
|
|
||||||
|
public class EdgeTask {
|
||||||
|
public APP_TYPES taskType;
|
||||||
|
public boolean requireCloud;
|
||||||
|
public double startTime;
|
||||||
|
public long length, inputFileSize, outputFileSize;
|
||||||
|
public int pesNumber;
|
||||||
|
public int mobileDeviceId;
|
||||||
|
|
||||||
|
public EdgeTask(int _mobileDeviceId, APP_TYPES _taskType, double _startTime, boolean _requireCloud, PoissonDistr[][] poissonRngList) {
|
||||||
|
mobileDeviceId=_mobileDeviceId;
|
||||||
|
requireCloud=_requireCloud;
|
||||||
|
startTime=_startTime;
|
||||||
|
taskType=_taskType;
|
||||||
|
|
||||||
|
inputFileSize = (long)poissonRngList[_taskType.ordinal()][0].sample();
|
||||||
|
outputFileSize =(long)poissonRngList[_taskType.ordinal()][1].sample();
|
||||||
|
length = (long)poissonRngList[_taskType.ordinal()][2].sample();
|
||||||
|
|
||||||
|
pesNumber = (int)SimSettings.getInstance().getTaskLookUpTable()[_taskType.ordinal()][8];
|
||||||
|
}
|
||||||
|
}
|
55
src/edu/boun/edgecloudsim/utils/Location.java
Normal file
55
src/edu/boun/edgecloudsim/utils/Location.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Location
|
||||||
|
*
|
||||||
|
* Description: Location class used in EdgeCloudSim
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.utils;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
|
||||||
|
public class Location {
|
||||||
|
private int xPos;
|
||||||
|
private int yPos;
|
||||||
|
private int servingWlanId;
|
||||||
|
SimSettings.PLACE_TYPES placeType;
|
||||||
|
public Location(SimSettings.PLACE_TYPES _placeType, int _servingWlanId, int _xPos, int _yPos){
|
||||||
|
servingWlanId = _servingWlanId;
|
||||||
|
placeType=_placeType;
|
||||||
|
xPos = _xPos;
|
||||||
|
yPos = _yPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other){
|
||||||
|
boolean result = false;
|
||||||
|
if (other == null) return false;
|
||||||
|
if (!(other instanceof Location))return false;
|
||||||
|
if (other == this) return true;
|
||||||
|
|
||||||
|
Location otherLocation = (Location)other;
|
||||||
|
if(this.xPos == otherLocation.xPos && this.yPos == otherLocation.yPos)
|
||||||
|
result = true;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getServingWlanId(){
|
||||||
|
return servingWlanId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimSettings.PLACE_TYPES getPlaceType(){
|
||||||
|
return placeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getXPos(){
|
||||||
|
return xPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYPos(){
|
||||||
|
return yPos;
|
||||||
|
}
|
||||||
|
}
|
63
src/edu/boun/edgecloudsim/utils/PoissonDistr.java
Normal file
63
src/edu/boun/edgecloudsim/utils/PoissonDistr.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Poisson Distribution
|
||||||
|
*
|
||||||
|
* Description: Poisson Distribution implementation
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.utils;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class PoissonDistr {
|
||||||
|
/** The num gen. */
|
||||||
|
private final Random numGen;
|
||||||
|
|
||||||
|
/** The mean. */
|
||||||
|
private final double mean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new exponential number generator.
|
||||||
|
*
|
||||||
|
* @param seed the seed to be used.
|
||||||
|
* @param mean the mean for the distribution.
|
||||||
|
*/
|
||||||
|
public PoissonDistr(long seed, double mean) {
|
||||||
|
if (mean <= 0.0) {
|
||||||
|
throw new IllegalArgumentException("Mean must be greater than 0.0");
|
||||||
|
}
|
||||||
|
numGen = new Random(seed);
|
||||||
|
this.mean = mean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new exponential number generator.
|
||||||
|
*
|
||||||
|
* @param mean the mean for the distribution.
|
||||||
|
*/
|
||||||
|
public PoissonDistr(double mean) {
|
||||||
|
if (mean <= 0.0) {
|
||||||
|
throw new IllegalArgumentException("Mean must be greated than 0.0");
|
||||||
|
}
|
||||||
|
numGen = new Random(System.currentTimeMillis());
|
||||||
|
this.mean = mean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new random number.
|
||||||
|
*
|
||||||
|
* @return the next random number in the sequence
|
||||||
|
*/
|
||||||
|
public double sample() {
|
||||||
|
double L = Math.exp(-mean);
|
||||||
|
int k = 0;
|
||||||
|
double p = 1.0;
|
||||||
|
do {
|
||||||
|
p = p * numGen.nextDouble();
|
||||||
|
k++;
|
||||||
|
} while (p > L);
|
||||||
|
return k - 1;
|
||||||
|
}
|
||||||
|
}
|
467
src/edu/boun/edgecloudsim/utils/SimLogger.java
Normal file
467
src/edu/boun/edgecloudsim/utils/SimLogger.java
Normal file
@ -0,0 +1,467 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Simulation Logger
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* SimLogger is responsible for storing simulation events/results
|
||||||
|
* in to the files in a specific format.
|
||||||
|
* Format is decided in a way to use results in matlab efficiently.
|
||||||
|
* If you need more results or another file format, you should modify
|
||||||
|
* this class.
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.utils;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimManager;
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
|
||||||
|
public class SimLogger {
|
||||||
|
public static enum TASK_STATUS {CREATED,
|
||||||
|
UPLOADING,
|
||||||
|
PROCESSING,
|
||||||
|
DOWNLOADING,
|
||||||
|
COMLETED,
|
||||||
|
REJECTED_DUE_TO_VM_CAPACITY,
|
||||||
|
REJECTED_DUE_TO_BANDWIDTH,
|
||||||
|
UNFINISHED_DUE_TO_BANDWIDTH,
|
||||||
|
UNFINISHED_DUE_TO_MOBILITY
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean fileLogEnabled;
|
||||||
|
private static boolean printLogEnabled;
|
||||||
|
private String filePrefix;
|
||||||
|
private String outputFolder;
|
||||||
|
private Map<Integer, LogItem> taskMap;
|
||||||
|
private LinkedList<VmLoadLogItem> vmLoadList;
|
||||||
|
|
||||||
|
private static SimLogger singleton = new SimLogger( );
|
||||||
|
|
||||||
|
/* A private Constructor prevents any other
|
||||||
|
* class from instantiating.
|
||||||
|
*/
|
||||||
|
private SimLogger(){
|
||||||
|
fileLogEnabled = false;
|
||||||
|
printLogEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Static 'instance' method */
|
||||||
|
public static SimLogger getInstance( ) {
|
||||||
|
return singleton;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enableFileLog() {
|
||||||
|
fileLogEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enablePrintLog() {
|
||||||
|
printLogEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFileLogEnabled() {
|
||||||
|
return fileLogEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disablePrintLog() {
|
||||||
|
printLogEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendToFile(BufferedWriter bw, String line) throws IOException{
|
||||||
|
bw.write(line);
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void printLine(String msg){
|
||||||
|
if(printLogEnabled)
|
||||||
|
System.out.println(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void print(String msg){
|
||||||
|
if(printLogEnabled)
|
||||||
|
System.out.print(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void simStarted(String outFolder,String fileName) {
|
||||||
|
filePrefix = fileName;
|
||||||
|
outputFolder = outFolder;
|
||||||
|
taskMap = new HashMap<Integer, LogItem>();
|
||||||
|
vmLoadList = new LinkedList<VmLoadLogItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLog(double taskStartTime, int taskId, int taskType, int taskLenght, int taskInputType, int taskOutputSize) {
|
||||||
|
//printLine(taskId+"->"+taskStartTime);
|
||||||
|
taskMap.put(taskId, new LogItem(taskStartTime, taskType, taskLenght, taskInputType, taskOutputSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void uploadStarted(int taskId, double taskUploadTime) {
|
||||||
|
taskMap.get(taskId).taskUploadStarted(taskUploadTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void uploaded(int taskId, int datacenterId, int hostId, int vmId, int vmType) {
|
||||||
|
taskMap.get(taskId).taskUploaded(datacenterId, hostId, vmId,vmType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void downloadStarted(int taskId, double taskDownloadTime) {
|
||||||
|
taskMap.get(taskId).taskDownloadStarted(taskDownloadTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void downloaded(int taskId, double taskEndTime) {
|
||||||
|
taskMap.get(taskId).taskDownloaded(taskEndTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rejectedDueToVMCapacity(int taskId, double taskRejectTime) {
|
||||||
|
taskMap.get(taskId).taskRejectedDueToVMCapacity(taskRejectTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rejectedDueToBandwidth(int taskId, double taskRejectTime) {
|
||||||
|
taskMap.get(taskId).taskRejectedDueToBandwidth(taskRejectTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void failedDueToBandwidth(int taskId, double taskRejectTime) {
|
||||||
|
taskMap.get(taskId).taskFailedDueToBandwidth(taskRejectTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void failedDueToMobility(int taskId, double time) {
|
||||||
|
taskMap.get(taskId).taskFailedDueToMobility(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addVmUtilizationLog(double time, double load) {
|
||||||
|
vmLoadList.add(new VmLoadLogItem(time, load));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void simStopped() throws IOException {
|
||||||
|
File file1=null,file2=null,file3=null,file4=null,file5=null;
|
||||||
|
FileWriter fileWriter1=null,fileWriter2=null,fileWriter3=null,fileWriter4=null,fileWriter5=null;
|
||||||
|
BufferedWriter bufferedWriter1=null,bufferedWriter2=null,bufferedWriter3=null,bufferedWriter4=null,bufferedWriter5=null;
|
||||||
|
|
||||||
|
int uncompletedTaskOnCloudlet = 0;
|
||||||
|
int completedTaskOnCloudlet = 0;
|
||||||
|
int uncompletedTaskOnCloud = 0;
|
||||||
|
int completedTaskOnCloud = 0;
|
||||||
|
int rejectedTaskDoToVmCapacity = 0;
|
||||||
|
int rejectedTaskDoToBandwidth = 0;
|
||||||
|
int failedTaskDuetoBandwidth = 0;
|
||||||
|
int failedTaskDuetoMobility = 0;
|
||||||
|
int totalCompletedTask = 0;
|
||||||
|
int totalFailedTask = 0;
|
||||||
|
double totalCost = 0;
|
||||||
|
double totalLanDelay = 0;
|
||||||
|
double totalWanDelay = 0;
|
||||||
|
double totalServiceTime = 0;
|
||||||
|
double totalNetworkDelay = 0;
|
||||||
|
double totalProcessingTime = 0;
|
||||||
|
double totalVmLoad = 0;
|
||||||
|
|
||||||
|
//open all files and prepare them for write
|
||||||
|
if(fileLogEnabled){
|
||||||
|
if(SimSettings.getInstance().getDeepFileLoggingEnabled()){
|
||||||
|
file1 = new File(outputFolder, filePrefix+"_SUCCESS.log");
|
||||||
|
fileWriter1 = new FileWriter(file1, true);
|
||||||
|
bufferedWriter1 = new BufferedWriter(fileWriter1);
|
||||||
|
|
||||||
|
file2 = new File(outputFolder, filePrefix+"_FAIL.log");
|
||||||
|
fileWriter2 = new FileWriter(file2, true);
|
||||||
|
bufferedWriter2 = new BufferedWriter(fileWriter2);
|
||||||
|
}
|
||||||
|
|
||||||
|
file3 = new File(outputFolder, filePrefix+"_VM_LOAD.log");
|
||||||
|
fileWriter3 = new FileWriter(file3, true);
|
||||||
|
bufferedWriter3 = new BufferedWriter(fileWriter3);
|
||||||
|
|
||||||
|
file4 = new File(outputFolder, filePrefix+"_GENERIC.log");
|
||||||
|
fileWriter4 = new FileWriter(file4, true);
|
||||||
|
bufferedWriter4 = new BufferedWriter(fileWriter4);
|
||||||
|
|
||||||
|
file5 = new File(outputFolder, filePrefix+"_LOCATION.log");
|
||||||
|
fileWriter5 = new FileWriter(file5, true);
|
||||||
|
bufferedWriter5 = new BufferedWriter(fileWriter5);
|
||||||
|
|
||||||
|
if(SimSettings.getInstance().getDeepFileLoggingEnabled()){
|
||||||
|
appendToFile(bufferedWriter1, "# taskId;dataCenterId;hostId;vmId;vmType;taskType;taskLenght;taskInputType;taskOutputSize;taskStartTime;taskEndTime;nwDelay");
|
||||||
|
appendToFile(bufferedWriter2, "# taskId;dataCenterId;hostId;vmId;vmType;taskType;taskLenght;taskInputType;taskOutputSize;taskStartTime;taskEndTime;failReason");
|
||||||
|
}
|
||||||
|
|
||||||
|
appendToFile(bufferedWriter3, "# time;load");
|
||||||
|
appendToFile(bufferedWriter4, "# completedTask;uncompletedTask;rejectedTask;failedDueToMobilityTask;avgFailure;avgServiceTime;avgNetworkDelay;avgServerLoad;avgCost");
|
||||||
|
appendToFile(bufferedWriter5, "# time;#ofClient@PlaceType1;#ofClient@PlaceTypen");
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract the result of each task and write it to the file if required
|
||||||
|
for (Map.Entry<Integer, LogItem> entry : taskMap.entrySet()) {
|
||||||
|
Integer key = entry.getKey();
|
||||||
|
LogItem value = entry.getValue();
|
||||||
|
|
||||||
|
if(value.isInWarmUpPeriod())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(value.getStatus() == SimLogger.TASK_STATUS.COMLETED){
|
||||||
|
if(value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal()){
|
||||||
|
completedTaskOnCloud++;
|
||||||
|
totalWanDelay += value.getNetworkDelay();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
completedTaskOnCloudlet++;
|
||||||
|
totalLanDelay += value.getNetworkDelay();
|
||||||
|
}
|
||||||
|
totalCost += value.getCost();
|
||||||
|
totalServiceTime += value.getServiceTime();
|
||||||
|
totalNetworkDelay += value.getNetworkDelay();
|
||||||
|
totalProcessingTime += (value.getServiceTime() - value.getNetworkDelay());
|
||||||
|
|
||||||
|
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
|
||||||
|
appendToFile(bufferedWriter1, value.toString(key));
|
||||||
|
}
|
||||||
|
else if(value.getStatus() == SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY){
|
||||||
|
rejectedTaskDoToVmCapacity++;
|
||||||
|
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
|
||||||
|
appendToFile(bufferedWriter2, value.toString(key));
|
||||||
|
}
|
||||||
|
else if(value.getStatus() == SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH){
|
||||||
|
rejectedTaskDoToBandwidth++;
|
||||||
|
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
|
||||||
|
appendToFile(bufferedWriter2, value.toString(key));
|
||||||
|
}
|
||||||
|
else if(value.getStatus() == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH){
|
||||||
|
failedTaskDuetoBandwidth++;
|
||||||
|
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
|
||||||
|
appendToFile(bufferedWriter2, value.toString(key));
|
||||||
|
}
|
||||||
|
else if(value.getStatus() == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY){
|
||||||
|
failedTaskDuetoMobility++;
|
||||||
|
if(fileLogEnabled && SimSettings.getInstance().getDeepFileLoggingEnabled())
|
||||||
|
appendToFile(bufferedWriter2, value.toString(key));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(value.getVmType() == SimSettings.VM_TYPES.CLOUD_VM.ordinal())
|
||||||
|
uncompletedTaskOnCloud++;
|
||||||
|
else
|
||||||
|
uncompletedTaskOnCloudlet++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalFailedTask = rejectedTaskDoToVmCapacity+rejectedTaskDoToBandwidth+failedTaskDuetoBandwidth;
|
||||||
|
totalCompletedTask = completedTaskOnCloudlet+completedTaskOnCloud;
|
||||||
|
|
||||||
|
//calculate server load
|
||||||
|
for(VmLoadLogItem entry : vmLoadList){
|
||||||
|
totalVmLoad += entry.getLoad();
|
||||||
|
if(fileLogEnabled)
|
||||||
|
appendToFile(bufferedWriter3, entry.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fileLogEnabled){
|
||||||
|
//write location info to file
|
||||||
|
for(int t=1; t<(SimSettings.getInstance().getSimulationTime()/SimSettings.getInstance().getVmLocationLogInterval()); t++){
|
||||||
|
int[] locationInfo = new int[SimSettings.PLACE_TYPES.values().length];
|
||||||
|
for(int i=0; i<SimManager.getInstance().getNumOfMobileDevice(); i++) {
|
||||||
|
|
||||||
|
Location loc = SimManager.getInstance().getMobilityModel().getLocation(i, t*SimSettings.getInstance().getVmLocationLogInterval());
|
||||||
|
SimSettings.PLACE_TYPES placeType = loc.getPlaceType();
|
||||||
|
locationInfo[placeType.ordinal()]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Double time=t*SimSettings.getInstance().getVmLocationLogInterval();
|
||||||
|
bufferedWriter5.write(time.toString());
|
||||||
|
for(int i=0; i<locationInfo.length; i++)
|
||||||
|
bufferedWriter5.write(SimSettings.DELIMITER + locationInfo[i]);
|
||||||
|
|
||||||
|
bufferedWriter5.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
//write generic results
|
||||||
|
String genericResult = Integer.toString(completedTaskOnCloudlet) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(uncompletedTaskOnCloudlet) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(completedTaskOnCloud) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(uncompletedTaskOnCloud) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(rejectedTaskDoToVmCapacity) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(rejectedTaskDoToBandwidth) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(failedTaskDuetoBandwidth) + SimSettings.DELIMITER +
|
||||||
|
Integer.toString(failedTaskDuetoMobility) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(((double)totalFailedTask*(double)100)/(double)(totalCompletedTask+totalFailedTask)) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalServiceTime/(double)totalCompletedTask) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalNetworkDelay/(double)totalCompletedTask) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalLanDelay/(double)totalCompletedTask) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalWanDelay/(double)totalCompletedTask) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalProcessingTime/(double)totalCompletedTask) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalVmLoad/(double)vmLoadList.size()) + SimSettings.DELIMITER +
|
||||||
|
Double.toString(totalCost/(double)totalCompletedTask);
|
||||||
|
|
||||||
|
appendToFile(bufferedWriter4,genericResult);
|
||||||
|
|
||||||
|
//close open files
|
||||||
|
if(SimSettings.getInstance().getDeepFileLoggingEnabled()){
|
||||||
|
bufferedWriter1.close();
|
||||||
|
bufferedWriter2.close();
|
||||||
|
}
|
||||||
|
bufferedWriter3.close();
|
||||||
|
bufferedWriter4.close();
|
||||||
|
bufferedWriter5.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//printout important results
|
||||||
|
printLine("# of uncompleted tasks on Cloudlet/Cloud: " + uncompletedTaskOnCloudlet + "/" + uncompletedTaskOnCloud);
|
||||||
|
printLine("# of completed task on Cloudlet/Cloud: " + (completedTaskOnCloudlet+uncompletedTaskOnCloudlet) + "/" + (completedTaskOnCloud+uncompletedTaskOnCloud));
|
||||||
|
printLine("# of rejected tasks (due to vm capacity): " + rejectedTaskDoToVmCapacity);
|
||||||
|
printLine("# of rejected tasks (due to bandwidth): " + rejectedTaskDoToBandwidth);
|
||||||
|
printLine("# of failed tasks (due to bandwidth): " + failedTaskDuetoBandwidth);
|
||||||
|
printLine("# of failed tasks (due to mobility): " + failedTaskDuetoMobility);
|
||||||
|
printLine("percentage of failed task: " + String.format("%.6f", ((double)totalFailedTask*(double)100)/(double)(totalCompletedTask+totalFailedTask)) + "%");
|
||||||
|
printLine("average service time: " + String.format("%.6f", totalServiceTime/(double)totalCompletedTask) + " seconds. ("
|
||||||
|
+ "processing time: " + String.format("%.6f", totalProcessingTime/(double)totalCompletedTask) + ")");
|
||||||
|
printLine("average netwrok delay: " + String.format("%.6f", totalNetworkDelay/(double)totalCompletedTask) + " seconds. ("
|
||||||
|
+ "LAN delay: " + String.format("%.6f", totalLanDelay/(double)totalCompletedTask) + ", "
|
||||||
|
+ "WAN delay: " + String.format("%.6f", totalWanDelay/(double)totalCompletedTask) + ")");
|
||||||
|
printLine("average server utilization: " + String.format("%.6f", totalVmLoad/(double)vmLoadList.size()) + "%");
|
||||||
|
printLine("average cost: " + totalCost/totalCompletedTask + "$");
|
||||||
|
|
||||||
|
//clear related collections (map list etc.)
|
||||||
|
taskMap.clear();
|
||||||
|
vmLoadList.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class VmLoadLogItem
|
||||||
|
{
|
||||||
|
private double time;
|
||||||
|
private double vmLoad;
|
||||||
|
|
||||||
|
VmLoadLogItem(double _time, double _vmLoad)
|
||||||
|
{
|
||||||
|
time = _time;
|
||||||
|
vmLoad = _vmLoad;
|
||||||
|
}
|
||||||
|
public double getLoad()
|
||||||
|
{
|
||||||
|
return vmLoad;
|
||||||
|
}
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return time + SimSettings.DELIMITER + vmLoad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class LogItem
|
||||||
|
{
|
||||||
|
private SimLogger.TASK_STATUS status;
|
||||||
|
private int datacenterId;
|
||||||
|
private int hostId;
|
||||||
|
private int vmId;
|
||||||
|
private int vmType;
|
||||||
|
private int taskType;
|
||||||
|
private int taskLenght;
|
||||||
|
private int taskInputType;
|
||||||
|
private int taskOutputSize;
|
||||||
|
private double taskStartTime;
|
||||||
|
private double taskEndTime;
|
||||||
|
private double networkDelay;
|
||||||
|
private double bwCost;
|
||||||
|
private double cpuCost;
|
||||||
|
private boolean isInWarmUpPeriod;
|
||||||
|
LogItem (double _taskStartTime, int _taskType, int _taskLenght, int _taskInputType, int _taskOutputSize)
|
||||||
|
{
|
||||||
|
taskStartTime = _taskStartTime;
|
||||||
|
taskType=_taskType;
|
||||||
|
taskLenght=_taskLenght;
|
||||||
|
taskInputType=_taskInputType;
|
||||||
|
taskOutputSize=_taskOutputSize;
|
||||||
|
status = SimLogger.TASK_STATUS.CREATED;
|
||||||
|
taskEndTime = 0;
|
||||||
|
|
||||||
|
if(_taskStartTime < SimSettings.getInstance().getWarmUpPeriod())
|
||||||
|
isInWarmUpPeriod = true;
|
||||||
|
else
|
||||||
|
isInWarmUpPeriod = false;
|
||||||
|
}
|
||||||
|
public void taskUploadStarted(double taskUploadTime) {
|
||||||
|
networkDelay += taskUploadTime;
|
||||||
|
status = SimLogger.TASK_STATUS.UPLOADING;
|
||||||
|
}
|
||||||
|
public void taskUploaded(int _datacenterId, int _hostId, int _vmId, int _vmType) {
|
||||||
|
status = SimLogger.TASK_STATUS.PROCESSING;
|
||||||
|
datacenterId = _datacenterId;
|
||||||
|
hostId = _hostId;
|
||||||
|
vmId = _vmId;
|
||||||
|
vmType=_vmType;
|
||||||
|
}
|
||||||
|
public void taskDownloadStarted(double taskDownloadTime) {
|
||||||
|
networkDelay += taskDownloadTime;
|
||||||
|
status = SimLogger.TASK_STATUS.DOWNLOADING;
|
||||||
|
}
|
||||||
|
public void taskDownloaded(double _taskEndTime) {
|
||||||
|
taskEndTime = _taskEndTime;
|
||||||
|
status = SimLogger.TASK_STATUS.COMLETED;
|
||||||
|
}
|
||||||
|
public void taskRejectedDueToVMCapacity(double _taskRejectTime) {
|
||||||
|
taskEndTime = _taskRejectTime;
|
||||||
|
status = SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY;
|
||||||
|
}
|
||||||
|
public void taskRejectedDueToBandwidth(double _taskRejectTime) {
|
||||||
|
taskEndTime = _taskRejectTime;
|
||||||
|
status = SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH;
|
||||||
|
}
|
||||||
|
public void taskFailedDueToBandwidth(double _time) {
|
||||||
|
taskEndTime = _time;
|
||||||
|
status = SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH;
|
||||||
|
}
|
||||||
|
public void taskFailedDueToMobility(double _time) {
|
||||||
|
taskEndTime = _time;
|
||||||
|
status = SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY;
|
||||||
|
}
|
||||||
|
public void setCost(double _bwCost, double _cpuCos) {
|
||||||
|
bwCost = _bwCost;
|
||||||
|
cpuCost = _cpuCos;
|
||||||
|
}
|
||||||
|
public boolean isInWarmUpPeriod(){
|
||||||
|
return isInWarmUpPeriod;
|
||||||
|
}
|
||||||
|
public double getCost() {
|
||||||
|
return bwCost + cpuCost;
|
||||||
|
}
|
||||||
|
public double getNetworkDelay() {
|
||||||
|
return networkDelay;
|
||||||
|
}
|
||||||
|
public double getServiceTime() {
|
||||||
|
return taskEndTime - taskStartTime;
|
||||||
|
}
|
||||||
|
public SimLogger.TASK_STATUS getStatus(){
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
public int getVmType(){
|
||||||
|
return vmType;
|
||||||
|
}
|
||||||
|
public String toString (int taskId)
|
||||||
|
{
|
||||||
|
String result = taskId + SimSettings.DELIMITER +
|
||||||
|
datacenterId + SimSettings.DELIMITER +
|
||||||
|
hostId + SimSettings.DELIMITER +
|
||||||
|
vmId + SimSettings.DELIMITER +
|
||||||
|
vmType + SimSettings.DELIMITER +
|
||||||
|
taskType + SimSettings.DELIMITER +
|
||||||
|
taskLenght + SimSettings.DELIMITER +
|
||||||
|
taskInputType + SimSettings.DELIMITER +
|
||||||
|
taskOutputSize + SimSettings.DELIMITER +
|
||||||
|
taskStartTime + SimSettings.DELIMITER +
|
||||||
|
taskEndTime + SimSettings.DELIMITER;
|
||||||
|
|
||||||
|
if(status == SimLogger.TASK_STATUS.COMLETED)
|
||||||
|
result += networkDelay;
|
||||||
|
else if(status == SimLogger.TASK_STATUS.REJECTED_DUE_TO_VM_CAPACITY)
|
||||||
|
result +="1"; //failure reason 1
|
||||||
|
else if(status == SimLogger.TASK_STATUS.REJECTED_DUE_TO_BANDWIDTH)
|
||||||
|
result +="2"; //failure reason 2
|
||||||
|
else if(status == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_BANDWIDTH)
|
||||||
|
result +="3"; //failure reason 3
|
||||||
|
else if(status == SimLogger.TASK_STATUS.UNFINISHED_DUE_TO_MOBILITY)
|
||||||
|
result +="4"; //failure reason 4
|
||||||
|
else
|
||||||
|
result +="0"; //default failure reason
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
103
src/edu/boun/edgecloudsim/utils/SimUtils.java
Normal file
103
src/edu/boun/edgecloudsim/utils/SimUtils.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Title: EdgeCloudSim - Simulation Utils
|
||||||
|
*
|
||||||
|
* Description: Utility class providing helper functions
|
||||||
|
*
|
||||||
|
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
|
||||||
|
* Copyright (c) 2017, Bogazici University, Istanbul, Turkey
|
||||||
|
*/
|
||||||
|
|
||||||
|
package edu.boun.edgecloudsim.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import edu.boun.edgecloudsim.core.SimSettings;
|
||||||
|
|
||||||
|
public class SimUtils {
|
||||||
|
|
||||||
|
public static final Random RNG = new Random(System.currentTimeMillis());
|
||||||
|
|
||||||
|
public static int getRandomNumber(int start, int end) {
|
||||||
|
//return pd.sample();
|
||||||
|
long range = (long)end - (long)start + 1;
|
||||||
|
long fraction = (long)(range * RNG.nextDouble());
|
||||||
|
return (int)(fraction + start);
|
||||||
|
}
|
||||||
|
public static double getRandomDoubleNumber(double start, double end) {
|
||||||
|
//return pd.sample();
|
||||||
|
double range = end - start;
|
||||||
|
double fraction = (range * RNG.nextDouble());
|
||||||
|
return (fraction + start);
|
||||||
|
}
|
||||||
|
public static long getRandomLongNumber(int start, int end) {
|
||||||
|
//return pd.sample();
|
||||||
|
long range = (long)end - (long)start + 1;
|
||||||
|
long fraction = (long)(range * RNG.nextDouble());
|
||||||
|
return (fraction + start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cleanOutputFolder(String outputFolder){
|
||||||
|
//clean the folder where the result files will be saved
|
||||||
|
File dir = new File(outputFolder);
|
||||||
|
if(dir.exists() && dir.isDirectory())
|
||||||
|
{
|
||||||
|
for (File f: dir.listFiles())
|
||||||
|
{
|
||||||
|
if (f.exists() && f.isFile())
|
||||||
|
{
|
||||||
|
if(!f.delete())
|
||||||
|
{
|
||||||
|
SimLogger.printLine("file cannot be cleared: " + f.getAbsolutePath());
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SimLogger.printLine("Output folder is not available: " + outputFolder);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String getTimeDifference(Date startDate, Date endDate){
|
||||||
|
String result = "";
|
||||||
|
long duration = endDate.getTime() - startDate.getTime();
|
||||||
|
|
||||||
|
long diffInMilli = TimeUnit.MILLISECONDS.toMillis(duration);
|
||||||
|
long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
|
||||||
|
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration);
|
||||||
|
long diffInHours = TimeUnit.MILLISECONDS.toHours(duration);
|
||||||
|
long diffInDays = TimeUnit.MILLISECONDS.toDays(duration);
|
||||||
|
|
||||||
|
if(diffInDays>0)
|
||||||
|
result += diffInDays + ((diffInDays>1 == true) ? " Days " : " Day ");
|
||||||
|
if(diffInHours>0)
|
||||||
|
result += diffInHours % 24 + ((diffInHours>1 == true) ? " Hours " : " Hour ");
|
||||||
|
if(diffInMinutes>0)
|
||||||
|
result += diffInMinutes % 60 + ((diffInMinutes>1 == true) ? " Minutes " : " Minute ");
|
||||||
|
if(diffInSeconds>0)
|
||||||
|
result += diffInSeconds % 60 + ((diffInSeconds>1 == true) ? " Seconds" : " Second");
|
||||||
|
if(diffInMilli>0 && result.isEmpty())
|
||||||
|
result += diffInMilli + ((diffInMilli>1 == true) ? " Milli Seconds" : " Milli Second");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SimSettings.PLACE_TYPES stringToPlace(String attractiveness){
|
||||||
|
SimSettings.PLACE_TYPES placeType = null;
|
||||||
|
if(attractiveness.equals("1"))
|
||||||
|
placeType = SimSettings.PLACE_TYPES.ATTRACTIVENESS_L1;
|
||||||
|
else if(attractiveness.equals("2"))
|
||||||
|
placeType = SimSettings.PLACE_TYPES.ATTRACTIVENESS_L2;
|
||||||
|
else if(attractiveness.equals("3"))
|
||||||
|
placeType = SimSettings.PLACE_TYPES.ATTRACTIVENESS_L3;
|
||||||
|
else{
|
||||||
|
SimLogger.printLine("Unknown attractiveness level! Terminating simulation...");
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return placeType;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user