📄 manet_tora_imep.ex.c
字号:
/* manet_tora_imep.ex.c *//****************************************//* Copyright (c) 1987-2005 *//* by OPNET Technologies, Inc. *//* (A Delaware Corporation) *//* 7255 Woodmont Av., Suite 250 *//* Bethesda, MD 20814, U.S.A. *//* All Rights Reserved. *//****************************************/#include <opnet.h>#include <manet_tora_imep.h>#include "ip_support.h"#include "ip_rte_support.h"#define ToraC_Del_Delay 0.0001/* Global list variable. */List* id_pool_list = OPC_NIL;/* Animation related global variables */Pmohandle global_imep_header_fields_pmohandle;Anvid Tora_ImepI_Anvid;Boolean tora_animation_requested;int tora_animation_refresh_interval;int tora_animated_dest_rid;Boolean global_flag_single_ulp;Objid Imep_Subnet_Objid;List* global_tora_node_lptr;/* Structure used for router id auto addressing. */typedef struct { int domain_id; int index; Objid id_pool[ToraC_Max_Domain_Node_Num]; }ToraT_Router_ID_Pool;/* Structure for IP delivery cache. */typedef struct { Objid nd_objid; int last_update_period; List* node_lptr; }ToraT_Ip_Deliver_List_Entry;/* Local function declaration. */EXTERN_C_BEGINint tora_imep_sup_status_display (const char* dummy1, void* dummy2);EXTERN_C_END void tora_imep_sup_router_id_auto_assign(ToraT_Router_ID_Pool*, Objid, Objid);void tora_imep_sup_router_id_assign (int domain_id, int node_id, Objid node_objid, Objid module_objid) { int pool_num, pool_index, i; ToraT_Router_ID_Pool* pool_ptr = OPC_NIL; Boolean found = OPC_FALSE; Objid tmp_objid; /** PURPOSE: Assign a usable node id to each TORA router. **/ /** REQUIRES: domain and router id as well as router objid. **/ /** EFFECTS: Unique domain and router id combo is assigned. **/ FIN(tora_imep_sup_router_id_assign(domain_id, node_id, node_objid)); /* See if we have created pool list already. */ if(id_pool_list == OPC_NIL) { id_pool_list = op_prg_list_create(); } /* See if we have the id pool struct for the domain. */ pool_num = op_prg_list_size(id_pool_list); for(pool_index=0; pool_index < pool_num; pool_index++) { pool_ptr = (ToraT_Router_ID_Pool*)op_prg_list_access(id_pool_list, pool_index); if(pool_ptr->domain_id == domain_id) { found = OPC_TRUE; break; } } if(!found) { /* Create an empty pool for the domain. */ pool_ptr = (ToraT_Router_ID_Pool*)op_prg_mem_alloc(sizeof(ToraT_Router_ID_Pool)); /* initialize some values. */ pool_ptr->domain_id = domain_id; pool_ptr->index = 0; for(i=0; i < ToraC_Max_Domain_Node_Num; i++) { pool_ptr->id_pool[i] = -1; } } /* The main algorithm to assign id number starts here! */ if(node_id == ToraC_Router_ID_Auto_Assigned) { /* Any available node id value from this domain can be assigned. */ tora_imep_sup_router_id_auto_assign(pool_ptr, node_objid, module_objid); } else { /* This node came with a value assigned. */ /* Sanity check first! */ if(node_id >= ToraC_Max_Domain_Node_Num) { op_sim_end("This node has an ID exceeding TORA maximum. Ending simulation.", OPC_NIL, OPC_NIL, OPC_NIL); } /* See if some body was auto assigned the value already. */ if(pool_ptr->id_pool[node_id] != -1) { /* lets move this to sone other id value. */ tmp_objid = pool_ptr->id_pool[node_id]; tora_imep_sup_router_id_auto_assign(pool_ptr, tmp_objid, module_objid); } /* Take waht is rightfully yours! */ pool_ptr->id_pool[node_id] = node_objid; } if(!found) { /* We have to put this newly created struct into the list. */ op_prg_list_insert(id_pool_list, pool_ptr, OPC_LISTPOS_TAIL); } FOUT; }void tora_imep_sup_router_id_auto_assign(ToraT_Router_ID_Pool* pool_ptr, Objid node_objid, Objid module_objid) { Objid tmp_objid; /** PURPOSE: Assign any available id to this object. **/ /** REQUIRES: Objid and the pool struct. **/ /** EFFECTS: Unique domain and router id combo is assigned. **/ FIN(tora_imep_sup_router_id_auto_assign(pool_ptr, node_objid)); /* Iterate through the pool to find a free id. */ while((pool_ptr->id_pool[pool_ptr->index] != -1) && (pool_ptr->index < ToraC_Max_Domain_Node_Num)) { pool_ptr->index++; } if(pool_ptr->index == ToraC_Max_Domain_Node_Num) { /* There are more than allowed number of nodes in this domain. */ op_sim_end("Too many nodes with the same domain ID detected. Ending simulation.", OPC_NIL, OPC_NIL, OPC_NIL); } else { /* We found an empty id to give out. */ pool_ptr->id_pool[pool_ptr->index] = node_objid; op_ima_obj_attr_get (module_objid, "manet_mgr.TORA/IMEP Parameters", &tmp_objid); tmp_objid = op_topo_child (tmp_objid, OPC_OBJTYPE_GENERIC, 0); op_ima_obj_attr_set (tmp_objid, "Router ID", pool_ptr->index); } FOUT; }Objidtora_imep_sup_nd_objid_from_rid (int router_id) { ToraT_Router_ID_Pool* pool_ptr; /* Helper function to resolve node objid from assigned router_id. */ FIN (tora_imep_sup_nd_objid_from_rid (router_id)); /* We expect only single domain for now. */ pool_ptr = (ToraT_Router_ID_Pool*)op_prg_list_access(id_pool_list, OPC_LISTPOS_HEAD); FRET (pool_ptr->id_pool[router_id]); } voidmanet_imep_disp_message (const char* msg0) { /* Purpose: Print a warning message and possibly continue the simulation. */ /* Requires: Character string that will be printed out to console */ /* Effects: None. */ FIN (manet_imep_disp_message (const char* msg0, const char* msg1)); op_sim_message ("\nWarning from Manet-Tora-Imep process:", msg0); FOUT; }voidimep_allocate_pooled_memory () { static Boolean init = OPC_FALSE; /* Purpose: Function allocates the pooled memory handles for the IMEP packet header */ /* and data fields. */ /* Requires: None. */ /* Effects: None. */ FIN (imep_allocate_pooled_memory ()) if (!init) { /* First define a PMO handle for the header fields */ global_imep_header_fields_pmohandle = op_prg_pmo_define ("IMEP Header Fields", sizeof (ImepT_Header_Fields_Struct), 256); /* Error handle the returned values */ if ((global_imep_header_fields_pmohandle == OPC_PMO_INVALID)) { manet_imep_disp_message ("Unable to allocate memory for the pooled memory handles."); op_sim_end ("Terminating simulation in IMEP", OPC_NIL, OPC_NIL, OPC_NIL); } init = OPC_TRUE; } FOUT; }ImepT_Header_Fields_Struct*imep_packet_header_field_copy (ImepT_Header_Fields_Struct* input_ptr, int PRG_ARG_UNUSED (size)) { /* Purpose: Function to be used for deep copy of header structure on the imep packet */ /* Requires: Valid input pointer that needs to be copied */ /* Effects: Returns a pointer to the newly allocated structure */ /* Note here that the "size" argument is really not used, its a dummy argument */ ImepT_Header_Fields_Struct* retval = OPC_NIL; FIN (imep_packet_header_field_copy (ImepT_Header_Fields_Struct* input_ptr, int size)) /* Error check the passed in value */ if (input_ptr == OPC_NIL) FRET (OPC_NIL); /* Allocate memory for the created structure and error check */ retval = (ImepT_Header_Fields_Struct*) op_prg_pmo_alloc (global_imep_header_fields_pmohandle); if (retval == OPC_NIL) { manet_imep_disp_message ("Unable to allocate memory for the header structure."); op_sim_end ("Terminating simulation in IMEP", OPC_NIL, OPC_NIL, OPC_NIL); } /* Copy the simple data types first. */ op_prg_mem_copy (input_ptr, retval, sizeof (ImepT_Header_Fields_Struct)); if (input_ptr->ack_list) { /* Copy the ack list. */ retval->ack_list = op_prg_list_create (); op_prg_list_elems_copy (input_ptr->ack_list, retval->ack_list); } if (input_ptr->ack_info_ptr) { /* Copy the ack information. */ retval->ack_info_ptr = (ImepT_Ack_Elem_Struct*) op_prg_mem_copy_create (input_ptr->ack_info_ptr, sizeof (ImepT_Ack_Elem_Struct)); } FRET (retval); }voidimep_packet_header_field_destroy (ImepT_Header_Fields_Struct* input_ptr) { /* Purpose: Function required to destroy the header field structure in IMEP packet */ /* Requires: A valid input structure that needs to be freed up. */ /* Effects: None. */ FIN (imep_packet_header_field_destroy (input_ptr)); if (input_ptr->ack_list) { /* Destroy the ack list. */ op_prg_list_free (input_ptr->ack_list); op_prg_mem_free (input_ptr->ack_list); } if (input_ptr->ack_info_ptr) { /* Destroy the ack information. */ op_prg_mem_free (input_ptr->ack_info_ptr); } /* Destroy the whole thing now. */ op_prg_mem_free (input_ptr); FOUT; }voidtora_imep_sup_rid_register (Objid node_objid, Objid module_objid, int rid, IpT_Address address, IpT_Interface_Info* lan_intf_info_ptr, int mgr_pro_id, int imep_pro_id, int strm_from_tora_interface) { static Boolean init = OPC_FALSE; ToraT_Topo_Struct* new_topo_struct_ptr; /** PURPOSE: Insert each TORA node and their info in the global list. **/ /** REQUIRES: Node object id, assigned router id and interface ip address. **/ /** EFFECTS: List is created and filled. **/ FIN (tora_imep_sup_rid_register (node_objid, module_objid, rid, address, local_net_addr, mgr_pro_id, imep_pro_id)); if (init == OPC_FALSE) { global_tora_node_lptr = op_prg_list_create (); init = OPC_TRUE; } new_topo_struct_ptr = (ToraT_Topo_Struct*) op_prg_mem_alloc (sizeof (ToraT_Topo_Struct)); /* Fill in the values to the struct and insert into the list. */ new_topo_struct_ptr->node_objid = node_objid; new_topo_struct_ptr->module_objid = module_objid; new_topo_struct_ptr->rid = rid; new_topo_struct_ptr->ip_addr = address; new_topo_struct_ptr->lan_intf_info_ptr = lan_intf_info_ptr; new_topo_struct_ptr->mgr_pro_id = mgr_pro_id; new_topo_struct_ptr->imep_pro_id = imep_pro_id; new_topo_struct_ptr->stream_from_tora_interface = strm_from_tora_interface; op_prg_list_insert (global_tora_node_lptr, new_topo_struct_ptr, OPC_LISTPOS_TAIL); FOUT; }voidtora_imep_sup_packet_deliver (Packet* pk_ptr, Objid nd_objid) { static int max_dist = -1; ToraT_Topo_Struct* tmp_topo_struct_ptr; double tx_alt, tx_lat, tx_lon, tx_x, tx_y, tx_z, rx_alt, rx_lat, rx_lon, rx_x, rx_y, rx_z, distance;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -