INET Framework for OMNeT++/OMNEST
EtherAppCli Class Reference

#include <EtherAppCli.h>

List of all members.

Protected Member Functions

virtual void initialize (int stage)
virtual int numInitStages () const
virtual void handleMessage (cMessage *msg)
virtual void finish ()
virtual MACAddress resolveDestMACAddress ()
virtual void sendPacket ()
virtual void receivePacket (cMessage *msg)
virtual void registerDSAP (int dsap)

Protected Attributes

long seqNum
cPar * reqLength
cPar * respLength
cPar * waitTime
int localSAP
int remoteSAP
MACAddress destMACAddress
long packetsSent
long packetsReceived
cOutVector eedVector
cStdDev eedStats

Detailed Description

Simple traffic generator for the Ethernet model.


Member Function Documentation

void EtherAppCli::finish ( ) [protected, virtual]
{
    recordScalar("packets sent", packetsSent);
    recordScalar("packets rcvd", packetsReceived);
    recordScalar("end-to-end delay mean", eedStats.getMean());
    recordScalar("end-to-end delay stddev", eedStats.getStddev());
    recordScalar("end-to-end delay min", eedStats.getMin());
    recordScalar("end-to-end delay max", eedStats.getMax());
}
void EtherAppCli::handleMessage ( cMessage *  msg) [protected, virtual]
{
    if (msg->isSelfMessage())
    {
        sendPacket();
        simtime_t d = waitTime->doubleValue();
        scheduleAt(simTime()+d, msg);
    }
    else
    {
        receivePacket(msg);
    }
}
void EtherAppCli::initialize ( int  stage) [protected, virtual]
{
    // we can only initialize in the 2nd stage (stage==1), because
    // assignment of "auto" MAC addresses takes place in stage 0
    if (stage == 1)
    {
        reqLength = &par("reqLength");
        respLength = &par("respLength");
        waitTime = &par("waitTime");

        localSAP = ETHERAPP_CLI_SAP;
        remoteSAP = ETHERAPP_SRV_SAP;

        seqNum = 0;
        WATCH(seqNum);

        // statistics
        packetsSent = packetsReceived = 0;
        eedVector.setName("end-to-end delay");
        eedStats.setName("end-to-end delay");
        WATCH(packetsSent);
        WATCH(packetsReceived);

        destMACAddress = resolveDestMACAddress();

        // if no dest address given, nothing to do
        if (destMACAddress.isUnspecified())
            return;

        bool registerSAP = par("registerSAP");
        if (registerSAP)
            registerDSAP(localSAP);

        cMessage *timermsg = new cMessage("generateNextPacket");
        simtime_t d = par("startTime").doubleValue();
        scheduleAt(simTime()+d, timermsg);
    }
}
virtual int EtherAppCli::numInitStages ( ) const [inline, protected, virtual]
{return 2;}
void EtherAppCli::receivePacket ( cMessage *  msg) [protected, virtual]

Referenced by handleMessage().

{
    EV << "Received packet `" << msg->getName() << "'\n";

    packetsReceived++;
    simtime_t lastEED = simTime() - msg->getCreationTime();
    eedVector.record(lastEED);
    eedStats.collect(lastEED);

    delete msg;
}
void EtherAppCli::registerDSAP ( int  dsap) [protected, virtual]

Referenced by initialize().

{
    EV << getFullPath() << " registering DSAP " << dsap << "\n";

    Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
    etherctrl->setDsap(dsap);
    cMessage *msg = new cMessage("register_DSAP", IEEE802CTRL_REGISTER_DSAP);
    msg->setControlInfo(etherctrl);

    send(msg, "out");
}
MACAddress EtherAppCli::resolveDestMACAddress ( ) [protected, virtual]

Referenced by initialize().

{
    MACAddress destMACAddress;
    const char *destAddress = par("destAddress");
    if (destAddress[0])
    {
        // try as mac address first, then as a module
        if (!destMACAddress.tryParse(destAddress))
        {
            cModule *destStation = simulation.getModuleByPath(destAddress);
            if (!destStation)
                error("cannot resolve MAC address '%s': not a 12-hex-digit MAC address or a valid module path name", destAddress);
            cModule *destMAC = destStation->getSubmodule("mac");
            if (!destMAC)
                error("module '%s' has no 'mac' submodule", destAddress);
            destMACAddress.setAddress(destMAC->par("address"));
        }
    }
    return destMACAddress;
}
void EtherAppCli::sendPacket ( ) [protected, virtual]

Referenced by handleMessage().

{
    seqNum++;

    char msgname[30];
    sprintf(msgname, "req-%d-%ld", getId(), seqNum);
    EV << "Generating packet `" << msgname << "'\n";

    EtherAppReq *datapacket = new EtherAppReq(msgname, IEEE802CTRL_DATA);

    datapacket->setRequestId(seqNum);

    long len = reqLength->longValue();
    datapacket->setByteLength(len);

    long respLen = respLength->longValue();
    datapacket->setResponseBytes(respLen);

    Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
    etherctrl->setSsap(localSAP);
    etherctrl->setDsap(remoteSAP);
    etherctrl->setDest(destMACAddress);
    datapacket->setControlInfo(etherctrl);

    send(datapacket, "out");
    packetsSent++;
}

Member Data Documentation

cStdDev EtherAppCli::eedStats [protected]

Referenced by finish(), initialize(), and receivePacket().

cOutVector EtherAppCli::eedVector [protected]

Referenced by initialize(), and receivePacket().

int EtherAppCli::localSAP [protected]

Referenced by initialize(), and sendPacket().

long EtherAppCli::packetsReceived [protected]

Referenced by finish(), initialize(), and receivePacket().

long EtherAppCli::packetsSent [protected]

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

int EtherAppCli::remoteSAP [protected]

Referenced by initialize(), and sendPacket().

cPar* EtherAppCli::reqLength [protected]

Referenced by initialize(), and sendPacket().

cPar* EtherAppCli::respLength [protected]

Referenced by initialize(), and sendPacket().

long EtherAppCli::seqNum [protected]

Referenced by initialize(), and sendPacket().

cPar* EtherAppCli::waitTime [protected]

Referenced by handleMessage(), and initialize().


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