NS2中基于AODV协议的请求洪泛攻击防御
来源:互联网 发布:手机淘宝首页多宽 编辑:程序博客网 时间:2024/05/16 16:22
转载地址:http://narentada.com/code-for-preventing-flood-attack-in-aodv/
step 1:Create two cache table ‘aodv_RREQcount’ and ‘aodv_broodyList’ in aodv_rtable.h
/* aodv request count cache *///NVT 11Feb12 class aodv_RREQcount{ friend class AODV; friend class aodv_rt_entry;public: aodv_RREQcount(u_int32_t c) {ct_addr=c; RREQentry=0;}protected: LIST_ENTRY(aodv_RREQcount) ct_link; u_int32_t RREQentry; nsaddr_t ct_addr; double ct_expire; }; LIST_HEAD(aodv_countcache, aodv_RREQcount);/*struct broodyList{ bool flag; nsaddr_t addr_; };*/ class aodv_broodyList{ friend class AODV; friend class aodv_rt_entry; public: //aodv_broodyList(u_int32_t e){bd_addr=e;} protected: LIST_ENTRY(aodv_broodyList) bd_link; nsaddr_t bd_addr; };Step 2: add following code in aodv.cc somewhere
aodv_broodyList*AODV::bd_lookup(nsaddr_t id){aodv_broodyList *bd = bdhead.lh_first;for(;bd;bd=bd->bd_link.le_next){ if(bd->bd_addr ==id) break; }return bd;}step 3: add the following funtion in aodv.h inside protected member of AODV class
void ct_add(nsaddr_t id); //NVT 11FEB12 //void ct_lookup(nsaddr_t id); //aodvplain_RREQcount* ct_lookup(nsaddr_t id);//NVT 11FEB12 void ct_remove(nsaddr_t id);//NVT 12FEB12 void ct_flush(void);//NVT 12FEB12 aodv_broodyList* bd_lookup(nsaddr_t id); //NVT 12FEB12Step 4:count number of request coming from neighbor and take the decision in ‘recvRequest()’
/* * Drop if: * - I'm the source * - I recently heard this request. */ aodv_broodyList *bd;bd=bd_lookup(rq->rq_src);if(!bd){ AODV_Neighbor *nb; //aodvplain_RREQcount *ct; nb = nb_lookup(rq->rq_src); if((nb) && (rq->rq_hop_count == 1) ) { printf("\nin recieve request at current time ::%f, index node %d is neighbor? 'TRUE', of node %d",CURRENT_TIME,index,rq->rq_src); double now = CURRENT_TIME; int peak_value =11; aodv_RREQcount *ct = rt_ctlist.lh_first; //aodvplain_RREQcount *ct2; for(; ct; ct = ct->ct_link.le_next) { if(ct->ct_addr == rq->rq_src) { if((ct->ct_expire <= now) && (ct->RREQentry >peak_value) ) { printf("\nat receive reqeustTimeout:::Flushhhhhhhhhh\n"); //*printf("\nno of count:: %d\n",count); //*count++; //ct_remove(ct->ct_addr); printf("\nexceed peak value giving permenent penently by droping packet\n"); aodv_broodyList *bd1 = new aodv_broodyList(); bd1->bd_addr=ct->ct_addr; LIST_INSERT_HEAD(&bdhead, bd1, bd_link); LIST_REMOVE(ct,ct_link); delete ct; break; } else if (ct->ct_expire<=now) { printf("\nOnly Timeout:::Flushhhhhhhhh\n"); LIST_REMOVE(ct,ct_link); delete ct; break; } ct->RREQentry= ct->RREQentry+1; printf(" count table entry:::%d",ct->RREQentry); break; } } if(!ct) { aodv_RREQcount *ct1 = new aodv_RREQcount(rq->rq_src); //*printf("\nin ct_add while adding entry\n"); //*printf("\nfrom node %d ct->ct_addr==%d\n",id,ct->ct_addr); ct1->ct_expire = CURRENT_TIME + 1; ct1->RREQentry= ct1->RREQentry+1; LIST_INSERT_HEAD(&rt_ctlist, ct1, ct_link); //printf("\nin node %d count table entry ::%d",index,ct1->RREQentry); /*ct= ct_lookup(rq->rq_src); if((!ct)) { printf("\nooop no entry of node %d",rq->rq_src); ct_add(rq->rq_src); }*/ } }}else{ printf("\nat time %f dropppppppp by %d\n",CURRENT_TIME,index); drop(p, DROP_RTR_ROUTE_LOOP); return;}Step 5: for flushing the request count table entries implement flushing mechanism
//NVT 11FEB12 voidAODV::ct_flush() {aodv_RREQcount *ct = rt_ctlist.lh_first;aodv_RREQcount *ct1; //aodvplain_RREQcount *ctc;double now = CURRENT_TIME; for(; ct; ct =ct1 ) {ct1=ct->ct_link.le_next; if(ct->ct_expire <= now) { printf("\nTimeout:::Flushhhhhhhhhhhh\n"); LIST_REMOVE(ct,ct_link); delete ct; }}}Step 6: add the timer for flushing entry...
voidCacheTimer::handle(Event*) {agent->ct_flush(); Scheduler::instance().schedule(this, &intr, CACHE_INTERVAL);}Step 7: add the cache timer and related information in AODV.h
class CacheTimer : public Handler {public: CacheTimer(AODV* a): agent(a){} void handle(Event*);private: AODV *agent; Event intr;}; class AODV: public Agent{//...... friend class CacheTimer;//Added by NVT*/ //.... Protected: //.... void ct_flush(void);//NVT 12FEB12//... CacheTimer ctimer; //added byNVT }step 8:add the information to aodv.cc constructor
AODV::AODV(nsaddr_t id) : Agent(PT_aodvplain), ctimer(this){//............... LIST_INIT(&bdhead); LIST_INIT(&nbhead); LIST_INIT(&bihead); LIST_INIT(&rt_ctlist); LIST_INIT(&trhead);//............ }
- NS2中基于AODV协议的请求洪泛攻击防御
- NS2中基于AODV协议实现的请求洪泛攻击
- 基于NS2的网络路由协议仿真(AODV、COPE+AODV)
- 在NS2 AODV协议中添加blackhole attacker(黑洞攻击)
- ns2下完善基于AODV的TDMA协议
- ns2中AODV协议HDR_CMN(p)的含义
- ns2中aodv协议中路由链表的操作
- 在NS2 AODV协议中添加blackhole attacker(黑洞攻击) [转载]
- NS2中AODV协议混杂模式配置
- NS2中DSDV, AODV, DSR协议评估
- ns2--AODV协议分析
- ns2,AODV协议解析
- 基于NS2的AODV协议的修改与仿真的实现
- 基于NS2的Ad Hoc网络AODV路由协议性能评估的仿真
- 基于NS2的Ad Hoc网络AODV路由协议仿真[ubuntu10.04+NS2.35含代码文件] [转载]
- 对ns2中aodv源文件的浅析
- NS2下AODV协议aodv.cc注释
- NS2下AODV协议aodv.cc注释
- 香港昂坪360缆车+贝澳+长洲岛+南丫岛两日游6-29/30
- 孙鑫VC++深入详解:Lesson7 Part3---对话框伸缩功能的实现
- Eclipse优化设置
- SAP View
- sublime text 2 注册码/破解方法
- NS2中基于AODV协议的请求洪泛攻击防御
- eclipse myeclipse 恢复copy过来的项目
- 面试题6:用两个栈实现队列
- _stdcall与_cdel
- HDU 1407 测试你是否和LTC水平一样高
- SSL-用Keytool和OpenSSL生成和签发数字证书
- SSL-用OpenSSL命令行生成证书文件
- 面试题7:用两个队列实现栈
- 这11道题据说要智商200的人才能全解出来