Measurement of throughput, packet loss rate, and end-to-end latency in Wireless Networks

Source: Internet
Author: User
Tags time 0

Link: http://blog.chinaunix.net/u3/105477/showart_2087878.html

 

 

Key points:

Learn how to compile the sampling process, how to obtain the required parameters, how to use individual files for recording, understand the specific physical meanings of throughput, packet loss rate, and end-to-end latency, and learn more about the parameter interfaces provided by NS2! [Scenario description]: four of the eight nodes serve as the source node of the data stream, and the remaining are the destination nodes of the data stream. Each source node and its corresponding destination node are connected through UDP, run the CBR application. Parameters of the CBR application: data packet size-512 bytes; transmission rate-600 kbps. Assume that each node is in the peer node (the next intermediate route node of the data packet) within the communication radius (the communication radius of each node: 195 m); The network simulation Duration: 80 seconds.

#
#
#
#===================================================== ======================================
# Define node configuration paramaters
#===================================================== ======================================
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) 8; # Number of parameter enodes
Set Val (RP) DSDV; # Routing Protocol
Set Val (x) 500; # x dimension of the topography
Set Val (y) 500; # y dimension of the topography
MAC/802_11 set rtsthreshold _ 3000
MAC/802_11 set basicrate _ 1 MB
MAC/802_11 set datarate _ 2 MB
#===================================================== ====================================
# Initialize trace file desctiptors
#===================================================== ====================================
# *** Throughput trace ***
Set F0 [open out02.tr w]
Set F1 [open out12.tr w]
Set F2 [open out22.tr w]
Set F3 [open out32.tr w]
# *** Packet loss trace ***
Set F4 [open lost02.tr w]
Set F5 [open lost12.tr w]
Set F6 [open lost22.tr w]
Set F7 [open lost32.tr w]
# *** Packet delay trace ***
Set F8 [open delay02.tr w]
Set F9 [open delay12.tr w]
Set F10 [open delay22.tr w]
Set F11 [open delay32.tr w]

# The following code has been commented out in detail in entry instance 2!
Set NS _ [New simulator]
Set tracefd [open trace2.tr w]
$ NS _ trace-all $ tracefd
Set namtrace [open sim12.nam w]
$ NS _ namtrace-all-Wireless $ namtrace $ Val (x) $ Val (y)

Set Topo [New topography]
$ Topo load_flatgrid 500 500
 
# Create general operations director (God) object.
# It is used to store global information about the state of the environment, network, or nodes that
# Omniscent observer wocould have, but that shocould not be made known to any participant in the simulation.
 
Create-God $ Val (NN)
# Configure nodes
$ 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 nodes
For {set I 0} {$ I <$ Val (NN)} {incr I }{
Set node _ ($ I) [$ NS _ node]
$ Node _ ($ I) random-motion 0; # disable random motion
}
# Initialize node coordinates
$ Node _ (0) set X _ 5.0
$ Node _ (0) set Y _ 5.0
$ Node _ (0) set Z _ 0.0

$ Node _ (1) set X _ 200.0
$ Node _ (1) set Y _ 5.0
$ Node _ (1) set Z _ 0.0

$ Node _ (2) set X _ 5.0
$ Node _ (2) set Y _ 50.0
$ Node _ (2) set Z _ 0.0

$ Node _ (3) set X _ 200.0
$ Node _ (3) set Y _ 50.0
$ Node _ (3) set Z _ 0.0
 
$ Node_( 4) set X _ 5.0
$ Node _ (4) set Y _ 100.0
$ Node _ (4) set Z _ 0.0

$ Node _ (5) set X _ 200.0
$ Node _ (5) set Y _ 100.0
$ Node _ (5) set Z _ 0.0

$ Node _ (6) set X _ 2.0
$ Node _ (6) set Y _ 150.0
$ Node _ (6) set Z _ 0.0

$ Node_( 7) set X _ 200.0
$ Node _ (7) set Y _ 150.0
$ Node _ (7) set Z _ 0.0

# Setup traffic flow between nodes
# TCP connections between node _ (0) and node _ (1)
# Create constant four bit rate traffic sources
#===================================================== ==================================
# The following code can be written as a process, which is much more convenient!
# Sort it out first, and I will change it later!
#===================================================== ==================================
Set agent1 [new agent/udp]; # create TCP agent
$ Agent1 set PRIO _ 0; # set its priority to 0
# Create loss monitor sink in order to be able to trace the number obytes attached ed

