Merge with ns-3-dev

This commit is contained in:
Kirill Andreev
2009-04-29 18:26:25 +04:00
97 changed files with 7132 additions and 401 deletions

View File

@@ -76,6 +76,7 @@ UdpEchoClient::UdpEchoClient ()
UdpEchoClient::~UdpEchoClient()
{
NS_LOG_FUNCTION_NOARGS ();
m_socket = 0;
}
void
@@ -117,6 +118,7 @@ UdpEchoClient::StopApplication ()
if (m_socket != 0)
{
m_socket->Close ();
m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket> > ());
}

View File

@@ -55,6 +55,7 @@ UdpEchoServer::UdpEchoServer ()
UdpEchoServer::~UdpEchoServer()
{
NS_LOG_FUNCTION_NOARGS ();
m_socket = 0;
}
void
@@ -87,6 +88,7 @@ UdpEchoServer::StopApplication ()
if (m_socket != 0)
{
m_socket->Close ();
m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket> > ());
}
}

View File

@@ -722,20 +722,6 @@ CsmaNetDevice::Receive (Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
NS_LOG_FUNCTION (packet << senderDevice);
NS_LOG_LOGIC ("UID is " << packet->GetUid ());
/* IPv6 support*/
uint8_t mac[6];
Mac48Address multicast6AllNodes("33:33:00:00:00:01");
Mac48Address multicast6AllRouters("33:33:00:00:00:02");
Mac48Address multicast6AllHosts("33:33:00:00:00:03");
Mac48Address multicast6Node; /* multicast address addressed to our MAC address */
/* generate IPv6 multicast ethernet destination that nodes will accept */
GetAddress().CopyTo(mac);
mac[0]=0x33;
mac[1]=0x33;
/* mac[2]=0xff; */
multicast6Node.CopyFrom(mac);
//
// We never forward up packets that we sent. Real devices don't do this since
// their receivers are disabled during send, so we don't.
@@ -805,16 +791,12 @@ CsmaNetDevice::Receive (Ptr<Packet> packet, Ptr<CsmaNetDevice> senderDevice)
// Classify the packet based on its destination.
//
PacketType packetType;
if (header.GetDestination ().IsBroadcast ())
{
packetType = PACKET_BROADCAST;
}
else if (header.GetDestination ().IsMulticast () ||
header.GetDestination() == multicast6Node ||
header.GetDestination() == multicast6AllNodes ||
header.GetDestination() == multicast6AllRouters ||
header.GetDestination() == multicast6AllHosts)
else if (header.GetDestination ().IsGroup ())
{
packetType = PACKET_MULTICAST;
}

View File

@@ -385,7 +385,10 @@ EmuNetDevice::CreateSocket (void)
//
// Execute the socket creation process image.
//
status = ::execl (FindCreator ().c_str (), "emu-sock-creator", oss.str ().c_str (), (char *)NULL);
status = ::execl (FindCreator ("emu-sock-creator").c_str (),
"emu-sock-creator", // argv[0] (filename)
oss.str ().c_str (), // argv[1] (-p<path?
(char *)NULL);
//
// If the execl successfully completes, it never returns. If it returns it failed or the OS is
@@ -520,20 +523,41 @@ EmuNetDevice::CreateSocket (void)
}
std::string
EmuNetDevice::FindCreator (void)
EmuNetDevice::FindCreator (std::string creatorName)
{
struct stat st;
std::string debug = "./build/debug/src/devices/emu/emu-sock-creator";
std::string optimized = "./build/optimized/src/devices/emu/emu-sock-creator";
NS_LOG_FUNCTION (creatorName);
if (::stat (debug.c_str (), &st) == 0)
{
return debug;
}
std::list<std::string> locations;
if (::stat (optimized.c_str (), &st) == 0)
// The path to the bits if we're sitting there with them
locations.push_back ("./");
locations.push_back ("./");
// The path to the bits if we're sitting in the root of the repo
locations.push_back ("./build/optimized/src/devices/emu/");
locations.push_back ("./build/debug/src/devices/emu/");
// if at the level of src (or build)
locations.push_back ("../build/optimized/src/devices/emu/");
locations.push_back ("../build/debug/src/devices/emu/");
// src/devices (or build/debug)
locations.push_back ("../../build/optimized/src/devices/emu/");
locations.push_back ("../../build/debug/src/devices/emu/");
// src/devices/emu (or build/debug/examples)
locations.push_back ("../../../build/optimized/src/devices/emu/");
locations.push_back ("../../../build/debug/src/devices/emu/");
for (std::list<std::string>::const_iterator i = locations.begin (); i != locations.end (); ++i)
{
return optimized;
struct stat st;
if (::stat ((*i + creatorName).c_str (), &st) == 0)
{
NS_LOG_INFO ("Found Creator " << *i + creatorName);
return *i + creatorName;
}
}
NS_FATAL_ERROR ("EmuNetDevice::FindCreator(): Couldn't find creator");
@@ -560,19 +584,6 @@ EmuNetDevice::ForwardUp (uint8_t *buf, uint32_t len)
{
NS_LOG_FUNCTION (buf << len);
/* IPv6 support*/
uint8_t mac[6];
Mac48Address multicast6AllNodes("33:33:00:00:00:01");
Mac48Address multicast6AllRouters("33:33:00:00:00:02");
Mac48Address multicast6AllHosts("33:33:00:00:00:03");
Mac48Address multicast6Node; /* multicast address addressed to our MAC address */
/* generate IPv6 multicast ethernet destination that nodes will accept */
GetAddress().CopyTo(mac);
mac[0]=0x33;
mac[1]=0x33;
multicast6Node.CopyFrom(mac);
//
// Create a packet out of the buffer we received and free that buffer.
//
@@ -586,13 +597,6 @@ EmuNetDevice::ForwardUp (uint8_t *buf, uint32_t len)
//
Ptr<Packet> originalPacket = packet->Copy ();
//
// Checksum the packet
//
EthernetTrailer trailer;
packet->RemoveTrailer (trailer);
trailer.CheckFcs (packet);
EthernetHeader header (false);
packet->RemoveHeader (header);
@@ -619,16 +623,12 @@ EmuNetDevice::ForwardUp (uint8_t *buf, uint32_t len)
}
PacketType packetType;
if (header.GetDestination ().IsBroadcast ())
{
packetType = NS3_PACKET_BROADCAST;
}
else if (header.GetDestination ().IsMulticast () ||
header.GetDestination() == multicast6Node ||
header.GetDestination() == multicast6AllNodes ||
header.GetDestination() == multicast6AllRouters ||
header.GetDestination() == multicast6AllHosts)
else if (header.GetDestination ().IsGroup ())
{
packetType = NS3_PACKET_MULTICAST;
}

View File

@@ -196,7 +196,7 @@ private:
/**
* Figure out where the raw socket creation process lives on the system.
*/
std::string FindCreator (void);
std::string FindCreator (std::string creatorName);
/**
* Get a copy of the attached Queue.

View File

@@ -87,7 +87,7 @@ MeshPointDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<const Packe
NS_LOG_DEBUG ("SRC="<<src48<<", DST = "<<dst48<<", I am: "<<m_address);
if (!m_promiscRxCallback.IsNull ())
m_promiscRxCallback (this, packet, protocol, src, dst, packetType);
if(dst48.IsBroadcast () || dst48.IsMulticast ())
if(dst48.IsBroadcast () || dst48.IsGroup ())
{
m_rxCallback (this, packet, protocol, src);
Forward (incomingPort, packet->Copy (), protocol, src48, dst48);

View File

@@ -46,7 +46,8 @@ AdhocWifiMac::GetTypeId (void)
.AddConstructor<AdhocWifiMac> ()
.AddAttribute ("DcaTxop", "The DcaTxop object",
PointerValue (),
MakePointerAccessor (&AdhocWifiMac::DoGetDcaTxop),
MakePointerAccessor (&AdhocWifiMac::GetDcaTxop,
&AdhocWifiMac::SetDcaTxop),
MakePointerChecker<DcaTxop> ())
;
return tid;
@@ -63,10 +64,6 @@ AdhocWifiMac::AdhocWifiMac ()
m_dcfManager = new DcfManager ();
m_dcfManager->SetupLowListener (m_low);
m_dca = CreateObject<DcaTxop> ();
m_dca->SetLow (m_low);
m_dca->SetManager (m_dcfManager);
}
AdhocWifiMac::~AdhocWifiMac ()
{}
@@ -250,9 +247,18 @@ AdhocWifiMac::ForwardUp (Ptr<Packet> packet, WifiMacHeader const *hdr)
m_upCallback (packet, hdr->GetAddr2 (), hdr->GetAddr1 ());
}
Ptr<DcaTxop>
AdhocWifiMac::DoGetDcaTxop(void) const
AdhocWifiMac::GetDcaTxop(void) const
{
return m_dca;
}
void
AdhocWifiMac::SetDcaTxop (Ptr<DcaTxop> dcaTxop)
{
m_dca = dcaTxop;
m_dca->SetLow (m_low);
m_dca->SetManager (m_dcfManager);
}
} // namespace ns3

View File

@@ -86,7 +86,8 @@ private:
void ForwardUp (Ptr<Packet> packet, WifiMacHeader const*hdr);
AdhocWifiMac (const AdhocWifiMac & ctor_arg);
AdhocWifiMac &operator = (const AdhocWifiMac &o);
Ptr<DcaTxop> DoGetDcaTxop(void) const;
Ptr<DcaTxop> GetDcaTxop(void) const;
void SetDcaTxop (Ptr<DcaTxop> dcaTxop);
Ptr<DcaTxop> m_dca;
Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> m_upCallback;

View File

@@ -0,0 +1,116 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "amsdu-subframe-header.h"
#include "ns3/address-utils.h"
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (AmsduSubframeHeader);
TypeId
AmsduSubframeHeader::GetTypeId ()
{
static TypeId tid = TypeId ("ns3::AmsduSubframeHeader")
.SetParent<Header> ()
.AddConstructor<AmsduSubframeHeader> ()
;
return tid;
}
TypeId
AmsduSubframeHeader::GetInstanceTypeId (void) const
{
return GetTypeId ();
}
AmsduSubframeHeader::AmsduSubframeHeader ()
: m_length (0)
{}
AmsduSubframeHeader::~AmsduSubframeHeader ()
{}
uint32_t
AmsduSubframeHeader::GetSerializedSize () const
{
return (6 + 6 + 2);
}
void
AmsduSubframeHeader::Serialize (Buffer::Iterator i) const
{
WriteTo (i, m_da);
WriteTo (i, m_sa);
i.WriteHtonU16 (m_length);
}
uint32_t
AmsduSubframeHeader::Deserialize (Buffer::Iterator start)
{
Buffer::Iterator i = start;
ReadFrom (i, m_da);
ReadFrom (i, m_sa);
m_length = i.ReadNtohU16 ();
return i.GetDistanceFrom (start);
}
void
AmsduSubframeHeader::Print (std::ostream &os) const
{
os << "DA = " << m_da << ", SA = " << m_sa << ", length = " << m_length;
}
void
AmsduSubframeHeader::SetDestinationAddr (Mac48Address to)
{
m_da = to;
}
void
AmsduSubframeHeader::SetSourceAddr (Mac48Address from)
{
m_sa = from;
}
void
AmsduSubframeHeader::SetLength (uint16_t length)
{
m_length = length;
}
Mac48Address
AmsduSubframeHeader::GetDestinationAddr (void) const
{
return m_da;
}
Mac48Address
AmsduSubframeHeader::GetSourceAddr (void) const
{
return m_sa;
}
uint16_t
AmsduSubframeHeader::GetLength (void) const
{
return m_length;
}
} //namespace ns3

View File

@@ -0,0 +1,57 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef AMSDU_SUBFRAME_HEADER_H
#define AMSDU_SUBFRAME_HEADER_H
#include "ns3/header.h"
#include "ns3/mac48-address.h"
namespace ns3 {
class AmsduSubframeHeader : public Header
{
public:
AmsduSubframeHeader ();
virtual ~AmsduSubframeHeader ();
static TypeId GetTypeId (void);
virtual TypeId GetInstanceTypeId (void) const;
virtual void Print (std::ostream &os) const;
virtual uint32_t GetSerializedSize (void) const;
virtual void Serialize (Buffer::Iterator start) const;
virtual uint32_t Deserialize (Buffer::Iterator start);
void SetDestinationAddr (Mac48Address to);
void SetSourceAddr (Mac48Address to);
void SetLength (uint16_t);
Mac48Address GetDestinationAddr (void) const;
Mac48Address GetSourceAddr (void) const;
uint16_t GetLength (void) const;
private:
Mac48Address m_da;
Mac48Address m_sa;
uint16_t m_length;
};
} //namespace ns3
#endif /* AMSDU_SUBFRAME_HEADER_H */

View File

@@ -93,10 +93,12 @@ private:
DcaTxop *m_txop;
};
NS_OBJECT_ENSURE_REGISTERED (DcaTxop);
TypeId
DcaTxop::GetTypeId (void)
{
static TypeId tid = TypeId ("DcaTxop")
static TypeId tid = TypeId ("ns3::DcaTxop")
.SetParent<Object> ()
.AddConstructor<DcaTxop> ()
.AddAttribute ("MinCw", "The minimum value of the contention window.",

View File

@@ -115,6 +115,9 @@ private:
friend class TransmissionListener;
friend class WifiRemoteStation;
DcaTxop &operator = (const DcaTxop &);
DcaTxop (const DcaTxop &o);
// Inherited from ns3::Object
Ptr<MacLow> Low (void);

View File

@@ -0,0 +1,691 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/log.h"
#include "ns3/assert.h"
#include "edca-txop-n.h"
#include "mac-low.h"
#include "dcf-manager.h"
#include "mac-tx-middle.h"
#include "wifi-mac-trailer.h"
#include "wifi-mac.h"
#include "random-stream.h"
#include "wifi-mac-queue.h"
#include "msdu-aggregator.h"
NS_LOG_COMPONENT_DEFINE ("EdcaTxopN");
#define MY_DEBUG(x) \
NS_LOG_DEBUG (m_low->GetAddress () << " " << x)
namespace ns3 {
class EdcaTxopN::Dcf : public DcfState
{
public:
Dcf (EdcaTxopN *txop)
: m_txop (txop)
{}
private:
virtual void DoNotifyAccessGranted (void) {
m_txop->NotifyAccessGranted ();
}
virtual void DoNotifyInternalCollision (void) {
m_txop->NotifyInternalCollision ();
}
virtual void DoNotifyCollision (void) {
m_txop->NotifyCollision ();
}
EdcaTxopN *m_txop;
};
class EdcaTxopN::TransmissionListener : public MacLowTransmissionListener
{
public:
TransmissionListener (EdcaTxopN *txop)
: MacLowTransmissionListener (),
m_txop (txop) {}
virtual ~TransmissionListener () {}
virtual void GotCts (double snr, WifiMode txMode) {
m_txop->GotCts (snr, txMode);
}
virtual void MissedCts (void) {
m_txop->MissedCts ();
}
virtual void GotAck (double snr, WifiMode txMode) {
m_txop->GotAck (snr, txMode);
}
virtual void MissedAck (void) {
m_txop->MissedAck ();
}
virtual void StartNext (void) {
m_txop->StartNext ();
}
virtual void Cancel (void) {
m_txop->Cancel ();
}
private:
EdcaTxopN *m_txop;
};
NS_OBJECT_ENSURE_REGISTERED (EdcaTxopN);
TypeId
EdcaTxopN::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::EdcaTxopN")
.SetParent<Object> ()
.AddConstructor<EdcaTxopN> ()
.AddAttribute ("MinCw", "The minimun value of the contention window.",
UintegerValue (31),
MakeUintegerAccessor (&EdcaTxopN::SetMinCw,
&EdcaTxopN::GetMinCw),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("MaxCw", "The maximum value of the contention window.",
UintegerValue (1023),
MakeUintegerAccessor (&EdcaTxopN::SetMaxCw,
&EdcaTxopN::GetMaxCw),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("Aifsn", "The AIFSN: the default value conforms to simple DCA.",
UintegerValue (3),
MakeUintegerAccessor (&EdcaTxopN::SetAifsn,
&EdcaTxopN::GetAifsn),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
EdcaTxopN::EdcaTxopN ()
: m_manager (0),
m_currentPacket(0),
m_aggregator (0)
{
NS_LOG_FUNCTION (this);
m_transmissionListener = new EdcaTxopN::TransmissionListener (this);
m_dcf = new EdcaTxopN::Dcf (this);
m_queue = CreateObject<WifiMacQueue> ();
m_rng = new RealRandomStream ();
}
EdcaTxopN::~EdcaTxopN ()
{
NS_LOG_FUNCTION (this);
}
void
EdcaTxopN::DoDispose (void)
{
NS_LOG_FUNCTION (this);
m_queue = 0;
m_low = 0;
m_stationManager = 0;
delete m_transmissionListener;
delete m_dcf;
delete m_rng;
m_transmissionListener = 0;
m_dcf = 0;
m_rng = 0;
m_txMiddle = 0;
m_aggregator = 0;
}
void
EdcaTxopN::SetManager (DcfManager *manager)
{
NS_LOG_FUNCTION (this << manager);
m_manager = manager;
m_manager->Add (m_dcf);
}
void
EdcaTxopN::SetTxOkCallback (TxOk callback)
{
m_txOkCallback = callback;
}
void
EdcaTxopN::SetTxFailedCallback (TxFailed callback)
{
m_txFailedCallback = callback;
}
void
EdcaTxopN::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> remoteManager)
{
NS_LOG_FUNCTION (this << remoteManager);
m_stationManager = remoteManager;
}
void
EdcaTxopN::SetTypeOfStation (enum TypeOfStation type)
{
NS_LOG_FUNCTION (this << type);
m_typeOfStation = type;
}
enum TypeOfStation
EdcaTxopN::GetTypeOfStation (void) const
{
return m_typeOfStation;
}
void
EdcaTxopN::SetMaxQueueSize (uint32_t size)
{
NS_LOG_FUNCTION (this << size);
m_queue->SetMaxSize (size);
}
void
EdcaTxopN::SetMaxQueueDelay (Time delay)
{
NS_LOG_FUNCTION (this << delay);
m_queue->SetMaxDelay (delay);
}
void
EdcaTxopN::SetMinCw (uint32_t minCw)
{
NS_LOG_FUNCTION (this << minCw);
m_dcf->SetCwMin (minCw);
}
void
EdcaTxopN::SetMaxCw (uint32_t maxCw)
{
NS_LOG_FUNCTION (this << maxCw);
m_dcf->SetCwMax (maxCw);
}
void
EdcaTxopN::SetAifsn (uint32_t aifsn)
{
NS_LOG_FUNCTION (this << aifsn);
m_dcf->SetAifsn (aifsn);
}
uint32_t
EdcaTxopN::GetMinCw (void) const
{
return m_dcf->GetCwMin ();
}
uint32_t
EdcaTxopN::GetMaxCw (void) const
{
return m_dcf->GetCwMax ();
}
uint32_t
EdcaTxopN::GetAifsn (void) const
{
return m_dcf->GetAifsn ();
}
void
EdcaTxopN::SetTxMiddle (MacTxMiddle *txMiddle)
{
m_txMiddle = txMiddle;
}
Ptr<MacLow>
EdcaTxopN::Low (void)
{
return m_low;
}
void
EdcaTxopN::SetLow(Ptr<MacLow> low)
{
NS_LOG_FUNCTION (this << low);
m_low = low;
}
bool
EdcaTxopN::NeedsAccess (void) const
{
return !m_queue->IsEmpty () || m_currentPacket != 0;
}
void
EdcaTxopN::NotifyAccessGranted (void)
{
NS_LOG_FUNCTION (this);
if (m_currentPacket == 0)
{
if (m_queue->IsEmpty ())
{
MY_DEBUG ("queue is empty");
return;
}
m_currentPacket = m_queue->Dequeue (&m_currentHdr);
NS_ASSERT (m_currentPacket != 0);
uint16_t sequence = m_txMiddle->GetNextSequenceNumberfor (&m_currentHdr);
m_currentHdr.SetSequenceNumber (sequence);
m_currentHdr.SetFragmentNumber (0);
m_currentHdr.SetNoMoreFragments ();
m_currentHdr.SetNoRetry ();
m_fragmentNumber = 0;
MY_DEBUG ("dequeued size="<<m_currentPacket->GetSize ()<<
", to="<<m_currentHdr.GetAddr1 ()<<
", seq="<<m_currentHdr.GetSequenceControl ());
}
MacLowTransmissionParameters params;
params.DisableOverrideDurationId ();
if (m_currentHdr.GetAddr1 ().IsBroadcast ())
{
params.DisableRts ();
params.DisableAck ();
params.DisableNextData ();
m_low->StartTransmission (m_currentPacket,
&m_currentHdr,
params,
m_transmissionListener);
m_currentPacket = 0;
m_dcf->ResetCw ();
m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
StartAccessIfNeeded ();
MY_DEBUG ("tx broadcast");
}
else
{
params.EnableAck ();
if (NeedFragmentation () && ((m_currentHdr.IsQosData () &&
!m_currentHdr.IsQosAmsdu ()) ||
m_currentHdr.IsData ()))
{
params.DisableRts ();
WifiMacHeader hdr;
Ptr<Packet> fragment = GetFragmentPacket (&hdr);
if (IsLastFragment ())
{
MY_DEBUG ("fragmenting last fragment size=" << fragment->GetSize ());
params.DisableNextData ();
}
else
{
MY_DEBUG ("fragmenting size=" << fragment->GetSize ());
params.EnableNextData (GetNextFragmentSize ());
}
m_low->StartTransmission (fragment, &hdr, params,
m_transmissionListener);
}
else
{
WifiMacHeader peekedHdr;
if (m_currentHdr.IsQosData () &&
m_queue->PeekByTidAndAddress (&peekedHdr, m_currentHdr.GetQosTid (),
WifiMacHeader::ADDR1, m_currentHdr.GetAddr1 ()) &&
!m_currentHdr.GetAddr1 ().IsBroadcast () &&
m_aggregator != 0)
{
/* here is performed aggregation */
Ptr<Packet> currentAggregatedPacket = Create<Packet> ();
m_aggregator->Aggregate (m_currentPacket, currentAggregatedPacket,
MapSrcAddressForAggregation (peekedHdr),
MapDestAddressForAggregation (peekedHdr));
bool aggregated = false;
bool isAmsdu = false;
Ptr<const Packet> peekedPacket = m_queue->PeekByTidAndAddress (&peekedHdr, m_currentHdr.GetQosTid (),
WifiMacHeader::ADDR1,
m_currentHdr.GetAddr1 ());
while (peekedPacket != 0)
{
aggregated = m_aggregator->Aggregate (peekedPacket, currentAggregatedPacket,
MapSrcAddressForAggregation (peekedHdr),
MapDestAddressForAggregation (peekedHdr));
if (aggregated)
{
isAmsdu = true;
m_queue->Remove (peekedPacket);
}
else
{
break;
}
peekedPacket = m_queue->PeekByTidAndAddress (&peekedHdr, m_currentHdr.GetQosTid (),
WifiMacHeader::ADDR1, m_currentHdr.GetAddr1 ());
}
if (isAmsdu)
{
m_currentHdr.SetQosAmsdu ();
m_currentHdr.SetAddr3 (m_low->GetBssid ());
m_currentPacket = currentAggregatedPacket;
currentAggregatedPacket = 0;
MY_DEBUG ("tx unicast A-MSDU");
}
}
if (NeedRts ())
{
params.EnableRts ();
MY_DEBUG ("tx unicast rts");
}
else
{
params.DisableRts ();
MY_DEBUG ("tx unicast");
}
params.DisableNextData ();
m_low->StartTransmission (m_currentPacket, &m_currentHdr,
params, m_transmissionListener);
}
}
}
void EdcaTxopN::NotifyInternalCollision (void)
{
NS_LOG_FUNCTION (this);
NotifyCollision ();
}
void
EdcaTxopN::NotifyCollision (void)
{
NS_LOG_FUNCTION (this);
m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
RestartAccessIfNeeded ();
}
void
EdcaTxopN::GotCts (double snr, WifiMode txMode)
{
NS_LOG_FUNCTION (this << snr << txMode);
MY_DEBUG ("got cts");
}
void
EdcaTxopN::MissedCts (void)
{
NS_LOG_FUNCTION (this);
MY_DEBUG ("missed cts");
if (!NeedRtsRetransmission ())
{
MY_DEBUG ("Cts Fail");
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
station->ReportFinalRtsFailed ();
if (!m_txFailedCallback.IsNull ())
{
m_txFailedCallback (m_currentHdr);
}
// to reset the dcf.
m_currentPacket = 0;
m_dcf->ResetCw ();
}
else
{
m_dcf->UpdateFailedCw ();
}
m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
RestartAccessIfNeeded ();
}
void
EdcaTxopN::Queue (Ptr<const Packet> packet, WifiMacHeader const &hdr)
{
NS_LOG_FUNCTION (this << packet << &hdr);
WifiMacTrailer fcs;
uint32_t fullPacketSize = hdr.GetSerializedSize () + packet->GetSize () + fcs.GetSerializedSize ();
WifiRemoteStation *station = GetStation (hdr.GetAddr1 ());
station->PrepareForQueue (packet, fullPacketSize);
m_queue->Enqueue (packet, hdr);
StartAccessIfNeeded ();
}
void
EdcaTxopN::GotAck (double snr, WifiMode txMode)
{
NS_LOG_FUNCTION (this << snr << txMode);
if (!NeedFragmentation () ||
IsLastFragment () ||
m_currentHdr.IsQosAmsdu ())
{
MY_DEBUG ("got ack. tx done.");
if (!m_txOkCallback.IsNull ())
{
m_txOkCallback (m_currentHdr);
}
m_currentPacket = 0;
m_dcf->ResetCw ();
m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
RestartAccessIfNeeded ();
}
else
{
MY_DEBUG ("got ack. tx not done, size="<<m_currentPacket->GetSize ());
}
}
void
EdcaTxopN::MissedAck (void)
{
NS_LOG_FUNCTION (this);
MY_DEBUG ("missed ack");
if (!NeedDataRetransmission ())
{
MY_DEBUG ("Ack Fail");
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
station->ReportFinalDataFailed ();
if (!m_txFailedCallback.IsNull ())
{
m_txFailedCallback (m_currentHdr);
}
// to reset the dcf.
m_currentPacket = 0;
m_dcf->ResetCw ();
}
else
{
MY_DEBUG ("Retransmit");
m_currentHdr.SetRetry ();
m_dcf->UpdateFailedCw ();
}
m_dcf->StartBackoffNow (m_rng->GetNext (0, m_dcf->GetCw ()));
RestartAccessIfNeeded ();
}
Ptr<MsduAggregator>
EdcaTxopN::GetMsduAggregator (void) const
{
return m_aggregator;
}
void
EdcaTxopN::RestartAccessIfNeeded (void)
{
NS_LOG_FUNCTION (this);
if ((m_currentPacket != 0 ||
!m_queue->IsEmpty ()) &&
!m_dcf->IsAccessRequested ())
{
m_manager->RequestAccess (m_dcf);
}
}
void
EdcaTxopN::StartAccessIfNeeded (void)
{
NS_LOG_FUNCTION (this);
if (m_currentPacket == 0 &&
!m_queue->IsEmpty () &&
!m_dcf->IsAccessRequested ())
{
m_manager->RequestAccess (m_dcf);
}
}
bool
EdcaTxopN::NeedRts (void)
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->NeedRts (m_currentPacket);
}
bool
EdcaTxopN::NeedRtsRetransmission (void)
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->NeedRtsRetransmission (m_currentPacket);
}
bool
EdcaTxopN::NeedDataRetransmission (void)
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->NeedDataRetransmission (m_currentPacket);
}
void
EdcaTxopN::NextFragment (void)
{
m_fragmentNumber++;
}
void
EdcaTxopN::StartNext (void)
{
NS_LOG_FUNCTION (this);
MY_DEBUG ("start next packet fragment");
/* this callback is used only for fragments. */
NextFragment ();
WifiMacHeader hdr;
Ptr<Packet> fragment = GetFragmentPacket (&hdr);
MacLowTransmissionParameters params;
params.EnableAck ();
params.DisableRts ();
params.DisableOverrideDurationId ();
if (IsLastFragment ())
{
params.DisableNextData ();
}
else
{
params.EnableNextData (GetNextFragmentSize ());
}
Low ()->StartTransmission (fragment, &hdr, params, m_transmissionListener);
}
void
EdcaTxopN::Cancel (void)
{
NS_LOG_FUNCTION (this);
MY_DEBUG ("transmission cancelled");
}
bool
EdcaTxopN::NeedFragmentation (void) const
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->NeedFragmentation (m_currentPacket);
}
uint32_t
EdcaTxopN::GetFragmentSize (void)
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->GetFragmentSize (m_currentPacket, m_fragmentNumber);
}
uint32_t
EdcaTxopN::GetNextFragmentSize (void)
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->GetFragmentSize (m_currentPacket, m_fragmentNumber + 1);
}
uint32_t
EdcaTxopN::GetFragmentOffset (void)
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->GetFragmentOffset (m_currentPacket, m_fragmentNumber);
}
WifiRemoteStation *
EdcaTxopN::GetStation (Mac48Address ad) const
{
return m_stationManager->Lookup (ad);
}
bool
EdcaTxopN::IsLastFragment (void) const
{
WifiRemoteStation *station = GetStation (m_currentHdr.GetAddr1 ());
return station->IsLastFragment (m_currentPacket, m_fragmentNumber);
}
Ptr<Packet>
EdcaTxopN::GetFragmentPacket (WifiMacHeader *hdr)
{
*hdr = m_currentHdr;
hdr->SetFragmentNumber (m_fragmentNumber);
uint32_t startOffset = GetFragmentOffset ();
Ptr<Packet> fragment;
if (IsLastFragment ())
{
hdr->SetNoMoreFragments ();
}
else
{
hdr->SetMoreFragments ();
}
fragment = m_currentPacket->CreateFragment (startOffset,
GetFragmentSize ());
return fragment;
}
Mac48Address
EdcaTxopN::MapSrcAddressForAggregation (WifiMacHeader const &hdr)
{
if (m_typeOfStation == STA || m_typeOfStation == ADHOC_STA)
{
return hdr.GetAddr2 ();
}
else
{
return hdr.GetAddr3 ();
}
}
Mac48Address
EdcaTxopN::MapDestAddressForAggregation (WifiMacHeader const &hdr)
{
if (m_typeOfStation == AP || m_typeOfStation == ADHOC_STA)
{
return hdr.GetAddr1 ();
}
else
{
return hdr.GetAddr3 ();
}
}
void
EdcaTxopN::SetMsduAggregator (Ptr<MsduAggregator> aggr)
{
m_aggregator = aggr;
}
} //namespace ns3

View File

@@ -0,0 +1,172 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef EDCA_TXOP_N_H
#define EDCA_TXOP_N_H
#include "ns3/object.h"
#include "ns3/mac48-address.h"
#include "ns3/packet.h"
#include "wifi-mode.h"
#include "wifi-mac.h"
#include "wifi-mac-header.h"
#include "qos-utils.h"
#include <map>
#include <list>
namespace ns3 {
class DcfState;
class DcfManager;
class MacLow;
class MacTxMiddle;
class WifiMacParameters;
class WifiMacQueue;
class RandomStream;
class MsduAggregator;
/* This queue contains packets for a particular access class.
* possibles access classes are:
*
* -AC_VO : voice, tid = 6,7 ^
* -AC_VI : video, tid = 4,5 |
* -AC_BE : best-effort, tid = 0,3 | priority
* -AC_BK : background, tid = 1,2 |
*
* For more details see section 9.1.3.1 in 802.11 standard.
*/
enum TypeOfStation
{
STA,
AP,
ADHOC_STA
};
class EdcaTxopN : public Object
{
public:
typedef Callback <void, WifiMacHeader const&> TxOk;
typedef Callback <void, WifiMacHeader const&> TxFailed;
static TypeId GetTypeId (void);
EdcaTxopN ();
virtual ~EdcaTxopN ();
void DoDispose ();
void SetLow (Ptr<MacLow> low);
void SetTxMiddle (MacTxMiddle *txMiddle);
void SetManager (DcfManager *manager);
void SetTxOkCallback (TxOk callback);
void SetTxFailedCallback (TxFailed callback);
void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> remoteManager);
void SetTypeOfStation (enum TypeOfStation type);
enum TypeOfStation GetTypeOfStation (void) const;
void SetMaxQueueSize (uint32_t size);
void SetMaxQueueDelay (Time delay);
void SetMinCw (uint32_t minCw);
void SetMaxCw (uint32_t maxCw);
void SetAifsn (uint32_t aifsn);
uint32_t GetMinCw (void) const;
uint32_t GetMaxCw (void) const;
uint32_t GetAifsn (void) const;
Ptr<MacLow> Low (void);
Ptr<MsduAggregator> GetMsduAggregator (void) const;
/* dcf notifications forwarded here */
bool NeedsAccess (void) const;
void NotifyAccessGranted (void);
void NotifyInternalCollision (void);
void NotifyCollision (void);
/*event handlers*/
void GotCts (double snr, WifiMode txMode);
void MissedCts (void);
void GotAck (double snr, WifiMode txMode);
void MissedAck (void);
void StartNext (void);
void Cancel (void);
void RestartAccessIfNeeded (void);
void StartAccessIfNeeded (void);
bool NeedRts (void);
bool NeedRtsRetransmission (void);
bool NeedDataRetransmission (void);
bool NeedFragmentation (void) const;
uint32_t GetNextFragmentSize (void);
uint32_t GetFragmentSize (void);
uint32_t GetFragmentOffset (void);
WifiRemoteStation *GetStation (Mac48Address to) const;
bool IsLastFragment (void) const;
void NextFragment (void);
Ptr<Packet> GetFragmentPacket (WifiMacHeader *hdr);
void Queue (Ptr<const Packet> packet, WifiMacHeader const &hdr);
void SetMsduAggregator (Ptr<MsduAggregator> aggr);
private:
/**
* This functions are used only to correctly set addresses in a-msdu subframe.
* If aggregating sta is a STA (in an infrastructured network):
* SA = Address2
* DA = Address3
* If aggregating sta is an AP
* SA = Address3
* DA = Address1
*/
Mac48Address MapSrcAddressForAggregation (WifiMacHeader const &hdr);
Mac48Address MapDestAddressForAggregation (WifiMacHeader const &hdr);
EdcaTxopN &operator = (const EdcaTxopN &);
EdcaTxopN (const EdcaTxopN &);
class Dcf;
class TransmissionListener;
friend class Dcf;
friend class TransmissionListener;
Dcf *m_dcf;
DcfManager *m_manager;
Ptr<WifiMacQueue> m_queue;
TxOk m_txOkCallback;
TxFailed m_txFailedCallback;
Ptr<MacLow> m_low;
MacTxMiddle *m_txMiddle;
TransmissionListener *m_transmissionListener;
RandomStream *m_rng;
Ptr<WifiRemoteStationManager> m_stationManager;
uint8_t m_fragmentNumber;
/* current packet could be a simple MSDU or, if an aggregator for this queue is
present, could be an A-MSDU.
*/
Ptr<const Packet> m_currentPacket;
WifiMacHeader m_currentHdr;
Ptr<MsduAggregator> m_aggregator;
TypeOfStation m_typeOfStation;
};
} //namespace ns3
#endif /* EDCA_TXOP_N_H */

View File

@@ -1,6 +1,7 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* Copyright (c) 2005, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/assert.h"
@@ -26,11 +28,14 @@
namespace ns3 {
MacTxMiddle::MacTxMiddle ()
: m_sequence (0)
{}
MacTxMiddle::~MacTxMiddle ()
{
m_sequence = 0;
for (uint8_t i = 0; i < 16; i++)
for (std::map<Mac48Address,uint16_t*>::iterator i = m_qosSequences.begin(); i != m_qosSequences.end (); i++)
{
m_qosSequences[i] = 0;
delete [] i->second;
}
}
@@ -43,9 +48,25 @@ MacTxMiddle::GetNextSequenceNumberfor (const WifiMacHeader *hdr)
{
uint8_t tid = hdr->GetQosTid ();
NS_ASSERT (tid < 16);
retval = m_qosSequences[tid];
m_qosSequences[tid]++;
m_qosSequences[tid] %= 4096;
std::map<Mac48Address, uint16_t*>::iterator it = m_qosSequences.find (hdr->GetAddr1 ());
if (it != m_qosSequences.end ())
{
retval = it->second[tid];
it->second[tid]++;
it->second[tid] %= 4096;
}
else
{
retval = 0;
std::pair <Mac48Address,uint16_t*> newSeq (hdr->GetAddr1 (), new uint16_t[16]);
std::pair <std::map<Mac48Address,uint16_t*>::iterator,bool> newIns = m_qosSequences.insert (newSeq);
NS_ASSERT(newIns.second == true);
for (uint8_t i = 0; i < 16; i++)
{
newIns.first->second[i] = 0;
}
newIns.first->second[tid]++;
}
}
else
{

View File

@@ -1,6 +1,7 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* Copyright (c) 2005, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,12 +17,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef MAC_TX_MIDDLE_H
#define MAC_TX_MIDDLE_H
#include <stdint.h>
#include <map>
#include "ns3/mac48-address.h"
namespace ns3 {
@@ -30,11 +34,12 @@ class WifiMacHeader;
class MacTxMiddle {
public:
MacTxMiddle ();
~MacTxMiddle ();
uint16_t GetNextSequenceNumberfor (const WifiMacHeader *hdr);
private:
uint16_t m_qosSequences[16];
std::map <Mac48Address,uint16_t*> m_qosSequences;
uint16_t m_sequence;
};

View File

@@ -0,0 +1,78 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/log.h"
#include "msdu-aggregator.h"
#include "wifi-mac-header.h"
NS_LOG_COMPONENT_DEFINE ("MsduAggregator");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (MsduAggregator);
TypeId
MsduAggregator::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::MsduAggregator")
.SetParent<Object> ()
;
return tid;
}
MsduAggregator::DeaggregatedMsdus
MsduAggregator::Deaggregate (Ptr<Packet> aggregatedPacket)
{
NS_LOG_FUNCTION_NOARGS ();
DeaggregatedMsdus set;
AmsduSubframeHeader hdr;
uint32_t maxSize = aggregatedPacket->GetSize ();
// The worst condition is: two aggregated packets with no padding.
// 28 bytes is the size of two Amsdu subframe headers.
uint8_t *buffer = new uint8_t[maxSize-28];
uint32_t padding;
uint32_t deserialized = 0;
while (deserialized < maxSize)
{
deserialized += aggregatedPacket->RemoveHeader (hdr);
deserialized += aggregatedPacket->CopyData (buffer, hdr.GetLength ());
aggregatedPacket->RemoveAtStart (hdr.GetLength ());
padding = (4 - ((hdr.GetLength () + 14) %4 )) % 4;
if (padding > 0)
{
aggregatedPacket->RemoveAtStart (padding);
deserialized += padding;
}
//a new packet is created with the content of extracted msdu
Ptr<Packet> p = Create<Packet> (buffer, hdr.GetLength ());
std::pair<Ptr<Packet>, AmsduSubframeHeader> packetHdr (p,hdr);
set.push_back (packetHdr);
}
delete [] buffer;
NS_LOG_INFO ("Deaggreated A-MSDU: extracted "<< set.size () << " MSDUs");
return set;
}
} //namespace ns3

View File

@@ -0,0 +1,55 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef MSDU_AGGREGATOR_H
#define MSDU_AGGREGATOR_H
#include "ns3/ptr.h"
#include "ns3/packet.h"
#include "ns3/object.h"
#include "amsdu-subframe-header.h"
#include <list>
namespace ns3 {
class WifiMacHeader;
/**
* \brief Abstract class that concrete msdu aggregators have to implement
*/
class MsduAggregator : public Object
{
public:
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> > DeaggregatedMsdus;
static TypeId GetTypeId (void);
/* Adds <i>packet</i> to <i>aggregatedPacket</i>. In concrete aggregator's implementation is
* specified how and if <i>packet</i> can be added to <i>aggregatedPacket</i>. If <i>packet</i>
* can be added returns true, false otherwise.
*/
virtual bool Aggregate (Ptr<const Packet> packet, Ptr<Packet> aggregatedPacket,
Mac48Address src, Mac48Address dest) = 0;
static DeaggregatedMsdus Deaggregate (Ptr<Packet> aggregatedPacket);
};
} //namespace ns3
#endif /* MSDU_AGGREGATOR_H */

View File

@@ -0,0 +1,86 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/log.h"
#include "ns3/uinteger.h"
#include "amsdu-subframe-header.h"
#include "msdu-standard-aggregator.h"
NS_LOG_COMPONENT_DEFINE ("MsduStandardAggregator");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (MsduStandardAggregator);
TypeId
MsduStandardAggregator::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::MsduStandardAggregator")
.SetParent<MsduAggregator> ()
.AddConstructor<MsduStandardAggregator> ()
.AddAttribute ("MaxAmsduSize", "Max length in byte of an A-MSDU",
UintegerValue (7935),
MakeUintegerAccessor (&MsduStandardAggregator::m_maxAmsduLength),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
MsduStandardAggregator::MsduStandardAggregator ()
{}
MsduStandardAggregator::~MsduStandardAggregator ()
{}
bool
MsduStandardAggregator::Aggregate (Ptr<const Packet> packet, Ptr<Packet> aggregatedPacket,
Mac48Address src, Mac48Address dest)
{
NS_LOG_FUNCTION (this);
Ptr<Packet> currentPacket;
AmsduSubframeHeader currentHdr;
uint32_t padding = CalculatePadding (packet);
uint32_t actualSize = aggregatedPacket->GetSize ();
if ((14 + packet->GetSize () + actualSize + padding) <= m_maxAmsduLength)
{
currentHdr.SetDestinationAddr (dest);
currentHdr.SetSourceAddr (src);
currentHdr.SetLength (packet->GetSize ());
currentPacket = packet->Copy ();
if (padding)
{
currentPacket->AddPaddingAtEnd (padding);
}
currentPacket->AddHeader (currentHdr);
aggregatedPacket->AddAtEnd (currentPacket);
return true;
}
return false;
}
uint32_t
MsduStandardAggregator::CalculatePadding (Ptr<const Packet> packet)
{
return (4 - ((packet->GetSize() + 14) %4 )) % 4;
}
} //namespace ns3

View File

@@ -0,0 +1,56 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef MSDU_STANDARD_AGGREGATOR_H
#define MSDU_STANDARD_AGGREGATOR_H
#include "msdu-aggregator.h"
namespace ns3 {
class MsduStandardAggregator : public MsduAggregator
{
public:
static TypeId GetTypeId (void);
MsduStandardAggregator ();
~MsduStandardAggregator ();
/**
* \param packet Packet we have to insert into </i>aggregatedPacket</i>.
* \param aggregatedPacket Packet that will contain <i>packet</i>, if aggregation is possible,
* \param src Source address of <i>packet</i>.
* \param dest Destination address of <i>packet</i>.
*
* This method performs an MSDU aggregation.
* Returns true if <i>packet</i> can be aggregated to <i>aggregatedPacket</i>, false otherwise.
*/
virtual bool Aggregate (Ptr<const Packet> packet, Ptr<Packet> aggregatedPacket,
Mac48Address src, Mac48Address dest);
private:
/* Calculates how much padding must be added to the end of packet.
Each A-MSDU subframe is padded so that its length is multiple of 4 octects.
*/
uint32_t CalculatePadding (Ptr<const Packet> packet);
uint32_t m_maxAmsduLength;
};
} //namespace ns3
#endif /* MSDU_STANDARD_AGGREGATOR_H */

View File

@@ -60,7 +60,8 @@ NqapWifiMac::GetTypeId (void)
MakeBooleanChecker ())
.AddAttribute ("DcaTxop", "The DcaTxop object",
PointerValue (),
MakePointerAccessor (&NqapWifiMac::DoGetDcaTxop),
MakePointerAccessor (&NqapWifiMac::GetDcaTxop,
&NqapWifiMac::SetDcaTxop),
MakePointerChecker<DcaTxop> ())
;
return tid;
@@ -78,12 +79,6 @@ NqapWifiMac::NqapWifiMac ()
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 (&NqapWifiMac::TxOk, this));
m_dca->SetTxFailedCallback (MakeCallback (&NqapWifiMac::TxFailed, this));
m_beaconDca = CreateObject<DcaTxop> ();
m_beaconDca->SetAifsn(1);
m_beaconDca->SetMinCw(0);
@@ -108,6 +103,7 @@ NqapWifiMac::DoDispose (void)
m_phy = 0;
m_dca = 0;
m_beaconDca = 0;
m_stationManager = 0;
m_beaconEvent.Cancel ();
WifiMac::DoDispose ();
}
@@ -300,8 +296,7 @@ NqapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Addr
hdr.SetAddr3 (from);
hdr.SetDsFrom ();
hdr.SetDsNotTo ();
m_dca->Queue (packet, hdr);
m_dca->Queue (packet, hdr);
}
void
NqapWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from)
@@ -565,9 +560,19 @@ NqapWifiMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
}
}
Ptr<DcaTxop>
NqapWifiMac::DoGetDcaTxop(void) const
NqapWifiMac::GetDcaTxop(void) const
{
return m_dca;
}
void
NqapWifiMac::SetDcaTxop (Ptr<DcaTxop> dcaTxop)
{
m_dca = dcaTxop;
m_dca->SetLow (m_low);
m_dca->SetManager (m_dcfManager);
m_dca->SetTxOkCallback (MakeCallback (&NqapWifiMac::TxOk, this));
m_dca->SetTxFailedCallback (MakeCallback (&NqapWifiMac::TxFailed, this));
}
} // namespace ns3

