00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006 INRIA, 2008 Timo Bingmann 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 * Based on yans-wifi-phy-state-helper.h by Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 * Modifications: Timo Bingmann <timo.bingmann@student.kit.edu> 00020 */ 00021 #ifndef NS2EXT_WIFI_PHY_STATE_HELPER_H 00022 #define NS2EXT_WIFI_PHY_STATE_HELPER_H 00023 00024 #include "wifi-phy.h" 00025 #include "ns3/traced-callback.h" 00026 #include "ns3/object.h" 00027 #include <vector> 00028 00029 namespace ns3 { 00030 00031 class Ns2ExtWifiPhyStateHelper : public Object 00032 { 00033 public: 00034 static TypeId GetTypeId (void); 00035 00036 Ns2ExtWifiPhyStateHelper (); 00037 00038 void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); 00039 void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); 00040 void RegisterListener (WifiPhyListener *listener); 00041 enum WifiPhy::State GetState (void); 00042 bool IsStateCcaBusy (void); 00043 bool IsStateIdle (void); 00044 bool IsStateBusy (void); 00045 bool IsStateSyncing (void); 00046 bool IsStateRx (void); 00047 bool IsStateTx (void); 00048 Time GetStateDuration (void); 00049 Time GetDelayUntilIdle (void); 00050 Time GetLastRxStartTime (void) const; 00051 00052 void SwitchToTx (Ptr<const Packet> packet, Time txDuration); 00053 void SwitchToRx (Time rxDuration); 00054 void SwitchFromRxEndOk (Ptr<Packet> packet); 00055 void SwitchFromRxEndError (Ptr<const Packet> packet); 00056 void SwitchMaybeToCcaBusy (Time duration); 00057 00058 void CallRxStartTrace (Ptr<const Packet> packet, const WifiPhyRxTag& rxTag); 00059 void CallRxErrorTrace (Ptr<const Packet> packet, WifiPhy::RxErrorReason rxErrorReason); 00060 00061 private: 00062 typedef std::vector<WifiPhyListener *> Listeners; 00063 00064 void LogPreviousIdleAndCcaBusyStates (void); 00065 00066 void NotifyTxStart (Time duration); 00067 void NotifyWakeup (void); 00068 void NotifyRxStart (Time duration); 00069 void NotifyRxEndOk (void); 00070 void NotifyRxEndError (void); 00071 void NotifyMaybeCcaBusyStart (Time duration); 00072 void DoSwitchFromRx (void); 00073 00074 bool m_rxing; 00075 Time m_endTx; 00076 Time m_endRx; 00077 Time m_endCcaBusy; 00078 Time m_startTx; 00079 Time m_startRx; 00080 Time m_startCcaBusy; 00081 Time m_previousStateChangeTime; 00082 00083 Listeners m_listeners; 00084 TracedCallback< Time, Time, enum WifiPhy::State > m_stateLogger; 00085 TracedCallback< Ptr<const Packet>, const WifiPhyRxTag& > m_rxStartTrace; 00086 TracedCallback< Ptr<const Packet> > m_rxOkTrace; 00087 TracedCallback< Ptr<const Packet>, WifiPhy::RxErrorReason > m_rxErrorTrace; 00088 TracedCallback< Ptr<const Packet> > m_txTrace; 00089 WifiPhy::RxOkCallback m_rxOkCallback; 00090 WifiPhy::RxErrorCallback m_rxErrorCallback; 00091 }; 00092 00093 } // namespace ns3 00094 00095 #endif /* NS2EXT_WIFI_PHY_STATE_HELPER_H */