29#include "ns3/core-module.h"
30#include "ns3/internet-module.h"
31#include "ns3/network-module.h"
32#include "ns3/stats-module.h"
45 .AddConstructor<Sender>()
46 .AddAttribute(
"PacketSize",
47 "The size of packets transmitted.",
50 MakeUintegerChecker<uint32_t>(1))
51 .AddAttribute(
"Destination",
52 "Target host address.",
55 MakeIpv4AddressChecker())
57 "Destination app port.",
60 MakeUintegerChecker<uint32_t>())
61 .AddAttribute(
"NumPackets",
62 "Total number of packets to send.",
65 MakeUintegerChecker<uint32_t>(1))
66 .AddAttribute(
"Interval",
67 "Delay between transmissions.",
68 StringValue(
"ns3::ConstantRandomVariable[Constant=0.5]"),
70 MakePointerChecker<RandomVariableStream>())
72 "A new packet is created and is sent",
74 "ns3::Packet::TracedCallback");
81 m_interval = CreateObject<ConstantRandomVariable>();
97 Application::DoDispose();
109 m_socket = socketFactory->CreateSocket();
165 .AddConstructor<Receiver>()
166 .AddAttribute(
"Port",
170 MakeUintegerChecker<uint32_t>());
194 Application::DoDispose();
206 m_socket = socketFactory->CreateSocket();
250 while ((packet = socket->
RecvFrom(from)))
252 if (InetSocketAddress::IsMatchingType(from))
255 << InetSocketAddress::ConvertFrom(from).GetIpv4());
290 .AddConstructor<TimestampTag>()
291 .AddAttribute(
"Timestamp",
292 "Some momentous point in time!",
315 i.
Write((
const uint8_t*)&t, 8);
322 i.
Read((uint8_t*)&t, 8);
void StopApplication() override
Application specific shutdown code.
uint32_t m_port
Listening port.
Ptr< Socket > m_socket
Receiving socket.
void DoDispose() override
Destructor implementation.
void SetDelayTracker(Ptr< TimeMinMaxAvgTotalCalculator > delay)
Set the delay tracker for received packets.
static TypeId GetTypeId()
Get the type ID.
void Receive(Ptr< Socket > socket)
Receive a packet.
Ptr< CounterCalculator<> > m_calc
Counter of the number of received packets.
void StartApplication() override
Application specific startup code.
void SetCounter(Ptr< CounterCalculator<> > calc)
Set the counter calculator for received packets.
Ptr< TimeMinMaxAvgTotalCalculator > m_delay
Delay calculator.
Ptr< Socket > m_socket
Sending socket.
void SendPacket()
Send a packet.
uint32_t m_count
Number of packets sent.
uint32_t m_destPort
Destination port.
Ptr< ConstantRandomVariable > m_interval
Rng for sending packets.
void StopApplication() override
Application specific shutdown code.
Ipv4Address m_destAddr
Destination address.
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Get the type ID.
EventId m_sendEvent
Send packet event.
uint32_t m_numPkts
Number of packets to send.
TracedCallback< Ptr< const Packet > > m_txTrace
Tx TracedCallback.
void StartApplication() override
Application specific startup code.
uint32_t m_pktSize
The packet size.
Timestamp tag - it carries when the packet has been sent.
void Print(std::ostream &os) const override
void Serialize(TagBuffer i) const override
static TypeId GetTypeId()
Get the type ID.
uint32_t GetSerializedSize() const override
void SetTimestamp(Time time)
Set the timestamp.
void Deserialize(TagBuffer i) override
Time GetTimestamp() const
Get the timestamp.
Time m_timestamp
Timestamp.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
a polymophic address class
The base class for all ns3 applications.
Ptr< Node > GetNode() const
double GetValue(double constant)
Get the next random value, as a double equal to the argument.
Template class CounterCalculator.
A class for an empty attribute value.
AttributeValue implementation for Ipv4Address.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Smart pointer class similar to boost::intrusive_ptr.
Object to create transport layer instances that provide a socket API to applications.
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.
void SetRecvCallback(Callback< void, Ptr< Socket > > receivedData)
Notify application when new data is available to be read.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
Hold variables of type string.
void Read(uint8_t *buffer, uint32_t size)
void Write(const uint8_t *buffer, uint32_t size)
tag a set of bytes in a packet
Simulation virtual time values and global simulation resolution.
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
void Update(const Time i)
Updates all variables of TimeMinMaxAvgTotalCalculator.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Callback< R, Args... > MakeNullCallback()
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
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< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.