The process of NS2 network simulation

Source: Internet
Author: User

The process of NS2 network simulation can be summarized as follows:
1. Initialization
Create NS Simulator
Create a. tr file (record simulation results)
Creating a. nam file (documenting the simulation process)
Set End Function
Set the required parameters in the simulation
2. Create a simulation topology
Create a Node
Create and set a link
Set how links are arranged in Nam
3. Create traffic
Probe traffic: Add additional traffic to the network, through the statistical analysis of these traffic can obtain end-to-end performance parameters, in the NS2 can be set up in the form of CBR, UDP, TCP and other forms of traffic implementation.
Background traffic: Used to simulate the existing traffic in the network, can have TCP, UDP, short-time TCP and many other forms. (Add criteria: as much as possible to reflect the characteristics of the actual network traffic)
4. Setup Steps
Set the generation and end of traffic
5. End Simulation

We can look at the simulation process against the following example:

#Create a simulator objectset ns [new simulator] #Define different colors for data flows$ns color 1 blue$ns color 2 red#ope n the NAM Trace fileset NF [open Out.nam W] $ns namtrace-all $nf # define a ' finish ' Procedureproc finish {} {Global NS NF $ns flush-trace#close The trace file Close $nf #execute nam on the trace file exec Nam Out.nam &        Amp Exit 0} #Create four nodesset n0 [$ns node]set N1 [$ns node]set n2 [$ns node]set N3 [$ns node] #Create links between the nod Es$ns duplex-link $n 0 $n 2 1Mb 10ms droptail$ns duplex-link $n 1 $n 2 1Mb 10ms droptail$ns duplex-link $n 3 $n 2 1Mb 10ms sfq$n s duplex-link-op $n 0 $n 2 Orient right-down$ns duplex-link-op $n 1 $n 2 Orient right-up$ns duplex-link-op $n 2 $n 3 Orient Righ T#monitor the queue for the link between Node 2 and node 3$ns duplex-link-op $n 2 $n 3 queuepos 0.5#create a UDP agent and a Ttach it to Node N0set udp0 [new AGENT/UDP] $UDP 0 Set class_ 1$ns attach-agent $n 0 $udp 0# Create a CBR traffic source and a Ttach it toUdp0set cbr0 [New APPLICATION/TRAFFIC/CBR] $CBR 0 Set packetsize_ 500$cbr0 set Interval_ 0.005$cbr0 attach-agent $udp 0#crea Te a UDP agent and attach it to Node N1set UDP1 [New AGENT/UDP] $UDP 1 set class_ 2$ns attach-agent $n 1 $udp # Create a CBR Traffic source and attach it to Udp1set CBR1 [new APPLICATION/TRAFFIC/CBR] $CBR 1 set packetsize_ 500$CBR1 set Interval_ 0.0 05$CBR1 attach-agent $udp 1#create a Null agent (a traffic sink) and attach it to Node N3set null0 [New Agent/null] $ns Atta Ch-agent $n 3 $null 0#connect The traffic sources with the traffic Sink$ns connect $udp 0 $null 0 $ns connect $udp 1 $null 0#sc Hedule events for the CBR Agents$ns at 0.5 "$CBR 0 start" $ns at 1.0 "$CBR 1 Start" $ns at 4.0 "$CBR 1 Stop" $ns at 4.5 "$CBR 0 S Top "#Call the finish procedure after 5 seconds of simulation Time$ns at 5.0" Finish "#Run the Simulation$ns Run

The result of this example operation is as follows:


The process of NS2 network simulation

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.