|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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 unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
UdpSocketImpl()
Create an unbound udp socket.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
static bool IsMatchingType(const Address &addr)
If the address match.
virtual void SetIpMulticastLoop(bool loop)
Set the IP multicast loop capability.
Ipv6EndPoint * m_endPoint6
the IPv6 endpoint
int32_t m_ipMulticastIf
Multicast Interface.
static bool IsMatchingType(const Address &address)
If the Address matches the type.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
static bool IsMatchingType(const Address &address)
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
virtual void SetRcvBufSize(uint32_t size)
Set the receiving buffer size.
virtual int GetSockName(Address &address) const
Get socket address.
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.
TracedCallback< Ptr< const Packet > > m_dropTrace
Trace for dropped packets.
static bool IsMatchingType(const Address &address)
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
SocketErrno
Enumeration of the possible errors returned by a socket.
uint16_t GetPort(void) const
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
bool IsIpv4MappedAddress() const
If the address is an IPv4-mapped address.
bool m_ipMulticastLoop
Allow multicast loop.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback
ICMP callback.
uint32_t m_rcvBufSize
Receive buffer size.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
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 m_shutdownRecv
Receive no longer allowed.
bool m_connected
Connection established.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< NetDevice > GetDevice(void) const
Ipv6Address GetLocalAddress()
Get the local address.
void SetAddress(Ipv6Address addr)
Set the tag's address.
virtual void SetMtuDiscover(bool discover)
Set the MTU discover capability.
IPv6 layer implementation.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
virtual bool GetIpMulticastLoop(void) const
Get the IP multicast loop capability.
virtual int Close(void)
Close a socket.
bool m_shutdownSend
Send no longer allowed.
void SetHoplimit(uint8_t ttl)
Set the tag's Hop Limit.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
bool IsIpv6RecvHopLimit(void) const
Ask if the socket is currently passing information about IPv6 Hop Limit up the stack.
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.
void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
bool m_allowBroadcast
Allow send broadcast packets.
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
virtual enum SocketType GetSocketType(void) const
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
Ptr< UdpL4Protocol > m_udp
the associated UDP L4 protocol
bool IsIpv6RecvTclass(void) const
Ask if the socket is currently passing information about IPv6 Traffic Class up the stack.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
Ipv6MulticastFilterMode
Enumeration of the possible filter of a socket.
virtual int MulticastJoinGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_JOIN_GROUP.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint16_t GetPort(void) const
Get the port.
uint16_t m_defaultPort
Default port.
virtual int Listen(void)
Listen for incoming connections.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
virtual uint8_t GetIpv6HopLimit(void) const
Query the value of IP Hop Limit field of this socket.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
Ptr< Node > m_node
the associated node
void SetNode(Ptr< Node > node)
Set the associated node.
Access to the IPv4 forwarding table, interfaces, and configuration.
Address m_defaultAddress
Default address.
bool IsMulticast(void) const
void SetPriority(uint8_t priority)
Set the tag's priority.
static Ipv4Address GetZero(void)
Ptr< const AttributeChecker > MakeCallbackChecker(void)
uint16_t GetLocalPort(void)
Get the local port.
(abstract) base class of all UdpSockets
void Enable(void)
Enables the DF (Don't Fragment) flag.
This class implements a tag that carries socket ancillary data to the socket interface.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
a polymophic address class
virtual bool GetMtuDiscover(void) const
Get the MTU discover capability.
a class to store IPv4 address information on an interface
virtual void Ipv6JoinGroup(Ipv6Address address, Socket::Ipv6MulticastFilterMode filterMode, std::vector< Ipv6Address > sourceAddresses)
Joins a IPv6 multicast group.
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.
Ptr< const AttributeAccessor > MakeCallbackAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ipv4Address GetIpv4(void) const
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
void Destroy6(void)
Kill this socket by zeroing its attributes (IPv6)
Ipv4Address GetIpv4MappedAddress() const
Return the Ipv4 address.
uint16_t GetLocalPort()
Get the local port.
static Ipv6Address ConvertFrom(const Address &address)
Convert the Address object into an Ipv6Address ones.
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error.
SocketType
Enumeration of the possible socket types.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
AttributeValue implementation for Callback.
Ipv4Address GetLocalAddress(void)
Get the local address.
bool IsManualIpv6HopLimit(void) const
Checks if the socket has a specific IPv6 Hop Limit set.
indicates whether the socket has IPV6_TCLASS set.
virtual int ShutdownRecv(void)
bool m_mtuDiscover
Allow MTU discovery.
virtual void SetIpMulticastTtl(uint8_t ipTtl)
Set the IP multicast TTL.
bool IsBroadcast(void) const
void SetUdp(Ptr< UdpL4Protocol > udp)
Set the associated UDP L4 protocol.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual void Ipv6LeaveGroup(void)
Leaves IPv6 multicast group this socket is joined to.
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Queue for incoming packets.
void DeallocateEndPoint(void)
Deallocate m_endPoint and m_endPoint6.
static const uint8_t PROT_NUMBER
protocol number (0x11)
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &address)
Send data to a specified peer.
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
A sockets interface to UDP.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
uint8_t m_ipMulticastTtl
Multicast TTL.
int DoSendTo(Ptr< Packet > p, Ipv4Address daddr, uint16_t dport, uint8_t tos)
Send a packet to a specific destination and port (IPv4)
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
indicates whether the socket has a priority set.
bool IsManualIpv6Tclass(void) const
Checks if the socket has a specific IPv6 Tclass set.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
static Ipv4Address GetAny(void)
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
enum SocketErrno m_errno
Socket error code.
void SetTclass(uint8_t tclass)
Set the tag's Tclass.
indicates whether the socket has IP_TOS set.
void SetTos(uint8_t tos)
Set the tag's TOS.
virtual int32_t GetIpMulticastIf(void) const
Get the IP multicast interface.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
uint8_t GetPriority(void) const
Query the priority value of this socket.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
uint8_t GetTos(void) const
Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > m_icmpCallback6
ICMPv6 callback.
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Ipv4Address GetLocal(void) const
Get the local address.
Access to the IPv6 forwarding table, interfaces, and configuration.
void Disable(void)
Disables the DF (Don't Fragment) flag.
virtual uint32_t GetRcvBufSize(void) const
Get the receiving buffer size.
int DoSend(Ptr< Packet > p)
Send a packet.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv6Header, uint16_t, Ptr< Ipv6Interface > > callback)
Set the reception callback.
static TypeId GetTypeId(void)
Get the type ID.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
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 void SetIpMulticastIf(int32_t ipIf)
Set the IP multicast interface.
void SetIcmpCallback(Callback< void, Ipv6Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
bool IsAny() const
If the IPv6 address is the "Any" address.
int FinishBind(void)
Finish the binding process.
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
void SetAddress(Ipv4Address addr)
Set the tag's address.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
void SetRxEnabled(bool enabled)
Enable or Disable the endpoint Rx capability.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
void SetIcmpCallback(Callback< void, Ipv4Address, uint8_t, uint8_t, uint8_t, uint32_t > callback)
Set the ICMP callback.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
Ipv6Address m_ipv6MulticastGroupAddress
IPv6 multicast group address.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
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.
virtual uint32_t GetIfIndex(void) const =0
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
virtual int MulticastLeaveGroup(uint32_t interfaceIndex, const Address &groupAddress)
Corresponds to socket option MCAST_LEAVE_GROUP.
uint8_t GetIpv6Tclass(void) const
Query the value of IPv6 Traffic Class field of this socket.
indicates whether packets should be sent out with the DF (Don't Fragment) flag set.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
static Ipv4Address ConvertFrom(const Address &address)
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack.
virtual int ShutdownSend(void)
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
void SetTrafficClass(uint8_t tclass)
Set the tag's Traffic Class.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
static const uint32_t MAX_IPV4_UDP_DATAGRAM_SIZE
Maximum UDP datagram size.
uint32_t m_rxAvailable
Number of available bytes to be received.
virtual uint8_t GetIpMulticastTtl(void) const
Get the IP multicast TTL.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.