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