1.Packet type declaration
common/packet.h
1: enum packet_t {
2: PT_TCP,
3: PT_UDP,
4: PT_CBR,
5: /* ... much more packet types ... */
6: PT_PROTONAME,
7: PT_NTYPE // This MUST be the LAST one
8: };
common/packet.h
1: p_info() {
2: name_[PT_TCP]= "tcp";
3: name_[PT_UDP]= "udp";
4: name_[PT_CBR]= "cbr";
5: /* ... much more names ... */
6: name_[PT_PROTONAME]= "protoname";
7: }
2.Tracing support
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, intoffset);
7: };
trace/cmu-trace.cc
1: #include
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: }
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: }
3.Tcl library
tcl/lib/ns-packet.tcl
1: foreach prot {
2: Protoname
3: AODV
4: ARP
5: # ...
6: NV
7: } {
8: add-packet-header $prot
9: }
tcl/lib/ns-default.tcl
1: # ...
2: # Defaults definedfor Protoname
3: Agent/Protoname setaccessible_var_ true
tcl/lib/ns-lib.tcl
1: Simulator instproccreate-wireless-node args {
2: # ...
3: switch -exact $routingAgent_ {
4: Protoname {
5: set ragent [$selfcreate-protoname-agent $node]
6: }
7: # ...
8: }
9: # ...
10: }
tcl/lib/ns-lib.tcl
1: Simulator instproccreate-protoname-agent{ node } {
2: # Create Protoname routing agent
3: set ragent [new Agent/Protoname [$nodenode-addr]]
4: $self at 0.0 "$ragent start"
5: $node set ragent_ $ragent
6: return $ragent
7: }
ns-mobilenode.tcl
1: Node/MobileNodeinstproc add-target{ agent port } {
2: #...
3: #Special processing forProtoname
4: setProtonameonly [string first "Protoname" [$agent info class]]
5: if{$Protonameonly!= -1 } {
6: $agentif-queue [$self set ifq_(0)] ;# ifqbetween LL and MAC
7: }
8: #...
9: }
4.Priority queue
queue/priqueue.cc
1: void
2:PriQueue::recv(Packet *p, Handler *h)
3: {
4: struct hdr_cmn *ch = HDR_CMN(p);
5:
6: if (Prefer_Routing_Protocols) {
7:
8: switch(ch->ptype()) {
9: case PT_DSR:
10: case PT_MESSAGE:
11: case PT_TORA:
12: case PT_AODV:
13: case PT_PROTONAME:
14: recvHighPriority(p,h);
15: break;
16:
17: default:
18: Queue::recv(p, h);
19: }
20: }
21: else {
22: Queue::recv(p, h);
23: }
24: }
5.Makefile
Makefile
1: OBJ_CC =
2: tools/random.o tools/rng.o tools/ranvar.ocommon/misc.o common/timer-handler.o
3: # ...
4: protoname/protoname.oprotoname/protoname_rtable.o
5: # ...
6: $(OBJ_STL)
References:
[1]Implementing a New Manet Unicast Routing Protocol in NS2