Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jun 2009 08:03:00 GMT
From:      Zachariah Riggle <zjriggl@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 164796 for review
Message-ID:  <200906210803.n5L830R1055929@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=164796

Change 164796 by zjriggl@zjriggl_tcpregression on 2009/06/21 08:02:56

	Periodic commit

Affected files ...

.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/__init__.py#4 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/hwAddress.py#2 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/ipAddress.py#2 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/networkPort.py#2 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/payload.py#2 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpConstructor.py#4 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpFilter.py#4 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpstatemachine.py#3 edit
.. //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/testconfig.py#4 edit

Differences ...

==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/__init__.py#4 (text+ko) ====

@@ -4,6 +4,7 @@
 import socket
 import sys
 
+from pcs.packets.ipv4 import ipv4
 from pcs.packets.tcp import tcp
 from pcs.packets.tcpv6 import tcpv6
 
@@ -28,11 +29,19 @@
 
 # Find the TCP layer in a packet.
 def findTcpLayer(packet):
+    return findPacketLayer(packet,tcp)
+
+def findIpLayer(packet):
+    return findPacketLayer(packet,ipv4)
+
+def findPacketLayer(packet, _class):
     p = packet
     while p is not None:
-        if isinstance(p,tcp) or isinstance(p,tcpv6):
+        if isinstance(p,_class):
             return p
         p = p.data
+    return None
+        
         
     
 def inet_lton(integer):
@@ -45,33 +54,4 @@
     return struct.unpack(">L",byteString)[0]
 
 def inet_atol(ipString):
-    return inet_ntol(socket.inet_aton(ipString))
-
-def getPcsFormattedIP(ipAddr):
-    if type(ipAddr) == str:
-        # The byte representation's length will be 4 bytes
-        if len(ipAddr) == 4:
-            return inet_ntol(ipAddr)
-        
-        # Otherwise, the length is between len("0.0.0.0") and len("255.255.255.255") (lengths are 7 and 15)
-        elif  7 <= len(ipAddr) and len(ipAddr) <= 15:
-            return inet_atol(ipAddr)
-        
-    elif type(ipAddr) == int:
-        return ipAddr
-    
-    logging.warn("Could not properly identify IP address type for: %s" % str(ipAddr))
-    return 0
-    
-def getPcsFormattedPort(port):
-    if type(port) == str:
-        if port.isdigit():
-            return htons(int(port))
-        else:
-            return struct.unpack("!i",'A\x00\x00\x00')[0]
-        
-    if type(port) == int:
-        return port
-    
-    logging.warn("Could not properly identify port type for: %s" % str(ipAddr))
-    return 0+    return inet_ntol(socket.inet_aton(ipString))
==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/hwAddress.py#2 (text+ko) ====

@@ -6,57 +6,67 @@
 from socket import inet_ntoa, inet_aton, htons, ntohs, htonl, ntohl
 from struct import pack, unpack
 import binascii
+from field import Field
 
-class hwAddress(object):
+class HwAddress( Field ):
     '''
     Stores a hardware address, and provides helper methods to retrieve the hardware address.
     Unless specified, all byte orders are host-byte-order.
     '''
-    
+
     # 00:00:00:00:00:00
     nbo = '\x00\x00\x00\x00\x00\x00'
-    
-    def setAscii(self, x):
-        
+
+    def setAscii( self, x ):
+
         nbo = ""
-        for word in x.split(":"):
-            nbo += binascii.a2b_hex(word)
-            
+        for word in x.split( ":" ):
+            nbo += binascii.a2b_hex( word )
+
         self.nbo = nbo
-        
-    def getAscii(self):
-        
+
+    def getAscii( self ):
+
         ascii = ""
         for b in self.nbo:
-            ascii += binascii.b2a_hex(b) + ":"
-            
+            ascii += binascii.b2a_hex( b ) + ":"
+
         # Strip of the trailing ":", return
         return ascii[0:-1]
-    
-    def setBytes(self, bytes):
+
+    def setBytes( self, bytes ):
         self.nbo = bytes[::-1]
-    
-    def getBytes(self):
-        return self.nbo[::-1]    
-    
-    def setNetworkBytes(self, bytes):
+
+    def getBytes( self ):
+        return self.nbo[::-1]
+
+    def setNetworkBytes( self, bytes ):
         self.nbo = bytes
-    
-    def getNetworkBytes(self):
+
+    def getNetworkBytes( self ):
         return self.nbo
