9#include "ns3/address-utils.h"
10#include "ns3/inet-socket-address.h"
11#include "ns3/inet6-socket-address.h"
12#include "ns3/ipv4-address.h"
13#include "ns3/ipv6-address.h"
15#include "ns3/nstime.h"
16#include "ns3/packet.h"
17#include "ns3/simulator.h"
18#include "ns3/socket-factory.h"
19#include "ns3/socket.h"
20#include "ns3/udp-socket.h"
21#include "ns3/uinteger.h"
34 TypeId(
"ns3::UdpEchoServer")
36 .SetGroupName(
"Applications")
39 "The Type of Service used to send IPv4 packets. "
40 "All 8 bits of the TOS byte are set (including ECN bits).",
44 .AddTraceSource(
"RxWithAddresses",
45 "A packet has been received",
47 "ns3::Packet::TwoAddressTracedCallback");
69 if (local.IsInvalid())
83 udpSocket->MulticastJoinGroup(0,
m_local);
106 udpSocket->MulticastJoinGroup(0, local);
123 while (
auto packet = socket->RecvFrom(from))
126 socket->GetSockName(localAddress);
133 << packet->GetSize() <<
" bytes from "
140 << packet->GetSize() <<
" bytes from "
145 packet->RemoveAllPacketTags();
146 packet->RemoveAllByteTags();
149 socket->SendTo(packet, 0, from);
154 << packet->GetSize() <<
" bytes to "
161 << packet->GetSize() <<
" bytes to "
a polymophic address class
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &addr)
If the address match.
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
static Ipv4Address GetAny()
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
ns3::TracedCallback< Ptr< const Packet > > m_rxTraceWithoutAddress
Callbacks for tracing the packet Rx events.
Ptr< Socket > m_socket6
IPv6 Socket (used if only port is specified).
TypeId m_protocolTid
Protocol TypeId value.
SinkApplication(uint16_t defaultPort=0)
Constructor.
Address m_local
Local address to bind to (address and port).
Ptr< Socket > m_socket
Socket (IPv4 or IPv6, depending on local address).
uint32_t m_port
Local port to bind to.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_rxTraceWithAddresses
Callbacks for tracing the packet Rx events, includes source and destination addresses.
static constexpr uint16_t DEFAULT_PORT
default port
uint8_t m_tos
The packets Type of Service.
static TypeId GetTypeId()
Get the type ID.
~UdpEchoServer() override
void DoStartApplication() override
Application specific startup code for child subclasses.
void HandleRead(Ptr< Socket > socket)
Handle a packet reception.
Hold an unsigned integer type.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#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_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#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.
bool IsMulticast(const Address &ad)
Address family-independent test for a multicast address.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.