Difference between revisions of "Ns-3-Network-Simulator/C2/CSMA-based-network-with-bus-topology/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with " {| border="1" |- || '''Visual Cue''' || '''Narration''' |- || '''Slide:1''' | style="color:#000000;" | Welcome to Spoken tutorial on '''CSMA based network with bus topology''...")
 
Line 6: Line 6:
 
|-
 
|-
 
|| '''Slide:1'''
 
|| '''Slide:1'''
| style="color:#000000;" | Welcome to Spoken tutorial on '''CSMA based network with bus topology'''.
+
|| Welcome to Spoken tutorial on '''CSMA based network with bus topology'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Show Slide:</div>
+
|| Show Slide:
  
<div style="color:#000000;">'''Learning Objectives'''</div>
+
'''Learning Objectives'''
 
|| In this tutorial, we will learn to
 
|| In this tutorial, we will learn to
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Create a '''CSMA''' based '''bus topology''' with '''10 nodes'''</div>
+
* Create a '''CSMA''' based '''bus topology''' with '''10 nodes'''
* <div style="color:#000000;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="color:#000000;margin-left:1.27cm;margin-right:0cm;">Connect the two nodes and routing packets from one node to the other</div>
+
* Connect the two nodes and routing packets from one node to the other
* <div style="color:#000000;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 Slide:  
|| <div style="color:#000000;">Show Slide: </div>
+
  
<div style="color:#000000;">'''System Requirements'''</div>
+
'''System Requirements'''
 
|| To record this tutorial, I am using
 
|| To record this tutorial, I am using
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">'''Ubuntu Linux OS''' version '''22.04'''</div>
+
* '''Ubuntu Linux OS''' version '''22.04'''
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">'''ns-3 '''version 3.38.</div>
+
* '''ns-3 '''version 3.38.
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">'''NetAnim''' visualizer tool.</div>
+
* '''NetAnim''' visualizer tool.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Show slide:</div>
+
|| Show slide:
  
<div style="color:#000000;">'''Pre-requisites'''</div>
+
'''Pre-requisites'''
 
|| To follow this tutorial:
 
|| To follow this tutorial:
* <div style="color:#000000;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="color:#000000;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;"><span style="color:#000000;">For pre-requisite Linux and ns-3 tutorials, please visit this website </span>[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;"
 
|- style="border:0.6pt solid #808080;padding:0.176cm;"
|| <div style="color:#000000;">Show Slide:</div>
+
|| Show Slide:
  
<div style="color:#000000;">'''Code Files'''</div>
+
'''Code Files'''
 
||  
 
||  
* <div style="color:#000000;margin-left:1.87cm;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="color:#000000;margin-left:1.87cm;margin-right:0cm;">Please download and extract the files.</div>
+
* Please download and extract the files.
* <div style="color:#000000;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;"
+
|-
|| <div style="color:#000000;">Show Slide: </div>
+
|| Show Slide:  
  
<div style="color:#000000;">'''Bus topology'''</div>
+
'''Bus topology'''
|| <div style="color:#000000;">For this tutorial, we would be creating the following topology.</div>
+
|| For this tutorial, we would be creating the following topology.
  
<div style="color:#000000;">A bus network topology with '''10 nodes''' and network address '''10.1.1.0.'''</div>
+
A bus network topology with '''10 nodes''' and network address '''10.1.1.0.'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Open '''csma_performance.cc''' source file
+
|| Open '''csma_performance.cc''' source file
|| <div style="color:#000000;">I have created the source file '''csma_performance.cc'''. for this program.</div>
+
|| I have created the source file '''csma_performance.cc'''. for this program.
  
<div style="color:#000000;">The source code contains the required functions to implement a '''CSMA''' based''' bus topology'''.</div>
+
The source code contains the required functions to implement a '''CSMA''' based''' bus topology'''.
  
<div style="color:#000000;">Here, I have routed the packets from the '''first node''' to the '''tenth node'''.</div>
+
Here, I have routed the packets from the '''first node''' to the '''tenth node'''.
  
<div style="color:#000000;">Now we will go through the source code for the program. </div>
+
Now we will go through the source code for the program.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''uint32_t nCsma = 10'''
+
|| Highlight '''uint32_t nCsma = 10'''
| style="color:#000000;" | We set the number of nodes in the '''CSMA '''network to 10.
+
|| We set the number of nodes in the '''CSMA '''network to 10.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''double trans_time_1'''
+
|| Highlight '''double trans_time_1'''
| style="color:#000000;" | This represents the transmission time '''at the client'''.
+
|| This represents the transmission time '''at the client'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''double rec_time_1'''
+
|| Highlight '''double rec_time_1'''
| style="color:#000000;" | This defines the receiving time at the server
+
|| This defines the receiving time at the server
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Highlight the line '''static void'''</div>
+
|| Highlight the line '''static void'''
  
<div style="color:#000000;">'''TxTraceClient'''</div>
+
'''TxTraceClient'''
  
| style="color:#000000;" | This is the function created to '''trace''' the '''client application'''.
+
|| This is the function created to '''trace''' the '''client application'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''if (context[10] == '0')'''
+
|| Highlight '''if (context[10] == '0')'''
| style="color:#000000;" | We use '''context '''to find which node has transmitted the packet.
+
|| We use '''context '''to find which node has transmitted the packet.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''trans_time_1 = Simulator::Now().GetSeconds();'''
+
|| Highlight '''trans_time_1 = Simulator::Now().GetSeconds();'''
| style="color:#000000;" | We shall define the '''transmission time''' by getting the current time in seconds from the simulator
+
|| We shall define the '''transmission time''' by getting the current time in seconds from the simulator
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Highlight '''static void'''</div>
+
|| Highlight '''static void'''
  
<div style="color:#000000;">'''RxTraceServer'''</div>
+
'''RxTraceServer'''
| style="color:#000000;" | This is the function created to '''trace''' the '''server application.'''
+
|| This is the function created to '''trace''' the '''server application.'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''if (context[10] == '9')'''
+
|| Highlight '''if (context[10] == '9')'''
| style="color:#000000;" | Here, '''context''' is used to get the''' node ID '''whenever the server gets the packets.
+
|| Here, '''context''' is used to get the''' node ID '''whenever the server gets the packets.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''rec_time_1'''
+
|| Highlight '''rec_time_1'''
| style="color:#000000;" | We then define the receiving time by getting the current time in seconds from the simulator
+
|| We then define the receiving time by getting the current time in seconds from the simulator
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''delay_1 '''and '''(rec_time_1 - trans_time_1)*1000'''.
+
|| Highlight '''delay_1 '''and '''(rec_time_1 - trans_time_1)*1000'''.
| style="color:#000000;" | Next, we use '''delay_1 '''to find the '''delay''' using this formula.  
+
|| Next, we use '''delay_1 '''to find the '''delay''' using this formula.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''if (pkt_cnt_1 == pkts)'''
+
|| Highlight '''if (pkt_cnt_1 == pkts)'''
| style="color:#000000;" | If we have reached the last packet, we have to print the '''parameters'''.
+
|| If we have reached the last packet, we have to print the '''parameters'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''NodeContainer csmaNodes'''
+
|| Highlight '''NodeContainer csmaNodes'''
| style="color:#000000;" | Then, we create a '''node container''' for the CSMA network.
+
|| Then, we 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;"
+
|-
| style="color:#000000;" | Highlight '''csmaNodes.Create(ncsma)'''
+
|| Highlight '''csmaNodes.Create(ncsma)'''
| style="color:#000000;" | Let us create a number of '''CSMA''' nodes assigned earlier using the '''Create() '''method.
+
|| Let us create a number of '''CSMA''' nodes assigned earlier using the '''Create() '''method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Highlight </div>
+
|| Highlight  
  
<div style="color:#000000;">'''CsmaHelper csma'''</div>
+
'''CsmaHelper csma'''
|| <div style="color:#000000;">The '''CsmaHelper''' is a helper class for initializing the '''CSMA''' network.</div>
+
|| The '''CsmaHelper''' is a helper class for initializing the '''CSMA''' network.
  
<div style="color:#000000;">This is the helper class to access the '''CSMA channe'''l created.</div>
+
This is the helper class to access the '''CSMA channe'''l created.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''csma.SetChannelAttribute'''
+
|| Highlight '''csma.SetChannelAttribute'''
 
|| Using the '''setChannelAttribute '''method,let us set the attributes for the CSMA network.
 
|| Using the '''setChannelAttribute '''method,let us set the attributes for the CSMA network.
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">'''Data rate''' 100 Mbps.</div>
+
* '''Data rate''' 100 Mbps.
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Channel '''delay''' 6560 nanoseconds or 0.00656 milliseconds.</div>
+
* Channel '''delay''' 6560 nanoseconds or 0.00656 milliseconds.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''stack.Install(csmaNodes)'''
+
|| Highlight '''stack.Install(csmaNodes)'''
| style="color:#000000;" | This command installs an internet stack on the nodes of the '''CSMA '''bus network.
+
|| This command installs an internet stack on the nodes of the '''CSMA '''bus network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''address.SetBase '''and '''address.Assign(csmaDevices)'''
+
|| Highlight '''address.SetBase '''and '''address.Assign(csmaDevices)'''
|| <div style="color:#000000;">The highlighted command assigns''' IP addresses''' to the nodes of the network. </div>
+
|| The highlighted command assigns''' IP addresses''' to the nodes of the network.  
  
<div style="color:#000000;">Now we set the '''base address'''<span style="background-color:transparent;"> </span><span style="background-color:transparent;">'''10.1.1.0'''</span><span style="background-color:transparent;"> f</span>or the '''bus network. '''</div>
+
Now we set the '''base address'''<span style="background-color:transparent;"> <span style="background-color:transparent;">'''10.1.1.0'''<span style="background-color:transparent;"> for the '''bus network. '''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Highlight <span style="background-color:#ffffff;">'''UdpEchoServerHelper echoServerA(9);'''</span></div>
+
|| Highlight '''UdpEchoServerHelper echoServerA(9);'''
  
|| <div style="color:#000000;">The '''UdpEchoServerHelper''' class is used to install server applications on a node of the network. </div>
+
|| The '''UdpEchoServerHelper''' class is used to install server applications on a node of the network.  
  
<div style="color:#000000;">An''' echo server '''receives a packet from the client.</div>
+
An''' echo server '''receives a packet from the client.
  
<div style="color:#000000;">The received packet is echoed back.</div>
+
The received packet is echoed back.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''echoServer.Install(csmaNodes.Get(9))'''
+
|| Highlight '''echoServer.Install(csmaNodes.Get(9))'''
|| <div style="color:#000000;">The tenth node of the''' CSMA network''' has '''index 9'''.</div>
+
|| The tenth node of the''' CSMA network''' has '''index 9'''.
  
<div style="color:#000000;">Let us '''install''' an '''echo server application '''on the tenth node.</div>
+
Let us '''install''' an '''echo server application '''on the tenth node.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''serverApps.Start(Seconds(1.0))'''
+
|| Highlight '''serverApps.Start(Seconds(1.0))'''
| style="color:#000000;" | Set the '''start''' of the server application to '''1 second'''.  
+
|| 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;"
+
|-
| style="color:#000000;" | Highlight '''serverApps.Stop(Seconds(10.0))'''
+
|| Highlight '''serverApps.Stop(Seconds(10.0))'''
| style="color:#000000;" | The '''stop time''' is '''10 seconds''' after the start of the '''simulation'''.
+
|| The '''stop time''' is '''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;"
+
|-
|| <div style="color:#000000;">Highlight <span style="background-color:#ffffff;">'''UdpEchoClientHelper echoClientA(csmaInterfaces.GetAddress(9), 9);'''</span></div>
+
|| Highlight '''UdpEchoClientHelper echoClientA(csmaInterfaces.GetAddress(9), 9);'''
|| <div style="color:#000000;">The '''UdpEchoClientHelper''' class is used to install client applications on a node of the network. </div>
+
|| The '''UdpEchoClientHelper''' class is used to install client applications on a node of the network.  
  
<div style="color:#000000;">An '''Echo client '''enables the node to send and receive echo packets from the server.</div>
+
An '''Echo client '''enables the node to send and receive echo packets from the server.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''echoClient(csmaInterfaces.GetAddress(9), 9);'''
+
|| Highlight '''echoClient(csmaInterfaces.GetAddress(9), 9);'''
|| <div style="color:#000000;">Let us '''install''' an '''echo client application'''.</div>
+
|| Let us '''install''' an '''echo client application'''.
  
<div style="color:#000000;">The target server is''' node 10''' of the CSMA network.</div>
+
The target server is''' node 10''' of the CSMA network.
  
<div style="color:#000000;">The '''port '''is set to''' 9'''. </div>
+
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;"
+
|-
| style="color:#000000;" | Highlight '''echoClientA.SetAttribute'''
+
|| Highlight '''echoClientA.SetAttribute'''
| style="color:#000000;" | This command is used to set the attributes of the client.
+
|| This command is used to set the attributes of the client.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''PopulateRoutingTables()'''
+
|| Highlight '''PopulateRoutingTables()'''
|| <div style="color:#000000;">Now, for the packets to be routed across the bus network, routing must be enabled.</div>
+
|| Now, for the packets to be routed across the bus network, routing must be enabled.
  
<div style="color:#000000;">To enable '''routing''' across the bus network, we use this method.</div>
+
To enable '''routing''' across the bus network, we use this method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Highlight '''AnimationInterface anim ("csma-performance-analysis.xml")'''
+
|| Highlight '''AnimationInterface anim ("csma-performance-analysis.xml")'''
| style="color:#000000;" | Let us specify the name for the '''XML output file'''.
+
|| Let us specify the name for the '''XML output file'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;">Highlight the lines:</div>
+
|| Highlight the lines:
  
<div style="color:#000000;">'''anim.SetConstantPosition() '''</div>
+
'''anim.SetConstantPosition() '''
| style="color:#000000;" | Set the position of the nodes using the '''SetConstantPosition() '''method.
+
|| 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;"
+
|-
| style="color:#000000;" | Highlight '''Simulator::Run()'''
+
|| Highlight '''Simulator::Run()'''
| style="color:#000000;" | The '''Run()''' function is used to run the simulation.
+
|| 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;"
+
|-
| style="color:#000000;" | Highlight '''Simulator::Destroy()'''
+
|| Highlight '''Simulator::Destroy()'''
|| <div style="color:#000000;">'''Destroy() '''function ends the simulation.</div>
+
|| '''Destroy() '''function ends the simulation.
  
<div style="color:#000000;">Now close the text editor.</div>
+
Now close the text editor.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
|| <div style="color:#000000;"></div>
+
|| Press '''Ctrl, Alt '''and '''T keys''' simultaneously
  
<div style="color:#000000;"></div>
+
Navigate to the '''ns-allinone-3.38/ns3.38 '''directory
  
<div style="color:#000000;">Press '''Ctrl, Alt '''and '''T keys''' simultaneously</div>
 
  
<div style="color:#000000;">Navigate to the '''ns-allinone-3.38/ns3.38 '''directory</div>
+
Type '''mv ~/Downloads/csma_performance.cc scratch/csma_performance.cc '''to move the source file to '''scratch '''directory.
 +
|| Now we will observe the simulation.
  
<div style="color:#000000;"></div>
+
Open the terminal by pressing '''Ctrl, Alt''' and '''T keys''' simultaneously.
  
<div style="color:#000000;">Type '''mv ~/Downloads/csma_performance.cc scratch/csma_performance.cc '''to move the source file to '''scratch '''directory.</div>
+
Using the '''cd '''command, navigate to the installation directory of '''ns-3'''.
|| <div style="color:#000000;">Now we will observe the simulation.</div>
+
  
<div style="color:#000000;">Open the terminal by pressing '''Ctrl, Alt''' and '''T keys''' simultaneously.</div>
+
Go to the '''ns-3.38''' directory.
  
<div style="color:#000000;">Using the '''cd '''command, navigate to the installation directory of '''ns-3'''.</div>
+
Move your '''source file''' to the '''scratch '''directory within the '''ns-3.38''' '''directory'''.
 +
|-
 +
|| Type ./'''ns3 run scratch/csma_performance.cc'''
 +
|| Now, run the command ./'''ns3 run scratch/csma_performance.cc '''
  
<div style="color:#000000;">Go to the '''ns-3.38''' directory.</div>
+
'''csma_performance.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'''.
  
<div style="color:#000000;">Move your '''source file''' to the '''scratch '''directory within the '''ns-3.38''' '''directory'''.</div>
+
We see the '''average end to end delay and throughput '''of the '''CSMA''' network.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Type ./'''ns3 run scratch/csma_performance.cc'''
+
|| Navigate to '''netanim '''directory under '''ns-allinone-3.38'''
|| <div style="color:#000000;">Now, run the command ./'''ns3 run scratch/csma_performance.cc '''</div>
+
  
<div style="color:#000000;">'''csma_performance.cc '''is the name of the source file. </div>
+
Type '''cd ..'''
|- 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
+
|| <div style="color:#000000;">After compilation, we get the details of each '''packet transfer'''.</div>
+
  
<div style="color:#000000;">We see the '''average end to end delay and throughput '''of the '''CSMA''' network.</div>
+
Type '''cd netanim'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|| Now, to visualize the network, we will use '''NetAnim'''.  
|| <div style="color:#000000;"></div>
+
  
<div style="color:#000000;"></div>
+
Navigate to the '''netanim '''directory under '''ns-allinone-3.38.'''
  
<div style="color:#000000;">Navigate to '''netanim '''directory under '''ns-allinone-3.38'''</div>
+
For that, type '''cd .. '''in the terminal window.
  
<div style="color:#000000;">Type '''cd ..'''</div>
+
Then type '''cd netanim'''
 +
|-
 +
|| Type ./'''NetAnim'''
 +
|| Now type '''./NetAnim. '''
  
<div style="color:#000000;">Type '''cd netanim'''</div>
+
The '''NetAnim''' window should open.
|| <div style="color:#000000;">Now, to visualize the network, we will use '''NetAnim'''. </div>
+
|-
 +
|| 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/ns3.38 '''directory and select the '''csma-performance-analysis.xml '''file.
 +
|| In the file picker, navigate to the '''ns-allinone-3.38 '''and then to the '''ns3.38 '''directory.
  
<div style="color:#000000;">Navigate to the '''netanim '''directory under '''ns-allinone-3.38.'''</div>
+
Then select the '''csma-performance-analysis.xml '''file.
 +
|-
 +
|| On the toolbar, click on the '''play''' button
  
<div style="color:#000000;">For that, type '''cd .. '''in the terminal window.</div>
+
Close the NetAnim window
 +
|| On the toolbar, click on the''' play button''' to view the simulation.
  
<div style="color:#000000;">Then type '''cd netanim'''</div>
+
Now we can observe the packet transfer.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
| style="color:#000000;" | Type ./'''NetAnim'''
+
|| <div style="color:#000000;">Now type '''./NetAnim. '''</div>
+
  
<div style="color:#000000;">The '''NetAnim''' window should open.</div>
+
Now, we can close the''' NetAnim''' window.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|-
| style="color:#000000;" | Click on the Open''' XML trace file '''icon on the top left corner of the window.
+
|| Show Slide: '''Summary'''
| style="color:#000000;" | Click on the''' Open XML trace file '''icon on the top left corner of the window.
+
|| This brings us to the end of this tutorial.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
| style="color:#000000;" | In the file picker, navigate to the '''ns-allinone-3.38/ns3.38 '''directory and select the '''csma-performance-analysis.xml '''file.
+
|| <div style="color:#000000;">In the file picker, navigate to the '''ns-allinone-3.38 '''and then to the '''ns3.38 '''directory.</div>
+
  
<div style="color:#000000;">Then select the '''csma-performance-analysis.xml '''file.</div>
+
Let us summarize.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|| <div style="color:#000000;">On the toolbar, click on the '''play''' button</div>
+
  
<div style="color:#000000;">Close the NetAnim window</div>
+
In this tutorial, we have
|| <div style="color:#000000;">On the toolbar, click on the''' play button''' to view the simulation.</div>
+
  
<div style="color:#000000;">Now we can observe the packet transfer.</div>
+
* Created a '''CSMA''' '''bus topology''' with '''10''' nodes
 +
* Configured '''client '''and '''server applications '''on the '''nodes'''
 +
* Connected the''' two''' nodes and '''routing packets''' from one '''node '''to the other
 +
* Visualized the network using '''NetAnim'''
  
<div style="color:#000000;">Now, we can close the''' NetAnim''' window.</div>
+
|-
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
|| Show Slide :''' Assignment'''
| style="color:#000000;" | Show Slide: '''Summary'''
+
|| As an assignment, please do the following
|| <div style="color:#000000;">This brings us to the end of this tutorial.</div>
+
  
<div style="color:#000000;">Let us summarize. </div>
+
* Create 10 nodes
 +
* Connect each of them using '''p2p helper''' classes
 +
* Initialize''' CSMA '''network using '''csmaHelper()''' class
 +
* Set''' datarate '''and '''delay'''
 +
* Route the packets from the second node to the eighth node
 +
* Visualize the network using '''NetAnim'''
  
<div style="color:#000000;">In this tutorial, we have </div>
+
|-
 +
|| Show Slide :''' Assignment - Observation'''
 +
|| In the terminal, you will get the following output.
  
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Created a '''CSMA''' '''bus topology''' with '''10''' nodes</div>
+
|-
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Configured '''client '''and '''server applications '''on the '''nodes'''</div>
+
|| Show Slide :''' Assignment - Observation '''
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Connected the''' two''' nodes and '''routing packets''' from one '''node '''to the other</div>
+
|| In the '''NetAnim''' window, you would observe the packet transfer from node-2 to node-8.
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Visualized the network using '''NetAnim'''</div>
+
 
+
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
| style="color:#000000;" | Show Slide :''' Assignment'''
+
|| <div style="color:#000000;">As an assignment, please do the following</div>
+
 
+
* <div style="color:#000000;margin-left:2.54cm;margin-right:0cm;">Create 10 nodes</div>
+
* <div style="color:#000000;margin-left:2.54cm;margin-right:0cm;">Connect each of them using '''p2p helper''' classes</div>
+
* <div style="color:#000000;margin-left:2.54cm;margin-right:0cm;">Initialize''' CSMA '''network using '''csmaHelper()''' class</div>
+
* <div style="color:#000000;margin-left:2.54cm;margin-right:0cm;">Set''' datarate '''and '''delay'''</div>
+
* <div style="color:#000000;margin-left:2.54cm;margin-right:0cm;">Route the packets from the second node to the eighth node</div>
+
* <div style="color:#000000;margin-left:2.54cm;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;"
+
| style="color:#000000;" | Show Slide :''' Assignment - Observation'''
+
|| <div style="color:#000000;">In the terminal, you will get the following output.</div>
+
 
+
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.206cm;padding-right:0.191cm;"
+
| style="color:#000000;" | Show Slide :''' Assignment - Observation '''
+
|| <div style="color:#000000;">In the '''NetAnim''' window, you would observe the packet transfer from node-2 to node-8.</div>
+
 
+
<div style="color:#000000;">Observe the packet transfer.</div>
+
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|| <div style="color:#000000;">Show Slide:</div>
+
  
<div style="color:#000000;">'''About Spoken Tutorial Project'''</div>
+
Observe the packet transfer.
|| <div style="color:#000000;">The video at the following link summarizes the '''Spoken Tutorial project'''.</div>
+
|-
 +
|| Show Slide:
  
<div style="color:#000000;">Please download and watch it.</div>
+
'''About Spoken Tutorial Project'''
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|| The video at the following link summarizes the '''Spoken Tutorial project'''.
|| <div style="color:#000000;">Show Slide:</div>
+
  
<div style="color:#000000;">'''Spoken Tutorial Workshops'''</div>
+
Please download and watch it.
|| <div style="color:#000000;">The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.</div>
+
|-
 +
|| Show Slide:
  
<div style="color:#000000;">For more details, please write to us.</div>
+
'''Spoken Tutorial Workshops'''
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|| The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.
|| <div style="color:#000000;">Show Slide:</div>
+
  
<div style="color:#000000;">'''Answers for THIS Spoken Tutorial'''</div>
+
For more details, please write to us.
| style="color:#000000;" | Please post your timed queries in this forum.
+
|-  
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|| Show Slide:
|| <div style="color:#000000;">Show Slide:</div>
+
  
<div style="color:#000000;">'''FOSSEE Forum'''</div>
+
'''Answers for THIS Spoken Tutorial'''
| style="color:#000000;" | For any general or technical questions on '''ns-3''', visit the''' FOSSEE forum''' and post your question.
+
|| Please post your timed queries in this forum.
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
|-  
| style="color:#000000;" | Show Slide: '''Acknowledgement'''
+
|| Show Slide:
|| <div style="color:#000000;">'''Spoken Tutorial''' Project is funded by the '''Ministry of Education, Government of India'''.</div>
+
  
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
'''FOSSEE Forum'''
| style="color:#000000;" | Show Slide: '''Acknowledgement'''
+
|| For any general or technical questions on '''ns-3''', visit the''' FOSSEE forum''' and post your question.
|| <div style="color:#000000;">We thank '''Dr.Moyukh Laha''' from '''IIT Kharagpur''' for his domain support.</div>
+
|-
 +
|| Show Slide: '''Acknowledgement'''
 +
|| '''Spoken Tutorial''' Project is funded by the '''Ministry of Education, Government of India'''.
  
<div style="color:#000000;">We would also like to thank '''Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi '''from''' VIT, Chennai '''for their support.</div>
+
|-
 +
|| Show Slide: '''Acknowledgement'''
 +
|| We thank '''Dr.Moyukh Laha''' from '''IIT Kharagpur''' for his domain support.
  
|- style="border:0.75pt solid #808080;padding:0.176cm;"
+
We would also like to thank '''Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi '''from''' VIT, Chennai '''for their support.
|| <div style="color:#000000;">Show Slide: '''Thank you'''</div>
+
  
<div style="color:#000000;"></div>
+
|-
|| <div style="color:#000000;">This is '''Arun Santhosh''', a FOSSEE Summer Fellow 2023, IIT Bombay signing off.</div>
+
|| Show Slide: '''Thank you'''
 +
|| This is '''Arun Santhosh''', a FOSSEE Summer Fellow 2023, IIT Bombay signing off.
  
<div style="color:#000000;">Thank you for joining.</div>
+
Thank you for joining.
 
|-
 
|-
 
|}
 
