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"
55 .AddConstructor<UdpSocketImpl> ()
56 .AddTraceSource (
"Drop",
"Drop UDP packet due to receive buffer overflow",
58 .AddAttribute (
"IcmpCallback",
"Callback invoked whenever an icmp error is received on this socket.",
61 MakeCallbackChecker ())
62 .AddAttribute (
"IcmpCallback6",
"Callback invoked whenever an icmpv6 error is received on this socket.",
65 MakeCallbackChecker ())
75 m_errno (ERROR_NOTERROR),
76 m_shutdownSend (false),
77 m_shutdownRecv (false),
524 for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
541 NS_LOG_LOGIC (
"Sending one copy from " << addri <<
" to " << dest
542 <<
" (mask is " << maski <<
")");
552 NS_LOG_LOGIC (
"Sending one copy from " << addri <<
" to " << bcast
553 <<
" (mask is " << maski <<
")");
571 else if (ipv4->GetRoutingProtocol () != 0)
580 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
586 uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->
GetOutputDevice ());
587 uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
588 for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
700 else if (ipv6->GetRoutingProtocol () != 0)
709 route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
948 NS_LOG_WARN (
"No receive buffer space available. Drop.");
996 NS_LOG_WARN (
"No receive buffer space available. Drop.");
1003 uint8_t icmpType, uint8_t icmpCode,
1006 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1007 (uint32_t)icmpCode << icmpInfo);
1010 m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1016 uint8_t icmpType, uint8_t icmpCode,
1019 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1020 (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
void SetTclass(uint8_t tclass)
static const uint32_t MAX_IPV4_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
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Ptr< UdpL4Protocol > m_udp
virtual bool GetIpMulticastLoop(void) const
Ipv4Mask GetMask(void) const
virtual uint8_t GetIpTtl(void) const
Ipv4EndPoint * m_endPoint
uint8_t GetIpTos(void) const
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
virtual void SetIpMulticastIf(int32_t ipIf)
Ipv4Address GetLocal(void) const
Access to the IPv6 forwarding table, interfaces, and configuration.
void NotifyDataRecv(void)
a class to represent an Ipv4 address mask
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Ptr< Packet > Recv(void)
Read a single packet from the socket.
void SetDestroyCallback(Callback< void > callback)
std::queue< Ptr< Packet > > m_deliveryQueue
void AddPacketTag(const Tag &tag) const
void SetAddress(Address addr)
virtual int Close(void)
Close a socket.
#define NS_ASSERT(condition)
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
virtual uint8_t GetIpMulticastTtl(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
bool IsManualIpTos(void) const
bool IsMulticast(void) const
void BindToNetDevice(Ptr< NetDevice > netdevice)
virtual uint8_t GetIpv6HopLimit(void) const
#define NS_LOG_FUNCTION_NOARGS()
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...
virtual void SetRcvBufSize(uint32_t size)
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
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)
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.
virtual enum SocketErrno GetErrno(void) const
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
bool PeekPacketTag(Tag &tag) const
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
int DoSendTo(Ptr< Packet > p, const Address &daddr)
void ForwardIcmp(Ipv4Address icmpSource, uint8_t icmpTtl, uint8_t icmpType, uint8_t icmpCode, uint32_t icmpInfo)
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
int DoSend(Ptr< Packet > p)
uint16_t GetLocalPort()
Get the local port.
void SetNode(Ptr< Node > node)
virtual uint32_t GetRcvBufSize(void) const
virtual uint32_t GetRxAvailable(void) const
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this 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.
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
Ipv4Address GetLocalAddress(void)
bool IsBroadcast(void) const
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)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
virtual int32_t GetIpMulticastIf(void) const
bool IsManualIpv6Tclass(void) const
void NotifyDataSent(uint32_t size)
Ipv4Address GetSource(void) const
static bool IsMatchingType(const Address &address)
#define NS_LOG_LOGIC(msg)
void SetHopLimit(uint8_t hopLimit)
static TypeId GetTypeId(void)
void NotifyConnectionSucceeded(void)
Access to the Ipv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
bool IsManualIpv6HopLimit(void) const
virtual void SetIpMulticastLoop(bool loop)
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
static InetSocketAddress ConvertFrom(const Address &address)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
uint8_t GetIpv6Tclass(void) const
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...
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t > callback)
Set the reception callback.
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.
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
virtual uint32_t GetTxAvailable(void) const
Ipv4Address GetBroadcast(void) const
Ptr< NetDevice > m_boundnetdevice
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
a class to store IPv4 address information on an interface
uint16_t GetLocalPort(void)
Ptr< NetDevice > GetDevice(void) const
Address GetAddress(void) const
void SetUdp(Ptr< UdpL4Protocol > udp)
virtual int Listen(void)
Listen for incoming connections.
bool RemovePacketTag(Tag &tag)
indicated whether packets should be sent out with the DF flag set.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
Ipv6EndPoint * m_endPoint6
static bool IsMatchingType(const Address &addr)
If the address match.
uint16_t GetPort(void) const
Get the port.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
void ForwardUp6(Ptr< Packet > p, Ipv6Header header, uint16_t port)
void ForwardUp(Ptr< Packet > p, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
#define NS_LOG_ERROR(msg)
uint16_t GetPort(void) const
static Ipv4Address ConvertFrom(const Address &address)
TracedCallback< Ptr< const Packet > > m_dropTrace
Ptr< T > GetObject(void) const
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
a unique identifier for an interface.
static const uint8_t PROT_NUMBER
bool IsIpv4MappedAddress()
If the address is an IPv4-mapped address.
void NotifySend(uint32_t spaceAvailable)
TypeId SetParent(TypeId tid)
static bool IsMatchingType(const Address &address)
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
virtual bool GetMtuDiscover(void) const
virtual void SetIpMulticastTtl(uint8_t ipTtl)
virtual Ptr< Node > GetNode(void) const
void SetRecvIf(uint32_t ifindex)