Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Classify the Host Based on the Modes in Cloudsim?

Classify the Host Based on the Modes in Cloudsim

Condition for Classify the Host Based on the Modes in Cloudsim

  • Description:
    In CloudSim, Hosts can be classified into different modes, such as active, idle, and sleep, based on their resource usage and energy consumption. In active mode, the Host processes VMs and cloudlets, consuming maximum power. Idle mode reflects reduced power usage when no VMs are active, while sleep mode represents minimal energy consumption when the Host is not in use. Classifying Hosts by these modes helps simulate energy-efficient data center operations and evaluate strategies for power-aware VM allocation and task scheduling.
Sample Code
  • package hostmodes;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Random;
    import org.cloudbus.cloudsim.Cloudlet;
    import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
    import org.cloudbus.cloudsim.Datacenter;
    import org.cloudbus.cloudsim.DatacenterBroker;
    import org.cloudbus.cloudsim.DatacenterCharacteristics;
    import org.cloudbus.cloudsim.Log;
    import org.cloudbus.cloudsim.Pe;
    import org.cloudbus.cloudsim.Storage;
    import org.cloudbus.cloudsim.UtilizationModel;
    import org.cloudbus.cloudsim.UtilizationModelFull;
    import org.cloudbus.cloudsim.Vm;
    import org.cloudbus.cloudsim.VmAllocationPolicySimple;
    import org.cloudbus.cloudsim.VmSchedulerTimeShared;
    import org.cloudbus.cloudsim.core.CloudSim;
    import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
    import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
    import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
    public class HostModeSample extends javax.swing.JFrame {
    DatacenterBroker broker = null;
    private static List cloudletList;
    private static List vmlist;
    static Random rnd = new Random();
    static List hostList = new ArrayList();
    static ModifiedHost host;
    /**
    * Creates new form HostModeSample
    */
    public HostModeSample() {
    initComponents();
    }
    private static List createVM(int userId, int vms, int idShift) {
    //Creates a container to store VMs. This list is passed to the broker later
    LinkedList list = new LinkedList();
    Random rt = new Random();
    //VM Parameters
    long size = HostModesConfiguration.storagesize1; //image size (MB)
    int ram = HostModesConfiguration.VMram1; //vm memory (MB)
    double mips = HostModesConfiguration.Vmmips1;
    long bw = HostModesConfiguration.VMBandwidth1;
    int pesNumber = HostModesConfiguration.VMpes1; //number of cpus
    String vmm = "Xen"; //VMM name
    double min = 1;
    //create VMs
    Vm[] vm = new Vm[HostModesConfiguration.NoofVm1];
    for (int i = 0, c = 1; i < HostModesConfiguration.NoofVm1 && c <= vms; i++,
    c++) {
    System.out.println("*********** Random mips values for VM**********:" +
    rt.nextInt((int) mips));
    vm[i] = new Vm(idShift + i, userId, (double)rt.nextInt((int) mips),
    pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
    list.add(vm[i]);
    }
    return list;
    }
    private static List createCloudlet(int userId, int cloudlets, int
    idShift) {
    // Creates a container to store Cloudlets
    LinkedList list = new LinkedList();
    //cloudlet parameters
    long length = HostModesConfiguration.Cloudletlength1;
    long fileSize = HostModesConfiguration.Cloudletfilesize1;
    long outputSize = HostModesConfiguration.Cloudletoutputsize1;
    int pesNumber = HostModesConfiguration.NoOfpes1;
    UtilizationModel utilizationModel = new UtilizationModelFull();
    Cloudlet[] cloudlet = new Cloudlet[HostModesConfiguration.Noofcloudlet1];
    for (int i = 0,c=0; i <
    HostModesConfiguration.Noofcloudlet1&&c System.out.println("************* Random values for cloudlet
    length********:"+rnd.nextInt((int) length));
    cloudlet[i] = new Cloudlet(idShift + i,(long)rnd.nextInt((int) length),
    pesNumber, fileSize, outputSize, utilizationModel, utilizationModel,
    utilizationModel);
    // setting the owner of these Cloudlets
    cloudlet[i].setUserId(userId);
    list.add(cloudlet[i]);
    }
    return list;
    }
    private static Datacenter createDatacenter(String name) {
    // Here are the steps needed to create a PowerDatacenter:
    // 1. We need to create a list to store one or more
    // Machines
    // ArrayList hostList = new ArrayList();
    // 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 peList1 = new ArrayList();
    // 3. Create PEs and add these into the list.
    //for a quad-core machine, a list of 4 PEs is required:
    // for (int i = 1; i < 9; i++) {
    // }
    //Another list, for a dual-core machine
    //4. Create Hosts with its id and list of PEs and add them to the list of
    machines
    int hostId;
    int ram = HostModesConfiguration.Hostram1;
    long storage = HostModesConfiguration.Hoststorage1; //host storage
    int bw = HostModesConfiguration.Hostbandwidth1;
    int mips = HostModesConfiguration.Hostmips1;
    ModifiedHost host;
    int n=HostModesConfiguration.Noofhost1/3;
    System.out.println("*****************n value**************:"+n);
    // int mips1=rt.nextInt(mips);
    //in this example, the VMAllocatonPolicy in use is SpaceShared. It means
    that only one VM
    //is allowed to run on each Pe. As each Host has only one Pe, only one VM
    can run on each Host.
    for (int i = 1; i <= (HostModesConfiguration.Noofhost1); i++) {
    double mips1 = (double) (1000 + rnd.nextInt((int) mips));
    peList1.add(new Pe(0, new PeProvisionerSimple(mips1)));
    host= new ModifiedHost(
    i,
    new RamProvisionerSimple(ram),
    new BwProvisionerSimple(bw),
    storage,
    peList1,
    new VmSchedulerTimeShared(peList1));
    hostList.add(host);
    if (i<=n) {
    host.setHostMode(" Active mode");
    } else if (i >= n && i <=n+n) {
    host.setHostMode("sleeping Mode");
    } else {
    host.setHostMode("idle mode");
    }
    // This is our first machine
    }
    // 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).
    String arch = "x86"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this
    resource
    double costPerMem = 0.05; // the cost of using memory in this
    resource
    double costPerStorage = 0.1; // the cost of using storage in this
    resource
    double costPerBw = 0.1; // the cost of using bw in this
    resource
    LinkedList storageList = new LinkedList(); //we are not
    adding SAN devices by now
    DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
    arch, os, vmm, hostList, time_zone, cost, costPerMem,
    costPerStorage, costPerBw);
    // 6. Finally, we need to create a PowerDatacenter object.
    Datacenter datacenter = null;
    try {
    datacenter = new Datacenter(name, characteristics, new
    VmAllocationPolicySimple(hostList), storageList, 0);
    } catch (Exception e) {
    }
    return datacenter;
    }
    private static DatacenterBroker createBroker() {
    DatacenterBroker broker = null;
    try {
    broker = new DatacenterBroker("Broker");
    } catch (Exception e) {
    return null;
    }
    return broker;
    }
    private static void printCloudletList(List list) {
    int size = list.size();
    Cloudlet cloudlet = null;
    String indent = " ";
    Log.printLine();
    Log.printLine("========== OUTPUT ==========");
    Log.printLine(indent + "Cloudlet ID" + indent + "STATUS" + indent
    + "Data center ID" + indent + "VM ID" + indent + indent + "Time" +
    indent + "Start Time" + indent + "Finish Time");
    DecimalFormat dft = new DecimalFormat("###.##");
    for (int i = 0; i < size; i++) {
    cloudlet = list.get(i);
    Log.print(indent + cloudlet.getCloudletId() + indent + indent);
    // +VMtype.get(cloudlet.getVmId()).Vmtype
    if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
    Log.print("SUCCESS");
    Log.printLine(indent + indent + cloudlet.getResourceId() + indent +
    indent + indent + cloudlet.getVmId()
    + indent + indent + indent + indent +
    dft.format(cloudlet.getActualCPUTime()) + indent + indent +
    dft.format(cloudlet.getExecStartTime())
    + indent + indent + dft.format(cloudlet.getFinishTime()));
    }
    }
    // Log.printLine("========== OUTPUT ==========");
    // Log.printLine(indent + indent+"vmid"+indent + indent+"mips"+indent +
    indent+"type");
    // for(int i=0;i // {
    //// System.out.println(vmlist.get(cloudlet.getVmId()));
    //// System.out.println(vmlist.get(i).mips1);
    //// System.out.println(vmlist.get(cloudlet.getVmId()).getVmType());
    // Log.printLine(indent + indent+vmlist.get(i).getId()+indent +
    indent+vmlist.get(i).getMips()+indent + indent+vmlist.get(i).getVmType());
    // }
    Log.printLine("========== OUTPUT ==========");
    Log.printLine(indent + indent+"Hostid"+indent + indent+"mips"+indent +
    indent+"type");
    for(int i=0;i {
    Log.printLine(indent + indent+hostList.get(i).getId()+indent +
    indent+hostList.get(i).getPeList().get(i).getMips()+indent +
    indent+hostList.get(i).getHostMode());
    }
    }
    /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // //GEN-
    BEGIN:initComponents
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    btnConfiguration = new javax.swing.JButton();
    btnDatacenterCreation = new javax.swing.JButton();
    btnSimulation = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new
    java.awt.Color(0, 0, 0)));
    btnConfiguration.setText("Configuration");
    btnConfiguration.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnConfigurationActionPerformed(evt);
    }
    });
    btnDatacenterCreation.setText("DatacenterCreation");
    btnDatacenterCreation.addActionListener(new java.awt.event.ActionListener()
    { public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnDatacenterCreationActionPerformed(evt);
    }
    });
    btnSimulation.setText("Simulation");
    btnSimulation.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    btnSimulationActionPerformed(evt);
    }
    });
    javax.swing.GroupLayout jPanel1Layout = new
    javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGap(37, 37, 37)
    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
    NG, false)
    .addComponent(btnConfiguration,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
    Short.MAX_VALUE)
    .addComponent(btnDatacenterCreation,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
    Short.MAX_VALUE)
    .addComponent(btnSimulation,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
    Short.MAX_VALUE))
    .addContainerGap(59, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(jPanel1Layout.createSequentialGroup()
    .addGap(30, 30, 30)
    .addComponent(btnConfiguration)
    .addGap(32, 32, 32)
    .addComponent(btnDatacenterCreation)
    .addGap(18, 18, 18)
    .addComponent(btnSimulation)
    .addContainerGap(30, Short.MAX_VALUE))
    );
    javax.swing.GroupLayout layout = new
    javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(46, 46, 46)
    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(41, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addGap(33, 33, 33)
    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
    javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(35, Short.MAX_VALUE))
    );
    pack();
    }//
    //GEN-END:initComponents
    private void btnConfigurationActionPerformed(java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_btnConfigurationActionPerformed
    HostModesConfiguration multibroker = new HostModesConfiguration();
    multibroker.setVisible(true);
    }//GEN-LAST:event_btnConfigurationActionPerformed
    private void
    btnDatacenterCreationActionPerformed(java.awt.event.ActionEvent
    evt) {//GEN-FIRST:event_btnDatacenterCreationActionPerformed
    // TODO add your handling code here:
    try {
    // First step: Initialize the CloudSim package. It should be called
    // before creating any entities.
    int num_user = 1; // number of cloud users
    Calendar calendar = Calendar.getInstance();
    boolean trace_flag = false; // mean trace events
    // Initialize the CloudSim library
    CloudSim.init(num_user, calendar, trace_flag);
    // Second step: Create Datacenters
    Datacenter datacenter0 = createDatacenter("Datacenter_0");
    //Third step: Create Broker
    broker = createBroker();
    int brokerId = broker.getId();
    //Fourth step: Create VMs and Cloudlets and send them to broker
    vmlist = createVM(brokerId, HostModesConfiguration.NoofVm1, 0);
    //creating 40 vms
    cloudletList = createCloudlet(brokerId,
    HostModesConfiguration.Noofcloudlet1, 0); // creating 40 cloudlets
    broker.submitVmList(vmlist);
    broker.submitCloudletList(cloudletList);
    } catch (Exception e) {
    e.printStackTrace();
    Log.printLine("The simulation has been terminated due to an unexpected
    error");
    }
    }//GEN-LAST:event_btnDatacenterCreationActionPerformed
    private void btnSimulationActionPerformed(java.awt.event.ActionEvent evt)
    {//GEN-FIRST:event_btnSimulationActionPerformed
    // TODO add your handling code here
    CloudSim.startSimulation();
    // Final step: Print results when simulation is over
    List newList = broker.getCloudletReceivedList();
    printCloudletList(newList);
    CloudSim.stopSimulation();
    }//GEN-LAST:event_btnSimulationActionPerformed
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the
    default look and feel.
    * For details see
    http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
    */
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info :
    javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClassName());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(HostModeSample.class.getName()).log(java.util.lo
    gging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(HostModeSample.class.getName()).log(java.util.lo
    gging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(HostModeSample.class.getName()).log(java.util.lo
    gging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(HostModeSample.class.getName()).log(java.util.lo
    gging.Level.SEVERE, null, ex);
    }
    //

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(() -> {
    new HostModeSample().setVisible(true);
    });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnConfiguration;
    private javax.swing.JButton btnDatacenterCreation;
    private javax.swing.JButton btnSimulation;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    }
Step 1
  • To classify the environment for host based on the modes.
  • host-based-on-the-modes1
Step 2
  • To put the Host, Virtual machine, cloudlet and broker configurations.
  • host-based-on-the-modes2
Step 3
  • To create a datacenter for host classification based on the modes.
  • host-based-on-the-modes3
Step 4
  • To simulate the result of host classification.
  • host-based-on-the-modes4
Step 5
  • To get the results for Host and virtual machines.
  • host-based-on-the-modes5
Step 6
  • To get the sending and receiving cloudlet ids.
  • host-based-on-the-modes6
Step 7
  • To get the cloudlet results for host classification based on the modes.
  • host-based-on-the-modes7