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