|}

Revision as of 16:24, 28 February 2024

Visual Cue Narration
Slide:1 Welcome to Spoken tutorial on CSMA based network with bus topology.
Show Slide:

Learning Objectives

In this tutorial, we will learn to
  • Create a CSMA based bus topology with 10 nodes
  • Configure client and server applications on the nodes
  • Connect the two nodes and routing packets from one node to the other
  • Visualize the network using NetAnim
Show Slide:

System Requirements

To record this tutorial, I am using
  • Ubuntu Linux OS version 22.04
  • ns-3 version 3.38.
  • NetAnim visualizer tool.
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:

Bus topology

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

A bus network topology with 10 nodes and network address 10.1.1.0.

Open csma_performance.cc source file I have created the source file csma_performance.cc. for this program.

The source code contains the required functions to implement a CSMA based bus topology.

Here, I have routed the packets from the first node to the tenth node.

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

Highlight uint32_t nCsma = 10 We set the number of nodes in the CSMA network to 10.
Highlight double trans_time_1 This represents the transmission time at the client.
Highlight double rec_time_1 This defines the receiving time at the server
Highlight the line static void

TxTraceClient

This is the function created to trace the client application.
Highlight if (context[10] == '0') We use context to find which node has transmitted the packet.
Highlight trans_time_1 = Simulator::Now().GetSeconds(); We shall define the transmission time by getting the current time in seconds from the simulator
Highlight static void

