Difference between revisions of "Ns-3-Network-Simulator/C3/Creating-TCP/UDP-flow-with-Star-Topology/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "{| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''''' || Welcome to Spoken tutorial on creating '''TCP/UDP flow '''with''' star topology.''' |- style=...")
 
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
 
|| '''Slide:1'''''
 
|| '''Slide:1'''''
 
|| Welcome to Spoken tutorial on creating '''TCP/UDP flow '''with''' star topology.'''  
 
|| Welcome to Spoken tutorial on creating '''TCP/UDP flow '''with''' star topology.'''  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show Slide:  
 
|| Show Slide:  
  
 
'''Learning Objectives'''
 
'''Learning Objectives'''
 
|| 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 '''star topology'''</div>
+
* Create a '''star topology'''
* <div style="margin-left:1.27cm;margin-right:0cm;">Create an on-off application to send '''TCP''' traffic</div>
+
* Create an on-off application to send '''TCP''' traffic
* <div style="margin-left:1.27cm;margin-right:0cm;">Create an on-off application to send '''UDP''' traffic</div>
+
* Create an on-off application to send '''UDP''' traffic
* <div style="margin-left:1.27cm;margin-right:0cm;">Calculate '''throughput''' and '''delay'''</div>
+
* Calculate '''throughput''' and '''delay'''
* <div style="margin-left:1.27cm;margin-right:0cm;">Analyze the flow using a '''flow monitor.'''</div>
+
* Analyze the flow using a '''flow monitor'''.
  
|- 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 OS version '''22.04.'''</div>
+
* '''Ubuntu''' Linux OS version '''22.04.'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''ns-3''' version 3.38.</div>
+
* '''ns-3''' version 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:
  
 
'''Pre-requisites'''
 
'''Pre-requisites'''
 
|| To follow this tutorial
 
|| To follow this tutorial
* <div style="margin-left:1.27cm;margin-right:0cm;">The learner must have basic knowledge of using Linux terminal</div>
+
* The learner must have basic knowledge of using Linux terminal
* <div style="margin-left:1.27cm;margin-right:0cm;">The learner must have understanding of network topologies</div>
+
* The learner must have understanding of network topologies
* <div style="margin-left:1.27cm;margin-right:0cm;">For pre-requisite Linux and ns-3 tutorials, please visit this website [https://spoken-tutorial.org/ https://spoken-tutorial.org]</div>
+
* For pre-requisite Linux and ns-3 tutorials, please visit this website [https://spoken-tutorial.org/ https://spoken-tutorial.org]
  
|- style="border:0.6pt solid #808080;padding:0.176cm;"
+
|-  
|| <div style="color:#252525;">Show Slide:</div>
+
|| Show Slide:
  
<div style="color:#252525;">'''Code Files'''</div>
+
'''Code Files'''
 
||
 
||
* <div style="margin-left:1.87cm;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.87cm;margin-right:0cm;">Please download and extract the files.</div>
+
* Please download and extract the files.
* <div style="color:#252525;margin-left:1.87cm;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 slide:
 
|| Show slide:
  
Line 51: Line 51:
 
A '''star topology''' network with '''five point to point links'''.
 
A '''star topology''' network with '''five point to point links'''.
  
The '''hub '''will be a part of all the links and hence, will have '''five IP addresses.'''
+
The '''hub ''' will be a part of all the links and hence, will have '''five IP addresses'''.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show Slide:
 
|| Show Slide:
  
Line 59: Line 59:
 
|| Let’s look at the '''classes '''and '''methods''' used to create '''TCP''' and '''UDP''' '''flows'''.
 
|| Let’s look at the '''classes '''and '''methods''' used to create '''TCP''' and '''UDP''' '''flows'''.
  
* <div style="margin-left:1.27cm;margin-right:0cm;">'''PacketSinkHelper '''class is used to create a '''packet sink '''on the '''hub'''. </div>
+
* '''PacketSinkHelper '''class is used to create a '''packet sink '''on the '''hub'''.  
* <div style="margin-left:1.27cm;margin-right:0cm;">'''OnOffHelper''' class is used to send a particular traffic to the hub.''' '''</div>
+
* <div style="margin-left:1.27cm;margin-right:0cm;">'''PointToPointStarHelper '''class is used to create star topology using p2p links.</div>
+
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
* '''OnOffHelper''' class is used to send a particular traffic to the hub.''' '''
 +
 
 +
* '''PointToPointStarHelper ''' class is used to create star topology using '''p2p''' links.
 +
 
 +
|-
 
|| Open code editor
 
|| Open code editor
 
|| I have created the source file '''flow2final.cc''' for this program.
 
|| I have created the source file '''flow2final.cc''' for this program.
Line 69: Line 71:
 
The source code contains the required functions to create,  
 
The source code contains the required functions to create,  
  
* <div style="margin-left:1.27cm;margin-right:0cm;">A '''TCP flow''' from '''node 3''' to the '''hub'''</div>
+
* A '''TCP flow''' from '''node 3''' to the '''hub'''
* <div style="margin-left:1.27cm;margin-right:0cm;">A '''UDP flow''' from '''node 2 '''to the '''hub.'''</div>
+
* A '''UDP flow''' from '''node 2 ''' to the '''hub'''.
  
 
Now we will go through the source file for the program.  
 
Now we will go through the source file for the program.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));'''
 
|| Highlight '''Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));'''
|| To build '''star topology '''let us set up default values for the '''size''' of the packets.
+
|| To build '''star topology ''' let us set up default values for the '''size''' of the packets.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1400 kb/s"));'''
 
