Skip to content

Commit

Permalink
irs: comment and format configurator classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpugliese6 authored and GiovanniGrieco committed Apr 4, 2023
1 parent 9924263 commit e5f06db
Show file tree
Hide file tree
Showing 12 changed files with 491 additions and 353 deletions.
123 changes: 64 additions & 59 deletions src/irs/patch-configurator/defined-patch-configurator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,107 +17,112 @@
*/
#include "defined-patch-configurator.h"

#include <ns3/pointer.h>
#include <ns3/simulator.h>

#include <ns3/irs.h>
#include <ns3/model-configuration-matrix.h>
#include <ns3/model-configuration.h>
#include <ns3/pointer.h>
#include <ns3/simulator.h>

namespace ns3 {
namespace ns3
{

NS_LOG_COMPONENT_DEFINE ("DefinedPatchConfigurator");
NS_OBJECT_ENSURE_REGISTERED (DefinedPatchConfigurator);
NS_LOG_COMPONENT_DEFINE("DefinedPatchConfigurator");
NS_OBJECT_ENSURE_REGISTERED(DefinedPatchConfigurator);

TypeId
DefinedPatchConfigurator::GetTypeId ()
DefinedPatchConfigurator::GetTypeId()
{
static TypeId tid = TypeId ("ns3::DefinedPatchConfigurator")
.SetParent<PatchConfigurator> ()
.SetGroupName ("Irs")
.AddConstructor<DefinedPatchConfigurator> ()
.AddAttribute ("Periods",
"List of validity periods for each configuration",
DoubleVectorValue (),
MakeDoubleVectorAccessor (&DefinedPatchConfigurator::SetPeriods),
MakeDoubleVectorChecker ())
.AddAttribute ("Configurations",
"List of configurations to be applied to the Irs during the simulation",
ModelConfigurationMatrixValue (),
MakeModelConfigurationMatrixAccessor (&DefinedPatchConfigurator::m_configurations),
MakeModelConfigurationMatrixChecker ())
;
return tid;
static TypeId tid =
TypeId("ns3::DefinedPatchConfigurator")
.SetParent<PatchConfigurator>()
.SetGroupName("Irs")
.AddConstructor<DefinedPatchConfigurator>()
.AddAttribute("Periods",
"List of validity periods for each configuration",
DoubleVectorValue(),
MakeDoubleVectorAccessor(&DefinedPatchConfigurator::SetPeriods),
MakeDoubleVectorChecker())
.AddAttribute(
"Configurations",
"List of configurations to be applied to the Irs during the simulation",
ModelConfigurationMatrixValue(),
MakeModelConfigurationMatrixAccessor(&DefinedPatchConfigurator::m_configurations),
MakeModelConfigurationMatrixChecker());
return tid;
}

DefinedPatchConfigurator::DefinedPatchConfigurator ()
DefinedPatchConfigurator::DefinedPatchConfigurator()
{

}

DefinedPatchConfigurator::~DefinedPatchConfigurator ()
DefinedPatchConfigurator::~DefinedPatchConfigurator()
{

}

void
DefinedPatchConfigurator::DoDispose ()
DefinedPatchConfigurator::DoDispose()
{
NS_LOG_FUNCTION (this);
Object::DoDispose ();
NS_LOG_FUNCTION(this);
Object::DoDispose();
}

void
DefinedPatchConfigurator::DoInitialize (void)
DefinedPatchConfigurator::DoInitialize(void)
{
NS_LOG_FUNCTION (this);
Object::DoInitialize ();
SetLifeTimes();
ScheduleUpdates ();
NS_LOG_FUNCTION(this);
Object::DoInitialize();
SetLifeTimes();
ScheduleUpdates();
}

void
DefinedPatchConfigurator::ScheduleUpdates ()
DefinedPatchConfigurator::ScheduleUpdates()
{
//You need to run this method at the beginning of the simulation since Simulator::Schedule(...)
//accepts as parameter the delay from now
if (Simulator::Now ().GetSeconds () > 0.0)
NS_LOG_WARN ("ScheduleUpdates has been executed during the simulation, the timing could be shifted");

double nextupdate = 0;
for (uint32_t i = 0; i < m_periods.size(); i++)
// You need to run this method at the beginning of the simulation since Simulator::Schedule(...)
// accepts as parameter the delay from now
if (Simulator::Now().GetSeconds() > 0.0)
NS_LOG_WARN(
"ScheduleUpdates has been executed during the simulation, the timing could be shifted");

double nextupdate = 0;
for (uint32_t i = 0; i < m_periods.size(); i++)
{
Simulator::Schedule(Seconds(nextupdate), &DefinedPatchConfigurator::UpdateConfiguration, this, m_configurations.Get(i));
nextupdate += m_periods.at(i);
Simulator::Schedule(Seconds(nextupdate),
&DefinedPatchConfigurator::UpdateConfiguration,
this,
m_configurations.Get(i));
nextupdate += m_periods.at(i);
}

}

void
DefinedPatchConfigurator::SetPeriods (const DoubleVector &a)
DefinedPatchConfigurator::SetPeriods(const DoubleVector& periods)
{
for (auto c = a.Begin (); c != a.End (); c++)
for (auto c = periods.Begin(); c != periods.End(); c++)
{
m_periods.push_back (*c);
m_periods.push_back(*c);
}
}

void
DefinedPatchConfigurator::SetLifeTimes ()
DefinedPatchConfigurator::SetLifeTimes()
{
uint32_t periodsIdx = 0;
NS_ASSERT_MSG (m_periods.size () == m_configurations.GetN (), "The number of periods and configurations must be equal");
uint32_t periodsIdx = 0;
NS_ASSERT_MSG(m_periods.size() == m_configurations.GetN(),
"The number of periods and configurations must be equal");

for (auto confIt = m_configurations.MutableBegin (); confIt != m_configurations.MutableEnd (); confIt++)
for (auto confIt = m_configurations.MutableBegin(); confIt != m_configurations.MutableEnd();
confIt++)
{
for (auto patchIt = confIt->MutableBegin (); patchIt != confIt->MutableEnd (); patchIt++)
for (auto patchIt = confIt->MutableBegin(); patchIt != confIt->MutableEnd(); patchIt++)
{
auto lifeTimeValue = DoubleValue (m_periods.at (periodsIdx));
Ptr<AttributeValue> attr = MakeDoubleChecker<double> ()->CreateValidValue (lifeTimeValue);
patchIt->SetAttribute ("LifeTime", attr);
auto lifeTimeValue = DoubleValue(m_periods.at(periodsIdx));
Ptr<AttributeValue> attr = MakeDoubleChecker<double>()->CreateValidValue(lifeTimeValue);
patchIt->SetAttribute("LifeTime", attr);
}

periodsIdx++;
periodsIdx++;
}
}

} //namespace ns3
} // namespace ns3
61 changes: 43 additions & 18 deletions src/irs/patch-configurator/defined-patch-configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,62 @@
#ifndef DEFINED_PATCH_CONFIGURATOR_H
#define DEFINED_PATCH_CONFIGURATOR_H

#include <ns3/object.h>
#include <ns3/pointer.h>

#include <ns3/double-vector.h>
#include <ns3/model-configuration-matrix.h>
#include <ns3/object.h>
#include <ns3/patch-configurator.h>
#include <ns3/pointer.h>

namespace ns3 {
namespace ns3
{

/**
* \brief Defines the base object that updates the patch configuration of an Irs during the simulation with defined periods.
* \ingroup irs
* Defines an object which, aggregated to an Irs, updates its patch organisation during the
* simulation. The different configurations are installed for a duration equal to that defined in
* m_periods vector.
*/
class DefinedPatchConfigurator : public PatchConfigurator
{
public:
static TypeId GetTypeId (void);
public:
/**
* \brief Register this configurator as a type in ns-3 TypeId System.
*/
static TypeId GetTypeId(void);

DefinedPatchConfigurator ();
~DefinedPatchConfigurator ();
/**
* \brief Default constructor
*/
DefinedPatchConfigurator();
/**
* \brief Default destructor
*/
~DefinedPatchConfigurator();

void ScheduleUpdates ();
void SetPeriods(const DoubleVector &a);
void SetLifeTimes();
/**
* \brief When invoked, it schedules the patch organisation updates over time, following the
* periods defined in the m_periods vector
*/
void ScheduleUpdates();
/**
* \brief Set the m_periods vector
* \param periods a DoubleVector containing the periods
*/
void SetPeriods(const DoubleVector& periods);
/**
* \brief Set the LifeTime attribute for each patch of each configuration. It is used by
* each dinamic patch to schedule the update of nodes to be served
*/
void SetLifeTimes();

protected:
void DoDispose (void);
void DoInitialize (void);
protected:
void DoDispose(void);
void DoInitialize(void);

private:
ModelConfigurationMatrix m_configurations;
std::vector<double> m_periods;
private:
ModelConfigurationMatrix
m_configurations; ///< Matrix of configurations (i.e. a vector of vector of patches)
std::vector<double> m_periods; ///< Vector of periods for which each configuration is valid
};

} // namespace ns3
Expand Down
24 changes: 11 additions & 13 deletions src/irs/patch-configurator/patch-configurator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,28 @@
*/
#include "patch-configurator.h"

#include <ns3/pointer.h>

#include <ns3/irs.h>
#include <ns3/pointer.h>

namespace ns3 {
namespace ns3
{

NS_LOG_COMPONENT_DEFINE ("PatchConfigurator");
NS_OBJECT_ENSURE_REGISTERED (PatchConfigurator);
NS_LOG_COMPONENT_DEFINE("PatchConfigurator");
NS_OBJECT_ENSURE_REGISTERED(PatchConfigurator);

PatchConfigurator::PatchConfigurator ()
PatchConfigurator::PatchConfigurator()
{

}

PatchConfigurator::~PatchConfigurator ()
PatchConfigurator::~PatchConfigurator()
{

}

void
PatchConfigurator::UpdateConfiguration (const ModelConfigurationVector& p)
PatchConfigurator::UpdateConfiguration(const ModelConfigurationVector& c)
{
Ptr<Irs> aggregatedIrs = GetObject<Irs> ();
aggregatedIrs->SetPatchVector (p);
Ptr<Irs> aggregatedIrs = GetObject<Irs>();
aggregatedIrs->SetPatchVector(c);
}

} //namespace ns3
} // namespace ns3
44 changes: 29 additions & 15 deletions src/irs/patch-configurator/patch-configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,42 @@
#ifndef PATCH_CONFIGURATOR_H
#define PATCH_CONFIGURATOR_H

#include <ns3/object.h>

#include <ns3/model-configuration-vector.h>
#include <ns3/object.h>

namespace ns3 {
namespace ns3
{

/**
* \brief Defines the base object that updates the patch configuration of an Irs during the simulation
* \ingroup irs
* Defines the base object for Patch Configurators. Such a configurator updates the patch
* organisation of an Irs during the simulation
*/
class PatchConfigurator : public Object
{
public:

PatchConfigurator ();
~PatchConfigurator ();

virtual void ScheduleUpdates () = 0;
void UpdateConfiguration (const ModelConfigurationVector& p);

protected:
virtual void DoDispose (void) = 0;
virtual void DoInitialize (void) = 0;
public:
/**
* \brief Default constructor
*/
PatchConfigurator();
/**
* \brief Default destructor
*/
~PatchConfigurator();

/**
* \brief This method schedule patch updates over time according to a certain logic. It must be
* implemented by child classes
*/
virtual void ScheduleUpdates() = 0;
/**
* \brief It sets a new patch configuration to the Irs to which the configurator is aggregated
*/
void UpdateConfiguration(const ModelConfigurationVector& c);

protected:
virtual void DoDispose(void) = 0;
virtual void DoInitialize(void) = 0;
};

} // namespace ns3
Expand Down
Loading

0 comments on commit e5f06db

Please sign in to comment.