View File

@@ -21,6 +21,7 @@
#define MAC_HIGH_NQAP_H
#include <stdint.h>
#include "ns3/mac48-address.h"
#include "ns3/callback.h"
#include "ns3/packet.h"
@@ -113,7 +114,8 @@ private:
virtual void DoDispose (void);
NqapWifiMac (const NqapWifiMac & ctor_arg);
NqapWifiMac &operator = (const NqapWifiMac &o);
Ptr<DcaTxop> DoGetDcaTxop(void) const;
Ptr<DcaTxop> GetDcaTxop (void) const;
void SetDcaTxop (Ptr<DcaTxop> dcaTxop);
Ptr<DcaTxop> m_dca;
Ptr<DcaTxop> m_beaconDca;

View File

@@ -89,7 +89,8 @@ NqstaWifiMac::GetTypeId (void)
MakeBooleanChecker ())
.AddAttribute ("DcaTxop", "The DcaTxop object",
PointerValue (),
MakePointerAccessor (&NqstaWifiMac::DoGetDcaTxop),
MakePointerAccessor (&NqstaWifiMac::GetDcaTxop,
&NqstaWifiMac::SetDcaTxop),
MakePointerChecker<DcaTxop> ())
.AddTraceSource ("Assoc", "Associated with an access point.",
MakeTraceSourceAccessor (&NqstaWifiMac::m_assocLogger))
@@ -99,7 +100,6 @@ NqstaWifiMac::GetTypeId (void)
return tid;
}
NqstaWifiMac::NqstaWifiMac ()
: m_state (BEACON_MISSED),
m_probeRequestEvent (),
@@ -115,10 +115,6 @@ NqstaWifiMac::NqstaWifiMac ()
m_dcfManager = new DcfManager ();
m_dcfManager->SetupLowListener (m_low);
m_dca = CreateObject<DcaTxop> ();
m_dca->SetLow (m_low);
m_dca->SetManager (m_dcfManager);
}
NqstaWifiMac::~NqstaWifiMac ()
@@ -137,6 +133,7 @@ NqstaWifiMac::DoDispose (void)
m_dcfManager = 0;
m_phy = 0;
m_dca = 0;
m_stationManager = 0;
WifiMac::DoDispose ();
}
@@ -207,10 +204,17 @@ NqstaWifiMac::GetPifs (void) const
return m_low->GetPifs ();
}
Ptr<DcaTxop>
NqstaWifiMac::DoGetDcaTxop(void) const
NqstaWifiMac::GetDcaTxop(void) const
{
return m_dca;
}
void
NqstaWifiMac::SetDcaTxop (Ptr<DcaTxop> dcaTxop)
{
m_dca = dcaTxop;
m_dca->SetLow (m_low);
m_dca->SetManager (m_dcfManager);
}
void
NqstaWifiMac::SetWifiPhy (Ptr<WifiPhy> phy)
{
@@ -565,7 +569,7 @@ NqstaWifiMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
SetState (WAIT_ASSOC_RESP);
SendAssociationRequest ();
}
}
}
else if (hdr->IsProbeResp ())
{
if (m_state == WAIT_PROBE_RESP)

View File

@@ -137,7 +137,8 @@ private:
virtual void DoDispose (void);
NqstaWifiMac (const NqstaWifiMac & ctor_arg);
NqstaWifiMac &operator = (const NqstaWifiMac & ctor_arg);
Ptr<DcaTxop> DoGetDcaTxop(void) const;
Ptr<DcaTxop> GetDcaTxop(void) const;
void SetDcaTxop (Ptr<DcaTxop> dcaTxop);
void SetState (enum MacState value);
enum MacState m_state;

View File

@@ -0,0 +1,441 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/pointer.h"
#include "ns3/log.h"
#include "ns3/string.h"
#include "qos-tag.h"
#include "edca-txop-n.h"
#include "qadhoc-wifi-mac.h"
#include "mac-low.h"
#include "dcf-manager.h"
#include "mac-rx-middle.h"
#include "mac-tx-middle.h"
#include "wifi-mac-header.h"
#include "msdu-aggregator.h"
#include "amsdu-subframe-header.h"
#include "mgt-headers.h"
NS_LOG_COMPONENT_DEFINE ("QadhocWifiMac");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (QadhocWifiMac);
TypeId
QadhocWifiMac::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::QadhocWifiMac")
.SetParent<WifiMac> ()
.AddConstructor<QadhocWifiMac> ()
.AddAttribute ("VO_EdcaTxopN",
"Queue that manages packets belonging to AC_VO access class",
PointerValue (),
MakePointerAccessor(&QadhocWifiMac::GetVOQueue,
&QadhocWifiMac::SetVOQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("VI_EdcaTxopN",
"Queue that manages packets belonging to AC_VI access class",
PointerValue (),
MakePointerAccessor(&QadhocWifiMac::GetVIQueue,
&QadhocWifiMac::SetVIQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("BE_EdcaTxopN",
"Queue that manages packets belonging to AC_BE access class",
PointerValue (),
MakePointerAccessor(&QadhocWifiMac::GetBEQueue,
&QadhocWifiMac::SetBEQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("BK_EdcaTxopN",
"Queue that manages packets belonging to AC_BK access class",
PointerValue (),
MakePointerAccessor(&QadhocWifiMac::GetBKQueue,
&QadhocWifiMac::SetBKQueue),
MakePointerChecker<EdcaTxopN> ())
;
return tid;
}
QadhocWifiMac::QadhocWifiMac ()
{
NS_LOG_FUNCTION (this);
m_rxMiddle = new MacRxMiddle ();
m_rxMiddle->SetForwardCallback (MakeCallback (&QadhocWifiMac::Receive, this));
m_txMiddle = new MacTxMiddle ();
m_low = CreateObject<MacLow> ();
m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));
m_dcfManager = new DcfManager ();
m_dcfManager->SetupLowListener (m_low);
}
QadhocWifiMac::~QadhocWifiMac ()
{
NS_LOG_FUNCTION (this);
}
void
QadhocWifiMac::DoDispose (void)
{
NS_LOG_FUNCTION (this);
delete m_rxMiddle;
m_rxMiddle = 0;
delete m_txMiddle;
m_txMiddle = 0;
delete m_dcfManager;
m_dcfManager = 0;
m_low = 0;
m_phy = 0;
m_voEdca = 0;
m_viEdca = 0;
m_beEdca = 0;
m_bkEdca = 0;
m_stationManager = 0;
std::map<AccessClass, Ptr<EdcaTxopN> >::iterator it = m_queues.begin ();
for (;it != m_queues.end (); it++)
{
it->second = 0;
}
WifiMac::DoDispose ();
}
void
QadhocWifiMac::SetSlot (Time slotTime)
{
m_dcfManager->SetSlot (slotTime);
m_low->SetSlotTime (slotTime);
}
void
QadhocWifiMac::SetSifs (Time sifs)
{
m_dcfManager->SetSifs (sifs);
m_low->SetSifs (sifs);
}
void
QadhocWifiMac::SetEifsNoDifs (Time eifsNoDifs)
{
m_dcfManager->SetEifsNoDifs (eifsNoDifs);
m_eifsNoDifs = eifsNoDifs;
}
void
QadhocWifiMac::SetAckTimeout (Time ackTimeout)
{
m_low->SetAckTimeout (ackTimeout);
}
void
QadhocWifiMac::SetCtsTimeout (Time ctsTimeout)
{
m_low->SetCtsTimeout (ctsTimeout);
}
void
QadhocWifiMac::SetPifs (Time pifs)
{
m_low->SetPifs (pifs);
}
Time
QadhocWifiMac::GetSlot (void) const
{
return m_low->GetSlotTime ();
}
Time
QadhocWifiMac::GetSifs (void) const
{
return m_low->GetSifs ();
}
Time
QadhocWifiMac::GetEifsNoDifs (void) const
{
return m_eifsNoDifs;
}
Time
QadhocWifiMac::GetAckTimeout (void) const
{
return m_low->GetAckTimeout ();
}
Time
QadhocWifiMac::GetCtsTimeout (void) const
{
return m_low->GetCtsTimeout ();
}
Time
QadhocWifiMac::GetPifs (void) const
{
return m_low->GetPifs ();
}
void
QadhocWifiMac::SetWifiPhy (Ptr<WifiPhy> phy)
{
m_phy = phy;
m_dcfManager->SetupPhyListener (phy);
m_low->SetPhy (phy);
}
void
QadhocWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
{
NS_LOG_FUNCTION (this << stationManager);
m_stationManager = stationManager;
m_voEdca->SetWifiRemoteStationManager (stationManager);
m_viEdca->SetWifiRemoteStationManager (stationManager);
m_beEdca->SetWifiRemoteStationManager (stationManager);
m_bkEdca->SetWifiRemoteStationManager (stationManager);
m_low->SetWifiRemoteStationManager (stationManager);
}
void
QadhocWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from)
{
NS_FATAL_ERROR ("Adhoc does not support a from != m_low->GetAddress ()");
}
void
QadhocWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to)
{
/* For now Qos adhoc stations sends only Qos frame. In the future they
* should be able to send frames also to Non-Qos Stas.
*/
NS_LOG_FUNCTION (packet->GetSize () << to);
WifiMacHeader hdr;
hdr.SetType (WIFI_MAC_QOSDATA);
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK);
hdr.SetQosNoEosp ();
hdr.SetQosNoAmsdu ();
/* Transmission of multiple frames in the same
Txop is not supported for now */
hdr.SetQosTxopLimit (0);
hdr.SetAddr1 (to);
hdr.SetAddr2 (m_low->GetAddress ());
hdr.SetAddr3 (GetBssid ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
WifiRemoteStation *destination = m_stationManager->Lookup (to);
if (destination->IsBrandNew ())
{
// in adhoc mode, we assume that every destination
// supports all the rates we support.
for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
{
destination->AddSupportedMode (m_phy->GetMode (i));
}
destination->RecordDisassociated ();
}
uint8_t tid = QosUtilsGetTidForPacket (packet);
if (tid < 8)
{
hdr.SetQosTid (tid);
AccessClass ac = QosUtilsMapTidToAc (tid);
m_queues[ac]->Queue (packet, hdr);
}
else
{
//packet is considerated belonging to BestEffort AC
hdr.SetQosTid (0);
m_queues[AC_BE]->Queue (packet, hdr);
}
}
bool
QadhocWifiMac::SupportsSendFrom (void) const
{
return false;
}
void
QadhocWifiMac::SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback)
{
m_forwardUp = upCallback;
}
void
QadhocWifiMac::SetLinkUpCallback (Callback<void> linkUp)
{
// an Adhoc network is always UP.
linkUp ();
}
void
QadhocWifiMac::SetLinkDownCallback (Callback<void> linkDown)
{}
Mac48Address
QadhocWifiMac::GetAddress (void) const
{
return m_low->GetAddress ();
}
Ssid
QadhocWifiMac::GetSsid (void) const
{
return m_ssid;
}
void
QadhocWifiMac::SetAddress (Mac48Address address)
{
m_low->SetAddress (address);
m_low->SetBssid (address);
}
void
QadhocWifiMac::SetSsid (Ssid ssid)
{
NS_LOG_FUNCTION (this << ssid);
// XXX: here, we should start a special adhoc network
m_ssid = ssid;
}
Mac48Address
QadhocWifiMac::GetBssid (void) const
{
return m_low->GetBssid ();
}
void
QadhocWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
{
NS_LOG_FUNCTION (this << packet << from);
m_forwardUp (packet, from, to);
}
void
QadhocWifiMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
{
NS_LOG_FUNCTION (this << packet << hdr);
NS_ASSERT (!hdr->IsCtl ());
Mac48Address from = hdr->GetAddr2 ();
Mac48Address to = hdr->GetAddr1 ();
if (hdr->IsData ())
{
if (hdr->IsQosData () && hdr->IsQosAmsdu ())
{
NS_LOG_DEBUG ("Received A-MSDU from"<<from);
DeaggregateAmsduAndForward (packet, hdr);
}
else
{
ForwardUp (packet, from, to);
}
}
else if (hdr->IsMgt ())
{
//Handling action frames
}
}
void
QadhocWifiMac::DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket,
WifiMacHeader const *hdr)
{
DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket);
for (DeaggregatedMsdusCI i = packets.begin (); i != packets.end (); ++i)
{
ForwardUp ((*i).first, (*i).second.GetSourceAddr (),
(*i).second.GetDestinationAddr ());
}
}
Ptr<EdcaTxopN>
QadhocWifiMac::GetVOQueue (void) const
{
return m_voEdca;
}
Ptr<EdcaTxopN>
QadhocWifiMac::GetVIQueue (void) const
{
return m_viEdca;
}
Ptr<EdcaTxopN>
QadhocWifiMac::GetBEQueue (void) const
{
return m_beEdca;
}
Ptr<EdcaTxopN>
QadhocWifiMac::GetBKQueue (void) const
{
return m_bkEdca;
}
void
QadhocWifiMac::SetVOQueue (Ptr<EdcaTxopN> voQueue)
{
m_voEdca = voQueue;
m_queues.insert (std::make_pair(AC_VO, m_voEdca));
m_queues[AC_VO]->SetLow (m_low);
m_queues[AC_VO]->SetManager (m_dcfManager);
m_queues[AC_VO]->SetTypeOfStation (ADHOC_STA);
m_queues[AC_VO]->SetTxMiddle (m_txMiddle);
}
void
QadhocWifiMac::SetVIQueue (Ptr<EdcaTxopN> viQueue)
{
m_viEdca = viQueue;
m_queues.insert (std::make_pair(AC_VI, m_viEdca));
m_queues[AC_VI]->SetLow (m_low);
m_queues[AC_VI]->SetManager (m_dcfManager);
m_queues[AC_VI]->SetTypeOfStation (ADHOC_STA);
m_queues[AC_VI]->SetTxMiddle (m_txMiddle);
}
void
QadhocWifiMac::SetBEQueue (Ptr<EdcaTxopN> beQueue)
{
m_beEdca = beQueue;
m_queues.insert (std::make_pair(AC_BE, m_beEdca));
m_queues[AC_BE]->SetLow (m_low);
m_queues[AC_BE]->SetManager (m_dcfManager);
m_queues[AC_BE]->SetTypeOfStation (ADHOC_STA);
m_queues[AC_BE]->SetTxMiddle (m_txMiddle);
}
void
QadhocWifiMac::SetBKQueue (Ptr<EdcaTxopN> bkQueue)
{
m_bkEdca = bkQueue;
m_queues.insert (std::make_pair(AC_BK, m_bkEdca));
m_queues[AC_BK]->SetLow (m_low);
m_queues[AC_BK]->SetManager (m_dcfManager);
m_queues[AC_BK]->SetTypeOfStation (ADHOC_STA);
m_queues[AC_BK]->SetTxMiddle (m_txMiddle);
}
} //namespace ns3

View File

