📄 dymo_support.ex.c
字号:
/* dymo_support.ex.c */
/* C support file for DYMO support functions */
/****************************************/
/* Copyright (c) 1987-2003 */
/* by OPNET Technologies, Inc. */
/* (A Delaware Corporation) */
/* 7255 Woodmont Av., Suite 250 */
/* Bethesda, MD 20814, U.S.A. */
/* All Rights Reserved. */
/****************************************/
/***** Includes *****/
#include <opnet.h>
#include <dymo.h>
#include <dymo_ptypes.h>
#include <prg_string_hash_funcs.h>
DymoT_Global_Stathandles*
dymo_support_global_stat_handles_obtain (void)
{
static Boolean stat_handles_registered = OPC_FALSE;
static DymoT_Global_Stathandles* stat_handle_ptr = OPC_NIL;
/** Registers the global statistics and returns a **/
/** handle to the global statistics **/
FIN (dymo_support_global_stat_handles_obtain (void));
if (stat_handles_registered == OPC_FALSE)
{
/* The statistic handles have not yet been registered */
/* Register the global statistic handles */
stat_handle_ptr = (DymoT_Global_Stathandles*) op_prg_mem_alloc (sizeof (DymoT_Global_Stathandles));
stat_handle_ptr->route_discovery_time_global_shandle = op_stat_reg ("DYMO.Route Discovery Time", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->num_hops_global_shandle = op_stat_reg ("DYMO.Number of Hops per Route", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->num_pkts_discard_global_shandle = op_stat_reg ("DYMO.Total Packets Dropped", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->rte_traf_rcvd_bps_global_shandle = op_stat_reg ("DYMO.Routing Traffic Received (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->rte_traf_rcvd_pps_global_shandle = op_stat_reg ("DYMO.Routing Traffic Received (pkts/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->rte_traf_sent_bps_global_shandle = op_stat_reg ("DYMO.Routing Traffic Sent (bits/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->rte_traf_sent_pps_global_shandle = op_stat_reg ("DYMO.Routing Traffic Sent (pkts/sec)", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->total_requests_sent_global_shandle = op_stat_reg ("DYMO.Total Route Requests Sent", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->total_replies_sent_global_shandle = op_stat_reg ("DYMO.Total Route Replies Sent", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->total_replies_sent_from_dest_global_shandle = op_stat_reg ("DYMO.Total Replies Sent from Destination", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->total_cached_replies_sent_global_shandle = op_stat_reg ("DYMO.Total Cached Replies Sent", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
stat_handle_ptr->total_route_errors_sent_global_shandle = op_stat_reg ("DYMO.Total Route Errors Sent", OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
/* Set the flag to indicate that the statistics */
/* have been registered */
stat_handles_registered = OPC_TRUE;
}
FRET (stat_handle_ptr);
}
Boolean
dymo_support_hello_efficiency_sim_attr_get (void)
{
static Boolean hello_efficiency_mode;
static Boolean attr_read = OPC_FALSE;
/** Reads the global attribute **/
FIN (dymo_support_hello_efficiency_sim_attr_get (void));
if (attr_read == OPC_FALSE)
{
/* Read the global attribute once */
op_ima_sim_attr_get (OPC_IMA_TOGGLE, "DYMO Hello Efficiency", &hello_efficiency_mode);
//hello_efficiency_mode = OPC_FALSE;
/* Set the flag so that */
/* it is not read again */
attr_read = OPC_TRUE;
}
FRET (hello_efficiency_mode);
}
void
dymo_support_routing_traffic_sent_stats_update (DymoT_Local_Stathandles* stat_handle_ptr, DymoT_Global_Stathandles* global_stathandle_ptr, Packet* pkptr)
{
OpT_Packet_Size pkt_size;
/** Updates the routing traffic sent statistics **/
/** in both bits/sec and pkts/sec **/
FIN (dymo_support_routing_traffic_sent_stats_update (<args>));
/* Get the size of the packet */
pkt_size = op_pk_total_size_get (pkptr);
/* Update the local routing traffic sent stat in bps */
op_stat_write (stat_handle_ptr->rte_traf_sent_bps_shandle, pkt_size);
op_stat_write (stat_handle_ptr->rte_traf_sent_bps_shandle, 0.0);
/* Update the local routing traffic sent stat in pps */
op_stat_write (stat_handle_ptr->rte_traf_sent_pps_shandle, 1.0);
op_stat_write (stat_handle_ptr->rte_traf_sent_pps_shandle, 0.0);
/* Update the global routing traffic sent stat in bps */
op_stat_write (global_stathandle_ptr->rte_traf_sent_bps_global_shandle, pkt_size);
op_stat_write (global_stathandle_ptr->rte_traf_sent_bps_global_shandle, 0.0);
/* Update the global routing traffic sent stat in pps */
op_stat_write (global_stathandle_ptr->rte_traf_sent_pps_global_shandle, 1.0);
op_stat_write (global_stathandle_ptr->rte_traf_sent_pps_global_shandle, 0.0);
FOUT;
}
void
dymo_support_routing_traffic_received_stats_update (DymoT_Local_Stathandles* stat_handle_ptr, DymoT_Global_Stathandles* global_stathandle_ptr, Packet* pkptr)
{
OpT_Packet_Size pkt_size;
/** Updates the routing traffic sent statistics **/
/** in both bits/sec and pkts/sec **/
FIN (dymo_support_routing_traffic_received_stats_update (<args>));
/* Get the size of the packet */
pkt_size = op_pk_total_size_get (pkptr);
/* Update the local routing traffic sent stat in bps */
op_stat_write (stat_handle_ptr->rte_traf_rcvd_bps_shandle, pkt_size);
op_stat_write (stat_handle_ptr->rte_traf_rcvd_bps_shandle, 0.0);
/* Update the local routing traffic sent stat in pps */
op_stat_write (stat_handle_ptr->rte_traf_rcvd_pps_shandle, 1.0);
op_stat_write (stat_handle_ptr->rte_traf_rcvd_pps_shandle, 0.0);
/* Update the global routing traffic sent stat in bps */
op_stat_write (global_stathandle_ptr->rte_traf_rcvd_bps_global_shandle, pkt_size);
op_stat_write (global_stathandle_ptr->rte_traf_rcvd_bps_global_shandle, 0.0);
/* Update the global routing traffic sent stat in pps */
op_stat_write (global_stathandle_ptr->rte_traf_rcvd_pps_global_shandle, 1.0);
op_stat_write (global_stathandle_ptr->rte_traf_rcvd_pps_global_shandle, 0.0);
FOUT;
}
void
dymo_support_route_reply_sent_stats_update (DymoT_Local_Stathandles* stat_handle_ptr, DymoT_Global_Stathandles* global_stathandle_ptr,
Boolean dest_route_reply)
{
/** Updates the statistics related to the route replies sent **/
FIN (dymo_support_route_reply_sent_stats_update (<args>));
/* Based on whether the route reply is a */
/* cached route reply or a route reply from */
/* the destination, update the statistic */
if (!dest_route_reply)
{
/* Update the statistic for the total */
/* number of cached route replies sent */
/* both locally and globally */
op_stat_write (stat_handle_ptr->total_cached_replies_sent_shandle, 1.0);
op_stat_write (global_stathandle_ptr->total_cached_replies_sent_global_shandle, 1.0);
}
else
{
/* Update the statistic for the total */
/* number of route replies sent from */
/* the destination both local and global*/
op_stat_write (stat_handle_ptr->total_replies_sent_from_dest_shandle, 1.0);
op_stat_write (global_stathandle_ptr->total_replies_sent_from_dest_global_shandle, 1.0);
}
/* Update the statistic for the total number of */
/* route replies sent both locally and globally */
op_stat_write (stat_handle_ptr->total_replies_sent_shandle, 1.0);
op_stat_write (global_stathandle_ptr->total_replies_sent_global_shandle, 1.0);
FOUT;
}
void
dymo_support_route_table_print_to_string (DymoT_Route_Table* route_table_ptr)
{
DymoT_Route_Entry* route_entry_ptr = OPC_NIL;
List* keys_lptr = OPC_NIL;
int num_routes, count;
char* key_ptr;
List* dest_routes_lptr = OPC_NIL;
char message_str [10000] = "";
char* final_str = OPC_NIL;
char temp_str [1000] = "";
int add_elements;
char next_addr_str [INETC_ADDR_STR_LEN];
char rt_entry[128];
/** Prints the DYMO Route Table maintained at this node **/
FIN (dymo_support_route_table_print_to_string (<args>));
/* Get the size of each string */
add_elements = strlen (message_str);
/* Append the new string to the return string */
final_str = (char*) dymo_array_elements_add (final_str, 0, (add_elements + 1), sizeof (char));
strcat (final_str, message_str);
/* Get the number of routes in the route table */
keys_lptr = (List*) prg_string_hash_table_keys_get (route_table_ptr->route_table);
num_routes = op_prg_list_size (keys_lptr);
if(num_routes == 0)
{
printf("\n Empty Route Table \n");
}
else
{
printf("=========================================================================================\n");
printf("- ROUTE TABLE \n");
printf("=========================================================================================\n");
printf("Dest. Node Dest Seq.Num Next Hop HopCount Rt.Expiry Time Rt.Entry Status \n");
printf("---------- ------------ -------- -------- -------------- -------------- \n");
for (count = 0; count < num_routes; count++)
{
/* For each route entry */
key_ptr = (char*) op_prg_list_access (keys_lptr, count);
route_entry_ptr = (DymoT_Route_Entry*) prg_string_hash_table_item_get (route_table_ptr->route_table, key_ptr);
if(route_entry_ptr == OPC_NIL)
{
printf("One Entry but Empty Route Table \n");
continue;
}
else
{
if (route_entry_ptr->route_entry_state == DymoC_Valid_Route)
{
sprintf(rt_entry, "VALID");
}
else if(route_entry_ptr->route_entry_state == DymoC_Invalid_Route)
{
sprintf(rt_entry, "INVALID");
}
else
{
sprintf(rt_entry, "UNDEFINED");
}
inet_address_print (next_addr_str, route_entry_ptr->next_hop_addr);
printf ("%s\t%d\t\t%s\t%d\t%18.5f\t%s\n", key_ptr, route_entry_ptr->dest_seq_num, next_addr_str,
route_entry_ptr->hop_count, route_entry_ptr->route_expiry_time, rt_entry);
}
}
printf("---------------------------------------------------------------------------------------------\n");
}/* close else */
/* Free the keys */
op_prg_list_free (keys_lptr);
op_prg_mem_free (keys_lptr);
FOUT;
}
void*
dymo_array_elements_add (void* array, int count, int add_count, int elem_size)
{
void* new_array;
/** This procedure allocates a new array of elements of **/
/** the specified size and copies the elements of the **/
/** original array into the new array. The old array **/
/** is deallocated and the new array is returned. **/
FIN (dymo_array_elements_add (<args>));
/* Allocate the array. If this fails, the called */
/* procedure will handle the error. */
new_array = op_prg_mem_alloc ((count + add_count) * elem_size);
/* If there were any elements previously, copy */
/* them into the new array. */
if (count != 0)
{
/* Copy the old array into the new array. */
op_prg_mem_copy (array, new_array, count * elem_size);
/* Deallocate the old array. */
op_prg_mem_free (array);
}
/* Return the new array pointer. */
FRET (new_array);
}
void
dymo_support_conn_table_print_to_string(PrgT_String_Hash_Table* neighbor_connectivity_table_ptr)
{
List* keys_lptr = OPC_NIL;
char* neighbor_addr_str;
char address [INETC_ADDR_STR_LEN];
DymoT_Conn_Info* neighbor_conn_info_ptr = OPC_NIL;
void* old_contents_ptr = OPC_NIL;
int num_neighbors;
int count;
/** Prints the neighbor connectivity table **/
FIN (dymo_support_conn_table_print_to_string (<args>));
/* Get the number of entries in connectivity hash table */
keys_lptr = (List*) prg_string_hash_table_keys_get (neighbor_connectivity_table_ptr);
num_neighbors = op_prg_list_size (keys_lptr);
if(num_neighbors == 0)
{
printf("Neighbor Connectivity Table Empty \n");
}
else
{
printf("Num of neighbors: %d\n", num_neighbors);
printf("Neighbour IP Address LastPktRecv Time LastHelloRecv Time \n");
printf("-------------------- ---------------- ------------------ \n");
for (count = 0; count < num_neighbors; count++)
{
/* For each route entry */
neighbor_addr_str = (char*) op_prg_list_access (keys_lptr, count);
/* Access the connectivity information of each neighbor */
neighbor_conn_info_ptr = (DymoT_Conn_Info*) prg_string_hash_table_item_get (neighbor_connectivity_table_ptr,
neighbor_addr_str);
inet_address_print (address, neighbor_conn_info_ptr->neighbor_address);
printf(" %s\t%18.5f\t%18.5f \n", address, neighbor_conn_info_ptr->last_pkt_received_time,
neighbor_conn_info_ptr->last_hello_received_time);
}
printf("------------------------------------------------------------------\n");
}
/* Free the keys */
op_prg_list_free (keys_lptr);
op_prg_mem_free (keys_lptr);
FOUT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -