Energy model

945 views
Skip to first unread message

Antonio Junior

unread,
Apr 19, 2010, 10:25:08 AM4/19/10
to ns-3-...@googlegroups.com
Dear NS-3 users,

Does anybody implemented or implementing a energy model (such as in
NS-2) to NS-3? Mainly to measure the energy consumption and using
energy-metric for routing at layer 3.

Best regards,

--
Antonio Júnior, PhD Student (MAP-i)
IAN - Internet Architectures and Networking
UTM - Telecommunications and Multimedia Unit
INESC Porto -- Porto University
http://ian.inescporto.pt/

--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

hrouz

unread,
Apr 19, 2010, 11:39:05 AM4/19/10
to ns-3-users
Hiii antonio yes i found an exemple of an energy model (energy-
model.cc energy-model.h and the executable program)
this is what i found below , but my problem is what to do or add
(namespace,waf...) if we add a model in NS3.

I started down this path about a year ago in one of my tutorials. The
code is out of date, but maybe it will be useful. Here is an energy-
model.h, and energy-model.cc and an example program energy.cc for your
enjoyment ...

========== BEGIN ENERGY-MODEL.H ==========

/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 University of Washington
*
* This program is free software; you can redistribute it and/or
modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/

#ifndef ENERGY_MODEL_H
#define ENERGY_MODEL_H

#include "ns3/object.h"
#include "ns3/ptr.h"
#include "ns3/nstime.h"

namespace ns3 {

class EnergyModel : public Object
{
public:
static const InterfaceId iid;

EnergyModel (
double ampHours,
double volts,
double idlePower,
double receivePower,
double transmitPower);

virtual ~EnergyModel ();

double GetCapacity (Time t);

double GetTotalIdlePower (Time t);
double GetTotalTransmitPower (void);
double GetTotalReceivePower (void);

bool DrawTransmitPower (Time t);
bool DrawReceivePower (Time t);

private:
double m_capacity;
double m_idlePower;
double m_receivePower;
double m_transmitPower;
double m_totalTransmitPower;
double m_totalReceivePower;

};
}; // namespace ns3

#endif /* ENERGY_MODEL_H */

========== END ENERGY-MODEL.H ==========

========== BEGIN ENERGY-MODEL.CC ==========

/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 University of Washington
*
* This program is free software; you can redistribute it and/or
modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/

#include "ns3/log.h"
#include "energy-model.h"

NS_LOG_COMPONENT_DEFINE("EnergyModel");

