PageRenderTime 59ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/src/network/model/socket.h

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