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

(-)a/src/wave/helper/wave-helper.cc (-390 / +2 lines)
 Lines 86-479    Link Here 
86
  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
86
  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
87
}
87
}
88
88
89
static void
90
PcapSniffTxEvent (
91
  Ptr<PcapFileWrapper> file,
92
  Ptr<const Packet>    packet,
93
  uint16_t             channelFreqMhz,
94
  uint16_t             channelNumber,
95
  uint32_t             rate,
96
  WifiPreamble         preamble,
97
  WifiTxVector         txVector,
98
  struct mpduInfo      aMpdu)
99
{
100
  uint32_t dlt = file->GetDataLinkType ();
101
102
  switch (dlt)
103
    {
104
    case PcapHelper::DLT_IEEE802_11:
105
      file->Write (Simulator::Now (), packet);
106
      return;
107
    case PcapHelper::DLT_PRISM_HEADER:
108
      {
109
        NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
110
        return;
111
      }
112
    case PcapHelper::DLT_IEEE802_11_RADIO:
113
      {
114
        Ptr<Packet> p = packet->Copy ();
115
        RadiotapHeader header;
116
        uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
117
        header.SetTsft (Simulator::Now ().GetMicroSeconds ());
118
119
        //Our capture includes the FCS, so we set the flag to say so.
120
        frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
121
122
        if (preamble == WIFI_PREAMBLE_SHORT)
123
          {
124
            frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
125
          }
126
127
        if (txVector.IsShortGuardInterval ())
128
          {
129
            frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_GUARD;
130
          }
131
132
        header.SetFrameFlags (frameFlags);
133
        header.SetRate (rate);
134
135
        uint16_t channelFlags = 0;
136
        switch (rate)
137
          {
138
          case 2:  //1Mbps
139
          case 4:  //2Mbps
140
          case 10: //5Mbps
141
          case 22: //11Mbps
142
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
143
            break;
144
145
          default:
146
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
147
            break;
148
          }
149
150
        if (channelFreqMhz < 2500)
151
          {
152
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ;
153
          }
154
        else
155
          {
156
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ;
157
          }
158
159
        header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
160
161
        if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
162
          {
163
            uint8_t mcsRate = 0;
164
            uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
165
            uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
166
167
            mcsKnown |= RadiotapHeader::MCS_KNOWN_INDEX;
168
            mcsRate = rate - 128;
169
170
            mcsKnown |= RadiotapHeader::MCS_KNOWN_BANDWIDTH;
171
            if (txVector.GetChannelWidth () == 40)
172
              {
173
                mcsFlags |= RadiotapHeader::MCS_FLAGS_BANDWIDTH_40;
174
              }
175
176
            mcsKnown |= RadiotapHeader::MCS_KNOWN_GUARD_INTERVAL;
177
            if (txVector.IsShortGuardInterval ())
178
              {
179
                mcsFlags |= RadiotapHeader::MCS_FLAGS_GUARD_INTERVAL;
180
              }
181
182
            mcsKnown |= RadiotapHeader::MCS_KNOWN_HT_FORMAT;
183
            if (preamble == WIFI_PREAMBLE_HT_GF)
184
              {
185
                mcsFlags |= RadiotapHeader::MCS_FLAGS_HT_GREENFIELD;
186
              }
187
188
            mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
189
            if (txVector.GetNess () & 0x01) //bit 1
190
              {
191
                mcsFlags |= RadiotapHeader::MCS_FLAGS_NESS_BIT_0;
192
              }
193
            if (txVector.GetNess () & 0x02) //bit 2
194
              {
195
                mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS_BIT_1;
196
              }
197
198
            mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
199
200
            mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
201
            if (txVector.IsStbc ())
202
              {
203
                mcsFlags |= RadiotapHeader::MCS_FLAGS_STBC_STREAMS;
204
              }
205
206
            header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
207
          }
208
209
        if (txVector.IsAggregation ())
210
          {
211
            uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
212
            ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
213
            /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
214
            AmpduSubframeHeader hdr;
215
            uint32_t extractedLength;
216
            p->RemoveHeader (hdr);
217
            extractedLength = hdr.GetLength ();
218
            p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
219
            if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
220
              {
221
                ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
222
              }
223
            header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
224
          }
225
226
        if (preamble == WIFI_PREAMBLE_VHT)
227
          {
228
            uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
229
            uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
230
            uint8_t vhtBandwidth = 0;
231
            uint8_t vhtMcsNss[4] = {0,0,0,0};
232
            uint8_t vhtCoding = 0;
233
            uint8_t vhtGroupId = 0;
234
            uint16_t vhtPartialAid = 0;
235
236
            vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
237
            if (txVector.IsStbc ())
238
              {
239
                vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
240
              }
241
242
            vhtKnown |= RadiotapHeader::VHT_KNOWN_GUARD_INTERVAL;
243
            if (txVector.IsShortGuardInterval ())
244
              {
245
                vhtFlags |= RadiotapHeader::VHT_FLAGS_GUARD_INTERVAL;
246
              }
247
248
            vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
249
250
            vhtKnown |= RadiotapHeader::VHT_KNOWN_BANDWIDTH;
251
            //not all bandwidth values are currently supported
252
            if (txVector.GetChannelWidth () == 40)
253
              {
254
                vhtBandwidth = 1;
255
              }
256
            else if (txVector.GetChannelWidth () == 80)
257
              {
258
                vhtBandwidth = 4;
259
              }
260
            else if (txVector.GetChannelWidth () == 160)
261
              {
262
                vhtBandwidth = 11;
263
              }
264
265
            //only SU PPDUs are currently supported
266
            vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
267
            vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
268
269
            header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
270
          }
271
272
        p->AddHeader (header);
273
        file->Write (Simulator::Now (), p);
274
        return;
275
      }
276
    default:
277
      NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
278
    }
279
}
280
281
static void
282
PcapSniffRxEvent (
283
  Ptr<PcapFileWrapper>  file,
284
  Ptr<const Packet>     packet,
285
  uint16_t              channelFreqMhz,
286
  uint16_t              channelNumber,
287
  uint32_t              rate,
288
  WifiPreamble          preamble,
289
  WifiTxVector          txVector,
290
  struct mpduInfo       aMpdu,
291
  struct signalNoiseDbm signalNoise)
