iFogsim Project Structure: A Beginners Guide

ifogsim Topology File

The Internet of Things (IoT) provides a broad range of services for the end-users using efficient endpoints for application delivery. IoT is still very early as the large-scale infrastructure is yet to be developed. There have been a lot of new research topics that are emerging based, especially in scheduling, power, and network load distribution.

Testing such use cases is difficult in the absence of a suitable infrastructure. Therefore iFogSim simulator possesses a huge potential to simulate the research-based use case and then, corresponding to the promising results, can be deployed to the existing system with minimum cost and effort involved.

This article will serve as a guide to understanding the iFogSim project structure API.

What is iFogsim?

iFogSim is a Java programming language-based API that inherits the established API of Cloudsim to manage its underlying discrete event-based simulation. It also utilizes the API of CloudsimSDN for relevant network-related workload handling.

Before we implement any use case in iFogsim, we must first be able to understand its project structure.

This article will enable you to choose the correct namespace for the implementation of our use case as well as any modifications to existing code to simulate the use case effectively. 

Let’s get started…

The iFogSim project contains 7 folders and 1 text file. Following is the default view of the iFogsim project:

iFogSim Project Structure
iFogSim Project Structure

Here is the description provided in the sequence as they appear in iFogsim Project Structure,

JRE System Library

This folder contains the default libraries required for the execution of the iFogsim simulation.

iFogSim default imports - iFogSim Project Structure
iFogSim default imports

Src

This folder contains the complete set of Java code files that are arranged in the form of namespaces. Among this, the first 11 packages are being included from the core cloudsim API.  You can read in detail about this set of namespaces from the article “Beginners Guide to Cloudsim Project Structure.

Cloudsim API namespaces included in iFogsim project structure
Cloudsim API namespaces included in iFogsim

Then, the next 10 packages are being included from the CloudsimSDN API 

CloudsimSDN API namespaces included in iFogsim project structure
CloudsimSDN API namespaces included in iFogsim

Then brings in the actual packages for the iFogSim model API; there are 13 packages and a topologies package containing the layout for a router. This set of API namespaces will contain the actual implementation of the related fog computing-based models and policy implementations.

iFogsim API namespaces - iFogSim Project Structure
iFogsim API namespaces

Referenced Libraries

The folder contains the set of additional JAR libraries that are required for the execution of the iFogsim simulation. This includes the Cloudsim source as well as the examples jar. Apaches common math library, JSON processing, etc.

Additional reference JAR libraries included in iFogsim project structure
Additional reference JAR libraries included in iFogsim

Jars: The folder contains the actual JAR files of all the libraries mentioned in point no. 3.

Output folder

In case if you opt to record the put the simulations console output inside a file, then it will be stored in this folder.

iFogsim Output log files from the console for a simulation.
iFogsim Output log files from the console for a simulation.

Results folder

The tested simulator results are recorded as Excel/Openoffice/PDF/Text file and saved in this folder. One interesting thing that the programmer has done is that the charts corresponding to the results were also generated for quick analysis. This is great if you are doing the simulation to produce some results for the research paper.

iFogsim simulated use-case result files including diagrams
iFogsim simulated use-case result files including diagrams

Topologies

This contains the network layout for any given use case to be simulated using the iFogSim. The format used for saving the layout is JSON based and is utilized by the simulation engine to define the infrastructure for the test simulation.

ifogsim Topology File
ifogsim Topology File

README.md

This file contains the basic introduction regarding the iFogsim project along with the reference link to the Github project page as well as the research references.

What’s next?

We have been working on a tutorial course titled “Essential iFogsim Tutorials,” which currently contains over 2 hours of video content for beginner-level researchers; this course will be a work in progress based on the feedback from its subscribers. We have committed ourselves to updating its content until August 2023. I look forward to catching you on the course page.

Virtual machine migration in Cloudsim

Efficient Virtual Machine migration is the primary task that a researcher considers while framing her research problem. And one of the most haunting tasks is to simulate the proposed algorithm using a cloudsim simulation toolkit.

This article will broadly discuss the basics of virtual machine migration, initial virtual machine allocation to hosts, and then how this initial virtual machine allocation is optimized using specific migration strategies. Throughout the article, I have referred to a couple of important methods(functions) that you should check side by side for better understanding. Now if you have not installed/setup the cloudsim on your computer then you should first follow this step by step guide.

