Date: Sun, 9 Aug 2009 04:21:26 GMT From: Zachariah Riggle <zjriggl@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 167121 for review Message-ID: <200908090421.n794LQNE035830@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=167121 Change 167121 by zjriggl@zjriggl_tcpregression on 2009/08/09 04:21:02 Periodic submit Affected files ... .. //depot/projects/soc2009/zjriggl_tcpregression/Makefile#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/loggable.py#6 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/.project#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/.pydevproject#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/__init__.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/__init__.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/arp.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/dhcpv4.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/dns.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/ethernet.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/icmpv4.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/icmpv6.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/ipsec.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/ipv4.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/ipv6.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/localhost.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/nd6.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/payload.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/pseudoipv6.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/tcp.orig.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/tcp.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/tcpv6.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/udp.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/udpv4.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/packets/udpv6.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap.so#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/HEAD#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/config#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/description#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/applypatch-msg.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/commit-msg.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/post-commit.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/post-receive.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/post-update.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/pre-applypatch.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/pre-commit.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/pre-rebase.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/prepare-commit-msg.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/hooks/update.sample#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/index#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/info/exclude#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/logs/HEAD#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/logs/refs/heads/master#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/logs/refs/remotes/origin/HEAD#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/objects/pack/pack-77f13729543285782c830a6a087aeb8ce3ad7c33.idx#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/objects/pack/pack-77f13729543285782c830a6a087aeb8ce3ad7c33.pack#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/packed-refs#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/refs/heads/master#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.git/refs/remotes/origin/HEAD#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.project#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/.pydevproject#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/CHANGES#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/LICENSE#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/Makefile#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/README#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/config.h#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/config.pkl#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/pcap.c#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/pcap.pyx#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/pcap.so#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/pcap_ex.c#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/pcap_ex.h#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/setup.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/test.pcap#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/test.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcs/pcap/testsniff.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/__init__.py#9 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/decorators.py#5 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/field.py#3 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/ipAddress.py#6 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/networkPort.py#5 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/sequence.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpstatemachine.py#9 edit .. //depot/projects/soc2009/zjriggl_tcpregression/src/tests/segmentBufferTest.py#1 add .. //depot/projects/soc2009/zjriggl_tcpregression/src/tests/tcpFilterTest.py#1 add Differences ... ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/loggable.py#6 (text+ko) ==== @@ -2,32 +2,65 @@ import pcsextension import inspect -# Configure logging +# -------- Configure logging -------- logging.config.fileConfig( "logging.conf" ) +# -------- Set Up New Loglevel Names -------- ( logging.FIELD_CHANGE, - logging.RESPONSE_GENERATION ) = range( logging.DEBUG - 2, logging.DEBUG ) - + logging.RESPONSE_GENERATION ) = range( logging.DEBUG - 2, logging.DEBUG ) + ( logging.PACKET_TRANSMIT, logging.PACKET_RECEIVED, logging.PACKET_SENT, logging.VALIDATE, logging.STATE_CHANGE ) = range( logging.INFO - 5, logging.INFO ) + +# -------- ANSI/VT100 Colors -------- +( fgBlack, +fgRed, +fgGreen, +fgYellow, +fgBlue, +fgMagenta, +fgCyan, +fgWhite ) = range( 30, 38 ) + +( bgBlack, +bgRed, +bgGreen, +bgYellow, +bgBlue, +bgMagenta, +bgCyan, +bgWhite ) = range( 40, 48 ) + +def colorText( text, fgColor = '', bgColor = '' ): + ''' + Returns text colored corresponding to the the ANSI/VT100 color code + provided a arguments. Colors are defined as fg_____ or bg_____ with + the color name. Alternatively, directly use the color code, see below. + Foreground Background Color + Code Code + 30 40 Black + 31 41 Red + 32 42 Green + 33 43 Yellow + 34 44 Blue + 35 45 Magenta + 36 46 Cyan + 37 47 White + ''' + return "\033[1;%s;%sm%s\033[1;m" % ( fgColor, bgColor, text ) + +# -------- Loglevel names -------- logging.addLevelName( logging.FIELD_CHANGE, "FIELD" ) -logging.addLevelName( logging.RESPONSE_GENERATION, "\033[1;36mGENERATE\033[1;m" ) -logging.addLevelName( logging.PACKET_TRANSMIT, "XMIT" ) -logging.addLevelName( logging.PACKET_RECEIVED, "\033[1;31mRECVD\033[1;m" ) -logging.addLevelName( logging.PACKET_SENT, "\033[1;31mSENT\033[1;m" ) +logging.addLevelName( logging.RESPONSE_GENERATION, colorText( "GENERATE", fgCyan ) ) +logging.addLevelName( logging.PACKET_RECEIVED, colorText( "RECVD", fgYellow ) ) +logging.addLevelName( logging.PACKET_SENT, colorText( "SENT", fgGreen ) ) logging.addLevelName( logging.VALIDATE, "VALIDATE" ) -logging.addLevelName( logging.STATE_CHANGE, "\033[1;37;44mSTATE\033[1;m" ) - -# 1;37;44 +logging.addLevelName( logging.STATE_CHANGE, colorText( "STATE", fgBlue ) ) -# print '\033[1;36mGENERATE\033[1;m' -# print '\033[1;36mCyan like Caribbean\033[1;m' -# '\033[1;31mRed like Radish\033[1;m' - class tcplog( object ): ''' Provides rapid access to logging mechanisms for derived classes. @@ -35,7 +68,7 @@ Provides all of the standard log levels: debug info - warn/warning + warn/warnings error fatal/critical As well as some custom-defined ones: @@ -65,22 +98,22 @@ ''' def __init__( self, parent ): - # self._log = logging.getLogger(parent.__class__.__module__ + '.' + parent.__class__.__name__) - self._log = logging.getLogger( parent.__class__.__name__ ) + # self.logger = logging.getLogger(parent.__class__.__module__ + '.' + parent.__class__.__name__) + self.logger = logging.getLogger( parent.__class__.__name__ ) def caller( self ): return inspect.stack()[2][3] - debug = lambda self, x: self._log.debug( "%s - %s" % ( self.caller(), x ) ) - info = lambda self, x: self._log.info( x ) - error = lambda self, x: self._log.error( x ) - critical = lambda self, x: self._log.critical( x ) - fatal = lambda self, x: self._log.fatal( x ) - warning = lambda self, x: self._log.warning( x ) - warn = lambda self, x: self._log.warn( x ) - state = lambda self, x: self._log.log( logging.STATE_CHANGE, x ) - validate = lambda self, x: self._log.log( logging.VALIDATE, x ) - pktsent = lambda self, x: self._log.log( logging.PACKET_SENT, x ) - pktrecv = lambda self, x: self._log.log( logging.PACKET_RECEIVED, x ) - generated = lambda self, x: self._log.log( logging.RESPONSE_GENERATION, x ) - field = lambda self, x: self._log.log( logging.FIELD_CHANGE, x ) + debug = lambda self, x: self.logger.debug( "%s - %s" % ( self.caller(), x ) ) + info = lambda self, x: self.logger.info( x ) + error = lambda self, x: self.logger.error( x ) + critical = lambda self, x: self.logger.critical( x ) + fatal = lambda self, x: self.logger.fatal( x ) + warning = lambda self, x: self.logger.warning( x ) + warn = lambda self, x: self.logger.warn( x ) + state = lambda self, x: self.logger.log( logging.STATE_CHANGE, x ) + validate = lambda self, x: self.logger.log( logging.VALIDATE, x ) + pktsent = lambda self, x: self.logger.log( logging.PACKET_SENT, x ) + pktrecv = lambda self, x: self.logger.log( logging.PACKET_RECEIVED, x ) + generated = lambda self, x: self.logger.log( logging.RESPONSE_GENERATION, x ) + field = lambda self, x: self.logger.log( logging.FIELD_CHANGE, x ) ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/__init__.py#9 (text+ko) ==== @@ -28,27 +28,13 @@ p = p.data return None - - -def inet_lton( integer ): - return struct.pack( ">L", integer ) - -def inet_ltoa( integer ): - return socket.inet_ntoa( inet_lton( integer ) ) - -def inet_ntol( byteString ): - return struct.unpack( ">L", byteString )[0] - -def inet_atol( ipString ): - return inet_ntol( socket.inet_aton( ipString ) ) - -def wireSharkFormatBytes(x): +def wireSharkFormatBytes( x ): twoBits = r"(\w\w)" octet = "((%s ){8})" % twoBits twoBytes = "((%s ){2})" % octet - x = re.sub(twoBits,r"\1 ",x) - x = re.sub(octet,r"\1 ",x) - x = re.sub(twoBytes,r"\1\n",x) + x = re.sub( twoBits, r"\1 ", x ) + x = re.sub( octet, r"\1 ", x ) + x = re.sub( twoBytes, r"\1\n", x ) return x ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/decorators.py#5 (text+ko) ==== @@ -5,48 +5,10 @@ ''' import sys -from inspect import * +# from inspect import * +from inspect import stack -""" -One of three degrees of enforcement may be specified by passing -the 'debug' keyword argument to the decorator: - 0 -- NONE: No type-checking. Decorators disabled. - 1 -- MEDIUM: Print warning message to stderr. (Default) - 2 -- STRONG: Raise TypeError with message. -If 'debug' is not passed to the decorator, the default level is used. - -Example usage: - >>> NONE, MEDIUM, STRONG = 0, 1, 2 - >>> - >>> @accepts(int, int, int) - ... @returns(float) - ... def average(x, y, z): - ... return (x + y + z) / 2 - ... - >>> average(5.5, 10, 15.0) - TypeWarning: 'average' method accepts (int, int, int), but was given - (float, int, float) - 15.25 - >>> average(5, 10, 15) - TypeWarning: 'average' method returns (float), but result is (int) - 15 - -Needed to cast params as floats in function def (or simply divide by 2.0). - - >>> TYPE_CHECK = STRONG - >>> @accepts(int, debug=TYPE_CHECK) - ... @returns(int, debug=TYPE_CHECK) - ... def fib(n): - ... if n in (0, 1): return n - ... return fib(n-1) + fib(n-2) - ... - >>> fib(5.3) - Traceback (most recent call last): - ... - TypeError: 'fib' method accepts (int), but was given (float) - -""" -def accepts(*types, **kw): +def accepts( *types, **kw ): """ Function decorator. Checks that inputs given to decorated function are of the expected type. @@ -63,20 +25,20 @@ else: debug = kw['debug'] try: - def decorator(f): - def newf(*args): + def decorator( f ): + def newf( *args ): if debug == 0: - return f(*args) - assert len(args) == len(types) - - if not validateTypes(args,types): - argtypes = tuple(map(type, args)) - msg = info(f.__name__, types, argtypes, 0) + return f( *args ) + assert len( args ) == len( types ) + + if not validateTypes( args, types ): + argtypes = tuple( map( type, args ) ) + msg = info( f.__name__, types, argtypes, 0 ) if debug == 1: print >> sys.stderr, 'TypeWarning: ', msg elif debug == 2: raise TypeError, msg - return f(*args) + return f( *args ) newf.__name__ = f.__name__ return newf return decorator @@ -84,45 +46,45 @@ raise KeyError, key + "is not a valid keyword argument" except TypeError, msg: raise TypeError, msg - - -def validateTypes(argTypeMap): + + +def validateTypes( argTypeMap ): debug = 1 - + arg = 0 - for (k,v) in argTypeMap.items(): - if not isinstance(k,v): + for ( k, v ) in argTypeMap.items(): + if not isinstance( k, v ): parentFile = stack()[1][1] parentLine = stack()[1][2] parentName = stack()[1][3] - - msg = 'TypeWarning: Arg %i of %s (%s:%i) should be %s. Encountered %s. \n' % (arg, parentName, parentFile, parentLine, v, type(k)) - - if len(stack()) > 2: + + msg = 'TypeWarning: Arg %i of %s (%s:%i) should be %s. Encountered %s. \n' % ( arg, parentName, parentFile, parentLine, v, type( k ) ) + + if len( stack() ) > 2: grandParentFile = stack()[2][1] grandParentLine = stack()[2][2] grandParentName = stack()[2][3] - - msg += 'Referenced from %s:%i in %s\n' % (grandParentFile, grandParentLine, grandParentName) - + + msg += 'Referenced from %s:%i in %s\n' % ( grandParentFile, grandParentLine, grandParentName ) + if debug == 1: - sys.stderr.write(msg) + sys.stderr.write( msg ) elif debug == 2: raise TypeError, msg return False return True -def info(fname, expected, actual, flag): +def info( fname, expected, actual, flag ): """ Convenience function returns nicely formatted error/warning msg. """ - format = lambda types: ', '.join([str(t).split("'")[1] for t in types]) - expected, actual = format(expected), format(actual) + format = lambda types: ', '.join( [str( t ).split( "'" )[1] for t in types] ) + expected, actual = format( expected ), format( actual ) msg = "'%s' method " % fname \ - + ("accepts", "returns")[flag] + " (%s), but " % expected\ - + ("was given", "result is")[flag] + " (%s)" % actual + + ( "accepts", "returns" )[flag] + " (%s), but " % expected\ + + ( "was given", "result is" )[flag] + " (%s)" % actual return msg - -def prop(func): + +def prop( func ): '''A decorator function for easy property creation. >>> class CLS(object): @@ -186,13 +148,13 @@ ''' ops = func() or {} - name=ops.get('name') or ops.get('prefix','_')+func.__name__ # property name - fget=ops.get('fget',lambda self:getattr(self, name)) - fset=ops.get('fset',lambda self,value:setattr(self,name,value)) - fdel=ops.get('fdel',lambda self:delattr(self,name)) - return property ( fget, fset, fdel, ops.get('doc',func.__doc__ or '') ) + name = ops.get( 'name' ) or ops.get( 'prefix', '_' ) + func.__name__ # property name + fget = ops.get( 'fget', lambda self:getattr( self, name ) ) + fset = ops.get( 'fset', lambda self, value:setattr( self, name, value ) ) + fdel = ops.get( 'fdel', lambda self:delattr( self, name ) ) + return property ( fget, fset, fdel, ops.get( 'doc', func.__doc__ or '' ) ) -def boundedInt(func): +def boundedInt( func ): ''' A bounded integer. See @prop for syntax. Set the 'max' field to set a wrap-around value. @@ -213,63 +175,42 @@ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ''' ops = func() or {} - upperBound = ops.get('max',1) # default to bound it to 2 + upperBound = ops.get( 'max', 1 ) # default to bound it to 2 wrapValue = upperBound + 1 - - name=ops.get('prefix','_')+func.__name__ # property name - fget = lambda self: getattr(self,name) % upperBound - fset = lambda self,value: setattr(self,name, (value % wrapValue)) - fdel = lambda self: delattr(self,value) - return property (fget, fset, fdel, ops.get('doc','') ) + + name = ops.get( 'prefix', '_' ) + func.__name__ # property name + fget = lambda self: getattr( self, name ) % upperBound + fset = lambda self, value: setattr( self, name, ( value % wrapValue ) ) + fdel = lambda self: delattr( self, name ) + return property ( fget, fset, fdel, ops.get( 'doc', '' ) ) -def uint32(func): - max = 2**32 +def uint32( func ): + max = 2 ** 32 ops = func() or {} - name=ops.get('prefix','_')+func.__name__ # property name - fget = lambda self: getattr(self,name) - fset = lambda self,value: setattr(self, name, (value % max)) - fdel = lambda self: delattr(self,value) - return property (fget, fset, fdel, func.__doc__) + name = ops.get( 'prefix', '_' ) + func.__name__ # property name + fget = lambda self: getattr( self, name ) + fset = lambda self, value: setattr( self, name, ( value % max ) ) + fdel = lambda self: delattr( self, name ) + return property ( fget, fset, fdel, func.__doc__ ) -def uint16(func): - max = 2**16 +def uint16( func ): + max = 2 ** 16 ops = func() or {} - name=ops.get('prefix','_')+func.__name__ # property name - fget = lambda self: getattr(self,name) - fset = lambda self,value: setattr(self, name, (value % max)) - fdel = lambda self: delattr(self,value) - return property (fget, fset, fdel, func.__doc__) + name = ops.get( 'prefix', '_' ) + func.__name__ # property name + fget = lambda self: getattr( self, name ) + fset = lambda self, value: setattr( self, name, ( value % max ) ) + fdel = lambda self: delattr( self, name ) + return property ( fget, fset, fdel, func.__doc__ ) +def synchronized( lock ): + """ Synchronization decorator. """ -def uint(limit=2**32): - ''' - >>> from pcsextension.decorators import * - >>> lim = 5 - >>> class A(object): - ... @uint(lim) - ... def x(): pass - ... _x = 0 - ... - _x - 5 - >>> a = A() - >>> l = [] - >>> for i in range(0,lim*2): - ... a.x = i - ... l += [a.x] - ... - >>> print l - [0, 1, 2, 3, 4, 0, 1, 2, 3, 4] - ''' - def unsignedInteger(func): - ops = func() or {} - name=ops.get('prefix','_')+func.__name__ # property name - - print name - print max - - fget = lambda self: getattr(self,name) - fset = lambda self,value: setattr(self, name, (value % max)) - fdel = lambda self: delattr(self, value) - return property(fget, fset, fdel) - return unsignedInteger+ def wrap( f ): + def newFunction( *args, **kw ): + lock.acquire() + try: + return f( *args, **kw ) + finally: + lock.release() + return newFunction + return wrap ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/field.py#3 (text+ko) ==== @@ -20,13 +20,13 @@ def __init__( self, default = 0, width = 8, networkByteOrder = False ): self.width = width self.networkByteOrder = networkByteOrder - + if isinstance( default, int ): self.setInteger( default ) if isinstance( default, str ): self.setAscii( default ) - if isinstance( default, Field): - self.setNetworkBytes(default.getNetworkBytes()) + if isinstance( default, Field ): + self.setNetworkBytes( default.getNetworkBytes() ) def setAscii( self, x ): ''' @@ -148,4 +148,4 @@ elif self.width == 8: if ( self.width == 8 and len( self.getBytes() ) > self.width * 8 ) or \ ( self.getInteger() > ( ( 2 ** self.width ) - 1 ) ): - raise Exception, "Value exceeds bit-width %i" % self.width+ raise Exception, "Value exceeds bit-width %i" % self.width ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/ipAddress.py#6 (text+ko) ==== @@ -4,13 +4,12 @@ @author: zach ''' -from socket import inet_ntoa, inet_aton, htons, ntohs, htonl, ntohl, inet_pton, inet_ntop from struct import pack, unpack from field import Field -from socket import IPPROTO_IP, IPPROTO_IPV6, AF_INET, AF_INET6, htonl, ntohl +from socket import IPPROTO_IP, IPPROTO_IPV6, AF_INET, AF_INET6, inet_ntoa, inet_aton, htons, ntohs, htonl, ntohl, inet_pton, inet_ntop class IpAddress( Field ): - ''' + ''' Stores an IP address, and provides helper methods to retrieve the IP address. Unless specified, all byte orders are host-byte-order. ''' @@ -20,11 +19,11 @@ def __init__( self, default = 0, width = None, networkByteOrder = False, version = AF_INET ): self.version = version Field.__init__( self, width = width, default = default, networkByteOrder = networkByteOrder ) - + # Override the default Field.__init__ behavior. If the string's length is 4, it is obviously # a byte-string as opposed to an IP address. - if type(default) == str: - if len(default) == 4: + if type( default ) == str: + if len( default ) == 4: self.nbo = default def setAscii( self, x ): @@ -52,7 +51,7 @@ return unpack( "!L", self.nbo )[0] def setNetworkInteger( self, x ): - self.nbo = pack( "!L", ntohl( x ) ) + self.nbo = pack( "!L", ntohl( x ) ) def getNetworkInteger( self ): return htonl( unpack( "!L", self.nbo )[0] ) ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/networkPort.py#5 (text+ko) ==== @@ -51,10 +51,10 @@ self.ho = ntohs( x ) def getNetworkInteger( self ): - print "%s %s" % (type(self.ho), self.ho) + print "%s %s" % ( type( self.ho ), self.ho ) return htons( self.ho ) - - def getPCS(self): + + def getPCS( self ): return self.getInteger() def __eq__( self, x ): ==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpstatemachine.py#9 (text+ko) ==== @@ -8,7 +8,7 @@ from pcs.packets import tcp, payload from pcsextension import findTcpLayer from pcsextension.checksum import tcpChecksum -from pcsextension.decorators import prop, validateTypes, uint16, uint32 +from pcsextension.decorators import prop, validateTypes, uint16, uint32, synchronized from pcsextension.hwAddress import HwAddress from pcsextension.ipAddress import IpAddress from pcsextension.networkPort import NetworkPort @@ -17,10 +17,11 @@ from tcpConstructor import tcpConstructor from tcpFilter import tcpFilter from tcprecvdaemon import TcpRecvDaemon -from tcpsenddaemon import TcpSendDaemon -from tcpstates import CLOSE_WAIT,CLOSED,CLOSING,ESTABLISHED,FIN_WAIT_1,FIN_WAIT_2, \ +from tcpsenddaemon import TcpSendDaemon +from tcpstates import CLOSE_WAIT, CLOSED, CLOSING, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, \ LAST_ACK, LISTEN, SYN_RECEIVED, SYN_SENT, TIME_WAIT, TcpState, synchronizedStates, tcpStates from time import time +from threading import RLock import pcap import pcs import testconfig @@ -119,22 +120,23 @@ __connector = tcpFilter( testconfig.interface ) __recvThread = None __sendThread = None + lock = RLock() # @uint32 @prop - def snd_nxt(): + def snd_nxt(): ''' Next sequence to be sent (SND.NXT). This is automatically calculated based on the next-available index in outboundSequences. However, if the value is set directly, it is overridden. Set it to None to re-enable auto-calculation - ''' + ''' return {'fget': lambda self: self._snd_nxt or self.outboundSequences.nextIndex } - + _snd_nxt = None # Define snd_nxt to allow it to be overridden - + @prop - def snd_una(): + def snd_una(): ''' First (i.e. oldest) unacknowledged sequence (SND.UNA). This is automatically calculated based on the first index in outboundSequences. @@ -142,32 +144,32 @@ remove any information from the retransmit queue with a lower SEQ #. ''' return {'fget': lambda self: self.outboundSequences.base, - 'fset': lambda self, x: self.outboundSequences.setBase(x) } + 'fset': lambda self, x: self.outboundSequences.setBase( x ) } # _snd_una = # Not necessary... - + @uint16 def snd_wnd(): ''' Send window size (SND.WND) ''' _snd_wnd = 0 - + @uint16 def snd_up(): ''' Send urgent pointer ''' _snd_up = 0 - + @uint32 - def snd_wl1(): ''' Sequence number used for last window update. ''' + def snd_wl1(): ''' Sequence number used for last window update. ''' _snd_wl1 = 0 - + @uint32 def snd_wl2(): ''' Ack number used for last window update ''' _snd_wl2 = 0 - + @prop def iss(): ''' Initial Send Sequence (ISS) ''' - return {'fset': lambda self, x: self.setISS(x) } + return {'fset': lambda self, x: self.setISS( x ) } _iss = 0 - - def setISS(self, iss): + + def setISS( self, iss ): ''' Sets the ISS, and also updates the outboundSequences base to reflect the new ISS. Any information in outboundSequences is deleted. @@ -177,31 +179,32 @@ # self.outboundSequences.base = iss self.outboundSequences = [] self.outboundSequences.base = iss - + @uint16 def rcv_wnd(): ''' Receive Window (RCV.WND) ''' - _rcv_wnd = 2**16 - 1 - + _rcv_wnd = 2 ** 16 - 1 + @uint16 def rcv_up(): ''' Receive Urgent Pointer ''' _rcv_up = 0 - + @prop def irs(): ''' Initial Receive Sequence (IRS) ''' - return {'fset': lambda self,x: self.setIRS(x)} + return {'fset': lambda self, x: self.setIRS( x )} _irs = 0 - - def setIRS(self,irs): + + def setIRS( self, irs ): ''' @see setISS ''' self._irs = irs self.inboundSequences.base = irs + self.inboundSequences = [] del self.inboundSequences[:] # self.inboundSequences = segmentBuffer([], irs, self.inboundSequences.limit) # self.inboundSequences.base = irs - + # @uint32 # def rcv_nxt(): @prop @@ -219,14 +222,14 @@ msl = 2 * 60 # Maximum Segment Lifetime. Arbitrarily defined in the RFC to 2 minutes timeout = 2 * msl # Timeout - @prop - def processPacketsOnArrival(): + @prop + def processPacketsOnArrival(): ''' Flag used to start/stop the recv'er thread from processing additional packets. Default is True. ''' _processPacketsOnArrival = True - + @prop def autoResendUnackedSequences(): ''' @@ -260,26 +263,26 @@ @prop def remotePort(): '''Remote port.''' _remotePort = NetworkPort( default = testconfig.remotePort ) - + @prop def userTimer(): ''' User timeout timer ''' _userTimer = None - + @prop def timeWaitTimer(): ''' Time-wait timer ''' _timeWaitTimer = None - + # Interface is actually a shortcut to the connector's interface field, # which is itself a property. Setting a TcpStateMachine's interface will # effectively trigger the tcpFilter object to switch interfaces to the # specified interface. @prop - def interface(): + def interface(): '''Interface to use for sending/recving data''' return {'fget': lambda self: self.__connector.interface, - 'fset': lambda self,x: setattr(self.__connector,'interface',x)} + 'fset': lambda self, x: setattr( self.__connector, 'interface', x )} - def getConnector(self): + def getConnector( self ): ''' Retrieves the connector used to send and receive packets. Note: The name 'connector' is simply for consistency. The object that is @@ -292,20 +295,20 @@ Call with lb=True to omit the ethernet layer with a loopback layer in its place. This should be done when using lo0 instead of eth0, or the source and destination IP address are the same. - ''' + ''' self.__constructor.loopback = lb # Override the interface - if lb and (self.interface not in self.loopbackInterfaces): + if lb and ( self.interface not in self.loopbackInterfaces ): self.log.warn( 'Overriding interface to be %s' % self.loopbackInterfaces[0] ) - + devs = [dev[0] for dev in pcap.findalldevs()] - loInterface = (iface for iface in self.loopbackInterfaces if iface in devs) - - if len(loInterface) < 1: - self.log.error('cannot set loopback, could not identify any ' + loInterface = ( iface for iface in self.loopbackInterfaces if iface in devs ) + + if len( loInterface ) < 1: + self.log.error( 'cannot set loopback, could not identify any ' ' loopback interfaces in available interfaces (%s) out ' - ' of known loopback interfaces (%s)' % (devs, self.loopbackInterfaces)) + ' of known loopback interfaces (%s)' % ( devs, self.loopbackInterfaces ) ) else : # Select the first interface self.interface = loInterface[0] @@ -319,7 +322,7 @@ def mtu(): '''Maximum Tranmission Unit''' _mtu = testconfig.mtu - def isSynchronized(self): + def isSynchronized( self ): ''' Is the connection in a synchronized state? Return True if yes, otherwise False. @@ -360,12 +363,12 @@ #tcp.f_dport: True, 'transition': True } - def generateISS(self): + def generateISS( self ): ''' Generates a new Initial Sequence Number (ISS). ''' - return seq(random.randint(0,(1 << 32)-1)) - + return seq( random.randint( 0, ( 1 << 32 ) - 1 ) ) + # def _updateSegmentBuffer(self, newBuffer, oldBuffer): # # If it's the same object, just return it. # if newBuffer is oldBuffer: @@ -378,7 +381,7 @@ # # # If it is the correct type, but is just a new buffer, assign it. # return newBuffer - + @prop def outboundSequences(): ''' @@ -395,25 +398,25 @@ Note that this implementation does not gracefully deal with wrap, i.e. when the sequence number overflows 2**32. ''' - return {'fset': lambda self,x: self.outboundSequences.update(x) } + return {'fset': lambda self, x: self.outboundSequences.update( x ) } _outboundSequences = segmentBuffer() - + @prop def inboundSequences(): ''' List of all received sequences. This includes data recv'd from IRS onward. @see outboundSequences for more information. ''' - return {'fset': lambda self,x: self.inboundSequences.update(x) } + return { 'fset': lambda self, x: self.inboundSequences.update( x ) } _inboundSequences = segmentBuffer() - + @prop def retransmissionQ(): ''' Sent data that has not been acknowledged. ''' return {'fget': lambda self: self.outboundSequences[self.snd_una:]} - + @prop def recvBuffer(): ''' @@ -421,50 +424,17 @@ Note that this buffer will explicitly exclude all SYN and FIN sequences. @see inboundSequences ''' - return {'fget': - lambda self: + return {'fget': + lambda self: [octet for octet in self.inboundSequences[seq( self.recvBufferOffset + self.irs ):] \ - if type(octet) != sequenced or not (octet.syn or octet.ack) ] + if type( octet ) != sequenced or not ( octet.syn or octet.ack ) ] } - + @prop def recvBufferOffset(): return {'fget': lambda self: self.inboundSequences.base, - 'fset': lambda self, x: self.inboundSequences.setBase(x) } -# @uint32 -# def _recvBufferOffset(): -# ''' -# Offset to the 'read' pointer in recvBuffer. This offset is relative to IRS, -# which is the first item in inboundSequences -# ''' -# __recvBufferOffset = 0 - -# @prop -# def packetsSent(): -# return {'doc': 'List of all packets the have been sent.' } -# _packetsSent = [] -# -# @prop -# def packetsSentAcked(): -# return {'doc': 'List of all packets the have been sent, for which ' -# 'an ACKnowledgement message has not been received.'} -# _packetsSentAcked = [] -# -# @prop -# def packetsRecvd(): -# return {'doc': 'List of all packets the have been received, but have not been ACKnowledged. ' -# 'Upon receiving, a packet will be put into this buffer. If its sequence number is rcv_nxt, ' -# 'it is moved to packetsRecvdAcked, and rcv_next is updated.'} -# _packetsRecvd = [] -# _packetsRecvdOffset = 0 -# -# @prop -# def packetsRecvdAcked(): -# return {'doc': 'List of all packets the have been received, but have not ' -# 'been ACKnowledged.'} -# _packetsRecvdAcked = [] + 'fset': lambda self, x: self.inboundSequences.setBase( x ) } - @prop def state(): return {'fset': lambda self, x: self.setState( x ), @@ -493,14 +463,14 @@ connName = 'Connection naming not supported' recvWindow = str( self.rcv_wnd ) sendWindow = str( self.snd_wnd ) - state = str(self.state) - nbaAck = len(self.retransmissionQ) + state = str( self.state ) + nbaAck = len( self.retransmissionQ ) # TODO TODO TODO # This should be the number of octets that have been received, but have # not been accounted for in an 'ACK' message to the other side. # TODO TODO TODO - nbpRecpt = 0 - + nbpRecpt = 0 + # TODO TODO TODO # Urgent state is not currently supported, and will be added later as # tests call for its use. @@ -513,8 +483,8 @@ return ( localSocket, remoteSocket, connName, recvWindow, sendWindow, state, nbaAck, nbpRecpt, urgState, precedence, security, timeout ) - def __repr__(self): - + def __repr__( self ): + return self.__class__.__name__ + '( (%s,%s), (%s,%s) )' % \ ( self.localIP, self.localPort, self.remoteIP, self.remotePort ) @@ -555,38 +525,36 @@ # Is the state a valid state? if state in tcpStates: - # if ( not self.validate['transition'] ) or ( state in self.state.next ): - # if ( not validateTransition ) or ( state in self.state.next ): action = "Setting" if validateTransition: action = "Advancing" self.log.state( "%s state from %s to %s" % ( action, self.state, state ) ) - + if state not in self.state.next: self.log.state( "Performing non-valid state transition from %s to %s" % ( self._lastState, self.state ) ) - + self._lastState = self._state self._state = state - + # If we are transitioning OUT of closed state, start the threads. if self._lastState == CLOSED: self.__recvThread = TcpRecvDaemon( self ) self.__sendThread = TcpSendDaemon( self ) self.__recvThread.start() self.__sendThread.start() - + >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908090421.n794LQNE035830>