2007-12-02
TAG:

如果在NS中做扩展代理模块。则需要新写这个模块。应用这个模块就要在tcl脚本中加入一段绑定的话:

set val(chan)   Channel/WirelessChannel    ;# channel type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)  Phy/WirelessPhy/OFDM       ;# network interface type
set val(mac)    Mac/802_16/MBS             ;# MAC type
set val(ifq)    Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)     LL                         ;# link layer type
set val(ant)    Antenna/OmniAntenna        ;# antenna model
set val(ifqlen) 50                         ;# max packet in ifq
set val(nn)     3                          ;# number of mobilenodes
set val(rp)     DSDV                       ;# routing protocol
set val(x)      600                        ;# X dimension of topography
set val(y)      600                        ;# Y dimension of topography
set val(stop)   200.0                      ;# time of simulation end

如上,如果我们在mac层应用的协议是802.11,则会写
set val(mac) Mac/802_11

当我们需要自己开发一个mac层协议时,我们首先需要考虑添加的协议名称。协议中的子类型。如协议名为802_16,802.16 mesh模式中有两种形式的节点,mesh base station 和 mesh sub station。于是需要在实现协议时,继承于802.16类,定义两个子类:802_16MBS,802_16MSS。通过一定的绑定机制,在tcl脚本中就可以写
set val(mac) Mac/802_16/MBS
或者 set val(mac) Mac/802_16/MSS

这两句话在tcl脚本中的意思是分别定义两种节点,一种节点是MBS类型。另一种是MSS类型。
具体定义方式:

#============================================
#  Initial variances about C++ class type
#============================================

set val(chan)   Channel/WirelessChannel    ;# channel type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)  Phy/WirelessPhy/OFDM       ;# network interface type
set val(mac)    Mac/802_16/MBS             ;# MAC type
set val(ifq)    Queue/DropTail/PriQueue    ;# interface queue type
set val(ll)     LL                         ;# link layer type
set val(ant)    Antenna/OmniAntenna        ;# antenna model
set val(ifqlen) 50                         ;# max packet in ifq
set val(nn)     3                          ;# number of mobilenodes
set val(rp)     DSDV                       ;# routing protocol
set val(x)      600                        ;# X dimension of topography
set val(y)      600                        ;# Y dimension of topography
set val(stop)   200.0                      ;# time of simulation end

 ### some variances initial ###

#============================================
#  set Trace and Topo
#============================================
*
* tcl code
*

#============================================
#  Configure for Node  
#============================================
$ns node-config -adhocRouting $val(rp) \
                -llType $val(ll) \
                -macType Mac/802_16/MBS \
                -ifqType $val(ifq) \
                -ifqLen $val(ifqlen) \
                -antType $val(ant) \
                -propType $val(prop) \
                -phyType $val(netif) \
                -channel [new $val(chan)] \
                -topoInstance $topo \
                -agentTrace OFF \
                -routerTrace OFF \
                -macTrace ON \
                -movementTrace OFF
在上面代码下面定义节点:
#============================================
#  Initial node - MBS          
#============================================
set node_(0) [$ns node]
$node_(0) set X_ 200
$node_(0) set Y_ 200
$node_(0) set Z_ 0.0
$ns initial_node_pos $node_(0) 30
[$node_(0) set mac_(0)] set-channel 0

若需要定义MSS类型的节点,则接着写
#============================================
#  Initial node - MSS
#============================================
$ns node-config -macType Mac/802_16/MSS \       ;#此处只能写这些,不能把路由,ll层等的绑定再写一遍
               -macTrace ON

set node_(1) [$ns node]
$node_(1) set X_ 300
$node_(1) set Y_ 300
$node_(1) set Z_ 0.0
$ns initial_node_pos $node_(1) 30
[$node_(1) set mac_(0)] set-channel 0

set node_(2) [$ns node]
$node_(2) set X_ 200
$node_(2) set Y_ 300
$node_(2) set Z_ 0.0
$ns initial_node_pos $node_(2) 30
[$node_(2) set mac_(0)] set-channel 4

这样,就声明了MBS和MSS的节点。具体工作过程就要看c++的实现函数了。

那么怎样完成c++与otcl在此处的绑定呢?方法如下:
1,先为父类写绑定函数:
/**
 * TCL Hooks for the simulator for wimax mac
 */
static class Mac802_16Class : public TclClass {
public:
  Mac802_16Class() : TclClass("Mac/802_16") {}
  TclObject* create(int, const char*const*) {
    return (new Mac802_16());
   
  }
} class_mac802_16;

2,为子类写绑定函数:
/**
*TCL Hooks for the simulator for wimax mac
*/
static class Mac802_16MBSClass : public TclClass {
public:
 Mac802_16MBSClass() : TclClass("Mac/802_16/MBS") {}
 TclObject* create(int, const char*const*){
  return(new Mac802_16MBS());
  }
} class_mac802_16MBS;

通过上述步骤,则实现了声明。当在tcl中写 -macType Mac/802_16/MBS \时,ns会自动寻找相应的解析函数,于是调用new Mac802_16MBS();完成对该类的初始化,形成这个类的一个对象。






@ 13:56:05 | 引用 0 | 编辑



评论
 
izuk () @ 2008-08-21 01:02:53
[$node_(0) set mac_(0)] set-channel 0

可以請問一下 $node_(0) set mac_(0) 這個是什麼意思嗎

我查了ns2的手冊 沒有看到類似的敘述

不知道能否請你告知我呢 謝謝



发表评论
 姓名: 
 E-mail: 
 地址: