这个网站上的一系列讲解NS2的内容真的是深入浅出,看完立刻豁然开朗。所以就接连转了几篇。

Scheduling Events那篇里的例子特别好,看完就懂了。

http://www.mathcs.emory.edu/~cheung/Courses/558-old/Syllabus/90-NS/

NS Simulation Basic



  • Common NS classes

    • The following figure shows the most commonly used NS classes in writing a network simulation:

    • A quick overview on these classes:
      1. Node: simulate routers . They simulate the IP protocol layer.
      2. Links: links are created using the duplex-link method call in an NS simulation object.
      3. Agent/TCP/Reno and Agent/TCP/Tahoe: simulate the Sending TCP protocol layer.

        A Agent/TCP/Reno or Agent/TCP/Tahoe needs to be attached to some Node (see figure)

        Also, a Agent/TCP/Reno or Agent/TCP/Tahoe need to be associated with a Agent/TCP/Sink !

      4. Agent/TCP/Sink: simulate the Receiving TCP protocol layer.

        A Agent/TCP/Sink sends ACK packets and needs to be attached to some Node (see figure)

      5. Application/FTP: simulate an continuously transmitting agent that uses a TCP protocol (Tahoe, Reno, or some other version of TCP)

        A Application/FTP needs to be attached to some TCP agent (see figure)

        The Application/FTP does not need to be asscoiated with a receiver:

        • The FTP agent triggers the TCP agent to transmit packets
        • TCP packets are acknowledged by the asscociated TCP-Sink
        • When the TCP source receives the ACK, it reports to the associated FTP agent that it can transmit more.


  • Steps in writing a network simulation in NS
    1. Create the network:

      1. Create nodes (routers): click here
      2. Connect the nodes with (duplex) links: click here
    2. Define transport sources and sinks at end point nodes
      1. Create transport source agents (Agent/TCP/Reno) and transport sink agents (Agent/TCP/Sink)
      2. Associate the transport source/sink agent to a end point node
      3. Connect a source transport agent to a transport sink agent
    3. Put traffic load (Application/FTP) on the transport sources


  • Using NS
    • In order to use the NS simulator, you need to create a Simulator object

      The Simulator object is the network simulation system and provides many methods needed to construct the network simulation.

    • How to create a Simulator object:
         new Simulator
      
    • Example:
         set ns [new Simulator]
      

      You only need one Simulator object

      If you look in the source of a NS script, you will always see this statement at the top of the program !



  • Creating Nodes in NS
    • The Node class in NS is used to simulate routers
    • The node must be created through the special method node defined in the Simulator class.

      The following expression will return a Node object in NS that you use to simulate ONE router:

        set ns [new Simulator]   
      
        [$ns node]
      
    • Use a set command to remember the Node object in some variable (e.g., n0):
        set ns [new Simulator]
      
        set n0 [$ns node]
      
    • If you need to create a lot of routers, use a for loop.

      Example: create Nodes n(0), n(1), ..., n(9):

         for {set i 0} {$i < 10} {incr i} {
      set n($i) [$ns node]
      }


  • Creating Links in NS
    • Links in NS are used to provide connectivity between Nodes (routers)
    • Links is not implemented as a class, but as a part of the Simulator object
    • Links have a number of properties:
      1. Duplex (bi-directional) or Simplex (uni-directional)

        BTW, a duplex link is actually 2 simplex links..

      2. Bandwidth (data transmission rate)

        Units: b (#bits/sec), Mb (#Megabits/sec)

      3. Propagation delay

        Units: s (seconds), ms (milliseconds)

      4. Queue management: specifies how packets in the queue are managed

        Some commonly used values:

        • DropTail: drop the last arriving packet when queue is full
        • RED: Random Early Drop method (this method tries to break the TCP Synchronization Syndrome)
        • DDR: Deficit Round Robin method (research material)
        • FQ: Fair Queuing method (research material)
        • SFQ: Stochastic Fair Queuing method (research material)

        We will mostly use DropTail

    • Example: duplex (bi-directional) link, 10 Mbps, 10 msec delay
       set n0 [$ns node]
      set n1 [$ns node] $ns duplex-link $n0 $n1 10Mb 10ms DropTail

  • NS Programming trick: More flexible way to create links
    • Often, you want to experiment with the same network configuration but using different bottleneck link capacities.

      For example, the bottleneck link is f times the normal bandwidth in other network links

    • Trick:
       set bw 10
      set f 0.5 $ns duplex-link $n0 $n1 [expr $bw]Mb 10ms DropTail
      $ns duplex-link $n0 $n1 [expr $f*$bw]Mb 10ms DropTail

  • Link: Changing its buffer size
    • You can change the buffer size of one particular link using the $ns queue-limit method
    • Example: set the queue length to 10 packets
       $ns duplex-link $n0 $n1 10Mb 10ms DropTail     
      
       $ns queue-limit $n0 $n1 10
      

  • Link: Changing the default buffer size of all links
    • Links in NS are created with a certain default queue size
    • Each class (DropTail, RED, FQ, etc) of queue has its own default queue size
    • You can change the buffer size of a class of queue using the set queue-limit command in the class Queue/QUEUE-CLASS
    • Example: set the default queue length of DropTail queues to 10 packets
       Queue/DropTail set queue-limit $n0 $n1 10
      


  • Routing in NS
    • After you created the nodes and connected them through links, NS will provide Internet routing automatically
    • So, after created the nodes and connected them through links, you have an Internet.
    • All you need to do now is:
      • Add transport protocol to the end point nodes (no need to do so to intermediate nodes)
      • Add traffic (load)


  • Transport Layer Protocol modules
    • For one reason or another, the transport protocol modules in NS are called agents
    • There are an ever increasing number of sending transport agents (because people are developing new TCP transmission protocols to improve network performance.
    • There are 2 receiving transport agents that sends back ACKs to the sending agent.
    • The most commonly used sending transport protocol modules are:

      1. Agent/TCP/Tahoe: TCP Tahoe
      2. Agent/TCP/Reno: TCP Reno
      3. Agent/TCP/Newreno: Improved TCP Reno that paces the transmission interval
      4. Agent/TCP/Vegas: TCP Vegas

      Example:

        set tcp1 [new Agent/TCP/Reno]
      
    • The most commonly used receiving transport protocol modules are:

      1. Agent/TCPSink: sends ACK packet immediately after receiving a packet
      2. Agent/TCPSink/DelAck: ACK is delayed. Receiver sends ACK packet after receiving 2 packets or after a certain delay (tries to reduce number of ACK packets)

      Example:

        set sink1 [new Agent/TCPSink]
      


  • Connecting Transport Protocol Agents to Nodes
    • Transport agents are end points of communication

      They can be attached to any Node object

    • You can attach multiple Transport agents to one Node object
    • The attach-agent command in a Simulator object is used to associate a Transport agents to a Node:
        $ns  attach-agent   NODE  TCP-Agent
      
    • Example:
        set ns [new Simulator]
      
        set  node1  [$ns node]
      set tcp1 [new Agent/TCP/Reno] $ns attach-agent $node1 $tcp1


  • Connecting a Sending Transport Agent to a Receiving Transport Agent
    • Transport agents are end points of communication

      We need to tell NS the destination of each sending Transport Agent.

      The destination must be a receiving Transport Agent.

    • In order to tell NS where to transmit the packets, we need to connect a sending communication end points to a receiving communication end points
    • This is done through the NS method: connect SOURCE DESTINATION
    • Example:
        set ns [new Simulator]       
      
        set tcp1 [new Agent/TCP/Reno]
      set sink1 [new Agent/TCPSink] (tcp1 and sink1 must also be attached to nodes, this step is omitted) $ns connect $tcp1 $sink1

      This will make NS route all packets from the source tcp1 towards the destination sink1


  • Some Parameters of the TCP module
    • After a TCP agent has been created, you can set some of its parameters (using the set command of the TCP agent)
    • The most useful parameters are:
      1. packetSize_: the packet size used by TCP (default packet size is 1000 bytes)
      2. maxcwnd_: the maximum of CWND (0 means infinite)
      3. window_: the Advertised Window size
    • Example:
        set  tcp1  [new  Agent/TCP/Reno]
      
        $tcp1  set   packetSize_   552
      
    • NOTE: recall that the set method without arguments will return the value of the variable !

      Example:

        set  tcp1  [new  Agent/TCP/Reno]
      
        set pksize  [$tcp1  set   packetSize_]   // get packetzise used
      


  • Generating Traffic for TCP
    • The standard traffic generator for TCP protocol is the FTP application.
    • The FTP application transmits continuously - as long as the TCP protocol permits.
    • FTP application are created using:
        new Application/FTP
      
    • Example:
        set  ftp1  [new  Application/FTP]
      

  • Associating FTP Traffic Generator with a TCP protocl module
    • You need to associate a FTP traffic generator with a sending TCP module
    • The association is made using the attach-agent method defined in the Application/FTP class.
    • Example:
        set  tcp1  [new  Agent/TCP/Reno]
      set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1

  • Starting the FTP traffic generator
    • The FTP traffic generator is run (started) using the start method defined in the Application/FTP class.
    • Example:
        set  ftp1  [new  Application/FTP]
      
        $ftp1  start  // Start the FTP application
      

  • Stopping the FTP traffic generator
    • The FTP traffic generator canbe stopped using the stap method defined in the Application/FTP class.
    • Example:
        set  ftp1  [new  Application/FTP]
      
        $ftp1  stop  // Stop the FTP application
      
    • NOTE: the TCP module does not need to be stopped and in fact, cannot be stopped.

      When the FTP traffic generator stops generating traffic, TCP will have no data to send and will "go quiet".

      You can start the FTP again after stopping it.

http://www.mathcs.emory.edu/~cheung/Courses/558-old/Syllabus/90-NS/2-NS-Prog/ns.html#links






NS Simulation Basic的更多相关文章

  1. NS Simulation: Scheduling Events (examples inside)

    NS Simulation: Scheduling Events Simulation time A similation system (such as NS) must have a built- ...

  2. 第一讲:vcs simulation basic

    要求: 1.complie a verilog/systemverilog design using vcs 2.simulate a verilog/systemverilog design vcs ...

  3. Studying TCP's Throughput and Goodput using NS

    Studying TCP's Throughput and Goodput using NS What is Throughput Throughput is the amount of data r ...

  4. Studying TCP's Congestion Window using NS

    Studying TCP's Congestion Window using NS How to obtain TCP's CWND value The most important value th ...

  5. ext树表

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2UAAAHwCAIAAACpIFDdAAAgAElEQVR4nOy9f5Qb5ZnvWWQZlnO5Oc ...

  6. extjs经典的增删改查

    首先,编辑一下yepnope,生成yepnope.jsp,如下: <%@ page language="java" pageEncoding="UTF-8" ...

  7. Basic认证

    Basic 概述 Basic 认证是HTTP 中非常简单的认证方式,因为简单,所以不是很安全,不过仍然非常常用. 当一个客户端向一个需要认证的HTTP服务器进行数据请求时,如果之前没有认证过,HTTP ...

  8. 【转】What's the difference between simulation and emulation

    摘要:这2个单词 还是用英文解释,比较准确.按我的理解:simulation就是模拟,可以做些改变. emulation是仿真,是按照原来的样子进行部署,不可以改变. Yes, the concept ...

  9. what is delta simulation time

    In digital logic simulation, a delta cycles are evaluation of expressions, followed by value updates ...

随机推荐

  1. Zookeeper概念学习系列之paxos协议

    不多说,直接上干货! 前言 一种最终一致的算法,paxos算法. paxos算法是由大牛lamport发明的,关于paxos算法有很多趣事.比如lamport论文最初由故事描述来引入算法,以至于那班习 ...

  2. Android AsyncTask异步加载WebAPI

    之前做的程序一直存在很多问题,因为需要加载的Activity需要从网络加载数据.并没有完全正确的使用异步的方法去加载! 之前用的虽然是AsyncTask,但是在加载完成的时候还是并没有使用AsyncT ...

  3. 编写规范的javascript

    js代码,前端都会写.但细节决定成败,代码是否优雅.规范,可以看得出一个JScoder的水平来. 曾经多次被项目组长吐槽,并被授予一本秘笈,上面有关于JS编程规范的一些总结. 无奈秘笈不能长借,无奈只 ...

  4. XPath语法简介

    XPath是一种在xml中查找信息的语言,具体可参考W3school XPath教程 XPath是以路径表达式来选择XML文档中的节点或节点集 === XPath节点(Node) 在 XPath 中, ...

  5. H5页面JS调试

    页面调试 常用的调试方法 开发时候的调试基本是在chrome的控制台Emulation完成 现有的一些手机端调试方案: Remote debugging with Opera Dragonfly 需要 ...

  6. JVM的内存分配和回收策略

    对象的Class加载 虚拟机遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已被加载.解析和初始化过.如果没有,那必须先执行相应 ...

  7. zato server启动后自动关闭问题解决

    症状 zato start server 启动server后,过一会server自动关闭了 解决 查看日志 UnicodeDecodeError: 'ascii' codec can't decode ...

  8. 破解b站极验验证码

    这就是极验验证码,通过拖动滑块移动拼图来验证.我们观察到点击滑块时拼图才会出现,所以我们可以在点击滑块之前截取图像,点击滑块再截取一次图像,将前后两次图像做比较就可以找到图片改动的位置.获得位置后,我 ...

  9. 送专利啦~~ .Net高阶异常处理之TopLevelEH

    我们知道,.Net的应用程序运行在.net framework虚拟机上,对于在运行时发生的错误,我们有try...catch可以捕捉,实在不济,对于winform和asp.net 我们都有全局的事件可 ...

  10. nodejs常用npm包

    express常用npm包整理如下 art-template 一款js模板引擎,性能不错 jayson     一款纯node的rpc应用包,可实现rpc服务.tcp.http等服务 multer   ...