|
INET Framework for OMNeT++/OMNEST
|
#include <IPTrafGen.h>
Protected Member Functions | |
| virtual IPvXAddress | chooseDestAddr () |
| virtual void | sendPacket () |
| virtual int | numInitStages () const |
| virtual void | initialize (int stage) |
| virtual void | handleMessage (cMessage *msg) |
Protected Attributes | |
| std::string | nodeName |
| int | protocol |
| int | msgByteLength |
| int | numPackets |
| std::vector< IPvXAddress > | destAddresses |
| int | numSent |
Static Protected Attributes | |
| static int | counter |
IP traffic generator application. See NED for more info.
| IPvXAddress IPTrafGen::chooseDestAddr | ( | ) | [protected, virtual] |
Referenced by sendPacket().
{
int k = intrand(destAddresses.size());
return destAddresses[k];
}
| void IPTrafGen::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from IPTrafSink.
{
if (msg->isSelfMessage())
{
// send, then reschedule next sending
sendPacket();
if (!numPackets || numSent<numPackets)
scheduleAt(simTime()+(double)par("packetInterval"), msg);
else
delete msg;
}
else
{
// process incoming packet
processPacket(PK(msg));
}
if (ev.isGUI())
{
char buf[40];
sprintf(buf, "rcvd: %d pks\nsent: %d pks", numReceived, numSent);
getDisplayString().setTagArg("t",0,buf);
}
}
| void IPTrafGen::initialize | ( | int | stage | ) | [protected, virtual] |
{
// because of IPAddressResolver, we need to wait until interfaces are registered,
// address auto-assignment takes place etc.
if (stage!=3)
return;
IPTrafSink::initialize();
protocol = par("protocol");
msgByteLength = par("packetLength");
numPackets = par("numPackets");
simtime_t startTime = par("startTime");
const char *destAddrs = par("destAddresses");
cStringTokenizer tokenizer(destAddrs);
const char *token;
while ((token = tokenizer.nextToken())!=NULL)
destAddresses.push_back(IPAddressResolver().resolve(token));
counter = 0;
numSent = 0;
WATCH(numSent);
if (destAddresses.empty())
return;
if (numPackets > 0) {
cMessage *timer = new cMessage("sendTimer");
scheduleAt(startTime, timer);
}
}
| virtual int IPTrafGen::numInitStages | ( | ) | const [inline, protected, virtual] |
{return 4;}
| void IPTrafGen::sendPacket | ( | ) | [protected, virtual] |
Referenced by handleMessage().
{
char msgName[32];
sprintf(msgName,"appData-%d", counter++);
cPacket *payload = new cPacket(msgName);
payload->setByteLength(msgByteLength);
IPvXAddress destAddr = chooseDestAddr();
if (!destAddr.isIPv6())
{
// send to IPv4
IPControlInfo *controlInfo = new IPControlInfo();
controlInfo->setDestAddr(destAddr.get4());
controlInfo->setProtocol(protocol);
payload->setControlInfo(controlInfo);
EV << "Sending packet: ";
printPacket(payload);
send(payload, "ipOut");
}
else
{
// send to IPv6
IPv6ControlInfo *controlInfo = new IPv6ControlInfo();
controlInfo->setDestAddr(destAddr.get6());
controlInfo->setProtocol(protocol);
payload->setControlInfo(controlInfo);
EV << "Sending packet: ";
printPacket(payload);
send(payload, "ipv6Out");
}
numSent++;
}
int IPTrafGen::counter [static, protected] |
Referenced by initialize(), and sendPacket().
std::vector<IPvXAddress> IPTrafGen::destAddresses [protected] |
Referenced by chooseDestAddr(), and initialize().
int IPTrafGen::msgByteLength [protected] |
Referenced by initialize(), and sendPacket().
std::string IPTrafGen::nodeName [protected] |
int IPTrafGen::numPackets [protected] |
Referenced by handleMessage(), and initialize().
int IPTrafGen::numSent [protected] |
Referenced by handleMessage(), initialize(), and sendPacket().
int IPTrafGen::protocol [protected] |
Referenced by initialize(), and sendPacket().