@@ -0,0 +1,122 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef QADHOC_WIFI_MAC_H
#define QADHOC_WIFI_MAC_H
#include "ns3/mac48-address.h"
#include "ns3/callback.h"
#include "ns3/packet.h"
#include "wifi-mac.h"
#include "qos-utils.h"
#include "amsdu-subframe-header.h"
namespace ns3 {
class EdcaTxopN;
class WifiMacHeader;
class WifiPhy;
class DcfManager;
class MacLow;
class MacRxMiddle;
class QadhocWifiMac : public WifiMac
{
public:
static TypeId GetTypeId (void);
QadhocWifiMac ();
~QadhocWifiMac ();
// all inherited from WifiMac base class.
virtual void SetSlot (Time slotTime);
virtual void SetSifs (Time sifs);
virtual void SetEifsNoDifs (Time eifsNoDifs);
virtual void SetAckTimeout (Time ackTimeout);
virtual void SetCtsTimeout (Time ctsTimeout);
virtual void SetPifs (Time pifs);
virtual Time GetSlot (void) const;
virtual Time GetSifs (void) const;
virtual Time GetEifsNoDifs (void) const;
virtual Time GetAckTimeout (void) const;
virtual Time GetCtsTimeout (void) const;
virtual Time GetPifs (void) const;
virtual void SetWifiPhy (Ptr<WifiPhy> phy);
virtual void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager);
virtual void Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from);
virtual void Enqueue (Ptr<const Packet> packet, Mac48Address to);
virtual bool SupportsSendFrom (void) const;
virtual void SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback);
virtual void SetLinkUpCallback (Callback<void> linkUp);
virtual void SetLinkDownCallback (Callback<void> linkDown);
virtual Mac48Address GetAddress (void) const;
virtual Ssid GetSsid (void) const;
virtual void SetAddress (Mac48Address address);
virtual void SetSsid (Ssid ssid);
virtual Mac48Address GetBssid (void) const;
private:
Callback<void, Ptr<Packet>, Mac48Address, Mac48Address> m_forwardUp;
virtual void DoDispose (void);
void Receive (Ptr<Packet> packet, WifiMacHeader const *hdr);
void ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to);
QadhocWifiMac &operator = (const QadhocWifiMac &);
QadhocWifiMac (const QadhocWifiMac &);
/**
* When an A-MSDU is received, is deaggregated by this method and all extracted packets are
* forwarded up.
*/
void DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr);
typedef std::map<AccessClass, Ptr<EdcaTxopN> > Queues;
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> > DeaggregatedMsdus;
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> >::const_iterator DeaggregatedMsdusCI;
Ptr<EdcaTxopN> GetVOQueue (void) const;
Ptr<EdcaTxopN> GetVIQueue (void) const;
Ptr<EdcaTxopN> GetBEQueue (void) const;
Ptr<EdcaTxopN> GetBKQueue (void) const;
void SetVOQueue (Ptr<EdcaTxopN> voQueue);
void SetVIQueue (Ptr<EdcaTxopN> viQueue);
void SetBEQueue (Ptr<EdcaTxopN> beQueue);
void SetBKQueue (Ptr<EdcaTxopN> bkQueue);
Queues m_queues;
Ptr<EdcaTxopN> m_voEdca;
Ptr<EdcaTxopN> m_viEdca;
Ptr<EdcaTxopN> m_beEdca;
Ptr<EdcaTxopN> m_bkEdca;
Ptr<MacLow> m_low;
Ptr<WifiPhy> m_phy;
Ptr<WifiRemoteStationManager> m_stationManager;
MacRxMiddle *m_rxMiddle;
MacTxMiddle *m_txMiddle;
DcfManager *m_dcfManager;
Ssid m_ssid;
Time m_eifsNoDifs;
};
} //namespace ns3
#endif /* QADHOC_WIFI_MAC_H */

View File

@@ -0,0 +1,789 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/assert.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/string.h"
#include "ns3/pointer.h"
#include "qos-tag.h"
#include "qap-wifi-mac.h"
#include "dca-txop.h"
#include "edca-txop-n.h"
#include "wifi-phy.h"
#include "dcf-manager.h"
#include "mac-rx-middle.h"
#include "mac-tx-middle.h"
#include "mgt-headers.h"
#include "mac-low.h"
#include "amsdu-subframe-header.h"
#include "msdu-aggregator.h"
NS_LOG_COMPONENT_DEFINE ("QapWifiMac");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (QapWifiMac);
TypeId
QapWifiMac::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::QapWifiMac")
.SetParent<WifiMac> ()
.AddConstructor<QapWifiMac> ()
.AddAttribute ("BeaconInterval", "Delay between two beacons",
TimeValue (Seconds (0.1)),
MakeTimeAccessor (&QapWifiMac::GetBeaconInterval,
&QapWifiMac::SetBeaconInterval),
MakeTimeChecker ())
.AddAttribute ("BeaconGeneration", "Whether or not beacons are generated.",
BooleanValue (true),
MakeBooleanAccessor (&QapWifiMac::SetBeaconGeneration,
&QapWifiMac::GetBeaconGeneration),
MakeBooleanChecker ())
.AddAttribute ("VO_EdcaTxopN",
"Queue that manages packets belonging to AC_VO access class",
PointerValue (),
MakePointerAccessor(&QapWifiMac::GetVOQueue,
&QapWifiMac::SetVOQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("VI_EdcaTxopN",
"Queue that manages packets belonging to AC_VI access class",
PointerValue (),
MakePointerAccessor(&QapWifiMac::GetVIQueue,
&QapWifiMac::SetVIQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("BE_EdcaTxopN",
"Queue that manages packets belonging to AC_BE access class",
PointerValue (),
MakePointerAccessor(&QapWifiMac::GetBEQueue,
&QapWifiMac::SetBEQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("BK_EdcaTxopN",
"Queue that manages packets belonging to AC_BK access class",
PointerValue (),
MakePointerAccessor(&QapWifiMac::GetBKQueue,
&QapWifiMac::SetBKQueue),
MakePointerChecker<EdcaTxopN> ())
;
return tid;
}
QapWifiMac::QapWifiMac ()
{
NS_LOG_FUNCTION (this);
m_rxMiddle = new MacRxMiddle ();
m_rxMiddle->SetForwardCallback (MakeCallback (&QapWifiMac::Receive, this));
m_txMiddle = new MacTxMiddle ();
m_low = CreateObject<MacLow> ();
m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));
m_dcfManager = new DcfManager ();
m_dcfManager->SetupLowListener (m_low);
m_beaconDca = CreateObject<DcaTxop> ();
m_beaconDca->SetAifsn(1);
m_beaconDca->SetMinCw(0);
m_beaconDca->SetMaxCw(0);
m_beaconDca->SetLow (m_low);
m_beaconDca->SetManager (m_dcfManager);
}
QapWifiMac::~QapWifiMac ()
{
NS_LOG_FUNCTION (this);
}
void
QapWifiMac::DoDispose ()
{
delete m_rxMiddle;
m_rxMiddle = 0;
delete m_txMiddle;
m_txMiddle = 0;
delete m_dcfManager;
m_dcfManager = 0;
m_low = 0;
m_phy = 0;
m_beaconDca = 0;
m_beaconEvent.Cancel ();
m_voEdca = 0;
m_viEdca = 0;
m_beEdca = 0;
m_bkEdca = 0;
m_stationManager = 0;
std::map<AccessClass, Ptr<EdcaTxopN> >::iterator it = m_queues.begin ();
for (;it != m_queues.end (); it++)
{
it->second = 0;
}
WifiMac::DoDispose ();
}
void
QapWifiMac::SetBeaconGeneration (bool enable)
{
NS_LOG_FUNCTION (this << enable);
if (enable)
{
m_beaconEvent = Simulator::ScheduleNow (&QapWifiMac::SendOneBeacon, this);
}
else
{
m_beaconEvent.Cancel ();
}
}
bool
QapWifiMac::GetBeaconGeneration (void) const
{
return m_beaconEvent.IsRunning ();
}
Time
QapWifiMac::GetBeaconInterval (void) const
{
return m_beaconInterval;
}
void
QapWifiMac::SetSlot (Time slotTime)
{
NS_LOG_FUNCTION (this << slotTime);
m_dcfManager->SetSlot (slotTime);
m_low->SetSlotTime (slotTime);
}
void
QapWifiMac::SetSifs (Time sifs)
{
NS_LOG_FUNCTION (this << sifs);
m_dcfManager->SetSifs (sifs);
m_low->SetSifs (sifs);
}
void
QapWifiMac::SetEifsNoDifs (Time eifsNoDifs)
{
NS_LOG_FUNCTION (this << eifsNoDifs);
m_dcfManager->SetEifsNoDifs (eifsNoDifs);
m_eifsNoDifs = eifsNoDifs;
}
void
QapWifiMac::SetAckTimeout (Time ackTimeout)
{
m_low->SetAckTimeout (ackTimeout);
}
void
QapWifiMac::SetCtsTimeout (Time ctsTimeout)
{
m_low->SetCtsTimeout (ctsTimeout);
}
void
QapWifiMac::SetPifs (Time pifs)
{
m_low->SetPifs (pifs);
}
Time
QapWifiMac::GetSlot (void) const
{
return m_low->GetSlotTime ();
}
Time
QapWifiMac::GetSifs (void) const
{
return m_low->GetSifs ();
}
Time
QapWifiMac::GetEifsNoDifs (void) const
{
return m_eifsNoDifs;
}
Time
QapWifiMac::GetAckTimeout (void) const
{
return m_low->GetAckTimeout ();
}
Time
QapWifiMac::GetCtsTimeout (void) const
{
return m_low->GetCtsTimeout ();
}
Time
QapWifiMac::GetPifs (void) const
{
return m_low->GetPifs ();
}
void
QapWifiMac::SetWifiPhy (Ptr<WifiPhy> phy)
{
NS_LOG_FUNCTION (this << phy);
m_phy = phy;
m_dcfManager->SetupPhyListener (phy);
m_low->SetPhy (phy);
}
void
QapWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
{
NS_LOG_FUNCTION (this << stationManager);
m_stationManager = stationManager;
m_voEdca->SetWifiRemoteStationManager (stationManager);
m_viEdca->SetWifiRemoteStationManager (stationManager);
m_beEdca->SetWifiRemoteStationManager (stationManager);
m_bkEdca->SetWifiRemoteStationManager (stationManager);
m_beaconDca->SetWifiRemoteStationManager (stationManager);
m_low->SetWifiRemoteStationManager (stationManager);
}
void
QapWifiMac::SetForwardUpCallback (Callback<void, Ptr<Packet>, Mac48Address, Mac48Address> upCallback)
{
NS_LOG_FUNCTION (this);
m_forwardUp = upCallback;
}
void
QapWifiMac::SetLinkUpCallback (Callback<void> linkUp)
{
NS_LOG_FUNCTION (this);
if (!linkUp.IsNull ())
{
linkUp ();
}
}
void
QapWifiMac::SetLinkDownCallback (Callback<void> linkDown)
{
NS_LOG_FUNCTION (this);
}
Mac48Address
QapWifiMac::GetAddress () const
{
return m_low->GetAddress ();
}
Ssid
QapWifiMac::GetSsid (void) const
{
return m_ssid;
}
void
QapWifiMac::SetAddress (Mac48Address address)
{
NS_LOG_FUNCTION (address);
m_low->SetAddress (address);
m_low->SetBssid (address);
}
void
QapWifiMac::SetSsid (Ssid ssid)
{
NS_LOG_FUNCTION (this << ssid);
m_ssid = ssid;
}
Mac48Address
QapWifiMac::GetBssid (void) const
{
return m_low->GetBssid ();
}
void
QapWifiMac::SetBeaconInterval (Time interval)
{
NS_LOG_FUNCTION (this << interval);
m_beaconInterval = interval;
}
void
QapWifiMac::StartBeaconing (void)
{
NS_LOG_FUNCTION (this);
SendOneBeacon ();
}
void
QapWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
{
NS_LOG_FUNCTION (this << packet << from);
m_forwardUp (packet, from, to);
}
void
QapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to)
{
/* For now Qos AP sends only Qos frame. In the future it should be able to
send frames also to Non-Qos Stas.
*/
NS_LOG_FUNCTION (this << packet << from << to);
WifiMacHeader hdr;
hdr.SetType (WIFI_MAC_QOSDATA);
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK);
hdr.SetQosNoEosp ();
hdr.SetQosNoAmsdu ();
/* Transmission of multiple frames in the same
Txop is not supported for now */
hdr.SetQosTxopLimit (0);
hdr.SetAddr1 (to);
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (from);
hdr.SetDsFrom ();
hdr.SetDsNotTo ();
uint8_t tid = QosUtilsGetTidForPacket (packet);
if (tid < 8)
{
hdr.SetQosTid (tid);
AccessClass ac = QosUtilsMapTidToAc (tid);
m_queues[ac]->Queue (packet, hdr);
}
else
{
//packet is considerated belonging to BestEffort AC
hdr.SetQosTid (0);
m_queues[AC_BE]->Queue (packet, hdr);
}
}
void
QapWifiMac::ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to,
WifiMacHeader const *oldHdr)
{
/* For now Qos AP sends only Qos frame. In the future it should be able to
send frames also to Non-Qos Stas.
*/
NS_LOG_FUNCTION (this << packet << from << to);
NS_ASSERT (oldHdr->IsQosData ());
WifiMacHeader hdr;
hdr.SetType (WIFI_MAC_QOSDATA);
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK);
hdr.SetQosNoEosp ();
hdr.SetQosNoAmsdu ();
/* Transmission of multiple frames in the same
Txop is not supported for now */
hdr.SetQosTxopLimit (0);
hdr.SetQosTid (oldHdr->GetQosTid ());
hdr.SetAddr1 (to);
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (from);
hdr.SetDsFrom ();
hdr.SetDsNotTo ();
AccessClass ac = QosUtilsMapTidToAc (oldHdr->GetQosTid ());
m_queues[ac]->Queue (packet, hdr);
}
void
QapWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from)
{
NS_LOG_FUNCTION (this << packet << from << to);
ForwardDown (packet, from, to);
}
void
QapWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to)
{
NS_LOG_FUNCTION (this << packet << to);
ForwardDown (packet, m_low->GetAddress (), to);
}
bool
QapWifiMac::SupportsSendFrom (void) const
{
return true;
}
SupportedRates
QapWifiMac::GetSupportedRates (void) const
{
// send the set of supported rates and make sure that we indicate
// the Basic Rate set in this set of supported rates.
SupportedRates rates;
for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
{
WifiMode mode = m_phy->GetMode (i);
rates.AddSupportedRate (mode.GetDataRate ());
}
// set the basic rates
for (uint32_t j = 0; j < m_stationManager->GetNBasicModes (); j++)
{
WifiMode mode = m_stationManager->GetBasicMode (j);
rates.SetBasicRate (mode.GetDataRate ());
}
return rates;
}
void
QapWifiMac::SendProbeResp (Mac48Address to)
{
NS_LOG_FUNCTION (this << to);
WifiMacHeader hdr;
hdr.SetProbeResp ();
hdr.SetAddr1 (to);
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (GetAddress ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
Ptr<Packet> packet = Create<Packet> ();
MgtProbeResponseHeader probe;
probe.SetSsid (GetSsid ());
probe.SetSupportedRates (GetSupportedRates ());
probe.SetBeaconIntervalUs (m_beaconInterval.GetMicroSeconds ());
packet->AddHeader (probe);
/* Which is correct queue for management frames ? */
m_queues[AC_VO]->Queue (packet, hdr);
}
void
QapWifiMac::SendAssocResp (Mac48Address to, bool success)
{
NS_LOG_FUNCTION (this << to << success);
WifiMacHeader hdr;
hdr.SetAssocResp ();
hdr.SetAddr1 (to);
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (GetAddress ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
Ptr<Packet> packet = Create<Packet> ();
MgtAssocResponseHeader assoc;
StatusCode code;
if (success)
{
code.SetSuccess ();
}
else
{
code.SetFailure ();
}
assoc.SetSupportedRates (GetSupportedRates ());
assoc.SetStatusCode (code);
packet->AddHeader (assoc);
/* Which is correct queue for management frames ? */
m_queues[AC_VO]->Queue (packet, hdr);
}
void
QapWifiMac::SendOneBeacon (void)
{
NS_LOG_FUNCTION (this);
WifiMacHeader hdr;
hdr.SetBeacon ();
hdr.SetAddr1 (Mac48Address::GetBroadcast ());
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (GetAddress ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
Ptr<Packet> packet = Create<Packet> ();
MgtBeaconHeader beacon;
beacon.SetSsid (GetSsid ());
beacon.SetSupportedRates (GetSupportedRates ());
beacon.SetBeaconIntervalUs (m_beaconInterval.GetMicroSeconds ());
packet->AddHeader (beacon);
m_beaconDca->Queue (packet, hdr);
m_beaconEvent = Simulator::Schedule (m_beaconInterval, &QapWifiMac::SendOneBeacon, this);
}
void
QapWifiMac::TxOk (WifiMacHeader const &hdr)
{
NS_LOG_FUNCTION (this);
WifiRemoteStation *station = m_stationManager->Lookup (hdr.GetAddr1 ());
if (hdr.IsAssocResp () &&
station->IsWaitAssocTxOk ())
{
NS_LOG_DEBUG ("associated with sta="<<hdr.GetAddr1 ());
station->RecordGotAssocTxOk ();
}
}
void
QapWifiMac::TxFailed (WifiMacHeader const &hdr)
{
NS_LOG_FUNCTION (this);
WifiRemoteStation *station = m_stationManager->Lookup (hdr.GetAddr1 ());
if (hdr.IsAssocResp () &&
station->IsWaitAssocTxOk ())
{
NS_LOG_DEBUG ("assoc failed with sta="<<hdr.GetAddr1 ());
station->RecordGotAssocTxFailed ();
}
}
void
QapWifiMac::Receive (Ptr<Packet> packet, WifiMacHeader const *hdr)
{
NS_LOG_FUNCTION (this << packet << hdr);
Mac48Address from = hdr->GetAddr2 ();
WifiRemoteStation *fromStation = m_stationManager->Lookup (from);
if (hdr->IsData ())
{
Mac48Address bssid = hdr->GetAddr1 ();
if (!hdr->IsFromDs () &&
hdr->IsToDs () &&
bssid == GetAddress () &&
fromStation->IsAssociated ())
{
Mac48Address to = hdr->GetAddr3 ();
WifiRemoteStation *toStation = m_stationManager->Lookup (to);
if (to == GetAddress ())
{
NS_LOG_DEBUG ("frame for me (Qap) from="<<from);
if (hdr->IsQosData ())
{
if (hdr->IsQosAmsdu ())
{
NS_LOG_DEBUG ("Received A-MSDU from="<<from<<", size="<<packet->GetSize ());
DeaggregateAmsduAndForward (packet, hdr);
packet = 0;
}
else
{
ForwardUp (packet, from, bssid);
}
}
else
{
ForwardUp (packet, from, bssid);
}
}
else if (to.IsGroup () ||
toStation->IsAssociated ())
{
NS_LOG_DEBUG ("forwarding frame from="<<from<<", to="<<to);
Ptr<Packet> copy = packet->Copy ();
ForwardDown (packet, from, to, hdr);
ForwardUp (copy, from, to);
}
else
{
ForwardUp (packet, from, to);
}
}
else if (hdr->IsFromDs () &&
hdr->IsToDs ())
{
// this is an AP-to-AP frame
// we ignore for now.
}
else
{
// we can ignore these frames since
// they are not targeted at the AP
}
}
else if (hdr->IsMgt ())
{
if (hdr->IsProbeReq ())
{
NS_ASSERT (hdr->GetAddr1 ().IsBroadcast ());
SendProbeResp (hdr->GetAddr2 ());
}
else if (hdr->GetAddr1 () == GetAddress ())
{
if (hdr->IsAssocReq ())
{
// first, verify that the the station's supported
// rate set is compatible with our Basic Rate set
MgtAssocRequestHeader assocReq;
packet->RemoveHeader (assocReq);
SupportedRates rates = assocReq.GetSupportedRates ();
bool problem = false;
for (uint32_t i = 0; i < m_stationManager->GetNBasicModes (); i++)
{
WifiMode mode = m_stationManager->GetBasicMode (i);
if (!rates.IsSupportedRate (mode.GetDataRate ()))
{
problem = true;
break;
}
}
if (problem)
{
// one of the Basic Rate set mode is not
// supported by the station. So, we return an assoc
// response with an error status.
SendAssocResp (hdr->GetAddr2 (), false);
}
else
{
// station supports all rates in Basic Rate Set.
// record all its supported modes in its associated WifiRemoteStation
for (uint32_t j = 0; j < m_phy->GetNModes (); j++)
{
WifiMode mode = m_phy->GetMode (j);
if (rates.IsSupportedRate (mode.GetDataRate ()))
{
fromStation->AddSupportedMode (mode);
}
}
fromStation->RecordWaitAssocTxOk ();
// send assoc response with success status.
SendAssocResp (hdr->GetAddr2 (), true);
}
}
else if (hdr->IsDisassociation ())
{
fromStation->RecordDisassociated ();
}
else if (hdr->IsReassocReq ())
{
/* we don't support reassoc frames for now */
}
else if (hdr->IsAuthentication () ||
hdr->IsDeauthentication ())
{
/*
*/
}
else
{
/* unknown mgt frame
*/
}
}
}
}
void
QapWifiMac::DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr)
{
DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket);
for (DeaggregatedMsdusCI i = packets.begin (); i != packets.end (); ++i)
{
if ((*i).second.GetDestinationAddr () == GetAddress ())
{
ForwardUp ((*i).first, (*i).second.GetSourceAddr (),
(*i).second.GetDestinationAddr ());
}
else
{
Mac48Address from = (*i).second.GetSourceAddr ();
Mac48Address to = (*i).second.GetDestinationAddr ();
NS_LOG_DEBUG ("forwarding QoS frame from="<<from<<", to="<<to);
ForwardDown ((*i).first, from, to, hdr);
}
}
}
Ptr<EdcaTxopN>
QapWifiMac::GetVOQueue (void) const
{
return m_voEdca;
}
Ptr<EdcaTxopN>
QapWifiMac::GetVIQueue (void) const
{
return m_viEdca;
}
Ptr<EdcaTxopN>
QapWifiMac::GetBEQueue (void) const
{
return m_beEdca;
}
Ptr<EdcaTxopN>
QapWifiMac::GetBKQueue (void) const
{
return m_bkEdca;
}
void
QapWifiMac::SetVOQueue (Ptr<EdcaTxopN> voQueue)
{
m_voEdca = voQueue;
m_queues.insert (std::make_pair(AC_VO, m_voEdca));
m_queues[AC_VO]->SetLow (m_low);
m_queues[AC_VO]->SetManager (m_dcfManager);
m_queues[AC_VO]->SetTypeOfStation (AP);
m_queues[AC_VO]->SetTxMiddle (m_txMiddle);
m_queues[AC_VO]->SetTxOkCallback (MakeCallback (&QapWifiMac::TxOk, this));
m_queues[AC_VO]->SetTxFailedCallback (MakeCallback (&QapWifiMac::TxFailed, this));
}
void
QapWifiMac::SetVIQueue (Ptr<EdcaTxopN> viQueue)
{
m_viEdca = viQueue;
m_queues.insert (std::make_pair(AC_VI, m_viEdca));
m_queues[AC_VI]->SetLow (m_low);
m_queues[AC_VI]->SetManager (m_dcfManager);
m_queues[AC_VI]->SetTypeOfStation (AP);
m_queues[AC_VI]->SetTxMiddle (m_txMiddle);
m_queues[AC_VI]->SetTxOkCallback (MakeCallback (&QapWifiMac::TxOk, this));
m_queues[AC_VI]->SetTxFailedCallback (MakeCallback (&QapWifiMac::TxFailed, this));
}
void
QapWifiMac::SetBEQueue (Ptr<EdcaTxopN> beQueue)
{
m_beEdca = beQueue;
m_queues.insert (std::make_pair(AC_BE, m_beEdca));
m_queues[AC_BE]->SetLow (m_low);
m_queues[AC_BE]->SetManager (m_dcfManager);
m_queues[AC_BE]->SetTypeOfStation (AP);
m_queues[AC_BE]->SetTxMiddle (m_txMiddle);
m_queues[AC_BE]->SetTxOkCallback (MakeCallback (&QapWifiMac::TxOk, this));
m_queues[AC_BE]->SetTxFailedCallback (MakeCallback (&QapWifiMac::TxFailed, this));
}
void
QapWifiMac::SetBKQueue (Ptr<EdcaTxopN> bkQueue)
{
m_bkEdca = bkQueue;
m_queues.insert (std::make_pair(AC_BK, m_bkEdca));
m_queues[AC_BK]->SetLow (m_low);
m_queues[AC_BK]->SetManager (m_dcfManager);
m_queues[AC_BK]->SetTypeOfStation (AP);
m_queues[AC_BK]->SetTxMiddle (m_txMiddle);
m_queues[AC_BK]->SetTxOkCallback (MakeCallback (&QapWifiMac::TxOk, this));
m_queues[AC_BK]->SetTxFailedCallback (MakeCallback (&QapWifiMac::TxFailed, this));
}
} //namespace ns3

