View | Details | Raw Unified | Return to bug 157
Collapse All | Expand All

(-)a/examples/tcp-large-transfer.cc (-1 / +1 lines)
 Lines 182-190   int main (int argc, char *argv[]) Link Here 
182
182
183
  std::ofstream ascii;
183
  std::ofstream ascii;
184
  ascii.open ("tcp-large-transfer.tr");
184
  ascii.open ("tcp-large-transfer.tr");
185
  PointToPointHelper::EnablePcap ("tcp-large-transfer");
186
  PointToPointHelper::EnableAscii (ascii);
185
  PointToPointHelper::EnableAscii (ascii);
187
186
187
  internet.EnablePcap ("tcp-large-transfer");
188
188
189
  Simulator::StopAt (Seconds(1000));
189
  Simulator::StopAt (Seconds(1000));
190
  Simulator::Run ();
190
  Simulator::Run ();
(-)a/src/helper/internet-stack-helper.cc (+66 lines)
 Lines 20-27    Link Here 
20
#include "internet-stack-helper.h"
20
#include "internet-stack-helper.h"
21
#include "ns3/internet-stack.h"
21
#include "ns3/internet-stack.h"
22
#include "ns3/packet-socket-factory.h"
22
#include "ns3/packet-socket-factory.h"
23
#include "ns3/config.h"
23
24
24
namespace ns3 {
25
namespace ns3 {
26
27
std::vector<InternetStackHelper::Trace> InternetStackHelper::m_traces;
25
28
26
void 
29
void 
27
InternetStackHelper::Build (NodeContainer c)
30
InternetStackHelper::Build (NodeContainer c)
 Lines 35-39   InternetStackHelper::Build (NodeContaine Link Here 
35
    }
38
    }
36
}
39
}
37
40
41
void
42
InternetStackHelper::EnablePcap (std::string filename)
43
{
44
  m_filename = filename;
45
  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Tx",
46
                              MakeCallback (&InternetStackHelper::LogTxIp, this));
47
  Config::Connect ("/NodeList/*/$ns3::Ipv4L3Protocol/Rx",
48
                              MakeCallback (&InternetStackHelper::LogRxIp, this));
49
}
50
51
uint32_t
52
InternetStackHelper::GetNodeIndex (std::string context) const
53
{
54
  std::string::size_type pos;
55
  pos = context.find ("/NodeList/");
56
  NS_ASSERT (pos == 0);
57
  std::string::size_type afterNodeIndex = context.find ("/", 11);
58
  NS_ASSERT (afterNodeIndex != std::string::npos);
59
  std::string index = context.substr (10, afterNodeIndex - 10);
60
  std::istringstream iss;
61
  iss.str (index);
62
  uint32_t nodeIndex;
63
  iss >> nodeIndex;
64
  return nodeIndex;
65
} 
66
67
void
68
InternetStackHelper::LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t interfaceIndex)
69
{
70
  Ptr<PcapWriter> writer = GetStream (GetNodeIndex (context), interfaceIndex);
71
  writer->WritePacket (packet);
72
}
73
74
void
75
InternetStackHelper::LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t interfaceIndex)
76
{
77
  Ptr<PcapWriter> writer = GetStream (GetNodeIndex (context), interfaceIndex);
78
  writer->WritePacket (packet);
79
}
80
81
Ptr<PcapWriter>
82
InternetStackHelper::GetStream (uint32_t nodeId, uint32_t interfaceId)
83
{
84
  for (std::vector<Trace>::iterator i = m_traces.begin ();
85
       i != m_traces.end (); i++)
86
  {
87
    if (i->nodeId == nodeId &&
88
        i->interfaceId == interfaceId)
89
    {
90
      return i->writer;
91
    }
92
  }
93
  InternetStackHelper::Trace trace;
94
  trace.nodeId = nodeId;
95
  trace.interfaceId = interfaceId;
96
  trace.writer = Create<PcapWriter> ();
97
  std::ostringstream oss;
98
  oss << m_filename << ".pcap-" << nodeId << "-" << interfaceId;
99
  trace.writer->Open (oss.str ());
100
  trace.writer->WriteIpHeader ();
101
  m_traces.push_back (trace);
102
  return trace.writer;
103
}
38
104
39
} // namespace ns3
105
} // namespace ns3
(-)a/src/helper/internet-stack-helper.h (+24 lines)
 Lines 21-26    Link Here 
21
#define INTERNET_STACK_HELPER_H
21
#define INTERNET_STACK_HELPER_H
22
22
23
#include "node-container.h"
23
#include "node-container.h"
24
#include "net-device-container.h"
25
#include "ns3/pcap-writer.h"
26
#include "ns3/packet.h"
24
27
25
namespace ns3 {
28
namespace ns3 {
26
29
 Lines 37-42   public: Link Here 
37
   * of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes.
40
   * of the ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes.
38
   */
41
   */
39
  void Build (NodeContainer c);
42
  void Build (NodeContainer c);
43
44
  /**
45
   * \param filename filename prefix to use for pcap files.
46
   *
47
   * Enable pcap output on each device which is of the
48
   * ns3::PointToPointNetDevice type
49
   */
50
  void EnablePcap (std::string filename);
51
52
private:
53
  void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
54
  void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
55
  Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t interfaceId);
56
  struct Trace {
57
    uint32_t nodeId;
58
    uint32_t interfaceId;
59
    Ptr<PcapWriter> writer;
60
  };
61
  std::string m_filename;
62
  uint32_t GetNodeIndex (std::string context) const;
63
  static std::vector<Trace> m_traces;
40
};
64
};
41
65
42
} // namespace ns3
66
} // namespace ns3

Return to bug 157