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

(-)a/examples/wifi-wired-bridging.cc (-2 / +5 lines)
 Lines 183-190   int main (int argc, char *argv[]) Link Here 
183
  apps.Start (Seconds (0.5));
183
  apps.Start (Seconds (0.5));
184
  apps.Stop (Seconds (3.0));
184
  apps.Stop (Seconds (3.0));
185
  
185
  
186
  YansWifiPhyHelper::EnablePcap ("wifi-wired-bridging", staNodes[1].Get (1));
186
  WifiHelper::EnablePcap ("wifi-wired-bridging", staNodes[1].Get (1));
187
  YansWifiPhyHelper::EnablePcap ("wifi-wired-bridging", staNodes[0].Get (0));
187
  WifiHelper::EnablePcap ("wifi-wired-bridging", staNodes[0].Get (0));
188
189
  YansWifiPhyHelper::EnablePcap ("wifi-wired-bridging-promisc", staNodes[1].Get (1));
190
  YansWifiPhyHelper::EnablePcap ("wifi-wired-bridging-promisc", staNodes[0].Get (0));
188
  std::ofstream os;
191
  std::ofstream os;
189
  os.open ("wifi-wired-bridging.mob");
192
  os.open ("wifi-wired-bridging.mob");
190
  MobilityHelper::EnableAsciiAll (os);
193
  MobilityHelper::EnableAsciiAll (os);
(-)a/src/devices/csma/csma-net-device.cc (-67 / +157 lines)
 Lines 77-93   CsmaNetDevice::GetTypeId (void) Link Here 
77
                   PointerValue (),
77
                   PointerValue (),
78
                   MakePointerAccessor (&CsmaNetDevice::m_receiveErrorModel),
78
                   MakePointerAccessor (&CsmaNetDevice::m_receiveErrorModel),
79
                   MakePointerChecker<ErrorModel> ())
79
                   MakePointerChecker<ErrorModel> ())
80
81
    //
82
    // Transmit queueing discipline for the device which includes its own set
83
    // of trace hooks.
84
    //
80
    .AddAttribute ("TxQueue", 
85
    .AddAttribute ("TxQueue", 
81
                   "A queue to use as the transmit queue in the device.",
86
                   "A queue to use as the transmit queue in the device.",
82
                   PointerValue (),
87
                   PointerValue (),
83
                   MakePointerAccessor (&CsmaNetDevice::m_queue),
88
                   MakePointerAccessor (&CsmaNetDevice::m_queue),
84
                   MakePointerChecker<Queue> ())
89
                   MakePointerChecker<Queue> ())
85
    .AddTraceSource ("Rx", 
90
86
                     "Trace source indicating reception of packet destined for broadcast, multicast or local address.",
91
    //
87
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_rxTrace))
92
    // Trace sources at the "top" of the net device, where packets transition
88
    .AddTraceSource ("Drop", 
93
    // to/from higher layers.
89
                     "Trace source indicating packet discarded due to receiver disabled or error model decision.",
94
    //
90
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_dropTrace))
95
    .AddTraceSource ("MacTx", 
96
                     "Trace source indicating a packet has arrived for transmission by this device",
97
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxTrace))
98
    .AddTraceSource ("MacTxDrop", 
99
                     "Trace source indicating a packet has been dropped by the device before transmission",
100
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxDropTrace))
101
    .AddTraceSource ("MacRx", 
102
                     "Trace source indicating a packet has been received by this device and is being forwarded up the stack",
103
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_macRxTrace))
104
    //
105
    // Trace souces at the "bottom" of the net device, where packets transition
106
    // to/from the channel.
107
    //
108
    .AddTraceSource ("PhyTxStart", 
109
                     "Trace source indicating a packet has begun transmitting over the channel",
110
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxStartTrace))
111
    .AddTraceSource ("PhyTx", 
112
                     "Trace source indicating a packet has been completely transmitted over the channel",
113
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxTrace))
114
    .AddTraceSource ("PhyTxDrop", 
115
                     "Trace source indicating a packet has been dropped by the device during transmission",
116
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxDropTrace))
117
    .AddTraceSource ("PhyRxStart", 
118
                     "Trace source indicating a packet has begun being received by the device",
119
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxStartTrace))
120
    .AddTraceSource ("PhyRx", 
121
                     "Trace source indicating a packet has been completely received by the device",
122
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxTrace))
123
    .AddTraceSource ("PhyRxDrop", 
124
                     "Trace source indicating a packet has been dropped by the device during reception",
125
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxDropTrace))
126
    .AddTraceSource ("PhyTxBackoff", 
127
                     "Trace source indicating a packet has been delayed by the CSMA backoff process",
128
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxBackoffTrace))
129
130
    //
131
    // Trace sources designed to simulate a packet sniffer facility (tcpdump). 
132
    //
133
    .AddTraceSource ("Sniffer", 
134
                     "Trace source simulating a non-promiscuous packet sniffer attached to the device",
135
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_snifferTrace))
136
    .AddTraceSource ("PromiscSniffer", 
137
                     "Trace source simulating a promiscuous packet sniffer attached to the device",
138
                     MakeTraceSourceAccessor (&CsmaNetDevice::m_promiscSnifferTrace))
91
    ;
139
    ;
92
  return tid;
140
  return tid;
93
}
141
}
 Lines 102-112   CsmaNetDevice::CsmaNetDevice () Link Here 
102
  m_channel = 0; 
150
  m_channel = 0; 
103
151
104
  // 
152
  // 
105
  // We would like to let the attribute system take care of initializing the packet encapsulation stuff, but we also don't want to
153
  // We would like to let the attribute system take care of initializing the 
106
  // get caught up in initialization order changes.  So we'll get the three problem variables into a consistent state here before the
154
  // packet encapsulation stuff, but we also don't want to get caught up in
107
  // attribute calls, and then depend on the semantics of the setters to preserve a consistent state.  This really doesn't have to be
155
  // initialization order changes.  So we'll get the three problem variables
108
  // the same set of values as the initial values set by the attributes, but it does have to be a consistent set.  That is, you can
156
  // into a consistent state here before the attribute calls, and then depend
109
  // just change the ddfault encapsulation mode above without having to change it here.  We keep it the same for GP.
157
  // on the semantics of the setters to preserve a consistent state.  This 
158
  // really doesn't have to be the same set of values as the initial values 
159
  // set by the attributes, but it does have to be a consistent set.  That is,
160
  // you can just change the default encapsulation mode above without having 
161
  // to change it here.
110
  //
162
  //
111
  m_encapMode = DIX;
163
  m_encapMode = DIX;
112
  m_frameSize = DEFAULT_FRAME_SIZE;
164
  m_frameSize = DEFAULT_FRAME_SIZE;
 Lines 332-338   CsmaNetDevice::AddHeader (Ptr<Packet> p, Link Here 
332
    case DIX:
384
    case DIX:
333
      NS_LOG_LOGIC ("Encapsulating packet as DIX (type interpretation)");
385
      NS_LOG_LOGIC ("Encapsulating packet as DIX (type interpretation)");
334
      //
386
      //
335
      // This corresponds to the type interpretation of the lengthType field as in the old Ethernet Blue Book.
387
      // This corresponds to the type interpretation of the lengthType field as
388
      // in the old Ethernet Blue Book.
336
      //
389
      //
337
      lengthType = protocolNumber;
390
      lengthType = protocolNumber;
338
      break;
391
      break;
 Lines 407-444   CsmaNetDevice::ProcessHeader (Ptr<Packet Link Here 
407
}
460
}
408
461
409
  void
462
  void
410
CsmaNetDevice::TransmitStart ()
463
CsmaNetDevice::TransmitStart (void)
411
{
464
{
412
  NS_LOG_FUNCTION_NOARGS ();
465
  NS_LOG_FUNCTION_NOARGS ();
413
466
414
  //
467
  //
415
  // This function is called to start the process of transmitting a packet.  We 
468
  // This function is called to start the process of transmitting a packet.  We 
416
  // expect that a Ptr to the packet to be transmitted has been placed in 
469
  // expect that the packet to transmit will be found in m_currentPkt.
417
  // m_currentPkt.
470
  //
471
  NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitStart(): m_currentPkt not set");
418
472
419
  NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
473
  NS_LOG_LOGIC ("m_currentPkt = " << m_currentPkt);
420
  NS_LOG_LOGIC ("UID is " << m_currentPkt->GetUid ());
474
  NS_LOG_LOGIC ("UID = " << m_currentPkt->GetUid ());
421
475
422
  //
476
  //
423
  // We need to tell the channel that we've started wiggling the wire and
477
  // Only transmit if the send side of net device is enabled
424
  // schedule an event that will be executed when it's time to tell the 
478
  //
425
  // channel that we're done wiggling the wire.
479
  if (IsSendEnabled () == false)
480
    {
481
      m_phyTxDropTrace (m_currentPkt);
482
      m_currentPkt = 0;
483
      return;
484
    }
485
486
  //
487
  // Somebody has called here telling us to start transmitting a packet.  They 
488
  // can only do this if the state machine is in the READY or BACKOFF state.
489
  // Specifically, if we are ready to start transmitting, we cannot already
490
  // be transmitting (i.e., BUSY)
426
  //
491
  //
427
  NS_ASSERT_MSG ((m_txMachineState == READY) || (m_txMachineState == BACKOFF), 
492
  NS_ASSERT_MSG ((m_txMachineState == READY) || (m_txMachineState == BACKOFF), 
428
                 "Must be READY to transmit. Tx state is: " << m_txMachineState);
493
                 "Must be READY to transmit. Tx state is: " << m_txMachineState);
429
494
430
  //
495
  //
431
  // Only transmit if send side of net device is enabled
496
  // Now we have to sense the state of the medium and either start transmitting
497
  // if it is idle, or backoff our transmission if someone else is on the wire.
432
  //
498
  //
433
  if (IsSendEnabled () == false)
434
    {
435
      return;
436
    }
437
438
  if (m_channel->GetState () != IDLE)
499
  if (m_channel->GetState () != IDLE)
439
    {
500
    {
440
      //
501
      //
441
      // The channel is busy -- backoff and rechedule TransmitStart ()
502
      // The channel is busy -- backoff and rechedule TransmitStart() unless
503
      // we have exhausted all of our retries.
442
      //
504
      //
443
      m_txMachineState = BACKOFF;
505
      m_txMachineState = BACKOFF;
444
506
 Lines 451-456   CsmaNetDevice::TransmitStart () Link Here 
451
        } 
513
        } 
452
      else 
514
      else 
453
        {
515
        {
516
          m_phyTxBackoffTrace (m_currentPkt);
517
454
          m_backoff.IncrNumRetries ();
518
          m_backoff.IncrNumRetries ();
455
          Time backoffTime = m_backoff.GetBackoffTime ();
519
          Time backoffTime = m_backoff.GetBackoffTime ();
456
520
 Lines 464-491   CsmaNetDevice::TransmitStart () Link Here 
464
      //
528
      //
465
      // The channel is free, transmit the packet
529
      // The channel is free, transmit the packet
466
      //
530
      //
467
      m_txMachineState = BUSY;
468
      Time tEvent = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ()));
469
      
470
      NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << tEvent.GetSeconds () << "sec");
471
      
472
      Simulator::Schedule (tEvent, &CsmaNetDevice::TransmitCompleteEvent, this);
473
474
      if (m_channel->TransmitStart (m_currentPkt, m_deviceId) == false)
531
      if (m_channel->TransmitStart (m_currentPkt, m_deviceId) == false)
475
        {
532
        {
476
          NS_LOG_WARN ("Channel transmit start did not work at " << tEvent.GetSeconds () << "sec");
533
          NS_LOG_WARN ("Channel TransmitStart returns an error");
534
          m_phyTxDropTrace (m_currentPkt);
535
          m_currentPkt = 0;
477
          m_txMachineState = READY;
536
          m_txMachineState = READY;
478
        } 
537
        } 
479
      else 
538
      else 
480
        {
539
        {
481
          //
540
          //
482
          // Transmission succeeded, reset the backoff time parameters.
541
          // Transmission succeeded, reset the backoff time parameters and
542
          // schedule a transmit complete event.
483
          //
543
          //
484
          m_backoff.ResetBackoffTime ();
544
          m_backoff.ResetBackoffTime ();
545
          m_txMachineState = BUSY;
546
          m_phyTxStartTrace (m_currentPkt);
547
548
          Time tEvent = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ()));
549
          NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << tEvent.GetSeconds () << "sec");
550
          Simulator::Schedule (tEvent, &CsmaNetDevice::TransmitCompleteEvent, this);
485
        }
551
        }
486
    }
552
    }
487
}
553
}
488
489
554
490
  void
555
  void
491
CsmaNetDevice::TransmitAbort (void)
556
CsmaNetDevice::TransmitAbort (void)
 Lines 493-511   CsmaNetDevice::TransmitAbort (void) Link Here 
493
  NS_LOG_FUNCTION_NOARGS ();
558
  NS_LOG_FUNCTION_NOARGS ();
494
559
495
  //
560
  //
496
  // When we started transmitting the current packet, it was placed in 
561
  // When we started the process of transmitting the current packet, it was 
497
  // m_currentPkt.  So we had better find one there.
562
  // placed in m_currentPkt.  So we had better find one there.
498
  //
563
  //
499
  NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitAbort(): m_currentPkt zero");
564
  NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitAbort(): m_currentPkt zero");
500
  NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
565
  NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
501
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
566
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
502
567
503
  //
568
  m_phyTxDropTrace (m_currentPkt);
504
  // Hit the drop trace source.
569
  m_currentPkt = 0;
505
  //
570
506
  // XXX Should there be a separate transmit drop trace?
571
  NS_ASSERT_MSG (m_txMachineState == BACKOFF, "Must be in BACKOFF state to abort.  Tx state is: " << m_txMachineState);
507
  //
508
  m_dropTrace (m_currentPkt);
509
572
510
  // 
573
  // 
511
  // We're done with that one, so reset the backoff algorithm and ready the
574
  // We're done with that one, so reset the backoff algorithm and ready the
 Lines 527-532   CsmaNetDevice::TransmitAbort (void) Link Here 
527
    {
590
    {
528
      m_currentPkt = m_queue->Dequeue ();
591
      m_currentPkt = m_queue->Dequeue ();
529
      NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?");
592
      NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?");
593
      m_snifferTrace (m_currentPkt);
594
      m_promiscSnifferTrace (m_currentPkt);
530
      TransmitStart ();
595
      TransmitStart ();
531
    }
596
    }
