ENSC 427: COMMUNICATION NETWORKSljilja/.../ENSC_427_finalreportfinal.pdf · 2 | P a g e Abstract In...
Transcript of ENSC 427: COMMUNICATION NETWORKSljilja/.../ENSC_427_finalreportfinal.pdf · 2 | P a g e Abstract In...
ENSC 427: COMMUNICATION NETWORKS
An Analysis of Peer-to-Peer Traffic over
an Ad-Hoc Network
Project Website: www.sfu.ca/~yha64/ENSC427.html
TEAM #13
Ian Brown
301066660
ita at sfu dot ca
Yumin Oliver Huang
301072798
yha64 at sfu dot ca
Simon Fraser University
School of Engineering
Course Instructor: Professor LjiljanaTrajkovic
4/16/2013
SFU
1 | P a g e
Table of Contents Abstract ........................................................................................................................................... 2
1. Introduction and Motivation ....................................................................................................... 3
1.1. General Background ................................................................................................................ 3
1.2. Peer-to-Peer Network ............................................................................................................. 3
1.3. Ad-hoc network ....................................................................................................................... 4
1.4. Peer-to-Peer over Ad-hoc network ......................................................................................... 4
2. Implementation ........................................................................................................................... 4
2.1. TCP file transfer in NS-2 .......................................................................................................... 4
2.2. Structure of AODV Protocol in NS-2 ........................................................................................ 5
3. Simulation ................................................................................................................................... 7
3.1. Scenario 1: Two Mobile Nodes................................................................................................ 7
3.2. Scenario 2: AODV Movement Baseline ................................................................................... 7
3.3. Scenario 3: Background Traffic Comparison ........................................................................... 8
4. Results ......................................................................................................................................... 9
5.1 Scenario 1: Two Mobile Nodes Results ................................................................................... 9
5.2 Scenario 2: AODV Movement Baseline Results ..................................................................... 10
5.3 Scenario 3: Background Traffic Comparison Results ............................................................. 11
5. Conclusion ................................................................................................................................. 12
6. Future Work .............................................................................................................................. 12
6.1. Implementation/ Algorithm Improvement ........................................................................... 13
6.2. Applicability and Network Model ......................................................................................... 13
7. References ................................................................................................................................. 14
8. Appendix ................................................................................................................................... 15
8.1. Scenario 1 .............................................................................................................................. 15
8.2. Scenario 2 .............................................................................................................................. 17
8.3. Scenario 3 (No Background Traffic) ....................................................................................... 20
8.4. Scenario 3 (Background Traffic) ............................................................................................ 23
2 | P a g e
Abstract
In recent years, the usage of mobile computing has increased, especially when needing to access distinct types of information anytime and anywhere. Over these new networks, quality of service (QoS) factors such as packet loss, delay, completion time, etc. are important considerations for users. For communication between mobile devices in the immediate vicinity, using a peer-to-peer network model to establish direct ad-hoc connections often provides higher efficiency for exchanging data. Our project seeks to model Peer-to-Peer traffic over a wireless ad-hoc networking utilizing the AODV protocol in a noisy environment in comparison with minimal to no extra traffic in an attempt to find points for improvement. In order to accomplish our project goals, we are planning to use the ns2 simulator to obtain information on Quality of Service over the specified network. The project will involve analysing the inquiry packet interference based on the analytical model for single inquiring node interference and to multiple inquiry nodes interference. This should help identify potential solutions for any issues that we across with and attempt to improve the points.
3 | P a g e
1. Introduction and Motivation
1.1. General Background As more and more devices become interconnected, new challenges will appear
and new network structures will emerge. One such example is the mass integration of wireless technologies into portable devices such as phones, computers, tablets, watches, and computer peripherals. For our project, we will be investigating the Quality of Service (QoS) of a Peer-to-Peer network of wireless nodes under the Ad-hoc On-Demand Distance Vector (AODV) routing protocol. The objective of this investigation will be to explore the impact on QoS between two nodes on the network by introducing movement and background traffic into the simulation. We will looked several different scenarios on a select few topologies and draw conclusions about the introduction of noise to the network.
1.2. Peer-to-Peer Network The peer-to-peer (p2p) network is a virtual network at the application level,
commonly used to distribute content as part of a Content Distribution Network (CDN) [1]. They have their own protocol for routing between devices. Sharing information and resources directly, instead of going through dedicated servers, allows the network to route on demand and to nodes out of reach. One of the main advantages of p2p networks is giving the users the opportunity to distribute data and information by contributing bandwidth back to the network. This allows members of a p2p network to receive resources from the network for sharing the resources with the network. The p2p network system can be categorized in three main types, centralized, decentralized and hybrid [2]. In the centralized p2p system, a central server manages the coordination between peers, and after receiving the information from the central server, peers can communicate with one another. This way, the system is easy to manage and secures the network. However, some data can only be held by the central server, thus resulting in a low fault-tolerance and limits network scalability due to the limitations of the server. Scalability can be improved by increasing processing power of the computers. This type of p2p network system is mainly used in the search architecture like Napster, and the system SETI@Home, which has a central job dispatcher. In decentralized system, the peers have equal roles where peers forward messages on behalf of others peers instead of having a central server to manage the communication. This topology gives a network to extend easily and gives an advantage for fault-tolerance. Examples of this topology used applications are Freenet and Gnutella. The hybrid p2p model is a combination of centralized method and decentralized methods where peers forward their queries to “super-peers” [3] which communicate with each other in a decentralized manner. Example of this model is Morpheus, and KazaA. In this research, we are using the decentralized and/or hybrid model for dynamic network analysis and ability to extend network for further research
4 | P a g e
1.3. Ad-hoc network Ad-hoc networks are a way to allow mobile device to establish direct
communication between nearby nodes in the network. Ad-hoc networks allow devices to communicate without involving central access points, including wireless routers. Several different mobile ad-hoc network routing protocols have been accepted so far. They include:
AODV: ad-hoc on demand distance vector
DSR: destination sequenced distance vector
OLSR: dynamic source routing
ZRP: Zone routing protocol
The protocol being explored in this investigation is the ns2 implementation of the AODV protocol [4]. This protocol creates paths between nodes by broadcasting a request over the network for a specific node and receiving a route to the desired node on the callback. Mobile ad-hoc networks (MANETs) is subset of the AODV protocol which are self-configuring networks of mobile devices connected wirelessly, which can form wireless network without any fixed infrastructure‟s existence [5]. The MANETs‟ IP routing protocol functionality makes it suitable for wireless routing application with potential dynamic topologies [6]. Thus, our primary focus for this approach is on managing and analysing the network links with p2p network protocol.
1.4. Peer-to-Peer over Ad-hoc network The main advantage of a peer-to-peer over ad-hoc network is an ability to form the
network without having an infrastructure,nor the network need to depend on a central server. Our future works will be analysing the network by using the NS-2 network simulator which supports ad-hoc network models [7][8]. The main goal of the research is investigating network traffic in the „P2P over Ad-hoc network‟. Yet, the algorithm of the chosen p2p (decentralized and/or hybrid model) and the structure of the network will discussed in the future project report(s).
2. Implementation
2.1. TCP file transfer in NS-2 TCP [9]implements a window based flow control mechanism, and TCP is known as a
connection-oriented protocol, which meansthe primary objective of TCP is to monitor and ensure the efficient delivery of individual packets between the pair of sender and receiver. This project chooses TCP over User Datagram Protocol (UDP) to establish the connection because that unlike UDP which is only being implemented at source, TCP is implemented at source and destination. Indeed, TCP’s flow control is based on Window size and packet transmission and error control is based on acknowledgement (ACK) packet transmission which makes TCP more reliable than UDP. The figure below describes the TCP Transition Diagram:
5 | P a g e
Figure 1: TCP State Transition Diagram [10]
Another important aspect s of TCP is that, the protocol has Congestion Control to avoid congestion collapse in the network which causes a packet during the transmission. Generally, when the congestion occurs TCP will slow down its transmission rate of packets in to the network, and then invoke the slow start algorithm to re-establish the transmission. TCP also has Fast Retransmit where an immediate acknowledgment (a duplicate ACK) will be generated when a segment is received in out of order. So that the other end will be informed about the out-of-order segment and tells the expected sequence to avoid the packet loss. Moreover, the Fast Recovery a method of TCP allows recover the transmission without reduces the flow abruptly, if more than a packet has been lost.
2.2. Structure of AODV Protocol in NS-2 One distinguishing feature of AODV [11] is that the protocol uses a destination sequence
number for each route entry. The destination sequence number is created by the destination where the route information is also included. By using the destination sequence numbers, the defined route can ensure that the route is loop-free.
The AODV protocol has two main phases; Route Discovery and Route Maintenance by using the following three message type; route request (RREQ), route reply (RREP) and rout error (RRER). Indeed, these message types are received via UDP, and have normal IP header process. The AODV performs Route Discovery using RREQ and RREP for sending packet from one node to the destination node. At the Route discovery stage, the source sends the RREQ packet in a controlled flooding manner throughout the network as shown in the Figure 2 and 3.
6 | P a g e
Figure 2: In Route Discovery stage, broadcasting RREQ
messages (Green Node: Source, Red Node: Destination)
Figure 3: In Route Discovery stage, Replying RREP
messages (Green Node: Source, Red Node: Destination)
Once the source route broadcasts a RREQ to find a route to the destination, intermediate node checks the routing. If the RREQ message reaches to the destination, it will reply RREP back to source node (through intermediate node(s) if there is/are node between them), otherwise the intermediate forwards RREQ packet to its neighbours. The route will be established once RREP message is back to the origination of the RREQ, the source node.
One of the advantages in AODV protocol is that nodes monitor the link status of next hops in active routes. If there is a link breakage in an active route is detected, a RERR message is used to notify other nodes that the loss of link connection occurred at the point. Then the source node will initialize a new route discovery stage and food the RREQ packet to create a new route to the destination as shown in the Figure 4 and 5.
Figure 4: In Route Maintenance stage, sending RRER massage (The cross sign indicates the link breakdown)
Figure 5: In Route Maintenance stage, broadcasting RREQ after link breakage
In NS-2 the upstream node can directly flood the RREQ packet as well as notify source to eliminate invalid route entry. In this way, the following scenarios can be simulated efficiently
7 | P a g e
and can be tested in the more realistic situation. In addition, please check the Appendix A for the format of RREQ, RREP and RRER.
3. Simulation To observe the effects of background traffic on the Quality of Service over an adhoc
wireless network, we have constructed three different scenarios. The first scenario is a test of the wireless networking capabilities in NS-2 and to extract the baseline performance of the wireless mobile nodes in NS-2 using AODV. The second scenario is a test of the AODV protocol behaviour as a node travels away from it is partner and must subsequently pass packets through other nodes. The final scenario is to analyse Peer-To-Peer traffic over an ADHOC network and observe it is quality of service between background traffic and no background traffic situations.
3.1. Scenario 1: Two Mobile Nodes Scenario 1 was designed to observe the basic behaviour of the NS-2 ftp behaviour. This
serves as a reference for Scenario 2 and 3. This simulation tests an Ad-hoc network using the AODV protocol. Figure 6 illustrates the basic design of Scenario 1.
Figure 6: Network Topology for Scenario 1
3.2. Scenario 2: AODV Movement Baseline Scenario 2 involves 5 nodes; four nodes are positioned at same distance away from each
other and one node moves right to left parallel to other four nodes and then once the node
8 | P a g e
pass all four nodes it moves up and away from the range of all the nodes. The graphical topology is presented in Figure 7.
Figure 7: Network Topology for Scenario 2
3.3. Scenario 3: Background Traffic Comparison Scenario 3 involves one network with two different parameters: one simulation without
background traffic and other with background traffic. The purpose of these two scenarios was to observe the difference between a network with no traffic and a network with other traffic. The specific types of data, constant bit rate, and pack drop rate will be compared for analysing the QoS of the network. The topology of the Scenario 3 is show in the Figure 8.
Figure 8: Network Topology for Scenario 3
9 | P a g e
4. Results
5.1 Scenario 1: Two Mobile Nodes Results The results of this simulation demonstrated that the NS-2 wireless mobile node's default
range is 250 units. This became the basis for spacing on the subsequent simulations. Figures 9 and 10 clearly demonstrate that the nodes become out of communication range and no longer transmit.
Figure 9: TCP window size for Scenario 1
End To End Delay Throughput
Figure 10: Results of Scenario 1 (End of Delay Left, Throughput Right)
0
10
20
30
40
50
60
70
80
90
100
10
.11
5.4
92
0.8
82
6.2
73
1.6
63
7.0
54
2.4
44
7.8
35
3.2
25
8.6
16
46
9.3
97
4.7
88
0.1
78
5.5
69
0.9
59
6.3
41
01
.73
10
7.1
21
12
.51
11
7.9
12
3.2
91
28
.68
13
4.0
71
39
.46
14
4.8
5Time (Seconds)
Scenario 1 - TCP Window Size
10 | P a g e
It is evident that the TCP connection experiences a timeout by Figure 9 and by the change in the
graphs around the 50 second mark through we suspect that the leveling out of the delay is a by-
product of taking the average of packets.
5.2 Scenario 2: AODV Movement Baseline Results Drawing upon the information in Scenario 1, it is evident that the as the TCP connection
goes through multiple intermediate nodes, the quality of service that the connection provides
degrades considerably until the connection become poor.
Figure 11: TCP Window Size for Scenario 2
End To End Delay Throughput
Figure 12: Results of Scenario 2 (End of Delay Left, Throughput Right)
0
20
40
60
80
100
120
10
.12
1.2
63
2.4
24
3.5
85
4.7
46
5.9
77
.06
88
.22
99
.38
11
0.5
41
21
.71
32
.86
14
4.0
21
55
.18
16
6.3
41
77
.51
88
.66
19
9.8
22
10
.98
22
2.1
42
33
.32
44
.46
25
5.6
22
66
.78
27
7.9
42
89
.1
Time (Seconds)
Scenario 2 - TCP Window Size
11 | P a g e
The delay and throughput computations also confirm that as the number of intermediate nodes
increase, so too does delay. Not as much data being passed through as a result of a smaller TCP
window can be expected as well.
5.3 Scenario 3:Background Traffic Comparison Results By analysing the results from Scenario 1 and 2, the Scenario 3 results without background
traffic follow rather closely to what we expected. The major change happens after the being
routed through 3 or 4 intermediate nodes. While observing the NAM simulations, RREQ requests
could be seen regularly until the moving nodes reached their final positions. These frequent RREQ
broadcasts changed routes from time to time so the sharp dips in TCP window size roughly
correlate to these times but not always.
Scenario 3 - TCP Window Size Scenario 3 (Background Traffic) - TCP Window Size
Figure 13: TCP Window Size for Scenario 3
Scenario 3 - End To End Delay Scenario 3 (Background Traffic)- End To End Delay
Figure 14: Results of Scenario 3 (End of Delay)
01020304050607080
10
.1
20
.1
30
.1
40
.1
50
.1
60
.1
70
.1
80
.1
90
.1
10
0.1
11
0.1
12
0.1
13
0.1
14
0.1
Time (Seconds)
0
10
20
30
40
50
60
10
.1
19
.43
28
.76
38
.09
47
.42
56
.75
66
.08
75
.41
84
.74
94
.07
10
3.4
11
2.7
3
12
2.0
6
13
1.3
9
14
0.7
2
Time (Seconds)
12 | P a g e
Figure 15: Figure 16: Results of Scenario 3 (Throughout)
The delay and throughput for the analysis without background traffic match Scenario 2 somewhat
which validates Scenario 2 and it is corresponding assumptions about the delay increasing to a
certain point and throughput decreasing.
Comparing these results to the results involving background traffic, we see that the constant
background traffic, achieved through strategically placed CBR nodes, provides sufficient disruption
in the connection and only gets worse as the ftp connection travels through more nodes handling
background traffic. This accounts for the behaviour of the TCP window size plot as the simulation
progressed. The throughput and delay were worse than we expected and a bit less stable given
the constant nature of the background traffic but the overall trend seems to be the same
5. Conclusion First and foremost, NS-2 has been shown to be a suitable tool for analyzing Ad-hoc network using
peer to peer routing. The AODV protocol and TCP used to analysing the Ad-hoc network were
tested and validated. A more complicated and realistic examination was performed with a
network model involving 18 nodes with background traffic and able to compare and analysis the
behaviour of the ad-hoc network with background traffic and without the background traffic.
Indeed, packet throughout and delay measurements was also being able to analysis from the
results.
6. Future Work There are two main categories for future work and improvements to the NS-2 simulation models
in this project for further researches in Ad-hoc networks
Scenario 3 - Throughput Scenario 3 (Background Traffic) - Throughput
13 | P a g e
6.1. Implementation/ Algorithm Improvement This project focused on the AODV protocol for Ad-hoc network, yet there are other protocols
as DSR, OLSR, and ZRP protocol could be implemented in order to make a comparison
between the protocols to testify the best use of those protocols in real situation. Additionally,
modifying the source code in the NS-2 in way to fit the scenario may able to increase the
complexity of the network simulation which would provide more realistic results and could
improve overall network performance.
6.2. Applicability and Network Model The simulations that ware performed involves equal distance between the nodes and the
receiver and sender were moving at constant speed. However, it is unlikely that a real network
would have these theoretical characteristics. Creating and simulating a real-world network
model and application would provide more realistic results.
14 | P a g e
7. References
[1] Charles E. Perkins, Elizabeth M. Royer, Ad hoc On-Demand Distance Vector Routing, 2nd ed.
New Orleans, LA, 1999.
[2] Piotr Wydrych, "Mobile Peer to Peer," IEEE Communications Magazine, vol. 48, no. 6, pp. 10-
10, June 2010.
[3] T. Hong, "Peer-to-Peer," Harnessing the Power of Disruptive, vol. 43, no. 5, pp. 31-31,
September 2001.
[4] The Network Simulator - ns-2. [Online]. http://www.isi.edu/nsnam/ns/
[5] Marisa A. Vasconcelos , Rainer P. Couto , Antonio A.F. Loureiro Fernanda P. Franciscani,
"(Re)configuration algorithms for peer-to-peer over ad hoc networks," Journal of Parallel and
Distributed Computing, vol. 65, no. 2, pp. 234-245, February 2005.
[6] P.C.Gupta, "Minimization of Average Delay, Routing Load and Packet Loss Rate in AODV
Routing Protocol," International Journal of Computer Applications, vol. 44, no. 15, pp. 14-17,
April 2012.
[7] Gerson Sunyé, Yves Le Traon, Patrick Valduriez Eduardo Cunha de Almeida, "Testing peer-to-
peer systems," Empirical Software Engineering, vol. 15, no. 4, pp. 346-379, August 2010.
[8] R. R. Brooks, Disruptive Security Technologies with Mobile Code and Peer-to-Peer Networks.:
CRC Press, 2004.
[9] Bharat Kumar, "Performance of TCP-Throughput on NS2 by Using Different Simulation
Parameters," International Journal of Advanced Computer Research, vol. 2, no. 4, p. 323,
December 2012.
[10] A TCP Tutorial. [Online]. http://www.ssfnet.org/Exchange/tcp/tcpTutorialNotes.html
[11] D. Azzi, "Ad-hoc Networks Energy Consumption: A review of the Ad-Hoc Routing Protocols,"
Journal of Engineering Science and Technology Review, vol. 3, no. 1, pp. 162-167, 2010.
[Online]. http://jist.ece.cornell.edu/docs/040421-swans-aodv.pdf
15 | P a g e
8. Appendix
8.1. Scenario 1 # Define options setval(chan) Channel/WirelessChannel setval(prop) Propagation/TwoRayGround setval(netif) Phy/WirelessPhy setval(mac) Mac/802_11 setval(ifq) Queue/DropTail/PriQueue setval(ll) LL setval(ant) Antenna/OmniAntenna setval(ifqlen) 50 ;# max packet in ifq setval(nn) 2 ;# how many nodes are simulated setval(rp) AODV setval(x) 500 ;# X dimension of topolograph setval(y) 400 setval(stop) 150 ;# simulation time #setup trace files set ns [new Simulator] settracefd [open BASELINE_tf.tr w] set windowVsTime2 [open BASELINE_win.tr w] setnamtrace [open BASELINE_simw.nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) #set up topography object settopo [new Topography] $topoload_flatgrid $val(x) $val(y) create-god $val(nn) # configure the 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) \
16 | P a g e
-phyType $val(netif) \ -channelType $val(chan) \ -topoInstance $topo \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace ON for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] } #Provide initial location of mobile nodes $node_(0) set X_ 5.0 $node_(0) set Y_ 5.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 5.0 $node_(1) set Y_ 5.0 $node_(1) set Z_ 0.0 #Generation of movements $ns at 1.0 "$node_(0) setdest 400.0 5.0 5.0" #Set a TCP connection between node_(0) and node_(1) settcp [new Agent/TCP/Newreno] $tcp set class_ 2 #$tcp set window_ 2000 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 $ns at 1.0 "$ftp start" #Printing the tcpwindow size procplotWindow {tcpSource file} { global ns set time 0.01 set now [$ns now] setcwnd [$tcpSource set cwnd_] puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.1 "plotWindow $tcp $windowVsTime2"
17 | P a g e
# Define node initial position in nam for {set i 0} {$i < $val(nn)} { incr i } { #node size for nam $ns initial_node_pos $node_($i) 30 } #when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; } #ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at 150.01 "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefdnamtrace $ns flush-trace close $tracefd close $namtrace execnamBASELINE_simw.nam& execxgraph BASELINE_win.tr & exit 0 } $ns run
8.2. Scenario 2 # Define options setval(chan) Channel/WirelessChannel setval(prop) Propagation/TwoRayGround setval(netif) Phy/WirelessPhy setval(mac) Mac/802_11 setval(ifq) Queue/DropTail/PriQueue setval(ll) LL setval(ant) Antenna/OmniAntenna setval(ifqlen) 50 ;# max packet in ifq setval(nn) 6 ;# how many nodes are simulated
18 | P a g e
setval(rp) AODV setval(x) 1000 ;# X dimension of topolograph setval(y) 350 setval(stop) 300 ;# simulation time #setup the trace files set ns [new Simulator] settracefd [open HOP_tf.tr w] set windowVsTime2 [open HOP_win.tr w] setnamtrace [open HOP_simw.nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) #set up topography object settopo [new Topography] $topoload_flatgrid $val(x) $val(y) create-god $val(nn) #configure the 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 ON for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] } #Provide initial location of mobile nodes $node_(0) set X_ 5.0 $node_(0) set Y_ 20.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 5.0
19 | P a g e
$node_(1) set Y_ 10.0 $node_(1) set Z_ 0.0 $node_(2) set X_ 240.0 $node_(2) set Y_ 10.0 $node_(2) set Z_ 0.0 $node_(3) set X_ 475.0 $node_(3) set Y_ 10.0 $node_(3) set Z_ 0.0 $node_(4) set X_ 710.0 $node_(4) set Y_ 10.0 $node_(4) set Z_ 0.0 $node_(5) set X_ 945.0 $node_(5) set Y_ 10.0 $node_(5) set Z_ 0.0 #movement of mobile node $ns at 10.0 "$node_(0) setdest 990.0 20.0 5.0" $ns at 220.0 "$node_(0) setdest 990.0 300.0 5.0" #Set TCP connection between node_(0) and node_(1) settcp [new Agent/TCP/Newreno] $tcp set class_ 2 #$tcp set window_ 2000 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 $ns at 5.0 "$ftp start" #This takes the TCP window size and makes it plotable procplotWindow {tcpSource file} { global ns set time 0.01 set now [$ns now] setcwnd [$tcpSource set cwnd_] puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.1 "plotWindow $tcp $windowVsTime2" #Define node initial position in nam
20 | P a g e
for {set i 0} {$i < $val(nn)} { incr i } { #define the node size for nam $ns initial_node_pos $node_($i) 15 } #simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; } #ending nam + simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at $val(stop) "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefdnamtrace $ns flush-trace close $tracefd close $namtrace execnamHOP_simw.nam& execxgraph HOP_win.tr & exit 0 } $ns run
8.3. Scenario 3 (No Background Traffic) # Define options setval(chan) Channel/WirelessChannel setval(prop) Propagation/TwoRayGround setval(netif) Phy/WirelessPhy setval(mac) Mac/802_11 setval(ifq) Queue/DropTail/PriQueue setval(ll) LL setval(ant) Antenna/OmniAntenna setval(ifqlen) 50 ;# max packet in ifq setval(nn) 18 ;# how many nodes are simulated setval(rp) AODV
21 | P a g e
setval(x) 1000 ;# X dimension of topolograph setval(y) 1000 setval(stop) 150 ;# simulation time #setup the trace files set ns [new Simulator] settracefd [open simulation1_tf.tr w] set windowVsTime2 [open simulation1_win.tr w] setnamtrace [open simulation1_simw.nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) #set up topography object settopo [new Topography] $topoload_flatgrid $val(x) $val(y) create-god $val(nn) #configure the 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 ON for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node] $node_($i) set X_ [expr 0.0+1] $node_($i) set Y_ [expr 0.0+1] $node_($i) set Z_ [expr 0.0+1] } #create an offset grid of wireless nodes for {set i 0} {$i < [expr $val(nn)-2] } {incr i} {
22 | P a g e
$node_($i) set Z_ 0.0 $node_($i) set Y_ [expr ($i/4)*210 + 5] # odd row aka first if { ((($i/4)+1)%2) == 1} { $node_($i) set X_ [expr ($i%4)*240 + 5] } elseif {((($i/4)+1)%2) == 0 } { $node_($i) set X_ [expr ($i%4)*240+5+120] } else { $node_($i) set X_ [expr $i*10] } } #the two mobile nodes $node_([expr $val(nn)-2]) set X_ 425.0 $node_([expr $val(nn)-2]) set Y_ 320.0 $node_([expr $val(nn)-2]) set Z_ 0.0 $node_([expr $val(nn)-1]) set X_ 425.0 $node_([expr $val(nn)-1]) set Y_ 320.0 $node_([expr $val(nn)-1]) set Z_ 0.0 #movements $ns at 5.0 "$node_([expr $val(nn)-1]) setdest 5.0 5.0 5.0" $ns at 5.0 "$node_([expr $val(nn)-2]) setdest 845.0 635.0 5.0" #at about 115 seconds, reach destination # Set a TCP connection between node_(2nd to last) and node_(last) settcp [new Agent/TCP/Newreno] $tcp set class_ 2 #$tcp set window_ 2000 set sink [new Agent/TCPSink] $ns attach-agent $node_([expr $val(nn)-1]) $tcp $ns attach-agent $node_([expr $val(nn)-2]) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp $ns at 4.0 "$ftp start" #250 units of range # Printing the window size procplotWindow {tcpSource file} { global ns
23 | P a g e
set time 0.01 set now [$ns now] setcwnd [$tcpSource set cwnd_] puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.1 "plotWindow $tcp $windowVsTime2" for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } # Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; } # ending nam and the simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at $val(stop) "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefdnamtrace $ns flush-trace close $tracefd close $namtrace execnam simulation1_simw.nam & execxgraph simulation1_win.tr & exit 0 } $ns run
8.4. Scenario 3 (Background Traffic) # Define options setval(chan) Channel/WirelessChannel setval(prop) Propagation/TwoRayGround setval(netif) Phy/WirelessPhy setval(mac) Mac/802_11 setval(ifq) Queue/DropTail/PriQueue
24 | P a g e
setval(ll) LL setval(ant) Antenna/OmniAntenna setval(ifqlen) 50 ;# max packet in ifq setval(nn) 18 ;# how many nodes are simulated setval(rp) AODV setval(x) 1000 ;# X dimension of topolograph setval(y) 1000 setval(stop) 150 ;# simulation time #create trace files set ns [new Simulator] settracefd [open simulationN_tf.tr w] set windowVsTime2 [open simulationN_win.tr w] setnamtrace [open simulationN_simw.nam w] $ns trace-all $tracefd $ns namtrace-all-wireless $namtrace $val(x) $val(y) #set up topography object settopo [new Topography] $topoload_flatgrid $val(x) $val(y) create-god $val(nn) #configure the 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 ON #make nodes and then set them to position 1 for {set i 0} {$i < $val(nn) } { incr i } { set node_($i) [$ns node]
25 | P a g e
$node_($i) set X_ [expr 0.0+1] $node_($i) set Y_ [expr 0.0+1] $node_($i) set Z_ [expr 0.0+1] } #create an offset grid of wireless nodes for {set i 0} {$i < [expr $val(nn)-2] } {incr i} { $node_($i) set Z_ 0.0 $node_($i) set Y_ [expr ($i/4)*210 + 5] # odd row aka first if { ((($i/4)+1)%2) == 1} { $node_($i) set X_ [expr ($i%4)*240 + 5] } elseif {((($i/4)+1)%2) == 0 } { $node_($i) set X_ [expr ($i%4)*240+5+120] } else { $node_($i) set X_ [expr $i*10] } } #set the locations of the mobile nodes $node_([expr $val(nn)-2]) set X_ 425.0 $node_([expr $val(nn)-2]) set Y_ 320.0 $node_([expr $val(nn)-2]) set Z_ 0.0 $node_([expr $val(nn)-1]) set X_ 425.0 $node_([expr $val(nn)-1]) set Y_ 320.0 $node_([expr $val(nn)-1]) set Z_ 0.0 # Generation of movements $ns at 5.0 "$node_([expr $val(nn)-1]) setdest 5.0 5.0 5.0" $ns at 5.0 "$node_([expr $val(nn)-2]) setdest 845.0 635.0 5.0" # Set a TCP connection between node_(2nd to last) and node_(last) settcp [new Agent/TCP/Newreno] $tcp set class_ 2 set sink [new Agent/TCPSink] $ns attach-agent $node_([expr $val(nn)-1]) $tcp $ns attach-agent $node_([expr $val(nn)-2]) $sink $ns connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp
26 | P a g e
$ns at 4.0 "$ftp start" #250 units of range set udp0 [new Agent/UDP] $ns attach-agent $node_(1) $udp0 set null0 [new Agent/Null] $ns attach-agent $node_(13) $null0 $ns connect $udp0 $null0 $udp0 set fid_ 2 #Setup a CBR over UDP connection set cbr0 [new Application/Traffic/CBR] $cbr0 attach-agent $udp0 $cbr0 set type_ CBR $cbr0 set packet_size_ 1000 $cbr0 set rate_ 100kb $cbr0 set random_ false set udp1 [new Agent/UDP] $ns attach-agent $node_(3) $udp1 set null1 [new Agent/Null] $ns attach-agent $node_(14) $null1 $ns connect $udp1 $null1 $udp1 set fid_ 3 #Setup a CBR over UDP connection set cbr1 [new Application/Traffic/CBR] $cbr1 attach-agent $udp1 $cbr1 set type_ CBR $cbr1 set packet_size_ 1000 $cbr1 set rate_ 100kb $cbr1 set random_ false #Schedule events for the CBR and FTP agents $ns at 3 "$cbr0 start" $ns at 150 "$cbr0 stop" $ns at 3 "$cbr1 start" $ns at 150 "$cbr1 stop" # Printing the window size procplotWindow {tcpSource file} {
27 | P a g e
global ns set time 0.01 set now [$ns now] setcwnd [$tcpSource set cwnd_] puts $file "$now $cwnd" $ns at [expr $now+$time] "plotWindow $tcpSource $file" } $ns at 10.1 "plotWindow $tcp $windowVsTime2" for {set i 0} {$i < $val(nn)} { incr i } { # 30 defines the node size for nam $ns initial_node_pos $node_($i) 30 } #Telling nodes when the simulation ends for {set i 0} {$i < $val(nn) } { incr i } { $ns at $val(stop) "$node_($i) reset"; } #ending nam+ simulation $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "stop" $ns at $val(stop) "puts \"end simulation\" ; $ns halt" proc stop {} { global ns tracefdnamtrace $ns flush-trace close $tracefd close $namtrace execnamsimulationN_simw.nam& execxgraph simulationN_win.tr & } $ns run