src/node/node.h
author Florian Westphal <fw@strlen.de>
Wed Jul 15 18:46:14 2009 +0200 (2009-07-15)
changeset 4685 ae536d9e0d6d
parent 4558 31e9053749bb
permissions -rw-r--r--
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.
mathieu@1175
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
mathieu@1175
     2
/*
mathieu@1175
     3
 * Copyright (c) 2006 Georgia Tech Research Corporation, INRIA
mathieu@1175
     4
 *
mathieu@1175
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@1175
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@1175
     7
 * published by the Free Software Foundation;
mathieu@1175
     8
 *
mathieu@1175
     9
 * This program is distributed in the hope that it will be useful,
mathieu@1175
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@1175
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@1175
    12
 * GNU General Public License for more details.
mathieu@1175
    13
 *
mathieu@1175
    14
 * You should have received a copy of the GNU General Public License
mathieu@1175
    15
 * along with this program; if not, write to the Free Software
mathieu@1175
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@1175
    17
 *
mathieu@1175
    18
 * Authors: George F. Riley<riley@ece.gatech.edu>
mathieu@1175
    19
 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
mathieu@1175
    20
 */
mathieu@1175
    21
#ifndef NODE_H
mathieu@1175
    22
#define NODE_H
mathieu@232
    23
mathieu@232
    24
#include <vector>
mathieu@232
    25
mathieu@710
    26
#include "ns3/object.h"
mathieu@1176
    27
#include "ns3/callback.h"
mathieu@1866
    28
#include "ns3/ptr.h"
gjc@3448
    29
#include "ns3/net-device.h"
tomh@355
    30
fw@4685
    31
struct INetStack;
fw@4685
    32
mathieu@232
    33