532
}
597
}
 Lines 555-560   CsmaNetDevice::TransmitCompleteEvent (vo Link Here 
555
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
620
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
556
621
557
  m_channel->TransmitEnd (); 
622
  m_channel->TransmitEnd (); 
623
  m_phyTxTrace (m_currentPkt);
624
  m_currentPkt = 0;
558
625
559
  NS_LOG_LOGIC ("Schedule TransmitReadyEvent in " << m_tInterframeGap.GetSeconds () << "sec");
626
  NS_LOG_LOGIC ("Schedule TransmitReadyEvent in " << m_tInterframeGap.GetSeconds () << "sec");
560
627
 Lines 575-586   CsmaNetDevice::TransmitReadyEvent (void) Link Here 
575
  m_txMachineState = READY;
642
  m_txMachineState = READY;
576
643
577
  //
644
  //
578
  // When we started transmitting the current packet, it was placed in 
645
  // We expect that the packet we had been transmitting was cleared when the 
579
  // m_currentPkt.  So we had better find one there.
646
  // TransmitCompleteEvent() was executed.
580
  //
647
  //
581
  NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitCompleteEvent(): m_currentPkt zero");
648
  NS_ASSERT_MSG (m_currentPkt == 0, "CsmaNetDevice::TransmitReadyEvent(): m_currentPkt nonzero");
582
  NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
583
  NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
584
649
585
  //
650
  //
586
  // Get the next packet from the queue for transmitting
651
  // Get the next packet from the queue for transmitting
 Lines 593-598   CsmaNetDevice::TransmitReadyEvent (void) Link Here 
593
    {
658
    {
594
      m_currentPkt = m_queue->Dequeue ();
659
      m_currentPkt = m_queue->Dequeue ();
595
      NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?");
660
      NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?");
661
      m_snifferTrace (m_currentPkt);
662
      m_promiscSnifferTrace (m_currentPkt);
596
      TransmitStart ();
663
      TransmitStart ();
597
    }
664
    }
598
}
665
}
 Lines 658-678   CsmaNetDevice::Receive (Ptr<Packet> pack Link Here 
658
  multicast6Node.CopyFrom(mac);
725
  multicast6Node.CopyFrom(mac);
659
726
660
  //
727
  //
661
  // We never forward up packets that we sent. Real devices don't do this since
728
  // We never forward up packets that we sent.  Real devices don't do this since
662
  // their receivers are disabled during send, so we don't. Drop the packet
729
  // their receivers are disabled during send, so we don't.
663
  // silently (no tracing) since it would really never get here in a real device.
664
  // 
730
  // 
665
  if (senderDevice == this)
731
  if (senderDevice == this)
666
    {
732
    {
667
      return;
733
      return;
668
    }
734
    }
669
735
736
  //
737
  // Hit the trace hook.  This trace will fire on all packets received from the
738
  // channel except those originated by this device.
739
  //
740
  m_phyRxTrace (packet);
741
670
  // 
742
  // 
671
  // Only receive if the send side of net device is enabled
743
  // Only receive if the send side of net device is enabled
672
  //
744
  //
673
  if (IsReceiveEnabled () == false)
745
  if (IsReceiveEnabled () == false)
674
    {
746
    {
675
      m_dropTrace (packet);
747
      m_phyRxDropTrace (packet);
676
      return;
748
      return;
677
    }
749
    }
678
750
 Lines 695-701   CsmaNetDevice::Receive (Ptr<Packet> pack Link Here 
695
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
767
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
696
    {
768
    {
697
      NS_LOG_LOGIC ("Dropping pkt due to error model ");
769
      NS_LOG_LOGIC ("Dropping pkt due to error model ");
698
      m_dropTrace (packet);
770
      m_phyRxDropTrace (packet);
699
    }
771
    }
700
  else
772
  else
701
    {
773
    {
 Lines 717-728   CsmaNetDevice::Receive (Ptr<Packet> pack Link Here 
717
          protocol = header.GetLengthType ();
789
          protocol = header.GetLengthType ();
718
        }
790
        }
719
791
792
      //
793
      // Classify the packet based on its destination.
794
      //
720
      PacketType packetType;
795
      PacketType packetType;
721
      
796
      
722
      if (header.GetDestination ().IsBroadcast ())
797
      if (header.GetDestination ().IsBroadcast ())
723
        {
798
        {
724
          packetType = PACKET_BROADCAST;
799
          packetType = PACKET_BROADCAST;
725
          m_rxTrace (originalPacket);
726
        }
800
        }
727
      else if (header.GetDestination ().IsMulticast () ||
801
      else if (header.GetDestination ().IsMulticast () ||
728
          header.GetDestination() == multicast6Node ||
802
          header.GetDestination() == multicast6Node ||
 Lines 731-755   CsmaNetDevice::Receive (Ptr<Packet> pack Link Here 
731
          header.GetDestination() == multicast6AllHosts)
805
          header.GetDestination() == multicast6AllHosts)
732
        {
806
        {
733
          packetType = PACKET_MULTICAST;          
807
          packetType = PACKET_MULTICAST;          
734
          m_rxTrace (originalPacket);
735
        }
808
        }
736
      else if (header.GetDestination () == m_address)
809
      else if (header.GetDestination () == m_address)
737
        {
810
        {
738
          packetType = PACKET_HOST;
811
          packetType = PACKET_HOST;
739
          m_rxTrace (originalPacket);
740
        }
812
        }
741
      else
813
      else
742
        {
814
        {
743
          packetType = PACKET_OTHERHOST;
815
          packetType = PACKET_OTHERHOST;
744
        }
816
        }
745
      
817
818
      // 
819
      // For all kinds of packetType we receive, we hit the promiscuous sniffer
820
      // hook and pass a copy up to the promiscuous callback.  Pass a copy to 
821
      // make sure that nobody messes with our packet.
822
      //
823
      m_promiscSnifferTrace (originalPacket);
746
      if (!m_promiscRxCallback.IsNull ())
824
      if (!m_promiscRxCallback.IsNull ())
747
        {
825
        {
748
          m_promiscRxCallback (this, packet, protocol, header.GetSource (), header.GetDestination (), packetType);
826
          m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), packetType);
749
        }
827
        }
750
828
829
      //
830
      // If this packet is not destined for some other host, it must be for us
831
      // as either a broadcast, multicast or unicast.  We need to hit the mac
832
      // packet received trace hook and forward the packet up the stack.
833
      //
751
      if (packetType != PACKET_OTHERHOST)
834
      if (packetType != PACKET_OTHERHOST)
752
        {
835
        {
836
          m_snifferTrace (originalPacket);
837
          m_macRxTrace (originalPacket);
753
          m_rxCallback (this, packet, protocol, header.GetSource ());
838
          m_rxCallback (this, packet, protocol, header.GetSource ());
754
        }
839
        }
755
    }
840
    }
 Lines 893-899   CsmaNetDevice::SendFrom (Ptr<Packet> pac Link Here 
893
CsmaNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
978
CsmaNetDevice::SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber)
894
{
979
{
895
  NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
980
  NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
896
  NS_LOG_LOGIC ("p=" << packet);
981
  NS_LOG_LOGIC ("packet =" << packet);
897
  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
982
  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
898
983
899
  NS_ASSERT (IsLinkUp ());
984
  NS_ASSERT (IsLinkUp ());
 Lines 903-908   CsmaNetDevice::SendFrom (Ptr<Packet> pac Link Here 
903
  //
988
  //
904
  if (IsSendEnabled () == false)
989
  if (IsSendEnabled () == false)
905
    {
990
    {
991
      m_macTxDropTrace (packet);
906
      return false;
992
      return false;
907
    }
993
    }
908
994
 Lines 910-920   CsmaNetDevice::SendFrom (Ptr<Packet> pac Link Here 
910
  Mac48Address source = Mac48Address::ConvertFrom (src);
996
  Mac48Address source = Mac48Address::ConvertFrom (src);
911
  AddHeader (packet, source, destination, protocolNumber);
997
  AddHeader (packet, source, destination, protocolNumber);
912
998
999
  m_macTxTrace (packet);
1000
913
  //
1001
  //
914
  // Place the packet to be sent on the send queue
1002
  // Place the packet to be sent on the send queue.  Note that the 
1003
  // queue may fire a drop trace, but we will too.
915
  //
1004
  //
916
  if (m_queue->Enqueue(packet) == false)
1005
  if (m_queue->Enqueue(packet) == false)
917
    {
1006
    {
1007
      m_macTxDropTrace (packet);
918
      return false;
1008
      return false;
919
    }
1009
    }
920
1010
 Lines 925-936   CsmaNetDevice::SendFrom (Ptr<Packet> pac Link Here 
925
  //
1015
  //
926
  if (m_txMachineState == READY) 
1016
  if (m_txMachineState == READY) 
927
    {
1017
    {
928
      //
1018
      if (m_queue->IsEmpty () == false)
929
      // The next packet to be transmitted goes in m_currentPkt
930
      //
931
      m_currentPkt = m_queue->Dequeue ();
932
      if (m_currentPkt != 0)
933
        {
1019
        {
1020
          m_currentPkt = m_queue->Dequeue ();
1021
          NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?");
1022
          m_promiscSnifferTrace (packet);
1023
          m_snifferTrace (packet);
934
          TransmitStart ();
1024
          TransmitStart ();
935
        }
1025
        }
936
    }
1026
    }
(-)a/src/devices/csma/csma-net-device.h (-7 / +115 lines)
 Lines 637-661   private: Link Here 
637
  Ptr<Queue> m_queue;
637
  Ptr<Queue> m_queue;
638
638
639
  /**
639
  /**
640
   * Error model for receive packet events
640
   * Error model for receive packet events.  When active this model will be
641
   * used to model transmission errors by marking some of the packets 
642
   * received as corrupt.
641
   */
643
   */
642
  Ptr<ErrorModel> m_receiveErrorModel;
644
  Ptr<ErrorModel> m_receiveErrorModel;
643
645
644
  /**
646
  /**
645
   * The trace source for the packet reception events that the device can
647
   * The trace source fired when packets come into the "top" of the device
646
   * fire.
648
   * at the L3/L2 transition, before being queued for transmission.
647
   *
649
   *
648
   * \see class CallBackTraceSource
650
   * \see class CallBackTraceSource
649
   */
651
   */
650
  TracedCallback<Ptr<const Packet> > m_rxTrace;
652
  TracedCallback<Ptr<const Packet> > m_macTxTrace;
651
653
652
  /**
654
  /**
653
   * The trace source for the packet drop events that the device can
655
   * The trace source fired when packets coming into the "top" of the device
654
   * fire.
656
   * at the L3/L2 transition are dropped before being queued for transmission.
655
   *
657
   *
656
   * \see class CallBackTraceSource
658
   * \see class CallBackTraceSource
657
   */
659
   */
658
  TracedCallback<Ptr<const Packet> > m_dropTrace;
660
  TracedCallback<Ptr<const Packet> > m_macTxDropTrace;
661
662
  /**
663
   * The trace source fired for packets successfully received by the device
664
   * immediately before being forwarded up to higher layers (at the L2/L3 
665
   * transition).
666
   *
667
   * \see class CallBackTraceSource
668
   */
669
  TracedCallback<Ptr<const Packet> > m_macRxTrace;
670
671
  /**
672
   * The trace source fired when a packet starts the transmission process on
673
   * the medium.
674
   *
675
   * \see class CallBackTraceSource
676
   */
677
  TracedCallback<Ptr<const Packet> > m_phyTxStartTrace;
678
679
  /**
680
   * The trace source fired when a packet ends the transmission process on
681
   * the medium.
682
   *
683
   * \see class CallBackTraceSource
684
   */
685
  TracedCallback<Ptr<const Packet> > m_phyTxTrace;
686
687
  /**
688
   * The trace source fired when the phy layer drops a packet as it tries
689
   * to transmit it.
690
   *
691
   * \see class CallBackTraceSource
692
   */
693
  TracedCallback<Ptr<const Packet> > m_phyTxDropTrace;
694
695
  /**
696
   * The trace source fired when a packet ends the reception process from
697
   * the medium.
698
   *
699
   * \see class CallBackTraceSource
700
   */
701
  TracedCallback<Ptr<const Packet> > m_phyRxTrace;
702
703
  /**
704
   * The trace source fired when a packet ends the reception process from
705
   * the medium.
706
   *
707
   * \see class CallBackTraceSource
708
   */
709
  TracedCallback<Ptr<const Packet> > m_phyRxStartTrace;
710
711
  /**
712
   * The trace source fired when the phy layer drops a packet it has received.
713
   *
714
   * \see class CallBackTraceSource
715
   */
716
  TracedCallback<Ptr<const Packet> > m_phyRxDropTrace;
717
718
  /**
719
   * The trace source fired when the phy layer is forced to begin the backoff
720
   * process for a packet.  This can happen a number of times as the backoff
721
   * sequence is repeated with increasing delays.
722
   *
723
   * \see class CallBackTraceSource
724
   */
725
  TracedCallback<Ptr<const Packet> > m_phyTxBackoffTrace;
726
727
  /**
728
   * A trace source that emulates a non-promiscuous protocol sniffer connected 
729
   * to the device.  Unlike your average everyday sniffer, this trace source 
730
   * will not fire on PACKET_OTHERHOST events.
731
   *
732
   * On the transmit size, this trace hook will fire after a packet is dequeued
733
   * from the device queue for transmission.  In Linux, for example, this would
734
   * correspond to the point just before a device hard_start_xmit where 
735
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
736
   * ETH_P_ALL handlers.
737
   *
738
   * On the receive side, this trace hook will fire when a packet is received,
739
   * just before the receive callback is executed.  In Linux, for example, 
740
   * this would correspond to the point at which the packet is dispatched to 
741
   * packet sniffers in netif_receive_skb.
742
   *
743
   * \see class CallBackTraceSource
744
   */
745
  TracedCallback<Ptr<const Packet> > m_snifferTrace;
746
747
  /**
748
   * A trace source that emulates a promiscuous mode protocol sniffer connected
749
   * to the device.  This trace source fire on packets destined for any host
750
   * just like your average everyday packet sniffer.
751
   *
752
   * On the transmit size, this trace hook will fire after a packet is dequeued
753
   * from the device queue for transmission.  In Linux, for example, this would
754
   * correspond to the point just before a device hard_start_xmit where 
755
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
756
   * ETH_P_ALL handlers.
757
   *
758
   * On the receive side, this trace hook will fire when a packet is received,
759
   * just before the receive callback is executed.  In Linux, for example, 
760
   * this would correspond to the point at which the packet is dispatched to 
761
   * packet sniffers in netif_receive_skb.
762
   *
763
   * \see class CallBackTraceSource
764
   */
765
  TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace;
659
766
660
  /**
767
  /**
661
   * The Node to which this device is attached.
768
   * The Node to which this device is attached.
 Lines 671-676   private: Link Here 
671
   * The callback used to notify higher layers that a packet has been received.
778
   * The callback used to notify higher layers that a packet has been received.
672
   */
779
   */
673
  NetDevice::ReceiveCallback m_rxCallback;
780
  NetDevice::ReceiveCallback m_rxCallback;
781
674
  /**
782
  /**
675
   * The callback used to notify higher layers that a packet has been received in promiscuous mode.
783
   * The callback used to notify higher layers that a packet has been received in promiscuous mode.
676
   */
784
   */
(-)a/src/devices/emu/emu-net-device.cc (-51 / +149 lines)
 Lines 22-38    Link Here 
22
#include "ns3/log.h"
22
#include "ns3/log.h"
23
#include "ns3/queue.h"
23
#include "ns3/queue.h"
24
#include "ns3/simulator.h"
24
#include "ns3/simulator.h"
25
#include "ns3/realtime-simulator-impl.h"
26
#include "ns3/mac48-address.h"
27
#include "ns3/ethernet-header.h"
25
#include "ns3/ethernet-header.h"
28
#include "ns3/ethernet-trailer.h"
26
#include "ns3/ethernet-trailer.h"
29
#include "ns3/llc-snap-header.h"
27
#include "ns3/llc-snap-header.h"
28
#include "ns3/boolean.h"
29
#include "ns3/uinteger.h"
30
#include "ns3/pointer.h"
31
#include "ns3/string.h"
30
#include "ns3/trace-source-accessor.h"
32
#include "ns3/trace-source-accessor.h"
31
#include "ns3/pointer.h"
32
#include "ns3/channel.h"
33
#include "ns3/channel.h"
33
#include "ns3/system-thread.h"
34
#include "ns3/system-thread.h"
34
#include "ns3/string.h"
35
#include "ns3/realtime-simulator-impl.h"
35
#include "ns3/boolean.h"
36
#include "ns3/mac48-address.h"
36
37
37
#include <sys/wait.h>
38
#include <sys/wait.h>
38
#include <sys/stat.h>
39
#include <sys/stat.h>
 Lines 82-95   EmuNetDevice::GetTypeId (void) Link Here 
82
                   TimeValue (Seconds (0.)),
83
                   TimeValue (Seconds (0.)),
83
                   MakeTimeAccessor (&EmuNetDevice::m_tStop),
84
                   MakeTimeAccessor (&EmuNetDevice::m_tStop),
84
                   MakeTimeChecker ())
85
                   MakeTimeChecker ())
86
87
    //
88
    // Transmit queueing discipline for the device which includes its own set
89
    // of trace hooks.  Note that this is really going to run "on top of" the 
90
    // queueing discipline that will most likely be present in the devices of
91
    // the underlying operating system.
92
    //
85
    .AddAttribute ("TxQueue", 
93
    .AddAttribute ("TxQueue", 
86
                   "A queue to use as the transmit queue in the device.",
94
                   "A queue to use as the transmit queue in the device.",
87
                   PointerValue (),
95
                   PointerValue (),
88
                   MakePointerAccessor (&EmuNetDevice::m_queue),
96
                   MakePointerAccessor (&EmuNetDevice::m_queue),
89
                   MakePointerChecker<Queue> ())
97
                   MakePointerChecker<Queue> ())
90
    .AddTraceSource ("Rx", 
98
91
                     "Trace source indicating recvfrom of packet destined for broadcast, multicast or local address.",
99
    //
92
                     MakeTraceSourceAccessor (&EmuNetDevice::m_rxTrace))
100
    // Trace sources at the "top" of the net device, where packets transition
101
    // to/from higher layers.  These points do not really correspond to the 
102
    // MAC layer of the underlying operating system, but exist to provide 
103
    // a consitent tracing environment.  These trace hooks should really be
104
    // interpreted as the points at which a packet leaves the ns-3 environment
105
    // destined for the underlying operating system or vice-versa.
106
    //
107
    .AddTraceSource ("MacTx", 
108
                     "Trace source indicating a packet has arrived for transmission by this device",
109
                     MakeTraceSourceAccessor (&EmuNetDevice::m_macTxTrace))
110
    .AddTraceSource ("MacTxDrop", 
111
                     "Trace source indicating a packet has been dropped by the device before transmission",
112
                     MakeTraceSourceAccessor (&EmuNetDevice::m_macTxDropTrace))
113
    .AddTraceSource ("MacRx", 
114
                     "Trace source indicating a packet has been received by this device and is being forwarded up the stack",
115
                     MakeTraceSourceAccessor (&EmuNetDevice::m_macRxTrace))
116
    //
117
    // In normal ns-3 net devices, these trace souces correspond to the "bottom"
118
    // of the net device, where packets transition to/from the channel.  In 
119
    // the case of the emu device, there is no physical layer access and so
120
    // these are duplicates of the MAC-level hooks.  Intepret these points
121
    // also as the points at which a packet leaves the ns-3 environment
122
    // destined for the underlying operating system or vice-versa.
123
    //
124
    .AddTraceSource ("PhyTxStart", 
125
                     "Trace source indicating a packet has begun transmitting over the channel",
126
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxStartTrace))
127
    .AddTraceSource ("PhyTx", 
128
                     "Trace source indicating a packet has been completely transmitted over the channel",
129
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxTrace))
130
    .AddTraceSource ("PhyTxDrop", 
131
                     "Trace source indicating a packet has been dropped by the device during transmission",
132
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyTxDropTrace))
133
    .AddTraceSource ("PhyRxStart", 
134
                     "Trace source indicating a packet has begun being received by the device",
135
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxStartTrace))
136
    .AddTraceSource ("PhyRx", 
137
                     "Trace source indicating a packet has been completely received by the device",
138
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxTrace))
139
    .AddTraceSource ("PhyRxDrop", 
140
                     "Trace source indicating a packet has been dropped by the device during reception",
141
                     MakeTraceSourceAccessor (&EmuNetDevice::m_phyRxDropTrace))
142
143
    //
144
    // Trace sources designed to simulate a packet sniffer facility (tcpdump). 
145
    //
146
    .AddTraceSource ("Sniffer", 
147
                     "Trace source simulating a non-promiscuous packet sniffer attached to the device",
148
                     MakeTraceSourceAccessor (&EmuNetDevice::m_snifferTrace))
149
    .AddTraceSource ("PromiscSniffer", 
150
                     "Trace source simulating a promiscuous packet sniffer attached to the device",
151
                     MakeTraceSourceAccessor (&EmuNetDevice::m_promiscSnifferTrace))
93
    ;
152
    ;
94
  return tid;
153
  return tid;
95
}
154
}
 Lines 490-495   EmuNetDevice::ForwardUp (uint8_t *buf, u Link Here 
490
{
549
{
491
  NS_LOG_FUNCTION (buf << len);
550
  NS_LOG_FUNCTION (buf << len);
492
551
552
  /* IPv6 support*/
553
  uint8_t mac[6];
554
  Mac48Address multicast6AllNodes("33:33:00:00:00:01");
555
  Mac48Address multicast6AllRouters("33:33:00:00:00:02");
556
  Mac48Address multicast6AllHosts("33:33:00:00:00:03");
557
  Mac48Address multicast6Node; /* multicast address addressed to our MAC address */
558
559
  /* generate IPv6 multicast ethernet destination that nodes will accept */
560
  GetAddress().CopyTo(mac);
561
  mac[0]=0x33;
562
  mac[1]=0x33;
563
  multicast6Node.CopyFrom(mac);
564
493
  //
565
  //
494
  // Create a packet out of the buffer we received and free that buffer.
566
  // Create a packet out of the buffer we received and free that buffer.
495
  //
567
  //
 Lines 504-509   EmuNetDevice::ForwardUp (uint8_t *buf, u Link Here 
504
  Ptr<Packet> originalPacket = packet->Copy ();
576
  Ptr<Packet> originalPacket = packet->Copy ();
505
577
506
  //
578
  //
579
  // Hit the trace hook.  This trace will fire on all packets received from the
580
  // OS (promiscuous).  Packets are received instantaneously.
581
  //
582
  m_phyRxStartTrace (packet);
583
  m_phyRxTrace (packet);
584
585
  //
507
  // Checksum the packet
586
  // Checksum the packet
508
  //
587
  //
509
  EthernetTrailer trailer;
588
  EthernetTrailer trailer;
 Lines 516-558   EmuNetDevice::ForwardUp (uint8_t *buf, u Link Here 
516
  NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
595
  NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
517
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
596
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
518
597
519
  LlcSnapHeader llc;
598
  uint16_t protocol;
520
  packet->RemoveHeader (llc);
599
  
521
  uint16_t protocol = llc.GetType ();
600
  //
601
  // If the length/type is less than 1500, it corresponds to a length 
602
  // interpretation packet.  In this case, it is an 802.3 packet and 
603
  // will also have an 802.2 LLC header.  If greater than 1500, we
604
  // find the protocol number (Ethernet type) directly.
605
  //
606
  if (header.GetLengthType () <= 1500)
607
    {
608
      LlcSnapHeader llc;
609
      packet->RemoveHeader (llc);
610
      protocol = llc.GetType ();
611
    }
612
  else
613
    {
614
      protocol = header.GetLengthType ();
615
    }
522
616
523
  PacketType packetType;
617
  PacketType packetType;
524
      
618
      
525
  if (header.GetDestination ().IsBroadcast ())
619
  if (header.GetDestination ().IsBroadcast ())
526
    {
620
    {
527
      NS_LOG_LOGIC ("Pkt destination is PACKET_BROADCAST");
528
      packetType = NS3_PACKET_BROADCAST;
621
      packetType = NS3_PACKET_BROADCAST;
529
    }
622
    }
530
  else if (header.GetDestination ().IsMulticast ())
623
  else if (header.GetDestination ().IsMulticast () ||
624
           header.GetDestination() == multicast6Node ||
625
           header.GetDestination() == multicast6AllNodes ||
626
           header.GetDestination() == multicast6AllRouters ||
627
           header.GetDestination() == multicast6AllHosts)
531
    {
628
    {
532
      NS_LOG_LOGIC ("Pkt destination is PACKET_MULTICAST");
629
      packetType = NS3_PACKET_MULTICAST;          
533
      packetType = NS3_PACKET_MULTICAST;
534
    }
630
    }
535
  else if (header.GetDestination () == m_address)
631
  else if (header.GetDestination () == m_address)
536
    {
632
    {
537
      NS_LOG_LOGIC ("Pkt destination is PACKET_HOST");
538
      packetType = NS3_PACKET_HOST;
633
      packetType = NS3_PACKET_HOST;
539
    }
634
    }
540
  else
635
  else
541
    {
636
    {
542
      NS_LOG_LOGIC ("Pkt destination is PACKET_OTHERHOST");
543
      packetType = NS3_PACKET_OTHERHOST;
637
      packetType = NS3_PACKET_OTHERHOST;
544
    }
638
    }
545
639
640
  // 
641
  // For all kinds of packetType we receive, we hit the promiscuous sniffer
642
  // hook and pass a copy up to the promiscuous callback.  Pass a copy to 
643
  // make sure that nobody messes with our packet.
644
  //
645
  m_promiscSnifferTrace (originalPacket);
546
  if (!m_promiscRxCallback.IsNull ())
646
  if (!m_promiscRxCallback.IsNull ())
547
    {
647
    {
548
      NS_LOG_LOGIC ("calling m_promiscRxCallback");
549
      m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), packetType);
648
      m_promiscRxCallback (this, packet->Copy (), protocol, header.GetSource (), header.GetDestination (), packetType);
550
    }
649
    }
551
650
651
  //
652
  // If this packet is not destined for some other host, it must be for us
653
  // as either a broadcast, multicast or unicast.  We need to hit the mac
654
  // packet received trace hook and forward the packet up the stack.
655
  //
552
  if (packetType != NS3_PACKET_OTHERHOST)
656
  if (packetType != NS3_PACKET_OTHERHOST)
553
    {
657
    {
554
      m_rxTrace (originalPacket);
658
      m_snifferTrace (originalPacket);
555
      NS_LOG_LOGIC ("calling m_rxCallback");
659
      m_macRxTrace (originalPacket);
556
      m_rxCallback (this, packet, protocol, header.GetSource ());
660
      m_rxCallback (this, packet, protocol, header.GetSource ());
557
    }
661
    }
558
}
662
}
 Lines 632-641   EmuNetDevice::SendFrom (Ptr<Packet> pack Link Here 
632
EmuNetDevice::SendFrom (Ptr<Packet> packet, const Address &src, const Address &dest, uint16_t protocolNumber)
736
EmuNetDevice::SendFrom (Ptr<Packet> packet, const Address &src, const Address &dest, uint16_t protocolNumber)
633
{
737
{
634
  NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
738
  NS_LOG_FUNCTION (packet << src << dest << protocolNumber);
739
  NS_LOG_LOGIC ("packet =" << packet);
740
  NS_LOG_LOGIC ("UID is " << packet->GetUid () << ")");
635
741
636
  if (IsLinkUp () == false)
742
  if (IsLinkUp () == false)
637
    {
743
    {
638
      NS_LOG_LOGIC ("Link is down, returning");
744
      m_macTxDropTrace (packet);
639
      return false;
745
      return false;
640
    }
746
    }
641
747
 Lines 646-679   EmuNetDevice::SendFrom (Ptr<Packet> pack Link Here 
646
  NS_LOG_LOGIC ("Transmit packet from " << source);
752
  NS_LOG_LOGIC ("Transmit packet from " << source);
647
  NS_LOG_LOGIC ("Transmit packet to " << destination);
753
  NS_LOG_LOGIC ("Transmit packet to " << destination);
648
754
649
#if 0
755
  //
650
  {
756
  // We've got to pick either DIX (Ethernet) or LLC/SNAP (IEEE 802.3) as a 
651
    struct ifreq ifr;
757
  // packet format.  IEEE 802.3 is slightly more formally correct, so we 
652
    bzero (&ifr, sizeof(ifr));
758
  // go that route.
653
    strncpy ((char *)ifr.ifr_name, m_deviceName.c_str (), IFNAMSIZ);
759
  //
654
655
    NS_LOG_LOGIC ("Getting MAC address");
656
    int32_t rc = ioctl (m_sock, SIOCGIFHWADDR, &ifr);
657
    if (rc == -1)
658
      {
659
        NS_FATAL_ERROR ("EmuNetDevice::SendFrom(): Can't get MAC address");
660
      }
661
662
    std::ostringstream oss;
663
    oss << std::hex <<
664
      (ifr.ifr_hwaddr.sa_data[0] & 0xff) << ":" <<
665
      (ifr.ifr_hwaddr.sa_data[1] & 0xff) << ":" <<
666
      (ifr.ifr_hwaddr.sa_data[2] & 0xff) << ":" <<
667
      (ifr.ifr_hwaddr.sa_data[3] & 0xff) << ":" <<
668
      (ifr.ifr_hwaddr.sa_data[4] & 0xff) << ":" <<
669
      (ifr.ifr_hwaddr.sa_data[5] & 0xff) << std::dec;
670
671
    NS_LOG_LOGIC ("Fixup source to HW MAC " << oss.str ());
672
    source = Mac48Address (oss.str ().c_str ());
673
    NS_LOG_LOGIC ("source now " << source);
674
  }
675
#endif
676
677
  LlcSnapHeader llc;
760
  LlcSnapHeader llc;
678
  llc.SetType (protocolNumber);
761
  llc.SetType (protocolNumber);
679
  packet->AddHeader (llc);
762
  packet->AddHeader (llc);
 Lines 688-698   EmuNetDevice::SendFrom (Ptr<Packet> pack Link Here 
688
  trailer.CalcFcs (packet);
771
  trailer.CalcFcs (packet);
689
  packet->AddTrailer (trailer);
772
  packet->AddTrailer (trailer);
690
773
774
  //
775
  // there's not much meaning associated with the different layers in this
776
  // device, so don't be surprised when they're all stacked together in 
777
  // essentially one place.  We do this for trace consistency across devices.
778
  //
779
  m_macTxTrace (packet);
780
691
  // 
781
  // 
692
  // Enqueue and dequeue the packet to hit the tracing hooks.
782
  // Enqueue and dequeue the packet to hit the queue tracing hooks.
693
  //
783
  //
694
  m_queue->Enqueue (packet);
784
  m_queue->Enqueue (packet);
695
  packet = m_queue->Dequeue ();
785
  packet = m_queue->Dequeue ();
786
  NS_ASSERT_MSG (packet, "EmuNetDevice::SendFrom(): packet zero from queue");
787
788
  m_promiscSnifferTrace (packet);
789
  m_snifferTrace (packet);
790
696
791
697
  struct sockaddr_ll ll;
792
  struct sockaddr_ll ll;
698
  bzero (&ll, sizeof (ll));
793
  bzero (&ll, sizeof (ll));
 Lines 703-712   EmuNetDevice::SendFrom (Ptr<Packet> pack Link Here 
703
798
704
  NS_LOG_LOGIC ("calling sendto");
799
  NS_LOG_LOGIC ("calling sendto");
705
800
801
  m_phyTxStartTrace (packet);
802
706
  int32_t rc;
803
  int32_t rc;
707
  rc = sendto (m_sock, packet->PeekData (), packet->GetSize (), 0, reinterpret_cast<struct sockaddr *> (&ll), sizeof (ll));
804
  rc = sendto (m_sock, packet->PeekData (), packet->GetSize (), 0, reinterpret_cast<struct sockaddr *> (&ll), sizeof (ll));
805
  NS_LOG_LOGIC ("sendto returns " << rc);
708
806
709
  NS_LOG_LOGIC ("sendto returns " << rc);
807
  m_phyTxTrace (packet);
710
808
711
  return rc == -1 ? false : true;
809
  return rc == -1 ? false : true;
712
}
810
}
(-)a/src/devices/emu/emu-net-device.h (-8 / +104 lines)
 Lines 264-283   private: Link Here 
264
  Ptr<Queue> m_queue;
264
  Ptr<Queue> m_queue;
265
265
266
  /**
266
  /**
267
   * The trace source for the packet reception events that the device can
267
   * The trace source fired when packets come into the "top" of the device
268
   * fire.
268
   * at the L3/L2 transition, before being queued for transmission.
269
   *
269
   *
270
   * @see class CallBackTraceSource
270
   * \see class CallBackTraceSource
271
   */
271
   */
272
  TracedCallback<Ptr<const Packet> > m_rxTrace;
272
  TracedCallback<Ptr<const Packet> > m_macTxTrace;
273
273
274
  /**
274
  /**
275
   * The trace source for the packet drop events that the device can
275
   * The trace source fired when packets coming into the "top" of the device
276
   * fire.
276
   * at the L3/L2 transition are dropped before being queued for transmission.
277
   *
277
   *
278
   * @see class CallBackTraceSource
278
   * \see class CallBackTraceSource
279
   */
279
   */
280
  TracedCallback<Ptr<const Packet> > m_dropTrace;
280
  TracedCallback<Ptr<const Packet> > m_macTxDropTrace;
281
282
  /**
283
   * The trace source fired for packets successfully received by the device
284
   * immediately before being forwarded up to higher layers (at the L2/L3 
285
   * transition).
286
   *
287
   * \see class CallBackTraceSource
288
   */
289
  TracedCallback<Ptr<const Packet> > m_macRxTrace;
290
291
  /**
292
   * The trace source fired when a packet starts the transmission process on
293
   * the medium.
294
   *
295
   * \see class CallBackTraceSource
296
   */
297
  TracedCallback<Ptr<const Packet> > m_phyTxStartTrace;
298
299
  /**
300
   * The trace source fired when a packet ends the transmission process on
301
   * the medium.
302
   *
303
   * \see class CallBackTraceSource
304
   */
305
  TracedCallback<Ptr<const Packet> > m_phyTxTrace;
306
307
  /**
308
   * The trace source fired when the phy layer drops a packet as it tries
309
   * to transmit it.
310
   *
311
   * \see class CallBackTraceSource
312
   */
313
  TracedCallback<Ptr<const Packet> > m_phyTxDropTrace;
314
315
  /**
316
   * The trace source fired when a packet ends the reception process from
317
   * the medium.
318
   *
319
   * \see class CallBackTraceSource
320
   */
321
  TracedCallback<Ptr<const Packet> > m_phyRxTrace;
322
323
  /**
324
   * The trace source fired when a packet starts the reception process from
325
   * the medium.
326
   *
327
   * \see class CallBackTraceSource
328
   */
329
  TracedCallback<Ptr<const Packet> > m_phyRxStartTrace;
330
331
  /**
332
   * The trace source fired when the phy layer drops a packet it has received.
333
   *
334
   * \see class CallBackTraceSource
335
   */
336
  TracedCallback<Ptr<const Packet> > m_phyRxDropTrace;
337
338
  /**
339
   * A trace source that emulates a non-promiscuous protocol sniffer connected 
340
   * to the device.  Unlike your average everyday sniffer, this trace source 
341
   * will not fire on PACKET_OTHERHOST events.
342
   *
343
   * On the transmit size, this trace hook will fire after a packet is dequeued
344
   * from the device queue for transmission.  In Linux, for example, this would
345
   * correspond to the point just before a device hard_start_xmit where 
346
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
347
   * ETH_P_ALL handlers.
348
   *
349
   * On the receive side, this trace hook will fire when a packet is received,
350
   * just before the receive callback is executed.  In Linux, for example, 
351
   * this would correspond to the point at which the packet is dispatched to 
352
   * packet sniffers in netif_receive_skb.
353
   *
354
   * \see class CallBackTraceSource
355
   */
356
  TracedCallback<Ptr<const Packet> > m_snifferTrace;
357
358
  /**
359
   * A trace source that emulates a promiscuous mode protocol sniffer connected
360
   * to the device.  This trace source fire on packets destined for any host
361
   * just like your average everyday packet sniffer.
362
   *
363
   * On the transmit size, this trace hook will fire after a packet is dequeued
364
   * from the device queue for transmission.  In Linux, for example, this would
365
   * correspond to the point just before a device hard_start_xmit where 
366
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
367
   * ETH_P_ALL handlers.
368
   *
369
   * On the receive side, this trace hook will fire when a packet is received,
370
   * just before the receive callback is executed.  In Linux, for example, 
371
   * this would correspond to the point at which the packet is dispatched to 
372
   * packet sniffers in netif_receive_skb.
373
   *
374
   * \see class CallBackTraceSource
375
   */
376
  TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace;
281
377
282
  /**
378
  /**
283
   * Time to start spinning up the device
379
   * Time to start spinning up the device
(-)a/src/devices/point-to-point/point-to-point-channel.h (-3 / +3 lines)
 Lines 62-74   public: Link Here 
62
  void Attach (Ptr<PointToPointNetDevice> device);
62
  void Attach (Ptr<PointToPointNetDevice> device);
63
63
64
  /**
64
  /**
65
   * \brief Attach a given netdevice to this channel
65
   * \brief Transmit a packet over this channel
66
   * \param p Packet to transmit
66
   * \param p Packet to transmit
67
   * \param src Source PointToPointNetDevice
67
   * \param src Source PointToPointNetDevice
68
   * \param txTime Transmit time to apply
68
   * \param txTime Transmit time to apply
69
   * \returns true if successful (currently always true)
69
   */
70
   */
70
  bool TransmitStart (Ptr<Packet> p, Ptr<PointToPointNetDevice> src,
71
  bool TransmitStart (Ptr<Packet> p, Ptr<PointToPointNetDevice> src, Time txTime);
71
    Time txTime);
72
72
73
  /**
73
  /**
74
   * \brief Get number of devices on this channel
74
   * \brief Get number of devices on this channel
(-)a/src/devices/point-to-point/point-to-point-net-device.cc (-70 / +146 lines)
 Lines 62-84   PointToPointNetDevice::GetTypeId (void) Link Here 
62
                   PointerValue (),
62
                   PointerValue (),
63
                   MakePointerAccessor (&PointToPointNetDevice::m_receiveErrorModel),
63
                   MakePointerAccessor (&PointToPointNetDevice::m_receiveErrorModel),
64
                   MakePointerChecker<ErrorModel> ())
64
                   MakePointerChecker<ErrorModel> ())
65
    .AddAttribute ("TxQueue",
66
                   "A queue to use as the transmit queue in the device.",
67
                   PointerValue (),
68
                   MakePointerAccessor (&PointToPointNetDevice::m_queue),
69
                   MakePointerChecker<Queue> ())
70
    .AddAttribute ("InterframeGap", 
65
    .AddAttribute ("InterframeGap", 
71
                   "The time to wait between packet (frame) transmissions",
66
                   "The time to wait between packet (frame) transmissions",
72
                   TimeValue (Seconds (0.0)),
67
                   TimeValue (Seconds (0.0)),
73
                   MakeTimeAccessor (&PointToPointNetDevice::m_tInterframeGap),
68
                   MakeTimeAccessor (&PointToPointNetDevice::m_tInterframeGap),
74
                   MakeTimeChecker ())
69
                   MakeTimeChecker ())
75
    .AddTraceSource ("Rx", 
76
                     "Trace source indicating reception of packet from the PointToPointChannel.",
77
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_rxTrace))
78
    .AddTraceSource ("Drop",
79
                     "Trace source indicating a packet was discarded due to a ReceiveErrorModel decision.",
80
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_dropTrace))
81
70
71
    //
72
    // Transmit queueing discipline for the device which includes its own set
73
    // of trace hooks.
74
    //
75
    .AddAttribute ("TxQueue", 
76
                   "A queue to use as the transmit queue in the device.",
77
                   PointerValue (),
78
                   MakePointerAccessor (&PointToPointNetDevice::m_queue),
79
                   MakePointerChecker<Queue> ())
80
81
    //
82
    // Trace sources at the "top" of the net device, where packets transition
83
    // to/from higher layers.
84
    //
85
    .AddTraceSource ("MacTx", 
86
                     "Trace source indicating a packet has arrived for transmission by this device",
87
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_macTxTrace))
88
    .AddTraceSource ("MacTxDrop", 
89
                     "Trace source indicating a packet has been dropped by the device before transmission",
90
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_macTxDropTrace))
91
    .AddTraceSource ("MacRx", 
92
                     "Trace source indicating a packet has been received by this device and is being forwarded up the stack",
93
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_macRxTrace))
94
    //
95
    // Trace souces at the "bottom" of the net device, where packets transition
96
    // to/from the channel.
97
    //
98
    .AddTraceSource ("PhyTxStart", 
99
                     "Trace source indicating a packet has begun transmitting over the channel",
100
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_phyTxStartTrace))
101
    .AddTraceSource ("PhyTx", 
102
                     "Trace source indicating a packet has been completely transmitted over the channel",
103
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_phyTxTrace))
104
    .AddTraceSource ("PhyTxDrop", 
105
                     "Trace source indicating a packet has been dropped by the device during transmission",
106
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_phyTxDropTrace))
107
    .AddTraceSource ("PhyRxStart", 
108
                     "Trace source indicating a packet has begun being received by the device",
109
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_phyRxStartTrace))
110
    .AddTraceSource ("PhyRx", 
111
                     "Trace source indicating a packet has been completely received by the device",
112
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_phyRxTrace))
113
    .AddTraceSource ("PhyRxDrop", 
114
                     "Trace source indicating a packet has been dropped by the device during reception",
115
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_phyRxDropTrace))
116
117
    //
118
    // Trace sources designed to simulate a packet sniffer facility (tcpdump).
119
    //
120
    .AddTraceSource ("Sniffer", 
121
                     "Trace source simulating a non-promiscuous packet sniffer attached to the device",
122
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_snifferTrace))
123
    .AddTraceSource ("PromiscSniffer", 
124
                     "Trace source simulating a promiscuous packet sniffer attached to the device",
125
                     MakeTraceSourceAccessor (&PointToPointNetDevice::m_promiscSnifferTrace))
82
    ;
126
    ;
83
  return tid;
127
  return tid;
84
}
128
}
 Lines 89-95   PointToPointNetDevice::PointToPointNetDe Link Here 
89
  m_txMachineState (READY),
133
  m_txMachineState (READY),
90
  m_channel (0), 
134
  m_channel (0), 
91
  m_name (""),
135
  m_name (""),
92
  m_linkUp (false)
136
  m_linkUp (false),
137
  m_currentPkt (0)
93
{
138
{
94
  NS_LOG_FUNCTION (this);
139
  NS_LOG_FUNCTION (this);
95
140
 Lines 112-119   PointToPointNetDevice::AddHeader(Ptr<Pac Link Here 
112
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
157
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber)
113
{
158
{
114
  NS_LOG_FUNCTION_NOARGS ();
159
  NS_LOG_FUNCTION_NOARGS ();
115
  NS_ASSERT_MSG (protocolNumber == 0x800,
160
  NS_ASSERT_MSG (protocolNumber == 0x800, "PointToPointNetDevice::AddHeader(): protocolNumber must be 0x800");
116
    "PointToPointNetDevice::AddHeader(): protocolNumber must be 0x800");
117
  PppHeader ppp;
161
  PppHeader ppp;
118
  p->AddHeader (ppp);
162
  p->AddHeader (ppp);
119
}
163
}
 Lines 135-140   PointToPointNetDevice::DoDispose() Link Here 
135
  m_node = 0;
179
  m_node = 0;
136
  m_channel = 0;
180
  m_channel = 0;
137
  m_receiveErrorModel = 0;
181
  m_receiveErrorModel = 0;
182
  m_currentPkt = 0;
138
  NetDevice::DoDispose ();
183
  NetDevice::DoDispose ();
139
}
184
}
140
185
 Lines 157-204   PointToPointNetDevice::TransmitStart (Pt Link Here 
157
{
202
{
158
  NS_LOG_FUNCTION (this << p);
203
  NS_LOG_FUNCTION (this << p);
159
  NS_LOG_LOGIC ("UID is " << p->GetUid () << ")");
204
  NS_LOG_LOGIC ("UID is " << p->GetUid () << ")");
160
//
205
161
// This function is called to start the process of transmitting a packet.
206
  //
162
// We need to tell the channel that we've started wiggling the wire and
207
  // This function is called to start the process of transmitting a packet.
163
// schedule an event that will be executed when the transmission is complete.
208
  // We need to tell the channel that we've started wiggling the wire and
164
//
209
  // schedule an event that will be executed when the transmission is complete.
210
  //
165
  NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit");
211
  NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit");
166
  m_txMachineState = BUSY;
212
  m_txMachineState = BUSY;
213
  m_phyTxTrace (m_currentPkt);
214
  m_currentPkt = p;
215
167
  Time txTime = Seconds (m_bps.CalculateTxTime(p->GetSize()));
216
  Time txTime = Seconds (m_bps.CalculateTxTime(p->GetSize()));
168
  Time txCompleteTime = txTime + m_tInterframeGap;
217
  Time txCompleteTime = txTime + m_tInterframeGap;
169
218
170
  NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << 
219
  NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << txCompleteTime.GetSeconds () << "sec");
171
    txCompleteTime.GetSeconds () << "sec");
220
  Simulator::Schedule (txCompleteTime, &PointToPointNetDevice::TransmitComplete, this);
172
221
173
  Simulator::Schedule (txCompleteTime, 
222
  bool result = m_channel->TransmitStart(p, this, txTime); 
174
    &PointToPointNetDevice::TransmitComplete, this);
223
  if (result == false)
175
224
    {
176
  return m_channel->TransmitStart(p, this, txTime); 
225
      m_phyTxDropTrace (p);
226
    }
227
  return result;
177
}
228
}
178
229
179
  void 
230
  void 
180
PointToPointNetDevice::TransmitComplete (void)
231
PointToPointNetDevice::TransmitComplete (void)
181
{
232
{
182
  NS_LOG_FUNCTION_NOARGS ();
233
  NS_LOG_FUNCTION_NOARGS ();
183
//
234
184
// This function is called to when we're all done transmitting a packet.
235
  //
185
// We try and pull another packet off of the transmit queue.  If the queue
236
  // This function is called to when we're all done transmitting a packet.
186
// is empty, we are done, otherwise we need to start transmitting the
237
  // We try and pull another packet off of the transmit queue.  If the queue
187
// next packet.
238
  // is empty, we are done, otherwise we need to start transmitting the
188
//
239
  // next packet.
240
  //
189
  NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
241
  NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
190
  m_txMachineState = READY;
242
  m_txMachineState = READY;
243
244
  NS_ASSERT_MSG (m_currentPkt != 0, "PointToPointNetDevice::TransmitComplete(): m_currentPkt zero");
245
246
  m_phyTxTrace (m_currentPkt);
247
  m_currentPkt = 0;
248
191
  Ptr<Packet> p = m_queue->Dequeue ();
249
  Ptr<Packet> p = m_queue->Dequeue ();
192
  if (p == 0)
250
  if (p == 0)
193
    {
251
    {
194
//
252
      //
195
// No packet was on the queue, so we just exit.
253
      // No packet was on the queue, so we just exit.
196
//
254
      //
197
      return;
255
      return;
198
    }
256
    }
199
//
257
200
// Got another packet off of the queue, so start the transmit process agin.
258
  //
201
//
259
  // Got another packet off of the queue, so start the transmit process agin.
260
  //
261
  m_snifferTrace (p);
202
  TransmitStart(p);
262
  TransmitStart(p);
203
}
263
}
204
264
 Lines 211-221   PointToPointNetDevice::Attach (Ptr<Point Link Here 
211
271
212
  m_channel->Attach(this);
272
  m_channel->Attach(this);
213
273
214
//
274
  //
215
// This device is up whenever it is attached to a channel.  A better plan
275
  // This device is up whenever it is attached to a channel.  A better plan
216
// would be to have the link come up when both devices are attached, but this
276
  // would be to have the link come up when both devices are attached, but this
217
// is not done for now.
277
  // is not done for now.
218
//
278
  //
219
  NotifyLinkUp ();
279
  NotifyLinkUp ();
220
  return true;
280
  return true;
221
}
281
}
 Lines 242-266   PointToPointNetDevice::Receive (Ptr<Pack Link Here 
242
302
243
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) 
303
  if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) 
244
    {
304
    {
245
// 
305
      // 
246
// If we have an error model and it indicates that it is time to lose a
306
      // If we have an error model and it indicates that it is time to lose a
247
// corrupted packet, don't forward this packet up, let it go.
307
      // corrupted packet, don't forward this packet up, let it go.
248
//
308
      //
249
      m_dropTrace (packet);
309
      m_phyRxDropTrace (packet);
250
    }
310
    }
251
  else 
311
  else 
252
    {
312
    {
253
// 
313
      // 
254
// Hit the receive trace hook, strip off the point-to-point protocol header
314
      // Hit the trace hooks.  All of these hooks are in the same place in this 
255
// and forward this packet up the protocol stack.
315
      // device becuase it is so simple, but this is not usually the case.  
256
//
316
      //
257
      m_rxTrace (packet);
317
      m_snifferTrace (packet);
318
      m_phyRxTrace (packet);
319
      m_macRxTrace (packet);
320
321
      //
322
      // Strip off the point-to-point protocol header and forward this packet
323
      // up the protocol stack.  Since this is a simple point-to-point link,
324
      // there is no difference in what the promisc callback sees and what the
325
      // normal receive callback sees.
326
      //
258
      ProcessHeader(packet, protocol);
327
      ProcessHeader(packet, protocol);
259
      m_rxCallback (this, packet, protocol, GetRemote ());
328
260
      if (!m_promiscCallback.IsNull ())
329
      if (!m_promiscCallback.IsNull ())
261
        {
330
        {
262
          m_promiscCallback (this, packet, protocol, GetRemote (), GetAddress (), NetDevice::PACKET_HOST);
331
          Ptr<Packet> pktCopy = packet->Copy ();
332
          m_promiscCallback (this, pktCopy, protocol, GetRemote (), GetAddress (), NetDevice::PACKET_HOST);
263
        }
333
        }
334
335
      m_rxCallback (this, packet, protocol, GetRemote ());
264
    }
336
    }
265
}
337
}
266
338
 Lines 406-438   PointToPointNetDevice::Send( Link Here 
406
  NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest);
478
  NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest);
407
  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
479
  NS_LOG_LOGIC ("UID is " << packet->GetUid ());
408
480
409
//
481
  //
410
// If IsLinkUp() is false it means there is no channel to send any packet 
482
  // If IsLinkUp() is false it means there is no channel to send any packet 
411
// over so we just return an error.
483
  // over so we just hit the drop trace on the packet and return an error.
412
//
484
  //
413
  if (IsLinkUp () == false)
485
  if (IsLinkUp () == false)
414
    {
486
    {
487
      m_macTxDropTrace (packet);
415
      return false;
488
      return false;
416
    }
489
    }
417
490
418
//
491
  //
419
// Stick a point to point protocol header on the packet in preparation for
492
  // Stick a point to point protocol header on the packet in preparation for
420
// shoving it out the door.
493
  // shoving it out the door.
421
//
494
  //
422
  AddHeader(packet, protocolNumber);
495
  AddHeader(packet, protocolNumber);
423
496
424
//
497
  m_macTxTrace (packet);
425
// If there's a transmission in progress, we enque the packet for later
498
426
// transmission; otherwise we send it now.
499
  //
427
//
500
  // If there's a transmission in progress, we enque the packet for later
501
  // transmission; otherwise we send it now.
502
  //
428
  if (m_txMachineState == READY) 
503
  if (m_txMachineState == READY) 
429
    {
504
    {
430
// 
505
      // 
431
// Even if the transmitter is immediately available, we still enqueue and 
506
      // Even if the transmitter is immediately available, we still enqueue and
432
// dequeue the packet to hit the tracing hooks.
507
      // dequeue the packet to hit the tracing hooks.
433
//
508
      //
434
      m_queue->Enqueue (packet);
509
      m_queue->Enqueue (packet);
435
      packet = m_queue->Dequeue ();
510
      packet = m_queue->Dequeue ();
511
      m_snifferTrace (packet);
436
      return TransmitStart (packet);
512
      return TransmitStart (packet);
437
    }
513
    }
438
  else
514
  else
(-)a/src/devices/point-to-point/point-to-point-net-device.h (-16 / +119 lines)
 Lines 388-412   private: Link Here 
388
  Ptr<Queue> m_queue;
388
  Ptr<Queue> m_queue;
389
389
390
  /**
390
  /**
391
   * The trace source for the packet reception events that the device can
392
   * fire.
393
   *
394
   * @see class CallBackTraceSource
395
   */
396
  TracedCallback<Ptr<const Packet> > m_rxTrace;
397
398
  /**
399
   * The trace source for the packet drop events that the device can
400
   * fire.
401
   *
402
   * @see class CallBackTraceSource
403
   */
404
  TracedCallback<Ptr<const Packet> > m_dropTrace;
405
406
  /**
407
   * Error model for receive packet events
391
   * Error model for receive packet events
408
   */
392
   */
409
  Ptr<ErrorModel> m_receiveErrorModel;
393
  Ptr<ErrorModel> m_receiveErrorModel;
394
395
  /**
396
   * The trace source fired when packets come into the "top" of the device
397
   * at the L3/L2 transition, before being queued for transmission.
398
   *
399
   * \see class CallBackTraceSource
400
   */
401
  TracedCallback<Ptr<const Packet> > m_macTxTrace;
402
403
  /**
404
   * The trace source fired when packets coming into the "top" of the device
405
   * at the L3/L2 transition are dropped before being queued for transmission.
406
   *
407
   * \see class CallBackTraceSource
408
   */
409
  TracedCallback<Ptr<const Packet> > m_macTxDropTrace;
410
411
  /**
412
   * The trace source fired for packets successfully received by the device
413
   * immediately before being forwarded up to higher layers (at the L2/L3 
414
   * transition).
415
   *
416
   * \see class CallBackTraceSource
417
   */
418
  TracedCallback<Ptr<const Packet> > m_macRxTrace;
419
420
  /**
421
   * The trace source fired when a packet starts the transmission process on
422
   * the medium.
423
   *
424
   * \see class CallBackTraceSource
425
   */
426
  TracedCallback<Ptr<const Packet> > m_phyTxStartTrace;
427
428
  /**
429
   * The trace source fired when a packet ends the transmission process on
430
   * the medium.  This happens immediately after the device has completed
431
   * packet transmission and has stopped "wiggling" the wire.  N.B. This
432
   * is not the same time that the packet will be received on a remote device
433
   * as that time includes a speed-of-light delay.
434
   *
435
   * \see class CallBackTraceSource
436
   */
437
  TracedCallback<Ptr<const Packet> > m_phyTxTrace;
438
439
  /**
440
   * The trace source fired when the phy layer drops a packet before it tries
441
   * to transmit it.
442
   *
443
   * \see class CallBackTraceSource
444
   */
445
  TracedCallback<Ptr<const Packet> > m_phyTxDropTrace;
446
447
  /**
448
   * The trace source fired when a packet starts the reception process from
449
   * the medium -- when the simulated first bit(s) arrive.
450
   *
451
   * \see class CallBackTraceSource
452
   */
453
  TracedCallback<Ptr<const Packet> > m_phyRxStartTrace;
454
455
  /**
456
   * The trace source fired when a packet ends the reception process from
457
   * the medium.
458
   *
459
   * \see class CallBackTraceSource
460
   */
461
  TracedCallback<Ptr<const Packet> > m_phyRxTrace;
462
463
  /**
464
   * The trace source fired when the phy layer drops a packet it has received.
465
   * This happens if the receiver is not enabled or the error model is active
466
   * and indicates that the packet is corrupt.
467
   *
468
   * \see class CallBackTraceSource
469
   */
470
  TracedCallback<Ptr<const Packet> > m_phyRxDropTrace;
471
472
  /**
473
   * A trace source that emulates a non-promiscuous protocol sniffer connected 
474
   * to the device.  Unlike your average everyday sniffer, this trace source 
475
   * will not fire on PACKET_OTHERHOST events.
476
   *
477
   * On the transmit size, this trace hook will fire after a packet is dequeued
478
   * from the device queue for transmission.  In Linux, for example, this would
479
   * correspond to the point just before a device hard_start_xmit where 
480
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
481
   * ETH_P_ALL handlers.
482
   *
483
   * On the receive side, this trace hook will fire when a packet is received,
484
   * just before the receive callback is executed.  In Linux, for example, 
485
   * this would correspond to the point at which the packet is dispatched to 
486
   * packet sniffers in netif_receive_skb.
487
   *
488
   * \see class CallBackTraceSource
489
   */
490
  TracedCallback<Ptr<const Packet> > m_snifferTrace;
491
492
  /**
493
   * A trace source that emulates a promiscuous mode protocol sniffer connected
494
   * to the device.  This trace source fire on packets destined for any host
495
   * just like your average everyday packet sniffer.
496
   *
497
   * On the transmit size, this trace hook will fire after a packet is dequeued
498
   * from the device queue for transmission.  In Linux, for example, this would
499
   * correspond to the point just before a device hard_start_xmit where 
500
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
501
   * ETH_P_ALL handlers.
502
   *
503
   * On the receive side, this trace hook will fire when a packet is received,
504
   * just before the receive callback is executed.  In Linux, for example, 
505
   * this would correspond to the point at which the packet is dispatched to 
506
   * packet sniffers in netif_receive_skb.
507
   *
508
   * \see class CallBackTraceSource
509
   */
510
  TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace;
410
511
411
  Ptr<Node> m_node;
512
  Ptr<Node> m_node;
412
  Mac48Address m_address;
513
  Mac48Address m_address;
 Lines 435-440   private: Link Here 
435
   * Ethernet.
536
   * Ethernet.
436
   */
537
   */
437
  uint32_t m_mtu;
538
  uint32_t m_mtu;
539
540
  Ptr<Packet> m_currentPkt;
438
};
541
};
439
542
440
} // namespace ns3
543
} // namespace ns3
(-)a/src/devices/wifi/adhoc-wifi-mac.cc (+3 lines)
 Lines 24-29    Link Here 
24
#include "mac-rx-middle.h"
24
#include "mac-rx-middle.h"
25
#include "wifi-phy.h"
25
#include "wifi-phy.h"
26
#include "dcf-manager.h"
26
#include "dcf-manager.h"
27
#include "wifi-mac-trailer.h"
27
#include "ns3/pointer.h"
28
#include "ns3/pointer.h"
28
#include "ns3/packet.h"
29
#include "ns3/packet.h"
29
#include "ns3/log.h"
30
#include "ns3/log.h"
 Lines 234-239   AdhocWifiMac::Enqueue (Ptr<const Packet> Link Here 
234
      destination->RecordDisassociated ();
235
      destination->RecordDisassociated ();
235
    }
236
    }
