示例#1
0
 def Send_Heartbeat():
     '''
     This routine sends Heartbeats to all DPS Client which have not been
     contacted for the specified amount of time. 
     '''
     curr_time = time.time()
     try:
         dps_clients = DPSClientHost.Collection.values()
         for dps_client in dps_clients:
             try:
                 time_diff = int(curr_time - dps_client.last_contact)
                 client_type = dps_client.client_type
                 time_no_contact = DPSClientHost.heartbeat_no_contact[
                     client_type]
                 time_heartbeat_send = DPSClientHost.heartbeat_frequency[
                     client_type]
                 if time_diff > time_no_contact:
                     print 'No contact from DPS Client %s for %s seconds. Deleting!!!\r' % (
                         dps_client.location.show_ip(), time_diff)
                     dps_client.delete()
                 elif time_diff >= time_heartbeat_send:
                     vnid = dps_client.vnid_random_get()
                     query_id = DpsCollection.generate_query_id()
                     dcslib.send_heartbeat(
                         dps_client.location.ip_value_packed,
                         dps_client.location.port, vnid, query_id)
             except Exception:
                 continue
     except Exception:
         pass
     return
示例#2
0
 def send_vm_migration_update_to(self, dps_client, endpoint, vnid, query_id):
     if not self.active:
         return
     if query_id == 0:
         query_id_use = DpsCollection.generate_query_id()
     else:
         query_id_use = query_id
     # to send to dcslib.send_all_vm_migration_update ()
     vipv4_list = []
     vipv6_list = []
     pipv4_list = endpoint.tunnel_endpoint.ip_listv4.ip_list[:]
     pipv6_list = endpoint.tunnel_endpoint.ip_listv6.ip_list[:]
     for vIP_obj in endpoint.vIP_set.values():
         if vIP_obj.fValid:
             if vIP_obj.inet_type == socket.AF_INET:
                 vipv4_list.append(vIP_obj.ip_value)
             elif vIP_obj.inet_type == socket.AF_INET6:
                 vipv6_list.append(vIP_obj.ip_value)
     ret_val = dcslib.send_all_vm_migration_update(dps_client.location.ip_value_packed, #DPS Client Location IP
                                                   dps_client.location.port, #DPS Client Port
                                                   vnid, #VNID ID
                                                   query_id_use,
                                                   endpoint.dvg.unique_id,
                                                   endpoint.version,
                                                   pipv4_list,
                                                   pipv6_list,
                                                   endpoint.vMac,
                                                   vipv4_list,
                                                   vipv6_list)
     if ret_val != 0: 
         message = 'send_all_vm_migration_update FAILED with value %d'%(ret_val)
         dcslib.dps_data_write_log(DpsLogLevels.NOTICE, message)
     return
示例#3
0
 def Send_Heartbeat():
     '''
     This routine sends Heartbeats to all DPS Client which have not been
     contacted for the specified amount of time. 
     '''
     curr_time = time.time()
     try:
         dps_clients = DPSClientHost.Collection.values()
         for dps_client in dps_clients:
             try:
                 time_diff = int(curr_time - dps_client.last_contact)
                 client_type = dps_client.client_type
                 time_no_contact = DPSClientHost.heartbeat_no_contact[client_type]
                 time_heartbeat_send = DPSClientHost.heartbeat_frequency[client_type]
                 if time_diff > time_no_contact:
                     print 'No contact from DPS Client %s for %s seconds. Deleting!!!\r'%(dps_client.location.show_ip(),
                                                                                          time_diff)
                     dps_client.delete()
                 elif time_diff >= time_heartbeat_send:
                     vnid = dps_client.vnid_random_get()
                     query_id = DpsCollection.generate_query_id()
                     dcslib.send_heartbeat(dps_client.location.ip_value_packed,
                                           dps_client.location.port,
                                           vnid, query_id)
             except Exception:
                 continue
     except Exception:
         pass
     return