View File

@@ -0,0 +1,147 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef QAP_WIFI_MAC_H
#define QAP_WIFI_MAC_H
#include "ns3/mac48-address.h"
#include "ns3/callback.h"
#include "ns3/packet.h"
#include "ns3/nstime.h"
#include "ns3/event-id.h"
#include "supported-rates.h"
#include "wifi-remote-station-manager.h"
#include "wifi-mac.h"
#include "qos-utils.h"
#include <map>
namespace ns3 {
class DcaTxop;
class EdcaTxopN;
class WifiMacHeader;
class WifiPhy;
class MacLow;
class MacRxMiddle;
class MacTxMiddle;
class DcfManager;
class AmsduSubframeHeader;
class MsduAggregator;
class QapWifiMac : public WifiMac
{
public:
static TypeId GetTypeId (void);
QapWifiMac ();
virtual ~QapWifiMac ();
// inherited from WifiMac.
virtual void SetSlot (Time slotTime);
virtual void SetSifs (Time sifs);
virtual void SetEifsNoDifs (Time eifsNoDifs);
virtual void SetAckTimeout (Time ackTimeout);
virtual void SetCtsTimeout (Time ctsTimeout);
virtual void SetPifs (Time pifs);
virtual Time GetSlot (void) const;
virtual Time GetSifs (void) const;
virtual Time GetEifsNoDifs (void) const;
virtual Time GetAckTimeout (void) const;
virtual Time GetCtsTimeout (void) const;
virtual Time GetPifs (void) const;
virtual void SetWifiPhy (Ptr<WifiPhy> phy);
virtual void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager);
virtual void Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from);
virtual void Enqueue (Ptr<const Packet> packet, Mac48Address to);
virtual bool SupportsSendFrom (void) const;
virtual void SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback);
virtual void SetLinkUpCallback (Callback<void> linkUp);
virtual void SetLinkDownCallback (Callback<void> linkDown);
virtual Mac48Address GetAddress (void) const;
virtual Ssid GetSsid (void) const;
virtual void SetAddress (Mac48Address address);
virtual void SetSsid (Ssid ssid);
virtual Mac48Address GetBssid (void) const;
void SetBeaconInterval (Time interval);
Time GetBeaconInterval (void) const;
void StartBeaconing (void);
private:
virtual void DoDispose (void);
void Receive (Ptr<Packet> packet, WifiMacHeader const *hdr);
void ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to);
void ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to);
/* Next function is invoked only when ap relies a frame. */
void ForwardDown (Ptr<const Packet> packet, Mac48Address from, Mac48Address to,
WifiMacHeader const *oldHdr);
void TxOk (WifiMacHeader const &hdr);
void TxFailed (WifiMacHeader const &hdr);
void SendProbeResp (Mac48Address to);
void SendAssocResp (Mac48Address to, bool success);
void SendOneBeacon (void);
SupportedRates GetSupportedRates (void) const;
void SetBeaconGeneration (bool enable);
bool GetBeaconGeneration (void) const;
void DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr);
QapWifiMac &operator = (const QapWifiMac &);
QapWifiMac (const QapWifiMac &);
typedef std::map<AccessClass, Ptr<EdcaTxopN> > Queues;
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> > DeaggregatedMsdus;
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> >::const_iterator DeaggregatedMsdusCI;
Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> m_forwardUp;
Ptr<EdcaTxopN> GetVOQueue (void) const;
Ptr<EdcaTxopN> GetVIQueue (void) const;
Ptr<EdcaTxopN> GetBEQueue (void) const;
Ptr<EdcaTxopN> GetBKQueue (void) const;
void SetVOQueue (Ptr<EdcaTxopN> voQueue);
void SetVIQueue (Ptr<EdcaTxopN> viQueue);
void SetBEQueue (Ptr<EdcaTxopN> beQueue);
void SetBKQueue (Ptr<EdcaTxopN> bkQueue);
/*Next map is used only for an esay access to a specific queue*/
Queues m_queues;
Ptr<EdcaTxopN> m_voEdca;
Ptr<EdcaTxopN> m_viEdca;
Ptr<EdcaTxopN> m_beEdca;
Ptr<EdcaTxopN> m_bkEdca;
Ptr<DcaTxop> m_beaconDca;
Ptr<MacLow> m_low;
Ptr<WifiPhy> m_phy;
Ptr<WifiRemoteStationManager> m_stationManager;
MacRxMiddle *m_rxMiddle;
MacTxMiddle *m_txMiddle;
DcfManager *m_dcfManager;
Ssid m_ssid;
EventId m_beaconEvent;
Time m_beaconInterval;
Time m_eifsNoDifs;
};
} //namespace ns3
#endif /* QAP_WIFI_MAC_H */

View File

@@ -0,0 +1,85 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "qos-tag.h"
#include "ns3/tag.h"
#include "ns3/uinteger.h"
namespace ns3 {
TypeId
QosTag::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::QosTag")
.SetParent<Tag> ()
.AddConstructor<QosTag> ()
.AddAttribute ("tid", "The tid that indicates AC which packet belongs",
UintegerValue (0),
MakeUintegerAccessor (&QosTag::Get),
MakeUintegerChecker<uint8_t> ())
;
return tid;
}
TypeId
QosTag::GetInstanceTypeId (void) const
{
return GetTypeId ();
}
QosTag::QosTag()
{}
uint32_t
QosTag::GetSerializedSize (void) const
{
return 1;
}
void
QosTag::Serialize (TagBuffer i) const
{
i.WriteU8 (m_tid);
}
void
QosTag::Deserialize (TagBuffer i)
{
m_tid = i.ReadU8 ();
}
void
QosTag::Set (uint8_t tid)
{
m_tid = tid;
}
uint8_t
QosTag::Get () const
{
return m_tid;
}
void
QosTag::Print (std::ostream &os) const
{
os << "Tid=" << m_tid;
}
} //namespace ns3

View File

@@ -0,0 +1,49 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef QOS_TAG_H
#define QOS_TAG_H
#include "ns3/packet.h"
namespace ns3 {
class Tag;
class QosTag : public Tag
{
public:
static TypeId GetTypeId (void);
virtual TypeId GetInstanceTypeId (void) const;
QosTag ();
virtual void Serialize (TagBuffer i) const;
virtual void Deserialize (TagBuffer i);
virtual uint32_t GetSerializedSize () const;
virtual void Print (std::ostream &os) const;
uint8_t Get (void) const;
void Set (uint8_t tid);
private:
uint8_t m_tid;
};
} //namespace ns3
#endif /* QOS_TAG_H */

View File

@@ -0,0 +1,72 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "qos-utils.h"
#include "qos-tag.h"
namespace ns3 {
AccessClass
QosUtilsMapTidToAc (uint8_t tid)
{
switch (tid) {
case 0 :
return AC_BE;
break;
case 1 :
return AC_BK;
break;
case 2 :
return AC_BK;
break;
case 3 :
return AC_BE;
break;
case 4 :
return AC_VI;
break;
case 5 :
return AC_VI;
break;
case 6 :
return AC_VO;
break;
case 7 :
return AC_VO;
break;
}
return AC_UNDEF;
}
uint8_t
QosUtilsGetTidForPacket (Ptr<const Packet> packet)
{
QosTag qos;
uint8_t tid = 8;
if (packet->PeekPacketTag (qos))
{
if (qos.Get () < 8)
{
tid = qos.Get ();
}
}
return tid;
}
} //namespace ns3

View File

@@ -0,0 +1,49 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef QOS_UTILS_H
#define QOS_UTILS_H
#include "ns3/uinteger.h"
#include "ns3/ptr.h"
#include "ns3/packet.h"
namespace ns3 {
enum AccessClass {
AC_VO = 0,
AC_VI = 1,
AC_BE = 2,
AC_BK = 3,
AC_UNDEF
};
/* Maps TID (Traffic ID) to Access classes.
* For more details see table 9-1 of IEEE802.11 standard.
*/
AccessClass QosUtilsMapTidToAc (uint8_t tid);
/* If a qos tag is attached to the packet, returns a value < 8.
A value >= 8 is returned otherwise.
*/
uint8_t QosUtilsGetTidForPacket (Ptr<const Packet> packet);
} //namespace ns3
#endif /* QOS_UTILS_H */

View File

