From e855838ed159be98cb5460fca50c663fc91a36da Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 13 Apr 2008 15:46:17 -0700 Subject: [PATCH] Align helper API use of Install() --- examples/mixed-wireless.cc | 39 ++++++++++++++------------ examples/simple-point-to-point-olsr.cc | 2 +- examples/wifi-adhoc.cc | 2 +- examples/wifi-ap.cc | 4 +-- samples/main-grid-topology.cc | 2 +- samples/main-random-topology.cc | 2 +- samples/main-random-walk.cc | 2 +- src/helper/internet-stack-helper.cc | 10 +++++++ src/helper/internet-stack-helper.h | 5 +++- src/helper/mobility-helper.cc | 6 ++-- src/helper/mobility-helper.h | 20 ++++++------- src/helper/ns2-mobility-helper.cc | 4 +-- src/helper/ns2-mobility-helper.h | 6 ++-- src/helper/olsr-helper.cc | 16 +++++++---- src/helper/olsr-helper.h | 6 ++-- src/internet-node/internet-stack.cc | 5 ---- 16 files changed, 74 insertions(+), 57 deletions(-) diff --git a/examples/mixed-wireless.cc b/examples/mixed-wireless.cc index cb28e8855..36a506959 100644 --- a/examples/mixed-wireless.cc +++ b/examples/mixed-wireless.cc @@ -166,7 +166,7 @@ main (int argc, char *argv[]) "Bounds", Rectangle (0, 1000, 0, 1000), "Speed", ConstantVariable (2000), "Pause", ConstantVariable (0.2)); - mobility.Layout (backbone); + mobility.Install (backbone); /////////////////////////////////////////////////////////////////////////// // // @@ -178,17 +178,19 @@ main (int argc, char *argv[]) // the "172.16 address space ipAddrs.SetBase ("172.16.0.0", "255.255.255.0"); + for (uint32_t i = 0; i < backboneNodes; ++i) { NS_LOG_INFO ("Configuring local area network for backbone node " << i); // - // Create a container to manage the nodes of the LAN. Pick one of - // the backbone nodes to be part of the LAN and first add it to - // the container. Then create the rest of the nodes we'll need. + // Create a container to manage the nodes of the LAN. We need + // two containers here; one with all of the new nodes, and one + // with all of the nodes including new and existing nodes // - NodeContainer lan; - lan.Add (backbone.Get (i)); - lan.Create (lanNodes - 1); + NodeContainer newLanNodes; + newLanNodes.Create (lanNodes - 1); + // Now, create the container with all nodes on this link + NodeContainer lan (backbone.Get (i), newLanNodes); // // Create the CSMA net devices and install them into the nodes in our // collection. @@ -198,9 +200,9 @@ main (int argc, char *argv[]) csma.SetChannelParameter ("Delay", MilliSeconds (2)); NetDeviceContainer lanDevices = csma.Install (lan); // - // Add the IPv4 protocol stack to the nodes in our container + // Add the IPv4 protocol stack to the new LAN nodes // - internet.Install (lan); + internet.Install (newLanNodes); // // Assign IPv4 addresses to the device drivers (actually to the // associated IPv4 interfaces) we just created. @@ -227,13 +229,14 @@ main (int argc, char *argv[]) { NS_LOG_INFO ("Configuring wireless network for backbone node " << i); // - // Create a container to manage the nodes of the network. Pick one of - // the backbone nodes to be part of the network and first add it to - // the container. Then create the rest of the nodes we'll need. + // Create a container to manage the nodes of the LAN. We need + // two containers here; one with all of the new nodes, and one + // with all of the nodes including new and existing nodes // - NodeContainer infra; - infra.Add (backbone.Get (i)); - infra.Create (infraNodes - 1); + NodeContainer newInfraNodes; + newInfraNodes.Create (infraNodes - 1); + // Now, create the container with all nodes on this link + NodeContainer infra (backbone.Get (i), newInfraNodes); // // Create another ad hoc network and devices // @@ -244,7 +247,7 @@ main (int argc, char *argv[]) // Add the IPv4 protocol stack to the nodes in our container // - internet.Install (infra); + internet.Install (newInfraNodes); // // Assign IPv4 addresses to the device drivers (actually to the associated // IPv4 interfaces) we just created. @@ -272,7 +275,7 @@ main (int argc, char *argv[]) "Bounds", Rectangle (-25, 25, -25, 25), "Speed", ConstantVariable (30), "Pause", ConstantVariable (0.4)); - mobility.Layout (infra); + mobility.Install (infra); } /////////////////////////////////////////////////////////////////////////// // // @@ -282,7 +285,7 @@ main (int argc, char *argv[]) NS_LOG_INFO ("Enabling OLSR routing on all backbone nodes"); OlsrHelper olsr; - olsr.Enable (backbone); + olsr.Install (backbone); /////////////////////////////////////////////////////////////////////////// // // diff --git a/examples/simple-point-to-point-olsr.cc b/examples/simple-point-to-point-olsr.cc index 4c85d605a..da726fa5d 100644 --- a/examples/simple-point-to-point-olsr.cc +++ b/examples/simple-point-to-point-olsr.cc @@ -120,7 +120,7 @@ main (int argc, char *argv[]) // Enable OLSR NS_LOG_INFO ("Enabling OLSR Routing."); OlsrHelper olsr; - olsr.EnableAll (); + olsr.InstallAll (); // Create the OnOff application to send UDP datagrams of size // 210 bytes at a rate of 448 Kb/s diff --git a/examples/wifi-adhoc.cc b/examples/wifi-adhoc.cc index cc5a4e9b3..06ac048b0 100644 --- a/examples/wifi-adhoc.cc +++ b/examples/wifi-adhoc.cc @@ -126,7 +126,7 @@ Experiment::Run (const WifiHelper &wifi) mobility.SetPositionAllocator (positionAlloc); mobility.SetMobilityModel ("ns3::StaticMobilityModel"); - mobility.Layout (c); + mobility.Install (c); PacketSocketAddress socket; socket.SetSingleDevice(devices.Get (0)->GetIfIndex ()); diff --git a/examples/wifi-ap.cc b/examples/wifi-ap.cc index 914439601..db91a1e80 100644 --- a/examples/wifi-ap.cc +++ b/examples/wifi-ap.cc @@ -151,8 +151,8 @@ int main (int argc, char *argv[]) wifi.Install (ap, channel); // mobility. - mobility.Layout (stas); - mobility.Layout (ap); + mobility.Install (stas); + mobility.Install (ap); Simulator::Schedule (Seconds (1.0), &AdvancePosition, ap.Get (0)); diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index 9c4a3617e..d1ca99e2b 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -37,7 +37,7 @@ int main (int argc, char *argv[]) // finalize the setup by attaching to each object // in the input array a position and initializing // this position with the calculated coordinates. - mobility.Layout (nodes); + mobility.Install (nodes); // iterate our nodes and print their position. for (NodeContainer::Iterator j = nodes.Begin (); diff --git a/samples/main-random-topology.cc b/samples/main-random-topology.cc index 022f02c6b..a83b8deef 100644 --- a/samples/main-random-topology.cc +++ b/samples/main-random-topology.cc @@ -31,7 +31,7 @@ int main (int argc, char *argv[]) "Y", String ("100.0"), "Rho", String ("Uniform:0:30")); mobility.SetMobilityModel ("ns3::StaticMobilityModel"); - mobility.Layout (c); + mobility.Install (c); Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange", MakeCallback (&CourseChange)); diff --git a/samples/main-random-walk.cc b/samples/main-random-walk.cc index 6a536d5fb..d234b8645 100644 --- a/samples/main-random-walk.cc +++ b/samples/main-random-walk.cc @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) "Time", String ("2s"), "Speed", String ("Constant:1.0"), "Bounds", String ("0:200:0:100")); - mobility.LayoutAll (); + mobility.InstallAll (); Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange", MakeCallback (&CourseChange)); diff --git a/src/helper/internet-stack-helper.cc b/src/helper/internet-stack-helper.cc index b6e3454ee..39728beec 100644 --- a/src/helper/internet-stack-helper.cc +++ b/src/helper/internet-stack-helper.cc @@ -17,6 +17,10 @@ * * Author: Mathieu Lacage */ +#include "ns3/assert.h" +#include "ns3/log.h" +#include "ns3/object.h" +#include "ns3/ipv4.h" #include "internet-stack-helper.h" #include "ns3/internet-stack.h" #include "ns3/packet-socket-factory.h" @@ -33,6 +37,12 @@ InternetStackHelper::Install (NodeContainer c) for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { Ptr node = *i; + if (node->GetObject () != 0) + { + NS_FATAL_ERROR ("InternetStackHelper::Install(): Aggregating " + "an InternetStack to a node with an existing Ipv4 object"); + return; + } AddInternetStack (node); Ptr factory = CreateObject (); node->AggregateObject (factory); diff --git a/src/helper/internet-stack-helper.h b/src/helper/internet-stack-helper.h index ecee023cf..19ddf1bcb 100644 --- a/src/helper/internet-stack-helper.h +++ b/src/helper/internet-stack-helper.h @@ -37,7 +37,10 @@ public: * \param c the set of nodes * * For each node in the input container, aggregate implementations - * of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes. + * of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes. The program + * will assert if this method is called on a container with a node + * that already has an Ipv4 object aggregated to it. + * */ void Install (NodeContainer c); diff --git a/src/helper/mobility-helper.cc b/src/helper/mobility-helper.cc index 94ade79c7..3fbe38197 100644 --- a/src/helper/mobility-helper.cc +++ b/src/helper/mobility-helper.cc @@ -122,7 +122,7 @@ MobilityHelper::GetMobilityModelType (void) const } void -MobilityHelper::Layout (NodeContainer c) +MobilityHelper::Install (NodeContainer c) { for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) { @@ -167,9 +167,9 @@ MobilityHelper::Layout (NodeContainer c) } void -MobilityHelper::LayoutAll (void) +MobilityHelper::InstallAll (void) { - Layout (NodeContainer::GetGlobal ()); + Install (NodeContainer::GetGlobal ()); } } // namespace ns3 diff --git a/src/helper/mobility-helper.h b/src/helper/mobility-helper.h index 5a8c07e3d..761b47a13 100644 --- a/src/helper/mobility-helper.h +++ b/src/helper/mobility-helper.h @@ -34,7 +34,7 @@ class MobilityModel; /** * \brief assign positions and mobility models to nodes. * - * MobilityHelper::Layout is the most important method here. + * MobilityHelper::Install is the most important method here. */ class MobilityHelper { @@ -43,14 +43,14 @@ public: ~MobilityHelper (); /** - * After this method is called, every call to MobilityHelper::Layout + * After this method is called, every call to MobilityHelper::Install * will also attach to the new ns3::MobilityModel an ns3::MobilityModelNotifier * which can be used to listen to CourseChange events. */ void EnableNotifier (void); /** * After this method is called, no ns3::MobilityModelNotifier object will - * be associated to any new ns3::MobilityModel created by MobilityHelper::Layout. + * be associated to any new ns3::MobilityModel created by MobilityHelper::Install. * This will make it impossible to listen to "CourseChange" events from these * new ns3::MobilityModel instances. */ @@ -60,7 +60,7 @@ public: * \param allocator allocate initial node positions * * Set the position allocator which will be used to allocate - * the initial position of every node in MobilityModel::Layout. + * the initial position of every node in MobilityModel::Install. */ void SetPositionAllocator (Ptr allocator); @@ -117,7 +117,7 @@ public: * \param n9 the name of the attribute to set in the mobility model. * \param v9 the value of the attribute to set in the mobility model. * - * Calls to MobilityHelper::Layout will create an instance of a matching + * Calls to MobilityHelper::Install will create an instance of a matching * mobility model for each node. */ void SetMobilityModel (std::string type, @@ -136,9 +136,9 @@ public: * * Push an item on the top of the stack of "reference mobility models". * The input item should be a node instance to which a mobility model - * has already been aggregated (usually by a call to Layout). + * has already been aggregated (usually by a call to Install). * - * If this this stack is not empty when MobilityHelper::Layout + * If this this stack is not empty when MobilityHelper::Install * is called, the model from the top of the stack is used * to create a ns3::HierarchicalMobilityModel to make the * newly-created models define their positions relative to that @@ -173,13 +173,13 @@ public: * ns3::MobilityModelNotifier to generate 'CourseChange' events based on the * boolean flag set by MobilityHelper::EnableNotifier and MobilityHelper::DisableNotifier. */ - void Layout (NodeContainer container); + void Install (NodeContainer container); /** - * Perform the work of MobilityHelper::Layout on _all_ nodes which + * Perform the work of MobilityHelper::Install on _all_ nodes which * exist in the simulation. */ - void LayoutAll (void); + void InstallAll (void); private: std::vector > m_mobilityStack; diff --git a/src/helper/ns2-mobility-helper.cc b/src/helper/ns2-mobility-helper.cc index 761dfaae0..736c92581 100644 --- a/src/helper/ns2-mobility-helper.cc +++ b/src/helper/ns2-mobility-helper.cc @@ -154,9 +154,9 @@ Ns2MobilityHelper::LayoutObjectStore (const ObjectStore &store) const } void -Ns2MobilityHelper::Layout (void) const +Ns2MobilityHelper::Install (void) const { - Layout (NodeList::Begin (), NodeList::End ()); + Install (NodeList::Begin (), NodeList::End ()); } } // namespace ns3 diff --git a/src/helper/ns2-mobility-helper.h b/src/helper/ns2-mobility-helper.h index b75a3221a..b112129a1 100644 --- a/src/helper/ns2-mobility-helper.h +++ b/src/helper/ns2-mobility-helper.h @@ -51,7 +51,7 @@ public: * whose nodeId is matches the nodeId of the nodes in the trace * file. */ - void Layout (void) const; + void Install (void) const; /** * \param begin an iterator which points to the start of the input @@ -65,7 +65,7 @@ public: * the index of the object in the input array. */ template - void Layout (T begin, T end) const; + void Install (T begin, T end) const; private: class ObjectStore { @@ -86,7 +86,7 @@ namespace ns3 { template void -Ns2MobilityHelper::Layout (T begin, T end) const +Ns2MobilityHelper::Install (T begin, T end) const { class MyObjectStore : public ObjectStore { diff --git a/src/helper/olsr-helper.cc b/src/helper/olsr-helper.cc index 4032f387c..bc6856312 100644 --- a/src/helper/olsr-helper.cc +++ b/src/helper/olsr-helper.cc @@ -51,26 +51,32 @@ OlsrHelper::SetAgent (std::string tid, } void -OlsrHelper::Enable (NodeContainer container) +OlsrHelper::Install (NodeContainer container) { for (NodeContainer::Iterator i = container.Begin (); i != container.End (); ++i) { Ptr node = *i; - Enable (node); + Install (node); } } void -OlsrHelper::Enable (Ptr node) +OlsrHelper::Install (Ptr node) { + if (node->GetObject () != 0) + { + NS_FATAL_ERROR ("OlsrHelper::Install(): Aggregating " + "an Olsr Agent to a node with an existing Olsr Agent"); + return; + } Ptr agent = m_agentFactory.Create (); agent->SetNode (node); node->AggregateObject (agent); agent->Start (); } void -OlsrHelper::EnableAll (void) +OlsrHelper::InstallAll (void) { - Enable (NodeContainer::GetGlobal ()); + Install (NodeContainer::GetGlobal ()); } } // namespace ns3 diff --git a/src/helper/olsr-helper.h b/src/helper/olsr-helper.h index 4afb6cd9a..599a6245d 100644 --- a/src/helper/olsr-helper.h +++ b/src/helper/olsr-helper.h @@ -41,9 +41,9 @@ public: std::string n6 = "", Attribute v6 = Attribute (), std::string n7 = "", Attribute v7 = Attribute ()); - void Enable (NodeContainer container); - void Enable (Ptr node); - void EnableAll (void); + void Install (NodeContainer container); + void Install (Ptr node); + void InstallAll (void); private: ObjectFactory m_agentFactory; }; diff --git a/src/internet-node/internet-stack.cc b/src/internet-node/internet-stack.cc index cde9ac719..916f436ac 100644 --- a/src/internet-node/internet-stack.cc +++ b/src/internet-node/internet-stack.cc @@ -36,11 +36,6 @@ namespace ns3 { void AddInternetStack (Ptr node) { - // This may be called on a node with a previously added stack - if (node->GetObject ()) - { - return; - } Ptr ipv4 = CreateObject (); Ptr arp = CreateObject (); ipv4->SetNode (node);