test/storage.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 storage
       
    18 net::default_num_nodes 1
       
    19 
       
    20 manifest::file apps/dtntest/dtntest dtntest
       
    21 
       
    22 set storage_type berkeleydb
       
    23 foreach {var val} $opt(opts) {
       
    24     if {$var == "-storage_type" || $var == "storage_type"} {
       
    25 	set storage_type $val
       
    26     } else {
       
    27 	testlog error "ERROR: unrecognized test option '$var'"
       
    28 	exit 1
       
    29     }
       
    30 }
       
    31 
       
    32 dtn::config -storage_type $storage_type
       
    33 dtn::config_topology_common false
       
    34 
       
    35 proc rand_int {} {
       
    36     return [expr int(rand() * 1000)]
       
    37 }
       
    38 
       
    39 set source_eid1 dtn://host-0/storage-test-src-[rand_int]
       
    40 set source_eid2 dtn://host-0/storage-test-src-[rand_int]
       
    41 set dest_eid1   dtn://host-0/storage-test-dst-[rand_int]
       
    42 set dest_eid2   dtn://host-0/storage-test-dst-[rand_int]
       
    43 set reg_eid1    dtn://host-0/storage-test-reg-[rand_int]
       
    44 set reg_eid2    dtn://host-0/storage-test-reg-[rand_int]
       
    45 
       
    46 set payload    "storage test payload"
       
    47 
       
    48 proc check {} {
       
    49     global source_eid1 source_eid2
       
    50     global dest_eid1 dest_eid2
       
    51     global reg_eid1 reg_eid2
       
    52     global payload
       
    53 
       
    54     dtn::wait_for_bundle_stat 0 2 pending
       
    55 
       
    56     dtn::check_bundle_data 0 bundleid-0 \
       
    57 	    bundleid     0 \
       
    58 	    source       $source_eid1 \
       
    59 	    dest         $dest_eid1   \
       
    60 	    expiration   30	      \
       
    61 	    payload_len  [string length $payload]  \
       
    62 	    payload_data $payload
       
    63 
       
    64     dtn::check_bundle_data 0 bundleid-1 \
       
    65 	    bundleid     1              \
       
    66 	    source       $source_eid2   \
       
    67 	    dest         $dest_eid2     \
       
    68 	    expiration   10		\
       
    69 	    payload_len  [string length $payload]  \
       
    70 	    payload_data $payload
       
    71 
       
    72     dtn::check test_reg_exists 0 10
       
    73     dtn::check test_reg_exists 0 11
       
    74 
       
    75     dtn::check_reg_data 0 10   \
       
    76 	    regid          10        \
       
    77 	    endpoint       $reg_eid1 \
       
    78 	    expiration     10        \
       
    79 	    failure_action 1         \
       
    80 	    session_flags  0
       
    81 
       
    82 
       
    83     dtn::check_reg_data 0 11         \
       
    84 	    regid          11        \
       
    85 	    endpoint       $reg_eid2 \
       
    86 	    expiration     30        \
       
    87 	    failure_action 0         \
       
    88 	    session_flags  0
       
    89 }
       
    90 
       
    91 test::script {
       
    92     testlog "starting dtnd..."
       
    93     dtn::run_dtnd 0
       
    94     
       
    95     testlog "waiting for dtnd"
       
    96     dtn::wait_for_dtnd 0
       
    97 
       
    98     testlog "setting up flamebox ignores"
       
    99     tell_dtnd 0 log /test always \
       
   100 	    "flamebox-ignore ign scheduling IMMEDIATE expiration"
       
   101 
       
   102     testlog "injecting two bundles"
       
   103     tell_dtnd 0 bundle inject $source_eid1 $dest_eid1 $payload expiration=30
       
   104     tell_dtnd 0 bundle inject $source_eid2 $dest_eid2 $payload expiration=10
       
   105 
       
   106     testlog "running dtntest"
       
   107     dtn::run_dtntest 0
       
   108     dtn::wait_for_dtntest 0
       
   109 
       
   110     testlog "creating two registrations"
       
   111     set h [dtn::tell_dtntest 0 dtn_open]
       
   112     dtn::tell_dtntest 0 dtn_register $h endpoint=$reg_eid1 expiration=10 \
       
   113             failure_action=defer
       
   114     dtn::tell_dtntest 0 dtn_register $h endpoint=$reg_eid2 expiration=30 \
       
   115             failure_action=drop
       
   116     dtn::tell_dtntest 0 dtn_close $h
       
   117     
       
   118     testlog "checking the data before shutdown"
       
   119     check
       
   120 
       
   121     testlog "restarting dtnd without the tidy option"
       
   122     dtn::stop_dtnd 0
       
   123     after 2000
       
   124     dtn::run_dtnd 0 dtnd {}
       
   125     dtn::wait_for_dtnd 0
       
   126 
       
   127     testlog "checking the data after reloading the database"
       
   128     check
       
   129 
       
   130     testlog "shutting down dtnd"
       
   131     dtn::stop_dtnd 0
       
   132 
       
   133     testlog "waiting for expirations to elapse"
       
   134     after 10000
       
   135 
       
   136     testlog "restarting dtnd"
       
   137     dtn::run_dtnd 0 dtnd {}
       
   138     after 2000
       
   139     dtn::wait_for_dtnd 0
       
   140 
       
   141     testlog "checking that 1 bundle expired"
       
   142     dtn::check_bundle_stats 0 1 pending
       
   143 
       
   144     testlog "checking that 1 registration expired"
       
   145     dtn::check ! test_reg_exists 0 10
       
   146     dtn::check test_reg_exists 0 11
       
   147 
       
   148     testlog "waiting for the others to expire"
       
   149     after 20000
       
   150 
       
   151     testlog "checking they're expired"
       
   152     dtn::check_bundle_stats 0 0 pending
       
   153     dtn::check ! test_reg_exists 0 10
       
   154     dtn::check ! test_reg_exists 0 11
       
   155 
       
   156     testlog "restarting again"
       
   157     dtn::stop_dtnd 0
       
   158     after 5000
       
   159     dtn::run_dtnd 0 dtnd {}
       
   160     dtn::wait_for_dtnd 0
       
   161 
       
   162     testlog "making sure they're all really gone"
       
   163     dtn::check_bundle_stats 0 0 pending
       
   164     dtn::check ! test_reg_exists 0 10
       
   165     dtn::check ! test_reg_exists 0 11
       
   166 
       
   167     testlog "clearing flamebox ignores"
       
   168     tell_dtnd 0 log /test always \
       
   169 	    "flamebox-ignore ign scheduling IMMEDIATE expiration"
       
   170 }
       
   171 
       
   172 test::exit_script {
       
   173     testlog "Shutting down dtnd and dtntest"
       
   174     dtn::stop_dtntest 0
       
   175     dtn::stop_dtnd 0
       
   176 }