src/internet-stack/udp-socket-impl.h
changeset 3260 8c0ab08144e6
parent 3213 08a0424399fb
child 3266 1ae7df5cf87b
equal deleted inserted replaced
3259:43b3f8ecd86d 3260:8c0ab08144e6
       
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2007 INRIA
       
     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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
       
    19  */
       
    20 #ifndef UDP_SOCKET_IMPL_H
       
    21 #define UDP_SOCKET_IMPL_H
       
    22 
       
    23 #include <stdint.h>
       
    24 #include <queue>
       
    25 #include "ns3/callback.h"
       
    26 #include "ns3/traced-callback.h"
       
    27 #include "ns3/socket.h"
       
    28 #include "ns3/ptr.h"
       
    29 #include "ns3/ipv4-address.h"
       
    30 #include "ns3/udp-socket.h"
       
    31 
       
    32 namespace ns3 {
       
    33 
       
    34 class Ipv4EndPoint;
       
    35 class Node;
       
    36 class Packet;
       
    37 class UdpL4Protocol;
       
    38 
       
    39 class UdpSocketImpl : public UdpSocket
       
    40 {
       
    41 public:
       
    42   static TypeId GetTypeId (void);
       
    43   /**
       
    44    * Create an unbound udp socket.
       
    45    */
       
    46   UdpSocketImpl ();
       
    47   virtual ~UdpSocketImpl ();
       
    48 
       
    49   void SetNode (Ptr<Node> node);
       
    50   void SetUdp (Ptr<UdpL4Protocol> udp);
       
    51 
       
    52   virtual enum SocketErrno GetErrno (void) const;
       
    53   virtual Ptr<Node> GetNode (void) const;
       
    54   virtual int Bind (void);
       
    55   virtual int Bind (const Address &address);
       
    56   virtual int Close (void);
       
    57   virtual int ShutdownSend (void);
       
    58   virtual int ShutdownRecv (void);
       
    59   virtual int Connect(const Address &address);
       
    60   virtual int Listen (uint32_t queueLimit);
       
    61   virtual int Send (Ptr<Packet> p);
       
    62   virtual int SendTo (Ptr<Packet> p, const Address &address);
       
    63   virtual uint32_t GetTxAvailable (void) const;
       
    64 
       
    65   virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
       
    66   virtual uint32_t GetRxAvailable (void) const;
       
    67 
       
    68 private:
       
    69   // Attributes set through UdpSocket base class 
       
    70   virtual void SetRcvBufSize (uint32_t size);
       
    71   virtual uint32_t GetRcvBufSize (void) const;
       
    72   virtual void SetIpTtl (uint32_t ipTtl);
       
    73   virtual uint32_t GetIpTtl (void) const;
       
    74   virtual void SetIpMulticastTtl (uint32_t ipTtl);
       
    75   virtual uint32_t GetIpMulticastTtl (void) const;
       
    76 
       
    77   friend class UdpSocketFactory;
       
    78   // invoked by Udp class
       
    79   int FinishBind (void);
       
    80   void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
       
    81   void Destroy (void);
       
    82   int DoSend (Ptr<Packet> p);
       
    83   int DoSendTo (Ptr<Packet> p, const Address &daddr);
       
    84   int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
       
    85 
       
    86   Ipv4EndPoint *m_endPoint;
       
    87   Ptr<Node> m_node;
       
    88   Ptr<UdpL4Protocol> m_udp;
       
    89   Ipv4Address m_defaultAddress;
       
    90   uint16_t m_defaultPort;
       
    91   Callback<void,Ptr<Socket>,uint32_t,const Address &> m_dummyRxCallback;
       
    92   Callback<void,Ptr<Socket>,uint8_t const*,uint32_t,const Address &> m_rxCallback;
       
    93   TracedCallback<Ptr<const Packet> > m_dropTrace;
       
    94 
       
    95   enum SocketErrno m_errno;
       
    96   bool m_shutdownSend;
       
    97   bool m_shutdownRecv;
       
    98   bool m_connected;
       
    99 
       
   100   std::queue<Ptr<Packet> > m_deliveryQueue;
       
   101   uint32_t m_rxAvailable;
       
   102   
       
   103   // Socket attributes
       
   104   uint32_t m_rcvBufSize;
       
   105   uint32_t m_ipTtl;
       
   106   uint32_t m_ipMulticastTtl;
       
   107 
       
   108 };
       
   109 
       
   110 }//namespace ns3
       
   111 
       
   112 #endif /* UDP_SOCKET_IMPL_H */