/** * Parse TE List from the channel buffer. * * @param cb of type channel buffer * @throws PcepParseException if mandatory fields are missing */ public void parseTEList(ChannelBuffer cb) throws PcepParseException { byte yObjClass; byte yObjType; llTEObjList = new LinkedList<PcepTEObject>(); // caller should verify for TE object if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { log.debug("Unable to find TE Object"); return; } cb.markReaderIndex(); PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); cb.resetReaderIndex(); yObjClass = tempObjHeader.getObjClass(); yObjType = tempObjHeader.getObjType(); PcepTEObject teObj; while ((yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) && ((yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_NODE_VALUE) || (yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_LINK_VALUE))) { teObj = PcepTEObjectVer1.read(cb); llTEObjList.add(teObj); if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { cb.markReaderIndex(); tempObjHeader = PcepObjectHeader.read(cb); cb.resetReaderIndex(); yObjClass = tempObjHeader.getObjClass(); yObjType = tempObjHeader.getObjType(); } else { break; } } }
/** * Reads the byte stream of PcepError from channel buffer. * * @param cb of type channel buffer * @return PcepError error part of PCEP-ERROR * @throws PcepParseException if mandatory fields are missing */ public static PcepErrorVer1 read(ChannelBuffer cb) throws PcepParseException { if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { throw new PcepParseException("Unknown Object"); } PcepErrorVer1 pcepError = new PcepErrorVer1(); // check whether any PCEP Error Info is present cb.markReaderIndex(); PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); cb.resetReaderIndex(); byte yObjClass = tempObjHeader.getObjClass(); // If RPlist present then store it.RPList and TEList are optional if (yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) { log.debug("RP_LIST"); pcepError.parseRPList(cb); yObjClass = checkNextObject(cb); } else if (yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) { log.debug("TE_LIST"); pcepError.parseTEList(cb); yObjClass = checkNextObject(cb); } if (yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) { log.debug("PCEP-ERROR obj list"); pcepError.parseErrObjList(cb); yObjClass = checkNextObject(cb); } return pcepError; }
/** * Checks Next Object. * * @param cb of type channel buffer. * @return object type class. */ private static byte checkNextObject(ChannelBuffer cb) { if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { return 0; } cb.markReaderIndex(); PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); cb.resetReaderIndex(); return tempObjHeader.getObjClass(); }
/** * parseErrObjList from the channel buffer. * * @param cb of type channel buffer * @throws PcepParseException if mandatory fields are missing */ public void parseErrObjList(ChannelBuffer cb) throws PcepParseException { byte yObjClass; byte yObjType; boolean bIsErrorObjFound = false; llErrObjList = new LinkedList<PcepErrorObject>(); // caller should verify for RP object if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { throw new PcepParseException("Unable to find PCEP-ERROR Object"); } cb.markReaderIndex(); PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); cb.resetReaderIndex(); yObjClass = tempObjHeader.getObjClass(); yObjType = tempObjHeader.getObjType(); PcepErrorObject errorObject; while ((yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) && (yObjType == PcepErrorObjectVer1.ERROR_OBJ_TYPE)) { errorObject = PcepErrorObjectVer1.read(cb); llErrObjList.add(errorObject); bIsErrorObjFound = true; if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { cb.markReaderIndex(); tempObjHeader = PcepObjectHeader.read(cb); cb.resetReaderIndex(); yObjClass = tempObjHeader.getObjClass(); yObjType = tempObjHeader.getObjType(); } else { break; } } if (!bIsErrorObjFound) { throw new PcepParseException("At least one PCEP-ERROR Object should be present."); } }
/** * Parse channel buffer and returns object of PcepLspObject. * * @param cb of type channel buffer * @return object of PcepLspObject * @throws PcepParseException when lsp object is not present in channel buffer */ public static PcepLspObject read(ChannelBuffer cb) throws PcepParseException { PcepObjectHeader lspObjHeader; int iPlspId; // 3-bits byte yOFlag; boolean bAFlag; boolean bRFlag; boolean bSFlag; boolean bDFlag; boolean bCFlag; // Optional TLV LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); lspObjHeader = PcepObjectHeader.read(cb); if (lspObjHeader.getObjClass() != PcepLspObjectVer1.LSP_OBJ_CLASS) { throw new PcepParseException( PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_8); } // take only LspObject buffer. ChannelBuffer tempCb = cb.readBytes(lspObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); Integer iTemp = tempCb.readInt(); iPlspId = (iTemp & PLSPID_TEMP_SHIFT_VALUE) >> PLSPID_SHIFT_VALUE; bCFlag = ((iTemp & CFLAG_TEMP_SHIFT_VALUE) >> CFLAG_SHIFT_VALUE) > 0; Integer iX = (iTemp & OFLAG_TEMP_SHIFT_VALUE) >> OFLAG_SHIFT_VALUE; yOFlag = iX.byteValue(); iX = (iTemp & AFLAG_TEMP_SHIFT_VALUE) >> AFLAG_SHIFT_VALUE; bAFlag = iX > 0; iX = (iTemp & RFLAG_TEMP_SHIFT_VALUE) >> RFLAG_SHIFT_VALUE; bRFlag = iX > 0; iX = (iTemp & SFLAG_TEMP_SHIFT_VALUE) >> SFLAG_SHIFT_VALUE; bSFlag = iX > 0; iX = iTemp & DFLAG_TEMP_SHIFT_VALUE; bDFlag = iX > 0; // parse optional TLV llOptionalTlv = parseOptionalTlv(tempCb); return new PcepLspObjectVer1( lspObjHeader, iPlspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, bCFlag, llOptionalTlv); }