一、下載gpsr協議源碼,在~/ns-allinone-2.35/ns-2.35下解壓,得到gpsr文件夾。
源碼地址:點擊打開鏈接
7個爲協議實現文件:
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
以上4個文件爲仿真所需文件
gpsr.tcl : the node and agent creation functions used by simultion configuration in wireless-gpsr.tclwireless-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
二、修改packet.h
進入~/ns-allinone-2.35/ns-2.35/common文件夾, 打開packet.h文件,增加一行:
static const packet_t PT_GPSR = 73
關鍵代碼如圖:
static const packet_t PT_GPSR = 73;
// insert new packet types here
static packet_t PT_NTYPE = 74; // This MUST be the LAST one
三、修改trace/cmu-trace.cc
進入~/ns-allinone-2.35/ns-2.35/trace,打開cmu-trace.cc文件。
在65行左右增加一行:
#include <gpsr/gpsr_packet.h>
關鍵代碼如圖:
#include <mdart/mdart_function.h>
#include <gpsr/gpsr_packet.h>
#include <cmu-trace.h>
在void CMUTrace::format(Packet *p, const char *why){}中第1460行左右增加2行:
case PT_GPSR:
break;
關鍵代碼如圖:
case PT_PING:
break;
case PT_GPSR:
break;
default:
四、修改priqueue.cc
進入~/ns-allinone-2.35/ns-2.35/queue文件夾, 打開priqueue.cc文件。
在void PriQueue::rece(Packet *p, Handler *h){}中第95行附近增加一行:
case PT_GPSR:
關鍵代碼如圖:
case PT_AOMDV:
case PT_GPSR:
case PT_MDART:
五、修改ns-packet.tcl
在~/ns-allinone-2.35/ns-2.35/tcl/lib文件夾, 打開ns-packet.tcl文件。
在set protolist{}中174行附近加入一行
GPSR
關鍵代碼如圖:
Diffusion # diffusion/diffusion.cc
GPSR
IMEP # Internet MANET Encapsulation Protocol, for ad-hoc networks
六、修改Makefile
在~/ns-allinone-2.35/ns-2.35,打開Makefile
在OBJ_CC = 的最後加入
gpsr/gpsr_neighbor.o gpsr/gpsr_sinklist.o gpsr/gpsr.o \
關鍵代碼如圖:
wpan/p802_15_4trace.o wpan/p802_15_4transac.o \
apps/pbc.o \
gpsr/gpsr_neighbor.o gpsr/gpsr_sinklist.o gpsr/gpsr.o \
$(OBJ_STL)
注意:每個【.o】後均有一個空格,包括最後一個【gpsr.o】
如果需要加入調試信息,則在CCOPT = -Wall 加上 -g, 如下:
CCOPT = -g -Wall
七、重新編譯
cd ~/ns-allinone-2.35/ns-2.35/common
touch packet.cc
cd ..
make clean
make
八、 運行仿真
進入~/ns-allinone-2.35/ns-2.35/gpsr文件夾,運行:ns wireless_gpsr.tcl
有疑問可參看源碼包中的readme。
原創文章,轉載請註明!
搜索
複製