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 cMessage * createPacket ()
virtual void sendPacket ()
virtual void processPacket (cMessage *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]

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

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

Reimplemented in UDPEchoApp.

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

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

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

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

Reimplemented in UDPEchoApp.

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

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

00052 {return 4;}

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

Reimplemented in UDPEchoApp.

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

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

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


Member Data Documentation

int UDPBasicApp::counter [static, protected]

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

int UDPBasicApp::destPort [protected]

int UDPBasicApp::localPort [protected]

int UDPBasicApp::msgByteLength [protected]

std::string UDPBasicApp::nodeName [protected]

int UDPBasicApp::numReceived [protected]

int UDPBasicApp::numSent [protected]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:25 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7