src/wifi/model/wifi-mode.cc
changeset 7141 072fb225b714
parent 6852 8f1a53d3f6ca
child 7252 c8200621e252
equal deleted inserted replaced
7140:d203296efb63 7141:072fb225b714
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     2 /*
     3  * Copyright (c) 2005,2006,2007 INRIA
     3  * Copyright (c) 2005,2006,2007 INRIA
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as 
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     7  * published by the Free Software Foundation;
     8  *
     8  *
     9  * This program is distributed in the hope that it will be useful,
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    39   is >> str;
    39   is >> str;
    40   mode = WifiModeFactory::GetFactory ()->Search (str);
    40   mode = WifiModeFactory::GetFactory ()->Search (str);
    41   return is;
    41   return is;
    42 }
    42 }
    43 
    43 
    44 uint32_t 
    44 uint32_t
    45 WifiMode::GetBandwidth (void) const
    45 WifiMode::GetBandwidth (void) const
    46 {
    46 {
    47   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    47   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    48   return item->bandwidth;
    48   return item->bandwidth;
    49 }
    49 }
    50 uint32_t 
    50 uint32_t
    51 WifiMode::GetPhyRate (void) const
    51 WifiMode::GetPhyRate (void) const
    52 {
    52 {
    53   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    53   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    54   return item->phyRate;
    54   return item->phyRate;
    55 }
    55 }
    56 uint32_t 
    56 uint32_t
    57 WifiMode::GetDataRate (void) const
    57 WifiMode::GetDataRate (void) const
    58 {
    58 {
    59   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    59   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    60   return item->dataRate;
    60   return item->dataRate;
    61 }
    61 }
    62 enum WifiCodeRate 
    62 enum WifiCodeRate
    63 WifiMode::GetCodeRate (void) const
    63 WifiMode::GetCodeRate (void) const
    64 {
    64 {
    65   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    65   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    66   return item->codingRate;
    66   return item->codingRate;
    67 }
    67 }
    68 uint8_t 
    68 uint8_t
    69 WifiMode::GetConstellationSize (void) const
    69 WifiMode::GetConstellationSize (void) const
    70 {
    70 {
    71   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    71   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    72   return item->constellationSize;
    72   return item->constellationSize;
    73 }
    73 }
    74 std::string 
    74 std::string
    75 WifiMode::GetUniqueName (void) const
    75 WifiMode::GetUniqueName (void) const
    76 {
    76 {
    77   // needed for ostream printing of the invalid mode
    77   // needed for ostream printing of the invalid mode
    78   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    78   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    79   return item->uniqueUid;
    79   return item->uniqueUid;
    82 WifiMode::IsMandatory (void) const
    82 WifiMode::IsMandatory (void) const
    83 {
    83 {
    84   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    84   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    85   return item->isMandatory;
    85   return item->isMandatory;
    86 }
    86 }
    87 uint32_t 
    87 uint32_t
    88 WifiMode::GetUid (void) const
    88 WifiMode::GetUid (void) const
    89 {
    89 {
    90   return m_uid;
    90   return m_uid;
    91 }
    91 }
    92 enum WifiModulationClass
    92 enum WifiModulationClass
    95   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    95   struct WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_uid);
    96   return item->modClass;
    96   return item->modClass;
    97 }
    97 }
    98 WifiMode::WifiMode ()
    98 WifiMode::WifiMode ()
    99   : m_uid (0)
    99   : m_uid (0)
   100 {}
   100 {
       
   101 }
   101 WifiMode::WifiMode (uint32_t uid)
   102 WifiMode::WifiMode (uint32_t uid)
   102   : m_uid (uid)
   103   : m_uid (uid)
   103 {}
   104 {
       
   105 }
   104 WifiMode::WifiMode (std::string name)
   106 WifiMode::WifiMode (std::string name)
   105 {
   107 {
   106   *this = WifiModeFactory::GetFactory ()->Search (name);
   108   *this = WifiModeFactory::GetFactory ()->Search (name);
   107 }
   109 }
   108 
   110 
   109 ATTRIBUTE_HELPER_CPP (WifiMode);
   111 ATTRIBUTE_HELPER_CPP (WifiMode);
   110 
   112 
   111 WifiModeFactory::WifiModeFactory ()
   113 WifiModeFactory::WifiModeFactory ()
   112 {}
   114 {
   113 
   115 }
   114 
   116 
   115 WifiMode 
   117 
       
   118 WifiMode
   116 WifiModeFactory::CreateWifiMode (std::string uniqueName,
   119 WifiModeFactory::CreateWifiMode (std::string uniqueName,
   117                                  enum WifiModulationClass modClass,
   120                                  enum WifiModulationClass modClass,
   118                                  bool isMandatory,
   121                                  bool isMandatory,
   119                                  uint32_t bandwidth,
   122                                  uint32_t bandwidth,
   120                                  uint32_t dataRate,
   123                                  uint32_t dataRate,
   132   item->bandwidth = bandwidth;
   135   item->bandwidth = bandwidth;
   133   item->dataRate = dataRate;
   136   item->dataRate = dataRate;
   134 
   137 
   135   item->codingRate = codingRate;
   138   item->codingRate = codingRate;
   136 
   139 
   137   switch (codingRate) {
   140   switch (codingRate)
   138   case WIFI_CODE_RATE_3_4:
   141     {
   139     item->phyRate = dataRate * 4 / 3;
   142     case WIFI_CODE_RATE_3_4:
   140     break;
   143       item->phyRate = dataRate * 4 / 3;
   141   case WIFI_CODE_RATE_2_3:
   144       break;
   142     item->phyRate = dataRate * 3 / 2;
   145     case WIFI_CODE_RATE_2_3:
   143     break;
   146       item->phyRate = dataRate * 3 / 2;
   144   case WIFI_CODE_RATE_1_2:
   147       break;
   145     item->phyRate = dataRate * 2 / 1;
   148     case WIFI_CODE_RATE_1_2:
   146     break;
   149       item->phyRate = dataRate * 2 / 1;
   147   case WIFI_CODE_RATE_UNDEFINED:
   150       break;
   148   default:
   151     case WIFI_CODE_RATE_UNDEFINED:
   149     item->phyRate = dataRate;
   152     default:
   150     break;
   153       item->phyRate = dataRate;
   151   }
   154       break;
       
   155     }
   152 
   156 
   153   // Check for compatibility between modulation class and coding
   157   // Check for compatibility between modulation class and coding
   154   // rate. If modulation class is DSSS then coding rate must be
   158   // rate. If modulation class is DSSS then coding rate must be
   155   // undefined, and vice versa. I could have done this with an
   159   // undefined, and vice versa. I could have done this with an
   156   // assertion, but it seems better to always give the error (i.e.,
   160   // assertion, but it seems better to always give the error (i.e.,
   157   // not only in non-optimised builds) and the cycles that extra test
   161   // not only in non-optimised builds) and the cycles that extra test
   158   // here costs are only suffered at simulation setup.
   162   // here costs are only suffered at simulation setup.
   159   if ((codingRate == WIFI_CODE_RATE_UNDEFINED) != (modClass == WIFI_MOD_CLASS_DSSS))
   163   if ((codingRate == WIFI_CODE_RATE_UNDEFINED) != (modClass == WIFI_MOD_CLASS_DSSS))
   160     {
   164     {
   161       NS_FATAL_ERROR ("Error in creation of WifiMode named " << uniqueName << std::endl
   165       NS_FATAL_ERROR ("Error in creation of WifiMode named " << uniqueName << std::endl
   162                       << "Code rate must be WIFI_CODE_RATE_UNDEFINED iff Modulation Class is WIFI_MOD_CLASS_DSSS");
   166                                                              << "Code rate must be WIFI_CODE_RATE_UNDEFINED iff Modulation Class is WIFI_MOD_CLASS_DSSS");
   163     }
   167     }
   164 
   168 
   165   item->constellationSize = constellationSize;
   169   item->constellationSize = constellationSize;
   166   item->isMandatory = isMandatory;
   170   item->isMandatory = isMandatory;
   167 
   171 
   174   WifiModeItemList::const_iterator i;
   178   WifiModeItemList::const_iterator i;
   175   uint32_t j = 0;
   179   uint32_t j = 0;
   176   for (i = m_itemList.begin (); i != m_itemList.end (); i++)
   180   for (i = m_itemList.begin (); i != m_itemList.end (); i++)
   177     {
   181     {
   178       if (i->uniqueUid == name)
   182       if (i->uniqueUid == name)
   179 	{
   183         {
   180           return WifiMode (j);
   184           return WifiMode (j);
   181 	}
   185         }
   182       j++;
   186       j++;
   183     }
   187     }
   184 
   188 
   185   // If we get here then a matching WifiMode was not found above. This
   189   // If we get here then a matching WifiMode was not found above. This
   186   // is a fatal problem, but we try to be helpful by displaying the
   190   // is a fatal problem, but we try to be helpful by displaying the
   209   uint32_t j = 0;
   213   uint32_t j = 0;
   210   for (WifiModeItemList::const_iterator i = m_itemList.begin ();
   214   for (WifiModeItemList::const_iterator i = m_itemList.begin ();
   211        i != m_itemList.end (); i++)
   215        i != m_itemList.end (); i++)
   212     {
   216     {
   213       if (i->uniqueUid == uniqueUid)
   217       if (i->uniqueUid == uniqueUid)
   214 	{
   218         {
   215 	  return j;
   219           return j;
   216 	}
   220         }
   217       j++;
   221       j++;
   218     }
   222     }
   219   uint32_t uid = m_itemList.size ();
   223   uint32_t uid = m_itemList.size ();
   220   m_itemList.push_back (WifiModeItem ());
   224   m_itemList.push_back (WifiModeItem ());
   221   return uid;
   225   return uid;