292
{
293
  uint32_t dlt = file->GetDataLinkType ();
294
295
  switch (dlt)
296
    {
297
    case PcapHelper::DLT_IEEE802_11:
298
      file->Write (Simulator::Now (), packet);
299
      return;
300
    case PcapHelper::DLT_PRISM_HEADER:
301
      {
302
        NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
303
        return;
304
      }
305
    case PcapHelper::DLT_IEEE802_11_RADIO:
306
      {
307
        Ptr<Packet> p = packet->Copy ();
308
        RadiotapHeader header;
309
        uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
310
        header.SetTsft (Simulator::Now ().GetMicroSeconds ());
311
312
        //Our capture includes the FCS, so we set the flag to say so.
313
        frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
314
315
        if (preamble == WIFI_PREAMBLE_SHORT)
316
          {
317
            frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
318
          }
319
320
        if (txVector.IsShortGuardInterval ())
321
          {
322
            frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_GUARD;
323
          }
324
325
        header.SetFrameFlags (frameFlags);
326
        header.SetRate (rate);
327
328
        uint16_t channelFlags = 0;
329
        switch (rate)
330
          {
331
          case 2:  //1Mbps
332
          case 4:  //2Mbps
333
          case 10: //5Mbps
334
          case 22: //11Mbps
335
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
336
            break;
337
338
          default:
339
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
340
            break;
341
          }
342
343
        if (channelFreqMhz < 2500)
344
          {
345
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ;
346
          }
347
        else
348
          {
349
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ;
350
          }
351
352
        header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
353
354
        header.SetAntennaSignalPower (signalNoise.signal);
355
        header.SetAntennaNoisePower (signalNoise.noise);
356
357
        if (preamble == WIFI_PREAMBLE_HT_MF || preamble == WIFI_PREAMBLE_HT_GF || preamble == WIFI_PREAMBLE_NONE)
358
          {
359
            uint8_t mcsRate = 0;
360
            uint8_t mcsKnown = RadiotapHeader::MCS_KNOWN_NONE;
361
            uint8_t mcsFlags = RadiotapHeader::MCS_FLAGS_NONE;
362
363
            mcsKnown |= RadiotapHeader::MCS_KNOWN_INDEX;
364
            mcsRate = rate - 128;
365
366
            mcsKnown |= RadiotapHeader::MCS_KNOWN_BANDWIDTH;
367
            if (txVector.GetChannelWidth () == 40)
368
              {
369
                mcsFlags |= RadiotapHeader::MCS_FLAGS_BANDWIDTH_40;
370
              }
371
372
            mcsKnown |= RadiotapHeader::MCS_KNOWN_GUARD_INTERVAL;
373
            if (txVector.IsShortGuardInterval ())
374
              {
375
                mcsFlags |= RadiotapHeader::MCS_FLAGS_GUARD_INTERVAL;
376
              }
377
378
            mcsKnown |= RadiotapHeader::MCS_KNOWN_HT_FORMAT;
379
            if (preamble == WIFI_PREAMBLE_HT_GF)
380
              {
381
                mcsFlags |= RadiotapHeader::MCS_FLAGS_HT_GREENFIELD;
382
              }
383
384
            mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS;
385
            if (txVector.GetNess () & 0x01) //bit 1
386
              {
387
                mcsFlags |= RadiotapHeader::MCS_FLAGS_NESS_BIT_0;
388
              }
389
            if (txVector.GetNess () & 0x02) //bit 2
390
              {
391
                mcsKnown |= RadiotapHeader::MCS_KNOWN_NESS_BIT_1;
392
              }
393
394
            mcsKnown |= RadiotapHeader::MCS_KNOWN_FEC_TYPE; //only BCC is currently supported
395
396
            mcsKnown |= RadiotapHeader::MCS_KNOWN_STBC;
397
            if (txVector.IsStbc ())
398
              {
399
                mcsFlags |= RadiotapHeader::MCS_FLAGS_STBC_STREAMS;
400
              }
401
402
            header.SetMcsFields (mcsKnown, mcsFlags, mcsRate);
403
          }
404
405
        if (txVector.IsAggregation ())
406
          {
407
            uint16_t ampduStatusFlags = RadiotapHeader::A_MPDU_STATUS_NONE;
408
            ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_DELIMITER_CRC_KNOWN;
409
            ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST_KNOWN;
410
            /* For PCAP file, MPDU Delimiter and Padding should be removed by the MAC Driver */
411
            AmpduSubframeHeader hdr;
412
            uint32_t extractedLength;
413
            p->RemoveHeader (hdr);
414
            extractedLength = hdr.GetLength ();
415
            p = p->CreateFragment (0, static_cast<uint32_t> (extractedLength));
416
            if (aMpdu.type == LAST_MPDU_IN_AGGREGATE || (hdr.GetEof () == true && hdr.GetLength () > 0))
417
              {
418
                ampduStatusFlags |= RadiotapHeader::A_MPDU_STATUS_LAST;
419
              }
420
            header.SetAmpduStatus (aMpdu.mpduRefNumber, ampduStatusFlags, hdr.GetCrc ());
421
          }
422
423
        if (preamble == WIFI_PREAMBLE_VHT)
424
          {
425
            uint16_t vhtKnown = RadiotapHeader::VHT_KNOWN_NONE;
426
            uint8_t vhtFlags = RadiotapHeader::VHT_FLAGS_NONE;
427
            uint8_t vhtBandwidth = 0;
428
            uint8_t vhtMcsNss[4] = {0,0,0,0};
429
            uint8_t vhtCoding = 0;
430
            uint8_t vhtGroupId = 0;
431
            uint16_t vhtPartialAid = 0;
432
433
            vhtKnown |= RadiotapHeader::VHT_KNOWN_STBC;
434
            if (txVector.IsStbc ())
435
              {
436
                vhtFlags |= RadiotapHeader::VHT_FLAGS_STBC;
437
              }
438
439
            vhtKnown |= RadiotapHeader::VHT_KNOWN_GUARD_INTERVAL;
440
            if (txVector.IsShortGuardInterval ())
441
              {
442
                vhtFlags |= RadiotapHeader::VHT_FLAGS_GUARD_INTERVAL;
443
              }
444
445
            vhtKnown |= RadiotapHeader::VHT_KNOWN_BEAMFORMED; //Beamforming is currently not supported
446
447
            vhtKnown |= RadiotapHeader::VHT_KNOWN_BANDWIDTH;
448
            //not all bandwidth values are currently supported
449
            if (txVector.GetChannelWidth () == 40)
450
              {
451
                vhtBandwidth = 1;
452
              }
453
            else if (txVector.GetChannelWidth () == 80)
454
              {
455
                vhtBandwidth = 4;
456
              }
457
            else if (txVector.GetChannelWidth () == 160)
458
              {
459
                vhtBandwidth = 11;
460
              }
461
462
            //only SU PPDUs are currently supported
463
            vhtMcsNss[0] |= (txVector.GetNss () & 0x0f);
464
            vhtMcsNss[0] |= (((rate - 128) << 4) & 0xf0);
465
466
            header.SetVhtFields (vhtKnown, vhtFlags, vhtBandwidth, vhtMcsNss, vhtCoding, vhtGroupId, vhtPartialAid);
467
          }
468
469
        p->AddHeader (header);
470
        file->Write (Simulator::Now (), p);
471
        return;
472
      }
473
    default:
474
      NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
475
    }
476
}
477
89
478
/****************************** YansWavePhyHelper ***********************************/
90
/****************************** YansWavePhyHelper ***********************************/
479
YansWavePhyHelper
91
YansWavePhyHelper
 Lines 520-527    Link Here 