|| Highlight '''Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1400 kb/s"));'''
 
|| We shall also set the value for '''data rate''' to be '''1400 kbps''' as the default value.
 
|| We shall also set the value for '''data rate''' to be '''1400 kbps''' as the default value.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Only narration
 
|| Only narration
|| Let us build a star topology with '''p2p connection'''s.
+
|| Let us build a star topology with '''p2p connections'''.
  
 
For that we shall use the''' PointToPointHelper''' class.
 
For that we shall use the''' PointToPointHelper''' class.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''InternetStackHelper internet;'''
 
|| Highlight '''InternetStackHelper internet;'''
  
Line 91: Line 93:
 
|| Then let us install the''' internet stack''' on all the nodes.
 
|| Then let us install the''' internet stack''' on all the nodes.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);'''
 
|| Highlight '''PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);'''
 
|| Next, we shall create a '''packet sink '''to '''receive''' the''' packets''' on the '''hub.'''
 
|| Next, we shall create a '''packet sink '''to '''receive''' the''' packets''' on the '''hub.'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());'''
 
|| Highlight '''ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());'''
 
|| Then let us create a '''container''' to receive the '''packets''' on the '''hub'''.  
 
|| Then let us create a '''container''' to receive the '''packets''' on the '''hub'''.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Only narration
 
|| Only narration
|| Further, we create an''' on-off application''' to send '''TCP/UDP traffic''' to the '''hub'''.
+
|| Further, we create an ''' on-off application''' to send '''TCP/UDP traffic''' to the '''hub'''.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight''' OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());'''
 
|| Highlight''' OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());'''
 
|| The address of the '''hub''' is fetched for sending the '''TCP traffic''' to it.
 
