Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <omnetpp.h>
00020 #include "UDPEchoApp.h"
00021 #include "UDPEchoAppMsg_m.h"
00022 #include "UDPControlInfo_m.h"
00023
00024
00025 Define_Module(UDPEchoApp);
00026
00027 void UDPEchoApp::initialize(int stage)
00028 {
00029 UDPBasicApp::initialize(stage);
00030
00031
00032
00033 if (stage!=3)
00034 return;
00035 }
00036
00037 void UDPEchoApp::finish()
00038 {
00039 }
00040
00041 cPacket *UDPEchoApp::createPacket()
00042 {
00043 char msgName[32];
00044 sprintf(msgName,"UDPEcho-%d", counter++);
00045
00046 UDPEchoAppMsg *message = new UDPEchoAppMsg(msgName);
00047 message->setByteLength(par("messageLength").longValue());
00048
00049 return message;
00050 }
00051
00052 void UDPEchoApp::processPacket(cPacket *msg)
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
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 }
00085
00086
00087