236
237
238
  m_macTxTrace (packet);
237
  m_dca->Queue (packet, hdr);
239
  m_dca->Queue (packet, hdr);
238
}
240
}
239
bool 
241
bool 
 Lines 246-251   AdhocWifiMac::ForwardUp (Ptr<Packet> pac Link Here 
246
AdhocWifiMac::ForwardUp (Ptr<Packet> packet, WifiMacHeader const *hdr)
248
AdhocWifiMac::ForwardUp (Ptr<Packet> packet, WifiMacHeader const *hdr)
247
{
249
{
248
  NS_LOG_DEBUG ("received size="<<packet->GetSize ()<<", from="<<hdr->GetAddr2 ());
250
  NS_LOG_DEBUG ("received size="<<packet->GetSize ()<<", from="<<hdr->GetAddr2 ());
251
  m_macRxTrace (packet);
249
  m_upCallback (packet, hdr->GetAddr2 (), hdr->GetAddr1 ());
252
  m_upCallback (packet, hdr->GetAddr2 (), hdr->GetAddr1 ());
250
}
253
}
251
Ptr<DcaTxop>
254
Ptr<DcaTxop>
(-)a/src/devices/wifi/mac-low.cc (+4 lines)
 Lines 840-845   MacLow::ForwardDown (Ptr<const Packet> p Link Here 
840
   */
840
   */
841
  Time txDuration = m_phy->CalculateTxDuration (packet->GetSize (), txMode, WIFI_PREAMBLE_LONG);
841
  Time txDuration = m_phy->CalculateTxDuration (packet->GetSize (), txMode, WIFI_PREAMBLE_LONG);
842
  Simulator::Schedule (txDuration, &MacLow::NotifyNav, this, *hdr, txMode, WIFI_PREAMBLE_LONG);
842
  Simulator::Schedule (txDuration, &MacLow::NotifyNav, this, *hdr, txMode, WIFI_PREAMBLE_LONG);
843
  /*
844
   * Tell the phy when we expect the packet has completely been sent -- for tracing
845
   */
846
  Simulator::Schedule (txDuration, &WifiPhy::SendDone, m_phy, packet);
843
}
847
}
844
848
845
void
849
void
(-)a/src/devices/wifi/nqap-wifi-mac.cc (+7 lines)
 Lines 30-35    Link Here 
30
#include "dcf-manager.h"
30
#include "dcf-manager.h"
31
#include "mac-rx-middle.h"
31
#include "mac-rx-middle.h"
32
#include "mac-low.h"
32
#include "mac-low.h"
33
#include "wifi-mac-trailer.h"
33
#include "ns3/pointer.h"
34
#include "ns3/pointer.h"
34
35
35
NS_LOG_COMPONENT_DEFINE ("NqapWifiMac");
36
NS_LOG_COMPONENT_DEFINE ("NqapWifiMac");
 Lines 285-292   NqapWifiMac::ForwardUp (Ptr<Packet> pack Link Here 
285
NqapWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
286
NqapWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
286
{
287
{
287
  NS_LOG_FUNCTION (this << packet << from);
288
  NS_LOG_FUNCTION (this << packet << from);
289
  m_macRxTrace (packet);
288
  m_upCallback (packet, from, to);
290
  m_upCallback (packet, from, to);
289
}
291
}
292
290
void 
293
void 
291
NqapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to)
294
NqapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to)
292
{
295
{
 Lines 298-303   NqapWifiMac::ForwardDown (Ptr<const Pack Link Here 
298
  hdr.SetAddr3 (from);
301
  hdr.SetAddr3 (from);
299
  hdr.SetDsFrom ();
302
  hdr.SetDsFrom ();
300
  hdr.SetDsNotTo ();
303
  hdr.SetDsNotTo ();
304
305
  m_macTxTrace (packet);
301
  m_dca->Queue (packet, hdr);  
306
  m_dca->Queue (packet, hdr);  
302
}
307
}
303
void 
308
void 
 Lines 472-482   NqapWifiMac::Receive (Ptr<Packet> packet Link Here 
472
        {
477
        {
473
          // this is an AP-to-AP frame
478
          // this is an AP-to-AP frame
474
          // we ignore for now.
479
          // we ignore for now.
480
          m_macRxDropTrace (packet);
475
        } 
481
        } 
476
      else 
482
      else 
477
        {
483
        {
478
          // we can ignore these frames since 
484
          // we can ignore these frames since 
479
          // they are not targeted at the AP
485
          // they are not targeted at the AP
486
          m_macRxDropTrace (packet);
480
        }
487
        }
481
    } 
488
    } 
482
  else if (hdr->IsMgt ()) 
489
  else if (hdr->IsMgt ()) 
(-)a/src/devices/wifi/nqsta-wifi-mac.cc (-2 / +19 lines)
 Lines 34-39    Link Here 
