start_oai.pl 2.81 KB
Newer Older
1 2 3 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
#!/usr/bin/perl -w

use strict;
use English;
use Getopt::Std;
use XML::LibXML;
use Socket;

# Enable file output autoflush
$| = 1;

BEGIN {
    require "/etc/emulab/paths.pm";
    import emulabpaths;
    require "/local/repository/lib/paths.pm";
    import oaipaths;
}

# PhantomNet library
use epclib;

my $CAT = "/bin/cat";


#
# Enforce running script as root.
#
($UID == 0)
    or die "You must run this script as root (e.g., via sudo)!\n";

#
# Ensure multitail is installed
#

system("apt-get install multitail");

#
# Setup ssh commands
#
40 41 42 43 44 45 46 47 48 49 50 51 52
#
# Display help and exit.
#
sub help() {
    logprint("Usage: start_oai [-r sim]\n");

    exit 1;
}

my %opts = ();
if (!getopts("r:",\%opts)) {
    help();
}
53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

my $role        = $opts{'r'};
my $simPresent = "0";
if ($role eq "sim") {
  $simPresent = "1";
}
my $enbStart;
if ($simPresent == "1")
{
  $enbStart = "/usr/bin/ssh -p 22 -o ServerAliveInterval=300 -o ServerAliveCountMax=3 -o BatchMode=yes -o StrictHostKeyChecking=no sim-enb ";
}
else
{
  $enbStart = "/usr/bin/ssh -p 22 -o ServerAliveInterval=300 -o ServerAliveCountMax=3 -o BatchMode=yes -o StrictHostKeyChecking=no enb1 ";
}
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
my $epcStart = "/usr/bin/ssh -p 22 -o ServerAliveInterval=300 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=no epc ";

my $nickname = `$CAT $BOOTDIR/nickname`;
chomp($nickname);

if ($nickname =~ /^epc/)
{
    $epcStart = "";
}
if ($nickname =~ /^enb/)
{
    $enbStart = "";
}

#
# Begin Services
#
print "Killing off any old services...\n";
87 88 89
system($epcStart . "/local/repository/bin/hss.kill.sh");
system($epcStart . "/local/repository/bin/mme.kill.sh");
system($epcStart . "/local/repository/bin/spgw.kill.sh");
90 91 92 93 94 95
if ($simPresent == "1")
{
system($enbStart . "/local/repository/bin/sim_enb.kill.sh");
}
else
{
96
system($enbStart . "/local/repository/bin/enb.kill.sh");
97
}
98 99 100 101 102 103 104 105 106 107 108 109 110

print "Starting HSS...\n";
system($epcStart . "/local/repository/bin/hss.start.sh");
sleep(5);

print "Starting MME...\n";
system($epcStart . "/local/repository/bin/mme.start.sh");
sleep(5);

print "Starting SPGW...\n";
system($epcStart . "/local/repository/bin/spgw.start.sh");
sleep(30);

111
if ($simPresent == "1")
112
{
113 114
  print "Starting SIM ENB...\n";
  system($enbStart . "/local/repository/bin/sim_enb.start.sh");
115 116 117
}
else
{
118
  print "Starting ENB...\n";
Rahman's avatar
Rahman committed
119 120
  my $devices = `${enbStart}SoapySDRUtill --find --sparse`;
  if ($devices =~ /RF3C000053/)
121 122 123 124 125
  {
    system($enbStart . "/local/repository/bin/enb.start.sh");
  }
  else
  {
Rahman's avatar
Rahman committed
126
    print "ERROR: Could not detect Iris030 radio on the enb1 node. This is usually a transient error. Please try again!\n";
127
    exit(1);
128
  }
129
}
130 131 132 133
#
# Display Output of services
#
system("multitail ".
134
       #       "-l \"$epcStart tail -f /var/log/oai/hss.log\" ".
135
       "-l \"$epcStart tail -f /var/log/oai/mme.log\" ".
136
       #       "-l \"$epcStart tail -f /var/log/oai/spgw.log\" ".
137
       "-l \"$enbStart tail -f /var/log/oai/enb.log\"");