📄 datagenerator.cc
字号:
// -*- C++ -*-
// Copyright (C) 2003 Leherstuh f黵 Betrieb System/ Verteilte System,
// Universitaet Dortmund
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// Author: Muddassar Farooq
// Informatik III, Universitaet Dortmund
// Germany
//-------------------------------------------------------------
// file: dataGenerator.cpp
// (part of AntNet Routing Simulation)
//-------------------------------------------------------------
#include <stdio.h>
#include "dataGenerator.h"
#include "Messages_m.h"
Define_Module( dataGenerator );
void dataGenerator::activity()
{
int numMessages = par("numMessages");
int myAddress = par("address");
int numStations = par("numStations");
double converganceTime = (double) par("converganceTime");
cPar& sleepTime = par("sleepTimeAtStart");
factor = par("factor");
cPar& messageLength = par("messageLength");
cPar& interArrivalTime = par("iaTime");
strcpy(sFileName,par("statFile"));
sPtr = statistics::Instance(sFileName);
debug = false;
logResults = par("logResults");
wait( sleepTime );
char msgname[70];
int i = 0;
for(;;)
{
messageGenerated = i;
// select length of message from ini file. We at the moment will work
// fixed length messages
int length = (int) messageLength;
// select a destinatin randomly (but not the local station)
// one ensures that we generate a destination address 0-4 and then increase it by
// one in case the address is local one or a variant of it
int dest = intrand(numStations - 1);
if(dest >= myAddress) dest++;
sprintf(msgname, "Packet%d-Source%d-Destination %d", i, myAddress, dest);
// create Packet
samplePacket *msg = new samplePacket(msgname);
msg->setSourceAddress(myAddress);
msg->setKind( (int) NETLAYER_DATA_PACKET);
msg->setDestAddress(dest);
// msg->setDestAddress(5);
msg->setHasPayLoad(true);
msg->setLength( BYTE * length);
msg->setTimestamp();
msg->setData("Here is some application dummy data");
// send this packet on the gate out that is connected to the router at network layer, that
// will take the routing decisions
if(debug)
{
ev << "Generated application data to send: \"" << msgname << "\", "
"length=" << length << "bytes, dest=" << dest << endl;
}
// since we need to send the message twice, hence it make senese to duplicate
// the message and then send as once we send the message then we are no
// more owner of the message.
if (simTime() >= converganceTime)
{
samplePacket *sendCopy = (samplePacket *) msg->dup();
send(sendCopy, "toRouter");
sPtr->incrTotalBitsGenerated();
}
// now send the copy
send(msg, "toAntGen");
// wait between packet sending. Here we could give different ditributions for
// packet arrival and then test the impact of load generated by these distributions
// and study the behavior of routing algorithm on them
double iaTime = (double) interArrivalTime;
wait( iaTime/factor );
i++;
}
}
void dataGenerator::finish()
{
ev << "*** Module: " << fullPath() << "***" << endl;
ev << "Stack allocated: " << stackSize() << " bytes";
ev << " (includes " << ev.extraStackForEnvir() << " bytes for environment)" << endl;
ev << "Stack actually used: " << stackUsage() << " bytes" << endl;
ev << "Total Messages Generated are " << messageGenerated << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -