5#include "cc-bwp-helper.h"
8#include <ns3/spectrum-channel.h>
16NS_LOG_COMPONENT_DEFINE(
"CcBwpHelper");
21 NS_LOG_FUNCTION(
this);
28 m_bwp.emplace_back(std::move(bwp));
31 while (i <
m_bwp.size() - 1)
33 auto& bwp =
m_bwp.at(i);
34 auto& nextBwp =
m_bwp.at(i + 1);
35 if (bwp->m_higherFrequency > nextBwp->m_lowerFrequency)
37 NS_LOG_ERROR(
"BWP ID "
38 << +bwp->m_bwpId <<
" has higher freq = " << bwp->m_higherFrequency / 1e6
39 <<
"MHz while BWP ID " << +nextBwp->m_bwpId
40 <<
" has lower freq = " << nextBwp->m_lowerFrequency / 1e6 <<
" MHz.");
46 for (
auto& bwp :
m_bwp)
48 NS_LOG_INFO(
"Create BWP with bwpId: "
49 << +bwp->m_bwpId <<
" lower: " << bwp->m_lowerFrequency / 1e6
50 <<
" with central freq: " << bwp->m_centralFrequency / 1e6
51 <<
" higher: " << bwp->m_higherFrequency / 1e6
52 <<
" BW: " << bwp->m_channelBandwidth / 1e6 <<
" MHz");
61 NS_LOG_FUNCTION(
this);
67 m_cc.emplace_back(std::move(cc));
70 while (i <
m_cc.size() - 1)
72 auto& cc =
m_cc.at(i);
73 auto& nextCc =
m_cc.at(i + 1);
74 if (cc->m_higherFrequency > nextCc->m_lowerFrequency)
76 NS_LOG_WARN(
"Cc at " << i <<
" has higher freq " << cc->m_higherFrequency / 1e6
77 <<
" while Cc at " << i + 1 <<
" has freq at "
86 NS_LOG_INFO(
"Create CC with ccId: "
87 << +cc->m_ccId <<
" lower: " << cc->m_lowerFrequency / 1e6
88 <<
" with central freq: " << cc->m_centralFrequency / 1e6
89 <<
" higher: " << cc->m_higherFrequency / 1e6
90 <<
" BW: " << cc->m_channelBandwidth / 1e6 <<
" MHz");
99 return m_cc.at(ccId)->m_bwp.at(bwpId);
117 std::vector<std::reference_wrapper<BandwidthPartInfoPtr>> ret;
119 for (
const auto& cc :
m_cc)
121 for (
auto& bwp : cc->m_bwp)
123 ret.emplace_back(bwp);
135CcBwpCreator::InitializeCc(std::unique_ptr<ComponentCarrierInfo>& cc,
141 NS_LOG_FUNCTION(
this);
142 cc->m_centralFrequency = lowerFreq + ccPosition * ccBandwidth + ccBandwidth / 2;
143 cc->m_lowerFrequency = lowerFreq + ccPosition * ccBandwidth;
144 cc->m_higherFrequency = lowerFreq + (ccPosition + 1) * ccBandwidth - 1;
145 cc->m_channelBandwidth = ccBandwidth;
147 NS_LOG_INFO(
"Initialize the op band "
148 << +ccPosition <<
"st (or nd) CC of BW " << ccBandwidth / 1e6 <<
" MHz "
149 <<
" from " << lowerFreq / 1e6 <<
"MHz, resulting in: " << *cc);
159 NS_LOG_FUNCTION(
this);
160 bwp->m_centralFrequency = lowerFreq + bwpPosition * bwOfBwp + bwOfBwp / 2;
161 bwp->m_lowerFrequency = lowerFreq + bwpPosition * bwOfBwp;
162 bwp->m_higherFrequency = lowerFreq + (bwpPosition + 1) * bwOfBwp - 1;
163 bwp->m_channelBandwidth = bwOfBwp;
164 bwp->m_bwpId = bwpId;
165 NS_LOG_INFO(
"Initialize the " << +bwpPosition <<
"st (or nd) BWP of BW " << bwOfBwp / 1e6
166 <<
" MHz, from " << lowerFreq / 1e6
167 <<
"MHz, resulting in: " << *bwp);
170std::unique_ptr<ComponentCarrierInfo>
171CcBwpCreator::CreateCc(
double ccBandwidth,
178 std::unique_ptr<ComponentCarrierInfo> cc(
new ComponentCarrierInfo());
179 InitializeCc(cc, ccBandwidth, lowerFreq, ccPosition, ccId);
181 double bwpBandwidth = ccBandwidth / bwpNumber;
183 for (uint8_t i = 0; i < bwpNumber; ++i)
185 std::unique_ptr<BandwidthPartInfo> bwp(
new BandwidthPartInfo());
186 InitializeBwp(bwp, bwpBandwidth, cc->m_lowerFrequency, i, m_bandwidthPartCounter++);
187 bool ret = cc->AddBwp(std::move(bwp));
198 NS_LOG_FUNCTION(
this);
199 NS_LOG_INFO(
"Creating an op band formed by " << +conf.
m_numCc <<
" contiguous CC"
205 band.
m_bandId = m_operationBandCounter++;
211 NS_LOG_INFO(
"Resulting OpBand: " << band);
213 uint32_t maxCcBandwidth = 198e6;
217 maxCcBandwidth = 396e6;
220 double ccBandwidth = std::min(
static_cast<double>(maxCcBandwidth),
223 for (uint8_t ccPosition = 0; ccPosition < conf.
m_numCc; ++ccPosition)
225 bool ret = band.
AddCc(CreateCc(ccBandwidth,
228 m_componentCarrierCounter++,
239 const std::vector<SimpleOperationBandConf>& configuration)
242 band.
m_bandId = m_operationBandCounter++;
244 for (
const auto& conf : configuration)
246 NS_ASSERT(conf.m_numBwp == 1);
247 band.
AddCc(CreateCc(conf.m_channelBandwidth,
250 m_componentCarrierCounter++,
259 const std::vector<std::reference_wrapper<OperationBandInfo>>& operationBands)
263 for (
const auto& operationBand : operationBands)
265 auto v = operationBand.get().
GetBwps();
266 ret.insert(ret.end(), std::make_move_iterator(v.begin()), std::make_move_iterator(v.end()));
274 const std::string& filename)
276 std::ofstream outFile;
277 outFile.open(filename.c_str(), std::ios_base::out | std::ios_base::trunc);
278 if (!outFile.is_open())
280 NS_LOG_ERROR(
"Can't open file " << filename);
289 double minFreq = 100e9;
291 for (
const auto& band : bands)
293 if (band->m_lowerFrequency < minFreq)
295 minFreq = band->m_lowerFrequency;
297 if (band->m_higherFrequency > maxFreq)
299 maxFreq = band->m_higherFrequency;
303 outFile <<
"set term eps" << std::endl;
304 outFile <<
"set output \"" << filename <<
".eps\"" << std::endl;
305 outFile <<
"set grid" << std::endl;
307 outFile <<
"set xrange [";
308 outFile << minFreq * 1e-6 - 1;
310 outFile << maxFreq * 1e-6 + 1;
312 outFile << std::endl;
314 outFile <<
"set yrange [1:100]" << std::endl;
315 outFile <<
"set xlabel \"f [MHz]\"" << std::endl;
318 for (
const auto& band : bands)
320 std::string label =
"n";
321 uint16_t bandId =
static_cast<uint16_t
>(band->m_bandId);
322 label += std::to_string(bandId);
323 PlotFrequencyBand(outFile,
325 band->m_lowerFrequency * 1e-6,
326 band->m_higherFrequency * 1e-6,
331 for (
auto& cc : band->m_cc)
333 uint16_t ccId =
static_cast<uint16_t
>(cc->m_ccId);
334 label =
"CC" + std::to_string(ccId);
335 PlotFrequencyBand(outFile,
337 cc->m_lowerFrequency * 1e-6,
338 cc->m_higherFrequency * 1e-6,
343 for (
auto& bwp : cc->m_bwp)
345 uint16_t bwpId =
static_cast<uint16_t
>(bwp->m_bwpId);
346 label =
"BWP" + std::to_string(bwpId);
347 PlotFrequencyBand(outFile,
349 bwp->m_lowerFrequency * 1e-6,
350 bwp->m_higherFrequency * 1e-6,
359 outFile <<
"unset key" << std::endl;
360 outFile <<
"plot -x" << std::endl;
365 const std::string& filename)
367 std::ofstream outFile;
368 outFile.open(filename.c_str(), std::ios_base::out | std::ios_base::trunc);
369 if (!outFile.is_open())
371 NS_LOG_ERROR(
"Can't open file " << filename);
378 double minFreq = 100e9;
380 for (
const auto& band : bands)
382 if (band->m_lowerFrequency < minFreq)
384 minFreq = band->m_lowerFrequency;
386 if (band->m_higherFrequency > maxFreq)
388 maxFreq = band->m_higherFrequency;
392 outFile <<
"set term eps" << std::endl;
393 outFile <<
"set output \"" << filename <<
".eps\"" << std::endl;
394 outFile <<
"set grid" << std::endl;
396 outFile <<
"set xrange [";
397 outFile << minFreq * 1e-6 - 1;
399 outFile << maxFreq * 1e-6 + 1;
401 outFile << std::endl;
403 outFile <<
"set yrange [1:100]" << std::endl;
404 outFile <<
"set xlabel \"f [MHz]\"" << std::endl;
407 for (
const auto& band : bands)
409 std::string label =
"n";
410 uint16_t bandId =
static_cast<uint16_t
>(band->m_bandId);
411 label += std::to_string(bandId);
412 PlotFrequencyBand(outFile,
414 band->m_lowerFrequency * 1e-6,
415 band->m_higherFrequency * 1e-6,
420 for (
auto& cc : band->m_cc)
422 uint16_t ccId =
static_cast<uint16_t
>(cc->m_ccId);
423 label =
"CC" + std::to_string(ccId);
424 PlotFrequencyBand(outFile,
426 cc->m_lowerFrequency * 1e-6,
427 cc->m_higherFrequency * 1e-6,
435 outFile <<
"unset key" << std::endl;
436 outFile <<
"plot -x" << std::endl;
440CcBwpCreator::PlotFrequencyBand(std::ofstream& outFile,
446 const std::string& label)
448 outFile <<
"set object " << index <<
" rect from " << xmin <<
"," << ymin <<
" to " << xmax
449 <<
"," << ymax <<
" front fs empty " << std::endl;
451 outFile <<
"LABEL" << index <<
" = \"" << label <<
"\"" << std::endl;
453 outFile <<
"set label " << index <<
" at " << xmin <<
"," << (ymin + ymax) / 2 <<
" LABEL"
454 << index << std::endl;
458operator<<(std::ostream& os,
const ComponentCarrierInfo& item)
460 os <<
"id: " << +item.m_ccId <<
" lower freq " << item.m_lowerFrequency / 1e6
461 <<
" MHz central freq " << item.m_centralFrequency / 1e6 <<
" MHz higher freq "
462 << item.m_higherFrequency / 1e6 <<
" MHz bw " << item.m_channelBandwidth / 1e6 <<
" MHz."
464 for (
const auto& bwp : item.m_bwp)
466 os <<
"\t\t" << *bwp << std::endl;
472operator<<(std::ostream& os,
const OperationBandInfo& item)
474 os <<
"id: " << +item.m_bandId <<
" lower freq " << item.m_lowerFrequency / 1e6
475 <<
" MHz central freq " << item.m_centralFrequency / 1e6 <<
" MHz higher freq "
476 << item.m_higherFrequency / 1e6 <<
" MHz bw " << item.m_channelBandwidth / 1e6 <<
" MHz."
478 for (
const auto& cc : item.m_cc)
480 os <<
"\t" << *cc << std::endl;
486operator<<(std::ostream& os,
const BandwidthPartInfo& item)
488 os <<
"id: " << +item.m_bwpId <<
" lower freq " << item.m_lowerFrequency / 1e6
489 <<
" MHz central freq " << item.m_centralFrequency / 1e6 <<
" MHz higher freq "
490 << item.m_higherFrequency / 1e6 <<
" MHz bw " << item.m_channelBandwidth / 1e6 <<
" MHz.";
OperationBandInfo CreateOperationBandContiguousCc(const SimpleOperationBandConf &conf)
Create an operation band with the CC specified.
static BandwidthPartInfoPtrVector GetAllBwps(const std::vector< std::reference_wrapper< OperationBandInfo > > &operationBands)
Get all the BWP pointers from the specified vector of operation bands.
static void PlotLteCaConfiguration(const std::vector< OperationBandInfo * > &bands, const std::string &filename)
Plots the CA/BWP configuration using GNUPLOT. There must be a valid configuration.
static void PlotNrCaBwpConfiguration(const std::vector< OperationBandInfo * > &bands, const std::string &filename)
Plots the CA/BWP configuration using GNUPLOT. There must be a valid configuration.
OperationBandInfo CreateOperationBandNonContiguousCc(const std::vector< SimpleOperationBandConf > &configuration)
Creates an operation band with non-contiguous CC.
std::unique_ptr< BandwidthPartInfo > BandwidthPartInfoPtr
unique_ptr of BandwidthPartInfo
std::vector< std::reference_wrapper< BandwidthPartInfoPtr > > BandwidthPartInfoPtrVector
vector of unique_ptr of BandwidthPartInfo
std::unique_ptr< ComponentCarrierInfo > ComponentCarrierInfoPtr
unique_ptr of ComponentCarrierInfo
Ptr< SpectrumChannel > GetChannel() const
Get the spectrum channel associated with the BWP.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the spectrum channel for the BWP.
Minimum configuration requirements for a OperationBand.
uint8_t m_numCc
Number of CC in this OpBand.
uint8_t m_numBwp
Number of BWP per CC.
double m_centralFrequency
Central Freq.
double m_channelBandwidth
Total Bandwidth of the operation band.
double m_higherFrequency
BWP higher frequency.
bool AddBwp(BandwidthPartInfoPtr &&bwp)
Adds a bandwidth part configuration to the carrier.
double m_lowerFrequency
BWP lower frequency.
std::vector< BandwidthPartInfoPtr > m_bwp
Space for BWP.
Operation band information structure.
double m_channelBandwidth
Operation band bandwidth.
BandwidthPartInfoPtr & GetBwpAt(uint32_t ccId, uint32_t bwpId) const
Get the BWP at the cc/bwp specified.
std::vector< ComponentCarrierInfoPtr > m_cc
Operation band component carriers.
BandwidthPartInfoPtrVector GetBwps() const
Get the list of all the BWPs to pass to NrHelper.
bool AddCc(ComponentCarrierInfoPtr &&cc)
Adds the component carrier definition given as an input reference to the current operation band confi...
double m_lowerFrequency
Operation band lower frequency.
double m_centralFrequency
Operation band central frequency.
double m_higherFrequency
Operation band higher frequency.
uint8_t m_bandId
Operation band id.