@@ -0,0 +1,768 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/string.h"
#include "ns3/pointer.h"
#include "qos-tag.h"
#include "edca-txop-n.h"
#include "qsta-wifi-mac.h"
#include "mac-low.h"
#include "dcf-manager.h"
#include "mac-rx-middle.h"
#include "mac-tx-middle.h"
#include "wifi-mac-header.h"
#include "msdu-aggregator.h"
#include "amsdu-subframe-header.h"
#include "mgt-headers.h"
NS_LOG_COMPONENT_DEFINE ("QstaWifiMac");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (QstaWifiMac);
TypeId
QstaWifiMac::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::QstaWifiMac")
.SetParent<WifiMac> ()
.AddConstructor<QstaWifiMac> ()
.AddAttribute ("ProbeRequestTimeout", "The interval between two consecutive probe request attempts.",
TimeValue (Seconds (0.05)),
MakeTimeAccessor (&QstaWifiMac::m_probeRequestTimeout),
MakeTimeChecker ())
.AddAttribute ("AssocRequestTimeout", "The interval between two consecutive assoc request attempts.",
TimeValue (Seconds (0.5)),
MakeTimeAccessor (&QstaWifiMac::m_assocRequestTimeout),
MakeTimeChecker ())
.AddAttribute ("MaxMissedBeacons",
"Number of beacons which much be consecutively missed before "
"we attempt to restart association.",
UintegerValue (10),
MakeUintegerAccessor (&QstaWifiMac::m_maxMissedBeacons),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("ActiveProbing", "If true, we send probe requests. If false, we don't.",
BooleanValue (false),
MakeBooleanAccessor (&QstaWifiMac::SetActiveProbing),
MakeBooleanChecker ())
.AddAttribute ("VO_EdcaTxopN",
"Queue that manages packets belonging to AC_VO access class",
PointerValue (),
MakePointerAccessor(&QstaWifiMac::GetVOQueue,
&QstaWifiMac::SetVOQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("VI_EdcaTxopN",
"Queue that manages packets belonging to AC_VI access class",
PointerValue (),
MakePointerAccessor(&QstaWifiMac::GetVIQueue,
&QstaWifiMac::SetVIQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("BE_EdcaTxopN",
"Queue that manages packets belonging to AC_BE access class",
PointerValue (),
MakePointerAccessor(&QstaWifiMac::GetBEQueue,
&QstaWifiMac::SetBEQueue),
MakePointerChecker<EdcaTxopN> ())
.AddAttribute ("BK_EdcaTxopN",
"Queue that manages packets belonging to AC_BK access class",
PointerValue (),
MakePointerAccessor(&QstaWifiMac::GetBKQueue,
&QstaWifiMac::SetBKQueue),
MakePointerChecker<EdcaTxopN> ())
;
return tid;
}
QstaWifiMac::QstaWifiMac ()
: m_state (BEACON_MISSED),
m_probeRequestEvent (),
m_assocRequestEvent (),
m_beaconWatchdogEnd (Seconds (0.0))
{
NS_LOG_FUNCTION (this);
m_rxMiddle = new MacRxMiddle ();
m_rxMiddle->SetForwardCallback (MakeCallback (&QstaWifiMac::Receive, this));
/*TxMiddle can be shared between all queues */
m_txMiddle= new MacTxMiddle ();
m_low = CreateObject<MacLow> ();
m_low->SetRxCallback (MakeCallback (&MacRxMiddle::Receive, m_rxMiddle));
m_dcfManager = new DcfManager ();
m_dcfManager->SetupLowListener (m_low);
}
QstaWifiMac::~QstaWifiMac ()
{
NS_LOG_FUNCTION (this);
}
void
QstaWifiMac::DoDispose ()
{
NS_LOG_FUNCTION (this);
delete m_rxMiddle;
delete m_txMiddle;
delete m_dcfManager;
m_rxMiddle = 0;
m_txMiddle = 0;
m_low = 0;
m_phy = 0;
m_dcfManager = 0;
m_voEdca = 0;
m_viEdca = 0;
m_beEdca = 0;
m_bkEdca = 0;
m_stationManager = 0;
std::map<AccessClass, Ptr<EdcaTxopN> >::iterator it = m_queues.begin ();
for (;it != m_queues.end (); it++)
{
it->second = 0;
}
WifiMac::DoDispose ();
}
void
QstaWifiMac::SetSlot (Time slotTime)
{
NS_LOG_FUNCTION (this << slotTime);
m_dcfManager->SetSlot (slotTime);
m_low->SetSlotTime (slotTime);
}
void
QstaWifiMac::SetSifs (Time sifs)
{
NS_LOG_FUNCTION (this << sifs);
m_dcfManager->SetSifs (sifs);
m_low->SetSifs (sifs);
}
void
QstaWifiMac::SetEifsNoDifs (Time eifsNoDifs)
{
NS_LOG_FUNCTION (this << eifsNoDifs);
m_dcfManager->SetEifsNoDifs (eifsNoDifs);
m_eifsNoDifs = eifsNoDifs;
}
void
QstaWifiMac::SetAckTimeout (Time ackTimeout)
{
m_low->SetAckTimeout (ackTimeout);
}
void
QstaWifiMac::SetCtsTimeout (Time ctsTimeout)
{
m_low->SetCtsTimeout (ctsTimeout);
}
void
QstaWifiMac::SetPifs (Time pifs)
{
m_low->SetPifs (pifs);
}
Time
QstaWifiMac::GetSlot (void) const
{
return m_low->GetSlotTime ();
}
Time
QstaWifiMac::GetSifs (void) const
{
return m_low->GetSifs ();
}
Time
QstaWifiMac::GetEifsNoDifs (void) const
{
return m_eifsNoDifs;
}
Time
QstaWifiMac::GetAckTimeout (void) const
{
return m_low->GetAckTimeout ();
}
Time
QstaWifiMac::GetCtsTimeout (void) const
{
return m_low->GetCtsTimeout ();
}
Time
QstaWifiMac::GetPifs (void) const
{
return m_low->GetPifs ();
}
void
QstaWifiMac::SetWifiPhy (Ptr<WifiPhy> phy)
{
m_phy = phy;
m_dcfManager->SetupPhyListener (phy);
m_low->SetPhy (phy);
}
void
QstaWifiMac::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager)
{
m_stationManager = stationManager;
m_queues[AC_VO]->SetWifiRemoteStationManager (stationManager);
m_queues[AC_VI]->SetWifiRemoteStationManager (stationManager);
m_queues[AC_BE]->SetWifiRemoteStationManager (stationManager);
m_queues[AC_BK]->SetWifiRemoteStationManager (stationManager);
m_low->SetWifiRemoteStationManager (stationManager);
}
void
QstaWifiMac::SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback)
{
m_forwardUp = upCallback;
}
void
QstaWifiMac::SetLinkUpCallback (Callback<void> linkUp)
{
m_linkUp = linkUp;
}
void
QstaWifiMac::SetLinkDownCallback (Callback<void> linkDown)
{
m_linkDown = linkDown;
}
Mac48Address
QstaWifiMac::GetAddress (void) const
{
return m_low->GetAddress ();
}
Ssid
QstaWifiMac::GetSsid (void) const
{
return m_ssid;
}
Mac48Address
QstaWifiMac::GetBssid () const
{
return m_low->GetBssid ();
}
void
QstaWifiMac::SetAddress (Mac48Address address)
{
NS_LOG_FUNCTION (this << address);
m_low->SetAddress (address);
}
void
QstaWifiMac::SetSsid (Ssid ssid)
{
NS_LOG_FUNCTION (this << ssid);
m_ssid = ssid;
}
void
QstaWifiMac::SetMaxMissedBeacons (uint32_t missed)
{
NS_LOG_FUNCTION (this << missed);
m_maxMissedBeacons = missed;
}
void
QstaWifiMac::SetProbeRequestTimeout (Time timeout)
{
NS_LOG_FUNCTION (this << timeout);
m_probeRequestTimeout = timeout;
}
void
QstaWifiMac::SetAssocRequestTimeout (Time timeout)
{
NS_LOG_FUNCTION (this << timeout);
m_assocRequestTimeout = timeout;
}
void
QstaWifiMac::StartActiveAssociation (void)
{
NS_LOG_FUNCTION (this);
TryToEnsureAssociated ();
}
Mac48Address
QstaWifiMac::GetBroadcastBssid (void)
{
return Mac48Address::GetBroadcast ();
}
void
QstaWifiMac::SetBssid (Mac48Address bssid)
{
NS_LOG_FUNCTION (this << bssid);
m_low->SetBssid (bssid);
}
void
QstaWifiMac::SetActiveProbing (bool enable)
{
NS_LOG_FUNCTION (this << enable);
if (enable)
{
TryToEnsureAssociated ();
}
else
{
m_probeRequestEvent.Cancel ();
}
}
void
QstaWifiMac::ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to)
{
NS_LOG_FUNCTION (this << packet << from << to);
m_forwardUp (packet, from, to);
}
void
QstaWifiMac::SendProbeRequest (void)
{
NS_LOG_FUNCTION (this);
WifiMacHeader hdr;
hdr.SetProbeReq ();
hdr.SetAddr1 (GetBroadcastBssid ());
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (GetBroadcastBssid ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
Ptr<Packet> packet = Create<Packet> ();
MgtProbeRequestHeader probe;
probe.SetSsid (GetSsid ());
probe.SetSupportedRates (GetSupportedRates ());
packet->AddHeader (probe);
/* Which is correct queue for management frames ? */
m_queues[AC_VO]->Queue (packet, hdr);
m_probeRequestEvent = Simulator::Schedule (m_probeRequestTimeout,
&QstaWifiMac::ProbeRequestTimeout, this);
}
void
QstaWifiMac::SendAssociationRequest (void)
{
NS_LOG_FUNCTION (this << GetBssid ());
WifiMacHeader hdr;
hdr.SetAssocReq ();
hdr.SetAddr1 (GetBssid ());
hdr.SetAddr2 (GetAddress ());
hdr.SetAddr3 (GetBssid ());
hdr.SetDsNotFrom ();
hdr.SetDsNotTo ();
Ptr<Packet> packet = Create<Packet> ();
MgtAssocRequestHeader assoc;
assoc.SetSsid (GetSsid ());
assoc.SetSupportedRates (GetSupportedRates ());
packet->AddHeader (assoc);
/* Which is correct queue for management frames ? */
m_queues[AC_VO]->Queue (packet, hdr);
m_assocRequestEvent = Simulator::Schedule (m_assocRequestTimeout,
&QstaWifiMac::AssocRequestTimeout, this);
}
void
QstaWifiMac::TryToEnsureAssociated (void)
{
NS_LOG_FUNCTION (this);
switch (m_state) {
case ASSOCIATED:
return;
break;
case WAIT_PROBE_RESP:
/* we have sent a probe request earlier so we
do not need to re-send a probe request immediately.
We just need to wait until probe-request-timeout
or until we get a probe response
*/
break;
case BEACON_MISSED:
/* we were associated but we missed a bunch of beacons
* so we should assume we are not associated anymore.
* We try to initiate a probe request now.
*/
m_linkDown ();
m_state = WAIT_PROBE_RESP;
SendProbeRequest ();
break;
case WAIT_ASSOC_RESP:
/* we have sent an assoc request so we do not need to
re-send an assoc request right now. We just need to
wait until either assoc-request-timeout or until
we get an assoc response.
*/
break;
case REFUSED:
/* we have sent an assoc request and received a negative
assoc resp. We wait until someone restarts an
association with a given ssid.
*/
break;
}
}
void
QstaWifiMac::AssocRequestTimeout (void)
{
NS_LOG_FUNCTION (this);
m_state = WAIT_ASSOC_RESP;
SendAssociationRequest ();
}
void
QstaWifiMac::ProbeRequestTimeout (void)
{
NS_LOG_FUNCTION (this);
m_state = WAIT_PROBE_RESP;
SendProbeRequest ();
}
void
QstaWifiMac::MissedBeacons (void)
{
NS_LOG_FUNCTION (this);
if (m_beaconWatchdogEnd > Simulator::Now ())
{
m_beaconWatchdog = Simulator::Schedule (m_beaconWatchdogEnd - Simulator::Now (),
&QstaWifiMac::MissedBeacons, this);
return;
}
NS_LOG_DEBUG ("beacon missed");
m_state = BEACON_MISSED;
TryToEnsureAssociated ();
}
void
QstaWifiMac::RestartBeaconWatchdog (Time delay)
{
NS_LOG_FUNCTION (this << delay);
m_beaconWatchdogEnd = std::max (Simulator::Now () + delay, m_beaconWatchdogEnd);
if (Simulator::GetDelayLeft (m_beaconWatchdog) < delay &&
m_beaconWatchdog.IsExpired ())
{
NS_LOG_DEBUG ("really restart watchdog.");
m_beaconWatchdog = Simulator::Schedule (delay, &QstaWifiMac::MissedBeacons, this);
}
}
bool
QstaWifiMac::IsAssociated ()
{
return (m_state == ASSOCIATED)?true:false;
}
void
QstaWifiMac::Enqueue (Ptr<const Packet> packet, Mac48Address to)
{
NS_LOG_FUNCTION (this << packet << to);
if (!IsAssociated ())
{
TryToEnsureAssociated ();
return;
}
WifiMacHeader hdr;
hdr.SetType (WIFI_MAC_QOSDATA);
hdr.SetQosAckPolicy (WifiMacHeader::NORMAL_ACK);
hdr.SetQosNoAmsdu ();
hdr.SetQosNoEosp ();
/* Transmission of multiple frames in the same
Txop is not supported for now */
hdr.SetQosTxopLimit (0);
hdr.SetAddr1 (GetBssid ());
hdr.SetAddr2 (m_low->GetAddress ());
hdr.SetAddr3 (to);
hdr.SetDsNotFrom ();
hdr.SetDsTo ();
uint8_t tid = QosUtilsGetTidForPacket (packet);
if (tid < 8)
{
hdr.SetQosTid (tid);
AccessClass ac = QosUtilsMapTidToAc (tid);
m_queues[ac]->Queue (packet, hdr);
}
else
{
//packet is considerated belonging to BestEffort Access Class (AC_BE)
hdr.SetQosTid (0);
m_queues[AC_BE]->Queue (packet, hdr);
}
}
bool
QstaWifiMac::SupportsSendFrom (void) const
{
return true;
}
void
QstaWifiMac::Receive (Ptr<Packet> packet, const WifiMacHeader *hdr)
{
NS_LOG_FUNCTION (this);
NS_ASSERT (!hdr->IsCtl ());
if (hdr->GetAddr1 () != GetAddress () &&
!hdr->GetAddr1 ().IsBroadcast ())
{
NS_LOG_LOGIC ("packet is not for us");
}
else if (hdr->IsData ())
{
if (!IsAssociated ())
{
NS_LOG_LOGIC ("Received data frame while not associated: ignore");
return;
}
if (!(hdr->IsFromDs () && !hdr->IsToDs ()))
{
NS_LOG_LOGIC ("Received data frame not from the DS: ignore");
return;
}
if (hdr->GetAddr2 () != GetBssid ())
{
NS_LOG_LOGIC ("Received data frame not from the BSS we are associated with: ignore");
return;
}
if (hdr->GetAddr3 () != GetAddress ())
{
if (hdr->IsQosData ())
{
if (hdr->IsQosAmsdu ())
{
NS_ASSERT (hdr->GetAddr3 () == GetBssid ());
DeaggregateAmsduAndForward (packet, hdr);
packet = 0;
}
else
{
ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ());
}
}
else
{
ForwardUp (packet, hdr->GetAddr3 (), hdr->GetAddr1 ());
}
}
}
else if (hdr->IsBeacon ())
{
MgtBeaconHeader beacon;
packet->RemoveHeader (beacon);
bool goodBeacon = false;
if (GetSsid ().IsBroadcast () ||
beacon.GetSsid ().IsEqual (GetSsid ()))
{
goodBeacon = true;
}
if (IsAssociated () && hdr->GetAddr3 () != GetBssid ())
{
goodBeacon = false;
}
if (goodBeacon)
{
Time delay = MicroSeconds (beacon.GetBeaconIntervalUs () * m_maxMissedBeacons);
RestartBeaconWatchdog (delay);
SetBssid (hdr->GetAddr3 ());
}
if (goodBeacon && m_state == BEACON_MISSED)
{
m_state = WAIT_ASSOC_RESP;
SendAssociationRequest ();
}
}
else if (hdr->IsProbeResp ())
{
if (m_state == WAIT_PROBE_RESP)
{
MgtProbeResponseHeader probeResp;
packet->RemoveHeader (probeResp);
if (!probeResp.GetSsid ().IsEqual (GetSsid ()))
{
//not a probe resp for our ssid.
return;
}
SetBssid (hdr->GetAddr3 ());
Time delay = MicroSeconds (probeResp.GetBeaconIntervalUs () * m_maxMissedBeacons);
RestartBeaconWatchdog (delay);
if (m_probeRequestEvent.IsRunning ())
{
m_probeRequestEvent.Cancel ();
}
m_state = WAIT_ASSOC_RESP;
SendAssociationRequest ();
}
}
else if (hdr->IsAssocResp ())
{
if (m_state == WAIT_ASSOC_RESP)
{
MgtAssocResponseHeader assocResp;
packet->RemoveHeader (assocResp);
if (m_assocRequestEvent.IsRunning ())
{
m_assocRequestEvent.Cancel ();
}
if (assocResp.GetStatusCode ().IsSuccess ())
{
m_state = ASSOCIATED;
NS_LOG_DEBUG ("assoc completed");
SupportedRates rates = assocResp.GetSupportedRates ();
WifiRemoteStation *ap = m_stationManager->Lookup (hdr->GetAddr2 ());
for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
{
WifiMode mode = m_phy->GetMode (i);
if (rates.IsSupportedRate (mode.GetDataRate ()))
{
ap->AddSupportedMode (mode);
if (rates.IsBasicRate (mode.GetDataRate ()))
{
m_stationManager->AddBasicMode (mode);
}
}
}
if (!m_linkUp.IsNull ())
{
m_linkUp ();
}
}
else
{
NS_LOG_DEBUG ("assoc refused");
m_state = REFUSED;
}
}
}
}
SupportedRates
QstaWifiMac::GetSupportedRates (void) const
{
SupportedRates rates;
for (uint32_t i = 0; i < m_phy->GetNModes (); i++)
{
WifiMode mode = m_phy->GetMode (i);
rates.AddSupportedRate (mode.GetDataRate ());
}
return rates;
}
void
QstaWifiMac::DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr)
{
DeaggregatedMsdus packets = MsduAggregator::Deaggregate (aggregatedPacket);
for (DeaggregatedMsdusCI i = packets.begin (); i != packets.end (); ++i)
{
ForwardUp ((*i).first, (*i).second.GetSourceAddr (),
(*i).second.GetDestinationAddr ());
}
}
Ptr<EdcaTxopN>
QstaWifiMac::GetVOQueue (void) const
{
return m_voEdca;
}
Ptr<EdcaTxopN>
QstaWifiMac::GetVIQueue (void) const
{
return m_viEdca;
}
Ptr<EdcaTxopN>
QstaWifiMac::GetBEQueue (void) const
{
return m_beEdca;
}
Ptr<EdcaTxopN>
QstaWifiMac::GetBKQueue (void) const
{
return m_bkEdca;
}
void
QstaWifiMac::SetVOQueue (Ptr<EdcaTxopN> voQueue)
{
m_voEdca = voQueue;
m_queues.insert (std::make_pair(AC_VO, m_voEdca));
m_queues[AC_VO]->SetLow (m_low);
m_queues[AC_VO]->SetManager (m_dcfManager);
m_queues[AC_VO]->SetTypeOfStation (STA);
m_queues[AC_VO]->SetTxMiddle (m_txMiddle);
}
void
QstaWifiMac::SetVIQueue (Ptr<EdcaTxopN> viQueue)
{
m_viEdca = viQueue;
m_queues.insert (std::make_pair(AC_VI, m_viEdca));
m_queues[AC_VI]->SetLow (m_low);
m_queues[AC_VI]->SetManager (m_dcfManager);
m_queues[AC_VI]->SetTypeOfStation (STA);
m_queues[AC_VI]->SetTxMiddle (m_txMiddle);
}
void
QstaWifiMac::SetBEQueue (Ptr<EdcaTxopN> beQueue)
{
m_beEdca = beQueue;
m_queues.insert (std::make_pair(AC_BE, m_beEdca));
m_queues[AC_BE]->SetLow (m_low);
m_queues[AC_BE]->SetManager (m_dcfManager);
m_queues[AC_BE]->SetTypeOfStation (STA);
m_queues[AC_BE]->SetTxMiddle (m_txMiddle);
}
void
QstaWifiMac::SetBKQueue (Ptr<EdcaTxopN> bkQueue)
{
m_bkEdca = bkQueue;
m_queues.insert (std::make_pair(AC_BK, m_bkEdca));
m_queues[AC_BK]->SetLow (m_low);
m_queues[AC_BK]->SetManager (m_dcfManager);
m_queues[AC_BK]->SetTypeOfStation (STA);
m_queues[AC_BK]->SetTxMiddle (m_txMiddle);
}
} //namespace ns3

View File

@@ -0,0 +1,171 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef QSTA_WIFI_MAC_H
#define QSTA_WIFI_MAC_H
#include "ns3/callback.h"
#include "ns3/packet.h"
#include "ns3/event-id.h"
#include "wifi-mac.h"
#include "supported-rates.h"
#include "qos-utils.h"
#include <string>
#include <vector>
#include <list>
#include <map>
namespace ns3 {
class DcfManager;
class EdcaTxopN;
class MacRxMiddle;
class MacTxMiddle;
class MacLow;
class WifiMacHeader;
class AmsduSubframeHeader;
class MsduAggregator;
class QstaWifiMac : public WifiMac
{
public:
static TypeId GetTypeId (void);
QstaWifiMac ();
virtual ~QstaWifiMac ();
// inherited from WifiMac.
virtual void SetSlot (Time slotTime);
virtual void SetSifs (Time sifs);
virtual void SetEifsNoDifs (Time eifsNoDifs);
virtual void SetAckTimeout (Time ackTimeout);
virtual void SetCtsTimeout (Time ctsTimeout);
virtual void SetPifs (Time pifs);
virtual Time GetSlot (void) const;
virtual Time GetSifs (void) const;
virtual Time GetEifsNoDifs (void) const;
virtual Time GetAckTimeout (void) const;
virtual Time GetCtsTimeout (void) const;
virtual Time GetPifs (void) const;
virtual void SetWifiPhy (Ptr<WifiPhy> phy);
virtual void SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> stationManager);
virtual void Enqueue (Ptr<const Packet> packet, Mac48Address to, Mac48Address from){};
virtual void Enqueue (Ptr<const Packet> packet, Mac48Address to);
virtual bool SupportsSendFrom (void) const;
virtual void SetForwardUpCallback (Callback<void,Ptr<Packet>, Mac48Address, Mac48Address> upCallback);
virtual void SetLinkUpCallback (Callback<void> linkUp);
virtual void SetLinkDownCallback (Callback<void> linkDown);
virtual Mac48Address GetAddress (void) const;
virtual Ssid GetSsid (void) const;
virtual void SetAddress (Mac48Address address);
virtual void SetSsid (Ssid ssid);
virtual Mac48Address GetBssid (void) const;
void SetMaxMissedBeacons (uint32_t missed);
void SetProbeRequestTimeout (Time timeout);
void SetAssocRequestTimeout (Time timeout);
void StartActiveAssociation (void);
private:
void SetBssid (Mac48Address bssid);
Mac48Address GetBroadcastBssid (void);
void Receive (Ptr<Packet> p, const WifiMacHeader *hdr);
void ForwardUp (Ptr<Packet> packet, Mac48Address from, Mac48Address to);
void SetActiveProbing (bool enable);
bool GetActiveProbing (void) const;
void MissedBeacons (void);
SupportedRates GetSupportedRates (void) const;
void RestartBeaconWatchdog (Time delay);
void AssocRequestTimeout (void);
void ProbeRequestTimeout (void);
void SendAssociationRequest (void);
void SendProbeRequest (void);
void TryToEnsureAssociated (void);
bool IsAssociated (void);
virtual void DoDispose (void);
/**
* When an A-MSDU is received, is deaggregated by this method and all extracted packets are
* forwarded up.
*/
void DeaggregateAmsduAndForward (Ptr<Packet> aggregatedPacket, WifiMacHeader const *hdr);
Ptr<EdcaTxopN> GetVOQueue (void) const;
Ptr<EdcaTxopN> GetVIQueue (void) const;
Ptr<EdcaTxopN> GetBEQueue (void) const;
Ptr<EdcaTxopN> GetBKQueue (void) const;
void SetVOQueue (Ptr<EdcaTxopN> voQueue);
void SetVIQueue (Ptr<EdcaTxopN> viQueue);
void SetBEQueue (Ptr<EdcaTxopN> beQueue);
void SetBKQueue (Ptr<EdcaTxopN> bkQueue);
QstaWifiMac &operator = (const QstaWifiMac &);
QstaWifiMac (const QstaWifiMac &);
typedef std::map<AccessClass, Ptr<EdcaTxopN> > Queues;
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> > DeaggregatedMsdus;
typedef std::list<std::pair<Ptr<Packet>, AmsduSubframeHeader> >::const_iterator DeaggregatedMsdusCI;
enum {
ASSOCIATED,
WAIT_PROBE_RESP,
WAIT_ASSOC_RESP,
BEACON_MISSED,
REFUSED
} m_state;
/*Next map is used only for an esay access to a specific queue*/
Queues m_queues;
Ptr<EdcaTxopN> m_voEdca;
Ptr<EdcaTxopN> m_viEdca;
Ptr<EdcaTxopN> m_beEdca;
Ptr<EdcaTxopN> m_bkEdca;
Ptr<MacLow> m_low;
Ptr<WifiPhy> m_phy;
Ptr<WifiRemoteStationManager> m_stationManager;
DcfManager *m_dcfManager;
MacRxMiddle *m_rxMiddle;
MacTxMiddle *m_txMiddle;
Ssid m_ssid;
Callback<void, Ptr<Packet>, Mac48Address, Mac48Address> m_forwardUp;
Callback<void> m_linkUp;
Callback<void> m_linkDown;
Time m_probeRequestTimeout;
Time m_assocRequestTimeout;
EventId m_probeRequestEvent;
EventId m_assocRequestEvent;
Time m_beaconWatchdogEnd;
EventId m_beaconWatchdog;
uint32_t m_maxMissedBeacons;
Time m_eifsNoDifs;
};
} //namespace ns3
#endif /* QSTA_WIFI_MAC_H */

View File

