【问题标题】:How to modify the behavior of a node in ns2 simulator?如何在 ns2 模拟器中修改节点的行为?
【发布时间】:2017-07-28 11:14:03
【问题描述】:

我想在 ns2 模拟器中修改节点的行为。特别是,我必须在 dsr 协议的模拟中修改节点的路由。 我知道 dsragent.cc 是管理这个协议路由的类。但是如果我有一个10个节点的tcl脚本,叫做$node1,$node2...node$10,如何修改$node5在dsr协议中的行为呢?如何找到该节点的单一行为?

【问题讨论】:

    标签: c++ network-programming tcl simulator ns2


    【解决方案1】:

    我曾使用过其他路由协议,但我会提到一些要点..可能有用。

    为了在 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);
    .
    }
    

    问候

    【讨论】:

    猜你喜欢
    • 2013-10-03
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 2019-11-03
    相关资源
    最近更新 更多