Chinaunix首页 | 论坛 | 博客
  • 博客访问: 537496
  • 博文数量: 126
  • 博客积分: 2071
  • 博客等级: 大尉
  • 技术积分: 1522
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-24 16:09
文章分类
文章存档

2013年(8)

2012年(37)

2011年(80)

2010年(1)

分类: 网络与安全

2013-04-28 01:04:53

1.tcl脚本传入一个int变量给c++代码
在command解析里
int nodenum=atoi(argv[2]);
printf("%d",nodenum);

2.nam中输出结果
Tcl::instance().evalf("$ns trace-annotate \"node send d_\"");

3.改变node颜色
$node1 color red

4.注册顶级命令
即tcl脚本写init_topology

class InitTopologyCommand : public TclCommand {
public:
InitTopologyCommand() : TclCommand("init_topology") { }
virtual int command(int, const char*const*) {
printf("wocao!\n");
return (TCL_OK);
}
};

在'/usr/local/ns2/ns-allinone-2.34/ns-2.34/common/misc.cc'
中包含你写类的头文件

在void init_misc(void)
{
(void)new InitTopologyCommand;
(void)new VersionCommand;
(void)new RandomCommand;
(void)new TimeAtofCommand;
(void)new HasInt64Command;
(void)new HasSTLCommand;
}
添加你自己的类即可

5.c++返回一个值给tcl脚本使用
现在tcl脚本定义变量
set varname 0
再在c++中调用Tcl示例

Tcl &tcl=Tcl::Instance();
tcl.evalf("set varname_ %d",var_in_c++);
即可

6.c++获得ns2系统时间
double
Scheduler::instance().clock();

7.c++获得ns2节点名字
在继承自tclobject之上的类
%s ,name()
===============================================================
没用到的

==============================================================


C++中如何得到节点的移动速度、坐标、移动方向

1.利用下面方法获得节点对象,其中nsaddr_t为节点ID.


static Node* get_node_by_address(nsaddr_t);


2.利用下列方法获取这个节点Node里面有获得节点坐标的方法,看看 mobilenode.cc


3.hdr_cmn结构体是什么意思
Ns-2中包结构包括:
一个报头(Header)堆栈,
一个可选择的数据空间。

hdr_cmn是包头堆栈中的一个重要报头,也就是我们常说的common头,他是数据包传输的关键域,不能被精简。

struct hdr_cmn {
double ts_;
packet_t ptype_;
int uid_;
int size_;
int iface_;


static int offset_;
inline static int& offset() { return offset_; }
inline static hdr_cmn* access(Packet* p) {
return (hdr_cmn*) p->access(offset_);
}


int& ptype() { return (ptype_); }
int& uid() { return (uid_); }
int& size() { return (size_); }
int& iface() { return (iface_); }
double& timestamp() { return (ts_); }
};

时间戳   用于测量每个交换节点的排队时延

ptype_   被调度程序用来确定分组的类型

uid_     被调度程序用于调度分组的到达

size_    是以bytes为单位的虚拟分组的大小


hdr_cmn::access()

接口函数,用来访问数据包(packet)中的这个报头部分,common头是必须得有的!当然一般情况下,你也不得够将其删除(代码中有特殊处理),除非你去修改源码(不过这将导致意料不到的错误)!

阅读(1635) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~