NS2メモ シナリオからC++へ

tclからC++C++からtclへ

set p_(0) [new Agent/Ping]
$ns_ attach-agent $node_(0) $p_(0)
set p_(1) [new Agent/Ping]
$ns_ attach-agent $node_(1) $p_(1)

$p_(0) set_foo 1
puts “[$p_(0) get_foo]”
$p_(1) set_foo 2
puts “[$p_(1) get_foo]”
Int PingAgent::command(int argc,const char*const* argv){
/*ここから*/
   if (strcomp(argv[1],”set_foo”)==0){
       foo = atoi(argv[2]);
       return (TCL_OK);//tclに帰る
   }
   if (strcomp(argv[1],”get_foo”)==0){
       Tcl::instance().resultf(“%d”,foo);//tclに返り値をもって帰る
       return (TCL_OK);
   }
/*ここまで*/
  • return (TCL\_OK),return (TCL\_ERROR)
  • Tcl::instance().resultf(“%d”,foo)
    • 呼び戻し元に値を返す
  • Tcl::instance().evalf("%s",foo)
    • Tclの関数を呼ぶ

tclからDSR

int DSRAgent::command(int argc, const char*const* argv) {
/*ここから*/
 if (strcasecmp(argv[1], "route_show") == 0){
  Path get_route;
  route_cache->findRoute(ID(atoi(argv[2]),::IP), get_route, 1);
  for( int i = 0 ; i < get_path.length() ; i++ ){
    printf("%s-",get_path[i].dump());
  }
  return TCL_OK;
 }
/*ここまで*/
SRNodeNew instproc dsr_route_show { } {
  $self instvar dsr_agent_
  $dsr_agent_ route_show 1
}
$ns_ at 3.0$node_(0) dsr_route_show”

tclからAODVとかDSDV

Node/MobileNode instproc route_show { } {
  set ragent [$self set ragent_]
  $ragent route_show
}
$ns_ at 3.0$node_(0) route_show”
int DSDV_Agent::command(int argc,const char *const *argv){
/*ここから*/
 if (strcasecmp(argv[1], "route_show") == 0){
  //任意に書く・・・
  return TCL_OK;
 }
/*ここまで*/

aodv解説

aodv.h
#define ACTIVE_ROUTE_TIMEOUT    15	// 50 seconds
//15秒したらルートが自動的に消える
(中略)
#define NETWORK_DIAMETER        10             // 30 hops(削除した)
//これはルート検索パケットのttlのデフォルトっぽいものを指定してる。