Академический Документы
Профессиональный Документы
Культура Документы
04614802716
INDEX
Experiment 1
Theory:-
System:
A collection of entities that act and interact together toward the accomplishment of
some logical end.
Discrete system:
State variables change instantaneously at separated point in time, e.g., a bank, since
state variables - number of customers, change only when a customer arrives or when a
customer finishes being served and departs
Continuous system:
State variable change continuously with respect to time, e.g., airplane moving through
the air, since state variables - position and velocity change continuously with respect to
time
HEMANT AGRAWAL
04614802716
Dynamic systems:
Definition: It is a system in which output at any instant of time depends on input sample
at the same time as well as at other times.
Here other time means, other than the present time instant. It may be past time or future
time. Note that if x(n) represents input signal at present instant then,
1) x(n-k); that means delayed input signal is called as past signal.
2) x(n+k); that means advanced input signal is called as future signal.
Thus in dynamic systems, output depends on present input as well as past or future
inputs.
HEMANT AGRAWAL
04614802716
Experiment 2
Theory
NS-3 is a discrete-event network simulator, targeted primarily for research and
educational use. ns-3 is free software, licensed under the GNU GPLv2 license, and is
publicly available for research, development, and use.
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 and should encourage community contribution, peer review, and
validation of the software.
NS3 is not backward compatible with NS2; it's built from the scratch to replace NS2.
NS3 is written in C++, Python Programming Language can be optionally used as an
interface.
NS3 is trying to solve problems present in NS2.
There is very limited number of contributed codes made with NS3 compared to NS2
In NS2, bi-language system make debugging complex (C++/Tcl), but for NS3 only
knowledge of C++ is enough (single-language architecture is more robust in the long
term).
NS3 has an emulation mode, which allows for the integration with real networks.
Experiment 3
Theory:-
Following are the basic steps that must be followed for installing NS3
1. Install Prerequisite packages
2. Download NS3 codes
3. Build NS3
4. Validate NS3
Experiment 4
Theory:-
Node
Because in any network simulation, we will need nodes. So ns-3 comes with
NodeContainer that you can use to manage all the nodes (Add, Create, Iterate, etc.)
// Create two nodes to hold.
Node Container nodes;
nodes. Create (2);
Then we need to install the devices. The internal of Install is actually more complicated,
but for now, let’s just skip the magic behind the scene.
// NetDevice: installed onto the channel
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
HEMANT AGRAWAL
04614802716
Protocols
Internet and IPv4. Since Internet is the current largest network to study, ns-3 has a
particular focus on it. The InternetStackHelper will install an Internet Stack (TCP, UDP,
IP, etc.) on each of the nodes in the node container.
// Protocol Stack: Internet Stack
InternetStackHelper stack;
stack.Install (nodes);
To assign IP addresses, use a helper and set the base. The low level ns-3 system actually
remembers all of the IP addresses allocated and will generate a fatal error if you
accidentally cause the same address to be generated twice.
// Since IP Address assignment is so common, the helper does the dirty work!
// You only need to set the base.
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Applications
Every application needs to have Start and Stop function so that the simulator knows
how to schedule it. Other functions are application-specific. We will use
UdpEchoServer and UdpEchoClientfor now.
// Application layer: UDP Echo Server and Client
// 1, Server:
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
HEMANT AGRAWAL
04614802716
// 2, Client:
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulation
// Start Simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
CODE
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
HEMANT AGRAWAL
04614802716
Simulator::Run ();
Simulator::Destroy ();
return 0;
HEMANT AGRAWAL
04614802716
Experiment 5
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"
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
return 0;
}
HEMANT AGRAWAL
04614802716
Experiment 6
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"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[])
//
// Set up some default values for the simulation.
//
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (137));
//
// Default number of nodes in the star. Overridable by command line argument.
//
uint32_t nSpokes = 8;
CommandLine cmd;
cmd.AddValue ("nSpokes", "Number of nodes to place in the star", nSpokes);
cmd.Parse (argc, argv);
//
// Create OnOff applications to send TCP to the hub, one on each spoke node.
//
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
onOffHelper.SetAttribute
("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
onOffHelper.SetAttribute
("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer spokeApps;
return 0;
}
HEMANT AGRAWAL
04614802716
Experiment 7
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"
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;
CommandLine cmd;
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
cmd.AddValue ("verbose", "Tell echo applications to log if true", verbose);
HEMANT AGRAWAL
04614802716
cmd.Parse (argc,argv);
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
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);
HEMANT AGRAWAL
04614802716
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
pointToPoint.EnablePcapAll ("second");
csma.EnablePcap ("second", csmaDevices.Get (1), true);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
HEMANT AGRAWAL
04614802716
Experiment 8
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"
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);
}
NodeContainer host, router, host1;
host.Create (2);
HEMANT AGRAWAL
04614802716
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;
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));
HEMANT AGRAWAL
04614802716
Experiment 9
Installing NetAnim:
The website:
http://www.nsnam.org/wiki/index.php/NetAnim
1. Install Mercurial: apt−get/dnf install mercurial
2. Install QT4 development package: apt−get/dnf install qt4−dev−tools
3. You can use Synaptic too, to install both the above packages.
4. Download NetAnim: hg clone http :// code .nsnam. org/netanim
5. Build NetAnim:
cd netanim
make clean qmake
NetAnim. pro make
...