Exemplo n.º 1
0
def dump_metadata(metadata_file, additional_metadata=None):
  with open(metadata_file, "w") as t:
    metadata = { 'timestamp' : timestamp_string(),
               'argv' : sys.argv,
               'user' : getpass.getuser(),
               'cwd' : os.getcwd(),
               'host' : {
                  'name' : socket.gethostname(),
                  'uptime' : backtick("uptime"),
                  'free' : backtick("exec 2>/dev/null free"),
                  'num_cores' : backtick("cat 2>/dev/null /proc/cpuinfo  | grep '^processor[[:space:]]' | wc -l"),
                  'cpu_info' : backtick("cat 2>/dev/null /proc/cpuinfo | grep 'model name[[:space:]]' | uniq | sed 's/.*://' | perl -pi -e 's/\s+/ /g'")
                },
               'sys' : {
                 'lsb_release' : backtick("exec 2>/dev/null lsb_release --description --short"),
                 'uname' : backtick("uname -a")
               },
               'modules' : {
                 module : { 'commit' : backtick("git rev-parse HEAD", cwd=path),
                            'branch' : backtick("git rev-parse --abbrev-ref HEAD", cwd=path),
                            'status' : backtick("git status", cwd=path),
                            'diff'   : backtick("git diff", cwd=path)
                          } for module, path in sts_modules
               },
               'additional_metadata': additional_metadata,
             }
    t.write(json.dumps(metadata, sort_keys=True, indent=2, separators=(',', ": ")) + "\n")
Exemplo n.º 2
0
def setup_experiment(args, config):
    # Grab parameters
    if args.exp_name:
        config.exp_name = args.exp_name
    elif not hasattr(config, 'exp_name'):
        config.exp_name = exp_lifecycle.guess_config_name(config)

    if not hasattr(config, 'results_dir'):
        config.results_dir = "experiments/%s" % config.exp_name

    if args.timestamp_results is not None:
        # Note that argparse returns a list
        config.timestamp_results = args.timestamp_results[0]

    if hasattr(config, 'timestamp_results') and config.timestamp_results:
        now = timestamp_string()
        config.results_dir += "_" + str(now)

    # Set up results directory
    create_python_dir("./experiments")
    create_clean_python_dir(config.results_dir)

    # Copy stdout and stderr to a file "simulator.out"
    tee = Tee(open(os.path.join(config.results_dir, "simulator.out"), "w"))
    tee.tee_stdout()
    tee.tee_stderr()

    # Load log configuration.
    # N.B. this must be done after Tee()'ing.
    if args.log_config:
        logging.config.fileConfig(args.log_config)
    else:
        logging.basicConfig(
            level=logging.DEBUG if args.verbose else logging.INFO)

    # If specified, set up a config file for each controller
    for controller_config in config.simulation_config.controller_configs:
        if controller_config.config_template:
            controller_config.generate_config_file(config.results_dir)

    # Make sure that there are no uncommited changes
    if args.publish:
        exp_lifecycle.publish_prepare(config.exp_name, config.results_dir)

    # Record machine information for this experiment
    exp_lifecycle.dump_metadata("%s/metadata" % config.results_dir)

    # Copy over config file
    config_file = re.sub(r'\.pyc$', '.py', config.__file__)
    if os.path.exists(config_file):
        canonical_config_file = config.results_dir + "/orig_config.py"
        if os.path.abspath(config_file) != os.path.abspath(
                canonical_config_file):
            shutil.copy(config_file, canonical_config_file)
Exemplo n.º 3
0
  def write_runtime_stats(self):
    # Now write contents to a file
    now = timestamp_string()

    if self.runtime_stats_file is None:
      self.runtime_stats_file = "runtime_stats/" + now + ".json"

    with file(self.runtime_stats_file, "w") as output:
      json_string = json.dumps(self.__dict__, sort_keys=True, indent=2,
                               separators=(',', ': '))
      output.write(json_string)
Exemplo n.º 4
0
def setup_experiment(args, config):
  # Grab parameters
  if args.exp_name:
    config.exp_name = args.exp_name
  elif not hasattr(config, 'exp_name'):
    config.exp_name = exp_lifecycle.guess_config_name(config)

  if not hasattr(config, 'results_dir'):
    config.results_dir = "experiments/%s" % config.exp_name

  if args.timestamp_results is not None:
    # Note that argparse returns a list
    config.timestamp_results = args.timestamp_results[0]

  if hasattr(config, 'timestamp_results') and config.timestamp_results:
    now = timestamp_string()
    config.results_dir += "_" + str(now)

  # Set up results directory
  create_python_dir("./experiments")
  create_clean_python_dir(config.results_dir)

  # Copy stdout and stderr to a file "simulator.out"
  tee = Tee(open(os.path.join(config.results_dir, "simulator.out"), "w"))
  tee.tee_stdout()
  tee.tee_stderr()

  # Load log configuration.
  # N.B. this must be done after Tee()'ing.
  if args.log_config:
    logging.config.fileConfig(args.log_config)
  else:
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

  # If specified, set up a config file for each controller
  for controller_config in config.simulation_config.controller_configs:
    if controller_config.config_template:
      controller_config.generate_config_file(config.results_dir)

  # Make sure that there are no uncommited changes
  if args.publish:
    exp_lifecycle.publish_prepare(config.exp_name, config.results_dir)

  # Record machine information for this experiment
  exp_lifecycle.dump_metadata("%s/metadata" % config.results_dir)

  # Copy over config file
  config_file = re.sub(r'\.pyc$', '.py', config.__file__)
  if os.path.exists(config_file):
    canonical_config_file = config.results_dir + "/orig_config.py"
    if os.path.abspath(config_file) != os.path.abspath(canonical_config_file):
      shutil.copy(config_file, canonical_config_file)
Exemplo n.º 5
0
Arquivo: setup.py Projeto: NetSys/sts
def setup_experiment(args, config):
  # Grab parameters
  if args.exp_name:
    config.exp_name = args.exp_name
  elif not hasattr(config, 'exp_name'):
    config.exp_name = exp_lifecycle.guess_config_name(config)

  if not hasattr(config, 'results_dir'):
    config.results_dir = "experiments/%s" % config.exp_name

  if args.timestamp_results is not None:
    # Note that argparse returns a list
    config.timestamp_results = args.timestamp_results[0]

  if hasattr(config, 'timestamp_results') and config.timestamp_results:
    now = timestamp_string()
    config.results_dir += "_" + str(now)

  # Set up results directory
  if not os.path.exists(config.results_dir):
    os.makedirs(config.results_dir)

  # Make sure there's an __init__.py
  module_init_py = os.path.join(config.results_dir, "__init__.py")
  if not os.path.exists(module_init_py):
    open(module_init_py,"a").close()

  # Copy stdout and stderr to a file "simulator.out"
  tee = Tee(open(os.path.join(config.results_dir, "simulator.out"), "w"))
  tee.tee_stdout()
  tee.tee_stderr()

  # If specified, set up a config file for each controller
  for controller_config in config.simulation_config.controller_configs:
    if controller_config.config_template:
      controller_config.generate_config_file(config.results_dir)

  # Make sure that there are no uncommited changes
  if args.publish:
    exp_lifecycle.publish_prepare(config.exp_name, config.results_dir)

  # Record machine information for this experiment
  exp_lifecycle.dump_metadata("%s/metadata" % config.results_dir)

  # Copy over config file
  config_file = re.sub(r'\.pyc$', '.py', config.__file__)
  if os.path.exists(config_file):
    canonical_config_file = config.results_dir + "/orig_config.py"
    if os.path.abspath(config_file) != os.path.abspath(canonical_config_file):
      shutil.copy(config_file, canonical_config_file)
