// // This file is part of an OMNeT++/OMNEST simulation example. // // Copyright (C) 2003-2008 Andras Varga // // This file is distributed WITHOUT ANY WARRANTY. See the file // `license' for details on this and other legal matters. // #include <stdio.h> #include <string.h> #include <omnetpp.h> class Txc7 : public cSimpleModule { private: cMessage *event; cMessage *tictocMsg; public: Txc7(); virtual ~Txc7(); protected: virtual void initialize(); virtual void handleMessage(cMessage *msg); }; Define_Module(Txc7); Txc7::Txc7() { event = tictocMsg = NULL; } Txc7::~Txc7() { cancelAndDelete(event); delete tictocMsg; } void Txc7::initialize() { event = new cMessage("event"); tictocMsg = NULL; if (strcmp("tic", getName()) == 0) { EV << "Scheduling first send to t=5.0s\n"; scheduleAt(5.0, event); tictocMsg = new cMessage("tictocMsg"); } } void Txc7::handleMessage(cMessage *msg) { if (msg==event) { EV << "Wait period is over, sending back message\n"; send(tictocMsg, "out"); tictocMsg = NULL; } else { // "Lose" the message with 0.1 probability: if (uniform(0,1) < 0.1) { EV << "\"Losing\" message\n"; delete msg; } else { // The "delayTime" module parameter can be set to values like // "exponential(5)" (tictoc7.ned, omnetpp.ini), and then here // we'll get a different delay every time. simtime_t delay = par("delayTime"); EV << "Message arrived, starting to wait " << delay << " secs...\n"; tictocMsg = msg; scheduleAt(simTime()+delay, event); } } }