22 #include "ns3/nstime.h"
23 #include "ns3/packet-socket-address.h"
24 #include "ns3/packet-socket.h"
25 #include "ns3/packet-socket-factory.h"
26 #include "ns3/socket.h"
27 #include "ns3/simulator.h"
28 #include "ns3/socket-factory.h"
29 #include "ns3/packet.h"
30 #include "ns3/uinteger.h"
31 #include "ns3/abort.h"
47 .SetGroupName(
"Network")
49 .AddTraceSource (
"Rx",
"A packet has been received",
51 "ns3::Packet::AddressTracedCallback")
115 while ((packet = socket->
RecvFrom (from)))
122 <<
"s packet sink received "
123 << packet->
GetSize () <<
" bytes from "
125 <<
" total Rx " <<
m_pktRx <<
" packets"
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool m_localAddressSet
Sanity check.
void SetLocal(PacketSocketAddress addr)
set the local address and protocol to be used
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
PacketSocketAddress m_localAddress
Local address.
uint32_t m_bytesRx
Total bytes received.
uint32_t m_pktRx
The number of received packets.
an address for a packet socket
static bool IsMatchingType(const Address &address)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Callback< R > MakeNullCallback(void)
virtual void StartApplication(void)
Application specific startup code.
void HandleRead(Ptr< Socket > socket)
Handle a packet received by the application.
a polymophic address class
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced Callback: received packets, source address.
The base class for all ns3 applications.
Ptr< Node > GetNode() const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void SetRecvCallback(Callback< void, Ptr< Socket > >)
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...
Ptr< Socket > m_socket
Socket.
virtual void DoDispose(void)
Destructor implementation.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual void DoDispose(void)
Destructor implementation.
static Time Now(void)
Return the current simulation virtual time.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
static TypeId GetTypeId(void)
Get the type ID.
virtual void StopApplication(void)
Application specific shutdown code.
A server using PacketSocket.
static PacketSocketAddress ConvertFrom(const Address &address)
virtual ~PacketSocketServer()
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.
virtual int Close(void)=0
Close a socket.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
static TypeId LookupByName(std::string name)
Get a TypeId by name.