-    
-    def setInteger(self, x):
-        self.nbo = pack("L", x)
-         
-    def getInteger(self):
-        return unpack("L", self.nbo)[0]
-    
-    def setNetworkInteger(self, x):
-         self.nbo = pack("!L", x)
-         
+
+    def setInteger( self, x ):
+        self.nbo = pack( "L", x )
+
+    def getInteger( self ):
+        return unpack( "L", self.nbo )[0]
+
+    def setNetworkInteger( self, x ):
+         self.nbo = pack( "!L", x )
+
          # Make sure the length is 6 bytes/48 bit
-         while len(self.nbo) > 6:
+         while len( self.nbo ) > 6:
              self.nbo = '\x00' + self.nbo
-    
-    def getNetworkInteger(self):
-        return unpack("!L", self.nbo)[0]+
+    def getNetworkInteger( self ):
+        return unpack( "!L", self.nbo )[0]
+
+    def getPCS( self ):
+        return self.getNetworkBytes()
+
+    def setPCS( self, x ):
+        self.setNetworkBytes( x )
+
+    def __str__( self ):
+        return getAscii()

==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/ipAddress.py#2 (text+ko) ====

@@ -4,43 +4,55 @@
 @author: zach
 '''
 
-from socket import inet_ntoa, inet_aton, htons, ntohs, htonl, ntohl
+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
 
-class IpAddress(object):
+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.
     '''
-    
+
     nbo = '\x7f\x00\x00\x01'
-    
-    def setAscii(self, x):
-        self.nbo = inet_aton(x)
-        
-    def getAscii(self):
-        return inet_ntoa(self.nbo)
-    
-    def setBytes(self, bytes):
-        self.nbo = bytes[::-1]
-    
-    def getBytes(self):
-        return self.nbo[::-1]    
-    
-    def setNetworkBytes(self, bytes):
+
+    def __init__( self, default = 0, width = None, networkByteOrder = False, version = AF_INET ):
+        self.version = version
+        Field.__init__( self, width = width, default = default, networkByteOrder = networkByteOrder )
+
+    def setAscii( self, x ):
+        self.nbo = inet_pton( self.version, x )
+
+    def getAscii( self ):
+        return inet_ntop( self.version, self.nbo )
+
+    def setBytes( self, bytes ):
+        self.nbo = bytes
+
+    def getBytes( self ):
+        return pack( "L", self.getInteger() )
+
+    def setNetworkBytes( self, bytes ):
         self.nbo = bytes
-    
-    def getNetworkBytes(self):
+
+    def getNetworkBytes( self ):
         return self.nbo
-    
-    def setInteger(self, x):
-        self.nbo = pack("L", x)
-         
-    def getInteger(self):
-        return unpack("L", self.nbo)[0]
-    
-    def setNetworkInteger(self, x):
-         self.nbo = pack("!L", x)
-    
-    def getNetworkInteger(self):
-        return unpack("!L", self.nbo)[0]
+
+    def setInteger( self, x ):
+        self.nbo = pack( "!L", x )
+
+    def getInteger( self ):
+        return unpack( "!L", self.nbo )[0]
+
+    def setNetworkInteger( self, x ):
+         self.nbo = pack( "!L", ntohl( x ) )
+
+    def getNetworkInteger( self ):
+        return htonl( unpack( "!L", self.nbo )[0] )
+
+    def getPCS( self ):
+        return self.getNetworkInteger()
+
+    def setPCS( self, x ):
+        self.setNetworkInteger( x )

==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/networkPort.py#2 (text+ko) ====

@@ -12,45 +12,52 @@
 
 from socket import inet_ntoa, inet_aton, htons, ntohs, htonl, ntohl
 from struct import pack, unpack
+from field import Field
 
-class NetworkPort(object):
+class NetworkPort( Field ):
     '''
     Stores an network (TCP/UDP) port, and provides helper methods to retrieve the port.
     Unless specified, all byte orders are host-byte-order.
     '''
-    
+
     # Host-order integer internally
     ho = 80