namespace ns3 {

//
// Some dimensional analysis ...
//
// 1 [watt] = 1 [joule] / [second]
// 1 [watt] = 1 [volt] * 1 [amp]
// 1 [amp] = 1 [coulomb] / 1 [second]
// 1 [watt-second] = 1 [joule] / [second] * [second] = 1 [joule]
//
// A watt has dimensions of energy per second. A watt-second has
dimensions
// of energy.
//
// 1 [amp-hour] = 1 [coulomb] / 1 [second] * 1 [hour]
// 1 [amp-hour] = 1 [coulomb] / 1 [second] * 3600 [seconds]
// 1 [amp-hour] = 3600 [amp-seconds]
// 1 [watt-second] = 1 [amp-seconds] * 1 [volt]
//
// To get the energy capacity of your battery in watt-seconds from its
// amp-hour rating, multiply by 3600 and then the voltage. For
example, your
// Alkaline AAA battery may be rated at 1.5 volts and 900 milli-amp-
hours;
// so the energy capacity will be .9 * 3600 * 1.5 = 4860 watt-seconds.
//
// In a very simple battery model, we'll take this naively to mean
that this
// battery can supply one watt continuously for 4860 seconds and then
will die
// instantaneously.
//
// We'll assume our transmitter is measured in watts. When it is
turned on
// it draws some amount of power, 100 milliwatts for example. If it
transmits
// for one second, it will suck up .1 watt-seconds of our precious
energy.
//

const InterfaceId EnergyModel::iid =
MakeInterfaceId ("EnergyModel", Object::iid);

EnergyModel::EnergyModel (
double ampHours,
double volts,
double idlePower,
double receivePower,
double transmitPower)
:
m_capacity (ampHours * 3600. * volts),
m_idlePower (idlePower),
m_receivePower (receivePower),
m_transmitPower (transmitPower),
m_totalTransmitPower (0.),
m_totalReceivePower (0.)
{
NS_LOG_FUNCTION;
SetInterfaceId (EnergyModel::iid);

}

EnergyModel::~EnergyModel ()
{
NS_LOG_FUNCTION;

}

double
EnergyModel::GetCapacity (Time t)
{
NS_LOG_FUNCTION;
double c = m_capacity - m_idlePower * t.GetSeconds ();
return c >= 0. ? c : 0.;

}

double
EnergyModel::GetTotalIdlePower (Time t)
{
NS_LOG_FUNCTION;
return m_idlePower * t.GetSeconds ();

}

double
EnergyModel::GetTotalReceivePower (void)
{
NS_LOG_FUNCTION;
return m_totalReceivePower;

}

double
EnergyModel::GetTotalTransmitPower (void)
{
NS_LOG_FUNCTION;
return m_totalTransmitPower;

}

bool
EnergyModel::DrawTransmitPower (Time t)
{
NS_LOG_FUNCTION;
double power = m_transmitPower * t.GetSeconds ();
m_totalTransmitPower += power;
m_capacity -= power;
return m_capacity - m_idlePower * t.GetSeconds () >= 0. ? true :
false;

}

bool
EnergyModel::DrawReceivePower (Time t)
{
NS_LOG_FUNCTION;
double power = m_receivePower * t.GetSeconds ();
m_totalReceivePower += power;
m_capacity -= power;
return m_capacity - m_idlePower * t.GetSeconds () >= 0. ? true :
false;

}
}; // namespace ns3

========== END ENERGY-MODEL.CC ==========

========== BEGIN ENERGY.CC ==========

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or
modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/

#include "ns3/log.h"
#include "ns3/ptr.h"
#include "ns3/internet-node.h"
#include "ns3/point-to-point-channel.h"
#include "ns3/mac48-address.h"
#include "ns3/point-to-point-net-device.h"
#include "ns3/point-to-point-topology.h"
#include "ns3/udp-echo-client.h"
#include "ns3/udp-echo-server.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/global-route-manager.h"

#include "energy-model.h"

NS_LOG_COMPONENT_DEFINE ("EnergyModelInterfaceExample");

using namespace ns3;

// Network topology
//
// point to point
// +--------------+
// | |
// n0 n1
//
int
main (int argc, char *argv[])
{
LogComponentEnable ("EnergyModelInterfaceExample", LOG_LEVEL_ALL);
// LogComponentEnable ("EnergyModel", LOG_LEVEL_ALL);

NS_LOG_INFO ("Energy Model Interface Example");

NS_LOG_INFO ("Creating Nodes");
Ptr<Node> n0 = CreateObject<InternetNode> ();
Ptr<Node> n1 = CreateObject<InternetNode> ();

NS_LOG_INFO ("Creating Channel");
Ptr<PointToPointChannel> link =
PointToPointTopology::AddPointToPointLink (
n0, n1, DataRate (38400), MilliSeconds (20));

PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1",
n1, "10.1.1.2");

NS_LOG_INFO ("Creating Applications");
uint16_t port = 7;

Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0,
"10.1.1.2",
port, 1, Seconds(1.), 1024);

Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);

server->Start(Seconds(1.));
client->Start(Seconds(2.));

server->Stop (Seconds(10.));
client->Stop (Seconds(10.));

NS_LOG_INFO ("Initializing Tracing");
AsciiTrace asciitrace ("energy.tr");
asciitrace.TraceAllQueues ();
asciitrace.TraceAllNetDeviceRx ();
//
// Pick a battery out of the air and use some somewhat real numbers
found on
// data sheets on the web.
//
// 2 AAA battery (900 mAh * 2, with imaginary wireless device that
uses
// 0.350 W at idle power, 0.025 W additional during receive, and 0.2 W
// additional power during transmission (10 mW TX power).
//
NS_LOG_INFO ("Initializing Energy Models");
Ptr<EnergyModel> e0 = CreateObject<EnergyModel> (1.8, 1.5, 0.35,
0.025, 0.2);
n0->AddInterface (e0);

