Difference between revisions of "Ns-3-Network-Simulator/C3/Analyzing-TCP-Congestion-window/English"
Line 6: | Line 6: | ||
|| '''Slide:1''''' | || '''Slide:1''''' | ||
'''Welcome''' | '''Welcome''' | ||
− | || Welcome to the spoken tutorial on''' Analyzing''' '''TCP Congestion''' '''Window | + | || Welcome to the spoken tutorial on''' Analyzing''' '''TCP Congestion''' '''Window'''. |
|- | |- | ||
|| Show slide: | || Show slide: | ||
Line 21: | Line 21: | ||
'''System Requirements''' | '''System Requirements''' | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | *'''Ubuntu''' '''Linux | + | * '''Ubuntu''' '''Linux''' operating version 22.04 |
*'''ns-3.38''' | *'''ns-3.38''' | ||
Line 31: | Line 31: | ||
[https://www.spoken-tutorial.org/ https://www.spoken-tutorial.org] | [https://www.spoken-tutorial.org/ https://www.spoken-tutorial.org] | ||
|| To follow this tutorial: | || To follow this tutorial: | ||
− | *You must have basic knowledge of Linux and''' ns-3''' software | + | * You must have basic knowledge of Linux and''' ns-3''' software |
− | *For pre-requisite Linux and ns-3 tutorials, please visit this website | + | * For pre-requisite Linux and ns-3 tutorials, please visit this website |
|- | |- | ||
Line 39: | Line 39: | ||
'''Code files''' | '''Code files''' | ||
|| | || | ||
− | *The files used in this tutorial are provided in the '''Code files''' link. | + | * The files used in this tutorial are provided in the '''Code files''' link. |
* Please download and extract the files. | * Please download and extract the files. | ||
* Make a copy and then use them while practicing. | * Make a copy and then use them while practicing. | ||
Line 54: | Line 54: | ||
'''Classes and Methods''' | '''Classes and Methods''' | ||
− | || | + | || Let us have a look at the classes and methods. |
These would be needed to apply TCP New Reno congestion control. | These would be needed to apply TCP New Reno congestion control. | ||
− | *The '''RateErrorModel '''class object determines and flags lost or errored packets | + | * The '''RateErrorModel '''class object determines and flags lost or errored packets |
− | *The '''CreateObject''' method of the '''Object''' base class creates an object by type | + | * The '''CreateObject''' method of the '''Object''' base class creates an object by type |
|- | |- | ||
Line 64: | Line 64: | ||
'''Tutorial App''' | '''Tutorial App''' | ||
− | || We shall be using a pre-coded application file, '''tutorial-app.cc | + | || We shall be using a pre-coded application file, '''tutorial-app.cc''' |
in this tutorial. | in this tutorial. | ||
Line 78: | Line 78: | ||
|- | |- | ||
|| Open a terminal by pressing Ctrl, Alt and T keys simultaneously. | || Open a terminal by pressing Ctrl, Alt and T keys simultaneously. | ||
+ | |||
+ | Type '''cd ns-allinone-3.38/ns-3.38''' | ||
+ | |||
|| Open a terminal by pressing Ctrl, Alt and T keys simultaneously. | || Open a terminal by pressing Ctrl, Alt and T keys simultaneously. | ||
− | |||
− | |||
− | + | Navigate to the installation directory of ns-3. | |
+ | |||
+ | Go to ns-3.38 directory. | ||
|- | |- | ||
+ | |||
|| Type '''cp examples/tutorial/tutorial-app.cc src/applications/model''' | || Type '''cp examples/tutorial/tutorial-app.cc src/applications/model''' | ||
Line 92: | Line 96: | ||
First we copy the file '''tutorial-app.cc'''. | First we copy the file '''tutorial-app.cc'''. | ||
− | Let us copy the file '''tutorial-app.cc '''which is available under '''examples/tutorial folder.''' | + | Let us copy the file '''tutorial-app.cc ''' which is available under '''examples/tutorial folder.''' |
|- | |- | ||
Line 129: | Line 133: | ||
|| In the text editor, find the '''SOURCE_FILES '''header. | || In the text editor, find the '''SOURCE_FILES '''header. | ||
− | After the last line under the header, add the line '''model/tutorial-app.cc | + | After the last line under the header, add the line '''model/tutorial-app.cc'''. |
|- | |- | ||
|| Under the HEADER_FILES header, add the line: '''model/tutorial-app.h''' after the last entry (usually model/tutorial-app.h) | || Under the HEADER_FILES header, add the line: '''model/tutorial-app.h''' after the last entry (usually model/tutorial-app.h) | ||
Line 144: | Line 148: | ||
Type '''./ns3 configure''' | Type '''./ns3 configure''' | ||
− | || In the terminal, type | + | || In the terminal, type '''./ns3 configure.''' |
This command scans for any changes in the build files. | This command scans for any changes in the build files. | ||
Line 150: | Line 154: | ||
|- | |- | ||
|| Type '''./ns3''' '''build''' | || Type '''./ns3''' '''build''' | ||
− | || Now type '''./ns3 build '''to start the build process. | + | || Now type '''./ns3 space build '''to start the build process. |
This command scans the '''CMakeLists.txt '''file for new changes and builds the '''ns-3 '''program again. | This command scans the '''CMakeLists.txt '''file for new changes and builds the '''ns-3 '''program again. | ||
Line 158: | Line 162: | ||
It could take several minutes. | It could take several minutes. | ||
− | |||
|- | |- | ||
|| Open the file '''tcp-congestion.cc '''in the text editor | || Open the file '''tcp-congestion.cc '''in the text editor | ||
Line 170: | Line 173: | ||
|- | |- | ||
|| Highlight '''<nowiki>#include “ns3/tutorial-app.h”</nowiki>''' | || Highlight '''<nowiki>#include “ns3/tutorial-app.h”</nowiki>''' | ||
− | || We have used this header file which we built earlier | + | || We have used this header file which we built earlier. |
|- | |- | ||
|| Highlight '''CwndChange''' | || Highlight '''CwndChange''' | ||
Line 183: | Line 186: | ||
|- | |- | ||
|| Only narration | || Only narration | ||
− | || For demonstration, we will be creating a '''point-to-point '''network. | + | || For demonstration, we will be creating a '''point-to-point ''' network. |
|- | |- | ||
|| Highlight''' csmaNodes.Create(2)''' | || Highlight''' csmaNodes.Create(2)''' | ||
Line 256: | Line 259: | ||
These include: | These include: | ||
− | *'''probe name''' | + | * '''probe name''' |
− | *'''probe path''' | + | * '''probe path''' |
− | *'''output trace source '''and | + | * '''output trace source '''and |
− | *'''data series label ''' | + | * '''data series label ''' |
The '''probeName '''and '''probeTrace '''values were set previously. | The '''probeName '''and '''probeTrace '''values were set previously. | ||
Line 266: | Line 269: | ||
|- | |- | ||
|| Highlight '''Simulator::Run()''' | || Highlight '''Simulator::Run()''' | ||
− | || Finally we use the '''Run '''and '''Destroy '''for running and stopping the simulation. | + | || Finally we use the '''Run '''and '''Destroy ''' for running and stopping the simulation. |
|- | |- | ||
|| Open terminal and navigate to the '''ns-3.38 '''directory | || Open terminal and navigate to the '''ns-3.38 '''directory | ||
Line 276: | Line 279: | ||
|| Run the source script using the run command. | || Run the source script using the run command. | ||
− | Here the name of the source file is '''tcp-congestion.cc | + | Here the name of the source file is '''tcp-congestion.cc'''. |
The output shows the time at which the change occurs in the size of the window. | The output shows the time at which the change occurs in the size of the window. | ||
Line 294: | Line 297: | ||
The '''cwnd '''file is used to provide the values for the plot. | The '''cwnd '''file is used to provide the values for the plot. | ||
|- | |- | ||
− | || Open the '''congestion.plt''' file | + | || Open the '''congestion.plt''' file. |
+ | |||
+ | Show terminal | ||
|| Using the commands displayed, we configure the plot. | || Using the commands displayed, we configure the plot. | ||
− | Let us first download the '''congestion.plt '''file from the | + | Let us first download the '''congestion.plt '''file from the Code files section. |
+ | |||
+ | Make sure that the file is in the same directory as the '''cwnd''' file. | ||
The commands in this file will configure the plot. | The commands in this file will configure the plot. | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
|| Type '''sudo apt install gnuplot''' | || Type '''sudo apt install gnuplot''' | ||
− | || To generate the | + | || To generate the '''gnuplot''', we use the '''gnuplot''' command. |
To install it, type '''sudo apt install gnuplot''' in the terminal. | To install it, type '''sudo apt install gnuplot''' in the terminal. | ||
Line 312: | Line 317: | ||
|- | |- | ||
|| Type '''gnuplot congestion.plt''' | || Type '''gnuplot congestion.plt''' | ||
− | || Next, we generate the plot using the command '''gnuplot congestion.plt.''' | + | || Next, we generate the plot using the command '''gnuplot space congestion.plt.''' |
|- | |- | ||
|| Switch to the file manager window. | || Switch to the file manager window. | ||
Line 328: | Line 333: | ||
In this tutorial, we have learnt to | In this tutorial, we have learnt to | ||
− | *Create a TCP socket with TCP Reno congestion control | + | * Create a TCP socket with TCP Reno congestion control |
− | *Track changes in congestion window size | + | * Track changes in congestion window size |
− | *Plot the change in the congestion window size against time | + | * Plot the change in the congestion window size against time |
|- | |- | ||
|| Show slide: '''Assignment''' | || Show slide: '''Assignment''' | ||
|| As an assignment, please do the following | || As an assignment, please do the following | ||
− | *Write an''' ns-3''' program | + | * Write an''' ns-3''' program |
− | *The program should have a '''CSMA '''network with 6 nodes | + | * The program should have a '''CSMA '''network with 6 nodes |
− | *Send packets from node 2 to node 5 | + | * Send packets from node 2 to node 5 |
− | *Trace the changes in the congestion window size | + | * Trace the changes in the congestion window size |
− | *Plot the changes using '''gnuplot''' | + | * Plot the changes using '''gnuplot''' |
|- | |- | ||
Line 379: | Line 384: | ||
'''Acknowledgement''' | '''Acknowledgement''' | ||
− | || '''Spoken Tutorial''' Project | + | || '''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''. |
|- | |- | ||
|| Show slide: | || Show slide: |
Latest revision as of 20:04, 22 April 2024
Visual Cue | Narration |
Slide:1
Welcome |
Welcome to the spoken tutorial on Analyzing TCP Congestion Window. |
Show slide:
Outline |
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:
Network topology with two nodes |
The network topology consists of two nodes.
They are connected using a point-to-point link. |
Show slide:
Classes and Methods |
Let us have a look at the classes and methods.
These would be needed to apply TCP New Reno congestion control.
|
Show slide:
Tutorial App |
We shall be using a pre-coded application file, tutorial-app.cc
in this tutorial. The application instance sends packets to the server node continuously. |
Show slide:
Trace sources |
This program uses the CongestionWindow trace source.
It tracks the changes in the congestion window size. Now we will go through the steps required to use the TutorialApp class in our program. |
Open a terminal by pressing Ctrl, Alt and T keys simultaneously.
Type cd ns-allinone-3.38/ns-3.38 |
Open a terminal by pressing Ctrl, Alt and T keys simultaneously.
Navigate to the installation directory of ns-3. Go to ns-3.38 directory. |
Type cp examples/tutorial/tutorial-app.cc src/applications/model | Now we will copy the required files.
These folders and files are created by default when ns-3 is installed. First we copy the file tutorial-app.cc. Let us copy the file tutorial-app.cc which is available under examples/tutorial folder. |
Only narration | The destination is the model directory under the src/applications directory.
The src directory stores the header files and the associated source files. These files can be imported in our program. |
Type cp examples/tutorial/tutorial-app.h src/applications/model | Now we copy the file tutorial-app.h.
It is a header file. It contains the required definitions for the TutorialApp class. |
Only narration | Once the files are copied, we need to edit the CMakeLists.txt file.
The CMakeLists.txt file lists the files that will be compiled during the build process. We need to add the files we copied to the CMakeLists.txt file. |
Type gedit src/applications/CMakeLists.txt | Using your favorite text editor, edit the CMakeLists.txt file.
It is present under the applications directory, which is under the src directory. We are using the gedit text editor. |
Under the SOURCE_FILES header, add the line: model/tutorial-app.cc after the last entry (usually model/udp-trace-client.cc) | In the text editor, find the SOURCE_FILES header.
After the last line under the header, add the line model/tutorial-app.cc. |
Under the HEADER_FILES header, add the line: model/tutorial-app.h after the last entry (usually model/tutorial-app.h) | Now find the HEADER_FILES header.
After the last line under the header, add the line model/tutorial-app.h. |
Save the file and close the text editor. | Save the file and close the text editor. |
Switch to the terminal window.
Type ./ns3 configure |
In the terminal, type ./ns3 configure.
This command scans for any changes in the build files. |
Type ./ns3 build | Now type ./ns3 space build to start the build process.
This command scans the CMakeLists.txt file for new changes and builds the ns-3 program again. Pause the video here and wait for the build process to finish. It could take several minutes. |
Open the file tcp-congestion.cc in the text editor | Now we will take a look at the code for the program.
I have created the source file tcp-congestion.cc for this program. The source code contains the required functions to implement a point-to-point network. Download this file from the Code files section and open it in a text editor. |
Highlight #include “ns3/tutorial-app.h” | We have used this header file which we built earlier. |
Highlight CwndChange | The CwndChange function is a callback function.
It acts as a trace sink for the CongestionWindow trace source. The function prints the old and new sizes of the congestion window. |
Highlight GetStream | It also writes these values to the output file using the GetStream function. |
Only narration | For demonstration, we will be creating a point-to-point network. |
Highlight csmaNodes.Create(2) | The network consists of 2 nodes. |
Highlight DataRate and then Delay | We set the data rate to 5 Mbps and the delay to 2 milliseconds. |
Highlight Ptr<RateErrorModel> | Next, we create a pointer to an object of the RateErrorModel class. |
Highlight em->SetAttribute | Then set the error rate to 0.00001. |
Highlight devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue(em)); | For this program, node 2, with index 1 is the receiver node.
On the receiver node, set the ReceiveErrorModel attribute. The value of the attribute is the pointer we created earlier. |
Highlight SetBase | The IP address of the network is set to 10.1.1.0 with subnet mask 255.255.255.0. |
Highlight packetSinkHelper.Install | To receive packets, we create a packet sink on the receiver node.
We shall have the first node, with index 0 as the sender node. It will then send the packets to the receiver node, node 2. |
Highlight Socket::CreateSocket | Create a socket on node 1 using the CreateSocket method. |
Highlight Config::Set | Then set the socket type using the set method. |
Highlight Ptr<TutorialApp> app | Now let’s create an instance of the TutorialApp class. |
Highlight Setup(ns3TcpSocket, sinkAddress, 1040, 1000, DataRate("1Mbps")) | The app uses the socket we created earlier. |
Highlight nodes.Get(0)->AddApplication(app); | Further, let’s add the application to the first node of the CSMA network. |
Highlight app->SetStartTime(Seconds(1.)) | Then we will set the start and stop times for the application. |
Highlight AsciiTraceHelper | The AsciiTraceHelper object creates an output file stream. |
Highlight TraceConnectWithoutContext | Then we connect the stream to the CongestionWindow trace source. |
Highlight GnuplotHelper plotHelper | Next, we create an object of the GnuplotHelper class. |
Highlight plotHelper.ConfigurePlot | Configure the parameters for the plot.
The first argument is the file name prefix. The second argument is the plot title. Here it is TCP Window Size vs Time’. The third and fourth arguments are the x-axis and y-axis labels respectively. |
Highlight plotHelper.PlotProbe | Using the PlotProbe method, we set attributes for the probe.
These include:
The probeName and probeTrace values were set previously. The FileHelper class object writes packet byte count over time. |
Highlight Simulator::Run() | Finally we use the Run and Destroy for running and stopping the simulation. |
Open terminal and navigate to the ns-3.38 directory | Let’s run the simulation for the program.
Navigate to the ns-3.38 directory. |
Type ./ns3 run scratch/tcp-congestion.cc | Run the source script using the run command.
Here the name of the source file is tcp-congestion.cc. The output shows the time at which the change occurs in the size of the window. Also available in the output are the old and new window sizes. Now we shall observe the plot of the congestion window change. On running the simulation, a file with cwnd extension is created. |
Open ns-3.38 directory and highlight the tcp-congestion.cwnd file | You can find the file in the ns-3.38 directory.
The name of the file is the one specified in the CreateFileStream function. Here the name of the file is tcp-congestion.cwnd. The cwnd file is used to provide the values for the plot. |
Open the congestion.plt file.
Show terminal |
Using the commands displayed, we configure the plot.
Let us first download the congestion.plt file from the Code files section. Make sure that the file is in the same directory as the cwnd file. The commands in this file will configure the plot. |
Type sudo apt install gnuplot | To generate the gnuplot, we use the gnuplot command.
To install it, type sudo apt install gnuplot in the terminal. If it is already installed, proceed to the next command. |
Type gnuplot congestion.plt | Next, we generate the plot using the command gnuplot space congestion.plt. |
Switch to the file manager window.
Show the congestion.png file |
An image file is generated in the same directory with the plot. |
Open congestion.png file | The plot shows the change in the size of the congestion window over time. |
Show slide:
Summary |
This brings us to the end of the tutorial. Let us summarize.
In this tutorial, we have learnt to
|
Show slide: Assignment | As an assignment, please do the following
|
Show slide:
Assignment - Observation |
In the terminal, observe the change in congestion window size over time. |
Show slide:
Assignment - Observation |
The image generated by gnuplot depicts the change in congestion window size. |
Show slide:
About the Spoken Tutorial Project |
The video at the following link summarizes 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 |
Please 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. |