Difference between revisions of "Ns-3-Network-Simulator/C3/Analyzing-TCP-Congestion-window/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''''' '''Welcome''' || Welcome to the spoken tutorial on''' Analyzing''' '''TCP Congestion''' '''Window...")
 
 
(One intermediate revision by the same user not shown)
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'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:  
 
|| Show slide:  
  
 
'''Outline'''
 
'''Outline'''
 
|| In this tutorial, we will learn to
 
|| In this tutorial, we will learn to
* <div style="margin-left:1.27cm;margin-right:0cm;">Create a '''TCP socket '''with''' TCP Reno congestion''' control</div>
+
* Create a '''TCP socket '''with''' TCP Reno congestion''' control
* <div style="margin-left:1.27cm;margin-right:0cm;">Track changes in congestion window size</div>
+
* Track changes in congestion window size
* <div style="margin-left:1.27cm;margin-right:0cm;">Plot the change in congestion window against time</div>
+
* Plot the change in congestion window against time
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
 
'''System Requirements'''
 
'''System Requirements'''
 
|| To record this tutorial, I am using
 
|| To record this tutorial, I am using
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Ubuntu''' '''Linux 22.04 OS'''</div>
+
* '''Ubuntu''' '''Linux''' operating version 22.04
* <div style="margin-left:1.27cm;margin-right:0cm;">'''ns-3.38'''</div>
+
*'''ns-3.38'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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:
* <div style="margin-left:1.27cm;margin-right:0cm;">You must have basic knowledge of Linux and''' ns-3''' software</div>
+
* You must have basic knowledge of Linux and''' ns-3''' software
* <div style="margin-left:1.27cm;margin-right:0cm;">For pre-requisite Linux and ns-3 tutorials, please visit this website</div>
+
* For pre-requisite Linux and ns-3 tutorials, please visit this website
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
 
'''Code files'''
 
'''Code files'''
 
||  
 
||  
* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#252525;">The files used in this tutorial are provided in the </span><span style="color:#252525;">'''Code files'''</span><span style="color:#252525;"> link.</span></div>
+
* The files used in this tutorial are provided in the '''Code files''' link.
* <div style="color:#252525;margin-left:1.27cm;margin-right:0cm;">Please download and extract the files.</div>
+
* Please download and extract the files.
* <div style="color:#252525;margin-left:1.27cm;margin-right:0cm;">Make a copy and then use them while practicing.</div>
+
* Make a copy and then use them while practicing.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show diagram:
 
|| Show diagram:
  
 
'''Network topology with two nodes'''
 
'''Network topology with two nodes'''
|| <div style="color:#252525;">The network topology consists of two nodes.</div>
+
|| The network topology consists of two nodes.
  
<div style="color:#252525;">They are connected using a point-to-point link.</div>
+
They are connected using a point-to-point link.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
 
'''Classes and Methods'''
 
'''Classes and Methods'''
|| Let’s have a look at the 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.
* <div style="margin-left:1.27cm;margin-right:0cm;">The '''RateErrorModel '''class object determines and flags lost or errored packets</div>
+
* The '''RateErrorModel '''class object determines and flags lost or errored packets
* <div style="margin-left:1.27cm;margin-right:0cm;">The '''CreateObject''' method of the '''Object''' base class creates an object by type</div>
+
* The '''CreateObject''' method of the '''Object''' base class creates an object by type
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
 
'''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.
  
 
The application instance sends packets to the server node continuously.
 
The application instance sends packets to the server node continuously.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
 
|| <span style="background-color:#ffffff;">Type </span><span style="background-color:#ffffff;">'''cd ns-allinone-3.38/ns-3.38'''</span>
 
  
|| Type '''cd ns-allinone-3.38 forward slash ns-3.38 '''as''' '''shown.
+
Navigate to the installation directory of ns-3.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
 
|| <span style="background-color:#ffffff;">Type </span><span style="background-color:#ffffff;">'''cp examples/tutorial/tutorial-app.cc src/applications/model'''</span>
+
Go to ns-3.38 directory.
 +
|-
 +
 
 +
|| 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 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 <span style="background-color:#ffffff;">'''examples/tutorial folder.'''</span>
+
Let us copy the file '''tutorial-app.cc ''' which is available under '''examples/tutorial folder.'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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 105:
  
 
These files can be imported in our program.
 
