Difference between revisions of "Ns-3-Network-Simulator/C2/Connecting-multiple-networks-with-routers/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''' <div style="color:#000000;">'''Welcome'''</div> || <span style="color:#000000;">Welcome to the...")
 
 
Line 7: Line 7:
 
|| '''Narration'''
 
|| '''Narration'''
 
|-
 
|-
|| '''Slide:1'''
+
|| ''' Show slide'''
  
<div style="color:#000000;">'''Welcome'''</div>
+
'''Welcome'''
|| <span style="color:#000000;">Welcome to the spoken tutorial on </span><span style="color:#000000;">'''connecting multiple networks with </span>router'''.
+
|| Welcome to the spoken tutorial on '''Connecting Multiple Networks with Router'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| Show s<span style="color:#000000;">lide:</span>
+
|| Show slide:
  
<div style="color:#000000;">'''Learning Outcomes'''</div>
+
'''Learning Outcomes'''
 
|| 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 with 4 nodes</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Create a '''CSMA''' bus topology with 4 nodes</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Configure client and server applications on the nodes</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Connect two networks </div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Route packets from one network to the other</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">Visualize the network using '''NetAnim'''</div>
 
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
* Create a '''star''' topology with 4 nodes
|| Show slide:
+
* Create a '''CSMA''' bus topology with 4 nodes
 +
* Configure client and server applications on the nodes
 +
* Connect two networks
 +
* Route packets from one network to the other
 +
* Visualize the network using '''NetAnim'''
 +
 
 +
|-
 +
|| '''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>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">'''ns-3.38'''</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">'''NetAnim '''visualizer tool</div>
 
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
* '''Ubuntu Linux 22.04 OS'''
|| Show slide:  
+
* '''ns-3.38'''
 +
* '''NetAnim '''visualizer tool
 +
 
 +
|-
 +
|| '''Show slide''':  
  
 
'''Prerequisite'''
 
'''Prerequisite'''
  
<div style="color:#000000;">[https://www.spoken-tutorial.org/ https://www.spoken-tutorial.org]</div>
+
[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 using Linux terminal</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">You must know how to create a '''point-to-point''' and '''CSMA''' network in '''ns-3'''</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">For pre-requisite Linux and '''ns-3 '''tutorials, please visit this website</div>
 
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
* You must have basic knowledge of using Linux terminal
|| Show slide:
+
* You must know how to create a '''point-to-point''' and '''CSMA''' network in '''ns-3'''
 +
 
 +
* For pre-requisite Linux and '''ns-3 ''' tutorials, please visit this website
 +
 
 +
|-
 +
|| '''Show slide''':
  
 
'''Code files'''
 
'''Code files'''
 
||  
 
||  
* <div style="margin-left:1.27cm;margin-right:0cm;">The files used in this tutorial are provided in the '''Code files''' link.</div>
+
* The files used in this tutorial are provided in the '''Code files''' link.
* <div style="margin-left:1.27cm;margin-right:0cm;">Please download and extract the files.</div>
+
* Please download and extract the files.
* <div style="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: Network topology with a '''star '''and a '''CSMA '''network
 
|| Show diagram: Network topology with a '''star '''and a '''CSMA '''network
 
|| For this tutorial, we would be creating the following topology:
 
|| For this tutorial, we would be creating the following topology:
* <div style="margin-left:1.27cm;margin-right:0cm;">A '''star''' network topology with 4 nodes and network address 10.1.1.0</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">A '''CSMA''' '''bus''' network topology with 4 nodes and 10.2.0.0 address</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">A '''point-to-point''' network between the two networks, with address 10.3.0.0</div>
 
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
* A '''star''' network topology with 4 nodes and network address 10.1.1.0
 +
* A '''CSMA''' '''bus''' network topology with 4 nodes and 10.2.0.0 address
 +
* A '''point-to-point''' network between the two networks, with address 10.3.0.0.
 +
 
 +
|-
 
|| Open the file '''router.cc '''in the text editor.
 
|| Open the file '''router.cc '''in the text editor.
 
|| I have already created the source file '''router.cc''' for this program.
 
|| I have already created the source file '''router.cc''' for this program.
Line 68: Line 73:
  
 
The source code creates a star, and a CSMA network.
 
The source code creates a star, and a CSMA network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| H<span style="color:#000000;">ighlight </span><span style="color:#000000;">'''uint32_t nCsma = 3'''</span>
+
|| Highlight '''uint32_t nCsma = 3'''
|| First, w<span style="color:#000000;">e set the number of nodes in the </span><span style="color:#000000;">'''CSMA'''</span><span style="color:#000000;"> network to 3.</span>
+
|| First, we set the number of nodes in the '''CSMA''' network to 3.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| H<span style="color:#000000;">ighlight </span><span style="color:#000000;">'''uint32_t nSpokes = 4'''</span>
+
|| Highlight '''uint32_t nSpokes = 4'''
|| Then we set <span style="color:#000000;">the number of nodes in the </span><span style="color:#000000;">'''star'''</span><span style="color:#000000;"> network to 4.</span>
+
|| Then we set the number of nodes in the '''star''' network to 4.
  
 
These variables can be named as per your program.
 
These variables can be named as per your program.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));'''
 
|| Highlight '''pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"));'''
  
Line 83: Line 88:
 
The '''data rate '''for the point-to-point connections is set to 5 mbps.
 
The '''data rate '''for the point-to-point connections is set to 5 mbps.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));'''
 
|| Highlight '''pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));'''
  
 
'''uint16_t port = 50000;'''
 
'''uint16_t port = 50000;'''
 
|| The channel '''delay''' is set to 2 milliseconds.
 
|| The channel '''delay''' is set to 2 milliseconds.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''uint16_t port = 50000;'''
 
|| Highlight '''uint16_t port = 50000;'''
  
 
|| The hub’s '''port''' is set to 50000.
 
|| The hub’s '''port''' is set to 50000.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| H<span style="color:#000000;">ighlight </span><span style="color:#000000;">'''PointToPointStarHelper star(nSpokes, pointToPoint)'''</span>
+
|| Highlight '''PointToPointStarHelper star(nSpokes, pointToPoint)'''
|| <span style="color:#000000;">Then we create a </span><span style="color:#000000;">'''PointToPointStarHelper'''</span><span style="color:#000000;"> object to create a star network.</span>
+
|| Then we create a '''PointToPointStarHelper''' object to create a star network.
  
 
The '''PointToPointStarHelper '''class is a helper class for initializing star networks.
 
The '''PointToPointStarHelper '''class is a helper class for initializing star networks.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''star.InstallStack'''
 
|| Highlight '''star.InstallStack'''
|| The '''InstallStack '''method installs an internet stack on the nodes.
+
|| The '''InstallStack ''' method installs an internet stack on the nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''star.AssignIpv4Addresses'''
 
|| Highlight '''star.AssignIpv4Addresses'''
|| The '''AssignIpv4Addresses '''method assigns IP addresses to the nodes.
+
|| The '''AssignIpv4Addresses ''' method assigns IP addresses to the nodes.
  
Here <span style="color:#000000;">we assign IP address 10.1.1.0 to the </span><span style="color:#000000;">'''star'''</span><span style="color:#000000;"> network.</span>
+
Here we assign IP address 10.1.1.0 to the '''star''' network.
|- 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'''
|| '''PacketSinkHelper '''class is used to install a packet sink on the hub.
+
|| '''PacketSinkHelper ''' class is used to install a packet sink on the hub.
  
A '''packet sink '''enables the hub to receive packets from other nodes.
+
A '''packet sink ''' enables the hub to receive packets from other nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''hubApp.Start '''and '''hubApp.Stop'''
 
|| Highlight '''hubApp.Start '''and '''hubApp.Stop'''
|| Here we s<span style="color:#000000;">et the start and stop times for the hub.</span>
+
|| Here we set the start and stop times for the hub.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''NodeContainer p2pNodes'''
 
|| Highlight '''NodeContainer p2pNodes'''
|| <span style="color:#000000;">Then we create a node container for the </span><span style="color:#000000;">'''point-to-point'''</span><span style="color:#000000;"> </span>network.
+
|| Then we create a node container for the '''point-to-point''' network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''p2pNodes.Add(star.GetSpokeNode(3))'''
 
|| Highlight '''p2pNodes.Add(star.GetSpokeNode(3))'''
 
|| Add the 4<sup>th</sup> node with index 3 to the node container.
 
|| Add the 4<sup>th</sup> node with index 3 to the node container.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''p2pNodes.Create(1)'''
 
|| Highlight '''p2pNodes.Create(1)'''
|| Create one node using the '''Create '''method.
+
|| Create one node using the '''Create ''' method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''NodeContainer csmaNodes'''
 
|| Highlight '''NodeContainer csmaNodes'''
|| <span style="color:#000000;">Similarly create a node container for the </span><span style="color:#000000;">'''CSMA'''</span><span style="color:#000000;"> network.</span>
+
|| Similarly create a node container for the '''CSMA''' network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''csmaNodes.Add(p2pNodes.Get(1))'''
 
|| Highlight '''csmaNodes.Add(p2pNodes.Get(1))'''
 
|| Add the previously created node in the '''point-to-point''' network to the container.
 
|| Add the previously created node in the '''point-to-point''' network to the container.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''csmaNodes.Create(nCsma)'''
 
|| Highlight '''csmaNodes.Create(nCsma)'''
|| Then create additional nodes using the '''Create '''method.
+
|| Then create additional nodes using the '''Create ''' method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''pointToPoint.Install(p2pNodes)'''
 
|| Highlight '''pointToPoint.Install(p2pNodes)'''
|| <span style="color:#000000;">Next, install net devices on the </span><span style="color:#000000;">'''point-to-point'''</span><span style="color:#000000;"> network nodes.</span>
+
|| Next, install net devices on the '''point-to-point''' network nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''csma.SetChannelAttribute'''
 
|| Highlight '''csma.SetChannelAttribute'''
|| Set the '''DataRate '''and '''Delay '''attributes for the channel.
+
|| Set the '''DataRate ''' and '''Delay ''' attributes for the channel.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''csma.Install(csmaNodes)'''
 
|| Highlight '''csma.Install(csmaNodes)'''
|| <span style="color:#000000;">Similarly install net devices on the </span><span style="color:#000000;">'''CSMA'''</span><span style="color:#000000;"> network nodes.</span>
+
|| Similarly install net devices on the '''CSMA''' network nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''stack.Install(csmaNodes)'''
 
|| Highlight '''stack.Install(csmaNodes)'''
|| <span style="color:#000000;">Then </span>install an internet<span style="color:#000000;"> stack on the </span><span style="color:#000000;">'''CSMA'''</span><span style="color:#000000;"> network nodes.</span>
+
|| Then install an internet stack on the '''CSMA''' network nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''address.Assign(p2pDevices)'''
 
|| Highlight '''address.Assign(p2pDevices)'''
|| <span style="color:#000000;">Now we assign the address 10.3.0.0 to the </span><span style="color:#000000;">'''Point-to-Point'''</span><span style="color:#000000;"> network. </span>
+
|| Now we will assign the address 10.3.0.0 to the '''Point-to-Point''' network.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''address.Assign(csmaDevices)'''
 
|| Highlight '''address.Assign(csmaDevices)'''
 
|| And assign the address 10.2.0.0 to the '''CSMA''' network.
 
|| And assign the address 10.2.0.0 to the '''CSMA''' network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''echoServer.Install(csmaNodes.Get(2))'''
 
|| Highlight '''echoServer.Install(csmaNodes.Get(2))'''
|| <span style="color:#000000;">Next we install an echo server application on the third node of the </span><span style="color:#000000;">'''CSMA'''</span><span style="color:#000000;"> network</span>.
+
|| Next we install an echo server application on the third node of the '''CSMA''' network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Only narration
 
|| Only narration
 
|| By zero indexing, its index is 2.
 
|| By zero indexing, its index is 2.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''serverApps.Start(Seconds(1.0))'''
 
