Discussion:
Get variable value from an application
Anny Caroline
2018-12-05 00:02:56 UTC
Permalink
Hi,

I'm devoloping an application following this tutorial:
https://www.nsnam.org/wiki/HOWTO_make_and_use_a_new_application

The application is called RequestResponseClient, and its based on
EchoServerClient.

I need to get the variable *m_sent* from my main application. So, I created
a public function called *GetPacketsSent *that should return this variable.

But, when I execute the main application (mainApplication.cc) I get a
Segmentation Fault.

A fun thing: If GetPacketsSent returns a number (for example, *return 1*)
everything works fine.
Function declared at RequestResponseClient.cc:
uint32_t
RequestResponseClient::GetPacketsSent (void)
{
NS_LOG_FUNCTION (this);
return m_sent;
} Function call at mainProgram.cc std::cout <<
filhos.Get(0)->GetObject<RequestResponseClient>()->GetPacketsSent() <<
std::endl;
------------------------------
HOWTO make and use a new application - Nsnam
<https://www.nsnam.org/wiki/HOWTO_make_and_use_a_new_application>
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.
Anny Caroline
2018-12-05 00:28:33 UTC
Permalink
Solved the problem changing

std::cout << filhos.Get(0)->GetObject<RequestResponseClient>()->GetDataSize()
<< std::endl; to

std::cout << filhosApp.Get(0)->GetObject<RequestResponseClient>()->GetDataSize()
<< std::endl;


Where *filhos* is a nodeCointer and *filhosApp *is an ApplicationContainer.
Looking again, makes more sense use *filhosApp* but I didn't understand why
*GetPacketsSent* returning 1 worked.

Em terça-feira, 4 de dezembro de 2018 22:02:56 UTC-2, Anny Caroline
Post by Anny Caroline
Hi,
https://www.nsnam.org/wiki/HOWTO_make_and_use_a_new_application
The application is called RequestResponseClient, and its based on
EchoServerClient.
I need to get the variable *m_sent* from my main application. So, I
created a public function called *GetPacketsSent *that should return this
variable.
But, when I execute the main application (mainApplication.cc) I get a
Segmentation Fault.
A fun thing: If GetPacketsSent returns a number (for example, *return 1*)
everything works fine.
uint32_t
RequestResponseClient::GetPacketsSent (void)
{
NS_LOG_FUNCTION (this);
return m_sent;
} Function call at mainProgram.cc std::cout <<
filhos.Get(0)->GetObject<RequestResponseClient>()->GetPacketsSent() <<
std::endl;
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.
Anny Caroline
2018-12-05 00:31:00 UTC
Permalink
Solved the problem changing my main application from
std::cout << filhos.Get(0)->GetObject<RequestResponseClient>()->
GetPacketsSent() << std::endl; to

std::cout << filhosApp.Get(0)->GetObject<RequestResponseClient>()->GetPacketsSent()
<< std::endl;


Where *filhos* is a nodeCointer and *filhosApp *is an ApplicationContainer.
Looking again, makes more sense use *filhosApp* but I didn't understand why
*GetPacketsSent* returning 1 worked.

Em terça-feira, 4 de dezembro de 2018 22:02:56 UTC-2, Anny Caroline
Post by Anny Caroline
Hi,
https://www.nsnam.org/wiki/HOWTO_make_and_use_a_new_application
The application is called RequestResponseClient, and its based on
EchoServerClient.
I need to get the variable *m_sent* from my main application. So, I
created a public function called *GetPacketsSent *that should return this
variable.
But, when I execute the main application (mainApplication.cc) I get a
Segmentation Fault.
A fun thing: If GetPacketsSent returns a number (for example, *return 1*)
everything works fine.
uint32_t
RequestResponseClient::GetPacketsSent (void)
{
NS_LOG_FUNCTION (this);
return m_sent;
} Function call at mainProgram.cc std::cout <<
filhos.Get(0)->GetObject<RequestResponseClient>()->GetPacketsSent() <<
std::endl;
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.
Loading...