Tuesday, April 27, 2010

Interesting blogs

http://www.cse.msu.edu/~wangbo1/ns2/

http://peelmeagrape.net/eoin/swarm/

http://tagus.inesc-id.pt/~pestrela/ns2/ns2_tips.html

http://www.ict.csiro.au/staff/ren.liu/ns-2/simulate-802_11.htm

http://elmurod.net/wps/?p=72

How to Display RTS/CTS Packet Type in NS2 Trace File

http://www.cse.msu.edu/~wangbo1/ns2/

There are several posts on NS2 user mailing list explaining how to display RTS/CTS packet type in NS2 trace file. Here is an example. However, I failed to adopt them in NS 2.26 with new trace format. Here is my solution which just uses code written for old trace format. You only need to modify ns-2.26/trace/cmu-trace.cc in the following way and I think this solution can also work for NS versions later than 2.26.

void
CMUTrace::format_mac(Packet *p, const char *why, int offset)
{

......


/*
sprintf(pt_->buffer() + offset,
"-Ma %x -Md %x -Ms %x -Mt %x ",
mh->dh_duration,
ETHER_ADDR(mh->dh_da),
ETHER_ADDR(mh->dh_sa),
GET_ETHER_TYPE(mh->dh_body));
*/



sprintf(pt_->buffer() + offset,
"-Ma %x -Md %x -Ms %x -Mt %s ",
mh->dh_duration,
ETHER_ADDR(mh->dh_da),
ETHER_ADDR(mh->dh_sa),
((ch->ptype() == PT_MAC) ? (
(mh->dh_fc.fc_subtype == MAC_Subtype_RTS) ? "RTS" :
(mh->dh_fc.fc_subtype == MAC_Subtype_CTS) ? "CTS" :
(mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "ACK" :
"UNKN"
) : packet_info.name(ch->ptype())));



return;


}

Here is an exmaple NS2 trace file which displays the RTS/CTS/ACK information of MAC layer frame.

r -t 0.003583515 -Hs 0 -Hd -2 ... -Nl MAC -Nw --- -Ma 0 -Md 0 -Ms 0 -Mt ACK
s -t 0.003853348 -Hs 8 -Hd -2 ...-Nl MAC -Nw --- -Ma 2ff -Md 0 -Ms 8 -Mt RTS
r -t 0.004125515 -Hs 0 -Hd -2 ... -Nl MAC -Nw --- -Ma 2ff -Md 0 -Ms 8 -Mt RTS
s -t 0.004135515 -Hs 0 -Hd -2 ... -Nl MAC -Nw --- -Ma 1fd -Md 8 -Ms 0 -Mt CTS
r -t 0.004383682 -Hs 8 -Hd -2 ... -Nl MAC -Nw --- -Ma 1fd -Md 8 -Ms 0 -Mt CTS

Thursday, April 22, 2010

Notes

Google .. blackhole attack ns2 aodv ..
Examples
http://elmurod.net/wps/?p=196

http://cdsweb.cern.ch/record/1206617?ln=de
http://arxiv.org/pdf/0909.2371.pdf


Some code here : ?
Google .. prevent blackhole ns2 ..
? http://www.nesmd.com/shtml/18947.shtml ?

in reference to:

"Google .. blackhole attack ns2 aodv .. Examples http://elmurod.net/wps/?p=196 http://cdsweb.cern.ch/record/1206617?ln=de http://arxiv.org/pdf/0909.2371.pdf Some code here : ? Google .. prevent blackhole ns2 .. ? http://www.nesmd.com/shtml/18947.shtml ?"
- simulating blackhole attack in ns-29 (view on Google Sidewiki)

Example to create BH node

I want to make a node behave as blackhole node, using the above technique. The above method drops all packets that go through it, but it doesn’t kind of forces a packet to go through it by sending a high sequence number.
For that, i have done this within this fn. AODV::recvRequest(Packet *p):

if(malicious==true) {
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
index, // Dest IP Address
4294967295, // Max. Dest Sequence Num if the node is malicious
MY_ROUTE_TIMEOUT, // Lifetime
rq->rq_timestamp); // timestamp
}
else {
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
index, // Dest IP Address
seqno, // Dest Sequence Num
MY_ROUTE_TIMEOUT, // Lifetime
rq->rq_timestamp); // timestamp
}

and removed
if(malicious == true) {
drop(p, DROP_RTR_ROUTE_LOOP);
}

from rt_resolve() fn.

Now, what changes do i need to make, so that the code can distinguish data packets and management packets, so that it could drop the data packet

if you want to drop only data packets you need to check packet type reger HDR_CMN for more info.

Ns2 code

# Preamble
set ns [new Simulator]

# Tell the simulator to use dynamic routing
$ns rtproto DV
Agent/rtProto/DV set advertInterval 1.0
Agent/rtProto/DV set INFINITY 100

# Set ns color indices
$ns color 0 blue
$ns color 1 black
$ns color 2 turquoise
$ns color 3 orange
$ns color 4 gold
$ns color 5 red


# Open trace files
set f [open SIM.tr w]
$ns trace-all $f
set nf [open SIM.nam w]
$ns namtrace-all $nf


proc finish {} {
global ns f nf
$ns flush-trace
close $nf
close $f
puts "running nam"
exit 0
}


# Create 13 routers
for {set i 0} {$i < 13} {incr i} {
set r($i) [$ns node]
}

# Create 30 pc
for {set i 13} {$i < 43} {incr i} {
set pc($i) [$ns node]
}

for {set i 0} {$i < 13} {incr i} {
$r($i) shape hexagon
$r($i) color green
}

for {set i 13} {$i < 43} {incr i} {
$pc($i) color blue
}





# Create duplex links
$ns duplex-link $r(0) $pc(13) 1Mb 50ms DropTail
$ns duplex-link $r(0) $pc(14) 1Mb 50ms DropTail
$ns duplex-link $r(0) $pc(15) 1Mb 50ms DropTail
$ns duplex-link $r(0) $r(1) 2Mb 50ms DropTail
$ns duplex-link $r(0) $r(5) 2Mb 50ms DropTail
$ns duplex-link $r(1) $pc(16) 1Mb 50ms DropTail
$ns duplex-link $r(1) $pc(17) 1Mb 50ms DropTail
$ns duplex-link $r(1) $pc(18) 1Mb 50ms DropTail
$ns duplex-link $r(1) $r(2) 2Mb 50ms DropTail
$ns duplex-link $r(1) $r(6) 10Mb 50ms DropTail
$ns duplex-link $r(2) $pc(19) 1Mb 50ms DropTail
$ns duplex-link $r(2) $pc(20) 1Mb 50ms DropTail
$ns duplex-link $r(2) $pc(21) 1Mb 50ms DropTail
$ns duplex-link $r(2) $r(3) 2Mb 50ms DropTail
$ns duplex-link $r(2) $r(7) 10Mb 50ms DropTail
$ns duplex-link $r(3) $pc(22) 1Mb 50ms DropTail
$ns duplex-link $r(3) $pc(23) 1Mb 50ms DropTail
$ns duplex-link $r(3) $pc(24) 1Mb 50ms DropTail
$ns duplex-link $r(3) $r(4) 2Mb 50ms DropTail
$ns duplex-link $r(3) $r(8) 10Mb 50ms DropTail
$ns duplex-link $r(4) $pc(25) 1Mb 50ms DropTail
$ns duplex-link $r(4) $pc(26) 1Mb 50ms DropTail
$ns duplex-link $r(4) $pc(27) 1Mb 50ms DropTail
$ns duplex-link $r(4) $r(9) 2Mb 50ms DropTail
$ns duplex-link $r(5) $pc(28) 1Mb 50ms DropTail
$ns duplex-link $r(5) $pc(29) 1Mb 50ms DropTail
$ns duplex-link $r(5) $pc(30) 1Mb 50ms DropTail
$ns duplex-link $r(5) $r(6) 10Mb 50ms DropTail
$ns duplex-link $r(6) $r(7) 10Mb 50ms DropTail
$ns duplex-link $r(6) $r(10) 10Mb 50ms DropTail
$ns duplex-link $r(7) $r(8) 10Mb 50ms DropTail
$ns duplex-link $r(7) $r(11) 10Mb 50ms DropTail
$ns duplex-link $r(8) $r(9) 10Mb 50ms DropTail
$ns duplex-link $r(8) $r(12) 10Mb 50ms DropTail
$ns duplex-link $r(9) $pc(31) 1Mb 50ms DropTail
$ns duplex-link $r(9) $pc(32) 1Mb 50ms DropTail
$ns duplex-link $r(9) $pc(33) 1Mb 50ms DropTail
$ns duplex-link $r(10) $r(11) 2Mb 50ms DropTail
$ns duplex-link $r(10) $pc(34) 1Mb 50ms DropTail
$ns duplex-link $r(10) $pc(35) 1Mb 50ms DropTail
$ns duplex-link $r(10) $pc(36) 1Mb 50ms DropTail
$ns duplex-link $r(11) $r(12) 2Mb 50ms DropTail
$ns duplex-link $r(11) $pc(37) 1Mb 50ms DropTail
$ns duplex-link $r(11) $pc(38) 1Mb 50ms DropTail
$ns duplex-link $r(11) $pc(39) 1Mb 50ms DropTail
$ns duplex-link $r(12) $pc(40) 1Mb 50ms DropTail
$ns duplex-link $r(12) $pc(41) 1Mb 50ms DropTail
$ns duplex-link $r(12) $pc(42) 1Mb 50ms DropTail