Set sink [new agent/lossmonitor]
$ NS _ attach-agent $ node _ (0) $ agent1; # attach agent to source node
$ NS _ attach-agent $ node _ (1) $ sink; # attach agent to sink node
$ NS _ connect $ agent1 $ sink; # connect the nodes
Set app1 [New Application/traffic/CBR]; # create constant bit rate application
$ App1 set packetsize _ 512; # Set packet size to 512 bytes
$ App1 set rate _ 600kb; # Set CBR rate to 200 kbits/sec
$ App1 attach-agent $ agent1; # attach application to Agent

Set agent2 [new agent/udp]; # create TCP agent
$ Agent2 set PRIO _ 1; # set its priority to 1
# Create loss monitor sink in order to be able to trace the number obytes attached ed
Set sink2 [new agent/lossmonitor]
$ NS _ attach-agent $ node _ (2) $ agent2; # attach agent to source node
$ NS _ attach-agent $ node _ (3) $ sink2; # attach agent to sink node
$ NS _ connect $ agent2 $ sink2; # connect the nodes
Set app2 [New Application/traffic/CBR]; # create constant bit rate application
$ App2 set packetsize _ 512; # Set packet size to 512 bytes
$ App2 set rate _ 600kb; # Set CBR rate to 200 kbits/sec
$ App2 attach-agent $ agent2; # attach application to Agent

Set agent3 [new agent/udp]; # create TCP agent
$ Agent3 set PRIO _ 2; # set its priority to 2
# Create loss monitor sink in order to be able to trace the number obytes attached ed
Set sink3 [new agent/lossmonitor]
$ NS _ attach-agent $ node _ (4) $ agent3; # attach agent to source node
$ NS _ attach-agent $ node _ (5) $ sink3; # attach agent to sink node
$ NS _ connect $ agent3 $ sink3; # connect the nodes
Set app3 [New Application/traffic/CBR]; # create constant bit rate application
$ App3 set packetsize _ 512; # Set packet size to 512 bytes
$ App3 set rate _ 600kb; # Set CBR rate to 200 kbits/sec
$ App3 attach-agent $ agent3; # attach application to Agent

Set agent4 [new agent/udp]; # create TCP agent
$ Agent4 set PRIO _ 3; # set its priority to 3
# Create loss monitor sink in order to be able to trace the number obytes attached ed
Set sink4 [new agent/lossmonitor]
$ NS _ attach-agent $ node _ (6) $ agent4; # attach agent to source node
$ NS _ attach-agent $ node _ (7) $ sink4; # attach agent to sink node
$ NS _ connect $ agent4 $ sink4; # connect the nodes
Set app4 [New Application/traffic/CBR]; # create constant bit rate application
$ App4 set packetsize _ 512; # Set packet size to 512 bytes
$ App4 set rate _ 600kb; # Set CBR rate to 200 kbits/sec
$ App4 attach-agent $ agent4; # attach application to Agent

# Defines the node size in network animator
For {set I 0} {$ I <$ Val (NN)} {incr I }{
$ NS _ initial_node_pos $ node _ ($ I) 20
}

# Initialize flags
Set holdtime 0
Set holdseq 0

Set holdtime1 0
Set holdseq1 0

Set holdtime2 0
Set holdseq2 0

Set holdtime3 0
Set holdseq3 0

Set holdrate1 0
Set holdrate2 0
Set holdrate3 0
Set holdrate4 0

