INET Framework for OMNeT++/OMNEST
inet::power::SimpleEpEnergyManagement Class Reference

#include <SimpleEpEnergyManagement.h>

Inheritance diagram for inet::power::SimpleEpEnergyManagement:
inet::power::IEpEnergyManagement inet::power::IEnergyManagement

Public Member Functions

virtual ~SimpleEpEnergyManagement ()
 
virtual IEnergyStoragegetEnergyStorage () const override
 Returns the energy storage that is managed by this energy management. More...
 
virtual J getEstimatedEnergyCapacity () const override
 Returns the estimated energy capacity in the range [0, +infinity). More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double value, cObject *details) override
 
- Public Member Functions inherited from inet::power::IEnergyManagement
virtual ~IEnergyManagement ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void executeNodeOperation (J estimatedEnergyCapacity)
 
virtual void scheduleLifecycleOperationTimer ()
 

Protected Attributes

J nodeShutdownCapacity = J(NaN)
 
J nodeStartCapacity = J(NaN)
 
IEpEnergyStorageenergyStorage = nullptr
 
LifecycleControllerlifecycleController = nullptr
 
cModule * networkNode = nullptr
 
NodeStatusnodeStatus = nullptr
 
cMessage * lifecycleOperationTimer = nullptr
 

Constructor & Destructor Documentation

inet::power::SimpleEpEnergyManagement::~SimpleEpEnergyManagement ( )
virtual
29 {
30  cancelAndDelete(lifecycleOperationTimer);
31 }
cMessage * lifecycleOperationTimer
Definition: SimpleEpEnergyManagement.h:42

Member Function Documentation

void inet::power::SimpleEpEnergyManagement::executeNodeOperation ( J  estimatedEnergyCapacity)
protectedvirtual

Referenced by handleMessage(), and receiveSignal().

64 {
65  if (!std::isnan(nodeShutdownCapacity.get()) && estimatedEnergyCapacity <= nodeShutdownCapacity && nodeStatus->getState() == NodeStatus::UP) {
66  EV_WARN << "Capacity reached node shutdown threshold" << endl;
68  NodeShutdownOperation *operation = new NodeShutdownOperation();
69  operation->initialize(networkNode, params);
71  }
72  else if (!std::isnan(nodeStartCapacity.get()) && estimatedEnergyCapacity >= nodeStartCapacity && nodeStatus->getState() == NodeStatus::DOWN) {
73  EV_INFO << "Capacity reached node start threshold" << endl;
75  NodeStartOperation *operation = new NodeStartOperation();
76  operation->initialize(networkNode, params);
78  }
79 }
const value_type & get() const
Definition: Units.h:89
NodeStatus * nodeStatus
Definition: SimpleEpEnergyManagement.h:41
std::map< std::string, std::string > StringMap
Definition: LifecycleOperation.h:37
cModule * networkNode
Definition: SimpleEpEnergyManagement.h:40
J nodeShutdownCapacity
Definition: SimpleEpEnergyManagement.h:34
J nodeStartCapacity
Definition: SimpleEpEnergyManagement.h:35
Definition: NodeStatus.h:40
LifecycleController * lifecycleController
Definition: SimpleEpEnergyManagement.h:39
virtual bool initiateOperation(LifecycleOperation *operation, IDoneCallback *completionCallback=nullptr)
Initiate an operation.
Definition: LifecycleController.cc:87
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual IEnergyStorage* inet::power::SimpleEpEnergyManagement::getEnergyStorage ( ) const
inlineoverridevirtual

Returns the energy storage that is managed by this energy management.

This function never returns nullptr.

Implements inet::power::IEnergyManagement.

54 { return energyStorage; }
IEpEnergyStorage * energyStorage
Definition: SimpleEpEnergyManagement.h:36
J inet::power::SimpleEpEnergyManagement::getEstimatedEnergyCapacity ( ) const
overridevirtual

Returns the estimated energy capacity in the range [0, +infinity).

