44 #include "ns3/core-module.h"
45 #include "ns3/network-module.h"
46 #include "ns3/mpi-interface.h"
47 #include "ns3/ipv4-global-routing-helper.h"
48 #include "ns3/ipv4-static-routing-helper.h"
49 #include "ns3/ipv4-list-routing-helper.h"
50 #include "ns3/point-to-point-helper.h"
51 #include "ns3/internet-stack-helper.h"
52 #include "ns3/ipv4-nix-vector-helper.h"
53 #include "ns3/ipv4-address-helper.h"
54 #include "ns3/on-off-helper.h"
55 #include "ns3/packet-sink-helper.h"
66 main (
int argc,
char *argv[])
83 std::cout <<
"This simulation requires 2 and only 2 logical processors." << std::endl;
95 cmd.
AddValue (
"nix",
"Enable the use of nix-vector or global routing", nix);
96 cmd.
Parse (argc, argv);
100 leftLeafNodes.
Create (4, 0);
106 Ptr<Node> routerNode1 = CreateObject<Node> (0);
107 Ptr<Node> routerNode2 = CreateObject<Node> (1);
108 routerNodes.
Add (routerNode1);
109 routerNodes.
Add (routerNode2);
113 rightLeafNodes.
Create (4, 1);
125 routerDevices = routerLink.
Install (routerNodes);
130 for (uint32_t i = 0; i < 4; ++i)
133 leftLeafDevices.
Add (temp.
Get (0));
134 leftRouterDevices.
Add (temp.
Get (1));
140 for (uint32_t i = 0; i < 4; ++i)
143 rightLeafDevices.
Add (temp.
Get (0));
144 rightRouterDevices.
Add (temp.
Get (1));
152 list.
Add (staticRouting, 0);
153 list.
Add (nixRouting, 10);
169 leftAddress.
SetBase (
"10.1.1.0",
"255.255.255.0");
172 routerAddress.
SetBase (
"10.2.1.0",
"255.255.255.0");
175 rightAddress.
SetBase (
"10.3.1.0",
"255.255.255.0");
178 routerInterfaces = routerAddress.
Assign (routerDevices);
181 for (uint32_t i = 0; i < 4; ++i)
184 ndc.
Add (leftLeafDevices.
Get (i));
185 ndc.
Add (leftRouterDevices.
Get (i));
187 leftLeafInterfaces.
Add (ifc.
Get (0));
188 leftRouterInterfaces.
Add (ifc.
Get (1));
193 for (uint32_t i = 0; i < 4; ++i)
196 ndc.
Add (rightLeafDevices.
Get (i));
197 ndc.
Add (rightRouterDevices.
Get (i));
199 rightLeafInterfaces.
Add (ifc.
Get (0));
200 rightRouterInterfaces.
Add (ifc.
Get (1));
210 uint16_t
port = 50000;
216 for (uint32_t i = 0; i < 4; ++i)
220 sinkApp.
Start (Seconds (1.0));
221 sinkApp.
Stop (Seconds (5));
229 (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
231 (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
234 for (uint32_t i = 0; i < 4; ++i)
239 clientApps.
Add (clientHelper.
Install (leftLeafNodes.
Get (i)));
241 clientApps.
Start (Seconds (1.0));
242 clientApps.
Stop (Seconds (5));
252 NS_FATAL_ERROR (
"Can't use distributed simulator without MPI compiled in");
holds a vector of ns3::Application pointers.
static Ipv4Address GetAny(void)
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation. Makes all nodes in the simulation into routers.
hold variables of type string
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
void InstallAll(void) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
static void Enable(int *pargc, char ***pargv)
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
static void Bind(std::string name, const AttributeValue &value)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
static void Destroy(void)
void SetDefault(std::string name, const AttributeValue &value)
keep track of a set of node pointers.
void Add(const Ipv4RoutingHelper &routing, int16_t priority)
void SetChannelAttribute(std::string name, const AttributeValue &value)
hold objects of type ns3::Address
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
int main(int argc, char *argv[])
static uint32_t GetSystemId()
Helper class that adds ns3::Ipv4StaticRouting objects.
void AddValue(const std::string &name, const std::string &help, T &value)
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ipv4Address NewNetwork(void)
Increment the network number and reset the IP address counter to the base value provided in the SetBa...
Helper class that adds ns3::Ipv4ListRouting objects.
ApplicationContainer Install(NodeContainer c) const
void Parse(int argc, char *argv[])
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(Ipv4InterfaceContainer other)
ApplicationContainer Install(NodeContainer c) const
static uint32_t GetSize()
void SetRoutingHelper(const Ipv4RoutingHelper &routing)
void SetAttribute(std::string name, const AttributeValue &value)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void LogComponentEnable(char const *name, enum LogLevel level)
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const