These files can be imported in our program.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="background-color:#ffffff;">Type </span><span style="background-color:#ffffff;">'''cp examples/tutorial/tutorial-app.h src/applications/model'''</span>
+
|| 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 113:
  
 
It contains the required definitions for the '''TutorialApp '''class.
 
It contains the required definitions for the '''TutorialApp '''class.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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 120:
  
 
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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="background-color:#ffffff;">Type</span><span style="background-color:#ffffff;">''' gedit src/applications/CMakeLists.txt'''</span>
+
|| 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 128:
  
 
We are using the '''gedit '''text editor.
 
We are using the '''gedit '''text editor.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="background-color:#ffffff;">Under the SOURCE_FILES header, add the line: </span><span style="background-color:#ffffff;">'''model/tutorial-app.cc '''</span><span style="background-color:#ffffff;">after the last entry (usually model/udp-trace-client.cc)</span>
+
|| 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'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="background-color:#ffffff;">Under the HEADER_FILES header, add the line: </span><span style="background-color:#ffffff;">'''model/tutorial-app.h'''</span><span style="background-color:#ffffff;"> after the last entry (usually model/tutorial-app.h)</span>
+
|| 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 <span style="background-color:#ffffff;">'''model/tutorial-app.h'''</span><span style="background-color:#ffffff;">.</span>
+
After the last line under the header, add the line '''model/tutorial-app.h'''.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Switch to the terminal window.
 
|| Switch to the terminal window.
  
 
Type '''./ns3 configure'''
 
Type '''./ns3 configure'''
|| In the terminal, type .'''/ns3 configure.'''  
+
|| 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.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="background-color:#ffffff;">Type </span><span style="background-color:#ffffff;">'''./ns3'''</span><span style="background-color:#ffffff;"> </span><span style="background-color:#ffffff;">'''build'''</span>
+
|| Type '''./ns3''' '''build'''
|| <span style="background-color:#ffffff;">Now type </span><span style="background-color:#ffffff;">'''./ns3 build '''</span><span style="background-color:#ffffff;">to start the build process.</span>
+
|| Now type '''./ns3 space build '''to start the build process.
  
<span style="background-color:#ffffff;">This command scans the </span><span style="background-color:#ffffff;">'''CMakeLists.txt '''</span><span style="background-color:#ffffff;">file for new changes and builds the </span><span style="background-color:#ffffff;">'''ns-3 '''</span><span style="background-color:#ffffff;">program again.</span>
+
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 162:
 
It could take several minutes.
 
It could take several minutes.
  
<span style="background-color:#ffffff;">Now the </span><span style="background-color:#ffffff;">'''tutorial-app.h '''</span><span style="background-color:#ffffff;">header file is ready to be used in our program.</span>
+
|-
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
 
|| 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 171:
  
 
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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''CwndChange'''
 
|| Highlight '''CwndChange'''
 
|| The '''CwndChange''' function is a callback function.
 
|| The '''CwndChange''' function is a callback function.
Line 178: Line 181:
  
 
The function prints the old and new sizes of the congestion window.
 
The function prints the old and new sizes of the congestion window.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight''' csmaNodes.Create(2)'''
 
|| Highlight''' csmaNodes.Create(2)'''
 
|| The network consists of 2 nodes.
 
|| The network consists of 2 nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''em->SetAttribute'''
 
|| Highlight '''em->SetAttribute'''
 
|| Then set the error rate to 0.00001.
 
|| Then set the error rate to 0.00001.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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 206:
  
 
The value of the attribute is the pointer we created earlier.
 
The value of the attribute is the pointer we created earlier.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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 216:
  
 
It will then send the packets to the receiver node, node 2.
 
It will then send the packets to the receiver node, node 2.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''Config::Set'''
 
