在 ns2.35 添加ZRP 协议

网上已有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 <cmu-trace.h>
  #include <mobilenode.h>
  #include <simulator.h>
+ #include <zrp/zrp.h>    // For ZRP
  //<zheng: add for 802.15.4>
  #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.h
touch ns-2.35/trace/cmu-trace.h


# make NS-2.
sudo make -k
sudo make install

 

现在可以运行测试例子了,可以参考http://www.cnblogs.com/lungeer/articles/2443894.html

 

 

 

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值