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): # 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)
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 = [] 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']): 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) return cls(flags=flags, sids=sids, sr_algo=sr_algo)
def unpack (cls,data,length): # We only support IS-IS flags for now. flags = LsGenericFlags.unpack(data[0:1],LsGenericFlags.ISIS_SR_ADJ_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 int(flags.flags['V']) and int(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, sids=sids, weight=weight)
def unpack (cls,data,length): sr_algos = [] while data: sr_algos.append(six.indexbytes(data,0)) data = data[1:] # Looks like IOS XR advertises len 0 on this sub TLV # when using default SPF. if not len(sr_algos): sr_algos.append(0) return cls(sr_algos=sr_algos)
def unpack(cls, data, negotiated): sr_attrs = [] while data: # Type = 1 octet scode = six.indexbytes(data,0) # L = 2 octet :| length = unpack('!H',data[1:3])[0] if scode in cls.registered_srids: klass = cls.registered_srids[scode].unpack(data[3:length+3],length) else: klass = GenericSRId(scode,data[3:length+3]) klass.TLV = scode sr_attrs.append(klass) data = data[length+3:] return cls(sr_attrs=sr_attrs)
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")
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")
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)