|| Highlight '''serverApps.Start(Seconds(1.0))'''
|| Now s<span style="color:#000000;">et the start of the server application to 1 second</span>.  
+
|| Now set the start of the server application to 1 second.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''serverApps.Stop(Seconds(10.0))'''
 
|| Highlight '''serverApps.Stop(Seconds(10.0))'''
 
|| Next, set the stop time to 10 seconds after the start of the simulation.
 
|| Next, set the stop time to 10 seconds after the start of the simulation.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''echoClient(csmaInterfaces.GetAddress(2), 9);'''
 
|| Highlight '''echoClient(csmaInterfaces.GetAddress(2), 9);'''
|| <span style="color:#000000;">Similarly, </span>we <span style="color:#000000;">install an echo client application.</span>
+
|| Similarly, we install an echo client application.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Only narration
 
|| Only narration
 
|| The target server is node 3 of the '''CSMA''' network.  
 
|| The target server is node 3 of the '''CSMA''' network.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Only narration
 
|| Only narration
 
|| The port is set to 9.
 
|| The port is set to 9.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight '''echoClient.Install(star.GetSpokeNode(1))'''
 
|| Highlight '''echoClient.Install(star.GetSpokeNode(1))'''
|| Then we <span style="color:#000000;">Install the client application on node 2 of the </span><span style="color:#000000;">'''star'''</span><span style="color:#000000;"> network.</span>
+
|| Then we Install the client application on node 2 of the '''star''' network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| Highlight <span style="color:#000000;">'''PopulateRoutingTables()'''</span>
+
|| Highlight '''PopulateRoutingTables()'''
 
|| The '''PopulateRoutingTables '''method of the '''Ipv4GlobalRoutingHelper '''class enables routing.  
 
|| The '''PopulateRoutingTables '''method of the '''Ipv4GlobalRoutingHelper '''class enables routing.  
  
It builds a routing database and initializes the routing tables.
+
|-
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|| Highlight '''BoundingBox'''
|| H<span style="color:#000000;">ighlight </span><span style="color:#000000;">'''BoundingBox'''</span>
+
 
|| The '''BoundingBox''' method sets the positions for the nodes of the star network.
 
|| The '''BoundingBox''' method sets the positions for the nodes of the star network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| H<span style="color:#000000;">ighlight </span>'''AnimationInterface anim ("router.xml")'''
+
|| Highlight '''AnimationInterface anim ("router.xml")'''
 
|| Next we specify the name for the '''XML''' output file.
 
|| Next we specify the name for the '''XML''' output file.
  
 
Here the name of the file is '''router.xml.'''
 
