Ignore:
Timestamp:
Mar 5, 2010 3:26:09 AM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
444790d
Parents:
c119839
Message:

More ProtoGENI accomodation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedkit/gateway_lib.pm

    rc119839 rf8fa72b  
    2727my $FINDIF = "/usr/local/etc/emulab/findif";
    2828my $TMCC = "/usr/local/etc/emulab/tmcc";
     29
     30# Linux choices
     31my $BRCTL = "/usr/sbin/brctl";
     32my $IPROUTE = "/sbin/ip route ";
    2933
    3034# Takes an ssh config file and a reference to a hash of keys whose values must
     
    176180    }
    177181
    178     system("ifconfig $bridge create");
    179     warn "Cannot create bridge: $?\n" if $?;
    180     foreach my $a (@addr) {
    181         system("ifconfig $iface delete $a");
    182         warn "Cannot delete address $a: $?\n" if $?;
    183     }
    184     system("ifconfig $bridge addm $iface up");
    185     warn "Cannot add intefrace $iface to bridge: $?\n" if $?;
    186     system("ifconfig $bridge addm $tap");
    187     warn "Cannot add intefrace $tap to bridge: $?\n" if $?;
    188     return $?;
     182    my $uname = `uname`;
     183    chomp $uname;
     184
     185    if ($uname =~ /FreeBSD/) {
     186        system("ifconfig $bridge create");
     187        warn "Cannot create bridge: $?\n" if $?;
     188        foreach my $a (@addr) {
     189            system("ifconfig $iface delete $a");
     190            warn "Cannot delete address $a: $?\n" if $?;
     191        }
     192        system("ifconfig $bridge addm $iface up");
     193        warn "Cannot add intefrace $iface to bridge: $?\n" if $?;
     194        system("ifconfig $bridge addm $tap");
     195        warn "Cannot add intefrace $tap to bridge: $?\n" if $?;
     196        return $?;
     197    }
     198    elsif ($uname =~ /Linux/) {
     199        system("$IFCONFIG $iface 0.0.0.0 down");
     200        system("$BRCTL addbr $bridge");
     201        warn "Cannot create bridge: $?\n" if $?;
     202        system("$BRCTL addif $bridge $tap");
     203        system("$BRCTL addif $bridge $iface");
     204        system("$BRCTL stp $bridge off");
     205        system("$IFCONFIG $bridge up");
     206        system("$IFCONFIG $tap up");
     207        system("$IFCONFIG $iface up");
     208        return $?;
     209    }
    189210}
    190211
     
    194215    my $ipipe = new IO::Pipe() || die "Can't create pipe for ifconfig: $!\n";
    195216    my @addr;
     217    my $uname = `uname`;
     218    my $ipre = "inet\\s+([0-9\\.]+)";
     219    chomp $uname;
     220
     221    if ($uname =~ /Linux/) {
     222        $ipre = "inet\\s+addr:\\s*([0-9\\.]+)";
     223    }
    196224
    197225    $ipipe->reader("$IFCONFIG $iface");
    198226    while(<$ipipe>) {
    199         /inet\s+([0-9\.]+)/ && push(@addr, $1);
     227        /$ipre/ && push(@addr, $1);
    200228    }
    201229    $ipipe->close();
     
    207235    my($dest) =@_;
    208236    my $rpipe = new IO::Pipe() || die "Can't create pipe for route: $!\n";
    209 
    210     $rpipe->reader("$ROUTE get $dest");
     237    my $uname = `uname`;
     238    chomp $uname;
     239    my $route;
     240    my $dev_re;
     241
     242    if ($uname =~ /Linux/) {
     243        $route = $IPROUTE;
     244        $dev_re = "\\s+dev\\s+(\\S+)";
     245    }
     246    elsif ($uname =~ /FreeBSD/) {
     247        $route = $ROUTE;
     248        $dev_re = 'interface:\\s*([[:alnum:]]+)';
     249    }
     250
     251
     252    print "$route get $dest\n";
     253    $rpipe->reader("$route get $dest");
    211254    while (<$rpipe>) {
    212         /interface:\s*([[:alnum:]]+)/ && do {
     255        /$dev_re/ && do {
    213256            my $iface = $1;
    214257            $rpipe->close();
     258            print "matched: $iface\n";
    215259            return $iface;
    216260        };
     
    290334
    291335
    292 sub emulab_config_filename {
    293     # Find the configuration file in the usual place, which depends on what
    294     # experiment and project we're in.
     336sub config_filename {
     337    # Find the configuration file in the usual places, if there is one in
     338    # /usr/local/federation/etc, use it, otherwise look in the emulab standard
     339    # filesystems which depends on what experiment and project we're in.
    295340    my $pid;
    296341    my $eid;
    297342    my $filename;
     343    my $fed_dir = "/usr/local/federation/etc/";
     344    my $hn = `hostname`;
     345    chomp $hn;
     346    $hn =~ s/\..*//;
     347
     348    return "$fed_dir/$hn.gw.conf" if -r "$fed_dir/$hn.gw.conf";
     349
    298350    my $tmcd = new IO::Pipe() || die "Can't create pipe: $!\n";
    299351
     
    308360    }
    309361    $tmcd->close();
    310     my $hn = `hostname`;
    311     chomp $hn;
    312     $hn =~ s/\..*//;
    313362    $filename = "/proj/$pid/exp/$eid/tmp/$hn.gw.conf"
    314363        if $pid and $eid;
     
    316365    return $filename;
    317366}
     367
    318368
    319369sub wait_for_port {
Note: See TracChangeset for help on using the changeset viewer.