View | Details | Raw Unified | Return to bug 215
Collapse All | Expand All

(-)a/src/node/node-list.cc (+29 lines)
 Lines 45-50   public: Link Here 
45
  NodeList::Iterator End (void) const;
45
  NodeList::Iterator End (void) const;
46
  Ptr<Node> GetNode (uint32_t n);
46
  Ptr<Node> GetNode (uint32_t n);
47
  uint32_t GetNNodes (void);
47
  uint32_t GetNNodes (void);
48
  Ptr<Node> GetNodeByName (const std::string name);
48
49
49
  static Ptr<NodeListPriv> Get (void);
50
  static Ptr<NodeListPriv> Get (void);
50
  
51
  
 Lines 143-148   NodeListPriv::GetNode (uint32_t n) Link Here 
143
  return m_nodes[n];
144
  return m_nodes[n];
144
}
145
}
145
146
147
Ptr<Node>
148
NodeListPriv::GetNodeByName (const std::string name)
149
{
150
  NS_LOG_FUNCTION_NOARGS ();
151
  uint32_t found = 0;
152
  Ptr<Node> foundNode = 0;
153
  for (std::vector<Ptr<Node> >::iterator i = m_nodes.begin ();
154
       i != m_nodes.end (); i++)
155
    {
156
      Ptr<Node> node = *i;
157
      if (node->GetName () == name)
158
        {
159
          foundNode = node;
160
          found++;
161
        }
162
    }
163
  if (found > 1)
164
    {
165
      NS_ASSERT_MSG (false, "More than one node with name: " << name);
166
    }
167
  return foundNode;
168
}
169
146
}
170
}
147
171
148
/**
172
/**
 Lines 172-176   NodeList::GetNode (uint32_t n) Link Here 
172
{
196
{
173
  return NodeListPriv::Get ()->GetNode (n);
197
  return NodeListPriv::Get ()->GetNode (n);
174
}
198
}
199
Ptr<Node>
200
NodeList::GetNodeByName (const std::string name)
201
{
202
  return NodeListPriv::Get ()->GetNodeByName (name);
203
}
175
204
176
}//namespace ns3
205
}//namespace ns3
(-)a/src/node/node-list.h (+8 lines)
 Lines 65-70   public: Link Here 
65
   * \returns the Node associated to index n.
65
   * \returns the Node associated to index n.
66
   */
66
   */
67
  static Ptr<Node> GetNode (uint32_t n);
67
  static Ptr<Node> GetNode (uint32_t n);
68
  /**
69
   * \param name index of requested node.
70
   * \returns the Node associated to name, if found
71
   *
72
   * This method returns a Ptr<Node> if a Node is found with that name.
73
   * If two or more Nodes have the same  name, the simulator asserts.
74
   */
75
  static Ptr<Node> GetNodeByName (const std::string name);
68
};
76
};
69
77
70
}//namespace ns3
78
}//namespace ns3
(-)a/src/node/node.cc (-6 / +43 lines)
 Lines 53-68   Node::GetTypeId (void) Link Here 
53
  return tid;
53
  return tid;
54
}
54
}
55
55
56
Node::Node()
56
Node::Node ()
57
  : m_id(0), 
57
  : m_id (0), 
58
    m_sid(0)
58
    m_sid (0),
59
    m_name ("")
60
59
{
61
{
60
  Construct ();
62
  Construct ();
61
}
63
}
62
64
63
Node::Node(uint32_t sid)
65
Node::Node (uint32_t sid)
64
  : m_id(0), 
66
  : m_id (0), 
65
    m_sid(sid)
67
    m_sid (sid),
68
    m_name ("")
66
{ 
69
{ 
67
  Construct ();
70
  Construct ();
68
}
71
}
 Lines 87-92   Node::GetSystemId (void) const Link Here 
87
{
90
{
88
  return m_sid;
91
  return m_sid;
89
}
92
}
93
94
void               
95
Node::SetName (const std::string name)
96
{   
97
  m_name = name;   
98
}                  
99
100
std::string        
101
Node::GetName (void) const
102
{                    
103
  return m_name;
104
}                    
90
105
91
uint32_t 
106
uint32_t 
92
Node::AddDevice (Ptr<NetDevice> device)
107
Node::AddDevice (Ptr<NetDevice> device)
 Lines 110-115   Node::GetNDevices (void) const Link Here 
110
  return m_devices.size ();
125
  return m_devices.size ();
111
}
126
}
112
127
128
Ptr<NetDevice>
129
Node::GetDeviceByName (const std::string name) const
130
{
131
  uint32_t found = 0;
132
  Ptr<NetDevice> foundDevice = 0;
133
  for (std::vector<Ptr<NetDevice> >::const_iterator i = m_devices.begin ();
134
       i != m_devices.end (); i++)
135
    {
136
      Ptr<NetDevice> device = *i;
137
      if (device->GetName () == name)
138
        {
139
          foundDevice = device;
140
          found++;
141
        }
142
    }
143
  if (found > 1)
144
    {
145
      NS_ASSERT_MSG (false, "More than one device with name: " << name);
146
    }
147
  return foundDevice;
148
}
149
113
uint32_t 
150
uint32_t 
114
Node::AddApplication (Ptr<Application> application)
151
Node::AddApplication (Ptr<Application> application)
115
{
152
{
(-)a/src/node/node.h (-1 / +19 lines)
 Lines 71-76   public: Link Here 
71
  virtual ~Node();
71
  virtual ~Node();
72
72
73
  /**
73
  /**
74
   * \param name name of the node (e.g. "n0")
75
   */
76
  void SetName (const std::string name);
77
  /**
78
   * \return name name of the node (e.g. "n0")
79
   */
80
  std::string GetName (void) const;
81
82
  /**
74
   * \returns the unique id of this node.
83
   * \returns the unique id of this node.
75
   * 
84
   * 
76
   * This unique id happens to be also the index of the Node into
85
   * This unique id happens to be also the index of the Node into
 Lines 108-114   public: Link Here 
108
   *          to this Node.
117
   *          to this Node.
109
   */
118
   */
110
  uint32_t GetNDevices (void) const;
119
  uint32_t GetNDevices (void) const;
111
120
  /**
121
   * \param name index of requested device.
122
   * \returns the NetDevice associated to name, if found
123
   *
124
   * This method returns a Ptr<NetDevice> if a NetDevice is found with 
125
   * that name.  If two or more NetDevices have the same name, the 
126
   * simulator asserts.
127
   */
128
  Ptr<NetDevice> GetDeviceByName (const std::string name) const;
112
  /**
129
  /**
113
   * \param application Application to associate to this node.
130
   * \param application Application to associate to this node.
114
   * \returns the index of the Application within the Node's list
131
   * \returns the index of the Application within the Node's list
 Lines 185-190   private: Link Here 
185
  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
202
  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
186
  uint32_t    m_id;         // Node id for this node
203
  uint32_t    m_id;         // Node id for this node
187
  uint32_t    m_sid;        // System id for this node
204
  uint32_t    m_sid;        // System id for this node
205
  std::string m_name;
188
  std::vector<Ptr<NetDevice> > m_devices;
206
  std::vector<Ptr<NetDevice> > m_devices;
189
  std::vector<Ptr<Application> > m_applications;
207
  std::vector<Ptr<Application> > m_applications;
190
  ProtocolHandlerList m_handlers;
208
  ProtocolHandlerList m_handlers;

Return to bug 215