Ns2-entry 2

Source: Internet
Author: User
# Scenario Description: # In a wireless network, two nodes, node _ (0), node _ (1), TCP + FTP, and set the node movement # parameter settings for wireless nodes #

# Scenario Description: # In a wireless network, two nodes, node _ (0), node _ (1), TCP + FTP, and set the movement of the node #================================================ ========================================================== ==# parameter settings of the wireless node #========================================== ======================================

# Scenario Description:
# In a wireless network, two nodes, node _ (0), node _ (1), TCP + FTP, and node movement
#===================================================== ==========================================
# Parameter settings for wireless nodes
#===================================================== ==========================================
Set val (chan) Channel/WirelessChannel; # channel type
Set val (prop) Propagation/TwoRayGround; # radio-propagation model
Set val (netif) Phy/WirelessPhy; # network interface type
Set val (mac) Mac/802_11; # MAC type
Set val (ifq) Queue/DropTail/PriQueue; # interface queue type
Set val (ll) LL; # link layer type
Set val (ant) Antenna/OmniAntenna; # antenna model
Set val (ifqlen) 50; # max packet in ifq
Set val (nn) 2; # number of parameter enodes
Set val (rp) Oscar; # routing protocol
Set val (x) 500; # X dimension of the topography
Set val (y) 500; # Y dimension of the topography
#===================================================== ============================================


# Create a Simulator object for event scheduling during simulation
Set ns [new Simulator]
# Set related record files
Set tracefd [open example2.tr w]
$ Ns trace-all $ tracefd
Set namtracefd [open example2.nam w]
# Note: it is different from the commands in Wired scenarios!
$ Ns namtrace-all-wireless $ namtracefd $ val (x) $ val (y)


# Set the operation at the end of the simulation, write the record to the file, close the file, and finally start NAM for animation display
Proc finish {}{
Global ns tracefd namtracefd
$ Ns flush-trace

Close $ tracefd
Close $ namtracefd

Exec nam example2.nam &
Exit 0
}

# Create a Topography object, which ensures that the moving node will move within the topology boundary.
Set topo [new Topography]
#500X500 Boundary
$ Topo load_flatgrid $ val (x) $ val (y)

# The God object is mainly used to evaluate the performance of the routing protocol,
# It stores information such as the total number of nodes and the shortest path table between nodes. This information is usually calculated before the simulation starts!
# The MAC object of a node calls the God object. (beginners do not have to worry about it !)
Create-god $ val (nn)

$ Ns node-config-adhocRouting $ val (rp) \;
-LlType $ val (ll )\
-MacType $ val (mac )\
-IfqType $ val (ifq )\
-IfqLen $ val (ifqlen )\
-AntType $ val (ant )\
-PropType $ val (prop )\
-PhyType $ val (netif )\
-ChannelType $ val (chan )\
-TopoInstance $ topo \
-AgentTrace ON \
-RouterTrace ON \
-MacTrace OFF \
-MovementTrace OFF


# Create two nodes and store them in the array Node,
For {set I 0} {$ I <$ val (nn)} {incr I }{
Set node _ ($ I) [$ ns node]
$ Node _ ($ I) random-motion 0; # disable random motion
}
# Set the physical location of the node. Generally, the third place is Z _ = 0.0. The simulation process is actually on the plane.
$ Node _ (0) set X _ 5.0
$ Node _ (0) set Y _ 2.0
$ Node _ (0) set Z _ 0.0
$ Node _ (1) set X _ 390.0
$ Node _ (1) set Y _ 385.0
$ Node _ (1) set Z _ 0.0


# Set the node movement. setdest 20.0 18.0 1.0: Move to the (20.0, 18.0) position at a speed of 1.0 Mb/s!
$ Ns at 1.0 "$ node _ (0) setdest 20.0 18.0 1.0"
$ Ns at 5.0 "$ node _ (1) setdest 25.0 20.0 15.0"
$ Ns at 100.0 "$ node _ (1) setdest 490.0 480.0 15.0"


# Create TCP and TCP-corresponding TCPSink, connect them, and add an FTP application to the TCP Connection
Set tcp [new Agent/TCP]
$ Tcp set class _ 2
Set sink [new Agent/TCPSink]
$ Ns attach-agent $ node _ (0) $ tcp
$ Ns attach-agent $ node _ (1) $ sink
$ Ns connect $ tcp $ sink
Set ftp [new Application/FTP]
$ Ftp attach-agent $ tcp


# Set the start time of the FTP data stream
$ Ns at 1.0 "$ ftp start"
# Call the reset function of each node before the end of the simulation. In wireless scenarios, you can write the reset function as needed!
For {set I 0} {$ I <$ val (nn)} {incr I }{
$ Ns at 150.0 "$ node _ ($ I) reset ";
}
$ Ns at 150.0 "finish"

$ Ns run

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.