PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/node/socket.h

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