Ns-3-Network-Simulator/C2/CSMA-based-network-with-bus-topology/English

From Script | Spoken-Tutorial
Jump to: navigation, search
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 the 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 space .. in the terminal window.

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

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

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

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat