00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: George F. Riley<riley@ece.gatech.edu> 00019 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00020 */ 00021 #ifndef NODE_H 00022 #define NODE_H 00023 00024 #include <vector> 00025 00026 #include "ns3/object.h" 00027 #include "ns3/callback.h" 00028 #include "ns3/ptr.h" 00029 #include "ns3/net-device.h" 00030 00031 namespace ns3 { 00032 00033 class Application; 00034 class Packet; 00035 class Address; 00036 00037 00038 /** 00039 * \ingroup node 00040 * 00041 * \brief A network Node. 00042 * 00043 * This class holds together: 00044 * - a list of NetDevice objects which represent the network interfaces 00045 * of this node which are connected to other Node instances through 00046 * Channel instances. 00047 * - a list of Application objects which represent the userspace 00048 * traffic generation applications which interact with the Node 00049 * through the Socket API. 00050 * - a node Id: a unique per-node identifier. 00051 * - a system Id: a unique Id used for parallel simulations. 00052 * 00053 * Every Node created is added to the NodeList automatically. 00054 */ 00055 class Node : public Object 00056 { 00057 public: 00058 static TypeId GetTypeId (void); 00059 00060 /** 00061 * Must be invoked by subclasses only. 00062 */ 00063 Node(); 00064 /** 00065 * \param systemId a unique integer used for parallel simulations. 00066 * 00067 * Must be invoked by subclasses only. 00068 */ 00069 Node(uint32_t systemId); 00070 00071 virtual ~Node(); 00072 00073 /** 00074 * \returns the unique id of this node. 00075 * 00076 * This unique id happens to be also the index of the Node into 00077 * the NodeList. 00078 */ 00079 uint32_t GetId (void) const; 00080 00081 /** 00082 * \returns the system id for parallel simulations associated 00083 * to this node. 00084 */ 00085 uint32_t GetSystemId (void) const; 00086 00087 /** 00088 * \param device NetDevice to associate to this node. 00089 * \returns the index of the NetDevice into the Node's list of 00090 * NetDevice. 00091 * 00092 * Associate this device to this node. 00093 */ 00094 uint32_t AddDevice (Ptr<NetDevice> device); 00095 /** 00096 * \param index the index of the requested NetDevice 00097 * \returns the requested NetDevice associated to this Node. 00098 * 00099 * The indexes used by the GetDevice method start at one and 00100 * end at GetNDevices () 00101 */ 00102 Ptr<NetDevice> GetDevice (uint32_t index) const; 00103 /** 00104 * \returns the number of NetDevice instances associated 00105 * to this Node. 00106 */ 00107 uint32_t GetNDevices (void) const; 00108 00109 /** 00110 * \param application Application to associate to this node. 00111 * \returns the index of the Application within the Node's list 00112 * of Application. 00113 * 00114 * Associated this Application to this Node. This method is called 00115 * automatically from Application::Application so the user 00116 * has little reasons to call this method directly. 00117 */ 00118 uint32_t AddApplication (Ptr<Application> application); 00119 /** 00120 * \param index 00121 * \returns the application associated to this requested index 00122 * within this Node. 00123 */ 00124 Ptr<Application> GetApplication (uint32_t index) const; 00125 00126 /** 00127 * \returns the number of applications associated to this Node. 00128 */ 00129 uint32_t GetNApplications (void) const; 00130 00131 /** 00132 * A protocol handler 00133 * 00134 * \param device a pointer to the net device which received the packet 00135 * \param packet the packet received 00136 * \param protocol the 16 bit protocol number associated with this packet. 00137 * This protocol number is expected to be the same protocol number 00138 * given to the Send method by the user on the sender side. 00139 * \param sender the address of the sender 00140 * \param receiver the address of the receiver; Note: this value is 00141 * only valid for promiscuous mode protocol 00142 * handlers. 00143 * \param packetType type of packet received 00144 * (broadcast/multicast/unicast/otherhost); Note: 00145 * this value is only valid for promiscuous mode 00146 * protocol handlers. 00147 */ 00148 typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &, 00149 const Address &, NetDevice::PacketType> ProtocolHandler; 00150 /** 00151 * \param handler the handler to register 00152 * \param protocolType the type of protocol this handler is 00153 * interested in. This protocol type is a so-called 00154 * EtherType, as registered here: 00155 * http://standards.ieee.org/regauth/ethertype/eth.txt 00156 * the value zero is interpreted as matching all 00157 * protocols. 00158 * \param device the device attached to this handler. If the 00159 * value is zero, the handler is attached to all 00160 * devices on this node. 00161 * \param promiscuous whether to register a promiscuous mode handler 00162 */ 00163 void RegisterProtocolHandler (ProtocolHandler handler, 00164 uint16_t protocolType, 00165 Ptr<NetDevice> device, 00166 bool promiscuous=false); 00167 /** 00168 * \param handler the handler to unregister 00169 * 00170 * After this call returns, the input handler will never 00171 * be invoked anymore. 00172 */ 00173 void UnregisterProtocolHandler (ProtocolHandler handler); 00174 00175 00176 protected: 00177 /** 00178 * The dispose method. Subclasses must override this method 00179 * and must chain up to it by calling Node::DoDispose at the 00180 * end of their own DoDispose method. 00181 */ 00182 virtual void DoDispose (void); 00183 private: 00184 00185 /** 00186 * \param device the device added to this Node. 00187 * 00188 * This method is invoked whenever a user calls Node::AddDevice. 00189 */ 00190 virtual void NotifyDeviceAdded (Ptr<NetDevice> device); 00191 00192 bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from); 00193 bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, 00194 const Address &from, const Address &to, NetDevice::PacketType packetType); 00195 bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, 00196 const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc); 00197 00198 void Construct (void); 00199 00200 struct ProtocolHandlerEntry { 00201 ProtocolHandler handler; 00202 Ptr<NetDevice> device; 00203 uint16_t protocol; 00204 bool promiscuous; 00205 }; 00206 typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList; 00207 uint32_t m_id; // Node id for this node 00208 uint32_t m_sid; // System id for this node 00209 std::vector<Ptr<NetDevice> > m_devices; 00210 std::vector<Ptr<Application> > m_applications; 00211 ProtocolHandlerList m_handlers; 00212 00213 }; 00214 00215 } //namespace ns3 00216 00217 #endif /* NODE_H */