NS2 移动节点
在NS2中,无线网络的中心实现位于移动节点中。根据OOP概念,移动节点继承了其前身Regular Node的所有属性和行为,Regular Node请见其它参考资料。
移动节点
在图1中,移动节点由C++类MobileNode表示,它绑定到OTcl类Node/MobileNode。类层次结构仅在C++域中定义,其中C++类从类Node派生MobileNode,但OTcl类Node/MobileNode是顶级类。程序1显示C++类MobileNode的声明。除了从其父类继承的属性外,类MobileNode还定义了支持节点移动性的属性(例如,坐标(X_,Y_,Z_)和速度)。
程序1显示C++类MobileNode的声明。除了从其父类继承的属性外,类MobileNode还定义了支持节点移动性的属性(例如,坐标(X_,Y_,Z_)和速度)。
图1: 移动节点的类层次结构
程序1 绑定到OTcl类Node/Mobile的C++类MobileNode
//˜ns/common/mobile-node.h
1class MobileNode : public Node
2{
3protected:
4 double X_,Y_,Z_;//The current location
5 double speed_;//In meters per second
6 double dX_,dY_,dZ_;//Units
7 double destX_,destY_;//The destination
8 Event pos_intr_;
9 double position_update_time_;//Last updated position
10 double position_update_interval_; //Update interval
11 PositionHandler pos_handle_;//For random-motion only
12 private:
13 int random_motion_;//Are we running random
motion?
14 Topography *T_;//Define an area for moving
15 LIST_ENTRY(MobileNode) link_; //A global list of mobile nodes
16 };
//˜ns/common/mobile-node.cc
17 static class MobileNodeClass : public TclClass {
18 public:
19 MobileNodeClass() : TclClass("Node/MobileNode") {}
20 TclObject * create(int, const char*const*) {
21 return (new MobileNode);
22 }
23 } class_mobilenode;