一 ALOHA
1.构建aloha_tx进程模型
新建一个进程模型,保存为aloha_tx
构建如图所示的进程模型,注意中间的idle围殴红色,其他为绿色
init入口代码
/*get the maximum packet count set at simulation run-time*/
op_ima_sim_attr_get_int32("max packet count",&max_packet_count);
tx_pkt入口代码
Packet* out_pkt;
out_pkt=op_pk_get(IN_STRM);
op_pk_send(out_pkt,OUT_STRM);
++subm_pkts;
if(subm_pkts==max_packet_count)
{
op_sim_end("max packet count reached.","","","");
}
HB区域代码
/*input stream from generator module.*/
#define IN_STRM 0
/*output stream from generator module.*/
#define OUT_STRM 0
/*condition macros*/
#define PKT_ARVL (op_intrpt_type()==OPC_INTRPT_STRM)
/*global variables*/
extern int subm_pkts;
SV变量
设置进程接口
设置全局属性
设置完成编译该模块,显示done就完成了。
2.构建aloha节点模型
新建节点,保存为cct_tx
gen的属性设置
tx_proc的属性设置
两条包流线的设置
3.构建接收进程模型
新建一个进程模型,保存为cct_rx
init入口代码
rcvd_pkts=0;
SV区域变量
HB代码
#define IN_STRM 0
#define PKT_RCVD (op_intrpt_type()==OPC_INTRPT_STRM)
#define END_SIM (op_intrpt_type()==OPC_INTRPT_ENDSIM)
int subm_pkts=0;
FB代码
/*this function gets the received packet,destroys it,and logs the incremented received packet total.*/
static void proc_pkt(void)
{
Packet* in_pkt;
FIN(proc_pkt());
/*get packet from bus receiver input stream*/
in_pkt=op_pk_get(IN_STRM);
/*destroy the received packet.*/
op_pk_destroy(in_pkt);
/*increnment the count of received packet*/
++rcvd_pkts;
FOUT;
}
/*this function writes channel triffic and throughput statistics at the end of simulation.*/
static void record_stats(void)
{
double cur_time;
FIN(record_stats());
cur_time=op_sim_time();
op_stat_scalar_write("Channel Traffic G",(double)subm_pkts/cur_time);
op_stat_scalar_write("Channel Throughput S",(double)rcvd_pkts/cur_time);
FOUT;
}
编译通过就完成了。
4.构建接收节点
rx_proc属性
保存
5.链路构建
新建一个链路
设置为bus
保存
6.网络构建
新建一个工程,office,700*700
在插入一个rx节点,用链路连接,注意,连接的时候先点总线,再点rx
7.仿真参数
run
8.统计
还可以导出表格
二 CSMA
1.构建csma_tx进程模型
打开aloha_tx进程模型,另存为csma_tx进程模型。
构建下图所示进程模型
HB代码
/*input stream from generator module.*/
#define IN_STRM 0
/*output stream from generator module.*/
#define OUT_STRM 0
/*condition macros*/
#define PKT_ARVL (op_intrpt_type()==OPC_INTRPT_STRM)
/*input statistics indices*/
#define CH_BUSY_STAT 0
/*condition macros*/
#define FREE (op_stat_local_read(CH_BUSY_STAT)==0.0)
#define PKTS_QUEUED (!op_strm_empty(IN_STRM))
#define CH_GOES_FREE (op_intrpt_type()==OPC_INTRPT_STAT)
/*global variables*/
extern int subm_pkts;
编译,保存。
2.构建csma_tx节点模型
打开aloha_tx进程模型,另存为cmsa_tx进程文件。
在aloha的基础上增加两个模块,如图所示
注意:中间有一条是统计线,不是包流线。
右击统计线,设置属性。
3.其他
构建如图所示网络模型与之前的方法一样,设置仿真参数,run。