A Discrete-Event Network Simulator
API
ns3::UdpSocket Class Referenceabstract

(abstract) base class of all UdpSockets More...

#include "udp-socket.h"

+ Inheritance diagram for ns3::UdpSocket:
+ Collaboration diagram for ns3::UdpSocket:

Public Member Functions

 UdpSocket ()
 
 ~UdpSocket () override
 
virtual int MulticastJoinGroup (uint32_t interface, const Address &groupAddress)=0
 Corresponds to socket option MCAST_JOIN_GROUP. More...
 
virtual int MulticastLeaveGroup (uint32_t interface, const Address &groupAddress)=0
 Corresponds to socket option MCAST_LEAVE_GROUP. More...
 
- Public Member Functions inherited from ns3::Socket
 Socket ()
 
 ~Socket () override
 
virtual int Bind ()=0
 Allocate a local IPv4 endpoint for this socket. More...
 
virtual int Bind (const Address &address)=0
 Allocate a local endpoint for this socket. More...
 
virtual int Bind6 ()=0
 Allocate a local IPv6 endpoint for this socket. More...
 
virtual void BindToNetDevice (Ptr< NetDevice > netdevice)
 Bind a socket to specific device. More...
 
virtual int Close ()=0
 Close a socket. More...
 
virtual int Connect (const Address &address)=0
 Initiate a connection to a remote host. More...
 
virtual bool GetAllowBroadcast () const =0
 Query whether broadcast datagram transmissions are allowed. More...
 
Ptr< NetDeviceGetBoundNetDevice ()
 Returns socket's bound NetDevice, if any. More...
 
virtual Socket::SocketErrno GetErrno () const =0
 Get last error number. More...
 
uint8_t GetIpTos () const
 Query the value of IP Type of Service of this socket. More...
 
virtual uint8_t GetIpTtl () const
 Query the value of IP Time to Live field of this socket. More...
 
virtual uint8_t GetIpv6HopLimit () const
 Query the value of IP Hop Limit field of this socket. More...
 
uint8_t GetIpv6Tclass () const
 Query the value of IPv6 Traffic Class field of this socket. More...
 
virtual Ptr< NodeGetNode () const =0
 Return the node this socket is associated with. More...
 
virtual int GetPeerName (Address &address) const =0
 Get the peer address of a connected socket. More...
 
uint8_t GetPriority () const
 Query the priority value of this socket. More...
 
virtual uint32_t GetRxAvailable () const =0
 Return number of bytes which can be returned from one or multiple calls to Recv. More...
 
virtual Socket::SocketType GetSocketType () const =0
 
virtual int GetSockName (Address &address) const =0
 Get socket address. More...
 
virtual uint32_t GetTxAvailable () const =0
 Returns the number of bytes which can be sent in a single call to Send. More...
 
virtual void Ipv6JoinGroup (Ipv6Address address)
 Joins a IPv6 multicast group without filters. More...
 
