Network Simulation Lab4
Network Simulation Lab4
WEEK - 04
DATE:13/04/2022
NAME: A. HARIKRISHNA
ROLL NO: 20R25A0513
PROBLEM STATEMENT: 05
Implement physical star topology and simulate using NS3.
#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"
NS_LOG_COMPONENT_DEFINE ("StarAnimation");
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;
std::string animFile = "star-animation.xml";
uint8_t useIpv6 = 0;
Ipv6Address ipv6AddressBase = Ipv6Address("2001::");
Ipv6Prefix ipv6AddressPrefix = Ipv6Prefix(64);
CommandLine cmd;
cmd.AddValue ("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
cmd.AddValue ("useIpv6", "use Ipv6", useIpv6);
//
// 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;
for (uint32_t i = 0; i < star.SpokeCount (); ++i)
{
AddressValue remoteAddress;
if (useIpv6 == 0)
{
remoteAddress = AddressValue(InetSocketAddress (star.GetHubIpv4Address (i),
port));
}
else
{
remoteAddress = AddressValue(Inet6SocketAddress (star.GetHubIpv6Address
(i), port));
}
onOffHelper.SetAttribute ("Remote", remoteAddress);
spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
}
spokeApps.Start (Seconds (1.0));
spokeApps.Stop (Seconds (10.0));
// Turn on global static routing so we can actually be routed across the star.
//
if (useIpv6 == 0)
{
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
}
return 0;
}
OUTPUT: