17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 // |
18 // |
19 // Author: George F. Riley<riley@ece.gatech.edu> |
19 // Author: George F. Riley<riley@ece.gatech.edu> |
20 // |
20 // |
21 |
21 |
22 // Implement the basic Node object for ns3. |
22 // Implement the basic INode object for ns3. |
23 // George F. Riley, Georgia Tech, Fall 2006 |
23 // George F. Riley, Georgia Tech, Fall 2006 |
24 |
24 |
25 #include "i-node.h" |
25 #include "i-node.h" |
26 #include "node-list.h" |
26 #include "node-list.h" |
27 #include "net-device.h" |
27 #include "net-device.h" |
28 #include "application.h" |
28 #include "application.h" |
29 #include "ns3/simulator.h" |
29 #include "ns3/simulator.h" |
30 |
30 |
31 namespace ns3{ |
31 namespace ns3{ |
32 |
32 |
33 const InterfaceId Node::iid ("Node"); |
33 const InterfaceId INode::iid ("INode"); |
34 |
34 |
35 Node::Node() |
35 INode::INode() |
36 : Interface (Node::iid), |
36 : Interface (INode::iid), |
37 m_id(0), |
37 m_id(0), |
38 m_sid(0) |
38 m_sid(0) |
39 { |
39 { |
40 m_id = NodeList::Add (this); |
40 m_id = NodeList::Add (this); |
41 } |
41 } |
42 |
42 |
43 Node::Node(uint32_t sid) |
43 INode::INode(uint32_t sid) |
44 : Interface (Node::iid), |
44 : Interface (INode::iid), |
45 m_id(0), |
45 m_id(0), |
46 m_sid(sid) |
46 m_sid(sid) |
47 { |
47 { |
48 m_id = NodeList::Add (this); |
48 m_id = NodeList::Add (this); |
49 } |
49 } |
50 |
50 |
51 Node::~Node () |
51 INode::~INode () |
52 {} |
52 {} |
53 |
53 |
54 TraceResolver * |
54 TraceResolver * |
55 Node::CreateTraceResolver (TraceContext const &context) |
55 INode::CreateTraceResolver (TraceContext const &context) |
56 { |
56 { |
57 return DoCreateTraceResolver (context); |
57 return DoCreateTraceResolver (context); |
58 } |
58 } |
59 |
59 |
60 uint32_t |
60 uint32_t |
61 Node::GetId (void) const |
61 INode::GetId (void) const |
62 { |
62 { |
63 return m_id; |
63 return m_id; |
64 } |
64 } |
65 |
65 |
66 uint32_t |
66 uint32_t |
67 Node::GetSystemId (void) const |
67 INode::GetSystemId (void) const |
68 { |
68 { |
69 return m_sid; |
69 return m_sid; |
70 } |
70 } |
71 |
71 |
72 uint32_t |
72 uint32_t |
73 Node::AddDevice (Ptr<NetDevice> device) |
73 INode::AddDevice (Ptr<NetDevice> device) |
74 { |
74 { |
75 uint32_t index = m_devices.size (); |
75 uint32_t index = m_devices.size (); |
76 m_devices.push_back (device); |
76 m_devices.push_back (device); |
77 DoAddDevice (device); |
77 DoAddDevice (device); |
78 device->SetIfIndex(index); |
78 device->SetIfIndex(index); |
79 return index; |
79 return index; |
80 } |
80 } |
81 Ptr<NetDevice> |
81 Ptr<NetDevice> |
82 Node::GetDevice (uint32_t index) const |
82 INode::GetDevice (uint32_t index) const |
83 { |
83 { |
84 return m_devices[index]; |
84 return m_devices[index]; |
85 } |
85 } |
86 uint32_t |
86 uint32_t |
87 Node::GetNDevices (void) const |
87 INode::GetNDevices (void) const |
88 { |
88 { |
89 return m_devices.size (); |
89 return m_devices.size (); |
90 } |
90 } |
91 |
91 |
92 uint32_t |
92 uint32_t |
93 Node::AddApplication (Ptr<Application> application) |
93 INode::AddApplication (Ptr<Application> application) |
94 { |
94 { |
95 uint32_t index = m_applications.size (); |
95 uint32_t index = m_applications.size (); |
96 m_applications.push_back (application); |
96 m_applications.push_back (application); |
97 return index; |
97 return index; |
98 } |
98 } |
99 Ptr<Application> |
99 Ptr<Application> |
100 Node::GetApplication (uint32_t index) const |
100 INode::GetApplication (uint32_t index) const |
101 { |
101 { |
102 return m_applications[index]; |
102 return m_applications[index]; |
103 } |
103 } |
104 uint32_t |
104 uint32_t |
105 Node::GetNApplications (void) const |
105 INode::GetNApplications (void) const |
106 { |
106 { |
107 return m_applications.size (); |
107 return m_applications.size (); |
108 } |
108 } |
109 |
109 |
110 |
110 |
111 void Node::DoDispose() |
111 void INode::DoDispose() |
112 { |
112 { |
113 for (std::vector<Ptr<NetDevice> >::iterator i = m_devices.begin (); |
113 for (std::vector<Ptr<NetDevice> >::iterator i = m_devices.begin (); |
114 i != m_devices.end (); i++) |
114 i != m_devices.end (); i++) |
115 { |
115 { |
116 Ptr<NetDevice> device = *i; |
116 Ptr<NetDevice> device = *i; |