A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
node.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: George F. Riley<riley@ece.gatech.edu>
18 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20#ifndef NODE_H
21#define NODE_H
22
23#include "net-device.h"
24
25#include "ns3/callback.h"
26#include "ns3/object.h"
27#include "ns3/ptr.h"
28
29#include <vector>
30
31namespace ns3
32{
33
34class Application;
35class Packet;
36class Address;
37class Time;
38
39/**
40 * \ingroup network
41 *
42 * \brief A network Node.
43 *
44 * This class holds together:
45 * - a list of NetDevice objects which represent the network interfaces
46 * of this node which are connected to other Node instances through
47 * Channel instances.
48 * - a list of Application objects which represent the userspace
49 * traffic generation applications which interact with the Node
50 * through the Socket API.
51 * - a node Id: a unique per-node identifier.
52 * - a system Id: a unique Id used for parallel simulations.
53 *
54 * Every Node created is added to the NodeList automatically.
55 */
56class Node : public Object
57{
58 public:
59 /**
60 * \brief Get the type ID.
61 * \return the object TypeId
62 */
63 static TypeId GetTypeId();
64
65 Node();
66 /**
67 * \param systemId a unique integer used for parallel simulations.
68 */
69 Node(uint32_t systemId);
70
71 ~Node() override;
72
73 /**
74 * \returns the unique id of this node.
75 *
76 * This unique id happens to be also the index of the Node into
77 * the NodeList.
78 */
79 uint32_t GetId() const;
80
81 /**
82 * In the future, ns3 nodes may have clock that returned a local time
83 * different from the virtual time Simulator::Now().
84 * This function is currently a placeholder to ease the development of this feature.
85 * For now, it is only an alias to Simulator::Now()
86 *
87 * \return The time as seen by this node
88 */
89 Time GetLocalTime() const;
90
91 /**
92 * \returns the system id for parallel simulations associated
93 * to this node.
94 */
95 uint32_t GetSystemId() const;
96
97 /**
98 * \brief Associate a NetDevice to this node.
99 *
100 * \param device NetDevice to associate to this node.
101 * \returns the index of the NetDevice into the Node's list of
102 * NetDevice.
103 */
105 /**
106 * \brief Retrieve the index-th NetDevice associated to this node.
107 *
108 * \param index the index of the requested NetDevice
109 * \returns the requested NetDevice.
110 */
111 Ptr<NetDevice> GetDevice(uint32_t index) const;
112 /**
113 * \returns the number of NetDevice instances associated
114 * to this Node.
115 */
116 uint32_t GetNDevices() const;
117
118 /**
119 * \brief Associate an Application to this Node.
120 *
121 * \param application Application to associate to this node.
122 * \returns the index of the Application within the Node's list
123 * of Application.
124 */
126 /**
127 * \brief Retrieve the index-th Application associated to this node.
128 *
129 * \param index the index of the requested Application
130 * \returns the requested Application.
131 */
133
134 /**
135 * \returns the number of Application instances associated to this Node.
136 */
138
139 /**
140 * A protocol handler
141 *
142 * \param device a pointer to the net device which received the packet
143 * \param packet the packet received
144 * \param protocol the 16 bit protocol number associated with this packet.
145 * This protocol number is expected to be the same protocol number
146 * given to the Send method by the user on the sender side.
147 * \param sender the address of the sender
148 * \param receiver the address of the receiver; Note: this value is
149 * only valid for promiscuous mode protocol
150 * handlers. Note: If the L2 protocol does not use L2
151 * addresses, the address reported here is the value of
152 * device->GetAddress().
153 * \param packetType type of packet received
154 * (broadcast/multicast/unicast/otherhost); Note:
155 * this value is only valid for promiscuous mode
156 * protocol handlers.
157 */
158 typedef Callback<void,
161 uint16_t,
162 const Address&,
163 const Address&,
166 /**
167 * \param handler the handler to register
168 * \param protocolType the type of protocol this handler is
169 * interested in. This protocol type is a so-called
170 * EtherType, as registered here:
171 * http://standards.ieee.org/regauth/ethertype/eth.txt
172 * the value zero is interpreted as matching all
173 * protocols.
174 * \param device the device attached to this handler. If the
175 * value is zero, the handler is attached to all
176 * devices on this node.
177 * \param promiscuous whether to register a promiscuous mode handler
178 */
180 uint16_t protocolType,
181 Ptr<NetDevice> device,
182 bool promiscuous = false);
183 /**
184 * \param handler the handler to unregister
185 *
186 * After this call returns, the input handler will never
187 * be invoked anymore.
188 */
190
191 /**
192 * A callback invoked whenever a device is added to a node.
193 */
195 /**
196 * \param listener the listener to add
197 *
198 * Add a new listener to the list of listeners for the device-added
199 * event. When a new listener is added, it is notified of the existence
200 * of all already-added devices to make discovery of devices easier.
201 */
203 /**
204 * \param listener the listener to remove
205 *
206 * Remove an existing listener from the list of listeners for the
207 * device-added event.
208 */
210
211 /**
212 * \returns true if checksums are enabled, false otherwise.
213 */
214 static bool ChecksumEnabled();
215
216 protected:
217 /**
218 * The dispose method. Subclasses must override this method
219 * and must chain up to it by calling Node::DoDispose at the
220 * end of their own DoDispose method.
221 */
222 void DoDispose() override;
223 void DoInitialize() override;
224
225 private:
226 /**
227 * \brief Notifies all the DeviceAdditionListener about the new device added.
228 * \param device the added device to notify.
229 */
231
232 /**
233 * \brief Receive a packet from a device in non-promiscuous mode.
234 * \param device the device
235 * \param packet the packet
236 * \param protocol the protocol
237 * \param from the sender
238 * \returns true if the packet has been delivered to a protocol handler.
239 */
241 Ptr<const Packet> packet,
242 uint16_t protocol,
243 const Address& from);
244 /**
245 * \brief Receive a packet from a device in promiscuous mode.
246 * \param device the device
247 * \param packet the packet
248 * \param protocol the protocol
249 * \param from the sender
250 * \param to the destination
251 * \param packetType the packet type
252 * \returns true if the packet has been delivered to a protocol handler.
253 */
255 Ptr<const Packet> packet,
256 uint16_t protocol,
257 const Address& from,
258 const Address& to,
259 NetDevice::PacketType packetType);
260 /**
261 * \brief Receive a packet from a device.
262 * \param device the device
263 * \param packet the packet
264 * \param protocol the protocol
265 * \param from the sender
266 * \param to the destination
267 * \param packetType the packet type
268 * \param promisc true if received in promiscuous mode
269 * \returns true if the packet has been delivered to a protocol handler.
270 */
273 uint16_t protocol,
274 const Address& from,
275 const Address& to,
276 NetDevice::PacketType packetType,
277 bool promisc);
278
279 /**
280 * \brief Finish node's construction by setting the correct node ID.
281 */
282 void Construct();
283
284 /**
285 * \brief Protocol handler entry.
286 * This structure is used to demultiplex all the protocols.
287 */
289 {
290 ProtocolHandler handler; //!< the protocol handler
291 Ptr<NetDevice> device; //!< the NetDevice
292 uint16_t protocol; //!< the protocol number
293 bool promiscuous; //!< true if it is a promiscuous handler
294 };
295
296 /// Typedef for protocol handlers container
297 typedef std::vector<Node::ProtocolHandlerEntry> ProtocolHandlerList;
298 /// Typedef for NetDevice addition listeners container
299 typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
300
301 uint32_t m_id; //!< Node id for this node
302 uint32_t m_sid; //!< System id for this node
303 std::vector<Ptr<NetDevice>> m_devices; //!< Devices associated to this node
304 std::vector<Ptr<Application>> m_applications; //!< Applications associated to this node
305 ProtocolHandlerList m_handlers; //!< Protocol handlers in the node
306 DeviceAdditionListenerList m_deviceAdditionListeners; //!< Device addition listeners in the node
307};
308
309} // namespace ns3
310
311#endif /* NODE_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
A network Node.
Definition: node.h:57
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:264
std::vector< DeviceAdditionListener > DeviceAdditionListenerList
Typedef for NetDevice addition listeners container.
Definition: node.h:299
uint32_t GetSystemId() const
Definition: node.cc:129
void DoDispose() override
The dispose method.
Definition: node.cc:190
bool PromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet from a device in promiscuous mode.
Definition: node.cc:286
DeviceAdditionListenerList m_deviceAdditionListeners
Device addition listeners in the node.
Definition: node.h:306
std::vector< Ptr< Application > > m_applications
Applications associated to this node.
Definition: node.h:304
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:135
uint32_t m_id
Node id for this node.
Definition: node.h:301
uint32_t GetNDevices() const
Definition: node.cc:158
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
A protocol handler.
Definition: node.h:165
uint32_t GetNApplications() const
Definition: node.cc:184
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:175
bool ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet >, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc)
Receive a packet from a device.
Definition: node.cc:314
bool NonPromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from)
Receive a packet from a device in non-promiscuous mode.
Definition: node.cc:298
std::vector< Node::ProtocolHandlerEntry > ProtocolHandlerList
Typedef for protocol handlers container.
Definition: node.h:297
uint32_t m_sid
System id for this node.
Definition: node.h:302
ProtocolHandlerList m_handlers
Protocol handlers in the node.
Definition: node.h:305
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:164
void Construct()
Finish node's construction by setting the correct node ID.
Definition: node.cc:105
static TypeId GetTypeId()
Get the type ID.
Definition: node.cc:55
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
A callback invoked whenever a device is added to a node.
Definition: node.h:194
uint32_t GetId() const
Definition: node.cc:117
Node()
Definition: node.cc:88
Time GetLocalTime() const
In the future, ns3 nodes may have clock that returned a local time different from the virtual time Si...
Definition: node.cc:123
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:351
void DoInitialize() override
Initialize() implementation.
Definition: node.cc:213
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:149
~Node() override
Definition: node.cc:111
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
Definition: node.cc:377
static bool ChecksumEnabled()
Definition: node.cc:278
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:363
std::vector< Ptr< NetDevice > > m_devices
Devices associated to this node.
Definition: node.h:303
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:231
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Protocol handler entry.
Definition: node.h:289
bool promiscuous
true if it is a promiscuous handler
Definition: node.h:293
uint16_t protocol
the protocol number
Definition: node.h:292
Ptr< NetDevice > device
the NetDevice
Definition: node.h:291
ProtocolHandler handler
the protocol handler
Definition: node.h:290