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
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, }
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
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
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, }
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, }
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, }
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, }