nsc: move nsc glue code from nsc-tcp-l4-protocol to node/nsc-glue.cc.
known problems:
- sim_interface.h is duplicated
- nsc-glue.cc adds hooks in node.cc, "hijacks" incoming packets
- nsc-glue exports NSCs INetStack (instead of wrapping it completely)
- nsc-tcp-l4-protocol and nsc-tcp-socket-impl make calls into nsc-glue
- nsc-tcp-socket-impl should really be "nsc-socket-core" (or something
like that)
needs fixing on nsc side:
- no support for multiple interfaces yet (also not yet supported
on nsc side)
- nsc initialisation still tied to IP (Adding an Interface and assigning the
IP address is a single step; it should be separate)
maybe there is more.
There is a NSC_NEXT define in nsc-glue.h, its main purpose is to flag
the places where the NSC API needs to be adapted to support multiple
interfaces in nsc.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3 * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
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;
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.
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
18 * Authors: George F. Riley<riley@ece.gatech.edu>
19 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
26 #include "ns3/object.h"
27 #include "ns3/callback.h"
29 #include "ns3/net-device.h"
43 * \brief A network Node.
45 * This class holds together:
46 * - a list of NetDevice objects which represent the network interfaces
47 * of this node which are connected to other Node instances through
49 * - a list of Application objects which represent the userspace
50 * traffic generation applications which interact with the Node
51 * through the Socket API.
52 * - a node Id: a unique per-node identifier.
53 * - a system Id: a unique Id used for parallel simulations.
55 * Every Node created is added to the NodeList automatically.
57 class Node : public Object
60 static TypeId GetTypeId (void);
63 * Must be invoked by subclasses only.
67 * \param systemId a unique integer used for parallel simulations.
69 * Must be invoked by subclasses only.
71 Node(uint32_t systemId);
76 * \returns the unique id of this node.
78 * This unique id happens to be also the index of the Node into
81 uint32_t GetId (void) const;
84 * \returns the system id for parallel simulations associated
87 uint32_t GetSystemId (void) const;
90 * \param device NetDevice to associate to this node.
91 * \returns the index of the NetDevice into the Node's list of
94 * Associate this device to this node.
96 uint32_t AddDevice (Ptr<NetDevice> device);
98 * \param index the index of the requested NetDevice
99 * \returns the requested NetDevice associated to this Node.
101 * The indexes used by the GetDevice method start at one and
102 * end at GetNDevices ()
104 Ptr<NetDevice> GetDevice (uint32_t index) const;
106 * \returns the number of NetDevice instances associated
109 uint32_t GetNDevices (void) const;
112 * \param application Application to associate to this node.
113 * \returns the index of the Application within the Node's list
116 * Associated this Application to this Node. This method is called
117 * automatically from Application::Application so the user
118 * has little reasons to call this method directly.
120 uint32_t AddApplication (Ptr<Application> application);
123 * \returns the application associated to this requested index
126 Ptr<Application> GetApplication (uint32_t index) const;
129 * \returns the number of applications associated to this Node.
131 uint32_t GetNApplications (void) const;
136 * \param device a pointer to the net device which received the packet
137 * \param packet the packet received
138 * \param protocol the 16 bit protocol number associated with this packet.
139 * This protocol number is expected to be the same protocol number
140 * given to the Send method by the user on the sender side.
141 * \param sender the address of the sender
142 * \param receiver the address of the receiver; Note: this value is
143 * only valid for promiscuous mode protocol
145 * \param packetType type of packet received
146 * (broadcast/multicast/unicast/otherhost); Note:
147 * this value is only valid for promiscuous mode
150 typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
151 const Address &, NetDevice::PacketType> ProtocolHandler;
153 * \param handler the handler to register
154 * \param protocolType the type of protocol this handler is
155 * interested in. This protocol type is a so-called
156 * EtherType, as registered here:
157 * http://standards.ieee.org/regauth/ethertype/eth.txt
158 * the value zero is interpreted as matching all
160 * \param device the device attached to this handler. If the
161 * value is zero, the handler is attached to all
162 * devices on this node.
163 * \param promiscuous whether to register a promiscuous mode handler
165 void RegisterProtocolHandler (ProtocolHandler handler,
166 uint16_t protocolType,
167 Ptr<NetDevice> device,
168 bool promiscuous=false);
170 * \param handler the handler to unregister
172 * After this call returns, the input handler will never
173 * be invoked anymore.
175 void UnregisterProtocolHandler (ProtocolHandler handler);
177 void SetNscLibrary (const std::string &soname);
178 std::string GetNscLibrary (void) const;
179 INetStack* GetNscInetStack(void);
180 void RegisterNscWakeupCallback (Callback<void>);
183 * \returns true if checksums are enabled, false otherwise.
185 static bool ChecksumEnabled (void);
189 * The dispose method. Subclasses must override this method
190 * and must chain up to it by calling Node::DoDispose at the
191 * end of their own DoDispose method.
193 virtual void DoDispose (void);
197 * \param device the device added to this Node.
199 * This method is invoked whenever a user calls Node::AddDevice.
201 virtual void NotifyDeviceAdded (Ptr<NetDevice> device);
203 bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from);
204 bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
205 const Address &from, const Address &to, NetDevice::PacketType packetType);
206 bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
207 const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
209 void Construct (void);
211 struct ProtocolHandlerEntry {
212 ProtocolHandler handler;
213 Ptr<NetDevice> device;
217 typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
218 uint32_t m_id; // Node id for this node
219 uint32_t m_sid; // System id for this node
220 std::vector<Ptr<NetDevice> > m_devices;
221 std::vector<Ptr<Application> > m_applications;
222 ProtocolHandlerList m_handlers;
224 Ptr <NscGlue> m_nscGlue;