1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/node/nsc-glue.h Wed Jul 15 18:46:14 2009 +0200
1.3 @@ -0,0 +1,116 @@
1.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1.5 +/*
1.6 + * Copyright (c) 2008 Florian Westphal
1.7 + *
1.8 + * This program is free software; you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License version 2 as
1.10 + * published by the Free Software Foundation;
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program; if not, write to the Free Software
1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.20 + *
1.21 + * Author: Florian Westphal <fw@strlen.de>
1.22 + */
1.23 +#ifndef NODE_NSC_H
1.24 +#define NODE_NSC_H
1.25 +
1.26 +#include <string>
1.27 +#include <list>
1.28 +
1.29 +#include "ns3/callback.h"
1.30 +#include "ns3/ptr.h"
1.31 +#include "ns3/object.h"
1.32 +#include "ns3/net-device.h"
1.33 +#include "ns3/timer.h"
1.34 +
1.35 +#include "nsc-sysctl.h"
1.36 +
1.37 +#include "sim_interface.h"
1.38 +
1.39 +/*
1.40 + * silly hack to switch betwwen NSC API revisions faster during development.
1.41 + * should be removed before erging with upstream ns3-dev.
1.42 + */
1.43 +#if NSC_VERSION == 0x00500
1.44 +#undef NSC_NEXT
1.45 +#else
1.46 +#define NSC_NEXT 1
1.47 +#endif
1.48 +
1.49 +
1.50 +namespace ns3 {
1.51 +
1.52 +// IInterruptCallback and ISendCallback are NSC interfaces.
1.53 +class NscGlue : public Object, IInterruptCallback, ISendCallback
1.54 +{
1.55 +public:
1.56 + static TypeId GetTypeId (void);
1.57 +
1.58 + NscGlue (void);
1.59 +
1.60 + void SetNode(Ptr<Node> n);
1.61 + void SetNscLibrary(const std::string &soname);
1.62 + std::string GetNscLibrary () const;
1.63 +
1.64 + // returns true if l3 protocol number can be handled by NSC.
1.65 + // currently only returns true for IPv4.
1.66 + bool IsNscProtocol (uint16_t proto);
1.67 +
1.68 + // passes packet on to NSC. NSC will see the packet arriving on
1.69 + // interface ifindex.
1.70 + void PassPacketToNsc (Ptr<const Packet> packet, int ifindex);
1.71 +
1.72 + // used to register the L4 wakeup call:
1.73 + // maybe it should directly be used to register individual
1.74 + // sockets?
1.75 + void RegisterWakeupCallback (Callback<void> cb);
1.76 +
1.77 + // HACK, make this private.
1.78 + // Socket implementations should not use m_nscStack-> methods
1.79 + // directly.
1.80 + INetStack* m_nscStack;
1.81 +private:
1.82 + // IInterruptCallback methods: wakeup and gettime.
1.83 + // wakeup is called by the NSC stack whenever something of interest
1.84 + // has happened, e.g. when data arrives on a socket, a listen socket
1.85 + // has a new connection pending, etc.
1.86 + virtual void wakeup();
1.87 +
1.88 + // This is called by the Linux stack RNG initialization.
1.89 + // Its also used by the cradle code to add a timestamp to
1.90 + // printk/printf/debug output.
1.91 + virtual void gettime(unsigned int *, unsigned int *);
1.92 +
1.93 + // send_callback is invoked by NSCs 'ethernet driver' to re-inject
1.94 + // a packet (i.e. an octet soup consisting of an IP Header, TCP Header
1.95 + // and user payload, if any), into ns-3.
1.96 +#ifdef NSC_NEXT
1.97 + void send_callback(int idx, const void* data, unsigned int datalen);
1.98 +#else
1.99 + void send_callback(const void* data, unsigned int datalen);
1.100 +#endif
1.101 + // internal helper. adds ipv4 addresses.
1.102 + // XXX: rethink. This really doesn't belong here.
1.103 + // NSC should also split up interface creation and address assignment.
1.104 + void AddIface(void);
1.105 +
1.106 + std::list<Callback<void> > m_wakeupCallbacks;
1.107 +
1.108 + void *m_dlopenHandle;
1.109 + Timer m_softTimer;
1.110 + // called by m_softTimer
1.111 + void SoftRtcInterrupt (void);
1.112 +
1.113 + std::string m_nscLibrary;
1.114 + Ptr<Node> m_node; // sigh...
1.115 +};
1.116 +
1.117 +} //namespace ns3
1.118 +
1.119 +#endif /* NODE_NSC_H */