Reading Notes on NS2(7)

本文介绍了NS2中的网络节点和链路的基本概念与配置方法。包括单播和多播节点的创建与结构,以及如何创建单向和双向链路并设置其特性。

(一)节点

 

[1] 单播和多播
根据网络节点之间通信方式的不同,分组的传输方式有两类:单播(unicast)和多播(multicast)。在NS2中设计了两类网络节点即单播节点和多播节点来实现以上两种不同的通信方式。

[2] 单播节点的创建
NS2默认创建的是单播节点:
#创建了一个单播节点n0
set ns [new Simulator]
set n0 [$ns node]

[3] 单播节点的结构
一个单播节点是一个组合对象,主要包括两个Tcl对象:地址分类器(address classifier)和端口分类器(port classifier)
注意:
(1)一个节点本质上是一个分类器的集合,一个简单的单播节点主要由地址分类器和端口分类器组成;
(2)每种不同的分类器分别查看分组的一个特殊部分,再依次转发分组;
(3)地址分类器的主要功能是用来判断分组的地址,转发分组到下一个接收器;
(4)端口分类器的主要功能是按照分组的目的端口进行匹配,将分组传递给相应的agent对象;

[4] 多播节点的创建
首先必须将模拟器对象ns内部的-Multicast属性值设置为on,然后调用node过程创建多播节点。
#创建一个多播节点n1
set ns [new Simulator -Multicast on]
set n1 [$ns node]
注意:
(1)一旦-Multicast的属性值设置为on,在此之后调用$ns node过程建立的节点都将是多播节点,如果要再创建单播节点,必须先将-Multicast的值重新设为off。

[5] 多播节点的结构
多播节点主要由多播分类器(Multicast Classifier)和复制器(Replicator)组成。
注意:
(1)多播节点包含复制器(Replicator)对象,并使用其生成分组的拷贝。

[6] 节点的配置
大部分情况下使用NS2是对无线网络做一些研究工作。在NS2中要创建一个移动节点,就必须在创建节点之前对节点进行配置。
节点的配置:就是在节点创建之前设定节点的各项属性,可以使用模拟器对象ns的内部过程node-config{}来配置节点的属性。
注意:(P.47 表3.1 节点所有可配置的属性)
(1)所有节点可配置的属性
(2)卫星节点和无线节点都可配置的属性
(3)仅无线节点可配置的属性
(4)仅卫星节点可配置的属性

[7] 与节点相关的命令
$ns node [<hier_addr>]      ;#创建和返回一个节点对象
$ns node-config <config-parameter> <optional-val>   ;#用于配置节点属性,-reset选项用于将节点属性配置为默认值
$node id                ;#返回节点的id号
$node node-addr  ;#返回节点的地址(当地址类型为flat时,节点地址和它的id一样;当为hierarchical时,节点地址以一个字符串返回)
$node reset          ;#重新设置绑定于节点的代理

#将<agent>绑定于节点上。如果用户没有指定端口号<port_num>,节点将自动为其分配一个端口号,并将该代理绑定到节点上。一旦代理绑定,代理将接收从该节点的端口传来的分组。
$node attach <agent> <optional:port_num>   

#与attach命令相反。该命令将代理从这个节点上撤除,然后在这个端口上绑定一个空代理,传入的分组将被空代理接收。
$node detach <agent> <null_agent>  

 

 

(二)链路

 

NS2的链路(link)与TCP/IP网络中数据链路不同,它同时实现了物理层、数据链路层以及部分网络层的功能。
两台网络设备之间的通信按通信方式可分为:单工、半双工和全双工三种方式。

[1] 单向链路的创建
#创建一条node1到node2的单向链路,并且定义一些特性
set ns [new Simulator]
$ns simplex-link <node1> <node2> <bandwidth> <delay> <queue_type>

[2] 单向链路的结构
一条简单的链路是由一系列的连接器(connector)逐步构成的。(像节点是由分类器组成的一样)
注意:
(1)NS有许多不同种类的连接器,每种连接器执行不同的功能;
(2)组成链路的Queues、DelayLink和TTLChecker都是Connector类的子类;

[3] 队列对象(Queues)
队列其实是一个缓冲区,用来存放或丢弃分组的地方。不同的队列类型拥有不同队列管理及分组的调度机制。
目前NS支持的队列类型有:
(a)丢弃队尾(Drop-tail)的先进先出队列
(b)RED缓冲区管理
(c)CBQ(包括优先级和轮换调度)
(d)各种公平队列(FQ、SFQ、DRR)

