how to assign energy module for multiple nodes

498 views
Skip to first unread message

Vanita Patil

unread,
Jun 17, 2014, 2:53:59 AM6/17/14
to ns-3-...@googlegroups.com
hello sir,
 i created 4 nodes one source and 3 sink nodes and getting problem 
please any body help me out


error
Program received signal SIGSEGV, Segmentation fault.
0x0805f142 in ns3::SimpleRefCount<ns3::Object, ns3::ObjectBase, ns3::ObjectDeleter>::Ref (this=0x179) at ./ns3/simple-ref-count.h:94
94        NS_ASSERT (m_count < std::numeric_limits<uint32_t>::max());
(gdb) where
#0  0x0805f142 in ns3::SimpleRefCount<ns3::Object, ns3::ObjectBase, ns3::ObjectDeleter>::Ref (this=0x179) at ./ns3/simple-ref-count.h:94
#1  0xb6c0c6fa in ns3::Ptr<ns3::DeviceEnergyModel>::Acquire (this=0xbffff328) at ./ns3/ptr.h:410
#2  0xb6aa9e05 in ns3::Ptr<ns3::DeviceEnergyModel>::Ptr (this=0xbffff328, o=...) at ./ns3/ptr.h:441
#3  0xb6ac15c3 in ns3::DeviceEnergyModelContainer::Get (this=0xbfffee80, i=3) at ../src/energy/model/device-energy-model-container.cc:84
#4  0x0805a72c in main (argc=2, argv=0xbffff504) at ../scratch/cl.cc:787



program

 /** Internet stack **/

  InternetStackHelper internet;
  internet.Install (networkNodes);

  Ipv4AddressHelper ipv4;
  NS_LOG_INFO ("Assign IP Addresses.");
  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer i = ipv4.Assign (devices);

  TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
  Ptr<Socket> recvSink = Socket::CreateSocket (networkNodes.Get (1), tid);  // node 1, receiver
  InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
  recvSink->Bind (local);
  recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));

  Ptr<Socket> source = Socket::CreateSocket (networkNodes.Get (0), tid);    // node 0, sender
  InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetBroadcast (), 80);
  source->SetAllowBroadcast (true);
  source->Connect (remote);

 Ptr<Socket> source1 = Socket::CreateSocket (networkNodes.Get (2), tid);    // node 0, sender
  InetSocketAddress remote1 = InetSocketAddress (Ipv4Address::GetBroadcast (), 80);
  source->SetAllowBroadcast (true);
  source->Connect (remote1);

 Ptr<Socket> source2 = Socket::CreateSocket (networkNodes.Get (3), tid);    // node 0, sender
  InetSocketAddress remote2 = InetSocketAddress (Ipv4Address::GetBroadcast (), 80);
  source->SetAllowBroadcast (true);
  source->Connect (remote2);

  /** connect trace sources **/
  /***************************************************************************/
  // all sources are connected to node 1
  // energy source
  Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (sources.Get (1));
  basicSourcePtr->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
  // device energy model
  Ptr<DeviceEnergyModel> basicRadioModelPtr =
    basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
  NS_ASSERT (basicRadioModelPtr != NULL);
  basicRadioModelPtr->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));

Ptr<DeviceEnergyModel> basicRadioModelPtr2 =
    basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (2);
NS_ASSERT (basicRadioModelPtr2 != NULL);
basicRadioModelPtr2->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));

Ptr<DeviceEnergyModel> basicRadioModelPtr3 =
    basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (3);
NS_ASSERT (basicRadioModelPtr3 != NULL);
 basicRadioModelPtr3->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));


  /***************************************************************************/
// steg();

  /** simulation setup **/
  // start traffic
wifiPhy.EnablePcap ("cl", devices);

  AnimationInterface anim ("cl.xml");
  anim.EnablePacketMetadata (true);

 Simulator::Schedule (Seconds (0.0), &GenerateTraffic, source, PpacketSize,
                       networkNodes.Get (0), numPackets, interPacketInterval);
 Simulator::Stop (Seconds (2.0));
Simulator::Run ();

Simulator::Schedule (Seconds (2.0), &GenerateTraffic, source1, PpacketSize,
                       networkNodes.Get (2), numPackets, interPacketInterval);
 Simulator::Stop (Seconds (4.0));
Simulator::Run ();

 Simulator::Schedule (Seconds (4.0), &GenerateTraffic, source2, PpacketSize,
                       networkNodes.Get (3), numPackets, interPacketInterval);
//steg();
  Simulator::Stop (Seconds (6.0));
Simulator::Run ();
/*
//steg();
 Simulator::Schedule (Seconds (4.0), &GenerateTraffic, source, PpacketSize,
                       networkNodes.Get (0), numPackets, interPacketInterval);

  Simulator::Stop (Seconds (6.0));

 Simulator::Run ();
*/
  Simulator::Destroy ();

  return 0;
}

Cristiano Tapparello

unread,
Jun 18, 2014, 12:01:29 PM6/18/14
to ns-3-...@googlegroups.com
Hi Vanita,

I think that the error that you are getting is due to the fact that you trying to connect to trace variables that do not exist. 

In particular here

Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (sources.Get (1));

you get a pointer to the energy source of node in position 1, and then you use that pointer in order to get the pointer to the device energy model connected to the wifi radio and the energy source of the same node, here

Ptr<DeviceEnergyModel> basicRadioModelPtr = basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);

After this you can use te pointer to the device energy model for tracing variables. 

Given the above, if you want to trace the energy consumption of the other nodes, you first need to obtain a pointer to the energy source of each node (sources.Get(2), sources.Get(3), ...) and then you use the so obtained pointer for getting the relative device energy model.

I hope this help! 

Best,

Cristiano 

mehrdad manoochehri

unread,
Apr 19, 2017, 5:56:04 AM4/19/17
to ns-3-users
hello. i have this problem as well. i don not know what to do to address this problem this a part of my code. please help me

  NodeContainer wifistation;
  wifistation.Create(1);
  NodeContainer wifistation1;
  wifistation1.Create(1);
  NodeContainer wifiAP;
  wifiAP.Create(2);

  BasicEnergySourceHelper basicSourceHelper;
  basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (2.5));
  EnergySourceContainer sources = basicSourceHelper.Install (wifiAP);
  WifiRadioEnergyModelHelper radioEnergyHelper;
  DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (apDevices, sources);



    Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (sources.Get (0));
    Ptr<BasicEnergySource> basicSourcePtr1 = DynamicCast<BasicEnergySource> (sources.Get(1));

    Ptr<DeviceEnergyModel> basicRadioModelPtr = basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
    NS_ASSERT (basicRadioModelPtr != NULL);
    basicRadioModelPtr->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
    Ptr<DeviceEnergyModel> basicRadioModelPtr1 = basicSourcePtr1->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (1);
    NS_ASSERT (basicRadioModelPtr1 != NULL);
    basicRadioModelPtr1->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));

Tommaso Pecorella

unread,
Apr 23, 2017, 9:13:00 PM4/23/17
to ns-3-users
Please read the posting guidelines.
Moreover, remember that anyone starting their posts with something like " i have the same problem", especially when replying to a 1+ years old thread, is automatically classified as "must read the posting guidelines AGAIN".

T.
Reply all
Reply to author
Forward
0 new messages