ns 2.35中移值gpsr协议(KeLiu版)

来源:互联网 发布:多益网络有年终奖吗 编辑:程序博客网 时间:2024/05/16 02:02

今日有空,把前期在ns 2.35平台上移值gpsr协议的过程记录一下,作以备忘。

1. 下载gpsr协议源文件

    下载地址为:http://www.cs.binghamton.edu/~kliu/research/ns2code/GPSR_KeLiu_SUNY_Binghamton.tgz

2. 建立gpsr文件夹,并拷贝协议文件

    在【~/ns-allinone-2.35/ns-2.35】下新建【gpsr】文件夹,并将第1步中下载好的压缩包解压到此目录中。
    各个文件功能如下:
  • gpsr_packet.h : definition of packets of different type used by this implementaion
  • gpsr_neighbor.h : definition of the neighbor list of each node used by this gpsr implementation including the planaring procedure (both GG and RNG)
  • gpsr_neighbor.cc : the implementation of the neighbor list class
  • gpsr.h : the definition of functions of GPSR routing agent of this implementation
  • gpsr.cc : the implementation of the GPSR routing agent
  • gpsr_sinklist.h: definition used for scenarios with multiple sinks 
  • gpsr_sinklist.cc: implementation of gpsr_sinklist.cc
  • 以上7个为协议实现文件
  • gpsr.tcl : the node and agent creation functions used by simultion configuration in wireless-gpsr.tcl
  • wireless-gpsr.tcl : the simulation configuration 
  • grid-deploy10x10.tcl : 100 nodes in a 200x200 meter area 
  • cbr100.tcl : node 99 sends cbr traffic on UDP to node 0
  • 以上4个文件为仿真所需文件

3. 修改相关文件

(1)修改的文件清单(均在【~/ns-allinone-2.35/ns-2.35】目录下)
  • common/packet.h
  • trace/cmu-trace.cc
  • queue/priqueue.cc
  • ns-packet.tcl
  • Makefile
(2) 修改packet.h文件
  • 进入【~/ns-allinone-2.35/ns-2.35/common】文件夹, 打开【packet.h】文件。
    • 在「typedef unsigned int packet_t;」后约200行附近,增加一行:
      • static const packet_t PT_GPSR = 73
    • 而后修改
      • static const packet_t PT_NTYPE = 73; //This MUST be the LAST one
      • 为:
      • static const packet_t PT_NTYPE = 74; //This MUST be the LAST one
      • 即把73修改为74.
  • 在static void initName(){}中第420行左右增加一行:
    • name_[PT_GPSR]="GPSR"
 (3)修改trace/cmu-trace.cc
  • 进入【~/ns-allinone-2.35/ns-2.35/trace】,打开【cmu-trace.cc】文件。
    • 65行左右增加一行
      • #include <gpsr/gpsr_packet.h>
    • 在「void CMUTrace::format(Packet *p, const char *why){}中第1460行左右增加2行
      • case PT_GPSR:
      •     break;
 (4)修改priqueue.cc
  •  进入【~/ns-allinone-2.35/ns-2.35/queue】文件夹, 打开【priqueue.cc】文件。
    • 在void PriQueue::rece(Packet *p, Handler *h){}中第95行附近增加一行:
      • case PT_GPSR:
 (5)修改ns-packet.tcl
  • 【~/ns-allinone-2.35/ns-2.35/tcl/lib】文件夹, 打开【ns-packet.tcl】文件。 
    • 在「set protolist{}」中174行附近加入一行
      • GPSR
 (6)修改Makefile
  • 【~/ns-allinone-2.35/ns-2.35】,打开【Makefile
    • 在OBJ_CC =  的最后按照格式加入( gpsr前为TAB键而不是空格)
      • gpsr/gpsr_neighbor.o gpsr/gpsr_sinklist.o gpsr/gpsr.o \
        • 注意:每个【.o】后均有一个空格,包括最后一个【gpsr.o】
  • 如果需要加入调试信息,则在CCOPT =  -Wall 加上 -g,  如下:
    • CCOPT =  -g  -Wall

4. 重新编译

cd ~/ns-allinone-2.35/ns-2.35/common
touch packet.cc
cd ..
make clean
make
5. 运行仿真
进入【~/ns-allinone-2.35/ns-2.35/gpsr】文件夹,运行:
ns wireless_gpsr.tcl

6. 以下部分为网友认为应该修改的部分,经验证,在我的机器上不需修改。
在使用脚本wireless_gpsr.tcl进行场景仿真时,需要对 ns-2.35所在的路径进行修改
 
   将wireless_gpsr.tcl 中的将ns2home 修改成  $HOME/ns-allinone-2.35/ns-2.35/
 
如:
 
source ../gpsr.tcl 要改成如下
 
source /home/f/ns-allinone-2.35/ns-2.35/gpsr/gpsr.tcl
 
文中还有以下几处,都需要给出正确的绝对路径
 
Set opt(cp)         "/home/f/ns-allinone-2.35/ns-2.35/gpsr/cbr100.tcl"
 
set opt(sc)             "/home/f/ns-allinone-2.35/ns-2.35/gpsr/grid-deploy10x10.tcl"
 
Source  /home/f/ns-allinone-2.35/ns-2.35/tcl/mobility/timer.tcl
 
Source  /home/f/ns-allinone-2.35/ns-2.35/tcl/lib/ns-bsnode.tcl
 
Source  /home/f/ns-allinone-2.35/ns-2.35/tcl/mobility/com.tcl

参考:
1.  协议中的readme
2.《NS2笔记8 gpsr移植》,新浪博客,http://blog.sina.com.cn/s/blog_414c2a9a01013r9e.html

本文历史:
2015.1.14    v1    XAN
0 0
原创粉丝点击