def unpack(cls, data, igp): dtype, dlength = unpack('!HH', data[0:4]) if dtype not in NODE_TLVS.keys(): raise Exception("Unknown Node Descriptor Sub-TLV") # OSPF Area-ID if dtype == 514: return cls(node_id=IP.unpack(data[4:4 + dlength]), dtype=dtype, packed=data[:4 + dlength]), data[4 + dlength:] # IGP Router-ID: The TLV size in combination with the protocol # identifier enables the decoder to determine the type # of the node: sec 3.2.1.4. elif dtype == 515: # OSPFv{2,3} non-pseudonode if (igp == 3 or igp == 6) and dlength == 4: r_id = IP.unpack(data[4:4 + 4]) return cls(node_id=r_id, dtype=dtype, packed=data[:4 + dlength]), data[4 + 4:] # OSPFv{2,3} LAN pseudonode if (igp == 3 or igp == 6) and dlength == 8: r_id = IP.unpack(data[4:4 + 4]) dr_id = IP.unpack(data[8:4 + 8]) return cls(node_id=r_id, dtype=dtype, psn=None, dr_id=dr_id, packed=data[:4 + dlength]), data[4 + 8:] # IS-IS non-pseudonode if (igp == 1 or igp == 2) and dlength == 6: return cls(node_id=ISO.unpack_sysid(data[4:4 + 6]), dtype=dtype, packed=data[:4 + dlength]), data[4 + 6:] # IS-IS LAN pseudonode = ISO Node-ID + PSN # Unpack ISO address if (igp == 1 or igp == 2) and dlength == 7: iso_node = ISO.unpack_sysid(data[4:4 + 6]) psn = unpack('!B', data[4 + 6:4 + 7])[0] return cls(node_id=iso_node, dtype=dtype, psn=psn, packed=data[:4 + dlength]), data[4 + 7:] elif dtype == 512 and dlength == 4: # ASN return cls(node_id=unpack('!L', data[4:4 + dlength])[0], dtype=dtype, packed=data[:4 + dlength]), data[4 + 4:] elif dtype == 513 and dlength == 4: # BGP-LS return cls(node_id=unpack('!L', data[4:4 + dlength])[0], dtype=dtype, packed=data[:4 + dlength]), data[4 + 4:] else: raise Notify(3, 5, 'could not decode Local Node descriptor')
def unpack(cls, data): # We only support IS-IS flags for now. flags = cls.unpack_flags(data[0:1]) # Parse adj weight weight = data[1] # Move pointer 4 bytes: Flags(1) + Weight(1) + Reserved(2) system_id = ISO.unpack_sysid(data[4:10]) data = data[10:] # 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: # Range Size: 3 octet value indicating the number of labels in # the range. if int(flags['V']) and int(flags['L']): sid = unpack('!L', bytes([0]) + data[:3])[0] data = data[3:] sids.append(sid) elif (not flags['V']) and (not flags['L']): sid = unpack('!I', data[:4])[0] data = data[4:] sids.append(sid) else: raw.append(hexstring(data)) break return cls([{'flags': flags, 'weight': weight, 'system-id': system_id, 'sid': sid, 'undecoded': raw}])
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: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, igp): node_type, length = unpack('!HH', data[0:4]) packed = data[:4 + length] payload = packed[4:] remaining = data[4 + length:] node_id = None dr_id = None psn = None # autonomous-system if node_type == 512: if length != 4: raise Exception(cls._error_tlvs[node_type]) node_id = unpack('!L', payload)[0] return cls(node_id, node_type, psn, dr_id, packed), remaining # bgp-ls-id if node_type == 513: if length != 4: raise Exception(cls._error_tlvs[node_type]) node_id = unpack('!L', payload)[0] return cls(node_id, node_type, psn, dr_id, packed), remaining # ospf-area-id if node_type == 514: if length not in (4, 16): # FIXME: it may only need to be 4 raise Exception(cls._error_tlvs[node_type]) node_id = IP.unpack(payload) return cls(node_id, node_type, psn, dr_id, packed), remaining # IGP Router-ID: The TLV size in combination with the protocol # identifier enables the decoder to determine the node_typee # of the node: sec 3.2.1.4. if node_type == 515: # IS-IS non-pseudonode if igp in (1, 2): if length not in (6, 7): raise Exception(cls._error_tlvs[node_type]) node_id = ISO.unpack_sysid(payload), if length == 7: psn = unpack('!B', payload[6:7])[0] return cls(node_id, node_type, psn, dr_id, packed), remaining # OSPFv{2,3} non-pseudonode if igp in (3, 5, 6, 227): if length not in (4, 8): raise Exception(cls._error_tlvs[node_type]) node_id = IP.unpack(payload[:4]), if length == 8: dr_id = IP.unpack(payload[4:8]) return cls(node_id, node_type, psn, dr_id, packed), remaining raise Exception("unknown node descriptor sub-tlv ({}, {})".format( f'node-type: {node_type}', f'igp: {igp}', ))
def unpack (cls, data, igp): dtype, dlength = unpack('!HH',data[0:4]) if dtype not in NODE_TLVS.keys(): raise Exception("Unknown Node Descriptor Sub-TLV") # OSPF Area-ID if dtype == 514: return cls(node_id=IP.unpack(data[4: 4 + dlength]), dtype=dtype,packed=data[:4+dlength]), data[4 + dlength:] # IGP Router-ID: The TLV size in combination with the protocol # identifier enables the decoder to determine the type # of the node: sec 3.2.1.4. elif dtype == 515: # OSPFv{2,3} non-pseudonode if (igp == 3 or igp == 6) and dlength == 4: r_id = IP.unpack(data[4: 4 + 4]) return cls(node_id=r_id, dtype=dtype, packed=data[:4+dlength]), data[4 + 4:] # OSPFv{2,3} LAN pseudonode if (igp == 3 or igp == 6) and dlength == 8: r_id = IP.unpack(data[4: 4 + 4]) dr_id = IP.unpack(data[8: 4 + 8]) return cls(node_id=r_id,dtype=dtype,psn=None, dr_id=dr_id,packed=data[:4+dlength]), data[4 + 8:] # IS-IS non-pseudonode if (igp == 1 or igp == 2) and dlength == 6: return cls(node_id=ISO.unpack_sysid(data[4: 4 + 6]), dtype=dtype,packed=data[:4+dlength]), data[4 + 6:] # IS-IS LAN pseudonode = ISO Node-ID + PSN # Unpack ISO address if (igp == 1 or igp == 2) and dlength == 7: iso_node = ISO.unpack_sysid(data[4: 4 + 6]) psn = unpack('!B', data[4 + 6: 4 + 7])[0] return cls(node_id=iso_node,dtype=dtype, psn=psn,packed=data[:4+dlength]), data[4 + 7:] elif dtype == 512 and dlength == 4: # ASN return cls(node_id=unpack('!L', data[4: 4 + dlength])[0], dtype=dtype,packed=data[:4+dlength]), data[4 + 4:] elif dtype == 513 and dlength == 4: # BGP-LS return cls(node_id=unpack('!L',data[4: 4 + dlength])[0], dtype=dtype,packed=data[:4+dlength]), data[4 + 4:] else: raise Notify(3,5,'could not decode Local Node descriptor')