Protected Member Functions | Protected Attributes | Static Protected Attributes

IPTrafGen Class Reference

#include <IPTrafGen.h>

Inheritance diagram for IPTrafGen:
IPTrafSink

List of all members.

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< IPvXAddressdestAddresses
int numSent

Static Protected Attributes

static int counter

Detailed Description

IP traffic generator application. See NED for more info.

Definition at line 49 of file IPTrafGen.h.


Member Function Documentation

IPvXAddress IPTrafGen::chooseDestAddr (  )  [protected, virtual]

Definition at line 126 of file IPTrafGen.cc.

Referenced by sendPacket().

{
    int k = intrand(destAddresses.size());
    return destAddresses[k];
}

void IPTrafGen::handleMessage ( cMessage *  msg  )  [protected, virtual]

Reimplemented from IPTrafSink.

Definition at line 170 of file IPTrafGen.cc.

{
    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]

Definition at line 92 of file IPTrafGen.cc.

{
    // 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]

Definition at line 67 of file IPTrafGen.h.

{return 4;}

void IPTrafGen::sendPacket (  )  [protected, virtual]

Definition at line 132 of file IPTrafGen.cc.

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++;
}


Member Data Documentation

int IPTrafGen::counter [static, protected]

Definition at line 58 of file IPTrafGen.h.

Referenced by initialize(), and sendPacket().

std::vector<IPvXAddress> IPTrafGen::destAddresses [protected]

Definition at line 56 of file IPTrafGen.h.

Referenced by chooseDestAddr(), and initialize().

int IPTrafGen::msgByteLength [protected]

Definition at line 54 of file IPTrafGen.h.

Referenced by initialize(), and sendPacket().

std::string IPTrafGen::nodeName [protected]

Definition at line 52 of file IPTrafGen.h.

int IPTrafGen::numPackets [protected]

Definition at line 55 of file IPTrafGen.h.

Referenced by handleMessage(), and initialize().

int IPTrafGen::numSent [protected]

Definition at line 60 of file IPTrafGen.h.

Referenced by handleMessage(), initialize(), and sendPacket().

int IPTrafGen::protocol [protected]

Definition at line 53 of file IPTrafGen.h.

Referenced by initialize(), and sendPacket().


The documentation for this class was generated from the following files: