PageRenderTime 36ms CodeModel.GetById 17ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/ns-allinone-3.14.1/ns-3.14.1/src/network/model/socket.h

https://bitbucket.org/hbhzwj/imalse
C++ Header | 709 lines | 161 code | 53 blank | 495 comment | 0 complexity | 146e3986853be16ce887e7109f03ae23 MD5 | raw file
  1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
  2/*
  3 * Copyright (c) 2006 Georgia Tech Research Corporation
  4 *               2007 INRIA
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License version 2 as
  8 * published by the Free Software Foundation;
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, write to the Free Software
 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18 *
 19 * Authors: George F. Riley<riley@ece.gatech.edu>
 20 *          Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
 21 */
 22
 23#ifndef NS3_SOCKET_H
 24#define NS3_SOCKET_H
 25
 26#include "ns3/callback.h"
 27#include "ns3/ptr.h"
 28#include "ns3/tag.h"
 29#include "ns3/object.h"
 30#include "ns3/net-device.h"
 31#include "address.h"
 32#include <stdint.h>
 33
 34namespace ns3 {
 35
 36
 37class Node;
 38class Packet;
 39
 40/**
 41 * \ingroup network
 42 * \defgroup socket Socket
 43 */
 44
 45/**
 46 * \brief A low-level Socket API based loosely on the BSD Socket API.
 47 * \ingroup socket
 48 *
 49 * A few things to keep in mind about this type of socket:
 50 * - it uses ns-3 API constructs such as class ns3::Address instead of
 51 *   C-style structs
 52 * - in contrast to the original BSD socket API, this API is asynchronous:
 53 *   it does not contain blocking calls.  Sending and receiving operations
 54 *   must make use of the callbacks provided. 
 55 * - It also uses class ns3::Packet as a fancy byte buffer, allowing 
 56 *   data to be passed across the API using an ns-3 Packet instead of 
 57 *   a raw data pointer.
 58 * - Not all of the full POSIX sockets API is supported
 59 *
 60 * Other than that, it tries to stick to the BSD API to make it 
 61 * easier for those who know the BSD API to use this API.
 62 * More details are provided in the ns-3 tutorial.
 63 */
 64class Socket : public Object
 65{
 66public:
 67  static TypeId GetTypeId (void);
 68
 69  Socket (void);
 70  virtual ~Socket (void);
 71
 72  enum SocketErrno {
 73    ERROR_NOTERROR,
 74    ERROR_ISCONN,
 75    ERROR_NOTCONN,
 76    ERROR_MSGSIZE,
 77    ERROR_AGAIN,
 78    ERROR_SHUTDOWN,
 79    ERROR_OPNOTSUPP,
 80    ERROR_AFNOSUPPORT,
 81    ERROR_INVAL,
 82    ERROR_BADF,
 83    ERROR_NOROUTETOHOST,
 84    ERROR_NODEV,
 85    ERROR_ADDRNOTAVAIL,
 86    ERROR_ADDRINUSE,
 87    SOCKET_ERRNO_LAST
 88  };
 89
 90  enum SocketType {
 91    NS3_SOCK_STREAM,
 92    NS3_SOCK_SEQPACKET,
 93    NS3_SOCK_DGRAM,
 94    NS3_SOCK_RAW
 95  };
 96
 97  /**
 98   * This method wraps the creation of sockets that is performed
 99   * on a given node by a SocketFactory specified by TypeId.
100   * 
101   * \return A smart pointer to a newly created socket.
102   * 
103   * \param node The node on which to create the socket
104   * \param tid The TypeId of a SocketFactory class to use
105   */
106  static Ptr<Socket> CreateSocket (Ptr<Node> node, TypeId tid);
107  /**
108   * \return the errno associated to the last call which failed in this
109   *         socket. Each socket's errno is initialized to zero
110   *         when the socket is created.
111   */
112  virtual enum Socket::SocketErrno GetErrno (void) const = 0;
113  /**
114    * \return the socket type, analogous to getsockopt (SO_TYPE)
115    */
116  virtual enum Socket::SocketType GetSocketType (void) const = 0;
117  /**
118   * \returns the node this socket is associated with.
119   */
120  virtual Ptr<Node> GetNode (void) const = 0;
121  /**
122   * \brief Specify callbacks to allow the caller to determine if
123   * the connection succeeds of fails.
124   * \param connectionSucceeded this callback is invoked when the 
125   *        connection request initiated by the user is successfully 
126   *        completed. The callback is passed  back a pointer to 
127   *        the same socket object.
128   * \param connectionFailed this callback is invoked when the 
129   *        connection request initiated by the user is unsuccessfully 
130   *        completed. The callback is passed back a pointer to the 
131   *        same socket object. 
132   */
133  void SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
134                           Callback<void,  Ptr<Socket> > connectionFailed);
135  /**
136   * \brief Detect socket recv() events such as graceful shutdown or error.
137   *
138   * For connection-oriented sockets, the first callback is used to signal
139   * that the remote side has gracefully shut down the connection, and the
140   * second callback denotes an error corresponding to cases in which
141   * a traditional recv() socket call might return -1 (error), such
142   * as a connection reset.  For datagram sockets, these callbacks may
143   * never be invoked.
144   *
145   * \param normalClose this callback is invoked when the
146   *        peer closes the connection gracefully
147   * \param errorClose this callback is invoked when the
148   *        connection closes abnormally
149   */
150  void SetCloseCallbacks (Callback<void, Ptr<Socket> > normalClose,
151                          Callback<void, Ptr<Socket> > errorClose);
152  /**
153   * \brief Accept connection requests from remote hosts
154   * \param connectionRequest Callback for connection request from peer. 
155   *        This user callback is passed a pointer to this socket, the 
156   *        ip address and the port number of the connection originator. 
157   *        This callback must return true to accept the incoming connection,
158   *        false otherwise. If the connection is accepted, the 
159   *        "newConnectionCreated" callback will be invoked later to 
160   *        give access to the user to the socket created to match 
161   *        this new connection. If the user does not explicitly 
162   *        specify this callback, all incoming  connections will be refused.
163   * \param newConnectionCreated Callback for new connection: when a new
164   *        is accepted, it is created and the corresponding socket is passed
165   *        back to the user through this callback. This user callback is 
166   *        passed a pointer to the new socket, and the ip address and 
167   *        port number of the connection originator.
168   */
169  void SetAcceptCallback (Callback<bool, Ptr<Socket>, 
170                                   const Address &> connectionRequest,
171                          Callback<void, Ptr<Socket>, 
172                                   const Address&> newConnectionCreated);
173  /**
174   * \brief Notify application when a packet has been sent from transport 
175   *        protocol (non-standard socket call)
176   * \param dataSent Callback for the event that data is sent from the
177   *        underlying transport protocol.  This callback is passed a
178   *        pointer to the socket, and the number of bytes sent.
179   */
180  void SetDataSentCallback (Callback<void, Ptr<Socket>, 
181                                     uint32_t> dataSent);
182  /**
183   * \brief Notify application when space in transmit buffer is added
184   *
185   *        This callback is intended to notify a 
186   *        socket that would have been blocked in a blocking socket model
187   *        that space is available in the transmit buffer and that it
188   *        can call Send() again.
189   *
190   * \param sendCb Callback for the event that the socket transmit buffer
191   *        fill level has decreased.  This callback is passed a pointer to
192   *        the socket, and the number of bytes available for writing
193   *        into the buffer (an absolute value).  If there is no transmit
194   *        buffer limit, a maximum-sized integer is always returned.
195   */
196  void SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> sendCb);
197  /**
198   * \brief Notify application when new data is available to be read.
199   *
200   *        This callback is intended to notify a socket that would
201   *        have been blocked in a blocking socket model that data
202   *        is available to be read.
203   */
204  void SetRecvCallback (Callback<void, Ptr<Socket> >);
205  /** 
206   * \brief Allocate a local endpoint for this socket.
207   * \param address the address to try to allocate
208   * \returns 0 on success, -1 on failure.
209   */
210  virtual int Bind (const Address &address) = 0;
211
212  /** 
213   * \brief Allocate a local IPv4 endpoint for this socket.
214   *
215   * \returns 0 on success, -1 on failure.
216   */
217  virtual int Bind () = 0;
218
219  /** 
220   * \brief Allocate a local IPv6 endpoint for this socket.
221   *
222   * \returns 0 on success, -1 on failure.
223   */
224  virtual int Bind6 () = 0;
225
226  /**
227   * \brief Close a socket.
228   * \returns zero on success, -1 on failure.
229   *
230   * After the Close call, the socket is no longer valid, and cannot
231   * safely be used for subsequent operations.
232   */
233  virtual int Close (void) = 0;
234
235  /**
236   * \returns zero on success, -1 on failure.
237   *
238   * Do not allow any further Send calls. This method is typically
239   * implemented for Tcp sockets by a half close.
240   */
241  virtual int ShutdownSend (void) = 0;
242
243  /**
244   * \returns zero on success, -1 on failure.
245   *
246   * Do not allow any further Recv calls. This method is typically
247   * implemented for Tcp sockets by a half close.
248   */
249  virtual int ShutdownRecv (void) = 0;
250
251  /**
252   * \brief Initiate a connection to a remote host
253   * \param address Address of remote.
254   */
255  virtual int Connect (const Address &address) = 0;
256
257  /**
258   * \brief Listen for incoming connections.
259   * \returns 0 on success, -1 on error (in which case errno is set).
260   */
261  virtual int Listen (void) = 0;
262
263  /**
264   * \brief Returns the number of bytes which can be sent in a single call
265   * to Send. 
266   * 
267   * For datagram sockets, this returns the number of bytes that
268   * can be passed atomically through the underlying protocol.
269   *
270   * For stream sockets, this returns the available space in bytes
271   * left in the transmit buffer.
272   */
273  virtual uint32_t GetTxAvailable (void) const = 0;
274 
275  /**
276   * \brief Send data (or dummy data) to the remote host
277   *
278   * This function matches closely in semantics to the send() function
279   * call in the standard C library (libc):
280   *   ssize_t send (int s, const void *msg, size_t len, int flags);
281   * except that the send I/O is asynchronous.  This is the
282   * primary Send method at this low-level API and must be implemented 
283   * by subclasses.
284   * 
285   * In a typical blocking sockets model, this call would block upon
286   * lack of space to hold the message to be sent.  In ns-3 at this
287   * API, the call returns immediately in such a case, but the callback
288   * registered with SetSendCallback() is invoked when the socket
289   * has space (when it conceptually unblocks); this is an asynchronous
290   * I/O model for send().
291   * 
292   * This variant of Send() uses class ns3::Packet to encapsulate
293   * data, rather than providing a raw pointer and length field.
294   * This allows an ns-3 application to attach tags if desired (such
295   * as a flow ID) and may allow the simulator to avoid some data
296   * copies.  Despite the appearance of sending Packets on a stream
297   * socket, just think of it as a fancy byte buffer with streaming
298   * semantics.
299   *
300   * If either the message buffer within the Packet is too long to pass 
301   * atomically through the underlying protocol (for datagram sockets), 
302   * or the message buffer cannot entirely fit in the transmit buffer
303   * (for stream sockets), -1 is returned and SocketErrno is set 
304   * to ERROR_MSGSIZE.  If the packet does not fit, the caller can
305   * split the Packet (based on information obtained from 
306   * GetTxAvailable) and reattempt to send the data.
307   *
308   * The flags argument is formed by or'ing one or more of the values:
309   *        MSG_OOB        process out-of-band data 
310   *        MSG_DONTROUTE  bypass routing, use direct interface 
311   * These flags are _unsupported_ as of ns-3.1.
312   *
313   * \param p ns3::Packet to send
314   * \param flags Socket control flags
315   * \returns the number of bytes accepted for transmission if no error
316   *          occurs, and -1 otherwise.
317   *
318   * \see SetSendCallback
319   */
320  virtual int Send (Ptr<Packet> p, uint32_t flags) = 0;
321
322  /**
323   * \brief Send data to a specified peer.
324   *
325   * This method has similar semantics to Send () but subclasses may
326   * want to provide checks on socket state, so the implementation is
327   * pushed to subclasses.
328   *
329   * \param p packet to send
330   * \param flags Socket control flags
331   * \param toAddress IP Address of remote host
332   * \returns -1 in case of error or the number of bytes copied in the 
333   *          internal buffer and accepted for transmission.
334   */
335  virtual int SendTo (Ptr<Packet> p, uint32_t flags, 
336                      const Address &toAddress) = 0;
337
338  /**
339   * Return number of bytes which can be returned from one or 
340   * multiple calls to Recv.
341   * Must be possible to call this method from the Recv callback.
342   */
343  virtual uint32_t GetRxAvailable (void) const = 0;
344
345  /**
346   * \brief Read data from the socket
347   *
348   * This function matches closely in semantics to the recv() function
349   * call in the standard C library (libc):
350   *   ssize_t recv (int s, void *buf, size_t len, int flags);
351   * except that the receive I/O is asynchronous.  This is the
352   * primary Recv method at this low-level API and must be implemented 
353   * by subclasses.
354   * 
355   * This method is normally used only on a connected socket.
356   * In a typical blocking sockets model, this call would block until
357   * at least one byte is returned or the connection closes.
358   * In ns-3 at this API, the call returns immediately in such a case
359   * and returns 0 if nothing is available to be read.
360   * However, an application can set a callback, ns3::SetRecvCallback,
361   * to be notified of data being available to be read
362   * (when it conceptually unblocks); this is an asynchronous
363   * I/O model for recv().
364   * 
365   * This variant of Recv() uses class ns3::Packet to encapsulate
366   * data, rather than providing a raw pointer and length field.
367   * This allows an ns-3 application to attach tags if desired (such
368   * as a flow ID) and may allow the simulator to avoid some data
369   * copies.  Despite the appearance of receiving Packets on a stream
370   * socket, just think of it as a fancy byte buffer with streaming
371   * semantics.
372   *
373   * The semantics depend on the type of socket.  For a datagram socket,
374   * each Recv() returns the data from at most one Send(), and order
375   * is not necessarily preserved.  For a stream socket, the bytes
376   * are delivered in order, and on-the-wire packet boundaries are
377   * not preserved.
378   * 
379   * The flags argument is formed by or'ing one or more of the values:
380   *        MSG_OOB             process out-of-band data
381   *        MSG_PEEK            peek at incoming message
382   * None of these flags are supported for now.
383   *
384   * Some variants of Recv() are supported as additional API,
385   * including RecvFrom(), overloaded Recv() without arguments,
386   * and variants that use raw character buffers.
387   *
388   * \param maxSize reader will accept packet up to maxSize
389   * \param flags Socket control flags
390   * \returns Ptr<Packet> of the next in-sequence packet.  Returns
391   * 0 if the socket cannot return a next in-sequence packet conforming
392   * to the maxSize and flags.
393   *
394   * \see SetRecvCallback
395   */
396  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags) = 0;
397
398  /**
399   * \brief Read a single packet from the socket and retrieve the sender 
400   * address.
401   *
402   * Calls Recv(maxSize, flags) with maxSize
403   * implicitly set to maximum sized integer, and flags set to zero.
404   *
405   * This method has similar semantics to Recv () but subclasses may
406   * want to provide checks on socket state, so the implementation is
407   * pushed to subclasses.
408   *
409   * \param maxSize reader will accept packet up to maxSize
410   * \param flags Socket control flags
411   * \param fromAddress output parameter that will return the
412   * address of the sender of the received packet, if any.  Remains
413   * untouched if no packet is received.
414   * \returns Ptr<Packet> of the next in-sequence packet.  Returns
415   * 0 if the socket cannot return a next in-sequence packet.
416   */
417  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
418                                Address &fromAddress) = 0;
419
420  /////////////////////////////////////////////////////////////////////
421  //   The remainder of these public methods are overloaded methods  //
422  //   or variants of Send() and Recv(), and they are non-virtual    //
423  /////////////////////////////////////////////////////////////////////
424 
425  /**
426   * \brief Send data (or dummy data) to the remote host
427   * 
428   * Overloaded version of Send(..., flags) with flags set to zero.
429   *
430   * \param p ns3::Packet to send
431   * \returns the number of bytes accepted for transmission if no error
432   *          occurs, and -1 otherwise.
433   */
434  int Send (Ptr<Packet> p);
435
436  /**
437   * \brief Send data (or dummy data) to the remote host
438   * 
439   * This method is provided so as to have an API which is closer in 
440   * appearance to that of real network or BSD sockets.
441   *
442   * \param buf A pointer to a raw byte buffer of some data to send.  If 
443   * this buffer is 0, we send dummy data whose size is specified by the 
444   * second parameter
445   * \param size the number of bytes to copy from the buffer
446   * \param flags Socket control flags
447   */
448  int Send (const uint8_t* buf, uint32_t size, uint32_t flags);
449
450
451  /**
452   * \brief Send data to a specified peer.
453   *
454   * This method is provided so as to have an API which is closer in 
455   * appearance to that of real network or BSD sockets.
456   *
457   * \param buf A pointer to a raw byte buffer of some data to send.
458   * If this is 0, we send dummy data whose size is specified by the 
459   * third parameter
460   * \param size the number of bytes to copy from the buffer
461   * \param flags Socket control flags
462   * \param address IP Address of remote host
463   * \returns -1 in case of error or the number of bytes copied in the 
464   *          internal buffer and accepted for transmission.
465   *
466   */
467  int SendTo (const uint8_t* buf, uint32_t size, uint32_t flags, 
468              const Address &address); 
469
470  /**
471   * \brief Read a single packet from the socket
472   *
473   * Overloaded version of Recv(maxSize, flags) with maxSize
474   * implicitly set to maximum sized integer, and flags set to zero.
475   *
476   * \returns Ptr<Packet> of the next in-sequence packet.  Returns
477   * 0 if the socket cannot return a next in-sequence packet.
478   */
479  Ptr<Packet> Recv (void);
480
481  /**
482   * \brief Recv data (or dummy data) from the remote host
483   *
484   * This method is provided so as to have an API which is closer in 
485   * appearance to that of real network or BSD sockets.
486   * 
487   * If the underlying packet was carring null (fake) data, this buffer
488   * will be zeroed up to the length specified by the return value.
489   *
490   * \param buf A pointer to a raw byte buffer to write the data to. 
491   * \param size Number of bytes (at most) to copy to buf
492   * \param flags any flags to pass to the socket
493   * \returns number of bytes copied into buf
494   */
495  int Recv (uint8_t* buf, uint32_t size, uint32_t flags);
496
497  /**
498   * \brief Read a single packet from the socket and retrieve the sender 
499   * address.
500   *
501   * Calls RecvFrom (maxSize, flags, fromAddress) with maxSize
502   * implicitly set to maximum sized integer, and flags set to zero.
503   *
504   * \param fromAddress output parameter that will return the
505   * address of the sender of the received packet, if any.  Remains
506   * untouched if no packet is received.
507   * \returns Ptr<Packet> of the next in-sequence packet.  Returns
508   * 0 if the socket cannot return a next in-sequence packet.
509   */
510  Ptr<Packet> RecvFrom (Address &fromAddress);
511
512  /**
513   * \brief Read a single packet from the socket and retrieve the sender
514   * address.
515   *
516   * This method is provided so as to have an API which is closer in 
517   * appearance to that of real network or BSD sockets.
518   * 
519   * \param buf A pointer to a raw byte buffer to write the data to. 
520   * If the underlying packet was carring null (fake) data, this buffer
521   * will be zeroed up to the length specified by the return value.
522   * \param size Number of bytes (at most) to copy to buf
523   * \param flags any flags to pass to the socket
524   * \param fromAddress output parameter that will return the
525   * address of the sender of the received packet, if any.  Remains
526   * untouched if no packet is received.
527   * \returns number of bytes copied into buf
528   */
529  int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags,
530                Address &fromAddress);
531  /**
532   * \param address the address name this socket is associated with.
533   * \returns 0 if success, -1 otherwise
534   */
535  virtual int GetSockName (Address &address) const = 0; 
536
537  /**
538   * \brief Bind a socket to specific device.
539   *
540   * This method corresponds to using setsockopt() SO_BINDTODEVICE
541   * of real network or BSD sockets.   If set on a socket, this option will
542   * force packets to leave the bound device regardless of the device that
543   * IP routing would naturally choose.  In the receive direction, only
544   * packets received from the bound interface will be delivered.
545   *
546   * This option has no particular relationship to binding sockets to
547   * an address via Socket::Bind ().  It is possible to bind sockets to a 
548   * specific IP address on the bound interface by calling both 
549   * Socket::Bind (address) and Socket::BindToNetDevice (device), but it
550   * is also possible to bind to mismatching device and address, even if
551   * the socket can not receive any packets as a result.
552   *
553   * \param netdevice Pointer to Netdevice of desired interface
554   * \returns nothing
555   */
556  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
557
558  /**
559   * \brief Returns socket's bound netdevice, if any.
560   *
561   * This method corresponds to using getsockopt() SO_BINDTODEVICE
562   * of real network or BSD sockets.
563   * 
564   * 
565   * \returns Pointer to interface.
566   */
567  Ptr<NetDevice> GetBoundNetDevice (); 
568
569
570  /**
571   * \brief Configure whether broadcast datagram transmissions are allowed
572   *
573   * This method corresponds to using setsockopt() SO_BROADCAST of
574   * real network or BSD sockets.  If set on a socket, this option
575   * will enable or disable packets to be transmitted to broadcast
576   * destination addresses.
577   *
578   * \param allowBroadcast Whether broadcast is allowed
579   * \return true if operation succeeds
580   */
581  virtual bool SetAllowBroadcast (bool allowBroadcast) = 0;
582
583  /**
584   * \brief Query whether broadcast datagram transmissions are allowed
585   *
586   * This method corresponds to using getsockopt() SO_BROADCAST of
587   * real network or BSD sockets.
588   *
589   * \returns true if broadcast is allowed, false otherwise
590   */
591  virtual bool GetAllowBroadcast () const = 0;
592
593  /**
594   * \brief Enable/Disable receive packet information to socket.
595   *
596   * For IP_PKTINFO/IP6_PKTINFO. This method is only usable for 
597   * Raw socket and Datagram Socket. Not supported for Stream socket.
598   *
599   * Method doesn't make distinction between IPv4 and IPv6. If it is enabled,
600   * it is enabled for all types of sockets that supports packet information
601   *
602   * \param flag Enable/Disable receive information
603   * \returns nothing
604   */
605  void SetRecvPktInfo (bool flag);
606
607  /**
608   * \brief Get status indicating whether enable/disable packet information to socket
609   *
610   * \returns True if packet information should be sent to socket
611   */
612  bool IsRecvPktInfo () const;
613 
614protected:
615  void NotifyConnectionSucceeded (void);
616  void NotifyConnectionFailed (void);
617  void NotifyNormalClose (void);
618  void NotifyErrorClose (void);
619  bool NotifyConnectionRequest (const Address &from);
620  void NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from);
621  void NotifyDataSent (uint32_t size);
622  void NotifySend (uint32_t spaceAvailable);
623  void NotifyDataRecv (void);
624  virtual void DoDispose (void);
625  Ptr<NetDevice> m_boundnetdevice;
626  bool m_recvPktInfo;
627private:
628  Callback<void, Ptr<Socket> >                   m_connectionSucceeded;
629  Callback<void, Ptr<Socket> >                   m_connectionFailed;
630  Callback<void, Ptr<Socket> >                   m_normalClose;
631  Callback<void, Ptr<Socket> >                   m_errorClose;
632  Callback<bool, Ptr<Socket>, const Address &>   m_connectionRequest;
633  Callback<void, Ptr<Socket>, const Address&>    m_newConnectionCreated;
634  Callback<void, Ptr<Socket>, uint32_t>          m_dataSent;
635  Callback<void, Ptr<Socket>, uint32_t >         m_sendCb;
636  Callback<void, Ptr<Socket> >                   m_receivedData;
637
638};
639
640/**
641 * \brief This class implements a tag that carries an address
642 * of a packet across the socket interface.
643 */
644class SocketAddressTag : public Tag
645{
646public:
647  SocketAddressTag ();
648  void SetAddress (Address addr);
649  Address GetAddress (void) const;
650
651  static TypeId GetTypeId (void);
652  virtual TypeId GetInstanceTypeId (void) const;
653  virtual uint32_t GetSerializedSize (void) const;
654  virtual void Serialize (TagBuffer i) const;
655  virtual void Deserialize (TagBuffer i);
656  virtual void Print (std::ostream &os) const;
657
658private:
659  Address m_address;
660};
661
662/**
663 * \brief This class implements a tag that carries the socket-specific
664 * TTL of a packet to the IP layer
665 */
666class SocketIpTtlTag : public Tag
667{
668public:
669  SocketIpTtlTag ();
670  void SetTtl (uint8_t ttl);
671  uint8_t GetTtl (void) const;
672
673  static TypeId GetTypeId (void);
674  virtual TypeId GetInstanceTypeId (void) const;
675  virtual uint32_t GetSerializedSize (void) const;
676  virtual void Serialize (TagBuffer i) const;
677  virtual void Deserialize (TagBuffer i);
678  virtual void Print (std::ostream &os) const;
679
680private:
681  uint8_t m_ttl;
682};
683
684
685/**
686 * \brief indicated whether packets should be sent out with
687 * the DF flag set.
688 */
689class SocketSetDontFragmentTag : public Tag
690{
691public:
692  SocketSetDontFragmentTag ();
693  void Enable (void);
694  void Disable (void);
695  bool IsEnabled (void) const;
696
697  static TypeId GetTypeId (void);
698  virtual TypeId GetInstanceTypeId (void) const;
699  virtual uint32_t GetSerializedSize (void) const;
700  virtual void Serialize (TagBuffer i) const;
701  virtual void Deserialize (TagBuffer i);
702  virtual void Print (std::ostream &os) const;
703private:
704  bool m_dontFragment;
705};
706
707} // namespace ns3
708
709#endif /* NS3_SOCKET_H */