/* Process model C form file: z_flood_node_proc.pr.c */
/* Portions of this file copyright 1986-2008 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char z_flood_node_proc_pr_c [] = "MIL_3_Tfile_Hdr_ 145A 30A modeler 7 528A2B8F 528A2B8F 1 yanhc yanhongcheng 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 1bcc 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
#define APP_STRM 4
#define ARV (op_intrpt_type()==OPC_INTRPT_STRM && \
op_intrpt_strm()==APP_STRM)
#define RCV (op_intrpt_type()==OPC_INTRPT_STRM && \
op_intrpt_strm()!=APP_STRM)
#define SRV (op_intrpt_type()==OPC_INTRPT_SELF)
#define MAX_SEQ 255
// routing table entry definition
typedef struct{
int seq_number;
int in_strm[4]; //1 means in, 0 means no in
}structseq;
typedef struct{
int srcaddr;
structseq seq_num[MAX_SEQ];
int seq_it; // iterator
}rttable_entry;
/* 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 node_id ;
int seq_no_self ; /* self sequence increment */
List * list_rttable ;
} z_flood_node_proc_state;
#define node_id op_sv_ptr->node_id
#define seq_no_self op_sv_ptr->seq_no_self
#define list_rttable op_sv_ptr->list_rttable
/* 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
#define FIN_PREAMBLE_DEC z_flood_node_proc_state *op_sv_ptr;
#define FIN_PREAMBLE_CODE \
op_sv_ptr = ((z_flood_node_proc_state *)(OP_SIM_CONTEXT_PTR->_op_mod_state_ptr));
/* Function Block */
#if !defined (VOSD_NO_FIN)
enum { _op_block_origin = __LINE__ + 2};
#endif
// Routing table manipulating functions
rttable_entry * rttable_lookup(int src_addr)
{
int rt_size, i;
rttable_entry * rt_entry;
FIN(rttable_lookup(src_addr));
rt_size = op_prg_list_size(list_rttable);
for(i=0; i<rt_size; i++)
{
rt_entry = op_prg_list_access(list_rttable, i);
if(rt_entry->srcaddr == src_addr)
{
FRET(rt_entry);
}
}
FRET(OPC_NIL);
}
void rttable_addEntry(int src_addr, int seq, int instrm)
{
rttable_entry * rt_entry;
int i;
FIN(rttable_addEntry(src_addr, seq, instrm));
rt_entry = (rttable_entry *)op_prg_mem_alloc(sizeof(rttable_entry));
rt_entry->srcaddr = src_addr;
rt_entry->seq_it = 1;
for(i=0; i<MAX_SEQ; i++)
{
rt_entry->seq_num[i].seq_number = 0xFFFF;
}
rt_entry->seq_num[0].seq_number = seq;
rt_entry->seq_num[0].in_strm[instrm] = 1;
op_prg_list_insert(list_rttable, rt_entry, OPC_LISTPOS_TAIL);
FOUT;
}
int rttable_isnewSeq(rttable_entry * rt_entry, int seq)
{
int i;
FIN(rttable_isnewSeq(rt_entry, seq));
for(i=0; i<MAX_SEQ; i++)
{
if(rt_entry->seq_num[i].seq_number == seq)
FRET(0);
}
FRET(1);
}
void rttable_addSeq(rttable_entry * rt_entry, int seq, int instrm)
{
FIN(rttable_addSeq(rt_entry, seq, instrm));
rt_entry->seq_num[rt_entry->seq_it].seq_number = seq;
rt_entry->seq_num[rt_entry->seq_it].in_strm[instrm] = 1;
rt_entry->seq_it = (rt_entry->seq_it + 1) % 0xFFFF;
FOUT;
}
void rttable_addinstrm(rttable_entry * rt_entry, int seq, int instrm)
{
int i;
FIN(rttable_addinstrm(rt_entry, seq, instrm));
for(i=0; i<MAX_SEQ; i++)
{
if(rt_entry->seq_num[i].seq_number == seq)
rt_entry->seq_num[i].in_strm[instrm] = 1;
}
FOUT;
}
void rttable_getstrm(int src_addr, int seq, int in_strm[])
{
int i;
rttable_entry * rt_entry;
FIN(rttable_getstrm(src_addr, seq, in_strm));
rt_entry = rttable_lookup(src_addr);
for(i=0; i<MAX_SEQ; i++)
{
if(rt_entry->seq_num[i].seq_number == seq)
{
in_strm[0] = rt_entry->seq_num[i].in_strm[0];
in_strm[1] = rt_entry->seq_num[i].in_strm[1];
in_strm[2] = rt_entry->seq_num[i].in_strm[2];
in_strm[3] = rt_entry->seq_num[i].in_strm[3];
}
}
FOUT;
}
/* 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 z_flood_node_proc (OP_SIM_CONTEXT_ARG_OPT);
VosT_Obtype _op_z_flood_node_proc_init (int * init_block_ptr);
void _op_z_flood_node_proc_diag (OP_SIM_CONTEXT_ARG_OPT);
void _op_z_flood_node_proc_terminate (OP_SIM_CONTEXT_ARG_OPT);
VosT_Address _op_z_flood_node_proc_alloc (VosT_Obtype, int);
void _op_z_flood_node_proc_svar (void *, const char *, void **);
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif
/* Process model interrupt handling procedure */
void
z_flood_node_proc (OP_SIM_CONTEXT_ARG_OPT)
{
#if !defined (VOSD_NO_FIN)
int _op_block_origin = 0;
#endif
FIN_MT (z_flood_node_proc ());
{
FSM_ENTER ("z_flood_node_proc")
FSM_BLOCK_SWITCH
{
/*---------------------------------------------------------*/
/** state (INIT) enter executives **/
FSM_STATE_ENTER_FORCED_NOLABEL (0, "INIT", "z_flood_node_proc [INIT enter execs]")
FSM_PROFILE_SECTION_IN ("z_flood_node_proc [INIT enter execs]", state0_enter_exec)
{
// get node id, init the seq
node_id = op_topo_parent(op_id_self()) - 2;
seq_no_self = 0;
list_rttable = op_prg_list_create();
op_intrpt_schedule_self(op_sim_time()+0.5, 0);
}
FSM_PROFILE_SECTION_OUT (state0_enter_exec)
/** state (INIT) exit executives **/
FSM_STATE_EXIT_FORCED (0, "INIT", "z_flood_node_proc [INIT exit execs]")
/** state (INIT) transition processing **/
FSM_TRANSIT_FORCE (1, state1_enter_exec, ;, "default", "", "INIT", "BRANCH", "tr_0", "z_flood_node_proc [INIT -> BRANCH : default / ]")
/*---------------------------------------------------------*/
/** state (BRANCH) enter executives **/
FSM_STATE_ENTER_UNFORCED (1, "BRANCH", state1_enter_exec, "z_flood_node_proc [BRANCH enter execs]")
/** blocking after enter executives of unforced state. **/
FSM_EXIT (3,"z_flood_node_proc")
/** state (BRANCH) exit executives **/
FSM_STATE_EXIT_UNFORCED (1, "BRANCH", "z_flood_node_proc [BRANCH exit execs]")
/** state (BRANCH) transition processing **/
FSM_PROFILE_SECTION_IN ("z_flood_node_proc [BRANCH trans conditions]", state1_trans_conds)
FSM_INIT_COND (SRV)
FSM_TEST_COND (ARV)
FSM_TEST_COND (RCV)
FSM_DFLT_COND
FSM_TEST_LOGIC ("BRANCH")
FSM_PROFILE_SECTION_OUT (state1_trans_conds)
FSM_TRANSIT_SWITCH
{
FSM_CASE_TRANSIT (0, 2, state2_enter_exec, ;, "SRV", "", "BRANCH", "Foward_Slot", "tr_1", "z_flood_node_proc [BRANCH -> Foward_Slot : SRV /
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
http://blog.csdn.net/yanhc519/article/details/16852481 NS2的有一个入门级的无线网络MFLood例子,可以很好的学习NS的一些基本的功能。很可惜,opnet没有,所以在学习opnet的过程中,做了下面这个基于有线网络的flood工程,分享出来,欢迎下载测试,提意见,改进,分享!
资源推荐
资源详情
资源评论
收起资源包目录
z_flood_net.project.zip (22个子文件)
z_flood_models
z_flood_node_proc.dev32.i0.pr.obj 57KB
z_flood_pkt.pk.m 1KB
z_flood_node_proc.pr.c 15KB
z_flood_node.nd.m 6KB
z_flood_node_proc.pr.m 9KB
z_flood_link.lk.m 1KB
z_flood_net.project
z_flood_net-baseline-DES-1.ot 45KB
z_flood_net-baseline.dev32.i0.nt.exp 7KB
z_flood_net-baseline.dev32.i0.nt.lib 14KB
z_flood_net.prj 1KB
z_flood_net-baseline.pb.m 851B
z_flood_net-baseline-DES-1.ah 2KB
z_flood_net-baseline-DES-1.ov 837B
z_flood_net-baseline.dev32.i0.nt.dll 88KB
z_flood_net-baseline.nt.m 32KB
z_flood_net-baseline.seq 4KB
z_flood_net-baseline.cml 122B
z_flood_net-baseline-DES-1.desinfo 39KB
z_flood_net-baseline-DES-1.ef 980B
z_flood_net-baseline.dev32.i0.nt.pdb 265KB
z_flood_net-baseline-DES-1.olf.dir
4476_11-18-2013_15.06.07.ot 3KB
log_info 421B
共 22 条
- 1
yanhc519
- 粉丝: 108
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页