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