16#include "ns3/assert.h"
17#include "ns3/boolean.h"
18#include "ns3/icmpv4-l4-protocol.h"
19#include "ns3/icmpv4.h"
20#include "ns3/inet-socket-address.h"
21#include "ns3/ipv4-address.h"
23#include "ns3/packet.h"
24#include "ns3/socket.h"
25#include "ns3/trace-source-accessor.h"
26#include "ns3/uinteger.h"
38 TypeId(
"ns3::V4TraceRoute")
40 .SetGroupName(
"Internet-Apps")
42 .AddAttribute(
"Remote",
43 "The address of the machine we want to trace.",
48 "The Type of Service used to send IPv4 packets. "
49 "All 8 bits of the TOS byte are set (including ECN bits).",
53 .AddAttribute(
"Verbose",
54 "Produce usual output.",
58 .AddAttribute(
"Interval",
59 "Wait interval between sent packets.",
64 "The number of data bytes to be sent, real packet will "
65 "be 8 (ICMP) + 20 (IP) bytes longer.",
69 .AddAttribute(
"MaxHop",
70 "The maximum number of hops to trace.",
74 .AddAttribute(
"ProbeNum",
75 "The number of packets send to each hop.",
79 .AddAttribute(
"Timeout",
80 "The waiting time for a route response before a timeout.",
97 m_waitIcmpReplyTimeout(
Seconds(5))
125 <<
" bytes of data.");
131 <<
" hops Max, " <<
m_size <<
" bytes of data.\n";
176 *
m_printStream->GetStream() <<
"Trace Complete\n" << std::endl;
199 for (
uint32_t i = 0; i < node->GetNApplications(); ++i)
201 if (node->GetApplication(i) ==
this)
224 p->RemoveHeader(ipv4);
227 p->RemoveHeader(icmp);
232 p->RemoveHeader(timeoutResp);
242 recvSeq = (uint16_t)
data[7] << 0;
243 recvSeq |= (uint16_t)
data[6] << 8;
245 auto i =
m_sent.find(recvSeq);
248 Time sendTime = i->second;
297 p->RemoveHeader(echo);
306 Time sendTime = i->second;
350 *
m_printStream->GetStream() <<
"Trace Complete\n" << std::endl;
391 p->AddHeader(header);
a polymophic address class
The base class for all ns3 applications.
void DoDispose() override
Destructor implementation.
Ptr< Node > GetNode() const
AttributeValue implementation for Boolean.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
void SetIdentifier(uint16_t id)
Set the Echo identifier.
void SetData(Ptr< const Packet > data)
Set the Echo data.
uint16_t GetIdentifier() const
Get the Echo identifier.
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
uint32_t GetDataSize() const
Get the Echo data size.
uint16_t GetSequenceNumber() const
Get the Echo sequence number.
static const uint8_t PROT_NUMBER
ICMP protocol number (0x1)
ICMP Time Exceeded header.
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
static Ipv4Address GetAny()
bool IsInitialized() const
AttributeValue implementation for Ipv4Address.
static bool ChecksumEnabled()
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
virtual void SetIpTtl(uint8_t ipTtl)
Manually set IP Time to Live field.
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
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 uint32_t GetRxAvailable() const =0
Return number of bytes which can be returned from one or multiple calls to Recv.
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 SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)=0
Send data to a specified peer.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Traceroute application sends one ICMP ECHO request with TTL=1, and after receiving an ICMP TIME EXCEE...
Ipv4Address m_remote
Remote address.
void HandleWaitReplyTimeout()
Triggers an action if an ICMP TIME EXCEED have not being received in the time defined by StartWaitRep...
void StopApplication() override
Application specific shutdown code.
EventId m_next
Next packet will be sent.
std::ostringstream m_routeIpv4
The Ipv4 address of the latest hop found.
void StartApplication() override
Application specific startup code.
Ptr< OutputStreamWrapper > m_printStream
Stream of the traceroute used for the output file.
uint32_t m_probeCount
The Current probe value.
uint16_t m_seq
ICMP ECHO sequence number.
uint32_t GetApplicationId() const
Return the application ID in the node.
uint16_t m_ttl
The current TTL value.
std::map< uint16_t, Time > m_sent
All sent but not answered packets. Map icmp seqno -> when sent.
void DoDispose() override
Destructor implementation.
Ptr< Socket > m_socket
The socket we send packets from.
uint32_t m_maxTtl
The maximum Ttl (Max number of hops to trace)
Time m_interval
Wait interval seconds between sending each packet.
void Print(Ptr< OutputStreamWrapper > stream)
Prints the application traced routes into a given OutputStream.
std::ostringstream m_osRoute
Stream of characters used for printing a single route.
Time m_started
Start time to report total ping time.
EventId m_waitIcmpReplyTimer
The timer used to wait for the probes ICMP replies.
uint32_t m_size
Specifies the number of data bytes to be sent.
uint8_t m_tos
The packets Type of Service.
uint16_t m_maxProbes
The maximum number of probe packets per hop.
Time m_waitIcmpReplyTimeout
The wait time until the response is considered lost.
void Receive(Ptr< Socket > socket)
Receive an ICMP Echo.
static TypeId GetTypeId()
Get the type ID.
void StartWaitReplyTimer()
Starts a timer after sending an ICMP ECHO.
bool m_verbose
produce traceroute style output if true
void Send()
Send one (ICMP ECHO) to the destination.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeIpv4AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeIpv4AddressChecker()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
#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_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#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< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Time Seconds(double value)
Construct a Time in the indicated unit.
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...