Ptr<EnergyModel> e1 = CreateObject<EnergyModel> (1.8, 1.5, 0.35,
0.025, 0.2);
n1->AddInterface (e1);

#if 0
//
// As simulation progresses, the battereis draw idle power. Down in
the
// net device, we will want to call DrawTransmitPower and
DrawReceivePower
// as required.
//
// This is just some example code showing how to draw power and check
// consumption.
//
NS_LOG_INFO("Node zero energy: " << e0->GetCapacity (Seconds (0.))
<<
" watt-seconds");
NS_LOG_INFO("Node one energy: " << e1->GetCapacity (Seconds (0.)) <<
" watt-seconds");

e0->DrawTransmitPower (Seconds (0.1));
e1->DrawReceivePower (Seconds (0.1));
e1->DrawTransmitPower (Seconds (0.1));
e0->DrawReceivePower (Seconds (0.1));

NS_LOG_INFO("Node zero energy: " << e0->GetCapacity (Seconds (10.))
<<
" watt-seconds");
NS_LOG_INFO("Node one energy: " << e1->GetCapacity (Seconds (10.))
<<
" watt-seconds");
#endif

Simulator::Run ();
Simulator::Destroy ();
}

========== END ENERGY.CC ==========

Antonio Junior

unread,
Apr 19, 2010, 1:06:20 PM4/19/10
to ns-3-...@googlegroups.com
Hi hrouz,

Thanks for your attention and answer.
I am ns2 user, but now I am beginning in NS3.
Later, if I can help you also, I sent an email... :)

Regards,
Antonio
--
Antonio Júnior, PhD Student (MAP-i)
IAN - Internet Architectures and Networking
UTM - Telecommunications and Multimedia Unit
INESC Porto -- Porto University
http://ian.inescporto.pt/

Tony Wu

unread,
Apr 20, 2010, 2:04:47 AM4/20/10
to ns-3-...@googlegroups.com
Hi,

I'm a graduate student form Network Security Lab, University of Washington, Seattle. Our lab have implemented a radio energy model for ns3. We are in the midst of some private review before posting it for public review sometime later this week.

Thanks,
He Wu

Tony Wu

unread,
Apr 20, 2010, 1:57:06 AM4/20/10
to ns-3-...@googlegroups.com
Hi,

I'm a graduate student form Network Security Lab, University of Washington, Seattle. Our lab have implemented a radio energy model for ns3. We are in the midst of some private review before posting it for public review sometime later this week.

Thanks,
He Wu

On Mon, Apr 19, 2010 at 10:06 AM, Antonio Junior <anton...@gmail.com> wrote:



--
Tony @ UW

Antonio Junior

unread,
Apr 20, 2010, 5:27:52 AM4/20/10
to ns-3-...@googlegroups.com
Hi Tony Wu,

It is good. I intend to analyse and implement energy metrics to multi
hop routing. So, this energy model could be used. I will wait the post
to see more details of the model.

Thanks,
--
Antonio Júnior, PhD Student (MAP-i)
http://ian.inescporto.pt/

Narendran Krishnan

unread,
Apr 20, 2010, 9:26:15 AM4/20/10
to ns-3-...@googlegroups.com
i take this opportunity to repost my previous mail on Power Saving
Class in WiMAX.

*********
Hi all,

I am currently working on wimax energy conservation (sleep
scheduling). So, I am looking to simulate the power saving classes (I,
II and II) in NS-3. When searched if NS-3 has already implemented it,
I couldn't find any. Can anybody let me if its available, and if not,
is it expected soon or later.

regards,
naren.
**********

regards,
naren.
Reply all
Reply to author
Forward
0 new messages