PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/network/model/socket.h

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