Get node id when MAC of node is create in constructor

218 views
Skip to first unread message

Francisco Eduardo Balart Sanchez

unread,
May 31, 2017, 7:47:33 PM5/31/17
to ns-3-users
This is slightly different from other related topics,

Basically when the Wifi Net Device is Created with the command 

NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);

A constructor of the selected MAC will be created in this case of the wifimac

By following Konstantinos advice in:


In the constructor of the mac i did this:

MyNewWifiMac::MyNewWifiMac ()
{
  NS_LOG_FUNCTION (this);
  NS_LOG_UNCOND ("%INFO: Entered to EssoaWifiMac constructor function of ESSOA MAC CLASS");
  //Let the lower layers know that we are acting in an IBSS
  // this is part of an enum in edca-txop-n.*
  SetTypeOfStation (ADHOC_STA);
  Ptr<Node> node = this->GetObject<Node>();
  NS_LOG_UNCOND ("%INFO: This MAC object belongs to node id: "<<node->GetId ());
}

I get no error from the part highlighted in yellow
but for some reason when i try to get the id from the node object i get this in compilation
maybe this is too obvious but not sure what the problem could be 
any help will be greatly appreciated

balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ ./waf
Waf: Entering directory `/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build'
[ 973/1918] Compiling src/wifi/model/essoa-wifi-mac.cc
../src/wifi/model/essoa-wifi-mac.cc: In constructor ‘ns3::EssoaWifiMac::EssoaWifiMac()’:
../src/wifi/model/essoa-wifi-mac.cc:66:68: error: invalid use of incomplete type ‘class ns3::Node’
   NS_LOG_UNCOD ("%INFO: This MAC object belongs to node id: "<<node->GetId());
                                                                    ^
In file included from ./ns3/arp-cache.h:29:0,
                 from ../src/wifi/model/essoa-ESSOARole.h:32,
                 from ../src/wifi/model/essoa-wifi-mac.h:27,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/net-device.h:37:7: error: forward declaration of ‘class ns3::Node’
 class Node;
       ^
../src/wifi/model/essoa-wifi-mac.cc:66:77: error: ‘NS_LOG_UNCOD’ was not declared in this scope
   NS_LOG_UNCOD ("%INFO: This MAC object belongs to node id: "<<node->GetId());
                                                                             ^
In file included from ./ns3/wifi-phy.h:28:0,
                 from ./ns3/wifi-mac.h:26,
                 from ../src/wifi/model/regular-wifi-mac.h:24,
                 from ../src/wifi/model/essoa-wifi-mac.h:25,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/object.h: In instantiation of ‘ns3::Ptr<T> ns3::Object::GetObject() const [with T = ns3::Node]’:
../src/wifi/model/essoa-wifi-mac.cc:65:42:   required from here
./ns3/object.h:459:57: error: cannot dynamic_cast ‘((ns3::Object::Aggregates*)((const ns3::Object*)this)->ns3::Object::m_aggregates)->ns3::Object::Aggregates::buffer[0]’ (of type ‘class ns3::Object*’) to type ‘class ns3::Node*’ (target is not pointer or reference to complete type)
   T *result = dynamic_cast<T *> (m_aggregates->buffer[0]);
                                                         ^
./ns3/object.h:465:50: error: incomplete type ‘ns3::Node’ used in nested name specifier
   Ptr<Object> found = DoGetObject (T::GetTypeId ());
                                                  ^
./ns3/object.h:468:60: error: invalid static_cast from type ‘ns3::Object*’ to type ‘ns3::Node*’
       return Ptr<T> (static_cast<T *> (PeekPointer (found)));
                                                            ^
In file included from ./ns3/attribute.h:25:0,
                 from ./ns3/type-id.h:23,
                 from ./ns3/object-base.h:23,
                 from ./ns3/chunk.h:24,
                 from ./ns3/header.h:24,
                 from ./ns3/packet.h:25,
                 from ./ns3/wifi-mac.h:24,
                 from ../src/wifi/model/regular-wifi-mac.h:24,
                 from ../src/wifi/model/essoa-wifi-mac.h:25,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/ptr.h: In instantiation of ‘ns3::Ptr<T>::~Ptr() [with T = ns3::Node]’:
../src/wifi/model/essoa-wifi-mac.cc:65:42:   required from here
./ns3/ptr.h:756:7: error: invalid use of incomplete type ‘class ns3::Node’
       m_ptr->Unref ();
       ^
In file included from ./ns3/arp-cache.h:29:0,
                 from ../src/wifi/model/essoa-ESSOARole.h:32,
                 from ../src/wifi/model/essoa-wifi-mac.h:27,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/net-device.h:37:7: error: forward declaration of ‘class ns3::Node’
 class Node;
       ^
In file included from ./ns3/attribute.h:25:0,
                 from ./ns3/type-id.h:23,
                 from ./ns3/object-base.h:23,
                 from ./ns3/chunk.h:24,
                 from ./ns3/header.h:24,
                 from ./ns3/packet.h:25,
                 from ./ns3/wifi-mac.h:24,
                 from ../src/wifi/model/regular-wifi-mac.h:24,
                 from ../src/wifi/model/essoa-wifi-mac.h:25,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/ptr.h: In instantiation of ‘void ns3::Ptr<T>::Acquire() const [with T = ns3::Node]’:
./ns3/ptr.h:741:12:   required from ‘ns3::Ptr<T>::Ptr(const ns3::Ptr<T>&) [with T = ns3::Node]’
../src/wifi/model/essoa-wifi-mac.cc:65:42:   required from here
./ns3/ptr.h:710:7: error: invalid use of incomplete type ‘class ns3::Node’
       m_ptr->Ref ();
       ^
In file included from ./ns3/arp-cache.h:29:0,
                 from ../src/wifi/model/essoa-ESSOARole.h:32,
                 from ../src/wifi/model/essoa-wifi-mac.h:27,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/net-device.h:37:7: error: forward declaration of ‘class ns3::Node’
 class Node;
       ^

Waf: Leaving directory `/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build'
Build failed
 -> task in 'ns3-wifi' failed (exit status 1): 
{task 140520150050896: cxx essoa-wifi-mac.cc -> essoa-wifi-mac.cc.1.o}
['/usr/bin/g++', '-O0', '-ggdb', '-g3', '-Wall', '-Werror', '-Wno-error=deprecated-declarations', '-fstrict-aliasing', '-Wstrict-aliasing', '-fPIC', '-pthread', '-I.', '-I..', '-DNS3_BUILD_PROFILE_DEBUG', '-DNS3_ASSERT_ENABLE', '-DNS3_LOG_ENABLE', '-DHAVE_SYS_IOCTL_H=1', '-DHAVE_IF_NETS_H=1', '-DHAVE_NET_ETHERNET_H=1', '-DHAVE_PACKET_H=1', '-DHAVE_IF_TUN_H=1', '-DHAVE_GSL=1', '-DHAVE_SQLITE3=1', '../src/wifi/model/essoa-wifi-mac.cc', '-c', '-o', '/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build/src/wifi/model/essoa-wifi-mac.cc.1.o']
balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ qclear
bash: qclear: command not found
balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ 
balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ clear

balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ ./waf
Waf: Entering directory `/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build'
[ 965/1918] Compiling src/wifi/model/essoa-wifi-mac.cc
../src/wifi/model/essoa-wifi-mac.cc: In constructor ‘ns3::EssoaWifiMac::EssoaWifiMac()’:
../src/wifi/model/essoa-wifi-mac.cc:66:68: error: invalid use of incomplete type ‘class ns3::Node’
   NS_LOG_UNCOD ("%INFO: This MAC object belongs to node id: "<<node->GetId ());
                                                                    ^
In file included from ./ns3/arp-cache.h:29:0,
                 from ../src/wifi/model/essoa-ESSOARole.h:32,
                 from ../src/wifi/model/essoa-wifi-mac.h:27,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/net-device.h:37:7: error: forward declaration of ‘class ns3::Node’
 class Node;
       ^
../src/wifi/model/essoa-wifi-mac.cc:66:78: error: ‘NS_LOG_UNCOD’ was not declared in this scope
   NS_LOG_UNCOD ("%INFO: This MAC object belongs to node id: "<<node->GetId ());
                                                                              ^
In file included from ./ns3/wifi-phy.h:28:0,
                 from ./ns3/wifi-mac.h:26,
                 from ../src/wifi/model/regular-wifi-mac.h:24,
                 from ../src/wifi/model/essoa-wifi-mac.h:25,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/object.h: In instantiation of ‘ns3::Ptr<T> ns3::Object::GetObject() const [with T = ns3::Node]’:
../src/wifi/model/essoa-wifi-mac.cc:65:42:   required from here
./ns3/object.h:459:57: error: cannot dynamic_cast ‘((ns3::Object::Aggregates*)((const ns3::Object*)this)->ns3::Object::m_aggregates)->ns3::Object::Aggregates::buffer[0]’ (of type ‘class ns3::Object*’) to type ‘class ns3::Node*’ (target is not pointer or reference to complete type)
   T *result = dynamic_cast<T *> (m_aggregates->buffer[0]);
                                                         ^
./ns3/object.h:465:50: error: incomplete type ‘ns3::Node’ used in nested name specifier
   Ptr<Object> found = DoGetObject (T::GetTypeId ());
                                                  ^
./ns3/object.h:468:60: error: invalid static_cast from type ‘ns3::Object*’ to type ‘ns3::Node*’
       return Ptr<T> (static_cast<T *> (PeekPointer (found)));
                                                            ^
In file included from ./ns3/attribute.h:25:0,
                 from ./ns3/type-id.h:23,
                 from ./ns3/object-base.h:23,
                 from ./ns3/chunk.h:24,
                 from ./ns3/header.h:24,
                 from ./ns3/packet.h:25,
                 from ./ns3/wifi-mac.h:24,
                 from ../src/wifi/model/regular-wifi-mac.h:24,
                 from ../src/wifi/model/essoa-wifi-mac.h:25,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/ptr.h: In instantiation of ‘ns3::Ptr<T>::~Ptr() [with T = ns3::Node]’:
../src/wifi/model/essoa-wifi-mac.cc:65:42:   required from here
./ns3/ptr.h:756:7: error: invalid use of incomplete type ‘class ns3::Node’
       m_ptr->Unref ();
       ^
In file included from ./ns3/arp-cache.h:29:0,
                 from ../src/wifi/model/essoa-ESSOARole.h:32,
                 from ../src/wifi/model/essoa-wifi-mac.h:27,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/net-device.h:37:7: error: forward declaration of ‘class ns3::Node’
 class Node;
       ^
In file included from ./ns3/attribute.h:25:0,
                 from ./ns3/type-id.h:23,
                 from ./ns3/object-base.h:23,
                 from ./ns3/chunk.h:24,
                 from ./ns3/header.h:24,
                 from ./ns3/packet.h:25,
                 from ./ns3/wifi-mac.h:24,
                 from ../src/wifi/model/regular-wifi-mac.h:24,
                 from ../src/wifi/model/essoa-wifi-mac.h:25,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/ptr.h: In instantiation of ‘void ns3::Ptr<T>::Acquire() const [with T = ns3::Node]’:
./ns3/ptr.h:741:12:   required from ‘ns3::Ptr<T>::Ptr(const ns3::Ptr<T>&) [with T = ns3::Node]’
../src/wifi/model/essoa-wifi-mac.cc:65:42:   required from here
./ns3/ptr.h:710:7: error: invalid use of incomplete type ‘class ns3::Node’
       m_ptr->Ref ();
       ^
In file included from ./ns3/arp-cache.h:29:0,
                 from ../src/wifi/model/essoa-ESSOARole.h:32,
                 from ../src/wifi/model/essoa-wifi-mac.h:27,
                 from ../src/wifi/model/essoa-wifi-mac.cc:23:
./ns3/net-device.h:37:7: error: forward declaration of ‘class ns3::Node’
 class Node;
       ^

thanks in advance and best regards

Eduardo

Francisco Eduardo Balart Sanchez

unread,
May 31, 2017, 8:07:02 PM5/31/17
to ns-3-users
I commented the ns_logging messages and just leaved this in the constructor

EssoaWifiMac::EssoaWifiMac ()
{
  NS_LOG_FUNCTION (this);
  NS_LOG_UNCOND ("%INFO: Entered to EssoaWifiMac constructor function of ESSOA MAC CLASS");
  //Let the lower layers know that we are acting in an IBSS
  // this is part of an enum in edca-txop-n.*
  SetTypeOfStation (ADHOC_STA);
  Ptr<Node> node = this->GetObject<Node>();
  //NS_LOG_UNCOND ("%INFO: pointer to node is: "<<node);
  //NS_LOG_UNCOND ("%INFO: This MAC object belongs to node id: "<<node->GetId ());
}

When i compiled i got

balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ ./waf
Waf: Entering directory `/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build'
[1714/1918] Compiling src/wifi/model/essoa-wifi-mac.cc
{task 140244802672720: cxx essoa-wifi-mac.cc -> essoa-wifi-mac.cc.1.o}
['/usr/bin/g++', '-O0', '-ggdb', '-g3', '-Wall', '-Werror', '-Wno-error=deprecated-declarations', '-fstrict-aliasing', '-Wstrict-aliasing', '-fPIC', '-pthread', '-I.', '-I..', '-DNS3_BUILD_PROFILE_DEBUG', '-DNS3_ASSERT_ENABLE', '-DNS3_LOG_ENABLE', '-DHAVE_SYS_IOCTL_H=1', '-DHAVE_IF_NETS_H=1', '-DHAVE_NET_ETHERNET_H=1', '-DHAVE_PACKET_H=1', '-DHAVE_IF_TUN_H=1', '-DHAVE_GSL=1', '-DHAVE_SQLITE3=1', '../src/wifi/model/essoa-wifi-mac.cc', '-c', '-o', '/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build/src/wifi/model/essoa-wifi-mac.cc.1.o']
balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ clear

balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ ls
AUTHORS   build         doc       LICENSE   README         run.log  sixth.cwnd  test.py      utils     utils.pyc  waf      waf-tools  wutils.py
bindings  CHANGES.html  examples  Makefile  RELEASE_NOTES  scratch  src         testpy.supp  utils.py  VERSION    waf.bat  wscript    wutils.pyc
balart40@balart40-VirtualBox:~/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25$ ./waf
Waf: Entering directory `/home/balart40/Desktop/balart40/ns/ns-allinone-3.25/ns-3.25/build'
[ 975/1918] Compiling src/wifi/model/essoa-wifi-mac.cc

¿Why i cannot get the node id of the node I (the mac object) i´m attached to if i´m already created?
I read some similar items, Tommasso suggest there is a null pointer, does this mean i need to do this after the constructor is made 
to make sure there is no null pointer, meaning that doing it in the constructor when the mac object hasn't been created yet will result in this error?

Francisco Eduardo Balart Sanchez

unread,
Jun 1, 2017, 2:28:24 PM6/1/17
to ns-3-users
Just to clarify:

I want to know if there is a way to obtain my "container" node id when i´m it's MAC object
After
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
Is run
The WifiHelper will attach the brand new MAC object to the node

NetDeviceContainer
WifiHelper::Install (const WifiPhyHelper &phyHelper,
                     const WifiMacHelper &macHelper, NodeContainer c) const
{
  NetDeviceContainer devices;
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
    {
      Ptr<Node> node = *i;
      Ptr<WifiNetDevice> device = CreateObject<WifiNetDevice> ();
      Ptr<WifiRemoteStationManager> manager = m_stationManager.Create<WifiRemoteStationManager> ();
      Ptr<WifiMac> mac = macHelper.Create ();
      Ptr<WifiPhy> phy = phyHelper.Create (node, device);
      mac->SetAddress (Mac48Address::Allocate ());
      mac->ConfigureStandard (m_standard);
      phy->ConfigureStandard (m_standard);
      device->SetMac (mac);
      device->SetPhy (phy);
      device->SetRemoteStationManager (manager);
      node->AddDevice (device);
      devices.Add (device);
      NS_LOG_DEBUG ("node=" << node << ", mob=" << node->GetObject<MobilityModel> ());
    }
  return devices;
}

I would like to know if there is a way that the MAC object created and attached to that node can get the node Id whom is attached to.

Thanks in advance and best regards

Rediet

unread,
Jun 2, 2017, 2:53:54 AM6/2/17
to ns-3-users
Hello Eduardo,

I don't think that it is possible in the current state of things because WifiMac is simply an attribute of WifiNetDevice, whereas WifiNetDevice is aggregated to the Node and contains a pointer to it. That is why you can access to the Node from the WifiNetDevice, but not from the WifiMac.
However, you can slightly modify your WifiMac class by adding either a pointer to the Node or simply storing the NodeId during WifiNetDevice::SetNode operation.

Cheers,

Rediet
Reply all
Reply to author
Forward
0 new messages