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