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

/src/network/model/socket.h

https://bitbucket.org/nsnam/ns-3-dev
C Header | 1395 lines | 260 code | 144 blank | 991 comment | 0 complexity | 6fe919ccd43df227417576ef0f956d9e 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. #include "ns3/inet-socket-address.h"
  32. #include "ns3/inet6-socket-address.h"
  33. namespace ns3 {
  34. class Node;
  35. class Packet;
  36. /**
  37. * \ingroup network
  38. * \defgroup socket Socket
  39. */
  40. /**
  41. * \brief A low-level Socket API based loosely on the BSD Socket API.
  42. * \ingroup socket
  43. *
  44. * A few things to keep in mind about this type of socket:
  45. * - it uses ns-3 API constructs such as class ns3::Address instead of
  46. * C-style structs
  47. * - in contrast to the original BSD socket API, this API is asynchronous:
  48. * it does not contain blocking calls. Sending and receiving operations
  49. * must make use of the callbacks provided.
  50. * - It also uses class ns3::Packet as a fancy byte buffer, allowing
  51. * data to be passed across the API using an ns-3 Packet instead of
  52. * a raw data pointer.
  53. * - Not all of the full POSIX sockets API is supported
  54. *
  55. * Other than that, it tries to stick to the BSD API to make it
  56. * easier for those who know the BSD API to use this API.
  57. * More details are provided in the ns-3 tutorial.
  58. */
  59. class Socket : public Object
  60. {
  61. public:
  62. /**
  63. * \brief Get the type ID.
  64. * \return the object TypeId
  65. */
  66. static TypeId GetTypeId (void);
  67. Socket (void);
  68. virtual ~Socket (void);
  69. /**
  70. * \enum SocketErrno
  71. * \brief Enumeration of the possible errors returned by a socket.
  72. */
  73. enum SocketErrno {
  74. ERROR_NOTERROR,
  75. ERROR_ISCONN,
  76. ERROR_NOTCONN,
  77. ERROR_MSGSIZE,
  78. ERROR_AGAIN,
  79. ERROR_SHUTDOWN,
  80. ERROR_OPNOTSUPP,
  81. ERROR_AFNOSUPPORT,
  82. ERROR_INVAL,
  83. ERROR_BADF,
  84. ERROR_NOROUTETOHOST,
  85. ERROR_NODEV,
  86. ERROR_ADDRNOTAVAIL,
  87. ERROR_ADDRINUSE,
  88. SOCKET_ERRNO_LAST
  89. };
  90. /**
  91. * \enum SocketType
  92. * \brief Enumeration of the possible socket types.
  93. */
  94. enum SocketType {
  95. NS3_SOCK_STREAM,
  96. NS3_SOCK_SEQPACKET,
  97. NS3_SOCK_DGRAM,
  98. NS3_SOCK_RAW
  99. };
  100. /**
  101. * \enum SocketPriority
  102. * \brief Enumeration of the possible socket priorities.
  103. *
  104. * Names and corresponding values are derived from
  105. * the Linux TC_PRIO_* macros
  106. */
  107. enum SocketPriority {
  108. NS3_PRIO_BESTEFFORT = 0,
  109. NS3_PRIO_FILLER = 1,
  110. NS3_PRIO_BULK = 2,
  111. NS3_PRIO_INTERACTIVE_BULK = 4,
  112. NS3_PRIO_INTERACTIVE = 6,
  113. NS3_PRIO_CONTROL = 7
  114. };
  115. /**
  116. * \enum Ipv6MulticastFilterMode
  117. * \brief Enumeration of the possible filter of a socket.
  118. *
  119. * A socket can have filters on specific sources to include only
  120. * packets incoming from them, or to exclude packets incoming
  121. * from specific sources.
  122. * Moreover, inclusion and exclusion also works as a leave,
  123. * since "joining" a group without allowed sources is equivalent
  124. * to leaving it.
  125. */
  126. enum Ipv6MulticastFilterMode
  127. {
  128. INCLUDE=1,
  129. EXCLUDE
  130. };
  131. /**
  132. * This method wraps the creation of sockets that is performed
  133. * on a given node by a SocketFactory specified by TypeId.
  134. *
  135. * \return A smart pointer to a newly created socket.
  136. *
  137. * \param node The node on which to create the socket
  138. * \param tid The TypeId of a SocketFactory class to use
  139. */
  140. static Ptr<Socket> CreateSocket (Ptr<Node> node, TypeId tid);
  141. /**
  142. * \brief Get last error number.
  143. *
  144. * \return the errno associated to the last call which failed in this
  145. * socket. Each socket's errno is initialized to zero
  146. * when the socket is created.
  147. */
  148. virtual enum Socket::SocketErrno GetErrno (void) const = 0;
  149. /**
  150. * \return the socket type, analogous to getsockopt (SO_TYPE)
  151. */
  152. virtual enum Socket::SocketType GetSocketType (void) const = 0;
  153. /**
  154. * \brief Return the node this socket is associated with.
  155. * \returns the node
  156. */
  157. virtual Ptr<Node> GetNode (void) const = 0;
  158. /**
  159. * \brief Specify callbacks to allow the caller to determine if
  160. * the connection succeeds of fails.
  161. * \param connectionSucceeded this callback is invoked when the
  162. * connection request initiated by the user is successfully
  163. * completed. The callback is passed back a pointer to
  164. * the same socket object.
  165. * \param connectionFailed this callback is invoked when the
  166. * connection request initiated by the user is unsuccessfully
  167. * completed. The callback is passed back a pointer to the
  168. * same socket object.
  169. */
  170. void SetConnectCallback (Callback<void, Ptr<Socket> > connectionSucceeded,
  171. Callback<void, Ptr<Socket> > connectionFailed);
  172. /**
  173. * \brief Detect socket recv() events such as graceful shutdown or error.
  174. *
  175. * For connection-oriented sockets, the first callback is used to signal
  176. * that the remote side has gracefully shut down the connection, and the
  177. * second callback denotes an error corresponding to cases in which
  178. * a traditional recv() socket call might return -1 (error), such
  179. * as a connection reset. For datagram sockets, these callbacks may
  180. * never be invoked.
  181. *
  182. * \param normalClose this callback is invoked when the
  183. * peer closes the connection gracefully
  184. * \param errorClose this callback is invoked when the
  185. * connection closes abnormally
  186. */
  187. void SetCloseCallbacks (Callback<void, Ptr<Socket> > normalClose,
  188. Callback<void, Ptr<Socket> > errorClose);
  189. /**
  190. * \brief Accept connection requests from remote hosts
  191. * \param connectionRequest Callback for connection request from peer.
  192. * This user callback is passed a pointer to this socket, the
  193. * ip address and the port number of the connection originator.
  194. * This callback must return true to accept the incoming connection,
  195. * false otherwise. If the connection is accepted, the
  196. * "newConnectionCreated" callback will be invoked later to
  197. * give access to the user to the socket created to match
  198. * this new connection. If the user does not explicitly
  199. * specify this callback, all incoming connections will be refused.
  200. * \param newConnectionCreated Callback for new connection: when a new
  201. * is accepted, it is created and the corresponding socket is passed
  202. * back to the user through this callback. This user callback is
  203. * passed a pointer to the new socket, and the ip address and
  204. * port number of the connection originator.
  205. */
  206. void SetAcceptCallback (Callback<bool, Ptr<Socket>,
  207. const Address &> connectionRequest,
  208. Callback<void, Ptr<Socket>,
  209. const Address&> newConnectionCreated);
  210. /**
  211. * \brief Notify application when a packet has been sent from transport
  212. * protocol (non-standard socket call)
  213. * \param dataSent Callback for the event that data is sent from the
  214. * underlying transport protocol. This callback is passed a
  215. * pointer to the socket, and the number of bytes sent.
  216. */
  217. void SetDataSentCallback (Callback<void, Ptr<Socket>,
  218. uint32_t> dataSent);
  219. /**
  220. * \brief Notify application when space in transmit buffer is added
  221. *
  222. * This callback is intended to notify a
  223. * socket that would have been blocked in a blocking socket model
  224. * that space is available in the transmit buffer and that it
  225. * can call Send() again.
  226. *
  227. * \param sendCb Callback for the event that the socket transmit buffer
  228. * fill level has decreased. This callback is passed a pointer to
  229. * the socket, and the number of bytes available for writing
  230. * into the buffer (an absolute value). If there is no transmit
  231. * buffer limit, a maximum-sized integer is always returned.
  232. */
  233. void SetSendCallback (Callback<void, Ptr<Socket>, uint32_t> sendCb);
  234. /**
  235. * \brief Notify application when new data is available to be read.
  236. *
  237. * This callback is intended to notify a socket that would
  238. * have been blocked in a blocking socket model that data
  239. * is available to be read.
  240. */
  241. void SetRecvCallback (Callback<void, Ptr<Socket> >);
  242. /**
  243. * \brief Allocate a local endpoint for this socket.
  244. * \param address the address to try to allocate
  245. * \returns 0 on success, -1 on failure.
  246. */
  247. virtual int Bind (const Address &address) = 0;
  248. /**
  249. * \brief Allocate a local IPv4 endpoint for this socket.
  250. *
  251. * \returns 0 on success, -1 on failure.
  252. */
  253. virtual int Bind () = 0;
  254. /**
  255. * \brief Allocate a local IPv6 endpoint for this socket.
  256. *
  257. * \returns 0 on success, -1 on failure.
  258. */
  259. virtual int Bind6 () = 0;
  260. /**
  261. * \brief Close a socket.
  262. * \returns zero on success, -1 on failure.
  263. *
  264. * After the Close call, the socket is no longer valid, and cannot
  265. * safely be used for subsequent operations.
  266. */
  267. virtual int Close (void) = 0;
  268. /**
  269. * \returns zero on success, -1 on failure.
  270. *
  271. * Do not allow any further Send calls. This method is typically
  272. * implemented for Tcp sockets by a half close.
  273. */
  274. virtual int ShutdownSend (void) = 0;
  275. /**
  276. * \returns zero on success, -1 on failure.
  277. *
  278. * Do not allow any further Recv calls. This method is typically
  279. * implemented for Tcp sockets by a half close.
  280. */
  281. virtual int ShutdownRecv (void) = 0;
  282. /**
  283. * \brief Initiate a connection to a remote host
  284. * \param address Address of remote.
  285. * \returns 0 on success, -1 on error (in which case errno is set).
  286. */
  287. virtual int Connect (const Address &address) = 0;
  288. /**
  289. * \brief Listen for incoming connections.
  290. * \returns 0 on success, -1 on error (in which case errno is set).
  291. */
  292. virtual int Listen (void) = 0;
  293. /**
  294. * \brief Returns the number of bytes which can be sent in a single call
  295. * to Send.
  296. *
  297. * For datagram sockets, this returns the number of bytes that
  298. * can be passed atomically through the underlying protocol.
  299. *
  300. * For stream sockets, this returns the available space in bytes
  301. * left in the transmit buffer.
  302. *
  303. * \returns The number of bytes which can be sent in a single Send call.
  304. */
  305. virtual uint32_t GetTxAvailable (void) const = 0;
  306. /**
  307. * \brief Send data (or dummy data) to the remote host
  308. *
  309. * This function matches closely in semantics to the send() function
  310. * call in the standard C library (libc):
  311. * ssize_t send (int s, const void *msg, size_t len, int flags);
  312. * except that the send I/O is asynchronous. This is the
  313. * primary Send method at this low-level API and must be implemented
  314. * by subclasses.
  315. *
  316. * In a typical blocking sockets model, this call would block upon
  317. * lack of space to hold the message to be sent. In ns-3 at this
  318. * API, the call returns immediately in such a case, but the callback
  319. * registered with SetSendCallback() is invoked when the socket
  320. * has space (when it conceptually unblocks); this is an asynchronous
  321. * I/O model for send().
  322. *
  323. * This variant of Send() uses class ns3::Packet to encapsulate
  324. * data, rather than providing a raw pointer and length field.
  325. * This allows an ns-3 application to attach tags if desired (such
  326. * as a flow ID) and may allow the simulator to avoid some data
  327. * copies. Despite the appearance of sending Packets on a stream
  328. * socket, just think of it as a fancy byte buffer with streaming
  329. * semantics.
  330. *
  331. * If either the message buffer within the Packet is too long to pass
  332. * atomically through the underlying protocol (for datagram sockets),
  333. * or the message buffer cannot entirely fit in the transmit buffer
  334. * (for stream sockets), -1 is returned and SocketErrno is set
  335. * to ERROR_MSGSIZE. If the packet does not fit, the caller can
  336. * split the Packet (based on information obtained from
  337. * GetTxAvailable) and reattempt to send the data.
  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_DONTROUTE bypass routing, use direct interface
  342. * These flags are _unsupported_ as of ns-3.1.
  343. *
  344. * \param p ns3::Packet to send
  345. * \param flags Socket control flags
  346. * \returns the number of bytes accepted for transmission if no error
  347. * occurs, and -1 otherwise.
  348. *
  349. * \see SetSendCallback
  350. */
  351. virtual int Send (Ptr<Packet> p, uint32_t flags) = 0;
  352. /**
  353. * \brief Send data to a specified peer.
  354. *
  355. * This method has similar semantics to Send () but subclasses may
  356. * want to provide checks on socket state, so the implementation is
  357. * pushed to subclasses.
  358. *
  359. * \param p packet to send
  360. * \param flags Socket control flags
  361. * \param toAddress IP Address of remote host
  362. * \returns -1 in case of error or the number of bytes copied in the
  363. * internal buffer and accepted for transmission.
  364. */
  365. virtual int SendTo (Ptr<Packet> p, uint32_t flags,
  366. const Address &toAddress) = 0;
  367. /**
  368. * Return number of bytes which can be returned from one or
  369. * multiple calls to Recv.
  370. * Must be possible to call this method from the Recv callback.
  371. *
  372. * \returns the number of bytes which can be returned from one or
  373. * multiple Recv calls.
  374. */
  375. virtual uint32_t GetRxAvailable (void) const = 0;
  376. /**
  377. * \brief Read data from the socket
  378. *
  379. * This function matches closely in semantics to the recv() function
  380. * call in the standard C library (libc):
  381. * ssize_t recv (int s, void *buf, size_t len, int flags);
  382. * except that the receive I/O is asynchronous. This is the
  383. * primary Recv method at this low-level API and must be implemented
  384. * by subclasses.
  385. *
  386. * This method is normally used only on a connected socket.
  387. * In a typical blocking sockets model, this call would block until
  388. * at least one byte is returned or the connection closes.
  389. * In ns-3 at this API, the call returns immediately in such a case
  390. * and returns 0 if nothing is available to be read.
  391. * However, an application can set a callback, ns3::SetRecvCallback,
  392. * to be notified of data being available to be read
  393. * (when it conceptually unblocks); this is an asynchronous
  394. * I/O model for recv().
  395. *
  396. * This variant of Recv() uses class ns3::Packet to encapsulate
  397. * data, rather than providing a raw pointer and length field.
  398. * This allows an ns-3 application to attach tags if desired (such
  399. * as a flow ID) and may allow the simulator to avoid some data
  400. * copies. Despite the appearance of receiving Packets on a stream
  401. * socket, just think of it as a fancy byte buffer with streaming
  402. * semantics.
  403. *
  404. * The semantics depend on the type of socket. For a datagram socket,
  405. * each Recv() returns the data from at most one Send(), and order
  406. * is not necessarily preserved. For a stream socket, the bytes
  407. * are delivered in order, and on-the-wire packet boundaries are
  408. * not preserved.
  409. *
  410. * The flags argument is formed by or'ing one or more of the values:
  411. * MSG_OOB process out-of-band data
  412. * MSG_PEEK peek at incoming message
  413. * None of these flags are supported for now.
  414. *
  415. * Some variants of Recv() are supported as additional API,
  416. * including RecvFrom(), overloaded Recv() without arguments,
  417. * and variants that use raw character buffers.
  418. *
  419. * \param maxSize reader will accept packet up to maxSize
  420. * \param flags Socket control flags
  421. * \returns Ptr<Packet> of the next in-sequence packet. Returns
  422. * 0 if the socket cannot return a next in-sequence packet conforming
  423. * to the maxSize and flags.
  424. *
  425. * \see SetRecvCallback
  426. */
  427. virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags) = 0;
  428. /**
  429. * \brief Read a single packet from the socket and retrieve the sender
  430. * address.
  431. *
  432. * Calls Recv(maxSize, flags) with maxSize
  433. * implicitly set to maximum sized integer, and flags set to zero.
  434. *
  435. * This method has similar semantics to Recv () but subclasses may
  436. * want to provide checks on socket state, so the implementation is
  437. * pushed to subclasses.
  438. *
  439. * \param maxSize reader will accept packet up to maxSize
  440. * \param flags Socket control flags
  441. * \param fromAddress output parameter that will return the
  442. * address of the sender of the received packet, if any. Remains
  443. * untouched if no packet is received.
  444. * \returns Ptr<Packet> of the next in-sequence packet. Returns
  445. * 0 if the socket cannot return a next in-sequence packet.
  446. */
  447. virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
  448. Address &fromAddress) = 0;
  449. /////////////////////////////////////////////////////////////////////
  450. // The remainder of these public methods are overloaded methods //
  451. // or variants of Send() and Recv(), and they are non-virtual //
  452. /////////////////////////////////////////////////////////////////////
  453. /**
  454. * \brief Send data (or dummy data) to the remote host
  455. *
  456. * Overloaded version of Send(..., flags) with flags set to zero.
  457. *
  458. * \param p ns3::Packet to send
  459. * \returns the number of bytes accepted for transmission if no error
  460. * occurs, and -1 otherwise.
  461. */
  462. int Send (Ptr<Packet> p);
  463. /**
  464. * \brief Send data (or dummy data) to the remote host
  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 of some data to send. If
  470. * this buffer is 0, we send dummy data whose size is specified by the
  471. * second parameter
  472. * \param size the number of bytes to copy from the buffer
  473. * \param flags Socket control flags
  474. * \returns the number of bytes accepted for transmission if no error
  475. * occurs, and -1 otherwise.
  476. */
  477. int Send (const uint8_t* buf, uint32_t size, uint32_t flags);
  478. /**
  479. * \brief Send data to a specified peer.
  480. *
  481. * This method is provided so as to have an API which is closer in
  482. * appearance to that of real network or BSD sockets.
  483. *
  484. * \param buf A pointer to a raw byte buffer of some data to send.
  485. * If this is 0, we send dummy data whose size is specified by the
  486. * third parameter
  487. * \param size the number of bytes to copy from the buffer
  488. * \param flags Socket control flags
  489. * \param address IP Address of remote host
  490. * \returns -1 in case of error or the number of bytes copied in the
  491. * internal buffer and accepted for transmission.
  492. *
  493. */
  494. int SendTo (const uint8_t* buf, uint32_t size, uint32_t flags,
  495. const Address &address);
  496. /**
  497. * \brief Read a single packet from the socket
  498. *
  499. * Overloaded version of Recv(maxSize, flags) with maxSize
  500. * implicitly set to maximum sized integer, and flags set to zero.
  501. *
  502. * \returns Ptr<Packet> of the next in-sequence packet. Returns
  503. * 0 if the socket cannot return a next in-sequence packet.
  504. */
  505. Ptr<Packet> Recv (void);
  506. /**
  507. * \brief Recv data (or dummy data) from the remote host
  508. *
  509. * This method is provided so as to have an API which is closer in
  510. * appearance to that of real network or BSD sockets.
  511. *
  512. * If the underlying packet was carring null (fake) data, this buffer
  513. * will be zeroed up to the length specified by the return value.
  514. *
  515. * \param buf A pointer to a raw byte buffer to write the data to.
  516. * \param size Number of bytes (at most) to copy to buf
  517. * \param flags any flags to pass to the socket
  518. * \returns number of bytes copied into buf
  519. */
  520. int Recv (uint8_t* buf, uint32_t size, uint32_t flags);
  521. /**
  522. * \brief Read a single packet from the socket and retrieve the sender
  523. * address.
  524. *
  525. * Calls RecvFrom (maxSize, flags, fromAddress) with maxSize
  526. * implicitly set to maximum sized integer, and flags set to zero.
  527. *
  528. * \param fromAddress output parameter that will return the
  529. * address of the sender of the received packet, if any. Remains
  530. * untouched if no packet is received.
  531. * \returns Ptr<Packet> of the next in-sequence packet. Returns
  532. * 0 if the socket cannot return a next in-sequence packet.
  533. */
  534. Ptr<Packet> RecvFrom (Address &fromAddress);
  535. /**
  536. * \brief Read a single packet from the socket and retrieve the sender
  537. * address.
  538. *
  539. * This method is provided so as to have an API which is closer in
  540. * appearance to that of real network or BSD sockets.
  541. *
  542. * \param buf A pointer to a raw byte buffer to write the data to.
  543. * If the underlying packet was carring null (fake) data, this buffer
  544. * will be zeroed up to the length specified by the return value.
  545. * \param size Number of bytes (at most) to copy to buf
  546. * \param flags any flags to pass to the socket
  547. * \param fromAddress output parameter that will return the
  548. * address of the sender of the received packet, if any. Remains
  549. * untouched if no packet is received.
  550. * \returns number of bytes copied into buf
  551. */
  552. int RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags,
  553. Address &fromAddress);
  554. /**
  555. * \brief Get socket address.
  556. * \param address the address name this socket is associated with.
  557. * \returns 0 if success, -1 otherwise
  558. */
  559. virtual int GetSockName (Address &address) const = 0;
  560. /**
  561. * \brief Get the peer address of a connected socket.
  562. * \param address the address this socket is connected to.
  563. * \returns 0 if success, -1 otherwise
  564. */
  565. virtual int GetPeerName (Address &address) const = 0;
  566. /**
  567. * \brief Bind a socket to specific device.
  568. *
  569. * This method corresponds to using setsockopt() SO_BINDTODEVICE
  570. * of real network or BSD sockets. If set on a socket, this option will
  571. * force packets to leave the bound device regardless of the device that
  572. * IP routing would naturally choose. In the receive direction, only
  573. * packets received from the bound interface will be delivered.
  574. *
  575. * This option has no particular relationship to binding sockets to
  576. * an address via Socket::Bind (). It is possible to bind sockets to a
  577. * specific IP address on the bound interface by calling both
  578. * Socket::Bind (address) and Socket::BindToNetDevice (device), but it
  579. * is also possible to bind to mismatching device and address, even if
  580. * the socket can not receive any packets as a result.
  581. *
  582. * \param netdevice Pointer to NetDevice of desired interface
  583. * \returns nothing
  584. */
  585. virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
  586. /**
  587. * \brief Returns socket's bound NetDevice, if any.
  588. *
  589. * This method corresponds to using getsockopt() SO_BINDTODEVICE
  590. * of real network or BSD sockets.
  591. *
  592. *
  593. * \returns Pointer to interface.
  594. */
  595. Ptr<NetDevice> GetBoundNetDevice ();
  596. /**
  597. * \brief Configure whether broadcast datagram transmissions are allowed
  598. *
  599. * This method corresponds to using setsockopt() SO_BROADCAST of
  600. * real network or BSD sockets. If set on a socket, this option
  601. * will enable or disable packets to be transmitted to broadcast
  602. * destination addresses.
  603. *
  604. * \param allowBroadcast Whether broadcast is allowed
  605. * \return true if operation succeeds
  606. */
  607. virtual bool SetAllowBroadcast (bool allowBroadcast) = 0;
  608. /**
  609. * \brief Query whether broadcast datagram transmissions are allowed
  610. *
  611. * This method corresponds to using getsockopt() SO_BROADCAST of
  612. * real network or BSD sockets.
  613. *
  614. * \returns true if broadcast is allowed, false otherwise
  615. */
  616. virtual bool GetAllowBroadcast () const = 0;
  617. /**
  618. * \brief Enable/Disable receive packet information to socket.
  619. *
  620. * For IP_PKTINFO/IP6_PKTINFO. This method is only usable for
  621. * Raw socket and Datagram Socket. Not supported for Stream socket.
  622. *
  623. * Method doesn't make distinction between IPv4 and IPv6. If it is enabled,
  624. * it is enabled for all types of sockets that supports packet information
  625. *
  626. * \param flag Enable/Disable receive information
  627. * \returns nothing
  628. */
  629. void SetRecvPktInfo (bool flag);
  630. /**
  631. * \brief Get status indicating whether enable/disable packet information to socket
  632. *
  633. * \returns True if packet information should be sent to socket
  634. */
  635. bool IsRecvPktInfo () const;
  636. /**
  637. * \brief Manually set the socket priority
  638. *
  639. * This method corresponds to using setsockopt () SO_PRIORITY of
  640. * real network or BSD sockets.
  641. *
  642. * \param priority The socket priority (in the range 0..6)
  643. */
  644. void SetPriority (uint8_t priority);
  645. /**
  646. * \brief Query the priority value of this socket
  647. *
  648. * This method corresponds to using getsockopt () SO_PRIORITY of real network
  649. * or BSD sockets.
  650. *
  651. * \return The priority value
  652. */
  653. uint8_t GetPriority (void) const;
  654. /**
  655. * \brief Return the priority corresponding to a given TOS value
  656. *
  657. * This function is implemented after the Linux rt_tos2priority
  658. * function. The usage of the TOS byte has been originally defined by
  659. * RFC 1349 (http://www.ietf.org/rfc/rfc1349.txt):
  660. *
  661. * 0 1 2 3 4 5 6 7
  662. * +-----+-----+-----+-----+-----+-----+-----+-----+
  663. * | PRECEDENCE | TOS | MBZ |
  664. * +-----+-----+-----+-----+-----+-----+-----+-----+
  665. *
  666. * where MBZ stands for 'must be zero'.
  667. *
  668. * The Linux rt_tos2priority function ignores the precedence bits and
  669. * maps each of the 16 values coded in bits 3-6 as follows:
  670. *
  671. * Bits 3-6 | Means | Linux Priority
  672. * ---------|-------------------------|----------------
  673. * 0 | Normal Service | Best Effort (0)
  674. * 1 | Minimize Monetary Cost | Best Effort (0)
  675. * 2 | Maximize Reliability | Best Effort (0)
  676. * 3 | mmc+mr | Best Effort (0)
  677. * 4 | Maximize Throughput | Bulk (2)
  678. * 5 | mmc+mt | Bulk (2)
  679. * 6 | mr+mt | Bulk (2)
  680. * 7 | mmc+mr+mt | Bulk (2)
  681. * 8 | Minimize Delay | Interactive (6)
  682. * 9 | mmc+md | Interactive (6)
  683. * 10 | mr+md | Interactive (6)
  684. * 11 | mmc+mr+md | Interactive (6)
  685. * 12 | mt+md | Int. Bulk (4)
  686. * 13 | mmc+mt+md | Int. Bulk (4)
  687. * 14 | mr+mt+md | Int. Bulk (4)
  688. * 15 | mmc+mr+mt+md | Int. Bulk (4)
  689. *
  690. * RFC 2474 (http://www.ietf.org/rfc/rfc2474.txt) redefines the TOS byte:
  691. *
  692. * 0 1 2 3 4 5 6 7
  693. * +-----+-----+-----+-----+-----+-----+-----+-----+
  694. * | DSCP | CU |
  695. * +-----+-----+-----+-----+-----+-----+-----+-----+
  696. *
  697. * where DSCP is the Differentiated Services Code Point and CU stands for
  698. * 'currently unused' (actually, RFC 3168 proposes to use these two bits for
  699. * ECN purposes). The table above allows to determine how the Linux
  700. * rt_tos2priority function maps each DSCP value to a priority value. Such a
  701. * mapping is shown below.
  702. *
  703. * DSCP | Hex | TOS (binary) | bits 3-6 | Linux Priority
  704. * -----|------|--------------|----------|----------------
  705. * EF | 0x2E | 101110xx | 12-13 | Int. Bulk (4)
  706. * AF11 | 0x0A | 001010xx | 4-5 | Bulk (2)
  707. * AF21 | 0x12 | 010010xx | 4-5 | Bulk (2)
  708. * AF31 | 0x1A | 011010xx | 4-5 | Bulk (2)
  709. * AF41 | 0x22 | 100010xx | 4-5 | Bulk (2)
  710. * AF12 | 0x0C | 001100xx | 8-9 | Interactive (6)
  711. * AF22 | 0x14 | 010100xx | 8-9 | Interactive (6)
  712. * AF32 | 0x1C | 011100xx | 8-9 | Interactive (6)
  713. * AF42 | 0x24 | 100100xx | 8-9 | Interactive (6)
  714. * AF13 | 0x0E | 001110xx | 12-13 | Int. Bulk (4)
  715. * AF23 | 0x16 | 010110xx | 12-13 | Int. Bulk (4)
  716. * AF33 | 0x1E | 011110xx | 12-13 | Int. Bulk (4)
  717. * AF43 | 0x26 | 100110xx | 12-13 | Int. Bulk (4)
  718. * CS0 | 0x00 | 000000xx | 0-1 | Best Effort (0)
  719. * CS1 | 0x08 | 001000xx | 0-1 | Best Effort (0)
  720. * CS2 | 0x10 | 010000xx | 0-1 | Best Effort (0)
  721. * CS3 | 0x18 | 011000xx | 0-1 | Best Effort (0)
  722. * CS4 | 0x20 | 100000xx | 0-1 | Best Effort (0)
  723. * CS5 | 0x28 | 101000xx | 0-1 | Best Effort (0)
  724. * CS6 | 0x30 | 110000xx | 0-1 | Best Effort (0)
  725. * CS7 | 0x38 | 111000xx | 0-1 | Best Effort (0)
  726. *
  727. * \param ipTos the TOS value (in the range 0..255)
  728. * \return The priority value corresponding to the given TOS value
  729. */
  730. static uint8_t IpTos2Priority (uint8_t ipTos);
  731. /**
  732. * \brief Manually set IP Type of Service field
  733. *
  734. * This method corresponds to using setsockopt () IP_TOS of
  735. * real network or BSD sockets. This option is for IPv4 only.
  736. * Setting the IP TOS also changes the socket priority as
  737. * stated in the man page.
  738. *
  739. * \param ipTos The desired TOS value for IP headers
  740. */
  741. void SetIpTos (uint8_t ipTos);
  742. /**
  743. * \brief Query the value of IP Type of Service of this socket
  744. *
  745. * This method corresponds to using getsockopt () IP_TOS of real network
  746. * or BSD sockets.
  747. *
  748. * \return The raw IP TOS value
  749. */
  750. uint8_t GetIpTos (void) const;
  751. /**
  752. * \brief Tells a socket to pass information about IP Type of Service up the stack
  753. *
  754. * This method corresponds to using setsockopt () IP_RECVTOS of real
  755. * network or BSD sockets. In our implementation, the socket simply
  756. * adds a SocketIpTosTag tag to the packet before passing the
  757. * packet up the stack.
  758. *
  759. * \param ipv4RecvTos Whether the socket should add SocketIpv4TosTag tag
  760. * to the packet
  761. */
  762. void SetIpRecvTos (bool ipv4RecvTos);
  763. /**
  764. * \brief Ask if the socket is currently passing information about IP Type of Service up the stack
  765. *
  766. * This method corresponds to using getsockopt () IP_RECVTOS of real
  767. * network or BSD sockets.
  768. *
  769. * \return Whether the IP_RECVTOS is set
  770. */
  771. bool IsIpRecvTos (void) const;
  772. /**
  773. * \brief Manually set IPv6 Traffic Class field
  774. *
  775. * This method corresponds to using setsockopt () IPV6_TCLASS of
  776. * real network or BSD sockets. This option is for IPv6 only.
  777. * Setting the IPV6_TCLASSS to -1 clears the option and let the socket
  778. * uses the default value.
  779. *
  780. * \param ipTclass The desired TCLASS value for IPv6 headers
  781. */
  782. void SetIpv6Tclass (int ipTclass);
  783. /**
  784. * \brief Query the value of IPv6 Traffic Class field of this socket
  785. *
  786. * This method corresponds to using getsockopt () IPV6_TCLASS of real network
  787. * or BSD sockets.
  788. *
  789. * \return The raw IPV6_TCLASS value
  790. */
  791. uint8_t GetIpv6Tclass (void) const;
  792. /**
  793. * \brief Tells a socket to pass information about IPv6 Traffic Class up the stack
  794. *
  795. * This method corresponds to using setsockopt () IPV6_RECVTCLASS of real
  796. * network or BSD sockets. In our implementation, the socket simply
  797. * adds a SocketIpv6TclasssTag tag to the packet before passing the
  798. * packet up the stack.
  799. *
  800. * \param ipv6RecvTclass Whether the socket should add SocketIpv6TclassTag tag
  801. * to the packet
  802. */
  803. void SetIpv6RecvTclass (bool ipv6RecvTclass);
  804. /**
  805. * \brief Ask if the socket is currently passing information about IPv6 Traffic Class up the stack
  806. *
  807. * This method corresponds to using getsockopt () IPV6_RECVTCLASS of real
  808. * network or BSD sockets.
  809. *
  810. * \return Whether the IPV6_RECVTCLASS is set
  811. */
  812. bool IsIpv6RecvTclass (void) const;
  813. /**
  814. * \brief Manually set IP Time to Live field
  815. *
  816. * This method corresponds to using setsockopt () IP_TTL of
  817. * real network or BSD sockets.
  818. *
  819. * \param ipTtl The desired TTL value for IP headers
  820. */
  821. virtual void SetIpTtl (uint8_t ipTtl);
  822. /**
  823. * \brief Query the value of IP Time to Live field of this socket
  824. *
  825. * This method corresponds to using getsockopt () IP_TTL of real network
  826. * or BSD sockets.
  827. *
  828. * \return The raw IP TTL value
  829. */
  830. virtual uint8_t GetIpTtl (void) const;
  831. /**
  832. * \brief Tells a socket to pass information about IP_TTL up the stack
  833. *
  834. * This method corresponds to using setsockopt () IP_RECVTTL of real
  835. * network or BSD sockets. In our implementation, the socket simply
  836. * adds a SocketIpTtlTag tag to the packet before passing the
  837. * packet up the stack.
  838. *
  839. * \param ipv4RecvTtl Whether the socket should add SocketIpv4TtlTag tag
  840. * to the packet
  841. */
  842. void SetIpRecvTtl (bool ipv4RecvTtl);
  843. /**
  844. * \brief Ask if the socket is currently passing information about IP_TTL up the stack
  845. *
  846. * This method corresponds to using getsockopt () IP_RECVTTL of real
  847. * network or BSD sockets.
  848. *
  849. * \return Whether the IP_RECVTTL is set
  850. */
  851. bool IsIpRecvTtl (void) const;
  852. /**
  853. * \brief Manually set IPv6 Hop Limit
  854. *
  855. * This method corresponds to using setsockopt () IPV6_HOPLIMIT of
  856. * real network or BSD sockets.
  857. *
  858. * \param ipHopLimit The desired Hop Limit value for IPv6 headers
  859. */
  860. virtual void SetIpv6HopLimit (uint8_t ipHopLimit);
  861. /**
  862. * \brief Query the value of IP Hop Limit field of this socket
  863. *
  864. * This method corresponds to using getsockopt () IPV6_HOPLIMIT of real network
  865. * or BSD sockets.
  866. *
  867. * \return The raw IPv6 Hop Limit value
  868. */
  869. virtual uint8_t GetIpv6HopLimit (void) const;
  870. /**
  871. * \brief Tells a socket to pass information about IPv6 Hop Limit up the stack
  872. *
  873. * This method corresponds to using setsockopt () IPV6_RECVHOPLIMIT of real
  874. * network or BSD sockets. In our implementation, the socket simply
  875. * adds a SocketIpv6HopLimitTag tag to the packet before passing the
  876. * packet up the stack.
  877. *
  878. * \param ipv6RecvHopLimit Whether the socket should add SocketIpv6HopLimitTag tag
  879. * to the packet
  880. */
  881. void SetIpv6RecvHopLimit (bool ipv6RecvHopLimit);
  882. /**
  883. * \brief Ask if the socket is currently passing information about IPv6 Hop Limit up the stack
  884. *
  885. * This method corresponds to using getsockopt () IPV6_RECVHOPLIMIT of real
  886. * network or BSD sockets.
  887. *
  888. * \return Whether the IPV6_RECVHOPLIMIT is set
  889. */
  890. bool IsIpv6RecvHopLimit (void) const;
  891. /**
  892. * \brief Joins a IPv6 multicast group.
  893. *
  894. * Based on the filter mode and source addresses this can be interpreted as a
  895. * join, leave, or modification to source filtering on a multicast group.
  896. *
  897. * Mind that a socket can join only one multicast group. Any attempt to join another group will remove the old one.
  898. *
  899. *
  900. * \param address Requested multicast address.
  901. * \param filterMode Socket filtering mode (INCLUDE | EXCLUDE).
  902. * \param sourceAddresses All the source addresses on which socket is interested or not interested.
  903. */
  904. virtual void Ipv6JoinGroup (Ipv6Address address, Ipv6MulticastFilterMode filterMode, std::vector<Ipv6Address> sourceAddresses);
  905. /**
  906. * \brief Joins a IPv6 multicast group without filters.
  907. *
  908. * A socket can join only one multicast group. Any attempt to join another group will remove the old one.
  909. *
  910. * \param address Group address on which socket wants to join.
  911. */
  912. virtual void Ipv6JoinGroup (Ipv6Address address);
  913. /**
  914. * \brief Leaves IPv6 multicast group this socket is joined to.
  915. */
  916. virtual void Ipv6LeaveGroup (void);
  917. protected:
  918. /**
  919. * \brief Notify through the callback (if set) that the connection has been
  920. * established.
  921. */
  922. void NotifyConnectionSucceeded (void);
  923. /**
  924. * \brief Notify through the callback (if set) that the connection has not been
  925. * established due to an error.
  926. */
  927. void NotifyConnectionFailed (void);
  928. /**
  929. * \brief Notify through the callback (if set) that the connection has been
  930. * closed.
  931. */
  932. void NotifyNormalClose (void);
  933. /**
  934. * \brief Notify through the callback (if set) that the connection has been
  935. * closed due to an error.
  936. */
  937. void NotifyErrorClose (void);
  938. /**
  939. * \brief Notify through the callback (if set) that an incoming connection
  940. * is being requested by a remote host.
  941. *
  942. * This function returns true by default (i.e., accept all the incoming connections).
  943. * The callback (if set) might restrict this behaviour by returning zero for a
  944. * connection that should be refused.
  945. *
  946. * \param from the address the connection is incoming from
  947. * \returns true if the connection must be accepted, false otherwise.
  948. */
  949. bool NotifyConnectionRequest (const Address &from);
  950. /**
  951. * \brief Notify through the callback (if set) that a new connection has been
  952. * created.
  953. * \param socket The socket receiving the new connection.
  954. * \param from The address of the node initiating the connection.
  955. */
  956. void NotifyNewConnectionCreated (Ptr<Socket> socket, const Address &from);
  957. /**
  958. * \brief Notify through the callback (if set) that some data have been sent.
  959. *
  960. * \param size number of sent bytes.
  961. */
  962. void NotifyDataSent (uint32_t size);
  963. /**
  964. * \brief Notify through the callback (if set) that some data have been sent.
  965. *
  966. * \param spaceAvailable the number of bytes available in the transmission buffer.
  967. */
  968. void NotifySend (uint32_t spaceAvailable);
  969. /**
  970. * \brief Notify through the callback (if set) that some data have been received.
  971. */
  972. void NotifyDataRecv (void);
  973. // inherited function, no doc necessary
  974. virtual void DoDispose (void);
  975. /**
  976. * \brief Checks if the socket has a specific IPv6 Tclass set
  977. *
  978. * \returns true if the socket has a IPv6 Tclass set, false otherwise.
  979. */
  980. bool IsManualIpv6Tclass (void) const;
  981. /**
  982. * \brief Checks if the socket has a specific IPv4 TTL set
  983. *
  984. * \returns true if the socket has a IPv4 TTL set, false otherwise.
  985. */
  986. bool IsManualIpTtl (void) const;
  987. /**
  988. * \brief Checks if the socket has a specific IPv6 Hop Limit set
  989. *
  990. * \returns true if the socket has a IPv6 Hop Limit set, false otherwise.
  991. */
  992. bool IsManualIpv6HopLimit (void) const;
  993. Ptr<NetDevice> m_boundnetdevice; //!< the device this socket is bound to (might be null).
  994. bool m_recvPktInfo; //!< if the socket should add packet info tags to the packet forwarded to L4.
  995. Ipv6Address m_ipv6MulticastGroupAddress; //!< IPv6 multicast group address.
  996. private:
  997. Callback<void, Ptr<Socket> > m_connectionSucceeded; //!< connection succeeded callback
  998. Callback<void, Ptr<Socket> > m_connectionFailed; //!< connection failed callback
  999. Callback<void, Ptr<Socket> > m_normalClose; //!< connection closed callback
  1000. Callback<void, Ptr<Socket> > m_errorClose; //!< connection closed due to errors callback
  1001. Callback<bool, Ptr<Socket>, const Address &> m_connectionRequest; //!< connection request callback
  1002. Callback<void, Ptr<Socket>, const Address&> m_newConnectionCreated; //!< connection created callback
  1003. Callback<void, Ptr<Socket>, uint32_t> m_dataSent; //!< data sent callback
  1004. Callback<void, Ptr<Socket>, uint32_t > m_sendCb; //!< packet sent callback
  1005. Callback<void, Ptr<Socket> > m_receivedData; //!< data received callback
  1006. uint8_t m_priority; //!< the socket priority
  1007. //IPv4 options
  1008. bool m_manualIpTtl; //!< socket has IPv4 TTL set
  1009. bool m_ipRecvTos; //!< socket forwards IPv4 TOS tag to L4
  1010. bool m_ipRecvTtl; //!< socket forwards IPv4 TTL tag to L4
  1011. uint8_t m_ipTos; //!< the socket IPv4 TOS
  1012. uint8_t m_ipTtl; //!< the socket IPv4 TTL
  1013. //IPv6 options
  1014. bool m_manualIpv6Tclass; //!< socket has IPv6 Tclass set
  1015. bool m_manualIpv6HopLimit; //!< socket has IPv6 Hop Limit set
  1016. bool m_ipv6RecvTclass; //!< socket forwards IPv6 Tclass tag to L4
  1017. bool m_ipv6RecvHopLimit; //!< socket forwards IPv6 Hop Limit tag to L4
  1018. uint8_t m_ipv6Tclass; //!< the socket IPv6 Tclass
  1019. uint8_t m_ipv6HopLimit; //!< the socket IPv6 Hop Limit
  1020. };
  1021. /**
  1022. * \brief This class implements a tag that carries the socket-specific
  1023. * TTL of a packet to the IP layer
  1024. */
  1025. class SocketIpTtlTag : public Tag
  1026. {
  1027. public:
  1028. SocketIpTtlTag ();
  1029. /**
  1030. * \brief Set the tag's TTL
  1031. *
  1032. * \param ttl the TTL
  1033. */
  1034. void SetTtl (uint8_t ttl);
  1035. /**
  1036. * \brief Get the tag's TTL
  1037. *
  1038. * \returns the TTL
  1039. */
  1040. uint8_t GetTtl (void) const;
  1041. /**
  1042. * \brief Get the type ID.
  1043. * \return the object TypeId
  1044. */
  1045. static TypeId GetTypeId (void);
  1046. // inherited function, no need to doc.
  1047. virtual TypeId GetInstanceTypeId (void) const;
  1048. // inherited function, no need to doc.
  1049. virtual uint32_t GetSerializedSize (void) const;
  1050. // inherited function, no need to doc.
  1051. virtual void Serialize (TagBuffer i) const;
  1052. // inherited function, no need to doc.
  1053. virtual void Deserialize (TagBuffer i);
  1054. // inherited function, no need to doc.
  1055. virtual void Print (std::ostream &os) const;
  1056. private:
  1057. uint8_t m_ttl; //!< the ttl carried by the tag
  1058. };
  1059. /**
  1060. * \brief This class implements a tag that carries the socket-specific
  1061. * HOPLIMIT of a packet to the IPv6 layer
  1062. */
  1063. class SocketIpv6HopLimitTag : public Tag
  1064. {
  1065. public:
  1066. SocketIpv6HopLimitTag ();
  1067. /**
  1068. * \brief Set the tag's Hop Limit
  1069. *
  1070. * \param hopLimit the Hop Limit
  1071. */
  1072. void SetHopLimit (uint8_t hopLimit);
  1073. /**
  1074. * \brief Get the tag's Hop Limit
  1075. *
  1076. * \returns the Hop Limit
  1077. */
  1078. uint8_t GetHopLimit (void) const;
  1079. /**
  1080. * \brief Get the type ID.
  1081. * \return the object TypeId
  1082. */
  1083. static TypeId GetTypeId (void);
  1084. // inherited function, no need to doc.
  1085. virtual TypeId GetInstanceTypeId (void) const;
  1086. // inherited function, no need to doc.
  1087. virtual uint32_t GetSerializedSize (void) const;
  1088. // inherited function, no need to doc.
  1089. virtual void Serialize (TagBuffer i) const;
  1090. // inherited function, no need to doc.
  1091. virtual void Deserialize (TagBuffer i);
  1092. // inherited function, no need to doc.
  1093. virtual void Print (std::ostream &os) const;
  1094. private:
  1095. uint8_t m_hopLimit; //!< the Hop Limit carried by the tag
  1096. };
  1097. /**
  1098. * \brief indicates whether packets should be sent out with
  1099. * the DF (Don't Fragment) flag set.
  1100. */
  1101. class SocketSetDontFragmentTag : public Tag
  1102. {
  1103. public:
  1104. SocketSetDontFragmentTag ();
  1105. /**
  1106. * \brief Enables the DF (Don't Fragment) flag
  1107. */
  1108. void Enable (void);
  1109. /**
  1110. * \brief Disables the DF (Don't Fragment) flag
  1111. */
  1112. void Disable (void);
  1113. /**
  1114. * \brief Checks if the DF (Don't Fragment) flag is set
  1115. *
  1116. * \returns true if DF is set.
  1117. */
  1118. bool IsEnabled (void) const;
  1119. /**
  1120. * \brief Get the type ID.
  1121. * \return the object TypeId
  1122. */
  1123. static TypeId GetTypeId (void);
  1124. // inherited function, no need to doc.
  1125. virtual TypeId GetInstanceTypeId (void) const;
  1126. // inherited function, no need to doc.
  1127. virtual uint32_t GetSerializedSize (void) const;
  1128. // inherited function, no need to doc.
  1129. virtual void Serialize (TagBuffer i) const;
  1130. // inherited function, no need to doc.
  1131. virtual void Deserialize (TagBuffer i);
  1132. // inherited function, no need to doc.
  1133. virtual void Print (std::ostream &os) const;
  1134. private:
  1135. bool m_dontFragment; //!< DF bit value for outgoing packets.
  1136. };
  1137. /**
  1138. * \brief indicates whether the socket has IP_TOS set.
  1139. * This tag is for IPv4 socket.
  1140. */
  1141. class SocketIpTosTag : public Tag
  1142. {
  1143. public:
  1144. SocketIpTosTag ();
  1145. /**
  1146. * \brief Set the tag's TOS
  1147. *
  1148. * \param tos the TOS
  1149. */
  1150. void SetTos (uint8_t tos);
  1151. /**
  1152. * \brief Get the tag's TOS
  1153. *
  1154. * \returns the TOS
  1155. */
  1156. uint8_t GetTos (void) const;
  1157. /**
  1158. * \brief Get the type ID.
  1159. * \return the object TypeId
  1160. */
  1161. static TypeId GetTypeId (void);
  1162. // inherited function, no need to doc.
  1163. virtual TypeId GetInstanceTypeId (void) const;
  1164. // inherited function, no need to doc.
  1165. virtual uint32_t GetSerializedSize (void) const;
  1166. // inherited function, no need to doc.
  1167. virtual void Serialize (TagBuffer i) const;
  1168. // inherited function, no need to doc.
  1169. virtual void Deserialize (TagBuffer i);
  1170. // inherited function, no need to doc.
  1171. virtual void Print (std::ostream &os) const;
  1172. private:
  1173. uint8_t m_ipTos; //!< the TOS carried by the tag
  1174. };
  1175. /**
  1176. * \brief indicates whether the socket has a priority set.
  1177. */
  1178. class SocketPriorityTag : public Tag
  1179. {
  1180. public:
  1181. SocketPriorityTag ();
  1182. /**
  1183. * \brief Set the tag's priority
  1184. *
  1185. * \param priority the priority
  1186. */
  1187. void SetPriority (uint8_t priority);
  1188. /**
  1189. * \brief Get the tag's priority
  1190. *
  1191. * \returns the priority
  1192. */
  1193. uint8_t GetPriority (void) const;
  1194. /**
  1195. * \brief Get the type ID.
  1196. * \return the object TypeId
  1197. */
  1198. static TypeId GetTypeId (void);
  1199. // inherited function, no need to doc.
  1200. virtual TypeId GetInstanceTypeId (void) const;
  1201. // inherited function, no need to doc.
  1202. virtual uint32_t GetSerializedSize (void) const;
  1203. // inherited function, no need to doc.
  1204. virtual void Serialize (TagBuffer i) const;
  1205. // inherited function, no need to doc.
  1206. virtual void Deserialize (TagBuffer i);
  1207. // inherited function, no need to doc.
  1208. virtual void Print (std::ostream &os) const;
  1209. private:
  1210. uint8_t m_priority; //!< the priority carried by the tag
  1211. };
  1212. /**
  1213. * \brief indicates whether the socket has IPV6_TCLASS set.
  1214. * This tag is for IPv6 socket.
  1215. */
  1216. class SocketIpv6TclassTag : public Tag
  1217. {
  1218. public:
  1219. SocketIpv6TclassTag ();
  1220. /**
  1221. * \brief Set the tag's Tclass
  1222. *
  1223. * \param tclass the Tclass
  1224. */
  1225. void SetTclass (uint8_t tclass);
  1226. /**
  1227. * \brief Get the tag's Tclass
  1228. *
  1229. * \returns the Tclass
  1230. */
  1231. uint8_t GetTclass (void) const;
  1232. /**
  1233. * \brief Get the type ID.
  1234. * \return the object TypeId
  1235. */
  1236. static TypeId GetTypeId (void);
  1237. // inherited function, no need to doc.
  1238. virtual TypeId GetInstanceTypeId (void) const;
  1239. // inherited function, no need to doc.
  1240. virtual uint32_t GetSerializedSize (void) const;
  1241. // inherited function, no need to doc.
  1242. virtual void Serialize (TagBuffer i) const;
  1243. // inherited function, no need to doc.
  1244. virtual void Deserialize (TagBuffer i);
  1245. // inherited function, no need to doc.
  1246. virtual void Print (std::ostream &os) const;
  1247. private:
  1248. uint8_t m_ipv6Tclass; //!< the Tclass carried by the tag
  1249. };
  1250. } // namespace ns3
  1251. #endif /* NS3_SOCKET_H */