-    
-    def __init__(self):
-        pass
-    
-    def setAscii(self, x):
-        self.ho = int(x)
-        
-    def getAscii(self):
-        return str(self.ho)
-    
-    def setBytes(self, bytes):
-        self.ho = unpack("L",bytes)
-    
-    def setNetworkBytes(self, bytes):
-        self.ho = unpack("!L",bytes)
-    
-    def getBytes(self):
-        return pack("L", self.ho)
-    
-    def getNetworkBytes(self):
-        return pack("!L", self.ho) 
-    
-    def setInteger(self, x):
+
+    def setAscii( self, x ):
+        self.ho = int( x )
+
+    def getAscii( self ):
+        return str( self.ho )
+
+    def setBytes( self, bytes ):
+        self.ho = unpack( "H", bytes )
+
+    def setNetworkBytes( self, bytes ):
+        self.ho = unpack( "!H", bytes )
+
+    def getBytes( self ):
+        return pack( "H", self.ho )
+
+    def getNetworkBytes( self ):
+        return pack( "!H", self.ho )
+
+    def setInteger( self, x ):
         self.ho = x
-         
-    def getInteger(self):
+
+    def getInteger( self ):
         return self.ho
-    
-    def setNetworkInteger(self, x):
-        self.ho = ntohs(x)
-        
-    def getNetworkInteger(self):
-        return htons(self.ho)+
+    def setNetworkInteger( self, x ):
+        self.ho = ntohs( x )
+
+    def getNetworkInteger( self ):
+        return htons( self.ho )
+
+    def __eq__( self, x ):
+        if isinstance( x, int ):
+            return x == self.getInteger()
+        if isinstance( x, str ):
+            if( x.isdigit() ):
+                return x == self.getAscii()
+            else:
+                return x == self.getBytes()

==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/pcsextension/payload.py#2 (text+ko) ====

@@ -5,40 +5,40 @@
 '''
 
 import pcs
-from pcsextension.StringField import StringField 
+from pcsextension.StringField import StringField
 from pprint import pformat
 import inspect
 import time
 import struct
 
-class payload(pcs.Packet):
+class Payload( pcs.Packet ):
     """Payload"""
 
     _layout = pcs.Layout()
     _map = None
-    
-    def __init__(self, bytes = None, **kv):
+
+    def __init__( self, bytes = None, **kv ):
         """initialize a payload packet"""
-        pcs.Packet.__init__(self, [], bytes = bytes, **kv)
-        self.description = inspect.getdoc(self)
+        pcs.Packet.__init__( self, [], bytes = bytes, **kv )
+        self.description = inspect.getdoc( self )
 
         # Dencode
-        self.decode(bytes)
+        self.decode( bytes )
 
         # Unconditionally the last packet in a chain
         self.data = None
-        
-    def encode(self):
+
+    def encode( self ):
         pass
-    
-    def decode(self, value):
+
+    def decode( self, value ):
         self._bytes = value
-        
-    def getbytes(self):
-        return struct.pack("!%ss" % len(self._bytes), self._bytes)
+
+    def getbytes( self ):
+        return struct.pack( "!%ss" % len( self._bytes ), self._bytes )
 
-    def __str__(self):
+    def __str__( self ):
         """return a readable version of a payload object"""
         retval = "Payload\n"
-        retval += "%s" % pformat(self.payload)
-        return retval+        retval += "%s" % pformat( self._bytes )
+        return retval

==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpConstructor.py#4 (text+ko) ====

@@ -5,106 +5,138 @@
 '''
 
 import socket
-from pcs.packets import ipv4
-from pcs.packets import ipv6
-from pcs.packets import tcp
-from pcs.packets import tcpv6
-from pcs.packets import ethernet
+import testconfig
+from random import randint
+from pcs.packets.ipv4 import ipv4
+from pcs.packets.tcp import tcp
+from pcs.packets.ethernet import *
+from socket import IPPROTO_IPV4, IPPROTO_IPV6, IPPROTO_TCP
+from pcsextension.ipAddress import IpAddress
+from pcsextension.hwAddress import HwAddress
+from pcsextension.checksum import *
+
+class tcpConstructor:
+    '''
+    Used to construct a packet complete with hardware and IP layers.
+    Currently supports:
+    - Ethernet
+    - IPv4
+    TODO IPv6
+    '''
+    ipVersion = IPPROTO_IPV4
+    localIP = IpAddress()
+    remoteIP = IpAddress()
+
+    localHw = HwAddress()
+    remoteHw = HwAddress()
+
+    def __init__( self ):
+        self.localIP.setAscii( testconfig.localIP )
+        self.remoteIP.setAscii( testconfig.remoteIP )
+
+        self.localHw.setAscii( testconfig.localMAC )
+        self.remoteHw.setAscii( testconfig.remoteMAC )
+
+    def setLocalIP( self, ip ):
+        '''
+        Sets the IP address to be used as the source IP address in the IP layer.
+        @param ip
+            IP parameter supports dotted-quad strings and IpAddress objects.
+        '''
+        if isinstance( ip, str ):
+            self.localIP.setAscii( ip )
+        elif isinstance( ip, IpAddress ):
+            self.localIP.setAscii( ip.getAscii() )
 
+    def setRemoteIP( self, ip ):
+        '''
+        Sets the IP address to be used as the remote address in the IP layer.
+        @see setLocalIP
+        '''
+        if isinstance( ip, str ):
+            self.remoteIP.setAscii( ip )
+        elif isinstance( ip, IpAddress ):
+            self.remoteIP.setAscii( ip.getAscii() )
 
-class tcpStateMachine:
-     
-    
-    srcMac = "FF:FF:FF:FF:FF:FF"
-    dstMac = "FF:FF:FF:FF:FF:FF"
-    srcPort = 1025
-    dstPort = 1025
-    srcIP = "127.0.0.1"
-    dstIP = "127.0.0.1"
-    ipv6 = False
-    
+    def setIpVersion( self, version ):
+        '''
+        Sets the IP version to be used when creating the IP layer.
+        @param version
+            Either socket.IPPROTO_IPV4 or socket.IPPROTO_IPV6
+        '''
+        if version == IPPROTO_IPV4 or version == IPPROTO_IPV6:
+            self.ipVersion = version
 
-    
-    # Tcp States
-    ( CLOSED,       # Initial closed state 
-    LISTEN,        # Listening for connections
-    SYNSENT,       # Initial SYN sent 
-    SYNRECVD,      # Initial SYN recvd
-    ESTAB,         # Connection established
-    FINWAIT1,      # FIN-Wait 1
-    CLOSEWAIT,     # Close-Wait
-    FINWAIT2,      # FIN-Wait 2
-    CLOSING,       # Connection closing
-    LASTACK,       # Last ACK
-    TIMEWAIT,      # Connection closing
-    CLOSED2 ) = range(12)       # Connection terminated
+    def generateIPv4( self ):
+        '''
+        Generates a pcs.packets.ipv4.ipv4 object with all of the fields set
+        to the following values:
+        - protocol = socket.IPPROTO_TCP
+        - src = local IP address (@see setLocalIP)
+        - dst = remote IP address (@see setRemoteIP)
+        - id = Random, between 0 and 65535 inclusive
         
-    
-    
-    
-    def tcpConstructor(self, srcMAC, srcIP, srcPort, dstMAC, dstIP, dstPort, ipv6=False):
-        self.srcMac = srcMAC
-        self.dstMac = dstMAC
-        self.srcPort = srcPort
-        self.dstPort = dstPort
-        self.srcIP = srcIP
-        self.dstIP = dstIP
-        
-    def createEthernetPacket(self):
-        ether = ethernet.ethernet()
-        ether.type = ethernet.ETHERTYPE_IP
-        ether.src = ethernet.ether_atob(testconfig.localMAC)
-        ether.dst = ethernet.ether_atob(testconfig.remoteMAC)
-        
-    
-    def _createIpv4Packet(self):
+        Other values are filled in with default values that will likely be changed.
+        '''
+        ip = ipv4()
+        ip.version = 4
+        ip.hlen = 5
+        ip.tos = 0  # Normal
+        ip.length = 20
+        ip.id = randint( 0, 65535 ) # See RFC4413, pp. 20
+        ip.flags = 0x4 # 'Dont fragment'
+        ip.ttl = 64
+        ip.protocol = IPPROTO_TCP
+        ip.src = self.localIP.getPCS()
+        ip.dst = self.remoteIP.getPCS()
+        return ip
+
+    def generateIPv6( self ):
+        '''
+        Genreates a pcs.packets.ipv6.ipv6 object
+        TODO: Not supported.
+        '''
         pass
