📄 gpr_route_layer_queue.pr.c
字号:
/* Process model C form file: gpr_route_layer_queue.pr.c */
/* Portions of this file copyright 1992-2003 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char gpr_route_layer_queue_pr_c [] = "MIL_3_Tfile_Hdr_ 100A 30A modeler 7 42DDC544 42DDC544 1 zhangzhong jc 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 8f3 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
// stream number definition
#define FROM_UPPER_LAYER_STRM 1
#define FROM_MAC_LAYER_STRM 0
#define TO_MAC_LAYER_STRM 0
#define TO_UPPER_LAYER_STRM 1
#define INT_RA_RCV 101
#define INT_ROUTE_CHANGE 102
#define INT_NA_TIMER 103
#define INT_CNSB_TIMER 104
#define INT_NA_REPLY 105
#define MAC_BROADCAST -1
// TRANSITION MACROS DEFINITION
//define interupt condition
#define UPPER_LAYER_ARRIVAL (op_intrpt_type()==OPC_INTRPT_STRM && op_intrpt_strm()==FROM_UPPER_LAYER_STRM)
#define MAC_LAYER_ARRIVAL (op_intrpt_type()==OPC_INTRPT_STRM && op_intrpt_strm()==FROM_MAC_LAYER_STRM)
#define NA_RCV (op_intrpt_type()==OPC_INTRPT_SELF && op_intrpt_code()==INT_RA_RCV)
#define ROUTE_UPDATE (op_intrpt_type()==OPC_INTRPT_SELF && op_intrpt_code()==INT_ROUTE_CHANGE)
#define NA_TIMER (op_intrpt_type()==OPC_INTRPT_SELF && op_intrpt_code()==INT_NA_TIMER&&0)
#define NA_REPLY (op_intrpt_type()==OPC_INTRPT_SELF && op_intrpt_code()==INT_NA_REPLY&&0)
#define CNSB_TIMER (op_intrpt_type()==OPC_INTRPT_SELF && op_intrpt_code()==INT_CNSB_TIMER&&0)
#define PROBE_TIMER (0)
#define NS_TIMER (0)
#define MAX_SIZE_ROUTE 8
#define MAX_SIZE_GROUP 16
// packet types definition
#define DATA_PACKET_TYPE 1
#define NA_PACKET_TYPE 2
#define PPROB_PACKET_TYPE 3
//Global var
char message[200]; // use as temporary variable to display some messages
//data structure
typedef struct
{
int Gp_route[MAX_SIZE_ROUTE];//sequence of groups
int size_route;//number of group node
}LINK_NODE;
//function declaration
Packet* gpr_extract_buffer(int destination_gpr_address);
void GPR_insert_buffer(Packet* pk_ptr, int destination_GPR_address);
/* End of Header Block */
#if !defined (VOSD_NO_FIN)
#undef BIN
#undef BOUT
#define BIN FIN_LOCAL_FIELD(_op_last_line_passed) = __LINE__ - _op_block_origin;
#define BOUT BIN
#define BINIT FIN_LOCAL_FIELD(_op_last_line_passed) = 0; _op_block_origin = __LINE__;
#else
#define BINIT
#endif /* #if !defined (VOSD_NO_FIN) */
/* State variable definitions */
typedef struct
{
/* Internal state tracking for FSM */
FSM_SYS_STATE
/* State Variables */
Objid my_module_id;
Objid my_node_id;
int my_mac_address;
int my_gpr_address;
int my_group_id;
LINK_NODE * GP_route_cache;
char * my_name;
} gpr_route_layer_queue_state;
#define pr_state_ptr ((gpr_route_layer_queue_state*) (OP_SIM_CONTEXT_PTR->mod_state_ptr))
#define my_module_id pr_state_ptr->my_module_id
#define my_node_id pr_state_ptr->my_node_id
#define my_mac_address pr_state_ptr->my_mac_address
#define my_gpr_address pr_state_ptr->my_gpr_address
#define my_group_id pr_state_ptr->my_group_id
#define GP_route_cache pr_state_ptr->GP_route_cache
#define my_name pr_state_ptr->my_name
/* These macro definitions will define a local variable called */
/* "op_sv_ptr" in each function containing a FIN statement. */
/* This variable points to the state variable data structure, */
/* and can be used from a C debugger to display their values. */
#undef FIN_PREAMBLE_DEC
#undef FIN_PREAMBLE_CODE
#if defined (OPD_PARALLEL)
# define FIN_PREAMBLE_DEC gpr_route_layer_queue_state *op_sv_ptr; OpT_Sim_Context * tcontext_ptr;
# define FIN_PREAMBLE_CODE \
if (VosS_Mt_Perform_Lock) \
VOS_THREAD_SPECIFIC_DATA_GET (VosI_Globals.simi_mt_context_data_key, tcontext_ptr, SimT_Context *); \
else \
tcontext_ptr = VosI_Globals.simi_sequential_context_ptr; \
op_sv_ptr = ((gpr_route_layer_queue_state *)(tcontext_ptr->mod_state_ptr));
#else
# define FIN_PREAMBLE_DEC gpr_route_layer_queue_state *op_sv_ptr;
# define FIN_PREAMBLE_CODE op_sv_ptr = pr_state_ptr;
#endif
/* Function Block */
#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ };
#endif
void GPR_route_init(LINK_NODE* cache, int n)
{
int i;
// init every gpr_address contained in the route to -1
for(i=0;i<MAX_SIZE_ROUTE;i++)
{
cache[n].Gp_route[i]=-1;
}
// init the size_route to 0
cache[n].size_route=0;
}
void GPR_tables_init()
{
int i;
int iGroupNum;
iGroupNum=MAX_SIZE_GROUP;
// memory allocation of the route cache => one route for each destination group
GP_route_cache=(LINK_NODE*)op_prg_mem_alloc(iGroupNum*sizeof(LINK_NODE));
// inititialisation of this route cache
for (i=0;i<iGroupNum;i++)
{
GPR_route_init(GP_route_cache,i);
}
}
void upper_layer_data_arrival (Packet* data_pk_ptr, int destination_gpr_address)
{
//encap the app data into gpr route packet
Packet * pk_ptr ;
Ici* iciptr;
// Create the data packet wich is going to transport the upper layer packet, and set its Type field
pk_ptr=op_pk_create_fmt("GPR_Data");
op_pk_nfd_set(pk_ptr,"Type",1);
//
// set the DEST field of the packet with this mac address
op_pk_nfd_set(pk_ptr,"DEST",destination_gpr_address);
// encap : insert the upper layer data in the gpr data packet
op_pk_nfd_set (pk_ptr, "data", data_pk_ptr);
//ARP
iciptr = op_ici_create("GPR_MAC_Dest_ICI");
op_ici_attr_set(iciptr,"MAC_Destination",MAC_BROADCAST);//ztl temp
op_ici_install(iciptr);
// op_pk_send( pk_ptr,TO_MAC_LAYER_STRM);
GPR_insert_buffer(pk_ptr,destination_gpr_address);
if (1)
{
op_prg_odb_bkpt("ztl_down");
}
}
void mac_data_arrival(Packet* pk_ptr)
{
//dencap the app data from gpr route packet
int source_gpr_address,destination_gpr_address;
Packet * data_pk_ptr;
// extract some usefull information from the data packet
op_pk_nfd_get (pk_ptr,"SRC",&source_gpr_address);
op_pk_nfd_get (pk_ptr,"DEST",&destination_gpr_address);
// if the current node is the destination and the final relay of the packet
if (my_gpr_address==destination_gpr_address|| destination_gpr_address==MAC_BROADCAST )
{
//decapulate the app data
op_pk_nfd_get (pk_ptr, "data", &data_pk_ptr);
op_pk_send( data_pk_ptr,TO_UPPER_LAYER_STRM);
}
if (1)
{
op_prg_odb_bkpt("ztl_up");
}
}
void GPR_message(const char* message)
{
printf("%s: ",my_name);
printf(message);
}
/*************************************************************/
/* Node BUFFER operation */
/*************************************************************/
/* This function inserts a data packet waiting to be transmitted
/* in the node buffer (queue) corresponding to its destination
/* Packet* pk_ptr: a pointer to the data packet to store
/* in the buffer
/* int destination_GPR_address: the gpr address of the data
/* packet destination
/*************************************************************/
void GPR_insert_buffer(Packet* pk_ptr, int destination_GPR_address)
{
// enqueue packet in the destination subqueue
printf("insert into queue %d",destination_GPR_address);
op_prg_odb_bkpt("ztl_queue");
if (op_subq_pk_insert(destination_GPR_address,pk_ptr,OPC_QPOS_TAIL)!=OPC_QINS_OK)
{
// if there is an error the packet is destroyed
GPR_message("Error, Can not insert packet in subqueue \n");
op_pk_destroy(pk_ptr);
}
else
{
// otherwise buffer statistic is updated
sprintf(message,"I am inserting in the buffer a data packet for %d to %d\n",destination_GPR_address);
GPR_message(message);
}
}
Packet* gpr_extract_buffer(int destination_gpr_address)
{
Packet* pk_ptr;
// if there is at list one packet in the destination suqueue
if (op_subq_empty(destination_gpr_address)==OPC_FALSE)
{
// extract the first packet from this queue
pk_ptr=op_subq_pk_remove(destination_gpr_address,OPC_QPOS_HEAD);
}
// if there is no packet in the destination subqueue
else
{
// will return OPC_NIL
pk_ptr=OPC_NIL;
}
// return the packet pointer
return(pk_ptr);
}
/* End of Function Block */
/* Undefine optional tracing in FIN/FOUT/FRET */
/* The FSM has its own tracing code and the other */
/* functions should not have any tracing. */
#undef FIN_TRACING
#define FIN_TRACING
#undef FOUTRET_TRACING
#define FOUTRET_TRACING
#if defined (__cplusplus)
extern "C" {
#endif
void gpr_route_layer_queue (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype gpr_route_layer_queue_init (int * init_block_ptr);
VosT_Address gpr_route_layer_queue_alloc (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype, int);
void gpr_route_layer_queue_diag (OP_SIM_CONTEXT_ARG_OPT);
void gpr_route_layer_queue_terminate (OP_SIM_CONTEXT_ARG_OPT);
void gpr_route_layer_queue_svar (void *, const char *, void **);
VosT_Fun_Status Vos_Define_Object (VosT_Obtype * obst_ptr, const char * name, unsigned int size, unsigned int init_obs, unsigned int inc_obs);
VosT_Address Vos_Alloc_Object_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Obtype ob_hndl);
VosT_Fun_Status Vos_Poolmem_Dealloc_MT (VOS_THREAD_INDEX_ARG_COMMA VosT_Address ob_ptr);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
gpr_route_layer_queue (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (gpr_route_layer_queue ());
if (1)
{
Packet * pk_ptr;
Ici* ici_dest_address;
int packet_type;
FSM_ENTER ("gpr_route_layer_queue")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (pre_ini) enter executives **/
FSM_STATE_ENTER_UNFORCED_NOLABEL (0, "pre_ini", "gpr_route_layer_queue [pre_ini enter execs]")
FSM_PROFILE_SECTION_IN (gpr_route_layer_queue [pre_ini enter execs], state0_enter_exec)
{
// ensure that each node has finised its pre-initialization before going in the init sate
op_intrpt_schedule_self(op_sim_time(),0);
my_module_id=op_id_self();
my_node_id=op_topo_parent(my_module_id);
op_ima_obj_attr_get(my_node_id,"wireless_lan_mac.Address",&my_mac_address);
op_ima_obj_attr_get(my_module_id,"GPR_address",&my_gpr_address);
op_ima_obj_attr_get(my_node_id,"GroupID",&my_group_id);
my_name=(char*)op_prg_mem_alloc(25*sizeof(char));
op_ima_obj_attr_get(my_node_id,"name",my_name);
//pk_ptr=op_pk_create(100);
//if (op_subq_pk_insert(10,pk_ptr,OPC_QPOS_TAIL)!=OPC_QINS_OK)
// {
// if there is an error the packet is destroyed
// }
op_prg_odb_bkpt("ztl_up");
}
FSM_PROFILE_SECTION_OUT (gpr_route_layer_queue [pre_ini enter execs], state0_enter_exec)
/** blocking after enter executives of unforced state. **/
FSM_EXIT (1,"gpr_route_layer_queue")
/** state (pre_ini) exit executives **/
FSM_STATE_EXIT_UNFORCED (0, "pre_ini", "gpr_route_layer_queue [pre_ini exit execs]")
FSM_PROFILE_SECTION_IN (gpr_route_layer_queue [pre_ini exit execs], state0_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (gpr_route_layer_queue [pre_ini exit execs], state0_exit_exec)
/** state (pre_ini) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "pre_ini", "ini")
/*---------------------------------------------------------*/
/** state (ini) enter executives **/
FSM_STATE_ENTER_FORCED (1, "ini", state1_enter_exec, "gpr_route_layer_queue [ini enter execs]")
FSM_PROFILE_SECTION_IN (gpr_route_layer_queue [ini enter execs], state1_enter_exec)
{
}
FSM_PROFILE_SECTION_OUT (gpr_route_layer_queue [ini enter execs], state1_enter_exec)
/** state (ini) exit executives **/
FSM_STATE_EXIT_FORCED (1, "ini", "gpr_route_layer_queue [ini exit execs]")
FSM_PROFILE_SECTION_IN (gpr_route_layer_queue [ini exit execs], state1_exit_exec)
{
}
FSM_PROFILE_SECTION_OUT (gpr_route_layer_queue [ini exit execs], state1_exit_exec)
/** state (ini) transition processing **/
FSM_TRANSIT_FORCE (2, state2_enter_exec, ;, "default", "", "ini", "idle")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -