Changeset 3138

Show
Ignore:
Timestamp:
07/11/08 14:15:55 (5 years ago)
Author:
getxsick
Message:

Number of bits are out of constructor. Now they are static variables of classes

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

Legend:

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

    r3136 r3138  
    2626 
    2727class HIHL(base.Field): 
     28    _bits = 4 
    2829    def fillout(self): 
    2930        pass 
    3031 
    3132class HTotalLength(base.Field): 
     33    _bits = 16 
    3234    def fillout(self): 
    3335        pass 
    3436 
    3537class HIdentification(base.Field): 
     38    _bits = 16 
    3639    def fillout(self): 
    3740        pass 
    3841 
    3942class HFragmentOffset(base.Field): 
     43    _bits = 13 
    4044    def fillout(self): 
    4145        pass 
    4246 
    4347class HProtocol(base.Field): 
     48    _bits = 8 
    4449    def fillout(self): 
    4550        pass 
    4651 
    4752class HHeaderChecksum(base.Field): 
    48     def fillout(self): 
    49         pass 
    50  
    51 class HSourceAddress(base.Field): 
    52     def fillout(self): 
    53         pass 
    54  
    55 class HDestinationAddress(base.Field): 
     53    _bits = 16 
    5654    def fillout(self): 
    5755        pass 
    5856 
    5957class HPadding(base.Field): 
     58    _bits = 0 
    6059    def fillout(self): 
    6160        pass 
     
    7776        flags = ('reserved', 'df', 'mf') 
    7877 
    79         fields_list = [ Field(4, 4, auto=True), HIHL(4, auto=True), 
    80                         Flags(tos, auto=False), HTotalLength(16, auto=True), 
    81                         HIdentification(16, auto=True), 
     78        fields_list = [ Field(4, 4, auto=True), HIHL(auto=True), 
     79                        Flags(tos, auto=False), HTotalLength(auto=True), 
     80                        HIdentification(auto=True), 
    8281                        Flags(flags, auto=False, reserved=0), 
    83                         HFragmentOffset(13, auto=True), Field(8, 255), 
    84                         HProtocol(8, auto=True), 
    85                         HHeaderChecksum(16, auto=True), 
     82                        HFragmentOffset(auto=True), Field(255, 8), 
     83                        HProtocol(auto=True), HHeaderChecksum(auto=True), 
    8684                        Field(16), Field(16), Flags((), auto=True), 
    87                         HPadding(0, auto=True) ] 
     85                        HPadding(auto=True) ] 
    8886 
    8987        # we pack objects of header's fields to the dict 
  • branch/UMPA/umpa/protocols/base.py

    r3137 r3138  
    2323 
    2424class Field(object): 
    25     def __init__(self, bits, value=None, auto=False): 
     25    def __init__(self, value=None, bits=None, auto=False): 
    2626        """Set auto if you wish to take care about the field 
    2727        by the library. Then you will have to write how 
    2828        to manage the field. 
    2929        """ 
    30         self._bits = bits 
     30        if bits is not None: 
     31            self._bits = bits 
    3132        self._auto = auto 
    3233        self._value = value 
     
    129130         """ 
    130131        # XXX: what if there is more than one Flags field in the protocol? 
     132        flag_field = None 
    131133        for obj in self._fields: 
    132134            if type(obj) == Flags: