/** * 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 from the channel buffer and returns Object of PcepTEObject. * * @param cb of type channel buffer * @return Object of PcepTEObject * @throws PcepParseException if mandatory fields are missing */ public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException { log.debug("read"); PcepObjectHeader teObjHeader; byte yProtocolId; // 2-flags boolean bRFlag; boolean bSFlag; int iTEId; LinkedList<PcepValueType> llOptionalTlv; teObjHeader = PcepObjectHeader.read(cb); // take only TEObject buffer. ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); yProtocolId = tempCb.readByte(); // ignore first two bytes of Flags tempCb.readShort(); Integer iTemp = (int) tempCb.readByte(); // read 3rd byte Flag bSFlag = ((iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG) ? true : false; bRFlag = ((iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG) ? true : false; iTEId = tempCb.readInt(); // parse optional TLV llOptionalTlv = parseOptionalTlv(tempCb); return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv); }
/** * 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(); }
/** * Reads from channel buffer and return object of PcepIroObject. * * @param cb of type channel buffer * @return object of PcepIroObject * @throws PcepParseException while parsing from channel buffer */ public static PcepIroObject read(ChannelBuffer cb) throws PcepParseException { PcepObjectHeader iroObjHeader; LinkedList<PcepValueType> llSubObjects; iroObjHeader = PcepObjectHeader.read(cb); // take only IroObject buffer. ChannelBuffer tempCb = cb.readBytes(iroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); llSubObjects = parseSubObjects(tempCb); return new PcepIroObjectVer1(iroObjHeader, llSubObjects); }
/** * 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); }