How to write a helper function in ns3

46 views
Skip to first unread message

Adnan Rashid

unread,
Nov 21, 2019, 1:28:28 PM11/21/19
to ns-3-users
Dear All,

I wrote this below code in the source file


  ApplicationContainer sixLbrApps;
  ObjectFactory factory;
  factory.SetTypeId (SixLowPanRadvd::GetTypeId ());
  Ptr<SixLowPanRadvd> sixLbr = factory.Create<SixLowPanRadvd> ();
  nodes.Get (0)->AddApplication (sixLbr);
  sixLbrApps.Add (sixLbr);
  sixLbrApps.Start(Seconds(0));


How can I write a helper function for the above code? 

Adnan Rashid

unread,
Nov 22, 2019, 7:47:56 AM11/22/19
to ns-3-users

I tried this way

helper.h file contains 

private:
  ObjectFactory m_deviceFactory; //!< Object factory.
  ApplicationContainer m_nodeApp;
  NodeContainer m_nodes;

ApplicationContainer SixLowPanHelper::InstallApplication6LowPanBorderRouter (NodeContainer c)
{

for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
Ptr<Node> node = *i;
m_deviceFactory.SetTypeId (SixLowPanRadvd::GetTypeId ());
Ptr<SixLowPanRadvd> sixLbr = m_deviceFactory.Create<SixLowPanRadvd> ();
node->AddApplication (sixLbr);
m_nodeApp.Add (sixLbr);
m_nodeApp.Start(Seconds(0));
}
return m_nodeApp;
}

BUT.... I am facing this error


In file included from ../src/sixlowpan/helper/sixlowpan-helper.cc:30:0:
../src/sixlowpan/helper/sixlowpan-helper.h:138:24: error: extra qualification ‘ns3::SixLowPanHelper::’ on member ‘InstallApplication6LowPanBorderRouter’ [-fpermissive]
   ApplicationContainer SixLowPanHelper::InstallApplication6LowPanBorderRouter (NodeContainer c);
                        ^~~~~~~~~~~~~~~


In file included from ./ns3/sixlowpan-module.h:11:0,
                 from ../scratch/node-6LBR.cc:52:
./ns3/sixlowpan-helper.h:138:24: error: extra qualification ‘ns3::SixLowPanHelper::’ on member ‘InstallApplication6LowPanBorderRouter’ [-fpermissive]
   ApplicationContainer SixLowPanHelper::InstallApplication6LowPanBorderRouter (NodeContainer c);
                        ^~~~~~~~~~~~~~~

Waf: Leaving directory `/home/adnan/eclipse-workspace/ns-3-dev/build'
Build failed
 -> task in 'ns3-sixlowpan' failed with exit status 1 (run with -v to display more information)
 -> task in 'example-sixlowpan' failed with exit status 1 (run with -v to display more information)
 -> task in 'uan-6lowpan-example' failed with exit status 1 (run with -v to display more information)
 -> task in 'wsn-ping6' failed with exit status 1 (run with -v to display more information)
 -> task in 'example-ping-lr-wpan' failed with exit status 1 (run with -v to display more information)
 -> task in 'example-ping-lr-wpan' failed with exit status 1 (run with -v to display more information)
 -> task in 'node-6LBR' failed with exit status 1 (run with -v to display more information)
 -> task in 'ns3-test-test' failed with exit status 1 (run with -v to display more information)

Adnan Rashid

unread,
Nov 27, 2019, 12:57:23 PM11/27/19
to ns-3-users
Hi All,

I forgot to write the solution. The bug was in header file of sixlowpan-helper.h where I wrote the signature of the function like this 

ApplicationContainer SixLowPanHelper::InstallApplication6LowPanBorderRouter (NodeContainer c)

instead of

ApplicationContainer InstallApplication6LowPanBorderRouter (NodeContainer c)

the red code must be omitted in the header file.

Problem solved
Reply all
Reply to author
Forward
0 new messages