Exemplo n.º 6
0
  def write_runtime_stats(self):
    # Now write contents to a file
    now = timestamp_string()

    if self._runtime_stats_path is None:
      # TODO(cs): race condition if multiple MCS processes are running
      self._runtime_stats_path = "runtime_stats/" + now + ".json"

    if os.path.exists(self._runtime_stats_path):
      raise RuntimeError("Runtime stats file %s already exists.." %
              self._runtime_stats_path)

    with file(self._runtime_stats_path, "w") as output:
      json_string = json.dumps(self.__dict__, sort_keys=True, indent=2,
                               separators=(',', ': '))
      output.write(json_string)
Exemplo n.º 7
0
  def write_runtime_stats(self):
    # Now write contents to a file
    now = timestamp_string()

    if self._runtime_stats_path is None:
      # TODO(cs): race condition if multiple MCS processes are running
      self._runtime_stats_path = "runtime_stats/" + now + ".json"

    if os.path.exists(self._runtime_stats_path):
      raise RuntimeError("Runtime stats file %s already exists.." %
              self._runtime_stats_path)

    with file(self._runtime_stats_path, "w") as output:
      json_string = json.dumps(self.__dict__, sort_keys=True, indent=2,
                               separators=(',', ': '))
      output.write(json_string)
Exemplo n.º 8
0
  def open(self, results_dir=None):
    if results_dir != None:
      self.output_path = results_dir + "/events.trace"
      self.dp_trace_path = results_dir + "/dataplane.trace"
      self.replay_cfg_path = results_dir + "/replay_config.py"
      self.mcs_cfg_path = results_dir + "/mcs_config.py"
    else:
      if self.output_path is None:
        now = timestamp_string()
        self.output_path = "input_traces/" + now + ".trace"
      basename = os.path.basename(self.output_path)

      self.dp_trace_path = "./dataplane_traces/" + basename
      self.replay_cfg_path = "./config/" + basename.replace(".trace", ".py")
      self.mcs_cfg_path = "./config/" + basename.replace(".trace", "") + "_mcs.py"

    self.output = open(self.output_path, 'w')
Exemplo n.º 9
0
 def __init__(self, output_path=None):
   '''
   Automatically generate an output_path in input_traces/
   if one is not provided.
   '''
   if output_path is None:
     now = timestamp_string()
     output_path = "input_traces/" + now + ".trace"
   self.output_path = output_path
   self.mcs_output_path = output_path.replace(".trace", "_mcs_final.trace")
   self.output = open(output_path, 'w')
   self.dp_events = []
   basename = os.path.basename(output_path)
   self.dp_trace_path = "./dataplane_traces/" + basename
   self.replay_cfg_path = "./config/" + basename.replace(".trace", ".py")
   self.mcs_cfg_path = "./config/" + basename.replace(".trace", "") + "_mcs.py"
   self.last_time = time.time()
Exemplo n.º 10
0
  def open(self, results_dir=None, output_filename="events.trace"):
    if results_dir is not None:
      self.output_path = results_dir + "/" + output_filename
      self.replay_cfg_path = results_dir + "/replay_config.py"
      self.mcs_cfg_path = results_dir + "/mcs_config.py"
      self.interactive_replay_cfg_path = results_dir + "/interactive_replay_config.py"
      self.openflow_replay_cfg_path = results_dir + "/openflow_replay_config.py"
    else:
      now = timestamp_string()
      self.output_path = "input_traces/" + now + ".trace"
      basename = os.path.basename(self.output_path)

      self.replay_cfg_path = "./config/" + basename.replace(".trace", ".py")
      self.mcs_cfg_path = "./config/" + basename.replace(".trace", "") + "_mcs.py"
      self.interactive_replay_cfg_path = "./config/" + basename.replace(".trace", "") + "_interactive.py"
      self.openflow_replay_cfg_path = "./config/" + basename.replace(".trace", "") + "_openflow.py"

    self.output = open(self.output_path, 'w')