@@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/assert.h"
#include "ns3/address-utils.h"
@@ -43,7 +45,8 @@ WifiMacHeader::WifiMacHeader ()
: m_ctrlPwrMgt (0),
m_ctrlMoreData (0),
m_ctrlWep (0),
m_ctrlOrder (1)
m_ctrlOrder (1),
m_amsduPresent (0)
{}
WifiMacHeader::~WifiMacHeader ()
{}
@@ -141,7 +144,7 @@ WifiMacHeader::SetMultihopAction (void)
}
void
WifiMacHeader::SetType (enum WifiMacType_e type)
WifiMacHeader::SetType (enum WifiMacType type)
{
switch (type) {
case WIFI_MAC_CTL_BACKREQ:
@@ -323,6 +326,39 @@ void WifiMacHeader::SetQosTid (uint8_t tid)
{
m_qosTid = tid;
}
void WifiMacHeader::SetQosEosp ()
{
m_qosEosp = 1;
}
void WifiMacHeader::SetQosNoEosp ()
{
m_qosEosp = 0;
}
void WifiMacHeader::SetQosAckPolicy (enum QosAckPolicy policy)
{
switch (policy) {
case NORMAL_ACK :
m_qosAckPolicy = 0;
break;
case NO_ACK :
m_qosAckPolicy = 1;
break;
case NO_EXPLICIT_ACK :
m_qosAckPolicy = 2;
break;
case BLOCK_ACK :
m_qosAckPolicy = 3;
break;
}
}
void WifiMacHeader::SetQosAmsdu (void)
{
m_amsduPresent = 1;
}
void WifiMacHeader::SetQosNoAmsdu (void)
{
m_amsduPresent = 0;
}
void WifiMacHeader::SetQosTxopLimit (uint8_t txop)
{
m_qosStuff = txop;
@@ -348,7 +384,8 @@ WifiMacHeader::GetAddr4 (void) const
{
return m_addr4;
}
enum WifiMacType_e
enum WifiMacType
WifiMacHeader::GetType (void) const
{
switch (m_ctrlType) {
@@ -468,7 +505,7 @@ WifiMacHeader::GetType (void) const
}
// NOTREACHED
NS_ASSERT (false);
return (enum WifiMacType_e)-1;
return (enum WifiMacType)-1;
}
bool
WifiMacHeader::IsFromDs (void) const
@@ -651,12 +688,46 @@ WifiMacHeader::IsQosAck (void) const
NS_ASSERT (IsQosData ());
return (m_qosAckPolicy == 0)?true:false;
}
bool
WifiMacHeader::IsQosEosp (void) const
{
NS_ASSERT (IsQosData ());
return (m_qosEosp == 1)?true:false;
}
bool
WifiMacHeader::IsQosAmsdu (void) const
{
NS_ASSERT (IsQosData ());
return (m_amsduPresent == 1)?true:false;
}
uint8_t
WifiMacHeader::GetQosTid (void) const
{
NS_ASSERT (IsQosData ());
return m_qosTid;
}
enum WifiMacHeader::QosAckPolicy
WifiMacHeader::GetQosAckPolicy (void) const
{
switch (m_qosAckPolicy) {
case 0 :
return NORMAL_ACK;
break;
case 1 :
return NO_ACK;
break;
case 2 :
return NO_EXPLICIT_ACK;
break;
case 3 :
return BLOCK_ACK;
break;
}
// NOTREACHED
NS_ASSERT (false);
return (enum QosAckPolicy)-1;
}
uint8_t
WifiMacHeader::GetQosTxopLimit (void) const
{
@@ -687,6 +758,7 @@ WifiMacHeader::GetQosControl (void) const
val |= m_qosTid;
val |= m_qosEosp << 4;
val |= m_qosAckPolicy << 5;
val |= m_amsduPresent << 7;
val |= m_qosStuff << 8;
return val;
}
@@ -716,6 +788,7 @@ WifiMacHeader::SetQosControl (uint16_t qos)
m_qosTid = qos & 0x000f;
m_qosEosp = (qos >> 4) & 0x0001;
m_qosAckPolicy = (qos >> 5) & 0x0003;
m_amsduPresent = (qos >> 7) & 0x0001;
m_qosStuff = (qos >> 8) & 0x00ff;
}
@@ -816,6 +889,7 @@ WifiMacHeader::GetTypeId (void)
;
return tid;
}
TypeId
WifiMacHeader::GetInstanceTypeId (void) const
{

View File

@@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006 INRIA
* Copyright (c) 2006, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef WIFI_MAC_HEADER_H
#define WIFI_MAC_HEADER_H
@@ -27,7 +29,7 @@
namespace ns3 {
enum WifiMacType_e {
enum WifiMacType {
WIFI_MAC_CTL_RTS = 0,
WIFI_MAC_CTL_CTS,
WIFI_MAC_CTL_ACK,
@@ -68,6 +70,19 @@ enum WifiMacType_e {
class WifiMacHeader : public Header
{
public:
enum QosAckPolicy {
NORMAL_ACK = 0,
NO_ACK = 1,
NO_EXPLICIT_ACK = 2,
BLOCK_ACK = 3,
};
enum AddressType {
ADDR1,
ADDR2,
ADDR3,
ADDR4
};
WifiMacHeader ();
~WifiMacHeader ();
@@ -96,7 +111,7 @@ public:
void SetAddr2 (Mac48Address address);
void SetAddr3 (Mac48Address address);
void SetAddr4 (Mac48Address address);
void SetType (enum WifiMacType_e type);
void SetType (enum WifiMacType type);
void SetRawDuration (uint16_t duration);
void SetDuration (Time duration);
void SetId (uint16_t id);
@@ -107,13 +122,19 @@ public:
void SetRetry (void);
void SetNoRetry (void);
void SetQosTid (uint8_t tid);
void SetQosEosp ();
void SetQosNoEosp ();
void SetQosAckPolicy (enum QosAckPolicy);
void SetQosAmsdu (void);
void SetQosNoAmsdu (void);
void SetQosTxopLimit (uint8_t txop);
Mac48Address GetAddr1 (void) const;
Mac48Address GetAddr2 (void) const;
Mac48Address GetAddr3 (void) const;
Mac48Address GetAddr4 (void) const;
enum WifiMacType_e GetType (void) const;
enum WifiMacType GetType (void) const;
bool IsFromDs (void) const;
bool IsToDs (void) const;
bool IsData (void) const;
@@ -146,7 +167,10 @@ public:
bool IsQosBlockAck (void) const;
bool IsQosNoAck (void) const;
bool IsQosAck (void) const;
bool IsQosEosp (void) const;
bool IsQosAmsdu (void) const;
uint8_t GetQosTid (void) const;
enum QosAckPolicy GetQosAckPolicy (void) const;
uint8_t GetQosTxopLimit (void) const;
uint32_t GetSize (void) const;
@@ -181,6 +205,7 @@ private:
uint8_t m_qosTid;
uint8_t m_qosEosp;
uint8_t m_qosAckPolicy;
uint8_t m_amsduPresent;
uint16_t m_qosStuff;
};

View File

@@ -1,6 +1,7 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* Copyright (c) 2005, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,8 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "ns3/simulator.h"
#include "ns3/packet.h"
#include "ns3/uinteger.h"
@@ -30,7 +31,6 @@ namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (WifiMacQueue);
WifiMacQueue::Item::Item (Ptr<const Packet> packet,
WifiMacHeader const &hdr,
Time tstamp)
@@ -69,16 +69,19 @@ WifiMacQueue::SetMaxSize (uint32_t maxSize)
{
m_maxSize = maxSize;
}
void
void
WifiMacQueue::SetMaxDelay (Time delay)
{
m_maxDelay = delay;
}
uint32_t
WifiMacQueue::GetMaxSize (void) const
{
return m_maxSize;
}
Time
WifiMacQueue::GetMaxDelay (void) const
{
@@ -97,6 +100,7 @@ WifiMacQueue::Enqueue (Ptr<const Packet> packet, WifiMacHeader const &hdr)
m_queue.push_back (Item (packet, hdr, now));
m_size++;
}
void
WifiMacQueue::Cleanup (void)
{
@@ -136,6 +140,72 @@ WifiMacQueue::Dequeue (WifiMacHeader *hdr)
return 0;
}
Ptr<const Packet>
WifiMacQueue::Peek (WifiMacHeader *hdr)
{
Cleanup ();
if (!m_queue.empty ())
{
Item i = m_queue.front ();
*hdr = i.hdr;
return i.packet;
}
return 0;
}
Ptr<const Packet>
WifiMacQueue::DequeueByTidAndAddress (WifiMacHeader *hdr, uint8_t tid,
WifiMacHeader::AddressType type, Mac48Address dest)
{
Cleanup ();
Ptr<const Packet> packet = 0;
if (!m_queue.empty ())
{
PacketQueueI it;
NS_ASSERT (type <= 4);
for (it = m_queue.begin (); it != m_queue.end (); ++it)
{
if (it->hdr.IsQosData ())
{
if (GetAddressForPacket (type, it) == dest &&
it->hdr.GetQosTid () == tid)
{
packet = it->packet;
*hdr = it->hdr;
m_queue.erase (it);
m_size--;
break;
}
}
}
}
return packet;
}
Ptr<const Packet>
WifiMacQueue::PeekByTidAndAddress (WifiMacHeader *hdr, uint8_t tid,
WifiMacHeader::AddressType type, Mac48Address dest)
{
Cleanup ();
if (!m_queue.empty ())
{
PacketQueueI it;
NS_ASSERT (type <= 4);
for (it = m_queue.begin (); it != m_queue.end (); ++it)
{
if (it->hdr.IsQosData ())
{
if (GetAddressForPacket (type, it) == dest &&
it->hdr.GetQosTid () == tid)
{
*hdr = it->hdr;
return it->packet;
}
}
}
}
return 0;
}
bool
WifiMacQueue::IsEmpty (void)
@@ -144,7 +214,6 @@ WifiMacQueue::IsEmpty (void)
return m_queue.empty ();
}
uint32_t
WifiMacQueue::GetSize (void)
{
@@ -158,4 +227,37 @@ WifiMacQueue::Flush (void)
m_size = 0;
}
Mac48Address
WifiMacQueue::GetAddressForPacket (uint8_t type, PacketQueueI it)
{
if (type == WifiMacHeader::ADDR1)
{
return it->hdr.GetAddr1 ();
}
if (type == WifiMacHeader::ADDR2)
{
return it->hdr.GetAddr2 ();
}
if (type == WifiMacHeader::ADDR3)
{
return it->hdr.GetAddr3 ();
}
return 0;
}
bool
WifiMacQueue::Remove (Ptr<const Packet> packet)
{
PacketQueueI it = m_queue.begin ();
for (; it != m_queue.end (); it++)
{
if (it->packet == packet)
{
m_queue.erase (it);
return true;
}
}
return false;
}
} // namespace ns3

View File

@@ -1,6 +1,7 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005 INRIA
* Copyright (c) 2005, 2009 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,11 +17,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef WIFI_MAC_QUEUE_H
#define WIFI_MAC_QUEUE_H
#include <deque>
#include <list>
#include <utility>
#include "ns3/packet.h"
#include "ns3/nstime.h"
@@ -60,25 +62,60 @@ public:
void Enqueue (Ptr<const Packet> packet, WifiMacHeader const &hdr);
Ptr<const Packet> Dequeue (WifiMacHeader *hdr);
Ptr<const Packet> Peek (WifiMacHeader *hdr);
/**
* Searchs and returns, if is present in this queue, first packet having
* address indicated by <i>type</i> equals to <i>addr</i>, and tid
* equals to <i>tid</i>. This method removes the packet from this queue.
* Is typically used by ns3::EdcaTxopN in order to perform correct MSDU
* aggregation (A-MSDU).
*/
Ptr<const Packet> DequeueByTidAndAddress (WifiMacHeader *hdr,
uint8_t tid,
WifiMacHeader::AddressType type,
Mac48Address addr);
/**
* Searchs and returns, if is present in this queue, first packet having
* address indicated by <i>type</i> equals to <i>addr</i>, and tid
* equals to <i>tid</i>. This method doesn't remove the packet from this queue.
* Is typically used by ns3::EdcaTxopN in order to perform correct MSDU
* aggregation (A-MSDU).
*/
Ptr<const Packet> PeekByTidAndAddress (WifiMacHeader *hdr,
uint8_t tid,
WifiMacHeader::AddressType type,
Mac48Address addr);
/**
* If exists, removes <i>packet</i> from queue and returns true. Otherwise it
* takes no effects and return false. Deletion of the packet is
* performed in linear time (O(n)).
*/
bool Remove (Ptr<const Packet> packet);
void Flush (void);
bool IsEmpty (void);
uint32_t GetSize (void);
private:
struct Item;
typedef std::list<struct Item> PacketQueue;
typedef std::list<struct Item>::reverse_iterator PacketQueueRI;
typedef std::list<struct Item>::iterator PacketQueueI;
void Cleanup (void);
Mac48Address GetAddressForPacket (uint8_t type, PacketQueueI);
struct Item {
Item (Ptr<const Packet> packet,
WifiMacHeader const&hdr,
WifiMacHeader const &hdr,
Time tstamp);
Ptr<const Packet> packet;
WifiMacHeader hdr;
Time tstamp;
};
typedef std::deque<struct Item> PacketQueue;
typedef std::deque<struct Item>::reverse_iterator PacketQueueRI;
typedef std::deque<struct Item>::iterator PacketQueueI;
PacketQueue m_queue;
WifiMacParameters *m_parameters;
uint32_t m_size;
@@ -88,5 +125,4 @@ private:
} // namespace ns3
#endif /* WIFI_MAC_QUEUE_H */

View File

@@ -33,6 +33,8 @@
#include "ns3/simulator.h"
#include "ns3/test.h"
#include "ns3/object-factory.h"
#include "dca-txop.h"
#include "ns3/pointer.h"
namespace ns3 {
@@ -69,7 +71,9 @@ WifiTest::CreateOne (Vector pos, Ptr<YansWifiChannel> channel)
Ptr<Node> node = CreateObject<Node> ();
Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
Ptr<DcaTxop> queue = CreateObject<DcaTxop> ();
Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
mac->SetAttribute("DcaTxop", PointerValue (queue));
Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();

View File

@@ -11,30 +11,61 @@
*
* The current implementation provides roughly 4 levels of models:
* - the PHY layer models
* - the so-called MAC low models: they implement DCF
* - the so-called MAC low models: they implement DCF and EDCAF
* - the so-called MAC high models: they implement the MAC-level
* beacon generation, probing, and association state machines.
* - a set of Rate control algorithms used by the MAC low models.
*
* We have today 3 MAC high models:
* We have today 6 MAC high models, 3 for non QoS MACs and 3 for QoS MACs.
*
* a)non QoS MACs:
*
* - a simple adhoc state machine which does not perform any
* kind of beacon generation, probing, or association. This
* state machine is implemented by the ns3::AdhocWifiNetDevice
* and ns3::MacHighAdhoc classes.
* state machine is implemented by the ns3::AdhocWifiMac class.
* - an active probing and association state machine which handles
* automatic re-association whenever too many beacons are missed
* is implemented by the ns3::NqstaWifiNetDevice and
* ns3::MacHighNqsta classes.
* is implemented by the ns3::NqstaWifiMac class.
* - an access point which generates periodic beacons, and which
* accepts every attempt to associate. This AP state machine
* is implemented by the ns3::NqapWifiNetDevice and
* ns3::MacHighNqap classes.
* is implemented by the ns3::NqapWifiMac class.
*
* b)QoS MACs:
*
* - like above but these MAC models are also able to manage QoS traffic.
* These MAC layers are implemented respectively by ns3::QadhocWifiMac,
* ns3::QstaWifiMac and ns3::QapWifiMac classes.
* With these MAC models is possible to work with traffic belonging to
* four different access classes: AC_VO for voice traffic, AC_VI for video
* traffic, AC_BE for best-effort traffic and AC_BK for background traffic.
* In order to determine MSDU's access class, every packet forwarded down
* to these MAC layers should be marked using ns3::QosTag in order to set
* a TID (traffic id) for that packet otherwise it will be considered
* belonging to AC_BE access class.
* How TIDs are mapped to access classes are shown in the table below.
*
* TID-AccessClass mapping:
*
* TID | Access class
* --------------------
* 7 | AC_VO ^
* 6 | AC_VO |
* 5 | AC_VI |
* 4 | AC_VI |
* 3 | AC_BE | priority
* 0 | AC_BE |
* 2 | AC_BK |
* 1 | AC_BK |
*
*
* The MAC low layer is split in 3 components:
* - ns3::MacLow which takes care of RTS/CTS/DATA/ACK transactions.
* - ns3::DcfManager and ns3::DcfState which implements the DCF function.
* - ns3::DcaTxop which handles the packet queue, packet fragmentation,
* and packet retransmissions if they are needed.
* - ns3::DcaTxop or ns3::EdcaTxopN which handle the packet queue, packet
* fragmentation, and packet retransmissions if they are needed.
* ns3::DcaTxop object is used by non QoS high MACs. ns3::EdcaTxopN is
* used by Qos high MACs and performs also QoS operations like 802.11n MSDU
* aggregation.
*
* The PHY layer implements a single model in the ns3::WifiPhy class: the
* physical layer model implemented there is described fully in a paper titled

View File

@@ -46,6 +46,15 @@ def build(bld):
'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',
]
headers = bld.new_task_gen('ns3header')
headers.module = 'wifi'
@@ -58,7 +67,7 @@ def build(bld):
'wifi-mode.h',
'ssid.h',
'wifi-preamble.h',
'wifi-phy-standard.h',
'wifi-phy-standard.h',
'yans-wifi-phy.h',
'yans-wifi-channel.h',
'wifi-phy.h',
@@ -77,17 +86,18 @@ def build(bld):
'nqap-wifi-mac.h',
'wifi-phy.h',
'supported-rates.h',
'mgt-headers.h',
'status-code.h',
'capability-information.h',
'error-rate-model.h',
'yans-error-rate-model.h',
# Need this for module devices/mesh
'dca-txop.h',
'wifi-mac-header.h',
'dcf-manager.h',
'mac-rx-middle.h',
'mac-low.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',
]
obj = bld.create_ns3_program('wifi-phy-test',

View File

@@ -0,0 +1,86 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "nqos-wifi-mac-helper.h"
#include "ns3/wifi-mac.h"
#include "ns3/pointer.h"
#include "ns3/dca-txop.h"
namespace ns3 {
NqosWifiMacHelper::NqosWifiMacHelper ()
{
m_queue.SetTypeId ("ns3::DcaTxop");
}
NqosWifiMacHelper::~NqosWifiMacHelper ()
{}
NqosWifiMacHelper
NqosWifiMacHelper::Default (void)
{
NqosWifiMacHelper helper;
helper.SetType ("ns3::AdhocWifiMac");
return helper;
}
void
NqosWifiMacHelper::SetType (std::string type,
std::string n0, const AttributeValue &v0,
std::string n1, const AttributeValue &v1,
std::string n2, const AttributeValue &v2,
std::string n3, const AttributeValue &v3,
std::string n4, const AttributeValue &v4,
std::string n5, const AttributeValue &v5,
std::string n6, const AttributeValue &v6,
std::string n7, const AttributeValue &v7)
{
m_mac.SetTypeId (type);
m_mac.Set (n0, v0);
m_mac.Set (n1, v1);
m_mac.Set (n2, v2);
m_mac.Set (n3, v3);
m_mac.Set (n4, v4);
m_mac.Set (n5, v5);
m_mac.Set (n6, v6);
m_mac.Set (n7, v7);
}
void
NqosWifiMacHelper::SetDcaParameters (std::string n0, const AttributeValue &v0,
std::string n1, const AttributeValue &v1,
std::string n2, const AttributeValue &v2,
std::string n3, const AttributeValue &v3)
{
m_queue.Set (n0, v0);
m_queue.Set (n1, v1);
m_queue.Set (n2, v2);
m_queue.Set (n3, v3);
}
Ptr<WifiMac>
NqosWifiMacHelper::Create (void) const
{
Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
Ptr<DcaTxop> queue = m_queue.Create<DcaTxop> ();
mac->SetAttribute ("DcaTxop", PointerValue (queue));
return mac;
}
} //namespace ns3

View File

@@ -0,0 +1,95 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef NQOS_WIFI_MAC_HELPER_H
#define NQOS_WIFI_MAC_HELPER_H
#include "wifi-helper.h"
namespace ns3 {
class NqosWifiMacHelper : public WifiMacHelper
{
public:
NqosWifiMacHelper ();
virtual ~NqosWifiMacHelper ();
/**
* Create a mac helper in a default working state.
*/
static NqosWifiMacHelper Default (void);
/**
* \param type the type of ns3::WifiMac to create.
* \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
*
* All the attributes specified in this method should exist
* in the requested mac.
*/
void SetType (std::string type,
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 type the type of ns3::WifiMac to create.
* \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
*/
void SetDcaParameters (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 ());
private:
/**
* \returns a newly-created MAC object.
*
* This method implements the pure virtual method defined in \ref ns3::WifiMacHelper.
*/
virtual Ptr<WifiMac> Create (void) const;
ObjectFactory m_mac;
ObjectFactory m_queue;
};
} //namespace ns3
#endif /* NQOS_WIFI_MAC_HELPER_H */

View File

@@ -0,0 +1,191 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "qos-wifi-mac-helper.h"
#include "ns3/msdu-aggregator.h"
#include "ns3/wifi-mac.h"
#include "ns3/edca-txop-n.h"
#include "ns3/pointer.h"
#include "ns3/uinteger.h"
namespace ns3 {
QosWifiMacHelper::QosWifiMacHelper ()
{
m_aggregators.insert (std::make_pair (AC_VO, ObjectFactory ()));
m_aggregators.insert (std::make_pair (AC_VI, ObjectFactory ()));
m_aggregators.insert (std::make_pair (AC_BE, ObjectFactory ()));
m_aggregators.insert (std::make_pair (AC_BK, ObjectFactory ()));
m_queues.insert (std::make_pair (AC_VO, ObjectFactory ()));
m_queues.insert (std::make_pair (AC_VI, ObjectFactory ()));
m_queues.insert (std::make_pair (AC_BE, ObjectFactory ()));
m_queues.insert (std::make_pair (AC_BK, ObjectFactory ()));
m_queues[AC_VO].SetTypeId ("ns3::EdcaTxopN");
m_queues[AC_VI].SetTypeId ("ns3::EdcaTxopN");
m_queues[AC_BE].SetTypeId ("ns3::EdcaTxopN");
m_queues[AC_BK].SetTypeId ("ns3::EdcaTxopN");
}
QosWifiMacHelper::~QosWifiMacHelper ()
{}
QosWifiMacHelper
QosWifiMacHelper::Default (void)
{
QosWifiMacHelper helper;
helper.SetType ("ns3::QstaWifiMac");
/* For more details about this default parameters see IEE802.11 section 7.3.2.29 */
helper.SetEdcaParametersForAc (AC_VO,"MinCw", UintegerValue (3),
"MaxCw", UintegerValue (7),
"Aifsn", UintegerValue (2));
helper.SetEdcaParametersForAc (AC_VI,"MinCw", UintegerValue (7),
"MaxCw", UintegerValue (15),
"Aifsn", UintegerValue (2));
helper.SetEdcaParametersForAc (AC_BE,"MinCw", UintegerValue (15),
"MaxCw", UintegerValue (1023),
"Aifsn", UintegerValue (3));
helper.SetEdcaParametersForAc (AC_BK,"MinCw", UintegerValue (15),
"MaxCw", UintegerValue (1023),
"Aifsn", UintegerValue (7));
return helper;
}
void
QosWifiMacHelper::SetType (std::string type,
std::string n0, const AttributeValue &v0,
std::string n1, const AttributeValue &v1,
std::string n2, const AttributeValue &v2,
std::string n3, const AttributeValue &v3,
std::string n4, const AttributeValue &v4,
std::string n5, const AttributeValue &v5,
std::string n6, const AttributeValue &v6,
std::string n7, const AttributeValue &v7)
{
m_mac.SetTypeId (type);
m_mac.Set (n0, v0);
m_mac.Set (n1, v1);
m_mac.Set (n2, v2);
m_mac.Set (n3, v3);
m_mac.Set (n4, v4);
m_mac.Set (n5, v5);
m_mac.Set (n6, v6);
m_mac.Set (n7, v7);
}
void
QosWifiMacHelper::SetMsduAggregatorForAc (AccessClass accessClass, std::string type,
std::string n0, const AttributeValue &v0,
std::string n1, const AttributeValue &v1,
std::string n2, const AttributeValue &v2,
std::string n3, const AttributeValue &v3)
{
std::map<AccessClass, ObjectFactory>::iterator it;
it = m_aggregators.find (accessClass);
if (it != m_aggregators.end ())
{
it->second.SetTypeId (type);
it->second.Set (n0, v0);
it->second.Set (n1, v1);
it->second.Set (n2, v2);
it->second.Set (n3, v3);
}
}
void
QosWifiMacHelper::SetEdcaParametersForAc (AccessClass accessClass,
std::string n0, const AttributeValue &v0,
std::string n1, const AttributeValue &v1,
std::string n2, const AttributeValue &v2,
std::string n3, const AttributeValue &v3)
{
std::map<AccessClass, ObjectFactory>::iterator it;
it = m_queues.find (accessClass);
if (it != m_queues.end ())
{
it->second.Set (n0, v0);
it->second.Set (n1, v1);
it->second.Set (n2, v2);
it->second.Set (n3, v3);
}
}
Ptr<WifiMac>
QosWifiMacHelper::Create (void) const
{
Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
Ptr<EdcaTxopN> edcaQueue;
Ptr<MsduAggregator> aggregator;
std::map<AccessClass, ObjectFactory>::const_iterator itQueue;
std::map<AccessClass, ObjectFactory>::const_iterator itAggr;
/* Setting for VO queue */
itQueue = m_queues.find (AC_VO);
itAggr = m_aggregators.find (AC_VO);
edcaQueue = itQueue->second.Create<EdcaTxopN> ();
if (itAggr->second.GetTypeId ().GetUid () != 0)
{
aggregator = itAggr->second.Create<MsduAggregator> ();
edcaQueue->SetMsduAggregator (aggregator);
}
mac->SetAttribute ("VO_EdcaTxopN", PointerValue (edcaQueue));
/* Setting for VI queue */
itQueue = m_queues.find (AC_VI);
itAggr = m_aggregators.find (AC_VI);
edcaQueue = itQueue->second.Create<EdcaTxopN> ();
if (itAggr->second.GetTypeId ().GetUid () != 0)
{
aggregator = itAggr->second.Create<MsduAggregator> ();
edcaQueue->SetMsduAggregator (aggregator);
}
mac->SetAttribute ("VI_EdcaTxopN", PointerValue (edcaQueue));
/* Setting for BE queue */
itQueue = m_queues.find (AC_BE);
itAggr = m_aggregators.find (AC_BE);
edcaQueue = itQueue->second.Create<EdcaTxopN> ();
if (itAggr->second.GetTypeId ().GetUid () != 0)
{
aggregator = itAggr->second.Create<MsduAggregator> ();
edcaQueue->SetMsduAggregator (aggregator);
}
mac->SetAttribute ("BE_EdcaTxopN", PointerValue (edcaQueue));
/* Setting for BK queue */
itQueue = m_queues.find (AC_BK);
itAggr = m_aggregators.find (AC_BK);
edcaQueue = itQueue->second.Create<EdcaTxopN> ();
if (itAggr->second.GetTypeId ().GetUid () != 0)
{
aggregator = itAggr->second.Create<MsduAggregator> ();
edcaQueue->SetMsduAggregator (aggregator);
}
mac->SetAttribute ("BK_EdcaTxopN", PointerValue (edcaQueue));
return mac;
}
} //namespace ns3

View File

@@ -0,0 +1,123 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2009 MIRKO BANCHI
*
* 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: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef QOS_WIFI_MAC_HELPER_H
#define QOS_WIFI_MAC_HELPER_H
#include "wifi-helper.h"
#include "ns3/qos-utils.h"
#include <map>
namespace ns3 {
class QosWifiMacHelper : public WifiMacHelper
{
public:
QosWifiMacHelper ();
virtual ~QosWifiMacHelper ();
/**
* Create a mac helper in a default working state.
*/
static QosWifiMacHelper Default (void);
/**
* \param type the type of ns3::WifiMac to create.
* \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
*
* All the attributes specified in this method should exist
* in the requested mac.
*/
void SetType (std::string type,
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 accessClass access class for which we are setting aggregator. Possibilities
* are: AC_BK, AC_BE, AC_VI, AC_VO.
* \param aggregatorType type of aggregator.
* \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
*
* All the attributes specified in this method should exist
* in the requested aggregator.
*/
void SetMsduAggregatorForAc (AccessClass accessClass, std::string type,
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 ());
/**
* \param accessClass access class for which we are setting edca params. Possibilities
* are: AC_BK, AC_BE, AC_VI, AC_VO.
* \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
*/
void SetEdcaParametersForAc (AccessClass accessClass,
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 ());
private:
/**
* \returns a newly-created MAC object.
*
* This method implements the pure virtual method defined in \ref ns3::WifiMacHelper.
*/
virtual Ptr<WifiMac> Create (void) const;
ObjectFactory m_mac;
std::map<AccessClass, ObjectFactory> m_queues;
std::map<AccessClass, ObjectFactory> m_aggregators;
};
} //namespace ns3
#endif /* QOS_WIFI_MAC_HELPER_H */

View File

@@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#include "wifi-helper.h"
#include "ns3/wifi-net-device.h"
@@ -40,6 +42,8 @@ namespace ns3 {
WifiPhyHelper::~WifiPhyHelper ()
{}
WifiMacHelper::~WifiMacHelper ()
{}
WifiHelper::WifiHelper ()
{}
@@ -49,7 +53,6 @@ WifiHelper::Default (void)
{
WifiHelper helper;
helper.SetRemoteStationManager ("ns3::ArfWifiManager");
helper.SetMac ("ns3::AdhocWifiMac");
return helper;
}
@@ -76,31 +79,9 @@ WifiHelper::SetRemoteStationManager (std::string type,
m_stationManager.Set (n7, v7);
}
void
WifiHelper::SetMac (std::string type,
std::string n0, const AttributeValue &v0,
std::string n1, const AttributeValue &v1,
std::string n2, const AttributeValue &v2,
std::string n3, const AttributeValue &v3,
std::string n4, const AttributeValue &v4,
std::string n5, const AttributeValue &v5,
std::string n6, const AttributeValue &v6,
std::string n7, const AttributeValue &v7)
{
m_mac = ObjectFactory ();
m_mac.SetTypeId (type);
m_mac.Set (n0, v0);
m_mac.Set (n1, v1);
m_mac.Set (n2, v2);
m_mac.Set (n3, v3);
m_mac.Set (n4, v4);
m_mac.Set (n5, v5);
m_mac.Set (n6, v6);
m_mac.Set (n7, v7);
}
NetDeviceContainer
WifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
WifiHelper::Install (const WifiPhyHelper &phyHelper,
const WifiMacHelper &macHelper, NodeContainer c) const
{
NetDeviceContainer devices;
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
@@ -108,7 +89,7 @@ WifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
Ptr<Node> node = *i;
Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
Ptr<WifiMac> mac = m_mac.Create<WifiMac> ();
Ptr<WifiMac> mac = macHelper.Create ();
Ptr<WifiPhy> phy = phyHelper.Create (node, device);
mac->SetAddress (Mac48Address::Allocate ());
device->SetMac (mac);
@@ -120,16 +101,20 @@ WifiHelper::Install (const WifiPhyHelper &phyHelper, NodeContainer c) const
}
return devices;
}
NetDeviceContainer
WifiHelper::Install (const WifiPhyHelper &phy, Ptr<Node> node) const
WifiHelper::Install (const WifiPhyHelper &phy,
const WifiMacHelper &mac, Ptr<Node> node) const
{
return Install (phy, NodeContainer (node));
return Install (phy, mac, NodeContainer (node));
}
NetDeviceContainer
WifiHelper::Install (const WifiPhyHelper &phy, std::string nodeName) const
WifiHelper::Install (const WifiPhyHelper &phy,
const WifiMacHelper &mac, std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node> (nodeName);
return Install (phy, NodeContainer (node));
return Install (phy, mac, NodeContainer (node));
}
} // namespace ns3

View File

@@ -1,6 +1,7 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2008 INRIA
* Copyright (c) 2009 MIRKO BANCHI
*
* 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
@@ -16,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Author: Mirko Banchi <mk.banchi@gmail.com>
*/
#ifndef WIFI_HELPER_H
#define WIFI_HELPER_H
@@ -29,6 +31,7 @@
namespace ns3 {
class WifiPhy;
class WifiMac;
class WifiNetDevice;
class Node;
@@ -53,6 +56,25 @@ public:
virtual Ptr<WifiPhy> Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const = 0;
};
/**
* \brief create MAC objects
*
* This base class must be implemented by new MAC implementation which wish to integrate
* with the \ref ns3::WifiHelper class.
*/
class WifiMacHelper
{
public:
virtual ~WifiMacHelper ();
/**
* \returns a new MAC object.
*
* Subclasses must implement this method to allow the ns3::WifiHelper class
* to create MAC objects from ns3::WifiHelper::Install.
*/
virtual Ptr<WifiMac> Create (void) const = 0;
};
/**
* \brief helps to create WifiNetDevice objects
*
@@ -108,61 +130,33 @@ public:
std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
/**
* \param type the type of ns3::WifiMac to create.
* \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
*
* All the attributes specified in this method should exist
* in the requested mac.
*/
void SetMac (std::string type,
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 phy the PHY helper to create PHY objects
* \param mac the MAC helper to create MAC objects
* \param c the set of nodes on which a wifi device must be created
* \returns a device container which contains all the devices created by this method.
*/
NetDeviceContainer Install (const WifiPhyHelper &phy, NodeContainer c) const;
NetDeviceContainer Install (const WifiPhyHelper &phy,
const WifiMacHelper &mac, NodeContainer c) const;
/**
* \param phy the PHY helper to create PHY objects
* \param mac the MAC helper to create MAC objects
* \param node the node on which a wifi device must be created
* \returns a device container which contains all the devices created by this method.
*/
NetDeviceContainer Install (const WifiPhyHelper &phy, Ptr<Node> node) const;
NetDeviceContainer Install (const WifiPhyHelper &phy,
const WifiMacHelper &mac, Ptr<Node> node) const;
/**
* \param phy the PHY helper to create PHY objects
* \param mac the MAC helper to create MAC objects
* \param nodeName the name of node on which a wifi device must be created
* \returns a device container which contains all the devices created by this method.
*/
NetDeviceContainer Install (const WifiPhyHelper &phy, std::string nodeName) const;
NetDeviceContainer Install (const WifiPhyHelper &phy,
const WifiMacHelper &mac, std::string nodeName) const;
private:
ObjectFactory m_stationManager;
ObjectFactory m_mac;
};
} // namespace ns3

View File

@@ -23,6 +23,8 @@ def build(bld):
'bridge-helper.cc',
'yans-wifi-helper.cc',
'v4ping-helper.cc',
'nqos-wifi-mac-helper.cc',
'qos-wifi-mac-helper.cc',
]
headers = bld.new_task_gen('ns3header')
@@ -48,6 +50,8 @@ def build(bld):
'bridge-helper.h',
'yans-wifi-helper.h',
'v4ping-helper.h',
'nqos-wifi-mac-helper.h',
'qos-wifi-mac-helper.h',
]
env = bld.env_of_name('default')

