Exemplo n.º 1
0
def main(args):
    def load_format_file(format_file):
        if format_file.endswith('.py'):
            format_file = format_file[:-3].replace("/", ".")
        config = __import__(format_file, globals(), locals(), ["*"])
        return config

    if args.format_file is not None:
        format_def = load_format_file(args.format_file)
    else:
        format_def = object()

    dp_trace = None
    if args.dp_trace_path is not None:
        dp_trace = Trace(args.dp_trace_path).dataplane_trace

    if hasattr(format_def, "fields"):
        fields = format_def.fields
    else:
        fields = default_fields

    for field in fields:
        if field not in field_formatters:
            raise ValueError("unknown field %s" % field)

    if hasattr(format_def, "filtered_classes"):
        filtered_classes = format_def.filtered_classes
    else:
        filtered_classes = default_filtered_classes

    stats = Stats()

    # all events are printed with a fixed number of lines, and (optionally)
    # separated by delimiter lines of the form:
    # ----------------------------------
    with open(args.input) as input_file:
        trace = parse(input_file)
        for event in trace:
            if type(event) not in filtered_classes:
                if dp_trace is not None and type(
                        event) == replay_events.TrafficInjection:
                    event.dp_event = dp_trace.pop(0)
                for field in fields:
                    field_formatters[field](event)
                stats.update(event)

        if check_for_violation_signature(trace, args.violation_signature):
            print "Violation occurs at end of trace: %s" % args.violation_signature
        elif args.violation_signature is not None:
            print("Violation does not occur at end of trace: %s",
                  args.violation_signature)
        print

    if args.stats:
        print "Stats: %s" % stats
def main(args):
  def load_format_file(format_file):
    if format_file.endswith('.py'):
      format_file = format_file[:-3].replace("/", ".")
    config = __import__(format_file, globals(), locals(), ["*"])
    return config

  if args.format_file is not None:
    format_def = load_format_file(args.format_file)
  else:
    format_def = object()

  dp_trace = None
  if args.dp_trace_path is not None:
    dp_trace = Trace(args.dp_trace_path).dataplane_trace

  if hasattr(format_def, "fields"):
    fields = format_def.fields
  else:
    fields = default_fields

  for field in fields:
    if field not in field_formatters:
      raise ValueError("unknown field %s" % field)

  if hasattr(format_def, "filtered_classes"):
    filtered_classes = format_def.filtered_classes
  else:
    filtered_classes = default_filtered_classes

  stats = Stats()

  # all events are printed with a fixed number of lines, and (optionally)
  # separated by delimiter lines of the form:
  # ----------------------------------
  with open(args.input) as input_file:
    trace = parse(input_file)
    for event in trace:
      if type(event) not in filtered_classes:
        if dp_trace is not None and type(event) == replay_events.TrafficInjection:
          event.dp_event = dp_trace.pop(0)
        for field in fields:
          field_formatters[field](event)
        stats.update(event)

    if check_for_violation_signature(trace, args.violation_signature):
      print "Violation occurs at end of trace: %s" % args.violation_signature
    elif args.violation_signature is not None:
      print ("Violation does not occur at end of trace: %s",
             args.violation_signature)
    print

  if args.stats:
    print "Stats: %s" % stats
Exemplo n.º 3
0
def main(args):
  trace1 = parse_event_trace(args.trace1)
  trace2 = parse_event_trace(args.trace2)

  if args.ignore_inputs:
    filtered_classes = set(replay_events.all_input_events)
  else:
    filtered_classes = set()

  print "Events in trace1, not in trace2"
  print "================================="
  t1_t2_stats = Stats()
  for e in l_minus_r(trace1, trace2):
    if type(e) not in filtered_classes:
      t1_t2_stats.update(e)
      for field in default_fields:
        field_formatters[field](e)
  print str(t1_t2_stats)

  print "Events in trace2, not in trace1"
  print "================================="
  t2_t1_stats = Stats()
  for e in l_minus_r(trace2, trace1):
    if type(e) not in filtered_classes:
      t2_t1_stats.update(e)
      for field in default_fields:
        field_formatters[field](e)
  print str(t2_t1_stats)