34
#include "mac-low.h"
34
#include "mac-low.h"
35
#include "dcf-manager.h"
35
#include "dcf-manager.h"
36
#include "mac-rx-middle.h"
36
#include "mac-rx-middle.h"
37
#include "wifi-mac-trailer.h"
37
#include "ns3/trace-source-accessor.h"
38
#include "ns3/trace-source-accessor.h"
38
#include "ns3/pointer.h"
39
#include "ns3/pointer.h"
39
40
 Lines 321-326   NqstaWifiMac::ForwardUp (Ptr<Packet> pac Link Here 
321
NqstaWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
322
NqstaWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
322
{
323
{
323
  NS_LOG_FUNCTION (this << packet << from << to);
324
  NS_LOG_FUNCTION (this << packet << from << to);
325
  m_macRxTrace (packet);
324
  m_forwardUp (packet, from, to);
326
  m_forwardUp (packet, from, to);
325
}
327
}
326
void
328
void
 Lines 457-470   void Link Here 
457
void 
459
void 
458
NqstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from)
460
NqstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from)
459
{
461
{
460
  NS_FATAL_ERROR ("Qsta does not support enqueue");
462
  NS_FATAL_ERROR ("Qsta does not support SendTo");
461
}
463
}
464
462
void 
465
void 
463
NqstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to)
466
NqstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to)
464
{
467
{
465
  NS_LOG_FUNCTION (this << packet << to);
468
  NS_LOG_FUNCTION (this << packet << to);
466
  if (!IsAssociated ()) 
469
  if (!IsAssociated ()) 
467
    {
470
    {
471
      m_macTxDropTrace (packet);
468
      TryToEnsureAssociated ();
472
      TryToEnsureAssociated ();
469
      return;
473
      return;
470
    }
474
    }
 Lines 476-487   NqstaWifiMac::Enqueue (Ptr<const Packet> Link Here 
476
  hdr.SetAddr3 (to);
480
  hdr.SetAddr3 (to);
477
  hdr.SetDsNotFrom ();
481
  hdr.SetDsNotFrom ();
478
  hdr.SetDsTo ();
482
  hdr.SetDsTo ();
483
484
  m_macTxTrace (packet);
479
  m_dca->Queue (packet, hdr);
485
  m_dca->Queue (packet, hdr);
480
}
486
}
487
481
bool 
488
bool 
482
NqstaWifiMac::SupportsSendFrom (void) const
489
NqstaWifiMac::SupportsSendFrom (void) const
483
{
490
{
484
  return true;
491
  //
492
  // The 802.11 MAC protocol has no way to support bridging outside of
493
  // infrastructure mode
494
  //
495
  return false;
485
}  
496
}  
486
497
487
498
 Lines 498-521   NqstaWifiMac::Receive (Ptr<Packet> packe Link Here 
498
           !hdr->GetAddr1 ().IsGroup ()) 
509
           !hdr->GetAddr1 ().IsGroup ()) 
499
    {
510
    {
500
      NS_LOG_LOGIC ("packet is not for us");
511
      NS_LOG_LOGIC ("packet is not for us");
512
      m_macRxDropTrace (packet);
501
    } 
513
    } 
502
  else if (hdr->IsData ()) 
514
  else if (hdr->IsData ()) 
503
    {
515
    {
504
      if (!IsAssociated ())
516
      if (!IsAssociated ())
505
        {
517
        {
506
          NS_LOG_LOGIC ("Received data frame while not associated: ignore");
518
          NS_LOG_LOGIC ("Received data frame while not associated: ignore");
519
          m_macRxDropTrace (packet);
507
          return;
520
          return;
508
        }
521
        }
509
      if (!(hdr->IsFromDs () && !hdr->IsToDs ()))
522
      if (!(hdr->IsFromDs () && !hdr->IsToDs ()))
510
        {
523
        {
511
          NS_LOG_LOGIC ("Received data frame not from the DS: ignore");
524
          NS_LOG_LOGIC ("Received data frame not from the DS: ignore");
525
          m_macRxDropTrace (packet);
512
          return;
526
          return;
513
        }
527
        }
514
      if (hdr->GetAddr2 () != GetBssid ())
528
      if (hdr->GetAddr2 () != GetBssid ())
515
        {
529
        {
516
          NS_LOG_LOGIC ("Received data frame not from the the BSS we are associated with: ignore");
530
          NS_LOG_LOGIC ("Received data frame not from the the BSS we are associated with: ignore");
531
          m_macRxDropTrace (packet);
517
          return;
532
          return;
518
        }
533
        }
534
519
      ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ());
535
      ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ());
520
    } 
536
    } 
521
  else if (hdr->IsProbeReq () ||
537
  else if (hdr->IsProbeReq () ||
 Lines 524-529   NqstaWifiMac::Receive (Ptr<Packet> packe Link Here 
524
      /* this is a frame aimed at an AP.
540
      /* this is a frame aimed at an AP.
525
       * so we can safely ignore it.
541
       * so we can safely ignore it.
526
       */
542
       */
543
      m_macRxDropTrace (packet);
527
    } 
544
    } 
528
  else if (hdr->IsBeacon ()) 
545
  else if (hdr->IsBeacon ()) 
529
    {
546
    {
(-)a/src/devices/wifi/wifi-mac.cc (+26 lines)
 Lines 19-24    Link Here 
19
 */
19
 */
20
#include "wifi-mac.h"
20
#include "wifi-mac.h"
21
#include "ns3/uinteger.h"
21
#include "ns3/uinteger.h"
22
#include "ns3/trace-source-accessor.h"
22
23
23
namespace ns3 {
24
namespace ns3 {
24
25
 Lines 117-123   WifiMac::GetTypeId (void) Link Here 
117
		   MakeSsidAccessor (&WifiMac::GetSsid,
118
		   MakeSsidAccessor (&WifiMac::GetSsid,
118
				     &WifiMac::SetSsid),
119
				     &WifiMac::SetSsid),
119
		   MakeSsidChecker ())
120
		   MakeSsidChecker ())
121
    .AddTraceSource ("MacTx", 
122
                     "A packet has been received from higher layers and is being processed in preparation for "
123
                     "queueing for transmission.",
124
                     MakeTraceSourceAccessor (&WifiMac::m_macTxTrace))
125
    .AddTraceSource ("MacTxDrop", 
126
                     "A packet has been dropped in the MAC layer before being queued for transmission.",
127
                     MakeTraceSourceAccessor (&WifiMac::m_macTxDropTrace))
128
    .AddTraceSource ("MacRx", 
129
                     "A packet has been received by this device, has been passed up from the physical layer "
130
                     "and is being forwarded up the local protocol stack.",
131
                     MakeTraceSourceAccessor (&WifiMac::m_macRxTrace))
132
    .AddTraceSource ("MacRxDrop", 
133
                     "A packet has been dropped in the MAC layer after it has been passed up from the physical "
134
                     "layer.",
135
                     MakeTraceSourceAccessor (&WifiMac::m_macRxDropTrace))
136
    .AddTraceSource ("Sniffer", 
137
                     "Trace source simulating a non-promiscuous packet sniffer attached to the device",
138
                     MakeTraceSourceAccessor (&WifiMac::m_snifferTrace))
120
    ;
139
    ;
140
121
  return tid;
141
  return tid;
122
}
142
}
123
143
 Lines 144-148   WifiMac::GetMaxMsduSize (void) const Link Here 
144
  return m_maxMsduSize;
164
  return m_maxMsduSize;
145
}
165
}
146
166
167
void
168
WifiMac::SnifferTrace (Ptr<const Packet> packet)
169
{
170
  m_snifferTrace (packet);
171
}
172
147
173
148
} // namespace ns3
174
} // namespace ns3
(-)a/src/devices/wifi/wifi-mac.h (-3 / +62 lines)
 Lines 176-185   public: Link Here 
176
   * \param linkDown the callback to invoke when the link becomes down.
176
   * \param linkDown the callback to invoke when the link becomes down.
177
   */
177
   */
178
  virtual void SetLinkDownCallback (Callback<void> linkDown) = 0;
178
  virtual void SetLinkDownCallback (Callback<void> linkDown) = 0;
179
180
  /*
181
   * Let the net device hit a trace hook.  This is done to group the high-level
182
   * trace sources all in one place for ease of use.
183
   */
184
  void SnifferTrace (Ptr<const Packet> packet);
185
179
private:
186
private:
180
181
182
183
  static Time GetDefaultMaxPropagationDelay (void);
187
  static Time GetDefaultMaxPropagationDelay (void);
184
  static Time GetDefaultSlot (void);
188
  static Time GetDefaultSlot (void);
185
  static Time GetDefaultSifs (void);
189
  static Time GetDefaultSifs (void);
 Lines 189-194   private: Link Here 
189
193
190
  Time m_maxPropagationDelay;
194
  Time m_maxPropagationDelay;
191
  uint32_t m_maxMsduSize;
195
  uint32_t m_maxMsduSize;
196
197
protected:
198
199
  /**
200
   * The trace source fired when packets come into the "top" of the device
201
   * at the L3/L2 transition, before being queued for transmission.
202
   *
203
   * \see class CallBackTraceSource
204
   */
205
  TracedCallback<Ptr<const Packet> > m_macTxTrace;
206
207
  /**
208
   * The trace source fired when packets coming into the "top" of the device
209
   * are dropped at the MAC layer during transmission.
210
   *
211
   * \see class CallBackTraceSource
212
   */
213
  TracedCallback<Ptr<const Packet> > m_macTxDropTrace;
214
215
  /**
216
   * The trace source fired for packets successfully received by the device
217
   * immediately before being forwarded up to higher layers (at the L2/L3 
218
   * transition).
219
   *
220
   * \see class CallBackTraceSource
221
   */
222
  TracedCallback<Ptr<const Packet> > m_macRxTrace;
223
224
  /**
225
   * The trace source fired when packets coming into the "top" of the device
226
   * are dropped at the MAC layer during reception.
227
   *
228
   * \see class CallBackTraceSource
229
   */
230
  TracedCallback<Ptr<const Packet> > m_macRxDropTrace;
231
232
  /**
233
   * A trace source that emulates a non-promiscuous protocol sniffer connected 
234
   * to the device.  Unlike your average everyday sniffer, this trace source 
235
   * will not fire on PACKET_OTHERHOST events.
236
   *
237
   * On the transmit size, this trace hook will fire after a packet is dequeued
238
   * from the device queue for transmission.  In Linux, for example, this would
239
   * correspond to the point just before a device hard_start_xmit where 
240
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
241
   * ETH_P_ALL handlers.
242
   *
243
   * On the receive side, this trace hook will fire when a packet is received,
244
   * just before the receive callback is executed.  In Linux, for example, 
245
   * this would correspond to the point at which the packet is dispatched to 
246
   * packet sniffers in netif_receive_skb.
247
   *
248
   * \see class CallBackTraceSource
249
   */
250
  TracedCallback<Ptr<const Packet> > m_snifferTrace;
192
};
251
};
193
252
194
} // namespace ns3
253
} // namespace ns3
(-)a/src/devices/wifi/wifi-net-device.cc (-6 / +33 lines)
 Lines 23-28    Link Here 
23
#include "wifi-remote-station-manager.h"
23
#include "wifi-remote-station-manager.h"
24
#include "wifi-channel.h"
24
#include "wifi-channel.h"
25
#include "ns3/llc-snap-header.h"
25
#include "ns3/llc-snap-header.h"
26
#include "ns3/ethernet-header.h"
27
#include "ns3/ethernet-trailer.h"
26
#include "ns3/packet.h"
28
#include "ns3/packet.h"
27
#include "ns3/uinteger.h"
29
#include "ns3/uinteger.h"
28
#include "ns3/pointer.h"
30
#include "ns3/pointer.h"
 Lines 57-66   WifiNetDevice::GetTypeId (void) Link Here 
57
                   MakePointerAccessor (&WifiNetDevice::SetRemoteStationManager,
59
                   MakePointerAccessor (&WifiNetDevice::SetRemoteStationManager,
58
                                        &WifiNetDevice::GetRemoteStationManager),
60
                                        &WifiNetDevice::GetRemoteStationManager),
59
                   MakePointerChecker<WifiRemoteStationManager> ())
61
                   MakePointerChecker<WifiRemoteStationManager> ())
60
    .AddTraceSource ("Rx", "Received payload from the MAC layer.",
61
                     MakeTraceSourceAccessor (&WifiNetDevice::m_rxLogger))
62
    .AddTraceSource ("Tx", "Send payload to the MAC layer.",
63
                     MakeTraceSourceAccessor (&WifiNetDevice::m_txLogger))
64
    ;
62
    ;
65
  return tid;
63
  return tid;
66
}
64
}
 Lines 243-253   WifiNetDevice::IsBridge (void) const Link Here 
243
  return false;
241
  return false;
244
}
242
}
245
bool 
243
bool 
246
WifiNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
244
WifiNetDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
247
{
245
{
248
  NS_ASSERT (Mac48Address::IsMatchingType (dest));
246
  NS_ASSERT (Mac48Address::IsMatchingType (dest));
249
247
250
  Mac48Address realTo = Mac48Address::ConvertFrom (dest);
248
  Mac48Address realTo = Mac48Address::ConvertFrom (dest);
249
  Mac48Address realFrom = Mac48Address::ConvertFrom (GetAddress ());
250
251
  SniffPacket (packet, realTo, realFrom, protocolNumber);
251
252
252
  LlcSnapHeader llc;
253
  LlcSnapHeader llc;
253
  llc.SetType (protocolNumber);
254
  llc.SetType (protocolNumber);
 Lines 303-315   WifiNetDevice::ForwardUp (Ptr<Packet> pa Link Here 
303
    {
304
    {
304
      type = NetDevice::PACKET_OTHERHOST;
305
      type = NetDevice::PACKET_OTHERHOST;
305
    }
306
    }
307
306
  if (type != NetDevice::PACKET_OTHERHOST)
308
  if (type != NetDevice::PACKET_OTHERHOST)
307
    {
309
    {
310
      SniffPacket (packet, to, from, llc.GetType ());
308
      m_forwardUp (this, packet, llc.GetType (), from);
311
      m_forwardUp (this, packet, llc.GetType (), from);
309
    }
312
    }
313
310
  if (!m_promiscRx.IsNull ())
314
  if (!m_promiscRx.IsNull ())
311
    {
315
    {
312
      m_promiscRx (this, packet, llc.GetType (), from, to, type);
316
      m_promiscRx (this, packet->Copy (), llc.GetType (), from, to, type);
313
    }
317
    }
314
}
318
}
315
319
 Lines 341-346   WifiNetDevice::SendFrom (Ptr<Packet> pac Link Here 
341
  Mac48Address realTo = Mac48Address::ConvertFrom (dest);
345
  Mac48Address realTo = Mac48Address::ConvertFrom (dest);
342
  Mac48Address realFrom = Mac48Address::ConvertFrom (source);
346
  Mac48Address realFrom = Mac48Address::ConvertFrom (source);
343
347
348
  SniffPacket (packet, realTo, realFrom, protocolNumber);
349
344
  LlcSnapHeader llc;
350
  LlcSnapHeader llc;
345
  llc.SetType (protocolNumber);
351
  llc.SetType (protocolNumber);
346
  packet->AddHeader (llc);
352
  packet->AddHeader (llc);
 Lines 364-368   WifiNetDevice::SupportsSendFrom (void) c Link Here 
364
  return m_mac->SupportsSendFrom ();
370
  return m_mac->SupportsSendFrom ();
365
}
371
}
366
372
373
void
374
WifiNetDevice::SniffPacket (Ptr<const Packet> packet, Mac48Address to, Mac48Address from, uint16_t type)
375
{
376
  Ptr<Packet> copy = packet->Copy ();
377
  EthernetHeader header (false);
378
  header.SetSource (from);
379
  header.SetDestination (to);
380
381
  LlcSnapHeader llc;
382
  llc.SetType (type);
383
  copy->AddHeader (llc);
384
385
  header.SetLengthType (copy->GetSize ());
386
  copy->AddHeader (header);
387
388
  EthernetTrailer trailer;
389
  trailer.CalcFcs (copy);
390
  copy->AddTrailer (trailer);
391
  m_mac->SnifferTrace (copy);
392
}
393
367
} // namespace ns3
394
} // namespace ns3
368
395
(-)a/src/devices/wifi/wifi-net-device.h (+10 lines)
 Lines 118-125   private: Link Here 
