GEC15Agenda/WednesdayPlenary/RACEDemo: race-scrpt.py

File race-scrpt.py, 3.8 KB (added by nriga@bbn.com, 7 years ago)
Line 
1#!/usr/bin/python
2
3#----------------------------------------------------------------------
4# Copyright (c) 2011 Raytheon BBN Technologies
5#
6# Permission is hereby granted, free of charge, to any person obtaining
7# a copy of this software and/or hardware specification (the "Work") to
8# deal in the Work without restriction, including without limitation the
9# rights to use, copy, modify, merge, publish, distribute, sublicense,
10# and/or sell copies of the Work, and to permit persons to whom the Work
11# is furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be
14# included in all copies or substantial portions of the Work.
15#
16# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
23# IN THE WORK.
24#----------------------------------------------------------------------
25
26import copy
27import string
28import sys
29import omni
30import os.path
31import time
32import readyToLogin
33
34def getLoginCommands( loginInfoDict, keyList ):
35  loginCommands = {}
36  for amUrl, amInfo in loginInfoDict.items() :
37    for item in amInfo["info"] :
38      try:
39        if item['geni_status'] != "ready" :
40          print "Not all the nodes are ready. Can't run the experiment exit!"
41          sys.exit(-1)
42      except KeyError:
43          print "There is no status information for a node. This script might fail. "
44
45      keys = readyToLogin.getKeysForUser(amInfo["amType"], item["username"], keyList)
46
47      clientid = item['client_id']
48      if loginCommands.has_key(clientid) :
49        print "More than one nodes have the same client id or the sliver is configured for multiple users. Exit!"
50        sys.exit(-1)
51      # Use only the first key
52      output = "ssh"
53      if str(item['port']) != '22' :
54            output += " -p %s " % item['port']
55      output += " -i %s %s@%s" % ( keys[0], item['username'], item['hostname'])
56      loginCommands[clientid] = output
57 
58  return loginCommands
59
60def modifyToIgnoreHostChecking(loginCommands) :
61
62  for k,c in loginCommands.items():
63    loginCommands[k] = c.replace("ssh ", "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ")
64
65def executeCommand( loginCommands, host, command) :
66  print "Send command %s to %s" % (command, host)
67  finalCommand = loginCommands[host] + " '" + command +"'"
68  os.system(finalCommand)
69  print "Done with command %s to %s" % (command, host)
70  time.sleep(5)
71
72def runtransfers(loginCommands) :
73  command = "/local/get_udt_file.sh med.100M"
74  executeCommand(loginCommands, 'PC2', command)
75  command = "/local/get_ftp_file.sh med.100M"
76  executeCommand(loginCommands, 'PC2', command)
77  #command = "/local/get_both_file.sh med.100M"
78  #executeCommand(loginCommands, 'PC2', command)
79
80
81def setLinkParams(loginCommands, bandwidth, delay, loss) :
82  command = "sudo ipfw pipe 60111 config bw %s delay %d plr %f; " % (bandwidth, delay, loss)
83  command += "sudo ipfw pipe 60121 config bw %s delay %d plr %f" % (bandwidth, delay, loss)
84  executeCommand(loginCommands, 'delay', command)
85
86def main(argv=None):
87 
88  loginInfoDict, keyList = readyToLogin.main_no_print(argv=argv)
89  loginCommands = getLoginCommands(loginInfoDict, keyList)
90  modifyToIgnoreHostChecking(loginCommands)
91  #for b in ["0M", "500M", "100M", "50M", "10M"] :
92  for b in ["0M"] :
93    #for l in [0, 0.0001, 0.001, 0.005] :
94    for l in [0] :
95      for d in [0, 25, 50, 100, 150, 200] :
96      #for d in [0]:
97        setLinkParams(loginCommands, b, d, l)
98        runtransfers(loginCommands)
99
100if __name__ == "__main__":
101    sys.exit(main())
102