00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef YANS_WIFI_PHY_STATE_HELPER_H 00021 #define YANS_WIFI_PHY_STATE_HELPER_H 00022 00023 #include "wifi-phy.h" 00024 #include "ns3/traced-callback.h" 00025 #include "ns3/object.h" 00026 #include <vector> 00027 00028 namespace ns3 { 00029 00030 class YansWifiPhyStateHelper : public Object 00031 { 00032 public: 00033 static TypeId GetTypeId (void); 00034 00035 YansWifiPhyStateHelper (); 00036 00037 void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); 00038 void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); 00039 void RegisterListener (WifiPhyListener *listener); 00040 enum WifiPhy::State GetState (void); 00041 bool IsStateCcaBusy (void); 00042 bool IsStateIdle (void); 00043 bool IsStateBusy (void); 00044 bool IsStateSyncing (void); 00045 bool IsStateRx (void); 00046 bool IsStateTx (void); 00047 Time GetStateDuration (void); 00048 Time GetDelayUntilIdle (void); 00049 Time GetLastRxStartTime (void) const; 00050 00051 void SwitchToTx (Ptr<const Packet> packet, Time txDuration); 00052 void SwitchToRx (Time rxDuration); 00053 void SwitchFromRxEndOk (Ptr<Packet> packet); 00054 void SwitchFromRxEndError (Ptr<const Packet> packet); 00055 void SwitchMaybeToCcaBusy (Time duration); 00056 00057 void CallRxErrorTrace (Ptr<const Packet> packet, WifiPhy::RxErrorReason rxErrorReason); 00058 00059 private: 00060 typedef std::vector<WifiPhyListener *> Listeners; 00061 00062 void LogPreviousIdleAndCcaBusyStates (void); 00063 00064 void NotifyTxStart (Time duration); 00065 void NotifyWakeup (void); 00066 void NotifyRxStart (Time duration); 00067 void NotifyRxEndOk (void); 00068 void NotifyRxEndError (void); 00069 void NotifyMaybeCcaBusyStart (Time duration); 00070 void DoSwitchFromRx (void); 00071 00072 bool m_rxing; 00073 Time m_endTx; 00074 Time m_endRx; 00075 Time m_endCcaBusy; 00076 Time m_startTx; 00077 Time m_startRx; 00078 Time m_startCcaBusy; 00079 Time m_previousStateChangeTime; 00080 00081 Listeners m_listeners; 00082 TracedCallback< Time, Time, enum WifiPhy::State > m_stateLogger; 00083 TracedCallback< Ptr<const Packet> > m_rxOkTrace; 00084 TracedCallback< Ptr<const Packet>, WifiPhy::RxErrorReason > m_rxErrorTrace; 00085 TracedCallback< Ptr<const Packet> > m_txTrace; 00086 WifiPhy::RxOkCallback m_rxOkCallback; 00087 WifiPhy::RxErrorCallback m_rxErrorCallback; 00088 }; 00089 00090 } // namespace ns3 00091 00092 #endif /* YANS_WIFI_PHY_STATE_HELPER_H */