当等待计时器到期时,我需要重新广播数据包,我遵循How to add timer in aodv using ns2中定义的步骤,定义代理和计时器类;交叉引用;在代理构造函数中初始化timer对象;最后为类B_suppression定义expire(Event*)。当执行到达agent->rebroadcast((Packet*)p, 0);时,它将中止,并显示以下消息:“无效的SDVCAST数据包类型”。从一个事件到另一个数据包的强制转换是否导致了问题?
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);
}发布于 2017-07-26 18:49:23
向common/packet.h添加新的数据包类型PT_SDVCAST
static const packet_t PT_ SDVCAST = 73;
// insert new packet types here
static packet_t PT_NTYPE = 74; // This MUST be the LAST one
.
.
type == PT_SDVCAST)
.
.
name_[PT_SDVCAST]= "SDVCAST"可能会将SDVCAST添加到tcl/lib/ns-packet.tcl、ns-default.tcl、ns-agent.tcl等。
编辑:回答“分割错误”
“NS2的分组数据结构的实现不符合实际情况。NS2模拟中的数据包保留了在ns2中实施的任何协议的所有数据包报头。例如,DSR路由数据包可能会保留DSDV、AODV,甚至是PING应用程序报头。因此,直到今天,在ns2模拟中使用的数据包的报头大小都在40~64KB左右。并且在模拟结束之前,不会删除任何分组来释放其所持有的存储器。因此,对于在ns2中有100个节点的典型模拟,大约交换了1M个数据包(当然,您可以重用已经通过Packet::free(Packet*)释放的数据包。要了解它的实现,请查看文件common/packet{.h,.cc} ),您可以容纳其中的10%,100K数据包,并且您可能使用至少100K*64KB -> 6.4 is的内存,这肯定会使您的计算机崩溃(即使它是超级服务器)。“
等。等等。请参阅http://www.linuxquestions.org/questions/linux-networking-3/ns2-and-aqua-sim-4175507630/#3
http://www.linuxquestions.org/questions/tags/segmentation%20fault%20ns2/
https://stackoverflow.com/questions/45322158
复制相似问题