博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在 ns2.35 添加ZRP 协议
阅读量:5051 次
发布时间:2019-06-12

本文共 7782 字,大约阅读时间需要 25 分钟。

网上已有ns2.33平台的zrp源代码,这里只是移植到NS2 2.35版本。

 

需要修改的文件有,在ns-allinone-2.35-RC[ ]文件夹下:

注意:修改前请自行备份。

(a)ns-2.35/tcl/lib/ns-agent.tcl(b)ns-2.35/tcl/lib/ns-default.tcl(c)ns-2.35/tcl/lib/ns-lib.tcl(d)ns-2.35/tcl/lib/ns-packet.tcl(e)ns-2.35/common/packet.h(f)ns-2.35/trace/cmu-trace.h(g)ns-2.35/trace/cmu-trace.cc(h)ns-2.35/Makefile

 

注意:行号略有出入,请注意识别,红色代码为更改部分。

1、修改packet.h

****************** 67,72 ****--- 67,73 ----  #define HDR_TORA(p)     (hdr_tora::access(p))  #define HDR_IMEP(p)     (hdr_imep::access(p))  #define HDR_CDIFF(p)    (hdr_cdiff::access(p))  /* chalermak's diffusion*/+ #define HDR_ZRP(p)      (hdr_zrp::access(p))    // [CHANGE-1(for_ZRP-AGENT) : Lines#1]  //#define HDR_DIFF(p)     (hdr_diff::access(p))  /* SCADD's diffusion ported into ns */  #define HDR_LMS(p)        (hdr_lms::access(p))  ***************--- 181,188 ----  static const packet_t PT_BLTRACE = 60;            // insert new packet types here+ static const packet_t PT_ZRP = 73 //by wcl,这个一定要为倒数第二个数字//static packet_t       PT_NTYPE = 74; // This MUST be the LAST one! static packet_t       PT_NTYPE = 62; // This MUST be the LAST one    enum packetClass  {***************--- 305,312 ----          name_[PT_CtrMcast_Encap]= "CtrMcast_Encap";          name_[PT_CtrMcast_Decap]= "CtrMcast_Decap";          name_[PT_SRM]= "SRM";+          name_[PT_ZRP]= "ZRP";// [CHANGE-3(for_ZRP-AGENT) : Lines#1]    !           name_[PT_REQUEST]= "sa_req";              name_[PT_ACCEPT]= "sa_accept";          name_[PT_CONFIRM]= "sa_conf";

 

2、修改Makefile,没有任何扩展名的那个。

***************--- 53,59 ----  # for diffusion  #DIFF_INCLUDES = "./diffusion3/main ./diffusion3/lib ./diffusion3/nr ./diffusion3/ns"    CCOPT   =  -g -Wall -Wall -Wno-write-strings //by wcl  STATIC    =   #LDFLAGS    = $(STATIC)  LDFLAGS    =  -Wl,-export-dynamic ****************** 259,264 ****--- 259,265 ----      mac/mac-simple.o \      satellite/sat-hdlc.o \      dsdv/dsdv.o dsdv/rtable.o queue/rtqueue.o \+     zrp/zrp.o \          routing/rttable.o \      imep/imep.o imep/dest_queue.o imep/imep_api.o \      imep/imep_rt.o imep/rxmit_queue.o imep/imep_timers.o \

 

3、修改ns-agent.tcl