|| The address of the '''hub''' is fetched for sending the '''TCP traffic''' to it.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''OnTime '''and then '''OffTime'''
 
|| Highlight '''OnTime '''and then '''OffTime'''
|| Now, we set the''' ontime''' to''' 1 '''and''' offtime''' to '''0'''.
+
|| Now, we set the ''' ontime''' to''' 1 ''' and ''' offtime''' to '''0'''.
 
Next, we fetch the '''port''' of the '''hub''' from the '''spoke node'''.
 
Next, we fetch the '''port''' of the '''hub''' from the '''spoke node'''.
  
 
Also let us set the attribute type to '''Remote.'''
 
Also let us set the attribute type to '''Remote.'''
  
Then install the '''OnOffHelper '''on the '''spoke node'''.  
+
Then install the '''OnOffHelper ''' on the '''spoke node'''.  
 +
|-
 
|-
 
|-
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
 
 
|| Highlight '''OnOffHelper clientHelper("ns3::UdpSocketFactory", Address());'''
 
|| Highlight '''OnOffHelper clientHelper("ns3::UdpSocketFactory", Address());'''
|| The address of the '''hub '''is fetched for receiving the '''UDP''' '''traffic '''from '''node 2.'''
+
|| The address of the '''hub ''' is fetched for receiving the '''UDP''' '''traffic '''from '''node 2'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Only Narration
 
|| Only Narration
|| We then follow the same procedure as we did for '''TCP.'''
+
|| We then follow the same procedure as we did for '''TCP'''.
  
Now pause the tutorial and repeat the same procedure for '''UDP.'''
+
Now pause the tutorial and repeat the same procedure for '''UDP'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''Ptr<FlowMonitor> flowMonitor;'''
 
|| Highlight '''Ptr<FlowMonitor> flowMonitor;'''
 
|| Then, '''Initialize''' flow monitor for tracing.
 
|| Then, '''Initialize''' flow monitor for tracing.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| HIghlight '''FlowMonitorHelper flowHelper;'''
 
|| HIghlight '''FlowMonitorHelper flowHelper;'''
  
Line 131: Line 133:
  
 
|| We shall then install a '''flow monitor''' on all the '''spoke nodes'''.
 
|| We shall then install a '''flow monitor''' on all the '''spoke nodes'''.
|- 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()'''
 
|| Now, the''' Run()''' function is used to run the simulation.
 
|| Now, the''' Run()''' function is used to run the simulation.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| HIghlight '''Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier());'''
 
|| HIghlight '''Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier());'''
|| Let us now create an object of the '''Ipv4FlowClassifier class.'''
+
|| Let us now create an object of the '''Ipv4FlowClassifier class'''.
  
The created '''object '''returns a''' pointer''' to the '''flow classifier.'''
+
The created '''object '''returns a''' pointer''' to the '''flow classifier'''.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''std::map<FlowId,FlowMonitor::FlowStats> stats=flowMonitor->GetFlowStats();'''
 
|| Highlight '''std::map<FlowId,FlowMonitor::FlowStats> stats=flowMonitor->GetFlowStats();'''
 
|| To store the information about the '''network flow, '''let us use this command.
 
|| To store the information about the '''network flow, '''let us use this command.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight the '''entire for loop.'''
 
|| Highlight the '''entire for loop.'''
  
Line 151: Line 153:
 
|| Let’s retrieve the details of the flow using a '''for loop.'''
 
|| Let’s retrieve the details of the flow using a '''for loop.'''
  
'''iter arrow first '''is used to collect the '''ID''' of the '''flow.'''
+
'''iter arrow first ''' is used to collect the '''ID''' of the '''flow.'''
  
'''iter arrow second '''is used to collect the '''data '''associated with the''' flow.'''
+
'''iter arrow second ''' is used to collect the '''data ''' associated with the''' flow.'''
  
 
We will analyze the '''type of flow''' and '''print''' the''' delay''' and '''throughput'''.
 
