Commit 6bade308 authored by Mac Newbold's avatar Mac Newbold

Removed. Funtionality replaced by snmpit.

parent 3516ad32
#!/usr/local/bin/expect
######################################################################
# copyconfig.exp
#
# Syntax:
# copyconfig.exp <switch>:<password> save <file>
# copyconfig.exp <switch>:<password> load <file>
# Environment:
# CC_SERVER is the ip address of the tftp server
# CC_PATH is the path to a directory on the tftp server accessable by
# the user.
# CC_LOCAL_PATH path to CC_PATH from the ftp server
# This connects to <switch> an Intel 510T switch running vs 2.42 and
# loads or saves a file.
#
# HOW:
# Saving: access switch, create world writable file on tftp server, copy to
# given path.
# Loading: access switch, copy file to tftp server, make wordl readable.
# Delete all created files/directories.
######################################################################
# DEFAULTS (Flux Group)
set CC_SERVER 155.99.214.88
set CC_PATH /n/moab/export/dnard/copyconfig
set CC_LOCAL_PATH /export/dnard/copyconfig
# parse argv
if {[llength $argv] != 3} {
puts "Syntax: $argv0 <switch>:<password> <save|load> <file>"
exit 1
}
set Delete {}
set sinfo [lindex $argv 0]
set mode [lindex $argv 1]
set file [lindex $argv 2]
set t [split $sinfo :]
set switch [lindex $t 0]
set pw [lindex $t 1]
if {$mode != "save" && $mode != "load"} {
puts stderr "Mode must be save or load"
exit 1
}
proc dotimeout {s} {
puts stderr "Timeout: $s"
exit 1
}
puts "Connecting to switch..."
spawn telnet $switch
log_user 0
set timeout 10
expect {
"Login" {}
timeout {dotimeout "Waiting for Login prompt"}
}
set timeout 10
puts "Logging in..."
send "a"
expect {
"password:" {}
timeout {dotimeout "Waiting for Password prompt"}
}
send "$pw\n"
expect {
"Local Management" {}
timeout {dotimeout "Waiting for Management Menu"}
}
puts "Manipulating..."
send "c"
expect {
"Configuration" {}
timeout {dotimeout "Waiting for Configuration Menu"}
}
if {$mode == "save"} {
send "a"
expect {
"Save to server" {}
timeout {dotimeout "Waiting for Save to server"}
}
for {set i 0} {$i < 20} {incr i} {
send "$Delete"
}
send "$CC_SERVER\n"
expect {
"Configuration file path" {}
timeout {dotimeout "Waiting for Configuration file path"}
}
for {set i 0} {$i < 60} {incr i} {
send "$Delete"
}
send "$CC_LOCAL_PATH\n"
expect {
-re {Will save file:[ ]*([/a-zA-Z0-9]+\.p)} {
set fpath $expect_out(1,string)
puts "File path: $fpath"
}
timeout {dotimeout "Waiting for file path"}
}
set lpath $CC_PATH/[file tail $fpath]
close [open $lpath "w"]
file attributes $lpath -permissions "00666"
expect {
"Confirm save to server?" {}
timeout {dotimeout "Waiting for confirm"}
}
send "y"
expect {
"press any key" {}
timeout {dotimeout "Waiting for status"}
}
file copy $lpath $file
} else {
send "o"
expect {
"Load from server" {}
timeout {dotimeout "Waiting for Load from server"}
}
for {set i 0} {$i < 20} {incr i} {
send "$Delete"
}
send "$CC_SERVER\n"
expect {
"Configuration file path" {}
timeout {dotimeout "Waiting for Configuration file path"}
}
for {set i 0} {$i < 60} {incr i} {
send "$Delete"
}
send "$CC_LOCAL_PATH\n"
expect {
-re {Will load file:[ ]*([/a-zA-Z0-9]+\.p)} {
set fpath $expect_out(1,string)
puts "File path: $fpath"
}
timeout {dotimeout "Waiting for file path"}
}
set lpath $CC_PATH/[file tail $fpath]
puts "! $lpath"
file copy $file $lpath
file attributes $lpath -permissions "00644"
expect {
"Confirm load from server?" {}
timeout {dotimeout "Waiting for confirm"}
}
send "y"
expect {
"File does not exist" {
puts stderr "Error: Could not load file"
exit 1
}
"press any key" {}
timeout {dotimeout "Waiting for status"}
}
}
send " qqql"
#file delete $lpath
puts "Transfer finished."
close
#!/bin/csh -f
set xxx=0
while ( -e time$xxx.log)
set xxx=`expr $xxx + 1`
end
echo "Using file time$xxx.log"
set file = time$xxx.log
unset xxx
echo "Pinging..."
ping -c 10 -q 155.99.214.170 >! pinged
grep -i received pinged >! ping2
set x = `cat ping2 | awk '{print $4}'`
echo "Received $x packets of 10..."
if ( $x < 1 ) then
echo "Switch down... try again later."
exit 1
endif
rm ping2
rm pinged
unset x
echo "Starting..."
echo ""
echo ""
#time to wait between tests in milliseconds
if ( $1 > 0 ) then
set delay=$1
else if ($1 < 0) then
set delay=0
else
set delay=2500
endif
echo "Wait between tests is set by the command line parameter,"
echo "an integer number of milliseconds, or -1 for no wait."
echo "Using wait time of $delay milliseconds."
echo "CAUTION: Too little wait will cause failures. Recommended Range"
echo " is from 1 second to 5 seconds. Wait time does NOT"
echo " affect the time each command takes to execute."
echo ""
echo ""
echo "This will test ports 1-24, 5 tests, 10 times per port."
echo "That will be 1200 tests. They take on the average 10 seconds"
echo "including the wait time. This will take about 3 to 3.5 hours."
echo ""
echo ""
foreach port ( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 )
echo ""
echo ""
echo "Testing Port $port..."
echo ""
echo ""
foreach i ( 1 2 3 4 5 6 7 8 9 10 )
echo ""
echo "Round $i of 10"
echo ""
pause.tcl $delay
/usr/bin/time -a -o $file setport.exp Alpha:TestBox $port -b
pause.tcl $delay
/usr/bin/time -a -o $file setport.exp Alpha:TestBox $port -f -a
pause.tcl $delay
/usr/bin/time -a -o $file setport.exp Alpha:TestBox $port -d Full -s 100
pause.tcl $delay
/usr/bin/time -a -o $file setport.exp Alpha:TestBox $port -d Half -s 10
pause.tcl $delay
/usr/bin/time -a -o $file setport.exp Alpha:TestBox $port -a
end
end
unset port
unset i
unset delay
echo ""
echo ""
echo "24 ports x 5 tests each x 10 reps = 1200 times logged"
echo "Results in $file"
echo ""
echo "Starting logger..."
echo ""
exec logger $file
unset file
#!/usr/local/bin/tclsh
#
# Usage:
#
# pause <ms>
#
# Pauses for <ms> milliseconds.
set ms [lindex $argv 0]
if {! [regexp {[0-9]+} $ms]} {
puts stderr "Usage: $argv0 <ms>"
puts stderr "Pauses for <ms> milliseconds."
exit 1
} else {
after $ms
}
#!/usr/local/bin/expect
######################################################################
# setport.exp
#
# Syntax:
# setport.exp <switch>:<password> <port> [-c][-f][-a]
# setport.exp <switch>:<password> <port> [-c][-f][-d duplex][-s speed]
# setport.exp <switch>:<password> <port> [-c] -b
# duplex = Half or Full
# speed = 10 or 100
# -a = Auto Negotiate Mode (duplex and speed are auto configured)
# -b = Break Link
# -c = Copy configuration to every port on the switch
# -f = Fix Link
#
# This connects to <switch> an Intel 510T switch running vs 2.42 and
# adjusts the port settings.
######################################################################
# parse argv
# argv must have the switch:password element, the port, and at least 1 more
if {[llength $argv] < 3} {
puts "\nSyntax:\n"
puts "$argv0 <switch>:<password> <port> \[-c\] \[-f\] \[-a\]"
puts -nonewline "$argv0 <switch>:<password> <port> \[-c\] "
puts "\[-f\] \[-d duplex\] \[-s speed\]"
puts "$argv0 <switch>:<password> <port> \[-c\] -b"
puts "\n<switch> = Alpha or Beta"
puts "<duplex> = Half or Full"
puts "<speed> = 10 or 100"
puts "-a = Auto Negotiate Mode (duplex and speed are auto configured)"
puts "-b = Break Link"
puts "-c = Copy configuration to every port on the switch"
puts "-f = Fix Link"
exit 1
}
set KeyDown {}
set sinfo [lindex $argv 0]
set port [lindex $argv 1]
set duplex "same"
set speed "same"
set disable 0
set enable 0
set auto 0
set copy 0
set done 0
for {set arg 2} { $arg < [llength $argv] && !$done} { incr arg} {
set option [lindex $argv $arg]
if {$option == "-c"} {
set copy 1
continue
}
if {$option == "-b"} {
set disable 1
set done 1
continue
}
if {$option == "-f"} {
set enable 1
continue
}
if {$option == "-a"} {
set auto 1
set done 1
continue
}
if {$option == "-d"} {
incr arg
set duplex [lindex $argv $arg]
continue
}
if {$option == "-s"} {
incr arg
set speed [lindex $argv $arg]
continue
}
puts stderr "Invalid option: $option"
exit 1
}
set t [split $sinfo :]
set switchname [lindex $t 0]
set pw [lindex $t 1]
if { $switchname == "Alpha" } {
set switch "155.99.214.170"
} else {
if { $switchname == "Beta" } {
set switch "155.99.214.171"
} else {
puts stderr "Error: Unknown switch"
puts stderr "Please specify Alpha or Beta"
exit 1
}
}
if {$duplex != "Half" && $duplex != "Full" && $duplex != "same"} {
puts stderr "Error: <duplex> must be Half or Full"
exit 1
}
if {$speed != "10" && $speed != "100" && $speed != "same"} {
puts stderr "Error: <speed> must be 10 or 100"
exit 1
}
if {! [regexp {[0-9]+} $port]} {
puts stderr "Error: <port> must be a positive number"
exit 1
} else {
if {$port > 24} {
puts stderr "Error: Cannot configure port $port on a 24 port switch."
exit 1
} else {
if {$port < 1} {
puts stderr "Error: Port $port is invalid."
exit 1
}
}
}
puts "\nSwitch : $switchname ($switch)"
puts "Port : $port"
if {$disable} {
puts "Disable Port."
}
if {$enable} {
puts "Enable Port."
}
if {$auto} {
puts "Enable Port Auto-Negotiation of duplex/speed."
}
if {$duplex!="same"} {
puts "Change Duplex to $duplex."
}
if {$speed!="same"} {
puts "Change Speed to $speed."
}
if {$copy} {
puts "Copy configuration to all ports."
}
proc dotimeout {s} {
puts stderr "\n\n*****Timeout: $s\n"
exit 1
}
puts "\nConnecting to switch..."
set t0 [clock clicks]
log_user 0
spawn telnet $switch
set t1 [clock clicks]
#14,000-17,000
set timeout 10
expect {
"Login" {}
timeout {dotimeout "Waiting for Login prompt"}
}
set timeout 10
puts "Logging in..."
set t2 [clock clicks]
#80,000-85,000
send "a"
expect {
"password:" {}
timeout {dotimeout "Waiting for Password prompt"}
}
send "$pw\n"
expect {
"Local Management" {}
timeout {dotimeout "Waiting for Management Menu"}
}
set t3 [clock clicks]
#930,000 - 110,000
send "c"
expect {
"Configuration" {}
timeout {dotimeout "Waiting for Configuration Menu"}
}
send "u"
expect {
"Quick Setup" {}
timeout {dotimeout "Waiting for Quick Setup"}
}
send "p"
expect {
"Port Parameter Setup" {}
timeout {dotimeout "Waiting for Port Parameter Setup"}
}
# Go in, and back out and and go back in - verifies that we're on 1
send "q"
expect {
"Quick Setup" {}
timeout {dotimeout "Waiting for Quick Setup"}
}
send "p"
expect {
"Port Parameter Setup" {}
timeout {dotimeout "Waiting for Port Parameter Setup"}
}
puts "Selecting Port $port..."
set t4 [clock clicks]
#2,400,000!!!
for {set i 1} {$i < $port} {incr i} {
if { $i == 17} {
send $KeyDown
}
send $KeyDown
}
set t5 [clock clicks]
#1044
send "s"
expect {
-re {Configure Port ([0-9]+)} {
set cport $expect_out(1,string)
if {$cport != $port} {
puts stderr "\n***Error: Somehow configuring port $cport instead!"
exit 1
}
}
timeout {dotimeout "Waiting for Configure Port $port"}
}
puts "Configuring..."
set t6 [clock clicks]
#2,000,000
expect {
-re {Port state[^:]*:[ ]+([A-Za-z]+)} {
set state $expect_out(1,string)
if {$state == "Enabled" && $disable} {
send " "
set state "Disabled"
} else {
if {$state == "Disabled" && $enable} {
send " "
set state "Enabled"
} else {
if { $state == "Disabled" && ! $disable} {
puts -nonewline stderr "\n***Port Disabled."
puts stderr " Cannot configure. Use -f Option."
}
}
}
}
timeout {dotimeout "Waiting for Port state"}
}
send "\n\r"
# If disabled, skips to copy these settings....
set t7 [clock clicks]
#400,000
if { $state == "Enabled"} {
expect {
-re {Auto-negotiation[^:]*:[ ]+([A-Za-z]+)} {
set autostate $expect_out(1,string)
if {$autostate != "Enabled" && $autostate != "Disabled"} {
puts stderr "Error: Invalid Auto-Negotiation State ($state)"
exit 1
}
if { $autostate == "Enabled" && !$auto } {
send " "
set autostate "Disabled"
} else {
if { $autostate == "Disabled" && $auto } {
send " "
set autostate "Enabled"
}
}
}
timeout {dotimeout "Waiting for Auto-Negotiation State"}
}
send "\n\r"
set t8 [clock clicks]
#32,000
# If $autostate enabled, skip to forwarding
if { $autostate == "Disabled" } {
expect {
-re {Duplex[^:]*:[ ]+([A-Za-z]+)} {
set pduplex $expect_out(1,string)
if {$pduplex != "Half" && $pduplex != "Full"} {
puts stderr "Error: Invalid Duplex State ($pduplex)"
exit 1
}
if {$duplex != "same"} {
if { $pduplex != $duplex } {
send " "
} else {
set duplex "same"
}
}
}
timeout {dotimeout "Waiting for Duplex State"}
}
send "\n\r"
expect {
-re {Speed[^:]*:[ ]+([0-9]+)Mbps} {
set pspeed $expect_out(1,string)
if { $autostate == "Disabled" } {
if {$pspeed != "10" && $pspeed != "100"} {
puts stderr "Error: Invalid Speed ($pspeed)"
exit 1
}
if {$speed != "same"} {
if {$pspeed != $speed } {
send " "
} else {
set speed "same"
}
}
}
}
timeout {dotimeout "Waiting for Speed State"}
}
send "\n\r"
}
#This ends $autostate=="Enabled"
expect {
"Forwarding mode" {}
timeout {dotimeout "Waiting for Forwarding Mode"}
}
send "\n\r"
expect {
"Flow control" {}
timeout {dotimeout "Waiting for Flow control"}
}
send "\n\r"
}
#This ends $state == "Enabled"
set t9 [clock clicks]
expect {
"Copy these settings" {}
timeout {dotimeout "Waiting for Copy these settings"}
}
if {$copy} {
send "y"
} else {
send "n"
}
send "\n\r"
expect {
"Confirm these settings?" {}
timeout {dotimeout "Waiting for Confirm these settings"}
}
send "y"
expect {
"Port Parameter Setup" {}
timeout {dotimeout "Waiting for return of Port Parameter Setup"}
}
send "qqqql"
set t10 [clock clicks]
puts "Configured Port $port on switch $switchname ($switch)"
puts " Current Port State : $state"
if {$state == "Enabled"} {
puts "Speed/Duplex Auto-Negotiation : $autostate"
if { $duplex != "same" || $speed != "same" } {
puts "Changed ($pduplex, $pspeed) to ($duplex, $speed)"
} else {
if { $autostate == "Disabled" } {
puts " Current Duplex Setting : $pduplex"
puts " Current Speed Setting : $pspeed"
}
}
}
if {$copy} {
puts "Configuration copied to all ports"
}
puts stderr "Spawn telnet:"
puts stderr "[expr $t1 - $t0]ms"
puts stderr "First Menu:"
puts stderr "[expr $t2 - $t1]ms"
puts stderr "Login/Password:"
puts stderr "[expr $t3 - $t2]ms"
puts stderr "Port Setup Menu:"
puts stderr "[expr $t4 - $t3]ms"
puts stderr "Select Port:"
puts stderr "[expr $t5 - $t4]ms"
puts stderr "Port Config Menu:"
puts stderr "[expr $t6 - $t5]ms"
puts stderr "Port State:"
puts stderr "[expr $t7 - $t6]ms"
puts stderr "AutoConfig State:"
puts stderr "[expr $t8 - $t7]ms"
puts stderr "Finish Config:"
puts stderr "[expr $t9 - $t8]ms"
puts stderr "Exit Telnet:"
puts stderr "[expr $t10 - $t9]ms"
puts stderr ""
puts stderr "Total Time:"
puts stderr "[expr $t10 - $t0]ms"
puts "\n"
close
#!/usr/local/bin/tclsh
# given the testbed intermediate representation (IR) on stdin,
# modify switch config file to contain new vlan information.
# currently, switch config file format is detailed in ~place/vlan/format-iq.
# vlan names must already be known to switch
proc config_switch name {
global argv0
switch $name {
alpha {set filename iqadbad4.p}
beta {set filename iqad24c3.p}
default {
puts stderr "$argv0 : switch name $name is not valid"
exit 1
}
}
if {[catch "open $filename r+" iqadfile]} {
puts stderr "$argv0 $errorInfo"
exit 1
}
# switch_name to stdout
puts -nonewline "$name VLANs:"
set iqadcontents [read $iqadfile]
set DSA [string first "STDALONE" $iqadcontents]
# DSA == Domain String Address. everything I want is at a fixed offset from
# this string
# clear any existing VLAN info
seek $iqadfile [expr $DSA + 0x22]
for {set i 0} {$i < 0x1f3} {incr i} {
puts -nonewline $iqadfile "\0\0\0\0\0\0\0\0"
}
seek $iqadfile [expr $DSA + 0x22]
# for a switch, each line goes as follows:
# vlan_name port port port port port ...
while {[gets stdin line] >=0} {
# comment found
if {[regexp -nocase {^[ \t]*#} $line]} {continue}
#empty line
if {[regexp -nocase {^[ \t]*$} $line]} {continue}
# "end" of switch config
if {[regexp -nocase {^[ \t]*end[ \t]*$} $line]} {break}
# vlan name is first field
set line [split [string trim $line]]
# write NULL-terminated VLAN name
set vlanname [lindex $line 0]
puts -nonewline " $vlanname"
puts -nonewline $iqadfile $vlanname
puts -nonewline $iqadfile [format "%c" 0]
#field length 0x14 bytes (-1 for the \0 byte)
seek $iqadfile [expr 0x13-[string length $vlanname]] current
#every port has a magic unique number.
#they start at 0xc9 for no discernible reason
set magicnumber 0xc9
# port list
set listsize [llength $line]
for {set i 1} {$i < $listsize} {incr i} {
set port [lindex $line $i]
# split may have given ""s when encountering whitespace
if {$port != ""} {
lappend ports $port
}
}
set ports [lsort -integer $ports]
set listsize [llength $ports]
for {set i 0} {$i < $listsize} {incr i} {
set curr [lindex $ports $i]
if {$curr == ""} {continue}
scan $curr "%d" portnum
#one byte for magic number and one for port
puts -nonewline $iqadfile [format "%c%c" $magicnumber $portnum]
incr magicnumber
}
unset ports
lappend vlanEndOffsets [expr [tell $iqadfile] -$DSA -0x1A]
}
if {[eof stdin]} {
error "unexpected EOF in IR during VLAN processing"
exit 1
}
#write config length.