****************** 192,194 ****--- 192,199 ----  Agent/AODV set sport_   0  Agent/AODV set dport_   0  + Agent/ZRP instproc init args {  # [CHANGE-4(for_ZRP-AGENT) : Lines#4]     +       $self next $args+ }+ Agent/ZRP set sport_   0+ Agent/ZRP set dport_   0

 

4、修改ns-default.tcl

****************** 1337,1342 ****--- 1337,1348 ----  # Routing protocol agents  Agent/Mcast/Control set packetSize_ 80  + # [CHANGE-5(for_ZRP-AGENT) : Lines#3]+ Agent/ZRP set packetSize_ 100              + #Agent/ZRP set sport_ 0+ #Agent/ZRP set dport_ 0+ +   # Dynamic routing defaults  Agent/rtProto set preference_ 200        ;# global default preference  Agent/rtProto/Direct set preference_ 100

 

5、修改ns-lib.tcl

****************** 621,626 ****--- 621,630 ----          set ragent [$self $rtAgentFunction_ $node]      } else {          switch -exact $routingAgent_ {+         # [CHANGE-6(for_ZRP-AGENT) : Lines#3]        +              ZRP  {        +                  set ragent [$self create-zrp-agent $node]+                  }              DSDV {                  set ragent [$self create-dsdv-agent $node]              }****************** 791,796 ****--- 795,808 ----      return $nodetype  }  + # [CHANGE-7(for_ZRP-AGENT) : Lines#6] + Simulator instproc create-zrp-agent { node } {+         set ragent [new Agent/ZRP [$node id]]+         $node set ragent_ $ragent+     $self at 0.0 "$ragent start"    ;# start updates+         return $ragent+ }+   Simulator instproc create-tora-agent { node } {          set ragent [new Agent/TORA [$node id]]      $node set ragent_ $ragent

 

6、修改ns-packet.tcl

****************** 167,172 ****--- 167,173 ----          MIP     # Mobile IP, mobile/mip-reg.cc      Smac     # Sensor-MAC      TORA     # routing protocol for ad-hoc networks+      ZRP     # [CHANGE-8(for_ZRP-AGENT) : Lines#1]   # Other:      Encap     # common/encap.cc          IPinIP     # IP encapsulation

 

7、修改cmu-trace.cc

****************** 54,59 ****--- 54,60 ----  #include 
#include
#include
+ #include
// For ZRP //
#include "wpan/p802_15_4pkt.h" #include "wpan/p802_15_4trace.h"****************** 464,469 ****--- 465,538 ---- // Note: HDLC format (format_hdlc()) has moved to satellite tracing + // [CHANGE-8(for_ZRP-AGENT)]+ void+ CMUTrace::format_zrp(Packet *p, int offset)+ {+ struct hdr_cmn *ch = HDR_CMN(p);+ struct hdr_ip *ih = HDR_IP(p);+ struct hdr_zrp *hdrz = HDR_ZRP(p);+ + char pktType[20];+ switch(hdrz->zrptype_) {+ case 0: // NDP_BEACON+ strcpy(pktType, "NDP_BEACON");+ break;+ case 1: // NDP_BEACON_ACK+ strcpy(pktType, "NDP_BEACON_ACK");+ break;+ case 2: // IARP_UPDATE+ strcpy(pktType, "IARP_UPDATE");+ break;+ case 3: // IARP_DATA+ strcpy(pktType, "IARP_DATA");+ break;+ case 4: // IERP_REPLY+ strcpy(pktType, "IERP_REPLY");+ break;+ case 5: // IERP_REQUEST+ strcpy(pktType, "IERP_REQUEST");+ break;+ case 6: // IERP_ROUTE_ERROR+ strcpy(pktType, "IERP_ROUTE_ERROR");+ break;+ case 7: // IERP_DATA+ strcpy(pktType, "IERP_DATA");+ break;+ default: // Invalid Packet+ strcpy(pktType, "INVALID");+ break; + }+ + // hack the IP address to convert pkt format to hostid format+ // for now until port ids are removed from IP address. -Padma.+ int src = Address::instance().get_nodeaddr(ih->saddr());+ int dst = Address::instance().get_nodeaddr(ih->daddr());+ + if (pt_->tagged()) {+ // Need to determine tag names for this data+ //sprintf(pt_->buffer() + offset,+ // "",+ // );+ } else if (newtrace_) {+ sprintf(pt_->buffer() + offset,+ "-Zsrc %d -Zdst %d -Ztyp %s -Zseq %d -Zqid %d -Zlbc %d ",+ hdrz->src_, // ZRP Source+ hdrz->dest_, // ZRP Destination+ pktType, // Packet-Type+ hdrz->seq_, // Sequence Number+ hdrz->queryID_, // Query ID+ hdrz->lastbc_); // Last Bordercaster+ } else {+ sprintf(pt_->buffer() + offset, "------- [%d:%d %d:%d %d %d] ",+ src, ih->sport(),+ dst, ih->dport(),+ ih->ttl_, (ch->next_hop_ < 0) ? 0 : ch->next_hop_);+ }+ }+ + + void CMUTrace::format_arp(Packet *p, int offset) {****************** 1218,1223 ****--- 1287,1297 ---- case PT_DSR: format_dsr(p, offset); break;+ // pgi - added for ZRP // [CHANGE-9(for_ZRP-AGENT) : Lines#5] + case PT_ZRP:+ format_zrp(p, offset);+ break;+ // pgi - added for ZRP case PT_MESSAGE: case PT_UDP: format_msg(p, offset);

 

8、修改cmu-trace.h

****************** 149,154 ****--- 149,156 ----      void    format_smac(Packet *p, int offset);      void    format_ip(Packet *p, int offset);  + //    [CHANGE-11(for_ZRP-AGENT) : Lines#1] +     void    format_zrp(Packet *p, int offset); // pgi added for zrp      void    format_arp(Packet *p, int offset);      void    format_hdlc(Packet *p, int offset);      void    format_dsr(Packet *p, int offset);

 

上述修改完后,将下载的2.33的压缩包解压,将其中的zrp文件夹放到ns-2.35文件夹下。

用终端进入ns-2.35文件夹,运行下述代码

touch ns-2.35/common/packet.htouch ns-2.35/trace/cmu-trace.h# make NS-2.sudo make -ksudo make install

 

现在可以运行测试例子了,可以参考。

 

 

 

转载于:https://www.cnblogs.com/lungeer/archive/2012/04/14/2447579.html

你可能感兴趣的文章
QT和JS的互相调用例子
查看>>
虚拟网卡配置
查看>>
php安装扩展
查看>>
mvn dependency:tree
查看>>
伸展树——自顶向下
查看>>
查询sql server 2008所有表和行数
查看>>
SQL 中不同类型的表连接
查看>>
最小高度设置
查看>>
css3创建3D场景
查看>>
40种聚会小游戏,出去玩不会冷场了!
查看>>
Spring知识点总结
查看>>
c#一些处理解决方案(组件,库)
查看>>
安装ansible前期准备,python和pip
查看>>
NPoco学习篇(2):NPoco简介
查看>>
【Codeforces】976A Minimum Binary Number
查看>>
安装最新版Mysql(APT方式安装)
查看>>
web.xml中配置——配置springmvc
查看>>
父容器不根据内容自适应高度的解决方法
查看>>
android-non-ui-ui-thread-communications-part-5-5
查看>>
android开发两种退出程序方式(killProcess,System.exit)
查看>>