|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
26 #include "ns3/address.h"
27 #include "ns3/inet-socket-address.h"
28 #include "ns3/inet6-socket-address.h"
29 #include "ns3/packet-socket-address.h"
31 #include "ns3/nstime.h"
32 #include "ns3/data-rate.h"
33 #include "ns3/random-variable-stream.h"
34 #include "ns3/socket.h"
35 #include "ns3/simulator.h"
36 #include "ns3/socket-factory.h"
37 #include "ns3/packet.h"
38 #include "ns3/uinteger.h"
39 #include "ns3/trace-source-accessor.h"
41 #include "ns3/udp-socket-factory.h"
42 #include "ns3/string.h"
43 #include "ns3/pointer.h"
44 #include "ns3/boolean.h"
57 .SetGroupName(
"Applications")
59 .AddAttribute (
"DataRate",
"The data rate in on state.",
63 .AddAttribute (
"PacketSize",
"The size of packets sent in on state",
66 MakeUintegerChecker<uint32_t> (1))
67 .AddAttribute (
"Remote",
"The address of the destination",
71 .AddAttribute (
"Local",
72 "The Address on which to bind the socket. If not set, it is generated automatically.",
76 .AddAttribute (
"OnTime",
"A RandomVariableStream used to pick the duration of the 'On' state.",
77 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
79 MakePointerChecker <RandomVariableStream>())
80 .AddAttribute (
"OffTime",
"A RandomVariableStream used to pick the duration of the 'Off' state.",
81 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
83 MakePointerChecker <RandomVariableStream>())
84 .AddAttribute (
"MaxBytes",
85 "The total number of bytes to send. Once these bytes are sent, "
86 "no packet is sent again, even in on state. The value zero means "
87 "that there is no limit.",
90 MakeUintegerChecker<uint64_t> ())
91 .AddAttribute (
"Protocol",
"The type of protocol to use. This should be "
92 "a subclass of ns3::SocketFactory",
97 .AddAttribute (
"EnableSeqTsSizeHeader",
98 "Enable use of SeqTsSizeHeader for sequence number and timestamp",
102 .AddTraceSource (
"Tx",
"A new packet is created and is sent",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource (
"TxWithAddresses",
"A new packet is created and is sent",
107 "ns3::Packet::TwoAddressTracedCallback")
108 .AddTraceSource (
"TxWithSeqTsSize",
"A new packet is created with SeqTsSizeHeader",
110 "ns3::PacketSink::SeqTsSizeCallback")
182 "Incompatible peer and local address IP version");
232 NS_LOG_WARN (
"OnOffApplication found null socket to close in StopApplication");
254 NS_LOG_DEBUG (
"Discarding cached packet upon CancelEvents ()");
358 <<
" on-off application sent "
359 << packet->
GetSize () <<
" bytes to "
368 <<
" on-off application sent "
369 << packet->
GetSize () <<
" bytes to "
378 NS_LOG_DEBUG (
"Unable to send packet; actual " << actual <<
" size " <<
m_pktSize <<
"; caching for later attempt");
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
AttributeValue implementation for DataRate.
static bool IsMatchingType(const Address &addr)
If the address match.
virtual bool SetAllowBroadcast(bool allowBroadcast)=0
Configure whether broadcast datagram transmissions are allowed.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
static bool IsMatchingType(const Address &address)
AttributeValue implementation for Boolean.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void AddHeader(const Header &header)
Add header to this packet.
uint16_t GetPort(void) const
Ptr< const AttributeAccessor > MakeAddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static TypeId GetTypeId(void)
Get the type ID.
AttributeValue implementation for Address.
EventId m_startStopEvent
Event id for next start or stop event.
bool m_connected
True if connected.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
void SetConnectCallback(Callback< void, Ptr< Socket > > connectionSucceeded, Callback< void, Ptr< Socket > > connectionFailed)
Specify callbacks to allow the caller to determine if the connection succeeds of fails.
uint64_t m_maxBytes
Limit total number of bytes sent.
virtual int Bind6()=0
Allocate a local IPv6 endpoint for this socket.
TracedCallback< Ptr< const Packet >, const Address &, const Address & > m_txTraceWithAddresses
Callbacks for tracing the packet Tx events, includes source and destination addresses.
void SetMaxBytes(uint64_t maxBytes)
Set the total number of bytes to send.
uint32_t m_residualBits
Number of generated, but not sent, bits.
DataRate m_cbrRateFailSafe
Rate that data is generated (check copy)
virtual void DoDispose(void)
Destructor implementation.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
DataRate m_cbrRate
Rate that data is generated.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
High precision numerical type, implementing Q64.64 fixed precision.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint16_t GetPort(void) const
Get the port.
TracedCallback< Ptr< const Packet >, const Address &, const Address &, const SeqTsSizeHeader & > m_txTraceWithSeqTsSize
Callback for tracing the packet Tx events, includes source, destination, the packet sent,...
static Inet6SocketAddress ConvertFrom(const Address &addr)
Convert the address to a InetSocketAddress.
static bool IsMatchingType(const Address &address)
virtual void StopApplication(void)
Application specific shutdown code.
Address m_local
Local address to bind to.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Class for representing data rates.
Ptr< const AttributeChecker > MakeAddressChecker(void)
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
void StopSending()
Start an Off period.
AttributeValue implementation for TypeId.
a polymophic address class
uint32_t m_pktSize
Size of packets.
virtual ~OnOffApplication()
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ipv4Address GetIpv4(void) const
Ptr< RandomVariableStream > m_onTime
rng for On Time
void ScheduleNextTx()
Schedule the next packet transmission.
void ConnectionFailed(Ptr< Socket > socket)
Handle a Connection Failed event.
void SendPacket()
Send a packet.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
void StartSending()
Start an On period.
Simulation virtual time values and global simulation resolution.
virtual int Close(void)=0
Close a socket.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
EventId m_sendEvent
Event id of pending "send packet" event.
void CancelEvents()
Cancel all pending events.
uint64_t GetBitRate() const
Get the underlying bitrate.
Address m_peer
Peer address.
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...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
virtual int GetPeerName(Address &address) const =0
Get the peer address of a connected socket.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ipv6Address GetIpv6(void) const
Get the IPv6 address.
Hold variables of type string.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_ABORT_IF(cond)
Abnormal program termination if a condition is true.
Generate traffic to a single destination according to an OnOff pattern.
Ptr< RandomVariableStream > m_offTime
rng for Off Time
int64_t GetHigh(void) const
Get the integer portion.
uint64_t m_totBytes
Total bytes sent so far.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Ptr< Packet > m_unsentPacket
Unsent packet cached for future attempt.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
bool IsInvalid(void) const
Time Seconds(double value)
Construct a Time in the indicated unit.
void ScheduleStartEvent()
Schedule the next On period start.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Hold an unsigned integer type.
Ptr< Socket > GetSocket(void) const
Return a pointer to associated socket.
Ptr< Node > GetNode() const
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...
Time m_lastStartTime
Time last packet sent.
Ptr< Socket > m_socket
Associated socket.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
The base class for all ns3 applications.
virtual int GetSockName(Address &address) const =0
Get socket address.
virtual int ShutdownRecv(void)=0
void ConnectionSucceeded(Ptr< Socket > socket)
Handle a Connection Succeed event.
bool m_enableSeqTsSizeHeader
Enable or disable the use of SeqTsSizeHeader.
TypeId m_tid
Type of the socket used.
virtual void DoDispose(void)
Destructor implementation.
int64x64_t To(enum Unit unit) const
Get the Time value expressed in a particular unit.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced Callback: transmitted packets.
Ptr< const AttributeChecker > MakeDataRateChecker(void)
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
virtual void StartApplication(void)
Application specific startup code.
void ScheduleStopEvent()
Schedule the next Off period start.