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

(-)a/src/common/pcap-writer.cc (-4 / +10 lines)
 Lines 46-55   PcapWriter::PcapWriter () Link Here 
46
46
47
PcapWriter::~PcapWriter ()
47
PcapWriter::~PcapWriter ()
48
{
48
{
49
  if (m_writer != 0)
49
  Close();
50
    {
51
      m_writer->close ();
52
    }
53
  delete m_writer;
50
  delete m_writer;
54
  m_writer = 0;
51
  m_writer = 0;
55
}
52
}
 Lines 59-64   PcapWriter::Open (std::string const &nam Link Here 
59
{
56
{
60
  m_writer = new std::ofstream ();
57
  m_writer = new std::ofstream ();
61
  m_writer->open (name.c_str ());
58
  m_writer->open (name.c_str ());
59
}
60
61
void
62
PcapWriter::Close ()
63
{
64
  if (m_writer != 0 && m_writer->is_open ())
65
    {
66
      m_writer->close ();
67
    }
62
}
68
}
63
69
64
void 
70
void 
(-)a/src/common/pcap-writer.h (+5 lines)
 Lines 50-55   public: Link Here 
50
  void Open (std::string const &name);
50
  void Open (std::string const &name);
51
51
52
  /**
52
  /**
53
   * Close file.
54
   */
55
  void Close (void);
56
57
  /**
53
   * Write a pcap header in the output file which specifies
58
   * Write a pcap header in the output file which specifies
54
   * that the content of the file will be Packets with
59
   * that the content of the file will be Packets with
55
   * Ethernet/LLC/SNAP encapsulation. This method should
60
   * Ethernet/LLC/SNAP encapsulation. This method should
(-)a/src/helper/csma-helper.cc (+41 lines)
 Lines 30-40    Link Here 
30
30
31
namespace ns3 {
31
namespace ns3 {
32
32
33
std::vector<CsmaHelper::Trace> CsmaHelper::m_traces;
34
33
CsmaHelper::CsmaHelper ()
35
CsmaHelper::CsmaHelper ()
34
{
36
{
35
  m_queueFactory.SetTypeId ("ns3::DropTailQueue");
37
  m_queueFactory.SetTypeId ("ns3::DropTailQueue");
36
  m_deviceFactory.SetTypeId ("ns3::CsmaNetDevice");
38
  m_deviceFactory.SetTypeId ("ns3::CsmaNetDevice");
37
  m_channelFactory.SetTypeId ("ns3::CsmaChannel");
39
  m_channelFactory.SetTypeId ("ns3::CsmaChannel");
40
}
41
42
void
43
CsmaHelper::Cleanup (void)
44
{
45
  uint32_t illegal = std::numeric_limits<uint32_t>::max();
46
  
47
  for (std::vector<Trace>::iterator i = m_traces.begin ();
48
       i != m_traces.end (); i++)
49
  { 
50
    i->nodeId = illegal;
51
    i->deviceId = illegal;
52
    i->writer->Close();
53
    i->writer = 0;
54
  }
55
  m_traces.clear ();
38
}
56
}
39
57
40
void 
58
void 
 Lines 95-100   CsmaHelper::EnablePcap (std::string file Link Here 
95
  oss.str ("");
113
  oss.str ("");
96
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
114
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
97
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
115
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
116
  // Store pcap pointer for later destruction
117
  CsmaHelper::Trace trace;
118
  trace.nodeId = nodeid;
119
  trace.deviceId = deviceid;
120
  trace.writer = pcap;
121
  m_traces.push_back (trace);
98
}
122
}
99
void 
123
void 
100
CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
124
CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
 Lines 123-128   void Link Here 
123
void
147
void
124
CsmaHelper::EnablePcapAll (std::string filename)
148
CsmaHelper::EnablePcapAll (std::string filename)
125
{
149
{
150
  Simulator::ScheduleDestroy (&CsmaHelper::Cleanup);
151
126
  EnablePcap (filename, NodeContainer::GetGlobal ());
152
  EnablePcap (filename, NodeContainer::GetGlobal ());
127
}
153
}
128
154
 Lines 271-274   CsmaHelper::AsciiRxEvent (std::ostream * Link Here 
271
  *os << path << " " << *packet << std::endl;
297
  *os << path << " " << *packet << std::endl;
272
}
298
}
273
299
300
Ptr<PcapWriter>
301
CsmaHelper::GetStream (uint32_t nodeId, uint32_t deviceId)
302
{
303
  for (std::vector<Trace>::iterator i = m_traces.begin ();
304
       i != m_traces.end (); i++)
305
    {
306
      if (i->nodeId == nodeId &&
307
          i->deviceId == deviceId)
308
        {
309
          return i->writer;
310
        }  
311
    }
312
  return 0;
313
}
314
274
} // namespace ns3
315
} // namespace ns3
(-)a/src/helper/csma-helper.h (+10 lines)
 Lines 240-245   public: Link Here 
240
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
240
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
241
241
242
private:
242
private:
243
  static void Cleanup (void);
244
243
  Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
245
  Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
244
246
245
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
247
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
 Lines 251-256   private: Link Here 
251
  ObjectFactory m_queueFactory;
253
  ObjectFactory m_queueFactory;
252
  ObjectFactory m_deviceFactory;
254
  ObjectFactory m_deviceFactory;
253
  ObjectFactory m_channelFactory;
255
  ObjectFactory m_channelFactory;
256
257
  static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t deviceId);
258
  struct Trace {
259
    uint32_t nodeId;
260
    uint32_t deviceId;
261
    Ptr<PcapWriter> writer;
262
  };
263
  static std::vector<Trace> m_traces;
254
};
264
};
255
265
256
266
(-)a/src/helper/point-to-point-helper.cc (-1 / +39 lines)
 Lines 26-40    Link Here 
26
#include "ns3/config.h"
26
#include "ns3/config.h"
27
#include "ns3/packet.h"
27
#include "ns3/packet.h"
28
28
29
30
namespace ns3 {
29
namespace ns3 {
31
30
31
std::vector<PointToPointHelper::Trace> PointToPointHelper::m_traces;
32
32
33
PointToPointHelper::PointToPointHelper ()
33
PointToPointHelper::PointToPointHelper ()
34
{
34
{
35
  m_queueFactory.SetTypeId ("ns3::DropTailQueue");
35
  m_queueFactory.SetTypeId ("ns3::DropTailQueue");
36
  m_deviceFactory.SetTypeId ("ns3::PointToPointNetDevice");
36
  m_deviceFactory.SetTypeId ("ns3::PointToPointNetDevice");
37
  m_channelFactory.SetTypeId ("ns3::PointToPointChannel");
37
  m_channelFactory.SetTypeId ("ns3::PointToPointChannel");
38
}
39
40
void
41
PointToPointHelper::Cleanup (void)
42
{
43
  uint32_t illegal = std::numeric_limits<uint32_t>::max();
44
  
45
  for (std::vector<Trace>::iterator i = m_traces.begin ();
46
       i != m_traces.end (); i++)
47
  { 
48
    i->nodeId = illegal;
49
    i->deviceId = illegal;
50
    i->writer->Close(); 
51
    i->writer = 0;
52
  }
53
  m_traces.clear ();
38
}
54
}
39
55
40
void 
56
void 
 Lines 95-100   PointToPointHelper::EnablePcap (std::str Link Here 
95
  oss.str ("");
111
  oss.str ("");
96
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
112
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
97
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::EnqueueEvent, pcap));
113
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::EnqueueEvent, pcap));
114
  // Store pcap pointer for later destruction
115
  PointToPointHelper::Trace trace;
116
  trace.nodeId = nodeid;
117
  trace.deviceId = deviceid;
118
  trace.writer = pcap;
119
  m_traces.push_back (trace);
98
}
120
}
99
void 
121
void 
100
PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
122
PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
 Lines 123-128   void Link Here 
123
void
145
void
124
PointToPointHelper::EnablePcapAll (std::string filename)
146
PointToPointHelper::EnablePcapAll (std::string filename)
125
{
147
{
148
  Simulator::ScheduleDestroy (&PointToPointHelper::Cleanup);
149
126
  EnablePcap (filename, NodeContainer::GetGlobal ());
150
  EnablePcap (filename, NodeContainer::GetGlobal ());
127
}
151
}
128
152
 Lines 251-255   PointToPointHelper::AsciiRxEvent (std::o Link Here 
251
  *os << path << " " << *packet << std::endl;
275
  *os << path << " " << *packet << std::endl;
252
}
276
}
253
277
278
Ptr<PcapWriter>
279
PointToPointHelper::GetStream (uint32_t nodeId, uint32_t deviceId)
280
{
281
  for (std::vector<Trace>::iterator i = m_traces.begin ();
282
       i != m_traces.end (); i++)
283
    {
284
      if (i->nodeId == nodeId &&
285
          i->deviceId == deviceId)
286
        {
287
          return i->writer;
288
        }  
289
    }
290
  return 0;
291
}
254
292
255
} // namespace ns3
293
} // namespace ns3
(-)a/src/helper/point-to-point-helper.h (+10 lines)
 Lines 208-213   public: Link Here 
208
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
208
                    NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices);
209
209
210
private:
210
private:
211
  static void Cleanup (void);
212
211
  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
213
  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
212
  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
214
  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
213
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
215
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
 Lines 219-224   private: Link Here 
219
  ObjectFactory m_queueFactory;
221
  ObjectFactory m_queueFactory;
220
  ObjectFactory m_channelFactory;
222
  ObjectFactory m_channelFactory;
221
  ObjectFactory m_deviceFactory;
223
  ObjectFactory m_deviceFactory;
224
225
  static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t deviceId);
226
  struct Trace {
227
    uint32_t nodeId;
228
    uint32_t deviceId;
229
    Ptr<PcapWriter> writer;
230
  };
231
  static std::vector<Trace> m_traces;
222
};
232
};
223
233
224
234

Return to bug 416