basic tracing support
This commit is contained in:
@@ -32,12 +32,19 @@
|
||||
#include "ns3/inet-socket-address.h"
|
||||
#include "ns3/global-route-manager.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/node-list.h"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
static void
|
||||
WifiNetDeviceTrace (const TraceContext &context, Packet p, Mac48Address address)
|
||||
{
|
||||
std::cout << context << " ad=" << address << " p: " << p << std::endl;
|
||||
}
|
||||
|
||||
static Ptr<Node>
|
||||
CreateApNode (Ptr<WifiChannel> channel,
|
||||
Position position,
|
||||
@@ -157,6 +164,8 @@ int main (int argc, char *argv[])
|
||||
|
||||
GlobalRouteManager::PopulateRoutingTables ();
|
||||
|
||||
NodeList::Connect ("/nodes/*/devices/*/*", MakeCallback (&WifiNetDeviceTrace));
|
||||
|
||||
Simulator::Run ();
|
||||
|
||||
Simulator::Destroy ();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/llc-snap-header.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/composite-trace-resolver.h"
|
||||
|
||||
#include "wifi-net-device.h"
|
||||
#include "wifi-phy.h"
|
||||
@@ -41,6 +42,44 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
WifiNetDeviceTraceType::WifiNetDeviceTraceType ()
|
||||
: m_type (RX)
|
||||
{}
|
||||
|
||||
WifiNetDeviceTraceType::WifiNetDeviceTraceType (enum Type type)
|
||||
: m_type (type)
|
||||
{}
|
||||
enum WifiNetDeviceTraceType::Type
|
||||
WifiNetDeviceTraceType::Get (void) const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
uint16_t
|
||||
WifiNetDeviceTraceType::GetUid (void)
|
||||
{
|
||||
static uint16_t uid = AllocateUid<WifiNetDeviceTraceType> ("ns3::WifiNetDeviceTraceType");
|
||||
return uid;
|
||||
}
|
||||
void
|
||||
WifiNetDeviceTraceType::Print (std::ostream &os) const
|
||||
{
|
||||
os << "event=";
|
||||
switch (m_type) {
|
||||
case RX:
|
||||
os << "rx";
|
||||
break;
|
||||
case TX:
|
||||
os << "tx";
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::string
|
||||
WifiNetDeviceTraceType::GetTypeName (void) const
|
||||
{
|
||||
return "ns3::WifiNetDeviceTraceType";
|
||||
}
|
||||
|
||||
|
||||
static WifiMode
|
||||
GetWifiModeForPhyMode (WifiPhy *phy, enum WifiDefaultParameters::PhyModeParameter mode)
|
||||
{
|
||||
@@ -165,6 +204,27 @@ WifiNetDevice::CreateDca (uint32_t minCw, uint32_t maxCw) const
|
||||
return dca;
|
||||
}
|
||||
|
||||
Ptr<TraceResolver>
|
||||
WifiNetDevice::GetTraceResolver (void) const
|
||||
{
|
||||
Ptr<CompositeTraceResolver> resolver =
|
||||
Create<CompositeTraceResolver> ();
|
||||
resolver->AddSource ("rx",
|
||||
TraceDoc ("Receive a packet",
|
||||
"Packet", "the packet received",
|
||||
"Mac48Address", "the sender of the packet"),
|
||||
m_rxLogger,
|
||||
WifiNetDeviceTraceType (WifiNetDeviceTraceType::RX));
|
||||
resolver->AddSource ("tx",
|
||||
TraceDoc ("Send a packet",
|
||||
"Packet", "the packet to send",
|
||||
"Mac48Address", "the destination of the packet"),
|
||||
m_txLogger,
|
||||
WifiNetDeviceTraceType (WifiNetDeviceTraceType::TX));
|
||||
resolver->SetParentResolver (NetDevice::GetTraceResolver ());
|
||||
return resolver;
|
||||
}
|
||||
|
||||
void
|
||||
WifiNetDevice::ConnectTo (Ptr<WifiChannel> channel)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,31 @@ class MacHighAdhoc;
|
||||
class MacHighNqsta;
|
||||
class MacHighNqap;
|
||||
|
||||
/**
|
||||
* \brief hold the type of trace event generated by
|
||||
* a WifiNetDevice.
|
||||
*/
|
||||
class WifiNetDeviceTraceType : public TraceContextElement
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
RX,
|
||||
TX
|
||||
};
|
||||
WifiNetDeviceTraceType ();
|
||||
WifiNetDeviceTraceType (enum Type type);
|
||||
/**
|
||||
* \returns the type of event
|
||||
*/
|
||||
enum Type Get (void) const;
|
||||
|
||||
static uint16_t GetUid (void);
|
||||
void Print (std::ostream &os) const;
|
||||
std::string GetTypeName (void) const;
|
||||
private:
|
||||
enum Type m_type;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief the base class for 802.11 network interfaces
|
||||
*
|
||||
@@ -77,6 +102,7 @@ private:
|
||||
virtual bool DoNeedsArp (void) const;
|
||||
virtual Ptr<Channel> DoGetChannel (void) const;
|
||||
virtual bool SendTo (const Packet &packet, const Address &to, uint16_t protocolNumber);
|
||||
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
|
||||
// defined for children
|
||||
virtual void NotifyConnected (void) = 0;
|
||||
virtual bool DoSendTo (const Packet &packet, const Mac48Address &to) = 0;
|
||||
|
||||
Reference in New Issue
Block a user