Difference between revisions of "Ns-3-Network-Simulator/C3/Analyzing-TCP-Congestion-window/English"
(Created page with "{| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''''' '''Welcome''' || Welcome to the spoken tutorial on''' Analyzing''' '''TCP Congestion''' '''Window...") |
|||
Line 7: | Line 7: | ||
'''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: | ||
'''Outline''' | '''Outline''' | ||
|| In this tutorial, we will learn to | || In this tutorial, we will learn to | ||
− | * | + | * Create a '''TCP socket '''with''' TCP Reno congestion''' control |
− | * | + | * Track changes in congestion window size |
− | * | + | * Plot the change in congestion window against time |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''System Requirements''' | '''System Requirements''' | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | * | + | *'''Ubuntu''' '''Linux 22.04 OS''' |
− | * | + | *'''ns-3.38''' |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
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 |
− | * | + | *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 practicing. |
− | |- | + | |- |
|| Show diagram: | || Show diagram: | ||
'''Network topology with two nodes''' | '''Network topology with two nodes''' | ||
− | || | + | || The network topology consists of two nodes. |
− | + | They are connected using a point-to-point link. | |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 57: | Line 57: | ||
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 '''CreateObject''' method of the '''Object''' base class creates an object by type |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 68: | Line 68: | ||
The application instance sends packets to the server node continuously. | The application instance sends packets to the server node continuously. | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 76: | Line 76: | ||
Now we will go through the steps required to use the '''TutorialApp''' class in our program. | 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. | || Open a terminal by pressing Ctrl, Alt and T keys simultaneously. | ||
|| 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''' |
|| Type '''cd ns-allinone-3.38 forward slash ns-3.38 '''as''' '''shown. | || Type '''cd ns-allinone-3.38 forward slash ns-3.38 '''as''' '''shown. | ||
− | |- | + | |- |
− | || | + | || Type '''cp examples/tutorial/tutorial-app.cc src/applications/model''' |
|| Now we will copy the required files. | || Now we will copy the required files. | ||
Line 92: | Line 92: | ||
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 | + | Let us copy the file '''tutorial-app.cc '''which is available under '''examples/tutorial folder.''' |
− | |- | + | |- |
|| Only narration | || Only narration | ||
|| The destination is the '''model''' directory under the '''src/applications '''directory. | || The destination is the '''model''' directory under the '''src/applications '''directory. | ||
Line 101: | Line 101: | ||
These files can be imported in our program. | 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'''. | || Now we copy the file '''tutorial-app.h'''. | ||
Line 109: | Line 109: | ||
It contains the required definitions for the '''TutorialApp '''class. | It contains the required definitions for the '''TutorialApp '''class. | ||
− | |- | + | |- |
|| Only narration | || Only narration | ||
|| Once the files are copied, we need to edit the '''CMakeLists.txt''' file. | || Once the files are copied, we need to edit the '''CMakeLists.txt''' file. | ||
Line 116: | Line 116: | ||
We need to add the files we copied to the '''CMakeLists.txt '''file. | 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. | || Using your favorite text editor, edit the '''CMakeLists.txt '''file. | ||
Line 124: | Line 124: | ||
We are using the '''gedit '''text editor. | 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. | || 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) |
|| Now find the '''HEADER_FILES '''header. | || Now find the '''HEADER_FILES '''header. | ||
− | After the last line under the header, add the line | + | 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. | ||
|| Save the file and close the text editor. | || Save the file and close the text editor. | ||
− | |- | + | |- |
|| Switch to the terminal window. | || Switch to the terminal window. | ||
Line 148: | Line 148: | ||
This command scans for any changes in the build files. | This command scans for any changes in the build files. | ||
− | |- | + | |- |
− | || | + | || Type '''./ns3''' '''build''' |
− | || | + | || Now type '''./ns3 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. | Pause the video here and wait for the build process to finish. | ||
Line 158: | Line 158: | ||
It could take several minutes. | It could take several minutes. | ||
− | + | Now the '''tutorial-app.h '''header file is ready to be used in our program. | |
− | |- | + | |- |
|| Open the file '''tcp-congestion.cc '''in the text editor | || Open the file '''tcp-congestion.cc '''in the text editor | ||
|| Now we will take a look at the code for the program. | || Now we will take a look at the code for the program. | ||
Line 168: | Line 168: | ||
Download this file from the '''Code files '''section and open it in a text editor. | Download this file from the '''Code files '''section and open it in a text editor. | ||
− | |- | + | |- |
|| 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''' | ||
|| The '''CwndChange''' function is a callback function. | || The '''CwndChange''' function is a callback function. | ||
Line 178: | Line 178: | ||
The function prints the old and new sizes of the congestion window. | The function prints the old and new sizes of the congestion window. | ||
− | |- | + | |- |
|| Highlight '''GetStream''' | || Highlight '''GetStream''' | ||
|| It also writes these values to the output file using the '''GetStream''' function. | || It also writes these values to the output file using the '''GetStream''' function. | ||
− | |- | + | |- |
|| 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)''' | ||
|| The network consists of 2 nodes. | || The network consists of 2 nodes. | ||
− | |- | + | |- |
|| Highlight '''DataRate '''and then '''Delay''' | || Highlight '''DataRate '''and then '''Delay''' | ||
|| We set the data rate to 5 Mbps and the delay to 2 milliseconds. | || We set the data rate to 5 Mbps and the delay to 2 milliseconds. | ||
− | |- | + | |- |
|| Highlight '''Ptr<RateErrorModel>''' | || Highlight '''Ptr<RateErrorModel>''' | ||
|| Next, we create a pointer to an object of the '''RateErrorModel '''class. | || Next, we create a pointer to an object of the '''RateErrorModel '''class. | ||
− | |- | + | |- |
|| Highlight '''em->SetAttribute''' | || Highlight '''em->SetAttribute''' | ||
|| Then set the error rate to 0.00001. | || Then set the error rate to 0.00001. | ||
− | |- | + | |- |
|| Highlight '''devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue(em));''' | || Highlight '''devices.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue(em));''' | ||
|| For this program, node 2, with index 1 is the receiver node. | || For this program, node 2, with index 1 is the receiver node. | ||
Line 203: | Line 203: | ||
The value of the attribute is the pointer we created earlier. | The value of the attribute is the pointer we created earlier. | ||
− | |- | + | |- |
|| Highlight '''SetBase''' | || Highlight '''SetBase''' | ||
|| The IP address of the network is set to 10.1.1.0 with subnet mask 255.255.255.0. | || The IP address of the network is set to 10.1.1.0 with subnet mask 255.255.255.0. | ||
− | |- | + | |- |
|| Highlight '''packetSinkHelper.Install''' | || Highlight '''packetSinkHelper.Install''' | ||
|| To receive packets, we create a packet sink on the receiver node. | || To receive packets, we create a packet sink on the receiver node. | ||
Line 213: | Line 213: | ||
It will then send the packets to the receiver node, node 2. | It will then send the packets to the receiver node, node 2. | ||
− | |- | + | |- |
|| Highlight '''Socket::CreateSocket''' | || Highlight '''Socket::CreateSocket''' | ||
|| Create a socket on node 1 using the '''CreateSocket''' method. | || Create a socket on node 1 using the '''CreateSocket''' method. | ||
− | |- | + | |- |
|| Highlight '''Config::Set''' | || Highlight '''Config::Set''' | ||
|| Then set the socket type using the '''set '''method. | || Then set the socket type using the '''set '''method. | ||
− | |- | + | |- |
|| Highlight '''Ptr<TutorialApp> app''' | || Highlight '''Ptr<TutorialApp> app''' | ||
|| Now let’s create an instance of the '''TutorialApp '''class. | || Now let’s create an instance of the '''TutorialApp '''class. | ||
− | |- | + | |- |
|| Highlight '''Setup(ns3TcpSocket, sinkAddress, 1040, 1000, DataRate("1Mbps"))''' | || Highlight '''Setup(ns3TcpSocket, sinkAddress, 1040, 1000, DataRate("1Mbps"))''' | ||
|| The app uses the socket we created earlier. | || The app uses the socket we created earlier. | ||
− | |- | + | |- |
|| Highlight '''nodes.Get(0)->AddApplication(app);''' | || Highlight '''nodes.Get(0)->AddApplication(app);''' | ||
|| Further, let’s add the application to the first node of the '''CSMA '''network. | || Further, let’s add the application to the first node of the '''CSMA '''network. | ||
− | |- | + | |- |
|| Highlight '''app->SetStartTime(Seconds(1.))''' | || Highlight '''app->SetStartTime(Seconds(1.))''' | ||
|| Then we will set the start and stop times for the application. | || Then we will set the start and stop times for the application. | ||
− | |- | + | |- |
|| Highlight '''AsciiTraceHelper''' | || Highlight '''AsciiTraceHelper''' | ||
|| The '''AsciiTraceHelper''' object creates an output file stream. | || The '''AsciiTraceHelper''' object creates an output file stream. | ||
− | |- | + | |- |
|| Highlight '''TraceConnectWithoutContext''' | || Highlight '''TraceConnectWithoutContext''' | ||
|| Then we connect the stream to the '''CongestionWindow''' trace source. | || Then we connect the stream to the '''CongestionWindow''' trace source. | ||
− | |- | + | |- |
|| Highlight '''GnuplotHelper '''plotHelper | || Highlight '''GnuplotHelper '''plotHelper | ||
|| Next, we create an object of the '''GnuplotHelper '''class. | || Next, we create an object of the '''GnuplotHelper '''class. | ||
− | |- | + | |- |
|| Highlight '''plotHelper.ConfigurePlot''' | || Highlight '''plotHelper.ConfigurePlot''' | ||
|| Configure the parameters for the plot. | || Configure the parameters for the plot. | ||
Line 251: | Line 251: | ||
The third and fourth arguments are the x-axis and y-axis labels respectively. | The third and fourth arguments are the x-axis and y-axis labels respectively. | ||
− | |- | + | |- |
|| Highlight '''plotHelper.PlotProbe''' | || Highlight '''plotHelper.PlotProbe''' | ||
|| Using the '''PlotProbe''' method, we set attributes for the probe. | || Using the '''PlotProbe''' method, we set attributes for the probe. | ||
These include: | These include: | ||
− | * | + | *'''probe name''' |
− | * | + | *'''probe path''' |
− | * | + | *'''output trace source '''and |
− | * | + | *'''data series label ''' |
The '''probeName '''and '''probeTrace '''values were set previously. | The '''probeName '''and '''probeTrace '''values were set previously. | ||
The '''FileHelper''' class object writes packet byte count over time. | The '''FileHelper''' class object writes packet byte count over time. | ||
− | |- | + | |- |
|| 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 | ||
|| Let’s run the simulation for the program. | || Let’s run the simulation for the program. | ||
Navigate to the '''ns-3.38 '''directory. | Navigate to the '''ns-3.38 '''directory. | ||
− | |- | + | |- |
|| Type '''./ns3 run scratch/tcp-congestion.cc''' | || Type '''./ns3 run scratch/tcp-congestion.cc''' | ||
|| Run the source script using the run command. | || Run the source script using the run command. | ||
Line 284: | Line 284: | ||
On running the simulation, a file with '''cwnd '''extension is created. | On running the simulation, a file with '''cwnd '''extension is created. | ||
− | |- | + | |- |
|| Open ns-3.38 directory and highlight the '''tcp-congestion.cwnd '''file | || Open ns-3.38 directory and highlight the '''tcp-congestion.cwnd '''file | ||
|| You can find the file in the '''ns-3.38 '''directory. | || You can find the file in the '''ns-3.38 '''directory. | ||
Line 293: | Line 293: | ||
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 | ||
|| Using the commands displayed, we configure the plot. | || Using the commands displayed, we configure the plot. | ||
Line 300: | Line 300: | ||
The commands in this file will configure the plot. | The commands in this file will configure the plot. | ||
− | |- | + | |- |
|| Show terminal | || Show terminal | ||
|| Make sure the file is in the same directory as the '''cwnd '''file. | || Make sure the file is in the same directory as the '''cwnd '''file. | ||
− | |- | + | |- |
|| Type '''sudo apt install gnuplot''' | || Type '''sudo apt install gnuplot''' | ||
|| To generate the plot, we use the gnuplot command. | || To generate the plot, we use the gnuplot command. | ||
Line 310: | Line 310: | ||
If it is already installed, proceed to the next command. | If it is already installed, proceed to the next command. | ||
− | |- | + | |- |
|| 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 congestion.plt.''' | ||
− | |- | + | |- |
|| Switch to the file manager window. | || Switch to the file manager window. | ||
Show the '''congestion.png''' file | Show the '''congestion.png''' file | ||
|| An image file is generated in the same directory with the plot. | || An image file is generated in the same directory with the plot. | ||
− | |- | + | |- |
|| Open '''congestion.png '''file | || Open '''congestion.png '''file | ||
|| The plot shows the change in the size of the congestion window over time. | || The plot shows the change in the size of the congestion window over time. | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Summary''' | '''Summary''' | ||
− | || | + | || This brings us to the end of the tutorial. Let us summarize. |
− | + | In this tutorial, we have learnt to | |
− | * | + | *Create a TCP socket with TCP Reno congestion control |
− | * | + | *Track changes in congestion window size |
− | * | + | *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 |
− | * | + | *The program should have a '''CSMA '''network with 6 nodes |
− | * | + | *Send packets from node 2 to node 5 |
− | * | + | *Trace the changes in the congestion window size |
− | * | + | *Plot the changes using '''gnuplot''' |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Assignment - Observation''' | '''Assignment - Observation''' | ||
|| In the terminal, observe the change in congestion window size over time. | || In the terminal, observe the change in congestion window size over time. | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Assignment - Observation''' | '''Assignment - Observation''' | ||
|| The image generated by gnuplot depicts the change in congestion window size. | || The image generated by gnuplot depicts the change in congestion window size. | ||
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''About the Spoken Tutorial Project''' | '''About the Spoken Tutorial Project''' | ||
− | || | + | || The video at the following link summarizes the '''Spoken Tutorial project'''. |
− | + | 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. | |
− | |- | + | |- |
− | || | + | || 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: | || Show slide: | ||
'''Acknowledgement''' | '''Acknowledgement''' | ||
− | || | + | || '''Spoken Tutorial''' Project is funded by the '''Ministry of Education, Government of India'''. |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
Line 388: | Line 388: | ||
We would also like to thank '''Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi '''from''' VIT, Chennai '''for their 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. |
− | + | Thanks for joining. | |
|- | |- | ||
|} | |} |
Revision as of 19:37, 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’s 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. | Open a terminal by pressing Ctrl, Alt and T keys simultaneously. |
Type cd ns-allinone-3.38/ns-3.38 | Type cd ns-allinone-3.38 forward slash ns-3.38 as shown. |
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 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. Now the tutorial-app.h header file is ready to be used in our program. |
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 | 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. The commands in this file will configure the plot. |
Show terminal | Make sure the file is in the same directory as the cwnd file. |
Type sudo apt install gnuplot | To generate the plot, 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 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 is funded 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. |