Difference between revisions of "Ns-3-Network-Simulator/C2/Creating-Point-to-Point-Network-in-ns-3/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="background-color:transparent...")
 
Line 1: Line 1:
 
 
 
 
 
  
 
{| border="1"
 
{| border="1"
Line 12: Line 7:
 
|| '''Slide:1'''
 
|| '''Slide:1'''
  
<div style="color:#000000;">'''Welcome'''</div>
+
'''Title Slide'''
|| <span style="background-color:transparent;color:#000000;">Welcome to the </span>'''S<span style="background-color:transparent;color:#000000;">poken </span>T<span style="background-color:transparent;color:#000000;">utorial'''</span><span style="background-color:transparent;color:#000000;"> on </span>Creating''' Point-to-Point Network''' in '''ns-3'''.
+
|| Welcome to the '''Spoken Tutorial''' on Creating''' Point-to-Point Network''' in '''ns-3'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Show s<span style="background-color:transparent;color:#000000;">lide: </span>
+
|| Show slide:  
  
 
'''Learning Objectives'''
 
'''Learning Objectives'''
|| <div style="color:#000000;">In this tutorial, we will learn</div>
+
|| In this tutorial, we will learn
  
* <div style="margin-left:1.27cm;margin-right:0cm;">About structure of an '''ns-3 '''program</div>
+
* About structure of an '''ns-3 '''program
* <div style="margin-left:1.27cm;margin-right:0cm;">About the classes and the methods</div>
+
* About the classes and the methods
* <div style="margin-left:1.27cm;margin-right:0cm;">To create nodes</div>
+
* To create nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">To establish a point-to-point connection between two nodes</div>
+
* To establish a point-to-point connection between two nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">To configure client and server applications on the nodes</div>
+
* To configure client and server applications on the nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">To visualize the network using '''NetAnim'''</div>
+
* To visualize the network using '''NetAnim'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Show s<span style="background-color:transparent;color:#000000;">lide: </span>
+
|| Show slide:  
  
<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="margin-left:1.27cm;margin-right:0cm;">'''Ubuntu''' '''Linux operating system version 22.04'''</div>
+
* '''Ubuntu''' '''Linux operating system version 22.04'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''ns-3.38'''</div>
+
* '''ns-3.38'''
* <div style="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.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide:  
 
|| Show slide:  
  
Line 43: Line 38:
 
[https://www.spoken-tutorial.org/ https://www.spoken-tutorial.org]
 
[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>
+
* You must have basic knowledge of using Linux terminal
* <div style="margin-left:1.27cm;margin-right:0cm;">For pre-requisite Linux tutorials, please visit this website</div>
+
* For pre-requisite Linux tutorials, please visit this website
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide:
 
|| Show slide:
  
 
'''Code files'''
 
'''Code files'''
 
||  
 
||  
* <div style="margin-left:1.27cm;margin-right:0cm;"><span style="color:#252525;">The files used in this tutorial are provided in the </span><span style="color:#252525;">'''Code files'''</span><span style="color:#252525;"> link.</span></div>
+
* The files used in this tutorial are provided in the '''Code files''' link.
* <div style="color:#252525;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;"><span style="color:#252525;">Make a copy and then use them while practicing</span><span style="color:#252525;">.</span></div>
+
* Make a copy and then use them while practicing.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide:  
 
|| Show slide:  
  
 
'''Point-to-Point Topology'''
 
'''Point-to-Point Topology'''
 +
 
|| A''' point-to-point''' topology is a communication link between two hosts in a network.  
 
|| A''' point-to-point''' topology is a communication link between two hosts in a network.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
 
 +
|-  
 
|| Show diagram: '''Point-to-Point network with two nodes'''
 
|| Show diagram: '''Point-to-Point network with two nodes'''
 
|| In this tutorial, we will be creating the topology shown below.
 
|| In this tutorial, we will be creating the topology shown below.
  
 
In this network, Node 0 is the transmitter and node 1 is the receiver.
 
In this network, Node 0 is the transmitter and node 1 is the receiver.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;">Open </span>'''point-to-point<span style="background-color:transparent;">.cc'''</span><span style="background-color:transparent;"> source file</span>
+
|| Open '''point-to-point.cc''' source file
 
|| I have created the source file '''point_to_point.cc''' for this program.
 
|| I have created the source file '''point_to_point.cc''' for this program.
  
Line 73: Line 70:
 
The source code contains the required functions to implement a point-to-point network.
 
The source code contains the required functions to implement a point-to-point network.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight the </span>lines:
+
|| Highlight the lines:
  
 
<nowiki>#include "ns3/applications-module.h"</nowiki>
 
<nowiki>#include "ns3/applications-module.h"</nowiki>
Line 92: Line 89:
 
<nowiki>#include "ns3/mobility-model.h"</nowiki>
 
<nowiki>#include "ns3/mobility-model.h"</nowiki>
  
| style="color:#000000;" | First we include the header files.
+
||First we include the header files.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''CommandLine cmd(__FILE__)'''</span>
+
|| Highlight '''CommandLine cmd(__FILE__)'''
|| '''cmd '''is a '''CommandLine '''class instance <span style="background-color:transparent;color:#000000;">method.</span>
+
|| '''cmd '''is a '''CommandLine '''class instance method.
  
 
It is used to get optional arguments for the program from the command line.
 
It is used to get optional arguments for the program from the command line.
  
 
In this program we would not be using any optional argument.
 
In this program we would not be using any optional argument.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Highlight '''cmd.Parse(argc, argv)'''
 
|| Highlight '''cmd.Parse(argc, argv)'''
 
|| The '''Parse '''method of the '''CommandLine '''class parses program arguments.
 
|| The '''Parse '''method of the '''CommandLine '''class parses program arguments.
Line 107: Line 104:
  
 
The second argument is the array of arguments.
 
The second argument is the array of arguments.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''LogComponentEnable '''</span><span style="background-color:transparent;color:#000000;">on both the lines</span>
+
|| Highlight '''LogComponentEnable '''on both the lines
|| <span style="background-color:transparent;color:#000000;">The </span><span style="background-color:transparent;color:#000000;">'''LogComponentEnable'''</span><span style="background-color:transparent;color:#000000;"> function is used to enable logging</span>.
+
|| The '''LogComponentEnable''' function is used to enable logging.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''NodeContainer nodes'''</span>
+
|| Highlight '''NodeContainer nodes'''
|| <span style="background-color:transparent;color:#000000;">Next we create a </span><span style="background-color:transparent;color:#000000;">'''NodeContainer'''</span><span style="background-color:transparent;color:#000000;"> class instance named nodes.</span>
+
|| Next we create a '''NodeContainer''' class instance named nodes.
  
 
A '''NodeContainer''' class instance is used to store nodes in the network.  
 
A '''NodeContainer''' class instance is used to store nodes in the network.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''nodes.Create(2)'''</span>
+
|| Highlight '''nodes.Create(2)'''
|| <span style="background-color:transparent;color:#000000;">Using the </span><span style="background-color:transparent;color:#000000;">'''Create'''</span><span style="background-color:transparent;color:#000000;"> method, we create 2 nodes in the nodes container.</span>
+
|| Using the '''Create''' method, we create 2 nodes in the nodes container.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''PointToPointHelper pointToPoint'''</span>
+
|| Highlight '''PointToPointHelper pointToPoint'''
|| Now lets <span style="background-color:transparent;color:#000000;">initialize the network and set parameters</span>.
+
|| Now lets initialize the network and set parameters.
  
 
Create an instance of the '''PointToPointHelper''' class with the name '''pointToPoint.'''
 
Create an instance of the '''PointToPointHelper''' class with the name '''pointToPoint.'''
 +
 
'''PointToPointHelper''' is a topology helper class.
 
'''PointToPointHelper''' is a topology helper class.
  
 
Helper class instances assist in creating and initializing networks.
 
Helper class instances assist in creating and initializing networks.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''pointToPoint.SetDeviceAttribute("DataRate", StringValue("100Mbps"))'''</span>
+
|| Highlight '''pointToPoint.SetDeviceAttribute("DataRate", StringValue("100Mbps"))'''
 
|| '''The SetDeviceAttribute''' sets the attributes for the devices or the nodes.
 
|| '''The SetDeviceAttribute''' sets the attributes for the devices or the nodes.
  
Her<span style="background-color:transparent;color:#000000;">e we set the data rate of the devices to 100 Mbps</span>.
+
Here we set the data rate of the devices to 100 Mbps.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''pointToPoint.SetChannelAttribute("Delay", TimeValue(NanoSeconds(6560)))'''</span>
+
|| Highlight '''pointToPoint.SetChannelAttribute("Delay", TimeValue(NanoSeconds(6560)))'''
 
|| '''The SetChannelAttribute''' sets attributes for the communication channel.
 
|| '''The SetChannelAttribute''' sets attributes for the communication channel.
  
We set the <span style="background-color:transparent;color:#000000;">delay of the communication channel to 6560 nanoseconds.</span>
+
We set the delay of the communication channel to 6560 nanoseconds.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Highlight<span style="background-color:transparent;color:#000000;"> </span><span style="background-color:transparent;color:#000000;">'''NetDeviceContainer devices'''</span>
+
|| Highlight '''NetDeviceContainer devices'''
|| <span style="background-color:transparent;color:#000000;">The nodes are not</span> yet ready <span style="background-color:transparent;color:#000000;">to communicate</span>.
+
|| The nodes are not yet ready to communicate.
  
 
We need to install net devices on the nodes.
 
We need to install net devices on the nodes.
Line 145: Line 143:
  
 
The '''NetDeviceContainer''' class instance holds net devices.
 
The '''NetDeviceContainer''' class instance holds net devices.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''devices = pointToPoint.Install(nodes)'''</span>
+
|| Highlight '''devices = pointToPoint.Install(nodes)'''
|| Now let’s<span style="background-color:transparent;color:#000000;"> install the net devices on the node</span>, using the '''Install''' method.
+
|| Now let’s install the net devices on the node, using the '''Install''' method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Hi<span style="background-color:transparent;color:#000000;">ghlight </span><span style="background-color:transparent;color:#000000;">'''InternetStackHelper stack'''</span>
+
|| Highlight '''InternetStackHelper stack'''
|| Next <span style="background-color:transparent;color:#000000;">we shall install</span> <span style="background-color:transparent;color:#000000;">internet stack on the nodes</span>.
+
|| Next we shall install internet stack on the nodes.
  
 
The '''InternetStackHelper''' class instance installs internet stack on the nodes.
 
The '''InternetStackHelper''' class instance installs internet stack on the nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''stack.Install(nodes)'''</span>
+
|| Highlight '''stack.Install(nodes)'''
 
|| The stack includes implementations of TCP, UDP etc.
 
|| The stack includes implementations of TCP, UDP etc.
  
 
The nodes are passed as the parameter, to the '''Install''' method,
 
The nodes are passed as the parameter, to the '''Install''' method,
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''Ipv4AddressHelper address and address.SetBase("10.1.1.0", "255.255.255.0")'''</span>
+
|| Highlight '''Ipv4AddressHelper address and address.SetBase("10.1.1.0", "255.255.255.0")'''
 
|| '''Ipv4AddressHelper''' class instance assigns IP addresses to the net devices.  
 
|| '''Ipv4AddressHelper''' class instance assigns IP addresses to the net devices.  
  
 
Let's set the base IP address for the network using the '''SetBase '''method.
 
Let's set the base IP address for the network using the '''SetBase '''method.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''Ipv4InterfaceContainer interfaces = address.Assign(devices)'''</span>
+
|| Highlight '''Ipv4InterfaceContainer interfaces = address.Assign(devices)'''
 
|| The '''Assign''' method assigns IP addresses sequentially to the net devices.
 
|| The '''Assign''' method assigns IP addresses sequentially to the net devices.
  
 
The '''Ipv4InterfaceContainer''' class instance stores the interfaces.
 
The '''Ipv4InterfaceContainer''' class instance stores the interfaces.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''UdpEchoServerHelper echoServer(9)'''</span>
+
|| Highlight '''UdpEchoServerHelper echoServer(9)'''
  
 
|| The '''UdpEchoServerHelper''' instance configures an echo server on a node.
 
|| The '''UdpEchoServerHelper''' instance configures an echo server on a node.
Line 177: Line 175:
 
It takes an integer as a parameter that represents the port number.
 
It takes an integer as a parameter that represents the port number.
 
]
 
]
Here, we <span style="background-color:transparent;color:#000000;">create an instance of </span><span style="background-color:transparent;color:#000000;">'''UdpEchoServerHelper'''</span><span style="background-color:transparent;color:#000000;"> with port number 9.</span>
+
Here, we create an instance of '''UdpEchoServerHelper''' with port number 9.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''ApplicationContainer serverApps = echoServer.Install(nodes.Get(1))'''</span>
+
|| Highlight '''ApplicationContainer serverApps = echoServer.Install(nodes.Get(1))'''
 
|| The '''ApplicationContainer''' class instance stores server or client applications.
 
|| The '''ApplicationContainer''' class instance stores server or client applications.
  
C<span style="background-color:transparent;color:#000000;">reate an </span><span style="background-color:transparent;color:#000000;">'''ApplicationContainer'''</span><span style="background-color:transparent;color:#000000;"> instance named </span><span style="background-color:transparent;color:#000000;">'''serverApps</span>.'''
+
Create an '''ApplicationContainer''' instance named '''serverApps.'''
  
 
Install a server application on the second node of the network with index 1.
 
Install a server application on the second node of the network with index 1.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''serverApps.Start(Seconds(1.0))'''</span>
+
|| Highlight '''serverApps.Start(Seconds(1.0))'''
 
|| The '''Start''' method specifies the start time in seconds for the applications.
 
|| The '''Start''' method specifies the start time in seconds for the applications.
  
S<span style="background-color:transparent;color:#000000;">et the start time of the applications to 1 second.</span>
+
Set the start time of the applications to 1 second.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''serverApps.Stop(Seconds(10.0))'''</span>
+
|| Highlight '''serverApps.Stop(Seconds(10.0))'''
 
|| The '''Stop''' method specifies the stop time in seconds.
 
|| The '''Stop''' method specifies the stop time in seconds.
  
S<span style="background-color:transparent;color:#000000;">et the stop time to 10 seconds.</span>
+
Set the stop time to 10 seconds.
  
 
The time values are counted from the start of the simulation.
 
The time values are counted from the start of the simulation.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9)'''</span>
+
|| Highlight '''UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9)'''
 
|| The '''UdpEchoClientHelper''' instance configures an echo client on a node.  
 
|| The '''UdpEchoClientHelper''' instance configures an echo client on a node.  
  
Line 209: Line 207:
 
The second is the port number.  
 
The second is the port number.  
  
Let’s <span style="background-color:transparent;color:#000000;">create the client application helper instance</span>.
+
Let’s create the client application helper instance.
  
 
The attributes are the client node and port number.  
 
The attributes are the client node and port number.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''echoClient.SetAttribute("MaxPackets", UintegerValue(10))'''</span>
+
|| Highlight '''echoClient.SetAttribute("MaxPackets", UintegerValue(10))'''
 
|| The '''SetAttribute''' method sets attributes for the client.  
 
|| The '''SetAttribute''' method sets attributes for the client.  
  
Line 219: Line 217:
  
 
Hence here we set the maximum number of packets, to 10.
 
Hence here we set the maximum number of packets, to 10.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''echoClient.SetAttribute("Interval", TimeValue(Seconds(0.5)))'''</span>
+
|| Highlight '''echoClient.SetAttribute("Interval", TimeValue(Seconds(0.5)))'''
|| <div style="color:#000000;">Then we set the time interval between the packet transmissions.</div>
+
|| Then we set the time interval between the packet transmissions.
  
 
Here the value is 0.5 seconds.
 
Here the value is 0.5 seconds.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''echoClient.SetAttribute("PacketSize", UintegerValue(1024))'''</span>
+
|| Highlight '''echoClient.SetAttribute("PacketSize", UintegerValue(1024))'''
| style="color:#000000;" | Next, set the packet size to 1024 bytes.
+
||Next, set the packet size to 1024 bytes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''ApplicationContainer clientApps = echoClient.Install(nodes.Get(0))'''</span>
+
|| Highlight '''ApplicationContainer clientApps = echoClient.Install(nodes.Get(0))'''
|| I<span style="background-color:transparent;color:#000000;">nstall the client application on the first node with index 0.</span>
+
|| Install the client application on the first node with index 0.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''clientApps.Start(Seconds(2.0))'''</span>
+
|| Highlight '''clientApps.Start(Seconds(2.0))'''
|| <span style="background-color:transparent;color:#000000;">Then set the start time of the client application</span>.
+
|| Then set the start time of the client application.
  
 
Here the start time is 2 seconds from the start of the simulation.
 
Here the start time is 2 seconds from the start of the simulation.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''clientApps.Stop(Seconds(10.0))'''</span>
+
|| Highlight '''clientApps.Stop(Seconds(10.0))'''
|| S<span style="background-color:transparent;color:#000000;">et the stop time to 10 seconds.</span>
+
|| Set the stop time to 10 seconds.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel")'''</span>
+
|| Highlight '''mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel")'''
|| Let’s<span style="background-color:transparent;color:#000000;"> set a mobility model for the nodes.</span>
+
|| Let’s set a mobility model for the nodes.
  
 
The details about mobility shall be covered in future tutorials.
 
The details about mobility shall be covered in future tutorials.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Highlight '''mobility.Install(nodes)'''
 
|| Highlight '''mobility.Install(nodes)'''
 
|| Here we install the mobility model on the nodes.
 
|| Here we install the mobility model on the nodes.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:#ffffff;">Highlight </span><span style="background-color:#ffffff;">'''AnimationInterface anim </span><span style="background-color:#ffffff;">("point-to-point.xml")'''</span>
+
|| Highlight '''AnimationInterface anim ("point-to-point.xml")'''
 
+
 
|| Here we create an object of the '''AnimationInterface '''class.
 
|| Here we create an object of the '''AnimationInterface '''class.
  
Line 259: Line 256:
 
Here the name of the file is '''point-to-point.xml.'''
 
Here the name of the file is '''point-to-point.xml.'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Highlight <span style="background-color:transparent;color:#000000;">'''anim.SetConstantPosition()'''</span>
+
|| Highlight '''anim.SetConstantPosition()'''
 
|| The '''SetConstantPosition''' method sets the X-Y position for a node.
 
|| The '''SetConstantPosition''' method sets the X-Y position for a node.
  
<span style="background-color:transparent;color:#000000;">Using the </span><span style="background-color:transparent;color:#000000;">'''anim '''</span><span style="background-color:transparent;color:#000000;">object, we set the position for both the nodes</span>.
+
Using the '''anim '''object, we set the position for both the nodes.
  
 
The first argument is the node whose position is being set.
 
The first argument is the node whose position is being set.
Line 270: Line 267:
  
 
The third argument is the Y coordinate.
 
The third argument is the Y coordinate.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''Simulator::Run()'''</span>
+
|| Highlight '''Simulator::Run()'''
|| <span style="background-color:transparent;color:#000000;">The </span><span style="background-color:transparent;color:#000000;">'''Run</span> '''<span style="background-color:transparent;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.191cm;padding-right:0.191cm;"
+
|-  
|| H<span style="background-color:transparent;color:#000000;">ighlight </span><span style="background-color:transparent;color:#000000;">'''Simulator::Destroy()'''</span>
+
|| Highlight '''Simulator::Destroy()'''
|| <span style="background-color:transparent;color:#000000;">And </span><span style="background-color:transparent;color:#000000;">'''Destroy '''</span><span style="background-color:transparent;color:#000000;">function ends the simulation.</span>
+
|| And '''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.191cm;padding-right:0.191cm;"
+
|-  
||  
+
|| Press Ctrl,Alt and T keys simultaneously.
 
+
Press Ctrl,Alt and T keys simultaneously.
+
 
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 298: Line 293:
  
 
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.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;">Type ./</span><span style="background-color:transparent;">'''ns3 run scratch/</span>point-to-point<span style="background-color:transparent;">.cc'''</span>
+
|| Type ./'''ns3 run scratch/point-to-point.cc'''
|| R<span style="background-color:transparent;">un the command</span> '''dot forward slash'''<span style="background-color:transparent;"> </span><span style="background-color:transparent;">'''ns3 run sp</span>ace <span style="background-color:transparent;">scratch</span> forward slash point hyphen to hyphen point dot <span style="background-color:transparent;">cc.'''</span>
+
|| Run the command '''dot forward slash''' '''ns3 run space scratch forward slash point hyphen to hyphen point dot cc.'''
  
 
'''point to point dot cc '''is the name of the source file.  
 
'''point to point dot cc '''is the name of the source file.  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;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="background-color:transparent;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.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;color:#000000;">Navigate to </span><span style="background-color:transparent;color:#000000;">'''netanim '''</span><span style="background-color:transparent;color:#000000;">directory under </span><span style="background-color:transparent;color:#000000;">'''ns-allinone-3.38'''</span>
+
|| Navigate to '''netanim '''directory under '''ns-allinone-3.38'''
  
 
Type '''cd ~/ns-allinone-3.38/netanim'''
 
Type '''cd ~/ns-allinone-3.38/netanim'''
|| <span style="background-color:transparent;color:#000000;">Now, to visualize the network, we will use </span><span style="background-color:transparent;color:#000000;">'''NetAnim'''</span><span style="background-color:transparent;color:#000000;">. </span>
+
|| Now, to visualize the network, we will use '''NetAnim'''.  
  
 
Navigate to the '''netanim '''directory under '''ns-allinone-3.38.'''
 
Navigate to the '''netanim '''directory under '''ns-allinone-3.38.'''
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;color:#000000;">Type ./</span><span style="background-color:transparent;color:#000000;">'''NetAnim'''</span>
+
|| Type ./'''NetAnim'''
|| <span style="background-color:transparent;color:#000000;">Now type </span>'''dot forward slash <span style="background-color:transparent;color:#000000;">NetAnim. '''</span><span style="background-color:transparent;color:#000000;">The NetAnim window </span>will <span style="background-color:transparent;color:#000000;">open.</span>
+
|| Now type '''dot forward slash NetAnim. '''The NetAnim window will open.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;color:#000000;">Click </span>on the '''Open<span style="background-color:transparent;color:#000000;"> XML trace file '''</span><span style="background-color:transparent;color:#000000;">icon </span>on the top<span style="background-color:transparent;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="background-color:transparent;color:#000000;">Click </span>on the '''Open<span style="background-color:transparent;color:#000000;"> XML trace file '''</span>button on the top<span style="background-color:transparent;color:#000000;"> left corner of the window.</span>
+
|| Click on the '''Open XML trace file '''button on the top left corner of the window.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;color:#000000;">In the file picker, navigate to the </span><span style="background-color:transparent;color:#000000;">'''ns-allinone-3.38/ns3.38 '''</span><span style="background-color:transparent;color:#000000;">directory and select the </span><span style="background-color:transparent;color:#000000;">'''point-to-point.xml '''</span><span style="background-color:transparent;color:#000000;">file.</span>
+
|| In the file picker, navigate to the '''ns-allinone-3.38/ns3.38 '''directory and select the '''point-to-point.xml '''file.
|| <span style="background-color:transparent;color:#000000;">In the file picker, navigate to the </span>'''ns-3.38 '''directory.
+
|| In the file picker, navigate to the '''ns-3.38 '''directory.
  
 
Select the '''point-to-point.xml '''file.
 
Select the '''point-to-point.xml '''file.
  
 
Click on open at the bottom.
 
Click on open at the bottom.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;color:#000000;">On the toolbar, click on the </span><span style="background-color:transparent;color:#000000;">'''Node Size '''</span><span style="background-color:transparent;color:#000000;">drop down button, and select size 10.</span>
+
|| On the toolbar, click on the '''Node Size '''drop down button, and select size 10.
|| <span style="background-color:transparent;color:#000000;">On the toolbar, click on the </span><span style="background-color:transparent;color:#000000;">'''Node Size '''</span><span style="background-color:transparent;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.191cm;padding-right:0.191cm;"
+
|-  
|| <span style="background-color:transparent;color:#000000;">On the toolbar, click on the play button</span>
+
|| 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 the circles representing the nodes.
 
We see the circles representing the nodes.
  
 
The lines with arrows represent the transfer of packets.
 
The lines with arrows represent the transfer of packets.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Hover over node 0.
 
|| Hover over node 0.
 
|| Node 0 is the transmitter or the source node.
 
|| Node 0 is the transmitter or the source node.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Hover over node 1.
 
|| Hover over node 1.
 
|| Node 1 is the receiver or the server node.
 
|| Node 1 is the receiver or the server node.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Show slide<span style="background-color:transparent;color:#000000;">: </span>
+
|| Show slide:  
  
 
'''Summary'''
 
'''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
 
In this tutorial, we have learnt
* <div style="margin-left:1.27cm;margin-right:0cm;">About the structure of an '''ns-3 '''program</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">About the classes and the methods</div>
 
* <div style="margin-left:1.27cm;margin-right:0cm;">To create nodes</div>
 
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
* About the structure of an '''ns-3 ''' program
|| Only narration
+
* About the classes and the methods
 +
* To create nodes
 +
 
 +
|-  
 +
||Show slide:
 +
 
 +
'''Summary'''
 
||
 
||
* <div style="margin-left:1.27cm;margin-right:0cm;">To establish a point-to-point connection between two nodes</div>
+
* To establish a point-to-point connection between two nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">To configure client and server applications on the nodes</div>
+
* To configure client and server applications on the nodes
* <div style="margin-left:1.27cm;margin-right:0cm;">To visualize the network using '''NetAnim'''</div>
+
* To visualize the network using '''NetAnim'''
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Show s<span style="background-color:transparent;color:#000000;">lide</span>:<span style="background-color:transparent;color:#000000;"> </span><span style="background-color:transparent;color:#000000;">'''Assignment'''</span>
+
|| Show slide:
|| <span style="background-color:transparent;color:#000000;">As an assignment, please </span>do the following:
+
  
* <div style="margin-left:1.27cm;margin-right:0cm;">Write an '''ns-3''' program with two '''point-to-point''' networks</div>
+
'''Assignment'''
* <div style="margin-left:1.27cm;margin-right:0cm;">Set '''IP address '''10.1.0.0 for the first network</div>
+
|| As an assignment, please do the following:
* <div style="margin-left:1.27cm;margin-right:0cm;">Set '''IP address '''10.2.0.0 for the second network</div>
+
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
* Write an '''ns-3''' program with two '''point-to-point''' networks
|| Show slide: '''Assignment'''
+
* Set '''IP address '''10.1.0.0 for the first network
 +
* Set '''IP address '''10.2.0.0 for the second network
 +
 
 +
|-
 +
|| Show slide:  
 +
 
 +
'''Assignment'''
 
||  
 
||  
* <div style="margin-left:1.27cm;margin-right:0cm;">Set different values for '''data rate, delay '''and '''packet size '''for each network</div>
+
* Set different values for '''data rate, delay '''and '''packet size '''for each network
* <div style="margin-left:1.27cm;margin-right:0cm;">Install client and server applications in each network</div>
+
* Install client and server applications in each network
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Show slide: '''Assignment'''
+
|| Show slide:
 +
 
 +
'''Assignment'''
 
||  
 
||  
* <div style="margin-left:1.27cm;margin-right:0cm;">Start transfer of packets in each network simultaneously</div>
+
* Start transfer of packets in each network simultaneously
* <div style="margin-left:1.27cm;margin-right:0cm;">Generate an XML file for '''NetAnim '''animation</div>
+
* Generate an XML file for '''NetAnim '''animation
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide: '''Assignment'''
 
|| Show slide: '''Assignment'''
 
||
 
||
* <div style="margin-left:1.27cm;margin-right:0cm;">Run the simulation in the terminal</div>
+
* Run the simulation in the terminal
* <div style="margin-left:1.27cm;margin-right:0cm;">Import the XML file in '''NetAnim '''and play the animation</div>
+
* Import the XML file in '''NetAnim '''and play the animation
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <div style="color:#000000;">Show slide:</div>
+
|| Show slide:
  
<div style="color:#000000;">'''Assignment - Observation'''</div>
+
'''Assignment - Observation'''
|| * <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">In the terminal, you will get this output.</div>
+
||
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Observe the differences for the two networks.</div>
+
* In the terminal, you will get this output.
 +
* Observe the differences for the two networks.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| <div style="color:#000000;">Show slide:</div>
+
|| Show slide:
  
<div style="color:#000000;">'''Assignment - Observation'''</div>
+
'''Assignment - Observation'''
 
||  
 
||  
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">In the '''NetAnim window, '''you will see two different networks.</div>
+
* In the '''NetAnim window, '''you will see two different networks.
* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Observe the packet transfer rate for each network.</div>
+
* Observe the packet transfer rate for each network.
  
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
|| Show slide<span style="background-color:transparent;color:#000000;">: </span>
+
|| Show slide:  
  
<div style="color:#000000;">'''About the Spoken Tutorial Project'''</div>
+
'''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.191cm;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'''
 
|| 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.191cm;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;">For any general or technical questions on </span><span style="background-color:#ffffff;">'''ns-3'''</span><span style="background-color:#ffffff;">, visit the</span><span style="background-color:#ffffff;">''' FOSSEE forum'''</span><span style="background-color:#ffffff;"> 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.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide
 
|| Show slide
  
 
'''Acknowledgement'''
 
'''Acknowledgement'''
 
|| '''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''.
 
|| '''Spoken Tutorial''' Project was established by the '''Ministry of Education, Government of India'''.
|- style="border:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide
 
|| Show slide
  
Line 440: Line 447:
  
 
We would also like to thank '''Dr. R. Radha, Dr. X. Anita, and Dr. T. Subbulakshmi '''from''' VIT, Chennai '''for their support.
 
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.191cm;padding-right:0.191cm;"
+
|-  
 
|| Show slide:
 
|| Show slide:
  
 
'''Thank You'''
 
'''Thank You'''
|| <span style="background-color:#ffffff;">This is </span><span style="background-color:#ffffff;">'''Josiga, '''</span><span style="background-color:#ffffff;">a FOSSEE summer fellow 2023, IIT Bombay signing off.</span>
+
|| This is '''Josiga, '''a FOSSEE summer fellow 2023, IIT Bombay signing off.
  
 
Thanks for joining.
 
Thanks for joining.
 
|-
 
|-
 
|}
 
|}

Revision as of 11:25, 1 February 2024

Visual Cue Narration
Slide:1

Title Slide

Welcome to the Spoken Tutorial on Creating Point-to-Point Network in ns-3.
Show slide:

Learning Objectives

In this tutorial, we will learn
  • About structure of an ns-3 program
  • About the classes and the methods
  • To create nodes
  • To establish a point-to-point connection between two nodes
  • To configure client and server applications on the nodes
  • To visualize the network using NetAnim
Show slide:

System Requirements

To record this tutorial, I am using
  • Ubuntu Linux operating system version 22.04
  • 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
  • For pre-requisite Linux 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 slide:

Point-to-Point Topology

A point-to-point topology is a communication link between two hosts in a network.
Show diagram: Point-to-Point network with two nodes In this tutorial, we will be creating the topology shown below.

In this network, Node 0 is the transmitter and node 1 is the receiver.

Open point-to-point.cc source file I have created the source file point_to_point.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 a point-to-point network.

Highlight the lines:

#include "ns3/applications-module.h"

#include "ns3/core-module.h"

#include "ns3/internet-module.h"

#include "ns3/network-module.h"

#include "ns3/point-to-point-module.h"

#include "ns3/netanim-module.h"

#include "ns3/mobility-helper.h"

#include "ns3/mobility-model.h"

First we include the header files.
Highlight CommandLine cmd(__FILE__) cmd is a CommandLine class instance method.

It is used to get optional arguments for the program from the command line.

In this program we would not be using any optional argument.

Highlight cmd.Parse(argc, argv) The Parse method of the CommandLine class parses program arguments.

The first argument is the number of arguments to parse.

The second argument is the array of arguments.

Highlight LogComponentEnable on both the lines The LogComponentEnable function is used to enable logging.
Highlight NodeContainer nodes Next we create a NodeContainer class instance named nodes.

A NodeContainer class instance is used to store nodes in the network.

Highlight nodes.Create(2) Using the Create method, we create 2 nodes in the nodes container.
Highlight PointToPointHelper pointToPoint Now lets initialize the network and set parameters.

Create an instance of the PointToPointHelper class with the name pointToPoint.

PointToPointHelper is a topology helper class.

Helper class instances assist in creating and initializing networks.

Highlight pointToPoint.SetDeviceAttribute("DataRate", StringValue("100Mbps")) The SetDeviceAttribute sets the attributes for the devices or the nodes.

Here we set the data rate of the devices to 100 Mbps.

Highlight pointToPoint.SetChannelAttribute("Delay", TimeValue(NanoSeconds(6560))) The SetChannelAttribute sets attributes for the communication channel.

We set the delay of the communication channel to 6560 nanoseconds.

Highlight NetDeviceContainer devices The nodes are not yet ready to communicate.

We need to install net devices on the nodes.

So we create a container for the net devices.

The NetDeviceContainer class instance holds net devices.

Highlight devices = pointToPoint.Install(nodes) Now let’s install the net devices on the node, using the Install method.
Highlight InternetStackHelper stack Next we shall install internet stack on the nodes.

The InternetStackHelper class instance installs internet stack on the nodes.

Highlight stack.Install(nodes) The stack includes implementations of TCP, UDP etc.

The nodes are passed as the parameter, to the Install method,

Highlight Ipv4AddressHelper address and address.SetBase("10.1.1.0", "255.255.255.0") Ipv4AddressHelper class instance assigns IP addresses to the net devices.

Let's set the base IP address for the network using the SetBase method.

Highlight Ipv4InterfaceContainer interfaces = address.Assign(devices) The Assign method assigns IP addresses sequentially to the net devices.

The Ipv4InterfaceContainer class instance stores the interfaces.

Highlight UdpEchoServerHelper echoServer(9) The UdpEchoServerHelper instance configures an echo server on a node.

An echo server receives data from its client and echoes it back.

It takes an integer as a parameter that represents the port number. ] Here, we create an instance of UdpEchoServerHelper with port number 9.

Highlight ApplicationContainer serverApps = echoServer.Install(nodes.Get(1)) The ApplicationContainer class instance stores server or client applications.

Create an ApplicationContainer instance named serverApps.

Install a server application on the second node of the network with index 1.

Highlight serverApps.Start(Seconds(1.0)) The Start method specifies the start time in seconds for the applications.

Set the start time of the applications to 1 second.

Highlight serverApps.Stop(Seconds(10.0)) The Stop method specifies the stop time in seconds.

Set the stop time to 10 seconds.

The time values are counted from the start of the simulation.

Highlight UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9) The UdpEchoClientHelper instance configures an echo client on a node.

An echo client sends data to an echo server.

The constructor takes two parameters.

The first one is the interface on which the application is to be installed.

The second is the port number.

Let’s create the client application helper instance.

The attributes are the client node and port number.

Highlight echoClient.SetAttribute("MaxPackets", UintegerValue(10)) The SetAttribute method sets attributes for the client.

The attributes include packet size, number of packets etc.

Hence here we set the maximum number of packets, to 10.

Highlight echoClient.SetAttribute("Interval", TimeValue(Seconds(0.5))) Then we set the time interval between the packet transmissions.

Here the value is 0.5 seconds.

Highlight echoClient.SetAttribute("PacketSize", UintegerValue(1024)) Next, set the packet size to 1024 bytes.
Highlight ApplicationContainer clientApps = echoClient.Install(nodes.Get(0)) Install the client application on the first node with index 0.
Highlight clientApps.Start(Seconds(2.0)) Then set the start time of the client application.

Here the start time is 2 seconds from the start of the simulation.

Highlight clientApps.Stop(Seconds(10.0)) Set the stop time to 10 seconds.
Highlight mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel") Let’s set a mobility model for the nodes.

The details about mobility shall be covered in future tutorials.

Highlight mobility.Install(nodes) Here we install the mobility model on the nodes.
Highlight AnimationInterface anim ("point-to-point.xml") Here we create an object of the AnimationInterface class.

The AnimationInterface class instance creates an XML file.

This file would be imported into NetAnim for animation.

The constructor takes the file name as a parameter.

Here the name of the file is point-to-point.xml.

Highlight anim.SetConstantPosition() The SetConstantPosition method sets the X-Y position for a node.

Using the anim object, we set the position for both the nodes.

The first argument is the node whose position is being set.

The second argument is the X coordinate.

The third argument is the Y coordinate.

Highlight Simulator::Run() The Run function is used to run the simulation.
Highlight Simulator::Destroy() And Destroy function ends the simulation.

Now close the text editor.

Press Ctrl,Alt and T keys simultaneously.

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

Type mv ~/Downloads/point-to-point.cc scratch/point-to-point.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/point-to-point.cc Run the command dot forward slash ns3 run space scratch forward slash point hyphen to hyphen point dot cc.

point to point 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 directory under ns-allinone-3.38

Type cd ~/ns-allinone-3.38/netanim

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. 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 button 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 point-to-point.xml file. In the file picker, navigate to the ns-3.38 directory.

Select the point-to-point.xml file.

Click on open at the bottom.

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 the circles representing the nodes.

The lines with arrows represent the transfer of packets.

Hover over node 0. Node 0 is the transmitter or the source node.
Hover over node 1. Node 1 is the receiver or the server node.
Show slide:

Summary

This brings us to the end of the tutorial.

Let us summarize.

In this tutorial, we have learnt

  • About the structure of an ns-3 program
  • About the classes and the methods
  • To create nodes
Show slide:
Summary
  • To establish a point-to-point connection between two nodes
  • To configure client and server applications on the nodes
  • To visualize the network using NetAnim
Show slide:
Assignment
As an assignment, please do the following:
  • Write an ns-3 program with two point-to-point networks
  • Set IP address 10.1.0.0 for the first network
  • Set IP address 10.2.0.0 for the second network
Show slide:

Assignment

  • Set different values for data rate, delay and packet size for each network
  • Install client and server applications in each network
Show slide:
Assignment
  • Start transfer of packets in each network simultaneously
  • Generate an XML file for NetAnim animation
Show slide: Assignment
  • Run the simulation in the terminal
  • Import the XML file in NetAnim and play the animation
Show slide:

Assignment - Observation

  • In the terminal, you will get this output.
  • Observe the differences for the two networks.
Show slide:

Assignment - Observation

  • In the NetAnim window, you will see two different networks.
  • Observe the packet transfer rate for each network.
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