20 #include "ns3/address.h"
21 #include "ns3/address-utils.h"
23 #include "ns3/inet-socket-address.h"
24 #include "ns3/inet6-socket-address.h"
26 #include "ns3/socket.h"
27 #include "ns3/udp-socket.h"
28 #include "ns3/simulator.h"
29 #include "ns3/socket-factory.h"
30 #include "ns3/packet.h"
31 #include "ns3/trace-source-accessor.h"
32 #include "ns3/udp-socket-factory.h"
34 #include "ns3/boolean.h"
47 .SetGroupName(
"Applications")
49 .AddAttribute (
"Local",
50 "The Address on which to Bind the rx socket.",
54 .AddAttribute (
"Protocol",
55 "The type id of the protocol to use for the rx socket.",
59 .AddAttribute (
"EnableSeqTsSizeHeader",
60 "Enable optional header tracing of SeqTsSizeHeader",
64 .AddTraceSource (
"Rx",
65 "A packet has been received",
67 "ns3::Packet::AddressTracedCallback")
68 .AddTraceSource (
"RxWithAddresses",
"A packet has been received",
70 "ns3::Packet::TwoAddressTracedCallback")
71 .AddTraceSource (
"RxWithSeqTsSize",
72 "A packet with SeqTsSize header has been received",
74 "ns3::PacketSink::SeqTsSizeCallback")
104 std::list<Ptr<Socket> >
142 udpSocket->MulticastJoinGroup (0,
m_local);
167 acceptedSocket->
Close ();
182 while ((packet = socket->
RecvFrom (from)))
192 <<
" packet sink received "
193 << packet->
GetSize () <<
" bytes from "
196 <<
" total Rx " <<
m_totalRx <<
" bytes");
201 <<
" packet sink received "
202 << packet->
GetSize () <<
" bytes from "
205 <<
" total Rx " <<
m_totalRx <<
" bytes");
225 auto itBuffer =
m_buffer.find (from);
228 itBuffer =
m_buffer.insert (std::make_pair (from, Create<Packet> (0))).first;
231 buffer = itBuffer->second;
a polymophic address class
AttributeValue implementation for Address.
The base class for all ns3 applications.
virtual void DoDispose(void)
Destructor implementation.
Ptr< Node > GetNode() const
AttributeValue implementation for Boolean.
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.
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.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Receive and consume traffic generated to an IP address and port.
virtual void DoDispose(void)
Destructor implementation.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer
Buffer for received packets.
Ptr< Socket > GetListeningSocket(void) const
TypeId m_tid
Protocol TypeId.
static TypeId GetTypeId(void)
Get the type ID.
Address m_local
Local address to bind to.
std::list< Ptr< Socket > > GetAcceptedSockets(void) const
virtual void StartApplication(void)
Application specific startup code.
std::list< Ptr< Socket > > m_socketList
the accepted sockets
virtual void StopApplication(void)
Application specific shutdown code.
void HandleRead(Ptr< Socket > socket)
Handle a packet received by the application.
uint64_t GetTotalRx() const
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an incoming connection.
void HandlePeerError(Ptr< Socket > socket)
Handle an connection error.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_rxTraceWithAddresses
Callback for tracing the packet Rx events, includes source and destination addresses.
uint64_t m_totalRx
Total bytes received.
bool m_enableSeqTsSizeHeader
Enable or disable the export of SeqTsSize header.
TracedCallback< Ptr< const Packet >, const Address &, const Address &, const SeqTsSizeHeader & > m_rxTraceWithSeqTsSize
Callbacks for tracing the packet Rx events, includes source, destination addresses,...
void HandlePeerClose(Ptr< Socket > socket)
Handle an connection close.
Ptr< Socket > m_socket
Listening socket.
void PacketReceived(const Ptr< Packet > &p, const Address &from, const Address &localAddress)
Packet received: assemble byte stream to extract SeqTsSizeHeader.
static Time Now(void)
Return the current simulation virtual time.
void SetAcceptCallback(Callback< bool, Ptr< Socket >, const Address & > connectionRequest, Callback< void, Ptr< Socket >, const Address & > newConnectionCreated)
Accept connection requests from remote hosts.
virtual int Listen(void)=0
Listen for incoming connections.
virtual int ShutdownSend(void)=0
virtual int GetSockName(Address &address) const =0
Get socket address.
virtual int Close(void)=0
Close a socket.
void SetCloseCallbacks(Callback< void, Ptr< Socket > > normalClose, Callback< void, Ptr< Socket > > errorClose)
Detect socket recv() events such as graceful shutdown or error.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AttributeValue implementation for TypeId.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeAddressChecker(void)
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
Callback< R, Ts... > MakeNullCallback(void)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...