add context information to tx and rx trace callbacks
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 29 Mar 2007 23:41:16 +0200
changeset 457 a468fac09924
parent 456 5361882cc2f3
child 458 0a5f4f427d66
add context information to tx and rx trace callbacks
src/node/ipv4.cc
src/node/ipv4.h
src/node/pcap-trace.cc
src/node/pcap-trace.h
--- a/src/node/ipv4.cc	Thu Mar 29 23:24:10 2007 +0200
+++ b/src/node/ipv4.cc	Thu Mar 29 23:41:16 2007 +0200
@@ -336,7 +336,16 @@
 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 @@
 
 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 @@
   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 ());
--- a/src/node/ipv4.h	Thu Mar 29 23:24:10 2007 +0200
+++ b/src/node/ipv4.h	Thu Mar 29 23:41:16 2007 +0200
@@ -228,8 +228,8 @@
   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;
 };
 
--- a/src/node/pcap-trace.cc	Thu Mar 29 23:24:10 2007 +0200
+++ b/src/node/pcap-trace.cc	Thu Mar 29 23:41:16 2007 +0200
@@ -50,7 +50,7 @@
 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 @@
 }
 
 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);
 }
--- a/src/node/pcap-trace.h	Thu Mar 29 23:24:10 2007 +0200
+++ b/src/node/pcap-trace.h	Thu Mar 29 23:41:16 2007 +0200
@@ -39,7 +39,7 @@
   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;