118
  Ptr<WifiRemoteStationManager> m_stationManager;
118
  Ptr<WifiRemoteStationManager> m_stationManager;
119
  NetDevice::ReceiveCallback m_forwardUp;
119
  NetDevice::ReceiveCallback m_forwardUp;
120
  NetDevice::PromiscReceiveCallback m_promiscRx;
120
  NetDevice::PromiscReceiveCallback m_promiscRx;
121
121
  TracedCallback<Ptr<const Packet>, Mac48Address> m_rxLogger;
122
  TracedCallback<Ptr<const Packet>, Mac48Address> m_rxLogger;
122
  TracedCallback<Ptr<const Packet>, Mac48Address> m_txLogger;
123
  TracedCallback<Ptr<const Packet>, Mac48Address> m_txLogger;
124
125
  /**
126
   * At the top of the MAC level, we do what many folks do and make the wifi 
127
   * packets look like Ethernet packets coming in and out of the "driver."  If
128
   * you are interested in seeing all of the wifi details, you should use the
129
   * much lower level PHY promiscuous sniffer trace.
130
   */
131
  void SniffPacket (Ptr<const Packet> packet, Mac48Address to, Mac48Address from, uint16_t type);
132
123
  uint32_t m_ifIndex;
133
  uint32_t m_ifIndex;
124
  std::string m_name;
134
  std::string m_name;
125
  bool m_linkUp;
135
  bool m_linkUp;
(-)a/src/devices/wifi/wifi-phy.cc (+21 lines)
 Lines 55-60   WifiPhy::GetTypeId (void) Link Here 
55
{
55
{
56
  static TypeId tid = TypeId ("ns3::WifiPhy")
56
  static TypeId tid = TypeId ("ns3::WifiPhy")
57
    .SetParent<Object> ()
57
    .SetParent<Object> ()
58
    .AddTraceSource ("PhyTxStart", 
59
                     "Trace source indicating a packet has begun transmitting over the channel medium",
60
                     MakeTraceSourceAccessor (&WifiPhy::m_phyTxStartTrace))
61
    .AddTraceSource ("PhyTx", 
62
                     "Trace source indicating a packet has been completely transmitted over the channel",
63
                     MakeTraceSourceAccessor (&WifiPhy::m_phyTxTrace))
64
    .AddTraceSource ("PhyTxDrop", 
65
                     "Trace source indicating a packet has been dropped by the device during transmission",
66
                     MakeTraceSourceAccessor (&WifiPhy::m_phyTxDropTrace))
67
    .AddTraceSource ("PhyRxStart", 
68
                     "Trace source indicating a packet has begun being received from the channel medium by the device",
69
                     MakeTraceSourceAccessor (&WifiPhy::m_phyRxStartTrace))
70
    .AddTraceSource ("PhyRx", 
71
                     "Trace source indicating a packet has been completely received from the channel medium by the device",
72
                     MakeTraceSourceAccessor (&WifiPhy::m_phyRxTrace))
73
    .AddTraceSource ("PhyRxDrop", 
74
                     "Trace source indicating a packet has been dropped by the device during reception",
75
                     MakeTraceSourceAccessor (&WifiPhy::m_phyRxDropTrace))
76
    .AddTraceSource ("PromiscSniffer", 
77
                     "Trace source simulating a promiscuous packet sniffer attached to the device",
78
                     MakeTraceSourceAccessor (&WifiPhy::m_promiscSnifferTrace))
58
    ;
79
    ;
59
  return tid;
80
  return tid;
60
}
81
}
(-)a/src/devices/wifi/wifi-phy.h (+77 lines)
 Lines 30-35    Link Here 
30
#include "wifi-mode.h"
30
#include "wifi-mode.h"
31
#include "wifi-preamble.h"
31
#include "wifi-preamble.h"
32
#include "wifi-phy-standard.h"
32
#include "wifi-phy-standard.h"
33
#include "ns3/traced-callback.h"
33
34
34
35
35
namespace ns3 {
36
namespace ns3 {
 Lines 79-84   public: Link Here 
79
   * unless they have received a cca busy report.
80
   * unless they have received a cca busy report.
80
   */
81
   */
81
  virtual void NotifyTxStart (Time duration) = 0;
82
  virtual void NotifyTxStart (Time duration) = 0;
83
82
  /**
84
  /**
83
   * \param duration the expected busy duration.
85
   * \param duration the expected busy duration.
84
   *
86
   *
 Lines 171-176   public: Link Here 
171
   *        transmission power is calculated as txPowerMin + txPowerLevel * (txPowerMax - txPowerMin) / nTxLevels
173
   *        transmission power is calculated as txPowerMin + txPowerLevel * (txPowerMax - txPowerMin) / nTxLevels
172
   */
174
   */
173
  virtual void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel) = 0;
175
  virtual void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel) = 0;
176
177
  /**
178
   * \param packet the packet that was sent
179
   *
180
   * Tell the PHY-level that MAC low believes it should have just completed the send.
181
   */
182
  virtual void SendDone (Ptr<const Packet> packet) = 0;
174
183
175
  /**
184
  /**
176
   * \param listener the new listener
185
   * \param listener the new listener
 Lines 250-255   public: Link Here 
250
  static WifiMode Get36mba (void);
259
  static WifiMode Get36mba (void);
251
  static WifiMode Get48mba (void);
260
  static WifiMode Get48mba (void);
252
  static WifiMode Get54mba (void);
261
  static WifiMode Get54mba (void);
262
263
protected:
264
  /**
265
   * The trace source fired when a packet starts the transmission process on
266
   * the medium.
267
   *
268
   * \see class CallBackTraceSource
269
   */
270
  TracedCallback<Ptr<const Packet> > m_phyTxStartTrace;
271
272
  /**
273
   * The trace source fired when a packet ends the transmission process on
274
   * the medium.
275
   *
276
   * \see class CallBackTraceSource
277
   */
278
  TracedCallback<Ptr<const Packet> > m_phyTxTrace;
279
280
  /**
281
   * The trace source fired when the phy layer drops a packet as it tries
282
   * to transmit it.
283
   *
284
   * \see class CallBackTraceSource
285
   */
286
  TracedCallback<Ptr<const Packet> > m_phyTxDropTrace;
287
288
  /**
289
   * The trace source fired when a packet starts the reception process from
290
   * the medium.
291
   *
292
   * \see class CallBackTraceSource
293
   */
294
  TracedCallback<Ptr<const Packet> > m_phyRxStartTrace;
295
296
  /**
297
   * The trace source fired when a packet ends the reception process from
298
   * the medium.
299
   *
300
   * \see class CallBackTraceSource
301
   */
302
  TracedCallback<Ptr<const Packet> > m_phyRxTrace;
303
304
  /**
305
   * The trace source fired when the phy layer drops a packet it has received.
306
   *
307
   * \see class CallBackTraceSource
308
   */
309
  TracedCallback<Ptr<const Packet> > m_phyRxDropTrace;
310
311
  /**
312
   * A trace source that emulates a promiscuous mode protocol sniffer connected
313
   * to the device.  This trace source fire on packets destined for any host
314
   * just like your average everyday packet sniffer.
315
   *
316
   * On the transmit size, this trace hook will fire after a packet is dequeued
317
   * from the device queue for transmission.  In Linux, for example, this would
318
   * correspond to the point just before a device hard_start_xmit where 
319
   * dev_queue_xmit_nit is called to dispatch the packet to the PF_PACKET 
320
   * ETH_P_ALL handlers.
321
   *
322
   * On the receive side, this trace hook will fire when a packet is received,
323
   * just before the receive callback is executed.  In Linux, for example, 
324
   * this would correspond to the point at which the packet is dispatched to 
325
   * packet sniffers in netif_receive_skb.
326
   *
327
   * \see class CallBackTraceSource
328
   */
329
  TracedCallback<Ptr<const Packet> > m_promiscSnifferTrace;
253
};
330
};
254
331
255
} // namespace ns3
332
} // namespace ns3
(-)a/src/devices/wifi/yans-wifi-phy.cc (+17 lines)
 Lines 34-39    Link Here 
34
#include "ns3/enum.h"
34
#include "ns3/enum.h"
35
#include "ns3/pointer.h"
35
#include "ns3/pointer.h"
36
#include "ns3/net-device.h"
36
#include "ns3/net-device.h"
37
#include "ns3/trace-source-accessor.h"
37
#include <math.h>
38
#include <math.h>
38
39
39
NS_LOG_COMPONENT_DEFINE ("YansWifiPhy");
40
NS_LOG_COMPONENT_DEFINE ("YansWifiPhy");
 Lines 322-327   YansWifiPhy::StartReceivePacket (Ptr<Pac Link Here 
322
  case YansWifiPhy::SYNC:
323
  case YansWifiPhy::SYNC:
323
    NS_LOG_DEBUG ("drop packet because already in Sync (power="<<
324
    NS_LOG_DEBUG ("drop packet because already in Sync (power="<<
324
                  rxPowerW<<"W)");
325
                  rxPowerW<<"W)");
326
    m_phyRxDropTrace (packet);
325
    if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) 
327
    if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) 
326
      {
328
      {
327
        // that packet will be noise _after_ the reception of the
329
        // that packet will be noise _after_ the reception of the
 Lines 332-337   YansWifiPhy::StartReceivePacket (Ptr<Pac Link Here 
332
  case YansWifiPhy::TX:
334
  case YansWifiPhy::TX:
333
    NS_LOG_DEBUG ("drop packet because already in Tx (power="<<
335
    NS_LOG_DEBUG ("drop packet because already in Tx (power="<<
334
                  rxPowerW<<"W)");
336
                  rxPowerW<<"W)");
337
    m_phyRxDropTrace (packet);
335
    if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) 
338
    if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) 
336
      {
339
      {
337
        // that packet will be noise _after_ the transmission of the
340
        // that packet will be noise _after_ the transmission of the
 Lines 347-352   YansWifiPhy::StartReceivePacket (Ptr<Pac Link Here 
347
        // sync to signal
350
        // sync to signal
348
        m_state->SwitchToSync (rxDuration);
351
        m_state->SwitchToSync (rxDuration);
349
        NS_ASSERT (m_endSyncEvent.IsExpired ());
352
        NS_ASSERT (m_endSyncEvent.IsExpired ());
353
        m_phyRxStartTrace (packet);
350
        m_endSyncEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndSync, this, 
354
        m_endSyncEvent = Simulator::Schedule (rxDuration, &YansWifiPhy::EndSync, this, 
351
                                              packet,
355
                                              packet,
352
                                              event);
356
                                              event);
 Lines 355-360   YansWifiPhy::StartReceivePacket (Ptr<Pac Link Here 
355
      {
359
      {
356
        NS_LOG_DEBUG ("drop packet because signal power too Small ("<<
360
        NS_LOG_DEBUG ("drop packet because signal power too Small ("<<
357
                      rxPowerW<<"<"<<m_edThresholdW<<")");
361
                      rxPowerW<<"<"<<m_edThresholdW<<")");
362
        m_phyRxDropTrace (packet);
358
        goto maybeCcaBusy;
363
        goto maybeCcaBusy;
359
      }
364
      }
360
    break;
365
    break;
 Lines 374-379   YansWifiPhy::StartReceivePacket (Ptr<Pac Link Here 
374
      m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
379
      m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
375
    }
380
    }
376
}
381
}
382
377
void 
383
void 
378
YansWifiPhy::SendPacket (Ptr<const Packet> packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower)
384
YansWifiPhy::SendPacket (Ptr<const Packet> packet, WifiMode txMode, WifiPreamble preamble, uint8_t txPower)
379
{
385
{
 Lines 391-398   YansWifiPhy::SendPacket (Ptr<const Packe Link Here 
391
    {
397
    {
392
      m_endSyncEvent.Cancel ();
398
      m_endSyncEvent.Cancel ();
393
    }
399
    }
400
  m_phyTxStartTrace (packet);
401
  m_promiscSnifferTrace (packet);
394
  m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower);
402
  m_state->SwitchToTx (txDuration, packet, txMode, preamble, txPower);
395
  m_channel->Send (this, packet, GetPowerDbm (txPower) + m_txGainDb, txMode, preamble);
403
  m_channel->Send (this, packet, GetPowerDbm (txPower) + m_txGainDb, txMode, preamble);
404
}
405
406
void
407
YansWifiPhy::SendDone (Ptr<const Packet> packet)
408
{
409
  m_phyTxTrace (packet);
396
}
410
}
397
411
398
uint32_t 
412
uint32_t 
 Lines 550-560   YansWifiPhy::EndSync (Ptr<Packet> packet Link Here 
550
  
564
  
551
  if (m_random.GetValue () > snrPer.per) 
565
  if (m_random.GetValue () > snrPer.per) 
552
    {
566
    {
567
      m_phyRxTrace (packet);
568
      m_promiscSnifferTrace (packet);
553
      m_state->SwitchFromSyncEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ());
569
      m_state->SwitchFromSyncEndOk (packet, snrPer.snr, event->GetPayloadMode (), event->GetPreambleType ());
554
    } 
570
    } 
555
  else 
571
  else 
556
    {
572
    {
557
      /* failure. */
573
      /* failure. */
574
      m_phyRxDropTrace (packet);
558
      m_state->SwitchFromSyncEndError (packet, snrPer.snr);
575
      m_state->SwitchFromSyncEndError (packet, snrPer.snr);
559
    }
576
    }
560
}
577
}
(-)a/src/devices/wifi/yans-wifi-phy.h (+50 lines)
 Lines 102-107   public: Link Here 
102
  virtual void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback);
102
  virtual void SetReceiveOkCallback (WifiPhy::SyncOkCallback callback);
103
  virtual void SetReceiveErrorCallback (WifiPhy::SyncErrorCallback callback);
103
  virtual void SetReceiveErrorCallback (WifiPhy::SyncErrorCallback callback);
104
  virtual void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel);
104
  virtual void SendPacket (Ptr<const Packet> packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel);
105
  virtual void SendDone (Ptr<const Packet> packet);
105
  virtual void RegisterListener (WifiPhyListener *listener);
106
  virtual void RegisterListener (WifiPhyListener *listener);
106
  virtual bool IsStateCcaBusy (void);
107
  virtual bool IsStateCcaBusy (void);
107
  virtual bool IsStateIdle (void);
108
  virtual bool IsStateIdle (void);
 Lines 134-139   private: Link Here 
