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] 相连)。