Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> | 18 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 * Sébastien Deronne <sebastien.deronne@gmail.com> | 19 * Sébastien Deronne <sebastien.deronne@gmail.com> |
20 */ | 20 */ |
21 | 21 |
22 #include <cmath> | |
23 #include "ns3/log.h" | |
22 #include "wifi-mode.h" | 24 #include "wifi-mode.h" |
23 #include "wifi-tx-vector.h" | 25 #include "wifi-tx-vector.h" |
24 #include "ns3/log.h" | |
25 #include <cmath> | |
26 | 26 |
27 namespace ns3 { | 27 namespace ns3 { |
28 | 28 |
29 /** | 29 /** |
30 * Check if the two WifiModes are identical. | 30 * Check if the two WifiModes are identical. |
31 * | 31 * |
32 * \param a WifiMode | 32 * \param a WifiMode |
33 * \param b WifiMode | 33 * \param b WifiMode |
34 * | 34 * |
35 * \return true if the two WifiModes are identical, | 35 * \return true if the two WifiModes are identical, |
36 * false otherwise | 36 * false otherwise |
37 */ | 37 */ |
38 bool operator == (const WifiMode &a, const WifiMode &b) | 38 bool operator == (const WifiMode &a, const WifiMode &b) |
39 { | 39 { |
40 return a.GetUid () == b.GetUid (); | 40 return a.GetUid () == b.GetUid (); |
41 } | 41 } |
42 /** | 42 /** |
43 * Compare two WifiModes | |
44 * | |
45 * \param a WifiMode | |
46 * \param b WifiMode | |
47 * | |
48 * \return true if a is less than b, | |
49 * false otherwise | |
50 */ | |
51 bool operator < (const WifiMode &a, const WifiMode &b) | |
52 { | |
53 return a.GetUid () < b.GetUid (); | |
54 } | |
55 /** | |
43 * Serialize WifiMode to ostream (human-readable). | 56 * Serialize WifiMode to ostream (human-readable). |
44 * | 57 * |
45 * \param os std::ostream | 58 * \param os std::ostream |
46 * \param mode | 59 * \param mode |
47 * | 60 * |
48 * \return std::ostream | 61 * \return std::ostream |
49 */ | 62 */ |
50 std::ostream & operator << (std::ostream & os, const WifiMode &mode) | 63 std::ostream & operator << (std::ostream & os, const WifiMode &mode) |
51 { | 64 { |
52 os << mode.GetUniqueName (); | 65 os << mode.GetUniqueName (); |
53 return os; | 66 return os; |
54 } | 67 } |
55 /** | 68 /** |
56 * Serialize WifiMode from istream (human-readable). | 69 * Serialize WifiMode from istream (human-readable). |
57 * | 70 * |
58 * \param is std::istream | 71 * \param is std::istream |
59 * \param mode | 72 * \param mode |
60 * | 73 * |
61 * \return std::istream | 74 * \return std::istream |
62 */ | 75 */ |
63 std::istream & operator >> (std::istream &is, WifiMode &mode) | 76 std::istream & operator >> (std::istream &is, WifiMode &mode) |
64 { | 77 { |
65 std::string str; | 78 std::string str; |
66 is >> str; | 79 is >> str; |
67 mode = WifiModeFactory::GetFactory ()->Search (str); | 80 mode = WifiModeFactory::GetFactory ()->Search (str); |
68 return is; | 81 return is; |
69 } | 82 } |
70 | 83 |
71 bool | 84 bool |
72 WifiMode::IsAllowed (uint8_t channelWidth, uint8_t nss) const | 85 WifiMode::IsAllowed (uint16_t channelWidth, uint8_t nss) const |
73 { | 86 { |
74 WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_u id); | 87 WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_u id); |
75 if (item->modClass == WIFI_MOD_CLASS_VHT) | 88 if (item->modClass == WIFI_MOD_CLASS_VHT) |
76 { | 89 { |
77 if (item->mcsValue == 9 && channelWidth == 20 && nss != 3) | 90 if (item->mcsValue == 9 && channelWidth == 20 && nss != 3) |
78 { | 91 { |
79 return false; | 92 return false; |
80 } | 93 } |
81 if (item->mcsValue == 6 && channelWidth == 80 && nss == 3) | 94 if (item->mcsValue == 6 && channelWidth == 80 && nss == 3) |
82 { | 95 { |
83 return false; | 96 return false; |
84 } | 97 } |
85 } | 98 } |
86 else | 99 else |
87 { | 100 { |
88 //We should not go here! | 101 //We should not go here! |
89 NS_ASSERT (false); | 102 NS_ASSERT (false); |
90 return false; | 103 return false; |
91 } | 104 } |
92 return true; | 105 return true; |
93 } | 106 } |
94 | 107 |
95 uint64_t | 108 uint64_t |
96 WifiMode::GetPhyRate (uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const | 109 WifiMode::GetPhyRate (uint16_t channelWidth, uint16_t guardInterval, uint8_t nss ) const |
97 { | 110 { |
98 //TODO: nss > 4 not supported yet | 111 //TODO: nss > 4 not supported yet |
99 NS_ASSERT (nss <= 4); | 112 NS_ASSERT (nss <= 4); |
100 uint64_t dataRate, phyRate; | 113 uint64_t dataRate, phyRate; |
101 dataRate = GetDataRate (channelWidth, guardInterval, nss); | 114 dataRate = GetDataRate (channelWidth, guardInterval, nss); |
102 switch (GetCodeRate ()) | 115 switch (GetCodeRate ()) |
103 { | 116 { |
104 case WIFI_CODE_RATE_5_6: | 117 case WIFI_CODE_RATE_5_6: |
105 phyRate = dataRate * 6 / 5; | 118 phyRate = dataRate * 6 / 5; |
106 break; | 119 break; |
(...skipping 14 matching lines...) Expand all Loading... | |
121 return phyRate; | 134 return phyRate; |
122 } | 135 } |
123 | 136 |
124 uint64_t | 137 uint64_t |
125 WifiMode::GetPhyRate (WifiTxVector txVector) const | 138 WifiMode::GetPhyRate (WifiTxVector txVector) const |
126 { | 139 { |
127 return GetPhyRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), txVector.GetNss ()); | 140 return GetPhyRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), txVector.GetNss ()); |
128 } | 141 } |
129 | 142 |
130 uint64_t | 143 uint64_t |
131 WifiMode::GetDataRate (uint8_t channelWidth) const | 144 WifiMode::GetDataRate (uint16_t channelWidth) const |
132 { | 145 { |
133 return GetDataRate (channelWidth, 800, 1); | 146 return GetDataRate (channelWidth, 800, 1); |
134 } | 147 } |
135 | 148 |
136 uint64_t | 149 uint64_t |
137 WifiMode::GetDataRate (WifiTxVector txVector) const | 150 WifiMode::GetDataRate (WifiTxVector txVector) const |
138 { | 151 { |
139 return GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), txVector.GetNss ()); | 152 return GetDataRate (txVector.GetChannelWidth (), txVector.GetGuardInterval (), txVector.GetNss ()); |
140 } | 153 } |
141 | 154 |
142 uint64_t | 155 uint64_t |
143 WifiMode::GetDataRate (uint8_t channelWidth, uint16_t guardInterval, uint8_t nss ) const | 156 WifiMode::GetDataRate (uint16_t channelWidth, uint16_t guardInterval, uint8_t ns s) const |
144 { | 157 { |
145 //TODO: nss > 4 not supported yet | 158 //TODO: nss > 4 not supported yet |
146 NS_ASSERT (nss <= 4); | 159 NS_ASSERT (nss <= 4); |
147 WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_u id); | 160 WifiModeFactory::WifiModeItem *item = WifiModeFactory::GetFactory ()->Get (m_u id); |
148 uint64_t dataRate = 0; | 161 uint64_t dataRate = 0; |
149 uint16_t usableSubCarriers = 0; | 162 uint16_t usableSubCarriers = 0; |
150 double symbolRate = 0; | 163 double symbolRate = 0; |
151 double codingRate = 0; | 164 double codingRate = 0; |
152 uint32_t numberOfBitsPerSubcarrier = static_cast<uint32_t> (log2 (GetConstella tionSize ())); | 165 uint32_t numberOfBitsPerSubcarrier = static_cast<uint32_t> (log2 (GetConstella tionSize ())); |
S. Deronne
2018/03/30 06:56:54
change type of numberOfBitsPerSubcarrier?
ammo6818-vandals.uidaho.edu
2018/04/05 17:51:01
no, i believe changing it to double may change the
S. Deronne
2018/04/05 19:46:50
no, not if you correct round up (or down) as would
|
S. Deronne
2018/05/11 14:46:05
an alternative is to declare it double, but it phy
|
153 if (item->modClass == WIFI_MOD_CLASS_DSSS) | 166 if (item->modClass == WIFI_MOD_CLASS_DSSS) |
154 { | 167 { |
155 dataRate = ((11000000 / 11) * numberOfBitsPerSubcarrier); | 168 dataRate = ((11000000 / 11) * numberOfBitsPerSubcarrier); |
156 } | 169 } |
157 else if (item->modClass == WIFI_MOD_CLASS_HR_DSSS) | 170 else if (item->modClass == WIFI_MOD_CLASS_HR_DSSS) |
158 { | 171 { |
159 dataRate = ((11000000 / 8) * numberOfBitsPerSubcarrier); | 172 dataRate = ((11000000 / 8) * numberOfBitsPerSubcarrier); |
160 } | 173 } |
161 else if (item->modClass == WIFI_MOD_CLASS_OFDM || item->modClass == WIFI_MOD_C LASS_ERP_OFDM) | 174 else if (item->modClass == WIFI_MOD_CLASS_OFDM || item->modClass == WIFI_MOD_C LASS_ERP_OFDM) |
162 { | 175 { |
(...skipping 28 matching lines...) Expand all Loading... | |
191 NS_FATAL_ERROR ("trying to get datarate for a mcs without any coding r ate defined"); | 204 NS_FATAL_ERROR ("trying to get datarate for a mcs without any coding r ate defined"); |
192 break; | 205 break; |
193 } | 206 } |
194 | 207 |
195 dataRate = lrint (ceil (symbolRate * usableSubCarriers * numberOfBitsPerSu bcarrier * codingRate)); | 208 dataRate = lrint (ceil (symbolRate * usableSubCarriers * numberOfBitsPerSu bcarrier * codingRate)); |
196 } | 209 } |
197 else if (item->modClass == WIFI_MOD_CLASS_HT || item->modClass == WIFI_MOD_CLA SS_VHT) | 210 else if (item->modClass == WIFI_MOD_CLASS_HT || item->modClass == WIFI_MOD_CLA SS_VHT) |
198 { | 211 { |
199 if (item->modClass == WIFI_MOD_CLASS_VHT) | 212 if (item->modClass == WIFI_MOD_CLASS_VHT) |
200 { | 213 { |
201 NS_ASSERT_MSG (IsAllowed (channelWidth, nss), "VHT MCS " << +item->mcs Value << " forbidden at " << +channelWidth << " MHz when NSS is " << +nss); | 214 NS_ASSERT_MSG (IsAllowed (channelWidth, nss), "VHT MCS " << +item->mcs Value << " forbidden at " << channelWidth << " MHz when NSS is " << +nss); |
202 } | 215 } |
203 | 216 |
204 NS_ASSERT (guardInterval == 800 || guardInterval == 400); | 217 NS_ASSERT (guardInterval == 800 || guardInterval == 400); |
205 symbolRate = (1 / (3.2 + (static_cast<double> (guardInterval) / 1000))) * 1e6; | 218 symbolRate = (1 / (3.2 + (static_cast<double> (guardInterval) / 1000))) * 1e6; |
206 | 219 |
207 if (item->modClass == WIFI_MOD_CLASS_HT) | 220 if (item->modClass == WIFI_MOD_CLASS_HT) |
208 { | 221 { |
209 switch (channelWidth) | 222 switch (channelWidth) |
210 { | 223 { |
211 case 20: | 224 case 20: |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 uint32_t j = 0; | 792 uint32_t j = 0; |
780 for (WifiModeItemList::const_iterator i = m_itemList.begin (); | 793 for (WifiModeItemList::const_iterator i = m_itemList.begin (); |
781 i != m_itemList.end (); i++) | 794 i != m_itemList.end (); i++) |
782 { | 795 { |
783 if (i->uniqueUid == uniqueUid) | 796 if (i->uniqueUid == uniqueUid) |
784 { | 797 { |
785 return j; | 798 return j; |
786 } | 799 } |
787 j++; | 800 j++; |
788 } | 801 } |
789 uint32_t uid = static_cast<uint32_t> (m_itemList.size ()); | 802 uint32_t uid = static_cast<uint32_t> (m_itemList.size ()); |
S. Deronne
2018/03/30 06:56:54
change type of uid to size_t?
ammo6818-vandals.uidaho.edu
2018/04/05 17:51:01
No, create other static cast so there is no differ
| |
790 m_itemList.push_back (WifiModeItem ()); | 803 m_itemList.push_back (WifiModeItem ()); |
791 return uid; | 804 return uid; |
792 } | 805 } |
793 | 806 |
794 WifiModeFactory::WifiModeItem * | 807 WifiModeFactory::WifiModeItem * |
795 WifiModeFactory::Get (uint32_t uid) | 808 WifiModeFactory::Get (uint32_t uid) |
796 { | 809 { |
797 NS_ASSERT (uid < m_itemList.size ()); | 810 NS_ASSERT (uid < m_itemList.size ()); |
798 return &m_itemList[uid]; | 811 return &m_itemList[uid]; |
799 } | 812 } |
(...skipping 12 matching lines...) Expand all Loading... | |
812 item->constellationSize = 0; | 825 item->constellationSize = 0; |
813 item->codingRate = WIFI_CODE_RATE_UNDEFINED; | 826 item->codingRate = WIFI_CODE_RATE_UNDEFINED; |
814 item->isMandatory = false; | 827 item->isMandatory = false; |
815 item->mcsValue = 0; | 828 item->mcsValue = 0; |
816 isFirstTime = false; | 829 isFirstTime = false; |
817 } | 830 } |
818 return &factory; | 831 return &factory; |
819 } | 832 } |
820 | 833 |
821 } //namespace ns3 | 834 } //namespace ns3 |
LEFT | RIGHT |