Here the name of the file is '''router.xml.'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
 
|| Highlight the lines:
 
|| Highlight the lines:
  
Line 198: Line 202:
  
 
|| Then we set the position of the nodes using the '''SetConstantPosition '''method.
 
|| Then we set the position of the nodes using the '''SetConstantPosition '''method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| Highlight <span style="color:#000000;">'''Simulator::Run()'''</span>
+
|| Highlight '''Simulator::Run()'''
|| <span style="color:#000000;">The </span><span style="color:#000000;">'''Run'''</span><span style="color:#000000;"> function is used to run the simulation.</span>
+
|| 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;"
+
|-
|| H<span style="color:#000000;">ighlight </span><span style="color:#000000;">'''Simulator::Destroy()'''</span>
+
|| Highlight '''Simulator::Destroy()'''
|| The '''Destroy<span style="color:#000000;"> '''</span><span style="color:#000000;">function ends the simulation.</span>
+
|| The '''Destroy '''function ends the simulation.
  
 
Now close the text editor.
 
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
+
  
 
Type '''cd ns-allinone-3.38/ns-3.38 '''to navigate to the ns3 installation directory
 
Type '''cd ns-allinone-3.38/ns-3.38 '''to navigate to the ns3 installation directory
Line 215: Line 217:
 
Type '''mv ~/Downloads/router.cc scratch/router.cc '''to move the source file to '''scratch '''directory.
 
Type '''mv ~/Downloads/router.cc scratch/router.cc '''to move the source file to '''scratch '''directory.
  
|| <div style="color:#000000;">Now we will observe the simulation.</div>
+
|| 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 226: Line 228:
  
 
The '''ns3 '''batch file is configured to run files from the '''scratch '''directory.
 
The '''ns3 '''batch file is configured to run files from the '''scratch '''directory.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="color:#000000;">Type ./</span><span style="color:#000000;">'''ns3 run scratch/router.cc'''</span>
+
|| Type ./'''ns3 run scratch/router.cc'''
|| R<span style="color:#000000;">un the command </span>'''dot forward slash <span style="color:#000000;">ns3 run scratch</span> forward slash <span style="color:#000000;">router'''</span>.
+
|| Run the command '''dot forward slash ns3 space run space scratch forward slash router'''.
  
 
'''router dot cc''' is the name of the source file.  
 
'''router dot cc''' is the name of the source file.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Keep the terminal open and show the output of the command  
+
|| Keep the terminal open and show the output of the command  
|| <span style="color:#000000;">After compilation, we get the details of each packet transfer</span>.
+
|| After compilation, we get the details of each packet transfer.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="color:#000000;">Navigate to </span><span style="color:#000000;">'''netanim-3.10</span>9<span style="color:#000000;"> '''</span><span style="color:#000000;">directory under </span><span style="color:#000000;">'''ns-allinone-3.38'''</span>
+
|| Navigate to '''netanim-3.109 '''directory under '''ns-allinone-3.38'''
  
|| <span style="color:#000000;">Now, to visualize the network, we will use </span><span style="color:#000000;">'''NetAnim'''</span><span style="color:#000000;">.</span>
+
|| Now, to visualize the network, we will use '''NetAnim'''.
  
 
Navigate to the '''netanim-3.109 '''directory under '''ns-allinone-3.38'''
 
Navigate to the '''netanim-3.109 '''directory under '''ns-allinone-3.38'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="color:#000000;">Type ./</span><span style="color:#000000;">'''NetAnim'''</span>
+
|| Type ./'''NetAnim'''
|| <span style="color:#000000;">Now type </span>'''dot slash <span style="color:#000000;">NetAnim. '''</span>
+
|| Now type '''dot slash NetAnim. '''
  
<span style="color:#000000;">The </span><span style="color:#000000;">'''NetAnim'''</span><span style="color:#000000;"> window </span>will <span style="color:#000000;">open.</span>
+
The '''NetAnim''' window will open.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="color:#000000;">Click </span>on the Open<span style="color:#000000;">''' XML trace file '''</span><span style="color:#000000;">icon </span>on the top<span style="color:#000000;"> left corner of the window.</span>
+
|| Click on the Open''' XML trace file '''icon on the top left corner of the window.
|| <span style="color:#000000;">Click </span>on the Open<span style="color:#000000;">''' XML trace file '''</span><span style="color:#000000;">icon </span>on the top<span style="color:#000000;"> left corner of the window.</span>
+
|| Click on the Open''' XML trace file '''icon on the top left corner of the window.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="color:#000000;">In the file picker, navigate to the </span><span style="color:#000000;">'''ns-allinone-3.38/ns-3.38 '''</span><span style="color:#000000;">directory and select the </span><span style="color:#000000;">'''router.xml '''</span><span style="color:#000000;">file.</span>
+
|| In the file picker, navigate to the '''ns-allinone-3.38/ns-3.38 '''directory and select the '''router.xml '''file.
|| <span style="color:#000000;">In the file picker, navigate to the </span><span style="color:#000000;">'''ns-allinone-3.38/ns-3.38 '''</span><span style="color:#000000;">directory</span>.
+
|| In the file picker, navigate to the '''ns-allinone-3.38/ns-3.38 '''directory.
  
 
Select the '''router dot xml '''file.
 
Select the '''router dot xml '''file.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <span style="color:#000000;">On the toolbar, click on the </span><span style="color:#000000;">'''Node Size '''</span><span style="color:#000000;">drop down button, and select size 10.</span>
+
|| On the toolbar, click on the '''Node Size '''drop down button, select size 10.
|| <span style="color:#000000;">On the toolbar, click on the </span><span style="color:#000000;">'''Node Size '''</span><span style="color:#000000;">drop down button</span>.
+
|| On the toolbar, click on the '''Node Size '''drop down button.
  
 
Select size 10.
 
Select size 10.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | On the toolbar, click on the play button
+
|| On the toolbar, click on the play button
|| <div style="color:#000000;">On the toolbar, click on the play animation button to view the simulation.</div>
+
|| On the toolbar, click on the play animation button to view the simulation.
  
 
We see here that the circles represent the nodes.  
 
We see here that the circles represent the nodes.  
Line 268: Line 270:
 
We see that the hub is connected to all the nodes of the star network.  
 
We see that the hub is connected to all the nodes of the star network.  
  
The directed lines show the packet transfers between the networks.
+
The directed line show the packet transfers between the networks.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| Show slide:<span style="color:#000000;"> </span>
+
|| '''Show slide''':  
  
'''S<span style="color:#000000;">ummary'''</span>
+
'''Summary'''
 
|| This brings us to the end of the tutorial. Let us summarize.
 
|| This brings us to the end of the tutorial. Let us summarize.
  
 
In this tutorial, we have learnt to
 
In this tutorial, we have learnt to
* <div style="margin-left:1.27cm;margin-right:0cm;">Create a '''star''' topology with 4 nodes</div>
+
* Create a '''star''' topology with 4 nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">Create a '''CSMA''' bus topology with 4 nodes</div>
+
* Create a '''CSMA''' bus topology with 4 nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">Configure client and server applications on the nodes</div>
+
* Configure client and server applications on the nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">Connect two networks </div>
+
* Connect two networks  
* <div style="margin-left:1.27cm;margin-right:0cm;">Route packets from one network to the other</div>
+
* Route packets from one network to the other
* <div style="margin-left:1.27cm;margin-right:0cm;">Visualize the network using '''NetAnim'''</div>
+
* Visualize the network using '''NetAnim'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| Show s<span style="color:#000000;">lide: </span>
+
|| '''Show slide''':  
  
