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

(-)a/examples/wifi-wired-bridging.cc (+1 lines)
 Lines 91-96    Link Here 
91
91
92
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
92
  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
93
  wifiPhy.SetPcapFormat(YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
93
  wifiPhy.SetPcapFormat(YansWifiPhyHelper::PCAP_FORMAT_80211_RADIOTAP);
94
  wifiPhy.SetPcapCaptureSize(0);
94
95
95
  for (uint32_t i = 0; i < nWifis; ++i)
96
  for (uint32_t i = 0; i < nWifis; ++i)
96
    {
97
    {
(-)a/src/common/pcap-writer.cc (-16 / +56 lines)
 Lines 46-51    Link Here 
46
};
46
};
47
47
48
PcapWriter::PcapWriter ()
48
PcapWriter::PcapWriter ()
49
  : m_captureSize(0)
49
{
50
{
50
  NS_LOG_FUNCTION (this);
51
  NS_LOG_FUNCTION (this);
51
  NS_LOG_LOGIC ("m_writer = 0");
52
  NS_LOG_LOGIC ("m_writer = 0");
 Lines 162-170    Link Here 
162
      uint64_t us = current % 1000000;
163
      uint64_t us = current % 1000000;
163
      Write32 (s & 0xffffffff);
164
      Write32 (s & 0xffffffff);
164
      Write32 (us & 0xffffffff);
165
      Write32 (us & 0xffffffff);
165
      Write32 (packet->GetSize ());
166
      uint32_t thisCaptureSize;
166
      Write32 (packet->GetSize ());
167
      if (m_captureSize == 0)
167
      packet->CopyData (m_writer, packet->GetSize ());
168
        {
169
          thisCaptureSize = packet->GetSize ();
170
        }
171
      else
172
        {
173
          thisCaptureSize = std::min (m_captureSize, packet->GetSize ());         
174
        }          
175
      Write32 (thisCaptureSize); 
176
      Write32 (packet->GetSize ()); // actual packet size
177
      packet->CopyData (m_writer, thisCaptureSize);
168
    }
178
    }
169
}
179
}
170
180
 Lines 203-209    Link Here 
203
  // real devices (e.g. madwifi) handle this case, especially for TX
213
  // real devices (e.g. madwifi) handle this case, especially for TX
204
  // packets (radiotap specs says TSFT is not used for TX packets,
214
  // packets (radiotap specs says TSFT is not used for TX packets,
205
  // but madwifi actually uses it).
215
  // but madwifi actually uses it).
206
  uint64_t tsft = current;      
216
  uint64_t tsft = current;    
217
218
  
219
  uint32_t wifiMonitorHeaderSize;  
207
    
220
    
208
  if (m_pcapMode == PCAP_80211_PRISM)
221
  if (m_pcapMode == PCAP_80211_PRISM)
209
    {
222
    {
 Lines 226-235    Link Here 
226
#define PRISM_ITEM_LENGTH       4
239
#define PRISM_ITEM_LENGTH       4
227
240
228
241
229
242
      wifiMonitorHeaderSize = PRISM_MSG_LENGTH;
230
      uint32_t size = packet->GetSize () + PRISM_MSG_LENGTH;
243
      if (m_captureSize == 0)
231
      Write32 (size); // total packet size
244
        {
232
      Write32 (size); // captured size
245
          Write32 (packet->GetSize () + wifiMonitorHeaderSize); // captured size == actual packet size
246
        }
247
      else
248
        {
249
          uint32_t thisCaptureSize = std::min (m_captureSize, packet->GetSize () + wifiMonitorHeaderSize);         
250
          Write32 (thisCaptureSize); 
251
        }
252
      Write32 (packet->GetSize () + wifiMonitorHeaderSize); // actual packet size
233
253
234
      Write32(PRISM_MSG_CODE);
254
      Write32(PRISM_MSG_CODE);
235
      Write32(PRISM_MSG_LENGTH);
255
      Write32(PRISM_MSG_LENGTH);
 Lines 349-366    Link Here 
349
369
350
#define RADIOTAP_TX_PRESENT (RADIOTAP_TSFT | RADIOTAP_FLAGS  | RADIOTAP_RATE | RADIOTAP_CHANNEL)
370
#define RADIOTAP_TX_PRESENT (RADIOTAP_TSFT | RADIOTAP_FLAGS  | RADIOTAP_RATE | RADIOTAP_CHANNEL)
351
#define RADIOTAP_TX_LENGTH (8+8+1+1+2+2)
371
#define RADIOTAP_TX_LENGTH (8+8+1+1+2+2)
352
372
      
353
      uint32_t size;
354
      if (isTx)
373
      if (isTx)
355
        {
374
        {
356
          size = packet->GetSize () + RADIOTAP_TX_LENGTH;
375
          wifiMonitorHeaderSize = RADIOTAP_TX_LENGTH;
357
        }
376
        }
358
      else
377
      else
359
        {
378
        {
360
          size = packet->GetSize () + RADIOTAP_RX_LENGTH;
379
          wifiMonitorHeaderSize = RADIOTAP_RX_LENGTH;
380
        }      
381
382
      if (m_captureSize == 0)
383
        {
384
          Write32 (packet->GetSize () + wifiMonitorHeaderSize); // captured size == actual packet size
361
        }
385
        }
362
      Write32 (size); // total packet size
386
      else
363
      Write32 (size); // captured size
387
        {
388
          uint32_t thisCaptureSize = std::min (m_captureSize, packet->GetSize () + wifiMonitorHeaderSize);         
389
          Write32 (thisCaptureSize); 
390
        }
391
      Write32 (packet->GetSize () + wifiMonitorHeaderSize); // actual packet size
364
392
365
      Write8(0); // radiotap version
393
      Write8(0); // radiotap version
366
      Write8(0); // padding
394
      Write8(0); // padding
 Lines 412-422    Link Here 
412
    }    
440
    }    
