UDPBasicApp Class Reference

#include <UDPBasicApp.h>

Inheritance diagram for UDPBasicApp:

UDPAppBase UDPEchoApp

List of all members.


Detailed Description

UDP application. See NED for more info.

Protected Member Functions

virtual IPvXAddress chooseDestAddr ()
virtual cPacket * createPacket ()
virtual void sendPacket ()
virtual void processPacket (cPacket *msg)
virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)

Protected Attributes

std::string nodeName
int localPort
int destPort
int msgByteLength
std::vector< IPvXAddressdestAddresses
int numSent
int numReceived

Static Protected Attributes

static int counter

Member Function Documentation

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

Referenced by sendPacket().

00063 {
00064     int k = intrand(destAddresses.size());
00065     return destAddresses[k];
00066 }

cPacket * UDPBasicApp::createPacket (  )  [protected, virtual]

Reimplemented in UDPEchoApp.

Referenced by sendPacket().

00070 {
00071     char msgName[32];
00072     sprintf(msgName,"UDPBasicAppData-%d", counter++);
00073 
00074     cPacket *payload = new cPacket(msgName);
00075     payload->setByteLength(msgByteLength);
00076     return payload;
00077 }

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

Referenced by handleMessage().

00080 {
00081     cPacket *payload = createPacket();
00082     IPvXAddress destAddr = chooseDestAddr();
00083     sendToUDP(payload, localPort, destAddr, destPort);
00084 
00085     numSent++;
00086 }

void UDPBasicApp::processPacket ( cPacket *  msg  )  [protected, virtual]

Reimplemented in UDPEchoApp.

Referenced by handleMessage().

00112 {
00113     EV << "Received packet: ";
00114     printPacket(msg);
00115     delete msg;
00116 
00117     numReceived++;
00118 }

virtual int UDPBasicApp::numInitStages (  )  const [inline, protected, virtual]

00051 {return 4;}

void UDPBasicApp::initialize ( int  stage  )  [protected, virtual]

Reimplemented in UDPEchoApp.

Referenced by UDPEchoApp::initialize().

00031 {
00032     // because of IPAddressResolver, we need to wait until interfaces are registered,
00033     // address auto-assignment takes place etc.
00034     if (stage!=3)
00035         return;
00036 
00037     counter = 0;
00038     numSent = 0;
00039     numReceived = 0;
00040     WATCH(numSent);
00041     WATCH(numReceived);
00042 
00043     localPort = par("localPort");
00044     destPort = par("destPort");
00045     msgByteLength = par("messageLength").longValue();
00046 
00047     const char *destAddrs = par("destAddresses");
00048     cStringTokenizer tokenizer(destAddrs);
00049     const char *token;
00050     while ((token = tokenizer.nextToken())!=NULL)
00051         destAddresses.push_back(IPAddressResolver().resolve(token));
00052 
00053     if (destAddresses.empty())
00054         return;
00055 
00056     bindToPort(localPort);
00057 
00058     cMessage *timer = new cMessage("sendTimer");
00059     scheduleAt((double)par("messageFreq"), timer);
00060 }

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

00089 {
00090     if (msg->isSelfMessage())
00091     {
00092         // send, then reschedule next sending
00093         sendPacket();
00094         scheduleAt(simTime()+(double)par("messageFreq"), msg);
00095     }
00096     else
00097     {
00098         // process incoming packet
00099         processPacket(PK(msg));
00100     }
00101 
00102     if (ev.isGUI())
00103     {
00104         char buf[40];
00105         sprintf(buf, "rcvd: %d pks\nsent: %d pks", numReceived, numSent);
00106         getDisplayString().setTagArg("t",0,buf);
00107     }
00108 }


Member Data Documentation

std::string UDPBasicApp::nodeName [protected]

int UDPBasicApp::localPort [protected]

Referenced by initialize(), and sendPacket().

int UDPBasicApp::destPort [protected]

Referenced by initialize(), and sendPacket().

int UDPBasicApp::msgByteLength [protected]

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

Referenced by chooseDestAddr(), and initialize().

int UDPBasicApp::counter [static, protected]

int UDPBasicApp::numSent [protected]

int UDPBasicApp::numReceived [protected]


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

Generated on Fri Mar 20 18:51:23 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5