It specifies the amount of energy that the energy storage contains at the moment according to the estimation of the management.

Implements inet::power::IEpEnergyManagement.

Referenced by handleMessage(), receiveSignal(), and scheduleLifecycleOperationTimer().

106 {
107  // NOTE: cheat with estimation and return the actual energy capacity known by the energy storage
109 }
virtual J getResidualEnergyCapacity() const =0
Returns the residual energy capacity in the range [0, nominalCapacity].
IEpEnergyStorage * energyStorage
Definition: SimpleEpEnergyManagement.h:36
void inet::power::SimpleEpEnergyManagement::handleMessage ( cMessage *  message)
overrideprotectedvirtual
54 {
55  if (message == lifecycleOperationTimer) {
58  }
59  else
60  throw cRuntimeError("Unknown message");
61 }
virtual void executeNodeOperation(J estimatedEnergyCapacity)
Definition: SimpleEpEnergyManagement.cc:63
virtual J getEstimatedEnergyCapacity() const override
Returns the estimated energy capacity in the range [0, +infinity).
Definition: SimpleEpEnergyManagement.cc:105
cMessage * lifecycleOperationTimer
Definition: SimpleEpEnergyManagement.h:42
virtual void scheduleLifecycleOperationTimer()
Definition: SimpleEpEnergyManagement.cc:81
void inet::power::SimpleEpEnergyManagement::initialize ( int  stage)
overrideprotectedvirtual
34 {
35  if (stage == INITSTAGE_LOCAL) {
36  nodeShutdownCapacity = J(par("nodeShutdownCapacity"));
37  nodeStartCapacity = J(par("nodeStartCapacity"));
39  energyStorage = check_and_cast<IEpEnergyStorage *>(networkNode->getSubmodule("energyStorage"));
40  auto energyStorageModule = check_and_cast<cModule *>(energyStorage);
41  energyStorageModule->subscribe(IEpEnergySource::powerConsumptionChangedSignal, this);
42  energyStorageModule->subscribe(IEpEnergySink::powerGenerationChangedSignal, this);
43  nodeStatus = dynamic_cast<NodeStatus *>(networkNode->getSubmodule("status"));
44  if (!nodeStatus)
45  throw cRuntimeError("Cannot find node status");
46  lifecycleController = dynamic_cast<LifecycleController *>(getModuleByPath("lifecycleController"));
48  throw cRuntimeError("Cannot find lifecycle controller");
49  lifecycleOperationTimer = new cMessage("lifecycleOperation");
50  }
51 }
NodeStatus * nodeStatus
Definition: SimpleEpEnergyManagement.h:41
static simsignal_t powerConsumptionChangedSignal
The signal that is used to publish power consumption changes.
Definition: IEpEnergySource.h:43
cModule * networkNode
Definition: SimpleEpEnergyManagement.h:40
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
J nodeShutdownCapacity
Definition: SimpleEpEnergyManagement.h:34
cMessage * lifecycleOperationTimer
Definition: SimpleEpEnergyManagement.h:42
IEpEnergyStorage * energyStorage
Definition: SimpleEpEnergyManagement.h:36
static simsignal_t powerGenerationChangedSignal
The signal that is used to publish power generation changes.
Definition: IEpEnergySink.h:40
compose< N, m > J
Definition: Units.h:769
J nodeStartCapacity
Definition: SimpleEpEnergyManagement.h:35
LifecycleController * lifecycleController
Definition: SimpleEpEnergyManagement.h:39
void inet::power::SimpleEpEnergyManagement::receiveSignal ( cComponent *  source,
simsignal_t  signal,
double  value,
cObject *  details 
)
overridevirtual
112 {
113  Enter_Method("receiveSignal");
117  }
118 }
virtual void executeNodeOperation(J estimatedEnergyCapacity)
Definition: SimpleEpEnergyManagement.cc:63
static simsignal_t powerConsumptionChangedSignal
The signal that is used to publish power consumption changes.
Definition: IEpEnergySource.h:43
virtual J getEstimatedEnergyCapacity() const override
Returns the estimated energy capacity in the range [0, +infinity).
Definition: SimpleEpEnergyManagement.cc:105
static simsignal_t powerGenerationChangedSignal
The signal that is used to publish power generation changes.
Definition: IEpEnergySink.h:40
virtual void scheduleLifecycleOperationTimer()
Definition: SimpleEpEnergyManagement.cc:81
void inet::power::SimpleEpEnergyManagement::scheduleLifecycleOperationTimer ( )
protectedvirtual