-    
-    def _createIpv6Packet(self):
-        pass
-    
-    def _createTCPv4Packet(self):
-        pass
-    
-    def _createTCPv6Packet(self):
-        pass
-    
-    def createIpPacket(self):
-        pass
-    
-    def createTcpPacket(self):
-        pass
-    
-    def buildConnectionPacket(self):
-        pass
-        
-    def buildPacket(self, srcMAC, srcIP, srcPort, dstMAC, dstIP, dstPort, ipv6=False):
-        
-        # Set ethernet information.
-        ether = ethernet.ethernet()
-        ether.type = ethernet.ETHERTYPE_IP
-        ether.src = ethernet.ether_atob(srcMAC)
-        ether.dst = ethernet.ether_atob(dstMAC)
-        
-        # IP and TCP levels
-        ip = None
-        t = None
-        
-        # Create the proper IP and TCP types
-        if ipv6 is True:
-            raise NotImplementedError
-        else:
-            ip = ipv4.ipv4()
-            t = tcp.tcp()
-            ip.src =inet_atol(srcIP)
-            ip.dst =inet_atol(dstIP)
+
+    def generateIP( self ):
+        '''
+        Generates the appropriate IP layer, depending on what the user has selected.
+        @see setIpVersion
+        @see generateIPv4
+        @see generateIPv6
+        '''
+        if self.ipVersion == IPPROTO_IPV4:
+            return self.generateIPv4()
+        elif self.ipVersion == IPPROTO_IPV6:
+            return self.generateIPv6()
+        return None
+
+    def generateEthernet( self ):
+        '''
+        Generates the ethernet-level data...
+        '''
+        ether = ethernet()
+        ether.type = ETHERTYPE_IP
+        ether.src = self.localHw.getPCS()
+        ether.dst = self.remoteHw.getPCS()
+        return ether
+
+    def generateChain( self, tcpPacket ):
+        '''
+        Generates a pcs.Chain complete with Ethernet and IP levels, that uses the provided
+        pcs.packets.tcp.tcp object as the TCP layer.
+        NOTE: This method makes no modifications to the TCP packet, and as such does not
+        perform any validation of auto-generation of ANY TCP fields.  The length of the
+        TCP header + data is necessary to set the IP length field.
+        '''
+        ether = self.generateEthernet()
+        ip = self.generateIP()
+
+        ether.data = ip
+        ip.data = tcpPacket
+
+        # Set the proper IP length and checksum
+        ip.length = ip.length + len( tcpPacket.chain().bytes )
+        ip.checksum = ipChecksum( ip )
 
-        t = tcp.tcp()
-        t.sport = srcPort
-        t.dport = dstPort
-        t.seq = 1
-        t.window = 1024
-        
-        ip.protocol = socket.IPPROTO_TCP
-        ip.checksum = ip.calc_checksum()
-        +        return ether.chain()

==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpFilter.py#4 (text+ko) ====

@@ -1,47 +1,48 @@
-from pcsextension import intToBytes, bytesToInt
-
 import sys
 import logging
 import struct
 
-from socket import inet_ntoa, ntohs, inet_aton, htons
+from socket import inet_ntoa, ntohs, inet_aton, htons, getnameinfo
 
-from loggable import Loggable
+from loggable import tcplog
 from pcs import PcapConnector
 from pcs.packets.ipv4 import ipv4
 from pcs.packets.tcp import tcp
 from pcs.packets.tcpv6 import tcpv6
 from pcs.packets.ethernet import ethernet
+from pcsextension.ipAddress import IpAddress
+from pcsextension.networkPort import NetworkPort
+from pcsextension import findIpLayer, findTcpLayer
 
-class tcpFilter(Loggable):
+class tcpFilter(object):
 
+    log = None
     pcapHandle = None
     doRead = False
     
     def __init__(self, interfaceName):
-        Loggable._setLogKey(self)
+        self.log = tcplog(self)
         self.openInterface(interfaceName)
 
     def openInterface(self, interfaceName):
         try:
             self.pcapHandle = PcapConnector(interfaceName)
+            # self.pcapHandle = IP4Connector();
         except:
-           self.log.error("Could not open interface %s" % interfaceName)
+            self.log.error("Could not open interface %s" % interfaceName)
             
     def read(self):
         return self.pcapHandle.readpkt()
         
-    def write(self,packet,byets):
-        self.pcapHandle.write(packet,bytes)
+    def write(self,bytes):
+        self.pcapHandle.write(bytes,len(bytes))
         
