src/wifi/model/monitor-mac-high.cc
author Ashwin Narayan
Sat, 16 Jul 2011 08:54:00 -0400
changeset 7328 141f8d6ccb03
parent 7326 bf036fdb9390
permissions -rw-r--r--
Cleaning up code for review

/* -*-  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 <mathieu.lacage@sophia.inria.fr>, Ashwin Narayan <ashwin.narayan89@gmail.com>
 */
#include "monitor-mac-high.h"

#include "ns3/log.h"
#include "ns3/boolean.h"
#include "ns3/pointer.h"
#include "ns3/uinteger.h"
#include "ns3/trace-source-accessor.h"

#include "mac-rx-middle.h"
#include "mac-tx-middle.h"
#include "mac-low.h"
#include "dcf.h"
#include "dcf-manager.h"
#include "wifi-phy.h"

#include "msdu-aggregator.h"

NS_LOG_COMPONENT_DEFINE ("MonitorMacHigh");

namespace ns3 {

NS_OBJECT_ENSURE_REGISTERED (MonitorMacHigh);

TypeId
MonitorMacHigh::GetTypeId (void)
{
  static TypeId tid = TypeId ("ns3::MonitorMacHigh")
    .SetParent<WifiMac> ()
    .AddConstructor<MonitorMacHigh> ()
  ;
  return tid;
}

MonitorMacHigh::MonitorMacHigh ()
{
  NS_LOG_FUNCTION (this);
  m_rxMiddle = new MacRxMiddle ();
  m_rxMiddle->SetForwardCallback (MakeCallback (&MonitorMacHigh::Receive, this));

  m_txMiddle = new MacTxMiddle ();

  m_low = CreateObject<MacLow> ();
  m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));
  m_low->SetMonitorMode ();

  m_dcfManager = new DcfManager ();
  m_dcfManager->SetupLowListener (m_low);

  m_dca = CreateObject<DcaTxop> ();
  m_dca->SetLow (m_low);
  m_dca->SetManager (m_dcfManager);
  m_dca->SetTxOkCallback (MakeCallback (&MonitorMacHigh::TxOk, this));
  m_dca->SetTxFailedCallback (MakeCallback (&MonitorMacHigh::TxFailed, this));
}

MonitorMacHigh::~MonitorMacHigh ()
{
  NS_LOG_FUNCTION (this);
}

void
MonitorMacHigh::DoStart ()
{
  NS_LOG_FUNCTION (this);

  m_dca->Start ();
}

void
MonitorMacHigh::DoDispose ()
{
  NS_LOG_FUNCTION (this);
  delete m_rxMiddle;
  m_rxMiddle = NULL;

  delete m_txMiddle;
  m_txMiddle = NULL;

  delete m_dcfManager;
  m_dcfManager = NULL;

  m_low->Dispose ();
  m_low = NULL;

  m_phy = NULL;
  m_stationManager = NULL;

  m_dca->Dispose ();
  m_dca = NULL;
}

Ptr<DcaTxop>
MonitorMacHigh::GetDcaTxop () const
{
  return m_dca;
}

void
MonitorMacHigh::SetForwardUpCallback (ForwardUpCallback upCallback)
{
  NS_LOG_FUNCTION (this);
  m_forwardUp = upCallback;
}

void
MonitorMacHigh::SetLinkUpCallback (Callback<void> linkUp)
{
  NS_LOG_FUNCTION (this);
  m_linkUp = linkUp;
}

void
MonitorMacHigh::SetLinkDownCallback (Callback<void> linkDown)
{
  NS_LOG_FUNCTION (this);
  m_linkDown = linkDown;
}

void
MonitorMacHigh::SetQosSupported (bool enable)
{
  NS_FATAL_ERROR ("QoS Functionality not supported in MonitorMacHigh");
}

bool
MonitorMacHigh::GetQosSupported () const
{
  return false;
}

void
MonitorMacHigh::SetSlot (Time slotTime)
{
  NS_LOG_FUNCTION (this << slotTime);
  m_dcfManager->SetSlot (slotTime);
  m_low->SetSlotTime (slotTime);
}

Time
MonitorMacHigh::GetSlot (void) const
{
  return m_low->GetSlotTime ();
}

void
MonitorMacHigh::SetSifs (Time sifs)
{
  NS_LOG_FUNCTION (this << sifs);
  m_dcfManager->SetSifs (sifs);
  m_low->SetSifs (sifs);
}

Time
MonitorMacHigh::GetSifs (void) const
{
  return m_low->GetSifs ();
}

void
MonitorMacHigh::SetEifsNoDifs (Time eifsNoDifs)
{
  NS_LOG_FUNCTION (this << eifsNoDifs);
  m_dcfManager->SetEifsNoDifs (eifsNoDifs);
}

Time
MonitorMacHigh::GetEifsNoDifs (void) const
{
  return m_dcfManager->GetEifsNoDifs ();
}

void
MonitorMacHigh::SetPifs (Time pifs)
{
  NS_LOG_FUNCTION (this << pifs);
  m_low->SetPifs (pifs);
}

Time
MonitorMacHigh::GetPifs (void) const
{
  return m_low->GetPifs ();
}

void
MonitorMacHigh::SetAckTimeout (Time ackTimeout)
{
  NS_LOG_FUNCTION (this << ackTimeout);
  m_low->SetAckTimeout (ackTimeout);
}

Time
MonitorMacHigh::GetAckTimeout (void) const
{
  return m_low->GetAckTimeout ();
}

