📄 dsr_route_discovery.ex.c
字号:
/* for this request ID from this source */ /* Do not insert this entry */ FOUT; } /* Check if there is space to insert the entry */ /* Delete the least recently used entry if */ /* there is no space available */ dsr_route_request_max_request_entries_check (src_requests_forward_table, route_request_table_ptr->max_request_table_entries); /* Allocate memory for the forwarded route request entry */ route_request_forward_entry = dsr_route_request_forward_entry_mem_alloc (); route_request_forward_entry->target_address = inet_address_copy (dest_address); route_request_forward_entry->route_request_id = request_id; route_request_forward_entry->last_used_time = op_sim_time (); /* Insert this entry in the route request forward table */ prg_string_hash_table_item_insert (src_requests_forward_table, req_id_str, route_request_forward_entry, &old_contents_ptr); FOUT; } Booleandsr_route_request_forwarding_table_entry_exists (DsrT_Route_Request_Table* route_request_table_ptr, InetT_Address src_address, int request_id) { PrgT_String_Hash_Table* src_requests_forward_table = OPC_NIL; DsrT_Request_Forward_Entry* route_request_forward_entry = OPC_NIL; char source_str [INETC_ADDR_STR_LEN]; char req_id_str [INETC_ADDR_STR_LEN]; /** Determines if an entry exists in the **/ /** forwarding request table for a request **/ /** ID from a source **/ FIN (dsr_route_request_forwarding_table_entry_exists (<args>)); /* Get the source address as a */ /* string to index the hash table */ inet_address_print (source_str, src_address); /* Check if there exists an entry for this source */ /* node in the route request table */ src_requests_forward_table = (PrgT_String_Hash_Table*) prg_string_hash_table_item_get (route_request_table_ptr->route_request_forward_table, source_str); if (src_requests_forward_table == OPC_NIL) { /* There does not exist an entry for this source */ FRET (OPC_FALSE); } /* Get the request ID string */ sprintf (req_id_str, "%d", request_id); /* Check if there exists an entry for this */ /* request ID from this source */ route_request_forward_entry = (DsrT_Request_Forward_Entry*) prg_string_hash_table_item_get (src_requests_forward_table, req_id_str); if (route_request_forward_entry == OPC_NIL) { /* There does not exist an entry for this */ /* request ID from this source */ FRET (OPC_FALSE); } /* Update the last used time */ route_request_forward_entry->last_used_time = op_sim_time (); /* There does exist an entry */ FRET (OPC_TRUE); } static voiddsr_route_request_table_size_check (DsrT_Route_Request_Table* route_request_table_ptr) { List* keys_lptr = OPC_NIL; int num_sources, num_requests; int count, size; List* request_keys_lptr = OPC_NIL; PrgT_String_Hash_Table* src_requests_forward_table = OPC_NIL; char* key_str = OPC_NIL; char* req_id_str = OPC_NIL; DsrT_Request_Forward_Entry* route_request_forward_entry = OPC_NIL; double most_recently_used_time = 0.0; char* most_recently_used_source_key = OPC_NIL; double least_recently_used_time = OPC_DBL_INFINITY; char* least_recently_used_source_key = OPC_NIL; /** Checks the size of the route request table **/ /** and deletes the least recently used entry **/ /** if the table is full **/ FIN (dsr_route_request_table_size_check (<void>)); if (route_request_table_ptr->current_table_size < route_request_table_ptr->max_table_size) { /* There is space in the request table */ FOUT; } /* There is no more space in the route request table */ /* Delete the least recently used entry from the */ /* forwarding request table. No entries are deleted */ /* from the originating request table since they are */ /* needed for retranmission. When the entries in the */ /* originating request table are not needed anymore, */ /* they are deleted */ /* Determine the least recently used entry in the */ /* forwarding request table */ keys_lptr = prg_string_hash_table_keys_get (route_request_table_ptr->route_request_forward_table); /* Determine the number of nodes */ num_sources = op_prg_list_size (keys_lptr); /* Determine the least recently used entry by */ /* going through each node and each request */ /* The least recently used entry would be the */ /* min(max (recently_used)) */ for (count = 0; count < num_sources; count++) { key_str = (char*) op_prg_list_access (keys_lptr, count); /* Get each node entry table */ src_requests_forward_table = (PrgT_String_Hash_Table*) prg_string_hash_table_item_get (route_request_table_ptr->route_request_forward_table, key_str); if (src_requests_forward_table == OPC_NIL) continue; /* Get the list of keys */ request_keys_lptr = prg_string_hash_table_keys_get (src_requests_forward_table); /* Get the number of requests for each node */ num_requests = op_prg_list_size (request_keys_lptr); for (size = 0; size < num_requests; size++) { req_id_str = (char*) op_prg_list_access (request_keys_lptr, size); /* Get each request entry */ route_request_forward_entry = (DsrT_Request_Forward_Entry*) prg_string_hash_table_item_get (src_requests_forward_table, req_id_str); if (route_request_forward_entry == OPC_NIL) continue; /* The get MAX(recently_used) */ if (route_request_forward_entry->last_used_time > most_recently_used_time) { most_recently_used_time = route_request_forward_entry->last_used_time; most_recently_used_source_key = key_str; } } /* Get the MIN (MAX(recently_used)) */ if (most_recently_used_time < least_recently_used_time) { least_recently_used_time = most_recently_used_time; least_recently_used_source_key = most_recently_used_source_key; } /* Free the keys list */ op_prg_list_free (request_keys_lptr); op_prg_mem_free (request_keys_lptr); } /* Delete the entry which is the least recently used */ src_requests_forward_table = (PrgT_String_Hash_Table*) prg_string_hash_table_item_remove (route_request_table_ptr->route_request_forward_table, least_recently_used_source_key); /* Get the number of keys */ request_keys_lptr = prg_string_hash_table_keys_get (src_requests_forward_table); /* Get the number of requests for this node */ num_requests = op_prg_list_size (request_keys_lptr); for (count = 0; count < num_requests; count++) { /* Get each key */ req_id_str = (char*) op_prg_list_access (request_keys_lptr, count); /* Remove the request entry */ route_request_forward_entry = (DsrT_Request_Forward_Entry*) prg_string_hash_table_item_remove (src_requests_forward_table, req_id_str); /* Free the request entry */ dsr_route_request_forward_entry_mem_free (route_request_forward_entry); } /* Free the keys list */ op_prg_list_free (request_keys_lptr); op_prg_mem_free (request_keys_lptr); /* Free the source hash table */ prg_string_hash_table_free (src_requests_forward_table); /* Decrement the size of the table */ route_request_table_ptr->current_table_size--; /* Update the request table size statistic */ dsr_request_table_size_stat_update (route_request_table_ptr); /* Free the keys list */ op_prg_list_free (keys_lptr); op_prg_mem_free (keys_lptr); FOUT; }static voiddsr_route_request_max_request_entries_check (PrgT_String_Hash_Table* src_requests_forward_table, int max_request_table_entries) { DsrT_Request_Forward_Entry* route_request_forward_entry = OPC_NIL; List* keys_lptr = OPC_NIL; int num_entries, count; char* key_str = OPC_NIL; double least_recently_used_time = OPC_DBL_INFINITY; char* least_recently_used_request_id_str = OPC_NIL; /** Checks if the maximum number of request **/ /** identifiers have been reached from a **/ /** single source. If so, it deletes the **/ /** least recently used request entry **/ FIN (dsr_route_request_max_request_entries_check (<args>)); /* Get the number of keys in the hash table */ keys_lptr = prg_string_hash_table_keys_get (src_requests_forward_table); num_entries = op_prg_list_size (keys_lptr); /* Determine is the maximum number of request */ /* identifiers have been reached */ if (num_entries < max_request_table_entries) { /* Free the keys list */ op_prg_list_free (keys_lptr); op_prg_mem_free (keys_lptr); /* The maximum entries have not been reached */ FOUT; } /* The maximum number of entries have been reached */ /* Delete the least recently used entry */ for (count = 0; count < num_entries; count++) { /* Get each entry */ key_str = (char*) op_prg_list_access (keys_lptr, count); /* Get the request entry */ route_request_forward_entry = (DsrT_Request_Forward_Entry*) prg_string_hash_table_item_get (src_requests_forward_table, key_str); /* Determine the least recently used entry */ if (route_request_forward_entry->last_used_time < least_recently_used_time) { least_recently_used_time = route_request_forward_entry->last_used_time; least_recently_used_request_id_str = key_str; } } /* Remove the least recently used request ID */ route_request_forward_entry = (DsrT_Request_Forward_Entry*) prg_string_hash_table_item_remove (src_requests_forward_table, least_recently_used_request_id_str); /* Free the request entry */ dsr_route_request_forward_entry_mem_free (route_request_forward_entry); /* Free the keys list */ op_prg_list_free (keys_lptr); op_prg_mem_free (keys_lptr); FOUT; }static voiddsr_request_table_size_stat_update (DsrT_Route_Request_Table* route_request_table_ptr) { /** Updates the request table size statistic **/ FIN (dsr_request_table_size_stat_update (<args>)); /* Update the size of the route request table statistic */ op_stat_write (route_request_table_ptr->dsr_stat_ptr->request_table_size_shandle, route_request_table_ptr->current_table_size); FOUT; } static DsrT_Route_Request_Table*dsr_request_table_mem_alloc (void) { DsrT_Route_Request_Table* route_request_table_ptr = OPC_NIL; /** Allocates memory for the send **/ /** and forward route request table **/ FIN (dsr_request_table_mem_alloc (void)); route_request_table_ptr = (DsrT_Route_Request_Table*) op_prg_mem_alloc (sizeof (DsrT_Route_Request_Table)); route_request_table_ptr->route_request_send_table = prg_string_hash_table_create (10, 10); route_request_table_ptr->route_request_forward_table = prg_string_hash_table_create (10, 10); FRET (route_request_table_ptr); }static DsrT_Request_Orig_Entry*dsr_route_request_orig_entry_mem_alloc (void) { static Pmohandle route_request_orig_entry_pmh;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -