Tuesday, April 27, 2010

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

2 comments:

Unknown said...

Can I use this code for ns2.35 to calculate rts cts information from trace files...

Unknown said...

Can I use this code for ns2.35 to calculate rts cts information from trace files...