Commit 4aeaac78 authored by Gary Wong's avatar Gary Wong

Add rflinks command (brings up or tears down RF/attenuator paths).

parent 87262d6f
......@@ -51,7 +51,8 @@ BIN_STUFF = power snmpit tbend tbprerun tbreport \
template_exprun template_delete template_metadata \
template_export template_control template_commit \
template_analyze template_linkgraph template_instantiate \
template_revise template_checkout vtopgen mapper regression
template_revise template_checkout vtopgen mapper regression \
rflinks
SBIN_STUFF = resetvlans console_setup.proxy sched_reload named_setup \
batch_daemon exports_setup lease_daemon reload_daemon \
......
#!/usr/bin/perl -w
#
# Copyright (c) 2016 University of Utah and the Flux Group.
#
# {{{EMULAB-LGPL
#
# This file is part of the Emulab network testbed software.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
#
# rflinks - Set up or tear down RF (attenuator) links for an experiment
#
#
# Configure variables
#
my $TB = '@prefix@';
my $ATTEN = '@prefix@/sbin/atten';
use lib '@prefix@/lib';
use libdb;
use libtblog;
use Experiment;
use Interface;
use Lan;
use English;
use Getopt::Std;
use strict;
sub usage {
print << "END";
Usage: $0 [-r] [-n] <pid> <eid>
Options:
-n Describe what would be done without changing any state
-r Remove RF links
END
exit( 1 );
}
my $optlist = "hnr";
my $impotent = 0;
my $remove = 0;
#
# Turn off line buffering on output
#
$| = 1;
#
# Untaint the path
#
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:";
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'h'})) {
usage();
}
if (defined($options{'n'})) {
$impotent = 1;
}
if (defined($options{'r'})) {
$remove = 1;
}
usage() unless( @ARGV == 2 );
my $pid = $ARGV[ 0 ];
my $eid = $ARGV[ 1 ];
my $experiment;
$experiment = Experiment->Lookup($pid,$eid);
if (!defined($experiment)) {
die "There is no experiment $eid in project $pid\n";
}
my @lans;
Lan->ExperimentLans( $experiment, \@lans );
if (!@lans) {
tbinfo( "rflinks: $pid/$eid has no LANs, skipping\n" );
exit( 0 );
}
foreach my $lan (@lans) {
my @members;
$lan->MemberList( \@members );
next unless( @members );
my $member = $members[ 0 ];
my $node_id;
my $iface;
$member->GetAttribute( "node_id", \$node_id );
$member->GetAttribute( "iface", \$iface );
my $interface;
$interface = Interface->LookupByIface( $node_id, $iface );
next unless( defined( $interface ) );
my $type = $interface->type();
next unless( $type eq "P2PLTE" );
if( @members != 2 ) {
my $vname = $lan->vname();
tbwarn( "rflinks: $pid/$eid lan $vname doesn't have two " .
"members, skipping!" );
next;
}
my $wire = Interface::Wire->LookupAny( $interface->node_id(),
$interface->card(),
$interface->port() );
if( !defined( $wire ) ) {
tbwarn( "rflinks: couldn't find RF wire for $pid/$eid " .
"$node_id:$iface" );
next;
}
my $path = $wire->field( 'cable' );
if( !defined( $path ) ) {
tbwarn( "rflinks: RF wire for $pid/$eid $node_id:$iface has " .
"no attenuator path" );
next;
}
tbinfo( "rflinks: $pid/$eid using attenuator path $path for " .
"$node_id:$iface" );
my $val = $remove ? 95 : 0;
if( !$impotent ) {
if( system( "$ATTEN $path $val" ) ) {
tbwarn( "rflinks: failed to modify attenuator $path" );
}
}
}
exit( 0 );
......@@ -62,6 +62,7 @@ my $piper = "$TBROOT/sbin/locpiper";
my $mapper = "$TBROOT/bin/mapper";
my $wrapper = "$TBROOT/libexec/assign_wrapper";
my $SNMPIT = "$TBROOT/bin/snmpit";
my $RFLINKS = "$TBROOT/bin/rflinks";
my $IMAGESETUP = "$TBROOT/sbin/image_setup";
my $portstats = "$TBROOT/bin/portstats";
my $TCPP = "$TBROOT/sbin/tcpp";
......@@ -568,6 +569,12 @@ sub doSwapout($) {
$experiment->ReleasePublicAddrPools();
}
if( $type >= CLEANUP ) {
if( system( "$RFLINKS -r $pid $eid" ) ) {
tbwarn( "Failed to remove RF links" );
}
}
#
# Grab our per-experiment switch stack name.
#
......@@ -1558,6 +1565,12 @@ sub doSwapin($) {
}
TBDebugTimeStamp("snmpit finished");
}
if( $type != MODIFY ) {
if( system( "$RFLINKS $pid $eid" ) ) {
tbwarn( "Failed to add RF links" );
}
}
#
# Look for ports in shared vlans. This method will call snmpit
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment