OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2005,2006 INRIA |
| 4 * Copyright (c) 2013 Dalian University of Technology |
| 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 |
| 7 * published by the Free Software Foundation; |
| 8 * |
| 9 * This program is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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 |
| 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 * |
| 18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
| 19 * Junling Bu <linlinjavaer@gmail.com> |
| 20 */ |
| 21 #ifndef WAVE_NET_DEVICE_H |
| 22 #define WAVE_NET_DEVICE_H |
| 23 |
| 24 #include "ns3/net-device.h" |
| 25 #include "ns3/packet.h" |
| 26 #include "ns3/traced-callback.h" |
| 27 #include "ns3/mac48-address.h" |
| 28 |
| 29 #include "channel-manager.h" |
| 30 #include "channel-scheduler.h" |
| 31 #include "channel-coordinator.h" |
| 32 #include "vsa-repeater.h" |
| 33 #include "vendor-specific-action.h" |
| 34 namespace ns3 { |
| 35 |
| 36 class WifiRemoteStationManager; |
| 37 class WifiChannel; |
| 38 class WifiPhy; |
| 39 class WifiMac; |
| 40 class ChannelScheduler; |
| 41 |
| 42 /** |
| 43 * indicate which interval the VSA frames will be transmitted in. |
| 44 * CchInterval will only allow in CCH Interval; |
| 45 * SchInterval will only allow in SCH Interval; |
| 46 * BothInterval will allow anytime. |
| 47 */ |
| 48 enum ChannelInterval |
| 49 { |
| 50 CchInterval, |
| 51 SchInerval, |
| 52 BothInterval, |
| 53 }; |
| 54 /** |
| 55 * \param peer The address of the peer MAC entity to which the |
| 56 * VSA is sent. |
| 57 * \param oi Identifies the source of the data when the source |
| 58 * is not an IEEE 1609 entity. See IEEE Std 802.11p. |
| 59 * \param managementId Identifies the source of the data when the source |
| 60 * is an IEEE 1609 entity. Values are specified in IEEE P1609.0. |
| 61 * Valid range: 0-15 |
| 62 * \param vsc pointer to Information that will be sent as vendor specific conten
t. |
| 63 * \param vscLength the length of vendor specific content |
| 64 * \param channelNumber The channel on which the transmissions are to occur |
| 65 * While section 7.2 of the standard specifies that channel identification |
| 66 * comprises Country String, Operating Class, and Channel Number, channel |
| 67 * number is all that is needed for simulation. |
| 68 * \param repeatRate The number of Vendor Specific Action frames to |
| 69 * be transmitted per 5 s. A value of 0 indicates a single message is to be sent
. |
| 70 * If Destination MAC Address is an individual address, Repeat Rate is ignored. |
| 71 * \param channelInterval The channel interval in which the transmissions |
| 72 * are to occur. |
| 73 */ |
| 74 struct VsaInfo |
| 75 { |
| 76 Mac48Address peer; |
| 77 OrganizationIdentifier oi; |
| 78 uint8_t management_id; |
| 79 uint8_t *vsc; |
| 80 uint32_t vscLength; |
| 81 uint32_t channelNumber; |
| 82 uint8_t repeatRate; |
| 83 enum ChannelInterval channelInterval; |
| 84 }; |
| 85 /** |
| 86 * \param channelNumber channel number that the SCH service |
| 87 * can be made available for communications. |
| 88 * \param operationalRateSet OperationalRateSet if present, as specified in IEEE
Std 802.11. |
| 89 * valid range: 1-127 |
| 90 * \param immediateAccess Indicates that the MLME should provide immediate |
| 91 * access to the SCH and not wait until the next SCH interval. |
| 92 * \param extendedAccess Indicates that the MLME should provide continuous |
| 93 * access (during both SCH interval and CCH interval) to the SCH for ExtendedAcc
ess |
| 94 * control channel intervals. A value of 255 indicates indefinite access. |
| 95 * \param edcaParameterSet If present, as specified in IEEE Std 802.11. |
| 96 * |
| 97 * note: operationalRateSet and edcaParameterSet are not implemented. |
| 98 */ |
| 99 struct SchInfo |
| 100 { |
| 101 uint32_t channelNumber; |
| 102 //OperationalRateSet operationalRateSet; |
| 103 bool immediateAccess; |
| 104 uint8_t extendedAccess; |
| 105 //EDCA_Parameter_Set edcaParameterSet; |
| 106 SchInfo () |
| 107 : channelNumber (CCH), |
| 108 immediateAccess (false), |
| 109 extendedAccess (0xff) |
| 110 { |
| 111 |
| 112 } |
| 113 SchInfo (uint32_t c, bool i, uint32_t e) |
| 114 : channelNumber (c), |
| 115 immediateAccess (i), |
| 116 extendedAccess (e) |
| 117 { |
| 118 |
| 119 } |
| 120 }; |
| 121 /** |
| 122 * \param channelNumber the specific channel |
| 123 * \param priority the priority of packet with range 0-7 |
| 124 * \param dataRate the transmit data rate of packet |
| 125 * \param txPowerLevel the transmit power level |
| 126 * \param expireTime indicate how many milliseconds the packet |
| 127 * can stay before sent |
| 128 * |
| 129 * normally these parameters are used by high layer to control |
| 130 * the transmission characteristics of WSMP data. |
| 131 */ |
| 132 struct TxInfo |
| 133 { |
| 134 uint32_t channelNumber; |
| 135 uint32_t priority; |
| 136 uint32_t dataRate; |
| 137 uint32_t txPowerLevel; |
| 138 uint32_t expiryTime; |
| 139 TxInfo () |
| 140 : channelNumber (CCH), |
| 141 priority (0), |
| 142 dataRate (0), |
| 143 txPowerLevel (0), |
| 144 expiryTime (0) |
| 145 { |
| 146 |
| 147 } |
| 148 TxInfo (uint32_t c, uint32_t p, uint32_t d, uint32_t t, uint32_t e) |
| 149 : channelNumber (c), |
| 150 priority (p), |
| 151 dataRate (d), |
| 152 txPowerLevel (t), |
| 153 expiryTime (e) |
| 154 { |
| 155 |
| 156 } |
| 157 }; |
| 158 /** |
| 159 * \param channelNumber the channel number for the SCH. |
| 160 * \param adaptable if true, the actual power level and data |
| 161 * rate for transmission are adaptable. TxPwr_Level is the maximum |
| 162 * transmit power that sets the upper bound for the actual transmit |
| 163 * power; DataRate is the minimum data rate that sets the lower |
| 164 * bound for the actual data rate. If false, the actual power level |
| 165 * and data rate for transmission are nonadaptable. TxPwr_Level and |
| 166 * DataRate are the actual values to be used for transmission. |
| 167 * \param dataRate |
| 168 * |
| 169 * note: txPowerLevel and dataRate are not supported yet, |
| 170 * I find the new 802.11n patch provides WifiTxVector that is perfect. |
| 171 * We will use that class to control datarate and txpower |
| 172 */ |
| 173 struct TxProfile |
| 174 { |
| 175 uint32_t channelNumber; |
| 176 bool adaptable; |
| 177 uint32_t txPowerLevel; |
| 178 uint32_t dataRate; |
| 179 TxProfile (void) |
| 180 : channelNumber (SCH1), |
| 181 adaptable (false), |
| 182 txPowerLevel (0), |
| 183 dataRate (0) |
| 184 { |
| 185 |
| 186 } |
| 187 TxProfile (uint32_t c, bool a, uint32_t t, uint32_t d) |
| 188 : channelNumber (c), |
| 189 adaptable (a), |
| 190 txPowerLevel (t), |
| 191 dataRate (d) |
| 192 { |
| 193 |
| 194 } |
| 195 }; |
| 196 /** |
| 197 * This class holds together ns3::WifiChannel, ns3::WifiPhy, |
| 198 * ns3::WifiMac, and ns3::WifiRemoteStationManager. |
| 199 * Besides that, to support multiple channel operation this |
| 200 * class also holds ns3::ChannelScheduler, ns3::ChannelManager, |
| 201 * ns3::Coordinator and ns3::VsaRepeater. |
| 202 * |
| 203 * these methods are not implemented because of limited use in simulation |
| 204 * void StartTimingAdvertisement (); |
| 205 * void StopTimingAdvertisement (); |
| 206 * UtcTime GetUtcTime (); |
| 207 * void SetUtcTime (); |
| 208 * void CancelTx (uint32_t channelNumber, AcIndex ac); |
| 209 */ |
| 210 class WaveNetDevice : public NetDevice |
| 211 { |
| 212 public: |
| 213 static TypeId GetTypeId (void); |
| 214 |
| 215 WaveNetDevice (); |
| 216 virtual ~WaveNetDevice (); |
| 217 |
| 218 /** |
| 219 * \param mac. |
| 220 */ |
| 221 void AddMac (Ptr<WifiMac> mac); |
| 222 /** |
| 223 * \param phy the phy layer to use. |
| 224 */ |
| 225 void SetPhy (Ptr<WifiPhy> phy); |
| 226 /** |
| 227 * \param manager the manager to use. |
| 228 * |
| 229 * Note: If high layer sets data rate for packets or register in |
| 230 * profile or channel table, the date rate selected from manager |
| 231 * will not used. And we suggest users should control data rate |
| 232 * all the time or just let manager select, mixed with these two |
| 233 * ways maybe will get trouble. |
| 234 */ |
| 235 void SetRemoteStationManager (Ptr<WifiRemoteStationManager> manager); |
| 236 /** |
| 237 * \returns the macs we are currently using. |
| 238 */ |
| 239 std::vector< Ptr<WifiMac> > GetMacs (void) const; |
| 240 /** |
| 241 * \returns the phy we are currently using. |
| 242 */ |
| 243 Ptr<WifiPhy> GetPhy (void) const; |
| 244 /** |
| 245 * \returns the remote station manager we are currently using. |
| 246 */ |
| 247 Ptr<WifiRemoteStationManager> GetRemoteStationManager (void) const; |
| 248 |
| 249 /** |
| 250 * \param vsa_info the parameters about how to send VSA frame |
| 251 * |
| 252 * before this method is called, channel access should be assigned. |
| 253 * note: although this method supports sending management information |
| 254 * that not indicates IEEE 1609 by setting OrganizationIdentifier |
| 255 * instead of management id, the 1609.4 standard declares that if |
| 256 * OrganizationIdentifier not indicates IEEE 1609, the management |
| 257 * frames will be not delivered to the IEEE 1609.4 MLME. |
| 258 * In a word, you can send other management frames, but cannot receive. |
| 259 */ |
| 260 bool StartVsa (VsaInfo & vsaInfo); |
| 261 /** |
| 262 * \param channelNumber the channel on which VSA frames send event |
| 263 * will be canceled. |
| 264 * Unimplemented now |
| 265 */ |
| 266 void StopVsa (uint32_t channelNumber); |
| 267 /** |
| 268 * \param packet the packet is Vendor Specific Action frame. |
| 269 * \param address the address of the MAC from which the management frame |
| 270 * was received. |
| 271 * \param managementID idenfify the originator of the data. |
| 272 * Values are specified in IEEE P1609.0 with range 0-15. |
| 273 * \param channelNumber the channel on which the frame was received. |
| 274 * \returns true if the callback could handle the packet successfully, false |
| 275 * otherwise. |
| 276 */ |
| 277 typedef Callback<bool, Ptr<const Packet>,const Address &, uint32_t, uint32_t>
VsaCallback; |
| 278 |
| 279 void SetVsaReceiveCallback (VsaCallback vsaCallback); |
| 280 /** |
| 281 * \param sch_info the parameters about how to start SCH service |
| 282 * |
| 283 * This method is used to assign channel access for sending packets. |
| 284 */ |
| 285 bool StartSch (const SchInfo & schInfo); |
| 286 /** |
| 287 * \param channelNumber the channel which access resource will be released. |
| 288 */ |
| 289 void StopSch (uint32_t channelNumber); |
| 290 /** |
| 291 * \param txprofile transmit profile for IP-based data |
| 292 * register a transmitter profile in the MLME before |
| 293 * the associated IP-based data transfer starts. |
| 294 * So normally this method should be called before Send |
| 295 * method is called. |
| 296 * And txprofile can only be registered once unless |
| 297 * users unregister. |
| 298 */ |
| 299 bool RegisterTxProfile (const TxProfile &txprofile); |
| 300 /** |
| 301 * \param channelNumber the specific channel number |
| 302 * delete a registered transmitter profile in the MLME |
| 303 * after the associated IP-based data transfer is complete |
| 304 */ |
| 305 void UnregisterTxProfile (uint32_t channelNumber); |
| 306 |
| 307 /** |
| 308 * \param packet packet sent from above down to Network Device |
| 309 * \param dest mac address of the destination (already resolved) |
| 310 * \param protocol identifies the type of payload contained in the packet. |
| 311 * Used to call the right L3Protocol when the packet is received. |
| 312 * note: although this method is mainly used for WSMP packets, users |
| 313 * can send any packets they like even this protocol is IP-based. |
| 314 * \param txInfo WSMP or other packets parameters for sending |
| 315 * \return whether the SendX operation succeeded |
| 316 * |
| 317 * SendX method implements MA-UNITDATAX.request primitive. |
| 318 * comparing to WaveNetDevice::Send, here is two differences |
| 319 * 1) WaveNetDevice::Send cannot control phy parameters for generality, |
| 320 * but WaveNetDevice::SendX can allow user control packets on a per-message b
asis; |
| 321 * 2) If users want to use priority in WifiNetDevice, they should insert |
| 322 * a QosTag into Packet before Send method, however with SendX method, |
| 323 * users should set the priority in TxInfo. |
| 324 * Normally this method is called by high 1609.3 standard to send WSMP packets
. |
| 325 */ |
| 326 bool SendX (Ptr<Packet> packet, const Address& dest, uint32_t protocol, const
TxInfo & txInfo); |
| 327 /** |
| 328 * \param newAddress |
| 329 * an immediate MAC-layer address change is required |
| 330 * (e.g., to support device pseudonymity) |
| 331 * note: this function is useful in real environment, |
| 332 * but seems useless in simulation. |
| 333 * And this method is similar to SetAddress method, but |
| 334 * SetAddress is suggested when initialize a device, and this method |
| 335 * is used when change address, a addressChange TracedCallback |
| 336 * will be called. |
| 337 */ |
| 338 void ChangeAddress (Mac48Address newAddress); |
| 339 |
| 340 // inherited from NetDevice base class. |
| 341 virtual void SetIfIndex (const uint32_t index); |
| 342 virtual uint32_t GetIfIndex (void) const; |
| 343 virtual Ptr<Channel> GetChannel (void) const; |
| 344 virtual void SetAddress (Address address); |
| 345 virtual Address GetAddress (void) const; |
| 346 virtual bool SetMtu (const uint16_t mtu); |
| 347 virtual uint16_t GetMtu (void) const; |
| 348 /** |
| 349 * Different from WifiNetDevice::IsLinkUp, a WaveNetDevice device |
| 350 * is always link up so the m_linkup variable is true forever, |
| 351 * even the device is in channel switch state, packets can be queued |
| 352 */ |
| 353 virtual bool IsLinkUp (void) const; |
| 354 virtual void AddLinkChangeCallback (Callback<void> callback); |
| 355 virtual bool IsBroadcast (void) const; |
| 356 virtual Address GetBroadcast (void) const; |
| 357 virtual bool IsMulticast (void) const; |
| 358 virtual Address GetMulticast (Ipv4Address multicastGroup) const; |
| 359 virtual bool IsPointToPoint (void) const; |
| 360 virtual bool IsBridge (void) const; |
| 361 /** |
| 362 * WAVE supports both WSMP and IPv6 packets in data plane |
| 363 * Here we will not prevent IPv4 packets, users can use this method |
| 364 * to send any packet, even WSMP packets. |
| 365 */ |
| 366 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolN
umber); |
| 367 virtual Ptr<Node> GetNode (void) const; |
| 368 virtual void SetNode (Ptr<Node> node); |
| 369 /** |
| 370 * Whether NeedsArp or not? |
| 371 * For IP-based Packets , yes; |
| 372 * For WSMP packets, no; |
| 373 * so now return true always. |
| 374 */ |
| 375 virtual bool NeedsArp (void) const; |
| 376 /** |
| 377 * see 1609.4-2010 chapter 5.3.3 |
| 378 * SendX method for WSMP packets and Send method for IP-based packets, |
| 379 * Here is to use this method to receive packets regardless of whether |
| 380 * the frame contains a WSMP or an IPv6 packet. |
| 381 */ |
| 382 virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb); |
| 383 |
| 384 virtual Address GetMulticast (Ipv6Address addr) const; |
| 385 |
| 386 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Addres
s& dest, uint16_t protocolNumber); |
| 387 virtual void SetPromiscReceiveCallback (PromiscReceiveCallback cb); |
| 388 // now return false, maybe change in the future |
| 389 virtual bool SupportsSendFrom (void) const; |
| 390 |
| 391 void SetChannelManager (Ptr<ChannelManager> channelManager); |
| 392 Ptr<ChannelManager> GetChannelManager (void) const; |
| 393 void SetChannelScheduler (Ptr<ChannelScheduler> channelScheduler); |
| 394 Ptr<ChannelScheduler> GetChannelScheduler (void) const; |
| 395 void SetChannelCoordinator (Ptr<ChannelCoordinator> channelCoordinator); |
| 396 Ptr<ChannelCoordinator> GetChannelCoordinator (void) const; |
| 397 |
| 398 private: |
| 399 // This value conforms to the 802.11 specification |
| 400 static const uint16_t MAX_MSDU_SIZE = 2304; |
| 401 |
| 402 virtual void DoDispose (void); |
| 403 virtual void DoInitialize (void); |
| 404 void ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to); |
| 405 Ptr<WifiChannel> DoGetChannel (void) const; |
| 406 |
| 407 Ptr<Node> m_node; |
| 408 Ptr<WifiRemoteStationManager> m_stationManager; |
| 409 std::vector< Ptr<WifiMac> > m_macs; |
| 410 Ptr<WifiPhy> m_phy; |
| 411 |
| 412 NetDevice::ReceiveCallback m_forwardUp; |
| 413 NetDevice::PromiscReceiveCallback m_promiscRx; |
| 414 VsaCallback m_vsaReceived; |
| 415 |
| 416 TracedCallback<Ptr<const Packet>, Mac48Address> m_rxLogger; |
| 417 TracedCallback<Ptr<const Packet>, Mac48Address> m_txLogger; |
| 418 |
| 419 uint32_t m_ifIndex; |
| 420 mutable uint16_t m_mtu; |
| 421 |
| 422 Ptr<ChannelManager> m_channelManager; |
| 423 Ptr<ChannelScheduler> m_channelScheduler; |
| 424 Ptr<ChannelCoordinator> m_channelCoordinator; |
| 425 TxProfile *m_txProfile; |
| 426 |
| 427 TracedCallback<Mac48Address, Mac48Address> m_addressChange; |
| 428 }; |
| 429 |
| 430 } // namespace ns3 |
| 431 |
| 432 #endif /* WAVE_NET_DEVICE_H */ |
OLD | NEW |