21#include "ns3/address-utils.h"
22#include "ns3/address.h"
23#include "ns3/boolean.h"
24#include "ns3/inet-socket-address.h"
25#include "ns3/inet6-socket-address.h"
26#include "ns3/ipv4-packet-info-tag.h"
27#include "ns3/ipv6-packet-info-tag.h"
30#include "ns3/packet.h"
31#include "ns3/simulator.h"
32#include "ns3/socket-factory.h"
33#include "ns3/socket.h"
34#include "ns3/trace-source-accessor.h"
35#include "ns3/udp-socket-factory.h"
36#include "ns3/udp-socket.h"
51 .SetGroupName(
"Applications")
53 .AddAttribute(
"Local",
54 "The Address on which to Bind the rx socket.",
58 .AddAttribute(
"Protocol",
59 "The type id of the protocol to use for the rx socket.",
63 .AddAttribute(
"EnableSeqTsSizeHeader",
64 "Enable optional header tracing of SeqTsSizeHeader",
69 "A packet has been received",
71 "ns3::Packet::AddressTracedCallback")
72 .AddTraceSource(
"RxWithAddresses",
73 "A packet has been received",
75 "ns3::Packet::TwoAddressTracedCallback")
76 .AddTraceSource(
"RxWithSeqTsSize",
77 "A packet with SeqTsSize header has been received",
79 "ns3::PacketSink::SeqTsSizeCallback");
109std::list<Ptr<Socket>>
148 udpSocket->MulticastJoinGroup(0,
m_local);
185 acceptedSocket->Close();
201 while ((packet = socket->RecvFrom(from)))
203 if (packet->GetSize() == 0)
211 << packet->GetSize() <<
" bytes from "
219 << packet->GetSize() <<
" bytes from "
222 <<
" total Rx " <<
m_totalRx <<
" bytes");
230 if (packet->RemovePacketTag(interfaceInfo))
234 else if (packet->RemovePacketTag(interface6Info))
240 socket->GetSockName(localAddress);
259 auto itBuffer =
m_buffer.find(from);
262 itBuffer =
m_buffer.insert(std::make_pair(from, Create<Packet>(0))).first;
265 buffer = itBuffer->second;
267 buffer->PeekHeader(header);
271 while (buffer->GetSize() >= header.
GetSize())
274 << buffer->GetSize());
278 complete->RemoveHeader(header);
284 buffer->PeekHeader(header);
a polymophic address class
AttributeValue implementation for Address.
The base class for all ns3 applications.
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
AttributeValue implementation for Boolean.
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
uint16_t GetPort() const
Get the port.
static bool IsMatchingType(const Address &addr)
If the address match.
Ipv6Address GetIpv6() const
Get the IPv6 address.
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
Ipv4Address GetAddress() const
Get the tag's address.
This class implements a tag that carries socket ancillary data to the socket interface.
Ipv6Address GetAddress() const
Get the tag's address.
Receive and consume traffic generated to an IP address and port.
static TypeId GetTypeId()
Get the type ID.
std::unordered_map< Address, Ptr< Packet >, AddressHash > m_buffer
Buffer for received packets.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_rxTraceWithAddresses
Callback for tracing the packet Rx events, includes source and destination addresses.
void StopApplication() override
Application specific shutdown code.
TypeId m_tid
Protocol TypeId.
Ptr< Socket > GetListeningSocket() const
uint16_t m_localPort
Local port to bind to.
Address m_local
Local address to bind to (address and port)
std::list< Ptr< Socket > > m_socketList
the accepted sockets
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 &, const Address &, const SeqTsSizeHeader & > m_rxTraceWithSeqTsSize
Callbacks for tracing the packet Rx events, includes source, destination addresses,...
uint64_t m_totalRx
Total bytes received.
void StartApplication() override
Application specific startup code.
void DoDispose() override
Destructor implementation.
bool m_enableSeqTsSizeHeader
Enable or disable the export of SeqTsSize header.
std::list< Ptr< Socket > > GetAcceptedSockets() const
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.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
void SetRecvPktInfo(bool flag)
Enable/Disable receive packet information to socket.
void SetAcceptCallback(Callback< bool, Ptr< Socket >, const Address & > connectionRequest, Callback< void, Ptr< Socket >, const Address & > newConnectionCreated)
Accept connection requests from remote hosts.
virtual int ShutdownSend()=0
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 Close()=0
Close a socket.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual int Listen()=0
Listen for incoming connections.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AttributeValue implementation for TypeId.
static TypeId GetTypeId()
Get the type ID.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeTypeIdChecker()
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Callback< R, Args... > MakeNullCallback()
#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, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...