As we know simulation's aim is to get a trace file describing what happended during execution. To feel familiar with traces please read chapter 23 [2]. A Trace object is used to write wanted information of a packet everytime it is received, sent or dropped. To log information regarding our packet type we implement the format_protoname() function inside the CMUTrace class. Trace support for wireless simulations is provided by CMUTrace objects and it is described in chapter 16 [2].
Let's edit trace/cmu-trace.h file. We must add our new function as in the line number 6 of the next example.
trace/cmu-trace.h
1: class CMUTrace : public Trace {
2: /* ... definitions ... */
3: private:
4: /* ... */
5: void format_aodv(Packet *p, int offset);
6: void format_protoname(Packet *p, int offset);
7: };
The next piece of code (extracted from trace/cmu-trace.cc) shows different types of traces.
trace/cmu-trace.cc
1: #include <protoname/protoname_pkt.h>
2:
3: /* ... */
4:
5: void
6: CMUTrace::format_protoname(Packet *p, int offset)
7: {
8: struct hdr_protoname_pkt* ph = HDR_PROTONAME_PKT(p);
9:
10: if (pt_->tagged()) {
11: sprintf(pt_->buffer() + offset,
12: "-protoname:o %d -protoname:s %d -protoname:l %d ",
13: ph->pkt_src(),
14: ph->pkt_seq_num(),
15: ph->pkt_len());
16: }
17: else if (newtrace_) {
18: sprintf(pt_->buffer() + offset,
19: "-P protoname -Po %d -Ps %d -Pl %d ",
20: ph->pkt_src(),
21: ph->pkt_seq_num(),
22: ph->pkt_len());
23: }
24: else {
25: sprintf(pt_->buffer() + offset,
26: "[protoname %d %d %d] ",
27: ph->pkt_src(),
28: ph->pkt_seq_num(),
29: ph->pkt_len());
30: }
31: }
We can deduce from above code that there are three different trace formats: tagged traces, new format traces and classical traces. The syntaxis followed by each, although different, is very easy and intuitive as you can tell. Both in tagged and new trace formats there exists tags used to identify each field of information being printed. We have decided to use ``o'' as source address (origin), ``s'' as sequence number and ``l'' as length of corresponding packet.
In order to call this recently created function we must change the format() in trace/cmu-trace.cc.
trace/cmu-trace.cc
1: void
2: CMUTrace::format(Packet* p, const char *why)
3: {
4: /* ... */
5: case PT_PING:
6: break;
7:
8: case PT_PROTONAME:
9: format_protoname(p, offset);
10: break;
11:
12: default:
13: /* ... */
14: }