From a1691fda9bb1a6be754432247f93f1f97aaf2f34 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 9 Oct 2007 16:40:24 +0200 Subject: [PATCH] add SupportedRates to build --- src/devices/wifi/supported-rates.cc | 103 ++++++++++++++++++++++++++++ src/devices/wifi/supported-rates.h | 50 ++++++++++++++ src/devices/wifi/wscript | 1 + 3 files changed, 154 insertions(+) create mode 100644 src/devices/wifi/supported-rates.cc create mode 100644 src/devices/wifi/supported-rates.h diff --git a/src/devices/wifi/supported-rates.cc b/src/devices/wifi/supported-rates.cc new file mode 100644 index 000000000..a0b79a04e --- /dev/null +++ b/src/devices/wifi/supported-rates.cc @@ -0,0 +1,103 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ + +#include "supported-rates.h" +#include "ns3/assert.h" + +namespace ns3 { + +SupportedRates::SupportedRates () + : m_nRates (0) +{} + +void +SupportedRates::AddSupportedRate (uint32_t bs) +{ + NS_ASSERT (m_nRates < 8); + m_rates[m_nRates] = bs/500000; + m_nRates++; +} +void +SupportedRates::SetBasicRate (uint32_t bs) +{ + uint8_t rate = bs / 500000; + for (uint8_t i = 0; i < m_nRates; i++) + { + if (rate == m_rates[i]) + { + m_rates[i] |= 0x80; + return; + } + } + AddSupportedRate (bs); + SetBasicRate (bs); +} +bool +SupportedRates::IsBasicRate (uint32_t bs) const +{ + uint8_t rate = bs / 500000; + for (uint8_t i = 0; i < m_nRates; i++) + { + if (rate == m_rates[i] && + m_rates[i] & 0x80) + { + return true; + } + } + return false; +} +bool +SupportedRates::IsSupportedRate (uint32_t bs) const +{ + uint8_t rate = bs / 500000; + for (uint8_t i = 0; i < m_nRates; i++) { + if (rate == m_rates[i]) { + return true; + } + } + return false; +} +uint8_t +SupportedRates::GetNRates (void) const +{ + return m_nRates; +} +uint32_t +SupportedRates::GetSerializedSize (void) const +{ + return m_nRates + 1; +} +Buffer::Iterator +SupportedRates::Write (Buffer::Iterator start) const +{ + start.WriteU8 (m_nRates); + start.Write (m_rates, m_nRates); + return start; +} +Buffer::Iterator +SupportedRates::Read (Buffer::Iterator start) +{ + m_nRates = start.ReadU8 (); + NS_ASSERT (m_nRates <= 8); + start.Read (m_rates, m_nRates); + return start; +} + +} // namespace ns3 diff --git a/src/devices/wifi/supported-rates.h b/src/devices/wifi/supported-rates.h new file mode 100644 index 000000000..e2880d689 --- /dev/null +++ b/src/devices/wifi/supported-rates.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2006 INRIA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#ifndef SUPPORTED_RATES_H +#define SUPPORTED_RATES_H + +#include +#include "ns3/buffer.h" + +namespace ns3 { + +class SupportedRates { +public: + SupportedRates (); + + void AddSupportedRate (uint32_t bs); + void SetBasicRate (uint32_t bs); + + bool IsSupportedRate (uint32_t bs) const; + bool IsBasicRate (uint32_t bs) const; + + uint8_t GetNRates (void) const; + + uint32_t GetSerializedSize (void) const; + Buffer::Iterator Write (Buffer::Iterator start) const; + Buffer::Iterator Read (Buffer::Iterator start); +private: + uint8_t m_nRates; + uint8_t m_rates[8]; +}; + +} // namespace ns3 + +#endif /* SUPPORTED_RATES_H */ diff --git a/src/devices/wifi/wscript b/src/devices/wifi/wscript index ef384fdfb..7a7a5e42a 100644 --- a/src/devices/wifi/wscript +++ b/src/devices/wifi/wscript @@ -24,6 +24,7 @@ def build(bld): 'dca-txop.cc', 'ideal-mac-stations.cc', 'mac-high-adhoc.cc', + 'supported-rates.cc', ] headers = bld.create_obj('ns3header') headers.source = [