From 072842446fd7d7c522706729c358d23c9aeeecd8 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Mon, 20 Apr 2009 13:44:35 +0000 Subject: 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 --- xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm | 141 ++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm (limited to 'xpp/perl_modules/Dahdi/Config') diff --git a/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm b/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm new file mode 100644 index 0000000..2b5166a --- /dev/null +++ b/xpp/perl_modules/Dahdi/Config/Gen/Xpporder.pm @@ -0,0 +1,141 @@ +package Dahdi::Config::Gen::Xpporder; +use strict; + +use Dahdi::Config::Gen qw(is_true); + +sub new($$$) { + my $pack = shift || die; + my $gconfig = shift || die; + my $genopts = shift || die; + my $file = $ENV{XPPORDER_CONF} || "/etc/dahdi/xpp_order"; + my $self = { + FILE => $file, + GCONFIG => $gconfig, + GENOPTS => $genopts, + }; + bless $self, $pack; + return $self; +} + +# +# Returns list of xbuses sorted by the span numbers assigned +# to their XPD's. Also checks that each XBUS span numbers are sequential. +sub get_sorted_xbuses(@) { + my @spans = @_; # Verify our spans + my @xbuses = Dahdi::Xpp::xbuses; + my %xbus_of_span; + my %xbus_beginning; + my %seen_spans; + my @sorted_xbuses; + foreach my $xbus (@xbuses) { + my $last_spanno; + foreach my $xpd ($xbus->xpds) { + my $spanno = $xpd->spanno; + if(!$spanno) { + printf STDERR "%s: Is not registered. Skipping.\n", $xpd->fqn; + next; + } + $seen_spans{$spanno}++; + if($xbus_of_span{$spanno}) { + printf STDERR "%s: Span %d already seen on %s\n", + $xpd->fqn, $spanno, $xbus_of_span{$spanno}->name; + die; + } + $xbus_of_span{$spanno} = $xbus; + # Check XPD's sequential numbering + if(defined $last_spanno) { + if($last_spanno + 1 != $spanno) { + printf STDERR "%s: Bad span numbers (%d, %d)\n", + $xpd->fqn, $last_spanno, $spanno; + die; + } + } else { + $xbus_beginning{$xbus} = $spanno; + } + $last_spanno = $spanno; + } + } + foreach my $span (@spans) { + my $spanno = $span->num; + if(!defined($seen_spans{$spanno})) { + warn "Span $span does not belong to any XPD!\n"; + } + } + @sorted_xbuses = sort { $xbus_beginning{$a} <=> $xbus_beginning{$b} } @xbuses; + return @sorted_xbuses; +} + +sub generate($$$) { + my $self = shift || die; + my $file = $self->{FILE}; + my $gconfig = $self->{GCONFIG}; + my $genopts = $self->{GENOPTS}; + my @spans = @_; # Verify it's all our spans + my @xbuses = get_sorted_xbuses(@spans); + warn "Empty configuration -- no xbuses\n" unless @xbuses; + rename "$file", "$file.bak" + or $! == 2 # ENOENT (No dependency on Errno.pm) + or die "Failed to backup old config: $!\n"; + #$gconfig->dump; + print "Generating $file\n" if $genopts->{verbose}; + open(F, ">$file") || die "$0: Failed to open $file: $!\n"; + my $old = select F; + printf "# Autogenerated by $0 on %s\n", scalar(localtime); + print "# If you edit this file and execute $0 again,\n"; + print "# your manual changes will be LOST.\n"; + print <<'HEAD'; +# +# This is an optional configuration file for ordering +# Dahdi registration. +# +# It is read from /etc/dahdi/xpp_order. This location +# may be overriden via the environment variable XPPORDER_CONF +# +# Lines may contain: +# - The Astribank label (verbatim) +# - The Astribank connector string (prefixed with @) +# Ordering number of each listed Astribank is determined +# by its position in this file. +# Astribanks not listed in this file, get an ordering +# number of 999 (last). +# +# Astribanks with same ordering number are sorted by their +# connectors (to preserve legacy behaviour). +# +# Examples: +#usb:TWS-08 +#@usb-0000:06:02.2-2 +HEAD + foreach my $xbus (@xbuses) { + my $label = $xbus->label; + my $connector = $xbus->connector; + my $name = $xbus->name; + printf "%s\t# %s (%s)\n", $label, $connector, $name; + } + close F; + select $old; +} + +1; + +__END__ + +=head1 NAME + +Xpporder - Generate Astribank ordering information for dahdi_registration. + +=head1 SYNOPSIS + + use Dahdi::Config::Gen::Xpporder; + + my $cfg = new Dahdi::Config::Gen::Xpporder(\%global_config, \%genopts); + $cfg->generate; + +=head1 DESCRIPTION + +Generate the F. +This is the configuration for dahdi_registration(1). +The order is determined according to current Dahdi registration +order. + +Its location may be overriden via the environment variable F. -- cgit v1.2.3