First NS2 Program

Source: Internet
Author: User

In fact, the example of the book is copied again, but at least understand the NS2 workflow, put aside the details, all NS2 simulation should be based on this process.

After the installation of NS2 encountered two problems, this installation is quite smooth sailing, pre-assembled build-essential, tcl8.4, Tcl8.4-dev, tk8.4, Tk8.4-dev, directly installed NS2 2.30 on it can be, After that, add a few paths. BASHRC it's all done. These online are very clear, I would like to say is a relatively rare problem:

1./bin already has an NS, and since this path is more preferred than ns2, this is the one that runs NS. So directly to the Ns2.30/bin under the NS copy to the/bin under the change of name ns2 to be done. NS seems to be a hostname related to the program, specifically can man

2. When running NS2 EXAMPLE.TCL, you are not prompted to find Nam. Results search, found to enter the ns2.30/nam1.12 directory, first install Libxmu-dev, and then in this directory make, the NAM executable file, and then copy to/bin under, complete.

Besides, I summed up the steps to build a simulation process.

1. New Simulator first to build a simulator

2. Create TRACEF and NAMTF as an information logger for this simulation

3. Creating nodes in the topology

4. Establish links between nodes and set parameters such as flow rate, discard mode, etc.

5. Create agent, this agent and SNMP inside the concept of different, can be understood as attached to the node

's Soul. If the node is an entity, then the agent is responsible for controlling the receiving and transmitting text. It can be

is UDP or TCP, or it can be null. The preceding one does not need to be explained, and if it is null, it means

This is a receiving end. This is to be bound on the node, determining the angle that the node plays in this topology

Color

6. Establishing CBR,CBR is a flow generator. Used to generate real traffic, you can set the parameters of this flow,

such as message size, send interval. The CBR object is bound to the agent

7. Connect the agent, that is, to determine who received the corresponding relationship

8. Start the CBR time setting, that is, when to set the contract, when to stop

9. Close the TRACEF and NAMTF and track it down.

10. Start the simulation

Whether wired or wireless, similar. When you have more nodes, you need to use extra tricks, but the overall framework

That's the way it is. The first procedure is as follows:

jun@warrior:~/ns2/ns2learning$ Cat EXAMPLE1.TCL
Set NS [New Simulator]

Set TRACEF [Open example1.tr W]
$ns Trace-all $TRACEF
Set NAMTF [Open Example1.nam W]
$ns Namtrace-all $NAMTF

Proc Finish {} {
Global NS TRACEF NAMTF
$ns Flush-trace
Close $TRACEF
Close $NAMTF
exec Nam Example1.nam &
Exit 0
}

Set n0 [$ns node]
Set n1 [$ns node]

$ns duplex-link $n 0 $n 1 1Mb 10ms droptail

Set udp0 [New AGENT/UDP]
$ns attach-agent $n 0 $udp 0

Set cbr0 [New APPLICATION/TRAFFIC/CBR]
$CBR 0 Set Packetsize_ 500
$CBR 0 Set Interval_ 0.005
$CBR 0 attach-agent $udp 0

Set null0 [New Agent/null]
$ns attach-agent $n 1 $null 0

$ns Connect $UDP 0 $null 0

$ns at 0.5 "$CBR 0 start"
$ns at 4.5 "$CBR 0 Stop"

$ns at 5.0 "Finish"
$ns Run

It is also the NS0 to the NS1 node to send a packet size of 500 bytes, starting from 0.5 seconds, 4.5 seconds end. The time metric for the simulator is 2ms

Unit, so 1 seconds is also a long time. The next step is to master the Tcl language.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.