src/devices/wifi/mac-low.cc
changeset 3038 5962e2962fa9
parent 2985 fa0747c4ad5e
child 3040 e11e106c7c19
equal deleted inserted replaced
3037:b0f12f3a75b3 3038:5962e2962fa9
    19  */
    19  */
    20 
    20 
    21 #include "ns3/assert.h"
    21 #include "ns3/assert.h"
    22 #include "ns3/packet.h"
    22 #include "ns3/packet.h"
    23 #include "ns3/simulator.h"
    23 #include "ns3/simulator.h"
    24 #include "ns3/tag.h"
    24 #include "ns3/mtag.h"
    25 #include "ns3/log.h"
    25 #include "ns3/log.h"
    26 #include "ns3/node.h"
    26 #include "ns3/node.h"
    27 
    27 
    28 #include "mac-low.h"
    28 #include "mac-low.h"
    29 #include "wifi-phy.h"
    29 #include "wifi-phy.h"
    35 #define MY_DEBUG(x) \
    35 #define MY_DEBUG(x) \
    36   NS_LOG_DEBUG (m_mac->GetAddress () << " " << x)
    36   NS_LOG_DEBUG (m_mac->GetAddress () << " " << x)
    37 
    37 
    38 namespace ns3 {
    38 namespace ns3 {
    39 
    39 
    40 class SnrTag : public Tag
    40 class SnrTag : public Mtag
    41 {
    41 {
    42 public:
    42 public:
    43   SnrTag ();
    43 
    44   SnrTag (const SnrTag &o);
    44   static TypeId GetTypeId (void);
    45   ~SnrTag ();
    45   virtual TypeId GetInstanceTypeId (void) const;
    46   static uint32_t GetUid (void);
    46 
    47   void Print (std::ostream &os) const;
    47   virtual uint32_t GetSerializedSize (void) const;
    48   uint32_t GetSerializedSize (void) const;
    48   virtual void Serialize (MtagBuffer i) const;
    49   void Serialize (Buffer::Iterator i) const;
    49   virtual void Deserialize (MtagBuffer i);
    50   uint32_t Deserialize (Buffer::Iterator i);
       
    51 
    50 
    52   void Set (double snr);
    51   void Set (double snr);
    53   double Get (void) const;
    52   double Get (void) const;
    54 private:
    53 private:
    55   double m_snr;
    54   double m_snr;
    56 };
    55 };
    57 
    56 
    58 SnrTag::SnrTag ()
    57 TypeId 
    59   : m_snr (0.0)
    58 SnrTag::GetTypeId (void)
    60 {}
    59 {
    61 SnrTag::SnrTag (const SnrTag &o)
    60   static TypeId tid = TypeId ("ns3::SnrTag")
    62   : m_snr (o.m_snr)
    61     .SetParent<Mtag> ()
    63 {}
    62     .AddConstructor<SnrTag> ()
    64 SnrTag::~SnrTag ()
    63     .AddAttribute ("Snr", "The snr of the last packet received",
    65 {}
    64                    DoubleValue (0.0),
    66 uint32_t 
    65                    MakeDoubleAccessor (&SnrTag::Get),
    67 SnrTag::GetUid (void)
    66                    MakeDoubleChecker<double> ())
    68 {
    67     ;
    69   static uint32_t uid = AllocateUid<SnrTag> ("SnrTag.ns3.inria.fr");
    68   return tid;
    70   return uid;
    69 }
    71 }
    70 TypeId 
    72 void 
    71 SnrTag::GetInstanceTypeId (void) const
    73 SnrTag::Print (std::ostream &os) const
    72 {
    74 {
    73   return GetTypeId ();
    75   os << "snr="<<m_snr;
    74 }
    76 }
    75 
    77 uint32_t 
    76 uint32_t 
    78 SnrTag::GetSerializedSize (void) const
    77 SnrTag::GetSerializedSize (void) const
    79 {
    78 {
    80   return 0;
    79   return sizeof (double);
    81 }
    80 }
    82 void 
    81 void 
    83 SnrTag::Serialize (Buffer::Iterator i) const
    82 SnrTag::Serialize (MtagBuffer i) const
    84 {
    83 {
    85   // would need to serialize double to platform-independent format.
    84   i.WriteDouble (m_snr);
    86 }
    85 }
    87 uint32_t 
    86 void 
    88 SnrTag::Deserialize (Buffer::Iterator i)
    87 SnrTag::Deserialize (MtagBuffer i)
    89 {
    88 {
    90   // would need to deserialize double from platform-independent format.
    89   m_snr = i.ReadDouble ();
    91   return 0;
       
    92 }
    90 }
    93 void 
    91 void 
    94 SnrTag::Set (double snr)
    92 SnrTag::Set (double snr)
    95 {
    93 {
    96   m_snr = snr;
    94   m_snr = snr;
   470            m_ctsTimeoutEvent.IsRunning () &&
   468            m_ctsTimeoutEvent.IsRunning () &&
   471            m_currentPacket != 0) 
   469            m_currentPacket != 0) 
   472     {
   470     {
   473       MY_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
   471       MY_DEBUG ("receive cts from="<<m_currentHdr.GetAddr1 ());
   474       SnrTag tag;
   472       SnrTag tag;
   475       packet->PeekTag (tag);
   473       packet->FindFirstMatchingTag (tag);
   476       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   474       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   477       station->ReportRxOk (rxSnr, txMode);
   475       station->ReportRxOk (rxSnr, txMode);
   478       station->ReportRtsOk (rxSnr, txMode, tag.Get ());
   476       station->ReportRtsOk (rxSnr, txMode, tag.Get ());
   479       
   477       
   480       m_ctsTimeoutEvent.Cancel ();
   478       m_ctsTimeoutEvent.Cancel ();
   493             m_superFastAckTimeoutEvent.IsRunning ()) &&
   491             m_superFastAckTimeoutEvent.IsRunning ()) &&
   494            m_txParams.MustWaitAck ()) 
   492            m_txParams.MustWaitAck ()) 
   495     {
   493     {
   496       MY_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
   494       MY_DEBUG ("receive ack from="<<m_currentHdr.GetAddr1 ());
   497       SnrTag tag;
   495       SnrTag tag;
   498       packet->PeekTag (tag);
   496       packet->FindFirstMatchingTag (tag);
   499       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   497       WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
   500       station->ReportRxOk (rxSnr, txMode);
   498       station->ReportRxOk (rxSnr, txMode);
   501       station->ReportDataOk (rxSnr, txMode, tag.Get ());
   499       station->ReportDataOk (rxSnr, txMode, tag.Get ());
   502       bool gotAck = false;
   500       bool gotAck = false;
   503       if (m_txParams.MustWaitNormalAck () &&
   501       if (m_txParams.MustWaitNormalAck () &&
  1036   WifiMacTrailer fcs;
  1034   WifiMacTrailer fcs;
  1037   packet->AddTrailer (fcs);
  1035   packet->AddTrailer (fcs);
  1038 
  1036 
  1039   struct SnrTag tag;
  1037   struct SnrTag tag;
  1040   tag.Set (rtsSnr);
  1038   tag.Set (rtsSnr);
  1041   packet->AddTag (tag);
  1039   packet->AddMtag (tag);
  1042 
  1040 
  1043   ForwardDown (packet, &cts, ctsTxMode);
  1041   ForwardDown (packet, &cts, ctsTxMode);
  1044 }
  1042 }
  1045 
  1043 
  1046 void
  1044 void
  1114   WifiMacTrailer fcs;
  1112   WifiMacTrailer fcs;
  1115   packet->AddTrailer (fcs);
  1113   packet->AddTrailer (fcs);
  1116 
  1114 
  1117   struct SnrTag tag;
  1115   struct SnrTag tag;
  1118   tag.Set (dataSnr);
  1116   tag.Set (dataSnr);
  1119   packet->AddTag (tag);
  1117   packet->AddMtag (tag);
  1120 
  1118 
  1121   ForwardDown (packet, &ack, ackTxMode);
  1119   ForwardDown (packet, &ack, ackTxMode);
  1122 }
  1120 }
  1123 
  1121 
  1124 } // namespace ns3
  1122 } // namespace ns3