src/devices/csma/csma-net-device.cc
changeset 4264 9d2e96c4e6e4
parent 4263 fec2f830d015
child 4265 5f837915710a
equal deleted inserted replaced
4263:fec2f830d015 4264:9d2e96c4e6e4
    99                      "Trace source indicating a packet has been dropped by the device before transmission",
    99                      "Trace source indicating a packet has been dropped by the device before transmission",
   100                      MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxDropTrace))
   100                      MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxDropTrace))
   101     .AddTraceSource ("MacRx", 
   101     .AddTraceSource ("MacRx", 
   102                      "Trace source indicating a packet has been received by this device and is being forwarded up the stack",
   102                      "Trace source indicating a packet has been received by this device and is being forwarded up the stack",
   103                      MakeTraceSourceAccessor (&CsmaNetDevice::m_macRxTrace))
   103                      MakeTraceSourceAccessor (&CsmaNetDevice::m_macRxTrace))
       
   104 #if 0
       
   105     // Not currently implemented in this device
       
   106     .AddTraceSource ("MacRxDrop", 
       
   107                      "Trace source indicating a packet was received, but dropped before being forwarded up the stack",
       
   108                      MakeTraceSourceAccessor (&CsmaNetDevice::m_macRxDropTrace))
       
   109 #endif
       
   110     .AddTraceSource ("MacTxBackoff", 
       
   111                      "Trace source indicating a packet has been delayed by the CSMA backoff process",
       
   112                      MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxBackoffTrace))
   104     //
   113     //
   105     // Trace souces at the "bottom" of the net device, where packets transition
   114     // Trace souces at the "bottom" of the net device, where packets transition
   106     // to/from the channel.
   115     // to/from the channel.
   107     //
   116     //
   108     .AddTraceSource ("PhyTxStart", 
   117     .AddTraceSource ("PhyTxBegin", 
   109                      "Trace source indicating a packet has begun transmitting over the channel",
   118                      "Trace source indicating a packet has begun transmitting over the channel",
   110                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxStartTrace))
   119                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxBeginTrace))
   111     .AddTraceSource ("PhyTx", 
   120     .AddTraceSource ("PhyTxEnd", 
   112                      "Trace source indicating a packet has been completely transmitted over the channel",
   121                      "Trace source indicating a packet has been completely transmitted over the channel",
   113                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxTrace))
   122                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxEndTrace))
   114     .AddTraceSource ("PhyTxDrop", 
   123     .AddTraceSource ("PhyTxDrop", 
   115                      "Trace source indicating a packet has been dropped by the device during transmission",
   124                      "Trace source indicating a packet has been dropped by the device during transmission",
   116                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxDropTrace))
   125                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyTxDropTrace))
   117     .AddTraceSource ("PhyRxStart", 
   126 #if 0
       
   127     // Not currently implemented in this device
       
   128     .AddTraceSource ("PhyRxBegin", 
   118                      "Trace source indicating a packet has begun being received by the device",
   129                      "Trace source indicating a packet has begun being received by the device",
   119                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxStartTrace))
   130                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxBeginTrace))
   120     .AddTraceSource ("PhyRx", 
   131 #endif
       
   132     .AddTraceSource ("PhyRxEnd", 
   121                      "Trace source indicating a packet has been completely received by the device",
   133                      "Trace source indicating a packet has been completely received by the device",
   122                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxTrace))
   134                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxEndTrace))
   123     .AddTraceSource ("PhyRxDrop", 
   135     .AddTraceSource ("PhyRxDrop", 
   124                      "Trace source indicating a packet has been dropped by the device during reception",
   136                      "Trace source indicating a packet has been dropped by the device during reception",
   125                      MakeTraceSourceAccessor (&CsmaNetDevice::m_phyRxDropTrace))
   137                      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     //
   138     //
   131     // Trace sources designed to simulate a packet sniffer facility (tcpdump). 
   139     // Trace sources designed to simulate a packet sniffer facility (tcpdump). 
   132     //
   140     //
   133     .AddTraceSource ("Sniffer", 
   141     .AddTraceSource ("Sniffer", 
   134                      "Trace source simulating a non-promiscuous packet sniffer attached to the device",
   142                      "Trace source simulating a non-promiscuous packet sniffer attached to the device",
   511           //
   519           //
   512           TransmitAbort ();
   520           TransmitAbort ();
   513         } 
   521         } 
   514       else 
   522       else 
   515         {
   523         {
   516           m_phyTxBackoffTrace (m_currentPkt);
   524           m_macTxBackoffTrace (m_currentPkt);
   517 
   525 
   518           m_backoff.IncrNumRetries ();
   526           m_backoff.IncrNumRetries ();
   519           Time backoffTime = m_backoff.GetBackoffTime ();
   527           Time backoffTime = m_backoff.GetBackoffTime ();
   520 
   528 
   521           NS_LOG_LOGIC ("Channel busy, backing off for " << backoffTime.GetSeconds () << " sec");
   529           NS_LOG_LOGIC ("Channel busy, backing off for " << backoffTime.GetSeconds () << " sec");
   541           // Transmission succeeded, reset the backoff time parameters and
   549           // Transmission succeeded, reset the backoff time parameters and
   542           // schedule a transmit complete event.
   550           // schedule a transmit complete event.
   543           //
   551           //
   544           m_backoff.ResetBackoffTime ();
   552           m_backoff.ResetBackoffTime ();
   545           m_txMachineState = BUSY;
   553           m_txMachineState = BUSY;
   546           m_phyTxStartTrace (m_currentPkt);
   554           m_phyTxBeginTrace (m_currentPkt);
   547 
   555 
   548           Time tEvent = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ()));
   556           Time tEvent = Seconds (m_bps.CalculateTxTime (m_currentPkt->GetSize ()));
   549           NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << tEvent.GetSeconds () << "sec");
   557           NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << tEvent.GetSeconds () << "sec");
   550           Simulator::Schedule (tEvent, &CsmaNetDevice::TransmitCompleteEvent, this);
   558           Simulator::Schedule (tEvent, &CsmaNetDevice::TransmitCompleteEvent, this);
   551         }
   559         }
   618   NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitCompleteEvent(): m_currentPkt zero");
   626   NS_ASSERT_MSG (m_currentPkt != 0, "CsmaNetDevice::TransmitCompleteEvent(): m_currentPkt zero");
   619   NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
   627   NS_LOG_LOGIC ("m_currentPkt=" << m_currentPkt);
   620   NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
   628   NS_LOG_LOGIC ("Pkt UID is " << m_currentPkt->GetUid () << ")");
   621 
   629 
   622   m_channel->TransmitEnd (); 
   630   m_channel->TransmitEnd (); 
   623   m_phyTxTrace (m_currentPkt);
   631   m_phyTxEndTrace (m_currentPkt);
   624   m_currentPkt = 0;
   632   m_currentPkt = 0;
   625 
   633 
   626   NS_LOG_LOGIC ("Schedule TransmitReadyEvent in " << m_tInterframeGap.GetSeconds () << "sec");
   634   NS_LOG_LOGIC ("Schedule TransmitReadyEvent in " << m_tInterframeGap.GetSeconds () << "sec");
   627 
   635 
   628   Simulator::Schedule (m_tInterframeGap, &CsmaNetDevice::TransmitReadyEvent, this);
   636   Simulator::Schedule (m_tInterframeGap, &CsmaNetDevice::TransmitReadyEvent, this);
   735 
   743 
   736   //
   744   //
   737   // Hit the trace hook.  This trace will fire on all packets received from the
   745   // Hit the trace hook.  This trace will fire on all packets received from the
   738   // channel except those originated by this device.
   746   // channel except those originated by this device.
   739   //
   747   //
   740   m_phyRxTrace (packet);
   748   m_phyRxEndTrace (packet);
   741 
   749 
   742   // 
   750   // 
   743   // Only receive if the send side of net device is enabled
   751   // Only receive if the send side of net device is enabled
   744   //
   752   //
   745   if (IsReceiveEnabled () == false)
   753   if (IsReceiveEnabled () == false)