#include <TCPEchoApp.h>
Protected Member Functions | |
virtual void | sendDown (cMessage *msg) |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
Protected Attributes | |
simtime_t | delay |
double | echoFactor |
long | bytesRcvd |
long | bytesSent |
void TCPEchoApp::sendDown | ( | cMessage * | msg | ) | [protected, virtual] |
Referenced by handleMessage().
00040 { 00041 if (msg->isPacket()) 00042 bytesSent += ((cPacket *)msg)->getByteLength(); 00043 send(msg, "tcpOut"); 00044 }
void TCPEchoApp::initialize | ( | ) | [protected, virtual] |
00023 { 00024 const char *address = par("address"); 00025 int port = par("port"); 00026 delay = par("echoDelay"); 00027 echoFactor = par("echoFactor"); 00028 00029 bytesRcvd = bytesSent = 0; 00030 WATCH(bytesRcvd); 00031 WATCH(bytesSent); 00032 00033 TCPSocket socket; 00034 socket.setOutputGate(gate("tcpOut")); 00035 socket.bind(address[0] ? IPvXAddress(address) : IPvXAddress(), port); 00036 socket.listen(); 00037 }
void TCPEchoApp::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
00047 { 00048 if (msg->isSelfMessage()) 00049 { 00050 sendDown(msg); 00051 } 00052 else if (msg->getKind()==TCP_I_PEER_CLOSED) 00053 { 00054 // we'll close too 00055 msg->setKind(TCP_C_CLOSE); 00056 if (delay==0) 00057 sendDown(msg); 00058 else 00059 scheduleAt(simTime()+delay, msg); // send after a delay 00060 } 00061 else if (msg->getKind()==TCP_I_DATA || msg->getKind()==TCP_I_URGENT_DATA) 00062 { 00063 cPacket *pkt = check_and_cast<cPacket *>(msg); 00064 bytesRcvd += pkt->getByteLength(); 00065 00066 if (echoFactor==0) 00067 { 00068 delete pkt; 00069 } 00070 else 00071 { 00072 // reverse direction, modify length, and send it back 00073 pkt->setKind(TCP_C_SEND); 00074 TCPCommand *ind = check_and_cast<TCPCommand *>(pkt->removeControlInfo()); 00075 TCPSendCommand *cmd = new TCPSendCommand(); 00076 cmd->setConnId(ind->getConnId()); 00077 pkt->setControlInfo(cmd); 00078 delete ind; 00079 00080 long byteLen = pkt->getByteLength()*echoFactor; 00081 if (byteLen<1) byteLen=1; 00082 pkt->setByteLength(byteLen); 00083 00084 if (delay==0) 00085 sendDown(pkt); 00086 else 00087 scheduleAt(simTime()+delay, pkt); // send after a delay 00088 } 00089 } 00090 else 00091 { 00092 // some indication -- ignore 00093 delete msg; 00094 } 00095 00096 if (ev.isGUI()) 00097 { 00098 char buf[80]; 00099 sprintf(buf, "rcvd: %ld bytes\nsent: %ld bytes", bytesRcvd, bytesSent); 00100 getDisplayString().setTagArg("t",0,buf); 00101 } 00102 }
simtime_t TCPEchoApp::delay [protected] |
Referenced by handleMessage(), and initialize().
double TCPEchoApp::echoFactor [protected] |
Referenced by handleMessage(), and initialize().
long TCPEchoApp::bytesRcvd [protected] |
Referenced by handleMessage(), and initialize().
long TCPEchoApp::bytesSent [protected] |
Referenced by handleMessage(), initialize(), and sendDown().