Difference between revisions of "Ns-3-Network-Simulator/C2/Network-performance-Analysis/English"
(Created page with " {| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''' '''Welcome''' || Welcome to the spoken tutorial on '''Analyzing network performance in ns-3.''...") |
|||
Line 12: | Line 12: | ||
'''Welcome''' | '''Welcome''' | ||
|| Welcome to the spoken tutorial on '''Analyzing network performance in ns-3.''' | || Welcome to the spoken tutorial on '''Analyzing network performance in ns-3.''' | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Learning Outcomes''' | '''Learning Outcomes''' | ||
|| In this tutorial, we will learn to | || In this tutorial, we will learn to | ||
− | * | + | * Use trace sources |
− | * | + | * Create callback functions |
− | * | + | * Connect trace sources to callback functions and |
− | * | + | * Calculate network parameters using trace sources |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''System Requirements''' | '''System Requirements''' | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | * | + | * '''Ubuntu''' '''Linux Operating system version''' '''22.04''' |
− | * | + | * '''ns-3.38''' |
− | * | + | * '''NetAnim '''visualizer tool |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 38: | Line 38: | ||
[https://spoken-tutorial.org/ https://spoken-tutorial.org] | [https://spoken-tutorial.org/ https://spoken-tutorial.org] | ||
|| To follow this tutorial, | || To follow this tutorial, | ||
− | * | + | * You must have basic knowledge of using Linux terminal |
− | * | + | * You must know how to create a '''point-to-point '''network in '''ns-3''' |
− | * | + | * For pre-requisite Linux and '''ns-3''' tutorials, please visit this website |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Code files''' | '''Code files''' | ||
|| | || | ||
− | * | + | * The files used in this tutorial are provided in the '''Code files''' link |
− | * | + | * Please download and extract the files |
− | * | + | * Make a copy and then use them while practising |
− | |- | + | |- |
|| Show diagram''':''' | || Show diagram''':''' | ||
'''Point-to-Point network with two nodes''' | '''Point-to-Point network with two nodes''' | ||
|| For this tutorial, we would be creating the following topology: | || For this tutorial, we would be creating the following topology: | ||
− | * | + | * A '''point-to-point''' network with address 10.1.1.0 |
− | |- | + | |- |
|| Open the file '''network_performance.cc '''in the text editor. | || Open the file '''network_performance.cc '''in the text editor. | ||
|| I have created the source file '''network_performance.cc''' for this program. | || I have created the source file '''network_performance.cc''' for this program. | ||
Line 66: | Line 66: | ||
The source code contains the required functions to analyse network performance. | The source code contains the required functions to analyse network performance. | ||
− | |- | + | |- |
|| Highlight '''double node0_trans_time''' | || Highlight '''double node0_trans_time''' | ||
|| First we declare the variables. | || First we declare the variables. | ||
Line 73: | Line 73: | ||
'''node0_trans_time''' holds the transmission time for node 0. | '''node0_trans_time''' holds the transmission time for node 0. | ||
− | |- | + | |- |
|| Highlight '''node1_rec_time''' | || Highlight '''node1_rec_time''' | ||
|| '''node1_rec_time '''holds the packet receiving time for node 1. | || '''node1_rec_time '''holds the packet receiving time for node 1. | ||
− | |- | + | |- |
|| Highlight '''node0_rec_time''' | || Highlight '''node0_rec_time''' | ||
|| '''Node0_rec_time '''is the time at which node 0 receives the echo packet from node 1. | || '''Node0_rec_time '''is the time at which node 0 receives the echo packet from node 1. | ||
− | |- | + | |- |
|| Highlight '''round_trip_time <nowiki>= 0.0</nowiki>''' | || Highlight '''round_trip_time <nowiki>= 0.0</nowiki>''' | ||
|| '''round_trip_time '''holds the round-trip packet time. | || '''round_trip_time '''holds the round-trip packet time. | ||
That is, the time taken to go from node 0 to node 1 and return. | That is, the time taken to go from node 0 to node 1 and return. | ||
− | |- | + | |- |
|| Highlight '''total_delay = 0.0''' | || Highlight '''total_delay = 0.0''' | ||
|| '''total_delay '''holds the sum of all delays. | || '''total_delay '''holds the sum of all delays. | ||
− | |- | + | |- |
|| Highlight '''prop_delay = 6560.0''' | || Highlight '''prop_delay = 6560.0''' | ||
|| '''prop_delay '''is the propagation delay of the channel. | || '''prop_delay '''is the propagation delay of the channel. | ||
It is set by us. | It is set by us. | ||
− | |- | + | |- |
|| Highlight '''throughput = 0.0''' | || Highlight '''throughput = 0.0''' | ||
|| '''throughput '''holds the throughput of the network. | || '''throughput '''holds the throughput of the network. | ||
It is the rate of packet delivery. | It is the rate of packet delivery. | ||
− | |- | + | |- |
|| Highlight '''trans_delay = 0.0''' | || Highlight '''trans_delay = 0.0''' | ||
|| '''trans_delay '''holds''' '''the transmission delay of a packet. | || '''trans_delay '''holds''' '''the transmission delay of a packet. | ||
− | |- | + | |- |
|| Highlight '''RxTraceClient(std::string context, Ptr<const Packet> p)''' | || Highlight '''RxTraceClient(std::string context, Ptr<const Packet> p)''' | ||
|| '''RxTraceClient '''is a '''callback function'''. | || '''RxTraceClient '''is a '''callback function'''. | ||
Line 113: | Line 113: | ||
The second argument is the packet received. | The second argument is the packet received. | ||
− | |- | + | |- |
|| Highlight '''node0_rec_time = Simulator::Now().GetSeconds()''' | || Highlight '''node0_rec_time = Simulator::Now().GetSeconds()''' | ||
|| In the function, we will update the value of '''node0_rec_time '''variable. | || In the function, we will update the value of '''node0_rec_time '''variable. | ||
Line 120: | Line 120: | ||
The current time is found using the '''GetSeconds '''method. | The current time is found using the '''GetSeconds '''method. | ||
− | |- | + | |- |
|| Highlight''' round_trip_time''' | || Highlight''' round_trip_time''' | ||
|| Similarly, we update the value of the '''round_trip_time '''variable. | || Similarly, we update the value of the '''round_trip_time '''variable. | ||
Line 129: | Line 129: | ||
The '''node0_trans_time '''variable would be updated in the '''TxTraceClient '''function. | The '''node0_trans_time '''variable would be updated in the '''TxTraceClient '''function. | ||
− | |- | + | |- |
|| Highlight '''round_cnt++''' | || Highlight '''round_cnt++''' | ||
Line 135: | Line 135: | ||
We do so, to keep a track of the number of round-trips. | We do so, to keep a track of the number of round-trips. | ||
− | |- | + | |- |
|| Highlight '''TxTraceClient''' | || Highlight '''TxTraceClient''' | ||
|| '''TxTraceClient '''is a callback function. | || '''TxTraceClient '''is a callback function. | ||
Line 144: | Line 144: | ||
The second argument is the receive packet. | The second argument is the receive packet. | ||
− | |- | + | |- |
− | || Highlight | + | || Highlight '''node0_trans_time''' |
|| In the function, we set the value of '''node0_trans_time.''' | || In the function, we set the value of '''node0_trans_time.''' | ||
The value is the time at which transmission starts. | The value is the time at which transmission starts. | ||
− | |- | + | |- |
|| Highlight '''RxTraceServer''' | || Highlight '''RxTraceServer''' | ||
|| The last callback function is '''RxTraceServer.''' | || The last callback function is '''RxTraceServer.''' | ||
Line 158: | Line 158: | ||
The second argument is the received packet. | The second argument is the received packet. | ||
− | |- | + | |- |
|| Highlight '''node1_rec_time = Simulator::Now().GetSeconds()''' | || Highlight '''node1_rec_time = Simulator::Now().GetSeconds()''' | ||
|| Here we set the receiving time to the current time in seconds. | || Here we set the receiving time to the current time in seconds. | ||
− | |- | + | |- |
|| Highlight '''total_delay += (node1_rec_time - node0_trans_time)*1000''' | || Highlight '''total_delay += (node1_rec_time - node0_trans_time)*1000''' | ||
|| Then, we set the '''total_delay''' variable, which stores the total delay. | || Then, we set the '''total_delay''' variable, which stores the total delay. | ||
Line 173: | Line 173: | ||
The value is multiplied by 1000 to get the unit in milliseconds. | The value is multiplied by 1000 to get the unit in milliseconds. | ||
− | |- | + | |- |
|| Highlight '''trans_delay += ((node1_rec_time - node0_trans_time)*1000 - prop_delay/1000000)''' | || Highlight '''trans_delay += ((node1_rec_time - node0_trans_time)*1000 - prop_delay/1000000)''' | ||
|| Next, we compute the value of '''transmission delay'''. | || Next, we compute the value of '''transmission delay'''. | ||
Line 182: | Line 182: | ||
This converts it into milliseconds. | This converts it into milliseconds. | ||
− | |- | + | |- |
|| Highlight '''pkt_cnt++''' | || Highlight '''pkt_cnt++''' | ||
|| Next we increment the packet count. | || Next we increment the packet count. | ||
− | |- | + | |- |
|| Highlight '''if (pkt_cnt == pkts)''' | || Highlight '''if (pkt_cnt == pkts)''' | ||
|| Finally we compare the value of packet count to the total packets. | || Finally we compare the value of packet count to the total packets. | ||
Line 192: | Line 192: | ||
If this is the last packet, we print all the parameters. | If this is the last packet, we print all the parameters. | ||
− | |- | + | |- |
|| Highlight '''NS_LOG_UNCOND''' | || Highlight '''NS_LOG_UNCOND''' | ||
|| Using the '''NS_LOG_UNCOND '''function, we print the parameters to the terminal. | || Using the '''NS_LOG_UNCOND '''function, we print the parameters to the terminal. | ||
We print the parameters: | We print the parameters: | ||
− | * | + | * End-to-end delay |
− | * | + | * Transmission delay |
− | * | + | * Throughput |
− | * | + | * Propagation delay (constant) |
− | |- | + | |- |
|| Highlight '''total_delay/(p->GetSize()*pkts''' | || Highlight '''total_delay/(p->GetSize()*pkts''' | ||
|| '''Throughput '''is calculated as total delay divided by total data size. | || '''Throughput '''is calculated as total delay divided by total data size. | ||
− | |- | + | |- |
|| Highlight '''nodes.Create(2)''' | || Highlight '''nodes.Create(2)''' | ||
Line 211: | Line 211: | ||
For the topology, we create a '''point-to-point''' network with two nodes. | For the topology, we create a '''point-to-point''' network with two nodes. | ||
− | |- | + | |- |
|| Highlight '''SetDeviceAttribute''' | || Highlight '''SetDeviceAttribute''' | ||
|| The '''data rate''' for the device is 100 Mbps. | || The '''data rate''' for the device is 100 Mbps. | ||
− | |- | + | |- |
|| Highlight '''SetChannelAttribute''' | || Highlight '''SetChannelAttribute''' | ||
|| The '''propagation delay''' is set to 6560 nanoseconds. | || The '''propagation delay''' is set to 6560 nanoseconds. | ||
− | |- | + | |- |
|| Highlight '''address.SetBase("10.1.1.0", "255.255.255.0")''' | || Highlight '''address.SetBase("10.1.1.0", "255.255.255.0")''' | ||
|| The base address of the network is 10.1.1.0. | || The base address of the network is 10.1.1.0. | ||
− | |- | + | |- |
|| Highlight '''UdpEchoServerHelper echoServer(9)''' | || Highlight '''UdpEchoServerHelper echoServer(9)''' | ||
|| Next we create a UDP echo server with port address 9. | || Next we create a UDP echo server with port address 9. | ||
− | |- | + | |- |
|| Highlight '''echoServer.Install(nodes.Get(1))''' | || Highlight '''echoServer.Install(nodes.Get(1))''' | ||
|| The echo server application is installed on the second node. | || The echo server application is installed on the second node. | ||
The index of the node is 1. | The index of the node is 1. | ||
− | |- | + | |- |
|| Highlight '''serverApps.Start(Seconds(1.0))''' | || Highlight '''serverApps.Start(Seconds(1.0))''' | ||
|| Here we set the start time of the server applications to 1 second. | || Here we set the start time of the server applications to 1 second. | ||
− | |- | + | |- |
|| Highlight '''serverApps.Stop(Seconds(10.0))''' | || Highlight '''serverApps.Stop(Seconds(10.0))''' | ||
|| Similarly, we set the stop time to 10 seconds. | || Similarly, we set the stop time to 10 seconds. | ||
Both the times are from the start of the simulation. | Both the times are from the start of the simulation. | ||
− | |- | + | |- |
|| Highlight '''echoClient(interfaces.GetAddress(1), 9)''' | || Highlight '''echoClient(interfaces.GetAddress(1), 9)''' | ||
|| Then we create an echo client application with destination port 9. | || Then we create an echo client application with destination port 9. | ||
− | |- | + | |- |
|| Highlight '''SetAttribute''' | || Highlight '''SetAttribute''' | ||
|| Using the '''SetAttribute '''method we set the following attributes for the client. | || Using the '''SetAttribute '''method we set the following attributes for the client. | ||
− | |- | + | |- |
|| Highlight '''MaxPackets''' | || Highlight '''MaxPackets''' | ||
|| The maximum number of packets is 10. | || The maximum number of packets is 10. | ||
− | |- | + | |- |
|| Highlight '''Interval''' | || Highlight '''Interval''' | ||
|| The time interval between packet transmissions is 0.5 seconds. | || The time interval between packet transmissions is 0.5 seconds. | ||
− | |- | + | |- |
|| Highlight '''PacketSize''' | || Highlight '''PacketSize''' | ||
|| The packet size is 1024 bytes. | || The packet size is 1024 bytes. | ||
− | |- | + | |- |
|| Highlight '''echoClient.Install(nodes.Get(0))''' | || Highlight '''echoClient.Install(nodes.Get(0))''' | ||
|| The echo client application is installed on the first node. | || The echo client application is installed on the first node. | ||
The index of the node is 0. | The index of the node is 0. | ||
− | |- | + | |- |
|| Highlight '''clientApps.Start(Seconds(2.0))''' | || Highlight '''clientApps.Start(Seconds(2.0))''' | ||
|| The start time of the client apps is set to 2 seconds. | || The start time of the client apps is set to 2 seconds. | ||
− | |- | + | |- |
|| Highlight '''clientApps.Stop(Seconds(10.0))''' | || Highlight '''clientApps.Stop(Seconds(10.0))''' | ||
|| The stop time is 10 seconds. | || The stop time is 10 seconds. | ||
− | |- | + | |- |
|| Highlight '''Config::Connect''' | || Highlight '''Config::Connect''' | ||
Line 277: | Line 277: | ||
These events include packet transmission, change in window size etc. | These events include packet transmission, change in window size etc. | ||
− | |- | + | |- |
|| Highlight '''UdpEchoClient/Tx''' | || Highlight '''UdpEchoClient/Tx''' | ||
Line 285: | Line 285: | ||
It traces the transmission of a packet by an echo client application. | It traces the transmission of a packet by an echo client application. | ||
− | |- | + | |- |
|| Highlight '''UdpEchoClient/Rx''' | || Highlight '''UdpEchoClient/Rx''' | ||
|| The second trace source is '''Rx, '''of the '''UdpEchoClient '''class. | || The second trace source is '''Rx, '''of the '''UdpEchoClient '''class. | ||
It traces the reception of a packet by an echo client application. | It traces the reception of a packet by an echo client application. | ||
− | |- | + | |- |
|| Highlight '''UdpEchoServer/Rx''' | || Highlight '''UdpEchoServer/Rx''' | ||
Line 296: | Line 296: | ||
It traces the reception of a packet by an echo server application. | It traces the reception of a packet by an echo server application. | ||
− | |- | + | |- |
− | || Highlight | + | || Highlight '''AnimationInterface anim ("network_performance.xml");''' |
|| Next we create an '''AnimationInterface '''object, '''anim, '''for '''NetAnim '''animation. | || Next we create an '''AnimationInterface '''object, '''anim, '''for '''NetAnim '''animation. | ||
Line 306: | Line 306: | ||
Here the name of the file is '''network_performance.xml'''. | Here the name of the file is '''network_performance.xml'''. | ||
− | |- | + | |- |
− | || | + | || Highlight '''anim.SetConstantPosition''' |
|| Then set the positions for the nodes using the '''SetConstantPosition '''function. | || Then set the positions for the nodes using the '''SetConstantPosition '''function. | ||
− | |- | + | |- |
|| Highlight '''Simulator::Run()''' | || Highlight '''Simulator::Run()''' | ||
|| The '''Run '''function is used to run the simulation. | || The '''Run '''function is used to run the simulation. | ||
− | |- | + | |- |
|| Highlight '''Simulator::Destroy()''' | || Highlight '''Simulator::Destroy()''' | ||
|| The '''Destroy '''function ends the simulation. | || The '''Destroy '''function ends the simulation. | ||
Close the text editor. | Close the text editor. | ||
− | |- | + | |- |
|| | || | ||
Line 325: | Line 325: | ||
Type '''mv ~/Downloads/network_performance.cc scratch/network_performance.cc '''to move the source file to '''scratch '''directory. | Type '''mv ~/Downloads/network_performance.cc scratch/network_performance.cc '''to move the source file to '''scratch '''directory. | ||
− | || | + | || Now we will observe the simulation. |
− | + | Open a terminal by pressing Ctrl, Alt and T keys simultaneously. | |
− | + | Using the '''cd '''command, navigate to the installation directory of '''ns-3'''. | |
− | + | Go to the '''ns-3.38''' directory. | |
− | + | Move your source file to the '''scratch '''directory within the '''ns-3.38''' directory. | |
− | |- | + | |- |
|| Type ./'''ns3 run scratch/network_performance.cc''' | || Type ./'''ns3 run scratch/network_performance.cc''' | ||
− | || | + | || Run the command '''dot forward slash''' '''ns3 run space scratch forward slash network underscore performance dot cc.''' |
− | + | '''network underscore performance '''is the name of the source file. | |
− | |- | + | |- |
|| Keep the terminal open and show the output of the command | || Keep the terminal open and show the output of the command | ||
|| After compilation, we get the network parameters. The parameters are | || After compilation, we get the network parameters. The parameters are | ||
− | * | + | * '''End-to-end delay''' |
− | * | + | * '''Transmission delay''' |
− | * | + | * '''Throughput '''and |
− | * | + | * '''Round trip time''' |
− | |- | + | |- |
|| Type '''cd ~/ns-allinone-3.38/netanim''' | || Type '''cd ~/ns-allinone-3.38/netanim''' | ||
|| Now, to visualise the network, we will use NetAnim. | || Now, to visualise the network, we will use NetAnim. | ||
Navigate to the '''netanim '''directory under '''ns-allinone-3.38.''' | Navigate to the '''netanim '''directory under '''ns-allinone-3.38.''' | ||
− | |- | + | |- |
|| Type ./'''NetAnim''' | || Type ./'''NetAnim''' | ||
|| Now type '''dot forward slash NetAnim. '''The NetAnim window will open. | || Now type '''dot forward slash NetAnim. '''The NetAnim window will open. | ||
− | |- | + | |- |
|| Click on the '''Open XML trace file '''icon on the top left corner of the window. | || Click on the '''Open XML trace file '''icon on the top left corner of the window. | ||
|| Click on the '''Open XML trace file '''icon on the top left corner of the window. | || Click on the '''Open XML trace file '''icon on the top left corner of the window. | ||
− | |- | + | |- |
|| In the file picker, navigate to the '''ns-allinone-3.38/ns-3.38 '''directory and select the '''network_performance.xml '''file. | || In the file picker, navigate to the '''ns-allinone-3.38/ns-3.38 '''directory and select the '''network_performance.xml '''file. | ||
|| In the file picker, navigate to the '''ns-3.38 '''directory. | || In the file picker, navigate to the '''ns-3.38 '''directory. | ||
Line 367: | Line 367: | ||
You can also download the file from '''Code Files''' section. | You can also download the file from '''Code Files''' section. | ||
− | |- | + | |- |
|| On the toolbar, click on the '''Node Size '''drop down button, and select size 10. | || On the toolbar, click on the '''Node Size '''drop down button, and select size 10. | ||
|| On the toolbar, click on the '''Node Size '''drop down button. | || On the toolbar, click on the '''Node Size '''drop down button. | ||
Select size 10. | Select size 10. | ||
− | |- | + | |- |
|| On the toolbar, click on the play button | || On the toolbar, click on the play button | ||
|| On the toolbar, click on the play button to view the simulation. | || On the toolbar, click on the play button to view the simulation. | ||
Line 379: | Line 379: | ||
The lines with arrows represent the transfer of packets. | The lines with arrows represent the transfer of packets. | ||
− | |- | + | |- |
|| Hover over node 0 and node 1 circles. | || Hover over node 0 and node 1 circles. | ||
|| We see the packets moving from node 0 to node 1. | || We see the packets moving from node 0 to node 1. | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 389: | Line 389: | ||
In this tutorial, we have learnt to | In this tutorial, we have learnt to | ||
− | * | + | * Use trace sources |
− | * | + | * Create callback functions |
− | * | + | * Connect trace sources to callback functions |
− | * | + | * Calculate network parameters using trace sources |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Assignment''' | '''Assignment''' | ||
− | || As an assignment, please do the following:* | + | || As an assignment, please do the following:* Create a '''Point-to-Point '''network with 3 nodes |
− | * | + | * Send packets from node 0 to node 2 |
− | * | + | * Calculate '''throughput '''and''' transmission delay''' |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 411: | Line 411: | ||
These parameters include packet size, propagation delay and data rate. | These parameters include packet size, propagation delay and data rate. | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''About the Spoken Tutorial Project''' | '''About the Spoken Tutorial Project''' | ||
− | || | + | || The video at the following link summarises the '''Spoken Tutorial project'''. |
Please download and watch it. | Please download and watch it. | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
− | + | '''Spoken Tutorial Workshops''' | |
− | || | + | || The '''Spoken Tutorial Project''' team conducts workshops and gives certificates. |
For more details, please write to us. | For more details, please write to us. | ||
|- style="border:0.75pt solid #808080;padding:0.176cm;" | |- style="border:0.75pt solid #808080;padding:0.176cm;" | ||
− | || | + | || Show Slide: |
− | + | '''Answers for THIS Spoken Tutorial''' | |
− | | | + | ||Post your timed queries in this forum. |
− | |- | + | |- |
− | || | + | || Show Slide: |
− | + | '''FOSSEE Forum''' | |
− | || | + | || For any general or technical questions on '''ns-3''', visit the''' FOSSEE forum''' and post your question. |
− | |- | + | |- |
|| Show slide | || Show slide | ||
'''Acknowledgement''' | '''Acknowledgement''' | ||
− | || | + | || '''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''. |
− | |- | + | |- |
|| Show slide | || Show slide | ||
'''Acknowledgement''' | '''Acknowledgement''' | ||
− | || | + | || We thank '''Dr.Moyukh Laha''' from '''IIT Kharagpur''' for his domain support. |
− | + | We would also like to thank '''Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi '''from''' VIT, Chennai '''for their support. | |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Thank You''' | '''Thank You''' | ||
− | || | + | || This is''' Josiga, '''a FOSSEE summer fellow 2023, IIT Bombay signing off. |
Revision as of 13:17, 31 January 2024
Visual Cue | Narration |
Slide:1
Welcome |
Welcome to the spoken tutorial on Analyzing network performance in ns-3. |
Show slide:
Learning Outcomes |
In this tutorial, we will learn to
|
Show slide:
System Requirements |
To record this tutorial, I am using
|
Show slide:
Prerequisite |
To follow this tutorial,
|
Show slide:
Code files |
|
Show diagram:
Point-to-Point network with two nodes |
For this tutorial, we would be creating the following topology:
|
Open the file network_performance.cc in the text editor. | I have created the source file network_performance.cc for this program.
Now we will go through the source code in the text editor. The source code contains the required functions to analyse network performance. |
Highlight double node0_trans_time | First we declare the variables.
These variables shall hold the network parameters. node0_trans_time holds the transmission time for node 0. |
Highlight node1_rec_time | node1_rec_time holds the packet receiving time for node 1. |
Highlight node0_rec_time | Node0_rec_time is the time at which node 0 receives the echo packet from node 1. |
Highlight round_trip_time = 0.0 | round_trip_time holds the round-trip packet time.
That is, the time taken to go from node 0 to node 1 and return. |
Highlight total_delay = 0.0 | total_delay holds the sum of all delays. |
Highlight prop_delay = 6560.0 | prop_delay is the propagation delay of the channel.
It is set by us. |
Highlight throughput = 0.0 | throughput holds the throughput of the network.
It is the rate of packet delivery. |
Highlight trans_delay = 0.0 | trans_delay holds the transmission delay of a packet. |
Highlight RxTraceClient(std::string context, Ptr<const Packet> p) | RxTraceClient is a callback function.
It is executed whenever the client receives a packet. The first argument is the traced source. We shall explain trace sources later in this tutorial. Here the traced source is Rx. The second argument is the packet received. |
Highlight node0_rec_time = Simulator::Now().GetSeconds() | In the function, we will update the value of node0_rec_time variable.
Here, we set the value of the current time. The current time is found using the GetSeconds method. |
Highlight round_trip_time | Similarly, we update the value of the round_trip_time variable.
We set it to the sum of transmission and reception time of packets. These values are represented by node0_trans_time and node0_rec_time. The node0_trans_time variable would be updated in the TxTraceClient function. |
Highlight round_cnt++ | Next, we increment the value of the round_cnt variable by 1.
We do so, to keep a track of the number of round-trips. |
Highlight TxTraceClient | TxTraceClient is a callback function.
It is executed whenever the client sends a packet. The first argument is the traced source. The second argument is the receive packet. |
Highlight node0_trans_time | In the function, we set the value of node0_trans_time.
The value is the time at which transmission starts. |
Highlight RxTraceServer | The last callback function is RxTraceServer.
It is executed when the server node receives a packet. The first argument is the traced source. The second argument is the received packet. |
Highlight node1_rec_time = Simulator::Now().GetSeconds() | Here we set the receiving time to the current time in seconds. |
Highlight total_delay += (node1_rec_time - node0_trans_time)*1000 | Then, we set the total_delay variable, which stores the total delay.
It is computed as the difference between two variables. The first is the packet reception time of the server. The second is the packet transmission time of the client. The value is multiplied by 1000 to get the unit in milliseconds. |
Highlight trans_delay += ((node1_rec_time - node0_trans_time)*1000 - prop_delay/1000000) | Next, we compute the value of transmission delay.
We get it by subtracting the value of propagation delay from total delay. The propagation delay value is in nanoseconds, hence we divide it by 1000000. This converts it into milliseconds. |
Highlight pkt_cnt++ | Next we increment the packet count. |
Highlight if (pkt_cnt == pkts) | Finally we compare the value of packet count to the total packets.
We do this to know when the last packet is received. If this is the last packet, we print all the parameters. |
Highlight NS_LOG_UNCOND | Using the NS_LOG_UNCOND function, we print the parameters to the terminal.
We print the parameters:
|
Highlight total_delay/(p->GetSize()*pkts | Throughput is calculated as total delay divided by total data size. |
Highlight nodes.Create(2) | Let’s move to the main function now.
For the topology, we create a point-to-point network with two nodes. |
Highlight SetDeviceAttribute | The data rate for the device is 100 Mbps. |
Highlight SetChannelAttribute | The propagation delay is set to 6560 nanoseconds. |
Highlight address.SetBase("10.1.1.0", "255.255.255.0") | The base address of the network is 10.1.1.0. |
Highlight UdpEchoServerHelper echoServer(9) | Next we create a UDP echo server with port address 9. |
Highlight echoServer.Install(nodes.Get(1)) | The echo server application is installed on the second node.
The index of the node is 1. |
Highlight serverApps.Start(Seconds(1.0)) | Here we set the start time of the server applications to 1 second. |
Highlight serverApps.Stop(Seconds(10.0)) | Similarly, we set the stop time to 10 seconds.
Both the times are from the start of the simulation. |
Highlight echoClient(interfaces.GetAddress(1), 9) | Then we create an echo client application with destination port 9. |
Highlight SetAttribute | Using the SetAttribute method we set the following attributes for the client. |
Highlight MaxPackets | The maximum number of packets is 10. |
Highlight Interval | The time interval between packet transmissions is 0.5 seconds. |
Highlight PacketSize | The packet size is 1024 bytes. |
Highlight echoClient.Install(nodes.Get(0)) | The echo client application is installed on the first node.
The index of the node is 0. |
Highlight clientApps.Start(Seconds(2.0)) | The start time of the client apps is set to 2 seconds. |
Highlight clientApps.Stop(Seconds(10.0)) | The stop time is 10 seconds. |
Highlight Config::Connect | Using the connect method, we connect trace sources to callback functions.
These functions are also known as trace sinks. A callback function is passed as an argument to another function. These are used in conjunction with trace sources. Trace sources are entities that signal events in an ns-3 program. These events include packet transmission, change in window size etc. |
Highlight UdpEchoClient/Tx | This program uses three trace sources.
The first is the Tx trace source, of the UdpEchoClient class. It traces the transmission of a packet by an echo client application. |
Highlight UdpEchoClient/Rx | The second trace source is Rx, of the UdpEchoClient class.
It traces the reception of a packet by an echo client application. |
Highlight UdpEchoServer/Rx | The last trace source is Rx, of the UdpEchoServer class.
It traces the reception of a packet by an echo server application. |
Highlight AnimationInterface anim ("network_performance.xml"); | Next we create an AnimationInterface object, anim, for NetAnim animation.
The parameter for the constructor is the name of the XML animation file. It will be generated by the program after the simulation. Here the name of the file is network_performance.xml. |
Highlight anim.SetConstantPosition | Then set the positions for the nodes using the SetConstantPosition function. |
Highlight Simulator::Run() | The Run function is used to run the simulation. |
Highlight Simulator::Destroy() | The Destroy function ends the simulation.
Close the text editor. |
Press Ctrl,Alt and T keys simultaneously. Type cd ns-allinone-3.38/ns-3.38 to navigate to the ns3 installation directory Type mv ~/Downloads/network_performance.cc scratch/network_performance.cc to move the source file to scratch directory. |
Now we will observe the simulation.
Open a terminal by pressing Ctrl, Alt and T keys simultaneously. Using the cd command, navigate to the installation directory of ns-3. Go to the ns-3.38 directory. Move your source file to the scratch directory within the ns-3.38 directory. |
Type ./ns3 run scratch/network_performance.cc | Run the command dot forward slash ns3 run space scratch forward slash network underscore performance dot cc.
network underscore performance is the name of the source file. |
Keep the terminal open and show the output of the command | After compilation, we get the network parameters. The parameters are
|
Type cd ~/ns-allinone-3.38/netanim | Now, to visualise the network, we will use NetAnim.
Navigate to the netanim directory under ns-allinone-3.38. |
Type ./NetAnim | Now type dot forward slash NetAnim. The NetAnim window will open. |
Click on the Open XML trace file icon on the top left corner of the window. | Click on the Open XML trace file icon on the top left corner of the window. |
In the file picker, navigate to the ns-allinone-3.38/ns-3.38 directory and select the network_performance.xml file. | In the file picker, navigate to the ns-3.38 directory.
Select the network_performance.xml file. The file would be generated by the program. You can also download the file from Code Files section. |
On the toolbar, click on the Node Size drop down button, and select size 10. | On the toolbar, click on the Node Size drop down button.
Select size 10. |
On the toolbar, click on the play button | On the toolbar, click on the play button to view the simulation.
We see the circles representing the nodes. The lines with arrows represent the transfer of packets. |
Hover over node 0 and node 1 circles. | We see the packets moving from node 0 to node 1. |
Show slide:
Summary |
This brings us to the end of the tutorial. Let us summarise.
In this tutorial, we have learnt to
|
Show slide:
Assignment |
As an assignment, please do the following:* Create a Point-to-Point network with 3 nodes
|
Show slide:
Assignment - Observation |
In the terminal, you will get this output.
The values may vary depending on the network parameters. These parameters include packet size, propagation delay and data rate. |
Show slide:
About the Spoken Tutorial Project |
The video at the following link summarises the Spoken Tutorial project.
Please download and watch it. |
Show Slide:
Spoken Tutorial Workshops |
The Spoken Tutorial Project team conducts workshops and gives certificates.
For more details, please write to us. |
Show Slide:
Answers for THIS Spoken Tutorial |
Post your timed queries in this forum. |
Show Slide:
FOSSEE Forum |
For any general or technical questions on ns-3, visit the FOSSEE forum and post your question. |
Show slide
Acknowledgement |
Spoken Tutorial Project was established by the Ministry of Education, Government of India. |
Show slide
Acknowledgement |
We thank Dr.Moyukh Laha from IIT Kharagpur for his domain support.
We would also like to thank Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi from VIT, Chennai for their support. |
Show slide:
Thank You |
This is Josiga, a FOSSEE summer fellow 2023, IIT Bombay signing off.
|