CNNNNN
CNNNNN
CNNNNN
Computer Networks
Batch
(2019-2023)
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 variables 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.
System
Analytical
Solution Simulation
Deterministic Stochastic
1. Many systems are overly complex, precluding the possibility of analytical solution.
A discrete-event simulation
Models a system whose state may change only at discrete point models a system whose
state may change only at discrete point in time
System:
It is composed of objects called entities that have certain properties called attributes.
State:
A collection of attributes or state variables that represent the entities of the system.
Event:
An instantaneous occurrence in time that may alter the state of the system.
Following are the basic steps which must be followed for installing NS3:
7. Now run the following command on the terminal window, to configure with waf (build
tool) ./waf -d debug --enable-examples --enable-tests configure To build with waf
(optional)
. /waf
8. To test everything all right run the following command on the terminal window, ./test.py
If the tests are ok the installation is done.
9. Now after installing ns3 and testing it run some programs first to be ns3 user: make
sure you are in directory where waf script is available then run.
OUTPUT:
Experiment 3: Run Hello- Simulator in NS3
Here we will run the Sample Code to ensure the Working of the NS3 Development
Environment. There are some bunch of example files one of which is hello-simulator.cc
Code:
#include "ns3/core-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("HelloSimulator");
int
main (int argc, char *argv[])
{
NS_LOG_UNCOND ("Hello Simulator");
}
OUTPUT:
Experiment 4: WAP in NS3 to connect two nodes.
#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"
//Take Logs
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
#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"
//
// 10.1.1.0
// n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.2.0
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
PointToPointHelper pointToPoint;
Installing NetAnim
5. Build NetAnim:
cd netanim
make clean qmake NetAnim. pro make
...
...
...
return (0);
}
To run the code:
1. Move the waf , waf.bat , wscript and wutils.py les in to the scratch folder (~/ns-
allinone-3.24/ns-3.24/scratch/).
2. Move the example code to the scratch folder and make the changes required for
NetAnim, as shown above.
3. Now cd to the scratch folder (cd ~/ns-allinone-3.24/ns-3.24/scratch/).
4. Run the code using the command:
./ waf −−run <filename>
To visualize on NetAnim:
1. cd to the netanim folder (cd ~/netanim/).
2. Run Netanim:
./NetAnim
#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"
//Take Logs
Time::SetResolution (Time::NS);
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"
using namespace ns3;
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);
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));
subnet3.Add(router.Get(2));
NetDeviceContainer subnet3Devices;
subnet3Devices = pointToPoint.Install(subnet3);
NodeContainer subnet4;
subnet4.Add(router.Get(1));
subnet4.Add(router.Get(3));
NetDeviceContainer subnet4Devices;
subnet4Devices = pointToPoint.Install(subnet4);
NodeContainer subnet5;
subnet5.Add(router.Get(2));
subnet5.Add(router.Get(1));
NetDeviceContainer subnet5Devices;
subnet5Devices = pointToPoint.Install(subnet5);
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Run();
Simulator::Destroy();
return(0);
}
OUTPUT:
29