add context information to tx and rx trace callbacks

Mathieu Lacage 2007-03-29 23:41:16 +02:00
parent 3af7a78855
commit aeed4279d7
4 changed files with 19 additions and 12 deletions

View File

@ -336,7 +336,16 @@ Ipv4::Copy(Node *node) const
void
Ipv4::Receive(Packet& packet, NetDevice &device)
{
m_rxTrace (packet);
uint32_t index = 0;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
{
if ((*i)->GetDevice () == &device)
{
m_rxTrace (packet, index);
break;
}
index++;
}
Ipv4Header ipHeader;
packet.Peek (ipHeader);
packet.Remove (ipHeader);
@ -356,9 +365,9 @@ Ipv4::Receive(Packet& packet, NetDevice &device)
void
Ipv4::Send (Packet const &packet,
Ipv4Address source,
Ipv4Address destination,
uint8_t protocol)
Ipv4Address source,
Ipv4Address destination,
uint8_t protocol)
{
Ipv4Header ipHeader;
@ -398,7 +407,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route
packet.Add (ip);
Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
m_txTrace (packet);
m_txTrace (packet, route.GetInterface ());
if (route.IsGateway ())
{
outInterface->Send (packet, route.GetGateway ());

View File

@ -228,8 +228,8 @@ public:
NetworkRoutes m_networkRoutes;
Ipv4Route *m_defaultRoute;
Node *m_node;
CallbackTraceSource<Packet const &> m_txTrace;
CallbackTraceSource<Packet const &> m_rxTrace;
CallbackTraceSource<Packet const &, uint32_t> m_txTrace;
CallbackTraceSource<Packet const &, uint32_t> m_rxTrace;
CallbackTraceSource<Packet const &> m_dropTrace;
};

View File

@ -50,7 +50,7 @@ PcapTrace::~PcapTrace ()
void
PcapTrace::TraceAllIp (void)
{
TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/(tx|rx)",
TraceRoot::Connect ("/nodes/*/ipv4/(tx|rx)",
MakeCallback (&PcapTrace::LogIp, this));
}
@ -80,13 +80,11 @@ PcapTrace::GetStream (uint32_t nodeId, uint32_t interfaceId)
}
void
PcapTrace::LogIp (TraceContext const &context, Packet &p)
PcapTrace::LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex)
{
NodeList::NodeIndex nodeIndex;
context.Get (nodeIndex);
uint32_t nodeId = NodeList::GetNode (nodeIndex)->GetId ();
Ipv4::InterfaceIndex interfaceIndex;
context.Get (interfaceIndex);
PcapWriter *writer = GetStream (nodeId, interfaceIndex);
writer->WritePacket (p);
}

View File

@ -39,7 +39,7 @@ public:
void TraceAllIp (void);
private:
PcapWriter *GetStream (uint32_t nodeId, uint32_t interfaceId);
void LogIp (TraceContext const &context, Packet &p);
void LogIp (TraceContext const &context, Packet const &p, uint32_t interfaceIndex);
std::string m_filename;
struct Trace {
uint32_t nodeId;