Exemplo n.º 11
0
 def __init__(self, output_path=None):
     '''
 Automatically generate an output_path in input_traces/
 if one is not provided.
 '''
     if output_path is None:
         now = timestamp_string()
         output_path = "input_traces/" + now + ".trace"
     self.output_path = output_path
     self.mcs_output_path = output_path.replace(".trace",
                                                "_mcs_final.trace")
     self.output = open(output_path, 'w')
     self.dp_events = []
     basename = os.path.basename(output_path)
     self.dp_trace_path = "./dataplane_traces/" + basename
     self.replay_cfg_path = "./config/" + basename.replace(".trace", ".py")
     self.mcs_cfg_path = "./config/" + basename.replace(".trace",
                                                        "") + "_mcs.py"
     self.last_time = time.time()
Exemplo n.º 12
0
 def _dump_runtime_stats(self):
   if self._runtime_stats is not None:
     # First compute durations
     if "replay_end_epoch" in self._runtime_stats:
       self._runtime_stats["replay_duration_seconds"] =\
         (self._runtime_stats["replay_end_epoch"] -
          self._runtime_stats["replay_start_epoch"])
     if "prune_end_epoch" in self._runtime_stats:
       self._runtime_stats["prune_duration_seconds"] =\
         (self._runtime_stats["prune_end_epoch"] -
          self._runtime_stats["prune_start_epoch"])
     self._runtime_stats["total_replays"] = Replayer.total_replays
     self._runtime_stats["total_inputs_replayed"] =\
         Replayer.total_inputs_replayed
     self._runtime_stats["config"] = str(self.simulation_cfg)
     self._runtime_stats["peeker"] = self.transform_dag is not None
     self._runtime_stats["split_ways"] = list(self._runtime_stats["split_ways"])
     # Now write contents to a file
     now = timestamp_string()
     with file("runtime_stats/" + now + ".json", "w") as output:
       json_string = json.dumps(self._runtime_stats)
       output.write(json_string)
Exemplo n.º 13
0
def setup_experiment(args, config):
    # Grab parameters
    if args.exp_name:
        config.exp_name = args.exp_name
    elif not hasattr(config, 'exp_name'):
        config.exp_name = exp_lifecycle.guess_config_name(config)

    if not hasattr(config, 'results_dir'):
        config.results_dir = "experiments/%s" % config.exp_name

    if args.timestamp_results is not None:
        # Note that argparse returns a list
        config.timestamp_results = args.timestamp_results

    if hasattr(config, 'timestamp_results') and config.timestamp_results:
        now = timestamp_string()
        config.results_dir += "_" + str(now)

    # Set up results directory
    create_python_dir("./experiments")
    create_clean_python_dir(config.results_dir)

    # Copy stdout and stderr to a file "simulator.out"
    tee = Tee(open(os.path.join(config.results_dir, "simulator.out"), "w"))
    tee.tee_stdout()
    tee.tee_stderr()

    # Load log configuration.
    # N.B. this must be done after Tee()'ing.
    if args.log_config:
        logging.config.fileConfig(args.log_config)
    else:
        logging.basicConfig(
            level=logging.DEBUG if args.verbose else logging.INFO)

    # If specified, set up a config file for each controller
    for controller_config in config.simulation_config.controller_configs:
        if controller_config.config_template:
            controller_config.generate_config_file(config.results_dir)

    # Make sure that there are no uncommited changes
    if args.publish:
        exp_lifecycle.publish_prepare(config.exp_name, config.results_dir)

    # Record machine information for this experiment
    additional_metadata = None
    if hasattr(config, "get_additional_metadata"):
        additional_metadata = config.get_additional_metadata()

    exp_lifecycle.dump_metadata("%s/metadata" % config.results_dir,
                                additional_metadata=additional_metadata)

    # Copy over config file
    config_file = re.sub(r'\.pyc$', '.py', config.__file__)
    if os.path.exists(config_file):
        canonical_config_file = config.results_dir + "/orig_config.py"
        if os.path.abspath(config_file) != os.path.abspath(
                canonical_config_file):
            shutil.copy(config_file, canonical_config_file)

    # Check configuration warnings
    log = logging.getLogger("setup")

    con = config.control_flow.simulation_cfg.controller_configs

    def builtin_pox_controller(c):
        # pox/ is already accounted for in metadata.
        return ("POXController" in str(c.controller_class)
                and c.cwd is not None
                and re.match("^pox[/]?", c.cwd) is not None)

    if (not hasattr(config, "get_additional_metadata")
            and find(lambda c: not builtin_pox_controller(c),
                     config.control_flow.simulation_cfg.controller_configs)
            is not None):
        log.warn(
            '''No get_additional_metadata() defined for config file. See '''
            '''config/nox_routing.py for an example.''')
