diff -r f8f2a9d65576 src/common/packet-tag-list.h --- a/src/common/packet-tag-list.h Wed Mar 10 11:11:38 2010 +0100 +++ b/src/common/packet-tag-list.h Mon Mar 15 13:17:33 2010 +1100 @@ -1,142 +1,1 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2006 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef PACKET_TAG_LIST_H -#define PACKET_TAG_LIST_H - -#include -#include -#include "ns3/type-id.h" - -namespace ns3 { - -class Tag; - -/** - * \ingroup constants - * \brief Tag maximum size - * The maximum size (in bytes) of a Tag is stored - * in this constant. - */ -#define PACKET_TAG_MAX_SIZE 20 - -class PacketTagList -{ -public: - struct TagData { - uint8_t data[PACKET_TAG_MAX_SIZE]; - struct TagData *next; - TypeId tid; - uint32_t count; - }; - - inline PacketTagList (); - inline PacketTagList (PacketTagList const &o); - inline PacketTagList &operator = (PacketTagList const &o); - inline ~PacketTagList (); - - void Add (Tag const&tag) const; - bool Remove (Tag &tag); - bool Peek (Tag &tag) const; - inline void RemoveAll (void); - - const struct PacketTagList::TagData *Head (void) const; - -private: - - bool Remove (TypeId tid); - struct PacketTagList::TagData *AllocData (void) const; - void FreeData (struct TagData *data) const; - - static struct PacketTagList::TagData *g_free; - static uint32_t g_nfree; - - struct TagData *m_next; -}; - -} // namespace ns3 - -/**************************************************** - * Implementation of inline methods for performance - ****************************************************/ - -namespace ns3 { - -PacketTagList::PacketTagList () - : m_next () -{} - -PacketTagList::PacketTagList (PacketTagList const &o) - : m_next (o.m_next) -{ - if (m_next != 0) - { - m_next->count++; - } -} - -PacketTagList & -PacketTagList::operator = (PacketTagList const &o) -{ - // self assignment - if (m_next == o.m_next) - { - return *this; - } - RemoveAll (); - m_next = o.m_next; - if (m_next != 0) - { - m_next->count++; - } - return *this; -} - -PacketTagList::~PacketTagList () -{ - RemoveAll (); -} - -void -PacketTagList::RemoveAll (void) -{ - struct TagData *prev = 0; - for (struct TagData *cur = m_next; cur != 0; cur = cur->next) - { - cur->count--; - if (cur->count > 0) - { - break; - } - if (prev != 0) - { - FreeData (prev); - } - prev = cur; - } - if (prev != 0) - { - FreeData (prev); - } - m_next = 0; -} - -} // namespace ns3 - -#endif /* PACKET_TAG_LIST_H */ +/home/quincy/code/ns3/common/packet-tag-list.h \ No newline at end of file diff -r f8f2a9d65576 src/devices/wifi/mac-low.cc --- a/src/devices/wifi/mac-low.cc Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/mac-low.cc Mon Mar 15 13:17:33 2010 +1100 @@ -1,1258 +1,1 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005,2006 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include "ns3/assert.h" -#include "ns3/packet.h" -#include "ns3/simulator.h" -#include "ns3/tag.h" -#include "ns3/log.h" -#include "ns3/node.h" - -#include "mac-low.h" -#include "wifi-phy.h" -#include "wifi-mac-trailer.h" - -NS_LOG_COMPONENT_DEFINE ("MacLow"); - -#undef NS_LOG_APPEND_CONTEXT -#define NS_LOG_APPEND_CONTEXT std::clog << "[mac=" << m_self << "] " - - -namespace ns3 { - -class SnrTag : public Tag -{ -public: - - static TypeId GetTypeId (void); - virtual TypeId GetInstanceTypeId (void) const; - - virtual uint32_t GetSerializedSize (void) const; - virtual void Serialize (TagBuffer i) const; - virtual void Deserialize (TagBuffer i); - virtual void Print (std::ostream &os) const; - - void Set (double snr); - double Get (void) const; -private: - double m_snr; -}; - -TypeId -SnrTag::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::SnrTag") - .SetParent () - .AddConstructor () - .AddAttribute ("Snr", "The snr of the last packet received", - DoubleValue (0.0), - MakeDoubleAccessor (&SnrTag::Get), - MakeDoubleChecker ()) - ; - return tid; -} -TypeId -SnrTag::GetInstanceTypeId (void) const -{ - return GetTypeId (); -} - -uint32_t -SnrTag::GetSerializedSize (void) const -{ - return sizeof (double); -} -void -SnrTag::Serialize (TagBuffer i) const -{ - i.WriteDouble (m_snr); -} -void -SnrTag::Deserialize (TagBuffer i) -{ - m_snr = i.ReadDouble (); -} -void -SnrTag::Print (std::ostream &os) const -{ - os << "Snr=" << m_snr; -} -void -SnrTag::Set (double snr) -{ - m_snr = snr; -} -double -SnrTag::Get (void) const -{ - return m_snr; -} - - -MacLowTransmissionListener::MacLowTransmissionListener () -{} -MacLowTransmissionListener::~MacLowTransmissionListener () -{} -MacLowDcfListener::MacLowDcfListener () -{} -MacLowDcfListener::~MacLowDcfListener () -{} - -MacLowTransmissionParameters::MacLowTransmissionParameters () - : m_nextSize (0), - m_waitAck (ACK_NONE), - m_sendRts (false), - m_overrideDurationId (Seconds (0)) -{} -void -MacLowTransmissionParameters::EnableNextData (uint32_t size) -{ - m_nextSize = size; -} -void -MacLowTransmissionParameters::DisableNextData (void) -{ - m_nextSize = 0; -} -void -MacLowTransmissionParameters::EnableOverrideDurationId (Time durationId) -{ - m_overrideDurationId = durationId; -} -void -MacLowTransmissionParameters::DisableOverrideDurationId (void) -{ - m_overrideDurationId = Seconds (0); -} -void -MacLowTransmissionParameters::EnableSuperFastAck (void) -{ - m_waitAck = ACK_SUPER_FAST; -} -void -MacLowTransmissionParameters::EnableFastAck (void) -{ - m_waitAck = ACK_FAST; -} -void -MacLowTransmissionParameters::EnableAck (void) -{ - m_waitAck = ACK_NORMAL; -} -void -MacLowTransmissionParameters::DisableAck (void) -{ - m_waitAck = ACK_NONE; -} -void -MacLowTransmissionParameters::EnableRts (void) -{ - m_sendRts = true; -} -void -MacLowTransmissionParameters::DisableRts (void) -{ - m_sendRts = false; -} -bool -MacLowTransmissionParameters::MustWaitAck (void) const -{ - return (m_waitAck != ACK_NONE); -} -bool -MacLowTransmissionParameters::MustWaitNormalAck (void) const -{ - return (m_waitAck == ACK_NORMAL); -} -bool -MacLowTransmissionParameters::MustWaitFastAck (void) const -{ - return (m_waitAck == ACK_FAST); -} -bool -MacLowTransmissionParameters::MustWaitSuperFastAck (void) const -{ - return (m_waitAck == ACK_SUPER_FAST); -} -bool -MacLowTransmissionParameters::MustSendRts (void) const -{ - return m_sendRts; -} -bool -MacLowTransmissionParameters::HasDurationId (void) const -{ - return (m_overrideDurationId != Seconds (0)); -} -Time -MacLowTransmissionParameters::GetDurationId (void) const -{ - NS_ASSERT (m_overrideDurationId != Seconds (0)); - return m_overrideDurationId; -} -bool -MacLowTransmissionParameters::HasNextPacket (void) const -{ - return (m_nextSize != 0); -} -uint32_t -MacLowTransmissionParameters::GetNextPacketSize (void) const -{ - NS_ASSERT (HasNextPacket ()); - return m_nextSize; -} - -std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters ¶ms) -{ - os << "[" - << "send rts=" << params.m_sendRts << ", " - << "next size=" << params.m_nextSize << ", " - << "dur=" << params.m_overrideDurationId << ", " - << "ack="; - switch (params.m_waitAck) { - case MacLowTransmissionParameters::ACK_NONE: - os << "none"; - break; - case MacLowTransmissionParameters::ACK_NORMAL: - os << "normal"; - break; - case MacLowTransmissionParameters::ACK_FAST: - os << "fast"; - break; - case MacLowTransmissionParameters::ACK_SUPER_FAST: - os << "super-fast"; - break; - } - os << "]"; - return os; -} - - -/*************************************************************** - * Listener for PHY events. Forwards to MacLow - ***************************************************************/ - - -class PhyMacLowListener : public ns3::WifiPhyListener { -public: - PhyMacLowListener (ns3::MacLow *macLow) - : m_macLow (macLow) {} - virtual ~PhyMacLowListener () {} - virtual void NotifyRxStart (Time duration) {} - virtual void NotifyRxEndOk (void) {} - virtual void NotifyRxEndError (void) {} - virtual void NotifyTxStart (Time duration) {} - virtual void NotifyMaybeCcaBusyStart (Time duration) {} - virtual void NotifySwitchingStart (Time duration) { - m_macLow->NotifySwitchingStartNow (duration); - } -private: - ns3::MacLow *m_macLow; -}; - - -MacLow::MacLow () - : m_normalAckTimeoutEvent (), - m_fastAckTimeoutEvent (), - m_superFastAckTimeoutEvent (), - m_fastAckFailedTimeoutEvent (), - m_ctsTimeoutEvent (), - m_sendCtsEvent (), - m_sendAckEvent (), - m_sendDataEvent (), - m_waitSifsEvent (), - m_currentPacket (0), - m_listener (0) -{ - NS_LOG_FUNCTION (this); - m_lastNavDuration = Seconds (0); - m_lastNavStart = Seconds (0); -} - -MacLow::~MacLow () -{ - NS_LOG_FUNCTION (this); -} - -void -MacLow::SetupPhyMacLowListener (Ptr phy) -{ - m_phyMacLowListener = new PhyMacLowListener (this); - phy->RegisterListener (m_phyMacLowListener); -} - - -void -MacLow::DoDispose (void) -{ - NS_LOG_FUNCTION (this); - m_normalAckTimeoutEvent.Cancel (); - m_fastAckTimeoutEvent.Cancel (); - m_superFastAckTimeoutEvent.Cancel (); - m_fastAckFailedTimeoutEvent.Cancel (); - m_ctsTimeoutEvent.Cancel (); - m_sendCtsEvent.Cancel (); - m_sendAckEvent.Cancel (); - m_sendDataEvent.Cancel (); - m_waitSifsEvent.Cancel (); - m_phy = 0; - m_stationManager = 0; - delete m_phyMacLowListener; - m_phyMacLowListener = 0; -} - -void -MacLow::CancelAllEvents (void) -{ - NS_LOG_FUNCTION (this); - bool oneRunning = false; - if (m_normalAckTimeoutEvent.IsRunning ()) - { - m_normalAckTimeoutEvent.Cancel (); - oneRunning = true; - } - if (m_fastAckTimeoutEvent.IsRunning ()) - { - m_fastAckTimeoutEvent.Cancel (); - oneRunning = true; - } - if (m_superFastAckTimeoutEvent.IsRunning ()) - { - m_superFastAckTimeoutEvent.Cancel (); - oneRunning = true; - } - if (m_fastAckFailedTimeoutEvent.IsRunning ()) - { - m_fastAckFailedTimeoutEvent.Cancel (); - oneRunning = true; - } - if (m_ctsTimeoutEvent.IsRunning ()) - { - m_ctsTimeoutEvent.Cancel (); - oneRunning = true; - } - if (m_sendCtsEvent.IsRunning ()) - { - m_sendCtsEvent.Cancel (); - oneRunning = true; - } - if (m_sendAckEvent.IsRunning ()) - { - m_sendAckEvent.Cancel (); - oneRunning = true; - } - if (m_sendDataEvent.IsRunning ()) - { - m_sendDataEvent.Cancel (); - oneRunning = true; - } - if (m_waitSifsEvent.IsRunning ()) - { - m_waitSifsEvent.Cancel (); - oneRunning = true; - } - if (oneRunning && m_listener != 0) - { - m_listener->Cancel (); - m_listener = 0; - } -} - -void -MacLow::SetPhy (Ptr phy) -{ - m_phy = phy; - m_phy->SetReceiveOkCallback (MakeCallback (&MacLow::ReceiveOk, this)); - m_phy->SetReceiveErrorCallback (MakeCallback (&MacLow::ReceiveError, this)); - SetupPhyMacLowListener(phy); -} -void -MacLow::SetWifiRemoteStationManager (Ptr manager) -{ - m_stationManager = manager; -} - -void -MacLow::SetAddress (Mac48Address ad) -{ - m_self = ad; -} -void -MacLow::SetAckTimeout (Time ackTimeout) -{ - m_ackTimeout = ackTimeout; -} -void -MacLow::SetCtsTimeout (Time ctsTimeout) -{ - m_ctsTimeout = ctsTimeout; -} -void -MacLow::SetSifs (Time sifs) -{ - m_sifs = sifs; -} -void -MacLow::SetSlotTime (Time slotTime) -{ - m_slotTime = slotTime; -} -void -MacLow::SetPifs (Time pifs) -{ - m_pifs = pifs; -} -void -MacLow::SetBssid (Mac48Address bssid) -{ - m_bssid = bssid; -} -Mac48Address -MacLow::GetAddress (void) const -{ - return m_self; -} -Time -MacLow::GetAckTimeout (void) const -{ - return m_ackTimeout; -} -Time -MacLow::GetCtsTimeout (void) const -{ - return m_ctsTimeout; -} -Time -MacLow::GetSifs (void) const -{ - return m_sifs; -} -Time -MacLow::GetSlotTime (void) const -{ - return m_slotTime; -} -Time -MacLow::GetPifs (void) const -{ - return m_pifs; -} -Mac48Address -MacLow::GetBssid (void) const -{ - return m_bssid; -} - -void -MacLow::SetRxCallback (Callback,const WifiMacHeader *> callback) -{ - m_rxCallback = callback; -} -void -MacLow::RegisterDcfListener (MacLowDcfListener *listener) -{ - m_dcfListeners.push_back (listener); -} - - -void -MacLow::StartTransmission (Ptr packet, - const WifiMacHeader* hdr, - MacLowTransmissionParameters params, - MacLowTransmissionListener *listener) -{ - NS_LOG_FUNCTION (this << packet << hdr << params << listener); - /* m_currentPacket is not NULL because someone started - * a transmission and was interrupted before one of: - * - ctsTimeout - * - sendDataAfterCTS - * expired. This means that one of these timers is still - * running. They are all cancelled below anyway by the - * call to CancelAllEvents (because of at least one - * of these two timer) which will trigger a call to the - * previous listener's cancel method. - * - * This typically happens because the high-priority - * QapScheduler has taken access to the channel from - * one of the Edca of the QAP. - */ - m_currentPacket = packet->Copy (); - m_currentHdr = *hdr; - CancelAllEvents (); - m_listener = listener; - m_txParams = params; - - //NS_ASSERT (m_phy->IsStateIdle ()); - - NS_LOG_DEBUG ("startTx size="<< GetSize (m_currentPacket, &m_currentHdr) << - ", to=" << m_currentHdr.GetAddr1()<<", listener="<IsStateTx ()); -} - -void -MacLow::ReceiveError (Ptr packet, double rxSnr) -{ - NS_LOG_FUNCTION (this << packet << rxSnr); - NS_LOG_DEBUG ("rx failed "); - if (m_txParams.MustWaitFastAck ()) - { - NS_ASSERT (m_fastAckFailedTimeoutEvent.IsExpired ()); - m_fastAckFailedTimeoutEvent = Simulator::Schedule (GetSifs (), - &MacLow::FastAckFailedTimeout, this); - } - return; -} - -void -MacLow::NotifySwitchingStartNow (Time duration) -{ - NS_LOG_DEBUG ("switching channel. Cancelling MAC pending events"); - m_stationManager->Reset(); - CancelAllEvents(); - if (m_navCounterResetCtsMissed.IsRunning ()) - { - m_navCounterResetCtsMissed.Cancel(); - } - m_lastNavStart = Simulator::Now (); - m_lastNavDuration = Seconds (0); - m_currentPacket = 0; - m_listener = 0; -} - -void -MacLow::ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamble preamble) -{ - NS_LOG_FUNCTION (this << packet << rxSnr << txMode << preamble); - /* A packet is received from the PHY. - * When we have handled this packet, - * we handle any packet present in the - * packet queue. - */ - WifiMacHeader hdr; - packet->RemoveHeader (hdr); - - bool isPrevNavZero = IsNavZero (); - NS_LOG_DEBUG ("duration/id=" << hdr.GetDuration ()); - NotifyNav (hdr, txMode, preamble); - if (hdr.IsRts ()) - { - /* see section 9.2.5.7 802.11-1999 - * A STA that is addressed by an RTS frame shall transmit a CTS frame after a SIFS - * period if the NAV at the STA receiving the RTS frame indicates that the medium is - * idle. If the NAV at the STA receiving the RTS indicates the medium is not idle, - * that STA shall not respond to the RTS frame. - */ - if (isPrevNavZero && - hdr.GetAddr1 () == m_self) - { - NS_LOG_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", schedule CTS"); - NS_ASSERT (m_sendCtsEvent.IsExpired ()); - WifiRemoteStation *station = GetStation (hdr.GetAddr2 ()); - station->ReportRxOk (rxSnr, txMode); - m_sendCtsEvent = Simulator::Schedule (GetSifs (), - &MacLow::SendCtsAfterRts, this, - hdr.GetAddr2 (), - hdr.GetDuration (), - txMode, - rxSnr); - } - else - { - NS_LOG_DEBUG ("rx RTS from=" << hdr.GetAddr2 () << ", cannot schedule CTS"); - } - } - else if (hdr.IsCts () && - hdr.GetAddr1 () == m_self && - m_ctsTimeoutEvent.IsRunning () && - m_currentPacket != 0) - { - NS_LOG_DEBUG ("receive cts from="<RemovePacketTag (tag); - WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); - station->ReportRxOk (rxSnr, txMode); - station->ReportRtsOk (rxSnr, txMode, tag.Get ()); - - m_ctsTimeoutEvent.Cancel (); - NotifyCtsTimeoutResetNow (); - m_listener->GotCts (rxSnr, txMode); - NS_ASSERT (m_sendDataEvent.IsExpired ()); - m_sendDataEvent = Simulator::Schedule (GetSifs (), - &MacLow::SendDataAfterCts, this, - hdr.GetAddr1 (), - hdr.GetDuration (), - txMode); - } - else if (hdr.IsAck () && - hdr.GetAddr1 () == m_self && - (m_normalAckTimeoutEvent.IsRunning () || - m_fastAckTimeoutEvent.IsRunning () || - m_superFastAckTimeoutEvent.IsRunning ()) && - m_txParams.MustWaitAck ()) - { - NS_LOG_DEBUG ("receive ack from="<RemovePacketTag (tag); - WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); - station->ReportRxOk (rxSnr, txMode); - station->ReportDataOk (rxSnr, txMode, tag.Get ()); - bool gotAck = false; - if (m_txParams.MustWaitNormalAck () && - m_normalAckTimeoutEvent.IsRunning ()) - { - m_normalAckTimeoutEvent.Cancel (); - NotifyAckTimeoutResetNow (); - gotAck = true; - } - if (m_txParams.MustWaitFastAck () && - m_fastAckTimeoutEvent.IsRunning ()) - { - m_fastAckTimeoutEvent.Cancel (); - NotifyAckTimeoutResetNow (); - gotAck = true; - } - if (gotAck) - { - m_listener->GotAck (rxSnr, txMode); - } - if (m_txParams.HasNextPacket ()) - { - m_waitSifsEvent = Simulator::Schedule (GetSifs (), - &MacLow::WaitSifsAfterEndTx, this); - } - } - else if (hdr.IsCtl ()) - { - NS_LOG_DEBUG ("rx drop " << hdr.GetTypeString ()); - } - else if (hdr.GetAddr1 () == m_self) - { - WifiRemoteStation *station = GetStation (hdr.GetAddr2 ()); - station->ReportRxOk (rxSnr, txMode); - - if (hdr.IsQosData () && hdr.IsQosNoAck ()) - { - NS_LOG_DEBUG ("rx unicast/noAck from="<RemoveTrailer (fcs); - m_rxCallback (packet, &hdr); - return; -} - -uint32_t -MacLow::GetAckSize (void) const -{ - WifiMacHeader ack; - ack.SetType (WIFI_MAC_CTL_ACK); - return ack.GetSize () + 4; -} -uint32_t -MacLow::GetRtsSize (void) const -{ - WifiMacHeader rts; - rts.SetType (WIFI_MAC_CTL_RTS); - return rts.GetSize () + 4; -} -Time -MacLow::GetAckDuration (Mac48Address to, WifiMode dataTxMode) const -{ - WifiMode ackMode = GetAckTxModeForData (to, dataTxMode); - return m_phy->CalculateTxDuration (GetAckSize (), ackMode, WIFI_PREAMBLE_LONG); -} -Time -MacLow::GetCtsDuration (Mac48Address to, WifiMode rtsTxMode) const -{ - WifiMode ctsMode = GetCtsTxModeForRts (to, rtsTxMode); - return m_phy->CalculateTxDuration (GetCtsSize (), ctsMode, WIFI_PREAMBLE_LONG); -} -uint32_t -MacLow::GetCtsSize (void) const -{ - WifiMacHeader cts; - cts.SetType (WIFI_MAC_CTL_CTS); - return cts.GetSize () + 4; -} -uint32_t -MacLow::GetSize (Ptr packet, const WifiMacHeader *hdr) const -{ - WifiMacTrailer fcs; - return packet->GetSize () + hdr->GetSize () + fcs.GetSerializedSize (); -} - -WifiMode -MacLow::GetRtsTxMode (Ptr packet, const WifiMacHeader *hdr) const -{ - Mac48Address to = hdr->GetAddr1 (); - return GetStation (to)->GetRtsMode (packet); -} -WifiMode -MacLow::GetDataTxMode (Ptr packet, const WifiMacHeader *hdr) const -{ - Mac48Address to = hdr->GetAddr1 (); - WifiMacTrailer fcs; - uint32_t size = packet->GetSize () + hdr->GetSize () + fcs.GetSerializedSize (); - return GetStation (to)->GetDataMode (packet, size); -} - -WifiMode -MacLow::GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const -{ - return GetStation (to)->GetCtsMode (rtsTxMode); -} -WifiMode -MacLow::GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const -{ - return GetStation (to)->GetAckMode (dataTxMode); -} - - -Time -MacLow::CalculateOverallTxTime (Ptr packet, - const WifiMacHeader* hdr, - const MacLowTransmissionParameters& params) const -{ - Time txTime = Seconds (0); - WifiMode rtsMode = GetRtsTxMode (packet, hdr); - WifiMode dataMode = GetDataTxMode (packet, hdr); - if (params.MustSendRts ()) - { - txTime += m_phy->CalculateTxDuration (GetRtsSize (), rtsMode, WIFI_PREAMBLE_LONG); - txTime += GetCtsDuration (hdr->GetAddr1 (), rtsMode); - txTime += GetSifs () * Scalar (2); - } - uint32_t dataSize = GetSize (packet, hdr); - txTime += m_phy->CalculateTxDuration (dataSize, dataMode, WIFI_PREAMBLE_LONG); - if (params.MustWaitAck ()) - { - txTime += GetSifs (); - txTime += GetAckDuration (hdr->GetAddr1 (), dataMode); - } - return txTime; -} - -Time -MacLow::CalculateTransmissionTime (Ptr packet, - const WifiMacHeader* hdr, - const MacLowTransmissionParameters& params) const -{ - Time txTime = CalculateOverallTxTime (packet, hdr, params); - if (params.HasNextPacket ()) - { - WifiMode dataMode = GetDataTxMode (packet, hdr); - txTime += GetSifs (); - txTime += m_phy->CalculateTxDuration (params.GetNextPacketSize (), dataMode, WIFI_PREAMBLE_LONG); - } - return txTime; -} - -void -MacLow::NotifyNav (const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble preamble) -{ - NS_ASSERT (m_lastNavStart <= Simulator::Now ()); - Time duration = hdr.GetDuration (); - - if (hdr.IsCfpoll () && - hdr.GetAddr2 () == m_bssid) - { - // see section 9.3.2.2 802.11-1999 - DoNavResetNow (duration); - return; - } - // XXX Note that we should also handle CF_END specially here - // but we don't for now because we do not generate them. - else if (hdr.GetAddr1 () != m_self) - { - // see section 9.2.5.4 802.11-1999 - bool navUpdated = DoNavStartNow (duration); - if (hdr.IsRts () && navUpdated) - { - /** - * A STA that used information from an RTS frame as the most recent basis to update its NAV setting - * is permitted to reset its NAV if no PHY-RXSTART.indication is detected from the PHY during a - * period with a duration of (2 * aSIFSTime) + (CTS_Time) + (2 * aSlotTime) starting at the - * PHY-RXEND.indication corresponding to the detection of the RTS frame. The “CTS_Time” shall - * be calculated using the length of the CTS frame and the data rate at which the RTS frame - * used for the most recent NAV update was received. - */ - WifiMacHeader cts; - cts.SetType (WIFI_MAC_CTL_CTS); - Time navCounterResetCtsMissedDelay = - m_phy->CalculateTxDuration (cts.GetSerializedSize (), txMode, preamble) + - Scalar (2) * GetSifs () + Scalar (2) * GetSlotTime (); - m_navCounterResetCtsMissed = Simulator::Schedule (navCounterResetCtsMissedDelay, - &MacLow::NavCounterResetCtsMissed, this, - Simulator::Now ()); - } - } -} - -void -MacLow::NavCounterResetCtsMissed (Time rtsEndRxTime) -{ - if (m_phy->GetLastRxStartTime () > rtsEndRxTime) - { - DoNavResetNow (Seconds (0.0)); - } -} - -void -MacLow::DoNavResetNow (Time duration) -{ - for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) - { - (*i)->NavReset (duration); - } - m_lastNavStart = Simulator::Now (); - m_lastNavStart = duration; -} -bool -MacLow::DoNavStartNow (Time duration) -{ - for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) - { - (*i)->NavStart (duration); - } - Time newNavEnd = Simulator::Now () + duration; - Time oldNavEnd = m_lastNavStart + m_lastNavDuration; - if (newNavEnd > oldNavEnd) - { - m_lastNavStart = Simulator::Now (); - m_lastNavDuration = duration; - return true; - } - return false; -} -void -MacLow::NotifyAckTimeoutStartNow (Time duration) -{ - for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) - { - (*i)->AckTimeoutStart (duration); - } -} -void -MacLow::NotifyAckTimeoutResetNow () -{ - for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) - { - (*i)->AckTimeoutReset (); - } -} -void -MacLow::NotifyCtsTimeoutStartNow (Time duration) -{ - for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) - { - (*i)->CtsTimeoutStart (duration); - } -} -void -MacLow::NotifyCtsTimeoutResetNow () -{ - for (DcfListenersCI i = m_dcfListeners.begin (); i != m_dcfListeners.end (); i++) - { - (*i)->CtsTimeoutReset (); - } -} - -void -MacLow::ForwardDown (Ptr packet, const WifiMacHeader* hdr, - WifiMode txMode) -{ - NS_LOG_FUNCTION (this << packet << hdr << txMode); - NS_LOG_DEBUG ("send " << hdr->GetTypeString () << - ", to=" << hdr->GetAddr1 () << - ", size=" << packet->GetSize () << - ", mode=" << txMode << - ", duration=" << hdr->GetDuration () << - ", seq=0x"<< std::hex << m_currentHdr.GetSequenceControl () << std::dec); - m_phy->SendPacket (packet, txMode, WIFI_PREAMBLE_LONG, 0); -} - -void -MacLow::CtsTimeout (void) -{ - NS_LOG_FUNCTION (this); - NS_LOG_DEBUG ("cts timeout"); - // XXX: should check that there was no rx start before now. - // we should restart a new cts timeout now until the expected - // end of rx if there was a rx start before now. - WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); - station->ReportRtsFailed (); - m_currentPacket = 0; - MacLowTransmissionListener *listener = m_listener; - m_listener = 0; - listener->MissedCts (); -} -void -MacLow::NormalAckTimeout (void) -{ - NS_LOG_FUNCTION (this); - NS_LOG_DEBUG ("normal ack timeout"); - // XXX: should check that there was no rx start before now. - // we should restart a new ack timeout now until the expected - // end of rx if there was a rx start before now. - WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); - station->ReportDataFailed (); - MacLowTransmissionListener *listener = m_listener; - m_listener = 0; - listener->MissedAck (); -} -void -MacLow::FastAckTimeout (void) -{ - NS_LOG_FUNCTION (this); - WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); - station->ReportDataFailed (); - MacLowTransmissionListener *listener = m_listener; - m_listener = 0; - if (m_phy->IsStateIdle ()) - { - NS_LOG_DEBUG ("fast Ack idle missed"); - listener->MissedAck (); - } - else - { - NS_LOG_DEBUG ("fast Ack ok"); - } -} -void -MacLow::SuperFastAckTimeout () -{ - NS_LOG_FUNCTION (this); - WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ()); - station->ReportDataFailed (); - MacLowTransmissionListener *listener = m_listener; - m_listener = 0; - if (m_phy->IsStateIdle ()) - { - NS_LOG_DEBUG ("super fast Ack failed"); - listener->MissedAck (); - } - else - { - NS_LOG_DEBUG ("super fast Ack ok"); - listener->GotAck (0.0, WifiMode ()); - } -} - -void -MacLow::SendRtsForPacket (void) -{ - NS_LOG_FUNCTION (this); - /* send an RTS for this packet. */ - WifiMacHeader rts; - rts.SetType (WIFI_MAC_CTL_RTS); - rts.SetDsNotFrom (); - rts.SetDsNotTo (); - rts.SetNoRetry (); - rts.SetNoMoreFragments (); - rts.SetAddr1 (m_currentHdr.GetAddr1 ()); - rts.SetAddr2 (m_self); - WifiMode rtsTxMode = GetRtsTxMode (m_currentPacket, &m_currentHdr); - Time duration = Seconds (0); - if (m_txParams.HasDurationId ()) - { - duration += m_txParams.GetDurationId (); - } - else - { - WifiMode dataTxMode = GetDataTxMode (m_currentPacket, &m_currentHdr); - duration += GetSifs (); - duration += GetCtsDuration (m_currentHdr.GetAddr1 (), rtsTxMode); - duration += GetSifs (); - duration += m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), - dataTxMode, WIFI_PREAMBLE_LONG); - duration += GetSifs (); - duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxMode); - } - rts.SetDuration (duration); - - Time txDuration = m_phy->CalculateTxDuration (GetRtsSize (), rtsTxMode, WIFI_PREAMBLE_LONG); - Time timerDelay = txDuration + GetCtsTimeout (); - - NS_ASSERT (m_ctsTimeoutEvent.IsExpired ()); - NotifyCtsTimeoutStartNow (timerDelay); - m_ctsTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::CtsTimeout, this); - - Ptr packet = Create (); - packet->AddHeader (rts); - WifiMacTrailer fcs; - packet->AddTrailer (fcs); - - ForwardDown (packet, &rts, rtsTxMode); -} - -void -MacLow::StartDataTxTimers (void) -{ - WifiMode dataTxMode = GetDataTxMode (m_currentPacket, &m_currentHdr); - Time txDuration = m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), dataTxMode, WIFI_PREAMBLE_LONG); - if (m_txParams.MustWaitNormalAck ()) - { - Time timerDelay = txDuration + GetAckTimeout (); - NS_ASSERT (m_normalAckTimeoutEvent.IsExpired ()); - NotifyAckTimeoutStartNow (timerDelay); - m_normalAckTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::NormalAckTimeout, this); - } - else if (m_txParams.MustWaitFastAck ()) - { - Time timerDelay = txDuration + GetPifs (); - NS_ASSERT (m_fastAckTimeoutEvent.IsExpired ()); - NotifyAckTimeoutStartNow (timerDelay); - m_fastAckTimeoutEvent = Simulator::Schedule (timerDelay, &MacLow::FastAckTimeout, this); - } - else if (m_txParams.MustWaitSuperFastAck ()) - { - Time timerDelay = txDuration + GetPifs (); - NS_ASSERT (m_superFastAckTimeoutEvent.IsExpired ()); - NotifyAckTimeoutStartNow (timerDelay); - m_superFastAckTimeoutEvent = Simulator::Schedule (timerDelay, - &MacLow::SuperFastAckTimeout, this); - } - else if (m_txParams.HasNextPacket ()) - { - Time delay = txDuration + GetSifs (); - NS_ASSERT (m_waitSifsEvent.IsExpired ()); - m_waitSifsEvent = Simulator::Schedule (delay, &MacLow::WaitSifsAfterEndTx, this); - } - else - { - // since we do not expect any timer to be triggered. - m_listener = 0; - } -} - -void -MacLow::SendDataPacket (void) -{ - NS_LOG_FUNCTION (this); - /* send this packet directly. No RTS is needed. */ - StartDataTxTimers (); - - WifiMode dataTxMode = GetDataTxMode (m_currentPacket, &m_currentHdr); - Time duration = Seconds (0.0); - if (m_txParams.HasDurationId ()) - { - duration += m_txParams.GetDurationId (); - } - else - { - if (m_txParams.MustWaitAck ()) - { - duration += GetSifs (); - duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxMode); - } - if (m_txParams.HasNextPacket ()) - { - duration += GetSifs (); - duration += m_phy->CalculateTxDuration (m_txParams.GetNextPacketSize (), - dataTxMode, WIFI_PREAMBLE_LONG); - if (m_txParams.MustWaitAck ()) - { - duration += GetSifs (); - duration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxMode); - } - } - } - m_currentHdr.SetDuration (duration); - - m_currentPacket->AddHeader (m_currentHdr); - WifiMacTrailer fcs; - m_currentPacket->AddTrailer (fcs); - - ForwardDown (m_currentPacket, &m_currentHdr, dataTxMode); - m_currentPacket = 0; -} - -bool -MacLow::IsNavZero (void) const -{ - if (m_lastNavStart + m_lastNavDuration < Simulator::Now ()) - { - return true; - } - else - { - return false; - } -} - -WifiRemoteStation * -MacLow::GetStation (Mac48Address ad) const -{ - return m_stationManager->Lookup (ad); -} - -void -MacLow::SendCtsAfterRts (Mac48Address source, Time duration, WifiMode rtsTxMode, double rtsSnr) -{ - NS_LOG_FUNCTION (this << source << duration << rtsTxMode << rtsSnr); - /* send a CTS when you receive a RTS - * right after SIFS. - */ - WifiMode ctsTxMode = GetCtsTxModeForRts (source, rtsTxMode); - WifiMacHeader cts; - cts.SetType (WIFI_MAC_CTL_CTS); - cts.SetDsNotFrom (); - cts.SetDsNotTo (); - cts.SetNoMoreFragments (); - cts.SetNoRetry (); - cts.SetAddr1 (source); - duration -= GetCtsDuration (source, rtsTxMode); - duration -= GetSifs (); - NS_ASSERT (duration >= MicroSeconds (0)); - cts.SetDuration (duration); - - Ptr packet = Create (); - packet->AddHeader (cts); - WifiMacTrailer fcs; - packet->AddTrailer (fcs); - - struct SnrTag tag; - tag.Set (rtsSnr); - packet->AddPacketTag (tag); - - ForwardDown (packet, &cts, ctsTxMode); -} - -void -MacLow::SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode) -{ - NS_LOG_FUNCTION (this); - /* send the third step in a - * RTS/CTS/DATA/ACK hanshake - */ - NS_ASSERT (m_currentPacket != 0); - StartDataTxTimers (); - - WifiMode dataTxMode = GetDataTxMode (m_currentPacket, &m_currentHdr); - Time newDuration = Seconds (0); - newDuration += GetSifs (); - newDuration += GetAckDuration (m_currentHdr.GetAddr1 (), dataTxMode); - Time txDuration = m_phy->CalculateTxDuration (GetSize (m_currentPacket, &m_currentHdr), - dataTxMode, WIFI_PREAMBLE_LONG); - duration -= txDuration; - duration -= GetSifs (); - - duration = std::max (duration, newDuration); - NS_ASSERT (duration >= MicroSeconds (0)); - m_currentHdr.SetDuration (duration); - - m_currentPacket->AddHeader (m_currentHdr); - WifiMacTrailer fcs; - m_currentPacket->AddTrailer (fcs); - - ForwardDown (m_currentPacket, &m_currentHdr, dataTxMode); - m_currentPacket = 0; -} - -void -MacLow::WaitSifsAfterEndTx (void) -{ - m_listener->StartNext (); -} - -void -MacLow::FastAckFailedTimeout (void) -{ - NS_LOG_FUNCTION (this); - MacLowTransmissionListener *listener = m_listener; - m_listener = 0; - listener->MissedAck (); - NS_LOG_DEBUG ("fast Ack busy but missed"); -} - -void -MacLow::SendAckAfterData (Mac48Address source, Time duration, WifiMode dataTxMode, double dataSnr) -{ - NS_LOG_FUNCTION (this); - /* send an ACK when you receive - * a packet after SIFS. - */ - WifiMode ackTxMode = GetAckTxModeForData (source, dataTxMode); - WifiMacHeader ack; - ack.SetType (WIFI_MAC_CTL_ACK); - ack.SetDsNotFrom (); - ack.SetDsNotTo (); - ack.SetNoRetry (); - ack.SetNoMoreFragments (); - ack.SetAddr1 (source); - duration -= GetAckDuration (source, dataTxMode); - duration -= GetSifs (); - NS_ASSERT (duration >= MicroSeconds (0)); - ack.SetDuration (duration); - - Ptr packet = Create (); - packet->AddHeader (ack); - WifiMacTrailer fcs; - packet->AddTrailer (fcs); - - struct SnrTag tag; - tag.Set (dataSnr); - packet->AddPacketTag (tag); - - ForwardDown (packet, &ack, ackTxMode); -} - -} // namespace ns3 +/home/quincy/code/ns3/devices/wifi/mac-low.cc \ No newline at end of file diff -r f8f2a9d65576 src/devices/wifi/mac-low.h --- a/src/devices/wifi/mac-low.h Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/mac-low.h Mon Mar 15 13:17:33 2010 +1100 @@ -1,454 +1,1 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005, 2006 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef MAC_LOW_H -#define MAC_LOW_H - -#include -#include -#include - -#include "wifi-mac-header.h" -#include "wifi-mode.h" -#include "wifi-preamble.h" -#include "wifi-remote-station-manager.h" -#include "ns3/mac48-address.h" -#include "ns3/callback.h" -#include "ns3/event-id.h" -#include "ns3/packet.h" -#include "ns3/nstime.h" - -namespace ns3 { - -class WifiPhy; -class WifiMac; - -/** - * \brief listen to events coming from ns3::MacLow. - */ -class MacLowTransmissionListener { -public: - MacLowTransmissionListener (); - virtual ~MacLowTransmissionListener (); - - /** - * \param snr the snr of the cts - * \param txMode the txMode of the cts - * - * ns3::MacLow received an expected CTS within - * CtsTimeout. - */ - virtual void GotCts (double snr, WifiMode txMode) = 0; - /** - * ns3::MacLow did not receive an expected CTS - * within CtsTimeout. - */ - virtual void MissedCts (void) = 0; - /** - * \param snr the snr of the ack - * \param txMode the transmission mode of the ack - * - * ns3::MacLow received an expected ACL within - * AckTimeout. The snr and txMode - * arguments are not valid when SUPER_FAST_ACK is - * used. - */ - virtual void GotAck (double snr, WifiMode txMode) = 0; - /** - * ns3::MacLow did not receive an expected ACK within - * AckTimeout. - */ - virtual void MissedAck (void) = 0; - /** - * Invoked when ns3::MacLow wants to start a new transmission - * as configured by MacLowTransmissionParameters::EnableNextData. - * The listener is expected to call again MacLow::StartTransmission - * with the "next" data to send. - */ - virtual void StartNext (void) = 0; - - /** - * Invoked if this transmission was canceled - * one way or another. When this method is invoked, - * you can assume that the packet has not been passed - * down the stack to the PHY. - */ - virtual void Cancel (void) = 0; -}; - - -/** - * \brief listen to NAV events - * - * This class is typically connected to an instance of ns3::Dcf - * and calls to its methods are forwards to the corresponding - * ns3::Dcf methods. - */ -class MacLowDcfListener { -public: - MacLowDcfListener (); - virtual ~MacLowDcfListener (); - /** - * \param duration duration of NAV timer - */ - virtual void NavStart (Time duration) = 0; - /** - * \param duration duration of NAV timer - */ - virtual void NavReset (Time duration) = 0; - virtual void AckTimeoutStart (Time duration) = 0; - virtual void AckTimeoutReset () = 0; - virtual void CtsTimeoutStart (Time duration) = 0; - virtual void CtsTimeoutReset () = 0; -}; - -/** - * \brief control how a packet is transmitted. - * - * The ns3::MacLow::StartTransmission method expects - * an instance of this class to describe how the packet - * should be transmitted. - */ -class MacLowTransmissionParameters { -public: - MacLowTransmissionParameters (); - - /** - * Wait ACKTimeout for an ACK. If we get an ACK - * on time, call MacLowTransmissionListener::GotAck. - * Call MacLowTransmissionListener::MissedAck otherwise. - */ - void EnableAck (void); - /** - * - wait PIFS after end-of-tx. If idle, call - * MacLowTransmissionListener::MissedAck. - * - if busy at end-of-tx+PIFS, wait end-of-rx - * - if Ack ok at end-of-rx, call - * MacLowTransmissionListener::GotAck. - * - if Ack not ok at end-of-rx, report call - * MacLowTransmissionListener::MissedAck - * at end-of-rx+SIFS. - * - * This is really complicated but it is needed for - * proper HCCA support. - */ - void EnableFastAck (void); - /** - * - if busy at end-of-tx+PIFS, call - * MacLowTransmissionListener::GotAck - * - if idle at end-of-tx+PIFS, call - * MacLowTransmissionListener::MissedAck - */ - void EnableSuperFastAck (void); - /** - * Send a RTS, and wait CTSTimeout for a CTS. If we get a - * CTS on time, call MacLowTransmissionListener::GotCts - * and send data. Otherwise, call MacLowTransmissionListener::MissedCts - * and do not send data. - */ - void EnableRts (void); - /** - * \param size size of next data to send after current packet is - * sent. - * - * Add the transmission duration of the next data to the - * durationId of the outgoing packet and call - * MacLowTransmissionListener::StartNext at the end of - * the current transmission + SIFS. - */ - void EnableNextData (uint32_t size); - - /** - * \param durationId the value to set in the duration/Id field of - * the outgoing packet. - * - * Ignore all other durationId calculation and simply force the - * packet's durationId field to this value. - */ - void EnableOverrideDurationId (Time durationId); - - /** - * Do not wait for Ack after data transmission. Typically - * used for Broadcast and multicast frames. - */ - void DisableAck (void); - /** - * Do not send rts and wait for cts before sending data. - */ - void DisableRts (void); - /** - * Do not attempt to send data burst after current transmission - */ - void DisableNextData (void); - /** - * Do not force the duration/id field of the packet: its - * value is automatically calculated by the MacLow before - * calling WifiPhy::Send. - */ - void DisableOverrideDurationId (void); - - /** - * \returns true if must wait for ACK after data transmission, - * false otherwise. - * - * This methods returns true when any of MustWaitNormalAck, - * MustWaitFastAck, or MustWaitSuperFastAck return true. - */ - bool MustWaitAck (void) const; - /** - * \returns true if normal ACK protocol should be used, false - * otherwise. - * - * \sa EnableAck - */ - bool MustWaitNormalAck (void) const; - /** - * \returns true if fast ack protocol should be used, false - * otherwise. - * - * \sa EnableFastAck - */ - bool MustWaitFastAck (void) const; - /** - * \returns true if super fast ack protocol should be used, false - * otherwise. - * - * \sa EnableSuperFastAck - */ - bool MustWaitSuperFastAck (void) const; - /** - * \returns true if RTS should be sent and CTS waited for before - * sending data, false otherwise. - */ - bool MustSendRts (void) const; - /** - * \returns true if a duration/id was forced with - * EnableOverrideDurationId, false otherwise. - */ - bool HasDurationId (void) const; - /** - * \returns the duration/id forced by EnableOverrideDurationId - */ - Time GetDurationId (void) const; - /** - * \returns true if EnableNextData was called, false otherwise. - */ - bool HasNextPacket (void) const; - /** - * \returns the size specified by EnableNextData. - */ - uint32_t GetNextPacketSize (void) const; - -private: - friend std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters ¶ms); - uint32_t m_nextSize; - enum { - ACK_NONE, - ACK_NORMAL, - ACK_FAST, - ACK_SUPER_FAST - } m_waitAck; - bool m_sendRts; - Time m_overrideDurationId; -}; - -std::ostream &operator << (std::ostream &os, const MacLowTransmissionParameters ¶ms); - - -/** - * \brief handle RTS/CTS/DATA/ACK transactions. - */ -class MacLow : public Object { -public: - typedef Callback, const WifiMacHeader*> MacLowRxCallback; - - MacLow (); - virtual ~MacLow (); - - void SetPhy (Ptr phy); - void SetWifiRemoteStationManager (Ptr manager); - - void SetAddress (Mac48Address ad); - void SetAckTimeout (Time ackTimeout); - void SetCtsTimeout (Time ctsTimeout); - void SetSifs (Time sifs); - void SetSlotTime (Time slotTime); - void SetPifs (Time pifs); - void SetBssid (Mac48Address ad); - Mac48Address GetAddress (void) const; - Time GetAckTimeout (void) const; - Time GetCtsTimeout (void) const; - Time GetSifs (void) const; - Time GetSlotTime (void) const; - Time GetPifs (void) const; - Mac48Address GetBssid (void) const; - - /** - * \param callback the callback which receives every incoming packet. - * - * This callback typically forwards incoming packets to - * an instance of ns3::MacRxMiddle. - */ - void SetRxCallback (Callback,const WifiMacHeader *> callback); - /** - * \param listener listen to NAV events for every incoming - * and outgoing packet. - */ - void RegisterDcfListener (MacLowDcfListener *listener); - - /** - * \param packet to send (does not include the 802.11 MAC header and checksum) - * \param hdr header associated to the packet to send. - * \param parameters transmission parameters of packet. - * - * This transmission time includes the time required for - * the next packet transmission if one was selected. - */ - Time CalculateTransmissionTime (Ptr packet, - const WifiMacHeader* hdr, - const MacLowTransmissionParameters& parameters) const; - - /** - * \param packet packet to send - * \param hdr 802.11 header for packet to send - * \param parameters the transmission parameters to use for this packet. - * \param listener listen to transmission events. - * - * Start the transmission of the input packet and notify the listener - * of transmission events. - */ - void StartTransmission (Ptr packet, - const WifiMacHeader* hdr, - MacLowTransmissionParameters parameters, - MacLowTransmissionListener *listener); - - /** - * \param packet packet received - * \param rxSnr snr of packet received - * \param txMode transmission mode of packet received - * \param preamble type of preamble used for the packet received - * - * This method is typically invoked by the lower PHY layer to notify - * the MAC layer that a packet was successfully received. - */ - void ReceiveOk (Ptr packet, double rxSnr, WifiMode txMode, WifiPreamble preamble); - /** - * \param packet packet received. - * \param rxSnr snr of packet received. - * - * This method is typically invoked by the lower PHY layer to notify - * the MAC layer that a packet was unsuccessfully received. - */ - void ReceiveError (Ptr packet, double rxSnr); - /** - * \param duration switching delay duration. - * - * This method is typically invoked by the PhyMacLowListener to notify - * the MAC layer that a channel switching occured. When a channel switching - * occurs, pending MAC transmissions (RTS, CTS, DATA and ACK) are cancelled. - */ - void NotifySwitchingStartNow (Time duration); -private: - void CancelAllEvents (void); - uint32_t GetAckSize (void) const; - uint32_t GetRtsSize (void) const; - uint32_t GetCtsSize (void) const; - uint32_t GetSize (Ptr packet, const WifiMacHeader *hdr) const; - Time NowUs (void) const; - WifiRemoteStation *GetStation (Mac48Address to) const; - void ForwardDown (Ptr packet, const WifiMacHeader *hdr, - WifiMode txMode); - Time CalculateOverallTxTime (Ptr packet, - const WifiMacHeader* hdr, - const MacLowTransmissionParameters ¶ms) const; - WifiMode GetRtsTxMode (Ptr packet, const WifiMacHeader *hdr) const; - WifiMode GetDataTxMode (Ptr packet, const WifiMacHeader *hdr) const; - WifiMode GetCtsTxModeForRts (Mac48Address to, WifiMode rtsTxMode) const; - WifiMode GetAckTxModeForData (Mac48Address to, WifiMode dataTxMode) const; - Time GetCtsDuration (Mac48Address to, WifiMode rtsTxMode) const; - Time GetAckDuration (Mac48Address to, WifiMode dataTxMode) const; - void NotifyNav (const WifiMacHeader &hdr, WifiMode txMode, WifiPreamble preamble); - void DoNavResetNow (Time duration); - bool DoNavStartNow (Time duration); - bool IsNavZero (void) const; - void NotifyAckTimeoutStartNow (Time duration); - void NotifyAckTimeoutResetNow (); - void NotifyCtsTimeoutStartNow (Time duration); - void NotifyCtsTimeoutResetNow (); - void MaybeCancelPrevious (void); - - void NavCounterResetCtsMissed (Time rtsEndRxTime); - void NormalAckTimeout (void); - void FastAckTimeout (void); - void SuperFastAckTimeout (void); - void FastAckFailedTimeout (void); - void CtsTimeout (void); - void SendCtsAfterRts (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr); - void SendAckAfterData (Mac48Address source, Time duration, WifiMode txMode, double rtsSnr); - void SendDataAfterCts (Mac48Address source, Time duration, WifiMode txMode); - void WaitSifsAfterEndTx (void); - - void SendRtsForPacket (void); - void SendDataPacket (void); - void SendCurrentTxPacket (void); - void StartDataTxTimers (void); - virtual void DoDispose (void); - - void SetupPhyMacLowListener (Ptr phy); - - Ptr m_phy; - Ptr m_stationManager; - MacLowRxCallback m_rxCallback; - typedef std::vector::const_iterator DcfListenersCI; - typedef std::vector DcfListeners; - DcfListeners m_dcfListeners; - - EventId m_normalAckTimeoutEvent; - EventId m_fastAckTimeoutEvent; - EventId m_superFastAckTimeoutEvent; - EventId m_fastAckFailedTimeoutEvent; - EventId m_ctsTimeoutEvent; - EventId m_sendCtsEvent; - EventId m_sendAckEvent; - EventId m_sendDataEvent; - EventId m_waitSifsEvent; - EventId m_navCounterResetCtsMissed; - - Ptr m_currentPacket; - WifiMacHeader m_currentHdr; - MacLowTransmissionParameters m_txParams; - MacLowTransmissionListener *m_listener; - Mac48Address m_self; - Mac48Address m_bssid; - Time m_ackTimeout; - Time m_ctsTimeout; - Time m_sifs; - Time m_slotTime; - Time m_pifs; - - Time m_lastNavStart; - Time m_lastNavDuration; - - // Listerner needed to monitor when a channel switching occurs. - class PhyMacLowListener *m_phyMacLowListener; -}; - -} // namespace ns3 - -#endif /* MAC_LOW_H */ +/home/quincy/code/ns3/devices/wifi/mac-low.h \ No newline at end of file diff -r f8f2a9d65576 src/devices/wifi/propagation-loss-model.cc --- a/src/devices/wifi/propagation-loss-model.cc Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/propagation-loss-model.cc Mon Mar 15 13:17:33 2010 +1100 @@ -1,546 +1,1 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005,2006,2007 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - * Contributions: Timo Bingmann - */ - -#include "propagation-loss-model.h" -#include "ns3/log.h" -#include "ns3/mobility-model.h" -#include "ns3/boolean.h" -#include "ns3/double.h" -#include - -NS_LOG_COMPONENT_DEFINE ("PropagationLossModel"); - -namespace ns3 { - -// ------------------------------------------------------------------------- // - -NS_OBJECT_ENSURE_REGISTERED (PropagationLossModel); - -TypeId -PropagationLossModel::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::PropagationLossModel") - .SetParent () - ; - return tid; -} - -PropagationLossModel::PropagationLossModel () - : m_next (0) -{} - -PropagationLossModel::~PropagationLossModel () -{} - -void -PropagationLossModel::SetNext (Ptr next) -{ - m_next = next; -} - -double -PropagationLossModel::CalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - double self = DoCalcRxPower (txPowerDbm, a, b); - if (m_next != 0) - { - self = m_next->CalcRxPower (self, a, b); - } - return self; -} - -// ------------------------------------------------------------------------- // - -NS_OBJECT_ENSURE_REGISTERED (RandomPropagationLossModel); - -TypeId -RandomPropagationLossModel::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::RandomPropagationLossModel") - .SetParent () - .AddConstructor () - .AddAttribute ("Variable", "The random variable used to pick a loss everytime CalcRxPower is invoked.", - RandomVariableValue (ConstantVariable (1.0)), - MakeRandomVariableAccessor (&RandomPropagationLossModel::m_variable), - MakeRandomVariableChecker ()) - ; - return tid; -} -RandomPropagationLossModel::RandomPropagationLossModel () - : PropagationLossModel () -{} - -RandomPropagationLossModel::~RandomPropagationLossModel () -{} - -double -RandomPropagationLossModel::DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - double rxc = -m_variable.GetValue (); - NS_LOG_DEBUG ("attenuation coefficent="< () - .AddConstructor () - .AddAttribute ("Lambda", - "The wavelength (default is 5.15 GHz at 300 000 km/s).", - DoubleValue (300000000.0 / 5.150e9), - MakeDoubleAccessor (&FriisPropagationLossModel::m_lambda), - MakeDoubleChecker ()) - .AddAttribute ("SystemLoss", "The system loss", - DoubleValue (1.0), - MakeDoubleAccessor (&FriisPropagationLossModel::m_systemLoss), - MakeDoubleChecker ()) - .AddAttribute ("MinDistance", - "The distance under which the propagation model refuses to give results (m)", - DoubleValue (0.5), - MakeDoubleAccessor (&FriisPropagationLossModel::SetMinDistance, - &FriisPropagationLossModel::GetMinDistance), - MakeDoubleChecker ()) - ; - return tid; -} - -FriisPropagationLossModel::FriisPropagationLossModel () -{} -void -FriisPropagationLossModel::SetSystemLoss (double systemLoss) -{ - m_systemLoss = systemLoss; -} -double -FriisPropagationLossModel::GetSystemLoss (void) const -{ - return m_systemLoss; -} -void -FriisPropagationLossModel::SetMinDistance (double minDistance) -{ - m_minDistance = minDistance; -} -double -FriisPropagationLossModel::GetMinDistance (void) const -{ - return m_minDistance; -} -void -FriisPropagationLossModel::SetLambda (double frequency, double speed) -{ - m_lambda = speed / frequency; -} -void -FriisPropagationLossModel::SetLambda (double lambda) -{ - m_lambda = lambda; -} -double -FriisPropagationLossModel::GetLambda (void) const -{ - return m_lambda; -} - -double -FriisPropagationLossModel::DbmToW (double dbm) const -{ - double mw = pow(10.0,dbm/10.0); - return mw / 1000.0; -} - -double -FriisPropagationLossModel::DbmFromW (double w) const -{ - double dbm = log10 (w * 1000.0) * 10.0; - return dbm; -} - -double -FriisPropagationLossModel::DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - /* - * Friis free space equation: - * where Pt, Gr, Gr and P are in Watt units - * L is in meter units. - * - * P Gt * Gr * (lambda^2) - * --- = --------------------- - * Pt (4 * pi * d)^2 * L - * - * Gt: tx gain (unit-less) - * Gr: rx gain (unit-less) - * Pt: tx power (W) - * d: distance (m) - * L: system loss - * lambda: wavelength (m) - * - * Here, we ignore tx and rx gain and the input and output values - * are in dB or dBm: - * - * lambda^2 - * rx = tx + 10 log10 (-------------------) - * (4 * pi * d)^2 * L - * - * rx: rx power (dB) - * tx: tx power (dB) - * d: distance (m) - * L: system loss (unit-less) - * lambda: wavelength (m) - */ - double distance = a->GetDistanceFrom (b); - if (distance <= m_minDistance) - { - return txPowerDbm; - } - double numerator = m_lambda * m_lambda; - double denominator = 16 * PI * PI * distance * distance * m_systemLoss; - double pr = 10 * log10 (numerator / denominator); - NS_LOG_DEBUG ("distance="< () - .AddConstructor () - .AddAttribute ("Exponent", - "The exponent of the Path Loss propagation model", - DoubleValue (3.0), - MakeDoubleAccessor (&LogDistancePropagationLossModel::m_exponent), - MakeDoubleChecker ()) - .AddAttribute ("ReferenceDistance", - "The distance at which the reference loss is calculated (m)", - DoubleValue (1.0), - MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceDistance), - MakeDoubleChecker ()) - .AddAttribute ("ReferenceLoss", - "The reference loss at reference distance (dB). (Default is Friis at 1m with 5.15 GHz)", - DoubleValue (46.6777), - MakeDoubleAccessor (&LogDistancePropagationLossModel::m_referenceLoss), - MakeDoubleChecker ()) - ; - return tid; - -} - -LogDistancePropagationLossModel::LogDistancePropagationLossModel () -{} - -void -LogDistancePropagationLossModel::SetPathLossExponent (double n) -{ - m_exponent = n; -} -void -LogDistancePropagationLossModel::SetReference (double referenceDistance, double referenceLoss) -{ - m_referenceDistance = referenceDistance; - m_referenceLoss = referenceLoss; -} -double -LogDistancePropagationLossModel::GetPathLossExponent (void) const -{ - return m_exponent; -} - -double -LogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - double distance = a->GetDistanceFrom (b); - if (distance <= m_referenceDistance) - { - return txPowerDbm; - } - /** - * The formula is: - * rx = 10 * log (Pr0(tx)) - n * 10 * log (d/d0) - * - * Pr0: rx power at reference distance d0 (W) - * d0: reference distance: 1.0 (m) - * d: distance (m) - * tx: tx power (dB) - * rx: dB - * - * Which, in our case is: - * - * rx = rx0(tx) - 10 * n * log (d/d0) - */ - double pathLossDb = 10 * m_exponent * log10 (distance / m_referenceDistance); - double rxc = -m_referenceLoss - pathLossDb; - NS_LOG_DEBUG ("distance="< () - .AddConstructor () - .AddAttribute ("Distance0", - "Beginning of the first (near) distance field", - DoubleValue (1.0), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance0), - MakeDoubleChecker ()) - .AddAttribute ("Distance1", - "Beginning of the second (middle) distance field.", - DoubleValue (200.0), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance1), - MakeDoubleChecker ()) - .AddAttribute ("Distance2", - "Beginning of the third (far) distance field.", - DoubleValue (500.0), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_distance2), - MakeDoubleChecker ()) - .AddAttribute ("Exponent0", - "The exponent for the first field.", - DoubleValue (1.9), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent0), - MakeDoubleChecker ()) - .AddAttribute ("Exponent1", - "The exponent for the second field.", - DoubleValue (3.8), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent1), - MakeDoubleChecker ()) - .AddAttribute ("Exponent2", - "The exponent for the third field.", - DoubleValue (3.8), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_exponent2), - MakeDoubleChecker ()) - .AddAttribute ("ReferenceLoss", - "The reference loss at distance d0 (dB). (Default is Friis at 1m with 5.15 GHz)", - DoubleValue (46.6777), - MakeDoubleAccessor (&ThreeLogDistancePropagationLossModel::m_referenceLoss), - MakeDoubleChecker ()) - ; - return tid; - -} - -ThreeLogDistancePropagationLossModel::ThreeLogDistancePropagationLossModel () -{ -} - -double -ThreeLogDistancePropagationLossModel::DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - double distance = a->GetDistanceFrom (b); - NS_ASSERT(distance >= 0); - - // See doxygen comments for the formula and explanation - - double pathLossDb; - - if (distance < m_distance0) - { - pathLossDb = 0; - } - else if (distance < m_distance1) - { - pathLossDb = m_referenceLoss - + 10 * m_exponent0 * log10(distance / m_distance0); - } - else if (distance < m_distance2) - { - pathLossDb = m_referenceLoss - + 10 * m_exponent0 * log10(m_distance1 / m_distance0) - + 10 * m_exponent1 * log10(distance / m_distance1); - } - else - { - pathLossDb = m_referenceLoss - + 10 * m_exponent0 * log10(m_distance1 / m_distance0) - + 10 * m_exponent1 * log10(m_distance2 / m_distance1) - + 10 * m_exponent2 * log10(distance / m_distance2); - } - - NS_LOG_DEBUG ("ThreeLogDistance distance=" << distance << "m, " << - "attenuation=" << pathLossDb << "dB"); - - return txPowerDbm - pathLossDb; -} - -// ------------------------------------------------------------------------- // - -NS_OBJECT_ENSURE_REGISTERED (NakagamiPropagationLossModel); - -TypeId -NakagamiPropagationLossModel::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::NakagamiPropagationLossModel") - .SetParent () - .AddConstructor () - .AddAttribute ("Distance1", - "Beginning of the second distance field. Default is 80m.", - DoubleValue (80.0), - MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance1), - MakeDoubleChecker ()) - .AddAttribute ("Distance2", - "Beginning of the third distance field. Default is 200m.", - DoubleValue (200.0), - MakeDoubleAccessor (&NakagamiPropagationLossModel::m_distance2), - MakeDoubleChecker ()) - .AddAttribute ("m0", - "m0 for distances smaller than Distance1. Default is 1.5.", - DoubleValue (1.5), - MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m0), - MakeDoubleChecker ()) - .AddAttribute ("m1", - "m1 for distances smaller than Distance2. Default is 0.75.", - DoubleValue (0.75), - MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m1), - MakeDoubleChecker ()) - .AddAttribute ("m2", - "m2 for distances greater than Distance2. Default is 0.75.", - DoubleValue (0.75), - MakeDoubleAccessor (&NakagamiPropagationLossModel::m_m2), - MakeDoubleChecker ()) - ; - return tid; - -} - -NakagamiPropagationLossModel::NakagamiPropagationLossModel () -{} - -double -NakagamiPropagationLossModel::DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - // select m parameter - - double distance = a->GetDistanceFrom (b); - NS_ASSERT(distance >= 0); - - double m; - if (distance < m_distance1) - { - m = m_m0; - } - else if (distance < m_distance2) - { - m = m_m1; - } - else - { - m = m_m2; - } - - // the current power unit is dBm, but Watt is put into the Nakagami / - // Rayleigh distribution. - double powerW = pow(10, (txPowerDbm - 30) / 10); - - double resultPowerW; - - // switch between Erlang- and Gamma distributions: this is only for - // speed. (Gamma is equal to Erlang for any positive integer m.) - unsigned int int_m = static_cast(floor(m)); - - if (int_m == m) - { - resultPowerW = m_erlangRandomVariable.GetValue(int_m, powerW / m); - } - else - { - resultPowerW = m_gammaRandomVariable.GetValue(m, powerW / m); - } - - double resultPowerDbm = 10 * log10(resultPowerW) + 30; - - NS_LOG_DEBUG ("Nakagami distance=" << distance << "m, " << - "power=" << powerW <<"W, " << - "resultPower=" << resultPowerW << "W=" << resultPowerDbm << "dBm"); - - return resultPowerDbm; -} - -// ------------------------------------------------------------------------- // - -NS_OBJECT_ENSURE_REGISTERED (FixedRssLossModel); - -TypeId -FixedRssLossModel::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::FixedRssLossModel") - .SetParent () - .AddConstructor () - .AddAttribute ("Rss", "The fixed receiver Rss.", - DoubleValue (-150.0), - MakeDoubleAccessor (&FixedRssLossModel::m_rss), - MakeDoubleChecker ()) - ; - return tid; -} -FixedRssLossModel::FixedRssLossModel () - : PropagationLossModel () -{} - -FixedRssLossModel::~FixedRssLossModel () -{} - -void -FixedRssLossModel::SetRss (double rss) -{ - m_rss = rss; -} - -double -FixedRssLossModel::DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const -{ - return m_rss; -} - -// ------------------------------------------------------------------------- // - -} // namespace ns3 +/home/quincy/code/ns3/devices/wifi/propagation-loss-model.cc \ No newline at end of file diff -r f8f2a9d65576 src/devices/wifi/propagation-loss-model.h --- a/src/devices/wifi/propagation-loss-model.h Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/propagation-loss-model.h Mon Mar 15 13:17:33 2010 +1100 @@ -1,375 +1,1 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005,2006,2007 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - * Contributions: Timo Bingmann - * Contributions: Gary Pei for fixed RSS - */ - -#ifndef PROPAGATION_LOSS_MODEL_H -#define PROPAGATION_LOSS_MODEL_H - -#include "ns3/object.h" -#include "ns3/random-variable.h" - -namespace ns3 { - -class MobilityModel; - -/** - * \brief Modelize the propagation loss through a transmission medium - * - * Calculate the receive power (dbm) from a transmit power (dbm) - * and a mobility model for the source and destination positions. - */ -class PropagationLossModel : public Object -{ -public: - static TypeId GetTypeId (void); - - PropagationLossModel (); - virtual ~PropagationLossModel (); - - void SetNext (Ptr next); - - /** - * \param txPowerDbm current transmission power (in dBm) - * \param a the mobility model of the source - * \param b the mobility model of the destination - * \returns the reception power after adding/multiplying propagation loss (in dBm) - */ - double CalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; -private: - PropagationLossModel (const PropagationLossModel &o); - PropagationLossModel &operator = (const PropagationLossModel &o); - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const = 0; - - Ptr m_next; -}; - -/** - * \brief The propagation loss follows a random distribution. - */ -class RandomPropagationLossModel : public PropagationLossModel -{ -public: - static TypeId GetTypeId (void); - - RandomPropagationLossModel (); - virtual ~RandomPropagationLossModel (); - -private: - RandomPropagationLossModel (const RandomPropagationLossModel &o); - RandomPropagationLossModel & operator = (const RandomPropagationLossModel &o); - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; - RandomVariable m_variable; -}; - -/** - * \brief a Friis propagation loss model - * - * The Friis propagation loss model was first described in - * "A Note on a Simple Transmission Formula", by - * "Harald T. Friis". - * - * The original equation was described as: - * \f$ \frac{P_r}{P_t} = \frac{A_r A_t}{d^2\lambda^2} \f$ - * with the following equation for the case of an - * isotropic antenna with no heat loss: - * \f$ A_{isotr.} = \frac{\lambda^2}{4\pi} \f$ - * - * The final equation becomes: - * \f$ \frac{P_r}{P_t} = \frac{\lambda^2}{(4 \pi d)^2} \f$ - * - * Modern extensions to this original equation are: - * \f$ P_r = \frac{P_t G_t G_r \lambda^2}{(4 \pi d)^2 L}\f$ - * - * With: - * - \f$ P_r \f$ : reception power (W) - * - \f$ P_t \f$ : transmission power (W) - * - \f$ G_t \f$ : transmission gain (unit-less) - * - \f$ G_r \f$ : reception gain (unit-less) - * - \f$ \lambda \f$ : wavelength (m) - * - \f$ d \f$ : distance (m) - * - \f$ L \f$ : system loss (unit-less) - * - * - * This model is invalid for small distance values. - * The current implementation returns the txpower as the rxpower - * for any distance smaller than MinDistance. - */ -class FriisPropagationLossModel : public PropagationLossModel -{ -public: - static TypeId GetTypeId (void); - FriisPropagationLossModel (); - /** - * \param frequency (Hz) - * \param speed (m/s) - * - * Set the main wavelength used in the Friis model - * calculation. - */ - void SetLambda (double frequency, double speed); - /** - * \param lambda (m) the wavelength - * - * Set the main wavelength used in the Friis model - * calculation. - */ - void SetLambda (double lambda); - /** - * \param systemLoss (dimension-less) - * - * Set the system loss used by the Friis propagation model. - */ - void SetSystemLoss (double systemLoss); - - /** - * \param minDistance the minimum distance - * - * Below this distance, the txpower is returned - * unmodified as the rxpower. - */ - void SetMinDistance (double minDistance); - - /** - * \returns the minimum distance. - */ - double GetMinDistance (void) const; - - /** - * \returns the current wavelength (m) - */ - double GetLambda (void) const; - /** - * \returns the current system loss (dimention-less) - */ - double GetSystemLoss (void) const; - -private: - FriisPropagationLossModel (const FriisPropagationLossModel &o); - FriisPropagationLossModel & operator = (const FriisPropagationLossModel &o); - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; - double DbmToW (double dbm) const; - double DbmFromW (double w) const; - - static const double PI; - double m_lambda; - double m_systemLoss; - double m_minDistance; -}; - -/** - * \brief a log distance propagation model. - * - * This model calculates the reception power with a so-called - * log-distance propagation model: - * \f$ L = L_0 + 10 n log_{10}(\frac{d}{d_0})\f$ - * - * where: - * - \f$ n \f$ : the path loss distance exponent - * - \f$ d_0 \f$ : reference distance (m) - * - \f$ L_0 \f$ : path loss at reference distance (dB) - * - \f$ d \f$ : distance (m) - * - \f$ L \f$ : path loss (dB) - * - * When the path loss is requested at a distance smaller than - * the reference distance, the tx power is returned. - * - */ -class LogDistancePropagationLossModel : public PropagationLossModel -{ -public: - static TypeId GetTypeId (void); - LogDistancePropagationLossModel (); - - /** - * \param n the path loss exponent. - * Set the path loss exponent. - */ - void SetPathLossExponent (double n); - /** - * \returns the current path loss exponent. - */ - double GetPathLossExponent (void) const; - - void SetReference (double referenceDistance, double referenceLoss); - -private: - LogDistancePropagationLossModel (const LogDistancePropagationLossModel &o); - LogDistancePropagationLossModel & operator = (const LogDistancePropagationLossModel &o); - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; - static Ptr CreateDefaultReference (void); - - double m_exponent; - double m_referenceDistance; - double m_referenceLoss; -}; - -/** - * \brief A log distance path loss propagation model with three distance - * fields. This model is the same as ns3::LogDistancePropagationLossModel - * except that it has three distance fields: near, middle and far with - * different exponents. - * - * Within each field the reception power is calculated using the log-distance - * propagation equation: - * \f[ L = L_0 + 10 \cdot n_0 log_{10}(\frac{d}{d_0})\f] - * Each field begins where the previous ends and all together form a continuous function. - * - * There are three valid distance fields: near, middle, far. Actually four: the - * first from 0 to the reference distance is invalid and returns txPowerDbm. - * - * \f[ \underbrace{0 \cdots\cdots}_{=0} \underbrace{d_0 \cdots\cdots}_{n_0} \underbrace{d_1 \cdots\cdots}_{n_1} \underbrace{d_2 \cdots\cdots}_{n_2} \infty \f] - * - * Complete formula for the path loss in dB: - * - * \f[\displaystyle L = -\begin{cases} -0 & d < d_0 \\ -L_0 + 10 \cdot n_0 \log_{10}(\frac{d}{d_0}) & d_0 \leq d < d_1 \\ -L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d}{d_1}) & d_1 \leq d < d_2 \\ -L_0 + 10 \cdot n_0 \log_{10}(\frac{d_1}{d_0}) + 10 \cdot n_1 \log_{10}(\frac{d_2}{d_1}) + 10 \cdot n_2 \log_{10}(\frac{d}{d_2})& d_2 \leq d -\end{cases}\f] - * - * where: - * - \f$ L \f$ : resulting path loss (dB) - * - \f$ d \f$ : distance (m) - * - \f$ d_0, d_1, d_2 \f$ : three distance fields (m) - * - \f$ n_0, n_1, n_2 \f$ : path loss distance exponent for each field (unitless) - * - \f$ L_0 \f$ : path loss at reference distance (dB) - * - * When the path loss is requested at a distance smaller than the reference - * distance \f$ d_0 \f$, the tx power (with no path loss) is returned. The - * reference distance defaults to 1m and reference loss defaults to - * ns3::FriisPropagationLossModel with 5.15 GHz and is thus \f$ L_0 \f$ = 46.67 dB. - */ - -class ThreeLogDistancePropagationLossModel : public PropagationLossModel -{ -public: - static TypeId GetTypeId (void); - ThreeLogDistancePropagationLossModel (); - - // Parameters are all accessible via attributes. - -private: - ThreeLogDistancePropagationLossModel (const ThreeLogDistancePropagationLossModel& o); - ThreeLogDistancePropagationLossModel& operator= (const ThreeLogDistancePropagationLossModel& o); - - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; - - double m_distance0; - double m_distance1; - double m_distance2; - - double m_exponent0; - double m_exponent1; - double m_exponent2; - - double m_referenceLoss; -}; - -/** - * \brief Nakagami-m fast fading propagation loss model. - * - * The Nakagami-m distribution is applied to the power level. The probability - * density function is defined as - * \f[ p(x; m, \omega) = \frac{2 m^m}{\Gamma(m) \omega^m} x^{2m - 1} e^{-\frac{m}{\omega} x^2} = 2 x \cdot p_{\text{Gamma}}(x^2, m, \frac{m}{\omega}) \f] - * with \f$ m \f$ the fading depth parameter and \f$ \omega \f$ the average received power. - * - * It is implemented by either a ns3::GammaVariable or a ns3::ErlangVariable - * random variable. - * - * Like in ns3::ThreeLogDistancePropagationLossModel, the m parameter is varied - * over three distance fields: - * \f[ \underbrace{0 \cdots\cdots}_{m_0} \underbrace{d_1 \cdots\cdots}_{m_1} \underbrace{d_2 \cdots\cdots}_{m_2} \infty \f] - * - * For m = 1 the Nakagami-m distribution equals the Rayleigh distribution. Thus - * this model also implements Rayleigh distribution based fast fading. - */ - -class NakagamiPropagationLossModel : public PropagationLossModel -{ -public: - static TypeId GetTypeId (void); - - NakagamiPropagationLossModel (); - - // Parameters are all accessible via attributes. - -private: - NakagamiPropagationLossModel (const NakagamiPropagationLossModel& o); - NakagamiPropagationLossModel& operator= (const NakagamiPropagationLossModel& o); - - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; - - double m_distance1; - double m_distance2; - - double m_m0; - double m_m1; - double m_m2; - - ErlangVariable m_erlangRandomVariable; - GammaVariable m_gammaRandomVariable; -}; - -/** - * \brief The propagation loss is fixed. The user can set received power level. - */ -class FixedRssLossModel : public PropagationLossModel -{ -public: - static TypeId GetTypeId (void); - - FixedRssLossModel (); - virtual ~FixedRssLossModel (); - /** - * \param rss (dBm) the received signal strength - * - * Set the RSS. - */ - void SetRss (double rss); - -private: - FixedRssLossModel (const FixedRssLossModel &o); - FixedRssLossModel & operator = (const FixedRssLossModel &o); - virtual double DoCalcRxPower (double txPowerDbm, - Ptr a, - Ptr b) const; - double m_rss; -}; - -} // namespace ns3 - -#endif /* PROPAGATION_LOSS_MODEL_H */ +/home/quincy/code/ns3/devices/wifi/propagation-loss-model.h \ No newline at end of file diff -r f8f2a9d65576 src/devices/wifi/wscript --- a/src/devices/wifi/wscript Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/wscript Mon Mar 15 13:17:33 2010 +1100 @@ -1,122 +1,1 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- - -def build(bld): - obj = bld.create_ns3_module('wifi', ['node']) - obj.source = [ - 'propagation-delay-model.cc', - 'propagation-loss-model.cc', - 'propagation-loss-model-test-suite.cc', - 'jakes-propagation-loss-model.cc', - 'wifi-channel.cc', - 'wifi-mode.cc', - 'ssid.cc', - 'wifi-phy.cc', - 'wifi-phy-state-helper.cc', - 'error-rate-model.cc', - 'yans-error-rate-model.cc', - 'interference-helper.cc', - 'interference-helper-tx-duration-test.cc', - 'yans-wifi-phy.cc', - 'yans-wifi-channel.cc', - 'wifi-mac-header.cc', - 'wifi-mac-trailer.cc', - 'mac-low.cc', - 'wifi-mac-queue.cc', - 'mac-tx-middle.cc', - 'mac-rx-middle.cc', - 'dca-txop.cc', - 'supported-rates.cc', - 'capability-information.cc', - 'status-code.cc', - 'mgt-headers.cc', - 'random-stream.cc', - 'dcf-manager.cc', - 'dcf-manager-test.cc', - 'wifi-mac.cc', - 'wifi-remote-station-manager.cc', - 'adhoc-wifi-mac.cc', - 'nqap-wifi-mac.cc', - 'nqsta-wifi-mac.cc', - 'wifi-net-device.cc', - 'arf-wifi-manager.cc', - 'aarf-wifi-manager.cc', - 'ideal-wifi-manager.cc', - 'amrr-wifi-manager.cc', - 'onoe-wifi-manager.cc', - 'rraa-wifi-manager.cc', - 'aarfcd-wifi-manager.cc', - 'cara-wifi-manager.cc', - 'constant-rate-wifi-manager.cc', - 'wifi-test.cc', - 'qos-tag.cc', - 'qos-utils.cc', - 'qadhoc-wifi-mac.cc', - 'qap-wifi-mac.cc', - 'qsta-wifi-mac.cc', - 'edca-txop-n.cc', - 'msdu-aggregator.cc', - 'amsdu-subframe-header.cc', - 'msdu-standard-aggregator.cc', - 'minstrel-wifi-manager.cc', - 'dcf.cc', - ] - headers = bld.new_task_gen('ns3header') - headers.module = 'wifi' - headers.source = [ - 'propagation-delay-model.h', - 'propagation-loss-model.h', - 'jakes-propagation-loss-model.h', - 'wifi-net-device.h', - 'wifi-channel.h', - 'wifi-mode.h', - 'ssid.h', - 'wifi-preamble.h', - 'wifi-phy-standard.h', - 'yans-wifi-phy.h', - 'yans-wifi-channel.h', - 'wifi-phy.h', - 'interference-helper.h', - 'wifi-remote-station-manager.h', - 'arf-wifi-manager.h', - 'aarf-wifi-manager.h', - 'constant-rate-wifi-manager.h', - 'ideal-wifi-manager.h', - 'amrr-wifi-manager.h', - 'onoe-wifi-manager.h', - 'rraa-wifi-manager.h', - 'wifi-mac.h', - 'adhoc-wifi-mac.h', - 'nqsta-wifi-mac.h', - 'nqap-wifi-mac.h', - 'wifi-phy.h', - 'supported-rates.h', - 'error-rate-model.h', - 'yans-error-rate-model.h', - 'dca-txop.h', - 'wifi-mac-header.h', - 'qadhoc-wifi-mac.h', - 'qap-wifi-mac.h', - 'qsta-wifi-mac.h', - 'qos-utils.h', - 'edca-txop-n.h', - 'msdu-aggregator.h', - 'amsdu-subframe-header.h', - 'qos-tag.h', - 'mgt-headers.h', - 'status-code.h', - 'capability-information.h', - 'dcf-manager.h', - 'mac-rx-middle.h', - 'mac-low.h', - 'minstrel-wifi-manager.h', - 'dcf.h', - ] - - if bld.env['ENABLE_GSL']: - obj.uselib = 'GSL GSLCBLAS M' - - obj = bld.create_ns3_program('wifi-phy-test', - ['core', 'simulator', 'mobility', 'node', 'wifi']) - obj.source = 'wifi-phy-test.cc' - - +/home/quincy/code/ns3/devices/wifi/wscript \ No newline at end of file diff -r f8f2a9d65576 src/devices/wifi/yans-wifi-phy.cc --- a/src/devices/wifi/yans-wifi-phy.cc Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/yans-wifi-phy.cc Mon Mar 15 13:17:33 2010 +1100 @@ -726,7 +726,7 @@ { NS_ASSERT (m_txPowerBaseDbm <= m_txPowerEndDbm); NS_ASSERT (m_nTxPower > 0); - double dbm = m_txPowerBaseDbm + power * (m_txPowerEndDbm - m_txPowerBaseDbm) / m_nTxPower; + double dbm = m_txPowerBaseDbm + power * (m_txPowerEndDbm - m_txPowerBaseDbm) / (m_nTxPower == 1 ? 1 : m_nTxPower - 1); return dbm; } diff -r f8f2a9d65576 src/devices/wifi/yans-wifi-phy.h --- a/src/devices/wifi/yans-wifi-phy.h Wed Mar 10 11:11:38 2010 +0100 +++ b/src/devices/wifi/yans-wifi-phy.h Mon Mar 15 13:17:33 2010 +1100 @@ -1,193 +1,1 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005,2006 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#ifndef YANS_WIFI_PHY_H -#define YANS_WIFI_PHY_H - -#include -#include "ns3/callback.h" -#include "ns3/event-id.h" -#include "ns3/packet.h" -#include "ns3/object.h" -#include "ns3/traced-callback.h" -#include "ns3/nstime.h" -#include "ns3/ptr.h" -#include "ns3/random-variable.h" -#include "wifi-phy.h" -#include "wifi-mode.h" -#include "wifi-preamble.h" -#include "wifi-phy-standard.h" -#include "interference-helper.h" - - -namespace ns3 { - -class RandomUniform; -class RxEvent; -class YansWifiChannel; -class WifiPhyStateHelper; - - -/** - * \brief 802.11 PHY layer model - * - * This PHY implements a model of 802.11a. The model - * implemented here is based on the model described - * in "Yet Another Network Simulator", - * (http://cutebugs.net/files/wns2-yans.pdf). - * - * - * This PHY model depends on a channel loss and delay - * model as provided by the ns3::PropagationLossModel - * and ns3::PropagationDelayModel classes, both of which are - * members of the ns3::YansWifiChannel class. - */ -class YansWifiPhy : public WifiPhy -{ -public: - - static TypeId GetTypeId (void); - - YansWifiPhy (); - virtual ~YansWifiPhy (); - - void SetChannel (Ptr channel); - - /** - * \brief Set channel number. - * - * Channel center frequency = Channel starting frequency + 5 MHz * (nch - 1) - * - * where Starting channel frequency is standard-dependent, see SetStandard() - * as defined in IEEE 802.11-2007 17.3.8.3.2. - * - * YansWifiPhy can switch among different channels. Basically, YansWifiPhy - * has a private attribute m_channelNumber that identifies the channel the - * PHY operates on. Channel switching cannot interrupt an ongoing transmission. - * When PHY is in TX state, the channel switching is postponed until the end - * of the current transmission. When the PHY is in RX state, the channel - * switching causes the drop of the synchronized packet. - */ - void SetChannelNumber (uint16_t id); - /// Return current channel number, see SetChannelNumber() - uint16_t GetChannelNumber () const; - /// Return current center channel frequency in MHz, see SetСhannelNumber() - double GetChannelFrequencyMhz() const; - - void StartReceivePacket (Ptr packet, - double rxPowerDbm, - WifiMode mode, - WifiPreamble preamble); - - void SetRxNoiseFigure (double noiseFigureDb); - void SetTxPowerStart (double start); - void SetTxPowerEnd (double end); - void SetNTxPower (uint32_t n); - void SetTxGain (double gain); - void SetRxGain (double gain); - void SetEdThreshold (double threshold); - void SetCcaMode1Threshold (double threshold); - void SetErrorRateModel (Ptr rate); - void SetDevice (Ptr device); - void SetMobility (Ptr mobility); - double GetRxNoiseFigure (void) const; - double GetTxGain (void) const; - double GetRxGain (void) const; - double GetEdThreshold (void) const; - double GetCcaMode1Threshold (void) const; - Ptr GetErrorRateModel (void) const; - Ptr GetDevice (void) const; - Ptr GetMobility (void); - - - - - virtual double GetTxPowerStart (void) const; - virtual double GetTxPowerEnd (void) const; - virtual uint32_t GetNTxPower (void) const; - virtual void SetReceiveOkCallback (WifiPhy::RxOkCallback callback); - virtual void SetReceiveErrorCallback (WifiPhy::RxErrorCallback callback); - virtual void SendPacket (Ptr packet, WifiMode mode, enum WifiPreamble preamble, uint8_t txPowerLevel); - virtual void RegisterListener (WifiPhyListener *listener); - virtual bool IsStateCcaBusy (void); - virtual bool IsStateIdle (void); - virtual bool IsStateBusy (void); - virtual bool IsStateRx (void); - virtual bool IsStateTx (void); - virtual bool IsStateSwitching (void); - virtual Time GetStateDuration (void); - virtual Time GetDelayUntilIdle (void); - virtual Time GetLastRxStartTime (void) const; - virtual Time CalculateTxDuration (uint32_t size, WifiMode payloadMode, enum WifiPreamble preamble) const; - virtual uint32_t GetNModes (void) const; - virtual WifiMode GetMode (uint32_t mode) const; - virtual double CalculateSnr (WifiMode txMode, double ber) const; - virtual Ptr GetChannel (void) const; - virtual void ConfigureStandard (enum WifiPhyStandard standard); - -private: - typedef std::vector Modes; - -private: - YansWifiPhy (const YansWifiPhy &o); - virtual void DoDispose (void); - void Configure80211a (void); - void Configure80211b (void); - void Configure80211_10Mhz (void); - void Configure80211_5Mhz (); - void ConfigureHolland (void); - void Configure80211p_CCH (void); - void Configure80211p_SCH (void); - double GetEdThresholdW (void) const; - double DbmToW (double dbm) const; - double DbToRatio (double db) const; - double WToDbm (double w) const; - double RatioToDb (double ratio) const; - double GetPowerDbm (uint8_t power) const; - void EndReceive (Ptr packet, Ptr event); - -private: - double m_edThresholdW; - double m_ccaMode1ThresholdW; - double m_txGainDb; - double m_rxGainDb; - double m_txPowerBaseDbm; - double m_txPowerEndDbm; - uint32_t m_nTxPower; - - Ptr m_channel; - uint16_t m_channelNumber; - Ptr m_device; - Ptr m_mobility; - Modes m_modes; - EventId m_endRxEvent; - UniformVariable m_random; - /// Standard-dependent center frequency of 0-th channel, MHz - double m_channelStartingFrequency; - Ptr m_state; - InterferenceHelper m_interference; - Time m_channelSwitchDelay; - -}; - -} // namespace ns3 - - -#endif /* YANS_WIFI_PHY_H */ +/home/quincy/code/ns3/devices/wifi/yans-wifi-phy.h \ No newline at end of file diff -r f8f2a9d65576 src/helper/wscript --- a/src/helper/wscript Wed Mar 10 11:11:38 2010 +0100 +++ b/src/helper/wscript Mon Mar 15 13:17:33 2010 +1100 @@ -1,124 +1,1 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- - -def build(bld): - helper = bld.create_ns3_module('helper', ['internet-stack', 'wifi', 'point-to-point', 'csma', 'olsr', 'global-routing', 'onoff', 'packet-sink', 'udp-echo']) - helper.source = [ - 'node-container.cc', - 'net-device-container.cc', - 'wifi-helper.cc', - 'olsr-helper.cc', - 'point-to-point-helper.cc', - 'csma-helper.cc', - 'mobility-helper.cc', - 'ns2-mobility-helper.cc', - 'ipv4-address-helper.cc', - 'ipv4-static-routing-helper.cc', - 'internet-stack-helper.cc', - 'application-container.cc', - 'on-off-helper.cc', - 'packet-sink-helper.cc', - 'packet-socket-helper.cc', - 'ipv4-interface-container.cc', - 'udp-echo-helper.cc', - 'bridge-helper.cc', - 'yans-wifi-helper.cc', - 'v4ping-helper.cc', - 'nqos-wifi-mac-helper.cc', - 'qos-wifi-mac-helper.cc', - 'ipv4-nix-vector-helper.cc', - 'ipv4-global-routing-helper.cc', - 'ipv4-list-routing-helper.cc', - 'ipv4-routing-helper.cc', - 'aodv-helper.cc', - 'mesh-helper.cc', - 'dot11s-installer.cc', - 'flame-installer.cc', - 'athstats-helper.cc', - 'ipv6-address-helper.cc', - 'ipv6-interface-container.cc', - 'ipv6-static-routing-helper.cc', - 'ipv6-list-routing-helper.cc', - 'ipv6-routing-helper.cc', - 'ping6-helper.cc', - 'flow-monitor-helper.cc', - 'animation-interface.cc', - 'canvas-location.cc', - 'point-to-point-dumbbell-helper.cc', - 'point-to-point-grid-helper.cc', - 'point-to-point-star-helper.cc', - 'csma-star-helper.cc', - 'udp-client-server-helper.cc', - ] - - headers = bld.new_task_gen('ns3header') - headers.module = 'helper' - headers.source = [ - 'node-container.h', - 'net-device-container.h', - 'wifi-helper.h', - 'olsr-helper.h', - 'point-to-point-helper.h', - 'csma-helper.h', - 'mobility-helper.h', - 'ns2-mobility-helper.h', - 'ipv4-address-helper.h', - 'ipv4-static-routing-helper.h', - 'internet-stack-helper.h', - 'application-container.h', - 'on-off-helper.h', - 'packet-sink-helper.h', - 'packet-socket-helper.h', - 'ipv4-interface-container.h', - 'udp-echo-helper.h', - 'bridge-helper.h', - 'yans-wifi-helper.h', - 'v4ping-helper.h', - 'nqos-wifi-mac-helper.h', - 'qos-wifi-mac-helper.h', - 'ipv4-nix-vector-helper.h', - 'ipv4-global-routing-helper.h', - 'ipv4-list-routing-helper.h', - 'ipv4-routing-helper.h', - 'aodv-helper.h', - 'mesh-helper.h', - 'mesh-stack-installer.h', - 'dot11s-installer.h', - 'flame-installer.h', - 'athstats-helper.h', - 'ipv6-address-helper.h', - 'ipv6-interface-container.h', - 'ipv6-static-routing-helper.h', - 'ipv6-list-routing-helper.h', - 'ipv6-routing-helper.h', - 'ping6-helper.h', - 'flow-monitor-helper.h', - 'animation-interface.h', - 'canvas-location.h', - 'point-to-point-dumbbell-helper.h', - 'point-to-point-grid-helper.h', - 'point-to-point-star-helper.h', - 'csma-star-helper.h', - 'udp-client-server-helper.h', - ] - - env = bld.env_of_name('default') - if env['ENABLE_EMU']: - helper.source.extend([ - 'emu-helper.cc', - ]) - headers.source.extend([ - 'emu-helper.h', - ]) - if env['ENABLE_TAP']: - helper.source.extend([ - 'tap-bridge-helper.cc', - ]) - headers.source.extend([ - 'tap-bridge-helper.h', - ]) - -def configure(conf): - conf.check(header_name='sys/socket.h', define_name='HAVE_SYS_SOCKET_H') - conf.check(header_name='netinet/in.h', define_name='HAVE_NETINET_IN_H') - conf.write_config_header('ns3/net-anim-config.h', top=True) - +/home/quincy/code/ns3/helper/wscript \ No newline at end of file diff -r f8f2a9d65576 src/helper/yans-wifi-helper.h --- a/src/helper/yans-wifi-helper.h Wed Mar 10 11:11:38 2010 +0100 +++ b/src/helper/yans-wifi-helper.h Mon Mar 15 13:17:33 2010 +1100 @@ -1,346 +1,1 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2008 INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef YANS_WIFI_HELPER_H -#define YANS_WIFI_HELPER_H - -#include "wifi-helper.h" -#include "ns3/yans-wifi-channel.h" - -namespace ns3 { - -/** - * \brief manage and create wifi channel objects for the yans model. - * - * The intent of this class is to make it easy to create a channel object - * which implements the yans channel model. The yans channel model is described - * in "Yet Another Network Simulator", http://cutebugs.net/files/wns2-yans.pdf - */ -class YansWifiChannelHelper -{ -public: - /** - * Create a channel helper without any parameter set. The user must set - * them all to be able to call Create later. - */ - YansWifiChannelHelper (); - - /** - * Create a channel helper in a default working state. By default, we create - * a channel model with a propagation delay equal to a constant, the speed of light, - * and a propagation loss based on a log distance model with a reference loss of 46.6777 dB - * at reference distance of 1m. - */ - static YansWifiChannelHelper Default (void); - - /** - * \param name the name of the model to add - * \param n0 the name of the attribute to set - * \param v0 the value of the attribute to set - * \param n1 the name of the attribute to set - * \param v1 the value of the attribute to set - * \param n2 the name of the attribute to set - * \param v2 the value of the attribute to set - * \param n3 the name of the attribute to set - * \param v3 the value of the attribute to set - * \param n4 the name of the attribute to set - * \param v4 the value of the attribute to set - * \param n5 the name of the attribute to set - * \param v5 the value of the attribute to set - * \param n6 the name of the attribute to set - * \param v6 the value of the attribute to set - * \param n7 the name of the attribute to set - * \param v7 the value of the attribute to set - * - * Add a propagation loss model to the set of currently-configured loss models. - * This method is additive to allow you to construct complex propagation loss models - * such as a log distance + jakes model, etc. - */ - void AddPropagationLoss (std::string name, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); - /** - * \param name the name of the model to set - * \param n0 the name of the attribute to set - * \param v0 the value of the attribute to set - * \param n1 the name of the attribute to set - * \param v1 the value of the attribute to set - * \param n2 the name of the attribute to set - * \param v2 the value of the attribute to set - * \param n3 the name of the attribute to set - * \param v3 the value of the attribute to set - * \param n4 the name of the attribute to set - * \param v4 the value of the attribute to set - * \param n5 the name of the attribute to set - * \param v5 the value of the attribute to set - * \param n6 the name of the attribute to set - * \param v6 the value of the attribute to set - * \param n7 the name of the attribute to set - * \param v7 the value of the attribute to set - * - * Configure a propagation delay for this channel. - */ - void SetPropagationDelay (std::string name, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); - - /** - * \returns a new channel - * - * Create a channel based on the configuration parameters set previously. - */ - Ptr Create (void) const; - -private: - std::vector m_propagationLoss; - ObjectFactory m_propagationDelay; -}; - -/** - * \brief Make it easy to create and manage PHY objects for the yans model. - * - * The yans PHY model is described in "Yet Another Network Simulator", - * http://cutebugs.net/files/wns2-yans.pdf - * - * The Pcap and ascii traces generated by the EnableAscii and EnablePcap methods defined - * in this class correspond to PHY-level traces. - */ -class YansWifiPhyHelper : public WifiPhyHelper -{ -public: - /** - * Create a phy helper without any parameter set. The user must set - * them all to be able to call Install later. - */ - YansWifiPhyHelper (); - - /** - * Create a phy helper in a default working state. - */ - static YansWifiPhyHelper Default (void); - - /** - * \param channel the channel to associate to this helper - * - * Every PHY created by a call to Install is associated to this channel. - */ - void SetChannel (Ptr channel); - /** - * \param channelName The name of the channel to associate to this helper - * - * Every PHY created by a call to Install is associated to this channel. - */ - void SetChannel (std::string channelName); - /** - * \param name the name of the attribute to set - * \param v the value of the attribute - * - * Set an attribute of the underlying PHY object. - */ - void Set (std::string name, const AttributeValue &v); - /** - * \param name the name of the error rate model to set. - * \param n0 the name of the attribute to set - * \param v0 the value of the attribute to set - * \param n1 the name of the attribute to set - * \param v1 the value of the attribute to set - * \param n2 the name of the attribute to set - * \param v2 the value of the attribute to set - * \param n3 the name of the attribute to set - * \param v3 the value of the attribute to set - * \param n4 the name of the attribute to set - * \param v4 the value of the attribute to set - * \param n5 the name of the attribute to set - * \param v5 the value of the attribute to set - * \param n6 the name of the attribute to set - * \param v6 the value of the attribute to set - * \param n7 the name of the attribute to set - * \param v7 the value of the attribute to set - * - * Set the error rate model and its attributes to use when Install is called. - */ - void SetErrorRateModel (std::string name, - std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (), - std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), - std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), - std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), - std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (), - std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (), - std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (), - std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ()); - - /** - * PCAP formats - * - */ - enum PcapFormat { - PCAP_FORMAT_80211 = 1, - PCAP_FORMAT_80211_PRISM = 2, - PCAP_FORMAT_80211_RADIOTAP = 3, - }; - - /** - * Set the format of PCAP traces to be used. This function has to be - * called before EnablePcap(), so that the header of the pcap file - * can be written correctly. - * - * In madwifi, this corresponds to setting - * /proc/sys/net/ath0/dev_type to a particular value. See - * http://madwifi-project.org/wiki/UserDocs/MonitorModeInterface for - * more information. - * - * @param format the PcapFormat to be used - */ - void SetPcapFormat (enum PcapFormat format); - - /** - * \param filename filename prefix to use for pcap files. - * \param nodeid the id of the node to generate pcap output for. - * \param deviceid the id of the device to generate pcap output for. - * - * Generate a pcap file which contains the link-level data observed - * by the specified deviceid within the specified nodeid. The pcap - * data is stored in the file prefix-nodeid-deviceid.pcap. By - * default, no PHY layer information is provided. An optional header - * with PHY layer information, such as the radiotap or the prism - * header, can be used by invoking SetPcapFormat(). - * - * This method should be invoked after the network topology has - * been fully constructed. - */ - void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid); - - /** - * \param filename filename prefix to use for pcap files. - * \param nd Net device on which you want to enable tracing. - * - * Enable pcap output on each input device which is of the - * ns3::WifiNetDevice type. - */ - void EnablePcap (std::string filename, Ptr nd); - - /** - * \param filename filename prefix to use for pcap files. - * \param ndName Name of net device on which you want to enable tracing. - * - * Enable pcap output on each input device which is of the - * ns3::WifiNetDevice type. - */ - void EnablePcap (std::string filename, std::string ndName); - - /** - * \param filename filename prefix to use for pcap files. - * \param d container of devices of type ns3::WifiNetDevice - * - * Enable pcap output on each input device which is of the - * ns3::WifiNetDevice type. - */ - void EnablePcap (std::string filename, NetDeviceContainer d); - - /** - * \param filename filename prefix to use for pcap files. - * \param n container of nodes. - * - * Enable pcap output on each device which is of the - * ns3::WifiNetDevice type and which is located in one of the - * input nodes. - */ - void EnablePcap (std::string filename, NodeContainer n); - - /** - * \param filename filename prefix to use for pcap files. - * - * Enable pcap output on each device which is of the - * ns3::WifiNetDevice type - */ - void EnablePcapAll (std::string filename); - - /** - * \param os output stream - * \param nodeid the id of the node to generate ascii output for. - * \param deviceid the id of the device to generate ascii output for. - * - * Enable ascii output on the specified deviceid within the - * specified nodeid if it is of type ns3::WifiNetDevice and dump - * that to the specified stdc++ output stream. - */ - static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid); - - /** - * \param os output stream - * \param d device container - * - * Enable ascii output on each device which is of the - * ns3::WifiNetDevice type and which is located in the input - * device container and dump that to the specified - * stdc++ output stream. - */ - static void EnableAscii (std::ostream &os, NetDeviceContainer d); - - /** - * \param os output stream - * \param n node container - * - * Enable ascii output on each device which is of the - * ns3::WifiNetDevice type and which is located in one - * of the input node and dump that to the specified - * stdc++ output stream. - */ - static void EnableAscii (std::ostream &os, NodeContainer n); - - /** - * \param os output stream - * - * Enable ascii output on each device which is of the - * ns3::WifiNetDevice type and dump that to the specified - * stdc++ output stream. - */ - static void EnableAsciiAll (std::ostream &os); - -private: - /** - * \param node the node on which we wish to create a wifi PHY - * \param device the device within which this PHY will be created - * \returns a newly-created PHY object. - * - * This method implements the pure virtual method defined in \ref ns3::WifiPhyHelper. - */ - virtual Ptr Create (Ptr node, Ptr device) const; - - ObjectFactory m_phy; - ObjectFactory m_errorRateModel; - Ptr m_channel; - enum PcapFormat m_pcapFormat; -}; - -} // namespace ns3 - -#endif /* YANS_WIFI_HELPER_H */ +/home/quincy/code/ns3/helper/yans-wifi-helper.h \ No newline at end of file diff -r f8f2a9d65576 src/node/packet-socket.cc --- a/src/node/packet-socket.cc Wed Mar 10 11:11:38 2010 +0100 +++ b/src/node/packet-socket.cc Mon Mar 15 13:17:33 2010 +1100 @@ -1,460 +1,1 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 Emmanuelle Laprise, INRIA - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Authors: Emmanuelle Laprise - * Mathieu Lacage - */ - -#include "packet-socket.h" -#include "packet-socket-address.h" -#include "ns3/log.h" -#include "ns3/node.h" -#include "ns3/packet.h" -#include "ns3/uinteger.h" -#include "ns3/trace-source-accessor.h" - -#include - -NS_LOG_COMPONENT_DEFINE ("PacketSocket"); - -namespace ns3 { - -TypeId -PacketSocket::GetTypeId (void) -{ - static TypeId tid = TypeId ("ns3::PacketSocket") - .SetParent () - .AddConstructor () - .AddTraceSource ("Drop", "Drop packet due to receive buffer overflow", - MakeTraceSourceAccessor (&PacketSocket::m_dropTrace)) - .AddAttribute ("RcvBufSize", - "PacketSocket maximum receive buffer size (bytes)", - UintegerValue (0xffffffffl), - MakeUintegerAccessor (&PacketSocket::m_rcvBufSize), - MakeUintegerChecker ()) - ; - return tid; -} - -PacketSocket::PacketSocket () : m_rxAvailable (0) -{ - NS_LOG_FUNCTION (this); - m_state = STATE_OPEN; - m_shutdownSend = false; - m_shutdownRecv = false; - m_errno = ERROR_NOTERROR; - m_isSingleDevice = false; - m_device = 0; -} - -void -PacketSocket::SetNode (Ptr node) -{ - NS_LOG_FUNCTION (this << node); - m_node = node; -} - -PacketSocket::~PacketSocket () -{ - NS_LOG_FUNCTION (this); -} - -void -PacketSocket::DoDispose (void) -{ - NS_LOG_FUNCTION (this); - m_device = 0; -} - -enum Socket::SocketErrno -PacketSocket::GetErrno (void) const -{ - NS_LOG_FUNCTION (this); - return m_errno; -} - -Ptr -PacketSocket::GetNode (void) const -{ - NS_LOG_FUNCTION (this); - return m_node; -} - -int -PacketSocket::Bind (void) -{ - NS_LOG_FUNCTION (this); - PacketSocketAddress address; - address.SetProtocol (0); - address.SetAllDevices (); - return DoBind (address); -} - -int -PacketSocket::Bind (const Address &address) -{ - NS_LOG_FUNCTION (this << address); - if (!PacketSocketAddress::IsMatchingType (address)) - { - m_errno = ERROR_INVAL; - return -1; - } - PacketSocketAddress ad = PacketSocketAddress::ConvertFrom (address); - return DoBind (ad); -} - -int -PacketSocket::DoBind (const PacketSocketAddress &address) -{ - NS_LOG_FUNCTION (this << address); - if (m_state == STATE_BOUND || - m_state == STATE_CONNECTED) - { - m_errno = ERROR_INVAL; - return -1; - } - if (m_state == STATE_CLOSED) - { - m_errno = ERROR_BADF; - return -1; - } - Ptr dev ; - if (address.IsSingleDevice ()) - { - dev = m_node->GetDevice (address.GetSingleDevice ()); - } - else - { - dev = 0; - } - m_node->RegisterProtocolHandler (MakeCallback (&PacketSocket::ForwardUp, this), - address.GetProtocol (), dev); - m_state = STATE_BOUND; - m_protocol = address.GetProtocol (); - m_isSingleDevice = address.IsSingleDevice (); - m_device = address.GetSingleDevice (); - return 0; -} - -int -PacketSocket::ShutdownSend (void) -{ - NS_LOG_FUNCTION (this); - if (m_state == STATE_CLOSED) - { - m_errno = ERROR_BADF; - return -1; - } - m_shutdownSend = true; - return 0; -} - -int -PacketSocket::ShutdownRecv (void) -{ - NS_LOG_FUNCTION (this); - if (m_state == STATE_CLOSED) - { - m_errno = ERROR_BADF; - return -1; - } - m_shutdownRecv = true; - return 0; -} - -int -PacketSocket::Close(void) -{ - NS_LOG_FUNCTION (this); - if (m_state == STATE_CLOSED) - { - m_errno = ERROR_BADF; - return -1; - } - m_state = STATE_CLOSED; - m_shutdownSend = true; - m_shutdownRecv = true; - return 0; -} - -int -PacketSocket::Connect(const Address &ad) -{ - NS_LOG_FUNCTION (this << ad); - PacketSocketAddress address; - if (m_state == STATE_CLOSED) - { - m_errno = ERROR_BADF; - goto error; - } - if (m_state == STATE_OPEN) - { - // connect should happen _after_ bind. - m_errno = ERROR_INVAL; // generic error condition. - goto error; - } - if (m_state == STATE_CONNECTED) - { - m_errno = ERROR_ISCONN; - goto error; - } - if (!PacketSocketAddress::IsMatchingType (ad)) - { - m_errno = ERROR_AFNOSUPPORT; - goto error; - } - m_destAddr = ad; - m_state = STATE_CONNECTED; - NotifyConnectionSucceeded (); - return 0; - error: - NotifyConnectionFailed (); - return -1; -} -int -PacketSocket::Listen(void) -{ - m_errno = Socket::ERROR_OPNOTSUPP; - return -1; -} - -int -PacketSocket::Send (Ptr p, uint32_t flags) -{ - NS_LOG_FUNCTION (this << p << flags); - if (m_state == STATE_OPEN || - m_state == STATE_BOUND) - { - m_errno = ERROR_NOTCONN; - return -1; - } - return SendTo (p, flags, m_destAddr); -} - -uint32_t -PacketSocket::GetMinMtu (PacketSocketAddress ad) const -{ - if (ad.IsSingleDevice ()) - { - Ptr device = m_node->GetDevice (ad.GetSingleDevice ()); - return device->GetMtu (); - } - else - { - uint32_t minMtu = 0xffff; - for (uint32_t i = 0; i < m_node->GetNDevices (); i++) - { - Ptr device = m_node->GetDevice (i); - minMtu = std::min (minMtu, (uint32_t)device->GetMtu ()); - } - return minMtu; - } -} - -uint32_t -PacketSocket::GetTxAvailable (void) const -{ - if (m_state == STATE_CONNECTED) - { - PacketSocketAddress ad = PacketSocketAddress::ConvertFrom (m_destAddr); - return GetMinMtu (ad); - } - // If we are not connected, we return a 'safe' value by default. - return 0xffff; -} - -int -PacketSocket::SendTo (Ptr p, uint32_t flags, const Address &address) -{ - NS_LOG_FUNCTION (this << p << flags << address); - PacketSocketAddress ad; - if (m_state == STATE_CLOSED) - { - NS_LOG_LOGIC ("ERROR_BADF"); - m_errno = ERROR_BADF; - return -1; - } - if (m_shutdownSend) - { - NS_LOG_LOGIC ("ERROR_SHUTDOWN"); - m_errno = ERROR_SHUTDOWN; - return -1; - } - if (!PacketSocketAddress::IsMatchingType (address)) - { - NS_LOG_LOGIC ("ERROR_AFNOSUPPORT"); - m_errno = ERROR_AFNOSUPPORT; - return -1; - } - ad = PacketSocketAddress::ConvertFrom (address); - if (p->GetSize () > GetMinMtu (ad)) - { - m_errno = ERROR_MSGSIZE; - return -1; - } - - bool error = false; - Address dest = ad.GetPhysicalAddress (); - if (ad.IsSingleDevice ()) - { - Ptr device = m_node->GetDevice (ad.GetSingleDevice ()); - if (!device->Send (p, dest, ad.GetProtocol ())) - { - NS_LOG_LOGIC ("error: NetDevice::Send error"); - error = true; - } - } - else - { - for (uint32_t i = 0; i < m_node->GetNDevices (); i++) - { - Ptr device = m_node->GetDevice (i); - if (!device->Send (p, dest, ad.GetProtocol ())) - { - NS_LOG_LOGIC ("error: NetDevice::Send error"); - error = true; - } - } - } - if (!error) - { - NotifyDataSent (p->GetSize ()); - NotifySend (GetTxAvailable ()); - } - - if (error) - { - NS_LOG_LOGIC ("ERROR_INVAL 2"); - m_errno = ERROR_INVAL; - return -1; - } - else - { - return 0; - } -} - -void -PacketSocket::ForwardUp (Ptr device, Ptr packet, - uint16_t protocol, const Address &from, - const Address &to, NetDevice::PacketType packetType) -{ - NS_LOG_FUNCTION (this << device << packet << protocol << from << to << packetType); - if (m_shutdownRecv) - { - return; - } - - - PacketSocketAddress address; - address.SetPhysicalAddress (from); - address.SetSingleDevice (device->GetIfIndex ()); - address.SetProtocol (protocol); - - if ((m_rxAvailable + packet->GetSize ()) <= m_rcvBufSize) - { - Ptr copy = packet->Copy (); - SocketAddressTag tag; - tag.SetAddress (address); - copy->AddPacketTag (tag); - m_deliveryQueue.push (copy); - m_rxAvailable += packet->GetSize (); - NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this); - NotifyDataRecv (); - } - else - { - // In general, this case should not occur unless the - // receiving application reads data from this socket slowly - // in comparison to the arrival rate - // - // drop and trace packet - NS_LOG_WARN ("No receive buffer space available. Drop."); - m_dropTrace (packet); - } -} - -uint32_t -PacketSocket::GetRxAvailable (void) const -{ - NS_LOG_FUNCTION (this); - // We separately maintain this state to avoid walking the queue - // every time this might be called - return m_rxAvailable; -} - -Ptr -PacketSocket::Recv (uint32_t maxSize, uint32_t flags) -{ - NS_LOG_FUNCTION (this << maxSize << flags); - if (m_deliveryQueue.empty() ) - { - return 0; - } - Ptr p = m_deliveryQueue.front (); - if (p->GetSize () <= maxSize) - { - m_deliveryQueue.pop (); - m_rxAvailable -= p->GetSize (); - } - else - { - p = 0; - } - return p; -} - -Ptr -PacketSocket::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress) -{ - NS_LOG_FUNCTION (this << maxSize << flags << fromAddress); - Ptr packet = Recv (maxSize, flags); - if (packet != 0) - { - SocketAddressTag tag; - bool found; - found = packet->PeekPacketTag (tag); - NS_ASSERT (found); - fromAddress = tag.GetAddress (); - } - return packet; -} - -int -PacketSocket::GetSockName (Address &address) const -{ - NS_LOG_FUNCTION (this << address); - PacketSocketAddress ad = PacketSocketAddress::ConvertFrom(address); - - ad.SetProtocol (m_protocol); - if (m_isSingleDevice) - { - Ptr device = m_node->GetDevice (ad.GetSingleDevice ()); - ad.SetPhysicalAddress(device->GetAddress()); - ad.SetSingleDevice (m_device); - } - else - { - ad.SetPhysicalAddress(Address()); - ad.SetAllDevices (); - } - address = ad; - - return 0; -} - -}//namespace ns3 +/home/quincy/code/ns3/node/packet-socket.cc \ No newline at end of file diff -r f8f2a9d65576 src/simulator/wscript --- a/src/simulator/wscript Wed Mar 10 11:11:38 2010 +0100 +++ b/src/simulator/wscript Mon Mar 15 13:17:33 2010 +1100 @@ -1,120 +1,1 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- -import sys - -import Options - - -def set_options(opt): - opt.add_option('--high-precision-as-double', - help=('Whether to use a double floating point' - ' type for high precision time values' - ' WARNING: this option only has effect ' - 'with the configure command.'), - action="store_true", default=False, - dest='high_precision_as_double') - - -def configure(conf): - if Options.options.high_precision_as_double: - conf.define('USE_HIGH_PRECISION_DOUBLE', 1) - conf.env['USE_HIGH_PRECISION_DOUBLE'] = 1 - highprec = 'long double' - else: - conf.env['USE_HIGH_PRECISION_DOUBLE'] = 0 - highprec = '128-bit integer' - - conf.check_message_custom('high precision time', 'implementation', highprec) - - conf.check(header_name='stdint.h', define_name='HAVE_STDINT_H') - - conf.check(header_name='inttypes.h', define_name='HAVE_INTTYPES_H') - - conf.check(header_name='sys/inttypes.h', define_name='HAVE_SYS_INT_TYPES_H') - - conf.write_config_header('ns3/simulator-config.h', top=True) - - if not conf.check(lib='rt', uselib='RT', define_name='HAVE_RT'): - conf.report_optional_feature("RealTime", "Real Time Simulator", - False, "librt is not available") - else: - conf.report_optional_feature("RealTime", "Real Time Simulator", - conf.env['ENABLE_THREADING'], - "threading not enabled") - conf.env["ENABLE_REAL_TIME"] = conf.env['ENABLE_THREADING'] - - -def build(bld): - sim = bld.create_ns3_module('simulator', ['core']) - sim.source = [ - 'high-precision.cc', - 'time.cc', - 'event-id.cc', - 'scheduler.cc', - 'list-scheduler.cc', - 'map-scheduler.cc', - 'heap-scheduler.cc', - 'calendar-scheduler.cc', - 'ns2-calendar-scheduler.cc', - 'event-impl.cc', - 'simulator.cc', - 'default-simulator-impl.cc', - 'timer.cc', - 'watchdog.cc', - 'synchronizer.cc', - 'make-event.cc', - ] - - headers = bld.new_task_gen('ns3header') - headers.module = 'simulator' - headers.source = [ - 'high-precision.h', - 'nstime.h', - 'event-id.h', - 'event-impl.h', - 'simulator.h', - 'simulator-impl.h', - 'default-simulator-impl.h', - 'scheduler.h', - 'list-scheduler.h', - 'map-scheduler.h', - 'heap-scheduler.h', - 'calendar-scheduler.h', - 'ns2-calendar-scheduler.h', - 'simulation-singleton.h', - 'timer.h', - 'timer-impl.h', - 'watchdog.h', - 'synchronizer.h', - 'make-event.h', - ] - - env = bld.env_of_name('default') - if env['USE_HIGH_PRECISION_DOUBLE']: - sim.source.extend([ - 'high-precision-double.cc', - ]) - headers.source.extend([ - 'high-precision-double.h', - ]) - else: - sim.source.extend([ - 'high-precision-128.cc', - 'cairo-wideint.c', - ]) - headers.source.extend([ - 'high-precision-128.h', - 'cairo-wideint-private.h', - ]) - - if env['ENABLE_REAL_TIME']: - headers.source.extend([ - 'realtime-simulator-impl.h', - 'wall-clock-synchronizer.h', - ]) - sim.source.extend([ - 'realtime-simulator-impl.cc', - 'wall-clock-synchronizer.cc', - ]) - sim.uselib = 'RT' - - +/home/quincy/code/ns3/simulator/wscript \ No newline at end of file diff -r f8f2a9d65576 src/wscript --- a/src/wscript Wed Mar 10 11:11:38 2010 +0100 +++ b/src/wscript Mon Mar 15 13:17:33 2010 +1100 @@ -1,253 +1,1 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- - -import os, os.path -import shutil -import types -import warnings - -import TaskGen -import Task -import Options -import Build -import Utils - -all_modules = ( - 'core', - 'common', - 'simulator', - 'contrib', - 'node', - 'internet-stack', - 'devices/point-to-point', - 'devices/csma', - 'devices/emu', - 'devices/bridge', - 'devices/tap-bridge', - 'devices/virtual-net-device', - 'applications/onoff', - 'applications/packet-sink', - 'applications/udp-echo', - 'routing/nix-vector-routing', - 'routing/olsr', - 'routing/global-routing', - 'routing/static-routing', - 'routing/list-routing', - 'routing/aodv', - 'mobility', - 'devices/wifi', - 'helper', - 'contrib/stats', - 'applications/v4ping', - 'devices/mesh', - 'devices/mesh/dot11s', - 'devices/mesh/flame', - 'applications/ping6', - 'applications/radvd', - 'test', - 'test/ns3tcp', - 'test/ns3wifi', - 'contrib/flow-monitor', - 'applications/udp-client-server', - ) - -def set_options(opt): - opt.sub_options('simulator') - - opt.add_option('--enable-rpath', - help=("Link programs with rpath" - " (normally not needed, see " - " --run and --shell; moreover, only works in some" - " specific platforms, such as Linux and Solaris)"), - action="store_true", dest='enable_rpath', default=False) - - opt.add_option('--enable-modules', - help=("Build only these modules (and dependencies)"), - dest='enable_modules') - -def configure(conf): - conf.sub_config('core') - conf.sub_config('simulator') - conf.sub_config('devices/emu') - conf.sub_config('devices/tap-bridge') - conf.sub_config('contrib') - conf.sub_config('internet-stack') - conf.sub_config('helper') - - blddir = os.path.abspath(os.path.join(conf.blddir, conf.env.variant())) - conf.env.append_value('NS3_MODULE_PATH', blddir) - if Options.options.enable_rpath: - conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),)) - - ## Used to link the 'test-runner' program with all of ns-3 code - conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules] - - -def create_ns3_module(bld, name, dependencies=()): - module = bld.new_task_gen('cxx') - module.name = 'ns3-' + name - module.target = module.name - module.add_objects = ['ns3-' + dep for dep in dependencies] - module.module_deps = list(dependencies) - if not module.env['ENABLE_STATIC_NS3']: - module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS']) - elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \ - os.uname()[4] == 'x86_64' and \ - module.env['ENABLE_PYTHON_BINDINGS']: - # enable that flag for static builds only on x86-64 platforms - # when gcc is present and only when we want python bindings - # (it's more efficient to not use this option if we can avoid it) - module.env.append_value('CXXFLAGS', '-mcmodel=large') - - module.env.append_value('CXXDEFINES', "NS3_MODULE_COMPILATION") - return module - -def create_obj(bld, *args): - warnings.warn("(in %s) Use bld.new_task_gen(...) now, instead of bld.create_obj(...)" % str(bld.path), - DeprecationWarning, stacklevel=2) - return bld.new_task_gen(*args) - -def build(bld): - bld.create_ns3_module = types.MethodType(create_ns3_module, bld) - bld.create_obj = types.MethodType(create_obj, bld) - - bld.add_subdirs(list(all_modules)) - - for module in all_modules: - modheader = bld.new_task_gen('ns3moduleheader') - modheader.module = module.split('/')[-1] - - -class ns3header_taskgen(TaskGen.task_gen): - """A set of NS-3 header files""" - COLOR = 'BLUE' - def __init__(self, *args, **kwargs): - super(ns3header_taskgen, self).__init__(*args, **kwargs) - self.install_path = None - self.sub_dir = None # if not None, header files will be published as ns3/sub_dir/file.h - self.module = None # module name - - def apply(self): - if self.module is None: - raise Utils.WafError("'module' missing on ns3headers object %s" % self) - ns3_dir_node = self.bld.path.find_dir("ns3") - if self.sub_dir is not None: - ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir) - for filename in self.to_list(self.source): - src_node = self.path.find_resource(filename) - if src_node is None: - raise Utils.WafError("source ns3 header file %s not found" % (filename,)) - dst_node = ns3_dir_node.find_or_declare(os.path.basename(filename)) - assert dst_node is not None - task = self.create_task('ns3header', self.env) - task.set_inputs([src_node]) - task.set_outputs([dst_node]) - -class ns3header_task(Task.Task): - before = 'cc cxx gen_ns3_module_header_task' - color = 'BLUE' - def run(self): - assert len(self.inputs) == len(self.outputs) - inputs = [node.srcpath(self.env) for node in self.inputs] - outputs = [node.bldpath(self.env) for node in self.outputs] - for src, dst in zip(inputs, outputs): - try: - os.chmod(dst, 0600) - except OSError: - pass - shutil.copy2(src, dst) - ## make the headers in builddir read-only, to prevent - ## accidental modification - os.chmod(dst, 0400) - return 0 - - - -class gen_ns3_module_header_task(Task.Task): - before = 'cc cxx' - after = 'ns3header_task' - color = 'BLUE' - def run(self): - assert len(self.outputs) == 1 - header_files = [os.path.basename(node.abspath(self.env)) for node in self.inputs] - outfile = file(self.outputs[0].bldpath(self.env), "w") - header_files.sort() - - print >> outfile, """ -#ifdef NS3_MODULE_COMPILATION -# error "Do not include ns3 module aggregator headers from other modules; these are meant only for end user scripts." -#endif - -#ifndef NS3_MODULE_%s - """ % (self.module.upper().replace('-', '_'),) - - # if self.module_deps: - # print >> outfile, "// Module dependencies:" - # for dep in self.module_deps: - # print >> outfile, "#include \"%s-module.h\"" % dep - - print >> outfile - print >> outfile, "// Module headers:" - for header in header_files: - print >> outfile, "#include \"%s\"" % (header,) - - print >> outfile, "#endif" - - outfile.close() - return 0 - - def sig_explicit_deps(self): - m = Utils.md5() - m.update('\n'.join([node.abspath(self.env) for node in self.inputs])) - return m.digest() - - def unique_id(self): - try: - return self.uid - except AttributeError: - "this is not a real hot zone, but we want to avoid surprizes here" - m = Utils.md5() - m.update("ns-3-module-header-%s" % self.module) - self.uid = m.digest() - return self.uid - - -class ns3moduleheader_taskgen(TaskGen.task_gen): - """ - Generates a 'ns3/foo-module.h' header file that includes all - public ns3 headers of a certain module. - """ - COLOR = 'BLUE' - def __init__(self, *args, **kwargs): - super(ns3moduleheader_taskgen, self).__init__(*args, **kwargs) - - def apply(self): - ## get all of the ns3 headers - ns3_dir_node = self.bld.path.find_dir("ns3") - all_headers_inputs = [] - found_the_module = False - for ns3headers in self.bld.all_task_gen: - if isinstance(ns3headers, ns3header_taskgen): - if ns3headers.module != self.module: - continue - found_the_module = True - for source in ns3headers.to_list(ns3headers.source): - source = os.path.basename(source) - node = ns3_dir_node.find_or_declare(os.path.basename(source)) - if node is None: - fatal("missing header file %s" % (source,)) - all_headers_inputs.append(node) - if not found_the_module: - raise Utils.WscriptError("error finding headers for module %s" % self.module) - if not all_headers_inputs: - return - module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env) - assert module_obj is not None - all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)] - task = self.create_task('gen_ns3_module_header', self.env) - task.set_inputs(all_headers_inputs) - task.set_outputs(all_headers_outputs) - task.module = self.module - task.module_deps = module_obj.module_deps - - def install(self): - pass +/home/quincy/code/ns3/wscript \ No newline at end of file