我想在ns2模拟器中修改节点的行为。特别是,我必须在dsr协议的模拟中修改节点的路由。我知道dsragent.cc是管理此协议路由的类。但是如果我有一个包含10个节点的tcl脚本,称为$node1,$node2...node$10,那么如何修改$node5在dsr协议中的行为呢?如何找到该节点的单一行为?
发布于 2017-11-17 04:31:19
我曾与其他路由协议,但我会提到一些要点..may它是有用的。
为了访问c++中的特定节点对象,您需要知道它在tcl中的地址。然后,您可能需要在forward或recv函数中进行修改。您可以从通用、IP、DSR报头中提取所需的所有信息
DSRAgent::recv(Packet* packet, Handler*)
/* handle packets with a MAC destination address of this host, or
the MAC broadcast addr */
{
hdr_sr *srh = hdr_sr::access(packet);
hdr_ip *iph = hdr_ip::access(packet);
hdr_cmn *cmh = hdr_cmn::access(packet);
p.dest = ID((Address::instance().get_nodeaddr(iph->daddr())),::IP);
p.src = ID((Address::instance().get_nodeaddr(iph->saddr())),::IP);
下面的意思是..如果当前节点是数据包的生成器
if (p.src == net_id) {code}
选择特定节点对象
if (net_id==ID("put the node address here", ::IP)) \\ notice net_id is a struct
{
your code here
}
您可以从tcl分配节点地址,该地址将通过命令函数传递给c++
DSRAgent::command(int argc, const char*const* argv)
.
.
if (strcasecmp(argv[1], "addr") == 0)
{
int temp;
temp = Address::instance().str2addr(argv[2]);
net_id = ID(temp, ::IP);
flow_table.setNetAddr(net_id.addr);
.
}
问候
https://stackoverflow.com/questions/45372058
复制相似问题