def parse_output(lines):
    results = {}
    results['succeeded'] = True

    seen_header = False
    streams    = {}

    dest_ip   = None
    dest_port = None
    src_ip    = None
    src_port  = None

    for line in lines:

        # ignore bogus sessions
        if re.match('\(nan%\)', line):
            results["succeeded"] = False
            results["error"]    = "Found NaN result";
            break;

        if re.match('read failed: Connection refused', line):
            results["succeeded"] = False
            results["error"]     = "Connection refused"
            break

        test = re.match('local ([^ ]+) port (\d+) connected with ([^ ]+) port (\d+)', line)
        if test:
            dest_ip   = test.group(1)
            dest_port = test.group(2)
            src_ip    = test.group(3)
            src_port  = test.group(4)

        # Example lines
        # TCP window size:  244 KByte (WARNING: requested 64.0 MByte)
        # TCP window size: 19800 Byte (default)
        test = re.match('TCP window size:\s+(\d+(\.\d+)?) (\S)?Byte(.*\(WARNING:\s+requested\s+(\d+(\.\d+)?) (\S)?Byte)?', line)
        if test:
            window_size = test.group(1)
            window_si   = test.group(3)

            request_size = test.group(5)
            request_si   = test.group(7)

            if window_si:
                window_size = pscheduler.si_as_number("%s%s" % (window_size, window_si))

            if request_size:
                if request_si:
                    request_size = pscheduler.si_as_number("%s%s" % (request_size, request_si))
                results["requested-tcp-window-size"] = int(request_size)

            results["tcp-window-size"] = int(window_size)

        # Example line
        # [  3] MSS size 1448 bytes (MTU 1500 bytes, ethernet)
        test = re.match('.*MSS size (\d+) bytes \(MTU (\d+) bytes', line)
        if test:
            results['mss'] = int(test.group(1))
            results['mtu'] = int(test.group(2))


        stream_id        = None
        interval_start   = None
        throughput_bytes = None
        si_bytes         = None
        throughput_bits  = None
        si_bits          = None
        jitter           = None
        lost             = None
        sent             = None

        # Example line
        # [  3] 16.0-17.0 sec  37355520 Bytes  298844160 bits/sec
        test = re.match('\[\s*(\d+|SUM)\s*\]\s+([0-9\.]+)\s*\-\s*([0-9\.]+)\s+sec\s+(\d+(\.\d+)?)\s+(P|T|G|M|K)?Bytes\s+(\d+(\.\d+)?)\s+(P|T|G|M|K)?bits\/sec(\s+([0-9\.]+)\s+ms\s+(\d+)\/\s*(\d+)\s+)?', line)
        if test:
            stream_id         = test.group(1)
            interval_start    = float(test.group(2))
            interval_end      = float(test.group(3))
            throughput_bytes  = float(test.group(4))
            si_bytes          = test.group(6)
            throughput_bits   = float(test.group(7))
            si_bits           = test.group(9)