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