[4] 延迟链路对象(DelayLink)
主要用来模拟链路延迟和带宽特性的对象。

[5] TTL检查器对象(TTLChecker)
将收到分组的TTL值减1。如果TTL值为正,分组将被送至链路上的下一个元素;否则,分组将被丢弃。
TTL(Time to Live)代表了分组的生存期,是分组中的一个域,它告诉网络分组在网络中的时间是否太长而应该被丢弃。TTL通常表示分组在被丢弃前最多能经过的路由器个数。当记数到0时,路由器决定丢弃该分组,并发送一个ICMP报文给最初的发送者。

[6] 双向链路的创建
#创建一条node1到node2的双向链路,并且定义一些特性
set ns [new Simulator]
$ns duplex-link <node1> <node2> <bandwidth> <delay> <queue_type>
一条双向链路其实是由两条方向不同的单向链路构成,所以等价于:
set ns [new Simulator]
$ns simplex-link <node1> <node2> <bandwidth> <delay> <queue_type>
$ns simplex-link <node2> <node1> <bandwidth> <delay> <queue_type>

[7] 与链路相关的NS命令
$ns simplex-link <node1> <node2> <bandwidth> <delay> <queue_type>
$ns duplex-link <node1> <node2> <bandwidth> <delay> <queue_type>

$ns simplex-link-op <node1> <node2> <option> <args> ;#设置单向链路的属性,主要包括方向、颜色等,用于Nam的动画显示
$ns duplex-link-op <node1> <node2> <option> <args>

The Network Simulator, Version 3 -------------------------------- Table of Contents: ------------------ 1) An overview 2) Building ns-3 3) Running ns-3 4) Getting access to the ns-3 documentation 5) Working with the development version of ns-3 Note: Much more substantial information about ns-3 can be found at http://www.nsnam.org 1) An Open Source project ------------------------- ns-3 is a free open source project aiming to build a discrete-event network simulator targeted for simulation research and education. This is a collaborative project; we hope that the missing pieces of the models we have not yet implemented will be contributed by the community in an open collaboration process. The process of contributing to the ns-3 project varies with the people involved, the amount of time they can invest and the type of model they want to work on, but the current process that the project tries to follow is described here: http://www.nsnam.org/developers/contributing-code/ This README excerpts some details from a more extensive tutorial that is maintained at: http://www.nsnam.org/documentation/latest/ 2) Building ns-3 ---------------- The code for the framework and the default models provided by ns-3 is built as a set of libraries. User simulations are expected to be written as simple programs that make use of these ns-3 libraries. To build the set of default libraries and the example programs included in this package, you need to use the tool 'waf'. Detailed information on how use waf is included in the file doc/build.txt However, the real quick and dirty way to get started is to type the command ./waf configure --enable-examples followed by ./waf in the the directory which contains this README file. The files built will be copied in the build/ directory. The current codebase is expected to build and run on the set of platforms listed in the RELEASE_NOTES file. Other platforms may or may not work: we welcome patches to improve the portability of the code to these other platforms. 3) Running ns-3 --------------- On recent Linux systems, once you have built ns-3 (with examples enabled), it should be easy to run the sample programs with the following command, such as: ./waf --run simple-global-routing That program should generate a simple-global-routing.tr text trace file and a set of simple-global-routing-xx-xx.pcap binary pcap trace files, which can be read by tcpdump -tt -r filename.pcap The program source can be found in the examples/routing directory. 4) Getting access to the ns-3 documentation ------------------------------------------- Once you have verified that your build of ns-3 works by running the simple-point-to-point example as outlined in 4) above, it is quite likely that you will want to get started on reading some ns-3 documentation. All of that documentation should always be available from the ns-3 website: http:://www.nsnam.org/documentation/. This documentation includes: - a tutorial - a reference manual - models in the ns-3 model library - a wiki for user-contributed tips: http://www.nsnam.org/wiki/ - API documentation generated using doxygen: this is a reference manual, most likely not very well suited as introductory text: http://www.nsnam.org/doxygen/index.html 5) Working with the development version of ns-3 ----------------------------------------------- If you want to download and use the development version of ns-3, you need to use the tool 'mercurial'. A quick and dirty cheat sheet is included in doc/mercurial.txt but reading through the mercurial tutorials included on the mercurial website is usually a good idea if you are not familiar with it. If you have successfully installed mercurial, you can get a copy of the development version with the following command: "hg clone http://code.nsnam.org/ns-3-dev"
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值