Example #1
0
def get_data(data):
    """
    Extract the ICMP test results from the protocol buffer data
    """

    results = []
    msg = ampsave.tests.icmp_pb2.Report()
    msg.ParseFromString(data)

    for i in msg.reports:
        # build the result structure based on what fields were present
        results.append(
            {
                "target": i.name if len(i.name) > 0 else "unknown",
                "address": getPrintableAddress(i.family, i.address),
                "rtt": i.rtt if i.HasField("rtt") else None,
                "error_type": i.err_type if i.HasField("err_type") else None,
                "error_code": i.err_code if i.HasField("err_code") else None,
                "ttl": i.ttl if i.HasField("ttl") else None,
                "packet_size": msg.header.packet_size,
                "random": msg.header.random,
                "loss": None if not i.HasField("address") else 0 if i.HasField("rtt") else 1,
                "dscp": getPrintableDscp(msg.header.dscp),
            }
        )

    return results
Example #2
0
def get_data(data):
    """
    Extract the test results from the protocol buffer data.
    """

    results = []
    msg = ampsave.tests.tcpping_pb2.Report()
    msg.ParseFromString(data)

    for i in msg.reports:
        results.append(
            {
                "target": i.name if len(i.name) > 0 else "unknown",
                "port": msg.header.port,
                "address": getPrintableAddress(i.family, i.address),
                "rtt": i.rtt if i.HasField("rtt") else None,
                "replyflags": {
                    "fin": i.flags.fin,
                    "syn": i.flags.syn,
                    "rst": i.flags.rst,
                    "psh": i.flags.psh,
                    "ack": i.flags.ack,
                    "urg": i.flags.urg,
                } if i.HasField("rtt") else None,
                "icmptype": i.icmptype if i.HasField("icmptype") else None,
                "icmpcode": i.icmpcode if i.HasField("icmpcode") else None,
                "packet_size": msg.header.packet_size,
                "random": msg.header.random,
                "loss": None if not i.HasField("address") else 0 if i.HasField("rtt") or i.HasField("icmptype") or i.HasField("icmpcode") else 1,
                "dscp": getPrintableDscp(msg.header.dscp),
            }
        )

    return results
Example #3
0
def get_data(data):
    """
    Extract the udpstream test results from the protocol buffer data
    """

    results = []
    msg = ampsave.tests.udpstream_pb2.Report()
    msg.ParseFromString(data)

    for i in msg.reports:
        # build the result structure based on what fields were present
        results.append(
            {
                "direction": direction_to_string(i.direction),
                "rtt": build_summary(i.rtt) if i.HasField("rtt") else None,
                "jitter": build_summary(i.jitter) if i.HasField("jitter") else None,
                "percentiles": i.percentiles,
                "packets_received": i.packets_received if i.HasField("packets_received") else None,
                "loss_periods": build_loss_periods(i.loss_periods),
                "loss_percent": i.loss_percent if i.HasField("loss_percent") else None,
                "voip": build_voip(i.voip) if i.HasField("voip") else None,
            }
        )

    return {
        "target": msg.header.name if len(msg.header.name) > 0 else "unknown",
        "address": getPrintableAddress(msg.header.family, msg.header.address),
        #"schedule": msg.header.schedule,
        "packet_size": msg.header.packet_size,
        "packet_spacing": msg.header.packet_spacing,
        "packet_count": msg.header.packet_count,
        "dscp": getPrintableDscp(msg.header.dscp),
        "rtt_samples": msg.header.rtt_samples,
        "results": results,
    }
Example #4
0
def get_data(data):
    """
    Extract the fastping test results from the protocol buffer data
    """

    results = []
    msg = ampsave.tests.fastping_pb2.Report()
    msg.ParseFromString(data)

    for i in msg.reports:
        results.append({
            "runtime":
            i.runtime if i.HasField("runtime") else None,
            "rtt":
            _build_summary(i.rtt) if i.HasField("rtt") else None,
            "jitter":
            _build_summary(i.jitter) if i.HasField("jitter") else None,
        })

    return {
        "destination":
        msg.header.name if len(msg.header.name) > 0 else "unknown",
        "address": getPrintableAddress(msg.header.family, msg.header.address),
        "packet_rate": msg.header.rate,
        "packet_size": msg.header.size,
        "packet_count": msg.header.count,
        "dscp": getPrintableDscp(msg.header.dscp),
        "preprobe": msg.header.preprobe,
        "results": results,
    }
Example #5
0
def get_data(data):
    """
    Extract the YOUTUBE test results from the protocol buffer data.
    """

    msg = ampsave.tests.youtube_pb2.Report()
    msg.ParseFromString(data)

    timeline = []
    for event in msg.item.timeline:
        timeline.append({
            "timestamp": event.timestamp,
            "event": event.type,
            "data": event.quality if event.quality else None,
        })

    return {
        "video": msg.header.video,
        "requested_quality": msg.header.quality,
        "dscp": getPrintableDscp(msg.header.dscp),
        "useragent": msg.header.useragent,
        "max_runtime": msg.header.maxruntime,
        "title": msg.item.title,
        "actual_quality": msg.item.quality,
        "initial_buffering": msg.item.initial_buffering,
        "playing_time": msg.item.playing_time,
        "stall_time": msg.item.stall_time,
        "stall_count": msg.item.stall_count,
        "total_time": msg.item.total_time,
        "pre_time": msg.item.pre_time,
        "reported_duration": msg.item.reported_duration,
        "timeline": timeline,
    }
Example #6
0
def get_data(data):
    """
    Extract the throughput test results from the protocol buffer data.
    """

    results = []
    msg = ampsave.tests.throughput_pb2.Report()
    msg.ParseFromString(data)

    testparams = schedule_to_test_params(msg.header.schedule)

    for i in msg.reports:
        params = testparams.pop(0)
        results.append({
            "duration": params["duration"],
            "runtime": i.duration/1000/1000 if i.HasField("duration") else None,
            "bytes": i.bytes if i.HasField("bytes") else None,
            "direction": direction_to_string(i.direction),
            "tcpreused": params["tcpreused"],
        })

    # TODO confirm what happens if the test fails to connect
    return {
        "target": msg.header.name,
        "address": getPrintableAddress(msg.header.family, msg.header.address),
        "schedule": msg.header.schedule,
        "write_size": msg.header.write_size,
        "dscp": getPrintableDscp(msg.header.dscp),
        "protocol": protocol_to_string(msg.header.protocol),
        "results": results,
    }
Example #7
0
def get_data(data):
    """
    Extract the TRACEROUTE test results from the protocol buffer data.
    """

    results = []
    msg = ampsave.tests.traceroute_pb2.Report()
    msg.ParseFromString(data)

    # someone has turned off all the reporting, ignore it, we shouldn't do this
    if msg.header.ip is False and msg.header.asn is False:
        return None

    for i in msg.reports:
        result = {
            "target": i.name if len(i.name) > 0 else "unknown",
            "address": getPrintableAddress(i.family, i.address),
            "length": len(i.path),
            "error_type": i.err_type if i.HasField("err_type") else None,
            "error_code": i.err_code if i.HasField("err_code") else None,
            "packet_size": msg.header.packet_size,
            "random": msg.header.random,
            "ip": msg.header.ip,
            "as": msg.header.asn,
            "dscp": getPrintableDscp(msg.header.dscp),
            "hops": [],
        }

        for hop in i.path:
            # XXX not currently checking global flags, do I need to?
            # the fields shouldn't be present unless the flags are set
            hopitem = {}
            if msg.header.ip and hop.HasField("rtt"):
                hopitem["rtt"] = hop.rtt
            elif msg.header.ip:
                hopitem["rtt"] = None

            if msg.header.ip and hop.HasField("address"):
                hopitem["address"] = getPrintableAddress(i.family, hop.address)
            elif msg.header.ip:
                hopitem["address"] = None

            if msg.header.asn and hop.HasField("asn"):
                hopitem["as"] = hop.asn
            elif msg.header.asn:
                hopitem["as"] = None

            result["hops"].append(hopitem)

        # Add this whole path with hops to the results
        results.append(result)

    return results
Example #8
0
def get_data(data):
    """
    Extract the sip test results from the protocol buffer data
    """

    results = []
    msg = ampsave.tests.sip_pb2.Report()
    msg.ParseFromString(data)

    for i in msg.reports:
        # build the result structure based on what fields were present
        results.append({
            "time_till_first_response":
            i.time_till_first_response
            if i.HasField("time_till_first_response") else None,
            "time_till_connected":
            i.time_till_connected
            if i.HasField("time_till_connected") else None,
            "duration":
            i.duration if i.HasField("duration") else None,
            "rtt":
            build_summary(i.rtt) if i.HasField("rtt") else None,
            "rx":
            build_stream(i.rx) if i.HasField("rx") else None,
            "tx":
            build_stream(i.tx) if i.HasField("tx") else None,
        })

    return {
        "uri": msg.header.uri if len(msg.header.uri) > 0 else "unknown",
        "useragent": msg.header.useragent,
        "filename": msg.header.filename,
        "max_duration": msg.header.max_duration,
        "proxy": list(msg.header.proxy),
        "repeat": msg.header.repeat,
        "dscp": getPrintableDscp(msg.header.dscp),
        "hostname": msg.header.hostname,
        "address": getPrintableAddress(msg.header.family, msg.header.address),
        "results": results,
    }
