sl_aloha.zip sl_aloha_ip.pr.c
> sl_aloha_ip.pr.c, change:,size:22303b
/* Process model C form file: sl_aloha_ip.pr.c */
/* Portions of this file copyright , 1998 by MIL 3, Inc. */
/* This variable carries the header into the object file */
static const char sl_aloha_ip_pr_c [] = "MIL_3_Tfile_Hdr_ 60L 30A modeler_radio 7 3D117 1 awurst jclark 0 0 none none 0 0 none 0 0 0 0 0 0";
/* OPNET system definitions */
#include &opnet.h>
#if defined (__cplusplus)
extern "C" {
FSM_EXT_DECS
#if defined (__cplusplus)
} /* end of 'extern "C"' */
/* Header Block */
#include "nato.h"
#include "ip_addr_v4.h"
#include "ip_dgram_sup.h"
#include "oms_pr.h"
#include "ip_rte_v4.h"
#include &math.h>
#define MIL
#define SUB_Q
#define TX_PACKET
#define GATEWAY_NODE 0
#define REMOTE_NODE
/* Conditional macros */
#define UPPER_ARRIVAL ((intrpt_type == OPC_I***PT_STRM) && (intrpt_strm == ip_in_strm))
#define LOWER_ARRIVAL ((intrpt_type == OPC_I***PT_STRM) && (intrpt_strm == rx_in_strm))
#define Q_EMPTY
(op_subq_empty (SUB_Q))
#define BEG_SLOT
((intrpt_type == OPC_I***PT_SELF) && (intrpt_code == TX_PACKET))
#define SET_SLOT
(op_intrpt_schedule_self ( op_sim_time() + slot_length + guard_band, TX_PACKET))
static void put_in_q (void);
static void send_to_ip (void);
/* End of Header Block */
#if !defined (VOSD_NO_FIN)
#undef BIN
#undef BOUT
#define BIN
_fstack_local_info.last_line_passed = __LINE__ - _block_
#define BOUT BIN
#define BINIT _fstack_local_info.last_line_passed = 0; _block_origin = __LINE__;
#define BINIT
#endif /* #if !defined (VOSD_NO_FIN) */
/* State variable definitions */
typedef struct
/* Internal state tracking for FSM */
FSM_SYS_STATE
/* State Variables */
Stathandle
chan_access_local_
Stathandle
chan_access_global_
IpT_Address
} sl_aloha_ip_
#define pr_state_ptr
((sl_aloha_ip_state*) SimI_Mod_State_Ptr)
#define slot_length
pr_state_ptr->slot_length
#define guard_band
pr_state_ptr->guard_band
#define chan_access_local_handle
pr_state_ptr->chan_access_local_handle
#define chan_access_global_handle
pr_state_ptr->chan_access_global_handle
#define ip_address
pr_state_ptr->ip_address
#define rx_in_strm
pr_state_ptr->rx_in_strm
#define ip_in_strm
pr_state_ptr->ip_in_strm
#define tx_out_strm
pr_state_ptr->tx_out_strm
#define ip_out_strm
pr_state_ptr->ip_out_strm
#define mod_objid
pr_state_ptr->mod_objid
#define node_objid
pr_state_ptr->node_objid
#define node_type
pr_state_ptr->node_type
/* This macro definition 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
#define FIN_PREAMBLE sl_aloha_ip_state *op_sv_ptr = pr_state_
/* Function Block */
enum { _block_origin = __LINE__ };
static void
put_in_q (void)
FIN (put_in_q ())
/* get the packet from the strm. */
pkptr = op_pk_get (ip_in_strm);
/* insert in q. */
op_subq_pk_insert (SUB_Q, pkptr, OPC_QPOS_TAIL);
static void
send_to_ip (void)
IpT_Dgram_Fields *pk_fd_
FIN (send_to_ip ())
/* Obtain the packet off the incoming stream. */
pk_ptr = op_pk_get (rx_in_strm);
/* Access the fields from the packet. */
op_pk_nfd_access (pk_ptr, "fields", &pk_fd_ptr);
/* Check to see if this packet should be sent to IP or not. */
if (node_type == GATEWAY_NODE)
if (pk_fd_ptr->src_addr == ip_address)
op_pk_destroy (pk_ptr);
op_pk_send (pk_ptr, ip_out_strm);
if (pk_fd_ptr->dest_addr != ip_address)
op_pk_destroy (pk_ptr);
op_pk_send (pk_ptr, ip_out_strm);
/* End of Function Block */
#if defined (__cplusplus)
extern "C" {
void sl_aloha_ip (void);
Compcode sl_aloha_ip_init (void **);
void sl_aloha_ip_diag (void);
void sl_aloha_ip_terminate (void);
void sl_aloha_ip_svar (void *, const char *, char **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
/* Process model interrupt handling procedure */
sl_aloha_ip (void)
int _block_origin = 0;
FIN (sl_aloha_ip ());
/* Packet pointer*/
/* The current time. */
double current_
/* current slot.*/
/* Time of next time slot. */
double next_time_
double chan_access_
proc_record_handle_list_
record_handle_list_
OmsT_Pr_Handle
process_record_
IpT_Interface_Info* ip_iface_elem_
ip_module_
ip_iface_table_
FSM_ENTER (sl_aloha_ip)
FSM_BLOCK_SWITCH
/*---------------------------------------------------------*/
/** state (q_empty) enter executives **/
FSM_STATE_ENTER_UNFORCED (0, state0_enter_exec, "q_empty", "sl_aloha_ip () [q_empty enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (1,sl_aloha_ip)
/** state (q_empty) exit executives **/
FSM_STATE_EXIT_UNFORCED (0, state0_exit_exec, "q_empty", "sl_aloha_ip () [q_empty exit execs]")
/* Obtain the interrupt type.
intrpt_type = op_intrpt_type ();
/* If this is a stream interrupt, obtain the stream.
if (intrpt_type == OPC_I***PT_STRM)
intrpt_strm = op_intrpt_strm ();
/** state (q_empty) transition processing **/
FSM_INIT_COND (UPPER_ARRIVAL)
FSM_TEST_COND (LOWER_ARRIVAL)
FSM_TEST_LOGIC ("q_empty")
FSM_TRANSIT_SWITCH
FSM_CASE_TRANSIT (0, 1, state1_enter_exec, put_in_q();)
FSM_CASE_TRANSIT (1, 0, state0_enter_exec, send_to_ip();)
/*---------------------------------------------------------*/
/** state (decide_next_time_slot) enter executives **/
FSM_STATE_ENTER_FORCED (1, state1_enter_exec, "decide_next_time_slot", "sl_aloha_ip () [decide_next_time_slot enter execs]")
/* Check the time of the global clock. */
current_time = op_sim_time ();
/* Get the current time slot. */
time_slot = floor ((current_time * MIL) / ((slot_length + guard_band) * MIL));
/* Figure out the next time slot. */
next_time_slot = (time_slot + 1) * (slot_length + guard_band);
/* Schedule a self intrpt for the next time slot*/
op_intrpt_schedule_self (next_time_slot, TX_PACKET);
/** state (decide_next_time_slot) exit executives **/
FSM_STATE_EXIT_FORCED (1, state1_exit_exec, "decide_next_time_slot", "sl_aloha_ip () [decide_next_time_slot exit execs]")
/** state (decide_next_time_slot) transition processing **/
FSM_TRANSIT_FORCE (2, state2_enter_exec, ;)
/*---------------------------------------------------------*/
/** state (q_not_empty) enter executives **/
FSM_STATE_ENTER_UNFORCED (2, state2_enter_exec, "q_not_empty", "sl_aloha_ip () [q_not_empty enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (5,sl_aloha_ip)
/** state (q_not_empty) exit executives **/
FSM_STATE_EXIT_UNFORCED (2, state2_exit_exec, "q_not_empty", "sl_aloha_ip () [q_not_empty exit execs]")
/* Obtain the interrupt type.
intrpt_type = op_intrpt_type ();
/* If this is a stream interrupt, obtain the stream.
if (intrpt_type == OPC_I***PT_STRM)
intrpt_strm = op_intrpt_strm ();
/* If this is a self interrupt, obtain the code.
if (intrpt_type == OPC_I***PT_SELF)
intrpt_code = op_intrpt_code ();
/** state (q_not_empty) transition processing **/
FSM_INIT_COND (BEG_SLOT)
FSM_TEST_COND (UPPER_ARRIVAL)
FSM_TEST_COND (LOWER_ARRIVAL)
FSM_TEST_LOGIC ("q_not_empty")
FSM_TRANSIT_SWITCH
FSM_CASE_TRANSIT (0, 3, state3_enter_exec, ;)
FSM_CASE_TRANSIT (1, 2, state2_enter_exec, put_in_q();)
FSM_CASE_TRANSIT (2, 2, state2_enter_exec, send_to_ip();)
/*---------------------------------------------------------*/
/** state (transmit_packet) enter executives **/
FSM_STATE_ENTER_FORCED (3, state3_enter_exec, "transmit_packet", "sl_aloha_ip () [transmit_packet enter execs]")
/* Remove the packet from the Queue. */
pkptr = op_subq_pk_remove (SUB_Q, OPC_QPOS_HEAD);
/* determine and record channel acces delay */
chan_access_delay = op_sim_time () - op_pk_creation_time_get (pkptr);
op_stat_write (chan_access_global_handle,
chan_access_delay * 1000.0);
op_stat_write (chan_access_local_handle,
chan_access_delay * 1000.0);
/* Send the packet at the begining of the slot. */
op_pk_send (pkptr, tx_out_strm);
/** state (transmit_packet) exit executives **/
FSM_STATE_EXIT_FORCED (3, state3_exit_exec, "transmit_packet", "sl_aloha_ip () [transmit_packet exit execs]")
/** state (transmit_packet) transition processing **/
FSM_INIT_COND (Q_EMPTY)
FSM_TEST_COND (!Q_EMPTY)
FSM_TEST_LOGIC ("transmit_packet")
FSM_TRANSIT_SWITCH
FSM_CASE_TRANSIT (0, 0, state0_enter_exec, ;)
FSM_CASE_TRANSIT (1, 2, state2_enter_exec, SET_SLOT;)
/*---------------------------------------------------------*/
/** state (init) enter executives **/
FSM_STATE_ENTER_UNFORCED (4, state4_enter_exec, "init", "sl_aloha_ip () [init enter execs]")
/* Obtain the module and node object ids. */
mod_objid = op_id_self ();
node_objid = op_topo_parent (mod_objid);
/* get the promoted attributes at run time */
slot_length = 0.01;
if (op_ima_sim_attr_exists ("ALOHA Slot Length") == OPC_TRUE)
op_ima_sim_attr_get (OPC_IMA_DOUBLE, "ALOHA Slot Length", &slot_length);
guard_band = 0.001;
if (op_ima_sim_attr_exists ("ALOHA Guard Band") == OPC_TRUE)
op_ima_sim_attr_get (OPC_IMA_DOUBLE, "ALOHA Guard Band", &guard_band);
/* get the statistics handles */
chan_access_local_handle = op_stat_reg ("Chan Access Delay (msec)",
OPC_STAT_INDEX_NONE, OPC_STAT_LOCAL);
chan_access_global_handle = op_stat_reg ("Chan Access Delay (msec)",
OPC_STAT_INDEX_NONE, OPC_STAT_GLOBAL);
/* Obtain the object id of the connected transmitter. */
tx_objid = op_topo_assoc (mod_objid, OPC_TOPO_ASSOC_OUT, OPC_OBJMTYPE_XMIT, 0);
/* Obtain the index of the interconnecting stream. */
strm_objid = op_topo_connect (mod_objid, tx_objid, OPC_OBJTYPE_STRM, 0);
op_ima_obj_attr_get (strm_objid, "src stream", &tx_out_strm);
/* Obtain the object id of the connected receiver. */
rx_objid = op_topo_assoc (mod_objid, OPC_TOPO_ASSOC_IN, OPC_OBJMTYPE_RECV, 0);
/* Obtain the index of the interconnecting stream. */
strm_objid = op_topo_connect (rx_objid, mod_objid, OPC_OBJTYPE_STRM, 0);
op_ima_obj_attr_get (strm_objid, "dest stream", &rx_in_strm);
/* Obtain the model attribute to determine if this mac */
/* resides under an IP gateway or not.
This is a workaround */
/* in order to not make modifications to aloha to include */
/* mac addresses. */
op_ima_obj_attr_get (mod_objid, "Node Type", &node_type);
/* Schedule a self interrupt. */
op_intrpt_schedule_self (op_sim_time (), 0);
/** blocking after enter executives of unforced state. **/
FSM_EXIT (9,sl_aloha_ip)
/** state (init) exit executives **/
FSM_STATE_EXIT_UNFORCED (4, state4_exit_exec, "init", "sl_aloha_ip () [init exit execs]")
/** state (init) transition processing **/
FSM_TRANSIT_FORCE (5, state5_enter_exec, ;)
/*---------------------------------------------------------*/
/** state (wait0) enter executives **/
FSM_STATE_ENTER_UNFORCED (5, state5_enter_exec, "wait0", "sl_aloha_ip () [wait0 enter execs]")
/* Schedule a self interrupt. */
op_intrpt_schedule_self (op_sim_time (), 0);
/** blocking after enter executives of unforced state. **/
FSM_EXIT (11,sl_aloha_ip)
/** state (wait0) exit executives **/
FSM_STATE_EXIT_UNFORCED (5, state5_exit_exec, "wait0", "sl_aloha_ip () [wait0 exit execs]")
/** state (wait0) transition processing **/
FSM_TRANSIT_FORCE (6, state6_enter_exec, ;)
/*---------------------------------------------------------*/
/** state (wait1) enter executives **/
FSM_STATE_ENTER_UNFORCED (6, state6_enter_exec, "wait1", "sl_aloha_ip () [wait1 enter execs]")
/* Schedule a self interrupt. */
op_intrpt_schedule_self (op_sim_time (), 0);
/** blocking after enter executives of unforced state. **/
FSM_EXIT (13,sl_aloha_ip)
/** state (wait1) exit executives **/
FSM_STATE_EXIT_UNFORCED (6, state6_exit_exec, "wait1", "sl_aloha_ip () [wait1 exit execs]")
Obtain the IP interface information for the local
/* ip process from the model-wide registry.
proc_record_handle_list_ptr = op_prg_list_create ();
oms_pr_process_discover (OPC_OBJID_INVALID, proc_record_handle_list_ptr,
"protocol",
OMSC_PR_STRING,
"node objid", OMSC_PR_OBJID,
node_objid,
record_handle_list_size = op_prg_list_size (proc_record_handle_list_ptr);
if (record_handle_list_size != 1)
An error should be created if there are more
/* than one ip process in the local node, or
/* if no match is found.
op_sim_end ("Error: either zero or several ip processes found in the local node", "", "", "");
/* Obtain a handle on the process record.
process_record_handle = (OmsT_Pr_Handle) op_prg_list_access (proc_record_handle_list_ptr, OPC_LISTPOS_HEAD);
/* Obtain a pointer to the ip interface table.
oms_pr_attr_get (process_record_handle, "interface information", OMSC_PR_ADDRESS, &ip_info_ptr);
/* Obtain the module objid for the IP module.
oms_pr_attr_get (process_record_handle, "module objid", OMSC_PR_OBJID, &ip_module_objid);
Deallocate no longer needed process registry
/* information.
while (op_prg_list_size (proc_record_handle_list_ptr))
op_prg_list_remove (proc_record_handle_list_ptr, OPC_LISTPOS_HEAD);
op_prg_mem_free (proc_record_handle_list_ptr);
Determine the output stream number from the IP
/* module to the ALOHA module.
if (oms_tan_neighbor_streams_find (ip_module_objid, mod_objid, &instrm, &outstrm) == OPC_COMPCODE_FAILURE)
op_sim_end ("Error: the IP and ALOHA module are not connected at all", "", "", "");
Look for the local IP net and node numbers
/* corresponding to the above port number.
ip_iface_table_size = op_prg_list_size (ip_info_ptr->ip_iface_table_ptr);
/* Obtain the IP address for this interface.
for (i=0; i & ip_iface_table_ i++)
ip_iface_elem_ptr = (IpT_Interface_Info*) op_prg_list_access (ip_info_ptr->ip_iface_table_ptr, i);
if (ip_iface_elem_ptr->port_num == outstrm)
ip_address = ip_iface_elem_ptr->addr_range_ptr->
ip_addrs_found = OPC_TRUE;
ip_addrs_found = OPC_FALSE;
Determine the output stream number from the ALOHA */
/* module to the IP module.
if (oms_tan_neighbor_streams_find (mod_objid, ip_module_objid, &ip_in_strm, &ip_out_strm) == OPC_COMPCODE_FAILURE)
op_sim_end ("Error: the ALOHA and IP modules are not connected at all", "", "", "");
/** state (wait1) transition processing **/
FSM_TRANSIT_FORCE (0, state0_enter_exec, ;)
/*---------------------------------------------------------*/
FSM_EXIT (4,sl_aloha_ip)
#if defined (__cplusplus)
void Vos_Vnop (void);
sl_aloha_ip_init (void ** gen_state_pptr)
int _block_origin = 0;
static VosT_Cm_Obtype obtype = OPC_NIL;
FIN (sl_aloha_ip_init (gen_state_pptr))
if (obtype == OPC_NIL)
/* Initialize memory management */
if (Vos_Catmem_Register ("proc state vars (sl_aloha_ip)",
sizeof (sl_aloha_ip_state), Vos_Vnop, &obtype) == VOSC_FAILURE)
FRET (OPC_COMPCODE_FAILURE)
*gen_state_pptr = Vos_Catmem_Alloc (obtype, 1);
if (*gen_state_pptr == OPC_NIL)
FRET (OPC_COMPCODE_FAILURE)
/* Initialize FSM handling */
((sl_aloha_ip_state *)(*gen_state_pptr))->current_block = 8;
FRET (OPC_COMPCODE_SUCCESS)
sl_aloha_ip_diag (void)
int _block_origin = __LINE__;
FIN (sl_aloha_ip_diag ())
/* Packet pointer*/
/* The current time. */
double current_
/* current slot.*/
/* Time of next time slot. */
double next_time_
double chan_access_
proc_record_handle_list_
record_handle_list_
OmsT_Pr_Handle
process_record_
IpT_Interface_Info* ip_iface_elem_
ip_module_
ip_iface_table_
/* Diagnostic Block */
/* End of Diagnostic Block */
sl_aloha_ip_terminate (void)
int _block_origin = __LINE__;
FIN (sl_aloha_ip_terminate (void))
/* Packet pointer*/
/* The current time. */
double current_
/* current slot.*/
/* Time of next time slot. */
double next_time_
double chan_access_
proc_record_handle_list_
record_handle_list_
OmsT_Pr_Handle
process_record_
IpT_Interface_Info* ip_iface_elem_
ip_module_
ip_iface_table_
/* No Termination Block */
Vos_Catmem_Dealloc (pr_state_ptr);
/* Undefine shortcuts to state variables to avoid */
/* syntax error in direct access to fields of */
/* local variable prs_ptr in sl_aloha_ip_svar function. */
#undef slot_length
#undef guard_band
#undef chan_access_local_handle
#undef chan_access_global_handle
#undef ip_address
#undef rx_in_strm
#undef ip_in_strm
#undef tx_out_strm
#undef ip_out_strm
#undef mod_objid
#undef node_objid
#undef node_type
sl_aloha_ip_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
sl_aloha_ip_state
FIN (sl_aloha_ip_svar (gen_ptr, var_name, var_p_ptr))
*var_p_ptr = (char *)VOS_NIL;
prs_ptr = (sl_aloha_ip_state *)gen_
if (Vos_String_Equal ("slot_length" , var_name))
*var_p_ptr = (char *) (&prs_ptr->slot_length);
goto func_
if (Vos_String_Equal ("guard_band" , var_name))
*var_p_ptr = (char *) (&prs_ptr->guard_band);
goto func_
if (Vos_String_Equal ("chan_access_local_handle" , var_name))
*var_p_ptr = (char *) (&prs_ptr->chan_access_local_handle);
goto func_
if (Vos_String_Equal ("chan_access_global_handle" , var_name))
*var_p_ptr = (char *) (&prs_ptr->chan_access_global_handle);
goto func_
if (Vos_String_Equal ("ip_address" , var_name))
*var_p_ptr = (char *) (&prs_ptr->ip_address);
goto func_
if (Vos_String_Equal ("rx_in_strm" , var_name))
*var_p_ptr = (char *) (&prs_ptr->rx_in_strm);
goto func_
if (Vos_String_Equal ("ip_in_strm" , var_name))
*var_p_ptr = (char *) (&prs_ptr->ip_in_strm);
goto func_
if (Vos_String_Equal ("tx_out_strm" , var_name))
*var_p_ptr = (char *) (&prs_ptr->tx_out_strm);
goto func_
if (Vos_String_Equal ("ip_out_strm" , var_name))
*var_p_ptr = (char *) (&prs_ptr->ip_out_strm);
goto func_
if (Vos_String_Equal ("mod_objid" , var_name))
*var_p_ptr = (char *) (&prs_ptr->mod_objid);
goto func_
if (Vos_String_Equal ("node_objid" , var_name))
*var_p_ptr = (char *) (&prs_ptr->node_objid);
goto func_
if (Vos_String_Equal ("node_type" , var_name))
*var_p_ptr = (char *) (&prs_ptr->node_type);
goto func_
func_return:您所在位置: &
 &  & 
OPNET常见错误.pdf50页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
文档加载中...广告还剩秒
需要金币:100 &&
OPNET常见错误.pdf
你可能关注的文档:
??????????
??????????
OPNET lvzhb_ 1unresolved externals symbol: · · · 2, unreferenced local variables
warning 3 · · 4
5output stream index
is out-of-range.
8choose statistics 9
Program Abort reported by process
burst_create
top.subnet_0.node_2.assembly_1
4.0298 , EV
6197 , MOD
top.subnet_0.node_2.assembly_1 , KP
op_sar_segbuf_pk_insert Packet pointer references unowned packet
17FAQ for OPNET from cnl.gmu.edu
1.Binding Problem Set these variables in your env_db file in your op_models directory:
comp_prog: "/opt/bin/gcc"
bind_libs: "-L/usr/ucblib -L/usr/lib -lucb -lresolv -lsocket -lnsl -lelf"
2.Simulation Terminated Abnormally. a. Don't start opnet from the xterm with black background
site b. Check for logic
process model c. See OPNET Debugger
ODB ////****
OPNET Debugger
ODB One of the features in OPNET to help you trace your errors is the Debugger.This tool is also useful
when the simulation program gets stuck at run time or when the simulation is taking too long. You
run the debugger from a Unix C Shell.
simulation,
information concerning that error. In that banner you will see two important fields, event number displayed ev #
displayed T #
. These are the event number and time at which the error
Now, run the simulation using -debug. Once in ODB, there are two commands you can use to go to
that error. The prefered method is to go to the error via the event number. The command evstop will
example odb
The other method is to use tstop and go to the time the error occured.
example odb
tstop time
Once at the error, type "full" to get into full trace mode and type next to continue. This should show
you where the error occured.
example odb
正在加载中,请稍后...