virtual void Ipv6JoinGroup (Ipv6Address address, Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
 Joins a IPv6 multicast group. More...
 
virtual void Ipv6LeaveGroup ()
 Leaves IPv6 multicast group this socket is joined to. More...
 
bool IsIpRecvTos () const
 Ask if the socket is currently passing information about IP Type of Service up the stack. More...
 
bool IsIpRecvTtl () const
 Ask if the socket is currently passing information about IP_TTL up the stack. More...
 
bool IsIpv6RecvHopLimit () const
 Ask if the socket is currently passing information about IPv6 Hop Limit up the stack. More...
 
bool IsIpv6RecvTclass () const
 Ask if the socket is currently passing information about IPv6 Traffic Class up the stack. More...
 
bool IsRecvPktInfo () const
 Get status indicating whether enable/disable packet information to socket. More...
 
virtual int Listen ()=0
 Listen for incoming connections. More...
 
Ptr< PacketRecv ()
 Read a single packet from the socket. More...
 
virtual Ptr< PacketRecv (uint32_t maxSize, uint32_t flags)=0
 Read data from the socket. More...
 
int Recv (uint8_t *buf, uint32_t size, uint32_t flags)
 Recv data (or dummy data) from the remote host. More...
 
Ptr< PacketRecvFrom (Address &fromAddress)
 Read a single packet from the socket and retrieve the sender address. More...
 
virtual Ptr< PacketRecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
 Read a single packet from the socket and retrieve the sender address. More...
 
int RecvFrom (uint8_t *buf, uint32_t size, uint32_t flags, Address &fromAddress)
 Read a single packet from the socket and retrieve the sender address. More...
 
int Send (const uint8_t *buf, uint32_t size, uint32_t flags)
 Send data (or dummy data) to the remote host. More...
 
int Send (Ptr< Packet > p)
 Send data (or dummy data) to the remote host. More...
 
virtual int Send (Ptr< Packet > p, uint32_t flags)=0
 Send data (or dummy data) to the remote host. More...
 
int SendTo (const uint8_t *buf, uint32_t size, uint32_t flags, const Address &address)
 Send data to a specified peer. More...
 
virtual int SendTo (Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
 Send data to a specified peer. More...
 
void SetAcceptCallback (Callback< bool, Ptr< Socket >, const Address & > connectionRequest, Callback< void, Ptr< Socket >, const Address & > newConnectionCreated)
 Accept connection requests from remote hosts. More...
 
virtual bool SetAllowBroadcast (bool allowBroadcast)=0
 Configure whether broadcast datagram transmissions are allowed. More...
 
void SetCloseCallbacks (Callback< void, Ptr< Socket >> normalClose, Callback< void, Ptr< Socket >> errorClose)
 Detect socket recv() events such as graceful shutdown or error. More...
 
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. More...
 
void SetDataSentCallback (Callback< void, Ptr< Socket >, uint32_t > dataSent)
 Notify application when a packet has been sent from transport protocol (non-standard socket call) More...
 
void SetIpRecvTos (bool ipv4RecvTos)
 Tells a socket to pass information about IP Type of Service up the stack. More...
 
void SetIpRecvTtl (bool ipv4RecvTtl)
 Tells a socket to pass information about IP_TTL up the stack. More...
 
void SetIpTos (uint8_t ipTos)
 Manually set IP Type of Service field. More...
 
virtual void SetIpTtl (uint8_t ipTtl)
 Manually set IP Time to Live field. More...
 
virtual void SetIpv6HopLimit (uint8_t ipHopLimit)
 Manually set IPv6 Hop Limit. More...
 
void SetIpv6RecvHopLimit (bool ipv6RecvHopLimit)
 Tells a socket to pass information about IPv6 Hop Limit up the stack. More...
 
void SetIpv6RecvTclass (bool ipv6RecvTclass)
 Tells a socket to pass information about IPv6 Traffic Class up the stack. More...
 
void SetIpv6Tclass (int ipTclass)
 Manually set IPv6 Traffic Class field. More...
 
void SetPriority (uint8_t priority)
 Manually set the socket priority. More...
 
void SetRecvCallback (Callback< void, Ptr< Socket >> receivedData)
 Notify application when new data is available to be read. More...
 
void SetRecvPktInfo (bool flag)
 Enable/Disable receive packet information to socket. More...
 
void SetSendCallback (Callback< void, Ptr< Socket >, uint32_t > sendCb)
 Notify application when space in transmit buffer is added. More...
 
virtual int ShutdownRecv ()=0
 
virtual int ShutdownSend ()=0
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
 ~Object () override
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose ()
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one. More...
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object. More...
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object. More...
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object. More...
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized () const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o[[maybe_unused]])
 Copy constructor. More...
 
uint32_t GetReferenceCount () const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o[[maybe_unused]])
 Assignment operator. More...
 
void Ref () const
 Increment the reference count. More...
 
void Unref () const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Socket
static Ptr< SocketCreateSocket (Ptr< Node > node, TypeId tid)
 This method wraps the creation of sockets that is performed on a given node by a SocketFactory specified by TypeId. More...
 
static TypeId GetTypeId ()
 Get the type ID. More...
 
static uint8_t IpTos2Priority (uint8_t ipTos)
 Return the priority corresponding to a given TOS value. More...
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID. More...
 

Private Member Functions

virtual int32_t GetIpMulticastIf () const =0
 Get the IP multicast interface. More...
 
virtual bool GetIpMulticastLoop () const =0
 Get the IP multicast loop capability. More...
 
virtual uint8_t GetIpMulticastTtl () const =0
 Get the IP multicast TTL. More...
 
virtual bool GetMtuDiscover () const =0
 Get the MTU discover capability. More...
 
virtual uint32_t GetRcvBufSize () const =0
 Get the receiving buffer size. More...
 
virtual void SetIpMulticastIf (int32_t ipIf)=0
 Set the IP multicast interface. More...
 
virtual void SetIpMulticastLoop (bool loop)=0
 Set the IP multicast loop capability. More...
 