View File

@@ -142,18 +142,6 @@ Mac48Address::IsBroadcast (void) const
return *this == GetBroadcast ();
}
bool
Mac48Address::IsMulticast (void) const
{
uint8_t mcBuf[6];
CopyTo (mcBuf);
mcBuf[3] &= 0x80;
mcBuf[4] = 0;
mcBuf[5] = 0;
Mac48Address prefix;
prefix.CopyFrom (mcBuf);
return prefix == Mac48Address::GetMulticastPrefix ();
}
bool
Mac48Address::IsGroup (void) const
{
return (m_address[0] & 0x01) == 0x01;

View File

@@ -90,10 +90,7 @@ public:
* \returns true if this is a broadcast address, false otherwise.
*/
bool IsBroadcast (void) const;
/**
* \returns true if this is a multicast address, false otherwise.
*/
bool IsMulticast (void) const;
/**
* \returns true if the group bit is set, false otherwise.
*/

View File

@@ -60,6 +60,17 @@ class Packet;
* If you want to write a new MAC layer, you need to subclass
* this base class and implement your own version of the
* NetDevice::SendTo method.
*
* This class was designed to hide as many MAC-level details as
* possible from the perspective of layer 3 to allow a single layer 3
* to work with any kind of MAC layer. Specifically, this class
* encapsulates the specific format of MAC addresses used by a
* device such that the layer 3 does not need any modification
* to handle new address formats. This means obviously that the
* NetDevice class must know about the address format of all potential
* layer 3 protocols through its GetMulticast methods: the current
* API has been optimized to make it easy to add new MAC protocols,
* not to add new layer 3 protocols.
*/
class NetDevice : public Object
{

View File

@@ -54,7 +54,7 @@ SimpleNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
{
packetType = NetDevice::PACKET_HOST;
}
else if (to.IsMulticast ())
else if (to.IsGroup ())
{
packetType = NetDevice::PACKET_MULTICAST;
}

View File

@@ -19,6 +19,7 @@
*/
#include "high-precision-128.h"
#include "ns3/test.h"
#include "ns3/fatal-error.h"
#include <math.h>
#include <iostream>
@@ -151,10 +152,69 @@ HighPrecision::SlowMul (HighPrecision const &o)
{
EnsureSlow ();
const_cast<HighPrecision &> (o).EnsureSlow ();
cairo_int128_t other = _cairo_int128_rsa (o.m_slowValue, 64);
m_slowValue = _cairo_int128_mul (m_slowValue, other);
//use the 128 bits multiplication
m_slowValue = Mul128(m_slowValue,o.m_slowValue);
return false;
}
/**
* this function multiplies two 128 bits fractions considering
* the high 64 bits as the integer part and the low 64 bits
* as the fractional part. It takes into account the sign
* of the operands to produce a signed 128 bits result.
*/
cairo_int128_t
HighPrecision::Mul128(cairo_int128_t a, cairo_int128_t b )
{
//Implement the 128 bits multiplication
cairo_int128_t result;
cairo_uint128_t hiPart,loPart,midPart;
bool resultNegative = false, signA = false,signB = false;
//take the sign of the operands
signA = _cairo_int128_negative (a);
signB = _cairo_int128_negative (b);
//the result is negative only if one of the operand is negative
if ((signA == true && signB == false) ||(signA == false && signB == true))
{
resultNegative = true;
}
//now take the absolute part to make sure that the resulting operands are positive
if (signA == true)
{
a = _cairo_int128_negate (a);
}
if (signB == true)
{
b = _cairo_int128_negate (b);
}
//Multiplying (a.h 2^64 + a.l) x (b.h 2^64 + b.l) =
// 2^128 a.h b.h + 2^64*(a.h b.l+b.h a.l) + a.l b.l
//get the low part a.l b.l
//multiply the fractional part
loPart = _cairo_uint64x64_128_mul (a.lo, b.lo);
//compute the middle part 2^64*(a.h b.l+b.h a.l)
midPart = _cairo_uint128_add(_cairo_uint64x64_128_mul(a.lo, b.hi),
_cairo_uint64x64_128_mul(a.hi, b.lo)) ;
//truncate the low part
result.lo = _cairo_uint64_add(loPart.hi,midPart.lo);
//compute the high part 2^128 a.h b.h
hiPart = _cairo_uint64x64_128_mul (a.hi, b.hi);
//truncate the high part and only use the low part
result.hi = _cairo_uint64_add(hiPart.lo,midPart.hi);
//if the high part is not zero, put a warning
if (hiPart.hi !=0)
{
NS_FATAL_ERROR("High precision 128 bits multiplication error: multiplication overflow.");
}
//add the sign to the result
if (resultNegative)
{
result = _cairo_int128_negate (result);
}
return result;
}
bool
HighPrecision::Div (HighPrecision const &o)
{
@@ -351,6 +411,22 @@ HighPrecision128Tests::RunTests (void)
a = HighPrecision (0.1);
a.Div (HighPrecision (1.25));
NS_TEST_ASSERT_EQUAL (a.GetDouble (), 0.08);
//test the multiplication
a = HighPrecision (0.5);
a.Mul(HighPrecision (5));
NS_TEST_ASSERT_EQUAL (a.GetDouble (), 2.5);
//test the sign of multiplication, first operand negative
a = HighPrecision (-0.5);
a.Mul(HighPrecision (5));
NS_TEST_ASSERT_EQUAL (a.GetDouble (), -2.5);
//two negative
a = HighPrecision (-0.5);
a.Mul(HighPrecision (-5));
NS_TEST_ASSERT_EQUAL (a.GetDouble (), 2.5);
//second operand negative
a = HighPrecision (0.5);
a.Mul(HighPrecision (-5));
NS_TEST_ASSERT_EQUAL (a.GetDouble (), -2.5);
return result;

View File

@@ -47,6 +47,26 @@
* If you want to monitor the efficiency of this strategy, you can
* enable the macro HP128INC below and call the HighPrecision::PrintStats
* method at the end of the simulation.
*
* Explanation of Slow and Fast values:
*
* HighPrecision class create a fastValue and a slowValue depending on the
* input number. If the input is an integer with 0 fractional part, it will
* use the fastValue which will contain the integer in a 64 bits format. If
* it has a fractional part, the slowValue will be used. It is represented
* simply as a high part slowValue.hi which will contain the integer part
* and the fractional part slowValue.lo which will contain the factional
* part as an integer (obtained by multiplying the fractional part by 2^64).
*
* Explanation of Slow and Fast operations:
*
* If both operands are fastValues, we will perform fast operations, i-e
* simply using integer operations. If we have though one of the value is
* slowValue we need to convert the fastValue into a slow one. It is simply
* obtained by putting the slowValue.lo = 0 and slowValue.hi = fastValue.
* After that we apply the slow operation which will be a 128 bits operation
* with two 128 bits operands.
*
*/
@@ -85,6 +105,7 @@ private:
bool SlowSub (HighPrecision const &o);
bool SlowMul (HighPrecision const &o);
int SlowCompare (HighPrecision const &o) const;
cairo_uint128_t Mul128(cairo_uint128_t , cairo_uint128_t );
inline void EnsureSlow (void);
static const double MAX_64;

View File

@@ -572,11 +572,11 @@ void TimeTests::CheckOld (bool *ok)
Time t4;
t4 = Seconds (10.0) * Scalar (1.5);
CheckTimeSec("old 11", t4.GetSeconds(), 10, ok);
CheckTimeSec("old 11", t4.GetSeconds(), 15, ok);
Time t5;
t5 = NanoSeconds (10) * Scalar (1.5);
CheckTime("old 12", t5.GetNanoSeconds(), 10, ok);
CheckTime("old 12", t5.GetNanoSeconds(), 15, ok);
t4 = Seconds (10.0) * Scalar (15) / Scalar (10);
CheckTimeSec("old 13", t4.GetSeconds(), 15, ok);

View File

@@ -74,7 +74,16 @@ def create_ns3_module(bld, name, dependencies=()):
module.target = module.name
module.add_objects = ['ns3-' + dep for dep in dependencies]
module.module_deps = list(dependencies)
module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
if not module.env['ENABLE_STATIC_NS3']:
module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
elif module.env['CXX_NAME'] == 'gcc' 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