実際にいくつかの宛先に送信するためにetherhost2関数を編集しようとしています。関数は、これら二つの機能のみ呼び出されるだけdestMACAddress = resolveDestMACAddress()と条件場合に二つの機能sendBurstPackets()とscheduleNextPacket(simTime())を移動させることにより、正常に動作して、元のコードでOmnet ++:関数の場所を変更すると、期待通りに機能しませんでした。
一度。
これは、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'ファイルで定義され、ローカル変数(モジュールごとに1つのインスタンス)として管理されます。このプログラミングパターンは、定期的に物事を行うアプリケーション(ビーコンやトラフィックの生成など)に特によく使用されます。 –