📄 sl_aloha_ip.pr.c
字号:
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, "init", "sl_aloha_ip () [init exit execs]")
{
}
/** state (init) transition processing **/
FSM_TRANSIT_FORCE (5, state5_enter_exec, ;, "default", "", "init", "wait0")
/*---------------------------------------------------------*/
/** 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, "wait0", "sl_aloha_ip () [wait0 exit execs]")
{
}
/** state (wait0) transition processing **/
FSM_TRANSIT_FORCE (6, state6_enter_exec, ;, "default", "", "wait0", "wait1")
/*---------------------------------------------------------*/
/** 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, "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, "ip",
"node objid", OMSC_PR_OBJID, node_objid,
OPC_NIL);
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", "", "", "");
}
else
{
/* 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_size; 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->address;
ip_addrs_found = OPC_TRUE;
break;
}
else
{
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, ;, "default", "", "wait1", "q_empty")
/*---------------------------------------------------------*/
}
FSM_EXIT (4,sl_aloha_ip)
}
}
#if defined (__cplusplus)
extern "C" {
#endif
extern VosT_Fun_Status Vos_Catmem_Register (const char * , int , VosT_Void_Null_Proc, VosT_Address *);
extern VosT_Address Vos_Catmem_Alloc (VosT_Address, size_t);
extern VosT_Fun_Status Vos_Catmem_Dealloc (VosT_Address);
#if defined (__cplusplus)
}
#endif
Compcode
sl_aloha_ip_init (void ** gen_state_pptr)
{
int _block_origin = 0;
static VosT_Address 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)
}
else
{
/* Initialize FSM handling */
((sl_aloha_ip_state *)(*gen_state_pptr))->current_block = 8;
FRET (OPC_COMPCODE_SUCCESS)
}
}
void
sl_aloha_ip_diag (void)
{
int _block_origin = __LINE__;
FIN (sl_aloha_ip_diag ())
if (1)
{
/* Packet pointer*/
Packet *pkptr;
/* The current time. */
double current_time;
/* current slot.*/
int time_slot;
/* Time of next time slot. */
double next_time_slot;
double chan_access_delay;
int intrpt_type;
int intrpt_strm;
int intrpt_code;
List* proc_record_handle_list_ptr;
Objid tx_objid;
Objid rx_objid;
Objid strm_objid;
Objid instrm;
Objid outstrm;
int record_handle_list_size;
OmsT_Pr_Handle process_record_handle;
IpT_Interface_Info* ip_iface_elem_ptr;
int i;
IpT_Info* ip_info_ptr;
Objid ip_module_objid;
int ip_iface_table_size;
Boolean ip_addrs_found;
/* Diagnostic Block */
BINIT
/* End of Diagnostic Block */
}
FOUT;
}
void
sl_aloha_ip_terminate (void)
{
int _block_origin = __LINE__;
FIN (sl_aloha_ip_terminate (void))
if (1)
{
/* Packet pointer*/
Packet *pkptr;
/* The current time. */
double current_time;
/* current slot.*/
int time_slot;
/* Time of next time slot. */
double next_time_slot;
double chan_access_delay;
int intrpt_type;
int intrpt_strm;
int intrpt_code;
List* proc_record_handle_list_ptr;
Objid tx_objid;
Objid rx_objid;
Objid strm_objid;
Objid instrm;
Objid outstrm;
int record_handle_list_size;
OmsT_Pr_Handle process_record_handle;
IpT_Interface_Info* ip_iface_elem_ptr;
int i;
IpT_Info* ip_info_ptr;
Objid ip_module_objid;
int ip_iface_table_size;
Boolean ip_addrs_found;
/* No Termination Block */
}
Vos_Catmem_Dealloc (pr_state_ptr);
FOUT;
}
/* 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
void
sl_aloha_ip_svar (void * gen_ptr, const char * var_name, char ** var_p_ptr)
{
sl_aloha_ip_state *prs_ptr;
FIN (sl_aloha_ip_svar (gen_ptr, var_name, var_p_ptr))
if (var_name == OPC_NIL)
{
*var_p_ptr = (char *)OPC_NIL;
FOUT;
}
prs_ptr = (sl_aloha_ip_state *)gen_ptr;
if (strcmp ("slot_length" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->slot_length);
FOUT;
}
if (strcmp ("guard_band" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->guard_band);
FOUT;
}
if (strcmp ("chan_access_local_handle" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->chan_access_local_handle);
FOUT;
}
if (strcmp ("chan_access_global_handle" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->chan_access_global_handle);
FOUT;
}
if (strcmp ("ip_address" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->ip_address);
FOUT;
}
if (strcmp ("rx_in_strm" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->rx_in_strm);
FOUT;
}
if (strcmp ("ip_in_strm" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->ip_in_strm);
FOUT;
}
if (strcmp ("tx_out_strm" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->tx_out_strm);
FOUT;
}
if (strcmp ("ip_out_strm" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->ip_out_strm);
FOUT;
}
if (strcmp ("mod_objid" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->mod_objid);
FOUT;
}
if (strcmp ("node_objid" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->node_objid);
FOUT;
}
if (strcmp ("node_type" , var_name) == 0)
{
*var_p_ptr = (char *) (&prs_ptr->node_type);
FOUT;
}
*var_p_ptr = (char *)OPC_NIL;
FOUT;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -