<s> """<STR_LIT>""" <EOL> import sys <EOL> from bacpypes . debugging import Logging , function_debugging , ModuleLogger <EOL> from bacpypes . consolelogging import ConsoleLogHandler <EOL> from bacpypes . pdu import Address <EOL> from bacpypes . analysis import trace , strftimestamp , Tracer <EOL> from bacpypes . apdu import ReadPropertyRequest , ReadPropertyACK <EOL> try : <EOL> from CSStat import Statistics <EOL> except ImportError : <EOL> Statistics = lambda : None <EOL> _debug = <NUM_LIT:0> <EOL> _log = ModuleLogger ( globals ( ) ) <EOL> filterSource = None <EOL> filterDestination = None <EOL> filterHost = None <EOL> filterEval = None <EOL> requests = { } <EOL> traffic = [ ] <EOL> class Traffic : <EOL> def __init__ ( self , req ) : <EOL> self . req = req <EOL> self . resp = None <EOL> self . ts = req . _timestamp <EOL> self . retry = <NUM_LIT:1> <EOL> @ function_debugging <EOL> def Match ( addr1 , addr2 ) : <EOL> """<STR_LIT>""" <EOL> if _debug : Match . _debug ( "<STR_LIT>" , addr1 , addr2 ) <EOL> if ( addr2 . addrType == Address . localBroadcastAddr ) : <EOL> return ( addr1 . addrType == Address . localStationAddr ) or ( addr1 . addrType == Address . localBroadcastAddr ) <EOL> elif ( addr2 . addrType == Address . localStationAddr ) : <EOL> return ( addr1 . addrType == Address . localStationAddr ) and ( addr1 . addrAddr == addr2 . addrAddr ) <EOL> elif ( addr2 . addrType == Address . remoteBroadcastAddr ) : <EOL> return ( ( addr1 . addrType == Address . remoteStationAddr ) or ( addr1 . addrType == Address . remoteBroadcastAddr ) ) and ( addr1 . addrNet == addr2 . addrNet ) <EOL> elif ( addr2 . addrType == Address . remoteStationAddr ) : <EOL> return ( addr1 . addrType == Address . remoteStationAddr ) and ( addr1 . addrNet == addr2 . addrNet ) and ( addr1 . addrAddr == addr2 . addrAddr ) <EOL> elif ( addr2 . addrType == Address . globalBroadcastAddr ) : <EOL> return ( addr1 . addrType == Address . globalBroadcastAddr ) <EOL> else : <EOL> raise RuntimeError , "<STR_LIT>" <EOL> class ReadPropertySummary ( Tracer , Logging ) : <EOL> def __init__ ( self ) : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> Tracer . __init__ ( self , self . Filter ) <EOL> def Filter ( self , pkt ) : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" , pkt ) <EOL> global requests <EOL> if filterSource : <EOL> if not Match ( pkt . pduSource , filterSource ) : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> return <EOL> if filterDestination : <EOL> if not Match ( pkt . pduDestination , filterDestination ) : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> return <EOL> if filterHost : <EOL> if ( not Match ( pkt . pduSource , filterHost ) ) and ( not Match ( pkt . pduDestination , filterHost ) ) : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> return <EOL> if filterEval : <EOL> try : <EOL> matches = eval ( filterEval , { '<STR_LIT>' : pkt } ) <EOL> if not matches : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> return <EOL> except : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> return <EOL> if isinstance ( pkt , ReadPropertyRequest ) : <EOL> key = ( pkt . pduSource , pkt . pduDestination , pkt . apduInvokeID ) <EOL> if key in requests : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> requests [ key ] . retry += <NUM_LIT:1> <EOL> else : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> msg = Traffic ( pkt ) <EOL> requests [ key ] = msg <EOL> traffic . append ( msg ) <EOL> elif isinstance ( pkt , ReadPropertyACK ) : <EOL> key = ( pkt . pduDestination , pkt . pduSource , pkt . apduInvokeID ) <EOL> req = requests . get ( key , None ) <EOL> if req : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> requests [ key ] . resp = pkt <EOL> del requests [ key ] <EOL> else : <EOL> if _debug : ReadPropertySummary . _debug ( "<STR_LIT>" ) <EOL> try : <EOL> if ( '<STR_LIT>' in sys . argv ) : <EOL> indx = sys . argv . index ( '<STR_LIT>' ) <EOL> for i in range ( indx + <NUM_LIT:1> , len ( sys . argv ) ) : <EOL> ConsoleLogHandler ( sys . argv [ i ] ) <EOL> del sys . argv [ indx : ] <EOL> if _debug : _log . debug ( "<STR_LIT>" ) <EOL> if ( '<STR_LIT>' in sys . argv ) : <EOL> i = sys . argv . index ( '<STR_LIT>' ) <EOL> filterSource = Address ( sys . argv [ i + <NUM_LIT:1> ] ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , filterSource ) <EOL> del sys . argv [ i : i + <NUM_LIT:2> ] <EOL> if ( '<STR_LIT>' in sys . argv ) : <EOL> i = sys . argv . index ( '<STR_LIT>' ) <EOL> filterDestination = Address ( sys . argv [ i + <NUM_LIT:1> ] ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , filterDestination ) <EOL> del sys . argv [ i : i + <NUM_LIT:2> ] <EOL> if ( '<STR_LIT>' in sys . argv ) : <EOL> i = sys . argv . index ( '<STR_LIT>' ) <EOL> filterHost = Address ( sys . argv [ i + <NUM_LIT:1> ] ) <EOL> if _debug : _log . debug ( "<STR_LIT>" , filterHost ) <EOL> del sys . argv [ i : i + <NUM_LIT:2> ] <EOL> if ( '<STR_LIT>' in sys . argv ) : <EOL> i = sys . argv . index ( '<STR_LIT>' ) <EOL> filterEval = sys . argv [ i + <NUM_LIT:1> ] <EOL> if _debug : _log . debug ( "<STR_LIT>" , filterEval ) <EOL> del sys . argv [ i : i + <NUM_LIT:2> ] <EOL> requests = { } <EOL> for fname in sys . argv [ <NUM_LIT:1> : ] : <EOL> trace ( fname , [ ReadPropertySummary ] ) <EOL> stats = Statistics ( ) <EOL> for msg in traffic : <EOL> req = msg . req <EOL> resp = msg . resp <EOL> if resp : <EOL> deltatime = ( resp . _timestamp - req . _timestamp ) * <NUM_LIT:1000> <EOL> if stats : <EOL> stats . Record ( deltatime , req . _timestamp ) <EOL> print strftimestamp ( req . _timestamp ) , '<STR_LIT:\t>' , req . pduSource , '<STR_LIT:\t>' , resp . pduSource , '<STR_LIT:\t>' , ( "<STR_LIT>" % ( deltatime , ) ) , '<STR_LIT:\t>' , msg . retry if ( msg . retry != <NUM_LIT:1> ) else "<STR_LIT>" <EOL> else : <EOL> print strftimestamp ( req . _timestamp ) , '<STR_LIT:\t>' , req . pduSource , '<STR_LIT:\t>' , "<STR_LIT>" , '<STR_LIT:\t>' , "<STR_LIT>" , '<STR_LIT:\t>' , msg . retry if ( msg . retry != <NUM_LIT:1> ) else "<STR_LIT>" <EOL> if stats : <EOL> xlw , lw , q1 , m , q3 , uw , xuw = stats . Whisker ( ) <EOL> if m is not None : <EOL> print "<STR_LIT>" % xuw <EOL> print "<STR_LIT>" % uw <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" % q3 <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" % m <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" % q1 <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" % lw <EOL> print "<STR_LIT>" % xlw <EOL> else : <EOL> print "<STR_LIT>" <EOL> except KeyboardInterrupt : <EOL> pass <EOL> except Exception , e : <EOL> _log . exception ( "<STR_LIT>" , e ) <EOL> finally : <EOL> if _debug : _log . debug ( "<STR_LIT>" ) </s>
