NS2中基于AODV协议的请求洪泛攻击防御
2013-07-07 23:33
435 查看
转载地址: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
2: add following code in aodv.cc somewhere
3: add the following funtion in aodv.h inside protected member of AODV class
4:count number of request coming from neighbor and take the decision in ‘recvRequest()’
5: for flushing the request count table entries implement flushing mechanism
the timer for flushing entry...
the cache timer and related information in AODV.h
the information to aodv.cc constructor
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 void AODV::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...
void CacheTimer::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协议中添加blackhole attacker(黑洞攻击)
- 基于NS2的网络路由协议仿真(AODV、COPE+AODV)
- 在NS2 AODV协议中添加blackhole attacker(黑洞攻击) [转载]
- ns2下完善基于AODV的TDMA协议
- ARP协议全面实战手册——协议详解、攻击与防御(内部资料)
- ns2,AODV协议解析
- ns2--AODV协议分析
- NS2 学习笔记—— AODV协议
- TCP SYN洪泛攻击的原理及防御方法
- 基于http的追加协议、构建web内容的技术、web的攻击技术(9,10,11)
- 基于Cookie的攻击和防御
- ARP缓存表的构成ARP协议全面实战协议详解、攻击与防御
- 基于NS2的Ad Hoc网络AODV路由协议性能评估的仿真
- AODV协议的NS2仿真
- TCP SYN洪泛攻击的原理及防御方法
- NS2 学习笔记—— AODV协议
- 基于NS2的Ad Hoc网络AODV路由协议仿真[ubuntu10.04+NS2.35含代码文件] [转载]
- NS2下AODV协议aodv.cc注释