AODV method: 1. define your timer in the .h file such as in the aodv.h file class PrintTimer : public Handler { 2. declare the timer in your routing agent in the .h file 3. In the aodv.cc file, implement your handle function which will do what you want to do when the timer expires void PrintTimer::handle(Event*) { //if you want to schedule this timer periodically 4. remember to initialize it AODV::AODV(nsaddr_t id) : ..., ptimer(this), ... { 5. Then you can use it. For example, in void .... .... //when it receives a reply, schedule the print timer for 0.5 s //Scheduler::instance().schedule(&ptimer, p->copy(), 0.5); //if want to process the packet // you can also directly call the handle function, no delay //ptimer.handle((Event*) 0); // or //Scheduler::instance().schedule(&ptimer, new Event(), 0.0); .... .... } | Another method: 1. define your timer in your .h file such as in my sensor-agent.h file class WakeupTimer : public TimerHandler { 2. declare the timer in your agent as in my sensorAgent in the .h file 3. In sensor-agent.cc file, implement your expire function which will do what you want to do after the delay void WakeupTimer::expire(Event* event) { 4. remember to initialize it sensorAgent::sensorAgent() : ..., wakeupTimer_(this), ... { 5. Then you can use it wakeupTimer_.sched(sleeping_duration); wakeupTimer_.cancel(); |
With stop, restart in .h class helloTimer : public Handler { in .cc void helloTimer::handle(Event*) { | |
|
定时器使用(for NS2)
最新推荐文章于 2017-07-13 16:57:27 发布