# Function to record statistcis (bit rate, delay, drop)
Proc record {}{

Global sink sink2 sink3 sink4 F0 F1 F2 F3 F5 F6 F6 F7 holdtime holdseq
Holdtime1 holdseq1 holdtime2 holdseq2 holdtime3 holdseq3 F8 F9 F10 F11
Holdrate1 holdrate2 holdrate3 holdrate4
Set NS [simulator instance]
Set Time 0.9; # Set sampling time to 0.9 Sec
Set bw0 [$ sink set bytes _]
Set bw1 [$ sink2 set bytes _]
Set bw2 [$ sink3 set bytes _]
Set bw3 [$ sink4 set bytes _]
Set bw4 [$ sink set nlost _]
Set bw5 [$ sink2 set nlost _]
Set Bw6 [$ sink3 set nlost _]
Set Bw7 [$ sink4 set nlost _]
Set bw8 [$ sink set lastpkttime _]
Set bw9 [$ sink set npkts _]
Set BW10 [$ sink2 set lastpkttime _]
Set bw11 [$ sink2 set npkts _]
Set BW12 [$ sink3 set lastpkttime _]
Set bw13 [$ sink3 set npkts _]
Set bw14 [$ sink4 set lastpkttime _]
Set bw15 [$ sink4 set npkts _]

Set now [$ NS now]
# Record Bit Rate in Trace files
Puts $ F0 "$ now [expr ($ bw0 + $ holdrate1) * 8)/(2 * $ time * 1000000)]"
Puts $ F1 "$ now [expr ($ bw1 + $ holdrate2) * 8)/(2 * $ time * 1000000)]"
Puts $ F2 "$ now [expr ($ bw2 + $ holdrate3) * 8)/(2 * $ time * 1000000)]"
Puts $ F3 "$ now [expr ($ bw3 + $ holdrate4) * 8)/(2 * $ time * 1000000)]"

# Record packet loss rate in file
Puts $ F4 "$ now [expr $ bw4/$ time]"
Puts $ F5 "$ now [expr $ bw5/$ time]"
Puts $ F6 "$ now [expr $ Bw6/$ time]"
Puts $ F7 "$ now [expr $ Bw7/$ time]"
 
# Record packet delay in file
If {$ bw9> $ holdseq }{
Puts $ F8 "$ now [expr ($ bw8-$ holdtime)/($ bw9-$ holdseq)]"
} Else {
Puts $ F8 "$ now [expr ($ bw9-$ holdseq)]"
}

If {$ bw11> $ holdseq1 }{
Puts $ F9 "$ now [expr ($ BW10-$ holdtime1)/($ bw11-$ holdseq1)]"
} Else {
Puts $ F9 "$ now [expr ($ bw11-$ holdseq1)]"
}

If {$ bw13> $ holdseq2 }{
Puts $ F10 "$ now [expr ($ BW12-$ holdtime2)/($ bw13-$ holdseq2)]"
} Else {
Puts $ F10 "$ now [expr ($ bw13-$ holdseq2)]"
}
 
If {$ bw15> $ holdseq3 }{
Puts $ F11 "$ now [expr ($ bw14-$ holdtime3)/($ bw15-$ holdseq3)]"
} Else {
Puts $ F11 "$ now [expr ($ bw15-$ holdseq3)]"
}

# Reset Variables
$ Sink set bytes _ 0
$ Sink2 set bytes _ 0
$ Sink3 set bytes _ 0
$ Sink4 set bytes _ 0

$ Sink set nlost _ 0
$ Sink2 set nlost _ 0
$ Sink3 set nlost _ 0
$ Sink4 set nlost _ 0

Set holdtime $ bw8
Set holdseq $ bw9
Set holdrate1 $ bw0
Set holdrate2 $ bw1
Set holdrate3 $ bw2
Set holdrate4 $ bw3

$ NS at [expr $ now + $ time] "record"; # Set timed sampling. Haha!
}
# Set events for simulating!
$ NS _ at 0.0 "record"
$ NS _ at 1.4 "$ app1 start"
$ NS _ at 10.0 "$ app2 start"
$ NS _ at 20.0 "$ app3 start"
$ NS _ at 30.0 "$ app4 start"

$ NS _ at 80.0 "stop"
# Reset nodes at time 80 sec
For {set I 0} {$ I <$ Val (NN)} {incr I }{
$ NS _ at 80.0 "$ node _ ($ I) reset ";
}

# Exit simulatoion at time 80.01 Sec
$ NS _ at 80.01 "puts/" ns exiting.../"; $ NS _ halt"
Proc stop {}{
Global NS _ tracefd F0 F1 F2 F3 F5 F6 F6 F7 F8 F9 F10 F11
# Close trace files
Close $ F0
Close $ F1
Close $ F2
Close $ F3
Close $ F4
Close $ F5
Close $ F6
Close $ F7
Close $ F8
Close $ F9
Close $ F10
Close $ F11

# Plot recorded statistics
Exec xgraph out02.tr out12.tr out22.tr out32.tr-geometry 800x400 &
Exec xgraph lost02.tr lost12.tr lost22.tr lost32.tr-geometry 800x400 &
Exec xgraph delay02.tr delay12.tr delay22.tr delay32.tr-geometry 800x400 &
# Reset trace file
$ NS _ flush-trace
Close $ tracefd
Exit 0
}
Puts "Starting simulation ..."
$ 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.