How to Perform VM Migration Process

  • The migration of VM process should be invoked in “Datacenter” class. One have to extend the “Datacenter” class, in “processCloudletSubmit()” method call the “processVmMigrate()” using the “VM_MIGRATE” tag.
  • protected void processCloudletSubmit(SimEvent ev, boolean ack) {
    *** choose the vm to migrate and the new host to allocate the migrating vm.
    Let “vm” be the migrating VM and “host” be the chosen Host to allocate the vm. Add the vm,host in Map and trigger the VM_MIGRATE tag.
    Map<String,Object> ma;
    ma = new HashMap<String,Object>();
    ma.put("VM", vm);
    ma.put("Host", host);
    protected void processVmMigrate(SimEvent ev, boolean ack) {
    Object tmp = ev.getData();
    if (!(tmp instanceof Map<?, ?>)) {
    throw new ClassCastException("The data object must be Map<string, object="">");
    Map<String, Object> migrate = (HashMap<String, Object>) tmp;
    Vm v = (Vm) migrate.get("vm");
    Host h= (Host) migrate.get("host");
    ** Deallocate the vm from its original Host
    ** call the allocation policy and allocate the migrating VM “vm” to the Host “h”
    boolean result = getVmAllocationPolicy().allocateHostForVm(v, h);
    if (!result) {
    Log.printLine("[Datacenter.processVmMigrate] VM allocation to the destination host failed");
    Log.formatLine("%.2f: Migration of VM #%d to Host #%d is completed",CloudSim.clock(),v.getId(),