0% found this document useful (0 votes)
80 views54 pages

Linux Rid

linux 2024

Uploaded by

rohan937291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views54 pages

Linux Rid

linux 2024

Uploaded by

rohan937291
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

Institute of Distance and Open Learning

Vidya Nagari, Kalina, Santacruz East – 400098.

CERTIFICATE

This is to certify that Mr/Ms. Riddhi Hemant Warekar of Master in Computer


Application (MCA) Semester II has completed the specified term work in the subject
of Networking with Linux Practical satisfactorily within this institute as laid down
by University of Mumbai during the academic year 2023 to 2024

___________ ____________ ____________


Subject In-charge External Examiner Coordinator – M.C.A
INDEX
Subject: Networking with Linux Practical
Sr.
Experiment Name Sign. Remarks
No.
Practical 1: Installation of NS-3, NetAnim and WireShark
1
in Linux.
Practical 2: To simulate traffic between two nodes (point to
2
point).

3 Practical 3:To simulate Star Topology.

4 Practical 4: To simulate Bus Topology.

Practical 5: Program to simulate Wireless Network


5
Topology using netanim and pyviz.

6 Practical 6: Program to simulate UDP Server Client.

Practical 7: Program to simulate DHCP server and n


7
clients.
Practical 8: Simulate a simple network using NetAnim in
8
Network Simulator.

9 Practical 9: Program to simulate FTP using TCP protocol.


Practical 1

AIM: Installation of NS-3, NetAnim and WireShark in Linux.

 THEORY:
o NS3:
1. NS-3 is a discrete-event network simulator for Internet systems, targeted
primarily for research and educational use.
2. NS3 stands for Network Simulator Version 3.
3. The goal of the ns-3 project is to develop a preferred, open simulation
environment for networking research: it should be aligned with the
simulation needs of modern networking research..

o NetAnim:
1. NetAnim stands for Network Animator.
2. It is capable of animating simulations with PointToPoint links in NS-3.
3. NetAnim requires a custom trace file for animation. This trace file is
generated by an animation interface and is included in the current
version of NS-3. The file is mostly of .xml type.
4. Features of NetAnim are as follows:
a. Animate packets over wired-links and wireless-links (Limited
support for LTE traces. No support for Ipv6)
b. Packet timeline with regex filter on packet meta-data.
c. Node position statistics with node trajectory plotting (path of a
mobile node).
o Wireshark:
1. Wireshark is a free and open-source packet analyzer. It is used for
network troubleshooting, analysis, software and communications
protocol development, and education.
2. Wireshark is cross-platform, using the Qt widget toolkit in current
releases to implement its user interface, and using pcap to capture

packets; it runs on Linux, macOS, BSD, Solaris, some other Unix-like


operating systems, and Microsoft Windows.

 INSTALLATION STEPS:
1. sudo apt upgrade

2. Sudo apt update

3. sudo apt-get install g++ python3 python3-dev pkg-config sqlite3


4. sudo apt-get install gir1.2-goocanvas-2.0 python-gi python-gi-cairo python-
pygraphviz python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0
ipython ipython3Sudo a

5. pt-get install gdb valgrind

6. Sudo apt-get install doxygen graphviz texlive texlive-extra-utils texlive-latex-extra


texlive-font-utils dvipng latexmk python3-sphinx dia tcpdump cmake libc6-dev
libc6-dev-i386 libclang-6.0-dev llvm-6.0-dev automake python3-pip
python3 -m pip install --user cxxfilt
7. To install wireshark follow these steps:
8. sudo apt install Wireshark

9. After running the above command, you might be asked for confirmation, hit y,
and then hit Enter, after which installation of Wireshark will be started in your
system.
10. After installation completes verify it on terminal using command:
wireshark --version

 CONCLUSION:
Hence we successfully installed NS3, NetAnim and Wireshark on
Linux Operating System.
Practical 2

AIM:To simulate traffic between two nodes (point to point).

 THEORY:
o What is Node?
1. In Internet jargon, a computing device that connects to a network is
called a host or sometimes an end system.
2. Because ns-3 is a network simulator, not specifically an Internet
simulator, it do not use the term host since it is closely associated
with the Internet and its protocols.
3. Instead, it use a more generic term also used by other simulators that

originates in Graph Theory the node.

o Netdevice:
1. Net device abstraction covers both the software river and the simulated
hardware.
2. A net device is installed in a Node in order to enable the Node to
communicate with other Nodes in the simulation via Channels.
3. Just as in a real computer, a Node may be connected to more than one
Channel via multiple NetDevices.
4. The net device abstraction is represented in C++ by the class NetDevice.
The Net Device class provides methods formanaging connections to Node
and Channel objects

o Classes used In code:


