Changeset 3608

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

Never ending the docstrings story ;)

Location:
branch/UMPA/umpa/protocols
Files:
8 modified

Legend:

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

    r3540 r3608  
    1919# along with this library; if not, write to the Free Software Foundation,  
    2020# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
     21 
     22""" 
     23This module contains ICMP (Internet Control Message Protocol) protocol 
     24implementation. 
     25""" 
    2126 
    2227from umpa.protocols import _consts 
     
    282287 
    283288class _HChecksum(_fields.IntField): 
     289    """ 
     290    A checksum of the ICMP protocol. 
     291    """ 
     292 
    284293    bits = 16 
    285294    auto = True 
     
    291300 
    292301class ICMP(_protocols.Protocol): 
     302    """ 
     303    Internet Control Message Protocol implementation. 
     304 
     305    It the most common protocol in the Internet on fourth layer 
     306    of the OSI model. 
     307    """ 
     308     
    293309    layer = 4 
    294310    protocol_id = _consts.PROTOCOL_ICMP 
     
    298314 
    299315    def __init__(self, **kw): 
     316        """ 
     317        Create a new ICMP(). 
     318 
     319        @param **kw: pass to super-constructor. 
     320        """ 
     321 
    300322        raise NotImplementedError("not finished yet") 
    301323        fields_list = [ _HType("Type"), 
     
    307329 
    308330    def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     331        """ 
     332        Handle with fields before calling fillout() for them. 
     333 
     334        @type raw_value: C{int} 
     335        @param raw_value: currently raw value for the packet. 
     336 
     337        @type bit: C{int} 
     338        @param bit: currently length of the protocol. 
     339 
     340        @type protocol_container: C{tuple} 
     341        @param protocol_container: tuple of protocols included in the packet. 
     342 
     343        @type protocol_bits: C{int} 
     344        @param protocol_bits: currently length of the packet. 
     345 
     346        @return: C{raw_value, bit} 
     347        """ 
     348 
    309349        return raw_value, bit 
    310350 
    311351    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     352        """ 
     353        Handle with fields after calling fillout() for them. 
     354 
     355        @type raw_value: C{int} 
     356        @param raw_value: currently raw value for the packet. 
     357 
     358        @type bit: C{int} 
     359        @param bit: currently length of the protocol. 
     360 
     361        @type protocol_container: C{tuple} 
     362        @param protocol_container: tuple of protocols included in the packet. 
     363 
     364        @type protocol_bits: C{int} 
     365        @param protocol_bits: currently length of the packet. 
     366 
     367        @return: C{raw_value, bit} 
     368        """ 
     369 
    312370        return raw_value, bit 
    313371 
  • branch/UMPA/umpa/protocols/IP.py

    r3479 r3608  
    2020# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
    2121 
     22""" 
     23This module contains IP (Internet Protocol) protocol implementation. 
     24""" 
     25 
    2226from umpa.protocols import _consts 
    2327from umpa.protocols import _fields 
     
    2731 
    2832class _HVersion(_fields.EnumField): 
    29     """The Version field indicates the format of the internet header. 
    30      
    31     See RFC 791 for more. 
    32     """ 
     33    """ 
     34    The Version field indicates the format of the internet header. 
     35     
     36    See RFC 791 for more. 
     37    """ 
     38     
    3339    bits = 4 
    3440    auto = True 
     
    4147 
    4248    def _generate_value(self): 
     49        """ 
     50        Generate value for undefined field yet. 
     51         
     52        @return: auto-generated value of the field. 
     53        """ 
     54 
    4355        return _consts.IPVERSION_4 
    4456 
    4557class _HIHL(_fields.SpecialIntField): 
    46     """Internet Header Length is the length of the internet header in 32 bit 
     58    """ 
     59    Internet Header Length is the length of the internet header in 32 bit 
    4760    words, and thus points to the beginning of the data. 
    4861     
    4962    See RFC 791 for more. 
    5063    """ 
     64 
    5165    bits = 4 
    5266    auto = True 
    53     def _generate_value(self): 
     67 
     68    def _generate_value(self): 
     69        """ 
     70        Generate value for undefined field yet. 
     71         
     72        @return: auto-generated value of the field. 
     73        """ 
     74 
    5475        return 5 + self._tmp_value / 32 # 5 is a minimum value (see RFC 791) 
    5576 
    5677class _HTotalLength(_fields.SpecialIntField): 
    57     """Total Length is the length of the datagram, measured in octets, 
     78    """ 
     79    Total Length is the length of the datagram, measured in octets, 
    5880    including internet header and data. 
    5981 
    6082    See RFC 791 for more. 
    6183    """ 
     84 
    6285    bits = 16 
    6386    auto = True 
    64     def _generate_value(self): 
     87     
     88    def _generate_value(self): 
     89        """ 
     90        Generate value for undefined field yet. 
     91         
     92        @return: auto-generated value of the field. 
     93        """ 
     94 
    6595        return self._tmp_value / _consts.BYTE 
    6696 
    6797class _HIdentification(_fields.IntField): 
    68     """An identifying value assigned by the sender to aid in assembling the 
     98    """ 
     99    An identifying value assigned by the sender to aid in assembling the 
    69100    fragments of a datagram. 
    70101 
    71102    See RFC 791 for more. 
    72103    """ 
     104     
    73105    bits = 16 
    74106    auto = True 
    75     def _generate_value(self): 
     107 
     108    def _generate_value(self): 
     109        """ 
     110        Generate value for undefined field yet. 
     111         
     112        @return: auto-generated value of the field. 
     113        """ 
     114 
    76115        # TODO: implementation of fragmentation 
    77116        # otherwise we can simple return 0 ;-) 
     
    79118 
    80119class _HFragmentOffset(_fields.IntField): 
    81     """This field indicates where in the datagram this fragment belongs. 
    82      
    83     See RFC 791 for more. 
    84     """ 
     120    """ 
     121    This field indicates where in the datagram this fragment belongs. 
     122     
     123    See RFC 791 for more. 
     124    """ 
     125     
    85126    bits = 13 
    86127    auto = True 
    87     def _generate_value(self): 
     128     
     129    def _generate_value(self): 
     130        """ 
     131        Generate value for undefined field yet. 
     132         
     133        @return: auto-generated value of the field. 
     134        """ 
     135 
    88136        # TODO: implementation of fragmentation 
    89137        # otherwise we can simple return 0 ;-) 
     
    91139 
    92140class _HTTL(_fields.IntField): 
    93     """This field indicates the maximum time the datagram is allowed to 
     141    """ 
     142    This field indicates the maximum time the datagram is allowed to 
    94143    remain in the internet system. 
    95144     
    96145    See RFC 791 for more. 
    97146    """ 
     147     
    98148    bits = 8 
    99149    auto = True 
    100     def _generate_value(self): 
     150     
     151    def _generate_value(self): 
     152        """ 
     153        Generate value for undefined field yet. 
     154         
     155        @return: auto-generated value of the field. 
     156        """ 
     157 
    101158        # TODO: checking platform to get correct value of TTL 
    102159        # unfortunately, there isn't any official document which described 
     
    106163 
    107164    def ttl(self, name): 
    108         """To set correct value of TTL for following platforms: 
     165        """ 
     166        Set TTL field to default value of the passed platform. 
     167 
     168        Set correct value of TTL for the following platforms: 
    109169        AIX, DEC, FREEBSD, HPUX, IRIX, LINUX, MACOS, OS2, SOLARIS, 
    110170        SUNOS, ULTRIX, WINDOWS. 
    111171 
    112         name argument can be pass as shown above or as TTL_NAME 
     172        @type name: C{str} 
     173        @param name: name of the platform (from the list above, TTL_ prefix 
     174                     also accepted. 
    113175        """ 
    114176 
     
    118180 
    119181class _HProtocol(_fields.SpecialIntField, _fields.EnumField): 
    120     """This field indicates the next level protocol used in the data portion 
     182    """ 
     183    This field indicates the next level protocol used in the data portion 
    121184    of the internet datagram. 
    122185     
    123186    See RFC 791 for more. 
    124187    """ 
     188 
    125189    bits = 8 
    126190    auto = True 
     
    157221 
    158222    def _generate_value(self): 
     223        """ 
     224        Generate value for undefined field yet. 
     225         
     226        @return: auto-generated value of the field. 
     227        """ 
     228 
    159229        return self._tmp_value 
    160230 
    161231class _HHeaderChecksum(_fields.IntField): 
    162     """A checksum on the header only. 
    163      
    164     See RFC 791 for more. 
    165     """ 
     232    """ 
     233    A checksum of the header only. 
     234     
     235    See RFC 791 for more. 
     236    """ 
     237     
    166238    bits = 16 
    167239    auto = True 
    168     def _generate_value(self): 
     240     
     241    def _generate_value(self): 
     242        """ 
     243        Generate value for undefined field yet. 
     244         
     245        @return: auto-generated value of the field. 
     246        """ 
     247 
    169248        return 0        # HeaderChecksum field should be initialized by 0 
    170249 
     
    172251 
    173252class IP(_protocols.Protocol): 
    174     """This is Internet Protocol. 
     253    """ 
     254    Internet Protocol implementation. 
     255 
    175256    The main protocol in third layer of OSI model. 
    176257    """ 
     258 
    177259    layer = 3      # layer of OSI 
    178260    protocol_id = _consts.ETHERTYPE_IP 
     
    186268 
    187269    def __init__(self, **kw): 
     270        """ 
     271        Create a new IP(). 
     272 
     273        @param **kw: pass to super-constructor. 
     274        """ 
     275 
    188276        tos = ('precedence0','precedence1', 'precedence2', 'delay', 
    189277                'throughput', 'relibility', 'reserved0', 'reserved1') 
     
    237325 
    238326    def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     327        """ 
     328        Handle with fields before calling fillout() for them. 
     329 
     330        Set Padding field, calculate header and total length, set protocol of the upper 
     331        layer. 
     332 
     333        @type raw_value: C{int} 
     334        @param raw_value: currently raw value for the packet. 
     335 
     336        @type bit: C{int} 
     337        @param bit: currently length of the protocol. 
     338 
     339        @type protocol_container: C{tuple} 
     340        @param protocol_container: tuple of protocols included in the packet. 
     341 
     342        @type protocol_bits: C{int} 
     343        @param protocol_bits: currently length of the packet. 
     344 
     345        @return: C{raw_value, bit} 
     346        """ 
     347 
    239348        # Padding 
    240349        self._get_field('_padding')._tmp_value = \ 
     
    265374 
    266375    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     376        """ 
     377        Handle with fields after calling fillout() for them. 
     378 
     379        Calculate header checksum. 
     380 
     381        @type raw_value: C{int} 
     382        @param raw_value: currently raw value for the packet. 
     383 
     384        @type bit: C{int} 
     385        @param bit: currently length of the protocol. 
     386 
     387        @type protocol_container: C{tuple} 
     388        @param protocol_container: tuple of protocols included in the packet. 
     389 
     390        @type protocol_bits: C{int} 
     391        @param protocol_bits: currently length of the packet. 
     392 
     393        @return: C{raw_value, bit} 
     394        """ 
     395 
    267396        # Header Checksum 
    268397        # a checksum on the header only. 
  • branch/UMPA/umpa/protocols/Payload.py

    r3482 r3608  
    2020# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
    2121 
     22""" 
     23This module contains Payload "protocol" implementation. 
     24 
     25Payload is the abstract protocol of 5-7 layers of the OSI model. 
     26""" 
     27 
    2228from umpa.protocols._fields import Field 
    2329from umpa.protocols._protocols import Protocol 
     
    2531 
    2632class _HData(Field): # FIXME: should we move it to _fields.py as a common field? 
    27     """Data as a strings. 
    2833    """ 
     34    Data as a strings. 
     35    """ 
     36     
    2937    bits = 0 
    3038    auto = False 
    3139 
    3240    def _is_valid(self, val): 
     41        """ 
     42        Validate if the value is not bigger than expected. 
     43 
     44        @param val: the new value. 
     45 
     46        @rtype: C{bool} 
     47        @return: C{True}. 
     48        """ 
    3349        return True     # we use str() so everything is ok 
    3450 
    3551    def set(self, value): 
     52        """ 
     53        Set the new value of the field. 
     54 
     55        @param value: assign new value with str() casting. 
     56        """ 
    3657        if self._is_valid(value): 
    3758            self._value = str(value)    # converting to str 
     
    4364 
    4465    def clear(self): 
    45         super(Field, self).lear() 
     66        """ 
     67        Clear the current value of the field. 
     68        """ 
     69 
     70        super(Field, self).clear() 
    4671        self.bits = 0 
    4772 
    4873    def _raw_value(self): 
     74        """ 
     75        Convert the value to the raw mode. 
     76 
     77        Convert every character into the integer ordinal. 
     78        Merge the integer values. 
     79        Raw value's type is a number. It has to be in big-endian order. 
     80        The bits of the result of this method are inserted into the raw number 
     81        of the whole protocol. 
     82 
     83        @rtype: C{number} 
     84        @return: raw value of the field. 
     85        """ 
     86 
    4987        raw = 0 
    5088        for char in self._value: 
     
    5694 
    5795class Payload(Protocol): 
    58     """Use this as a protocol upper 4th layer of OSI model. 
    5996    """ 
     97    Payload -- data of 5-7 layers of the OSI model. 
     98    """ 
     99 
    60100    layer = 5 
    61101    name = "Payload" 
     
    63103 
    64104    def __init__(self, **kw): 
     105        """ 
     106        Create a new Payload(). 
     107 
     108        @param **kw: pass to super-constructor. 
     109        """ 
     110 
    65111        fields_list = [ _HData("Data"), ] 
    66112 
     
    68114 
    69115    def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     116        """ 
     117        Handle with fields before calling fillout() for them. 
     118 
     119        Nothing to do for Payload class here. Return required vars. 
     120 
     121        @type raw_value: C{int} 
     122        @param raw_value: currently raw value for the packet. 
     123 
     124        @type bit: C{int} 
     125        @param bit: currently length of the protocol. 
     126 
     127        @type protocol_container: C{tuple} 
     128        @param protocol_container: tuple of protocols included in the packet. 
     129 
     130        @type protocol_bits: C{int} 
     131        @param protocol_bits: currently length of the packet. 
     132 
     133        @return: C{raw_value, bit} 
     134        """ 
     135 
    70136        return raw_value, bit 
    71137 
    72138    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     139        """ 
     140        Handle with fields after calling fillout() for them. 
     141 
     142        Nothing to do for Payload class here. Return required vars. 
     143 
     144        @type raw_value: C{int} 
     145        @param raw_value: currently raw value for the packet. 
     146 
     147        @type bit: C{int} 
     148        @param bit: currently length of the protocol. 
     149 
     150        @type protocol_container: C{tuple} 
     151        @param protocol_container: tuple of protocols included in the packet. 
     152 
     153        @type protocol_bits: C{int} 
     154        @param protocol_bits: currently length of the packet. 
     155 
     156        @return: C{raw_value, bit} 
     157        """ 
     158 
    73159        return raw_value, bit 
    74160 
  • 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') - \ 
  • branch/UMPA/umpa/protocols/UDP.py

    r3479 r3608  
    2020# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
    2121 
     22""" 
     23This module contains UDP (Uset Datagram Protocol) protocol implementation. 
     24""" 
     25 
    2226from umpa.protocols import _consts 
    2327from umpa.protocols import _fields 
     
    2832 
    2933class _HPort(_fields.EnumField): 
     34    """ 
     35    UDP uses ports to allow application-to-application communication. 
     36    """ 
     37 
    3038    bits = 16 
    3139    auto = False 
     
    242250 
    243251class _HLength(_fields.SpecialIntField): 
    244     """Length  is the length  in octets  of this user datagram  including  this 
     252    """ 
     253    Length  is the length  in octets  of this user datagram  including  this 
    245254    header  and the data. 
    246     """ 
     255 
     256    See RFC 768 for more. 
     257    """ 
     258     
    247259    bits = 16 
    248260    auto = True 
    249261    def _generate_value(self): 
     262        """ 
     263        Generate value for undefined field yet. 
     264         
     265        @return: auto-generated value of the field. 
     266        """ 
     267 
    250268        # returns in byte units 
    251269        return 8 + self._tmp_value/8    # minimum is 8 
    252270 
    253271class UDP(_protocols.Protocol): 
    254     """This is User Datagram Protocol. 
     272    """ 
     273    User Datagram Protocol implementation. 
    255274     
    256275    This protocol  provides  a procedure  for application  programs  to send 
     
    259278    are not guaranteed. 
    260279    """ 
     280 
    261281    layer = 4 
    262282    protocol_id = _consts.PROTOCOL_UDP 
     
    267287 
    268288    def __init__(self, **kw): 
     289        """ 
     290        Create a new UDP(). 
     291 
     292        @param **kw: pass to super-constructor. 
     293        """ 
     294 
    269295        fields_list = [ _HPort("Source Port", 0), 
    270296                        _HPort("Destination Port", 0), 
     
    285311 
    286312    def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     313        """ 
     314        Handle with fields before calling fillout() for them. 
     315 
     316        Store temp value of protocols bits for checksum field. 
     317 
     318        @type raw_value: C{int} 
     319        @param raw_value: currently raw value for the packet. 
     320 
     321        @type bit: C{int} 
     322        @param bit: currently length of the protocol. 
     323 
     324        @type protocol_container: C{tuple} 
     325        @param protocol_container: tuple of protocols included in the packet. 
     326 
     327        @type protocol_bits: C{int} 
     328        @param protocol_bits: currently length of the packet. 
     329 
     330        @return: C{raw_value, bit} 
     331        """ 
     332 
    287333        # Length 
    288334        self._get_field('_checksum')._tmp_value = protocol_bits 
     
    291337 
    292338    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     339        """ 
     340        Handle with fields after calling fillout() for them. 
     341 
     342        Calculate header checksum with new instance of PseudoHeader object. 
     343 
     344        @type raw_value: C{int} 
     345        @param raw_value: currently raw value for the packet. 
     346 
     347        @type bit: C{int} 
     348        @param bit: currently length of the protocol. 
     349 
     350        @type protocol_container: C{tuple} 
     351        @param protocol_container: tuple of protocols included in the packet. 
     352 
     353        @type protocol_bits: C{int} 
     354        @param protocol_bits: currently length of the packet. 
     355 
     356        @return: C{raw_value, bit} 
     357        """ 
     358 
    293359        cksum_rev_offset = 0 
    294360        # checking if user not defined his own value of checksum 
  • branch/UMPA/umpa/protocols/_fields.py

    r3605 r3608  
    151151        Convert the value to the raw mode. 
    152152 
    153         Raw value is a number type. It has to be in big-endian order. 
     153        Raw value's type is a number. It has to be in big-endian order. 
    154154        The bits of the result of this method are inserted into the raw number 
    155155        of the whole protocol. 
     
    216216        Convert the value to the raw mode. 
    217217 
    218         Raw value is a number type. It has to be in big-endian order. 
     218        Raw value's type is a number. It has to be in big-endian order. 
    219219        The bits of the result of this method are inserted into the raw number 
    220220        of the whole protocol. 
     
    383383        Convert the value to the raw mode. 
    384384 
    385         Raw value is a number type. It has to be in big-endian order. 
     385        Raw value's type is a number. It has to be in big-endian order. 
    386386        The bits of the result of this method are inserted into the raw number 
    387387        of the whole protocol. 
     
    527527    def _generate_value(self): 
    528528        """ 
    529         Generate value for undefined yet field. 
     529        Generate value for undefined field yet. 
    530530         
    531531        @return: auto-generated value of the field. 
  • branch/UMPA/umpa/protocols/_layer4.py

    r3411 r3608  
    2020# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
    2121 
     22""" 
     23This module contains usefull classes for 4th layer's protocols. 
     24 
     25TCP/UDP use special pseudo header to calculate checksum. These classes 
     26are provided. 
     27""" 
     28 
    2229from umpa.protocols._protocols import Protocol 
    2330from umpa.protocols.IP import IP 
     
    2532 
    2633class Layer4ChecksumField(IntField): 
     34    """ 
     35    A checksum for the common classes of 4th layer of OSI model. 
     36 
     37    Especially UDP/TCP use it. The checksum is calculated from the Pseudo 
     38    Header, the main header and the payload. 
     39    """ 
     40 
    2741    bits = 16 
    2842    auto = True 
    2943    def _generate_value(self): 
     44        """ 
     45        Generate value for undefined field yet. 
     46         
     47        @return: auto-generated value of the field. 
     48        """ 
     49 
    3050        return 0 
    3151 
    3252class PseudoHeader(Protocol): 
    33     """This is class is useful for some protocols like TCP or UDP. 
    34     It has been used to calculate checksum of those protocols. 
     53    """ 
     54    This is Pseudo Header. 
     55     
     56    This class is useful for some protocols like TCP or UDP. 
     57    It's used to calculate checksum of those protocols. 
    3558    It's prefixed to the protocol header before calculating. 
    3659    """ 
     60 
    3761    _ordered_fields = ('source_address', 'destination_address', 'reserved', 
    3862                    'protocol_id', 'total_length') 
    3963 
    4064    def __init__(self, protocol_id, total_length): 
     65        """ 
     66        Create a new PseudoHeader() 
     67 
     68        @type protocol_id: C{int} 
     69        @param protocol_id: id of the protocol which use PseudoHeader. 
     70 
     71        @type total_length: C{int} 
     72        @param total_length: length of the real header and payload. 
     73 
     74        """ 
    4175 
    4276        fields_list = [ IPv4AddrField("Source Address"), 
     
    4882 
    4983    def _pre_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     84        """ 
     85        Handle with fields before calling fillout() for them. 
     86 
     87        Parse lower protocol (usually IP) to get source/destination address. 
     88 
     89        @type raw_value: C{int} 
     90        @param raw_value: currently raw value for the packet. 
     91 
     92        @type bit: C{int} 
     93        @param bit: currently length of the protocol. 
     94 
     95        @type protocol_container: C{tuple} 
     96        @param protocol_container: tuple of protocols included in the packet. 
     97 
     98        @type protocol_bits: C{int} 
     99        @param protocol_bits: currently length of the packet. 
     100 
     101        @return: C{raw_value, bit} 
     102        """ 
     103 
    50104        # we assign first localhost becuase if there is not IP instance 
    51105        # than better 0 than nothing (for nonstrict users) 
     
    63117 
    64118    def _post_raw(self, raw_value, bit, protocol_container, protocol_bits): 
     119        """ 
     120        Handle with fields after calling fillout() for them. 
     121 
     122        Nothing to do for PseudoHeader class here. Return required vars. 
     123 
     124        @type raw_value: C{int} 
     125        @param raw_value: currently raw value for the packet. 
     126 
     127        @type bit: C{int} 
     128        @param bit: currently length of the protocol. 
     129 
     130        @type protocol_container: C{tuple} 
     131        @param protocol_container: tuple of protocols included in the packet. 
     132 
     133        @type protocol_bits: C{int} 
     134        @param protocol_bits: currently length of the packet. 
     135 
     136        @return: C{raw_value, bit} 
     137        """ 
     138 
    65139        return raw_value, bit 
  • branch/UMPA/umpa/protocols/_protocols.py

    r3604 r3608  
    3636 
    3737class Protocol(object): 
    38  
    39     """Superclass for every protocol's implementations. 
     38    """ 
     39    Superclass for every protocol's implementations. 
    4040    
    4141    You have to override following methods: