def dumper_tracer(mt,kind,fmt=None,path=None,ret=None): """Logs full decoded packet dumps of what is happening to :data:`sys.stdout`. Assign to :attr:`rdma.madtransactor.MADTransactor.trace_func`.""" if kind == TRACE_COMPLETE: simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret); print "D: Request",fmt.describe(); fmt.printer(sys.stdout,header=False); if ret is not None: res = fmt.__class__(bytes(ret[0])); print "D: Reply",res.describe() res.printer(sys.stdout,header=False); if kind == TRACE_UNEXPECTED: simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret); IBA.MADHeader(bytes(ret[0])).printer(sys.stdout); if kind == TRACE_RECEIVE: simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret); if fmt is not None: print "D: Incoming request",fmt.describe(); fmt.printer(sys.stdout,header=False); if kind == TRACE_REPLY: simple_tracer(mt,kind,fmt=fmt,path=path,ret=ret); if fmt is not None: print "D: Outgoing reply",fmt.describe(); fmt.printer(sys.stdout,header=False);
def cmd_decode_mad(argv,o): """Accept on stdin a hex dump of a MAD and pretty print it. Usage: %prog [-v] All spaces and newlines are removed from the input text, the result must be a single string of hex digits.""" import libibtool.vendstruct libibtool.vendstruct.install_vend(); o.add_option("-v","--verbosity",dest="verbosity",action="count",default=0, help="Increase the verbosity level of diagnostic messages, each -v increases by 1.") o.add_option("-o","--offset",dest="offset",action="store",default=0,type=int, help="Start at this offest before decoding.") (args,values) = o.parse_args(argv,expected_values = 0); o.verbosity = args.verbosity; print "Input the MAD in HEX followed by Ctrl-D"; inp = "".join(sys.stdin.readlines()); if inp[0] == '"' or inp[0] == "'": bytes = inp.strip()[1:-1].decode("string_escape"); else: inp = inp.replace(" ","").replace("\n","").replace("\r","").replace("\t",""); if o.verbosity >= 2: print "Input HEX value is:\n ",repr(inp); bytes = inp.decode("hex"); bytes = bytes[args.offset:]; if o.verbosity >= 2: print bytes.encode("hex"); hdr = IBA.MADHeader(bytes); if o.verbosity >= 1: hdr.printer(sys.stdout); kind = IBA.get_fmt_payload(*rdma.madtransactor.MADTransactor.get_request_match_key(bytes)); if kind[0] is None: if o.verbosity == 0: hdr.printer(sys.stdout); raise CmdError("Don't know what this mgmtClass/classVersion is.") fmt = kind[0](bytes); print fmt.__class__.__name__,fmt.describe(); fmt.printer(sys.stdout,header=False);