Reading Notes on NS2(6)

NS2的离散事件调度机制

 

[1] Simulator类
在NS2中,每个网络模拟过程需要一个类对整个过程进行控制和管理,这个类就是模拟器类(Simulator类)。
注意:
(1)整个模拟过程可以看作是对模拟器类对象的操作;
(2)模拟器类是一个解释类,没有相应的编译类,封装了节点(node)、链路(link)、代理(agent)、数据分组格式等。
(3)整个模拟过程从创建一个模拟器类对象开始,通过调用这个对象的各种过程实现:创建节点、构建拓扑结构图、对模拟的各个方面进行配置、定义事件、根据定义的事件模拟整个网络的运行等。

创建一个模拟器类对象:
set ns [new Simulator]   ;#新建一个Simulator对象ns(后面要使用这个ns对象,必须在前面加$)
与此同时完成了下列一系列的初始化操作:
(a)初始化分组格式(调用create_packetformat);
(b)创建一个事件调度器(scheduler,缺省为calendar scheduler);
(c)创建一个空代理(null agent);

[2] NS2的事件和事件调度器
NS2是一个事件驱动的模拟器。
注意:
(1)一个NS2事件通常包含两个部分:(a)事件的触发时间;(b)用来处理事件的功能函数的句柄;
NS2模拟器内部at过程的主要功能是在特定的时间调用事件处理函数处理事件。
例如:
#下面这段Tcl代码首先创建了模拟器对象ns,由事件调度器在5秒时,调用执行handle_fun函数
set ns [new Simulator]
$ns at 5.0 "handle_fun"
$ns run
proc handle_fun {} {puts "This is the event handle function!"}
(2)事件调度器的工作过程:
事件调度器其实就是一个事件队列,所有的事件按事件的触发时间排列。当时间到达某一事件的触发时间时,事件调度器选择该事件出队,同时调用事件处理函数执行完该事件,如此反复执行上述过程。
如果在同一时刻,有多个事件需要执行,事件调度器将按照先调度先执行(first scheduled-first dispatched)的原则进行调度。
目前NS2支持四种事件调度器:
(a)链表式(linked-list)调度器
(b)堆式(heap)调度器——适用于有大量事件的情况
(c)时间队列式(calendar)调度器——默认的事件调度器
(d)实时(real-time)调度器

[3] 相关命令
set ns [Simulator]           ;#创建一个模拟器对象
set now [$ns now]          ;#将调度器的当前时间赋值给now变量,以便在模拟时跟踪时间
$ns halt                          ;#停止或暂停调度器
$ns run                           ;#启动调度器
$ns at <time> <event>   ;#在一个特定时间<time>调度一个事件<event>
$ns cancel <event>         ;#取消<event>事件,将事件从准备好的调度器中删除

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、付费专栏及课程。

余额充值