520
  for (i = phys.begin (); i != phys.end (); ++i)
132
  for (i = phys.begin (); i != phys.end (); ++i)
521
    {
133
    {
522
      Ptr<WifiPhy> phy = (*i);
134
      Ptr<WifiPhy> phy = (*i);
523
      phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
135
      phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&YansWavePhyHelper::PcapSniffTxEvent, file));
524
      phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
136
      phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&YansWavePhyHelper::PcapSniffRxEvent, file));
525
    }
137
    }
526
}
138
}
527
139
(-)a/src/wifi/helper/yans-wifi-helper.cc (-6 / +6 lines)
 Lines 248-255    Link Here 
248
  return phy;
248
  return phy;
249
}
249
}
250
250
251
static void
251
void
252
PcapSniffTxEvent (
252
YansWifiPhyHelper::PcapSniffTxEvent (
253
  Ptr<PcapFileWrapper> file,
253
  Ptr<PcapFileWrapper> file,
254
  Ptr<const Packet>    packet,
254
  Ptr<const Packet>    packet,
255
  uint16_t             channelFreqMhz,
255
  uint16_t             channelFreqMhz,
 Lines 440-447    Link Here 
440
    }
440
    }
441
}
441
}
442
442
443
static void
443
void
444
PcapSniffRxEvent (
444
YansWifiPhyHelper::PcapSniffRxEvent (
445
  Ptr<PcapFileWrapper>  file,
445
  Ptr<PcapFileWrapper>  file,
446
  Ptr<const Packet>     packet,
446
  Ptr<const Packet>     packet,
447
  uint16_t              channelFreqMhz,
447
  uint16_t              channelFreqMhz,
 Lines 692-699    Link Here 
692
692
693
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
693
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
694
694
695
  phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
695
  phy->TraceConnectWithoutContext ("MonitorSnifferTx", MakeBoundCallback (&YansWifiPhyHelper::PcapSniffTxEvent, file));
696
  phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
696
  phy->TraceConnectWithoutContext ("MonitorSnifferRx", MakeBoundCallback (&YansWifiPhyHelper::PcapSniffRxEvent, file));
697
}
697
}
698
698
699
void
699
void
(-)a/src/wifi/helper/yans-wifi-helper.h (+46 lines)
 Lines 255-260    Link Here 
255
   */
255
   */
256
  uint32_t GetPcapDataLinkType (void) const;
256
  uint32_t GetPcapDataLinkType (void) const;
257
257
258
259
protected:
260
  /**
261
   * \param file the pcap file wrapper
262
   * \param packet the packet
263
   * \param channelFreqMhz the channel frequency
264
   * \param channelNumber the channel number
265
   * \param rate the PHY bitrate
266
   * \param preamble the preamble type
267
   * \param txVector the TXVECTOR
268
   * \param aMpdu the A-MPDU information
269
   *
270
   * Handle tx pcap.
271
   */
272
static void PcapSniffTxEvent (Ptr<PcapFileWrapper> file,
273
                              Ptr<const Packet> packet,
274
                              uint16_t channelFreqMhz,
275
                              uint16_t channelNumber,
276
                              uint32_t rate,
277
                              WifiPreamble preamble,
278
                              WifiTxVector txVector,
279
                              struct mpduInfo aMpdu);
280
  /**
281
   * \param file the pcap file wrapper
282
   * \param packet the packet
283
   * \param channelFreqMhz the channel frequency
284
   * \param channelNumber the channel number
285
   * \param rate the PHY bitrate
286
   * \param preamble the preamble type
287
   * \param txVector the TXVECTOR
288
   * \param aMpdu the A-MPDU information
289
   * \param signalNoise the rx signal and noise information
290
   *
291
   * Handle rx pcap.
292
   */
293
static void PcapSniffRxEvent (Ptr<PcapFileWrapper> file,
294
                              Ptr<const Packet> packet,
295
                              uint16_t channelFreqMhz,
296
                              uint16_t channelNumber,
297
                              uint32_t rate,
298
                              WifiPreamble preamble,
299
                              WifiTxVector txVector,
300
                              struct mpduInfo aMpdu,
301
                              struct signalNoiseDbm signalNoise);
302
303
258
private:
304
private:
259
  /**
305
  /**
260
   * \param node the node on which we wish to create a wifi PHY
306
   * \param node the node on which we wish to create a wifi PHY

Return to bug 2420