A Discrete-Event Network Simulator
API
node.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: George F. Riley<riley@ece.gatech.edu>
19 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 */
21#ifndef NODE_H
22#define NODE_H
23
24#include <vector>
25
26#include "ns3/object.h"
27#include "ns3/callback.h"
28#include "ns3/ptr.h"
29#include "ns3/net-device.h"
30
31namespace ns3 {
32
33class Application;
34class Packet;
35class Address;
36class Time;
37
38
56class Node : public Object
57{
58public:
63 static TypeId GetTypeId (void);
64
65 Node();
69 Node(uint32_t systemId);
70
71 virtual ~Node();
72
79 uint32_t GetId (void) const;
80
89 Time GetLocalTime (void) const;
90
95 uint32_t GetSystemId (void) const;
96
111 Ptr<NetDevice> GetDevice (uint32_t index) const;
116 uint32_t GetNDevices (void) const;
117
133
137 uint32_t GetNApplications (void) const;
138
174 uint16_t protocolType,
175 Ptr<NetDevice> device,
176 bool promiscuous=false);
184
204
205
206
210 static bool ChecksumEnabled (void);
211
212
213protected:
219 virtual void DoDispose (void);
220 virtual void DoInitialize (void);
221private:
222
227 void NotifyDeviceAdded (Ptr<NetDevice> device);
228
237 bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol, const Address &from);
248 bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
249 const Address &from, const Address &to, NetDevice::PacketType packetType);
261 bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
262 const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
263
267 void Construct (void);
268
276 uint16_t protocol;
278 };
279
281 typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
283 typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
284
287 std::vector<Ptr<NetDevice> > m_devices;
288 std::vector<Ptr<Application> > m_applications;
291};
292
293} // namespace ns3
294
295#endif /* NODE_H */
a polymophic address class
Definition: address.h:91
Callback template class.
Definition: callback.h:1279
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
A network Node.
Definition: node.h:57
static bool ChecksumEnabled(void)
Definition: node.cc:278
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:263
std::vector< DeviceAdditionListener > DeviceAdditionListenerList
Typedef for NetDevice addition listeners container.
Definition: node.h:283
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:287
virtual ~Node()
Definition: node.cc:103
DeviceAdditionListenerList m_deviceAdditionListeners
Device addition listeners in the node.
Definition: node.h:290
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
A callback invoked whenever a device is added to a node.
Definition: node.h:188
uint32_t GetId(void) const
Definition: node.cc:109
std::vector< struct Node::ProtocolHandlerEntry > ProtocolHandlerList
Typedef for protocol handlers container.
Definition: node.h:281
std::vector< Ptr< Application > > m_applications
Applications associated to this node.
Definition: node.h:288
void Construct(void)
Finish node's construction by setting the correct node ID.
Definition: node.cc:97
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
uint32_t m_id
Node id for this node.
Definition: node.h:285
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
A protocol handler.
Definition: node.h:159
uint32_t GetNApplications(void) const
Definition: node.cc:178
Ptr< Application > GetApplication(uint32_t index) const
Retrieve the index-th Application associated to this node.
Definition: node.cc:170
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:303
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:295
virtual void DoDispose(void)
The dispose method.
Definition: node.cc:185
uint32_t m_sid
System id for this node.
Definition: node.h:286
Time GetLocalTime(void) const
In the future, ns3 nodes may have clock that returned a local time different from the virtual time Si...
Definition: node.cc:116
virtual void DoInitialize(void)
Initialize() implementation.
Definition: node.cc:209
uint32_t GetNDevices(void) const
Definition: node.cc:152
ProtocolHandlerList m_handlers
Protocol handlers in the node.
Definition: node.h:289
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
Node()
Definition: node.cc:80
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:335
static TypeId GetTypeId(void)
Get the type ID.
Definition: node.cc:52
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
uint32_t GetSystemId(void) const
Definition: node.cc:123
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
Definition: node.cc:362
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:347
std::vector< Ptr< NetDevice > > m_devices
Devices associated to this node.
Definition: node.h:287
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:229
A base class which provides memory management and object aggregation.
Definition: object.h:88
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
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:793
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Protocol handler entry.
Definition: node.h:273
bool promiscuous
true if it is a promiscuous handler
Definition: node.h:277
uint16_t protocol
the protocol number
Definition: node.h:276
Ptr< NetDevice > device
the NetDevice
Definition: node.h:275
ProtocolHandler handler
the protocol handler
Definition: node.h:274