A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
device-energy-model.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
7 */
8
9#ifndef DEVICE_ENERGY_MODEL_H
10#define DEVICE_ENERGY_MODEL_H
11
12#include "ns3/node.h"
13#include "ns3/object.h"
14#include "ns3/ptr.h"
15#include "ns3/type-id.h"
16
17namespace ns3
18{
19namespace energy
20{
21
22class EnergySource;
23
24/**
25 * \ingroup energy
26 * \brief Base class for device energy models.
27 *
28 * A device energy model should represent the energy consumption behavior of a
29 * specific device. It will update remaining energy stored in the EnergySource
30 * object installed on node. When energy is depleted, each DeviceEnergyModel
31 * object installed on the same node will be informed by the EnergySource.
32 *
33 */
35{
36 public:
37 /**
38 * Callback type for ChangeState function. Devices uses this state to notify
39 * DeviceEnergyModel of a state change.
40 */
42
43 public:
44 /**
45 * \brief Get the type ID.
46 * \return The object TypeId.
47 */
48 static TypeId GetTypeId();
50 ~DeviceEnergyModel() override;
51
52 /**
53 * \param source Pointer to energy source installed on node.
54 *
55 * This function sets the pointer to energy source installed on node. Should
56 * be called only by DeviceEnergyModel helper classes.
57 */
58 virtual void SetEnergySource(Ptr<EnergySource> source) = 0;
59
60 /**
61 * \returns Total energy consumption of the device.
62 *
63 * DeviceEnergyModel records its own energy consumption during simulation.
64 */
65 virtual double GetTotalEnergyConsumption() const = 0;
66
67 /**
68 * \param newState New state the device is in.
69 *
70 * DeviceEnergyModel is a state based model. This function is implemented by
71 * all child of DeviceEnergyModel to change the model's state. States are to
72 * be defined by each child using an enum (int).
73 */
74 virtual void ChangeState(int newState) = 0;
75
76 /**
77 * \returns Current draw of the device, in Ampere.
78 *
79 * This function returns the current draw at the device in its current state.
80 * This function is called from the EnergySource to obtain the total current
81 * draw at any given time during simulation.
82 */
83 double GetCurrentA() const;
84
85 /**
86 * This function is called by the EnergySource object when energy stored in
87 * the energy source is depleted. Should be implemented by child classes.
88 */
89 virtual void HandleEnergyDepletion() = 0;
90
91 /**
92 * This function is called by the EnergySource object when energy stored in
93 * the energy source is recharged. Should be implemented by child classes.
94 */
95 virtual void HandleEnergyRecharged() = 0;
96
97 /**
98 * This function is called by the EnergySource object when energy stored in
99 * the energy source is changed. Should be implemented by child classes.
100 */
101 virtual void HandleEnergyChanged() = 0;
102
103 private:
104 /**
105 * \returns 0.0 as the current value, in Ampere.
106 *
107 * Child class does not have to implement this method if current draw for its
108 * states are not know. This default method will always return 0.0A. For the
109 * devices who does know the current draw of its states, this method must be
110 * overwritten.
111 */
112 virtual double DoGetCurrentA() const;
113};
114
115} // namespace energy
116} // namespace ns3
117
118#endif /* DEVICE_ENERGY_MODEL_H */
Callback template class.
Definition callback.h:422
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
Base class for device energy models.
virtual void HandleEnergyRecharged()=0
This function is called by the EnergySource object when energy stored in the energy source is recharg...
virtual void ChangeState(int newState)=0
static TypeId GetTypeId()
Get the type ID.
virtual void HandleEnergyChanged()=0
This function is called by the EnergySource object when energy stored in the energy source is changed...
virtual void HandleEnergyDepletion()=0
This function is called by the EnergySource object when energy stored in the energy source is deplete...
virtual void SetEnergySource(Ptr< EnergySource > source)=0
Callback< void, int > ChangeStateCallback
Callback type for ChangeState function.
virtual double GetTotalEnergyConsumption() const =0
virtual double DoGetCurrentA() const
Every class exported by the ns3 library is enclosed in the ns3 namespace.