向NS2中添加新的无线移动网络路由协议

5 篇文章 0 订阅
按照[1]所述,添加新的路由协议之后,很多人问为什么总有“debug_”未定义的错误?这主要是因为没有将移动节点的新路由协议与队列关联起来。关联的过程实际上就是路由协议类通过 TclObject::lookup()获得队列的指针。

1Packet 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: }

 

2Tracing 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: }

 

3Tcl 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: }

 

4Priority 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: }

 

5Makefile

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值