|| Highlight '''Config::Set'''
 
|| Then set the socket type using the '''set '''method.
 
|| Then set the socket type using the '''set '''method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''AsciiTraceHelper'''
 
|| Highlight '''AsciiTraceHelper'''
 
|| The '''AsciiTraceHelper''' object creates an output file stream.
 
|| The '''AsciiTraceHelper''' object creates an output file stream.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''TraceConnectWithoutContext'''
 
|| Highlight '''TraceConnectWithoutContext'''
 
|| Then we connect the stream to the '''CongestionWindow''' trace source.
 
|| Then we connect the stream to the '''CongestionWindow''' trace source.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''GnuplotHelper '''plotHelper
 
|| Highlight '''GnuplotHelper '''plotHelper
 
|| Next, we create an object of the '''GnuplotHelper '''class.
 
|| Next, we create an object of the '''GnuplotHelper '''class.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''plotHelper.ConfigurePlot'''
 
|| Highlight '''plotHelper.ConfigurePlot'''
 
|| Configure the parameters for the plot.  
 
|| Configure the parameters for the plot.  
Line 251: Line 254:
  
 
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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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:
* <div style="margin-left:1.27cm;margin-right:0cm;">'''probe name'''</div>
+
* '''probe name'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''probe path'''</div>
+
* '''probe path'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''output trace source '''and</div>
+
* '''output trace source '''and
* <div style="margin-left:1.27cm;margin-right:0cm;">'''data series label '''</div>
+
* '''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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
  
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 284: Line 287:
  
 
On running the simulation, a file with '''cwnd '''extension is created.
 
On running the simulation, a file with '''cwnd '''extension is created.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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 296:
  
 
The '''cwnd '''file is used to provide the values for the plot.
 
The '''cwnd '''file is used to provide the values for the plot.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| 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 code files section. Make sure that the file is in the same directory.
+
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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
 
|| Show terminal
+
|-
|| Make sure the file is in the same directory as the '''cwnd '''file.
+
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
 
|| Type '''sudo apt install gnuplot'''
 
|| Type '''sudo apt install gnuplot'''
|| To generate the plot, we use the gnuplot command.
+
|| 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.
  
 
If it is already installed, proceed to the next command.
 
If it is already installed, proceed to the next command.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:  
 
|| Show slide:  
  
 
'''Summary'''
 
'''Summary'''
|| <div style="color:#252525;">This brings us to the end of the tutorial. Let us summarize.</div>
+
|| This brings us to the end of the tutorial. Let us summarize.
  
<div style="color:#252525;">In this tutorial, we have learnt to</div>
+
In this tutorial, we have learnt to
* <div style="margin-left:1.27cm;margin-right:0cm;">Create a TCP socket with TCP Reno congestion control</div>
+
* Create a TCP socket with TCP Reno congestion control
* <div style="margin-left:1.27cm;margin-right:0cm;">Track changes in congestion window size</div>
+
* Track changes in congestion window size
* <div style="margin-left:1.27cm;margin-right:0cm;">Plot the change in the congestion window size against time</div>
+
* Plot the change in the congestion window size against time
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide: '''Assignment'''
 
|| Show slide: '''Assignment'''
 
|| As an assignment, please do the following
 
|| As an assignment, please do the following
* <div style="margin-left:1.27cm;margin-right:0cm;">Write an''' ns-3''' program</div>
+
* Write an''' ns-3''' program
* <div style="margin-left:1.27cm;margin-right:0cm;">The program should have a '''CSMA '''network with 6 nodes</div>
+
* The program should have a '''CSMA '''network with 6 nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">Send packets from node 2 to node 5</div>
+
* Send packets from node 2 to node 5
* <div style="margin-left:1.27cm;margin-right:0cm;">Trace the changes in the congestion window size</div>
+
* Trace the changes in the congestion window size
* <div style="margin-left:1.27cm;margin-right:0cm;">Plot the changes using '''gnuplot'''</div>
+
* Plot the changes using '''gnuplot'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| 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.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:  
 
