Linux Rid
Linux Rid
CERTIFICATE
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
INSTALLATION STEPS:
1. sudo apt upgrade
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
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
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
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
THEORY:
o Star Topology:
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"
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;
//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
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.
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)
{
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
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.
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"
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;
cmd.Parse (argc,argv);
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);
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));
o ./waf output:
o Python Visualizer:
o NetAnim Output:
o Wireshark
CONCLUSION:
Hence we successfully simulated Wireless Network Topology.
Practical 6
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.
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);
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:
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.
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.
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);
LogComponentEnable("UdpEchoClientApplication",LOG_LEVEL_INFO);
}
Time stopTime = Seconds (20);
NS_LOG_INFO("Createnodes.");
NodeContainer nodes; NodeContainer
router; nodes.Create (3);
router.Create(2);
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;
//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"));
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:
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.
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:
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:
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;
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: