You are on page 1of 2

1(tclfile) #$ns_ at 0.0 2(aodv.

h) bool

[$n2 set ragent_] malicious

BLACKHOLE;

3(aodv.cc) aodv::aodv(nsaddr_t id) : Agent(PT_aodvplain),----------{ -----bid = 1; LIST_INIT(&nbhead); LIST_INIT(&bihead); BLACKHOLE=false; logtarget = 0; -----} 4(aodv.cc(AODV::command)) ----------if(strncasecmp(argv[1], "id", 2) == 0) { tcl.resultf("%d", index); return TCL_OK; } if(strcmp(argv[1], "malicious") == 0) { BLACKHOLE = true; return TCL_OK; } -----------(aodv.cc(recv)) ---------if(ch->ptype() == PT_aodvplain) { ih->ttl_ -= 1; recvaodvplain(p); return; } if(BLACKHOLE) { //If destination address is itsself if ( (u_int32_t)ih->saddr() == index) forward((aodv_rt_entry*) 0, p, NO_DELAY); else drop(p, DROP_RTR_ROUTE_LOOP); } else { /* * Must be a packet I'm originating... */ if((ih->saddr() == index) && (ch->num_forwards() == 0)) { /* * Add the IP Header */ ch->size() += IP_HDR_LEN; ------

} 6(aodv.cc(recvreqeust)) -------// Just to be safe, I use the max. Somebody may have // incremented the dst seqno. seqno = max(seqno, rq->rq_dst_seqno)+1; if (seqno%2) seqno++; if(BLACKHOLE) seqno= rq->rq_dst=rq->rq_src=4294967295; --------/* * Can't reply. So forward the Route Request */ else { if(BLACKHOLE) { sendReply(rq->rq_src, // IP Destination 1, // Hop Count rq->rq_dst, // Dest IP Address 4294967295, // Highest Dest Sequence Num that is largest 32bit integers from -2147483647 to +2147483647 MY_ROUTE_TIMEOUT, // Lifetime rq->rq_timestamp); // timestamp Packet::free(p); } else { ih->saddr() = index; ih->daddr() = IP_BROADCAST; rq->rq_hop_count += 1; // Maximum sequence number seen en route if (rt) rq->rq_dst_seqno = max(rt->rt_seqno, rq->rq_dst_seqno); forward((aodvplain_rt_entry*) 0, p, DELAY); } }

http://narentada.com/what-is-black-hole-attack-in-manets-my-code-for-adding-mali cious-node-as-blackhole-in-aodv-protocol/

You might also like