# HG changeset patch # User Tom Henderson # Date 1212731567 25200 # Node ID 6187b1cddc175d2a0d4f0cb43f09e9f92f156d7a # Parent c2f34dac1b9ea3c813434949e1889a68dec66f49 Node and NetDevice names patch diff -r c2f34dac1b9e -r 6187b1cddc17 src/node/node-list.cc --- a/src/node/node-list.cc Thu Jun 05 15:56:23 2008 -0700 +++ b/src/node/node-list.cc Thu Jun 05 22:52:47 2008 -0700 @@ -45,6 +45,7 @@ public: NodeList::Iterator End (void) const; Ptr GetNode (uint32_t n); uint32_t GetNNodes (void); + Ptr GetNodeByName (const std::string name); static Ptr Get (void); @@ -143,6 +144,29 @@ NodeListPriv::GetNode (uint32_t n) return m_nodes[n]; } +Ptr +NodeListPriv::GetNodeByName (const std::string name) +{ + NS_LOG_FUNCTION_NOARGS (); + uint32_t found = 0; + Ptr foundNode = 0; + for (std::vector >::iterator i = m_nodes.begin (); + i != m_nodes.end (); i++) + { + Ptr node = *i; + if (node->GetName () == name) + { + foundNode = node; + found++; + } + } + if (found > 1) + { + NS_ASSERT_MSG (false, "More than one node with name: " << name); + } + return foundNode; +} + } /** @@ -172,5 +196,10 @@ NodeList::GetNode (uint32_t n) { return NodeListPriv::Get ()->GetNode (n); } +Ptr +NodeList::GetNodeByName (const std::string name) +{ + return NodeListPriv::Get ()->GetNodeByName (name); +} }//namespace ns3 diff -r c2f34dac1b9e -r 6187b1cddc17 src/node/node-list.h --- a/src/node/node-list.h Thu Jun 05 15:56:23 2008 -0700 +++ b/src/node/node-list.h Thu Jun 05 22:52:47 2008 -0700 @@ -65,6 +65,14 @@ public: * \returns the Node associated to index n. */ static Ptr GetNode (uint32_t n); + /** + * \param name index of requested node. + * \returns the Node associated to name, if found + * + * This method returns a Ptr if a Node is found with that name. + * If two or more Nodes have the same name, the simulator asserts. + */ + static Ptr GetNodeByName (const std::string name); }; }//namespace ns3 diff -r c2f34dac1b9e -r 6187b1cddc17 src/node/node.cc --- a/src/node/node.cc Thu Jun 05 15:56:23 2008 -0700 +++ b/src/node/node.cc Thu Jun 05 22:52:47 2008 -0700 @@ -53,16 +53,19 @@ Node::GetTypeId (void) return tid; } -Node::Node() - : m_id(0), - m_sid(0) +Node::Node () + : m_id (0), + m_sid (0), + m_name ("") + { Construct (); } -Node::Node(uint32_t sid) - : m_id(0), - m_sid(sid) +Node::Node (uint32_t sid) + : m_id (0), + m_sid (sid), + m_name ("") { Construct (); } @@ -87,6 +90,18 @@ Node::GetSystemId (void) const { return m_sid; } + +void +Node::SetName (const std::string name) +{ + m_name = name; +} + +std::string +Node::GetName (void) const +{ + return m_name; +} uint32_t Node::AddDevice (Ptr device) @@ -110,6 +125,28 @@ Node::GetNDevices (void) const return m_devices.size (); } +Ptr +Node::GetDeviceByName (const std::string name) const +{ + uint32_t found = 0; + Ptr foundDevice = 0; + for (std::vector >::const_iterator i = m_devices.begin (); + i != m_devices.end (); i++) + { + Ptr device = *i; + if (device->GetName () == name) + { + foundDevice = device; + found++; + } + } + if (found > 1) + { + NS_ASSERT_MSG (false, "More than one device with name: " << name); + } + return foundDevice; +} + uint32_t Node::AddApplication (Ptr application) { diff -r c2f34dac1b9e -r 6187b1cddc17 src/node/node.h --- a/src/node/node.h Thu Jun 05 15:56:23 2008 -0700 +++ b/src/node/node.h Thu Jun 05 22:52:47 2008 -0700 @@ -71,6 +71,15 @@ public: virtual ~Node(); /** + * \param name name of the node (e.g. "n0") + */ + void SetName (const std::string name); + /** + * \return name name of the node (e.g. "n0") + */ + std::string GetName (void) const; + + /** * \returns the unique id of this node. * * This unique id happens to be also the index of the Node into @@ -108,7 +117,15 @@ public: * to this Node. */ uint32_t GetNDevices (void) const; - + /** + * \param name index of requested device. + * \returns the NetDevice associated to name, if found + * + * This method returns a Ptr if a NetDevice is found with + * that name. If two or more NetDevices have the same name, the + * simulator asserts. + */ + Ptr GetDeviceByName (const std::string name) const; /** * \param application Application to associate to this node. * \returns the index of the Application within the Node's list @@ -185,6 +202,7 @@ private: typedef std::vector ProtocolHandlerList; uint32_t m_id; // Node id for this node uint32_t m_sid; // System id for this node + std::string m_name; std::vector > m_devices; std::vector > m_applications; ProtocolHandlerList m_handlers;