23 #include "ns3/inet-socket-address.h"
24 #include "ns3/inet6-socket-address.h"
25 #include "ns3/ipv4-route.h"
26 #include "ns3/ipv6-route.h"
29 #include "ns3/ipv4-header.h"
30 #include "ns3/ipv4-routing-protocol.h"
31 #include "ns3/ipv6-routing-protocol.h"
32 #include "ns3/udp-socket-factory.h"
33 #include "ns3/trace-source-accessor.h"
34 #include "ns3/ipv4-packet-info-tag.h"
35 #include "ns3/ipv6-packet-info-tag.h"
60 .AddConstructor<UdpSocketImpl> ()
61 .AddTraceSource (
"Drop",
"Drop UDP packet due to receive buffer overflow",
63 .AddAttribute (
"IcmpCallback",
"Callback invoked whenever an icmp error is received on this socket.",
66 MakeCallbackChecker ())
67 .AddAttribute (
"IcmpCallback6",
"Callback invoked whenever an icmpv6 error is received on this socket.",
70 MakeCallbackChecker ())
80 m_errno (ERROR_NOTERROR),
81 m_shutdownSend (false),
82 m_shutdownRecv (false),
539 for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
556 NS_LOG_LOGIC (
"Sending one copy from " << addri <<
" to " << dest
557 <<
" (mask is " << maski <<
")");
567 NS_LOG_LOGIC (
"Sending one copy from " << addri <<
" to " << bcast
568 <<
" (mask is " << maski <<
")");
586 else if (ipv4->GetRoutingProtocol () != 0)
595 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
601 uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->
GetOutputDevice ());
602 uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
603 for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
715 else if (ipv6->GetRoutingProtocol () != 0)
724 route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
963 NS_LOG_WARN (
"No receive buffer space available. Drop.");
1019 NS_LOG_WARN (
"No receive buffer space available. Drop.");
1026 uint8_t icmpType, uint8_t icmpCode,
1029 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1030 (uint32_t)icmpCode << icmpInfo);
1033 m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1039 uint8_t icmpType, uint8_t icmpCode,
1042 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1043 (uint32_t)icmpCode << icmpInfo);
static bool IsMatchingType(const Address &address)
If the Address matches the type.
Ipv6Address GetLocalAddress()
Get the local address.
(abstract) base class of all UdpSockets
bool m_shutdownSend
Send no longer allowed.
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE
Maximum UDP datagram size.
static Ipv4Mask GetOnes(void)
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
Ipv4Mask GetMask(void) const
Get the network mask.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
enum SocketErrno m_errno
Socket error code.
virtual void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
Ipv4Address GetLocal(void) const
Get the local address.
Access to the IPv6 forwarding table, interfaces, and configuration.
bool m_allowBroadcast
Allow send broadcast packets.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
a class to represent an Ipv4 address mask
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
std::queue< Ptr< Packet > > m_deliveryQueue
Queue for incoming packets.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
void SetAddress(Address addr)
Set the tag's address.
virtual int Close(void)
Close a socket.
#define NS_ASSERT(condition)
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
uint32_t GetSize(void) const
bool IsManualIpTos(void) const
Checks if the socket has a specific IPv4 ToS set.
uint32_t m_rxAvailable
Number of available bytes to be received.
bool IsMulticast(void) const
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void SetTos(uint8_t tos)
Set the tag's TOS.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
SocketErrno
Enumeration of the possible errors returned by a socket.
virtual void SetRcvBufSize(uint32_t size)
Set the receiving buffer size.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
bool m_connected
Connection established.
Ipv4Address GetSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
void ForwardIcmp6(Ipv6Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMPv6 packet to pass on to TCP.
a polymophic address class
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
AttributeValue form of a Callback.
void ForwardUp(Ptr< Packet > packet, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
Ptr< NetDevice > GetOutputDevice(void) const
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack...
virtual int ShutdownRecv(void)
virtual int GetSockName(Address &address) const
Get socket address.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
int DoSendTo(Ptr< Packet > p, const Address &daddr)
Send a packet to a specific destination.
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Called by the L3 protocol when it received an ICMP packet to pass on to TCP.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
int DoSend(Ptr< Packet > p)
Send a packet.
uint16_t GetLocalPort()
Get the local port.
void SetNode(Ptr< Node > node)
Set the associated node.
virtual uint32_t GetRcvBufSize(void) const
Get the receiving buffer size.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
UdpSocketImpl()
Create an unbound udp socket.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual int MulticastJoinGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_JOIN_GROUP.
Ipv4Address GetLocalAddress(void)
Get the local address.
bool IsBroadcast(void) const
uint8_t m_ipMulticastTtl
Multicast TTL.
Address m_defaultAddress
Default address.
virtual enum SocketType GetSocketType(void) const
This class implements a tag that carries an address of a packet across the socket interface...
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
virtual int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
Ipv4Address GetSource(void) const
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
static bool IsMatchingType(const Address &address)
#define NS_LOG_LOGIC(msg)
int FinishBind(void)
Finish the binding process.
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
static TypeId GetTypeId(void)
Get the type ID.
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
Access to the Ipv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
virtual void SetIpMulticastLoop(bool loop)
Set the IP multicast loop capability.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
bool m_shutdownRecv
Receive no longer allowed.
static InetSocketAddress ConvertFrom(const Address &address)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Ptr< Node > m_node
the associated node
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
indicates whether the socket has IPV6_TCLASS set.
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
static Ipv4Address GetZero(void)
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack...
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
virtual int ShutdownSend(void)
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
void Disable(void)
Disables the DF (Don't Fragment) flag.
Describes an IPv6 address.
void ForwardUp6(Ptr< Packet > packet, Ipv6Header header, uint16_t port, Ptr< Ipv6Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
Ipv4 addresses are stored in host order in this class.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
a class to store IPv4 address information on an interface
uint32_t m_rcvBufSize
Receive buffer size.
uint16_t GetLocalPort(void)
Get the local port.
Ptr< NetDevice > GetDevice(void) const
Address GetAddress(void) const
Get the tag's address.
void SetUdp(Ptr< UdpL4Protocol > udp)
Set the associated UDP L4 protocol.
bool m_ipMulticastLoop
Allow multicast loop.
virtual int Listen(void)
Listen for incoming connections.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
uint16_t m_defaultPort
Default port.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
static bool IsMatchingType(const Address &addr)
If the address match.
void Enable(void)
Enables the DF (Don't Fragment) flag.
uint16_t GetPort(void) const
Get the port.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
int32_t m_ipMulticastIf
Multicast Interface.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
#define NS_LOG_ERROR(msg)
uint16_t GetPort(void) const
This class implements a tag that carries socket ancillary data to the socket interface.
static Ipv4Address ConvertFrom(const Address &address)
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
indicates whether the socket has IP_TOS set.
Ptr< T > GetObject(void) const
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
SocketType
Enumeration of the possible socket types.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
a unique identifier for an interface.
static const uint8_t PROT_NUMBER
protocol number (0x11)
bool m_mtuDiscover
Allow MTU discovery.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
TypeId SetParent(TypeId tid)
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
static bool IsMatchingType(const Address &address)
NS_LOG_COMPONENT_DEFINE("UdpSocketImpl")
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
virtual bool GetMtuDiscover(void) const
Get the MTU discover capability.
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.