RxTraceServer

This is the function created to trace the server application.
Highlight if (context[10] == '9') Here, context is used to get the node ID whenever the server gets the packets.
Highlight rec_time_1 We then define the receiving time by getting the current time in seconds from the simulator
Highlight delay_1 and (rec_time_1 - trans_time_1)*1000. Next, we use delay_1 to find the delay using this formula.
Highlight if (pkt_cnt_1 == pkts) If we have reached the last packet, we have to print the parameters.
Highlight NodeContainer csmaNodes Then, we create a node container for the CSMA network.
Highlight csmaNodes.Create(ncsma) Let us create a number of CSMA nodes assigned earlier using the Create() method.
Highlight

CsmaHelper csma

The CsmaHelper is a helper class for initializing the CSMA network.

This is the helper class to access the CSMA channel created.

Highlight csma.SetChannelAttribute Using the setChannelAttribute method,let us set the attributes for the CSMA network.
  • Data rate 100 Mbps.
  • Channel delay 6560 nanoseconds or 0.00656 milliseconds.
Highlight stack.Install(csmaNodes) This command installs an internet stack on the nodes of the CSMA bus network.
Highlight address.SetBase and address.Assign(csmaDevices) The highlighted command assigns IP addresses to the nodes of the network.

Now we set the base address 10.1.1.0 for the bus network.

