Difference between revisions of "Ns-3-Network-Simulator/C2/Network-performance-Analysis/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 180: Line 180:
 
The propagation delay value is in nanoseconds, hence we divide it by 1000000.
 
The propagation delay value is in nanoseconds, hence we divide it by 1000000.
  
This converts it into milliseconds.
+
This converts it to milliseconds.
 
|-  
 
|-  
 
|| Highlight '''pkt_cnt++'''
 
|| Highlight '''pkt_cnt++'''

Revision as of 17:48, 28 February 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
  • Use trace sources
  • Create callback functions
  • Connect trace sources to callback functions and
  • Calculate network parameters using trace sources
Show slide:

System Requirements

To record this tutorial, I am using
  • Ubuntu Linux Operating system version 22.04
  • ns-3.38
  • NetAnim visualizer tool
Show slide:

Prerequisite

https://spoken-tutorial.org

To follow this tutorial,
  • You must have basic knowledge of using Linux terminal
  • You must know how to create point-to-point network in ns-3
  • For pre-requisite Linux and ns-3 tutorials, please visit this website
Show slide:

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 practicing
Show diagram:

Point-to-Point network with two nodes

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. 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 to 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:

  • End-to-end delay
  • Transmission delay
  • Throughput
  • Propagation delay (constant)
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

  • End-to-end delay
  • Transmission delay
  • Throughput and
  • Round trip time
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

  • Use trace sources
  • Create callback functions
  • Connect trace sources to callback functions
  • Calculate network parameters using trace sources
Show slide:

Assignment

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:

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.


Thanks for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat