src/node/nsc-glue.h
author Florian Westphal <fw@strlen.de>
Wed Jul 15 18:46:14 2009 +0200 (2009-07-15)
changeset 4685 ae536d9e0d6d
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.
fw@4685
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
fw@4685
     2
/*
fw@4685
     3
 * Copyright (c) 2008 Florian Westphal
fw@4685
     4
 *
fw@4685
     5
 * This program is free software; you can redistribute it and/or modify
fw@4685
     6
 * it under the terms of the GNU General Public License version 2 as
fw@4685
     7
 * published by the Free Software Foundation;
fw@4685
     8
 *
fw@4685
     9
 * This program is distributed in the hope that it will be useful,
fw@4685
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fw@4685
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fw@4685
    12
 * GNU General Public License for more details.
fw@4685
    13
 *
fw@4685
    14
 * You should have received a copy of the GNU General Public License
fw@4685
    15
 * along with this program; if not, write to the Free Software
fw@4685
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
fw@4685
    17
 *
fw@4685
    18
 * Author: Florian Westphal <fw@strlen.de>
fw@4685
    19
 */
fw@4685
    20
#ifndef NODE_NSC_H
fw@4685
    21
#define NODE_NSC_H
fw@4685
    22
fw@4685
    23
#include <string>
fw@4685
    24
#include <list>
fw@4685
    25
fw@4685
    26
#include "ns3/callback.h"
fw@4685
    27
#include "ns3/ptr.h"
fw@4685
    28
#include "ns3/object.h"
fw@4685
    29
#include "ns3/net-device.h"
fw@4685
    30
#include "ns3/timer.h"
fw@4685
    31
fw@4685
    32
#include "nsc-sysctl.h"
fw@4685
    33
fw@4685
    34
#include "sim_interface.h"
fw@4685
    35
fw@4685
    36
/*
fw@4685
    37
 * silly hack to switch betwwen NSC API revisions faster during development.
fw@4685
    38
 * should be removed before erging with upstream ns3-dev.
fw@4685
    39
 */
fw@4685
    40
#if NSC_VERSION == 0x00500
fw@4685
    41
#undef NSC_NEXT
fw@4685
    42
#else
fw@4685
    43
#define NSC_NEXT	1
fw@4685
    44
#endif
fw@4685
    45
fw@4685
    46
fw@4685
    47
namespace ns3 {
fw@4685
    48
fw@4685
    49
// IInterruptCallback and ISendCallback are NSC interfaces.
fw@4685
    50
class NscGlue : public Object, IInterruptCallback, ISendCallback
fw@4685
    51
{
fw@4685
    52
public:
fw@4685
    53
  static TypeId GetTypeId (void);
fw@4685
    54
fw@4685
    55
  NscGlue (void);
fw@4685
    56
fw@4685
    57
  void SetNode(Ptr<Node> n);
fw@4685
    58
  void SetNscLibrary(const std::string &soname);
fw@4685
    59
  std::string GetNscLibrary () const;
fw@4685
    60
fw@4685
    61
  // returns true if l3 protocol number can be handled by NSC.
fw@4685
    62
  // currently only returns true for IPv4.
fw@4685
    63
  bool IsNscProtocol (uint16_t proto);
fw@4685
    64
fw@4685
    65
  // passes packet on to NSC. NSC will see the packet arriving on
fw@4685
    66
  // interface ifindex.
fw@4685
    67
  void PassPacketToNsc (Ptr<const Packet> packet, int ifindex);
fw@4685
    68
fw@4685
    69
  // used to register the L4 wakeup call:
fw@4685
    70
  // maybe it should directly be used to register individual
fw@4685
    71
  // sockets?
fw@4685
    72
  void RegisterWakeupCallback (Callback<void> cb);
fw@4685
    73
fw@4685
    74
  // HACK, make this private.
fw@4685
    75
  // Socket implementations should not use m_nscStack-> methods
fw@4685
    76
  // directly.
fw@4685
    77
  INetStack* m_nscStack;
fw@4685
    78
private:
fw@4685
    79
  // IInterruptCallback methods: wakeup and gettime.
fw@4685
    80
  // wakeup is called by the NSC stack whenever something of interest
fw@4685
    81
  // has happened, e.g. when data arrives on a socket, a listen socket
fw@4685
    82
  // has a new connection pending, etc.
fw@4685
    83
  virtual void wakeup();
fw@4685
    84
fw@4685
    85
  // This is called by the Linux stack RNG initialization.
fw@4685
    86
  // Its also used by the cradle code to add a timestamp to
fw@4685
    87
  // printk/printf/debug output.
fw@4685
    88
  virtual void gettime(unsigned int *, unsigned int *);
fw@4685
    89
fw@4685
    90
  // send_callback is invoked by NSCs 'ethernet driver' to re-inject
fw@4685
    91
  // a packet (i.e. an octet soup consisting of an IP Header, TCP Header
fw@4685
    92
  // and user payload, if any), into ns-3.
fw@4685
    93
#ifdef NSC_NEXT
fw@4685
    94
  void send_callback(int idx, const void* data, unsigned int datalen);
fw@4685
    95
#else
fw@4685
    96
  void send_callback(const void* data, unsigned int datalen);
fw@4685
    97
#endif
fw@4685
    98
  // internal helper. adds ipv4 addresses.
fw@4685
    99
  // XXX: rethink. This really doesn't belong here.
fw@4685
   100
  // NSC should also split up interface creation and address assignment.
fw@4685
   101
  void AddIface(void);
fw@4685
   102
fw@4685
   103
  std::list<Callback<void> > m_wakeupCallbacks;
fw@4685
   104
fw@4685
   105
  void *m_dlopenHandle;
fw@4685
   106
  Timer m_softTimer;
fw@4685
   107
  // called by m_softTimer
fw@4685
   108
  void SoftRtcInterrupt (void);
fw@4685
   109
fw@4685
   110
  std::string m_nscLibrary;
fw@4685
   111
  Ptr<Node> m_node; // sigh...
fw@4685
   112
};
fw@4685
   113
fw@4685
   114
} //namespace ns3
fw@4685
   115
fw@4685
   116
#endif /* NODE_NSC_H */