0
我實際上試圖編輯etherhost2函數發送到幾個目的地,我達到了只有第一次可能的點。Omnet ++:改變功能的位置沒有按預期工作
在功能通過只移動該兩個函數sendBurstPackets()正常工作的原代碼和scheduleNextPacket(simTime())中如果與destMACAddress = resolveDestMACAddress()這兩個功能僅稱爲條件一旦。
這是否意味着destMacAddress通過整個模擬設置一次?
原始代碼
void EtherTrafGen::handleMessage(cMessage *msg)
{
if (!isNodeUp())
throw cRuntimeError("Application is not running");
if (msg->isSelfMessage()) {
if (msg->getKind() == START) {
destMACAddress = resolveDestMACAddress();
// if no dest address given, nothing to do
if (destMACAddress.isUnspecified())
return;
}
sendBurstPackets();
scheduleNextPacket(simTime());
}
else
receivePacket(check_and_cast<cPacket *>(msg));
}
我的變更
void EtherTrafGen::handleMessage(cMessage *msg)
{
if (!isNodeUp())
throw cRuntimeError("Application is not running");
if (msg->isSelfMessage()) {
if (msg->getKind() == START) {
if (!multipacket)
{
destMACAddress = resolveDestMACAddress();
sendBurstPackets();
scheduleNextPacket(simTime());
}
// if no dest address given, nothing to do
if (destMACAddress.isUnspecified())
return;
}
}
else
receivePacket(check_and_cast<cPacket *>(msg));
}
通常情況下,自消息在相應的'.h'文件中定義,並作爲局部變量(即每個模塊一個實例)進行維護。這種編程模式對於定期執行任務的應用程序(例如信標或流量生成)特別常見。 –