#include <UDPBasicApp.h>
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 |
| std::vector< IPvXAddress > | destAddresses |
| int | numSent |
| int | numReceived |
Static Protected Attributes | |
| static int | counter |
UDP application. See NED for more info.
Definition at line 31 of file UDPBasicApp.h.
| IPvXAddress UDPBasicApp::chooseDestAddr | ( | ) | [protected, virtual] |
Definition at line 61 of file UDPBasicApp.cc.
Referenced by sendPacket().
{
int k = intrand(destAddresses.size());
return destAddresses[k];
}
| cPacket * UDPBasicApp::createPacket | ( | ) | [protected, virtual] |
Reimplemented in UDPEchoApp.
Definition at line 68 of file UDPBasicApp.cc.
Referenced by sendPacket().
{
char msgName[32];
sprintf(msgName,"UDPBasicAppData-%d", counter++);
cPacket *payload = new cPacket(msgName);
payload->setByteLength(par("messageLength").longValue());
return payload;
}
| void UDPBasicApp::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Definition at line 87 of file UDPBasicApp.cc.
{
if (msg->isSelfMessage())
{
// send, then reschedule next sending
sendPacket();
scheduleAt(simTime()+(double)par("messageFreq"), 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 UDPBasicApp::initialize | ( | int | stage | ) | [protected, virtual] |
Reimplemented in UDPEchoApp.
Definition at line 30 of file UDPBasicApp.cc.
{
// because of IPAddressResolver, we need to wait until interfaces are registered,
// address auto-assignment takes place etc.
if (stage!=3)
return;
counter = 0;
numSent = 0;
numReceived = 0;
WATCH(numSent);
WATCH(numReceived);
localPort = par("localPort");
destPort = par("destPort");
const char *destAddrs = par("destAddresses");
cStringTokenizer tokenizer(destAddrs);
const char *token;
while ((token = tokenizer.nextToken())!=NULL)
destAddresses.push_back(IPAddressResolver().resolve(token));
if (destAddresses.empty())
return;
bindToPort(localPort);
cMessage *timer = new cMessage("sendTimer");
scheduleAt((double)par("messageFreq"), timer);
}
| virtual int UDPBasicApp::numInitStages | ( | ) | const [inline, protected, virtual] |
Definition at line 50 of file UDPBasicApp.h.
{return 4;}
| void UDPBasicApp::processPacket | ( | cPacket * | msg | ) | [protected, virtual] |
Reimplemented in UDPEchoApp.
Definition at line 110 of file UDPBasicApp.cc.
Referenced by handleMessage().
{
EV << "Received packet: ";
printPacket(msg);
delete msg;
numReceived++;
}
| void UDPBasicApp::sendPacket | ( | ) | [protected, virtual] |
Definition at line 78 of file UDPBasicApp.cc.
Referenced by handleMessage().
{
cPacket *payload = createPacket();
IPvXAddress destAddr = chooseDestAddr();
sendToUDP(payload, localPort, destAddr, destPort);
numSent++;
}
int UDPBasicApp::counter [static, protected] |
Definition at line 38 of file UDPBasicApp.h.
Referenced by UDPEchoApp::createPacket(), createPacket(), and initialize().
std::vector<IPvXAddress> UDPBasicApp::destAddresses [protected] |
Definition at line 36 of file UDPBasicApp.h.
Referenced by chooseDestAddr(), and initialize().
int UDPBasicApp::destPort [protected] |
Definition at line 35 of file UDPBasicApp.h.
Referenced by initialize(), and sendPacket().
int UDPBasicApp::localPort [protected] |
Definition at line 35 of file UDPBasicApp.h.
Referenced by initialize(), and sendPacket().
std::string UDPBasicApp::nodeName [protected] |
Definition at line 34 of file UDPBasicApp.h.
int UDPBasicApp::numReceived [protected] |
Definition at line 41 of file UDPBasicApp.h.
Referenced by handleMessage(), initialize(), UDPEchoApp::processPacket(), and processPacket().
int UDPBasicApp::numSent [protected] |
Definition at line 40 of file UDPBasicApp.h.
Referenced by handleMessage(), initialize(), and sendPacket().
1.7.1