src/wifi/model/interference-helper.cc
changeset 7143 0146b1916bc0
parent 7141 072fb225b714
child 7385 10beb0e53130
equal deleted inserted replaced
7142:89a701fec3a1 7143:0146b1916bc0
   187         }
   187         }
   188     }
   188     }
   189   return end > now ? end - now : MicroSeconds (0);
   189   return end > now ? end - now : MicroSeconds (0);
   190 }
   190 }
   191 
   191 
   192 WifiMode
       
   193 InterferenceHelper::GetPlcpHeaderMode (WifiMode payloadMode, WifiPreamble preamble)
       
   194 {
       
   195   switch (payloadMode.GetModulationClass ())
       
   196     {
       
   197     case WIFI_MOD_CLASS_OFDM:
       
   198       {
       
   199         switch (payloadMode.GetBandwidth ())
       
   200           {
       
   201           case 5000000:
       
   202             return WifiPhy::GetOfdmRate1_5MbpsBW5MHz ();
       
   203           case 10000000:
       
   204             return WifiPhy::GetOfdmRate3MbpsBW10MHz ();
       
   205           default:
       
   206             // IEEE Std 802.11-2007, 17.3.2
       
   207             // actually this is only the first part of the PlcpHeader,
       
   208             // because the last 16 bits of the PlcpHeader are using the
       
   209             // same mode of the payload
       
   210             return WifiPhy::GetOfdmRate6Mbps ();
       
   211           }
       
   212       }
       
   213 
       
   214     case WIFI_MOD_CLASS_ERP_OFDM:
       
   215       return WifiPhy::GetErpOfdmRate6Mbps ();
       
   216 
       
   217     case WIFI_MOD_CLASS_DSSS:
       
   218       if (preamble == WIFI_PREAMBLE_LONG)
       
   219         {
       
   220           // IEEE Std 802.11-2007, sections 15.2.3 and 18.2.2.1
       
   221           return WifiPhy::GetDsssRate1Mbps ();
       
   222         }
       
   223       else  //  WIFI_PREAMBLE_SHORT
       
   224         {
       
   225           // IEEE Std 802.11-2007, section 18.2.2.2
       
   226           return WifiPhy::GetDsssRate2Mbps ();
       
   227         }
       
   228 
       
   229     default:
       
   230       NS_FATAL_ERROR ("unsupported modulation class");
       
   231       return WifiMode ();
       
   232     }
       
   233 }
       
   234 
       
   235 uint32_t
       
   236 InterferenceHelper::GetPlcpHeaderDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble)
       
   237 {
       
   238   switch (payloadMode.GetModulationClass ())
       
   239     {
       
   240     case WIFI_MOD_CLASS_OFDM:
       
   241       {
       
   242         switch (payloadMode.GetBandwidth ())
       
   243           {
       
   244           case 20000000:
       
   245           default:
       
   246             // IEEE Std 802.11-2007, section 17.3.3 and figure 17-4
       
   247             // also section 17.3.2.3, table 17-4
       
   248             // We return the duration of the SIGNAL field only, since the
       
   249             // SERVICE field (which strictly speaking belongs to the PLCP
       
   250             // header, see section 17.3.2 and figure 17-1) is sent using the
       
   251             // payload mode.
       
   252             return 4;
       
   253           case 10000000:
       
   254             // IEEE Std 802.11-2007, section 17.3.2.3, table 17-4
       
   255             return 8;
       
   256           case 5000000:
       
   257             // IEEE Std 802.11-2007, section 17.3.2.3, table 17-4
       
   258             return 16;
       
   259           }
       
   260       }
       
   261 
       
   262     case WIFI_MOD_CLASS_ERP_OFDM:
       
   263       return 16;
       
   264 
       
   265     case WIFI_MOD_CLASS_DSSS:
       
   266       if (preamble == WIFI_PREAMBLE_SHORT)
       
   267         {
       
   268           // IEEE Std 802.11-2007, section 18.2.2.2 and figure 18-2
       
   269           return 24;
       
   270         }
       
   271       else // WIFI_PREAMBLE_LONG
       
   272         {
       
   273           // IEEE Std 802.11-2007, sections 18.2.2.1 and figure 18-1
       
   274           return 48;
       
   275         }
       
   276 
       
   277     default:
       
   278       NS_FATAL_ERROR ("unsupported modulation class");
       
   279       return 0;
       
   280     }
       
   281 }
       
   282 
       
   283 uint32_t
       
   284 InterferenceHelper::GetPlcpPreambleDurationMicroSeconds (WifiMode payloadMode, WifiPreamble preamble)
       
   285 {
       
   286   switch (payloadMode.GetModulationClass ())
       
   287     {
       
   288     case WIFI_MOD_CLASS_OFDM:
       
   289       {
       
   290         switch (payloadMode.GetBandwidth ())
       
   291           {
       
   292           case 20000000:
       
   293           default:
       
   294             // IEEE Std 802.11-2007, section 17.3.3,  figure 17-4
       
   295             // also section 17.3.2.3, table 17-4
       
   296             return 16;
       
   297           case 10000000:
       
   298             // IEEE Std 802.11-2007, section 17.3.3, table 17-4
       
   299             // also section 17.3.2.3, table 17-4
       
   300             return 32;
       
   301           case 5000000:
       
   302             // IEEE Std 802.11-2007, section 17.3.3
       
   303             // also section 17.3.2.3, table 17-4
       
   304             return 64;
       
   305           }
       
   306       }
       
   307 
       
   308     case WIFI_MOD_CLASS_ERP_OFDM:
       
   309       return 4;
       
   310 
       
   311     case WIFI_MOD_CLASS_DSSS:
       
   312       if (preamble == WIFI_PREAMBLE_SHORT)
       
   313         {
       
   314           // IEEE Std 802.11-2007, section 18.2.2.2 and figure 18-2
       
   315           return 72;
       
   316         }
       
   317       else // WIFI_PREAMBLE_LONG
       
   318         {
       
   319           // IEEE Std 802.11-2007, sections 18.2.2.1 and figure 18-1
       
   320           return 144;
       
   321         }
       
   322 
       
   323     default:
       
   324       NS_FATAL_ERROR ("unsupported modulation class");
       
   325       return 0;
       
   326     }
       
   327 }
       
   328 
       
   329 uint32_t
       
   330 InterferenceHelper::GetPayloadDurationMicroSeconds (uint32_t size, WifiMode payloadMode)
       
   331 {
       
   332   NS_LOG_FUNCTION (size << payloadMode);
       
   333 
       
   334   switch (payloadMode.GetModulationClass ())
       
   335     {
       
   336     case WIFI_MOD_CLASS_OFDM:
       
   337     case WIFI_MOD_CLASS_ERP_OFDM:
       
   338       {
       
   339         // IEEE Std 802.11-2007, section 17.3.2.3, table 17-4
       
   340         // corresponds to T_{SYM} in the table
       
   341         uint32_t symbolDurationUs;
       
   342 
       
   343         switch (payloadMode.GetBandwidth ())
       
   344           {
       
   345           case 20000000:
       
   346           default:
       
   347             symbolDurationUs = 4;
       
   348             break;
       
   349           case 10000000:
       
   350             symbolDurationUs = 8;
       
   351             break;
       
   352           case 5000000:
       
   353             symbolDurationUs = 16;
       
   354             break;
       
   355           }
       
   356 
       
   357         // IEEE Std 802.11-2007, section 17.3.2.2, table 17-3
       
   358         // corresponds to N_{DBPS} in the table
       
   359         double numDataBitsPerSymbol = payloadMode.GetDataRate ()  * symbolDurationUs / 1e6;
       
   360 
       
   361         // IEEE Std 802.11-2007, section 17.3.5.3, equation (17-11)
       
   362         uint32_t numSymbols = lrint (ceil ((16 + size * 8.0 + 6.0) / numDataBitsPerSymbol));
       
   363 
       
   364         // Add signal extension for ERP PHY
       
   365         if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM)
       
   366           {
       
   367             return numSymbols * symbolDurationUs + 6;
       
   368           }
       
   369         else
       
   370           {
       
   371             return numSymbols * symbolDurationUs;
       
   372           }
       
   373       }
       
   374 
       
   375     case WIFI_MOD_CLASS_DSSS:
       
   376       // IEEE Std 802.11-2007, section 18.2.3.5
       
   377       NS_LOG_LOGIC (" size=" << size
       
   378                              << " mode=" << payloadMode
       
   379                              << " rate=" << payloadMode.GetDataRate () );
       
   380       return lrint (ceil ((size * 8.0) / (payloadMode.GetDataRate () / 1.0e6)));
       
   381 
       
   382     default:
       
   383       NS_FATAL_ERROR ("unsupported modulation class");
       
   384       return 0;
       
   385     }
       
   386 }
       
   387 
       
   388 Time
       
   389 InterferenceHelper::CalculateTxDuration (uint32_t size, WifiMode payloadMode, WifiPreamble preamble)
       
   390 {
       
   391   uint32_t duration = GetPlcpPreambleDurationMicroSeconds (payloadMode, preamble)
       
   392     + GetPlcpHeaderDurationMicroSeconds (payloadMode, preamble)
       
   393     + GetPayloadDurationMicroSeconds (size, payloadMode);
       
   394   return MicroSeconds (duration);
       
   395 }
       
   396 
       
   397 void
   192 void
   398 InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
   193 InterferenceHelper::AppendEvent (Ptr<InterferenceHelper::Event> event)
   399 {
   194 {
   400   Time now = Simulator::Now ();
   195   Time now = Simulator::Now ();
   401   if (!m_rxing)
   196   if (!m_rxing)
   468   double psr = 1.0; /* Packet Success Rate */
   263   double psr = 1.0; /* Packet Success Rate */
   469   NiChanges::iterator j = ni->begin ();
   264   NiChanges::iterator j = ni->begin ();
   470   Time previous = (*j).GetTime ();
   265   Time previous = (*j).GetTime ();
   471   WifiMode payloadMode = event->GetPayloadMode ();
   266   WifiMode payloadMode = event->GetPayloadMode ();
   472   WifiPreamble preamble = event->GetPreambleType ();
   267   WifiPreamble preamble = event->GetPreambleType ();
   473   WifiMode headerMode = GetPlcpHeaderMode (payloadMode, preamble);
   268   WifiMode headerMode = WifiPhy::GetPlcpHeaderMode (payloadMode, preamble);
   474   Time plcpHeaderStart = (*j).GetTime () + MicroSeconds (GetPlcpPreambleDurationMicroSeconds (payloadMode, preamble));
   269   Time plcpHeaderStart = (*j).GetTime () + MicroSeconds (WifiPhy::GetPlcpPreambleDurationMicroSeconds (payloadMode, preamble));
   475   Time plcpPayloadStart = plcpHeaderStart + MicroSeconds (GetPlcpHeaderDurationMicroSeconds (payloadMode, preamble));
   270   Time plcpPayloadStart = plcpHeaderStart + MicroSeconds (WifiPhy::GetPlcpHeaderDurationMicroSeconds (payloadMode, preamble));
   476   double noiseInterferenceW = (*j).GetDelta ();
   271   double noiseInterferenceW = (*j).GetDelta ();
   477   double powerW = event->GetRxPowerW ();
   272   double powerW = event->GetRxPowerW ();
   478 
   273 
   479   j++;
   274   j++;
   480   while (ni->end () != j)
   275   while (ni->end () != j)