Referenced by handleMessage(), and receiveSignal().

82 {
83  J targetCapacity = J(NaN);
84  J estimatedResidualCapacity = getEstimatedEnergyCapacity();
86  if (totalPower > W(0)) {
87  // override target capacity if start is needed
88  if (!std::isnan(nodeStartCapacity.get()) && nodeStatus->getState() == NodeStatus::DOWN && estimatedResidualCapacity < nodeStartCapacity)
89  targetCapacity = nodeStartCapacity;
90  }
91  else if (totalPower < W(0)) {
92  // override target capacity if shutdown is needed
93  if (!std::isnan(nodeShutdownCapacity.get()) && nodeStatus->getState() == NodeStatus::UP && estimatedResidualCapacity > nodeShutdownCapacity)
94  targetCapacity = nodeShutdownCapacity;
95  }
96  // enforce target capacity to be in range
97  simtime_t remainingTime = unit((targetCapacity - estimatedResidualCapacity) / totalPower / s(1)).get();
98  if (lifecycleOperationTimer->isScheduled())
99  cancelEvent(lifecycleOperationTimer);
100  // don't schedule if there's no progress
101  if (remainingTime > 0)
102  scheduleAt(simTime() + remainingTime, lifecycleOperationTimer);
103 }
const value_type & get() const
Definition: Units.h:89
NodeStatus * nodeStatus
Definition: SimpleEpEnergyManagement.h:41
compose< J, pow< s,-1 > > W
Definition: Units.h:770
#define NaN
Definition: INETMath.h:103
J nodeShutdownCapacity
Definition: SimpleEpEnergyManagement.h:34
virtual W getTotalPowerGeneration() const =0
Returns the total power generation in the range [0, +infinity).
virtual J getEstimatedEnergyCapacity() const override
Returns the estimated energy capacity in the range [0, +infinity).
Definition: SimpleEpEnergyManagement.cc:105
pow< internal::none, 0 > unit
Definition: Units.h:60
cMessage * lifecycleOperationTimer
Definition: SimpleEpEnergyManagement.h:42
value< double, units::s > s
Definition: Units.h:1049
IEpEnergyStorage * energyStorage
Definition: SimpleEpEnergyManagement.h:36
compose< N, m > J
Definition: Units.h:769
J nodeStartCapacity
Definition: SimpleEpEnergyManagement.h:35
Definition: NodeStatus.h:40
virtual W getTotalPowerConsumption() const =0
Returns the total power consumption in the range [0, +infinity).
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40

Member Data Documentation

IEpEnergyStorage* inet::power::SimpleEpEnergyManagement::energyStorage = nullptr
protected
LifecycleController* inet::power::SimpleEpEnergyManagement::lifecycleController = nullptr
protected

Referenced by executeNodeOperation(), and initialize().

cMessage* inet::power::SimpleEpEnergyManagement::lifecycleOperationTimer = nullptr
protected
cModule* inet::power::SimpleEpEnergyManagement::networkNode = nullptr
protected

Referenced by executeNodeOperation(), and initialize().

J inet::power::SimpleEpEnergyManagement::nodeShutdownCapacity = J(NaN)
protected
J inet::power::SimpleEpEnergyManagement::nodeStartCapacity = J(NaN)
protected
NodeStatus* inet::power::SimpleEpEnergyManagement::nodeStatus = nullptr
protected

The documentation for this class was generated from the following files: