Tuesday, December 16, 2008

How to Display RTS/CTS Packet Type in NS2 New Trace Format

There are several posts on NS2 user mailing list explaining how to display RTS/CTS packet type in NS2 trace file. 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)
{
struct hdr_cmn *ch = HDR_CMN(p);
......

} else if (newtrace_) {
sprintf(pt_->buffer() + offset,"-Ma %x -Md %x -Ms %x -Mt %s ",
mh->dh_duration,ETHER_ADDR(mh->dh_ra),ETHER_ADDR(mh->dh_ta),
((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())));
} else {
...

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


Sourced from http://www.cse.msu.edu/~wangbo1/ns2/nshowto7.html

No comments: