天天看点

ns2多协议节点的实现-nist

ns2多协议节点的实现-nist

垂直网络切换的模拟客观上要求ns2中的一个节点可以配置多个协议,但是ns2中原来的实现(包括移动节点)并没有实现多协议节点,通过查找一些资料以及对ns2代码的分析(尤其是nist的实现)对多协议实现有了初步的体会。

ns2中的移动节点的都包括地址分类器和端口分类器用做数据流的路径的处理,在nist的mobility的包中,将多个不同协议的节点的端口分类器出来的数据流接到同一个节点——multiNode的端口分类器,而在这些不同协议的节点中不再有上层agent的存在,转而讲agent加到mulitNode上,从而实现了多协议的节点。

ns2多协议节点的实现-nist

如图所示,如果一个包到达(也就是受到),那么如果当前的连接接口是左上的接口(节点),那么通过该节点的分类器Classfier/Port的defaulttarget_包将被传到MulitFace的端口分类器,可以看到,MultiFace的地址分类器是废弃不用的;如果要将一个封包传送出去,那么Application首先会寻找target_是哪个节点(那种协议的),从而会将该封包传送到那个节点上去。

而NIST实现的802.21的MIHF和使用mih服务的上层协议都是安装在MulitFace上面的,也就是总的节点上,其他节点只是作为这个总的节点的一个借口(可以理解为网卡),由于有不同的协议的存在,所以邻居发现模块(检查第三层的移动)的模块是安装在接口节点上(作为一个agent),这样做的好处应该是提供了统一的一个对移动后策略处理的框架(将信息送给if-manager处理——MIH USER)。MIH和MIH-USR也可以实现互操作。在处理多协议,多接口的移动模型的时候还包括很多内容,如信道的选择,冲突发声的处理等等还需要更深入的理解。

下面是对代码的理解:

配置:

ns2多协议节点的实现-nist

节点初始化过程:

Simulator instproc node-config args {

        # Object::init-vars{} is defined in ~tclcl/tcl-object.tcl.

        # It initializes all default variables in the following way:

        #  1.  Look for pairs of {-cmd val} in args

        #  2.  If "$self $cmd $val" is not valid then put it in a list of

        #      arguments to be returned to the caller.

        #

        # Since we do not handle undefined {-cmd val} pairs, we ignore

        # return value from init-vars{}.

        set args [eval $self init-vars $args]

}//这里就是会调用ns的mulitIf命令:

在ns-wireless-mip.tcl中

Simulator instproc multiIf {val} { $self set multiIf_ $val }

讲多接口属性设置为ON。

从而在new MulitFaceNode的时候:

Simulator instproc node args {

      if { [info exists multiIf_] && ($multiIf_ == "ON") } {

                set node [eval $self create-multiFaceNode $args]

                #puts "Multi-interface node with id [$node id] created"

                return $node

        }

}

进而:

Simulator instproc create-multiFaceNode args {

        $self instvar Node_

        set node [eval new MultiFaceNode $args]

        #set Node_([$node id]) $node

        #add to simulator's nodelist in C++ space

        $self add-node $node [$node id]

        #set the nodeid in c++ Node - ratul

        $node nodeid [$node id]

        $node set ns_ $self

        $self check-node-num

        return $node

}

这是多协议接口节点的初始化,使用过程是这样的:

ns2多协议节点的实现-nist

同样在在ns-wireless-mip.tcl中

MultiFaceNode instproc add-interface-node { ifaceNode } {

    #puts "Adding interface node [$ifaceNode node-addr]."

    $self instvar dmux_ address_

    #

    # If a port demuxer doesn't exist, create it.

    #

    if { $dmux_ == "" } {

         set dmux2_ [new Classifier/Port]

       #puts "Creating dmux_ $dmux2_ in node $address_"

       $self install-demux $dmux2_

    }

    # install the SAME dmux into the interface.

    #$ifaceNode install-demux $dmux_

    # set the default target of the interface node to this demux

    if {[$ifaceNode set dmux_] == ""} {

       set tmp [new Classifier/Port]

       $ifaceNode install-demux $tmp

    }

    [$ifaceNode set dmux_] defaulttarget $dmux_

    # add interface to the list

    $self registerIf $ifaceNode

    #puts "Interface node added."

}

过程就是在开头讲过的,将各个端口分类器连接起来。随着切换的发生,mulitFaceNode的app的target也跟着发生变化,这样多接口节点就已经实现了接法多协议数据的能力了。看完代码感觉NIST的实现是很巧妙的,但是是建立在mac层的修改的基础上,还有MIH的实现的基础上的。

注:多接口多信道的实现思路大体上就是这个,都是在tcl层面上多不同的模块进行“架构”,想要了解更多的实现请参考:

http://www.loosky.net/?p=649

http://personales.unican.es/aguerocr/

继续阅读