def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed: '192.168.0.20 -> 192.168.0.61 ' If set to 2 the representation of the object also includes the protocol and length of payload: '192.168.0.20 -> 192.168.0.61, protocol: 17(UDP), len: 84' """ rdebug = self.debug_repr() if rdebug == 1: out = "%s -> %s " % (self.src, self.dst) elif rdebug == 2: proto = _IP_map.get(self.protocol, None) proto = str( self.protocol) if proto is None else "%d(%s)" % (self.protocol, proto) out = "%s -> %s, protocol: %s, len: %d" % (self.src, self.dst, proto, self.total_size) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed to display the frame number and the timestamp: '57 2014-03-16 13:42:56.530957 ' If set to 2 the representation of the object also includes the number of bytes on the wire, number of bytes captured and a little bit more verbose: 'frame 57 @ 2014-03-16 13:42:56.530957, 42 bytes on wire, 42 packet bytes' """ rdebug = self.debug_repr() if rdebug in [1, 2]: tstamp = "%s.%06d" % (time.strftime( "%Y-%m-%d %H:%M:%S", time.localtime(self.seconds)), self.usecs) if rdebug == 1: out = "%d %s " % (self.index, tstamp) elif rdebug == 2: out = "frame %d @ %s, %d bytes on wire, %d packet bytes" % ( self.index, tstamp, self.length_inc, self.length_orig) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed: 'TCP 708 -> 2049, seq: 3294175829, ack: 3395739041, ACK,FIN' If set to 2 the representation of the object also includes the length of payload and a little bit more verbose: 'src port 708 -> dst port 2049, seq: 3294175829, ack: 3395739041, len: 0, flags: ACK,FIN' """ rdebug = self.debug_repr() if rdebug > 0: flags = [] for flag in _TCP_map: if self.flags_raw & flag != 0: flags.append(_TCP_map[flag]) if rdebug == 1: out = "TCP %d -> %d, seq: %d, ack: %d, %s" % \ (self.src_port, self.dst_port, self.seq_number, self.ack_number, ','.join(flags)) elif rdebug == 2: out = "src port %d -> dst port %d, seq: %d, ack: %d, len: %d, flags: %s" % \ (self.src_port, self.dst_port, self.seq_number, self.ack_number, self.length, ','.join(flags)) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is: 'RPC call program: 100003, version: 4, procedure: 0, xid: 0xe37d3d5 ' If set to 2 the representation of the object is as follows: 'CALL(0), program: 100003, version: 4, procedure: 0, xid: 0xe37d3d5' """ rdebug = self.debug_repr() if rdebug > 0: prog = '' for item in ['program', 'version', 'procedure']: value = getattr(self, item, None) if value != None: prog += " %s: %d," % (item, value) if rdebug == 1: rtype = "%-5s" % msg_type.get(self.type, 'Unknown').lower() out = "RPC %s %s xid: %s" % (rtype, prog, self.xid) elif rdebug == 2: rtype = "%-5s(%d)" % (msg_type.get(self.type, 'Unknown'), self.type) if self.type == CALL: creds = ", %s" % self.credential else: creds = ", %s" % self.verifier out = "%s,%s xid: %s%s" % (rtype, prog, self.xid, creds) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is: 'RPC call program: 100003, version: 4, procedure: 0, xid: 0xe37d3d5 ' If set to 2 the representation of the object is as follows: 'CALL(0), program: 100003, version: 4, procedure: 0, xid: 0xe37d3d5' """ rdebug = self.debug_repr() if rdebug > 0: prog = '' for item in ['program', 'version', 'procedure']: value = getattr(self, item, None) if value != None: prog += " %s: %d," % (item, value) if rdebug == 1: rtype = "%-5s" % msg_type.get(self.type, 'Unknown').lower() out = "RPC %s %s xid: 0x%08x" % (rtype, prog, self.xid) elif rdebug == 2: rtype = "%-5s(%d)" % (msg_type.get(self.type, 'Unknown'), self.type) out = "%s,%s xid: 0x%08x" % (rtype, prog, self.xid) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is: 'GSSD length: 176, seq_num: 1' If set to 2 the representation of the object is as follows: 'length: 176, seq_num: 1' """ rdebug = self.debug_repr() rdata = "" if rdebug > 0: if self._proc == RPCSEC_GSS_DATA: rdata = "length: %d, seq_num: %d" % (self.length, self.seq_num) elif self._proc == RPCSEC_GSS_INIT: if self._type == CALL: rdata = "token: 0x%s..." % self.token[:32].encode('hex') else: rdata = "major: %d, " % self.major + \ "minor: %d, " % self.minor + \ "seq_window: %d, " % self.seq_window + \ "context: 0x%s, " % self.context.encode('hex') + \ "token: 0x%s..." % self.token[:16].encode('hex') if rdebug == 1: out = "GSSD %s" % rdata elif rdebug == 2: out = rdata else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of is condensed into a single line. It contains, the frame number, IP source and destination and/or the last layer: '1 0.386615 192.168.0.62 -> 192.168.0.17 TCP 2049 -> 708, seq: 3395733180, ack: 3294169773, ACK,SYN' '5 0.530957 00:0c:29:54:09:ef -> ff:ff:ff:ff:ff:ff, type: 0x806' '19 0.434370 192.168.0.17 -> 192.168.0.62 NFS v4 COMPOUND4 call SEQUENCE;PUTFH;GETATTR' If set to 2 the representation of the object is a line for each layer: 'Pkt( RECORD: frame 19 @ 0.434370 secs, 238 bytes on wire, 238 bytes captured ETHERNET: 00:0c:29:54:09:ef -> e4:ce:8f:58:9f:f4, type: 0x800(IPv4) IP: 192.168.0.17 -> 192.168.0.62, protocol: 6(TCP), len: 224 TCP: src port 708 -> dst port 2049, seq: 3294170673, ack: 3395734137, len: 172, flags: ACK,PSH RPC: CALL(0), program: 100003, version: 4, procedure: 1, xid: 0x1437d3d5 NFS: COMPOUND4args(tag='', minorversion=1, argarray=[nfs_argop4(argop=OP_SEQUENCE, ...), ...]) )' """ rdebug = self.debug_repr() if rdebug > 0: out = "Pkt(\n" if rdebug == 2 else '' klist = [] for key in PKT_layers: if getattr(self, key, None) is not None and (rdebug > 1 or key not in _PKT_nlayers): klist.append(key) index = 0 lastkey = len(klist) - 1 for key in klist: value = getattr(self, key, None) if value is not None and (rdebug > 1 or index == lastkey or key in _PKT_rlayers): if rdebug == 1: if index == lastkey and key in _PKT_mlayers: # Display level 2 if last layer is in _PKT_mlayers self.debug_repr(2) out += str(value) self.debug_repr(1) else: out += str(value) else: sps = " " * (_maxlen - len(key)) out += " %s:%s %s\n" % (key.upper(), sps, str(value)) index += 1 out += ")\n" if rdebug == 2 else "" else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of is condensed into a single line. It contains, the frame number, IP source and destination and/or the last layer: '1 0.386615 192.168.0.62 -> 192.168.0.17 TCP 2049 -> 708, seq: 3395733180, ack: 3294169773, ACK,SYN' '5 0.530957 00:0c:29:54:09:ef -> ff:ff:ff:ff:ff:ff, type: 0x806' '19 0.434370 192.168.0.17 -> 192.168.0.62 NFS v4 COMPOUND4 call SEQUENCE;PUTFH;GETATTR' If set to 2 the representation of the object is a line for each layer: 'Pkt( RECORD: frame 19 @ 0.434370 secs, 238 bytes on wire, 238 bytes captured ETHERNET: 00:0c:29:54:09:ef -> e4:ce:8f:58:9f:f4, type: 0x800(IPv4) IP: 192.168.0.17 -> 192.168.0.62, protocol: 6(TCP), len: 224 TCP: src port 708 -> dst port 2049, seq: 3294170673, ack: 3395734137, len: 172, flags: ACK,PSH RPC: CALL(0), program: 100003, version: 4, procedure: 1, xid: 0x1437d3d5 NFS: COMPOUND4args(tag='', minorversion=1, argarray=[nfs_argop4(argop=OP_SEQUENCE, ...), ...]) )' """ rdebug = self.debug_repr() if rdebug > 0: out = "Pkt(\n" if rdebug == 2 else '' klist = [] for key in PKT_layers: if getattr(self, key, None) is not None and (rdebug > 1 or key not in _PKT_nlayers): klist.append(key) index = 0 lastkey = len(klist) - 1 for key in klist: value = getattr(self, key, None) if value is not None and (rdebug > 1 or index == lastkey or key in _PKT_rlayers or (self != "ip" and key == "ethernet")): if rdebug == 1: if index == lastkey and key in _PKT_mlayers: # Display level 2 if last layer is in _PKT_mlayers self.debug_repr(2) out += str(value) self.debug_repr(1) else: out += str(value) else: sps = " " * (_maxlen - len(key)) out += " %s:%s %s\n" % (key.upper(), sps, str(value)) if index == lastkey and hasattr(value, "data") and value.data is not None and key != "nfs": sps = " " * (_maxlen - 4) out += " DATA:%s 0x%s\n" % (sps, value.data.encode("hex")) index += 1 out += ")\n" if rdebug == 2 else "" else: out = BaseObj.__str__(self) return out
def __str__(self): """Informal string representation of object""" rpc = self._rpc rdebug = self.debug_repr() if rdebug == 1: # String format for verbose level 1 out = self.rpc_str("NFS") if rpc.program >= 0x40000000 and rpc.program < 0x60000000: cb_flag = True priority = CBpriority else: cb_flag = False priority = NFSpriority if rpc.procedure == 0: # NULL procedure out += self.__class__.__name__ return out elif rpc.version == 4 or cb_flag: # NFS version 4.x if not utils.NFS_mainop: # Display all NFS operation names in the compound oplist = [str(x.op)[3:] for x in self.array] out += "%-25s" % ";".join(oplist) if utils.LOAD_body or utils.NFS_mainop: # Order operations by their priority item_list = sorted(self.array, key=lambda x: priority.get(x.op ,0)) if utils.NFS_mainop: # Display only the highest priority operation name out += "%-10s" % str(item_list[-1].op)[3:] if utils.LOAD_body: # Get the highest priority operation body to display display_op = None while item_list: item = item_list.pop() if priority.get(item.op, 0) == 0: # Ignore operations with no priority continue itemstr = str(item) if (display_op is None and len(itemstr)) or item.op == display_op: out += " " + itemstr # Check if there is another operation to display display_op = getattr(item, "_opdisp", None) if display_op is None: break if rpc.type and getattr(self, "status", 0) != 0: # Display the status of the NFS packet only if it is an error out += " %s" % self.status return out else: return BaseObj.__str__(self)
def __str__(self): """Informal string representation""" rdebug = self.debug_repr() if rdebug == 1: out = self.rpc_str(self._strname) out += "%-10s" % str(self.procedure)[self._pindex:] if LOAD_body and getattr(self, "switch", None) is not None: itemstr = str(self.switch) if len(itemstr): out += " " + itemstr rpc = self._rpc if rpc.type and getattr(self, "status", 0) != 0: # Display the status of the packet only if it is an error out += " %s" % self.status return out else: return BaseObj.__str__(self)
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed: '192.168.0.20 -> 192.168.0.61 ' If set to 2 the representation of the object also includes the protocol and length of payload: '192.168.0.20 -> 192.168.0.61, protocol: 17(UDP), len: 84' """ rdebug = self.debug_repr() if rdebug == 1: out = "%s -> %s " % (self.src, self.dst) elif rdebug == 2: proto = _IP_map.get(self.protocol, self.protocol) out = "%s -> %s, protocol: %s, len: %d" % (self.src, self.dst, proto, self.total_size) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is: 'GSSC token: 0x602306092a864886f71201020201010000...' If set to 2 the representation of the object is as follows: 'token: 0x602306092a864886f71201020201010000...' """ rdebug = self.debug_repr() rdata = "" if rdebug > 0: rdata = "token: 0x%s..." % self.token[:32].encode('hex') if rdebug == 1: out = "GSSC %s" % rdata elif rdebug == 2: out = rdata else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed: '00:0c:29:54:09:ef -> 60:33:4b:29:6e:9d ' If set to 2 the representation of the object also includes the type of payload: '00:0c:29:54:09:ef -> 60:33:4b:29:6e:9d, type: 0x800(IPv4)' """ rdebug = self.debug_repr() if rdebug == 1: out = "%s -> %s " % (self.src, self.dst) elif rdebug == 2: etype = _ETHERNET_map.get(self.type, None) etype = hex(self.type) if etype is None else "%s(%s)" % (hex(self.type), etype) out = "%s -> %s, type: %s" % (self.src, self.dst, etype) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed to display the frame number and the timestamp: '57 0.530957 ' If set to 2 the representation of the object also includes the number of bytes on the wire, number of bytes captured and a little bit more verbose: 'frame 57 @ 0.530957 secs, 42 bytes on wire, 42 packet bytes' """ rdebug = self.debug_repr() if rdebug == 1: out = "%d %f " % (self.index, self.secs) elif rdebug == 2: out = "frame %d @ %f secs, %d bytes on wire, %d packet bytes" % (self.index, self.secs, self.length_inc, self.length_orig) else: out = BaseObj.__str__(self) return out
def __str__(self): """String representation of object The representation depends on the verbose level set by debug_repr(). If set to 0 the generic object representation is returned. If set to 1 the representation of the object is condensed to display either or both the frame or packet numbers and the timestamp: '57 2014-03-16 13:42:56.530957 ' If set to 2 the representation of the object also includes the number of bytes on the wire, number of bytes captured and a little bit more verbose: 'frame 57 @ 2014-03-16 13:42:56.530957, 42 bytes on wire, 42 packet bytes' """ idxstr = "" tstamp = "" rdebug = self.debug_repr() if TSTAMP and rdebug in [1,2]: tstamp = "%s.%06d" % (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(self.seconds)), self.usecs) if rdebug == 1: if FRAME and INDEX: idxstr = "%d,%d " % (self.frame, self.index) elif FRAME: idxstr = "%d " % self.frame elif INDEX: idxstr = "%d " % self.index out = "%s%s " % (idxstr, tstamp) elif rdebug == 2: if FRAME and INDEX: idxstr = "frame %d,%d @ " % (self.frame, self.index) elif FRAME: idxstr = "frame %d @ " % self.frame elif INDEX: idxstr = "index %d @ " % self.index out = "%s%s, %d bytes on wire, %d packet bytes" % (idxstr, tstamp, self.length_inc, self.length_orig) else: out = BaseObj.__str__(self) return out
import parser import symbol import nfstest_config as c from baseobj import BaseObj from packet.pkt import Pkt from packet.unpack import Unpack from packet.record import Record from packet.link.ethernet import ETHERNET # Module constants __author__ = 'Jorge Mora (%s)' % c.NFSTEST_AUTHOR_EMAIL __version__ = '1.0.2' __copyright__ = "Copyright (C) 2012 NetApp, Inc." __license__ = "GPL v2" BaseObj.debug_map(0x100000000, 'pkt1', "PKT1: ") BaseObj.debug_map(0x200000000, 'pkt2', "PKT2: ") BaseObj.debug_map(0x400000000, 'pkt3', "PKT3: ") BaseObj.debug_map(0x800000000, 'pkt4', "PKT4: ") BaseObj.debug_map(0xF00000000, 'pktt', "PKTT: ") # Map of tokens _token_map = dict(token.tok_name.items() + symbol.sym_name.items()) # Map of items not in the array of the compound _nfsopmap = {'status': 1, 'tag': 1} # Match function map _match_func_map = { 'ETHERNET': 'self.match_ethernet', 'IP': 'self.match_ip', 'TCP': 'self.match_tcp', 'RPC': 'self.match_rpc',
# Provide colors on PASS, FAIL, WARN messages _test_map_c = { HEAD: "\n*** ", INFO: " ", PASS: "******", FAIL: " \033[31mFAIL\033[m: ", WARN: " \033[33mWARN\033[m: ", BUG: " \033[33mBUG\033[m: ", IGNR: " \033[33mIGNR\033[m: ", } _tverbose_map = {'group': 0, 'normal': 1, 'verbose': 2, '0':0, '1':1, '2':2} _rtverbose_map = dict(zip(_tverbose_map.values(),_tverbose_map)) BaseObj.debug_map(0x100, 'opts', "OPTS: ") class TestUtil(NFSUtil): """TestUtil object TestUtil() -> New server object Usage: x = TestUtil() # Process command line options x.scan_options() # Start packet trace using tcpdump x.trace_start()
import symbol from formatstr import * import nfstest_config as c from baseobj import BaseObj from packet.unpack import Unpack from packet.record import Record from packet.pkt import Pkt, PKT_layers from packet.link.ethernet import ETHERNET # Module constants __author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL __copyright__ = "Copyright (C) 2012 NetApp, Inc." __license__ = "GPL v2" __version__ = "2.0" BaseObj.debug_map(0x100000000, 'pkt1', "PKT1: ") BaseObj.debug_map(0x200000000, 'pkt2', "PKT2: ") BaseObj.debug_map(0x400000000, 'pkt3', "PKT3: ") BaseObj.debug_map(0x800000000, 'pkt4', "PKT4: ") BaseObj.debug_map(0xF00000000, 'pktt', "PKTT: ") # Map of tokens _token_map = dict(token.tok_name.items() + symbol.sym_name.items()) # Map of items not in the array of the compound _nfsopmap = {'status': 1, 'tag': 1} # Match function map _match_func_map = dict( zip(PKT_layers, ["self._match_%s" % x for x in PKT_layers])) class Header(BaseObj):