test/ondemand-links.tcl
changeset 0 2b3e5ec03512
equal deleted inserted replaced
-1:000000000000 0:2b3e5ec03512
       
     1 #
       
     2 #    Copyright 2006 Intel Corporation
       
     3 # 
       
     4 #    Licensed under the Apache License, Version 2.0 (the "License");
       
     5 #    you may not use this file except in compliance with the License.
       
     6 #    You may obtain a copy of the License at
       
     7 # 
       
     8 #        http://www.apache.org/licenses/LICENSE-2.0
       
     9 # 
       
    10 #    Unless required by applicable law or agreed to in writing, software
       
    11 #    distributed under the License is distributed on an "AS IS" BASIS,
       
    12 #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    13 #    See the License for the specific language governing permissions and
       
    14 #    limitations under the License.
       
    15 #
       
    16 
       
    17 test::name ondemand-links
       
    18 net::num_nodes 3
       
    19 
       
    20 set cl tcp
       
    21 set link_opts "idle_close_time=5"
       
    22 
       
    23 for {set i 0} {$i < [llength $opt(opts)]} {incr i} {
       
    24     set var [lindex $opt(opts) $i]
       
    25     if {$var == "-cl" || $var == "cl"} {
       
    26 	set val [lindex $opt(opts) [incr i]]
       
    27 	set cl $val
       
    28     } elseif {$var == "fast" || $var == "-fast_retries"} {
       
    29 	append link_opts " min_retry_interval=1 max_retry_interval=10 data_timeout=1000"
       
    30     } else {
       
    31 	puts "ERROR: unrecognized test option '$var'"
       
    32 	exit 1
       
    33     }
       
    34 }
       
    35 
       
    36 dtn::config
       
    37 dtn::config_interface $cl
       
    38 
       
    39 dtn::config_linear_topology ONDEMAND $cl true $link_opts
       
    40 
       
    41 test::script {
       
    42     testlog "running dtnds"
       
    43     dtn::run_dtnd *
       
    44 
       
    45     testlog "waiting for dtnds to start up"
       
    46     dtn::wait_for_dtnd *
       
    47 
       
    48     set source    dtn://host-0/test
       
    49     set dest      dtn://host-2/test 
       
    50 
       
    51     dtn::tell_dtnd 2 tcl_registration $dest
       
    52 
       
    53     testlog "checking that link is available "
       
    54     dtn::wait_for_link_state 0 $cl-link:0-1 AVAILABLE
       
    55     
       
    56     testlog "sending bundle"
       
    57     set timestamp [dtn::tell_dtnd 0 sendbundle $source $dest]
       
    58 
       
    59     testlog "waiting for bundle arrival"
       
    60     dtn::wait_for_bundle 2 "$source,$timestamp" 5
       
    61     
       
    62     testlog "sanity checking stats"
       
    63     dtn::wait_for_bundle_stats 0 {1 received 1 transmitted} 5
       
    64     dtn::wait_for_bundle_stats 1 {1 received 1 transmitted} 5
       
    65     dtn::wait_for_bundle_stats 2 {1 received 0 transmitted} 5
       
    66 
       
    67     testlog "checking that link is open"
       
    68     dtn::wait_for_link_state 0 $cl-link:0-1 OPEN
       
    69 
       
    70     testlog "killing daemon 1"
       
    71     dtn::stop_dtnd 1
       
    72     
       
    73     testlog "checking that link is unavailable"
       
    74     dtn::wait_for_link_state 0 $cl-link:0-1 UNAVAILABLE
       
    75 
       
    76     testlog "sending another bundle"
       
    77     set timestamp [dtn::tell_dtnd 0 sendbundle $source $dest]
       
    78 
       
    79     testlog "waiting for a few retry timers"
       
    80     after 10000
       
    81     
       
    82     testlog "checking that link is still UNAVAILABLE"
       
    83     dtn::wait_for_link_state 0 $cl-link:0-1 UNAVAILABLE
       
    84     
       
    85     testlog "restarting daemon 1"
       
    86     dtn::run_dtnd 1
       
    87     dtn::wait_for_dtnd 1
       
    88     
       
    89     testlog "checking that link is AVAILABLE or OPEN"
       
    90     dtn::wait_for_link_state 0 $cl-link:0-1 {AVAILABLE OPEN}
       
    91 
       
    92     testlog "waiting for bundle arrival"
       
    93     dtn::wait_for_bundle 2 "$source,$timestamp" 5
       
    94     
       
    95     testlog "sanity checking stats"
       
    96     dtn::wait_for_bundle_stats 0 {2 received 2 transmitted} 5
       
    97     dtn::wait_for_bundle_stats 1 {1 received 1 transmitted} 5
       
    98     dtn::wait_for_bundle_stats 2 {2 received 0 transmitted} 5
       
    99 
       
   100     testlog "waiting for the idle timer to close the link"
       
   101     dtn::wait_for_link_state 0 $cl-link:0-1 AVAILABLE
       
   102 
       
   103     testlog "forcibly setting the link to unavailable"
       
   104     dtn::tell_dtnd 0 link set_available $cl-link:0-1 false
       
   105     dtn::wait_for_link_state 0 $cl-link:0-1 UNAVAILABLE
       
   106 
       
   107     testlog "sending another bundle, checking that the link stays closed"
       
   108     set timestamp [dtn::tell_dtnd 0 sendbundle $source $dest]
       
   109     dtn::wait_for_link_state 0 $cl-link:0-1 UNAVAILABLE
       
   110 
       
   111     testlog "resetting the link to available, checking that it opens"
       
   112     dtn::tell_dtnd 0 link set_available $cl-link:0-1 true
       
   113     dtn::wait_for_link_state 0 $cl-link:0-1 OPEN
       
   114     
       
   115     testlog "waiting for bundle arrival"
       
   116     dtn::wait_for_bundle 2 "$source,$timestamp" 5
       
   117 
       
   118     testlog "forcibly closing the link"
       
   119     dtn::tell_dtnd 0 link close $cl-link:0-1
       
   120     dtn::wait_for_link_state 0 $cl-link:0-1 UNAVAILABLE
       
   121     
       
   122     testlog "resetting the link to available, checking that it's not yet open"
       
   123     dtn::tell_dtnd 0 link set_available $cl-link:0-1 true
       
   124     dtn::wait_for_link_state 0 $cl-link:0-1 AVAILABLE
       
   125     
       
   126     testlog "forcibly opening the link"
       
   127     dtn::tell_dtnd 0 link open $cl-link:0-1
       
   128     dtn::wait_for_link_state 0 $cl-link:0-1 OPEN
       
   129     
       
   130     testlog "test success!"
       
   131 }
       
   132 
       
   133 test::exit_script {
       
   134     testlog "stopping all dtnds"
       
   135     dtn::stop_dtnd *
       
   136 }