1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2009 IITP RAS 4 * 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: Kirill Andreev <andreev@iitp.ru> 19 */ 20 21 #ifndef PEER_MANAGEMENT_PROTOCOL_MAC_H 22 #define PEER_MANAGEMENT_PROTOCOL_MAC_H 23 24 #include "ns3/mesh-wifi-interface-mac-plugin.h" 25 26 namespace ns3 { 27 class MeshWifiInterfaceMac; 28 class WifiMacQueueItem; 29 enum WifiMacDropReason : uint8_t; // opaque enum declaration 30 namespace dot11s { 31 class PeerManagementProtocol; 32 class IeConfiguration; 33 class IePeerManagement; 34 class PeerManagementProtocol; 35 /** 36 * \ingroup dot11s 37 * 38 * \brief This is plugin to Mesh WiFi MAC, which implements the 39 * interface to dot11s peer management protocol: it takes proper 40 * frames from MAC-layer, extracts peer link management information 41 * element and mesh configuration element and passes it to main part 42 * of protocol 43 */ 44 class PeerManagementProtocolMac : public MeshWifiInterfaceMacPlugin 45 { 46 public: 47 /** 48 * Constructor 49 * 50 * \param interface interface index 51 * \param protocol peer management protocol 52 */ 53 PeerManagementProtocolMac (uint32_t interface, Ptr<PeerManagementProtocol> protocol); 54 ~PeerManagementProtocolMac (); 55 56 // Inherited from plugin abstract class 57 /** 58 * Set pointer to parent 59 * \param parent Ptr<MeshWifiInterfaceMac> 60 */ 61 void SetParent (Ptr<MeshWifiInterfaceMac> parent); 62 /** 63 * Receive and process a packet 64 * \param packet the packet received 65 * \param header the header 66 * \returns true if received 67 */ 68 bool Receive (Ptr<Packet> packet, const WifiMacHeader & header); 69 /** 70 * This method appears to test a few conditions. If an action frame, 71 * it returns true if SELF_PROTECTED. It then checks if it is either 72 * a broadcast or sent on an active link, and returns true if so. 73 * Otherwise, it returns false (indicating it is to be dropped) 74 * \param packet the packet 75 * \param header the header 76 * \param from the MAC address of the sender 77 * \param to the MAC address of the receiver 78 * \returns true if successful, false if to be dropped 79 */ 80 bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to); 81 /** 82 * Add beacon timing and mesh ID information elements, and notify beacon sent 83 * \param beacon the beacon 84 */ 85 void UpdateBeacon (MeshWifiBeacon & beacon) const; 86 /** 87 * Assign the streams 88 * \param stream the stream to assign 89 * \return the assigned stream 90 */ 91 int64_t AssignStreams (int64_t stream); 92 93 /// \name Statistics 94 ///@{ 95 /** 96 * \brief Report statistics 97 * \param os the output stream 98 */ 99 void Report (std::ostream &) const; 100 /// Reset stats 101 void ResetStats (); 102 /** 103 * Get the link metric 104 * \param peerAddress the peer address 105 * \return The metric 106 */ 107 uint32_t GetLinkMetric (Mac48Address peerAddress); 108 ///@} 109 110 private: 111 /** 112 * assignment operator 113 * 114 * \param peer the object to assign 115 * \returns the assigned value 116 */ 117 PeerManagementProtocolMac& operator= (const PeerManagementProtocolMac & peer); 118 /// type conversion operator 119 PeerManagementProtocolMac (const PeerManagementProtocolMac &); 120 121 /// allow PeerManagementProtocol class access friend access 122 friend class PeerManagementProtocol; 123 /// allow PeerLink class access friend access 124 friend class PeerLink; 125 ///\name Create peer link management frames 126 // \{ 127 /** 128 * \brief This structure keeps all fields in peer link management frame, 129 * which are not subclasses of WifiInformationElement 130 */ 131 struct PlinkFrameStart 132 { 133 uint8_t subtype; ///< subtype 134 uint16_t aid; ///< aid 135 SupportedRates rates; ///< rates 136 uint16_t qos; ///< QOS 137 }; 138 /** 139 * Create peer link open frame function 140 * \returns the packet 141 */ 142 Ptr<Packet> CreatePeerLinkOpenFrame (); 143 /** 144 * Create peer link confirm frame function 145 * \returns the packet 146 */ 147 Ptr<Packet> CreatePeerLinkConfirmFrame (); 148 /** 149 * Create peer link clode frame function 150 * \returns the packet 151 */ 152 Ptr<Packet> CreatePeerLinkCloseFrame (); 153 /** 154 * Parses the start of the frame, where no WifiInformationElements exist 155 * \param packet the packet 156 * \returns PlinkFrameStart 157 */ 158 PlinkFrameStart ParsePlinkFrame (Ptr<const Packet> packet); 159 // \} 160 /** 161 * Closes link when a proper number of successive transmissions have failed 162 * \param reason the reason why the MPDU was dropped 163 * \param mpdu the dropped MPDU 164 */ 165 void TxError (WifiMacDropReason reason, Ptr<const WifiMacQueueItem> mpdu); 166 /** 167 * Transmit OK function 168 * \param mpdu the MPDU 169 */ 170 void TxOk (Ptr <const WifiMacQueueItem> mpdu); 171 // BCA functionality 172 /** 173 * Set beacon shift function 174 * \param shift the beacon time shift 175 */ 176 void SetBeaconShift (Time shift); 177 /** 178 * Set peer manager protocol function 179 * \param protocol the peer manager protocol 180 */ 181 void SetPeerManagerProtcol (Ptr<PeerManagementProtocol> protocol); 182 /** 183 * Send peer link management frame function 184 * \param peerAddress the peer MAC address 185 * \param peerMpAddress the peer MP address 186 * \param aid the AID 187 * \param peerElement IePeerManagement 188 * \param meshConfig IeConfiguration 189 */ 190 void SendPeerLinkManagementFrame ( 191 Mac48Address peerAddress, 192 Mac48Address peerMpAddress, 193 uint16_t aid, 194 IePeerManagement peerElement, 195 IeConfiguration meshConfig 196 ); 197 /** 198 * \brief debug only, used to print established links 199 * \returns the MAC address 200 */ 201 Mac48Address GetAddress () const; 202 /// Statistics structure 203 struct Statistics 204 { 205 uint16_t txOpen; ///< transmit open 206 uint16_t txConfirm; ///< transmit confirm 207 uint16_t txClose; ///< transmit close 208 uint16_t rxOpen; ///< receive open 209 uint16_t rxConfirm; ///< receive confirm 210 uint16_t rxClose; ///< receive close 211 uint16_t dropped; ///< dropped 212 uint16_t brokenMgt; ///< broken management 213 uint16_t txMgt; ///< transmit management 214 uint32_t txMgtBytes; ///< transmit management bytes 215 uint16_t rxMgt; ///< receive management 216 uint32_t rxMgtBytes; ///< receive management bytes 217 uint16_t beaconShift; ///< beacon shift 218 219 /// constructor 220 Statistics (); 221 /** 222 * Print function 223 * \param os the output stream 224 */ 225 void Print (std::ostream & os) const; 226 }; 227 228 private: 229 struct Statistics m_stats; ///< statistics 230 ///\name Information about MAC and protocol: 231 Ptr<MeshWifiInterfaceMac> m_parent; ///< parent 232 uint32_t m_ifIndex; ///< IF index 233 Ptr<PeerManagementProtocol> m_protocol; ///< protocol 234 }; 235 236 } // namespace dot11s 237 } // namespace ns3 238 239 #endif /* PEER_MANAGEMENT_PROTOCOL_MAC_H */ 240 241