Chinaunix首页 | 论坛 | 博客
  • 博客访问: 63175
  • 博文数量: 46
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2017-04-22 16:11
文章分类
文章存档

2017年(46)

我的朋友

分类: 系统运维

2017-05-16 14:57:21

例如要在Agent/MFlood C++类中调用tcl的Agent/MFlood类中的方法,具体如下:

1.在你的TCL脚本中定义下列过程

Agent/MFlood instproc putargs {} {

    puts " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^"

}

2.然后在c++类中如下方式调用

  char out[100];

sprintf(out, "%s putargs", name());

Tcl& tcl = Tcl::instance();    

tcl.eval(out);//调用函数。

3.应用举例

  例如在C++代码中需要调用CBR数据流,调用的场景如果网络中的node0节点向node1节点发送了一个资源请求信息,则节点node1向节点node0发送一个持续30庙的cbr数据流,只需要在node0的代理里面调用下列过程即可,

 下面函数的含义是:在starttm时刻本节点(node0)向节点node($args)发送了一个持续时间为30秒的CBR数据流

Agent/MFlood instproc putargs {args starttm} {

global ns_ tracefd 

 $self instvar node_

puts "CBR START^_^1 at $starttm node[$node_ id] send a cbr to node$args"

set udp_(0) [new Agent/UDP]

$ns_ attach-agent $node_ $udp_(0)

set null_(0) [new Agent/Null]

# $ns_ attach-agent $node_($args) $null_(0)

$ns_ connect $udp_(0) $null_(0)

set cbr_(0) [new Application/Traffic/CBR]

$cbr_(0) set packetSize_ 512

$cbr_(0) set interval_ 4.0

$cbr_(0) set random_ 1

$cbr_(0) set maxpkts_ 10000

$cbr_(0) attach-agent $udp_(0)

$ns_ at $starttm "$cbr_(0) start"

$ns_ at [expr $starttm+30.0 ] "$cbr_(0) stop"

}

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