def recvMessages(self, io): lsas = [] QuaggaHeaderStruct = Struct("quagga_msg_header",Byte("version"), Byte("msgtype"), UBInt16("msglen"),UBInt32("msgseq")) try: while True: hdrStr = io.recv(8) if len(hdrStr) == 0: # We're at the end of the file, time to get out break if len(hdrStr) != 8: raise OspfNetworkInputException("! Error, expecting header of 8 bytes, got %s bytes" % len(hdr)) hdr = QuaggaHeaderStruct.parse(hdrStr) if hdr.version != 1: raise OspfNetworkInputException("! Received wrong version, misalignment?") self.logger.debug("* Preparing to receive body of length %d (type %d)" % (hdr.msglen, hdr.msgtype)) bodyStr = io.recv(hdr.msglen) if len(bodyStr) != hdr.msglen: raise OspfNetworkInputException( "! Error, expecting body of length %d, got %d bytes." % (hdr.msglen, len(bodyStr))) # We're leaving out the Quagga header lsas.append(hdrStr+bodyStr) except socket.timeout: # There's no other way to figure out that the LSA sending is compelete... pass self.logger.debug("Connection timed out.") return [ospflsa.newLSAFromZebra(lsa) for lsa in lsas]
def getLSAs(self): """getLSAsFromOspfDump reads from the open file <filename> and retrieves the separate LSAs from the file, and returns them as a list. """ lsas = [] QuaggaHeaderStruct = Struct("quagga_msg_header", Byte("version"), Byte("msgtype"), UBInt16("msglen"), UBInt32("msgseq")) while True: hdrStr = self.io.read(8) if len(hdrStr) == 0: # We're at the end of the file, time to get out break if len(hdrStr) != 8: # QuaggaHeaderStruct is 8 bytes long raise OspfFileInputException( "expecting header from %s, got %s" % (self.io.name, len(hdrStr))) hdr = QuaggaHeaderStruct.parse(hdrStr) if hdr.version != 1: raise OspfFileInputException( "! Received wrong version, misalignment?") bodyStr = self.io.read(hdr.msglen) if len(bodyStr) != hdr.msglen: raise OspfFileInputException( "! Error, expecting body of length %d, got %d bytes." % (hdr.msglen, len(bodyStr))) self.logger.debug("Received an LSA.") lsas.append(hdrStr + bodyStr) return [ospflsa.newLSAFromZebra(lsa) for lsa in lsas]
def recvMessages(self, io): lsas = [] QuaggaHeaderStruct = Struct("quagga_msg_header", Byte("version"), Byte("msgtype"), UBInt16("msglen"), UBInt32("msgseq")) try: while True: hdrStr = io.recv(8) if len(hdrStr) == 0: # We're at the end of the file, time to get out break if len(hdrStr) != 8: raise OspfNetworkInputException( "! Error, expecting header of 8 bytes, got %s bytes" % len(hdr)) hdr = QuaggaHeaderStruct.parse(hdrStr) if hdr.version != 1: raise OspfNetworkInputException( "! Received wrong version, misalignment?") self.logger.debug( "* Preparing to receive body of length %d (type %d)" % (hdr.msglen, hdr.msgtype)) bodyStr = io.recv(hdr.msglen) if len(bodyStr) != hdr.msglen: raise OspfNetworkInputException( "! Error, expecting body of length %d, got %d bytes." % (hdr.msglen, len(bodyStr))) # We're leaving out the Quagga header lsas.append(hdrStr + bodyStr) except socket.timeout: # There's no other way to figure out that the LSA sending is compelete... pass self.logger.debug("Connection timed out.") return [ospflsa.newLSAFromZebra(lsa) for lsa in lsas]
def getLSAs(self): """getLSAsFromOspfDump reads from the open file <filename> and retrieves the separate LSAs from the file, and returns them as a list. """ lsas = [] QuaggaHeaderStruct = Struct("quagga_msg_header",Byte("version"), Byte("msgtype"), UBInt16("msglen"),UBInt32("msgseq")) while True: hdrStr = self.io.read(8) if len(hdrStr) == 0: # We're at the end of the file, time to get out break if len(hdrStr) != 8: # QuaggaHeaderStruct is 8 bytes long raise OspfFileInputException("expecting header from %s, got %s" % (self.io.name, len(hdrStr))) hdr = QuaggaHeaderStruct.parse(hdrStr) if hdr.version != 1: raise OspfFileInputException("! Received wrong version, misalignment?") bodyStr = self.io.read(hdr.msglen) if len(bodyStr) != hdr.msglen: raise OspfFileInputException("! Error, expecting body of length %d, got %d bytes." % (hdr.msglen, len(bodyStr))) self.logger.debug("Received an LSA.") lsas.append(hdrStr+bodyStr) return [ospflsa.newLSAFromZebra(lsa) for lsa in lsas]