virtual void SetIpMulticastTtl (uint8_t ipTtl)=0
 Set the IP multicast TTL. More...
 
virtual void SetMtuDiscover (bool discover)=0
 Set the MTU discover capability. More...
 
virtual void SetRcvBufSize (uint32_t size)=0
 Set the receiving buffer size. More...
 

Additional Inherited Members

- Public Types inherited from ns3::Socket
enum  Ipv6MulticastFilterMode { INCLUDE = 1 , EXCLUDE }
 Enumeration of the possible filter of a socket. More...
 
enum  SocketErrno {
  ERROR_NOTERROR , ERROR_ISCONN , ERROR_NOTCONN , ERROR_MSGSIZE ,
  ERROR_AGAIN , ERROR_SHUTDOWN , ERROR_OPNOTSUPP , ERROR_AFNOSUPPORT ,
  ERROR_INVAL , ERROR_BADF , ERROR_NOROUTETOHOST , ERROR_NODEV ,
  ERROR_ADDRNOTAVAIL , ERROR_ADDRINUSE , SOCKET_ERRNO_LAST
}
 Enumeration of the possible errors returned by a socket. More...
 
enum  SocketPriority {
  NS3_PRIO_BESTEFFORT = 0 , NS3_PRIO_FILLER = 1 , NS3_PRIO_BULK = 2 , NS3_PRIO_INTERACTIVE_BULK = 4 ,
  NS3_PRIO_INTERACTIVE = 6 , NS3_PRIO_CONTROL = 7
}
 Enumeration of the possible socket priorities. More...
 
enum  SocketType { NS3_SOCK_STREAM , NS3_SOCK_SEQPACKET , NS3_SOCK_DGRAM , NS3_SOCK_RAW }
 Enumeration of the possible socket types. More...
 
- Protected Member Functions inherited from ns3::Socket
void DoDispose () override
 Destructor implementation. More...
 
bool IsManualIpTtl () const
 Checks if the socket has a specific IPv4 TTL set. More...
 
bool IsManualIpv6HopLimit () const
 Checks if the socket has a specific IPv6 Hop Limit set. More...
 
bool IsManualIpv6Tclass () const
 Checks if the socket has a specific IPv6 Tclass set. More...
 
void NotifyConnectionFailed ()
 Notify through the callback (if set) that the connection has not been established due to an error. More...
 
bool NotifyConnectionRequest (const Address &from)
 Notify through the callback (if set) that an incoming connection is being requested by a remote host. More...
 
void NotifyConnectionSucceeded ()
 Notify through the callback (if set) that the connection has been established. More...
 
void NotifyDataRecv ()
 Notify through the callback (if set) that some data have been received. More...
 
void NotifyDataSent (uint32_t size)
 Notify through the callback (if set) that some data have been sent. More...
 
void NotifyErrorClose ()
 Notify through the callback (if set) that the connection has been closed due to an error. More...
 
void NotifyNewConnectionCreated (Ptr< Socket > socket, const Address &from)
 Notify through the callback (if set) that a new connection has been created. More...
 
void NotifyNormalClose ()
 Notify through the callback (if set) that the connection has been closed. More...
 
void NotifySend (uint32_t spaceAvailable)
 Notify through the callback (if set) that some data have been sent. More...
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object. More...
 
virtual void DoInitialize ()
 Initialize() implementation. More...
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes. More...
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed. More...
 
- Protected Attributes inherited from ns3::Socket
Ptr< NetDevicem_boundnetdevice
 the device this socket is bound to (might be null). More...
 
Ipv6Address m_ipv6MulticastGroupAddress
 IPv6 multicast group address. More...
 
bool m_recvPktInfo
 if the socket should add packet info tags to the packet forwarded to L4. More...
 

Detailed Description

(abstract) base class of all UdpSockets

This class exists solely for hosting UdpSocket attributes that can be reused across different implementations, and for declaring UDP-specific multicast API.

Definition at line 47 of file udp-socket.h.

Constructor & Destructor Documentation

◆ UdpSocket()

ns3::UdpSocket::UdpSocket ( )

Definition at line 82 of file udp-socket.cc.

References NS_LOG_FUNCTION.

◆ ~UdpSocket()

ns3::UdpSocket::~UdpSocket ( )
override

Definition at line 87 of file udp-socket.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ GetIpMulticastIf()

virtual int32_t ns3::UdpSocket::GetIpMulticastIf ( ) const
privatepure virtual

Get the IP multicast interface.

Returns
the IP multicast interface

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ GetIpMulticastLoop()

