How to Display Packet Type in Trace File

Description

To display the packet type in trace, modification should be done in the files packet.h, cmu-trace.h and cmu-trace.cc files in ns-allinone package. A pre defined packet types or new packet types are defined in the unsigned int packet_t method and the textual name of the packet type will defined in p_info class in packet.h file. The new packet type trace file format is added to the format_newpackettype method, that is defined in cmu-trace.cc file. The format_newpackettype method is declared in cmu-trace.h file.

Modification of cmu-trace.cc

void
CMUTrace::format_gpsr(Packet *p, int offset)
{
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_rtp *rh = HDR_RTP(p);
struct hdr_ip *ih = HDR_IP(p);
Node* thisnode = Node::get_node_by_address(src_);

//hacking, needs to change later,
int dst = Address::instance().get_nodeaddr(ih->daddr());

if (dst == src_){
// I just received a cbr data packet
if (thisnode->energy_model() &&
thisnode->energy_model()->powersavingflag()) {
thisnode->energy_model()->set_node_state(EnergyModel::INROUTE);
}
}

if (pt_->tagged()) {
sprintf(pt_->buffer() + offset,
"-cbr:s %d -cbr:f %d -cbr:o %d ",
rh->seqno_,
ch->num_forwards(),
ch->opt_num_forwards());
} else if (newtrace_) {
sprintf(pt_->buffer() + offset,
"-Pn cbr -Pi %d -Pf %d -Po %d ",
rh->seqno_,
ch->num_forwards(),
ch->opt_num_forwards());
} else {
sprintf(pt_->buffer() + offset,
"[%d] %d %d",
rh->seqno_,
ch->num_forwards(),
ch->opt_num_forwards());
}
}
Modification of cmu-trace.h
void format_gpsr(Packet *p, int offset);

Data flow

Display Packet Type in Trace File