Ns-3-Network-Simulator/C3/Dynamic-Routing-Protocol/English
Visual Cue | Narration |
Slide:1 | Welcome to the spoken tutorial on Dynamic routing protocols in ns-3. |
Show slide:
Learning Objectives |
In this tutorial, we will learn to
|
Show slide:
System Requirements |
To record this tutorial, I am using:
|
Show slide:
Prerequisite |
To follow this tutorial
|
Show slide:
Code files |
|
Show slide:
What is OSPF Routing? |
|
Show diagram:
Network topology with 6 nodes and four paths |
For this tutorial, we would be creating the following topology:
|
Open the file DynamicRouting.cc in text editor | I have created the source file DynamicRoutingprotocols.cc for this program.
Now we will go through the source code in the text editor. The source code contains the required functions to implement OSPF dynamic routing. |
Highlight Config::SetDefault("ns3::Ipv4GlobalRouting::RespondToInterfaceEvents", BooleanValue(true)) | Using the SetDefault method, we first enable dynamic routing.
RespondToInterfaceEvents enables the ns-3 program to automatically change routes. |
Highlight
NodeContainer p2pNodes p2pNodes.Create(6) |
The node container contains 6 nodes. |
Highlight stack.Install(p2pNodes); | Let’s install an internet stack on the nodes. |
Highlight NodeContainer n01, n02, n23, n14, n15, n45; | Next we create 6 more node containers.
These containers are for the individual point-to-point networks. The node containers are n01, n02, n23, n34, n14, n15 and n45. |
Highlight Address.SetBase | Then we assign base addresses to the point-to-point networks. |
Highlight 10.1.1.0 | The address of the network between node 0 and node 1 is 10.1.1.0. |
Highlight 10.1.2.0 | The address of the network between node 0 and node 2 is 10.1.2.0.
Similarly, the addresses of the other networks are set. |
Highlight pointToPoint.Install(n01) | The Install method installs point-to-point channels on the nodes.
The nodes are node 0 and node 1 here. |
Highlight NetDeviceContainer nd01 | The Install method returns an object of NetDeviceContainer class.
We store it in object nd01. |
Highlight Address.Assign(nd01) | The Assign method assigns IP addresses to the nodes.
The IP addresses are based on the network address. |
Highlight Ipv4InterfaceContainer i01 | The Assign method returns an Ipv4InterfaceContainer object.
We store it in object i01. |
Highlight uint16_t port = 9 | Next, we set the port number to 9. |
Highlight OnOffHelper onoff | Then we create OnOff applications to send packets. |
Highlight InetSocketAddress(i45.GetAddress(1), port) | Here we create a UDP socket on the remote destination node.
The socket is created on port 9 of node 5. We get the IP address of node 5 using the i45 object. The GetAddress method is used to get the address of the node with index 1. Please note that the indexing is within i45 interface. |
Highlight onoff.SetConstantRate(DataRate("2kbps")) | Then, we set the properties for the application.
The data rate is set to 2kbps. |
Highlight onoff.SetAttribute | The packet size is set to 50 bytes. |
Highlight ApplicationContainer apps = onoff.Install(p2pNodes.Get(0)) | Create an application container.
Then, install the OnOff application on node 0. Here the indexing is in the overall network. |
Highlight apps.Start(Seconds(1.0)) | Set the start time for the apps to 1 second from the start of the simulation. |
Highlight apps.Stop(Seconds(16.0)) | Similarly set the stop time to 16 seconds from the start of the simulation. |
Highlight Ipv4GlobalRoutingHelper | In order to get the routing tables, we create an Ipv4GlobalRoutingHelper object. |
Highlight Create<OutputStreamWrapper> | Then we create an output stream, with the class OutputStreamWrapper.
The OutputStreamWrapper encapsulates an output stream. |
Highlight global-routing.routes | The name of the output file is global-routing.routes. |
Highlight PrintRoutingTableAllAt | The PrintRoutingTableAllAt sets the time at which the routing tables are printed. |
Highlight Seconds (2) | We print the tables two times.
One at 2 seconds. |
Highlight Seconds (12) | The other at 12 seconds. |
Highlight routingStream | The routes are printed to the output stream created earlier. |
Only narration | We print the tables two times to observe the dynamic selection of routes.
Between the two prints, we shall make the shortest link down. Then, the next shortest link would be selected dynamically. In this program, the network between nodes 1 and 5 will be set down. |
Highlight Ptr<Node> n1 = p2pNodes.Get(1) | Next we create a pointer to the node whose link would be set down.
In this case, it is node 1. |
Highlight n1->GetObject<Ipv4> | Then, we get the IPv4 class object for the node using the GetObject method. |
Highlight ipv4ifIndex1 = 1 | Now we need to select the network that has to be set down.
A single node can be connected to multiple networks. We need to specify the index of the network. The network indexes start from 1. For this tutorial, we are deactivating the link between nodes 0 and 1. It is the first network for node 1. Hence, the index is 1 here. |
Highlight Simulator::Schedule(Seconds(5), &Ipv4::SetDown, ipv41, ipv4ifIndex1) | Then, we schedule the down time for the network to 5 seconds. |
Highlight AnimationInterface anim | Next we create an AnimationInterface object for NetAnim animation. |
Highlight anim.SetConstantPosition | Then set the positions for the nodes using the SetConstantPosition function. |
Highlight Simulator::Run() | The Run function is used to run the simulation. |
Highlight Simulator::Destroy() | And Destroy function ends the simulation.
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/DynamicRouting.cc scratch/DynamicRouting.cc |
Now we will observe the simulation.
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/DynamicRouting.cc | Run the command dot forward slash ns3 run space scratch forward slash DynamicRoutingprotocols dot cc.
DynamicRoutingprotocols dot cc is the name of the source file. |
Keep the terminal open and show the output of the command | After compilation, there is no output on the terminal.
We shall observe the routing tables in the routes file created earlier. |
Switch to file manager and open the ns-3.38 directory.
Select the global-routing.routes file. |
The routes file is created in the same directory from which we run the simulation.
In this case, it is ns-3.38 directory. In the directory, a file with the name global-routing.routes should appear. |
Open the global-routing.routes file.
Highlight Node: 0, Time: +2s |
Open the file by double clicking on it.
In the file for each node, the following details are shown:
|
Highlight Destination and Gateway. | The destination address and the gateway are of interest to us.
These represent the possible paths that the packet can take. |
Hover over the table under node 0. | As configured earlier, the tables are printed two times. |
Highlight Time: +2s | Once at 2 seconds, and the next at 12 seconds.
At 5 seconds, the link between nodes 0 and 1 goes down. |
Scroll down and highlight Node: 0, Time: +12s | Hence, at 12 seconds, the routes are different. |
Hover over the table under node 0. | You may inspect the routing tables to see the difference. |
Type cd ~/ns-allinone-3.38/netanim to navigate to the netanim directory. | Now, to visualize the network, we will use NetAnim.
Navigate to the netanim directory under ns-allinone-3.38. |
Type ./NetAnim | Now type dot forward slash NetAnim.
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 DynamicRouting.xml file. | In the file picker, navigate to the ns-3.38 directory.
Select the DynamicRouting.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. |
Hover the cursor over node 0. | We see the circles representing the nodes.
The packets go from node 0 to node 5, via node 1. |
Move the cursor over the link between node 0 and node 1. | The lines with arrows represent the transfer of packets. |
Move the cursor from node 0 to node 1.
Then move the cursor from node 1 to node 5. Move the cursor according to the arrows. |
The packets go from node 0 to node 5, via node 1. |
Hover over the ‘Sim time’ slider on the toolbar.
Wait for it to cross 5 seconds. |
After 5 seconds, the link between nodes 0 and 1 gets down.
Before the link was set down, path 0-1-5 was the shortest. This route goes from nodes 2, 3 and 4. |
Hover the cursor over the arrows as they move from node 0 to node 5. | As we can see, the packets automatically switch to the next available route.
The selection of paths is based on the OSPF protocol. To learn more about OSPF, please refer to this link |
Show slide:
Summary |
This brings us to the end of the tutorial. Let us summarize.
In this tutorial, we have learnt to
|
Show slide:
Assignment |
As an assignment, please do the following:
|
Show slide:
Assignment - Observation |
In NetAnim, you will observe the change in routes after 5 seconds.
The route from node 0 to node 5 through node 4 gets chosen automatically. |
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.
|