Index: CHANGES.html
===================================================================
--- a/CHANGES.html
+++ b/CHANGES.html
@@ -63,6 +63,12 @@ can override this virtual method, perfor
RFC 3561
Ipv4::IsDestinationAddress (Ipv4Address address, uint32_t iif) Method added to support checks of whether a destination address should be accepted
as one of the host's own addresses. RFC 1122 Strong/Weak end system behavior can be changed with a new attribute (WeakEsModel) in class Ipv4.
+
+
Net-anim interface: Provides an inteface to net-anim, a network animator for point-to-point
+links in ns-3. The interface generates a custom trace file for use with the NetAnim program.
+
+
Topology Helpers: New topology helpers have been introduced including PointToPointStarHelper,
+PointToPointDumbbellHelper, PointToPointGridHelper, and CsmaStarHelper.
@@ -128,7 +134,37 @@ Simulator::SetScheduler (sched);
Extensions to IPv4 Ping application: verbose output and the ability to configure different ping
-sizes and time intervals (via new attributes)
+sizes and time intervals (via new attributes)
+
+
Topology Helpers: Previously, topology helpers such as a point-to-point star existed in the
+PointToPointHelper class in the form of a method (ex: PointToPointHelper::InstallStar). These topology
+helpers have been pulled out of the specific helper classes and created as separate classes. Several
+different topology helper classes now exist including PointToPointStarHelper, PointToPointGridHelper,
+PointToPointDumbbellHelper, and CsmaStarHelper. For example, a user wishes to create a
+point-to-point star network:
+Before:
+
Index: RELEASE_NOTES
===================================================================
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -35,6 +35,16 @@ New user-visible features
of the event which called the macro.
b) Ad hoc On-Demand Distance Vector (AODV) routing model according to RFC 3561.
+
+ c) Net-anim:
+ - interface for animation of point-to-point links.
+ - dumbbell, grid, and star examples in examples/animation
+
+ d) Topology Helper classes:
+ - PointToPointDumbbellHelper
+ - PointToPointGridHelper
+ - PointToPointStarHelper
+ - CsmaStarHelper
API changes from ns-3.6
-----------------------
Index: examples/animation/dumbbell-animation.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/examples/animation/dumbbell-animation.cc
@@ -0,0 +1,118 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: George F. Riley
+ */
+
+#include
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+int main (int argc, char *argv[])
+{
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
+
+ uint32_t nLeftLeaf = 5;
+ uint32_t nRightLeaf = 5;
+ uint32_t nLeaf = 0; // If non-zero, number of both left and right
+ uint16_t port = 0; // If non zero, port to bind to for anim connection
+ std::string animFile; // Name of file for animation output
+
+ CommandLine cmd;
+ cmd.AddValue ("nLeftLeaf", "Number of left side leaf nodes", nLeftLeaf);
+ cmd.AddValue ("nRightLeaf","Number of right side leaf nodes", nRightLeaf);
+ cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
+ cmd.AddValue ("port", "Port Number for Remote Animation", port);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc,argv);
+ if (nLeaf > 0)
+ {
+ nLeftLeaf = nLeaf;
+ nRightLeaf = nLeaf;
+ }
+
+ // Create the point-to-point link helpers
+ PointToPointHelper pointToPointRouter;
+ pointToPointRouter.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ pointToPointRouter.SetChannelAttribute ("Delay", StringValue ("1ms"));
+ PointToPointHelper pointToPointLeaf;
+ pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
+ pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
+
+ PointToPointDumbbellHelper d(nLeftLeaf, pointToPointLeaf,
+ nRightLeaf, pointToPointLeaf,
+ pointToPointRouter);
+
+ // Install Stack
+ InternetStackHelper stack;
+ d.InstallStack (stack);
+
+ // Assign IP Addresses
+ d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
+
+ // Install on/off app on all right side nodes
+ OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", RandomVariableValue (UniformVariable (0, 1)));
+ clientHelper.SetAttribute
+ ("OffTime", RandomVariableValue (UniformVariable (0, 1)));
+ ApplicationContainer clientApps;
+
+ for (uint32_t i = 0; i < d.RightCount (); ++i)
+ {
+ // Create an on/off app sending packets to the same leaf right side
+ AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), 1000));
+ clientHelper.SetAttribute ("Remote", remoteAddress);
+ clientApps.Add(clientHelper.Install (d.GetRight (i)));
+ }
+
+ clientApps.Start (Seconds (0.0));
+ clientApps.Stop (Seconds (10.0));
+
+ // Set the bounding box for animation
+ d.BoundingBox (1, 1, 10, 10);
+
+ // Create the animation object and configure for specified output
+ AnimationInterface anim;
+ if (port > 0)
+ {
+ anim.SetServerPort (port);
+ }
+ else if (!animFile.empty ())
+ {
+ anim.SetOutputFile (animFile);
+ }
+ anim.StartAnimation ();
+
+ // Set up the acutal simulation
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ std::cout << "Running the simulation" << std::endl;
+ Simulator::Run ();
+ std::cout << "Destroying the simulation" << std::endl;
+ Simulator::Destroy ();
+ std::cout << "Stopping the animation" << std::endl;
+ anim.StopAnimation();
+ return 0;
+}
Index: examples/animation/grid-animation.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/examples/animation/grid-animation.cc
@@ -0,0 +1,106 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Josh Pelkey
+ */
+
+#include
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+using namespace ns3;
+
+int main (int argc, char *argv[])
+{
+ Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("500kb/s"));
+
+ uint32_t xSize = 5;
+ uint32_t ySize = 5;
+ uint16_t port = 0;
+ std::string animFile;
+
+ CommandLine cmd;
+ cmd.AddValue ("xSize", "Number of rows of nodes", xSize);
+ cmd.AddValue ("ySize", "Number of columns of nodes", ySize);
+ cmd.AddValue ("port", "Port Number for Remote Animation", port);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc,argv);
+ if (xSize < 1 || ySize < 1 || (xSize < 2 && ySize < 2))
+ {
+ NS_FATAL_ERROR ("Need more nodes for grid.");
+ }
+
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+ // Create Grid
+ PointToPointGridHelper grid (xSize, ySize, pointToPoint);
+
+ // Install stack on Grid
+ InternetStackHelper stack;
+ grid.InstallStack (stack);
+
+ // Assign Addresses to Grid
+ grid.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
+ Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"));
+
+
+ OnOffHelper clientHelper ("ns3::UdpSocketFactory", Address ());
+ clientHelper.SetAttribute
+ ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ clientHelper.SetAttribute
+ ("OffTime", RandomVariableValue (ConstantVariable (0)));
+ ApplicationContainer clientApps;
+
+ // Create an on/off app sending packets
+ AddressValue remoteAddress (InetSocketAddress (grid.GetIpv4Address (xSize-1,ySize-1), 1000));
+ clientHelper.SetAttribute ("Remote", remoteAddress);
+ clientApps.Add (clientHelper.Install (grid.GetNode (0,0)));
+
+ clientApps.Start (Seconds (0.0));
+ clientApps.Stop (Seconds (1.5));
+
+ // Set the bounding box for animation
+ grid.BoundingBox (1, 1, 10, 10);
+
+ // Create the animation object and configure for specified output
+ AnimationInterface anim;
+ if (port > 0)
+ {
+ anim.SetServerPort (port);
+ }
+ else if (!animFile.empty ())
+ {
+ anim.SetOutputFile (animFile);
+ }
+ anim.StartAnimation ();
+
+ // Set up the actual simulation
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ std::cout << "Running the simulation" << std::endl;
+ Simulator::Run ();
+ std::cout << "Destroying the simulation" << std::endl;
+ Simulator::Destroy ();
+ std::cout << "Stopping the animation" << std::endl;
+ anim.StopAnimation();
+ return 0;
+}
Index: examples/animation/star-animation.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/examples/animation/star-animation.cc
@@ -0,0 +1,134 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "ns3/core-module.h"
+#include "ns3/simulator-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+
+// Network topology (default)
+//
+// n2 n3 n4 .
+// \ | / .
+// \|/ .
+// n1--- n0---n5 .
+// /|\ .
+// / | \ .
+// n8 n7 n6 .
+//
+
+
+using namespace ns3;
+
+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));
+
+ // ??? try and stick 15kb/s into the data rate
+ Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("14kb/s"));
+
+ //
+ // Default number of nodes in the star. Overridable by command line argument.
+ //
+ uint32_t nSpokes = 8;
+ uint32_t animPort = 0;
+ std::string animFile;
+
+ CommandLine cmd;
+ cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
+ cmd.AddValue ("animPort", "Port Number for Remote Animation", animPort);
+ cmd.AddValue ("animFile", "File Name for Animation Output", animFile);
+
+ cmd.Parse (argc, argv);
+
+ NS_LOG_INFO ("Build star topology.");
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ PointToPointStarHelper star (nSpokes, pointToPoint);
+
+ NS_LOG_INFO ("Install internet stack on all nodes.");
+ InternetStackHelper internet;
+ star.InstallStack (internet);
+
+ NS_LOG_INFO ("Assign IP Addresses.");
+ star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"));
+
+ NS_LOG_INFO ("Create applications.");
+ //
+ // Create a packet sink on the star "hub" to receive packets.
+ //
+ uint16_t port = 50000;
+ Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
+ PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
+ ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
+ hubApp.Start (Seconds (1.0));
+ hubApp.Stop (Seconds (10.0));
+
+ //
+ // Create OnOff applications to send TCP to the hub, one on each spoke node.
+ //
+ OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
+ onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer spokeApps;
+
+ for (uint32_t i = 0; i < star.SpokeCount (); ++i)
+ {
+ AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
+ onOffHelper.SetAttribute ("Remote", remoteAddress);
+ spokeApps.Add (onOffHelper.Install (star.GetSpoke (i)));
+ }
+ spokeApps.Start (Seconds (1.0));
+ spokeApps.Stop (Seconds (10.0));
+
+ NS_LOG_INFO ("Enable static global routing.");
+ //
+ // Turn on global static routing so we can actually be routed across the star.
+ //
+ Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+ // Set the bounding box for animation
+ star.BoundingBox (1, 1, 10, 10);
+
+ // Create the animation object and configure for specified output
+ AnimationInterface anim;
+ if (animPort > 0)
+ {
+ anim.SetServerPort (animPort);
+ }
+ else if (!animFile.empty ())
+ {
+ anim.SetOutputFile (animFile);
+ }
+ anim.StartAnimation ();
+
+ NS_LOG_INFO ("Run Simulation.");
+ Simulator::Run ();
+ Simulator::Destroy ();
+ NS_LOG_INFO ("Done.");
+
+ return 0;
+}
Index: examples/animation/waf
===================================================================
new file mode 100755
--- /dev/null
+++ b/examples/animation/waf
@@ -0,0 +1,1 @@
+exec "`dirname "$0"`"/../../waf "$@"
Index: examples/animation/wscript
===================================================================
new file mode 100644
--- /dev/null
+++ b/examples/animation/wscript
@@ -0,0 +1,14 @@
+## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+ obj = bld.create_ns3_program('dumbbell-animation',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'dumbbell-animation.cc'
+
+ obj = bld.create_ns3_program('grid-animation',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'grid-animation.cc'
+
+ obj = bld.create_ns3_program('star-animation',
+ ['point-to-point', 'internet-stack'])
+ obj.source = 'star-animation.cc'
Index: examples/csma/csma-star.cc
===================================================================
--- a/examples/csma/csma-star.cc
+++ b/examples/csma/csma-star.cc
@@ -58,26 +58,17 @@ main (int argc, char *argv[])
//
// Default number of nodes in the star. Overridable by command line argument.
//
- uint32_t nNodes = 7;
+ uint32_t nSpokes = 7;
CommandLine cmd;
- cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
+ cmd.AddValue("nSpokes", "Number of spoke nodes to place in the star", nSpokes);
cmd.Parse (argc, argv);
- NS_LOG_INFO ("Create nodes.");
- NodeContainer hubNode;
- NodeContainer spokeNodes;
- hubNode.Create (1);
- Ptr hub = hubNode.Get (0);
- spokeNodes.Create (nNodes - 1);
-
+ NS_LOG_INFO ("Build star topology.");
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", StringValue ("1ms"));
-
- NS_LOG_INFO ("Build star topology.");
- NetDeviceContainer hubDevices, spokeDevices;
- csma.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
+ CsmaStarHelper star (nSpokes, csma);
NodeContainer fillNodes;
@@ -89,12 +80,11 @@ main (int argc, char *argv[])
NetDeviceContainer fillDevices;
uint32_t nFill = 14;
- for (uint32_t i = 0; i < spokeDevices.GetN (); ++i)
+ for (uint32_t i = 0; i < star.GetSpokeDevices ().GetN (); ++i)
{
- Ptr channel = spokeDevices.Get (i)->GetChannel ();
+ Ptr channel = star.GetSpokeDevices ().Get (i)->GetChannel ();
Ptr csmaChannel = channel->GetObject ();
NodeContainer newNodes;
- NetDeviceContainer newDevices;
newNodes.Create (nFill);
fillNodes.Add (newNodes);
fillDevices.Add (csma.Install (newNodes, csmaChannel));
@@ -102,39 +92,30 @@ main (int argc, char *argv[])
NS_LOG_INFO ("Install internet stack on all nodes.");
InternetStackHelper internet;
- internet.Install (NodeContainer (hubNode, spokeNodes, fillNodes));
+ star.InstallStack (internet);
+ internet.Install (fillNodes);
NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper address;
+ star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.0.0", "255.255.255.0"));
//
- // Assign IPv4 interfaces and IP addresses to the devices we previously
- // created. Keep track of the resulting addresses, one for the addresses
- // of the hub node, and one for addresses on the spoke nodes. Despite the
- // name of the class (Ipv4InterfaceContainer), what is visible to clients
- // is really the address not the interface.
+ // We assigned addresses to the logical hub and the first "drop" of the
+ // CSMA network that acts as the spoke, but we also have a number of fill
+ // devices (nFill) also hanging off the CSMA network. We have got to
+ // assign addresses to them as well. We put all of the fill devices into
+ // a single device container, so the first nFill devices are associated
+ // with the channel connected to spokeDevices.Get (0), the second nFill
+ // devices afe associated with the channel connected to spokeDevices.Get (1)
+ // etc.
//
- Ipv4InterfaceContainer hubAddresses;
- Ipv4InterfaceContainer spokeAddresses;
-
- for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ Ipv4AddressHelper address;
+ for(uint32_t i = 0; i < star.SpokeCount (); ++i)
{
std::ostringstream subnet;
subnet << "10.1." << i << ".0";
NS_LOG_INFO ("Assign IP Addresses for CSMA subnet " << subnet.str ());
- address.SetBase (subnet.str ().c_str (), "255.255.255.0");
- hubAddresses.Add (address.Assign (hubDevices.Get (i)));
- spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
- //
- // We assigned addresses to the logical hub and the first "drop" of the
- // CSMA network that acts as the spoke, but we also have a number of fill
- // devices (nFill) also hanging off the CSMA network. We have got to
- // assign addresses to them as well. We put all of the fill devices into
- // a single device container, so the first nFill devices are associated
- // with the channel connected to spokeDevices.Get (0), the second nFill
- // devices afe associated with the channel connected to spokeDevices.Get (1)
- // etc.
- //
+ address.SetBase (subnet.str ().c_str (), "255.255.255.0", "0.0.0.3");
+
for (uint32_t j = 0; j < nFill; ++j)
{
address.Assign (fillDevices.Get (i * nFill + j));
@@ -148,7 +129,7 @@ main (int argc, char *argv[])
uint16_t port = 50000;
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
- ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
+ ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
hubApp.Start (Seconds (1.0));
hubApp.Stop (Seconds (10.0));
@@ -161,11 +142,11 @@ main (int argc, char *argv[])
ApplicationContainer spokeApps;
- for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ for (uint32_t i = 0; i < star.SpokeCount (); ++i)
{
- AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
+ AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
onOffHelper.SetAttribute ("Remote", remoteAddress);
- spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
+ spokeApps.Add (onOffHelper.Install (star.GetSpoke (i)));
}
spokeApps.Start (Seconds (1.0));
@@ -183,7 +164,7 @@ main (int argc, char *argv[])
for (uint32_t i = 0; i < fillNodes.GetN (); ++i)
{
- AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i / nFill), port));
+ AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i / nFill), port));
onOffHelper.SetAttribute ("Remote", remoteAddress);
fillApps.Add (onOffHelper.Install (fillNodes.Get (i)));
}
Index: examples/tcp/star.cc
===================================================================
--- a/examples/tcp/star.cc
+++ b/examples/tcp/star.cc
@@ -51,52 +51,24 @@ main (int argc, char *argv[])
//
// Default number of nodes in the star. Overridable by command line argument.
//
- uint32_t nNodes = 9;
+ uint32_t nSpokes = 8;
CommandLine cmd;
- cmd.AddValue("nNodes", "Number of nodes to place in the star", nNodes);
+ cmd.AddValue("nSpokes", "Number of nodes to place in the star", nSpokes);
cmd.Parse (argc, argv);
- NS_LOG_INFO ("Create nodes.");
- NodeContainer hubNode;
- NodeContainer spokeNodes;
- hubNode.Create (1);
- Ptr hub = hubNode.Get (0);
- spokeNodes.Create (nNodes - 1);
+ NS_LOG_INFO ("Build star topology.");
+ PointToPointHelper pointToPoint;
+ pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
+ pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+ PointToPointStarHelper star (nSpokes, pointToPoint);
NS_LOG_INFO ("Install internet stack on all nodes.");
InternetStackHelper internet;
- internet.Install (NodeContainer (hubNode, spokeNodes));
-
- PointToPointHelper pointToPoint;
- pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
- pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
-
- NS_LOG_INFO ("Build star topology.");
- NetDeviceContainer hubDevices, spokeDevices;
- pointToPoint.InstallStar (hubNode.Get (0), spokeNodes, hubDevices, spokeDevices);
+ star.InstallStack (internet);
NS_LOG_INFO ("Assign IP Addresses.");
- Ipv4AddressHelper address;
-
- //
- // Assign IPv4 interfaces and IP addresses to the devices we previously
- // created. Keep track of the resulting addresses, one for the addresses
- // of the hub node, and one for addresses on the spoke nodes. Despite the
- // name of the class, what is visible to clients is really the address.
- //
- Ipv4InterfaceContainer hubAddresses;
- Ipv4InterfaceContainer spokeAddresses;
-
- for(uint32_t i = 0; i < spokeNodes.GetN (); ++i)
- {
- std::ostringstream subnet;
- subnet << "10.1.1." << (i << 2);
- NS_LOG_INFO ("Assign IP Addresses for point-to-point subnet " << subnet.str ());
- address.SetBase (subnet.str ().c_str (), "255.255.255.252");
- hubAddresses.Add (address.Assign (hubDevices.Get (i)));
- spokeAddresses.Add (address.Assign (spokeDevices.Get (i)));
- }
+ star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"));
NS_LOG_INFO ("Create applications.");
//
@@ -105,7 +77,7 @@ main (int argc, char *argv[])
uint16_t port = 50000;
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", hubLocalAddress);
- ApplicationContainer hubApp = packetSinkHelper.Install (hubNode);
+ ApplicationContainer hubApp = packetSinkHelper.Install (star.GetHub ());
hubApp.Start (Seconds (1.0));
hubApp.Stop (Seconds (10.0));
@@ -118,11 +90,11 @@ main (int argc, char *argv[])
ApplicationContainer spokeApps;
- for (uint32_t i = 0; i < spokeNodes.GetN (); ++i)
+ for (uint32_t i = 0; i < star.SpokeCount (); ++i)
{
- AddressValue remoteAddress (InetSocketAddress (hubAddresses.GetAddress (i), port));
+ AddressValue remoteAddress (InetSocketAddress (star.GetHubIpv4Address (i), port));
onOffHelper.SetAttribute ("Remote", remoteAddress);
- spokeApps.Add (onOffHelper.Install (spokeNodes.Get (i)));
+ spokeApps.Add (onOffHelper.Install (star.GetSpoke (i)));
}
spokeApps.Start (Seconds (1.0));
spokeApps.Stop (Seconds (10.0));
Index: examples/wscript
===================================================================
--- a/examples/wscript
+++ b/examples/wscript
@@ -3,6 +3,7 @@ def build(bld):
def build(bld):
env = bld.env_of_name('default')
if env['ENABLE_EXAMPLES']:
+ bld.add_subdirs('animation')
bld.add_subdirs('csma')
bld.add_subdirs('emulation')
bld.add_subdirs('error-model')
Index: src/contrib/net-anim/animation-interface.cc
===================================================================
deleted file mode 100644
--- a/src/contrib/net-anim/animation-interface.cc
+++ /dev/null
@@ -1,202 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: George F. Riley
- */
-
-// Interface between ns3 and the network animator
-
-#include
-#include
-
-#include "ns3/net-anim-config.h"
-
-// Socket related includes
-#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
-# include
-# include
-#else
-#include
-#endif
-
-// ns3 includes
-#include "ns3/animation-interface.h"
-#include "ns3/channel.h"
-#include "ns3/config.h"
-#include "ns3/node.h"
-#include "ns3/node-location.h"
-#include "ns3/packet.h"
-#include "ns3/simulator.h"
-
-using namespace std;
-
-NS_LOG_COMPONENT_DEFINE ("AnimationInterface");
-
-namespace ns3 {
-
-AnimationInterface::AnimationInterface ()
- : m_fHandle (STDOUT_FILENO), m_model (0)
-{
-}
-
-bool AnimationInterface::SetOutputFile (const std::string& fn)
-{
- FILE* f = fopen (fn.c_str (), "w");
- if (!f)
- {
- return false; // Can't open
- }
- m_fHandle = fileno (f); // Set the file handle
- return true;
-}
-
-bool AnimationInterface::SetServerPort (uint16_t port)
-{
-#if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NETINET_IN_H)
- int s = socket (AF_INET, SOCK_STREAM, 0);
- struct sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = htons (port);
- addr.sin_addr.s_addr = htonl (INADDR_ANY);
- if (bind (s, (struct sockaddr*)&addr, sizeof (addr)) < 0)
- {
- NS_LOG_WARN ("Can't bind to port " << port << ", exiting.");
- return false;
- }
- listen (s, 1);
- NS_LOG_INFO ("Waiting for animator connection");
- // Now wait for the animator to connect in
- m_fHandle = accept (s, 0, 0);
- NS_LOG_INFO ("Got animator connection from remote");
- // set the linger socket option
- int t = 1;
- setsockopt (s, SOL_SOCKET, SO_LINGER, &t, sizeof(t));
- return true;
-#endif
- return false;//never reached unless the above is disabled
-}
-
-bool AnimationInterface::SetInternalAnimation ()
-{
- return false; // Not implemented yet
-}
-
-void AnimationInterface::StartAnimation ()
-{
- // Dump the topology
- for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
- {
- Ptr n = *i;
- Ptr loc = n->GetObject ();
- if (loc)
- {
- // Location exists, dump it
- Vector v = loc->GetLocation ();
- ostringstream oss;
- oss << "0.0 N " << n->GetId ()
- << " " << v.x << " " << v.y << endl;
- WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
- }
- }
- // Now dump the p2p links
- for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End(); ++i)
- {
- Ptr n = *i;
- uint32_t n1Id = n->GetId ();
- uint32_t nDev = n->GetNDevices (); // Number of devices
- for (uint32_t i = 0; i < nDev; ++i)
- {
- Ptr dev = n->GetDevice (i);
- Ptr ch = dev->GetChannel ();
- if (!ch)
- {
- continue; // No channel, can't be p2p device
- }
- string channelType = ch->GetInstanceTypeId ().GetName ();
- if (channelType == string ("ns3::PointToPointChannel"))
- { // Since these are duplex links, we only need to dump
- // if srcid < dstid
- uint32_t nChDev = ch->GetNDevices ();
- for (uint32_t j = 0; j < nChDev; ++j)
- {
- Ptr chDev = ch->GetDevice (j);
- uint32_t n2Id = chDev->GetNode ()->GetId ();
- if (n1Id < n2Id)
- { // ouptut the p2p link
- ostringstream oss;
- oss << "0.0 L " << n1Id << " " << n2Id << endl;
- WriteN (m_fHandle, oss.str ().c_str (),
- oss.str ().length ());
- }
- }
- }
- else
- {
- NS_FATAL_ERROR ("Net animation currently only supports point-to-point links.");
- }
- }
- }
-
- // Connect the callback for packet tx events
- Config::Connect ("/ChannelList/*/TxRxPointToPoint",
- MakeCallback (&AnimationInterface::DevTxTrace, this));
-}
-
-void AnimationInterface::StopAnimation ()
-{
- if (m_fHandle > 0)
- {
- close (m_fHandle);
- }
-}
-
-
-// Private methods
-int AnimationInterface::WriteN (int h, const char* data, uint32_t count)
-{ // Write count bytes to h from data
- uint32_t nLeft = count;
- const char* p = data;
- uint32_t written = 0;
-
- while (nLeft)
- {
- int n = write (h, p, nLeft);
- if (n <= 0)
- {
- return written;
- }
- written += n;
- nLeft -= n;
- p += n;
- }
- return written;
-}
-
-void AnimationInterface::DevTxTrace (std::string context, Ptr p,
- Ptr tx, Ptr rx,
- Time txTime, Time rxTime)
-{
- Time now = Simulator::Now ();
- ostringstream oss;
- oss << now.GetSeconds() << " P "
- << tx->GetNode ()->GetId () << " "
- << rx->GetNode ()->GetId () << " "
- << (now + txTime).GetSeconds () << " " // last bit tx time
- << (now + rxTime - txTime).GetSeconds() << " " // first bit rx time
- << (now + rxTime).GetSeconds () << endl; // last bit rx time
- WriteN (m_fHandle, oss.str ().c_str (), oss.str ().length ());
-}
-
-} // namespace ns3
Index: src/contrib/net-anim/animation-interface.h
===================================================================
deleted file mode 100644
--- a/src/contrib/net-anim/animation-interface.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: George F. Riley
- */
-
-// Interface between ns3 and the network animator
-
-#ifndef __ANIMATION_INTERFACE__H__
-#define __ANIMATION_INTERFACE__H__
-
-#include
-
-#include "ns3/ptr.h"
-#include "ns3/net-device.h"
-#include "ns3/nstime.h"
-#include "ns3/log.h"
-#include "ns3/node-list.h"
-
-
-namespace ns3 {
-class NetModel;
-
-/**
- * \brief Interface to network animator
- *
- * Provides functions that facilitate communications with an
- * external or internal network animator.
- */
-class AnimationInterface
-{
-public:
-/**
- * @brief Construct the animator interface. No arguments needed.
- */
- AnimationInterface ();
-/**
- * @brief Specify that animation commands are to be written
- * to the specified output file.
- *
- * This call is used to write the animation information to a text
- * file that can later be used as input to the network animator tool.
- *
- * @param fn The name of the output file.
- * @returns true if successful open.
- */
- bool SetOutputFile (const std::string& fn);
-
-/**
- * @brief Specify that animation commands are to be written to
- * a socket.
- *
- * This call is used to set the ns3 process in server mode, waiting
- * for a TCP connection from the animator. This call will not
- * return until the animator connects in, or if the bind to the
- * specified port fails.
- *
- * @param port Port number to bind to.
- * @returns true if connection created, false if bind failed.
- */
- bool SetServerPort (uint16_t port);
-
-/**
- * @brief Specify that animation window is to be created as part
- * of the ns3 process.
- *
- * This call is used to set the ns3 animator internal to the
- * current process. This will fail if the ns3 library was built
- * without the QT4 developer packages.
- *
- * @returns true if animation started, false if failed.
- */
- bool SetInternalAnimation ();
-
-/**
- * @brief Writes the topology information and sets up the appropriate
- * animation packet tx callback
- *
- * Writes the topology information to the appropriate output, depending
- * on prior calls to SetOutputFile, SetServerPort, or SetInternalAnimation.
- * Then creates the callbacks needed for the animator to start processing
- * packets.
- *
- */
- void StartAnimation ();
-
-/**
- * @brief Closes the interface to the animator.
- *
- */
- void StopAnimation ();
-
-
-private:
- // Packet tx animation callback
- void DevTxTrace (std::string context, Ptr p,
- Ptr tx, Ptr rx,
- Time txTime, Time rxTime);
- // Write specified amount of data to the specified handle
- int WriteN (int, const char*, uint32_t);
-private:
- int m_fHandle; // File handle for output (-1 if none)
- NetModel* m_model; // If non nil, points to the internal network model
- // for the interlan animator
-};
-}
-#endif
-
Index: src/contrib/net-anim/node-location.cc
===================================================================
deleted file mode 100644
--- a/src/contrib/net-anim/node-location.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 Georgia Institute of Technology
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: George Riley
- */
-
-#include "node-location.h"
-
-namespace ns3 {
-
-TypeId
-NodeLocation::GetTypeId (void)
-{
- static TypeId tid = TypeId ("ns3::NodeLocation")
- .SetParent