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