首先,在NS2 AODV协议中,希望某个节点侦听到其邻居节点间通信信息时。不能直接在AODV协议中获取邻居节点之间的数据。所以要设置成混杂模式来监听过程。下面具体介绍如何添加该过程:
1.修改aodv/aodv.h
Make AODV agent a child class of Tap, and define the Mac variable
#include <mac.h> class AODV: public Tap, public Agent { public: void tap(const Packet *p); ...... protected: Mac *mac_; ...... }
int AODV::command(int argc, const char*const* argv) { ...... else if(argc == 3) { ...... else if (strcmp(argv[1], "install-tap") == 0) { mac_ = (Mac*)TclObject::lookup(argv[2]); if (mac_ == 0) return TCL_ERROR; mac_->installTap(this); return TCL_OK; } } return Agent::command(argc, argv); } void AODV::tap(const Packet *p) { // put your code here }
Node/MobileNode instproc add-target { agent port } { $self instvar dmux_ imep_ toraDebug_ mac_ ...... # Special processing for AODV set aodvonly [string first "AODV" [$agent info class]] if {$aodvonly != -1 } { $agent if-queue [$self set ifq_(0)] ; # ifq between LL and MAC $agent install-tap $mac_(0) ...... }
else if (strcmp(argv[1], "install-tap") == 0) { printf("执行install-tap /n"); mac_ = (Mac*)TclObject::lookup(argv[2]); if (mac_ == 0) return TCL_ERROR; mac_->installTap(this); return TCL_OK; }
void AODV::tap(const Packet *p) { struct hdr_cmn *ch = HDR_CMN(p); struct hdr_ip *ih = HDR_IP(p); //sendToWatchdog(p); if(ch->ptype() == PT_AODV) //为AODV Packet { struct hdr_aodv *ah = HDR_AODV(p); switch(ah->ah_type) { case AODVTYPE_RREQ: Sniffer_readRREQ(p); break; case AODVTYPE_RREP: Sniffer_readRREP(p); break; default: break; } } }
$i就是你要定义的IDS节点ID。
- 顶
- 0
- 踩
- 0