OMNeT 例程 Tictoc10 学习笔记

Tictoc10 构建了一个网络。tic[0] 首先发送消息,最后 tic[3] 收到消息结束。路由效率不高,数据包会在两个节点之间来回传送。

方括号[ ]把之前的门变成了门向量,当用 Txc 来建立网络的时候,才决定其向量的大小(门数)。

  gates:
        input in[];  // declare in[] and out[] to be vector gates
        output out[];

随机选择一个门发送消息:

	void Txc10::forwardMessage(cMessage *msg)
{
    // In this example, we just pick a random gate to send it on.
    // We draw a random number between 0 and the size of gate `out[]'.
    int n = gateSize("out");
    int k = intuniform(0, n-1);

    EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
    send(msg, "out", k);
}

int n = gateSize("out");

指的是此刻的这个门的索引号有几个。比如 tic[0] 一共有1个索引号——[0]( [0]与 tic[1] 相连);tic[1] 一共有3个索引号——[0]、[1]、[2]( [0]与 tic[0] 相连、[1]与 tic[2] 相连、[2]与 tic[4] 相连)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值