Show
Ignore:
Timestamp:
08/23/08 16:48:00 (5 years ago)
Author:
getxsick
Message:

Never ending the docstrings story ;)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branch/UMPA/umpa/protocols/TCP.py

    r3479 r3608  
    2020# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
    2121 
     22""" 
     23This module contains TCP (Transmission Control Protocol) protocol 
     24implementation. 
     25""" 
     26 
    2227from umpa.protocols import _consts 
    2328from umpa.protocols import _fields 
     
    2833 
    2934class _HPort(_fields.EnumField): 
     35    """ 
     36    TCP uses the notion of port numbers to identify sending and receiving 
     37    application end-points on a host, or Internet sockets. 
     38    """ 
     39 
    3040    bits = 16 
    3141    auto = False 
     
    324334 
    325335class _HSequenceNumber(_fields.IntField): 
    326     """The sequence number of the first data octet in this segment (except 
     336    """ 
     337    The sequence number of the first data octet in this segment (except 
    327338    when SYN is present). 
    328339 
    329340    See RFC 793 for more. 
    330341    """ 
     342 
    331343    bits = 32 
    332344    auto = True 
     345     
    333346    def _generate_value(self): 
     347        """ 
     348        Generate value for undefined field yet. 
     349         
     350        @return: auto-generated value of the field. 
     351        """ 
     352 
    334353        # TODO: implemention real auto-filling here ;) 
    335354        # otherwise we can simple return 0 
     
    337356 
    338357class _HAcknowledgmentNumber(_fields.IntField): 
    339     """If the ACK control bit is set this field contains the value of the 
     358    """ 
     359    If the ACK control bit is set this field contains the value of the 
    340360    next sequence number the sender of the segment is expecting to receive. 
    341361 
    342362    See RFC 793 for more. 
    343363    """ 
     364     
    344365    bits = 32 
    345366    auto = True 
     367     
    346368    def _generate_value(self): 
     369        """ 
     370        Generate value for undefined field yet. 
     371         
     372        @return: auto-generated value of the field. 
     373        """ 
     374 
    347375        # TODO: implemention real auto-filling here ;) 
    348376        # otherwise we can simple return 0 
     
    350378 
    351379class _HDataOffset(_fields.SpecialIntField): 
    352     """The number of 32 bit words in the TCP Header. This indicates where 
     380    """ 
     381    The number of 32 bit words in the TCP Header. This indicates where 
    353382    the data begins. 
    354383 
    355384    See RFC 793 for more. 
    356385    """ 
     386     
    357387    bits = 4 
    358388    auto = True 
     389     
    359390    def _generate_value(self): 
     391        """ 
     392        Generate value for undefined field yet. 
     393         
     394        @return: auto-generated value of the field. 
     395        """ 
     396 
    360397        # returns in 32-bits units 
    361398        return 5 + self._tmp_value / 32 # 5 is a minimum value 
    362399 
    363400class _HReserved(_fields.IntField): 
    364     """Reserved for future use. 
     401    """ 
     402    Reserved for future use. 
    365403 
    366404    See RFC 793 for more. 
    367405    """ 
     406     
    368407    bits = 6 
    369408    auto = True 
     409     
    370410    def _generate_value(self): 
     411        """ 
     412        Generate value for undefined field yet. 
     413         
     414        @return: auto-generated value of the field. 
     415        """ 
     416 
    371417        return 0 
    372418 
    373419class _HWindow(_fields.IntField): 
    374     """The number of data octets beginning with the one indicated in the 
     420    """ 
     421    The number of data octets beginning with the one indicated in the 
    375422    acknowledgment field which the sender of this segment is willing to accept. 
    376423 
    377424    See RFC 793 for more. 
    378425    """ 
     426     
    379427    bits = 16 
    380428    auto = True 
     429     
    381430    def _generate_value(self): 
     431        """ 
     432        Generate value for undefined field yet. 
     433         
     434        @return: auto-generated value of the field. 
     435        """ 
     436 
    382437        # TODO: implemention real auto-filling here ;) 
    383438        # otherwise we can simple return 0 
     
    385440 
    386441class _HUrgentPointer(_fields.IntField): 
    387     """This field communicates the current value of the urgent pointer as a 
     442    """ 
     443    This field communicates the current value of the urgent pointer as a 
    388444    positive offset from the sequence number in this segment. 
    389445 
    390446    See RFC 793 for more. 
    391447    """ 
     448     
    392449    bits = 16 
    393450    auto = True 
     451     
    394452    def _generate_value(self): 
     453        """ 
     454        Generate value for undefined field yet. 
     455         
     456        @return: auto-generated value of the field. 
     457        """ 
     458 
    395459        # TODO: implemention real auto-filling here ;) 
    396460        # otherwise we can simple return 0 
     
    398462 
    399463class TCP(_protocols.Protocol): 
    400     """This is Transmission Control Protocol. 
     464    """ 
     465    Transmission Control Protocol implementation. 
     466 
    401467    It the most common protocol in the Internet on fourth layer 
    402468    of the OSI model. 
    403469    """ 
     470     
    404471    layer = 4       # layer of the OSI 
    405472    protocol_id = _consts.PROTOCOL_TCP 
     
    412479 
    413480    def __init__(self, **kw): 
     481        """ 
     482        Create a new TCP(). 
     483 
     484        @param **kw: pass to super-constructor. 
     485        """ 
     486 
    414487        control_bits = ('urg', 'ack', 'psh', 'rst', 'syn', 'fin') 
    415488        control_bits_predefined = dict.fromkeys(control_bits, 0) 
     
    450523 
    451524    def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     525        """ 
     526        Handle with fields before calling fillout() for them. 
     527 
     528        Set Padding field and calculate header length. 
     529 
     530        @type raw_value: C{int} 
     531        @param raw_value: currently raw value for the packet. 
     532 
     533        @type bit: C{int} 
     534        @param bit: currently length of the protocol. 
     535 
     536        @type protocol_container: C{tuple} 
     537        @param protocol_container: tuple of protocols included in the packet. 
     538 
     539        @type protocol_bits: C{int} 
     540        @param protocol_bits: currently length of the packet. 
     541 
     542        @return: C{raw_value, bit} 
     543        """ 
     544 
    452545        # Padding 
    453546        self._get_field('_padding')._tmp_value = \ 
     
    461554 
    462555    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     556        """ 
     557        Handle with fields after calling fillout() for them. 
     558 
     559        Calculate header checksum with new instance of PseudoHeader object. 
     560 
     561        @type raw_value: C{int} 
     562        @param raw_value: currently raw value for the packet. 
     563 
     564        @type bit: C{int} 
     565        @param bit: currently length of the protocol. 
     566 
     567        @type protocol_container: C{tuple} 
     568        @param protocol_container: tuple of protocols included in the packet. 
     569 
     570        @type protocol_bits: C{int} 
     571        @param protocol_bits: currently length of the packet. 
     572 
     573        @return: C{raw_value, bit} 
     574        """ 
     575 
    463576        # rev_offset it the offset from the right side 
    464577        cksum_rev_offset = bit - self.get_offset('_checksum') - \