-    def readFilteredByIP(self, ipAddress):
+    def readFilteredByIP(self, ip):
         """
         Reads packets until a packet is found going either to or from the specified IP address
         is discovered.  Returns the first matching packet.
-        @param port TCP port in network byte order (byte-string or integer representation)
-        @return A pcs.ipv4.ipv4 or pcs.ipv6.ipv6 object.
-        @see pcs.htons(integer)
-        @see pcs.htonl(integer)
+        @param ip IpAddress or dotted-quad string
+        @return A pcs.Packet object
         """
         
 #        if isinstance(ipAddress,int):
@@ -49,58 +50,52 @@
 
         # If the IP address is a string ("127.0.0.1") or byte array ('\x7f\x00\x00\x01')
         # we need to convert it into an integer representation of the same.
-        if isinstance(ipAddress,str):
-            if len(ipAddress) != 4:
-                ipAddress = inet_aton(ipAddress)
-            
-            ipAddress = bytesToInt(ipAddress)
-                
+        if isinstance(ip,str):
+            tmp = IpAddress()
+            tmp.setAscii(ip)
+            ip = tmp
+
+        srcIP = IpAddress()
+        dstIP = IpAddress()
         
         while True:
             packet = self.read()
             
-            if isinstance(packet,ethernet):
-                packet = packet.data
+            ipLayer = findIpLayer(packet)
             
-            if not isinstance(packet,ipv4):
+            if ipLayer == None:
                 continue
             
-            if (not packet.src == ipAddress) and \
-                (not packet.dst == ipAddress):
-                continue
+            srcIP.setNetworkInteger(ipLayer.src)
+            dstIP.setNetworkInteger(ipLayer.dst)
             
-            return packet
+            if ipLayer.src == ip.getPCS() or ipLayer.dst == ip.getPCS():
+                return packet            
         
     def readFilteredByTuple(self, ipAddress, port):
         """
         Reads packets until a packet is found going either to or from [1] the specified
         IP address and [2] the specified port.  Returns the first matching packet.
-        @param ipAddress IP address in network byte order.
-        @param port TCP port in network byte order.
-        @return A pcs.tcp.tcp or pcs.tcpv6.tcpv6 object.
-        @see pcs.inet_aton(string)
-        @see pcs.htons(integer)
-        @see pcs.htonl(integer)
+        @param IpAddress object or dotted-quad string ('127.0.0.1')
+        @param NetworkPort object or integer port number.
+        @return A pcs.Packet object.
+        @see readFilteredByIP
         """
         
+        if isinstance(port,int):
+            tmp = NetworkPort()
+            tmp.setInteger(port)
+            port = tmp
+        
         while True:
             packet = self.readFilteredByIP(ipAddress)
             
-            if isinstance(port,str):
-                if port.isdigit():
-                    port = htons(port)
-                
-                port = bytesToInt(port)
-                
-            port = htons(port)
-            
-            if (not isinstance(packet.data, tcp)) and \
-                (not isinstance(packet.data, tcpv6)):
+            tcpLayer = findTcpLayer(packet)
+            if tcpLayer == None:
                 continue
             
-            tcpPacket = packet.data
-            if (not tcpPacket.sport == port) and \
-                (not tcpPacket.dport == port):
-                continue
+            print tcpLayer.sport
+            print port.getNetworkInteger()
             
-            return packet+            if tcpLayer.sport == port.getInteger() or tcpLayer.dport == port.getInteger():
+                return packet
==== //depot/projects/soc2009/zjriggl_tcpregression/src/tcpregression/tcpstatemachine.py#3 (text+ko) ====

@@ -5,21 +5,20 @@
 '''
 
 from loggable import tcplog
+from pcs.packets import ethernet, ipv4, tcp
 from pcsextension.decorators import prop, validateTypes
+from pcsextension.hwAddress import HwAddress
 from pcsextension.ipAddress import IpAddress
 from pcsextension.networkPort import NetworkPort
 from pcsextension.pseudoipv4 import pseudoipv4, ipv4_cksum
 from socket import IPPROTO_TCP
-from tcpstates import *
 from tcpFilter import tcpFilter
+from tcpConstructor import tcpConstructor
+from tcpstates import
+import binascii
 import binhex
 import pcs
-from pcs.packets import tcp
-from pcs.packets import ipv4
-from pcs.packets import ethernet
 import testconfig
-import binascii
-
 
 # Valid state transitions, as defined by the diagram on RFC 793 pp. 23:
 #    September 1981                                                          
@@ -76,7 +75,7 @@
 #    
 #                                                                   [Page 23]
 
-class TcpStateMachine(object):
+class TcpStateMachine( object ):
     '''
     Enumerates the various states of a TCP connection as defined by RFC 793, 
     pages 21-22.
