当等待定时器过期时,我需要重新广播数据包,我遵循在How to add timer in aodv using ns2定义的步骤,我定义了代理和定时器类;交叉引用;代理构造函数中定时器对象的初始化;并最终到期(事件*)类B_suppression。当执行到达 agent->rebroadcast((Packet*)p, 0);
它将终止并显示以下消息'无效的SDVCAST数据包类型'。从事件到包造成问题?当定时器到期时ns2重播数据包
class SDVCAST;
class B_suppression_Timer : public TimerHandler {
friend class SDVCAST;
public:
B_suppression_Timer (SDVCAST *s){agent = s;};
virtual void expire (Event *p);
private:
SDVCAST *agent;
};
class SDVCAST: public Agent
{ //define object from timer
B_suppression_Timer bstimer;
}
//initialized timer in Constructor of the SDVCAST
SDVCAST::SDVCAST(nsaddr_t id) : Agent(PT_SDVCAST),
bstimer(this){
}
// start timer
void
SDVCAST::weightepersistence(Packet *p, double delay){
bstimer.resched(delay);
}
// define expire of bstimer
void
B_suppression_Timer::expire(Event *p){
agent->rebroadcast((Packet*)p, 0);
}
感谢您的回复,已完成此步骤。我测试协议,所以发送和接收Hello消息工作正常。通过使用Eclipse调试ns2我发现从事件到包的投射是不正确的,不知道为什么!所以我必须转换到Handler类,并使用句柄函数而不是TimerHandler及其“过期”。错误消息'无效SDVCAST数据包类型'消失,但不幸的是执行停止并收到分段错误消息。 –
当模拟过于复杂时,可能会出现'Segmentation fault',或者只是无法使用ns2进行处理。有时一个操作系统的变化可以帮助。 –
我已经在Ubuntu 12.04上安装ns 2.35。是的,我正试图在DV-Cast协议上实现安全层,这个协议本身很复杂。尽管通过多种功能降低了复杂性。我需要使用定时器,我会做什么?提前致谢。 –