59 #include "ns3/core-module.h" 60 #include "ns3/network-module.h" 61 #include "ns3/mpi-interface.h" 62 #include "ns3/ipv4-global-routing-helper.h" 63 #include "ns3/point-to-point-helper.h" 64 #include "ns3/internet-stack-helper.h" 65 #include "ns3/ipv4-nix-vector-helper.h" 66 #include "ns3/ipv4-address-helper.h" 67 #include "ns3/on-off-helper.h" 68 #include "ns3/packet-sink-helper.h" 79 main (
int argc,
char *argv[])
89 cmd.AddValue (
"nix",
"Enable the use of nix-vector or global routing", nix);
90 cmd.AddValue (
"nullmsg",
"Enable the use of null-message synchronization", nullmsg);
91 cmd.AddValue (
"tracing",
"Enable pcap tracing", tracing);
92 cmd.Parse (argc, argv);
113 uint32_t rightHalfSystemId = 777;
117 if (systemCount == 2)
119 rightHalfSystemId = 0;
121 else if (systemCount == 3)
123 rightHalfSystemId = 1;
127 std::cout <<
"This simulation requires 2 or 3 logical processors." << std::endl;
138 leftLeafNodes.
Create (4, 0);
144 Ptr<Node> routerNode1 = CreateObject<Node> (0);
145 Ptr<Node> routerNode2 = CreateObject<Node> (rightHalfSystemId);
146 routerNodes.
Add (routerNode1);
147 routerNodes.
Add (routerNode2);
151 rightLeafNodes.
Create (4, rightHalfSystemId);
163 routerDevices = routerLink.
Install (routerNodes);
168 for (uint32_t i = 0; i < 4; ++i)
171 leftLeafDevices.
Add (temp.
Get (0));
172 leftRouterDevices.
Add (temp.
Get (1));
178 for (uint32_t i = 0; i < 4; ++i)
181 rightLeafDevices.
Add (temp.
Get (0));
182 rightRouterDevices.
Add (temp.
Get (1));
189 stack.SetRoutingHelper (nixRouting);
201 leftAddress.
SetBase (
"10.1.1.0",
"255.255.255.0");
204 routerAddress.
SetBase (
"10.2.1.0",
"255.255.255.0");
207 rightAddress.
SetBase (
"10.3.1.0",
"255.255.255.0");
210 routerInterfaces = routerAddress.
Assign (routerDevices);
213 for (uint32_t i = 0; i < 4; ++i)
216 ndc.
Add (leftLeafDevices.
Get (i));
217 ndc.
Add (leftRouterDevices.
Get (i));
219 leftLeafInterfaces.
Add (ifc.
Get (0));
220 leftRouterInterfaces.
Add (ifc.
Get (1));
225 for (uint32_t i = 0; i < 4; ++i)
228 ndc.
Add (rightLeafDevices.
Get (i));
229 ndc.
Add (rightRouterDevices.
Get (i));
231 rightLeafInterfaces.
Add (ifc.
Get (0));
232 rightRouterInterfaces.
Add (ifc.
Get (1));
245 routerLink.
EnablePcap(
"router-left", routerDevices,
true);
246 leafLink.
EnablePcap(
"leaf-left", leftLeafDevices,
true);
249 if (systemId == rightHalfSystemId)
251 routerLink.
EnablePcap(
"router-right", routerDevices,
true);
252 leafLink.
EnablePcap(
"leaf-right", rightLeafDevices,
true);
257 uint16_t
port = 50000;
258 if (systemId == rightHalfSystemId)
263 for (uint32_t i = 0; i < 4; ++i)
265 sinkApp.
Add (sinkHelper.Install (rightLeafNodes.
Get (i)));
275 clientHelper.SetAttribute
276 (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
277 clientHelper.SetAttribute
278 (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
281 for (uint32_t i = 0; i < 4; ++i)
285 clientHelper.SetAttribute (
"Remote", remoteAddress);
286 clientApps.Add (clientHelper.Install (leftLeafNodes.
Get (i)));
299 NS_FATAL_ERROR (
"Can't use distributed simulator without MPI compiled in");
holds a vector of ns3::Application pointers.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static Ipv4Address GetAny(void)
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.
Hold variables of type string.
NetDeviceContainer Install(NodeContainer c)
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
static void Run(void)
Run the simulation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Helper class that adds Nix-vector routing to nodes.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
static void Disable()
Terminates the parallel environment.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
a polymophic address class
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
static void Enable(int *pargc, char ***pargv)
Sets up parallel communication interface.
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
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)
Execute the events scheduled with ScheduleDestroy().
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for 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.
static uint32_t GetSystemId()
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Time Seconds(double value)
Construct a Time in the indicated unit.
void SetDefault(std::string name, const AttributeValue &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...
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 EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
std::pair< Ptr< Ipv4 >, uint32_t > Get(uint32_t i) const
Get the std::pair of an Ptr<Ipv4> and interface stored at the location specified by the index...
static uint32_t GetSize()
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.