<div style="color:#000000;">'''Assignment'''</div>
+
'''Assignment'''
|| As an assignment, please do the following:* <div style="margin-left:1.27cm;margin-right:0cm;">Write an '''ns-3 '''program with two '''CSMA '''networks</div>
+
|| As an assignment, please do the following:* Write an '''ns-3 '''program with two '''CSMA '''networks
* <div style="margin-left:1.27cm;margin-right:0cm;">Both networks should have 4 nodes</div>
+
* Both networks should have 4 nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">Assign '''IP address '''10.1.0.0 to first network</div>
+
* Assign '''IP address '''10.1.0.0 to first network
* <div style="margin-left:1.27cm;margin-right:0cm;">Assign '''IP address '''10.2.0.0 to second network</div>
+
* Assign '''IP address '''10.2.0.0 to second network
* <div style="margin-left:1.27cm;margin-right:0cm;">Route packets from node 2 of the first network to node 3 of the second network</div>
+
* Route packets from node 2 of the first network to node 3 of the second network
  
|- 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
Line 300: Line 302:
  
 
Observe the transfer of packets between the networks.
 
Observe the transfer of packets between the networks.
|- 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
Line 307: Line 309:
  
 
On playing the animation, the arrows will show the direction of packet transfer.
 
On playing the animation, the arrows will show the direction of packet transfer.
|- 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;">The video at the following link summarizes the </span><span style="background-color:#ffffff;">'''Spoken Tutorial project'''</span><span style="background-color:#ffffff;">.</span>
+
|| The video at the following link summarizes the '''Spoken Tutorial project'''.
 
+
 
Please download and watch it.
 
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;">The </span><span style="background-color:#ffffff;">'''Spoken Tutorial Project'''</span><span style="background-color:#ffffff;"> team conducts workshops and gives certificates.</span>
+
|| The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.
  
 
For more details, please write to us.
 
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="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'''.
  
<div style="color:#252525;"></div>
+
 
|- 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="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 </span><span style="color:#252525;">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: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;">'''Josiga, '''</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 18:04, 13 March 2024


Visual Cue Narration
Show slide

Welcome

Welcome to the spoken tutorial on Connecting Multiple Networks with Router.
Show slide:

Learning Outcomes

In this tutorial, we will learn to
  • Create a star topology with 4 nodes
  • Create a CSMA bus topology with 4 nodes
  • Configure client and server applications on the nodes
  • Connect two networks
  • Route packets from one network to the other
  • Visualize the network using NetAnim
Show slide:

System Requirements

To record this tutorial, I am using:
  • Ubuntu Linux 22.04 OS
  • ns-3.38
  • NetAnim visualizer tool
Show slide:

Prerequisite

https://www.spoken-tutorial.org

To follow this tutorial:
  • You must have basic knowledge of using Linux terminal
  • You must know how to create a point-to-point and CSMA network in ns-3
  • 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 a star and a CSMA network For this tutorial, we would be creating the following topology:
  • A star network topology with 4 nodes and network address 10.1.1.0
  • A CSMA bus network topology with 4 nodes and 10.2.0.0 address
  • A point-to-point network between the two networks, with address 10.3.0.0.
Open the file router.cc in the text editor. I have already created the source file router.cc for this program.

Now we will go through the source code in the text editor.

It contains the required functions to implement routing.

The source code creates a star, and a CSMA network.

Highlight uint32_t nCsma = 3 First, we set the number of nodes in the CSMA network to 3.
Highlight uint32_t nSpokes = 4 Then we set the number of nodes in the star network to 4.

These variables can be named as per your program.

Highlight pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps")); We will set the following parameters for the star network.

The data rate for the point-to-point connections is set to 5 mbps.

Highlight pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"));

uint16_t port = 50000;

The channel delay is set to 2 milliseconds.
Highlight uint16_t port = 50000; The hub’s port is set to 50000.
Highlight PointToPointStarHelper star(nSpokes, pointToPoint) Then we create a PointToPointStarHelper object to create a star network.

The PointToPointStarHelper class is a helper class for initializing star networks.

Highlight star.InstallStack The InstallStack method installs an internet stack on the nodes.
Highlight star.AssignIpv4Addresses The AssignIpv4Addresses method assigns IP addresses to the nodes.

Here we assign IP address 10.1.1.0 to the star network.

Highlight packetSinkHelper.Install PacketSinkHelper class is used to install a packet sink on the hub.

A packet sink enables the hub to receive packets from other nodes.

Highlight hubApp.Start and hubApp.Stop Here we set the start and stop times for the hub.
Highlight NodeContainer p2pNodes Then we create a node container for the point-to-point network.
Highlight p2pNodes.Add(star.GetSpokeNode(3)) Add the 4th node with index 3 to the node container.
Highlight p2pNodes.Create(1) Create one node using the Create method.
Highlight NodeContainer csmaNodes Similarly create a node container for the CSMA network.
Highlight csmaNodes.Add(p2pNodes.Get(1)) Add the previously created node in the point-to-point network to the container.
Highlight csmaNodes.Create(nCsma) Then create additional nodes using the Create method.
Highlight pointToPoint.Install(p2pNodes) Next, install net devices on the point-to-point network nodes.
Highlight csma.SetChannelAttribute Set the DataRate and Delay attributes for the channel.
Highlight csma.Install(csmaNodes) Similarly install net devices on the CSMA network nodes.
Highlight stack.Install(csmaNodes) Then install an internet stack on the CSMA network nodes.
Highlight address.Assign(p2pDevices) Now we will assign the address 10.3.0.0 to the Point-to-Point network.
Highlight address.Assign(csmaDevices) And assign the address 10.2.0.0 to the CSMA network.
Highlight echoServer.Install(csmaNodes.Get(2)) Next we install an echo server application on the third node of the CSMA network.
Only narration By zero indexing, its index is 2.
Highlight serverApps.Start(Seconds(1.0)) Now set the start of the server application to 1 second.
Highlight serverApps.Stop(Seconds(10.0)) Next, set the stop time to 10 seconds after the start of the simulation.
Highlight echoClient(csmaInterfaces.GetAddress(2), 9); Similarly, we install an echo client application.
Only narration The target server is node 3 of the CSMA network.
Only narration The port is set to 9.
Highlight echoClient.Install(star.GetSpokeNode(1)) Then we Install the client application on node 2 of the star network.
Highlight PopulateRoutingTables() The PopulateRoutingTables method of the Ipv4GlobalRoutingHelper class enables routing.
Highlight BoundingBox The BoundingBox method sets the positions for the nodes of the star network.
Highlight AnimationInterface anim ("router.xml") Next we specify the name for the XML output file.