413
441
414
  // finally, write rest of packet
442
  // finally, write rest of packet
415
  packet->CopyData (m_writer, packet->GetSize ());
443
  if (m_captureSize == 0)
444
    {
445
      packet->CopyData (m_writer, packet->GetSize ());
446
    }
447
  else
448
    {
449
      packet->CopyData (m_writer, m_captureSize - wifiMonitorHeaderSize);      
450
    }
451
416
}
452
}
417
    
453
    
418
  
454
  
419
455
void 
456
PcapWriter::SetCaptureSize (uint32_t size)
457
{
458
  m_captureSize = size;
459
}
420
460
421
int8_t 
461
int8_t 
422
PcapWriter::RoundToInt8 (double value)
462
PcapWriter::RoundToInt8 (double value)
(-)a/src/common/pcap-writer.h (-1 / +9 lines)
 Lines 128-134    Link Here 
128
                              uint32_t rate, bool isShortPreamble, bool isTx, 
128
                              uint32_t rate, bool isShortPreamble, bool isTx, 
129
                              double signalDbm, double noiseDbm);
129
                              double signalDbm, double noiseDbm);
130
130
131
131
  /** 
132
   * Set the maximum number of bytes to be captured for each packet. 
133
   * 
134
   * @param size the maximum number of bytes to be captured. If zero
135
   * (default), the whole packet will be captured. 
136
   */
137
  void SetCaptureSize (uint32_t size);
132
138
133
139
134
private:
140
private:
 Lines 141-146    Link Here 
141
  int8_t RoundToInt8 (double value);
147
  int8_t RoundToInt8 (double value);
142
  std::ofstream *m_writer;
148
  std::ofstream *m_writer;
143
  uint32_t m_pcapMode;
149
  uint32_t m_pcapMode;
150
  uint32_t m_captureSize;
151
  
144
};
152
};
145
153
146
} // namespace ns3
154
} // namespace ns3
(-)a/src/helper/yans-wifi-helper.cc (-2 / +8 lines)
 Lines 148-155    Link Here 
148
148
149
YansWifiPhyHelper::YansWifiPhyHelper ()
149
YansWifiPhyHelper::YansWifiPhyHelper ()
150
  : m_channel (0),
150
  : m_channel (0),
151
    m_pcapFormat(PCAP_FORMAT_80211)
151
    m_pcapFormat(PCAP_FORMAT_80211),
152
    
152
    m_pcapCaptureSize(0)
153
{
153
{
154
  m_phy.SetTypeId ("ns3::YansWifiPhy");
154
  m_phy.SetTypeId ("ns3::YansWifiPhy");
155
}
155
}
 Lines 221-226    Link Here 
221
  m_pcapFormat = format;
221
  m_pcapFormat = format;
222
}
222
}
223
223
224
void 
225
YansWifiPhyHelper::SetPcapCaptureSize (uint32_t size)
226
{
227
  m_pcapCaptureSize = size;
228
}
224
229
225
void 
230
void 
226
YansWifiPhyHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
231
YansWifiPhyHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
 Lines 237-242    Link Here 
237
  // we must fully-qualify the call to Create below because it conflicts
242
  // we must fully-qualify the call to Create below because it conflicts
238
  // with the locally-defined WifiPhyHelper::Create method.
243
  // with the locally-defined WifiPhyHelper::Create method.
239
  Ptr<PcapWriter> pcap = ::ns3::Create<PcapWriter> ();
244
  Ptr<PcapWriter> pcap = ::ns3::Create<PcapWriter> ();
245
  pcap->SetCaptureSize (m_pcapCaptureSize);
240
  pcap->Open (oss.str ());
246
  pcap->Open (oss.str ());
241
247
242
  switch (m_pcapFormat) {
248
  switch (m_pcapFormat) {
(-)a/src/helper/yans-wifi-helper.h (+10 lines)
 Lines 221-226    Link Here 
221
   */
221
   */
222
  void SetPcapFormat (enum PcapFormat format);
222
  void SetPcapFormat (enum PcapFormat format);
223
223
224
  /** 
225
   * Set the maximum number of bytes to be captured for each packet
226
   * appearing in the PCAP trace.  
227
   * 
228
   * @param size the maximum number of bytes to be captured. If zero
229
   * (default), the whole packet will be captured. 
230
   */
231
  void SetPcapCaptureSize (uint32_t size);
232
224
  /**
233
  /**
225
   * \param filename filename prefix to use for pcap files.
234
   * \param filename filename prefix to use for pcap files.
226
   * \param nodeid the id of the node to generate pcap output for.
235
   * \param nodeid the id of the node to generate pcap output for.
 Lines 339-344    Link Here 
339
  ObjectFactory m_errorRateModel;
348
  ObjectFactory m_errorRateModel;
340
  Ptr<YansWifiChannel> m_channel;
349
  Ptr<YansWifiChannel> m_channel;
341
  enum PcapFormat m_pcapFormat;
350
  enum PcapFormat m_pcapFormat;
351
  uint32_t m_pcapCaptureSize;
342
};
352
};
343
353
344
} // namespace ns3
354
} // namespace ns3

Return to bug 639