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);
588 for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
601 NS_LOG_LOGIC (
"Sending one copy from " << addri <<
" to " << dest);
618 else if (ipv4->GetRoutingProtocol () != 0)
627 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
633 uint32_t outputIfIndex = ipv4->GetInterfaceForDevice (route->
GetOutputDevice ());
634 uint32_t ifNAddr = ipv4->GetNAddresses (outputIfIndex);
635 for (uint32_t addrI = 0; addrI < ifNAddr; ++addrI)
755 else if (ipv6->GetRoutingProtocol () != 0)
764 route = ipv6->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
814 uint8_t tos = transport.
GetTos ();
977 if (oldBoundNetDevice)
979 uint32_t index = ipv6l3->GetInterfaceForDevice (oldBoundNetDevice);
989 uint32_t index = ipv6l3->GetInterfaceForDevice (netdevice);
1056 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);
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 Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
bool IsBroadcast(void) const
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
enum SocketErrno m_errno
Socket error code.
virtual int GetSockName(Address &address) const
Get socket address.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
virtual void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack...
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
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.
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.
IPv6 layer implementation.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
uint8_t GetTos(void) const
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error...
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
virtual int Close(void)
Close a socket.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
uint32_t m_rxAvailable
Number of available bytes to be received.
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
virtual enum SocketType GetSocketType(void) const
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
void SetTos(uint8_t tos)
Set the tag's TOS.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
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.
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
virtual void Ipv6JoinGroup(Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
Joins a IPv6 multicast group.
A sockets interface to UDP.
bool m_connected
Connection established.
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 implementation for 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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
virtual int ShutdownRecv(void)
bool IsMulticast(void) const
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
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.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
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 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.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Ptr< const AttributeAccessor > MakeCallbackAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack...
Ipv4Address GetLocalAddress(void)
Get the local address.
uint8_t m_ipMulticastTtl
Multicast TTL.
indicates whether the socket has a priority set.
Address m_defaultAddress
Default address.
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
static bool IsMatchingType(const Address &address)
int FinishBind(void)
Finish the binding process.
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
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< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
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.
Ptr< NetDevice > GetOutputDevice(void) const
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ptr< NetDevice > GetDevice(void) const
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
Ptr< Node > m_node
the associated node
uint16_t GetPort(void) const
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
indicates whether the socket has IPV6_TCLASS set.
virtual void Ipv6LeaveGroup(void)
Leaves IPv6 multicast group this socket is joined to.
static Ipv4Address GetZero(void)
Ptr< const AttributeChecker > MakeCallbackChecker(void)
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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 int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
virtual int ShutdownSend(void)
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
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 bool GetMtuDiscover(void) const
Get the MTU discover capability.
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
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
uint32_t m_rcvBufSize
Receive buffer size.
uint16_t GetLocalPort(void)
Get the local port.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
virtual uint32_t GetRcvBufSize(void) const
Get the receiving buffer size.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
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.
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
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.
Ipv4Address GetLocal(void) const
Get the local address.
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
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.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
This class implements a tag that carries socket ancillary data to the socket interface.
static Ipv4Address ConvertFrom(const Address &address)
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Queue for incoming packets.
uint16_t GetPort(void) const
Get the port.
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
Ipv4Address GetSource(void) const
void SetPriority(uint8_t priority)
Set the tag's priority.
indicates whether the socket has IP_TOS set.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
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.
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
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)
Set the parent TypeId.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
static bool IsMatchingType(const Address &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 uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
uint8_t GetPriority(void) const
Query the priority value of this socket.
bool IsAny() const
If the IPv6 address is the "Any" address.
Ipv4Address GetIpv4(void) const
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.