Example #1
0
	def unpack (cls,data,length):
		if length != 4:
			raise Notify(3,5, "Unable to decode attribute. Incorrect Size")
		else:
			b = BitArray(bytes=data)
			colormask = b.unpack('uintbe:32')
			return cls(colormask=colormask)
Example #2
0
	def unpack (cls,data,length):
		if len(data) == 2:
    		# OSPF
			igpmetric = unpack('!H',data)[0]
			return cls(igpmetric=igpmetric)
		elif len(data) == 1:
    		# ISIS small metrics
			igpmetric = unpack('!B',data)[0]
			return cls(igpmetric=igpmetric)
		elif len(data) == 3:
    		# ISIS wide metrics
			b = BitArray(bytes=data)
			igpmetric = b.unpack('uintbe:24')
			return cls(igpmetric=igpmetric)
		else:
			raise Notify(3,5, "Incorrect IGP Metric Size")
Example #3
0
	def unpack (cls,data,length):
		igpflags = ['D', 'N', 'L', 'P']
		if length > 1:
			raise Notify(3,5, "IGP Flags TLV length too large")
		else:
			flag_array = binascii.b2a_hex(data[0])
			hex_rep = hex(int(flag_array, 16))
			bit_array = BitArray(hex_rep)
			valid_flags = [''.join(item)+'0000' for item in itertools.product('01', repeat=4)]
 			valid_flags.append('0000')
 			if bit_array.bin in valid_flags:
				flags = dict(zip(igpflags, bit_array.bin))
				return cls(igpflags=flags)
			else:
    				raise Notify(3,5, "Invalid IGP flags mask")
Example #4
0
 def unpack(cls, data, length):
     node_flags = ['O', 'T', 'E', 'B', 'R', 'V', 'RSV', 'RSV']
     if length > 1:
         raise Notify(3, 5, "Node Flags TLV length too large")
     else:
         flag_array = binascii.b2a_hex(data[0])
         hex_rep = hex(int(flag_array, 16))
         bit_array = BitArray(hex_rep)
         valid_flags = [
             ''.join(item) + '00'
             for item in itertools.product('01', repeat=6)
         ]
         valid_flags.append('0000')
         if bit_array.bin in valid_flags:
             flags = dict(zip(node_flags, bit_array.bin))
     return cls(nodeflags=flags)
Example #5
0
 def unpack(cls, data, length):
     protection_mask = [
         'ExtraTrafic', 'Unprotected', 'Shared', 'Dedicated 1:1',
         'Dedicated 1+1', 'Enhanced', 'RSV', 'RSV'
     ]
     if length != 2:
         raise Notify(3, 5, "Wrong size for protection type TLV")
     else:
         # We only care about the first octect
         flag_array = binascii.b2a_hex(data[0])
         hex_rep = hex(int(flag_array, 16))
         bit_array = BitArray(hex_rep)
         valid_flags = [
             ''.join(item) + '00'
             for item in itertools.product('01', repeat=6)
         ]
         valid_flags.append('0000')
         if bit_array.bin in valid_flags:
             flags = dict(zip(protection_mask, bit_array.bin))
     return cls(protectionflags=flags)
Example #6
0
 def unpack(cls, data, length):
     mpls_mask = [
         'LDP', 'RSVP-TE', 'RSV', 'RSV', 'RSV', 'RSV', 'RSV', 'RSV'
     ]
     if length > 1:
         raise Notify(3, 5, "LINK TLV length too large")
     else:
         flag_array = binascii.b2a_hex(data[0])
         hex_rep = hex(int(flag_array, 16))
         bit_array = BitArray(hex_rep)
         valid_flags = [
             ''.join(item) + '000000'
             for item in itertools.product('01', repeat=2)
         ]
         valid_flags.append('0000')
         if bit_array.bin in valid_flags:
             flags = dict(zip(mpls_mask, bit_array.bin))
             return cls(mplsflags=flags)
         else:
             raise Notify(3, 5, "Invalid MPLS flags mask")
Example #7
0
	def unpack (cls,data,length):

		b = BitArray(bytes=data)
		return cls(areaid=b.hex)
Example #8
0
 def unpack_sysid(cls, data):
     b = BitArray(bytes=data)
     return b.hex