Changeset 3136
- Timestamp:
- 07/11/08 10:28:59 (5 years ago)
- Location:
- branch/UMPA/umpa/protocols
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
branch/UMPA/umpa/protocols/IP.py
r3128 r3136 21 21 22 22 import base 23 24 from base import Field, Flags 23 25 from umpa.utils.my_exceptions import UMPAAttributeException 24 26 25 class HVersion(base.Field):26 def fillout(self):27 pass28 29 27 class HIHL(base.Field): 30 def fillout(self):31 pass32 33 class HTypeOfService(base.Field):34 28 def fillout(self): 35 29 pass … … 43 37 pass 44 38 45 class HFlags(base.Flags):46 def fillout(self):47 pass48 49 39 class HFragmentOffset(base.Field): 50 def fillout(self):51 pass52 53 class HTimeToLive(base.Field):54 40 def fillout(self): 55 41 pass … … 71 57 pass 72 58 73 class HOptions(base.Field):74 def fillout(self):75 pass76 77 59 class HPadding(base.Field): 78 60 def fillout(self): … … 83 65 class IP(base.Protocol): 84 66 _ordered_fields = ('_version', '_ihl', 'type_of_service', '_total_length', 85 ' identification', 'flags', '_fragment_offset',86 'time_to_live', ' protocol', '_header_checksum',67 '_identification', 'flags', '_fragment_offset', 68 'time_to_live', '_protocol', '_header_checksum', 87 69 'source_address', 'destination_address', 'options', 88 70 '_padding',) … … 91 73 base.Protocol.__init__(self, kw) 92 74 93 fields_list = [ HVersion(4, True), HIHL(4, True), 94 HTypeOfService(8), HTotalLength(16, True), 95 HIdentification(16, True), HFlags(3, True), # add names to flags later 96 HFragmentOffset(13, True), HTimeToLive(8), 97 HProtocol(8, True), HHeaderChecksum(16, True), 98 HSourceAddress(16), HDestinationAddress(16), 99 HOptions(0), HPadding(0, True), ] 75 tos = ('presedence0','presedence1', 'presedence2', 'delay', 76 'throughput', 'relibility', 'reserved0', 'reserverd1') 77 flags = ('reserved', 'df', 'mf') 78 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), 82 Flags(flags, auto=False, reserved=0), 83 HFragmentOffset(13, auto=True), Field(8, 255), 84 HProtocol(8, auto=True), 85 HHeaderChecksum(16, auto=True), 86 Field(16), Field(16), Flags((), auto=True), 87 HPadding(0, auto=True) ] 100 88 101 89 # we pack objects of header's fields to the dict -
branch/UMPA/umpa/protocols/base.py
r3133 r3136 23 23 24 24 class Field(object): 25 def __init__(self, bits, auto=False):25 def __init__(self, bits, value=None, auto=False): 26 26 """Set auto if you wish to take care about the field 27 27 by the library. Then you will have to write how … … 30 30 self._bits = bits 31 31 self._auto = auto 32 self._value = None # default value of the field32 self._value = value 33 33 34 34 def set(self, value): … … 48 48 return True 49 49 50 def fillout(self): 51 print "Not implemented yet." 52 return False 53 50 54 class Flags(Field): 51 55 """Most of protocols have a special field with bit-flags. … … 53 57 """ 54 58 55 def __init__(self, auto=False, *names): 56 Field.__init__(self, len(names), auto) 59 def __init__(self, names, auto=False, **preset): 60 """Names has to be in correct order. 61 If you use **preset, check if keys are in names list as well 62 because of order issue. 63 """ 64 Field.__init__(self, len(names), auto=auto) 57 65 58 66 self._ordered_fields = names … … 61 69 false_list = [ False for i in xrange(self._bits) ] 62 70 self._value = dict(zip(self._ordered_fields, false_list)) 71 72 # if preset exists then we update values 73 for name in preset: 74 if preset[name] == False: 75 self.set(name) 76 else: 77 self.unset(name) 63 78 64 79 def _is_valid(self, name):
