18 #include "ns3/icmpv4.h"
19 #include "ns3/assert.h"
21 #include "ns3/ipv4-address.h"
22 #include "ns3/socket.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/boolean.h"
25 #include "ns3/inet-socket-address.h"
26 #include "ns3/packet.h"
27 #include "ns3/trace-source-accessor.h"
41 .AddConstructor<V4Ping> ()
42 .AddAttribute (
"Remote",
43 "The address of the machine we want to ping.",
46 MakeIpv4AddressChecker ())
47 .AddAttribute (
"Verbose",
48 "Produce usual output.",
51 MakeBooleanChecker ())
52 .AddAttribute (
"Interval",
"Wait interval seconds between sending each packet.",
56 .AddAttribute (
"Size",
"The number of data bytes to be sent, real packet will be 8 (ICMP) + 20 (IP) bytes longer.",
59 MakeUintegerChecker<uint32_t> (16))
60 .AddTraceSource (
"Rtt",
61 "The rtt calculated by the ping.",
68 : m_interval (Seconds (1)),
120 uint32_t recvSize = p->
GetSize ();
132 uint32_t * buf =
new uint32_t [
m_size];
139 Read32 ((
const uint8_t *) &buf[0], nodeId);
140 Read32 ((
const uint8_t *) &buf[1], appId);
142 if (nodeId ==
GetNode ()->GetId () &&
145 Time sendTime = i->second;
156 std::cout << recvSize <<
" bytes from " << realFrom.
GetIpv4 () <<
":"
158 <<
" ttl=" << (unsigned)ipv4.GetTtl ()
175 buffer[0] = (data >> 0) & 0xff;
176 buffer[1] = (data >> 8) & 0xff;
177 buffer[2] = (data >> 16) & 0xff;
178 buffer[3] = (data >> 24) & 0xff;
186 data = (buffer[3] << 24) + (buffer[2] << 16) + (buffer[1] << 8) + buffer[0];
199 echo.SetIdentifier (0);
208 for (uint32_t i = 0; i <
m_size; ++i) data[i] = 0;
212 Write32 (&data[0 *
sizeof(uint32_t)], tmp);
215 Write32 (&data[1 *
sizeof(uint32_t)], tmp);
217 Ptr<Packet> dataPacket = Create<Packet> ((uint8_t *) data, m_size);
218 echo.SetData (dataPacket);
242 std::cout <<
"PING " <<
m_remote <<
" 56(84) bytes of data.\n";
268 std::ostringstream os;
270 os <<
"--- " <<
m_remote <<
" ping statistics ---\n"
271 <<
m_seq <<
" packets transmitted, " <<
m_recv <<
" received, "
279 std::cout << os.str ();
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
virtual void StartApplication(void)
Application specific startup code.
void Write32(uint8_t *buffer, const uint32_t data)
Writes data to buffer in little-endian format.
keep track of time values and allow control of global simulation resolution
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
uint32_t GetNApplications(void) const
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
double Stddev() const
Standard deviation.
static bool ChecksumEnabled(void)
uint32_t GetDataSize(void) const
Get the Echo data size.
#define NS_ASSERT(condition)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetSize(void) const
TracedCallback< Time > m_traceRtt
TracedCallback for RTT measured by ICMP ECHOs.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
uint32_t GetApplicationId(void) const
Return the application ID in the node.
double Avg() const
Sample average.
uint16_t GetIdentifier(void) const
Get the Echo identifier.
V4Ping()
create a pinger applications
a polymophic address class
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Ptr< Application > GetApplication(uint32_t index) const
void Read32(const uint8_t *buffer, uint32_t &data)
Writes data from a little-endian formatted buffer to data.
Time m_started
Start time to report total ping time.
static TypeId GetTypeId(void)
Get the type ID.
The base class for all ns3 applications.
hold objects of type ns3::Time
void Receive(Ptr< Socket > socket)
Receive an ICMP Echo.
Hold an unsigned integer type.
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...
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
std::map< uint16_t, Time > m_sent
All sent but not answered packets. Map icmp seqno -> when sent.
static InetSocketAddress ConvertFrom(const Address &address)
bool m_verbose
produce ping-style output if true
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Doxygen introspection did not find any typical Config paths.
uint16_t m_seq
ICMP ECHO sequence number.
uint32_t GetData(uint8_t payload[]) const
Get the Echo data.
hold objects of type ns3::Ipv4Address
static Time Now(void)
Return the "current simulation time".
EventId m_next
Next packet will be sent.
#define NS_ASSERT_MSG(condition, message)
virtual void StopApplication(void)
Application specific shutdown code.
uint32_t GetId(void) const
void Send()
Send one Ping (ICMP ECHO) to the destination.
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
#define NS_LOG_DEBUG(msg)
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
uint16_t GetSequenceNumber(void) const
Get the Echo sequence number.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Time m_interval
Wait interval seconds between sending each packet.
uint16_t GetPort(void) const
uint32_t m_recv
received packets counter
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 Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
Ipv4Address m_remote
Remote address.
virtual int Close(void)=0
Close a socket.
uint32_t Count() const
Sample size.
void SetAttribute(std::string name, const AttributeValue &value)
a unique identifier for an interface.
int64_t GetMilliSeconds(void) const
TypeId SetParent(TypeId tid)
static bool IsMatchingType(const Address &address)
uint32_t m_size
Specifies the number of data bytes to be sent.
void AddHeader(const Header &header)
Add header to this packet.
Average< double > m_avgRtt
Average rtt is ms.
Ptr< Socket > m_socket
The socket we send packets from.
static TypeId LookupByName(std::string name)
virtual uint32_t GetRxAvailable(void) const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
void Update(T const &x)
Add new sample.