void
MonitorMacHigh::SetCtsTimeout (Time ctsTimeout)
{
  NS_LOG_FUNCTION (this << ctsTimeout);
  m_low->SetCtsTimeout (ctsTimeout);
}

Time
MonitorMacHigh::GetCtsTimeout (void) const
{
  return m_low->GetCtsTimeout ();
}

void
MonitorMacHigh::SetBasicBlockAckTimeout (Time blockAckTimeout)
{
  NS_LOG_FUNCTION (this << blockAckTimeout);
  m_low->SetBasicBlockAckTimeout (blockAckTimeout);
}

Time
MonitorMacHigh::GetBasicBlockAckTimeout (void) const
{
  return m_low->GetBasicBlockAckTimeout ();
}

void
MonitorMacHigh::SetCompressedBlockAckTimeout (Time blockAckTimeout)
{
  NS_LOG_FUNCTION (this << blockAckTimeout);
  m_low->SetCompressedBlockAckTimeout (blockAckTimeout);
}

Time
MonitorMacHigh::GetCompressedBlockAckTimeout (void) const
{
  return m_low->GetCompressedBlockAckTimeout ();
}

void
MonitorMacHigh::SetAddress (Mac48Address address)
{
  NS_LOG_FUNCTION (this << address);
  m_low->SetAddress (address);
}

Mac48Address
MonitorMacHigh::GetAddress (void) const
{
  return m_low->GetAddress ();
}

void
MonitorMacHigh::SetSsid (Ssid ssid)
{
  NS_LOG_FUNCTION (this << ssid);
  m_ssid = ssid;
}

Ssid
MonitorMacHigh::GetSsid (void) const
{
  return m_ssid;
}

void
MonitorMacHigh::SetBssid (Mac48Address bssid)
{
  NS_LOG_FUNCTION (this << bssid);
  m_low->SetBssid (bssid);
}

Mac48Address
MonitorMacHigh::GetBssid (void) const
{
  return m_low->GetBssid ();
}

void
MonitorMacHigh::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
{
  NS_LOG_FUNCTION (this << stationManager);
  m_stationManager = stationManager;
  m_low->SetWifiRemoteStationManager (stationManager);

  m_dca->SetWifiRemoteStationManager (stationManager);
}

void
MonitorMacHigh::SetWifiPhy (Ptr<WifiPhy> phy)
{
  NS_LOG_FUNCTION (this << phy);
  m_phy = phy;
  m_dcfManager->SetupPhyListener (phy);
  m_low->SetPhy (phy);
}

void
MonitorMacHigh::SetPromisc (void)
{
  m_low->SetPromisc ();
}

void
MonitorMacHigh::Enqueue (Ptr<const Packet> packet,
                         Mac48Address to, Mac48Address from)
{
}

void
MonitorMacHigh::Enqueue (Ptr<const Packet> packet,
                         Mac48Address to)
{
}

bool
MonitorMacHigh::SupportsSendFrom (void) const
{
  return false;
}

void
MonitorMacHigh::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
{
  NS_LOG_FUNCTION (this << packet << from);
  m_forwardUp (packet, from, to);
}

void
MonitorMacHigh::Receive (Ptr<Packet> packet, const WifiMacHeader *hdr, const RadiotapHeader *radiotaphdr)
{

  Mac48Address to = hdr->GetAddr1 ();
  Mac48Address from = hdr->GetAddr2 ();
  NS_LOG_DEBUG ("Received packet to: " << to << " from: " << from << " at:" << m_low->GetAddress ());
  packet->AddHeader (*radiotaphdr);
  ForwardUp (packet, from, to);
}

void
MonitorMacHigh::DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket,
                                            const WifiMacHeader *hdr)
{
}

void
MonitorMacHigh::SendAddBaResponse (const MgtAddBaRequestHeader *reqHdr,
                                   Mac48Address originator)
{
}

void
MonitorMacHigh::FinishConfigureStandard (enum WifiPhyStandard standard)
{
  uint32_t cwmin;
  uint32_t cwmax;

  switch (standard)
    {
    case WIFI_PHY_STANDARD_80211p_CCH:
    case WIFI_PHY_STANDARD_80211p_SCH:
      cwmin = 15;
      cwmax = 511;
      break;

    case WIFI_PHY_STANDARD_holland:
    case WIFI_PHY_STANDARD_80211a:
    case WIFI_PHY_STANDARD_80211g:
    case WIFI_PHY_STANDARD_80211_10Mhz:
    case WIFI_PHY_STANDARD_80211_5Mhz:
      cwmin = 15;
      cwmax = 1023;
      break;

    case WIFI_PHY_STANDARD_80211b:
      cwmin = 31;
      cwmax = 1023;
      break;

    default:
      NS_FATAL_ERROR ("Unsupported WifiPhyStandard in MonitorMacHigh::FinishConfigureStandard ()");
    }

  // The special value of AC_BE_NQOS which exists in the Access
  // Category enumeration allows us to configure plain old DCF.
  ConfigureDcf (m_dca, cwmin, cwmax, AC_BE_NQOS);
}

void
MonitorMacHigh::TxOk (const WifiMacHeader &hdr)
{
  NS_LOG_FUNCTION (this << hdr);
  m_txOkCallback (hdr);
}

void
MonitorMacHigh::TxFailed (const WifiMacHeader &hdr)
{
  NS_LOG_FUNCTION (this << hdr);
  m_txErrCallback (hdr);
}

} // namespace ns3