1. Following different classes are used in code:
a. NodeClass:
i. Inns-3thebasiccomputingdeviceabstractioniscalledthe
node. This abstraction is represented in C++ by the class
Node.
ii. The Node class provides methods for managing the
representations of computing devices in
simulations.
b. Application Class:
i. In ns-3 the basic abstraction for a user program that
generates some activity to be simulated is the application.
This abstraction is represented in C++ by the class
Application.
c. Channel Class:
i. The basic communication subnetwork abstraction is called
the channel and is represented in C++ by the class
Channel.

A) The Channel class provides methods for managing


communication subnetwork objects and connecting nodes to
them.Write a Program to simulate traffic between two nodes (point to
point).

 CODE:
#include "ns3/core-module.h"
#include"ns3/network-module.h"
#include"ns3/internet-module.h"
#include"ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
//Default Network Topology
//
// 10.1.1.0
//n0 n1
// point-to-point
//

usingnamespacens3;
NS_LOG_COMPONENT_DEFINE("First Script Example"); int main (int
argc, char *argv[])
{
CommandLine cmd (FILE);
cmd.Parse (argc, argv);
Time::SetResolution(Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication",LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelperpointToPoint;
pointToPoint.SetDeviceAttribute("DataRate",StringValue("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices=pointToPoint.Install(nodes);
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase("10.1.1.0","255.255.255.0");
Ipv4InterfaceContainer interfaces=address.Assign(devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get(1));
serverApps.Start (Seconds (1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainerclientApps=echoClient.Install(nodes.Get(0));
clientApps.Start (Seconds (2.0));
clientApps.Stop(Seconds(10.0));
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(nodes);
AnimationInterface anim("first.xml");
AnimationInterface::SetConstantPosition(nodes.Get(0),10,25);
AnimationInterface::SetConstantPosition(nodes.Get(1),40,25);
anim.EnablePacketMetadata(true);
Simulator::Run ();
Simulator::Destroy();

return0;
}

 OUTPUT:
o OPOF ./waf:

OPofPython Visualizer:
o OPof NetAnim:

 CONCLUSION:
Hence we successfully simulated traffic between two nodes (point
to point).
Practical 3

AIM: To simulate Star Topology.

 THEORY:
o Star Topology:

1.Star topology is a network topology where each individual piece of a


network is attached to a central node called hub. The star topology is
one of the most common computer network topologies.
2.The attachment of these network pieces to the central component
is visually represented in a form similar to a star.
3. Star topology is also known as a star network.
4.The central network device acts as a server and the peripheral devices
act as clients.
5.The hub and hosts, and the transmission lines between them, forma
graph with the topology of a star.
6. Disadvantages of star topology
a. May have a higher cost to implement, especially when using a
switch or router as the central network device.

b. The central network device determines the performance


and number of nodes the network can handle.
c. If the central computer, hub, or switch fails, the entire network
goes down and all computers are disconnected from the
network.
o How star topology works:
1.Star Network, simply comprises of a central device referred as Hub
and all the Network Nodes run wires to this central device.
2.Connect Servers, Clients and other Network Devices to the central Hub
with the help of patch cables.
3. Data can be transferred from one node to other through hub.
4. Data first is sent to the hub with the address of the destination node.
o Classes UsedIn Code:
1. Following different classes are use din code:

a. Application Container Class:


i. Typicallyns-3Applicationsareinstalledonnodesusingan
Application helper. The helper Install method takes a
NodeContainer which holds some number of Ptr<Node>.
ii. For each of the Nodes in the NodeContainer the helper will
instantiate an application, install it in a node and add a
Ptr<Application> to that application into a Container for
use by the caller.

b. Ipv4 Address HelperClass:


i. AhelperclasstomakelifeeasierwhiledoingsimpleIPv4
address assignment in scripts.

ii. This class is a very simple IPv4 address generator. You can
think of it as a simple local number in crementer. It has no
notion that IP addresses are part of a global address space.
c. Inet Socket Address Class:
i. This class is similar to inet_sock addr in the BSD socket
API. i.e., this class holds an Ipv4Address and a port
number to form an ipv4 transport endpoint.
d. Address Class:
i. This class is very similar in design and spirit to the BSD
sockaddr structure: they are both used to hold multiple
types of addresses together with the type of the address.
ii. A new address class defined by a user needs to:
1. Allocate a type id with Address::Register
2. Provide a method to convert his new address to an
Address instance. This method is typically a
member method named Convert To: Address My
Address::Convert To (void) const;
A) Write a program to simulate star topology.

 CODE:

#include "ns3/core-module.h"
#include"ns3/network-module.h"
#include"ns3/netanim-
module.h"#include"ns3/internet-
module.h"

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

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

using namespace ns3;


NS_LOG_COMPONENT_DEFINE("Star");

intmain(intargc,char *argv[])
{

//

//Setupsomedefaultvaluesforthesimulation.

//

Config::SetDefault("ns3::OnOffApplication::PacketSize",UintegerValue(137));

//???tryandstick15kb/sintothedatarate

Config::SetDefault("ns3::OnOffApplication::DataRate",StringValue("14kb/s"));

//

//Defaultnumberofnodesinthestar.Overridablebycommandlineargument.

//

uint32_tnSpokes= 8;
std::stringanimfile="staranim.xml";
CommandLine cmd (FILE);

cmd.AddValue("nSpokes","Numberofnodestoplaceinthestar",nSpokes); cmd.Parse
(argc, argv);

NS_LOG_INFO("Buildstartopology.");
PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute("DataRate",StringValue("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointStarHelper star (nSpokes, pointToPoint);

NS_LOG_INFO("Installinternetstackonallnodes."); InternetStackHelper
internet;

star.InstallStack (internet);
NS_LOG_INFO("AssignIPAddresses.");

star.AssignIpv4Addresses(Ipv4AddressHelper("10.1.1.0","255.255.255.0"));
NS_LOG_INFO ("Create applications.");

//

//Createapacketsinkonthestar"hub"toreceive packets.

//

uint16_tport=50000;

Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));


PacketSinkHelperpacketSinkHelper("ns3::TcpSocketFactory",hubLocalAddress); //

//Dopcaptracingonallpoint-to-pointdevicesonallnodes.

//

pointToPoint.EnablePcapAll("star");
star.BoundingBox (1, 1, 100, 100);
AnimationInterface anim(animfile);
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();NS_LOG_INFO
("Done.");

return0;
}

 OUTPUT:
o ./wafoutput

o PythonVisualizer
o NetAnimOutput

CONCLUSION: Hence we successfully simulated Star Topology


Practical 4

AIM: To simulate Bus Topology.

 THEORY:
o BusTopology:
1. A bus network is a network topology in which nodes are directly
connected to a common half-duplex link called a bus.
2. A host on a bus network is called a station. In a bus network, every
stationwillreceiveallnetworktraffic,andthetrafficgeneratedbyeach
station has equal transmission priority.
3. A bus network forms a single network segment and collision domain. In
order for nodes to share the bus, they use a medium access control
technology such as carrier-sense multiple access (CSMA) or a bus master.
4. Advantages
a. Very easy to connect a computer or peripheral to a linear bus.
b. Requires less cable length than a star network resulting in
lower costs.
c. The linear architecture is very simple and reliable.
d. It works well for small networks.
e. It is easy to extend by joining cable with connect or orrepeater.

A) Write a program to simulate bus topology.

 CODE:

#include "ns3/core-module.h"
#include"ns3/network-
module.h" #include
"ns3/csma-module.h"
#include"ns3/internet-
module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include"ns3/ipv4-global-routing-
helper.h" #include "ns3/netanim-
module.h"
#include"ns3/mobility-
module.h" using namespace
ns3;
NS_LOG_COMPONENT_DEFINE("SecondScriptExamp
le"); int main (int argc, char *argv[])
{

bool verbose=true;
uint32_t nCsma = 3;
CommandLinecmd(FILE);
cmd.AddValue("nCsma","Numberof\"extra\"CSMAnodes/devices",nCsma);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.Parse (argc,argv);
if(verbose)
{

LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);


LogComponentEnable("UdpEchoServerApplication",LOG_LEVEL_INFO);
}

nCsma = nCsma == 0 ? 1 : nCsma;


NodeContainer p2pNodes;
p2pNodes.Create (2);
NodeContainer csmaNodes;
csmaNodes.Add(p2pNodes.Get(1));
csmaNodes.Create (nCsma);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute("DataRate",StringValue("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices=pointToPoint.Install(p2pNodes);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute("Delay",TimeValue(NanoSeconds(6560)));
NetDeviceContainer csmaDevices;
csmaDevices=csma.Install(csmaNodes);
InternetStackHelper stack;
stack.Install(p2pNodes.Get(0));
stack.Install (csmaNodes);
Ipv4AddressHelper address;

address.SetBase("10.1.1.0","255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces=address.Assign(p2pDevices);

address.SetBase("10.1.2.0","255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces=address.Assign(csmaDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainerserverApps=echoServer.Install(csmaNodes.Get(nCsma))
; serverApps.Start (Seconds (1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelperechoClient(csmaInterfaces.GetAddress(nCsma),9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (p2pNodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables
(); pointToPoint.EnablePcapAll
("second");csma.EnablePcap ("second",
csmaDevices.Get (1), true); MobilityHelper mobility;

t(3),60,25); anim.EnablePacketMetadata(true);
Simulator::Run ();
Simulator::Destroy();
return 0;
}

 OUTPUT:
o ./wafoutput:

o PythonVisualizer

o NetAnimOutput
 CONCLUSION:
Hence we successfully simulated Bus Topology.
Practical 5

AIM: Program to simulate Wireless Network Topology using


netanim and pyviz.

 THEORY:
1. A Wireless network is a type of the computer network that uses the wireless
connections for connecting network nodes for data transfer.
2. Wireless network topology shows how the computers connect each other when
there is no physical connection. The computers communicate each using the
wireless devices.
3. The wireless networks are very useful, inexpensive, popular and widely used.
They are easy setup and do not require the cables installation.

1. The Node class provides methods for managing the


representations of computing devices in simulations.
ii. PointToPointHelper Class:
1. PointToPointNetDevice class specializes the NetDevice
abstract base class.
iii. NetDevice Class:
1. Net device abstraction covers both the software driver and
the simulated hardware. The net device abstraction is
represented in C++ by the class NetDevice.

iv. Ipv4AddressHelper Class:


1. A helper class to make life easier while doing simple IPv4
address assignment in scripts.
2. This class is a very simple IPv4 address generator. You can
think of it as a simple local number incrementer. It has no
notion that IP addresses are part of a global address space.

A) Write a program to simulate wireless network


topology.

 CODE:
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
#include "ns3/netanim-module.h"

// Default Network Topology


//
// Wifi 10.1.3.0
// AP
// * * * *
// | | | | 10.1.1.0
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.2.0

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nWifi = 3;
bool tracing = false;

CommandLine cmd (__FILE__);


cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);

cmd.Parse (argc,argv);

// The underlying restriction of 18 is due to the grid position


// allocator's configuration; the grid layout will exceed the
// bounding box if more than 18 nodes are provided.
if (nWifi > 18)
{
std::cout << "nWifi should be 18 or less; otherwise grid layout exceeds the
bounding box" << std::endl;
return 1;
}

if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}

NodeContainer p2pNodes;
p2pNodes.Create (2);

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);

YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();


phy.SetChannel (channel.Create ());

WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));

anim.UpdateNodeDescription (wifiApNode.Get (i), "AP"); // Optional


anim.UpdateNodeColor (wifiApNode.Get (i), 0, 255, 0); // Optional
}
for (uint32_t i = 0; i < csmaNodes.GetN (); ++i)
{

anim.UpdateNodeDescription (csmaNodes.Get (i), "CSMA"); // Optional


anim.UpdateNodeColor (csmaNodes.Get (i), 0, 0, 255); // Optional
}
anim.EnablePacketMetadata (); // Optional
anim.EnableIpv4RouteTracking ("routingtable-wireless.xml", Seconds (0), Seconds
(5), Seconds (0.25)); //Optional
anim.EnableWifiMacCounters (Seconds (0), Seconds (10)); //Optional
anim.EnableWifiPhyCounters (Seconds (0), Seconds (10)); //Optional
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
 OUTPUT:

o ./waf output:

o Python Visualizer:
o NetAnim Output:
o Wireshark

 CONCLUSION:
Hence we successfully simulated Wireless Network Topology.
Practical 6

AIM: Program to simulate UDPServer Client.

 THEORY:
1. In computer networking, the User Data gram Protocol (UDP)is one of the
core members of the Internet protocol suite.
2. With UDP, computer applications can send messages, in this case referred to as
data grams, to other hosts on an Internet Protocol (IP) network. Prior
communicationsarenotrequiredinordertosetupcommunicationchannelsor data
paths.
3. UDP uses a simple connection less communication model with a minimum
of protocol mechanisms.
4. Classes Used In Code:
a. Following different classes are use din code:
i. Ipv4AddressHelperClass:
1. AhelperclasstomakelifeeasierwhiledoingsimpleIPv4
address assignment in scripts.
2. This class is a very simple IPv4 address generator. You can
think of it as a simple local number incrementer. It has no
notion that IP addresses are part of a global address space.
ii. Udp Client Helper Class:
1. It create a client application which sends UDP packets
carryinga32bitsequencenumberanda64bittimestamp.
2. It sends UDP packet carrying sequence number and time
stamp in their payloads.
iii. Net Device Class:
1. Netdevice abstraction covers both the software driver and
the simulated hardware. The net device abstraction is
represented in C++ by the class NetDevice.
2. The NetDevice class provides methods for managing
connections to Node and Channel objects ; and may
be specialized by developers in the object-oriented
programming sense.

iv. Application Class:


A) In ns-3 the basic abstraction for a user program that generates some activity to be
simulated is the application. This abstraction is represented in C++ by the class

Application.Write a program to simulate UDP server client.

 CODE:
//Networktopology
//
// n0 n1
// | |
// =======
// LAN
//
//-UDPflowsfromn0ton1

#include<fstream>
#include "ns3/core-module.h"
#include "ns3/csma-module.h"
#include"ns3/applications-module.h"
#include "ns3/internet-module.h"
#include "ns3/netanim-module.h"
using namespace ns3;

NS_LOG_COMPONENT_DEFINE("UdpClientServerExample");

int
main(intargc,char*argv[])
{
//
//EnableloggingforUdpClientand
//
LogComponentEnable("UdpClient",LOG_LEVEL_INFO);
LogComponentEnable("UdpServer",LOG_LEVEL_INFO);

bool useV6 = false;


AddressserverAddress;

CommandLinecmd(FILE);
cmd.AddValue("useIpv6","UseIpv6",useV6); cmd.Parse (argc,
argv);

//
//Explicitlycreatethenodesrequiredbythetopology(shown above).
//

NS_LOG_INFO("Createnodes.");
NodeContainer n;
n.Create(2);

InternetStackHelperinternet;
internet.Install (n);

NS_LOG_INFO("Createchannels.");
//
//Explicitlycreatethechannelsrequiredbythetopology(shownabove).
//

CsmaHelpercsma;
csma.SetChannelAttribute("DataRate",DataRateValue(DataRate(5000000)));
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); csma.SetDeviceAttribute
("Mtu", UintegerValue (1400));
NetDeviceContainerd=csma.Install(n);
//
//node one.
//
uint32_tMaxPacketSize=1024;
Time interPacketInterval = Seconds (0.05); uint32_t
maxPacketCount = 320;
UdpClientHelperclient(serverAddress,port);
client.SetAttribute("MaxPackets",UintegerValue(maxPacketCount));
client.SetAttribute ("Interval", TimeValue (interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue (MaxPacketSize)); apps =
client.Install (n.Get (0));
apps.Start(Seconds(2.0));
apps.Stop (Seconds (10.0));
AnimationInterfaceanim("udp.xml");
//
//Now,dotheactual simulation.
//

NS_LOG_INFO("RunSimulation.");
Simulator::Run (); Simulator::Destroy ();
NS_LOG_INFO ("Done.");
}

 OUTPUT:
o ./wafoutput:

o PythonVisualizer:
o NetAnimOutput:

CONCLUSION: Hence we successfully simulated UDP Server Client

Practical 7
AIM:ProgramtosimulateDHCPserverandn clients.

 THEORY:
1. The Dynamic Host Configuration Protocol (DHCP) is a network management
protocol used on Internet Protocol (IP) networks for automatically assigning IP
addresses and other communication parameters to devices connected to the
network using a client–server architecture.
2. The technology eliminates the need for individually configuring network devices
manually, and consists of two network components, a centrally installed
network DHCP server and client instances of the protocol stack on each
computer or device.

3. Working:
a. DHCP works by leasing IP addresses and IP information to network clients
for a period of time. For the lease to happen, the following negotiation
process occurs:
b. During the boot process, a client computer that is configured as a DHCP
client sends out a broad cast packet called DHCP DISCOVER. This
Discover packet contains the client’s computer name and Media Access
Control (MAC) address so the DHCP servers can respond to it.

client’s IP address lease as well as other IP addressing information that


you con figure the server to provide. The client is now a TCP/IP client
and can participate on the network.
4. Classes Used In Code:
a. Following different classes are use din code:

i. Node Class:
1. Inns-3thebasiccomputingdeviceabstractioniscalledthe
node. This abstraction is represented in C++ by the class
Node.
2. The Node class provides methods for managing the
representations of computing devices in
simulations.
ii. Point To Point Helper Class:
1. Point To Point Net Device class specializes the
NetDevice abstract base class.
2. Together with a Point To Point Channel the class models,
with some level of abstraction, a generic point-to-point or
serial link. Key parameters or objects that can be specified
for this device include a queue, data rate, and inter frame
transmission gap.

iii. Dhcp Helper Class:


1. The helper class used to configure and install
DHCP applications on nodes.
iv. NetDevice Class:
1. Netdevice abstraction covers both the software river and
the simulated hardware. The net device abstraction is
represented in C++ by the class NetDevice.

2. The NetDevice class provides methods for managing


connections to Node and Channel objects ; and may
beSpecialized by developers in the object-oriented
programming sense.

A) Write a program to simulate DHCP server andn clients.

 CODE:
#include"ns3/core-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/csma-module.h"#include
"ns3/internet-module.h"
#include"ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"using
namespace ns3;
NS_LOG_COMPONENT_DEFINE("DhcpExample");
Int main (int argc, char *argv[])
{
CommandLinecmd(FILE);

boolverbose=false; bool tracing =


false;
cmd.AddValue ("verbose", "turn on the logs", verbose);
cmd.AddValue("tracing","turnonthetracing",tracing); cmd.Parse (argc,
argv);
//GlobalValue::Bind("ChecksumEnabled",BooleanValue(true)); if (verbose)
{
LogComponentEnable ("DhcpServer", LOG_LEVEL_ALL);
LogComponentEnable ("DhcpClient", LOG_LEVEL_ALL);
LogComponentEnable("UdpEchoServerApplication",LOG_LEVEL_INFO);

LogComponentEnable("UdpEchoClientApplication",LOG_LEVEL_INFO);
}
Time stopTime = Seconds (20);
NS_LOG_INFO("Createnodes.");
NodeContainer nodes; NodeContainer
router; nodes.Create (3);
router.Create(2);

NodeContainer net (nodes,router);

NS_LOG_INFO("Createchannels."); CsmaHelper
csma;
csma.SetChannelAttribute("DataRate",StringValue("5Mbps"));
csma.SetChannelAttribute ("Delay", StringValue ("2ms"));
csma.SetDeviceAttribute ("Mtu", UintegerValue (1500));
NetDeviceContainer devNet = csma.Install (net);

NodeContainer p2pNodes;
p2pNodes.Add(net.Get(4));
p2pNodes.Create(1);
PointToPointHelperpointToPoint;
pointToPoint.SetDeviceAttribute("DataRate",StringValue("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));

NetDeviceContainerp2pDevices;
p2pDevices=pointToPoint.Install(p2pNodes);
InternetStackHelper tcpip; tcpip.Install
(nodes); tcpip.Install (router);
tcpip.Install(p2pNodes.Get(1));

Ipv4AddressHelperaddress;
address.SetBase("172.30.1.0","255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces=address.Assign(p2pDevices);

//manuallyaddaroutingentrybecausewedon'twanttoaddadynamicrouting Ipv4StaticRoutingHelper
ipv4RoutingHelper;
Ptr<Ipv4>ipv4Ptr=p2pNodes.Get(1)->GetObject<Ipv4> ();
Ptr<Ipv4StaticRouting>staticRoutingA=ipv4RoutingHelper.GetStaticRouting(ipv4Ptr);
staticRoutingA->AddNetworkRouteTo (Ipv4Address ("172.30.0.0"), Ipv4Mask ("/24"),
Ipv4Address("172.30.1.1"),1);

NS_LOG_INFO("SetuptheIPaddressesandcreateDHCPapplications."); DhcpHelper
dhcpHelper;

//The routermusthaveafixed IP.


Ipv4InterfaceContainerfixedNodes=dhcpHelper.InstallFixedAddress(devNet.Get(4),
Ipv4Address ("172.30.0.17"), Ipv4Mask ("/24"));
// Not really necessary, IP forwarding is enabled by default in IPv4.
fixedNodes.Get(0).first->SetAttribute("IpForward",BooleanValue(true));

//DHCPserver
ApplicationContainerdhcpServerApp=dhcpHelper.InstallDhcpServer(devNet.Get(3),
Ipv4Address ("172.30.0.12"),

//Thisisjusttoshowhowit canbedone.
DynamicCast<DhcpServer>(dhcpServerApp.Get(0))->AddStaticDhcpEntry(devNet.Get
(2)->GetAddress (), Ipv4Address ("172.30.0.14"));

echoClient.SetAttribute ("MaxPackets", UintegerValue (100));


echoClient.SetAttribute("Interval",TimeValue(Seconds(1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

ApplicationContainerclientApps=echoClient.Install(nodes.Get(1)); clientApps.Start
(Seconds (10.0));
clientApps.Stop(stopTime);

Simulator::Stop(stopTime+Seconds(10.0)); if (tracing)
{
csma.EnablePcapAll ("dhcp-csma");
pointToPoint.EnablePcapAll("dhcp-p2p");
}

AnimationInterfaceanim("dhcp.xml");
NS_LOG_INFO ("Run Simulation.");
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO("Done.");
}
 OUTPUT:
o ./waf Output:

o Python Visualizer:
o NetAnim Output:

 CONCLUSION: Hence we successfully simulated DHC Pserver


andn clients.

Practical 8
AIM: Simulate a simple network using NetAnim in Network
Simulator.

 THEORY:
1. In this practical, the simple network that is animated using NetAniminNetwork
Simulator is Hybrid Topology.
2. A hybrid topology is a kind of network topology that is a combination of two
or more network topologies, such as mesh topology, bus topology, and ring
topology.
3. It susage and choice are dependenton its deployments and requirement slike
the performance of the desired network, and the number of computers, their
location.
4. However,avariety of technologies are needed for its physical implementation,
and it offers a complex structure.
5. Classes Used InCode:
a. Following different classes are use din code:
i. Node Class:
1. Inns-3thebasiccomputingdeviceabstractioniscalledthe
node. This abstraction is represented in C++ by the class
Node.
2. The Node class provides methods for managing the
representations of computing devices in simulations.
ii. Point To Point Helper Class:
1. Point To Point NetDeviceclass specializes the
NetDevice abstract base class.
2. Together with a PointToPointChannel the class models,
with some level of abstraction, a generic point-to-point or
serial link. Key parameters or objects that can be specified
for this device include a queue, data rate, and interframe
transmission gap.

A) Write a program to simulate a simple network.

 CODE:
#include "ns3/core-module.h"
#include"ns3/network-module.h"
#include "ns3/csma-module.h"
#include"ns3/internet-module.h"
#include "ns3/point-to-point-module.h" #include
"ns3/applications-module.h" #include"ns3/ipv4-
global-routing-helper.h" #include "ns3/netanim-
module.h"

//DefaultNetworkTopology 10.1.5.0
//r2 ------------------- n1
///10.1.3.0
//no r0 r1
// 10.1.1.010.1.2.0\10.1.4.0

//r3

usingnamespacens3;
NS_LOG_COMPONENT_DEFINE("SecondScriptExample"); int main
(int argc, char *argv[])
{
boolverbose=true; if
(verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable("UdpEchoServerApplication",LOG_LEVEL_INFO);

}
bool useV6 = false;
CommandLinecmd(FILE);
cmd.AddValue("useIpv6","UseIpv6",useV6); cmd.Parse
(argc, argv);
NodeContainerhost,router,host1; host.Create (2);
router.Create (4); NodeContainer
subnet1; subnet1.Add(host.Get(0));
subnet1.Add (router.Get (0));
PointToPointHelperpointToPoint;
pointToPoint.SetDeviceAttribute("DataRate",StringValue("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms")); NetDeviceContainer
subnet1Devices;
subnet1Devices=pointToPoint.Install(subnet1);
InternetStackHelper stack;
stack.Install(router);
stack.Install (host);
Ipv4AddressHelperaddress1,address2,address3,address4,address5,address6; address1.SetBase
("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainersubnet1Interfaces;

subnet1Interfaces=address1.Assign(subnet1Devices);
NodeContainer subnet2;

subnet2.Add(router.Get(0));
subnet2.Add (router.Get (1));
NetDeviceContainersubnet2Devices;
subnet2Devices=pointToPoint.Install(subnet2); address2.SetBase
("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer subnet2Interfaces;
subnet2Interfaces=address2.Assign(subnet2Devices);
NodeContainer subnet3;
subnet3.Add(router.Get(1));
subnet3.Add (router.Get (2)); NetDeviceContainer
subnet3Devices;
subnet3Devices=pointToPoint.Install(subnet3);
address3.SetBase ("10.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer subnet3Interfaces;
subnet3Interfaces=address3.Assign(subnet3Devices);
NodeContainer subnet4;
subnet4.Add(router.Get(1));
subnet4.Add (router.Get (3)); NetDeviceContainer
subnet4Devices;
subnet4Devices=pointToPoint.Install(subnet4);
address4.SetBase ("10.1.4.0", "255.255.255.0");
Ipv4InterfaceContainer subnet4Interfaces;
subnet4Interfaces=address4.Assign(subnet4Devices);
NodeContainer subnet5;
subnet5.Add(router.Get(2));
subnet5.Add (host.Get (1));
NetDeviceContainersubnet5Devices;

subnet5Devices=pointToPoint.Install(subnet5); address5.SetBase
("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainersubnet5Interfaces;
subnet5Interfaces=address5.Assign(subnet5Devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainerserverApps=echoServer.Install(subnet5.Get(1)); serverApps.Start
(Seconds (1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelperechoClient(subnet5Interfaces.GetAddress(1),9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (3)); echoClient.SetAttribute
("Interval", TimeValue (Seconds (1.0))); echoClient.SetAttribute ("PacketSize",
UintegerValue (1024)); ApplicationContainer clientApps = echoClient.Install (subnet1.Get
(0)); clientApps.Start (Seconds (1.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
AnimationInterface anim("ftp-tcp.xml"); Simulator::Run ();
Simulator::Destroy(); return
0;
}

 OUTPUT:

o ./waf Output:

o Python Visualizer:
o NetAnim Output:

 CONCLUSION: Hence we successfully simulated simple


network using NetAnim in Network Simulator.
Practical 9

AIM:Program to simulate FTP using TCP protocol.

 THEORY:
1. The File Transfer Protocol (FTP) Is a standard communication protocol used
for the transfer of computer files from a server to a client on a computer
network.
2. FTPisbuiltonaclient–servermodelarchitectureusingseparatecontrolanddata
connections between the client and the server.
3. Working:
a. FTP servers are the solutions used to facilitate file transfers across
the internet.
b. FTP is based on the TCP protocol service, which is a file transfer protocol
on the Internet.
c. By default, two ports 20 and 21 are used, a data port and a command
port, and port 20 is a data port for file transfer between the client and
theserverdataflow.Port21isacommandportusedtotransmitcontrol flow
and accept related FTP commands and parameters issued by the client.
4. Classes Used InCode:
a. Following different classes are use din code:

i. Ipv4 Address Helper Class:


1. A helper class to make life easier while doing simple IPv4
address assignment in scripts.
2. This class is a very simple IPv4 address generator. You can
think of it as a simple local number incrementer. It has no
notion that IP addresses are part of a global address space.
3. If you have a complicated address assignment situation
youmaywanttolookattheIpv4AddressGeneratorwhich
does recognize that IP address and network number
generationispartofaglobalproblem.Ipv4AddressHelper is a
simple class to make simple problems easy to handle.
ii. Node Class:
1. Inns-3thebasiccomputingdeviceabstractioniscalledthe
node. This abstraction is represented in C++ by the class
Node.
2. The Node class provides methods for managing the
representations of computing devices in simulations.
iii. Packet Sink Helper Class:
1. A helper to make it easier to instantiate an
ns3::Packet Sink Application on a set of
nodes.
iv. As cii Trace Helper Class
1. It manages ASCII tracefiles for device models.
2. Handlingasciitracefilesisacommonoperationforns-3
devices. It is useful to provide a common base class for
dealing with these ops.

A) Write a program to simulate FTP using TC Pprotocol.

 CODE:
#include<iostream>
#include <fstream>
#include <string>
#include "ns3/core-module.h"
#include"ns3/applications-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include"ns3/ipv4-global-routing-helper.h"
#include "ns3/netanim-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("TcpLargeTransfer");
//Thenumberofbytestosendinthissimulation.
static const uint32_t totalTxBytes = 2000000;
static uint32_t currentTxBytes = 0;
//Performseriesof1040bytewrites(thisisamultipleof26since
//wewanttodetectdatasplicingintheoutputstream) static
const uint32_t writeSize = 1040;
uint8_tdata[writeSize];

//Theseareforstartingthewritingprocess,andhandlingthe sending
//socket'snotificationupcalls(events).Thesetwotogethermoreorless
//implementasending"Application",althoughnotaproperns3::Application
//subclass.
voidStartFlow(Ptr<Socket>,Ipv4Address,uint16_t);
void WriteUntilBufferFull (Ptr<Socket>, uint32_t);
static void
CwndTracer(uint32_toldval,uint32_t newval)
{

NS_LOG_INFO("Movingcwndfrom"<<oldval<<"to"<< newval);
}
intmain(intargc,char *argv[])
{
//Usersmayfinditconvenienttoturnonexplicitdebugging
//forselectedmodules;thebelowlinessuggesthowtodo this
//LogComponentEnable("TcpL4Protocol",LOG_LEVEL_ALL);
//LogComponentEnable("TcpSocketImpl",LOG_LEVEL_ALL);
//LogComponentEnable("PacketSink",LOG_LEVEL_ALL);
//LogComponentEnable("TcpLargeTransfer",LOG_LEVEL_ALL); CommandLine cmd
(FILE);
cmd.Parse(argc, argv);
// initialize the tx buffer.
for(uint32_ti=0;i<writeSize;++i)
{
charm=toascii(97+i%26); data[i] =
m;
}
//Here,wewillexplicitlycreatethreenodes.Thefirstcontainercontains
//nodes0and1fromthediagram above,andthesecondonecontainsnodes
//1and2.Thisreflectsthechannelconnectivity,andwillbeusedto
//installthenetworkinterfacesandconnectthemwithachannel. NodeContainer n0n1;

n0n1.Create (2); NodeContainer n1n2;


n1n2.Add(n0n1.Get(1));
n1n2.Create(1);
//WecreatethechannelsfirstwithoutanyIPaddressinginformation
//Firstmakeandconfigurethehelper,sothatitwillputtheappropriate
//attributesonthenetworkinterfacesandchannelsweareabouttoinstall. PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate",DataRateValue(DataRate(10000000)));
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10)));
//Andtheninstalldevicesandchannelsconnectingourtopology.
NetDeviceContainer dev0 = p2p.Install (n0n1); NetDeviceContainer dev1 =
p2p.Install (n1n2);
//Nowaddip/tcpstacktoallnodes.
InternetStackHelper internet;
internet.InstallAll ();
//Later,weaddIPaddresses.
Ipv4AddressHelper ipv4;
ipv4.SetBase("10.1.3.0","255.255.255.0");
ipv4.Assign(dev0);
ipv4.SetBase("10.1.2.0","255.255.255.0");
Ipv4InterfaceContaineripInterfs=ipv4.Assign(dev1);
//andsetupiproutingtablestogettotalip-levelconnectivity.
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
///////////////////////////////////////////////////////////////////////////
//Simulation1
//
//Send2000000bytesover aconnectiontoserver port50000 attime0
//ShouldobserveSYNexchange,alot ofdatasegmentsandACKS,andFIN
}

voidWriteUntilBufferFull(Ptr<Socket>localSocket,uint32_ttxSpace)
{
while(currentTxBytes<totalTxBytes&&localSocket->GetTxAvailable()>0)
{
uint32_t left = totalTxBytes - currentTxBytes;
uint32_tdataOffset=currentTxBytes%writeSize;
uint32_t toWrite = writeSize - dataOffset;toWrite
= std::min (toWrite, left);
toWrite=std::min(toWrite,localSocket->GetTxAvailable ());
intamountSent=localSocket->Send(&data[dataOffset],toWrite,0);
if(amountSent < 0)
{
//wewillbecalledagainwhennewtxspacebecomesavailable. return;
}
currentTxBytes+=amountSent;
}
if(currentTxBytes>=totalTxBytes)
{
localSocket->Close();
}
}
 OUTPUT:
o PythonVisualizer:

o NetAnim Output:

 CONCLUSION: Hence we successfully simulated FTP


using TCP protocol.

You might also like