Highlight UdpEchoServerHelper echoServerA(9); The UdpEchoServerHelper class is used to install server applications on a node of the network.

An echo server receives a packet from the client.

The received packet is echoed back.

Highlight echoServer.Install(csmaNodes.Get(9)) The tenth node of the CSMA network has index 9.

Let us install an echo server application on the tenth node.

Highlight serverApps.Start(Seconds(1.0)) Set the start of the server application to 1 second.
Highlight serverApps.Stop(Seconds(10.0)) The stop time is 10 seconds after the start of the simulation.
Highlight UdpEchoClientHelper echoClientA(csmaInterfaces.GetAddress(9), 9); The UdpEchoClientHelper class is used to install client applications on a node of the network.

An Echo client enables the node to send and receive echo packets from the server.

Highlight echoClient(csmaInterfaces.GetAddress(9), 9); Let us install an echo client application.

The target server is node 10 of the CSMA network.

The port is set to 9.

Highlight echoClientA.SetAttribute This command is used to set the attributes of the client.
Highlight PopulateRoutingTables() Now, for the packets to be routed across the bus network, routing must be enabled.

To enable routing across the bus network, we use this method.

Highlight AnimationInterface anim ("csma-performance-analysis.xml") Let us specify the name for the XML output file.
Highlight the lines:

