Exemple #1
0
    def unpack(cls, data, length):
        # Extract node capability flags
        flags = LsGenericFlags.unpack(data[0],
                                      LsGenericFlags.ISIS_SR_CAP_FLAGS)
        # Move pointer past flags and reserved bytes
        data = data[2:]
        sids = []
        while data:
            # Range Size: 3 octet value indicating the number of labels in
            # the range.
            b = BitArray(bytes=data[:3])
            range_size = b.unpack('uintbe:24')[0]
            # SID/Label: If length is set to 3, then the 20 rightmost bits
            # represent a label.  If length is set to 4, then the value
            # represents a 32 bit SID.
            t, l = unpack('!HH', data[3:7])
            if t != 1161:
                raise Notify(3, 5, "Invalid sub-TLV type: {}".format(t))
            v = data[7:l + 7]
            if l == 3:
                b = BitArray(bytes=v)
                sid = b.unpack('uintbe:24')[0]
            elif l == 4:
                sid = unpack('!I', v)[0]
            sids.append((range_size, sid))
            data = data[l + 7:]

        return cls(sr_flags=flags.flags, sids=sids)
Exemple #2
0
    def unpack(cls, data, length):
        # We only support IS-IS flags for now.
        flags = LsGenericFlags.unpack(data[0], LsGenericFlags.ISIS_SR_FLAGS)
        #
        # Parse Algorithm
        sr_algo = six.indexbytes(data, 1)
        # Move pointer 4 bytes: Flags(1) + Algorithm(1) + Reserved(2)
        data = data[4:]
        # SID/Index/Label: according to the V and L flags, it contains
        # either:
        # *  A 3 octet local label where the 20 rightmost bits are used for
        #	 encoding the label value.  In this case the V and L flags MUST
        #	 be set.
        #
        # *  A 4 octet index defining the offset in the SID/Label space
        # 	 advertised by this router using the encodings defined in
        #  	 Section 3.1.  In this case V and L flags MUST be unset.
        sids = []
        while data:
            if flags.flags['V'] and flags.flags['L']:
                b = BitArray(bytes=data[:3])
                sid = b.unpack('uintbe:24')[0]
                data = data[3:]
            elif (not flags.flags['V']) and (not flags.flags['L']):
                sid = unpack('!I', data[:4])[0]
                data = data[4:]
            sids.append(sid)

        return cls(flags=flags.flags, sids=sids, sr_algo=sr_algo)
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
 def unpack(cls, data, length):
     # We only support IS-IS flags for now.
     flags = LsGenericFlags.unpack(data[0],
                                   LsGenericFlags.ISIS_ADJ_SR_FLAGS)
     # Parse adj weight
     weight = six.indexbytes(data, 1)
     # Move pointer 4 bytes: Flags(1) + Weight(1) + Reserved(2)
     data = data[4:]
     isis_system_id = ISO.unpack_sysid(data[:6])
     # SID/Index/Label: according to the V and L flags, it contains
     # either:
     # *  A 3 octet local label where the 20 rightmost bits are used for
     #	 encoding the label value.  In this case the V and L flags MUST
     #	 be set.
     #
     # *  A 4 octet index defining the offset in the SID/Label space
     # 	 advertised by this router using the encodings defined in
     #  	 Section 3.1.  In this case V and L flags MUST be unset.
     sids = []
     while data:
         # Range Size: 3 octet value indicating the number of labels in
         # the range.
         if flags.flags['V'] and flags.flags['L']:
             b = BitArray(bytes=data[:3])
             sid = b.unpack('uintbe:24')[0]
             data = data[3:]
         elif (not flags.flags['V']) and (not flags.flags['L']):
             sid = unpack('!I', data[:4])[0]
             data = data[4:]
         sids.append(sid)
     return cls(flags=flags.flags, sids=sids, weight=weight)
 def unpack(cls, data, length):
     srgbs = []
     # Flags: 16 bits of flags.  None is defined by this document.  The
     # flag field MUST be clear on transmission and MUST be ignored at
     # reception.
     data = data[2:]
     # SRGB: 3 octets of base followed by 3 octets of range.  Note that
     # the SRGB field MAY appear multiple times.  If the SRGB field
     # appears multiple times, the SRGB consists of multiple ranges.
     while data:
         b = BitArray(bytes=data[:3])
         base = b.unpack('uintbe:24')[0]
         b = BitArray(bytes=data[3:6])
         srange = b.unpack('uintbe:24')[0]
         srgbs.append((base, srange))
         data = data[6:]
     return cls(srgbs=srgbs)
Exemple #7
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)
Exemple #8
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")
	def unpack(cls,data,pattern):
		pad = pattern.count('RSV')
		repeat = len(pattern) - pad
		flag_array = binascii.b2a_hex(data)
		hex_rep = hex(int(flag_array, 16))
		bit_array = BitArray(hex_rep)
		valid_flags = [concat_strs(''.join(item), ''.join(itertools.repeat('0',pad)))
				for item in itertools.product('01', repeat=repeat)]
		valid_flags.append('0000')
		if bit_array.bin in valid_flags:
			flags = dict(zip(pattern, bit_array.bin))
			flags = {k:int(v) for k, v in flags.items()}
		else:
			raise Notify(3,5, "Invalid SR flags mask")
		return cls(flags=flags)
Exemple #10
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 = six.indexbytes(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")
Exemple #11
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")
Exemple #12
0
    def unpack(cls, data, length):
        # We only support IS-IS flags for now.
        flags = LsGenericFlags.unpack(data[0:1], LsGenericFlags.ISIS_SR_FLAGS)
        #
        # Parse Algorithm
        sr_algo = six.indexbytes(data, 1)
        # Move pointer 4 bytes: Flags(1) + Algorithm(1) + Reserved(2)
        data = data[4:]
        # SID/Index/Label: according to the V and L flags, it contains
        # either:
        # *  A 3 octet local label where the 20 rightmost bits are used for
        #	 encoding the label value.  In this case the V and L flags MUST
        #	 be set.
        #
        # *  A 4 octet index defining the offset in the SID/Label space
        # 	 advertised by this router using the encodings defined in
        #  	 Section 3.1.  In this case V and L flags MUST be unset.
        sids = []
        raw = []
        while data:
            if flags.flags['V'] and flags.flags['L']:
                b = BitArray(bytes=data[:3])
                sid = b.unpack('uintbe:24')[0]
                data = data[3:]
                sids.append(sid)
            elif (not flags.flags['V']) and \
             (not flags.flags['L']):
                if len(data) != 4:
                    # Cisco IOS XR Software, Version 6.1.1.19I is not
                    # correctly setting the flags
                    raise Notify(
                        3, 5,
                        "SID/Label size doesn't match V and L flag state")
                sid = unpack('!I', data[:4])[0]
                data = data[4:]
                sids.append(sid)
            else:
                raw.append(hexstring(data))
                break

        return cls(flags=flags, sids=sids, sr_algo=sr_algo, undecoded=raw)
Exemple #13
0
	def unpack_sysid(cls,data):
		b = BitArray(bytes=data)
		return b.hex
Exemple #14
0
	def unpack (cls,data,length):

		b = BitArray(bytes=data)
		return cls(areaid=b.hex)