Exemplo n.º 14
0
if args.config.endswith('.py'):
  args.config = args.config[:-3].replace("/", ".")

try:
  config = __import__(args.config, globals(), locals(), ["*"])
except ImportError:
  # try again, but prepend config module path
  config = __import__("config.%s" % args.config, globals(), locals(), ["*"])

if not hasattr(config, 'exp_name'):
  config.exp_name = exp_lifecycle.guess_config_name(config)

if not hasattr(config, 'results_dir'):
  config.results_dir = "exp/%s" % config.exp_name

now = timestamp_string()
if hasattr(config, 'timestamp_results') and config.timestamp_results:
  config.results_dir += "_" + str(now)

if not os.path.exists(config.results_dir):
  os.makedirs(config.results_dir)
module_init_py = os.path.join(config.results_dir, "__init__.py")
if not os.path.exists(module_init_py):
  open(module_init_py,"a").close()
tee_stdout(os.path.join(config.results_dir, "simulator.out"))

for controller_config in config.simulation_config.controller_configs:
  if controller_config.config_template:
    controller_config.generate_config_file(config.results_dir)

if args.publish:
Exemplo n.º 15
0
                     cwd="../floodlight-w3",
                     address="127.0.0.1",
                     port=6633,
                     sync="tcp:127.0.0.1:19999"),
    ControllerConfig(command_line_client,
                     cwd="../floodlight-w3",
                     address="127.0.0.1",
                     port=6634,
                     sync="tcp:127.0.0.1:20000")
]

topology_class = MeshTopology
topology_params = "num_switches=2"
dataplane_trace = "dataplane_traces/ping_pong_same_subnet.trace"

simulation_config = SimulationConfig(controller_configs=controllers,
                                     topology_class=topology_class,
                                     topology_params=topology_params,
                                     dataplane_trace=dataplane_trace)

from sts.util.convenience import timestamp_string

# Use a Fuzzer (already the default)
control_flow = Interactive(
    simulation_config,
    input_logger=InputLogger(output_path="input_traces/fl_" +
                             timestamp_string() +
                             ".trace"))  #Fuzzer(input_logger=InputLogger(),
#check_interval=80,
#invariant_check=InvariantChecker.check_connectivity)
Exemplo n.º 16
0
from sts.topology import MeshTopology
from sts.control_flow import Interactive
from sts.invariant_checker import InvariantChecker
from sts.input_traces.input_logger import InputLogger
from sts.simulation_state import SimulationConfig

# Use POX as our controller
command_line_server = "./fl-server.sh"
command_line_client = "./fl-client.sh"
controllers = [
    ControllerConfig(command_line_server, cwd="../floodlight-w3", address="127.0.0.1", port=6633, sync="tcp:127.0.0.1:19999"),
    ControllerConfig(command_line_client, cwd="../floodlight-w3", address="127.0.0.1", port=6634, sync="tcp:127.0.0.1:20000")
]

topology_class = MeshTopology
topology_params = "num_switches=2"
dataplane_trace = "dataplane_traces/ping_pong_same_subnet.trace"

simulation_config = SimulationConfig(controller_configs=controllers,
                                     topology_class=topology_class,
                                     topology_params=topology_params,
                                     dataplane_trace=dataplane_trace)

from sts.util.convenience import timestamp_string

# Use a Fuzzer (already the default)
control_flow = Interactive(simulation_config, input_logger=InputLogger(output_path="input_traces/fl_"+timestamp_string()+".trace")) #Fuzzer(input_logger=InputLogger(),
                           #check_interval=80,
                           #invariant_check_name=InvariantChecker.check_connectivity)

