def do_algorithm(self, ipaddr, token): """ Perform the appropriate migration decision algorithm. param ipaddr: The IP address of the virtual machine to consider migration for. param token: The migration token. return: The IP of the destination server to send the VM to; None if the VM should not be migrated. """ hypervisor = None if (self.algorithm == 'round_robin'): hypervisor = self.migration.round_robin(ipaddr) elif (self.algorithm == 'distributed'): hypervisor = self.migration.distributed(ipaddr, token) else: # No such algorithm - don't do a migration! return False mac = hypervisor[0] dst = hypervisor[1] doms = xen.xm_get_parsed_doms() for dom in doms: if (xen.xm_get_mac(dom) == mac): live_migrate(dom, dst, None) return True
def round_robin(self, ipaddr): """ Perform a round-robin decision process for the VM with given IP address. param ipaddr: The IP address of the VM to consider for migration. return: IP address of server to migrate to, None otherwise. """ src, dst, mac = self.get_entries_and_mac(ipaddr) values = dict() total_cost = 0 total_cost_new = 0 hypervisor = None current = datetime.datetime.now() if (src is None and dst is None): #print 'Returning.' return None # Get aggregate throughput to/from neighbouring VMs, and communication costs. if (src is not None): for ip in src[1].keys(): if (ip.startswith('')): #192.168.1.')): values[ip] = [src[1][ip][0] + src[1][ip][1], 0, 0, ''] ### EVALUATION ### hypervisor, cost = self.lookup.communication_cost( '192.168.1.4') #hypervisor, cost = self.lookup.communication_cost(ip) #print ip #print hypervisor, cost if (hypervisor is None and cost is None): # Can't find hypervisor and associated cost, so can't migrate here. del values[ip] else: values[ip][1] = cost values[ip][2] = 2 * values[ip][0] * values[ip][1] / ( current - src[2]).total_seconds() total_cost = total_cost + values[ip][2] values[ip][3] = hypervisor if (dst is not None): for ip in dst[1].keys(): if not (values.has_key(ip)): if (ip.startswith('')): #192.168.1.')): values[ip] = ([ dst[1][ip][0] + dst[1][ip][1], 0, 0, '' ]) / (current - src[2]).total_seconds() ### EVALUATION ### hypervisor, cost = self.lookup.communication_cost( '192.168.1.4') #hypervisor, cost = self.lookup.communication_cost(ip) values[ip][1] = cost values[ip][2] = 2 * values[ip][0] * values[ip][1] total_cost = total_cost + values[ip][2] values[ip][3] = hypervisor else: # Cost should already exist - save doing another lookup. values[ip][0] = (values[ip][0] + dst[1][ip][0] + dst[1][ip][1]) / ( current - src[2]).total_seconds() values[ip][2] = 2 * values[ip][0] * values[ip][1] total_cost = total_cost + values[ip][2] # Find a destination server to migrate to, with appropriate space. max_cost = sys.maxint while (max_cost > 0): hypervisor, max_cost = self.get_highest_cost_hypervisor( values, max_cost) #print hypervisor, max_cost if (hypervisor is not None): ### EVALUATION ### capacity = self.lookup.capacity_request(hypervisor) #capacity = self.lookup.capacity_request(hypervisor) if (capacity is not None): doms = xen.xm_get_parsed_doms() print capacity #print doms for dom in doms: #print dom, mac #print xen.xm_get_mac(dom) if (xen.xm_get_mac(dom) == mac): if (capacity[0] < MAX_DOMS and capacity[1] > xen.xm_get_mem_vmid(dom)): return (mac, hypervisor) return None # Calculate new communication cost if migration takes place. new_values = dict() for ip in values.keys(): new_cost = self.lookup.communication_cost( hypervisor, values[ip][3]) new_values[ip] = values[ip][1] * new_cost total_cost_new = total_cost_new + new_values[ip] # Make/return migration decision. if (total_cost_new < total_cost): return hypervisor return None return None
def round_robin(self, ipaddr): """ Perform a round-robin decision process for the VM with given IP address. param ipaddr: The IP address of the VM to consider for migration. return: IP address of server to migrate to, None otherwise. """ src, dst, mac = self.get_entries_and_mac(ipaddr) values = dict() total_cost = 0 total_cost_new = 0 hypervisor = None current = datetime.datetime.now() if (src is None and dst is None): #print 'Returning.' return None # Get aggregate throughput to/from neighbouring VMs, and communication costs. if (src is not None): for ip in src[1].keys(): if (ip.startswith('')):#192.168.1.')): values[ip] = [src[1][ip][0]+src[1][ip][1], 0, 0, ''] ### EVALUATION ### hypervisor, cost = self.lookup.communication_cost('192.168.1.4') #hypervisor, cost = self.lookup.communication_cost(ip) #print ip #print hypervisor, cost if (hypervisor is None and cost is None): # Can't find hypervisor and associated cost, so can't migrate here. del values[ip] else: values[ip][1] = cost values[ip][2] = 2*values[ip][0]*values[ip][1] / (current - src[2]).total_seconds() total_cost = total_cost + values[ip][2] values[ip][3] = hypervisor if (dst is not None): for ip in dst[1].keys(): if not (values.has_key(ip)): if (ip.startswith('')):#192.168.1.')): values[ip] = ([dst[1][ip][0]+dst[1][ip][1], 0, 0, '']) / (current - src[2]).total_seconds() ### EVALUATION ### hypervisor, cost = self.lookup.communication_cost('192.168.1.4') #hypervisor, cost = self.lookup.communication_cost(ip) values[ip][1] = cost values[ip][2] = 2*values[ip][0]*values[ip][1] total_cost = total_cost + values[ip][2] values[ip][3] = hypervisor else: # Cost should already exist - save doing another lookup. values[ip][0] = (values[ip][0] + dst[1][ip][0]+dst[1][ip][1]) / (current - src[2]).total_seconds() values[ip][2] = 2*values[ip][0]*values[ip][1] total_cost = total_cost + values[ip][2] # Find a destination server to migrate to, with appropriate space. max_cost = sys.maxint while (max_cost > 0): hypervisor, max_cost = self.get_highest_cost_hypervisor(values, max_cost) #print hypervisor, max_cost if (hypervisor is not None): ### EVALUATION ### capacity = self.lookup.capacity_request(hypervisor) #capacity = self.lookup.capacity_request(hypervisor) if (capacity is not None): doms = xen.xm_get_parsed_doms() print capacity #print doms for dom in doms: #print dom, mac #print xen.xm_get_mac(dom) if (xen.xm_get_mac(dom) == mac): if (capacity[0] < MAX_DOMS and capacity[1] > xen.xm_get_mem_vmid(dom)): return (mac, hypervisor) return None # Calculate new communication cost if migration takes place. new_values = dict() for ip in values.keys(): new_cost = self.lookup.communication_cost(hypervisor, values[ip][3]) new_values[ip] = values[ip][1] * new_cost total_cost_new = total_cost_new + new_values[ip] # Make/return migration decision. if (total_cost_new < total_cost): return hypervisor return None return None