We will analyze the '''type of flow''' and '''print''' the''' delay''' and '''throughput'''.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''Simulator::Destroy()'''
 
|| Highlight '''Simulator::Destroy()'''
 
|| The '''Destroy() '''function ends the simulation.
 
|| The '''Destroy() '''function ends the simulation.
  
Now close the text editor.
+
|-
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|| Press '''Ctrl, Alt '''and '''T keys'''
||  
+
 
+
Press '''Ctrl, Alt '''and '''T keys'''
+
  
 
Navigate to the '''ns-allinone-3.38/ns3.38 '''directory
 
Navigate to the '''ns-allinone-3.38/ns3.38 '''directory
Line 172: Line 171:
 
|| Now we will observe the simulation.
 
|| Now we will observe the simulation.
  
Open the terminal by pressing '''Ctrl, Alt''' and '''T keys''' simultaneously.
+
Open the terminal by pressing '''Ctrl''', '''Alt''' and '''T keys''' simultaneously.
  
 
Using the '''cd '''command, navigate to the installation directory of '''ns-3'''.
 
Using the '''cd '''command, navigate to the installation directory of '''ns-3'''.
Line 179: Line 178:
  
 
Move your '''source file''' to the '''scratch '''directory within the '''ns-3.38''' '''directory'''.
 
Move your '''source file''' to the '''scratch '''directory within 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/flow2final.cc'''
 
|| Type ./'''ns3 run scratch/flow2final.cc'''
  
 
Highlight '''throughput '''and '''delay'''
 
Highlight '''throughput '''and '''delay'''
|| Run the command ./'''ns3 run scratch/flow2final.cc '''command.
+
|| Run the command ./'''ns3 space run space scratch/flow2final.cc ''' command.
  
'''flow2final.cc '''is the name of the source file.  
+
'''flow2final.cc ''' is the name of the source file.  
  
After compilation, we see the details of '''TCP '''and''' UDP flows'''.
+
After compilation, we see the details of '''TCP ''' and ''' UDP flows'''.
  
We also see the''' throughput''' and''' delay''' of the flow.
+
We also see the ''' throughput''' and''' delay''' of the flow.
 +
|-
 
|-
 
|-
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
 
 
|| Show Slide: '''Summary'''
 
|| Show Slide: '''Summary'''
 
|| This brings us to the end of this tutorial.  
 
|| This brings us to the end of this tutorial.  
Line 198: Line 197:
  
 
In this tutorial, we have  
 
In this tutorial, we have  
* <div style="margin-left:1.27cm;margin-right:0cm;">Created a '''star topology'''.</div>
+
* Created a '''star topology'''.
* <div style="margin-left:1.27cm;margin-right:0cm;">Created a '''TCP''' flow with star topology.</div>
+
* Created a '''TCP''' flow with star topology.
* <div style="margin-left:1.27cm;margin-right:0cm;">Created a''' UDP''' flow with star topology.</div>
+
* Created a ''' UDP''' flow with star topology.
* <div style="margin-left:1.27cm;margin-right:0cm;">Calculated '''throughput''' and '''delay'''</div>
+
* Calculated '''throughput''' and '''delay'''
* <div style="margin-left:1.27cm;margin-right:0cm;">Analyzed the''' flow''' using a '''flow monitor.'''</div>
+
* Analyzed the ''' flow''' using a '''flow monitor'''.
  
|- 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;">Create a''' star topology''' with 10 '''spoke''' nodes.</div>
+
* Create a ''' star topology''' with 10 '''spoke''' nodes.
* <div style="margin-left:1.27cm;margin-right:0cm;">Create an '''on-off '''application.</div>
+
* Create an '''on-off '''application.
* <div style="margin-left:1.27cm;margin-right:0cm;">Send '''TCP''' traffic through the '''on-off''' application.</div>
+
* Send '''TCP''' traffic through the '''on-off''' application.
* <div style="margin-left:1.27cm;margin-right:0cm;">Set the '''attribute''' to '''Remote.'''</div>
+
* Set the '''attribute''' to '''Remote'''.
* <div style="margin-left:1.27cm;margin-right:0cm;">Analyze the flow using a flow''' monitor.''' </div>
+
* Analyze the flow using a flow''' monitor'''.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Show Slide:
 
|| Show Slide:
  
 
'''Assignment- Observations'''
 
'''Assignment- Observations'''
 
|| In the terminal, you will observe this output with '''TCP flow'''.
 
|| In the terminal, you will observe this output with '''TCP flow'''.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide:
 
|| Show Slide:
  
Line 225: Line 224:
  
 
Please download and watch it.
 