134
  void EndSync (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
135
  void EndSync (Ptr<Packet> packet, Ptr<InterferenceHelper::Event> event);
135
136
136
private:
137
private:
138
  /**
139
   * The trace source fired when a packet starts the transmission process on
140
   * the medium.
141
   *
142
   * \see class CallBackTraceSource
143
   */
144
  TracedCallback<Ptr<const Packet> > m_phyTxStartTrace;
145
146
  /**
147
   * The trace source fired when a packet ends the transmission process on
148
   * the medium.
149
   *
150
   * \see class CallBackTraceSource
151
   */
152
  TracedCallback<Ptr<const Packet> > m_phyTxTrace;
153
154
  /**
155
   * The trace source fired when the phy layer drops a packet as it tries
156
   * to transmit it.
157
   *
158
   * \see class CallBackTraceSource
159
   */
160
  TracedCallback<Ptr<const Packet> > m_phyTxDropTrace;
161
162
  /**
163
   * The trace source fired when a packet ends the reception process from
164
   * the medium.
165
   *
166
   * \see class CallBackTraceSource
167
   */
168
  TracedCallback<Ptr<const Packet> > m_phyRxTrace;
169
170
  /**
171
   * The trace source fired when a packet ends the reception process from
172
   * the medium.
173
   *
174
   * \see class CallBackTraceSource
175
   */
176
  TracedCallback<Ptr<const Packet> > m_phyRxStartTrace;
177
178
  /**
179
   * The trace source fired when the phy layer drops a packet it has received.
180
   *
181
   * \see class CallBackTraceSource
182
   */
183
  TracedCallback<Ptr<const Packet> > m_phyRxDropTrace;
184
185
private:
137
  double   m_edThresholdW;
186
  double   m_edThresholdW;
138
  double   m_ccaMode1ThresholdW;
187
  double   m_ccaMode1ThresholdW;
139
  double   m_txGainDb;
188
  double   m_txGainDb;
 Lines 151-156   private: Link Here 
151
  WifiPhyStandard m_standard;
200
  WifiPhyStandard m_standard;
152
  Ptr<WifiPhyStateHelper> m_state;
201
  Ptr<WifiPhyStateHelper> m_state;
153
  InterferenceHelper m_interference;
202
  InterferenceHelper m_interference;
203
154
};
204
};
155
205
156
} // namespace ns3
206
} // namespace ns3
(-)a/src/helper/csma-helper.cc (-12 / +7 lines)
 Lines 69-74   CsmaHelper::SetDeviceParameter (std::str Link Here 
69
{
69
{
70
  SetDeviceAttribute (n1, v1);
70
  SetDeviceAttribute (n1, v1);
71
}
71
}
72
72
void 
73
void 
73
CsmaHelper::SetChannelParameter (std::string n1, const AttributeValue &v1)
74
CsmaHelper::SetChannelParameter (std::string n1, const AttributeValue &v1)
74
{
75
{
 Lines 91-102   CsmaHelper::EnablePcap (std::string file Link Here 
91
  pcap->Open (oss.str ());
92
  pcap->Open (oss.str ());
92
  pcap->WriteEthernetHeader ();
93
  pcap->WriteEthernetHeader ();
93
  oss.str ("");
94
  oss.str ("");
94
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Rx";
95
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Sniffer";
95
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::RxEvent, pcap));
96
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::SniffEvent, pcap));
96
  oss.str ("");
97
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
98
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
99
}
97
}
98
100
void 
99
void 
101
CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
100
CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
102
{
101
{
 Lines 132-138   CsmaHelper::EnableAscii (std::ostream &o Link Here 
132
{
131
{
133
  Packet::EnablePrinting ();
132
  Packet::EnablePrinting ();
134
  std::ostringstream oss;
133
  std::ostringstream oss;
135
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Rx";
134
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx";
136
  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os));
135
  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os));
137
  oss.str ("");
136
  oss.str ("");
138
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
137
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
 Lines 279-293   CsmaHelper::InstallStar (std::string hub Link Here 
279
}
278
}
280
279
281
void 
280
void 
282
CsmaHelper::EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
281
CsmaHelper::SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
283
{
282
{
284
  writer->WritePacket (packet);
283
  writer->WritePacket (packet);
285
}
284
}
286
void 
285
287
CsmaHelper::RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
288
{
289
  writer->WritePacket (packet);
290
}
291
void 
286
void 
292
CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
287
CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
293
{
288
{
(-)a/src/helper/csma-helper.h (-3 / +4 lines)
 Lines 331-342   private: Link Here 
331
private:
331
private:
332
  Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
332
  Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const;
333
333
334
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
334
  static void SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
335
  static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
335
336
  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
336
  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
337
  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
337
  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
338
  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
338
  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
339
  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
339
  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
340
340
  ObjectFactory m_queueFactory;
341
  ObjectFactory m_queueFactory;
341
  ObjectFactory m_deviceFactory;
342
  ObjectFactory m_deviceFactory;
342
  ObjectFactory m_channelFactory;
343
  ObjectFactory m_channelFactory;
(-)a/src/helper/emu-helper.cc (-34 / +11 lines)
 Lines 78-93   EmuHelper::EnablePcap ( Link Here 
78
  pcap->WriteEthernetHeader ();
78
  pcap->WriteEthernetHeader ();
79
79
80
  oss.str ("");
80
  oss.str ("");
81
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
81
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/Sniffer";
82
    "/$ns3::EmuNetDevice/Rx";
82
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&EmuHelper::SniffEvent, pcap));
83
  Config::ConnectWithoutContext (oss.str (), 
84
    MakeBoundCallback (&EmuHelper::RxEvent, pcap));
85
86
  oss.str ("");
87
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
88
    "/$ns3::EmuNetDevice/TxQueue/Enqueue";
89
  Config::ConnectWithoutContext (oss.str (), 
90
    MakeBoundCallback (&EmuHelper::EnqueueEvent, pcap));
91
}
83
}
92
84
93
  void 
85
  void 
 Lines 131-158   EmuHelper::EnableAscii (std::ostream &os Link Here 
131
  Packet::EnablePrinting ();
123
  Packet::EnablePrinting ();
132
  std::ostringstream oss;
124
  std::ostringstream oss;
133
125
134
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
126
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/MacRx";
135
    "/$ns3::EmuNetDevice/Rx";
127
  Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiRxEvent, &os));
136
  Config::Connect (oss.str (), 
137
    MakeBoundCallback (&EmuHelper::AsciiRxEvent, &os));
138
128
139
  oss.str ("");
129
  oss.str ("");
140
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
130
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Enqueue";
141
    "/$ns3::EmuNetDevice/TxQueue/Enqueue";
131
  Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, &os));
142
  Config::Connect (oss.str (), 
143
    MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, &os));
144
132
145
  oss.str ("");
133
  oss.str ("");
146
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
134
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Dequeue";
147
    "/$ns3::EmuNetDevice/TxQueue/Dequeue";
135
  Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, &os));
148
  Config::Connect (oss.str (), 
149
    MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, &os));
150
136
151
  oss.str ("");
137
  oss.str ("");
152
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
138
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::EmuNetDevice/TxQueue/Drop";
153
    "/$ns3::EmuNetDevice/TxQueue/Drop";
139
  Config::Connect (oss.str (), MakeBoundCallback (&EmuHelper::AsciiDropEvent, &os));
154
  Config::Connect (oss.str (), 
155
    MakeBoundCallback (&EmuHelper::AsciiDropEvent, &os));
156
}
140
}
157
141
158
  void 
142
  void 
 Lines 228-241   EmuHelper::InstallPriv (Ptr<Node> node) Link Here 
228
}
212
}
229
213
230
  void 
214
  void 
231
EmuHelper::EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
215
EmuHelper::SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
232
{
233
  NS_LOG_FUNCTION (writer << packet);
234
  writer->WritePacket (packet);
235
}
236
237
  void 
238
EmuHelper::RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
239
{
216
{
240
  NS_LOG_FUNCTION (writer << packet);
217
  NS_LOG_FUNCTION (writer << packet);
241
  writer->WritePacket (packet);
218
  writer->WritePacket (packet);
(-)a/src/helper/emu-helper.h (-10 / +6 lines)
 Lines 184-199   public: Link Here 
184
184
185
private:
185
private:
186
  Ptr<NetDevice> InstallPriv (Ptr<Node> node) const;
186
  Ptr<NetDevice> InstallPriv (Ptr<Node> node) const;
187
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
187
  static void SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
188
  static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
188
189
  static void AsciiEnqueueEvent (std::ostream *os, std::string path, 
189
  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
190
    Ptr<const Packet> packet);
190
  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
191
  static void AsciiDequeueEvent (std::ostream *os, std::string path, 
191
  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
192
    Ptr<const Packet> packet);
192
  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
193
  static void AsciiDropEvent (std::ostream *os, std::string path, 
194
    Ptr<const Packet> packet);
195
  static void AsciiRxEvent (std::ostream *os, std::string path, 
196
    Ptr<const Packet> packet);
197
193
198
  ObjectFactory m_queueFactory;
194
  ObjectFactory m_queueFactory;
199
  ObjectFactory m_deviceFactory;
195
  ObjectFactory m_deviceFactory;
(-)a/src/helper/point-to-point-helper.cc (-12 / +4 lines)
 Lines 90-100   PointToPointHelper::EnablePcap (std::str Link Here 
90
  pcap->Open (oss.str ());
90
  pcap->Open (oss.str ());
91
  pcap->WritePppHeader ();
91
  pcap->WritePppHeader ();
92
  oss.str ("");
92
  oss.str ("");
93
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/Rx";
93
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/Sniffer";
94
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::RxEvent, pcap));
94
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::SniffEvent, pcap));
95
  oss.str ("");
96
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
97
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::EnqueueEvent, pcap));
98
}
95
}
99
void 
96
void 
100
PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
97
PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
 Lines 131-137   PointToPointHelper::EnableAscii (std::os Link Here 
131
{
128
{
132
  Packet::EnablePrinting ();
129
  Packet::EnablePrinting ();
133
  std::ostringstream oss;
130
  std::ostringstream oss;
134
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/Rx";
131
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/MacRx";
135
  Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, &os));
132
  Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, &os));
136
  oss.str ("");
133
  oss.str ("");
137
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
134
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
 Lines 247-258   PointToPointHelper::InstallStar (std::st Link Here 
247
}
244
}
248
245
249
void 
246
void 
250
PointToPointHelper::EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
247
PointToPointHelper::SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
251
{
252
  writer->WritePacket (packet);
253
}
254
void 
255
PointToPointHelper::RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
256
{
248
{
257
  writer->WritePacket (packet);
249
  writer->WritePacket (packet);
258
}
250
}
(-)a/src/helper/point-to-point-helper.h (-3 / +4 lines)
 Lines 261-273   public: Link Here 
261
261
262
private:
262
private:
263
  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
263
  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
264
  static void SniffEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
265
264
  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
266
  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
265
  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
267
  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
266
  static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
267
  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
268
  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
268
  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
269
  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
269
  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
270
  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
270
  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
271
271
  ObjectFactory m_queueFactory;
272
  ObjectFactory m_queueFactory;
272
  ObjectFactory m_channelFactory;
273
  ObjectFactory m_channelFactory;
273
  ObjectFactory m_deviceFactory;
274
  ObjectFactory m_deviceFactory;
(-)a/src/helper/wifi-helper.cc (+55 lines)
 Lines 36-41   NS_LOG_COMPONENT_DEFINE ("WifiHelper"); Link Here 
36
NS_LOG_COMPONENT_DEFINE ("WifiHelper");
36
NS_LOG_COMPONENT_DEFINE ("WifiHelper");
37
37
38
namespace ns3 {
38
namespace ns3 {
39
40
static void PcapSnifferEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
41
{
42
  writer->WritePacket (packet);
43
}
44
45
void 
46
WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
47
{
48
  std::ostringstream oss;
49
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Mac/";
50
  Config::MatchContainer matches = Config::LookupMatches (oss.str ());
51
  if (matches.GetN () == 0)
52
    {
53
      return;
54
    }
55
  oss.str ("");
56
  oss << filename << "-" << nodeid << "-" << deviceid << ".pcap";
57
  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
58
  pcap->Open (oss.str ());
59
  pcap->WriteEthernetHeader ();
60
  oss.str ("");
61
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Mac/Sniffer";
62
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapSnifferEvent, pcap));
63
}
64
65
void 
66
WifiHelper::EnablePcap (std::string filename, NetDeviceContainer d)
67
{
68
  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
69
    {
70
      Ptr<NetDevice> dev = *i;
71
      EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ());
72
    }
73
}
74
void
75
WifiHelper::EnablePcap (std::string filename, NodeContainer n)
76
{
77
  NetDeviceContainer devs;
78
  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
79
    {
80
      Ptr<Node> node = *i;
81
      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
82
        {
83
          devs.Add (node->GetDevice (j));
84
        }
85
    }
86
  EnablePcap (filename, devs);
87
}
88
89
void
90
WifiHelper::EnablePcapAll (std::string filename)
91
{
92
  EnablePcap (filename, NodeContainer::GetGlobal ());
93
}
39
94
40
WifiPhyHelper::~WifiPhyHelper ()
95
WifiPhyHelper::~WifiPhyHelper ()
41
{}
96
{}
(-)a/src/helper/wifi-helper.h (+37 lines)
 Lines 159-164   public: Link Here 
159
   * \returns a device container which contains all the devices created by this method.
159
   * \returns a device container which contains all the devices created by this method.
160
   */
160
   */
161
  NetDeviceContainer Install (const WifiPhyHelper &phy, std::string nodeName) const;
161
  NetDeviceContainer Install (const WifiPhyHelper &phy, std::string nodeName) const;
162
  /**
163
   * \param filename filename prefix to use for pcap files.
164
   * \param nodeid the id of the node to generate pcap output for.
165
   * \param deviceid the id of the device to generate pcap output for.
166
   *
167
   * Generate a pcap file which contains the link-level data observed
168
   * by the specified deviceid within the specified nodeid. The pcap
169
   * data is stored in the file prefix-nodeid-deviceid.pcap.
170
   *
171
   * This method should be invoked after the network topology has 
172
   * been fully constructed.
173
   */
174
  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
175
  /**
176
   * \param filename filename prefix to use for pcap files.
177
   * \param d container of devices of type ns3::WifiNetDevice
178
   *
179
   * Enable pcap output on each input device which is of the
180
   * ns3::WifiNetDevice type.
181
   */
182
  static void EnablePcap (std::string filename, NetDeviceContainer d);
183
  /**
184
   * \param filename filename prefix to use for pcap files.
185
   * \param n container of nodes.
186
   *
187
   * Enable pcap output on each device which is of the
188
   * ns3::WifiNetDevice type and which is located in one of the 
189
   * input nodes.
190
   */
191
  static void EnablePcap (std::string filename, NodeContainer n);
192
  /**
193
   * \param filename filename prefix to use for pcap files.
194
   *
195
   * Enable pcap output on each device which is of the
196
   * ns3::WifiNetDevice type
197
   */
198
  static void EnablePcapAll (std::string filename);
162
199
163
private:
200
private:
164
  ObjectFactory m_stationManager;
201
  ObjectFactory m_stationManager;
(-)a/src/helper/yans-wifi-helper.cc (-15 / +3 lines)
 Lines 31-46    Link Here 
31
31
32
namespace ns3 {
32
namespace ns3 {
33
33
34
static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet,
34
static void PcapSnifferEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
35
                            WifiMode mode, WifiPreamble preamble, 
36
                            uint8_t txLevel)
37
{
38
  writer->WritePacket (packet);
39
}
40
41
static void PcapPhyRxEvent (Ptr<PcapWriter> writer, 
42
                            Ptr<const Packet> packet, double snr, WifiMode mode, 
43
                            enum WifiPreamble preamble)
44
{
35
{
45
  writer->WritePacket (packet);
36
  writer->WritePacket (packet);
46
}
37
}
 Lines 229-239   YansWifiPhyHelper::EnablePcap (std::stri Link Here 
229
  pcap->Open (oss.str ());
220
  pcap->Open (oss.str ());
230
  pcap->WriteWifiHeader ();
221
  pcap->WriteWifiHeader ();
231
  oss.str ("");
222
  oss.str ("");
232
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
223
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/PromiscSniffer";
233
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyTxEvent, pcap));
224
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapSnifferEvent, pcap));
234
  oss.str ("");
235
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
236
  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyRxEvent, pcap));
237
}
225
}
238
void 
226
void 
239
YansWifiPhyHelper::EnablePcap (std::string filename, NetDeviceContainer d)
227
YansWifiPhyHelper::EnablePcap (std::string filename, NetDeviceContainer d)

Return to bug 443