virtual bool ns3::UdpSocket::GetIpMulticastLoop ( ) const
privatepure virtual

Get the IP multicast loop capability.

This means that the socket will receive the packets sent by itself on a multicast address. Equivalent to setsockopt IP_MULTICAST_LOOP

Returns
the IP multicast loop capability

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ GetIpMulticastTtl()

virtual uint8_t ns3::UdpSocket::GetIpMulticastTtl ( ) const
privatepure virtual

Get the IP multicast TTL.

Returns
the IP multicast TTL

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ GetMtuDiscover()

virtual bool ns3::UdpSocket::GetMtuDiscover ( ) const
privatepure virtual

Get the MTU discover capability.

Returns
the MTU discover capability

Implemented in ns3::UdpSocketImpl.

Referenced by ns3::Ipv4::GetTypeId(), and GetTypeId().

+ Here is the caller graph for this function:

◆ GetRcvBufSize()

virtual uint32_t ns3::UdpSocket::GetRcvBufSize ( ) const
privatepure virtual

Get the receiving buffer size.

Returns
the buffer size

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ GetTypeId()

◆ MulticastJoinGroup()

virtual int ns3::UdpSocket::MulticastJoinGroup ( uint32_t  interface,
const Address groupAddress 
)
pure virtual

Corresponds to socket option MCAST_JOIN_GROUP.

Parameters
interfaceinterface number, or 0
groupAddressmulticast group address
Returns
on success, zero is returned. On error, -1 is returned, and errno is set appropriately

Enable reception of multicast datagrams for this socket on the interface number specified. If zero is specified as the interface, then a single local interface is chosen by system. In the future, this function will generate trigger IGMP joins as necessary when IGMP is implemented, but for now, this just enables multicast datagram reception in the system if not already enabled for this interface/groupAddress combination.

Attention
IGMP is not yet implemented in ns-3

This function may be called repeatedly on a given socket but each join must be for a different multicast address, or for the same multicast address but on a different interface from previous joins. This enables host multihoming, and the ability to join the same group on different interfaces.

Implemented in ns3::UdpSocketImpl.

Referenced by Ipv4DeduplicationTest::DoRun().

+ Here is the caller graph for this function:

◆ MulticastLeaveGroup()

virtual int ns3::UdpSocket::MulticastLeaveGroup ( uint32_t  interface,
const Address groupAddress 
)
pure virtual

Corresponds to socket option MCAST_LEAVE_GROUP.

Parameters
interfaceinterface number, or 0
groupAddressmulticast group address
Returns
on success, zero is returned. On error, -1 is returned, and errno is set appropriately

Disable reception of multicast datagrams for this socket on the interface number specified. If zero is specified as the interfaceIndex, then a single local interface is chosen by system. In the future, this function will generate trigger IGMP leaves as necessary when IGMP is implemented, but for now, this just disables multicast datagram reception in the system if this socket is the last for this interface/groupAddress combination.

Attention
IGMP is not yet implemented in ns-3

Implemented in ns3::UdpSocketImpl.

◆ SetIpMulticastIf()

virtual void ns3::UdpSocket::SetIpMulticastIf ( int32_t  ipIf)
privatepure virtual

Set the IP multicast interface.

Parameters
ipIfthe IP multicast interface

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetIpMulticastLoop()

virtual void ns3::UdpSocket::SetIpMulticastLoop ( bool  loop)
privatepure virtual

Set the IP multicast loop capability.

This means that the socket will receive the packets sent by itself on a multicast address. Equivalent to setsockopt IP_MULTICAST_LOOP

Parameters
loopthe IP multicast loop capability

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetIpMulticastTtl()

virtual void ns3::UdpSocket::SetIpMulticastTtl ( uint8_t  ipTtl)
privatepure virtual

Set the IP multicast TTL.

Parameters
ipTtlthe IP multicast TTL

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetMtuDiscover()

virtual void ns3::UdpSocket::SetMtuDiscover ( bool  discover)
privatepure virtual

Set the MTU discover capability.

Parameters
discoverthe MTU discover capability

Implemented in ns3::UdpSocketImpl.

Referenced by ns3::Ipv4::GetTypeId(), and GetTypeId().

+ Here is the caller graph for this function:

◆ SetRcvBufSize()

virtual void ns3::UdpSocket::SetRcvBufSize ( uint32_t  size)
privatepure virtual

Set the receiving buffer size.

Parameters
sizethe buffer size

Implemented in ns3::UdpSocketImpl.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: