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/ipv6-l3-protocol.h"
30 #include "ns3/ipv4-header.h"
31 #include "ns3/ipv4-routing-protocol.h"
32 #include "ns3/ipv6-routing-protocol.h"
33 #include "ns3/udp-socket-factory.h"
34 #include "ns3/trace-source-accessor.h"
35 #include "ns3/ipv4-packet-info-tag.h"
36 #include "ns3/ipv6-packet-info-tag.h"
60 .SetGroupName (
"Internet")
62 .AddTraceSource (
"Drop",
63 "Drop UDP packet due to receive buffer overflow",
65 "ns3::Packet::TracedCallback")
66 .AddAttribute (
"IcmpCallback",
"Callback invoked whenever an icmp error is received on this socket.",
70 .AddAttribute (
"IcmpCallback6",
"Callback invoked whenever an icmpv6 error is received on this socket.",
83 m_errno (ERROR_NOTERROR),
84 m_shutdownSend (false),
85 m_shutdownRecv (false),
335 ipv6l3->AddMulticastAddress (ipv6);
582 for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
595 NS_LOG_LOGIC (
"Sending one copy from " << addri <<
" to " << dest);
612 else if (ipv4->GetRoutingProtocol () != 0)
621 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
628 uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->GetOutputDevice ());
629 uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
630 for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
750 else if (ipv6->GetRoutingProtocol () != 0)
759 route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
809 uint8_t tos = transport.
GetTos ();
972 if (oldBoundNetDevice)
974 uint32_t index = ipv6l3->GetInterfaceForDevice (oldBoundNetDevice);
984 uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
1053 NS_LOG_WARN (
"No receive buffer space available. Drop.");
1113 NS_LOG_WARN (
"No receive buffer space available. Drop.");
1120 uint8_t icmpType, uint8_t icmpCode,
1123 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1124 (uint32_t)icmpCode << icmpInfo);
1127 m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
1133 uint8_t icmpType, uint8_t icmpCode,
1136 NS_LOG_FUNCTION (
this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
1137 (uint32_t)icmpCode << icmpInfo);
1229 if (filterMode ==
INCLUDE && sourceAddresses.empty ())
1235 NS_ASSERT_MSG (index >= 0,
"Interface without a valid index");
1236 ipv6l3->RemoveMulticastAddress (
address, index);
1240 ipv6l3->RemoveMulticastAddress (
address);
1249 NS_ASSERT_MSG (index >= 0,
"Interface without a valid index");
1250 ipv6l3->AddMulticastAddress (
address, index);
1254 ipv6l3->AddMulticastAddress (
address);
a polymophic address class
AttributeValue implementation for Callback.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
uint16_t GetPort(void) const
Get the port.
uint8_t GetTos(void) const
uint16_t GetPort(void) const
Ipv4Address GetIpv4(void) const
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
bool IsMulticast(void) const
static Ipv4Address ConvertFrom(const Address &address)
static bool IsMatchingType(const Address &address)
bool IsBroadcast(void) const
static Ipv4Address GetAny(void)
static Ipv4Address GetZero(void)
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
uint16_t GetLocalPort(void)
Get the local port.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ipv4Address GetLocalAddress(void)
Get the local address.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
Ipv4Address GetLocal(void) const
Get the local address.
Ptr< NetDevice > GetDevice(void) const
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
void SetAddress(Ipv4Address addr)
Set the tag's address.
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
Describes an IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
Ipv6Address GetLocalAddress()
Get the local address.
uint16_t GetLocalPort()
Get the local port.
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Access to the IPv6 forwarding table, interfaces, and configuration.
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
IPv6 layer implementation.
This class implements a tag that carries socket ancillary data to the socket interface.
void SetTrafficClass(uint8_t tclass)
Set the tag's Traffic Class.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
void SetHoplimit(uint8_t ttl)
Set the tag's Hop Limit.
void SetAddress(Ipv6Address addr)
Set the tag's address.
virtual uint32_t GetIfIndex(void) const =0
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
uint8_t GetPriority(void) const
Query the priority value of this socket.
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack.
SocketType
Enumeration of the possible socket types.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
SocketErrno
Enumeration of the possible errors returned by a socket.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
virtual void Ipv6LeaveGroup(void)
Leaves IPv6 multicast group this socket is joined to.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
indicates whether the socket has IP_TOS set.
void SetTos(uint8_t tos)
Set the tag's TOS.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
indicates whether the socket has IPV6_TCLASS set.
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
indicates whether the socket has a priority set.
void SetPriority(uint8_t priority)
Set the tag's priority.
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
void Disable(void)
Disables the DF (Don't Fragment) flag.
void Enable(void)
Enables the DF (Don't Fragment) flag.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
static const uint8_t PROT_NUMBER
protocol number (0x11)
(abstract) base class of all UdpSockets
A sockets interface to UDP.
virtual void SetRcvBufSize(uint32_t size)
Set the receiving buffer size.
void SetUdp(Ptr< UdpL4Protocol > udp)
Set the associated UDP L4 protocol.
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
virtual bool GetMtuDiscover(void) const
Get the MTU discover capability.
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
bool m_allowBroadcast
Allow send broadcast packets.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
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.
virtual int GetSockName(Address &address) const
Get socket address.
int DoSendTo(Ptr< Packet > p, Ipv4Address daddr, uint16_t dport, uint8_t tos)
Send a packet to a specific destination and port (IPv4)
virtual int Listen(void)
Listen for incoming connections.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
bool m_connected
Connection established.
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.
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
static TypeId GetTypeId(void)
Get the type ID.
uint8_t m_ipMulticastTtl
Multicast TTL.
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.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
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.
virtual enum SocketType GetSocketType(void) const
virtual int ShutdownRecv(void)
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
virtual void Ipv6JoinGroup(Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
Joins a IPv6 multicast group.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Queue for incoming packets.
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
virtual void SetIpMulticastLoop(bool loop)
Set the IP multicast loop capability.
uint32_t m_rxAvailable
Number of available bytes to be received.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
uint32_t m_rcvBufSize
Receive buffer size.
Address m_defaultAddress
Default address.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
UdpSocketImpl()
Create an unbound udp socket.
virtual int ShutdownSend(void)
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
uint16_t m_defaultPort
Default port.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
virtual int Close(void)
Close a socket.
bool m_shutdownSend
Send no longer allowed.
bool m_ipMulticastLoop
Allow multicast loop.
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
int FinishBind(void)
Finish the binding process.
virtual int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
bool m_mtuDiscover
Allow MTU discovery.
bool m_shutdownRecv
Receive no longer allowed.
void SetNode(Ptr< Node > node)
Set the associated node.
enum SocketErrno m_errno
Socket error code.
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 int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
virtual void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
virtual int MulticastJoinGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_JOIN_GROUP.
int DoSend(Ptr< Packet > p)
Send a packet.
Ptr< Node > m_node
the associated node
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.
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeCallbackAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeCallbackChecker(void)
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE
Maximum UDP datagram size.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...