Here the name of the file is router.xml.

Highlight the lines:

anim.SetConstantPosition(p2pNodes.Get(1),400,200);

anim.SetConstantPosition(csmaNodes.Get(1),600,150);

anim.SetConstantPosition(csmaNodes.Get(2),700,150);

anim.SetConstantPosition(csmaNodes.Get(3),700,150);

Then we set the position of the nodes using the SetConstantPosition method.
Highlight Simulator::Run() The Run function is used to run the simulation.
Highlight Simulator::Destroy() The Destroy function ends the simulation.

Now close the text editor.

Press Ctrl,Alt and T keys

Type cd ns-allinone-3.38/ns-3.38 to navigate to the ns3 installation directory

Type mv ~/Downloads/router.cc scratch/router.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.

The ns3 batch file is configured to run files from the scratch directory.

Type ./ns3 run scratch/router.cc Run the command dot forward slash ns3 space run space scratch forward slash router.

router dot cc is the name of the source file.

Keep the terminal open and show the output of the command After compilation, we get the details of each packet transfer.
Navigate to netanim-3.109 directory under ns-allinone-3.38 Now, to visualize the network, we will use NetAnim.

Navigate to the netanim-3.109 directory under ns-allinone-3.38

Type ./NetAnim Now type dot slash NetAnim.

The NetAnim window will open.

Click on the Open XML trace file icon on the top left corner of the window. Click on the Open XML trace file icon on the top left corner of the window.
In the file picker, navigate to the ns-allinone-3.38/ns-3.38 directory and select the router.xml file. In the file picker, navigate to the ns-allinone-3.38/ns-3.38 directory.

Select the router dot xml file.

On the toolbar, click on the Node Size drop down button, select size 10. On the toolbar, click on the Node Size drop down button.

Select size 10.

On the toolbar, click on the play button On the toolbar, click on the play animation button to view the simulation.

We see here that the circles represent the nodes.

The lines represent the connection between the nodes.

We see that the hub is connected to all the nodes of the star network.

The directed line show the packet transfers between the networks.

Show slide:

Summary

This brings us to the end of the tutorial. Let us summarize.

In this tutorial, we have learnt to

  • Create a star topology with 4 nodes
  • Create a CSMA bus topology with 4 nodes
  • Configure client and server applications on the nodes
  • Connect two networks
  • Route packets from one network to the other
  • Visualize the network using NetAnim
Show slide:

Assignment

As an assignment, please do the following:* Write an ns-3 program with two CSMA networks
  • Both networks should have 4 nodes
  • Assign IP address 10.1.0.0 to first network
  • Assign IP address 10.2.0.0 to second network
  • Route packets from node 2 of the first network to node 3 of the second network
Show slide:

Assignment - Observation

In the terminal, you will get this output.

Observe the transfer of packets between the networks.

Show slide:

Assignment - Observation

In the window, you can observe two CSMA networks.

On playing the animation, the arrows will show the direction of packet transfer.

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