anim.SetConstantPosition()

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() Destroy() function ends the simulation.

Now close the text editor.

Press Ctrl, Alt and T keys simultaneously

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


Type mv ~/Downloads/csma_performance.cc scratch/csma_performance.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/csma_performance.cc Now, run the command ./ns3 run scratch/csma_performance.cc

csma_performance.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.

We see the average end to end delay and throughput of the CSMA network.

Navigate to netanim directory under ns-allinone-3.38

Type cd ..

Type cd netanim

Now, to visualize the network, we will use NetAnim.

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

For that, type cd .. in the terminal window.

Then type cd netanim

Type ./NetAnim Now type ./NetAnim.

The NetAnim window should 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/ns3.38 directory and select the csma-performance-analysis.xml file. In the file picker, navigate to the ns-allinone-3.38 and then to the ns3.38 directory.

Then select the csma-performance-analysis.xml file.

On the toolbar, click on the play button

Close the NetAnim window

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

Now we can observe the packet transfer.

Now, we can close the NetAnim window.

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

Let us summarize.

In this tutorial, we have

  • Created a CSMA bus topology with 10 nodes
  • Configured client and server applications on the nodes
  • Connected the two nodes and routing packets from one node to the other
  • Visualized the network using NetAnim
Show Slide : Assignment As an assignment, please do the following
  • Create 10 nodes
  • Connect each of them using p2p helper classes
  • Initialize CSMA network using csmaHelper() class
  • Set datarate and delay
  • Route the packets from the second node to the eighth node
  • Visualize the network using NetAnim
Show Slide : Assignment - Observation In the terminal, you will get the following output.
Show Slide : Assignment - Observation In the NetAnim window, you would observe the packet transfer from node-2 to node-8.

Observe the packet transfer.

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 is funded by the Ministry of Education, Government of India.
Show Slide: Acknowledgement We thank Dr.Moyukh Laha from IIT Kharagpur for his domain support.

We would also like to thank Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi from VIT, Chennai for their support.

Show Slide: Thank you This is Arun Santhosh, a FOSSEE Summer Fellow 2023, IIT Bombay signing off.

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat