src/internet-stack/nsc-tcp-socket-impl.h
author Florian Westphal <fw@strlen.de>
Wed Jul 15 18:46:14 2009 +0200 (2009-07-15)
changeset 4685 ae536d9e0d6d
parent 3778 78c4c41557f3
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  * This program is free software; you can redistribute it and/or modify
     4  * it under the terms of the GNU General Public License version 2 as
     5  * published by the Free Software Foundation;
     6  *
     7  * This program is distributed in the hope that it will be useful,
     8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    10  * GNU General Public License for more details.
    11  *
    12  * You should have received a copy of the GNU General Public License
    13  * along with this program; if not, write to the Free Software
    14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    15  */
    16 #ifndef NSC_TCP_SOCKET_IMPL_H
    17 #define NSC_TCP_SOCKET_IMPL_H
    18 
    19 #include <stdint.h>
    20 #include <queue>
    21 #include <vector>
    22 
    23 #include "ns3/callback.h"
    24 #include "ns3/traced-value.h"
    25 #include "ns3/tcp-socket.h"
    26 #include "ns3/ptr.h"
    27 #include "ns3/ipv4-address.h"
    28 #include "ns3/inet-socket-address.h"
    29 #include "ns3/event-id.h"
    30 #include "tcp-typedefs.h"
    31 #include "pending-data.h"
    32 #include "sequence-number.h"
    33 #include "rtt-estimator.h"
    34 
    35 class INetStreamSocket;
    36 namespace ns3 {
    37 
    38 class Ipv4EndPoint;
    39 class Node;
    40 class Packet;
    41 class NscTcpL4Protocol;
    42 class TcpHeader;
    43 
    44 /**
    45  * \ingroup socket
    46  * \ingroup nsctcp
    47  *
    48  * \brief Socket logic for the NSC TCP sockets.  
    49  * 
    50  * Most of the TCP internal
    51  * logic is handled by the NSC tcp library itself; this class maps ns3::Socket
    52  * calls to the NSC TCP library.
    53  */
    54 class NscTcpSocketImpl : public TcpSocket
    55 {
    56 public:
    57   static TypeId GetTypeId (void);
    58   /**
    59    * Create an unbound tcp socket.
    60    */
    61   NscTcpSocketImpl ();
    62   NscTcpSocketImpl (const NscTcpSocketImpl& sock);
    63   virtual ~NscTcpSocketImpl ();
    64 
    65   void SetNode (Ptr<Node> node);
    66   void SetTcp (Ptr<NscTcpL4Protocol> tcp);
    67   void SetRtt (Ptr<RttEstimator> rtt);
    68 
    69   virtual enum SocketErrno GetErrno (void) const;
    70   virtual Ptr<Node> GetNode (void) const;
    71   virtual int Bind (void);
    72   virtual int Bind (const Address &address);
    73   virtual int Close (void);
    74   virtual int ShutdownSend (void);
    75   virtual int ShutdownRecv (void);
    76   virtual int Connect(const Address &address);
    77   virtual int Listen(void);
    78   virtual uint32_t GetTxAvailable (void) const;
    79   virtual int Send (Ptr<Packet> p, uint32_t flags);
    80   virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress);
    81   virtual uint32_t GetRxAvailable (void) const;
    82   virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
    83   virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
    84     Address &fromAddress);
    85   virtual int GetSockName (Address &address) const; 
    86 
    87 private:
    88   void NSCWakeup(void);
    89   friend class Tcp;
    90   // invoked by Tcp class
    91   int FinishBind (void);
    92   void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
    93   void Destroy (void);
    94   //methods for state
    95   bool SendPendingData(void);
    96   bool ReadPendingData(void);
    97   bool Accept(void);
    98   void CompleteFork(void);
    99   void ConnectionSucceeded();
   100 
   101   // Manage data tx/rx
   102   // XXX This should be virtual and overridden
   103   Ptr<NscTcpSocketImpl> Copy ();
   104 
   105   // attribute related
   106   virtual void SetSndBufSize (uint32_t size);
   107   virtual uint32_t GetSndBufSize (void) const;
   108   virtual void SetRcvBufSize (uint32_t size);
   109   virtual uint32_t GetRcvBufSize (void) const;
   110   virtual void SetSegSize (uint32_t size);
   111   virtual uint32_t GetSegSize (void) const;
   112   virtual void SetAdvWin (uint32_t window);
   113   virtual uint32_t GetAdvWin (void) const;
   114   virtual void SetSSThresh (uint32_t threshold);
   115   virtual uint32_t GetSSThresh (void) const;
   116   virtual void SetInitialCwnd (uint32_t cwnd);
   117   virtual uint32_t GetInitialCwnd (void) const;
   118   virtual void SetConnTimeout (Time timeout);
   119   virtual Time GetConnTimeout (void) const;
   120   virtual void SetConnCount (uint32_t count);
   121   virtual uint32_t GetConnCount (void) const;
   122   virtual void SetDelAckTimeout (Time timeout);
   123   virtual Time GetDelAckTimeout (void) const;
   124   virtual void SetDelAckMaxCount (uint32_t count);
   125   virtual uint32_t GetDelAckMaxCount (void) const;
   126 
   127   enum Socket::SocketErrno GetNativeNs3Errno(int err) const;
   128   uint32_t m_delAckMaxCount;
   129   Time m_delAckTimeout;
   130 
   131   Ipv4EndPoint *m_endPoint;
   132   Ptr<Node> m_node;
   133   Ptr<NscTcpL4Protocol> m_tcp;
   134   Ipv4Address m_remoteAddress;
   135   uint16_t m_remotePort;
   136   //these two are so that the socket/endpoint cloning works
   137   Ipv4Address m_localAddress;
   138   uint16_t m_localPort;
   139   InetSocketAddress m_peerAddress;
   140   enum SocketErrno m_errno;
   141   bool m_shutdownSend;
   142   bool m_shutdownRecv;
   143   bool m_connected;
   144   
   145   //manage the state infomation
   146   States_t m_state;
   147   bool m_closeOnEmpty;
   148 
   149   //needed to queue data when in SYN_SENT state
   150   std::queue<Ptr<Packet> > m_txBuffer;
   151   uint32_t m_txBufferSize;
   152 
   153   // Window management
   154   uint32_t                       m_segmentSize;          //SegmentSize
   155   uint32_t                       m_rxWindowSize;
   156   uint32_t                       m_advertisedWindowSize; //Window to advertise
   157   TracedValue<uint32_t>          m_cWnd;                 //Congestion window
   158   uint32_t                       m_ssThresh;             //Slow Start Threshold
   159   uint32_t                       m_initialCWnd;          //Initial cWnd value
   160 
   161   // Round trip time estimation
   162   Ptr<RttEstimator> m_rtt;
   163   Time m_lastMeasuredRtt;
   164 
   165   // Timer-related members
   166   Time              m_cnTimeout; 
   167   uint32_t          m_cnCount;
   168 
   169   // Temporary queue for delivering data to application
   170   std::queue<Ptr<Packet> > m_deliveryQueue;
   171   uint32_t m_rxAvailable;
   172   INetStreamSocket* m_nscTcpSocket;
   173 
   174   // Attributes
   175   uint32_t m_sndBufSize;   // buffer limit for the outgoing queue
   176   uint32_t m_rcvBufSize;   // maximum receive socket buffer size
   177 };
   178 
   179 }//namespace ns3
   180 
   181 #endif /* NSC_TCP_SOCKET_IMPL_H */