|| Show slide:  
  
 
'''About the Spoken Tutorial Project'''
 
'''About the Spoken Tutorial Project'''
|| <span style="background-color:#ffffff;color:#252525;">The video at the following link summarizes the </span><span style="background-color:#ffffff;color:#252525;">'''Spoken Tutorial project'''</span><span style="background-color:#ffffff;color:#252525;">.</span>
+
|| The video at the following link summarizes the '''Spoken Tutorial project'''.
  
<div style="color:#252525;">Please download and watch it.</div>
+
Please download and watch it.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show Slide:
 
|| Show Slide:
  
<span style="background-color:#ffffff;color:#252525;">'''Spoken Tutorial Workshops'''</span>
+
'''Spoken Tutorial Workshops'''  
|| <span style="background-color:#ffffff;color:#252525;">The </span><span style="background-color:#ffffff;color:#252525;">'''Spoken Tutorial Project'''</span><span style="background-color:#ffffff;color:#252525;"> team conducts workshops and gives certificates.</span>
+
|| The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.
  
<div style="color:#252525;">For more details, please write to us.</div>
+
For more details, please write to us.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
|| <div style="color:#252525;">Show Slide:</div>
+
|| Show Slide:
  
<div style="color:#252525;">'''Answers for THIS Spoken Tutorial'''</div>
+
'''Answers for THIS Spoken Tutorial'''
| style="color:#252525;" | Please post your timed queries in this forum.
+
|| Please post your timed queries in this forum.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#252525;">Show Slide:</div>
+
|| Show Slide:
  
<div style="color:#252525;">'''FOSSEE Forum'''</div>
+
'''FOSSEE Forum'''
|| <span style="background-color:#ffffff;color:#252525;">For any general or technical questions on </span><span style="background-color:#ffffff;color:#252525;">'''ns-3'''</span><span style="background-color:#ffffff;color:#252525;">, visit the</span><span style="background-color:#ffffff;color:#252525;">''' FOSSEE forum'''</span><span style="background-color:#ffffff;color:#252525;"> and post your question.</span>
+
|| For any general or technical questions on '''ns-3''', visit the''' FOSSEE forum''' and post your question.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
 
'''Acknowledgement'''
 
'''Acknowledgement'''
|| <span style="background-color:#ffffff;color:#252525;">'''Spoken Tutorial'''</span><span style="background-color:#ffffff;color:#252525;"> Project is funded by the </span><span style="background-color:#ffffff;color:#252525;">'''Ministry of Education, Government of India'''</span><span style="background-color:#ffffff;color:#252525;">.</span>
+
|| '''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
Line 388: Line 393:
 
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.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show slide:
 
|| Show slide:
  
 
'''Thank You'''
 
'''Thank You'''
|| <span style="background-color:#ffffff;color:#252525;">This is </span><span style="background-color:#ffffff;color:#252525;">'''Karthik Chandrasekhar, '''</span><span style="background-color:#ffffff;color:#252525;">a FOSSEE summer fellow 2023, IIT Bombay signing off.</span>
+
|| This is '''Josiga''', a FOSSEE summer fellow 2023, IIT Bombay signing off.
  
<div style="color:#252525;">Thanks for joining.</div>
+
Thanks for joining.
 
|-
 
|-
 
|}
 
|}

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
  • 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:

System Requirements

To record this tutorial, I am using
  • Ubuntu Linux operating version 22.04
  • ns-3.38
Show slide:

Prerequisite

https://www.spoken-tutorial.org

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:

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:

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.

  • 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:

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:

  • probe name
  • probe path
  • output trace source and
  • data series label

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

  • 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 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:

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.

Contributors and Content Editors

Madhurig, Nirmala Venkat