A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
31 namespace ns3 {
32 
33 class Application;
34 class Packet;
35 class Address;
36 
37 
55 class Node : public Object
56 {
57 public:
58  static TypeId GetTypeId (void);
59 
60  Node();
64  Node(uint32_t systemId);
65 
66  virtual ~Node();
67 
74  uint32_t GetId (void) const;
75 
80  uint32_t GetSystemId (void) const;
81 
89  uint32_t AddDevice (Ptr<NetDevice> device);
97  Ptr<NetDevice> GetDevice (uint32_t index) const;
102  uint32_t GetNDevices (void) const;
103 
111  uint32_t AddApplication (Ptr<Application> application);
117  Ptr<Application> GetApplication (uint32_t index) const;
118 
122  uint32_t GetNApplications (void) const;
123 
143  typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
159  uint16_t protocolType,
160  Ptr<NetDevice> device,
161  bool promiscuous=false);
169 
189 
190 
191 
195  static bool ChecksumEnabled (void);
196 
197 
198 protected:
204  virtual void DoDispose (void);
205  virtual void DoInitialize (void);
206 private:
207  void NotifyDeviceAdded (Ptr<NetDevice> device);
208  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from);
209  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
210  const Address &from, const Address &to, NetDevice::PacketType packetType);
211  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
212  const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
213 
214  void Construct (void);
215 
219  uint16_t protocol;
221  };
222  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
223  typedef std::vector<DeviceAdditionListener> DeviceAdditionListenerList;
224 
225  uint32_t m_id; // Node id for this node
226  uint32_t m_sid; // System id for this node
227  std::vector<Ptr<NetDevice> > m_devices;
228  std::vector<Ptr<Application> > m_applications;
231 };
232 
233 } // namespace ns3
234 
235 #endif /* NODE_H */
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:147
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Callback template class.
Definition: callback.h:920
uint32_t GetNApplications(void) const
Definition: node.cc:166
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
Definition: node.cc:197
DeviceAdditionListenerList m_deviceAdditionListeners
Definition: node.h:230
std::vector< DeviceAdditionListener > DeviceAdditionListenerList
Definition: node.h:223
static bool ChecksumEnabled(void)
Definition: node.cc:266
void NotifyDeviceAdded(Ptr< NetDevice > device)
Definition: node.cc:350
ProtocolHandler handler
Definition: node.h:217
std::vector< Ptr< NetDevice > > m_devices
Definition: node.h:227
uint32_t GetSystemId(void) const
Definition: node.cc:111
void UnregisterProtocolHandler(ProtocolHandler handler)
Definition: node.cc:251
a polymophic address class
Definition: address.h:86
std::vector< struct Node::ProtocolHandlerEntry > ProtocolHandlerList
Definition: node.h:222
uint32_t m_sid
Definition: node.h:226
Ptr< Application > GetApplication(uint32_t index) const
Definition: node.cc:158
virtual void DoDispose(void)
The dispose method.
Definition: node.cc:173
Ptr< NetDevice > device
Definition: node.h:218
bool PromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet >, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Definition: node.cc:275
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:132
uint16_t protocol
Definition: node.h:219
uint32_t GetNDevices(void) const
Definition: node.cc:140
ProtocolHandlerList m_handlers
Definition: node.h:229
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:323
std::vector< Ptr< Application > > m_applications
Definition: node.h:228
Definition: node.h:216
uint32_t m_id
Definition: node.h:225
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:217
static TypeId GetTypeId(void)
Definition: node.cc:48
bool ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet >, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc)
Definition: node.cc:291
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:118
uint32_t GetId(void) const
Definition: node.cc:104
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
Definition: node.cc:335
virtual ~Node()
Definition: node.cc:98
A network Node.
Definition: node.h:55
Callback< void, Ptr< NetDevice > > DeviceAdditionListener
A callback invoked whenever a device is added to a node.
Definition: node.h:173
bool NonPromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet >, uint16_t protocol, const Address &from)
Definition: node.cc:283
a base class which provides memory management and object aggregation
Definition: object.h:63
Callback< void, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, NetDevice::PacketType > ProtocolHandler
A protocol handler.
Definition: node.h:144
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:270
a unique identifier for an interface.
Definition: type-id.h:49
void Construct(void)
Definition: node.cc:92
bool promiscuous
Definition: node.h:220
Node()
Definition: node.cc:75