A Discrete-Event Network Simulator
API
spectrum-model.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
3/*
4 * Copyright (c) 2009 CTTC
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation;
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Nicola Baldo <nbaldo@cttc.es>
20 */
21
22#include <cmath>
23#include <cstddef>
24#include <ns3/spectrum-model.h>
25#include <ns3/log.h>
26#include <ns3/assert.h>
27
28
29
30namespace ns3 {
31
32NS_LOG_COMPONENT_DEFINE ("SpectrumModel");
33
34bool operator== (const SpectrumModel& lhs, const SpectrumModel& rhs)
35{
36 return (lhs.m_uid == rhs.m_uid);
37}
38
40
41SpectrumModel::SpectrumModel (const std::vector<double>& centerFreqs)
42{
43 NS_ASSERT (centerFreqs.size () > 1);
44 m_uid = ++m_uidCount;
45
46 for (std::vector<double>::const_iterator it = centerFreqs.begin ();
47 it != centerFreqs.end ();
48 ++it)
49 {
50 BandInfo e;
51 e.fc = *it;
52 if (it == centerFreqs.begin ())
53 {
54 double delta = ((*(it + 1)) - (*it)) / 2;
55 e.fl = *it - delta;
56 e.fh = *it + delta;
57 }
58 else if (it == centerFreqs.end () - 1 )
59 {
60 double delta = ((*it) - (*(it - 1))) / 2;
61 e.fl = *it - delta;
62 e.fh = *it + delta;
63 }
64 else
65 {
66 e.fl = ((*it) + (*(it - 1))) / 2;
67 e.fh = ((*(it + 1)) + (*it)) / 2;
68 }
69 m_bands.push_back (e);
70 }
71}
72
74{
75 m_uid = ++m_uidCount;
76 NS_LOG_INFO ("creating new SpectrumModel, m_uid=" << m_uid);
77 m_bands = bands;
78}
79
81 : m_bands (std::move (bands))
82{
83 m_uid = ++m_uidCount;
84 NS_LOG_INFO ("creating new SpectrumModel, m_uid=" << m_uid);
85}
86
87Bands::const_iterator
89{
90 return m_bands.begin ();
91}
92
93Bands::const_iterator
95{
96 return m_bands.end ();
97}
98
99size_t
101{
102 return m_bands.size ();
103}
104
107{
108 return m_uid;
109}
110
111bool
113{
114 for (Bands::const_iterator myIt = Begin ();
115 myIt != End ();
116 ++myIt)
117 {
118 for (Bands::const_iterator otherIt = other.Begin ();
119 otherIt != other.End ();
120 ++otherIt)
121 {
122 if (std::max (myIt->fl, otherIt->fl) < std::min (myIt->fh, otherIt->fh))
123 {
124 return false;
125 }
126 }
127 }
128 return true;
129}
130
131
132} // namespace ns3
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
Set of frequency values implementing the domain of the functions in the Function Space defined by Spe...
bool IsOrthogonal(const SpectrumModel &other) const
Check if another SpectrumModels has bands orthogonal to our bands.
static SpectrumModelUid_t m_uidCount
counter to assign m_uids
SpectrumModelUid_t m_uid
unique id for a given set of frequencies
SpectrumModel(const std::vector< double > &centerFreqs)
This constructs a SpectrumModel based on a given set of frequencies, which is assumed to be sorted by...
Bands::const_iterator End() const
Const Iterator to the model Bands container end.
size_t GetNumBands() const
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
SpectrumModelUid_t GetUid() const
Bands m_bands
Actual definition of frequency bands within this SpectrumModel.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:158
std::vector< BandInfo > Bands
Container of BandInfo.
uint32_t SpectrumModelUid_t
Uid for SpectrumModels.
STL namespace.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband