Ejemplo n.º 1
0
def Main (args):
  show_converge = True
  if len(args) != 7:
    print >>sys.stderr, "Usage: perturbation.py setup trace stable_time begin_mean_perturb end_mean_perturn step_mean_perturb seed"
  else:
    topo = open(args[0]).read()
    trace = open(args[1]).readlines()
    stable = float(args[2])
    begin = float(args[3])
    end = float(args[4])
    step = float(args[5])
    seed = int(args[6])
    print "Setting %s %s %f %f %f %f %d"%(args[0], args[1], stable, begin, end, step, seed)
    for mean in np.arange(begin, end, step):
      Singleton.clear()
      sim = Simulation()
      sim.check_always = False
      random.seed(seed)
      print "mean_perturb %f"%(mean)
      (end_time, new_trace) = TransformTrace(trace, mean, stable)
      sim.Setup(topo, new_trace, True)
      for time in np.arange(stable, end_time, 0.5 * mean):
        sim.scheduleCheck(time)
      # Measure latency less often
      for time in np.arange(stable, end_time, mean):
        for (ha, hb) in permutations(sim.hosts, 2):
          sim.scheduleSend(time, ha.name, ha.address, hb.address)
      sim.Run()
      sim.Report(show_converge)
      sim.Clear()
def Main (args):
  show_converge = True
  if len(args) != 10:
    print >>sys.stderr, "Usage: perturbation_extreme.py setup stable_time links_to_fail mean_recovery end_time " + \
                                " begin_mean_perturb end_mean_perturn step_mean_perturb sampling_rate seed"
  else:
    topo = open(args[0]).read()
    stable = float(args[1])
    links_to_fail = int(args[2])
    mean_recovery = float(args[3])
    end_time = float(args[4])
    begin = float(args[5])
    end = float(args[6])
    step = float(args[7])
    sampling_rate = float(args[8])
    seed = int(args[9])
    print "Setting %s %f %d %f %f %f %f %f %f %d"%(args[0], stable, links_to_fail, mean_recovery, end_time, begin, end,\
            step, sampling_rate, seed)
    topo_yaml = yaml.load(topo)

    # If no fail links then just use links
    links = topo_yaml['links']

    if 'fail_links' in topo_yaml:
      fail_links = topo_yaml['fail_links']
    else:
      fail_links = links

    for mean in np.arange(begin, end, step):
      Singleton.clear()
      sim = Simulation()
      sim.check_always = False
      random.seed(seed)
      print "mean_perturb %f"%(mean)
      print "generating trace"
      (end_time, new_trace) = TransformTrace(links, fail_links, links_to_fail, mean, mean_recovery, stable, end_time)
      print "done generating trace"
      print "TRACE TRACE TRACE"
      for t in new_trace:
        print t
      print "TRACE TRACE TRACE"
      sim.Setup(topo, new_trace, False)
      for time in np.arange(stable, end_time, sampling_rate):
        sim.scheduleCheck(time)
      # Measure latency less often
      for time in np.arange(stable, end_time, sampling_rate):
        for (ha, hb) in permutations(sim.hosts, 2):
          sim.scheduleSend(time, ha.name, ha.address, hb.address)
      sim.Run()
      sim.Report(show_converge)
      sim.Clear()