#!/usr/bin/tclsh

set auto_path [linsert $auto_path 0 [file join /usr/cdrouter/lib]]

#
# -- load pktsrc
package require pktsrc

# -- set the ATM interface
set atm 0.0.35

puts "Running ATM loopback test on $atm"

# -- open the interface
set handle [ pktsrc open-atm-pvc $atm ]

# -- initial in count
set inCount 0

# -- number of packets to send
set target 500

# -- counter callback
$handle read { 
   global inCount
   incr inCount 
}

# -- build data packet with size 1024
set data [ string repeat af 1024 ]

# -- main loop
for { set c 1 } { $c <= $target } { incr c } {

   # -- display . for each send
   puts -nonewline "."
   flush stdout

   # -- send data
   $handle send $data
   Event_wait 10

   # -- handle line returns
   set needBreak [ expr $c % 72 ]
   if { "$needBreak" == "0" } {
      puts ""
      flush stdout
   }
}

puts ""

# -- show stats
puts "\nSent $target packets, received $inCount packets"

# -- check final results
if { "$target" != "$inCount" } {
   puts "Loopback test failed"
} else {
   puts "Loopback test passed"
}

puts ""

# -- that's it

