ensc 427: communication networks spring 2013 final …
TRANSCRIPT
1
ENSC 427: COMMUNICATION NETWORKS SPRING 2013
FINAL PROJECT
Delay Tolerant Network Protocol - Analysis
http://www.sfu.ca/~cha55/
Team 1:
George Chang 301115373 [email protected]
Clark Hsieh 301092627 [email protected]
Nelson Meira 301090094 [email protected]
ABSTRACT Networks in deep space are subject to high delay and exhibits high rates of disruption. In order for a reliable system to be established, appropriate protocols must be chosen. DTN - delay-tolerant networks or disruption-tolerant networks - operate on a hop-to-hop, store-and-forward basis using bundling protocols, which take custody of bundles at each node. To examine their effectiveness in application, this project implements two topologies, with a TCP version and a DTN version for each. The TCP implementations are used as a baseline for comparison. The improvement in transmission speeds of networks utilizing DTN bundles over TCP was evident in the gathered results. Furthermore, in demonstrating the inadequacy of TCP in scenarios where the connection would drop, the effectiveness of DTN bundling was affirmed.
2
Table of Contents 1. INTRODUCTION ...................................................................................................................... 4
1.1. Special Thanks ................................................................................................................... 4
2. OVERVIEW .............................................................................................................................. 4
2.2. Team Organization ............................................................................................................. 6
3. IMPLEMENTATION ................................................................................................................. 7
3.1. SPICE’s DTN Agent ........................................................................................................... 7
3.2. Topology - Wired Nodes .................................................................................................... 7
3.3. Topology - Mars Station ..................................................................................................... 9
3.4. Topology - Mars Rover ..................................................................................................... 10
3.5. Shell Scripts ..................................................................................................................... 10
4. RESULTS AND DISCUSSION ............................................................................................... 11
4.1. Results - Wired Nodes ..................................................................................................... 11
4.2. Results - Mars Station and Mars Rover ........................................................................... 13
4.3. Improvements and Future Work ....................................................................................... 14
5. CONCLUSION ........................................................................................................................ 14
6. REFERENCES ....................................................................................................................... 15
APPENDIX .................................................................................................................................. 17
CODE - Wired Nodes TCP - retrans_wired_TCP.tcl ............................................................... 17
CODE - Wired Nodes DTN - retrans_wired_DTN.tcl .............................................................. 19
CODE - Mars Rover TCP - George-roverTCP.tcl ................................................................... 22
CODE - Mars Rover DTN - George-roverDTN.tcl ................................................................... 27
CODE - Earth to Mars DTN - dtnTestWireless2wireless2Land.tcl ........................................ 33
CODE - AWK Trace Analysis .................................................................................................. 38
3
Table of Figures and Tables Figure 1 NASA: Space Network ................................................................................................... 5 Figure 2 DTN OSI implementation model ..................................................................................... 6 Figure 3 retrans_wired model topology ........................................................................................ 8 Figure 4 Original Topology with basestation ................................................................................. 9 Figure 5 Wireless Rover Topology ............................................................................................. 10 Figure 6 Transmission time and the cumilative transmited data ................................................. 13 Table 1 - Node location for BaseStation Topology ....................................................................... 9 Table 2 0% Error - Transmission time (s) ................................................................................... 11 Table 3 5% Error - Transmission time (s) ................................................................................... 11
4
1. INTRODUCTION The Space Frontier has been a goal of mankind since the space race, as the USA and the Soviet Union competed to put the first man out and on to the Moon. Around the same time period, the Internet was spreading its roots; fast-forwarding to the present day, we have come to recognize its value in allowing us to easily connect and share information across the globe. In our project, we wanted to combine the communication technologies and the history of decades of space exploration in search of a similar communication protocol that would support the challenges of deep space communication. The following report thus focuses on the implementation of DTN, or Delay and Disruption Tolerant Network protocol. The goal of DTN is to allow our current telecommunication network design to overcome the challenges in space where long distances, long variable delays and disruptions are present that renders our TCP/IP ineffective. To measure its effectiveness, we evaluated the performance of DTN compared to TCP in a topology intended to model interplanetary establishments. These analyses were completed with NS-2, with the addition of the DTN agent class developed by the SPICE (Space Internetworking Center) group, which has opened their developed models to the public. Our investigation focused on the transfer of packets across wired and wireless nodes, looking at the statuses (e.g. “received”, “dropped”, “retransmit”, etc). We observed clear improvements in a network with delays and/or disruption when utilizing DTN instead of purely TCP, where these improvements correlated with the size of the transferred file. Furthermore, in certain scenarios, TCP failed altogether in being unable to re-establish a dropped connection. From these results, the essentiality of the reliability of the implemented DTN protocol to Deep Space networks becomes evident. Perhaps a testament to its potential, various organizations continues their research [2] to fully optimize and standardize DTN.
1.1. Special Thanks We would like to express our gratitude towards Dimitris Vardalis (dvardali(at)ee.duth.gr) for his work on the development of the NS-2 DTN Agent, which was partially funded by the Space Internetworking Center (SPICE).
2. OVERVIEW The Delay Tolerant Network (DTN), or Disruption Tolerant Network, is an experimental implementation of a separate control protocol on top of the network layer. The motivation behind this design is to extend the idea of Internet beyond our stratosphere. The problems at these interstellar distances are propagation delay, link connectivity, and error rates. Our team is very interested to push the boundary of the modern day Internet and observe the effects of internetworking in deep space. We want to observe implementations and experiments performed by space network engineers and get a feel of how the future of Internet in space would be like.
5
Figure 1: NASA: Space Network
Besides research of DTN in space applications, there is also much research conducted in various other fields; monitoring the deep sea, large forest environments, large geographic locations for seismic data, and animal tracking [10] could all benefit from this research as they share the common properties of the high delay or disruption in their networks. DTN has been implemented over TCP in some experimental environments. The most popular and tested method of DTN is the store and forward method, where information or the packets are bundled and sent forth downstream in the network without the requirement of a known and defined path at the time of transmission. The motivation behind this implementation comes from the fact that end-to-end delays can be in the order of minutes, so a round trip time for a three-way handshake would take too long and potentially cause the TCP connection or application to time out. DTN attempts to circumvent this problem: nodes have localized storage of bundles, or “chunks” of data, and take custody of each one received. This way, nodes at each hop are responsible for the transmission of bundles to the next hop. This method of custody inheritance all the way downstream for data transmission alleviates the requirement of a constant link and effectively reduces total retransmission time as it only happens from node to node, instead of end to end.
6
Figure 2: DTN OSI implementation model
Some further implementations to improve DTN would be the opportunistic contact, and scheduled contact method. The realization of these methods can improve power utilization and connectivity as these nodes will only transmit or look for peer nodes during programmed times. These times could be based on the daily known orbit or location of a satellite or rover on mars and can significantly cut power consumption by avoiding long haul transmission and utilize a shorter range relaying instead.
2.2. Team Organization The team organization was based around trust and mutual cooperation. The team members were already well acquainted prior to the start of the semester, which simplified communication and encouraged open discussion. Each of us had our own laptops with NS-2 capability, thus enabling independent exploration with the custom modified DTN agents, provided by the SPICE research organization. We did not have an appointed leader, but instead shared the initiative of determining what to work on and made decisions collectively, increasing the speed of our project progression. We used email extensively ensuring to cc all our team members in all related exchanges to keep everyone informed. To communicate changes and encourage source control, we implemented an SVN (subversion) server, which logged and stored all our code versions. This service kept track of changes and also allowed us to individually take the main code body and create experimental branches without worrying about losing original working code. This method of code development and collaborative work enabled us to quickly explore our options and share our results with each other. Subversion client is readily installed in the Ubuntu distributions and is easily accessible via the command line. High level of communication, efficiency and teamwork was key in the collaboration of our team in this project.
7
3. IMPLEMENTATION To preface the subsequent sections, it should be mentioned that further details about our implementations could be found in our references and appendices containing all our NS-2 tcl scripts as well as other code.
3.1. SPICE’s DTN Agent As mentioned earlier, we utilized the DTN Agent class model developed by SPICE in the creation of our topologies. Their implementation of the DtnAgent (following the NS-2 Agent class conventions) has been made open source [8], and in following their brief instructions, we were able to re-build NS-2.35 after making the appropriate modifications to the .h, .cc, and .tcl. Regarding the usage of the class, excerpts of .tcl script are displayed below..
# create a new DTN agent and attach it to a node set dtn0 [new Agent/DTN] $ns_ attach-‐dtnagent $n(0) $dtn0 # connect DTN agents $ns_ connect-‐dtn $dtn0 $dtn1
The DTN agents have several modifiable parameters. The size of the bundles, as well as the size of the fragments the bundles are divided into can be set. The timeout period can also be adjusted:
# Set bundle sizes, fragment sizes, and timeout period. $dtn0 set nMaxBundleSize_ $bundle_size $dtn0 set nTCPPacketSize_ $packet_size $dtn0 set fTimeout_ $time_out
In wireless topologies, base station nodes which have a DTN agent attached must explicitly have a parameter set in order for them to employ RV, rendezvous. The setting for RV is a specialized setting for DTN as it allows for dynamic scheduling of retransmission, of which we enabled and used default values.
# turn on RV -‐ rendezvous -‐ Sets the transmission scheduling $dtnBS0 set nIsBSNode_ 1
3.2. Topology - Wired Nodes Our linearly connected four-node topology was designed with the intention of creating a simple case with clear parameters from which conclusive quantitative results could be extracted. The topology below allowed for the observation of the effects of link delay and disruption, separately or together, on TCP and DTN connections. The former was modelled via the delay parameter of link connections, while the latter with the error model attached to the final link (i.e. the one
8
connected to the sink node). Restating a statement from the introduction, we know DTN will not require end to end retransmission and will only retransmit from the nearest upstream node. Thus, we hypothesized the superiority of DTN over TCP due to its flexibility to link disruption and its requirements for retransmission, setting transmission speed as the focus.
Figure 3: retrans_wired model topology
In both TCP and DTN versions of the NS-2 topology, the four nodes were created and connected with duplex links. In the TCP topology, the transport layer TCP and TCPSink agents were attached to the source and sink nodes, respectively. On the other hand, in the DTN topology the DTN agents were attached to all four nodes. This is sensible considering the store-and-forward nature of the protocol. An FTP application was attached to the agent at the source, with the file size as a variable. The simulation end time was set to allow for the FTP transfer to complete before terminating NS-2. Due to the simple nature of the topology, we opted for the recording of all information to the trace files. The .tcl scripts also generated nam files, but for our goal of analyzing data quantitatively rather than qualitatively, they are of less importance. To generate errors in our links we used the NS-2’s built-in ErrorModel utilizing a random number generator to decide which packet it will corrupt, at the set rate. We chose a uniform distribution for its simplicity, as our goal does not rely on the type of corruption designated. Sample code is displayed below:
set loss_random_variable [new Randomvariable/Uniform] $loss_random_variable set min_ 0 $loss_random_variable set max_100 set loss_module [new ErrorModel] $loss_module drop-‐target [new Agent/Null] $loss_module set rate_ 50 $loss_module ranvar $loss_random_variable
Several sets of data were collected with different combinations of parameters. The results are presented and discussed later in section 4. Results and Discussion of the report.
9
3.3. Topology - Mars Station Our second topology was actually the one we began with at the initial stages of the project, with an interplanetary model in mind. We wanted to simulate communication between Earth and Mars through a simple, straight path. This topology models a source station connected to several relays (routers) directed to a satellite base station on Earth that would transmit the signal wirelessly into space. A DTN-capable geocentric orbiting satellite would then receive the signal. This satellite would likewise forward the transmissions to a Mars orbiting DTN-node satellite as its target. In reverse, the Mars satellite would then transmit down towards a base station on the planet’s surface. Our topology follows our original intention to simulate an actual scenario where there is only one connection end to end through an established path. In summary, this would be representative of a Mars exploration remote station communicating to Earth for instructions and support. Within our NS-2 .tcl script, we placed the nodes as detailed in the table below: Table 1 - Node location for Base Station Topology
BS(1) w(1) w(0) BS(0) l(1) L(0)
X_ 100 300 500 700 650 700
Y_ 300 400 400 300 200 200
Our initial topology is displayed below. At this stage of our implementation, base stations resided at both ends of the topology, representing an, “Earth,” base and a, “Mars,” base station.
Figure 4: Original Topology with Base Station
10
Data starts from the source node and travels through a wired segment to reach BS0. BS0 transmits wirelessly to w0; data is forwarded to w1 and again to reach BS1. Finally BS1 would forward the message to the Mars based base-station.
3.4. Topology - Mars Rover The Mars Rover topology is a modified version of the previous Mars Station topology we made to circumvent a few issues we faced where the base station in the receiving side was unable to forward packets to the LAN node. This topology tries to model the Earth’s to Mars connection path with a moving node. We wanted to test the transfer speed and efficiency of the protocol with the main focus on link disruptions when the nodes move out of range. This shape allows the wireless satellite w1 to be in connection range of both w0 and the rover. The Mars orbiter moves out of range of both its neighbours, then horizontally to the only in range of the downstream node, the rover. This setup allow us to see the store and forward mechanism of DTN and also to simulate an interruption in the connection between DTN and TCP to see observe their how each would handle the situation. This topology demonstrated the capabilities of DTN networks as the nodes do not require retransmission from the source, but instead directly from the node upstream, thus avoiding heavy transmission disruptions and delay time from further upstream.
Figure 5: Wireless Rover Topology
3.5. Shell Scripts In order analyze the trace files created by our simulations, shell (bash) scripts were written which utilized awk commands to filter the trace files into separate text files. In the case of the Wired Nodes topology, the rows corresponding to dropped and received packets at the sink node were collected into separate output files. A third output file contained, again, the received packets at the sink node, but only the time and packet size columns. These data sets would be plotted to compare the transmission speeds in the subsequent section of the report. As before, please refer to the Appendix for the full code.
11
4. RESULTS AND DISCUSSION Having implemented the above topologies, we present the collected data and derived conclusions.
4.1. Results - Wired Nodes From this section we can clearly see that DTN implementation does not require retransmission and reconnection from the original client node many hops upstream. From this observation we can assume the power saving capabilities of wireless nodes as it is required to send less data when there are frequent link interruptions downstream, many wireless hops down. If this scenario is located on nodes where there are predictable intermittency, like in the case of orbital satellite going around Mars going dark. The collected data is displayed in the table below, from where drastic performance degradations of TCP and the improvements of using DTN bundling can be seen. Table 2 0% Error - Transmission time (s)
0% error rate 100 kB 1 MB
Delay 5ms TCP 10.123 11.145
DTN 10.087 16.494
Delay 100ms TCP 16.615 32.235
DTN 13.315 26.939
Delay 10s TCP 991.010 2950.034
DTN 400.004 1060.013
Table 3 5% Error - Transmission time (s)
5% error rate 100 kB 1 MB
Delay 100ms TCP 34.113 182.814
DTN 16.5107 68.657
Delay 10s TCP 2239.022 23479.227
DTN 679.009 5809.544
The data shown proves that retransmission from drop of a 5% error rate will degrade the performance of a pure TCP transfer significantly. From the above-established baseline, we can
12
see that without the error, TCP performs similarly to DTN, which was expected as this experimental DTN implementation is extended on top of TCP. The discrepancy in our result, the zero error, 5 ms delay, and 100 Mb transfer showed the performance of DTN being faster than TCP. Since we were expecting TCP to beat out DTN at all low delay transfers, due to the DTN overhead, but instead the results surprised us. We hypothesise that when sending such a small file the first node hop acknowledges the first bundle of packet and allows further bundles to be sent before the first bundle even reaches the end destination. With this small hop delay, the source is able to send almost all the data before the destination even gets the first packet. This hypothesis also include the effect of the slow start protocol built in TCP where the window size increase as each acknowledgement is received. The slow start protocol will increase the number of packet bursts exponentially until it drop packet, or congestion notification back from the destination, then drops the speed it sends. With this in mind, we can conclude that during large file transfers, the larger bursts of packets is able to achieve faster overall transfer speeds as it shoots more and more packets through each hops towards the destination without the intermediary nodes storing and forwarding. As a final comparison, the plot below of the TCP versus the DTN bundling networks demonstrates the superior transfer speed of DTN. In this case, the error rate was set to 5% and the links were set to have 100ms delays. In total, 100 kB of data was to be transferred via FTP. We noted that the DTN topology received a few extra packets compared to the TCP version, but were unable to explain with absolute certainty the reason for it. We suspect the cause to involve the randomly dropped packets and retransmission. Other scenarios are simply slightly different variations of the available graph below, and were not posted because we were mainly focused on the completion time stated in the table above.
13
Figure 6 Transmission time and the cumilative transmited data
4.2. Results - Mars Station and Mars Rover After we ran the simulations for TCP and DTN we discerned from in our terminal that with a 5 mb transfer size, TCP failed to transmit once the satellite connectivity moves out of the transfer range. DTN however does finish transfer. For the purpose of monitoring we simulate both TCP and DTN for a total of 3000 seconds to see the effects after they finish transmitting. We observed that for TCP, it doesn’t even reach completion. The DTN, even though finished transmitting, we observed that there are still packets being transferred and dropped. This is hypothesised that it is due to duplicate packet retransmitted/requested made by wireless nodes. The DTN protocol demonstrated the send and forget type of transmission, where the sender only needs to know that the immediate downstream node received the complete data, then transfer the responsibility of further downstream delivery to it or so called custody transfer. In reality we believe the FTP session connected over TCP will eventually complete if restarted or resumed by the human user after an end-to-end link and connection was re established. The session of course will fail again as soon as the lengthy link interruption is introduced.
14
4.3. Improvements and Future Work While our models successfully investigate DTNs in general, they lack the depth to truly simulate deep space scenarios with time and space variables in the astronomical - literally - scales. Wireless transmission methods and technologies, routing protocols and standards, mathematical calculations on satellite and planetary orbits, and much more would need attention in order to implement a model that would simulate their physical counterparts. Apart from this, on utilizing and improving our current topologies, we have also thought about other scenarios that would be interesting to investigate as future works. One such scenario describes a common situation that is unique in space and to DTN where flying debris or asteroids may potentially pose a threat to unmanned satellites. We are interested in how DTN would cope with the stored custody and bundles when a satellite is destroyed, and to how DTN would react when a catastrophic incident occurs to the network. Lastly, we would also be interested in observing the behaviour of other applications like VoIP or video streaming running on top of DTN. The grand scale of Deep Space DTN is a very interesting topic and we would like to continue our research into its future.
5. CONCLUSION Through the entire exploratory nature of this project, we were able to utilize and implement agent models created by Dimitris Vardalis to observe the effect of delay and disruption in a space type scenario on communication networks. Utilizing NS-2 to create scenarios to model real-life situations we were able to obtain data and evaluate the performance of the DTN protocol, particularly in comparing with TCP-only counterparts. From our tests and simulations, we were able to observe the store-and-forward performance characteristics of the protocol and affirm its effectiveness in a high delay and high disruption networks: FTP transfers could be completed significantly faster with bundling. Including the cases where TCP would completely fail after dropping a connection, we concluded that DTN is indeed necessary in Deep Space environments where high delay and disruption are inherent properties of the network.
15
6. REFERENCES [1] L. Wood, "Delay Tolerant Networking Research Group," 09 04 2010. [Online]. Available: http://www.dtnrg.org/wiki/About . [Accessed 17 02 2013]. [2] K. Gifford, "NASA - Disruption Tolerant Networking for Space Operations," NASA, 12 05 2012. [Online]. Available: http://www.nasa.gov/mission_pages/station/research/experiments/DTN.html . [Accessed 16 02 2013]. [3] M. Demmer, DTN Reference Implementation, San Diego: DTNRG Conference Meeting, 2004. [4] K. Fall and S. Farrell, "DTN: an architectural retrospective," IEEE Journal, vol. 26, no. 5, pp. 828-836, 2008. [5] J. Jackson, "IEEE Spectrum - The Interplanetary Internet," August 2005. [Online]. Available: http://spectrum.ieee.org/telecom/internet/the-interplanetary-internet/3 . [Accessed 16 02 2013]. [6] T. Issaraiyakul and E. Hossain. (2009). Introduction to Network Simulator NS2: Post processing NS2 Result using NS2 Trace [Online]. Available: http://www.ns2ultimate.com/post/3702976577/post-processing-ns2-result-using-ns2-trace-ex2 [7] Z. WU. (2010, Oct 08). Network Simulator 2 for Wireless: Analyze ns-2 trace file [Online]. Available: http://zbinwu.blogspot.ca/2010/10/analyze-ns-2-trace-file.html [8] Space Internetworking Center, “DTN-Agent”. [Online]. Available: http://www.spice-center.org/dtn-agent. [Accessed Feb. 25, 2013] [9] S. Farrell et al., "When TCP Breaks: Delay- and Disruption- Tolerant Networking," Internet Computing, IEEE , vol.10, no.4, pp.72,78, July-Aug. 2006 doi: 10.1109/MIC.2006.91 URL:http://ieeexplore.ieee.org.proxy.lib.sfu.ca/stamp/stamp.jsp?tp=&arnumber=1704758&isnumber=35969 [10] S. Farrell and V. Cahill, Delay and Disruption-Tolerant Networking. Macatucits: Artech House Inc, 2006, pp. 171-181. [11] Giorgos Papastergiou, Ioannis Psaras, Vassilis Tsaoussidis, Deep-Space Transport Protocol: A novel transport scheme for Space DTNs, Computer Communications, Volume 32, Issue 16, 15 October 2009, Pages 1757-1767, ISSN 0140-3664, 10.1016/j.comcom.2009.02.012.
16
URL:http://www.sciencedirect.com/science/article/pii/S0140366409000565 [Access Mar. 20, 2013] [12] F. Warthman. (2003, Mar). delay-Tolerant Networks (DTNs): A Tutorial v1.1 [Online]. Available: http://www.dtnrg.org/docs/tutorials/warthman-1.1.pdf [13] Dr. K. Scott. (2009, May,11). Delay /Disruption Tolerant Networking [Online]. Available: http://usenix.org/events/lisa09/tech/slides/scott.pdf [14] Space Academy, “Communication Delay”. [Online]. Available:http://www.spaceacademy.net.au/spacelink/commdly.htm. [Accessed Mar. 20, 2013 [15] B.Saha . (2011, Jul, 04). Delay Tolerant Networks A novice's blog on Delay Tolerant Networks: The ONE Tutorial[Online]. Available: http://delay-tolerant-networks.blogspot.ca/p/one-tutorial.html [16] Wu Xiuchao (2009, Jul 06). Simulate 802.11b Channel within NS2. Available: http://cir.nus.edu.sg/reactivetcp/report/80211ChannelinNS2_new.pdf
PICTURES REFERENCE [17] Kerry K. Lawson ( 2009, July, 04). Disruption Tolerant Networking (DTN) available: https://www.spacecomm.nasa.gov/spacecomm/programs/technology/dtn/
17
APPENDIX
CODE - Wired Nodes TCP - retrans_wired_TCP.tcl set ns_ [new Simulator] $ns_ color 1 Red $ns_ color 2 Blue $ns_ color 3 Green # settings/variables set opt(tr) ./retrans_data/wiredDTN.tr set opt(namtr) ./retrans_data/wiredDTN.nam set opt(n2-‐n3_tr) ./retrans_data/wiredDTN-‐n2n3.tr set opt(x) 550 set opt(y) 550 set opt(sim_time) 300 set opt(ftp_start) 10 #NUMBER WE TWEEK set transferSize 100000 ;#100 kB set tcpPacketSize 1000 set opt(errorRate) 0.05 #dtn tweek set maxBundleSize 30000 ;# default 30000 set storageSpace 50000 ;# default 50000 set retransmissionTimeout 2.0 ;# default , 0 disables retransmission Agent/TCP set window_ 100 puts "Please ensure ./retrans_data directory exists." #openfile set tracefd [open $opt(tr) w] set namtracefd [open $opt(namtr) w] set n2n3tracefd [open $opt(n2-‐n3_tr) w] $ns_ trace-‐all $tracefd $ns_ namtrace-‐all $namtracefd Trace set show_dtnhdr_ 1 ;# for dtn traces show header #trace-‐queue needs link to exist first #$ns_ trace-‐queue $n(2) $n(3) $n2n3tracefd #TOPOLOGY set topo [new Topography] $topo load_flatgrid $opt(x) $opt(y) #Define a 'finish' procedure proc finish {} { global ns_ tracefd namtracefd n2n3tracefd $ns_ flush-‐trace #Close the trace file close $tracefd close $namtracefd close $n2n3tracefd #Execute nam on the trace file #exec nam namtracefd.nam &
18
exit 0 } #create the nodes set n(0) [$ns_ node] set n(1) [$ns_ node] set n(2) [$ns_ node] set n(3) [$ns_ node] #hard code location $n(0) set Y_ 400.0 $n(0) set Z_ 0.0 $n(1) set Y_ 400.0 $n(2) set Y_ 400.0 $n(3) set Y_ 400.0 $n(0) label "FTP-‐Source" $n(1) label "Relay" $n(2) label "Relay" $n(3) label "FTP-‐Sink" #creating duplex links( connecting nodes) $ns_ duplex-‐link $n(0) $n(1) 5MB 100ms SFQ $ns_ duplex-‐link $n(1) $n(2) 5MB 100ms SFQ $ns_ duplex-‐link $n(2) $n(3) 5MB 100ms SFQ #add queue $ns_ duplex-‐link-‐op $n(0) $n(1) queuePos 0.5 $ns_ duplex-‐link-‐op $n(1) $n(2) queuePos 0.5 $ns_ duplex-‐link-‐op $n(2) $n(3) queuePos 0.5 #orientation of the nodes $ns_ duplex-‐link-‐op $n(0) $n(1) orient left $ns_ duplex-‐link-‐op $n(1) $n(2) orient left $ns_ duplex-‐link-‐op $n(2) $n(3) orient left #trace-‐queue $ns_ trace-‐queue $n(2) $n(3) $n2n3tracefd #set error model set em [new ErrorModel] $em set rate_ $opt(errorRate) $em unit pkt $em ranvar [new RandomVariable/Uniform] $em drop-‐target [new Agent/Null] $ns_ link-‐lossmodel $em $n(2) $n(3) #create the DTN agents set dtn0 [new Agent/DTN] $ns_ attach-‐dtnagent $n(0) $dtn0 set dtn1 [new Agent/DTN] $ns_ attach-‐dtnagent $n(1) $dtn1 set dtn2 [new Agent/DTN] $ns_ attach-‐dtnagent $n(2) $dtn2 set dtn3 [new Agent/DTN] $ns_ attach-‐dtnagent $n(3) $dtn3 # connect the DTN agents $ns_ connect-‐dtn $dtn0 $dtn1 $ns_ connect-‐dtn $dtn1 $dtn2
19
$ns_ connect-‐dtn $dtn2 $dtn3 # tweak parameter of dtn $dtn0 set nTCPPacketSize_ $tcpPacketSize $dtn1 set nTCPPacketSize_ $tcpPacketSize $dtn2 set nTCPPacketSize_ $tcpPacketSize $dtn3 set nTCPPacketSize_ $tcpPacketSize $dtn0 set nMaxBundleSize_ $maxBundleSize $dtn1 set nMaxBundleSize_ $maxBundleSize $dtn2 set nMaxBundleSize_ $maxBundleSize $dtn3 set nMaxBundleSize_ $maxBundleSize $dtn0 set fTimeout_ $retransmissionTimeout $dtn1 set fTimeout_ $retransmissionTimeout $dtn2 set fTimeout_ $retransmissionTimeout $dtn3 set fTimeout_ $retransmissionTimeout #custom application to show transmit time when FTP0 finishes Application instproc recv {nBytes} { global ns_ puts " " puts "Application received $nBytes bytes at [$ns_ now]." puts "ftp0 stop at [$ns_ now]" puts " " puts " " puts " " } # attach custom applicaiton set app1 [new Application] $app1 attach-‐agent $dtn3 $app1 start # attach ftp application set ftp [new Application/FTP] $ftp attach-‐agent $dtn0 # times $ns_ at $opt(ftp_start) "$ftp send $transferSize" $ns_ at $opt(ftp_start) "puts \"Transfer of FTP at of size $transferSize started at $opt(ftp_start) sec\"" $ns_ at $opt(sim_time).001 "puts \"Simulation stopped after $opt(sim_time) seconds.\"" $ns_ at $opt(sim_time).002 "finish" # process to write to tracefd proc WriteToTrace {contents} { global tracefd puts $tracefd $contents } # runs NS############################################## $ns_ run
CODE - Wired Nodes DTN - retrans_wired_DTN.tcl set ns_ [new Simulator] $ns_ color 1 Red
20
$ns_ color 2 Blue $ns_ color 3 Green # settings/variables set opt(tr) ./retrans_data/wiredDTN.tr set opt(namtr) ./retrans_data/wiredDTN.nam set opt(n2-‐n3_tr) ./retrans_data/wiredDTN-‐n2n3.tr set opt(x) 550 set opt(y) 550 set opt(sim_time) 300 set opt(ftp_start) 10 #NUMBER WE TWEEK set transferSize 100000 ;#100 kB set tcpPacketSize 1000 set opt(errorRate) 0.05 #dtn tweek set maxBundleSize 30000 ;# default 30000 set storageSpace 50000 ;# default 50000 set retransmissionTimeout 2.0 ;# default , 0 disables retransmission Agent/TCP set window_ 100 puts "Please ensure ./retrans_data directory exists." #openfile set tracefd [open $opt(tr) w] set namtracefd [open $opt(namtr) w] set n2n3tracefd [open $opt(n2-‐n3_tr) w] $ns_ trace-‐all $tracefd $ns_ namtrace-‐all $namtracefd Trace set show_dtnhdr_ 1 ;# for dtn traces show header #trace-‐queue needs link to exist first #$ns_ trace-‐queue $n(2) $n(3) $n2n3tracefd #TOPOLOGY set topo [new Topography] $topo load_flatgrid $opt(x) $opt(y) #Define a 'finish' procedure proc finish {} { global ns_ tracefd namtracefd n2n3tracefd $ns_ flush-‐trace #Close the trace file close $tracefd close $namtracefd close $n2n3tracefd #Execute nam on the trace file #exec nam namtracefd.nam & exit 0 } #create the nodes set n(0) [$ns_ node] set n(1) [$ns_ node] set n(2) [$ns_ node] set n(3) [$ns_ node]
21
#hard code location $n(0) set Y_ 400.0 $n(0) set Z_ 0.0 $n(1) set Y_ 400.0 $n(2) set Y_ 400.0 $n(3) set Y_ 400.0 $n(0) label "FTP-‐Source" $n(1) label "Relay" $n(2) label "Relay" $n(3) label "FTP-‐Sink" #creating duplex links( connecting nodes) $ns_ duplex-‐link $n(0) $n(1) 5MB 100ms SFQ $ns_ duplex-‐link $n(1) $n(2) 5MB 100ms SFQ $ns_ duplex-‐link $n(2) $n(3) 5MB 100ms SFQ #add queue $ns_ duplex-‐link-‐op $n(0) $n(1) queuePos 0.5 $ns_ duplex-‐link-‐op $n(1) $n(2) queuePos 0.5 $ns_ duplex-‐link-‐op $n(2) $n(3) queuePos 0.5 #orientation of the nodes $ns_ duplex-‐link-‐op $n(0) $n(1) orient left $ns_ duplex-‐link-‐op $n(1) $n(2) orient left $ns_ duplex-‐link-‐op $n(2) $n(3) orient left #trace-‐queue $ns_ trace-‐queue $n(2) $n(3) $n2n3tracefd #set error model set em [new ErrorModel] $em set rate_ $opt(errorRate) $em unit pkt $em ranvar [new RandomVariable/Uniform] $em drop-‐target [new Agent/Null] $ns_ link-‐lossmodel $em $n(2) $n(3) #create the DTN agents set dtn0 [new Agent/DTN] $ns_ attach-‐dtnagent $n(0) $dtn0 set dtn1 [new Agent/DTN] $ns_ attach-‐dtnagent $n(1) $dtn1 set dtn2 [new Agent/DTN] $ns_ attach-‐dtnagent $n(2) $dtn2 set dtn3 [new Agent/DTN] $ns_ attach-‐dtnagent $n(3) $dtn3 # coonnect the DTN agents $ns_ connect-‐dtn $dtn0 $dtn1 $ns_ connect-‐dtn $dtn1 $dtn2 $ns_ connect-‐dtn $dtn2 $dtn3 #tweek parameter of dtn $dtn0 set nTCPPacketSize_ $tcpPacketSize $dtn1 set nTCPPacketSize_ $tcpPacketSize $dtn2 set nTCPPacketSize_ $tcpPacketSize $dtn3 set nTCPPacketSize_ $tcpPacketSize #-‐-‐
22
$dtn0 set nMaxBundleSize_ $maxBundleSize $dtn1 set nMaxBundleSize_ $maxBundleSize $dtn2 set nMaxBundleSize_ $maxBundleSize $dtn3 set nMaxBundleSize_ $maxBundleSize #-‐-‐ $dtn0 set fTimeout_ $retransmissionTimeout $dtn1 set fTimeout_ $retransmissionTimeout $dtn2 set fTimeout_ $retransmissionTimeout $dtn3 set fTimeout_ $retransmissionTimeout #custom application to show transmit time when FTP0 finishes Application instproc recv {nBytes} { global ns_ puts " " puts "Application received $nBytes bytes at [$ns_ now]." puts "ftp0 stop at [$ns_ now]" puts " " puts " " puts " " } # attach custom applicaiton set app1 [new Application] $app1 attach-‐agent $dtn3 $app1 start # attach ftp application set ftp [new Application/FTP] $ftp attach-‐agent $dtn0 # times $ns_ at $opt(ftp_start) "$ftp send $transferSize" $ns_ at $opt(ftp_start) "puts \"Transfer of FTP at of size $transferSize started at $opt(ftp_start) sec\"" $ns_ at $opt(sim_time).001 "puts \"Simulation stopped after $opt(sim_time) seconds.\"" $ns_ at $opt(sim_time).002 "finish" # process to write to tracefd proc WriteToTrace {contents} { global tracefd puts $tracefd $contents } # runs NS############################################## $ns_ run
CODE - Mars Rover TCP - George-roverTCP.tcl #global opt set opt(chan) Channel/WirelessChannel ;# channel type set opt(prop) Propagation/TwoRayGround ;# radio-‐propagation model set opt(netif) Phy/WirelessPhy ;# network interface type set opt(mac) Mac/802_11 ;# MAC type set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type set opt(ll) LL ;# link layer type set opt(ant) Antenna/OmniAntenna ;# antenna model set opt(ifqLen) 50 ;# max packet in ifq
23
set opt(adhocRouting) DSDV ;# routing protocol set opt(cp) "" ;# cp file not used set opt(sc) "" ;# node movement file. #size of simulation plane set opt(x) 800 set opt(y) 800 ## max packet in ifq set opt(ifqlen) 50 set opt(tr) George-‐roverTCP.tr set opt(namtr) George-‐roverTCP.nam set opt(trace1) George-‐rover-‐packetTCP.tr #values TIME for ftp, cbr, start/end set opt(stop) 3000 set opt(mainFTP-‐start) 30 ##num of wireless nodes exclude BS set opt(nn) 3 ;# number of mobilenodes set num_wired_nodes 2 set num_bs_nodes 1 set transferSize 5242880;# 1 MB Mac/802_11 set dataRate_ 11Mb Mac/802_11 set basicRate_ 1Mb Agent/TCP set window_ 1000 #======================================================== # MAIN PROGRAM #======================================================== set ns_ [new Simulator] $ns_ color 1 Red $ns_ color 2 Blue $ns_ color 3 Green # set up for hierarchical routing $ns_ node-‐config -‐addressType hierarchical 3 8 8 8 set domain_num 2 lappend cluster_num 2 1 lappend eilastlevel 1 1 4 AddrParams set domain_num_ $domain_num AddrParams set cluster_num_ $cluster_num AddrParams set nodes_num_ $eilastlevel #openfile set tracefd [open $opt(tr) w] set namtracefd [open $opt(namtr) w] $ns_ trace-‐all $tracefd $ns_ namtrace-‐all $namtracefd #TOPOLOGY set topo [new Topography] $topo load_flatgrid $opt(x) $opt(y)
24
#god needs to know number of all wireless interfaces create-‐god [expr $opt(nn) + $num_bs_nodes] #create wire nodes set l(0) [ $ns_ node 0.0.0 ] ; # on earth set l(1) [ $ns_ node 0.1.0 ] ; # on earth $l(0) set X_ 700.0 $l(0) set Y_ 200.0 $l(0) set Z_ 0.0 $l(1) set X_ 650.0 $l(1) set Y_ 200.0 $l(1) set Z_ 0.0 $l(0) shape box $l(1) shape box $l(0) label "Source TCP" $l(1) label "Relay TCP" #configure the node $ns_ node-‐config -‐adhocRouting $opt(adhocRouting) \ -‐llType $opt(ll) \ -‐macType $opt(mac) \ -‐ifqType $opt(ifq) \ -‐ifqLen $opt(ifqlen) \ -‐antType $opt(ant) \ -‐propInstance [new $opt(prop)] \ -‐phyType $opt(netif) \ -‐channel [new $opt(chan)] \ -‐topoInstance $topo \ -‐wiredRouting ON \ -‐agentTrace ON \ -‐routerTrace ON \ -‐macTrace ON \ -‐phyTrace ON \ -‐movementTrace ON \ -‐eotTrace ON \ -‐toraDebug ON #create BASE stations set BS(0) [$ns_ node 1.0.0] $BS(0) random-‐motion 0 # Provide fixed coordinates for the base station node $BS(0) set X_ 700.0 $BS(0) set Y_ 300.0 $BS(0) set Z_ 0.0 $BS(0) label "Base Station TCP" $BS(0) shape hexagon #configure for mobilenodes $ns_ node-‐config -‐wiredRouting OFF \ -‐energyModel EnergyModel \ -‐idlePower 0.805 \ -‐rxPower 0.950 \ -‐txPower 1.400 \ -‐sleepPower 0.060 \
25
-‐transitionPower 0.0 \ -‐transitionTime 0.0 \ -‐initialEnergy 100 #create mobile nodes set w(0) [ $ns_ node 1.0.1 ] set w(1) [ $ns_ node 1.0.2 ] set w(2) [ $ns_ node 1.0.3 ] $w(0) base-‐station [AddrParams addr2id [$BS(0) node-‐addr]] $w(1) base-‐station [AddrParams addr2id [$w(0) node-‐addr]] $w(2) base-‐station [AddrParams addr2id [$w(1) node-‐addr]] $w(0) set X_ 500.0 $w(0) set Y_ 400.0 $w(0) set Z_ 0.0 $w(0) label "Wireless-‐Relay" $w(1) set X_ 300.0 $w(1) set Y_ 400.0 $w(1) set Z_ 0.0 $w(1) label "Wireless-‐Relay" $w(2) set X_ 100.0 $w(2) set Y_ 300.0 $w(2) set Z_ 0.0 $w(2) label "Mars Rover" $w(2) shape hexagon $ns_ initial_node_pos $w(0) 20 $ns_ initial_node_pos $w(1) 20 $ns_ initial_node_pos $w(2) 20 #create duplex links for wired nodes and basestaitons $ns_ duplex-‐link $l(0) $l(1) 5MB 50ms SFQ $ns_ duplex-‐link $l(1) $BS(0) 5MB 50ms SFQ $ns_ duplex-‐link-‐op $l(0) $l(1) queuePos 0.5 $ns_ duplex-‐link-‐op $l(1) $BS(0) queuePos 0.5 #Attaching and creating Agents ****** BUNDLE AND DTN SETTINGS #Agent/DTN set debug_ true set tcpSource0 [new Agent/TCP] ; # attach to l(0) $tcpSource0 set class_ 2 set tcpSink0 [new Agent/TCPSink] ;# attach to l(2) set tcp0 [new Agent/TCP] ; # attach to l(1) set tcpBS0 [new Agent/TCP] ; # attach to BS(0) set tcp1 [new Agent/TCP] ;# attach to w(0) set tcp2 [new Agent/TCP] ; # to attach to w(1) set tcpBS1 [new Agent/TCP] ; # to attach to BS(1) $ns_ attach-‐agent $l(0) $tcpSource0 $ns_ attach-‐agent $w(2) $tcpSink0 $ns_ connect $tcpSource0 $tcpSink0 # attaching applicaiton FTP set ftp0 [new Application/FTP] $ftp0 attach-‐agent $tcpSource0
26
#custom application to show transmit time when FTP0 finishes Application instproc recv {nBytes} { global ns_ puts " " puts "Application received $nBytes bytes at [$ns_ now]." puts " " puts " " } set app1 [new Application] $app1 attach-‐agent $tcpSink0 $app1 start #Define a 'recv' function for the class 'Agent/Ping' Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from \ $from with round-‐trip-‐time $rtt ms." } #Create two ping agents and attach them to the nodes n0 and n2 set p0 [new Agent/Ping] $ns_ attach-‐agent $BS(0) $p0 set p1 [new Agent/Ping] $ns_ attach-‐agent $w(1) $p1 #Connect the two agents $ns_ connect $p0 $p1 ############################################################# ################ CODE for time step coding ################## ############################################################# #Necessary for route discovery so that no time is lost at first transfer $ns_ at 0.01 "$p0 send" $ns_ at 1.5 "$p0 send" #starts the ftp #$ns_ at $opt(mainCBR-‐start) "puts \"Transfer of FTP at of size $transferSize started at $opt(mainFTP-‐start) sec\"" $ns_ at $opt(mainFTP-‐start) "$ftp0 send $transferSize" ;# Send $transferSize #$ns_ at $opt(mainFTP-‐start) "$ftp0 start" $ns_ at 30.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 40.0000000001 "$w(1) setdest 100.0000000001 100.0000000001 30.0000000001" $ns_ at 50.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 60.0000000001 "$w(1) setdest 300.0000000001 500.0000000001 30.0000000001" $ns_ at 70.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 80.0000000001 "$w(1) setdest 100.0000000001 100.0000000001 30.0000000001" $ns_ at 90.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 100.0000000001 "$w(1) setdest 300.0000000001 500.0000000001 30.0000000001" $ns_ at 110.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 120.0000000001 "$w(1) setdest 100.0000000001 100.0000000001 30.0000000001" $ns_ at 130.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 140.0000000001 "$w(1) setdest 300.0000000001 400.0000000001 30.0000000001" $ns_ at $opt(stop).0001 "finish"
27
############################################################# # finish procedure proc finish {} { global ns_ tracefd namtracefd w BS;#opt BS w l #Tell all nodes when the simulation ends puts "$w(0) reset"; puts "$w(1) reset"; puts "$BS(0) reset"; close $tracefd close $namtracefd exec nam George-‐roverTCP.nam & puts "starting NAM file $opt(namtr)"; puts "NS EXITING..."; puts "$ns_ halt" ; exit 0 } # process to write to tracefd proc WriteToTrace {contents} { global tracefd puts $tracefd $contents } # proc UniformErr {} { # set err [new ErrorModel] # $err unit packet # $err set rate_ 0.01 # return $err # } # runs NS############################################## $ns_ run
CODE - Mars Rover DTN - George-roverDTN.tcl ## -‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐DTN NETWORK-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐-‐ global opt #channel type set opt(chan) Channel/WirelessChannel #radio prop set opt(prop) Propagation/TwoRayGround ## network interface set opt(netif) Phy/WirelessPhy # mac type set opt(mac) Mac/802_11 # interfacequeue type set opt(ifq) CMUPriQueue ## link layer type set opt(ll) LL set opt(ant) Antenna/OmniAntenna #size of simulation plane set opt(x) 800 set opt(y) 800 ## max packet in ifq
28
set opt(ifqlen) 50 set opt(tr) George-‐roverDTN.tr set opt(namtr) George-‐roverDTN.nam set opt(trace1) George-‐roverDTN-‐packet.tr set opt(cp) "" #scenario file set opt(sc) "" #values TIME for ftp, cbr, start/end set opt(stop) 30000 set opt(mainFTP-‐start) 30 ##num of wireless nodes exclude BS set opt(nn) 3 set opt(adhocRouting) DSDV #NUMBER WE TWEEK set transferSize 5242880 ;# 10 MB set tcpPacketSize 1000 ;# default 1500 set maxBundleSize 30000 ;# default 30000 set storageSpace 1000000 ;# default 50000 set retransmissionTimeout 2.0 ;# default , 0 disables retransmission set num_wired_nodes 2 set num_bs_nodes 1 Mac/802_11 set dataRate_ 11Mb Mac/802_11 set basicRate_ 1Mb Agent/TCP set window_ 100 #======================================================== # MAIN PROGRAM #======================================================== set ns_ [new Simulator] $ns_ color 1 Red $ns_ color 2 Blue $ns_ color 3 Green # set up for hierarchical routing $ns_ node-‐config -‐addressType hierarchical 3 8 8 8 set domain_num 2 lappend cluster_num 2 1 lappend eilastlevel 1 1 4 AddrParams set domain_num_ $domain_num AddrParams set cluster_num_ $cluster_num AddrParams set nodes_num_ $eilastlevel #openfile and traces $ns_ use-‐newtrace;# use the new trafe format set tracefd [open $opt(tr) w] set namtracefd [open $opt(namtr) w] Trace set show_dtnhdr_ 1 $ns_ trace-‐all $tracefd $ns_ namtrace-‐all $namtracefd #TOPOLOGY set topo [new Topography] $topo load_flatgrid $opt(x) $opt(y) #god needs to know number of all wireless interfaces
29
create-‐god [expr $opt(nn) + $num_bs_nodes] #create wire nodes set l(0) [ $ns_ node 0.0.0 ] ; # on earth set l(1) [ $ns_ node 0.1.0 ] ; # on earth $l(0) set X_ 700.0 $l(0) set Y_ 200.0 $l(0) set Z_ 0.0 $l(1) set X_ 650.0 $l(1) set Y_ 200.0 $l(1) set Z_ 0.0 $l(0) shape box $l(1) shape box $l(0) label "Source DTN" $l(1) label "Relay DTN" #configure the node $ns_ node-‐config -‐adhocRouting $opt(adhocRouting) \ -‐llType $opt(ll) \ -‐macType $opt(mac) \ -‐ifqType $opt(ifq) \ -‐ifqLen $opt(ifqlen) \ -‐antType $opt(ant) \ -‐propInstance [new $opt(prop)] \ -‐phyType $opt(netif) \ -‐channel [new $opt(chan)] \ -‐topoInstance $topo \ -‐wiredRouting ON \ -‐agentTrace ON \ -‐routerTrace ON \ -‐macTrace ON \ -‐phyTrace ON \ -‐movementTrace ON \ -‐eotTrace ON \ -‐toraDebug ON #create BASE stations set BS(0) [$ns_ node 1.0.0] $BS(0) random-‐motion 0 # Provide fixed coordinates for the base station node $BS(0) set X_ 700.0 $BS(0) set Y_ 300.0 $BS(0) set Z_ 0.0 $BS(0) label "Base Station DTN" $BS(0) shape hexagon #configure for mobilenodes $ns_ node-‐config -‐wiredRouting OFF \ -‐energyModel EnergyModel \ -‐idlePower 0.805 \ -‐rxPower 0.950 \ -‐txPower 1.400 \ -‐sleepPower 0.060 \ -‐transitionPower 0.0 \ -‐transitionTime 0.0 \ -‐initialEnergy 1000 #create mobile nodes set w(0) [ $ns_ node 1.0.1 ]
30
set w(1) [ $ns_ node 1.0.2 ] set w(2) [ $ns_ node 1.0.3 ] $w(0) base-‐station [AddrParams addr2id [$BS(0) node-‐addr]] $w(1) base-‐station [AddrParams addr2id [$BS(0) node-‐addr]] $w(2) base-‐station [AddrParams addr2id [$BS(0) node-‐addr]] $w(0) set X_ 500.0 $w(0) set Y_ 400.0 $w(0) set Z_ 0.0 $w(0) label "Earth-‐Satellite-‐Relay" $w(1) set X_ 300.0 $w(1) set Y_ 400.0 $w(1) set Z_ 0.0 $w(1) label "Mars-‐Orbital-‐Relay" $w(2) set X_ 100.0 $w(2) set Y_ 300.0 $w(2) set Z_ 0.0 $w(2) label "Mars-‐Rover" $ns_ initial_node_pos $w(0) 20 $ns_ initial_node_pos $w(1) 20 $ns_ initial_node_pos $w(2) 20 $w(0) random-‐motion 0 $w(1) random-‐motion 0 $w(2) random-‐motion 0 #create duplex links for wired nodes and basestaitons $ns_ duplex-‐link $l(0) $l(1) 5MB 50ms SFQ $ns_ duplex-‐link $l(1) $BS(0) 5MB 50ms SFQ #Attaching and creating Agents ****** BUNDLE AND DTN SETTINGS Agent/DTN set debug_ true set dtnSource0 [new Agent/DTN]; # attach to l(0) set dtn0 [new Agent/DTN] ; # attach to l(1) set dtnBS0 [new Agent/DTN] ; # attach to BS(0) set dtn1 [new Agent/DTN] ;# attach to w(0) set dtn2 [new Agent/DTN] ; # to attach to w(1) set dtnSink0 [new Agent/DTN] ; # to attach to w(2) $dtnBS0 set nIsBSNode_ 1 $dtnBS0 set nTCPPacketSize_ $tcpPacketSize $dtnSource0 set nTCPPacketSize_ $tcpPacketSize $dtn0 set nTCPPacketSize_ $tcpPacketSize $dtn1 set nTCPPacketSize_ $tcpPacketSize $dtn2 set nTCPPacketSize_ $tcpPacketSize $dtnSink0 set nTCPPacketSize_ $tcpPacketSize $dtnBS0 set nMaxBundleSize_ $maxBundleSize $dtnSource0 set nMaxBundleSize_ $maxBundleSize $dtn0 set nMaxBundleSize_ $maxBundleSize $dtn1 set nMaxBundleSize_ $maxBundleSize $dtn2 set nMaxBundleSize_ $maxBundleSize $dtnSink0 set nMaxBundleSize_ $maxBundleSize $dtnBS0 set fTimeout_ $retransmissionTimeout $dtnSource0 set fTimeout_ $retransmissionTimeout
31
$dtn0 set fTimeout_ $retransmissionTimeout $dtn1 set fTimeout_ $retransmissionTimeout $dtn2 set fTimeout_ $retransmissionTimeout $dtnSink0 set fTimeout_ $retransmissionTimeout $ns_ attach-‐dtnagent $l(0) $dtnSource0 $ns_ attach-‐dtnagent $l(1) $dtn0 $ns_ attach-‐dtnagent $BS(0) $dtnBS0 $ns_ attach-‐dtnagent $w(0) $dtn1 $ns_ attach-‐dtnagent $w(1) $dtn2 $ns_ attach-‐dtnagent $w(2) $dtnSink0 # Connect the agents $ns_ connect-‐dtn $dtnSource0 $dtn0 $ns_ connect-‐dtn $dtn0 $dtnBS0 $ns_ connect-‐dtn $dtnBS0 $dtn1 $ns_ connect-‐dtn $dtn1 $dtn2 $ns_ connect-‐dtn $dtn2 $dtnSink0 # attaching applicaiton FTP set ftp0 [new Application/FTP] $ftp0 attach-‐agent $dtnSource0 #custom application to show transmit time when FTP0 finishes Application instproc recv {nBytes} { global ns_ puts " " puts "Application received $nBytes bytes at [$ns_ now]." puts "ftp0 stop at [$ns_ now]" puts " " puts " " puts " " } set app1 [new Application] $app1 attach-‐agent $dtnSink0 $app1 start #Define a 'recv' function for the class 'Agent/Ping' Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from $from with round-‐trip-‐time $rtt ms." } #Create two ping agents and attach them to the nodes n0 and n2 set p0 [new Agent/Ping] $ns_ attach-‐agent $BS(0) $p0 set p1 [new Agent/Ping] $ns_ attach-‐agent $w(1) $p1 #Connect the two agents $ns_ connect $p0 $p1 ############################################################# ################ CODE for time step coding ################## ############################################################# #Necessary for route discovery so that no time is lost at first transfer $ns_ at 0.01 "$p0 send"
32
$ns_ at 1.5 "$p0 send" # $ns_ at 60 "$God_ set-‐dist 3 4 0" #starts the ftp $ns_ at $opt(mainFTP-‐start) "puts \"Transfer of FTP at of size $transferSize started at $opt(mainFTP-‐start) sec\"" $ns_ at $opt(mainFTP-‐start) "$ftp0 send $transferSize " # $ns_ at 3 "$w(1) setdest 200 400 50" # $ns_ at 6 "$w(1) setdest 300 400 250" # $ns_ at 6.5 "$w(1) setdest 300 100 90" # $ns_ at 10 "$w(1) setdest 300 400 90" $ns_ at 30.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 40.0000000001 "$w(1) setdest 100.0000000001 100.0000000001 30.0000000001" $ns_ at 50.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 60.0000000001 "$w(1) setdest 300.0000000001 500.0000000001 30.0000000001" $ns_ at 70.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 80.0000000001 "$w(1) setdest 100.0000000001 100.0000000001 30.0000000001" $ns_ at 90.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 100.0000000001 "$w(1) setdest 300.0000000001 500.0000000001 30.0000000001" $ns_ at 110.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 120.0000000001 "$w(1) setdest 100.0000000001 100.0000000001 30.0000000001" $ns_ at 130.0000000001 "$w(1) setdest 300.0000000001 100.0000000001 30.0000000001" $ns_ at 140.0000000001 "$w(1) setdest 300.0000000001 400.0000000001 30.0000000001" $ns_ at $opt(stop).0001 "finish" ############################################################# # finish procedure proc finish {} { global ns_ tracefd namtracefd opt BS w l # Tell all nodes when the simulation ends puts "$w(0) reset"; puts "$w(1) reset"; puts "$BS(0) reset"; close $tracefd close $namtracefd puts "NS EXITING..."; puts "$ns_ halt" ; puts "starting NAM file $opt(namtr)"; exec nam $opt(namtr) & } # process to write to tracefd proc WriteToTrace {contents} { global tracefd puts $tracefd $contents } proc UniformErr {} { set err [new ErrorModel] $err unit packet $err set rate_ 0.01 return $err }
33
# runs NS############################################## $ns_ run
CODE - Earth to Mars DTN - dtnTestWireless2wireless2Land.tcl
# ====================================================================== # Define options # ====================================================================== set val(chan) Channel/WirelessChannel set val(prop) Propagation/TwoRayGround set val(netif) Phy/WirelessPhy set val(mac) Mac/802_11 #set val(ifq) Queue/DropTail/PriQueue set val(ifq) CMUPriQueue set val(ifqlen) 50 ;# max packet in ifq set val(adhocRouting) DSDV set val(ll) LL set val(ant) Antenna/OmniAntenna set val(x) 800 ;# X dimension of the topography set val(y) 800 ;# Y dimension of the topography set val(seed) 0.0 set val(nn) 2 #set val(nn) 1 set val(mainFTP-‐start) 20 set val(mainFTP-‐stop) 10 set val(crossCBR-‐start) 10 set val(crossCBR-‐stop) 1500 set val(stop) 1500 ;# time to stop simulation set val(tr) dtnTestWireless.tr set val(namtr) dtnTestWireless.nam set num_wired_nodes 5 set num_bs_nodes 2 set transferSize 10000000
34
set tcpPacketSize 1460 Mac/802_11 set dataRate_ 11Mb Mac/802_11 set basicRate_ 1Mb Agent/TCP set window_ 100 # ====================================================================== # Main Program # ====================================================================== set ns_ [new Simulator] $ns_ color 1 red $ns_ color 2 Blue # set up for hierarchical routing $ns_ node-‐config -‐addressType hierarchical 3 8 8 8 AddrParams set domain_num_ 2 ;# number of domains lappend cluster_num 5 1 ;# number of clusters in each domain AddrParams set cluster_num_ $cluster_num lappend eilastlevel 1 1 1 1 1 3 AddrParams set nodes_num_ $eilastlevel ;# of each cluster set namtracefd [open $val(namtr) w] $ns_ namtrace-‐all $namtracefd set topo [new Topography] $topo load_flatgrid $val(x) $val(y) # god needs to know the number of all wireless interfaces create-‐god [expr $val(nn) + $num_bs_nodes] # Wired part 4 relaying nodes set temp {0.0.0 0.1.0 0.2.0 0.3.0 0.4.0} for {set i 0} {$i < $num_wired_nodes} {incr i} { set wiredNode($i) [$ns_ node [lindex $temp $i]] $wiredNode($i) label "Relaying DTN" } Trace set show_dtnhdr_ 1 set tracefd [open $val(tr) w] $ns_ trace-‐all $tracefd $ns_ node-‐config -‐adhocRouting $val(adhocRouting) \ -‐llType $val(ll) \ -‐macType $val(mac) \ -‐ifqType $val(ifq) \ -‐ifqLen $val(ifqlen) \ -‐antType $val(ant) \ -‐propInstance [new $val(prop)] \ -‐phyType $val(netif) \ -‐channel [new $val(chan)] \ -‐topoInstance $topo \ -‐wiredRouting ON \ -‐agentTrace ON \ -‐routerTrace ON \
35
-‐macTrace ON \ -‐phyTrace ON \ -‐movementTrace ON \ -‐eotTrace ON \ -‐toraDebug ON # -‐OutgoingErrProc UniformErr \ proc UniformErr {} { set err [new ErrorModel] $err unit packet $err set rate_ 0.3 return $err } # Create base station node set baseStationNode(0) [$ns_ node 1.0.0] $baseStationNode(0) random-‐motion 0 set baseStationNode(1) [$ns_ node 1.0.3] $baseStationNode(1) random-‐motion 0 # Provide fixed coordinates for the base station Earth node $baseStationNode(0) set X_ 250.0 $baseStationNode(0) set Y_ 150.0 $baseStationNode(0) set Z_ 0.0 $baseStationNode(0) label "Earth BS DTN " $baseStationNode(0) shape hexagon # Provide fixed coordinates for the base station Mars node $baseStationNode(1) set X_ 452 $baseStationNode(1) set Y_ 150 $baseStationNode(1) set Z_ 0.0 $baseStationNode(1) label "Mars BS DTN" $baseStationNode(1) shape hexagon # Earth connections $ns_ duplex-‐link $wiredNode(0) $wiredNode(1) 3Mb 100ms SFQ $ns_ duplex-‐link $wiredNode(0) $wiredNode(2) 3Mb 100ms SFQ $ns_ duplex-‐link $wiredNode(0) $wiredNode(3) 3Mb 100ms SFQ $ns_ duplex-‐link $wiredNode(1) $baseStationNode(0) 3Mb 100ms SFQ $ns_ duplex-‐link $wiredNode(2) $baseStationNode(0) 3Mb 100ms SFQ $ns_ duplex-‐link $wiredNode(3) $baseStationNode(0) 3Mb 100ms SFQ # Mars Connections $ns_ duplex-‐link $baseStationNode(1) $wiredNode(4) 3Mb 100ms SFQ #orientation $ns_ duplex-‐link-‐op $wiredNode(0) $wiredNode(1) orient left-‐up $ns_ duplex-‐link-‐op $wiredNode(0) $wiredNode(2) orient left $ns_ duplex-‐link-‐op $wiredNode(0) $wiredNode(3) orient left-‐down $ns_ duplex-‐link-‐op $wiredNode(1) $baseStationNode(0) orient left-‐down $ns_ duplex-‐link-‐op $wiredNode(2) $baseStationNode(0) orient left $ns_ duplex-‐link-‐op $wiredNode(3) $baseStationNode(0) orient left-‐up set tracefd [open $val(tr) w] $ns_ trace-‐all $tracefd
36
#configure for mobilenodes $ns_ node-‐config -‐wiredRouting OFF \ -‐energyModel EnergyModel \ -‐idlePower 0.805 \ -‐rxPower 0.950 \ -‐txPower 1.400 \ -‐sleepPower 0.060 \ -‐transitionPower 0.0 \ -‐transitionTime 0.0 \ -‐initialEnergy 1000 $ns_ node-‐config -‐agentTrace ON # Earth to Earth Satellite set wirelessNode(0) [ $ns_ node 1.0.1 ] $wirelessNode(0) base-‐station [AddrParams addr2id [$baseStationNode(0) node-‐addr]] $wirelessNode(0) set X_ 150 $wirelessNode(0) set Y_ 150 #$wirelessNode(0) set Z_ 0.0 $wirelessNode(0) shape hexagon $wirelessNode(0) label "Wireless DTN Target" # Earth Satellite to Mars Satellite set wirelessNode(1) [ $ns_ node 1.0.2 ] $wirelessNode(1) base-‐station [AddrParams addr2id [$wirelessNode(0) node-‐addr]] $wirelessNode(1) set X_ 250 $wirelessNode(1) set Y_ 150 #$wirelessNode(1) set Z_ 0.0 $wirelessNode(1) shape square $wirelessNode(1) label "Wireless DTN Target1" $ns_ initial_node_pos $wirelessNode(0) 10 $ns_ initial_node_pos $wirelessNode(1) 10 # creating all the DTN agents Agent/DTN set debug_ true set dtnSource [new Agent/DTN] $dtnSource set debug_ true $ns_ attach-‐dtnagent $wiredNode(0) $dtnSource set ftp0 [new Application/FTP] $ftp0 attach-‐agent $dtnSource set dtn1 [new Agent/DTN] $dtn1 set debug_ true $ns_ attach-‐dtnagent $wiredNode(1) $dtn1 set dtn2 [new Agent/DTN] $dtn2 set debug_ true $ns_ attach-‐dtnagent $wiredNode(2) $dtn2 set dtn3 [new Agent/DTN] $dtn3 set debug_ true $ns_ attach-‐dtnagent $wiredNode(3) $dtn3
37
set dtnBS [new Agent/DTN] $dtnBS set debug_ true #setting the basestation node to RV mode $dtnBS set nIsBSNode_ 1 $ns_ attach-‐dtnagent $baseStationNode(0) $dtnBS set dtnBS1 [new Agent/DTN] $dtnBS1 set debug_ true $ns_ attach-‐dtnagent $baseStationNode(1) $dtnBS1 #attaching set dtnWireless [new Agent/DTN] $ns_ attach-‐dtnagent $wirelessNode(0) $dtnWireless set dtnWireless1 [new Agent/DTN] $ns_ attach-‐dtnagent $wirelessNode(1) $dtnWireless1 set dtnSink [new Agent/DTN] $ns_ attach-‐dtnagent $wiredNode(4) $dtnSink #defined connection. $ns_ connect-‐dtn $dtnSource $dtn1 $ns_ connect-‐dtn $dtnSource $dtn2 $ns_ connect-‐dtn $dtnSource $dtn3 $ns_ connect-‐dtn $dtn1 $dtnBS $ns_ connect-‐dtn $dtn2 $dtnBS $ns_ connect-‐dtn $dtn3 $dtnBS $ns_ connect-‐dtn $dtnSource $dtnBS $ns_ connect-‐dtn $dtnBS $dtnWireless $ns_ connect-‐dtn $dtnWireless $dtnWireless1 $ns_ connect-‐dtn $dtnWireless1 $dtnBS1 $ns_ connect-‐dtn $dtnBS1 $dtnSink #Define a 'recv' function for the class 'Agent/Ping' Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from $from with round-‐trip-‐time $rtt ms." } Application instproc recv {nBytes} { global ns_ puts "Application received $nBytes bytes at [$ns_ now]." } set app1 [new Application] $app1 attach-‐agent $dtnSink $app1 start #Define a 'recv' function for the class 'Agent/Ping' Agent/Ping instproc recv {from rtt} { $self instvar node_
38
puts "node [$node_ id] received ping answer from \ $from with round-‐trip-‐time $rtt ms." } #Create two ping agents and attach them to the nodes n0 and n2 set p0 [new Agent/Ping] $ns_ attach-‐agent $baseStationNode(0) $p0 set p1 [new Agent/Ping] $ns_ attach-‐agent $wirelessNode(1) $p1 #Connect the two agents $ns_ connect $p0 $p1 #Necessary for route discovery so that no time is lost at first transfer $ns_ at 0 "$p0 send" $ns_ at 1.5 "$p0 send" $ns_ at $val(mainFTP-‐start) "puts \"Transfer of $transferSize started at $val(mainFTP-‐start) sec\"" $ns_ at $val(mainFTP-‐start) "$ftp0 send $transferSize" ;# Send 10MB proc WriteToTrace {contents} { global tracefd puts $tracefd $contents } $ns_ at $val(stop) "finish" proc finish {} { global ns_ tracefd namtracefd val wirelessNode baseStationNode # Tell all nodes when the simulation ends $ns_ at $val(stop) "$wirelessNode(0) reset"; $ns_ at $val(stop) "$baseStationNode(0) reset"; close $tracefd close $namtracefd exec nam $val(namtr) & puts "NS EXITING..." exit 0 } $ns_ run
CODE - AWK Trace Analysis #!/bin/bash #usage: extractData_andGraph.sh inputFilename1 inputFilename2 #extracts received and dropped pkts from each input tracefile and #graphs time vs. cumulative pkt size of both inputs onto the same xgraph #input parameters inTCP=$1 inDTN=$2 r="r-‐" d="d-‐"
39
xy="xy-‐" # concatenated strings rTCP=$r$inTCP dTCP=$d$inTCP xyTCP=$xy$inTCP rDTN=$r$inDTN dDTN=$d$inDTN xyDTN=$xy$inDTN awk -‐v inTCP=$1 '{if ($1=="r" && $4=="3" && $6=="1040") {print}}' $inTCP > $rTCP; awk -‐v inTCP=$1 '{if ($1=="d" && $4=="3") {print}}' $inTCP > $dTCP; awk -‐v inTCP=$1 '{sum+=$6;print $2,sum}' $inTCP > $xyTCP; echo "TCP -‐ Received data written to $rTCP" echo "TCP -‐ Dropped packets written to $dTCP" echo "TCP -‐ Xgraph-‐ready data written to $xyTCP" awk -‐v inDTN=$2 '{if ($1=="r" && $4=="3" && $6=="1040") {print}}' $inDTN > $rDTN; awk -‐v inDTN=$2 '{if ($1=="d" && $4=="3") {print}}' $inDTN > $dDTN; awk -‐v inDTN=$2 '{sum+=$6;print $2,sum}' $inDTN > $xyDTN; echo "DTN -‐ Received data written to $rDTN" echo "DTN -‐ Dropped packets written to $dDTN" echo "DTN -‐ Xgraph-‐ready data written to $xyDTN" xgraph $xyTCP $xyDTN -‐fg gray -‐bg black -‐t "TCP/DTN Time vs Transferred Data" -‐x "Time (s)" -‐y "Total Transferred Data (kB)"