示例#4
0
 def endpoint_claim(self, endpoint, transaction_type):
     '''
     This routine adds a Endpoint that claims to have this vIP previously. This routine
     should be called from Endpoint_Find_and_Detect_Conflict routine
     @attention: This routine assumes the global lock is held when this routine
                 is called.
     @param endpoint: The Endpoint
     @type endpoint: Endpoint
     @param transaction_type: The Type of Transaction: should be in DpsTransactionType
     @type transaction_type: Integer
     '''
     #log.warning('endpoint_claim: vIP %s, transaction_type %s\r',
     #            self.vIP.show(), transaction_type)
     #endpoint.show()
     while True:
         tunnel = endpoint.tunnel_endpoint
         if tunnel is None:
             break
         dps_client = tunnel.dps_client
         self.endpoints_claim[endpoint] = endpoint
         #Let the previous owner be the one to claim this IP.
         self.endpoint_owner = endpoint
         if transaction_type != DpsTransactionType.normal:
             break
         #Send address resolution request to the DPS Client
         query_id = DpsCollection.generate_query_id()
         ret_val = dcslib.send_address_resolution(
             dps_client.location.ip_value_packed,  #DPS Client Location IP
             dps_client.location.port,  #DPS Client Port
             endpoint.vnid,  #VNID ID
             query_id,  #Query ID
             self.vIP.ip_value_packed,  #IP packed
             endpoint.vMac  #vMac
         )
         if ret_val != 0 and len(
                 DpsCollection.Address_Resolution_Requests_To
         ) < DpsCollection.Max_Pending_Queue_Size:
             #Insert into a retry queue to be tried in the next iteration. In this case it
             #will be sent without a MAC address, but it's ok since this is a rare condition
             key = '%s:%s:%s' % (self.unique_id,
                                 dps_client.location.ip_value,
                                 self.vIP.ip_value_packed)
             DpsCollection.Address_Resolution_Requests_To[key] = (
                 self, dps_client, self.vIP.ip_value_packed)
         break
     return
示例#5
0
 def endpoint_claim(self, endpoint, transaction_type):
     '''
     This routine adds a Endpoint that claims to have this vIP previously. This routine
     should be called from Endpoint_Find_and_Detect_Conflict routine
     @attention: This routine assumes the global lock is held when this routine
                 is called.
     @param endpoint: The Endpoint
     @type endpoint: Endpoint
     @param transaction_type: The Type of Transaction: should be in DpsTransactionType
     @type transaction_type: Integer
     '''
     #log.warning('endpoint_claim: vIP %s, transaction_type %s\r', 
     #            self.vIP.show(), transaction_type)
     #endpoint.show()
     while True:
         tunnel = endpoint.tunnel_endpoint
         if tunnel is None:
             break
         dps_client = tunnel.dps_client
         self.endpoints_claim[endpoint] = endpoint
         #Let the previous owner be the one to claim this IP.
         self.endpoint_owner = endpoint
         if transaction_type != DpsTransactionType.normal:
             break
         #Send address resolution request to the DPS Client
         query_id = DpsCollection.generate_query_id()
         ret_val = dcslib.send_address_resolution(dps_client.location.ip_value_packed, #DPS Client Location IP
                                                  dps_client.location.port, #DPS Client Port
                                                  endpoint.vnid, #VNID ID
                                                  query_id, #Query ID
                                                  self.vIP.ip_value_packed, #IP packed
                                                  endpoint.vMac #vMac
                                                  )
         if ret_val != 0 and len(DpsCollection.Address_Resolution_Requests_To) < DpsCollection.Max_Pending_Queue_Size:
             #Insert into a retry queue to be tried in the next iteration. In this case it
             #will be sent without a MAC address, but it's ok since this is a rare condition
             key = '%s:%s:%s'%(self.unique_id, dps_client.location.ip_value, self.vIP.ip_value_packed)
             DpsCollection.Address_Resolution_Requests_To[key] = (self, dps_client, self.vIP.ip_value_packed)
         break
     return
示例#6
0
 def send_vm_migration_update_to(self, dps_client, endpoint, vnid,
                                 query_id):
     if not self.active:
         return
     if query_id == 0:
         query_id_use = DpsCollection.generate_query_id()
     else:
         query_id_use = query_id
     # to send to dcslib.send_all_vm_migration_update ()
     vipv4_list = []
     vipv6_list = []
     pipv4_list = endpoint.tunnel_endpoint.ip_listv4.ip_list[:]
     pipv6_list = endpoint.tunnel_endpoint.ip_listv6.ip_list[:]
     for vIP_obj in endpoint.vIP_set.values():
         if vIP_obj.fValid:
             if vIP_obj.inet_type == socket.AF_INET:
                 vipv4_list.append(vIP_obj.ip_value)
             elif vIP_obj.inet_type == socket.AF_INET6:
                 vipv6_list.append(vIP_obj.ip_value)
     ret_val = dcslib.send_all_vm_migration_update(
         dps_client.location.ip_value_packed,  #DPS Client Location IP
         dps_client.location.port,  #DPS Client Port
         vnid,  #VNID ID
         query_id_use,
         endpoint.dvg.unique_id,
         endpoint.version,
         pipv4_list,
         pipv6_list,
         endpoint.vMac,
         vipv4_list,
         vipv6_list)
     if ret_val != 0:
         message = 'send_all_vm_migration_update FAILED with value %d' % (
             ret_val)
         dcslib.dps_data_write_log(DpsLogLevels.NOTICE, message)
     return