def invariant_check_prompt(self): answer = msg.raw_input('Check Invariants? [Ny]') if answer != '' and answer.lower() != 'n': msg.interactive("Which one?") msg.interactive(" 'o' - omega") msg.interactive(" 'c' - connectivity") msg.interactive(" 'lo' - loops") msg.interactive(" 'li' - controller liveness") answer = msg.raw_input("> ") result = None message = "" if answer.lower() == 'o': self._log_input_event(CheckInvariants(invariant_check=InvariantChecker.check_correspondence)) result = InvariantChecker.check_correspondence(self.simulation) message = "Controllers with miscorrepondence: " elif answer.lower() == 'c': self._log_input_event(CheckInvariants(invariant_check=InvariantChecker.check_connectivity)) result = self.invariant_checker.check_connectivity(self.simulation) message = "Disconnected host pairs: " elif answer.lower() == 'lo': self._log_input_event(CheckInvariants(invariant_check=InvariantChecker.check_loops)) result = self.invariant_checker.check_loops(self.simulation) message = "Loops: " elif answer.lower() == 'li': self._log_input_event(CheckInvariants(invariant_check=InvariantChecker.check_liveness)) result = self.invariant_checker.check_loops(self.simulation) message = "Crashed controllers: " else: log.warn("Unknown input...") if result is None: return else: msg.interactive("%s: %s" % (message, str(result)))
def dataplane_trace_prompt(self): if self.simulation.dataplane_trace: while True: answer = msg.raw_input('Feed in next dataplane event? [Ny]') if answer != '' and answer.lower() != 'n': dp_event = self.simulation.dataplane_trace.inject_trace_event() self._log_input_event(TrafficInjection(), dp_event=dp_event) else: break
def invariant_check_prompt(self): answer = msg.raw_input('Check Invariants? [Ny]') if answer != '' and answer.lower() != 'n': msg.interactive("Which one?") msg.interactive(" 'o' - omega") msg.interactive(" 'c' - connectivity") msg.interactive(" 'lo' - loops") msg.interactive(" 'li' - controller liveness") answer = msg.raw_input("> ") result = None message = "" if answer.lower() == 'o': self._log_input_event( CheckInvariants( invariant_check=InvariantChecker.check_correspondence)) result = InvariantChecker.check_correspondence(self.simulation) message = "Controllers with miscorrepondence: " elif answer.lower() == 'c': self._log_input_event( CheckInvariants( invariant_check=InvariantChecker.check_connectivity)) result = self.invariant_checker.check_connectivity( self.simulation) message = "Disconnected host pairs: " elif answer.lower() == 'lo': self._log_input_event( CheckInvariants( invariant_check=InvariantChecker.check_loops)) result = self.invariant_checker.check_loops(self.simulation) message = "Loops: " elif answer.lower() == 'li': self._log_input_event( CheckInvariants( invariant_check=InvariantChecker.check_liveness)) result = self.invariant_checker.check_loops(self.simulation) message = "Crashed controllers: " else: log.warn("Unknown input...") if result is None: return else: msg.interactive("%s: %s" % (message, str(result)))
def dataplane_trace_prompt(self): if self.simulation.dataplane_trace: while True: answer = msg.raw_input('Feed in next dataplane event? [Ny]') if answer != '' and answer.lower() != 'n': dp_event = self.simulation.dataplane_trace.inject_trace_event( ) self._log_input_event(TrafficInjection(), dp_event=dp_event) else: break
def input(prompt): if self.default_command: prompt = prompt + color.GRAY + "["+ self.default_command + "]" + color.WHITE + " >" else: prompt = prompt + "> " x = msg.raw_input(prompt) if x == "" and self.default_command: x = self.default_command parts = x.split(" ") cmd_name = parts[0] if cmd_name in self.commands: x = parts[0]+"(" + ", ".join(map(lambda s: quote_parameter(s), parts[1:])) + ")" return x
def loop(self): try: while True: # TODO(cs): print out the state of the network at each timestep? Take a # verbose flag.. time.sleep(0.05) self.logical_time += 1 self.invariant_check_prompt() self.dataplane_trace_prompt() self.check_dataplane() self.check_message_receipts() answer = msg.raw_input('Continue to next round? [Yn]').strip() if answer != '' and answer.lower() != 'y': break finally: if self._input_logger is not None: self._input_logger.close(self.simulation_cfg)
def check_dataplane(self): ''' Decide whether to delay, drop, or deliver packets ''' if type(self.simulation.patch_panel) == BufferedPatchPanel: for dp_event in self.simulation.patch_panel.queued_dataplane_events: answer = msg.raw_input('Allow [a], Drop [d], or Delay [e] dataplane packet %s? [Ade]' % dp_event) if ((answer == '' or answer.lower() == 'a') and self.simulation.topology.ok_to_send(dp_event)): self.simulation.patch_panel.permit_dp_event(dp_event) self._log_input_event(DataplanePermit(dp_event.fingerprint)) elif answer.lower() == 'd': self.simulation.patch_panel.drop_dp_event(dp_event) self._log_input_event(DataplaneDrop(dp_event.fingerprint)) elif answer.lower() == 'e': self.simulation.patch_panel.delay_dp_event(dp_event) else: log.warn("Unknown input...") self.simulation.patch_panel.delay_dp_event(dp_event)
def check_dataplane(self): ''' Decide whether to delay, drop, or deliver packets ''' if type(self.simulation.patch_panel) == BufferedPatchPanel: for dp_event in self.simulation.patch_panel.queued_dataplane_events: answer = msg.raw_input( 'Allow [a], Drop [d], or Delay [e] dataplane packet %s? [Ade]' % dp_event) if ((answer == '' or answer.lower() == 'a') and self.simulation.topology.ok_to_send(dp_event)): self.simulation.patch_panel.permit_dp_event(dp_event) self._log_input_event(DataplanePermit( dp_event.fingerprint)) elif answer.lower() == 'd': self.simulation.patch_panel.drop_dp_event(dp_event) self._log_input_event(DataplaneDrop(dp_event.fingerprint)) elif answer.lower() == 'e': self.simulation.patch_panel.delay_dp_event(dp_event) else: log.warn("Unknown input...") self.simulation.patch_panel.delay_dp_event(dp_event)
def __init__(self, simulation_cfg, superlog_path_or_dag, invariant_check_name=None, transform_dag=None, end_wait_seconds=0.5, mcs_trace_path=None, extra_log=None, runtime_stats_path=None, wait_on_deterministic_values=False, no_violation_verification_runs=1, optimized_filtering=False, forker=LocalForker(), replay_final_trace=True, strict_assertion_checking=False, delay_flow_mods=False, **kwargs): super(MCSFinder, self).__init__(simulation_cfg) # number of subsequences delta debugging has examined so far, for # distingushing runtime stats from different intermediate runs. self.subsequence_id = 0 self.mcs_log_tracker = None self.replay_log_tracker = None self.mcs_trace_path = mcs_trace_path self.sync_callback = None self._log = logging.getLogger("mcs_finder") if invariant_check_name is None: raise ValueError("Must specify invariant check") if invariant_check_name not in name_to_invariant_check: raise ValueError( '''Unknown invariant check %s.\n''' '''Invariant check name must be defined in config.invariant_checks''', invariant_check_name) self.invariant_check = name_to_invariant_check[invariant_check_name] if type(superlog_path_or_dag) == str: self.superlog_path = superlog_path_or_dag # The dag is codefied as a list, where each element has # a list of its dependents self.dag = EventDag(log_parser.parse_path(self.superlog_path)) else: self.dag = superlog_path_or_dag last_invariant_violation = self.dag.get_last_invariant_violation() if last_invariant_violation is None: raise ValueError("No invariant violation found in dag...") violations = last_invariant_violation.violations if len(violations) > 1: self.bug_signature = None while self.bug_signature is None: msg.interactive( "\n------------------------------------------\n") msg.interactive( "Multiple violations detected! Choose one for MCS Finding:" ) for i, violation in enumerate(violations): msg.interactive(" [%d] %s" % (i + 1, violation)) violation_index = msg.raw_input("> ") if re.match("^\d+$", violation_index) is None or\ int(violation_index) < 1 or\ int(violation_index) > len(violations): msg.fail("Must provide an integer between 1 and %d!" % len(violations)) continue self.bug_signature = violations[int(violation_index) - 1] else: self.bug_signature = violations[0] msg.success( "\nBug signature to match is %s. Proceeding with MCS finding!\n" % self.bug_signature) self.transform_dag = transform_dag # A second log with just our MCS progress log messages self._extra_log = extra_log self.kwargs = kwargs self.end_wait_seconds = end_wait_seconds self.wait_on_deterministic_values = wait_on_deterministic_values # `no' means "number" self.no_violation_verification_runs = no_violation_verification_runs self._runtime_stats = RuntimeStats( self.subsequence_id, runtime_stats_path=runtime_stats_path) # Whether to try alternate trace splitting techiques besides splitting by time. self.optimized_filtering = optimized_filtering self.forker = forker self.replay_final_trace = replay_final_trace self.strict_assertion_checking = strict_assertion_checking self.delay_flow_mods = delay_flow_mods
def __init__(self, simulation_cfg, superlog_path_or_dag, invariant_check_name=None, transform_dag=None, end_wait_seconds=0.5, mcs_trace_path=None, extra_log=None, runtime_stats_path=None, wait_on_deterministic_values=False, no_violation_verification_runs=1, optimized_filtering=False, forker=LocalForker(), replay_final_trace=True, strict_assertion_checking=False, **kwargs): super(MCSFinder, self).__init__(simulation_cfg) # number of subsequences delta debugging has examined so far, for # distingushing runtime stats from different intermediate runs. self.subsequence_id = 0 self.mcs_log_tracker = None self.replay_log_tracker = None self.mcs_trace_path = mcs_trace_path self.sync_callback = None self._log = logging.getLogger("mcs_finder") if invariant_check_name is None: raise ValueError("Must specify invariant check") if invariant_check_name not in name_to_invariant_check: raise ValueError('''Unknown invariant check %s.\n''' '''Invariant check name must be defined in config.invariant_checks''', invariant_check_name) self.invariant_check = name_to_invariant_check[invariant_check_name] if type(superlog_path_or_dag) == str: self.superlog_path = superlog_path_or_dag # The dag is codefied as a list, where each element has # a list of its dependents self.dag = EventDag(log_parser.parse_path(self.superlog_path)) else: self.dag = superlog_path_or_dag last_invariant_violation = self.dag.get_last_invariant_violation() if last_invariant_violation is None: raise ValueError("No invariant violation found in dag...") violations = last_invariant_violation.violations if len(violations) > 1: self.bug_signature = None while self.bug_signature is None: msg.interactive("\n------------------------------------------\n") msg.interactive("Multiple violations detected! Choose one for MCS Finding:") for i, violation in enumerate(violations): msg.interactive(" [%d] %s" % (i+1, violation)) violation_index = msg.raw_input("> ") if re.match("^\d+$", violation_index) is None or\ int(violation_index) < 1 or\ int(violation_index) > len(violations): msg.fail("Must provide an integer between 1 and %d!" % len(violations)) continue self.bug_signature = violations[int(violation_index)-1] else: self.bug_signature = violations[0] msg.success("\nBug signature to match is %s. Proceeding with MCS finding!\n" % self.bug_signature) self.transform_dag = transform_dag # A second log with just our MCS progress log messages self._extra_log = extra_log self.kwargs = kwargs self.end_wait_seconds = end_wait_seconds self.wait_on_deterministic_values = wait_on_deterministic_values # `no' means "number" self.no_violation_verification_runs = no_violation_verification_runs self._runtime_stats = RuntimeStats(self.subsequence_id, runtime_stats_path=runtime_stats_path) # Whether to try alternate trace splitting techiques besides splitting by time. self.optimized_filtering = optimized_filtering self.forker = forker self.replay_final_trace = replay_final_trace self.strict_assertion_checking = strict_assertion_checking
def __init__(self, simulation_cfg, superlog_path_or_dag, invariant_check_name="", bug_signature="", transform_dag=None, mcs_trace_path=None, extra_log=None, runtime_stats_path=None, max_replays_per_subsequence=1, optimized_filtering=False, forker=LocalForker(), replay_final_trace=True, strict_assertion_checking=False, no_violation_verification_runs=None, **kwargs): ''' Note that you may pass in any keyword argument for Replayer to MCSFinder, except 'bug_signature' and 'invariant_check_name' ''' super(MCSFinder, self).__init__(simulation_cfg) # number of subsequences delta debugging has examined so far, for # distingushing runtime stats from different intermediate runs. self.subsequence_id = 0 self.mcs_log_tracker = None self.replay_log_tracker = None self.mcs_trace_path = mcs_trace_path self.sync_callback = None self._log = logging.getLogger("mcs_finder") if invariant_check_name == "": raise ValueError("Must specify invariant check") if invariant_check_name not in name_to_invariant_check: raise ValueError('''Unknown invariant check %s.\n''' '''Invariant check name must be defined in config.invariant_checks''', invariant_check_name) self.invariant_check_name = invariant_check_name self.invariant_check = name_to_invariant_check[invariant_check_name] if type(superlog_path_or_dag) == str: self.superlog_path = superlog_path_or_dag # The dag is codefied as a list, where each element has # a list of its dependents self.dag = EventDag(log_parser.parse_path(self.superlog_path)) else: self.dag = superlog_path_or_dag if self.simulation_cfg.ignore_interposition: filtered_events = [e for e in self.dag.events if type(e) not in all_internal_events] self.dag = EventDag(filtered_events) last_invariant_violation = self.dag.get_last_invariant_violation() if last_invariant_violation is None: raise ValueError("No invariant violation found in dag...") violations = last_invariant_violation.violations self.bug_signature = bug_signature if len(violations) > 1: while self.bug_signature == "": msg.interactive("\n------------------------------------------\n") msg.interactive("Multiple violations detected! Choose one for MCS Finding:") for i, violation in enumerate(violations): msg.interactive(" [%d] %s" % (i+1, violation)) violation_index = msg.raw_input("> ") if re.match("^\d+$", violation_index) is None or\ int(violation_index) < 1 or\ int(violation_index) > len(violations): msg.fail("Must provide an integer between 1 and %d!" % len(violations)) continue self.bug_signature = violations[int(violation_index)-1] if self.bug_signature == "": self.bug_signature = violations[0] msg.success("\nBug signature to match is %s. Proceeding with MCS finding!\n" % self.bug_signature) self.transform_dag = transform_dag # A second log with just our MCS progress log messages self._extra_log = extra_log self.kwargs = kwargs unknown_kwargs = [ k for k in kwargs.keys() if k not in Replayer.kwargs ] if unknown_kwargs != []: raise ValueError("Unknown kwargs %s" % str(unknown_kwargs)) if no_violation_verification_runs is not None: raise ValueError('''no_violation_verification_runs parameter is deprecated. ''' '''Use max_replays_per_subsequence.''') self.max_replays_per_subsequence = max_replays_per_subsequence self._runtime_stats = RuntimeStats(self.subsequence_id, runtime_stats_path=runtime_stats_path) # Whether to try alternate trace splitting techiques besides splitting by time. self.optimized_filtering = optimized_filtering self.forker = forker self.replay_final_trace = replay_final_trace self.strict_assertion_checking = strict_assertion_checking