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...")
(No difference)

Revision as of 18:02, 28 February 2024


Visual Cue Narration
Slide:1
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

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

It builds a routing database and initializes the routing tables.

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 run 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, and 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 lines 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