0% found this document useful (0 votes)
74 views8 pages

Practical 8

The document describes simulating a simple network using NetAnim in the Network Simulator ns-3. It discusses using a hybrid network topology, which combines elements of different topologies. The code simulates a network with 5 subnets connected by 4 routers in a hybrid configuration. It installs UDP echo client and server applications to generate and receive traffic. NetAnim is used to visualize the network simulation.

Uploaded by

panaspa1993
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)
74 views8 pages

Practical 8

The document describes simulating a simple network using NetAnim in the Network Simulator ns-3. It discusses using a hybrid network topology, which combines elements of different topologies. The code simulates a network with 5 subnets connected by 4 routers in a hybrid configuration. It installs UDP echo client and server applications to generate and receive traffic. NetAnim is used to visualize the network simulation.

Uploaded by

panaspa1993
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/ 8

ATHARVA KALE PRACTICAL NO.

8 ROLL NO: 27

AIM: Simulate a simple network using NetAnim in Network


Simulator.

 THEORY:
1. In this practical, the simple network that is animated using NetAnim in Network
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. Its usage and choice are dependent on its deployments and requirements like
the performance of the desired network, and the number of computers, their
location.
4. However, a variety of technologies are needed for its physical implementation,
and it offers a complex structure.
5. Also, it includes an advantage as increasing flexibility; it can increase fault
tolerance, and allows new basic topologies to be added or removed easily.
6. The hybrid topology is more useful when you need to fulfil diversity in Computer
Network. In this topology, all network sections can include the configuration of
different Network Topology.
7. Classes Used In Code:
a. Following different classes are used in code:
i. Node Class:
1. In ns-3 the basic computing device abstraction is called the
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.
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

ii. PointToPointHelper Class:


1. PointToPointNetDevice class 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.
iii. InternetStackHelper Class:
1. This helper enables pcap and ascii tracing of events in the
internet stack associated with a node.
2. This is substantially similar to the tracing that happens in
device helpers, but the important difference is that, well,
there is no device. This means that the creation of output
file names will change, and also the user-visible methods
will not reference devices and therefore the number of
trace enable methods is reduced.
3. Normally we avoid multiple inheritance in ns-3, however,
the classes PcapUserHelperForIpv4 and
AsciiTraceUserHelperForIpv4 are treated as "mixins". A
mixin is a self-contained class that encapsulates a general
attribute or a set of functionality that may be of interest to
many other classes.
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

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"

// Default Network Topology 10.1.5.0


// r2---------n1
// / 10.1.3.0
// no----------r0--------r1
// 10.1.1.0 10.1.2.0 \ 10.1.4.0

// r3

using namespace ns3;


NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
int main (int argc, char *argv[])
{
bool verbose = true;
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

}
bool useV6 = false;
CommandLine cmd (__FILE__);
cmd.AddValue ("useIpv6", "Use Ipv6", useV6);
cmd.Parse (argc, argv);
NodeContainer host, router, host1;
host.Create (2);
router.Create (4);
NodeContainer subnet1;
subnet1.Add (host.Get (0));
subnet1.Add (router.Get (0));
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer subnet1Devices;
subnet1Devices = pointToPoint.Install (subnet1);
InternetStackHelper stack;
stack.Install (router);
stack.Install (host);
Ipv4AddressHelper address1, address2, address3, address4, address5, address6;
address1.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer subnet1Interfaces;

subnet1Interfaces = address1.Assign (subnet1Devices);


NodeContainer subnet2;

subnet2.Add (router.Get (0));


subnet2.Add (router.Get (1));
NetDeviceContainer subnet2Devices;
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

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));
NetDeviceContainer subnet5Devices;

subnet5Devices = pointToPoint.Install (subnet5);


address5.SetBase ("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainer subnet5Interfaces;
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

subnet5Interfaces = address5.Assign (subnet5Devices);


UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (subnet5.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (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;
}
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

 OUTPUT:

o ./waf Output:

o Python Visualizer:
ATHARVA KALE PRACTICAL NO. 8 ROLL NO: 27

o NetAnim Output:

 CONCLUSION:
Hence we successfully simulated simple network using NetAnim in
Network Simulator.

You might also like