#include <UDPEchoApp.h>
Protected Member Functions | |
virtual cPacket * | createPacket () |
virtual void | processPacket (cPacket *msg) |
virtual void | initialize (int stage) |
virtual void | finish () |
cPacket * UDPEchoApp::createPacket | ( | ) | [protected, virtual] |
Reimplemented from UDPBasicApp.
00042 { 00043 char msgName[32]; 00044 sprintf(msgName,"UDPEcho-%d", counter++); 00045 00046 UDPEchoAppMsg *message = new UDPEchoAppMsg(msgName); 00047 message->setByteLength(msgByteLength); 00048 00049 return message; 00050 }
void UDPEchoApp::processPacket | ( | cPacket * | msg | ) | [protected, virtual] |
Reimplemented from UDPBasicApp.
00053 { 00054 if (msg->getKind() == UDP_I_ERROR) 00055 { 00056 delete msg; 00057 return; 00058 } 00059 00060 UDPEchoAppMsg *packet = check_and_cast<UDPEchoAppMsg *>(msg); 00061 00062 if (packet->getIsRequest()) 00063 { 00064 UDPControlInfo *controlInfo = check_and_cast<UDPControlInfo *>(packet->getControlInfo()); 00065 00066 // swap src and dest 00067 IPvXAddress srcAddr = controlInfo->getSrcAddr(); 00068 int srcPort = controlInfo->getSrcPort(); 00069 controlInfo->setSrcAddr(controlInfo->getDestAddr()); 00070 controlInfo->setSrcPort(controlInfo->getDestPort()); 00071 controlInfo->setDestAddr(srcAddr); 00072 controlInfo->setDestPort(srcPort); 00073 00074 packet->setIsRequest(false); 00075 send(packet, "udpOut"); 00076 } 00077 else 00078 { 00079 simtime_t rtt = simTime() - packet->getCreationTime(); 00080 EV << "RTT: " << rtt << "\n"; 00081 delete msg; 00082 } 00083 numReceived++; 00084 }
void UDPEchoApp::initialize | ( | int | stage | ) | [protected, virtual] |
Reimplemented from UDPBasicApp.
00028 { 00029 UDPBasicApp::initialize(stage); 00030 00031 // because of IPAddressResolver, we need to wait until interfaces are registered, 00032 // address auto-assignment takes place etc. 00033 if (stage!=3) 00034 return; 00035 }