Let's explore how to get the attribute value of a node in `ns3` with the help of below code [2][3]. In the provided code, once the `using namespace ns3` statement is in place, you can directly access attributes and functions related to the ns3 namespace without explicitly using the `ns3::` scope resolution operator. All declarations from the ns3 namespace are now available within this scope.
```cpp
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/applications-module.h"
// First include all the necessary header files.
using namespace ns3;
int main()
{
// create the node
Ptr<Node> node = CreateObject<Node>();
// Set the attribute value
node->SetAttribute("Name1", StringValue("Node12"));
// Get attribute value
std::string name;
node->GetAttribute("Name1", StringValue(name));
// You can print the retrieved attribute value by utilizing the NS_LOG_INFO macro.
NS_LOG_INFO("Node name: " << name);
return 0;
}
```
For instance, you can directly utilize SomeAttributeType from the code to access the attribute type without specifying the "ns3" scope. The `GetAttribute` function is employed to retrieve the value of a node's attribute. It requires two arguments: the attribute's name and the reference where its value will be stored [6].
Note- Make sure you have` ns3` installed in your system [5].