#include <IPTrafGen.h>
Protected Member Functions | |
virtual IPvXAddress | chooseDestAddr () |
virtual void | sendPacket () |
virtual int | numInitStages () const |
virtual void | initialize (int stage) |
virtual void | handleMessage (cMessage *msg) |
Protected Attributes | |
std::string | nodeName |
int | protocol |
int | msgByteLength |
int | numPackets |
std::vector< IPvXAddress > | destAddresses |
int | numSent |
Static Protected Attributes | |
static int | counter |
IPvXAddress IPTrafGen::chooseDestAddr | ( | ) | [protected, virtual] |
Referenced by sendPacket().
00125 { 00126 int k = intrand(destAddresses.size()); 00127 return destAddresses[k]; 00128 }
void IPTrafGen::sendPacket | ( | ) | [protected, virtual] |
Referenced by handleMessage().
00131 { 00132 char msgName[32]; 00133 sprintf(msgName,"appData-%d", counter++); 00134 00135 cPacket *payload = new cPacket(msgName); 00136 payload->setByteLength(msgByteLength); 00137 00138 IPvXAddress destAddr = chooseDestAddr(); 00139 if (!destAddr.isIPv6()) 00140 { 00141 // send to IPv4 00142 IPControlInfo *controlInfo = new IPControlInfo(); 00143 controlInfo->setDestAddr(destAddr.get4()); 00144 controlInfo->setProtocol(protocol); 00145 payload->setControlInfo(controlInfo); 00146 00147 EV << "Sending packet: "; 00148 printPacket(payload); 00149 00150 send(payload, "ipOut"); 00151 } 00152 else 00153 { 00154 // send to IPv6 00155 IPv6ControlInfo *controlInfo = new IPv6ControlInfo(); 00156 controlInfo->setDestAddr(destAddr.get6()); 00157 controlInfo->setProtocol(protocol); 00158 payload->setControlInfo(controlInfo); 00159 00160 EV << "Sending packet: "; 00161 printPacket(payload); 00162 00163 send(payload, "ipv6Out"); 00164 } 00165 numSent++; 00166 }
void IPTrafGen::initialize | ( | int | stage | ) | [protected, virtual] |
00093 { 00094 // because of IPAddressResolver, we need to wait until interfaces are registered, 00095 // address auto-assignment takes place etc. 00096 if (stage!=3) 00097 return; 00098 00099 IPTrafSink::initialize(); 00100 00101 protocol = par("protocol"); 00102 msgByteLength = par("packetLength"); 00103 numPackets = par("numPackets"); 00104 simtime_t startTime = par("startTime"); 00105 00106 const char *destAddrs = par("destAddresses"); 00107 cStringTokenizer tokenizer(destAddrs); 00108 const char *token; 00109 while ((token = tokenizer.nextToken())!=NULL) 00110 destAddresses.push_back(IPAddressResolver().resolve(token)); 00111 00112 counter = 0; 00113 00114 numSent = 0; 00115 WATCH(numSent); 00116 00117 if (destAddresses.empty()) 00118 return; 00119 00120 cMessage *timer = new cMessage("sendTimer"); 00121 scheduleAt(startTime, timer); 00122 }
void IPTrafGen::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from IPTrafSink.
00169 { 00170 if (msg->isSelfMessage()) 00171 { 00172 // send, then reschedule next sending 00173 sendPacket(); 00174 00175 if (!numPackets || numSent<numPackets) 00176 scheduleAt(simTime()+(double)par("packetInterval"), msg); 00177 } 00178 else 00179 { 00180 // process incoming packet 00181 processPacket(PK(msg)); 00182 } 00183 00184 if (ev.isGUI()) 00185 { 00186 char buf[40]; 00187 sprintf(buf, "rcvd: %d pks\nsent: %d pks", numReceived, numSent); 00188 getDisplayString().setTagArg("t",0,buf); 00189 } 00190 }
std::string IPTrafGen::nodeName [protected] |
int IPTrafGen::protocol [protected] |
Referenced by initialize(), and sendPacket().
int IPTrafGen::msgByteLength [protected] |
Referenced by initialize(), and sendPacket().
int IPTrafGen::numPackets [protected] |
Referenced by handleMessage(), and initialize().
std::vector<IPvXAddress> IPTrafGen::destAddresses [protected] |
Referenced by chooseDestAddr(), and initialize().
int IPTrafGen::counter [static, protected] |
Referenced by initialize(), and sendPacket().
int IPTrafGen::numSent [protected] |
Referenced by handleMessage(), initialize(), and sendPacket().