printing values in command line

248 views
Skip to first unread message

Natalia Molinero

unread,
Aug 3, 2015, 7:13:54 AM8/3/15
to ns-3-users
Hi,

I've read this example https://www.nsnam.org/docs/manual/html/tracing.html#the-simplest-example and I'm doing std::cout << "The value of x is " << x << std::endl; to output a value on the command line, but I don't get anything, not even an error. Does anyone know what's going on?

Thank you!

Konstantinos

unread,
Aug 3, 2015, 7:25:54 AM8/3/15
to ns-3-users
Hi Natalia,

The command you gave is correct to send to the standard output something. 
The question is WHERE do you call this? Are you sure that the program flow goes there? 
Perhaps not, that's why you do not see something in the output. 

Regards,
K.

Natalia Molinero

unread,
Aug 3, 2015, 11:54:00 AM8/3/15
to ns-3-users
Hi Konstatinos,

thanks for your answer. What I really want to do is to trace or prompt the users and eNodeBs positions, but I've been looking to documentation and I found difficult to get this property so I'm doing this little test to try to understand what I can prompt in the command line: I put this: 


enbDevs = lteHelper->InstallEnbDevice (enbNodes);
ueDevs = lteHelper->InstallUeDevice (ueNodes);

std::cout << "The value of x is " << ueDevs << std::endl;


in lena-simple-epc.cc ... which I guess is not correct. I also had a look to the code fourth.cc but I don't get it (and I read the documentation)

