Exemple #1
0
def xping(neighbor,tryUntilSuccess=False,src=None):
    xpingcmd = '/home/cmu_xia/fedora-bin/xia-core/bin/xping'
    if src:
        xpingcmd = '%s -s "%s"' % (xpingcmd, src)
    while True:
        s = '%s -t 5 "%s"' % (xpingcmd, neighbor)
        while True:
            try:
                printtime(s)
                out = check_output(s)
                printtime(out)
                stat = "%.3f" % float(out[0].split("\n")[-2].split('=')[1].split('/')[1])
                break
            except:
                pass
        s = '%s -t 30 -i %s -c %s "%s"' % (xpingcmd, XPING_INTERVAL, XPING_COUNT, neighbor)
        while True:
            try:
                printtime(s)
                out = check_output(s)
                break
            except:
                if not tryUntilSuccess:
                    break
        printtime(out)
        try:
            l = sorted([float(x.split('time=')[1].split(' ')[0]) for x in out[0].split('\n') if 'time=' in x])[:5]
            print l
            stat = sum(l) / len(l)
            #stat = "%.3f" % float(out[0].split("\n")[-2].split('=')[1].split('/')[1])
        except:
            stat = -1
        stat = "%.3f" % stat
        stat = -1 if stat == '=' else stat
        return stat
 def test_lisod_file(self):
     self.print_str('\n\n----- Testing make -----')
     commit = self.resolve_tag()
     path = self.get_path()
     if not path: path = self.find_path('Makefile', commit.tree)
     os.chdir(path)
     check_output('make')
     self.pAssertTrue(os.path.exists('./lisod'))
 def test_lisod_file(self):
     self.print_str('\n\n----- Testing make -----')
     commit = self.resolve_tag()
     path = self.get_path()
     if not path: path = self.find_path('Makefile', commit.tree)
     os.chdir(path)
     check_output('make')
     self.pAssertTrue(os.path.exists('./lisod'))
 def test_bw(self):
     print '(----- Testing BW -----'
     check_output('echo "----- Testing BW ----" >> %s' % self.grader.results)
     commit = self.resolve_tag()
     self.git_checkout(commit.hex)
     name = self.run_lisod(commit.tree)
     time.sleep(1)
     self.pAssertEqual(0, os.system('curl -m 10 -o /dev/null http://127.0.0.1:%d/big.html 2>> %s' % (self.port, self.grader.results)))
 def test_apache_bench(self):
     print '----- Testing Apache Bench -----'
     check_output('echo "----- Testing Apache Bench ----" >> %s' % self.grader.results)
     check_output('echo "ab -kc 800 -n 100000 http://127.0.0.1:%d/index.html" >> %s' % (self.port, self.grader.results))
     commit = self.resolve_tag()
     self.git_checkout(commit.hex)
     name = self.run_lisod(commit.tree)
     time.sleep(3)
     cmd = 'ab -kc 800 -n 100000 http://127.0.0.1:%d/index.html >> %s' % (self.port, self.grader.results)
     self.pAssertEqual(0, os.system(cmd))
    def setUp(self):
        super(Checkpoint3Test, self).setUp()

        # save a copy of src for moss
        if not os.path.exists(self.grader.moss_dir):
            os.makedirs(self.grader.moss_dir)
        if not os.path.exists('%s/%s' % (self.grader.moss_dir, self.grader.andrewid)):
            print 'Saving copy of source for moss in %s/%s' % (self.grader.moss_dir, self.grader.andrewid)
            os.makedirs('%s/%s' % (self.grader.moss_dir, self.grader.andrewid))
            check_output('cp -r . %s/%s/' % (self.grader.moss_dir, self.grader.andrewid))
    def setUp(self):
        super(Checkpoint3Test, self).setUp()

        # save a copy of src for moss
        if not os.path.exists(self.grader.moss_dir):
            os.makedirs(self.grader.moss_dir)
        if not os.path.exists('%s/%s' %
                              (self.grader.moss_dir, self.grader.andrewid)):
            print 'Saving copy of source for moss in %s/%s' % (
                self.grader.moss_dir, self.grader.andrewid)
            os.makedirs('%s/%s' % (self.grader.moss_dir, self.grader.andrewid))
            check_output('cp -r . %s/%s/' %
                         (self.grader.moss_dir, self.grader.andrewid))
 def test_bw(self):
     print '(----- Testing BW -----'
     check_output('echo "----- Testing BW ----" >> %s' %
                  self.grader.results)
     commit = self.resolve_tag()
     self.git_checkout(commit.hex)
     name = self.run_lisod(commit.tree)
     time.sleep(1)
     self.pAssertEqual(
         0,
         os.system(
             'curl -m 10 -o /dev/null http://127.0.0.1:%d/big.html 2>> %s' %
             (self.port, self.grader.results)))
Exemple #9
0
    def exposed_gather_browser_stats(self, type):
        # write to etc/hosts.xia
        check_output('echo "%s %s" > %s' % (BROWSER_ADDR, rpc(MASTER_SERVER, 'get_neighbor_webserver', (type,)), ETC_HOSTS))

        print check_output('cat %s' % ETC_HOSTS)

        while True:
            try:
                check_output('ps -e | grep proxy.py')
                break
            except:
                if type == 'tunneling':
                    Popen(PROXY_CMD, shell=True)
                else:
                    proxy_dag = rpc(MASTER_SERVER, 'exposed_get_proxy_address', (type,))
                    print 'proxy going to start'
                    print proxy_dag
                    Popen('%s "%s"' % (PROXY_CMD, proxy_dag), shell=True)
                time.sleep(1)
        time.sleep(3)
        print 'running browser cmd'
        p = Popen(BROWSER_CMD,shell=True)
        p.wait()
        time.sleep(3)
        while True:
            (out, rc) = check_both(BROWSER_CMD, check=False)
            if rc == 1:
                raise Execption("BROWSER_CMD failed")
            if rc == 0:
                break
            time.sleep(1)
        out = out[0].split('\n')[-2].split(' ')[-1]
        rpc(MASTER_SERVER, 'browser_stats', (out,type))
        check_output('killall proxy.py')
 def test_apache_bench(self):
     print '----- Testing Apache Bench -----'
     check_output('echo "----- Testing Apache Bench ----" >> %s' %
                  self.grader.results)
     check_output(
         'echo "ab -kc 800 -n 100000 http://127.0.0.1:%d/index.html" >> %s'
         % (self.port, self.grader.results))
     commit = self.resolve_tag()
     self.git_checkout(commit.hex)
     name = self.run_lisod(commit.tree)
     time.sleep(3)
     cmd = 'ab -kc 800 -n 100000 http://127.0.0.1:%d/index.html >> %s' % (
         self.port, self.grader.results)
     self.pAssertEqual(0, os.system(cmd))
 def run_lisod(self, tree):
     path = self.get_path()
     liso = self.liso_name()
     port = self.get_port()
     tls_port = self.get_tls_port()
     if not path: path = self.find_path('Makefile', tree)
     print 'switching to: %s' % path
     os.chdir(path)
     check_both('make clean', False, False)
     check_output('make')
     self.ran = True
     resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
     cmd = '%s %d %d %slisod.log %slisod.lock %s %s %s %s&' % (liso, port, tls_port, self.grader.tmp_dir, self.grader.tmp_dir, self.grader.www[:-1], self.grader.cgi, self.grader.priv_key, self.grader.cert)
     #cmd = 'nohup ' + cmd
     #cmd = cmd + " > /dev/null"
     print cmd
     self.pAssertEqual(0, os.system(cmd))
     return liso
 def run_lisod(self, tree):
     path = self.get_path()
     liso = self.liso_name()
     port = self.get_port()
     tls_port = self.get_tls_port()
     if not path: path = self.find_path('Makefile', tree)
     print 'switching to: %s' % path
     os.chdir(path)
     check_both('make clean', False, False)
     check_output('make')
     self.ran = True
     resource.setrlimit(resource.RLIMIT_STACK,
                        (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
     cmd = '%s %d %d %slisod.log %slisod.lock %s %s %s %s&' % (
         liso, port, tls_port, self.grader.tmp_dir, self.grader.tmp_dir,
         self.grader.www[:-1], self.grader.cgi, self.grader.priv_key,
         self.grader.cert)
     #cmd = 'nohup ' + cmd
     #cmd = cmd + " > /dev/null"
     print cmd
     self.pAssertEqual(0, os.system(cmd))
     return liso
Exemple #13
0
def traceroute(neighbor, gateway=False):
    out = check_output('sudo traceroute -I -w 1 %s' % neighbor)
    print out
    if gateway:
        out = out[0].split('\n')
        z = my_name.split('.')[-2]
        stat = -1
        for o in out:
            stat = int(o.strip().split(' ')[0]) if z in o else stat
    else:
        stat = int(out[0].split("\n")[-2].strip().split(' ')[0])
        stat = -1 if stat is 30 else stat
    return stat
Exemple #14
0
def xtraceroute(neighbor,tryUntilSuccess=True, src=None):
    cmd = '/home/cmu_xia/fedora-bin/xia-core/bin/xtraceroute -t 30'
    if src:
        cmd = '%s -s "%s"' % (cmd, src)
    cmd = '%s "%s"' % (cmd, neighbor)
    while tryUntilSuccess:
        try:
            printtime(cmd)
            out = check_output(cmd)
            printtime(out)
            break
        except Exception, e:
            printtime('%s' % e)
            pass
Exemple #15
0
 def exposed_get_neighbors(self):
     xr_out = check_output(XROUTE)
     neighbors = []
     for xline in xr_out[0].split('\n'):
         try:
             neighbors.append(re.split(' *',xline)[4].split(':')[1])
         except:
             pass
     neighbors = list(set(neighbors))
     neighbors = [neighbor.lower() for neighbor in neighbors]
     myHID = self.exposed_get_hid()
     if myHID in neighbors: neighbors.remove(myHID)
     if BROADCAST_HID in neighbors: neighbors.remove(BROADCAST_HID)
     return neighbors
Exemple #16
0
 def run(self):
     while FINISH_EVENT.isSet():
         try:
             printtime('<<<<DISCOVERY>>>>')
             nodes_to_check = rpc(MASTER_SERVER, 'get_nodes_to_check', ())
             for node in nodes_to_check:
                 if check_neighbor(node) == "": continue
                 cmd = 'ab http://%s:%d/test | grep "Transfer rate"' % (node, HTTP_PORT)
                 out = check_output(cmd)[0]
                 printtime(out)
                 stats = (node, int(float(out.split(':')[1].split('[')[0].strip())))
                 rpc(MASTER_SERVER, 'discovery_stats', (stats,))
         except Exception, e:
             print e
             pass
         time.sleep(DISCOVERY_PERIOD)
Exemple #17
0
 def exposed_check_httpd(self):
     check_output('pgrep httpd', False)
Exemple #18
0
def start_httpd(conf_file = HTTPD_CONF_TOP):
    printtime('Starting httpd')
    check_output('sudo cp %s %s' % (conf_file, HTTPD_CONF))
    check_output(HTTP_START)
Exemple #19
0
MASTER_SERVER = 'GS11698.SP.CS.CMU.EDU'
#'ec2-54-200-36-219.us-west-2.compute.amazonaws.com' 

BEAT_PERIOD = 3
DISCOVERY_PERIOD = 3
HTTP_PORT = 8881

CDN_DIR = '/home/cmu_xia/cdn/'
HTTPD_CONF_TOP = CDN_DIR + 'httpd.conf.top'
HTTPD_CONF_CACHE = CDN_DIR + 'httpd.conf.cache'
HTTPD_TEMP = CDN_DIR + 'httpd.conf.temp'
HTTPD_CONF = '/etc/httpd/conf/httpd.conf'

HTTP_START = 'sudo /usr/sbin/httpd -k graceful'

my_name = check_output("hostname")[0].strip()

#ForwardingTable = {}

FINISH_EVENT = threading.Event()    
    
def check_neighbor(neighbor):
    try:
        printtime('checking on: %s' % neighbor)
        return rpc(neighbor, 'check_httpd', ())
    except:
        return ""

def start_httpd(conf_file = HTTPD_CONF_TOP):
    printtime('Starting httpd')
    check_output('sudo cp %s %s' % (conf_file, HTTPD_CONF))
Exemple #20
0
 def try_xroute(self):
     return check_output(XROUTE)
 def test_make(self):
     #if self.testsuite.scores['test_git'] <= 0:
     #    self.skipTest("Not a git repo, skip rest of the test.")
     check_both('make clean', False, False)
     check_output('make')
     self.testsuite.scores['test_make'] = 1
Exemple #22
0
 def exposed_soft_restart(self, neighbor):
     xianetcmd = rpc(MASTER_SERVER, 'get_xianet', (neighbor, ))
     check_output(KILL_XIANET)
     printtime('running %s' % xianetcmd)
     exec(xianetcmd)
     return xianetcmd