Example #9
0
def get_data(data):
    """
    Extract the DNS test results from the protocol buffer data
    """

    results = []
    msg = ampsave.tests.dns_pb2.Report()
    msg.ParseFromString(data)

    for i in msg.reports:
        # build the result structure based on what fields were present
        results.append({
            "destination":
            i.name if len(i.name) > 0 else "unknown",
            # XXX nntsc is trying to split streams based on the instance
            # that responded, which I'm not 100% certain is the best idea.
            # For now we'll keep putting the server hostname in this field
            "instance":
            i.name if len(i.name) > 0 else "unknown",
            "address":
            getPrintableAddress(i.family, i.address),
            "rtt":
            i.rtt if i.HasField("rtt") else None,
            "query_len":
            i.query_length if i.HasField("query_length") else None,
            "response_size":
            i.response_size if i.HasField("response_size") else None,
            "total_answer":
            i.total_answer if i.HasField("total_answer") else None,
            "total_authority":
            i.total_authority if i.HasField("total_authority") else None,
            "total_additional":
            i.total_additional if i.HasField("total_additional") else None,
            "flags": {
                "rd": i.flags.rd,
                "tc": i.flags.tc,
                "aa": i.flags.aa,
                "opcode": i.flags.opcode,
                "qr": i.flags.qr,
                "rcode": i.flags.rcode,
                "cd": i.flags.cd,
                "ad": i.flags.ad,
                "ra": i.flags.ra,
            } if i.HasField("rtt") and i.HasField("flags") else {},
            "ttl":
            i.ttl if i.HasField("ttl") else None,
            # XXX create a new field to store the instance name returned
            # by the NSID query so that we don't break nntsc
            "nsid_bytes":
            i.instance if len(i.instance) > 0 else None,
            "rrsig":
            i.rrsig,
        })

    return {
        "query": msg.header.query,
        "query_type": get_query_type(msg.header.query_type),
        "query_class": get_query_class(msg.header.query_class),
        "udp_payload_size": msg.header.udp_payload_size,
        "recurse": msg.header.recurse,
        "dnssec": msg.header.dnssec,
        "nsid": msg.header.nsid,
        "dscp": getPrintableDscp(msg.header.dscp),
        "results": results,
    }
Example #10
0
def get_data(data):
    """
    Extract the HTTP test results from the protocol buffer data.
    """

    msg = ampsave.tests.http_pb2.Report()
    msg.ParseFromString(data)

    results = {
        "url": msg.header.url,
        "duration": msg.header.duration if msg.header.duration > 0 else None,
        "bytes":
        msg.header.total_bytes if msg.header.total_bytes > 0 else None,
        "server_count": len(msg.servers),
        "object_count": msg.header.total_objects,
        "keep_alive": msg.header.persist,
        "max_connections": msg.header.max_connections,
        "max_connections_per_server": msg.header.max_connections_per_server,
        "max_persistent_connections_per_server":
        msg.header.max_persistent_connections_per_server,
        "pipelining": msg.header.pipelining,
        "pipelining_maxrequests": msg.header.pipelining_maxrequests,
        "caching": msg.header.caching,
        "dscp": getPrintableDscp(msg.header.dscp),
        "useragent": msg.header.useragent,
        "proxy": msg.header.proxy,
        "failed_object_count": 0,
        "servers": []
    }

    # extract every server that we contacted
    for s in msg.servers:
        server = {
            "hostname": s.hostname,
            "address": s.address,
            "start": s.start,
            "end": s.end,
            "bytes": s.total_bytes,
            #"object_count": # XXX is this used?
            "objects": [],
        }

        # extract each object from this server
        for obj in s.objects:
            if obj.code == 0:
                results["failed_object_count"] += 1

            # Append this object to the list for this server
            server["objects"].append({
                "path": obj.path,
                "start": obj.start,
                "end": obj.end,
                "lookup_time": obj.lookup,
                "connect_time": obj.connect,
                "start_transfer_time": obj.start_transfer,
                "total_time": obj.total_time,
                "code": obj.code,
                "bytes": obj.size,
                "connect_count": obj.connect_count,
                "pipeline": obj.pipeline,
                "headers": {
                    "flags": {
                        "pub": obj.cache_headers.pub,
                        "priv": obj.cache_headers.priv,
                        "no_cache": obj.cache_headers.no_cache,
                        "no_store": obj.cache_headers.no_store,
                        "no_transform": obj.cache_headers.no_transform,
                        "must_revalidate": obj.cache_headers.must_revalidate,
                        "proxy_revalidate": obj.cache_headers.proxy_revalidate,
                    },
                    "max_age":
                    obj.cache_headers.max_age
                    if obj.cache_headers.HasField("max_age") else None,
                    "s_maxage":
                    obj.cache_headers.s_maxage
                    if obj.cache_headers.HasField("s_maxage") else None,
                    "x_cache":
                    obj.cache_headers.x_cache
                    if obj.cache_headers.HasField("x_cache") else None,
                    "x_cache_lookup":
                    obj.cache_headers.x_cache_lookup
                    if obj.cache_headers.HasField("x_cache_lookup") else None,
                },
            })

        # Add this whole server with objects to the results
        results["servers"].append(server)

    return results