namespace ns3 {
mathieu@232
    34
mathieu@585
    35
class Application;
mathieu@1176
    36
class Packet;
mathieu@1186
    37
class Address;
fw@4685
    38
class NscGlue;
mathieu@2182
    39
mathieu@2182
    40
/**
tomh@3183
    41
 * \ingroup node
tomh@3183
    42
 *
mathieu@728
    43
 * \brief A network Node.
mathieu@595
    44
 *
mathieu@595
    45
 * This class holds together:
mathieu@595
    46
 *   - a list of NetDevice objects which represent the network interfaces
mathieu@728
    47
 *     of this node which are connected to other Node instances through
mathieu@595
    48
 *     Channel instances.
mathieu@595
    49
 *   - a list of Application objects which represent the userspace
mathieu@728
    50
 *     traffic generation applications which interact with the Node
mathieu@595
    51
 *     through the Socket API.
mathieu@595
    52
 *   - a node Id: a unique per-node identifier.
mathieu@595
    53
 *   - a system Id: a unique Id used for parallel simulations.
mathieu@595
    54
 *
mathieu@728
    55
 * Every Node created is added to the NodeList automatically.
mathieu@595
    56
 */
mathieu@728
    57
class Node : public Object
mathieu@484
    58
{
mathieu@512
    59
public:
mathieu@2251
    60
  static TypeId GetTypeId (void);
riley@361
    61
mathieu@1186
    62
  /**
mathieu@1186
    63
   * Must be invoked by subclasses only.
mathieu@1186
    64
   */
mathieu@1186
    65
  Node();
mathieu@1186
    66
  /**
mathieu@1186
    67
   * \param systemId a unique integer used for parallel simulations.
mathieu@1186
    68
   *
mathieu@1186
    69
   * Must be invoked by subclasses only.
mathieu@1186
    70
   */
mathieu@1186
    71
  Node(uint32_t systemId);
mathieu@1186
    72
mathieu@728
    73
  virtual ~Node();
mathieu@244
    74
mathieu@595
    75
  /**
mathieu@595
    76
   * \returns the unique id of this node.
mathieu@595
    77
   * 
mathieu@728
    78
   * This unique id happens to be also the index of the Node into
mathieu@595
    79
   * the NodeList. 
mathieu@595
    80
   */
mathieu@244
    81
  uint32_t GetId (void) const;
mathieu@595
    82
mathieu@595
    83
  /**
mathieu@595
    84
   * \returns the system id for parallel simulations associated
mathieu@595
    85
   *          to this node.
mathieu@595
    86
   */
mathieu@244
    87
  uint32_t GetSystemId (void) const;
mathieu@232
    88
mathieu@595
    89
  /**
mathieu@595
    90
   * \param device NetDevice to associate to this node.
mathieu@728
    91
   * \returns the index of the NetDevice into the Node's list of
mathieu@595
    92
   *          NetDevice.
mathieu@595
    93
   *
mathieu@595
    94
   * Associate this device to this node.
mathieu@595
    95
   */
mathieu@568
    96
  uint32_t AddDevice (Ptr<NetDevice> device);
mathieu@595
    97
  /**
mathieu@595
    98
   * \param index the index of the requested NetDevice
mathieu@728
    99
   * \returns the requested NetDevice associated to this Node.
mathieu@1186
   100
   *
mathieu@1186
   101
   * The indexes used by the GetDevice method start at one and
mathieu@1186
   102
   * end at GetNDevices ()
mathieu@595
   103
   */
mathieu@568
   104
  Ptr<NetDevice> GetDevice (uint32_t index) const;
mathieu@595
   105
  /**
mathieu@595
   106
   * \returns the number of NetDevice instances associated
mathieu@728
   107
   *          to this Node.
mathieu@595
   108
   */
mathieu@447
   109
  uint32_t GetNDevices (void) const;
mathieu@447
   110
mathieu@595
   111
  /**
mathieu@595
   112
   * \param application Application to associate to this node.
mathieu@728
   113
   * \returns the index of the Application within the Node's list
mathieu@595
   114
   *          of Application.
mathieu@595
   115
   *
mathieu@728
   116
   * Associated this Application to this Node. This method is called
mathieu@595
   117
   * automatically from Application::Application so the user
mathieu@595
   118
   * has little reasons to call this method directly.
mathieu@595
   119
   */
mathieu@585
   120
  uint32_t AddApplication (Ptr<Application> application);
mathieu@595
   121
  /**
mathieu@595
   122
   * \param index
mathieu@595
   123
   * \returns the application associated to this requested index
mathieu@728
   124
   *          within this Node.
mathieu@595
   125
   */
mathieu@585
   126
  Ptr<Application> GetApplication (uint32_t index) const;
tjkopena@3380
   127
tjkopena@3380
   128
  /**
mathieu@728
   129
   * \returns the number of applications associated to this Node.
mathieu@595
   130
   */
mathieu@585
   131
  uint32_t GetNApplications (void) const;
mathieu@585
   132
mathieu@1176
   133
  /**
mathieu@1176
   134
   * A protocol handler
gjc@3460
   135
   *
gjc@3460
   136
   * \param device a pointer to the net device which received the packet
gjc@3460
   137
   * \param packet the packet received
gjc@3460
   138
   * \param protocol the 16 bit protocol number associated with this packet.
gjc@3460
   139
   *        This protocol number is expected to be the same protocol number
gjc@3460
   140
   *        given to the Send method by the user on the sender side.
gjc@3460
   141
   * \param sender the address of the sender
gjc@3460
   142
   * \param receiver the address of the receiver; Note: this value is
gjc@3460
   143
   *                 only valid for promiscuous mode protocol
gjc@3460
   144
   *                 handlers.
gjc@3460
   145
   * \param packetType type of packet received
gjc@3460
   146
   *                   (broadcast/multicast/unicast/otherhost); Note:
gjc@3460
   147
   *                   this value is only valid for promiscuous mode
gjc@3460
   148
   *                   protocol handlers.
mathieu@1176
   149
   */
mathieu@3548
   150
  typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
gjc@3448
   151
                   const Address &, NetDevice::PacketType> ProtocolHandler;
mathieu@1176
   152
  /**
mathieu@1176
   153
   * \param handler the handler to register
mathieu@1176
   154
   * \param protocolType the type of protocol this handler is 
mathieu@1186
   155
   *        interested in. This protocol type is a so-called
mathieu@1186
   156
   *        EtherType, as registered here:
mathieu@1186
   157
   *        http://standards.ieee.org/regauth/ethertype/eth.txt
mathieu@1186
   158
   *        the value zero is interpreted as matching all
mathieu@1186
   159
   *        protocols.
mathieu@1176
   160
   * \param device the device attached to this handler. If the
mathieu@1176
   161
   *        value is zero, the handler is attached to all
mathieu@1176
   162
   *        devices on this node.
gjc@3460
   163
   * \param promiscuous whether to register a promiscuous mode handler
mathieu@1176
   164
   */
mathieu@1176
   165
  void RegisterProtocolHandler (ProtocolHandler handler, 
mathieu@1176
   166
                                uint16_t protocolType,
gjc@3460
   167
                                Ptr<NetDevice> device,
gjc@3460
   168
                                bool promiscuous=false);
mathieu@1176
   169
  /**
mathieu@1176
   170
   * \param handler the handler to unregister
mathieu@1176
   171
   *
mathieu@1176
   172
   * After this call returns, the input handler will never
mathieu@1176
   173
   * be invoked anymore.
mathieu@1176
   174
   */
mathieu@1176
   175
  void UnregisterProtocolHandler (ProtocolHandler handler);
mathieu@1176
   176
fw@4685
   177
  void SetNscLibrary (const std::string &soname);
fw@4685
   178
  std::string GetNscLibrary (void) const;
fw@4685
   179
  INetStack* GetNscInetStack(void);
fw@4685
   180
  void RegisterNscWakeupCallback (Callback<void>);
mathieu@4558
   181
  
mathieu@4558
   182
  /**
mathieu@4558
   183
   * \returns true if checksums are enabled, false otherwise.
mathieu@4558
   184
   */
mathieu@4558
   185
  static bool ChecksumEnabled (void);
mathieu@4558
   186
mathieu@513
   187
protected:
mathieu@595
   188
  /**
mathieu@595
   189
   * The dispose method. Subclasses must override this method
mathieu@728
   190
   * and must chain up to it by calling Node::DoDispose at the
mathieu@595
   191
   * end of their own DoDispose method.
mathieu@595
   192
   */
mathieu@513
   193
  virtual void DoDispose (void);
mathieu@447
   194
private:
mathieu@1341
   195
mathieu@595
   196
  /**
mathieu@728
   197
   * \param device the device added to this Node.
mathieu@595
   198
   *
mathieu@728
   199
   * This method is invoked whenever a user calls Node::AddDevice.
mathieu@595
   200
   */
mathieu@1176
   201
  virtual void NotifyDeviceAdded (Ptr<NetDevice> device);
mathieu@447
   202
mathieu@3548
   203
  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from);
mathieu@3548
   204
  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
gjc@3460
   205
                                 const Address &from, const Address &to, NetDevice::PacketType packetType);
mathieu@3548
   206
  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
gjc@3460
   207
                          const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
gjc@3460
   208
mathieu@1186
   209
  void Construct (void);
mathieu@1176
   210
mathieu@1176
   211
  struct ProtocolHandlerEntry {
mathieu@1176
   212
    ProtocolHandler handler;
gjc@3460
   213
    Ptr<NetDevice> device;
mathieu@1176
   214
    uint16_t protocol;
gjc@3460
   215
    bool promiscuous;
mathieu@1176
   216
  };
mathieu@1176
   217
  typedef std::vector<struct Node::ProtocolHandlerEntry> ProtocolHandlerList;
mathieu@728
   218
  uint32_t    m_id;         // Node id for this node
mathieu@244
   219
  uint32_t    m_sid;        // System id for this node
mathieu@568
   220
  std::vector<Ptr<NetDevice> > m_devices;
mathieu@585
   221
  std::vector<Ptr<Application> > m_applications;
mathieu@1176
   222
  ProtocolHandlerList m_handlers;
gjc@3435
   223
fw@4685
   224
  Ptr <NscGlue> m_nscGlue;
fw@4685
   225
  bool m_useNsc;
mathieu@232
   226
};
mathieu@232
   227
tomh@355
   228
} //namespace ns3
mathieu@605
   229
mathieu@1175
   230
#endif /* NODE_H */