Please download and watch it.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide:
 
|| Show Slide:
  
Line 232: Line 231:
  
 
For more details, please write to us.
 
For more details, please write to us.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide:
 
|| Show Slide:
  
 
'''Answers for THIS Spoken Tutorial'''
 
'''Answers for THIS Spoken Tutorial'''
 
|| Please post your timed queries in this forum.
 
|| Please post your timed queries in this forum.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide:
 
|| Show Slide:
  
 
'''FOSSEE Forum'''
 
'''FOSSEE Forum'''
 
|| For any general or technical questions on ns-3, visit the''' FOSSEE forum''' and post your question
 
|| For any general or technical questions on ns-3, visit the''' FOSSEE forum''' and post your question
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide: '''Acknowledgement'''
 
|| Show Slide: '''Acknowledgement'''
|| <span style="color:#252525;">'''Spoken Tutorial'''</span><span style="color:#252525;"> Project was established by the </span><span style="color:#252525;">'''Ministry of Education, Government of India'''</span><span style="color:#252525;">.</span>
+
||'''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide: '''Acknowledgement'''
 
|| Show Slide: '''Acknowledgement'''
|| <span style="color:#252525;">We thank </span><span style="color:#252525;">'''Dr.Moyukh Laha'''</span><span style="color:#252525;"> from </span><span style="color:#252525;">'''IIT Kharagpur'''</span><span style="color:#252525;"> for his domain support.</span>
+
||We thank '''Dr.Moyukh Laha''' from '''IIT Kharagpur''' for his domain support.
  
<span style="color:#252525;">We would also like to thank </span><span style="color:#252525;">'''Dr. R. Radha, Dr. X. Anita, and Dr.T.Subbulakshmi '''</span><span style="color:#252525;">from</span><span style="color:#252525;">''' VIT, Chennai '''</span><span style="color:#252525;">for their support.</span>
+
We would also like to thank '''Dr. R. Radha, Dr. X. Anita, and Dr.T.Subbulakshmi '''from''' VIT, Chennai ''' for their support.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
 
|| Show Slide: Thank you
 
|| Show Slide: Thank you
  
|| <span style="color:#252525;">This is </span><span style="color:#252525;">'''Arun Santhosh'''</span><span style="color:#252525;"> ,a FOSSEE Summer Fellow 2023, IIT Bombay signing off.</span>
+
||This is '''Arun Santhosh''', a FOSSEE Summer Fellow 2023, IIT Bombay signing off.
  
<div style="color:#252525;">Thank you for joining.</div>
+
Thank you for joining.
 
|-
 
|-
 
|}
 
|}

Latest revision as of 13:15, 26 March 2024

Visual Cue Narration
Slide:1 Welcome to Spoken tutorial on creating TCP/UDP flow with star topology.
Show Slide:

Learning Objectives

In this tutorial, we will learn to
  • Create a star topology
  • Create an on-off application to send TCP traffic
  • Create an on-off application to send UDP traffic
  • Calculate throughput and delay
  • Analyze the flow using a flow monitor.
Show Slide:

System Requirements

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

Pre-requisites

To follow this tutorial
  • The learner must have basic knowledge of using Linux terminal
  • The learner must have understanding of network topologies
  • For pre-requisite Linux and ns-3 tutorials, please visit this website https://spoken-tutorial.org
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 slide:

Star topology

For this tutorial, we would be creating the following topology.

A star topology network with five point to point links.

The hub will be a part of all the links and hence, will have five IP addresses.

Show Slide:

Classes and Methods

Let’s look at the classes and methods used to create TCP and UDP flows.
  • PacketSinkHelper class is used to create a packet sink on the hub.
  • OnOffHelper class is used to send a particular traffic to the hub.
  • PointToPointStarHelper class is used to create star topology using p2p links.
Open code editor I have created the source file flow2final.cc for this program.

The source code contains the required functions to create,

  • A TCP flow from node 3 to the hub
  • A UDP flow from node 2 to the hub.

Now we will go through the source file for the program.

Highlight Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137)); To build star topology let us set up default values for the size of the packets.
Highlight Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("1400 kb/s")); We shall also set the value for data rate to be 1400 kbps as the default value.
Only narration Let us build a star topology with p2p connections.

For that we shall use the PointToPointHelper class.

Highlight InternetStackHelper internet;

star.InstallStack (internet);

Then let us install the internet stack on all the nodes.
Highlight PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress); Next, we shall create a packet sink to receive the packets on the hub.
Highlight ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ()); Then let us create a container to receive the packets on the hub.
Only narration Further, we create an on-off application to send TCP/UDP traffic to the hub.
Highlight OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ()); The address of the hub is fetched for sending the TCP traffic to it.
Highlight OnTime and then OffTime Now, we set the ontime to 1 and offtime to 0.

Next, we fetch the port of the hub from the spoke node.

Also let us set the attribute type to Remote.

Then install the OnOffHelper on the spoke node.

Highlight OnOffHelper clientHelper("ns3::UdpSocketFactory", Address()); The address of the hub is fetched for receiving the UDP traffic from node 2.
Only Narration We then follow the same procedure as we did for TCP.

Now pause the tutorial and repeat the same procedure for UDP.

Highlight Ptr<FlowMonitor> flowMonitor; Then, Initialize flow monitor for tracing.
HIghlight FlowMonitorHelper flowHelper;

flowMonitor= flowHelper.InstallAll();

We shall then install a flow monitor on all the spoke nodes.
Highlight Simulator::Run() Now, the Run() function is used to run the simulation.
HIghlight Ptr<Ipv4FlowClassifier> classifier=DynamicCast<Ipv4FlowClassifier> (flowHelper.GetClassifier()); Let us now create an object of the Ipv4FlowClassifier class.

The created object returns a pointer to the flow classifier.

Highlight std::map<FlowId,FlowMonitor::FlowStats> stats=flowMonitor->GetFlowStats(); To store the information about the network flow, let us use this command.
Highlight the entire for loop.

Highlight iter->first

Highlight iter->second

Let’s retrieve the details of the flow using a for loop.

iter arrow first is used to collect the ID of the flow.

iter arrow second is used to collect the data associated with the flow.

We will analyze the type of flow and print the delay and throughput.

Highlight Simulator::Destroy() The Destroy() function ends the simulation.
Press Ctrl, Alt and T keys

Navigate to the ns-allinone-3.38/ns3.38 directory

Type mv ~/Downloads/flow2final.cc scratch/flow2final.cc to move the source file to scratch directory.

Now we will observe the simulation.

Open the terminal by pressing Ctrl, Alt and T keys simultaneously.

Using the cd command, navigate to the installation directory of ns-3.

Go to the ns-3.38 directory.

Move your source file to the scratch directory within the ns-3.38 directory.

Type ./ns3 run scratch/flow2final.cc

Highlight throughput and delay

Run the command ./ns3 space run space scratch/flow2final.cc command.

flow2final.cc is the name of the source file.

After compilation, we see the details of TCP and UDP flows.

We also see the throughput and delay of the flow.

Show Slide: Summary This brings us to the end of this tutorial.

Let us summarize.

In this tutorial, we have

  • Created a star topology.
  • Created a TCP flow with star topology.
  • Created a UDP flow with star topology.
  • Calculated throughput and delay
  • Analyzed the flow using a flow monitor.
Show Slide: Assignment As an assignment, please do the following:
  • Create a star topology with 10 spoke nodes.
  • Create an on-off application.
  • Send TCP traffic through the on-off application.
  • Set the attribute to Remote.
  • Analyze the flow using a flow monitor.
Show Slide:

Assignment- Observations

In the terminal, you will observe this output with TCP flow.
Show Slide:

About 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 Arun Santhosh, a FOSSEE Summer Fellow 2023, IIT Bombay signing off.

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat