rflinks.in 3.39 KB
Newer Older
1
2
#!/usr/bin/perl -w
#
3
# Copyright (c) 2016-2017 University of Utah and the Flux Group.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# 
# {{{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;
    }

137
    my $wire = Interface::Wire->LookupAnyByIface( $node_id, $iface );
138
139
140
141
142
143
144

    if( !defined( $wire ) ) {
	tbwarn( "rflinks: couldn't find RF wire for $pid/$eid " .
		"$node_id:$iface" );
	next;
    }

145
    my $path = $wire->field( 'external_wire' );
146
147
148
149
150
151
152
153
154
155
156
157
158

    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 ) {
159
160
161
162
	foreach my $p ( split( ",", $path ) ) {
	    if( system( "$ATTEN $p $val" ) ) {
		tbwarn( "rflinks: failed to modify attenuator $path" );
	    }
163
164
165
166
167
	}
    }
}

exit( 0 );