diff options
author | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-04-20 13:44:35 +0000 |
---|---|---|
committer | Tzafrir Cohen <tzafrir.cohen@xorcom.com> | 2009-04-20 13:44:35 +0000 |
commit | 072842446fd7d7c522706729c358d23c9aeeecd8 (patch) | |
tree | e855926f6053bac057f13362bcec8784eb4719f9 /xpp/twinstar_setup | |
parent | 469e3f161db8d43374994ff4ad8a047669e3a96d (diff) |
xpp: twinstar-related perl improvements
* New generator Dahdi::Config::Gen::Xpporder can generate
and xpp_order config for an existing setup.
* Add more TwinStar related logic to Dahdi::Xpp::Mpp. Simplifies
the twinstar utility accordingly.
* twinstar_hook: for the multiple Astribanks case.
* twinstar_setup: More logic tests. Now delegates configuration
generation to dahdi_genconf (with new Xpporder generator).
* dahdi_hardware: Show number of channels with -v
git-svn-id: http://svn.asterisk.org/svn/dahdi/tools/trunk@6417 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'xpp/twinstar_setup')
-rwxr-xr-x | xpp/twinstar_setup | 161 |
1 files changed, 86 insertions, 75 deletions
diff --git a/xpp/twinstar_setup b/xpp/twinstar_setup index da76dca..0e53bdf 100755 --- a/xpp/twinstar_setup +++ b/xpp/twinstar_setup @@ -9,39 +9,80 @@ # use strict; use File::Basename; -BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } +BEGIN { + my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); + $ENV{PATH} = "$dir:$ENV{PATH}"; +} use Dahdi::Config::Gen qw(is_true); use Dahdi::Hardware; use Dahdi::Xpp::Mpp; use Dahdi::Xpp::Xbus; -my $tws_file = $ENV{DAHDI_TWINSTAR_SETUP} || "/etc/dahdi/twinstar_setup.conf"; my $xpporder_file = $ENV{XPPORDER_CONF} || "/etc/dahdi/xpp_order"; +my @devices = Dahdi::Hardware->device_list; my @xbuses = Dahdi::Xpp::xbuses; my $format = "%-20s %-10s # %s\n"; -sub prep_lines() { - my @twinstar_out; +sub bad_xpds($) { + my $xbus = shift || die; + my $bad_xpds = 0; + + foreach my $xpd ($xbus->xpds) { + if(! $xpd->spanno) { + my $fqn = $xpd->fqn; + warn "\t$fqn -- Not registered with DAHDI\n"; + $bad_xpds++; + } + } + return $bad_xpds; +} + +sub twinstar_checks() { + my @twinstar_good; my $first_port; if(! -d "/sys/bus/astribanks") { die "CANNOT generate TwinStar setup -- xpp drivers are not loaded\n"; } - foreach my $xbus (@xbuses) { - my $dev = $xbus->transport; - my $connector = $xbus->connector; - my $label = $xbus->label; - my $xbusstr = sprintf "%s (%s) [%s]", $xbus->name, $connector, $label; + foreach my $dev (@devices) { + my $hwname = $dev->hardware_name; + my $xbus; + my $loaded; + my $tws_port; + my $tws_power; + my $tws_watchdog; + my $mppinfo; + if(! $dev->is_astribank) { + warn "SKIP $hwname -- Only Astribanks can be used for TwinStar\n"; + next; + } Dahdi::Xpp::Mpp->mpp_addinfo($dev); - my $mppinfo = $dev->mppinfo; + $mppinfo = $dev->mppinfo; if(! defined $mppinfo) { - warn "SKIP $xbusstr -- is not Twinstar capable\n"; + warn "SKIP $hwname -- is not TwinStar ready\n"; next; } if(! defined $mppinfo->{MPP_TALK}) { - warn "SKIP $xbusstr -- USB firmware is not loaded\n"; + warn "SKIP $hwname -- USB firmware is not loaded\n"; + next; + } + if(! $mppinfo->{TWINSTAR_CAPABLE}) { + warn "SKIP $hwname -- is not TwinStar capable\n"; + next; + } + $xbus = $dev->xbus; + if(! defined $xbus) { + warn "SKIP $hwname -- No XBUS for this device (FPGA firmware? Initialization?)\n"; + next; + } + my $dev = $xbus->transport; + my $connector = $xbus->connector; + my $label = $xbus->label; + my $xbusstr = sprintf "%s (%s) [%s]", $xbus->name, $connector, $label; + if(bad_xpds($xbus)) { + warn "SKIP $xbusstr -- Not registered with DAHDI\n"; next; } my $port = $mppinfo->{TWINSTAR_PORT}; @@ -55,12 +96,11 @@ sub prep_lines() { next; } if(!$power->[0] || !$power->[1]) { - warn "Only one cable: $xbusstr\n"; + warn "WARNING: Only one cable: $xbusstr\n"; } $first_port = $port unless defined $first_port; - my $line = sprintf $format, - $label, $port, $connector; - push(@twinstar_out, $line); + printf "GOOD: %-15s port=%d %s\n", $label, $port, $connector; + push(@twinstar_good, $xbus); if($first_port != $port) { die "$0: ", @@ -69,64 +109,17 @@ sub prep_lines() { "(others to $first_port)\n"; } } - return @twinstar_out; -} - -sub gen_twinstar_setup($) { - my $file = shift || die; - my @twinstar_out = prep_lines; - if(!@twinstar_out) { - print STDERR "No Twinstar capable Astribanks found\n"; - return; - } - rename "$file", "$file.bak" - or $! == 2 # ENOENT (No dependency on Errno.pm) - or die "Failed to backup old config: $!\n"; - print "Generating $file\n"; - open(F, ">$file") || die "$0: Failed to open $file: $!\n"; - my $old = select F; - printf "# Autogenerated by %s on %s -- Next run will overwrite contents.\n", - $0, scalar(localtime); - print <<"HEAD"; -# -# This file is parsed by twinstar_hook -# -HEAD - printf $format, "# LABEL", "PORT", "CONNECTOR"; - foreach (@twinstar_out) { - print; - } - close F; - select $old; + return @twinstar_good; } -sub gen_xpporder($) { - my $file = shift || die; - - rename "$file", "$file.bak" - or $! == 2 # ENOENT (No dependency on Errno.pm) - or die "Failed to backup old config: $!\n"; - print "Generating $file\n"; - open(F, ">$file") || die "$0: Failed to open $file: $!\n"; - my $old = select F; - printf "# Autogenerated by %s on %s -- Next run will overwrite contents.\n", - $0, scalar(localtime); - print <<"HEAD"; -# -# This file is parsed by Dahdi::Xpp -# -HEAD - foreach my $xbus (@xbuses) { - my $label = $xbus->label; - printf "%s\t# @%s (%s)\n", - $label, $xbus->connector, $xbus->name; - } - close F; - select $old; +my @twinstar_good = twinstar_checks; +if(!@twinstar_good) { + print STDERR "Abort. No Twinstar capable Astribanks found\n"; + exit 1; } - -gen_twinstar_setup($tws_file); -gen_xpporder($xpporder_file); +print "Generating Configuration\n"; +system("dahdi_genconf -v xpporder"); +die "Failed: $?\n" if $?; 1; @@ -134,11 +127,29 @@ __END__ =head1 NAME -twinstar - Generate configuration for dahdi drivers. +twinstar_setup - Prepares a server for Astribank TwinStar operation. =head1 DESCRIPTION -Generate the F</etc/dahdi/twinstar_setup.conf>. -This is the configuration for twinstar_hook(8). +This script prepares a server for Astribank TwinStar operation. +The stages are: + +=over + +=item Preliminary checks + +Check that we have only TwinStar capable Astribanks, that the drivers are already loaded. + +=item Configuration Generation + +Indirectly generate the F</etc/dahdi/xpp_order> file that describes the current configuration. +This is done by running C<dahdi_genconf xpporder> + +This configuration file is used by twinstar_hook(8) to know when all Astribanks has reconnected +to the backup server. + +=item Deployment to Backup Server + +Not implemented yet. Should be done manualy. -Its location may be overriden via the environment variable F<DAHDI_TWINSTAR_SETUP>. +=back |