OMNeT++ ALOHA sample代码阅读

本文介绍了OMNeT++中ALOHA协议的Server模块代码,包括Server.ned、Server.h和Server.cc文件的详细解析。讲解了.cMessage在模拟中的作用,以及handleMessage函数如何处理消息,特别是数据包到达时间和冲突检测的逻辑。同时,提到了sendDirect函数在直接发送消息中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

写在最前

前一篇博客谢了关于ALOHA的一些原理,现在看OMNeT++这个网络仿真软件的sample是如何实现ALOHA网络的。

代码

Server.ned

simple Server
{
    parameters:
        @display("i=device/antennatower_l");
        @signal[receiveBegin](type="long");  // increases with each new frame arriving to the server and drops to 0 if the channel becomes finally idle
        @signal[receive](type="long");  // for successful receptions (non-collisions): 1 at the start of the reception, 0 at the end of the reception
        @signal[collision](type="long"); // the number of collided frames at the beginning of the collision period
        @signal[collisionLength](type="simtime_t");  // the length of the last collision period at the end of the collision period
        @signal[channelState](type="long");

        //source 
        @statistic[serverChannelState](source="channelState";title="Channel state";enum="IDLE=0,TRANSMISSION=1,COLLISION=2";record=vector);
        @statistic[receiveBegin](source="receiveBegin"; record=vector?; interpolationmode=sample-hold; title="receive begin");
        @statistic[channelUtilization](source="timeavg(receive)"; record=last; interpolationmode=linear; title="channel utilization");
        @statistic[collisionMultiplicity](source=collision; record=vector?,histogram; title="collision multiplicity");
        @statistic[collisionLength](record=vector?,histogram,mean,sum,max; title="collision length");
        @statistic[receivedFrames](source="sum(receive)"; record=last; title="received frames");
        @statistic[collidedFrames](source="sum(collision)"; record=last; title="collided frames");
    gates:
        input in @directIn;
}

.ned文件一般是用于OMNeT中模块与仿真内核的配置,里面一般包含该模块的parameter,gates,connections等等。其中这里Server.ned文件中,开头定义了一些signal,主要是配合后面的statistic来使用,用于统计仿真过程中需要的统计指标(如时延,信道利用率等)。还定义了一个输入

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值