Exemplo n.º 17
0
def setup_experiment(args, config):
  # Grab parameters
  if args.exp_name:
    config.exp_name = args.exp_name
  elif not hasattr(config, 'exp_name'):
    config.exp_name = exp_lifecycle.guess_config_name(config)

  if not hasattr(config, 'results_dir'):
    config.results_dir = "experiments/%s" % config.exp_name

  if args.timestamp_results is not None:
    # Note that argparse returns a list
    config.timestamp_results = args.timestamp_results

  if hasattr(config, 'timestamp_results') and config.timestamp_results:
    now = timestamp_string()
    config.results_dir += "_" + str(now)

  # Set up results directory
  create_python_dir("./experiments")
  create_clean_python_dir(config.results_dir)

  # Copy stdout and stderr to a file "simulator.out"
  tee = Tee(open(os.path.join(config.results_dir, "simulator.out"), "w"))
  tee.tee_stdout()
  tee.tee_stderr()

  # Load log configuration.
  # N.B. this must be done after Tee()'ing.
  if args.log_config:
    logging.config.fileConfig(args.log_config)
  else:
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

  # If specified, set up a config file for each controller
  for controller_config in config.simulation_config.controller_configs:
    if controller_config.config_template:
      controller_config.generate_config_file(config.results_dir)

  # Make sure that there are no uncommited changes
  if args.publish:
    exp_lifecycle.publish_prepare(config.exp_name, config.results_dir)

  # Record machine information for this experiment
  additional_metadata = None
  if hasattr(config, "get_additional_metadata"):
    additional_metadata = config.get_additional_metadata()

  exp_lifecycle.dump_metadata("%s/metadata" % config.results_dir,
                              additional_metadata=additional_metadata)

  # Copy over config file
  config_file = re.sub(r'\.pyc$', '.py', config.__file__)
  if os.path.exists(config_file):
    canonical_config_file = config.results_dir + "/orig_config.py"
    if os.path.abspath(config_file) != os.path.abspath(canonical_config_file):
      shutil.copy(config_file, canonical_config_file)

  # Check configuration warnings
  log = logging.getLogger("setup")

  con = config.control_flow.simulation_cfg.controller_configs

  def builtin_pox_controller(c):
    # pox/ is already accounted for in metadata.
    return ("POXController" in str(c.controller_class) and
            c.cwd is not None and
            re.match("^pox[/]?", c.cwd) is not None)

  if (not hasattr(config, "get_additional_metadata") and
      find(lambda c: not builtin_pox_controller(c),
           config.control_flow.simulation_cfg.controller_configs) is not None):
    log.warn('''No get_additional_metadata() defined for config file. See '''
             '''config/nox_routing.py for an example.''')
Exemplo n.º 18
0
from experiment_config_lib import ControllerConfig
from sts.topology import MeshTopology
from sts.control_flow import Interactive
from sts.invariant_checker import InvariantChecker
from sts.simulation_state import SimulationConfig

# Use POX as our controller
command_line_server = "./fl-server.sh"
command_line_client = "./fl-client.sh"
controllers = [
    ControllerConfig(command_line_server, cwd="../floodlight-w3", address="127.0.0.1", port=6633),
    ControllerConfig(command_line_client, cwd="../floodlight-w3", address="127.0.0.1", port=6634)
]

topology_class = MeshTopology
topology_params = "num_switches=2"
dataplane_trace = "dataplane_traces/ping_pong_same_subnet.trace"

simulation_config = SimulationConfig(controller_configs=controllers,
                                     topology_class=topology_class,
                                     topology_params=topology_params,
                                     dataplane_trace=dataplane_trace)

from sts.util.convenience import timestamp_string

# Use a Fuzzer (already the default)
control_flow = Interactive(simulation_config, input_logger=InputLogger(output_path="input_traces/fl_"+timestamp_string()+".trace")) #Fuzzer(input_logger=InputLogger(),
                           #check_interval=80,
                           #invariant_check=InvariantChecker.check_connectivity)