so :( I was also thinking that maybe ueDevs can't be displayed?

Please, help me a bit. Thank you. Best regards, 

Natalia Molinero

unread,
Aug 3, 2015, 11:55:24 AM8/3/15
to ns-3-users
when I said that I don't get the example fourth.cc, I mean that I don't get how to use that in lena-simple-epc.cc to trace the users' position :-(

Konstantinos

unread,
Aug 3, 2015, 6:45:29 PM8/3/15
to ns-3-users
Hi Natalia,

First things first.
What you are trying to print is not correct. The 'ueDevs' variable is a NetDeviceContainer (i.e. a vector of NetDevices). By printing it, you will print the pointer to that memory.

You said you want to print the positions of the nodes. If the nodes are static, then you know where they are, not need to print them. 
If they are moving, you can use the trace source from the mobility model as explained in the tutorial 

Generally, the positions of any node (ue, enb) is available from the MobilityModel class installed on that node. So, by getting a pointer to the installed mobility model you can get its position. We have discussed similar issues in the list several times. Please search it.

Regards,
K.

Natalia Molinero

unread,
Aug 4, 2015, 12:09:03 PM8/4/15
to ns-3-users
Hi Konstantinos,

so if I'm using the constant-position-mobility-model, can I do: mobility.ListPositionAllocator->GetNext();?

This is from the class position-allocator. 
Message has been deleted

Konstantinos

unread,
Aug 4, 2015, 2:20:04 PM8/4/15
to ns-3-users
In any case/mobility model this code gives you the position of the node (assuming you have a Ptr<Node> node):

Ptr<MobilityModel> mobility = node->GetObject<MobilityModel>();
Vector position = mobility->GetPosition();

Natalia Molinero

unread,
Aug 5, 2015, 3:26:58 AM8/5/15
to ns-3-users
Thanks Konstantinos,

so I'm doing this:

Ptr <Node> enbDevs = lteHelper->InstallEnbDevice (enbNodes);
Ptr <Node>   ueDevs = lteHelper->InstallUeDevice (ueNodes);

Ptr<MobilityModel> mobility = enbNodes->GetObject<MobilityModel>();
Vector position1 = mobility->GetPosition();
Ptr<MobilityModel> mobility = enbNodes->GetObject<MobilityModel>();
Vector position2 = mobility->GetPosition();

std::cout << "The value of position enbNodes is " << position1 << std::endl;
std::cout << "The value of UEs is " << position2 << std::endl;


But there is nothing printed in the command line, not even an error... I don't understand :(

Natalia Molinero

unread,
Aug 5, 2015, 5:34:56 AM8/5/15
to ns-3-users
Also, I'm running the original lena-simple-epc.cc and I don't get anything in the command line when I think I should, shouldn't it? I put these files in the ns-3.22 folder where I've got the waf and where the traces are stored...I think this is correct but it's weird that I don't get any output (not even errors) :-(

Konstantinos

unread,
Aug 5, 2015, 7:14:54 AM8/5/15
to ns-3-users
You have not understood the code. I would recommend to study the documentation one more time.

Ptr <Node> enbDevs = lteHelper->InstallEnbDevice (enbNodes);
Ptr <Node>   ueDevs = lteHelper->InstallUeDevice (ueNodes);

This is totally wrong. Check the API for the command you are using, e.g. InstallEnbDevice()
NetDeviceContainer ns3::LteHelper::InstallEnbDevice ( NodeContainer  c )

It takes as input a NodeContainer and it returns a NetDeviceContainer. 
In your code you say that this NetDeviceContainer is a Ptr<Node> !!!

You have your nodes in the enbNodes and ueNodes NodeContainers. 
These NodeContainers are in principle vectors of Ptr<Node>, so you need to iterate on each element of the container to get each node.
This is not some NS3 whim, it's basic C++. You have a vector of elements, and you want to access each one individually. 

As far as the lena-simple-epc example, there is nothing to be printed in the command line. It generates trace files with this command whose content is explained here https://www.nsnam.org/docs/models/html/lte-user.html#simulation-output

180  lteHelper->EnableTraces ();

Natalia Molinero

unread,
Aug 19, 2015, 4:59:37 AM8/19/15
to ns-3-users
Hi Konstatinos,

I've been through the documentation again, and according to it, there is no trace sources to show the nodes' position unless they are moving: https://www.nsnam.org/docs/release/3.23/doxygen/_trace_source_list.html is this right?

Konstantinos

unread,
Aug 19, 2015, 5:38:49 AM8/19/15
to ns-3-users
Hi Natalia, 

What you interpreted from the manual is wrong. In ANY case (moving or static) you can get the position of a node by accessing its MobilityModel.
I explained that here https://groups.google.com/d/msg/ns-3-users/RSG7e0zSgAk/8PxHAqqFCQAJ
However, in the special case of moving nodes, you have the trace source to 'update' you with the new position. You can see that the trace-source gives you a pointer to the MobilityModel for that node to easily access its position/speed.
In static nodes that's not needed since they are static. You can manually get the MobilityModel and access its position.

Regards,
K.

Natalia Molinero

unread,
Aug 19, 2015, 6:44:05 AM8/19/15
to ns-3-users
I got an error when I do this:

Ptr<Node> ue = ueNodes.Get (0);

Ptr<MobilityNodel> mobility = ue->GetObject<MobilityModel>();

Vector position = mobility->GetPosition();

I think there is no vector as I'm getting one user, but it could work for one user as well, right?

Konstantinos

unread,
Aug 19, 2015, 6:56:54 AM8/19/15
to ns-3-users
What type of error? Have you created any node in ueNodes and have you installed a MobiltyModel on that node/nodeContainer?

Natalia Molinero

unread,
Aug 19, 2015, 9:21:03 AM8/19/15
to ns-3-users
Thanks Konstantinos. This is the bit of code:

NodeContainer enbNodes;
  NodeContainer ueNodes;
  enbNodes.Create (1);
  ueNodes.Create (1);

  // Install Mobility Model
  MobilityHelper mobility;
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (enbNodes);
  BuildingsHelper::Install (enbNodes);
  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
  mobility.Install (ueNodes);
  BuildingsHelper::Install (ueNodes);

  // Create Devices and install them in the Nodes (eNB and UE)
  NetDeviceContainer enbDevs;
  NetDeviceContainer ueDevs;
  // Default scheduler is PF, uncomment to use RR
  //lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");


  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
  ueDevs = lteHelper->InstallUeDevice (ueNodes);

  // Attach a UE to a eNB
  lteHelper->Attach (ueDevs, enbDevs.Get (0));

Ptr<Node> ue = ueNodes.Get (0);

Ptr<MobilityNodel> mobility = ue->GetObject<MobilityModel>();
Vector position = mobility->GetPosition();

and this is the error:

Build failed
 -> task in 'lena-simple' failed (exit status 1):
    {task 139634471287952: cxx lena-simple.cc -> lena-simple.cc.10.o}
['/usr/bin/g++', '-O0', '-ggdb', '-g3', '-Wall', '-Werror', '-Wno-error=deprecated-declarations', '-fstrict-aliasing', '-Wstrict-aliasing', '-pthread', '-pthread', '-I.', '-I..', '-I/usr/include/gtk-2.0', '-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include', '-I/usr/include/atk-1.0', '-I/usr/include/cairo', '-I/usr/include/gdk-pixbuf-2.0', '-I/usr/include/pango-1.0', '-I/usr/include/gio-unix-2.0', '-I/usr/include/freetype2', '-I/usr/include/glib-2.0', '-I/usr/lib/x86_64-linux-gnu/glib-2.0/include', '-I/usr/include/pixman-1', '-I/usr/include/libpng12', '-I/usr/include/harfbuzz', '-I/usr/include/libxml2', '-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_SQLITE3=1', '-DHAVE_IF_TUN_H=1', '-DHAVE_GSL=1', '../src/lte/examples/lena-simple.cc', '-c', '-o', 'src/lte/examples/lena-simple.cc.10.o']

Thanks a lot!

Tommaso Pecorella

unread,
Aug 19, 2015, 9:33:41 AM8/19/15
to ns-3-users
Hi,

the error is in the line *above* the one you posted.
About the code, please attach the whole script, not just the snippet you think is throwing the error. Often the problem is elsewhere.

Have fun
T.

Natalia Molinero

unread,
Aug 19, 2015, 12:12:21 PM8/19/15
to ns-3-users
ooops! sorry! this is the error:

Waf: Entering directory `/home/natalia/Downloads/workspace/ns-allinone-3.22/ns-3.22/build'
[1149/2306] cxx: src/lte/examples/lena-simple.cc -> build/src/lte/examples/lena-simple.cc.10.o
../src/lte/examples/lena-simple.cc: In function ‘int main(int, char**)’:
../src/lte/examples/lena-simple.cc:82:5: error: ‘MobilityNodel’ was not declared in this scope

 Ptr<MobilityNodel> mobility = ue->GetObject<MobilityModel>();
     ^
../src/lte/examples/lena-simple.cc:82:18: error: template argument 1 is invalid

 Ptr<MobilityNodel> mobility = ue->GetObject<MobilityModel>();
                  ^
../src/lte/examples/lena-simple.cc:82:29: error: invalid type in declaration before ‘=’ token

 Ptr<MobilityNodel> mobility = ue->GetObject<MobilityModel>();
                             ^
../src/lte/examples/lena-simple.cc:82:29: error: conflicting declaration ‘int mobility’
../src/lte/examples/lena-simple.cc:61:18: error: ‘mobility’ has a previous declaration as ‘ns3::MobilityHelper mobility’
   MobilityHelper mobility;
                  ^
../src/lte/examples/lena-simple.cc:83:27: error: base operand of ‘->’ has non-pointer type ‘ns3::MobilityHelper’

 Vector position = mobility->GetPosition();
                           ^
../src/lte/examples/lena-simple.cc:83:8: error: unused variable ‘position’ [-Werror=unused-variable]

 Vector position = mobility->GetPosition();
        ^
cc1plus: all warnings being treated as errors


and I've attached the file. thanks a lot!
lena-simple.cc

Konstantinos

unread,
Aug 19, 2015, 12:16:08 PM8/19/15
to ns-3-users


On Wednesday, August 19, 2015 at 5:12:21 PM UTC+1, Natalia Molinero wrote:
ooops! sorry! this is the error:

Waf: Entering directory `/home/natalia/Downloads/workspace/ns-allinone-3.22/ns-3.22/build'
[1149/2306] cxx: src/lte/examples/lena-simple.cc -> build/src/lte/examples/lena-simple.cc.10.o
../src/lte/examples/lena-simple.cc: In function ‘int main(int, char**)’:
../src/lte/examples/lena-simple.cc:82:5: error: ‘MobilityNodel’ was not declared in this scope
 Ptr<MobilityNodel> mobility = ue->GetObject<MobilityModel>();
     ^

It is a typo. There is no MobilityNodel... it's MoblilityModel.
The compiler shows you exactly where the problem. Read the %$%@# output!

Natalia Molinero

unread,
Aug 19, 2015, 3:32:31 PM8/19/15
to ns-3-users
ouch! shhhh#t!! sorry guys! I'll correct tomorrow and see how it goes... %$%@#!!! gazie mille! :)

Natalia Molinero

unread,
Aug 20, 2015, 3:03:01 AM8/20/15
to ns-3-users
morning! there were a couple of %$%@# errors more, but it's finally working! :) I've attached it in case it could be usefulf for someone else. thanks a lot!!


El miércoles, 19 de agosto de 2015, 17:16:08 (UTC+1), Konstantinos escribió:
lena-simple.cc
Reply all
Reply to author
Forward
0 new messages