@@ -107,139 +106,129 @@
     >>> t.state
     3
     '''
-    
-    _connector = None
-    
-    def generateInitialSequence(self):
+
+    _constructor = tcpConstructor()
+    _connector = tcpFilter( testconfig.interface )
+
+    def generateInitialSequence( self ):
         return 0
-    
+
     snd_nxt = 0       # Next available send sequence #
     snd_una = 0         # Unacknowledge send sequence #
-    snd_wnd = 128*1024  # Send window
-    snd_up  = 0         # Seng urgent pointer
+    snd_wnd = 128 * 1024  # Send window
+    snd_up = 0         # Seng urgent pointer
     snd_wl1 = 0         # Sequence number used for last window update
     snd_wl2 = 0         # Ack number used for last window update
-    iss     = -1        # Initial sequence number
-    
-    rcv_wnd = 128*1024  # Recv window size
-    rcv_up  = 0         # Recv urgent pointer
-    irs     = -1        # Initial receive sequence number
+    iss = -1        # Initial sequence number
+
+    rcv_wnd = 128 * 1024  # Recv window size
+    rcv_up = 0         # Recv urgent pointer
+    irs = -1        # Initial receive sequence number
     rcv_nxt = irs       # Expected next recv sequence #
-    
+
     ack_nxt = 0         # Next ACK number to send.
     ack_lst = 0         # Last ACK number sent.
-    
+
     msl = 2 * 60        # Maximum Segment Lifetime. Arbitrarily defined in the RFC to 2 minutes
-    timeout = 2*msl     # Timeout
-    
-    
+    timeout = 2 * msl     # Timeout
+
+    # Ethernet stuff
+    def localEthernet():
+        return {'doc': 'Local hardware ethernet address'}
+    _localEthernet = HwAddress( default = testconfig.localMAC )
+
+    def remoteEthernet():
+        return {'doc': 'Remote hardware ethernet address'}
+    remoteEthernet = HwAddress( default = testconfig.remoteMAC )
+
     @prop
     def localIP():
         return {'doc': 'Local IP address.'}
-        
-        
+    _localIP = IpAddress( default = testconfig.localIP )
+
     @prop
     def remoteIP():
         return {'doc': 'Remote IP address.' }
-        
+    _remoteIP = IpAddress( default = testconfig.remoteIP )
+
     @prop
     def localPort():
         return {'doc': 'Local port.'}
-    
+    _localPort = NetworkPort( default = testconfig.localPort )
+
     @prop
     def remotePort():
-        return {'doc': 'Remote port.'} 
-    
+        return {'doc': 'Remote port.'}
+    _remotePort = NetworkPort( default = testconfig.remotePort )
+
     @prop
     def mtu():
         return {'doc': 'Maximum Tranmission Unit'}
-    
-#    packetsToSend = []
-    # = testconfig.mtu
-    
-    
+    _mtu = testconfig.mtu
+
+    def generate():
+        return {'doc': 'What fields of outgoing TCP packets should be auto-generated.'}
+    _generate = {'cksum': True,
+                'off': True,
+                'seq': True,
+                'acknum': True,
+                'sport': True,
+                'dport': True,
+                'window': True,
+                'urg': True,
+                'ack': True,
+                'syn': True,
+                'fin': True,
+                'rst': True,
+                'psh': True,
+                'urgp': True }
+
+    @prop
+    def validate():
+        return {'doc': 'What fields of incoming TCP packets should be validated.'}
+    _validate = { 'cksum': True,
+                'seq': True,
+                'acknum': True,
+                'sport': True,
+                'dport': True }
+
     @prop
     def packetsToSend():
         return {'doc': 'List of all packets to be sent.' }
-    
+    _packetsToSend = []
+
     @prop
     def packetsSent():
         return {'doc': 'List of all packets the have been sent.' }
+    _packetsSent = []
 
-    # packetsSent = []
     @prop
     def packetsSentAcked():
         return {'doc': 'List of all packets the have been sent, for which '
                 'an ACKnowledgement message has not been received.'}
-    #packetsSentUnack = []
-    
+    _packetsSentAcked = []
+
     @prop
-    def packetsRecvd(): 
-        return {'doc': 'List of all packets the have been received, but have not been ACKnowledged.  ' 
+    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 = []

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906210803.n5L830R1055929>