# Orient the nodes
$ns duplex-link-op $r(0) $pc(13) orient 165deg
$ns duplex-link-op $r(0) $pc(14) orient 180deg
$ns duplex-link-op $r(0) $pc(15) orient 195deg
$ns duplex-link-op $r(0) $r(1) orient 0deg
$ns duplex-link-op $r(0) $r(5) orient 270deg
$ns duplex-link-op $r(1) $pc(16) orient 105deg
$ns duplex-link-op $r(1) $pc(17) orient 90deg
$ns duplex-link-op $r(1) $pc(18) orient 75deg
$ns duplex-link-op $r(1) $r(2) orient 0deg
$ns duplex-link-op $r(1) $r(6) orient 270deg
$ns duplex-link-op $r(2) $pc(19) orient 105deg
$ns duplex-link-op $r(2) $pc(20) orient 90deg
$ns duplex-link-op $r(2) $pc(21) orient 75deg
$ns duplex-link-op $r(2) $r(3) orient 0deg
$ns duplex-link-op $r(2) $r(7) orient 270deg
$ns duplex-link-op $r(3) $pc(22) orient 105deg
$ns duplex-link-op $r(3) $pc(23) orient 90deg
$ns duplex-link-op

in reference to: [ns] black hole simulation (view on Google Sidewiki)

Wednesday, April 21, 2010

Printing Routing Table in AODV


Actually you can find all this information in trace file which NS2 made, however using following code simplifies getting required informaiton during running time. The code stores

Add following code to aodv.h after void rt_down(aodv_rt_entry *rt);

void rt_print(nsaddr_t node_id);

Add following code to aodv.cc after void AODV::rt_down(aodv_rt_entry *rt)

void AODV::rt_print(nsaddr_t node_id) {
FILE * dumpFile;
char dumpFileName[50] = "rtable.txt";
dumpFile = fopen(dumpFileName, 'a');
aodv_rt_entry *rt;
fprintf(dumpFile, "=======================================================");
for (rt=rtable.head();rt; rt = rt->rt_link.le_next) {
fprintf(dumpFile, "NODE: %i\t %.4lf\t %i\t %i\t %i\t %i\t %i\t %.4lf\t %d \n", node_id, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno, rt->rt_expire, rt->rt_flags)
}
fclose(dumpFile);
}

The function (rt_print) can be used anywhere in AODV. For example, I am using the function, when route request generated node receives route reply message (RREP).

if (ih->daddr() == index) { // If I am the original source
// Update the route discovery latency statistics
// rp->rp_timestamp is the time of request origination
rt_print(index); // print this nodes whole routing table
rt->rt_disc_latency[(unsigned char)rt->hist_indx] = (CURRENT_TIME - rp->rp_timestamp)
/ (double) rp->rp_hop_count;
// increment indx for next time
rt->hist_indx = (rt->hist_indx + 1) % MAX_HISTORY;
}