在无线网络模拟中,借助God可以获得整个网络的一些全局性信息。在有些情况下,这些信息非常必要,比如要判断两个相邻无线节点是否在传输范围之类。
NS2对God的支持在C++空间中主要是God类,该类分别声明和实现在ns-2.30/mobile/god.h文件和ns-2.30/mobile/god.cc文件中(我使用的是ns-2.30版)。
Notebook: How to Get Neighbors of a Mobile Node in Wireless Simulation
1. Get the number of nodes in the network
2. In order to use God object in C++ code, in your simluation script, you should have
3. In order to check that if node j is node i's neighbor, use the following function.
4. In oder to use IsNeighbor function in C++ code, either add EnergyModel in simulation script, (please refer to NS Manual Chapter 19 for detail)
or change the IsNeighbor function in mobile/god.cc (disable energy checking)
转自
http://www.cse.msu.edu/~wangbo1/ns2/nshowto2.html
NS2对God的支持在C++空间中主要是God类,该类分别声明和实现在ns-2.30/mobile/god.h文件和ns-2.30/mobile/god.cc文件中(我使用的是ns-2.30版)。
Notebook: How to Get Neighbors of a Mobile Node in Wireless Simulation
1. Get the number of nodes in the network
#include <god.h> God::instance()->nodes(); |
2. In order to use God object in C++ code, in your simluation script, you should have
# Create God set god_ [create-god $opt(nn)] for {set i 0} {$i < $opt(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion $god_ new_node $node_($i) } |
3. In order to check that if node j is node i's neighbor, use the following function.
God::instance()->IsNeighbor(i , j); |
4. In oder to use IsNeighbor function in C++ code, either add EnergyModel in simulation script, (please refer to NS Manual Chapter 19 for detail)
$ns_ node-config -energyModel $energymodel \ -rxPower $p_rx \ -txPower $p_tx \ -initialEnergy $initialenergy \ |
or change the IsNeighbor function in mobile/god.cc (disable energy checking)
bool God::IsNeighbor(int i, int j) { assert(i<num_nodes && j<num_nodes); /* if (mb_node->energy_model()->node_on() == false || mb_node[j]->energy_model()->node_on() == false || mb_node->energy_model()->energy() <= 0.0 || mb_node[j]->energy_model()->energy() <= 0.0 ) { return false; } */ vector a(mb_node->X(), mb_node->Y(), mb_node->Z()); vector b(mb_node[j]->X(), mb_node[j]->Y(), mb_node[j]->Z()); vector d = a - b; if (d.length() < RANGE) return true; else return false; } |