Not getting remaining energy of ALL nodes at time T with Basic Source Helper

72 views
Skip to first unread message

Francisco Eduardo Balart Sanchez

unread,
Oct 31, 2018, 11:20:47 PM10/31/18
to ns-3-users
Good day:

In the beginning i had my energy model setup as shown below

  for (uint32_t i = 0; i < numOfNodes; ++i)
  {
    Ptr<BasicEnergySource> energySource = CreateObject<BasicEnergySource>();
    Ptr<WifiRadioEnergyModel> radioenergyModel = CreateObject<WifiRadioEnergyModel>();
    energySource->SetInitialEnergy (double (100));
    energySource->SetEnergyUpdateInterval (t1);
    radioenergyModel->SetEnergySource (energySource);
    energySource->AppendDeviceEnergyModel (radioenergyModel);
    radioenergyModel->SetTxCurrentA (double (0.0174));
    radioenergyModel->SetRxCurrentA (double (0.0174));
    nodes.Get (nodeIndexxx)->AggregateObject (energySource);
    nodeIndexxx++;
}

But later i switched to use the helper as the example and as per recomendation, now my setup is the following

  BasicEnergySourceHelper basicSourceHelper;
  basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (100));
  basicSourceHelper.Set ("PeriodicEnergyUpdateInterval", t1);
  EnergySourceContainer sources = basicSourceHelper.Install (nodes);
  WifiRadioEnergyModelHelper wifiRadioEnergyModelHelper;
  wifiRadioEnergyModelHelper.Set ("TxCurrentA", DoubleValue (0.0174));
  wifiRadioEnergyModelHelper.Set ("RxCurrentA", DoubleValue (0.0174));
  DeviceEnergyModelContainer deviceModels = wifiRadioEnergyModelHelper.Install (devices, sources);

And the trace connection is performed (can be done in several ways these is mine)

  int iii = 0;
  uint32_t nDevices = devices.GetN ();
  for (uint32_t i = 0;i < nDevices; ++i)
  {
    Ptr<WifiNetDevice> p = DynamicCast<WifiNetDevice> (devices.Get (i)); 
    p->SetAddress(Mac48Address::Allocate ());  
    Ptr<EESOA> macN = DynamicCast<EESOA> (p->GetMac());
    macN->SetNodeId(p->GetNode ()->GetId ());
    prev_role[i]= 100; //this role does not exists.
    prev_nNodes[i]= 0;
    Simulator::ScheduleWithContext (p->GetNode ()->GetId (), MilliSeconds(90), &modify, p, &anim);
    Simulator::ScheduleWithContext (p->GetNode ()->GetId (), Seconds(1), &printNonEESOAtx, p);
    p->GetPhy()->TraceConnect ("PhyTxBegin",PrintID(p->GetNode ()), MakeCallback (&PhyTxBegin));
         Ptr<BasicEnergySource>  basicSourcePtr  =  DynamicCast<BasicEnergySource>(p->GetNode ()->GetObject<EnergySourceContainer>()->Get(0));
    NS_ASSERT (basicSourcePtr != NULL);
    basicSourcePtr->TraceConnect ("RemainingEnergy",PrintID(p->GetNode ()), MakeCallback (&RemainingEnergyTrace)); 
    Ptr<DeviceEnergyModel> basicRadioModelPtr = basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get(0);
    NS_ASSERT (basicRadioModelPtr != NULL);
      iii++;
  }

The remaining energy function
void RemainingEnergyTrace (std::string context, double oldValue, double remainingEnergy)
{
  NS_LOG_UNCOND ("%INFO: TimeStamp: "<<Simulator::Now ().GetSeconds ()<<" segs Node: "<<context<<" Current Remaining energy = "<<remainingEnergy<< " Joules");        
}



That combined with the changes to the animation interface mentioned by John Abraham at:

Provide remaining energy of the nodes.

Problem

It only shows the remaining energy of the Nodes at such time T  which are active at that exact moment 
It does not show remaining energy of ALL nodes, i require to get it so i can make comparisons see below

50: Node ID: 30  Start sending packet
%INFO: TimeStamp: 50 segs Node: ID: 30   Current Remaining energy = 59.6457 Joules
%INFO: TimeStamp: 50 segs Node: ID: 55   Current Remaining energy = 59.7018 Joules
%INFO: TimeStamp: 50 segs Node: ID: 34   Current Remaining energy = 60.8215 Joules
%INFO: TimeStamp: 50 segs Node: ID: 59   Current Remaining energy = 59.7593 Joules
%INFO: TimeStamp: 50 segs Node: ID: 61   Current Remaining energy = 59.7564 Joules
%INFO: TimeStamp: 50 segs Node: ID: 13   Current Remaining energy = 59.9294 Joules
%INFO: TimeStamp: 50 segs Node: ID: 23   Current Remaining energy = 59.7571 Joules
%INFO: TimeStamp: 50 segs Node: ID: 64   Current Remaining energy = 61.3666 Joules
%INFO: TimeStamp: 50 segs Node: ID: 92   Current Remaining energy = 61.3275 Joules
%INFO: TimeStamp: 50 segs Node: ID: 25   Current Remaining energy = 60.0478 Joules
%INFO: TimeStamp: 50 segs Node: ID: 43   Current Remaining energy = 61.2333 Joules
%INFO: TimeStamp: 50 segs Node: ID: 77   Current Remaining energy = 61.5995 Joules
%INFO: TimeStamp: 50 segs Node: ID: 24   Current Remaining energy = 61.7428 Joules
%INFO: TimeStamp: 50 segs Node: ID: 28   Current Remaining energy = 61.433 Joules
%INFO: TimeStamp: 50 segs Node: ID: 53   Current Remaining energy = 59.9551 Joules
%INFO: TimeStamp: 50 segs Node: ID: 71   Current Remaining energy = 60.3789 Joules
%INFO: TimeStamp: 50 segs Node: ID: 43   Current Remaining energy = 61.2333 Joules
%INFO: TimeStamp: 50 segs Node: ID: 34   Current Remaining energy = 60.8215 Joules
%INFO: TimeStamp: 50 segs Node: ID: 77   Current Remaining energy = 61.5995 Joules
%INFO: TimeStamp: 50 segs Node: ID: 24   Current Remaining energy = 61.7428 Joules
%INFO: TimeStamp: 50 segs Node: ID: 64   Current Remaining energy = 61.3666 Joules
%INFO: TimeStamp: 50 segs Node: ID: 92   Current Remaining energy = 61.3275 Joules
%INFO: TimeStamp: 50 segs Node: ID: 28   Current Remaining energy = 61.433 Joules


How can i obtain the energy of ALL nodes at such time using the helper

Im using ns3.25

Thanks in advance and best regards

pdbarnes

unread,
Nov 2, 2018, 9:25:26 PM11/2/18
to ns-3-users
In RemainingEnergyTrace you could cache the last energy report from each node, then log the entire cache.

Peter

Reply all
Reply to author
Forward
0 new messages