Difference between revisions of "Ns-3-Network-Simulator/C3/Creating-TCP/UDP-flow-with-Star-Topology/English"
(Created page with "{| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''''' || Welcome to Spoken tutorial on creating '''TCP/UDP flow '''with''' star topology.''' |- style=...") |
|||
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.''' | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
'''Learning Objectives''' | '''Learning Objectives''' | ||
|| In this tutorial, we will learn to | || 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: | || Show Slide: | ||
'''System Requirements''' | '''System Requirements''' | ||
|| To record this tutorial, I am using | || To record this tutorial, I am using | ||
− | * | + | * '''Ubuntu''' Linux OS version '''22.04.''' |
− | * | + | * '''ns-3''' version 3.38. |
− | |- | + | |- |
|| Show slide: | || Show slide: | ||
'''Pre-requisites''' | '''Pre-requisites''' | ||
|| To follow this tutorial | || 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/ 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: | || Show slide: | ||
Line 53: | Line 53: | ||
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.''' | ||
− | |- | + | |- |
|| 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'''. | ||
− | * | + | * '''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 | || 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 69: | ||
The source code contains the required functions to create, | 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. | Now we will go through the source file for the program. | ||
− | |- | + | |- |
|| 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. | ||
− | |- | + | |- |
|| 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. | ||
− | |- | + | |- |
|| Only narration | || Only narration | ||
|| Let us build a star topology with '''p2p connection'''s. | || Let us build a star topology with '''p2p connection'''s. | ||
For that we shall use the''' PointToPointHelper''' class. | For that we shall use the''' PointToPointHelper''' class. | ||
− | |- | + | |- |
|| Highlight '''InternetStackHelper internet;''' | || Highlight '''InternetStackHelper internet;''' | ||
Line 91: | Line 91: | ||
|| Then let us install the''' internet stack''' on all the nodes. | || Then let us install the''' internet stack''' on all the nodes. | ||
− | |- | + | |- |
|| 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.''' | ||
− | |- | + | |- |
|| 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'''. | ||
− | |- | + | |- |
|| 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'''. | ||
− | |- | + | |- |
|| 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. | ||
− | |- | + | |- |
|| 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'''. | ||
Line 114: | Line 114: | ||
Then install the '''OnOffHelper '''on the '''spoke node'''. | Then install the '''OnOffHelper '''on the '''spoke node'''. | ||
|- | |- | ||
− | |- | + | |- |
|| 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.''' | ||
− | |- | + | |- |
|| 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.''' | ||
− | |- | + | |- |
|| Highlight '''Ptr<FlowMonitor> flowMonitor;''' | || Highlight '''Ptr<FlowMonitor> flowMonitor;''' | ||
|| Then, '''Initialize''' flow monitor for tracing. | || Then, '''Initialize''' flow monitor for tracing. | ||
− | |- | + | |- |
|| HIghlight '''FlowMonitorHelper flowHelper;''' | || HIghlight '''FlowMonitorHelper flowHelper;''' | ||
Line 131: | Line 131: | ||
|| We shall then install a '''flow monitor''' on all the '''spoke nodes'''. | || We shall then install a '''flow monitor''' on all the '''spoke nodes'''. | ||
− | |- | + | |- |
|| 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. | ||
− | |- | + | |- |
|| 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.''' | ||
Line 140: | Line 140: | ||
The created '''object '''returns a''' pointer''' to the '''flow classifier.''' | The created '''object '''returns a''' pointer''' to the '''flow classifier.''' | ||
− | |- | + | |- |
|| 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. | ||
− | |- | + | |- |
|| Highlight the '''entire for loop.''' | || Highlight the '''entire for loop.''' | ||
Line 157: | Line 157: | ||
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'''. | ||
− | |- | + | |- |
|| Highlight '''Simulator::Destroy()''' | || Highlight '''Simulator::Destroy()''' | ||
|| The '''Destroy() '''function ends the simulation. | || The '''Destroy() '''function ends the simulation. | ||
Now close the text editor. | Now close the text editor. | ||
− | |- | + | |- |
|| | || | ||
Line 179: | Line 179: | ||
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'''. | ||
− | |- | + | |- |
|| Type ./'''ns3 run scratch/flow2final.cc''' | || Type ./'''ns3 run scratch/flow2final.cc''' | ||
Line 191: | Line 191: | ||
We also see the''' throughput''' and''' delay''' of the flow. | We also see the''' throughput''' and''' delay''' of the flow. | ||
|- | |- | ||
− | |- | + | |- |
|| 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 198: | ||
In this tutorial, we have | 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''' | || Show Slide:''' Assignment''' | ||
|| As an assignment, please do the following: | || 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: | || 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'''. | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
Line 225: | Line 225: | ||
Please download and watch it. | Please download and watch it. | ||
− | |- | + | |- |
|| Show Slide: | || Show Slide: | ||
Line 232: | Line 232: | ||
For more details, please write to us. | For more details, please write to us. | ||
− | |- | + | |- |
|| 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. | ||
− | |- | + | |- |
|| 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 | ||
− | |- | + | |- |
|| Show Slide: '''Acknowledgement''' | || Show Slide: '''Acknowledgement''' | ||
− | || | + | ||'''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''. |
− | |- | + | |- |
|| Show Slide: '''Acknowledgement''' | || 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 | || Show Slide: Thank you | ||
− | || | + | ||This is '''Arun Santhosh''', a FOSSEE Summer Fellow 2023, IIT Bombay signing off. |
− | + | Thank you for joining. | |
|- | |- | ||
|} | |} |
Revision as of 12:59, 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
|
Show Slide:
System Requirements |
To record this tutorial, I am using
|
Show slide:
Pre-requisites |
To follow this tutorial
|
Show Slide:
Code Files |
|
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.
|
Open code editor | I have created the source file flow2final.cc for this program.
The source code contains the required functions to create,
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.
Now close the text editor. |
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 run 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
|
Show Slide: Assignment | As an assignment, please do the following:
|
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. |