1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * This program is free software; you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License version 2 as 5 * published by the Free Software Foundation; 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 * 16 * Author: Junling Bu <linlinjavaer@gmail.com> 17 */ 18 19 #ifndef WAVE_HELPER_H 20 #define WAVE_HELPER_H 21 22 #include <string> 23 #include "ns3/attribute.h" 24 #include "ns3/object-factory.h" 25 #include "ns3/node-container.h" 26 #include "ns3/net-device-container.h" 27 #include "ns3/trace-helper.h" 28 #include "ns3/yans-wifi-helper.h" 29 30 namespace ns3 { 31 32 class WaveNetDevice; 33 class Node; 34 35 /** 36 * \ingroup wave 37 * To trace WaveNetDevice, we have to overwrite the trace functions of class YansWifiPhyHelper. 38 * The source code is very similar with YansWifiPhy, only with some adaptation. 39 */ 40 class YansWavePhyHelper : public YansWifiPhyHelper 41 { 42 public: 43 /** 44 * Create a phy helper in a default working state. 45 * \return A phy helper 46 */ 47 static YansWavePhyHelper Default (void); 48 49 private: 50 /** 51 * @brief Enable pcap output the indicated net device. 52 * 53 * NetDevice-specific implementation mechanism for hooking the trace and 54 * writing to the trace file. 55 * 56 * @param prefix Filename prefix to use for pcap files. 57 * @param nd Net device for which you want to enable tracing. 58 * @param promiscuous If true capture all possible packets available at the device. 59 * @param explicitFilename Treat the prefix as an explicit filename if true 60 */ 61 virtual void EnablePcapInternal (std::string prefix, 62 Ptr<NetDevice> nd, 63 bool promiscuous, 64 bool explicitFilename); 65 66 /** 67 * \brief Enable ascii trace output on the indicated net device. 68 * \internal 69 * 70 * NetDevice-specific implementation mechanism for hooking the trace and 71 * writing to the trace file. 72 * 73 * \param stream The output stream object to use when logging ascii traces. 74 * \param prefix Filename prefix to use for ascii trace files. 75 * \param nd Net device for which you want to enable tracing. 76 * \param explicitFilename Treat the prefix as an explicit filename if true 77 */ 78 virtual void EnableAsciiInternal (Ptr<OutputStreamWrapper> stream, 79 std::string prefix, 80 Ptr<NetDevice> nd, 81 bool explicitFilename); 82 }; 83 84 /** 85 * \ingroup wave 86 * \brief helps to create WaveNetDevice objects 87 * 88 * This class can help to create a large set of similar 89 * WaveNetDevice objects and to configure a large set of 90 * their attributes during creation. 91 * 92 * Generally WaveHelper with default configuration will 93 * create devices with 7 MAC entities,1 PHY entity and a 94 * multiple-channel scheduler for to deal with these entities. 95 * 96 * If users can make sure on which channel this WAVE device 97 * will work, they can set specific channel numbers to save 98 * resources of unused channels as below: 99 * WaveHelper helper = WaveHelper::Default (); 100 * uint32_t channels[] = {CCH, SCH1}; 101 * std::vector<uint32_t> channelsVector (channels, channels + 2); 102 * helper.helper.CreateMacForChannel (channelsVector); 103 * 104 * If users can create other channel scheduler such as "AnotherScheduler" 105 * which can assign channel access in the context of more PHY entities, 106 * they can use this helper to create WAVE devices as below: 107 * WaveHelper helper = WaveHelper::Default (); 108 * helper.helper.CreateMacForChannel (ChannelManager::GetWaveChannels ()); 109 * helper.CreatePhys (2); // or other number which should be less than 7 110 * helper.SetChannelScheduler ("ns3::AnotherScheduler"); 111 * helper.SetRemoteStationManager ("ns3::ConstantRateWifiManager"); // or other rate control algorithms 112 */ 113 class WaveHelper 114 { 115 public: 116 WaveHelper (); 117 virtual ~WaveHelper (); 118 119 /** 120 * \returns a new WaveHelper in a default state 121 * 122 * The default state is defined as being seven OcbWifiMac MAC entities 123 * with an ConstantRate rate control algorithm, one WifiPhy entity and 124 * a default multiple-channel scheduler DefaultChannelScheduler for 125 * assigning channel access with these created entities. 126 */ 127 static WaveHelper Default (void); 128 129 /** 130 * \param channelNumbers the MAC entities will be created to support these channels for multiple channel operation. 131 */ 132 void CreateMacForChannel (std::vector<uint32_t> channelNumbers); 133 /** 134 * \param phys the number of PHY entity which will be created for multiple channel operation. 135 */ 136 void CreatePhys (uint32_t phys); 137 138 /** 139 * \param type the type of ns3::WifiRemoteStationManager to create. 140 * \param n0 the name of the attribute to set 141 * \param v0 the value of the attribute to set 142 * \param n1 the name of the attribute to set 143 * \param v1 the value of the attribute to set 144 * \param n2 the name of the attribute to set 145 * \param v2 the value of the attribute to set 146 * \param n3 the name of the attribute to set 147 * \param v3 the value of the attribute to set 148 * \param n4 the name of the attribute to set 149 * \param v4 the value of the attribute to set 150 * \param n5 the name of the attribute to set 151 * \param v5 the value of the attribute to set 152 * \param n6 the name of the attribute to set 153 * \param v6 the value of the attribute to set 154 * \param n7 the name of the attribute to set 155 * \param v7 the value of the attribute to set 156 * 157 * All the attributes specified in this method should exist 158 * in the requested station manager. 159 */ 160 void SetRemoteStationManager (std::string type, 161 std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), 162 std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), 163 std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), 164 std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), 165 std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), 166 std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), 167 std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), 168 std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); 169 /** 170 * \param type the type of ns3::ChannelScheduler to create. 171 * \param n0 the name of the attribute to set 172 * \param v0 the value of the attribute to set 173 * \param n1 the name of the attribute to set 174 * \param v1 the value of the attribute to set 175 * \param n2 the name of the attribute to set 176 * \param v2 the value of the attribute to set 177 * \param n3 the name of the attribute to set 178 * \param v3 the value of the attribute to set 179 * \param n4 the name of the attribute to set 180 * \param v4 the value of the attribute to set 181 * \param n5 the name of the attribute to set 182 * \param v5 the value of the attribute to set 183 * \param n6 the name of the attribute to set 184 * \param v6 the value of the attribute to set 185 * \param n7 the name of the attribute to set 186 * \param v7 the value of the attribute to set 187 * 188 * All the attributes specified in this method should exist 189 * in the requested channel scheduler. 190 */ 191 void SetChannelScheduler (std::string type, 192 std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), 193 std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), 194 std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), 195 std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), 196 std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), 197 std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), 198 std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), 199 std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); 200 201 /** 202 * \param phy the PHY helper to create PHY objects 203 * \param mac the MAC helper to create MAC objects 204 * \param c the set of nodes on which a wifi device must be created 205 * \returns a device container which contains all the devices created by this method. 206 */ 207 virtual NetDeviceContainer Install (const WifiPhyHelper &phy, 208 const WifiMacHelper &mac, NodeContainer c) const; 209 /** 210 * \param phy the PHY helper to create PHY objects 211 * \param mac the MAC helper to create MAC objects 212 * \param node the node on which a wifi device must be created 213 * \returns a device container which contains all the devices created by this method. 214 */ 215 virtual NetDeviceContainer Install (const WifiPhyHelper &phy, 216 const WifiMacHelper &mac, Ptr<Node> node) const; 217 /** 218 * \param phy the PHY helper to create PHY objects 219 * \param mac the MAC helper to create MAC objects 220 * \param nodeName the name of node on which a wifi device must be created 221 * \returns a device container which contains all the devices created by this method. 222 */ 223 virtual NetDeviceContainer Install (const WifiPhyHelper &phy, 224 const WifiMacHelper &mac, std::string nodeName) const; 225 226 /** 227 * Helper to enable all WaveNetDevice log components with one statement 228 */ 229 static void EnableLogComponents (void); 230 231 /** 232 * Assign a fixed random variable stream number to the random variables 233 * used by the Phy and Mac aspects of the WAVE models. Each device in 234 * container c has fixed stream numbers assigned to its random variables. 235 * The Wifi channel (e.g. propagation loss model) is excluded. 236 * Return the number of streams (possibly zero) that 237 * have been assigned. The Install() method should have previously been 238 * called by the user. 239 * 240 * \param c NetDeviceContainer of the set of net devices for which the 241 * WaveNetDevice should be modified to use fixed streams 242 * \param stream first stream index to use 243 * \return the number of stream indices assigned by this helper 244 */ 245 int64_t AssignStreams (NetDeviceContainer c, int64_t stream); 246 247 protected: 248 ObjectFactory m_stationManager; ///< station manager 249 ObjectFactory m_channelScheduler; ///< channel scheduler 250 std::vector<uint32_t> m_macsForChannelNumber; ///< MACs for channel number 251 uint32_t m_physNumber; ///< Phy number 252 }; 253 } 254 #endif /* WAVE_HELPER_H */ 255