我正在尝试使用TraCIDemo计算邮件传递率。
在sendBeacon
中,每次发送消息时,我都会递增messageDeliverySend
,而在processBeacon
中,我会根据发送节点递增messageDeliveryReceive
参数。
在processBeacon
我与node[0]
进行字符串比较,但我想动态检查此参数。如何为此代码执行动态检查部分?
我的方案是,如果有多个节点传输到node[1]
,例如我想仅从node[0]
记录值。
void ROAMER::sendBeacon(ROAMERBeacon * beacon, double delay) {
ROAMER_EV << "Sending beacon: address = " << beacon->getAddress()
<< ", position = " << beacon->getPosition() << endl;
IPv4ControlInfo * networkProtocolControlInfo = new IPv4ControlInfo();
networkProtocolControlInfo->setProtocol(IP_PROT_MANET);
networkProtocolControlInfo->setTimeToLive(255);
networkProtocolControlInfo->setDestAddr(IPv4Address::LL_MANET_ROUTERS);
networkProtocolControlInfo->setSrcAddr(getSelfAddress().get4());
messageDeliverySend++;
delayTime = simTime();
UDPPacket * udpPacket = new UDPPacket(beacon->getName());
udpPacket->encapsulate(beacon);
udpPacket->setSourcePort(ROAMER_UDP_PORT);
udpPacket->setDestinationPort(ROAMER_UDP_PORT);
udpPacket->setControlInfo(networkProtocolControlInfo);
sendUDPPacket(udpPacket, delay);
}
void ROAMER::processBeacon(ROAMERBeacon * beacon) {
if(strcmp(beacon->getSenderAddress(),"node[0]") == 0){
messageDeliveryReceive++;
}
}
void ROAMER::finish(){
messageDeliveryRatio = messageDeliveryReceive/messageDeliverySend;
recordScalar("Message Delivery Ratio",messageDeliveryVecRatio);
}