Sequence to allocate a Virtual machine to the simulated host in cloudsim

At the start of the cloudsim simulation scenario, first, the configuration details of the Virtual Machine(VM) and cloudlets are defined and submitted to the DatacenterBroker instance. Now, once the Datacentre instance is up and running in the simulation, the DatacenterBroker instance requests the Datacentre instance to create a virtual machine and allocate it to the desired host. For this, the DatacenterBroker initiates the event using 

CloudSimTags.VM_CREATE_ACK

from the method “createVMInDatacentre()” , where DatacentreID passed as a parameter.

Now, once the Datacentre is processing, its assigned events and reaches the event call assigned by the DatacentreBroker. Then, it allocates the virtual machines through the “processVMCreate()” method, which intern recognizes the attached Virtual Machine allocation policy and utilizes the “allocateHostForVM()” method and sends an acknowledgment to the DatacentreBroker.

Now, let us consider two different scenarios

  1. If there is a need to map a particular virtual machine to a specific Datacenter, then the method createVMInDatacentre() (defined inside DatacentreBroker) logic is required to be changed as per the need of the scenario. For example, the situation related to the federated Datacentre or failsafe region-based replication. OR
  2. If there is a requirement for managing the adequate host resource utilization corresponding to the virtual machine to host mapping, then “allocateHostForVM()” method from Datacenter class is required to implement the necessary logic. For this already, a scenario is included in “org.cloudbus.cloudsim.power” packages like “PowerVMAllocationPolicyAbstract” and “VMAllocationPolicysimple“.

Sequence to initiate the VM Migration in cloudsim simulation

Datacentres are responsible for the execution of the workloads, and in cloudsim simulation, the cloudlet is considered as workload; therefore, primarily cloudlet processing performed at every cycle of entity(Datacenter, DatacenterBroker, etc.)event processing which in turn update the VM processing metrics through the host. 

The Datacentre instance utilizes the “updateCloudedProcessing()” method for the progress of the simulation run cycle.

Now, because this cloudlet processing cycle is the primary driving force for simulation; therefore, the power-aware package implements the VM utilization checks between these events only.

 There is a method named as “optimizeAllocation()” whose implementation is in PowerVMAllocationPolicyMigrationAbstract.Java. This method accepts the list of active VMs and performs the following steps in sequence:

  1.  Get the list of all the over-utilized hosts as per the threshold (w.r.t.) The VM allocation policy used.
  2. The list of all over-utilized hosts, along with its utilization metrics, are printed on the console.
  3. Identify the list of virtual machines to be migrated from the over-utilized host, but before doing this, the system takes a backup of the current VM to host mappings.
  4. A VM placement/allocation mapping to a new suitable host identified and kept in a temporary migration map. During this phase, the search space for a suitable host excludes already identified, overloaded hosts.
  5. Now the hosts, which are underutilized(utilization below 1%), are also identified to move their virtual machines. It is done to reduce power consumption by idle server machines. Now to reduce the search space overutilized, switched off(previously underutilized) and hosts identified in step 4 are excluded, and the list of VMs from these hosts also marked for migration
  6. And, finally, the final migration map is prepared, and the current allocation is restored to continue the simulation.

Now Once the migration map is final and is available to Datacentre, then the “updateCloudletProcessing()” method call gets to utilize the migration map. And, for each new VM to host mapping from migration map is scheduled as a new event for the current Datacentre instance with event tag as

CloudSimTags.VM_MIGRATE.

This event will also consider an added network delay calculated based on the available network bandwidth, and further cloudlet processing event gets rescheduled. 

This event is then further processed in the next simulation cycle of the cloudsim simulation engine through the “processVMMigrate()” method available in Datacentre.Java class.

In this following steps are followed:

  1.  Location of VM from the current host.
  2. Allocation of VM to the identified suitable host performed, and if acknowledgment is requested, then an acknowledgment is scheduled. Otherwise, confirmation of migration gets printed on the console.

 So, overall in every cycle of the simulation run, the Cloudsim simulator performs intense calculations to determine the right migration map to optimize the overall allocation of virtual machines to hosts. 

Now, to implement your appropriate Virtual Machine allocation and selection policy, you may consider the study of the proper VM allocation and selection policies available in “org.cloudbus.cloudsim.power” package. 

Now, In case you are looking for a comprehensive cloudsim tutorial, you should subscribe to “Learn Basics of Cloudsim.”