add application tracing support

This commit is contained in:
Mathieu Lacage
2007-12-11 13:51:03 +01:00
parent df27c80c72
commit 3262a4e103
6 changed files with 88 additions and 1 deletions

View File

@@ -33,6 +33,7 @@
#include "ns3/socket-factory.h"
#include "ns3/default-value.h"
#include "ns3/packet.h"
#include "ns3/composite-trace-resolver.h"
#include "onoff-application.h"
NS_LOG_COMPONENT_DEFINE ("OnOffApplication");
@@ -241,6 +242,7 @@ void OnOffApplication::SendPacket()
NS_ASSERT (m_sendEvent.IsExpired ());
Ptr<Packet> packet = Create<Packet> (m_pktSize);
m_txTrace (packet);
m_socket->Send (packet);
m_totBytes += m_pktSize;
m_lastStartTime = Simulator::Now();
@@ -262,4 +264,17 @@ void OnOffApplication::ConnectionFailed(Ptr<Socket>)
cout << "OnOffApplication, Connection Failed" << endl;
}
Ptr<TraceResolver>
OnOffApplication::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddSource ("tx",
TraceDoc ("A new packet is created and is sent",
"Ptr<const Packet>",
"The newly-created packet."),
m_txTrace);
resolver->SetParentResolver (Application::GetTraceResolver ());
return resolver;
}
} // Namespace ns3

View File

@@ -29,6 +29,7 @@
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include "ns3/data-rate.h"
#include "ns3/callback-trace-source.h"
namespace ns3 {
@@ -135,8 +136,10 @@ private:
EventId m_sendEvent; // Eventid of pending "send packet" event
bool m_sending; // True if currently in sending state
std::string m_iid;
CallbackTraceSource<Ptr<const Packet> > m_txTrace;
private:
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
void ScheduleNextTx();
void ScheduleStartEvent();
void ScheduleStopEvent();

View File

@@ -25,6 +25,7 @@
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "ns3/composite-trace-resolver.h"
#include "packet-sink.h"
using namespace std;
@@ -101,8 +102,23 @@ void PacketSink::Receive(Ptr<Socket> socket, Ptr<Packet> packet,
NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " <<
address.GetIpv4() << " [" << address << "]---'" <<
packet->PeekData() << "'");
// TODO: Add a tracing source here
}
m_rxTrace (packet, from);
}
Ptr<TraceResolver>
PacketSink::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddSource ("rx",
TraceDoc ("A new packet has been received",
"Ptr<const Packet>",
"The newly-received packet.",
"const Address &",
"The source address of the received packet."),
m_rxTrace);
resolver->SetParentResolver (Application::GetTraceResolver ());
return resolver;
}
} // Namespace ns3

View File

@@ -24,6 +24,8 @@
#include "ns3/application.h"
#include "ns3/event-id.h"
#include "ns3/ptr.h"
#include "ns3/callback-trace-source.h"
#include "ns3/address.h"
namespace ns3 {
@@ -68,6 +70,8 @@ private:
// inherited from Application base class.
virtual void StartApplication (void); // Called at time specified by Start
virtual void StopApplication (void); // Called at time specified by Stop
// inherited from Object base class.
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
void Construct (Ptr<Node> n,
const Address &local,
@@ -78,6 +82,7 @@ private:
Ptr<Socket> m_socket; // Associated socket
Address m_local; // Local address to bind to
std::string m_iid; // Protocol name (e.g., "Udp")
CallbackTraceSource<Ptr<const Packet>, const Address &> m_rxTrace;
};

View File

@@ -60,6 +60,34 @@ NodeNetDeviceIndex::GetTypeName (void) const
}
NodeApplicationIndex::NodeApplicationIndex ()
: m_index (0)
{}
NodeApplicationIndex::NodeApplicationIndex (uint32_t index)
: m_index (index)
{}
uint32_t
NodeApplicationIndex::Get (void) const
{
return m_index;
}
void
NodeApplicationIndex::Print (std::ostream &os) const
{
os << "device=" << m_index;
}
uint16_t
NodeApplicationIndex::GetUid (void)
{
static uint16_t uid = AllocateUid<NodeApplicationIndex> ("NodeApplicationIndex");
return uid;
}
std::string
NodeApplicationIndex::GetTypeName (void) const
{
return "ns3::NodeApplicationIndex";
}
Node::Node()
: m_id(0),
@@ -92,6 +120,7 @@ Node::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ());
resolver->AddArray ("applications", m_applications.begin (), m_applications.end (), NodeApplicationIndex ());
resolver->SetParentResolver (Object::GetTraceResolver ());
return resolver;
}

View File

@@ -57,6 +57,25 @@ private:
uint32_t m_index;
};
/**
* \brief hold in a TraceContext the index of an Application within a Node
*/
class NodeApplicationIndex : public TraceContextElement
{
public:
NodeApplicationIndex ();
NodeApplicationIndex (uint32_t index);
/**
* \returns the index of the Application within its container Node.
*/
uint32_t Get (void) const;
void Print (std::ostream &os) const;
std::string GetTypeName (void) const;
static uint16_t GetUid (void);
private:
uint32_t m_index;
};
/**
* \brief A network Node.
*