示例#1
0
  /**
   * 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);
  }
示例#2
0
  @Override
  public int write(ChannelBuffer cb) throws PcepParseException {
    // write Object header
    int objStartIndex = cb.writerIndex();

    int objLenIndex = iroObjHeader.write(cb);

    if (objLenIndex <= 0) {
      throw new PcepParseException(" ObjectLength is " + objLenIndex);
    }

    ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
    while (listIterator.hasNext()) {
      listIterator.next().write(cb);
    }

    // Update object length now
    int length = cb.writerIndex() - objStartIndex;
    // will be helpful during print().
    iroObjHeader.setObjLen((short) length);
    // As per RFC the length of object should be
    // multiples of 4
    int pad = length % 4;
    if (pad != 0) {
      pad = 4 - pad;
      for (int i = 0; i < pad; i++) {
        cb.writeByte((byte) 0);
      }
      length = length + pad;
    }
    cb.setShort(objLenIndex, (short) length);
    objLenIndex = cb.writerIndex();
    return objLenIndex;
  }
示例#3
0
  /**
   * 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;
  }
示例#4
0
 /**
  * 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();
 }
示例#5
0
  /**
   * 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);
  }
示例#6
0
    @Override
    public PcepIroObject build() {

      PcepObjectHeader iroObjHeader =
          this.bIsHeaderSet ? this.iroObjHeader : DEFAULT_IRO_OBJECT_HEADER;

      if (bIsPFlagSet) {
        iroObjHeader.setPFlag(bPFlag);
      }

      if (bIsIFlagSet) {
        iroObjHeader.setIFlag(bIFlag);
      }

      return new PcepIroObjectVer1(iroObjHeader, this.llSubObjects);
    }
示例#7
0
  /**
   * 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;
      }
    }
  }
示例#8
0
  /**
   * 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);
  }
示例#9
0
  @Override
  public int write(ChannelBuffer cb) throws PcepParseException {

    // write Object header
    int objStartIndex = cb.writerIndex();
    int objLenIndex = teObjHeader.write(cb);

    if (objLenIndex <= 0) {
      throw new PcepParseException("ObjectLength Index is " + objLenIndex);
    }

    // write Protocol ID
    cb.writeByte(this.yProtocolId);

    // write Flag
    cb.writeShort(0);

    byte bTemp = 0;
    if (bSFlag) {
      bTemp = FLAG_SET_S_FLAG;
    }

    if (bRFlag) {
      bTemp = (byte) (bTemp | FLAG_SET_R_FLAG);
    }
    cb.writeByte(bTemp);

    // write TEId
    cb.writeInt(iTEId);

    // Add optional TLV
    packOptionalTlv(cb);

    // Update object length now
    int length = cb.writerIndex() - objStartIndex;

    // will be helpful during print().
    teObjHeader.setObjLen((short) length);

    cb.setShort(objLenIndex, (short) length);

    return cb.writerIndex();
  }
示例#10
0
  @Override
  public int write(ChannelBuffer cb) throws PcepParseException {

    // write Object header
    int objStartIndex = cb.writerIndex();

    int objLenIndex = lspObjHeader.write(cb);

    if (objLenIndex <= 0) {
      throw new PcepParseException("Failed to write lsp object header. Index " + objLenIndex);
    }

    int iTemp = iPlspId << PLSPID_SHIFT_VALUE;

    iTemp = iTemp | (((bCFlag) ? BIT_SET : BIT_RESET) << CFLAG_SHIFT_VALUE);

    iTemp = iTemp | (yOFlag << OFLAG_SHIFT_VALUE);
    byte bFlag;
    iTemp = bAFlag ? (iTemp | AFLAG_TEMP_SHIFT_VALUE) : iTemp;

    bFlag = (bRFlag) ? (byte) BIT_SET : BIT_RESET;
    iTemp = iTemp | (bFlag << RFLAG_SHIFT_VALUE);
    bFlag = (bSFlag) ? (byte) BIT_SET : BIT_RESET;
    iTemp = iTemp | (bFlag << SFLAG_SHIFT_VALUE);
    bFlag = (bDFlag) ? (byte) BIT_SET : BIT_RESET;
    iTemp = iTemp | bFlag;
    cb.writeInt(iTemp);

    // Add optional TLV
    packOptionalTlv(cb);

    // Update object length now
    int length = cb.writerIndex() - objStartIndex;
    // will be helpful during print().
    lspObjHeader.setObjLen((short) length);
    // As per RFC the length of object should be
    // multiples of 4

    cb.setShort(objLenIndex, (short) length);

    return length;
  }
示例#11
0
    @Override
    public PcepTEObject build() {
      PcepObjectHeader teObjHeader =
          this.bIsHeaderSet ? this.teObjHeader : DEFAULT_TE_OBJECT_HEADER;

      byte yProtocolId = this.bIsProtocolIdSet ? this.yProtocolId : DEFAULT_PROTOCOL_ID;
      boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_R_FLAG;
      boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_S_FLAG;
      int iTEId = this.bIsTEIdSet ? this.iTEId : DEFAULT_TE_ID;

      if (bIsPFlagSet) {
        teObjHeader.setPFlag(bPFlag);
      }

      if (bIsIFlagSet) {
        teObjHeader.setIFlag(bIFlag);
      }

      return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
    }
示例#12
0
    @Override
    public PcepLspObject build() {
      PcepObjectHeader lspObjHeader =
          this.bIsHeaderSet ? this.lspObjHeader : DEFAULT_LSP_OBJECT_HEADER;

      int plspId = this.bIsPlspIdSet ? this.plspId : DEFAULT_PLSPID;
      byte yOFlag = this.bIsOFlagSet ? this.yOFlag : DEFAULT_OFLAG;
      boolean bAFlag = this.bIsAFlagSet ? this.bAFlag : DEFAULT_AFLAG;
      boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG;
      boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_SFLAG;
      boolean bDFlag = this.bIsDFlagSet ? this.bDFlag : DEFAULT_DFLAG;
      boolean bCFlag = this.bIsCFlagSet ? this.bCFlag : DEFAULT_CFLAG;

      if (bIsPFlagSet) {
        lspObjHeader.setPFlag(bPFlag);
      }

      if (bIsIFlagSet) {
        lspObjHeader.setIFlag(bIFlag);
      }

      return new PcepLspObjectVer1(
          lspObjHeader, plspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, bCFlag, llOptionalTlv);
    }
示例#13
0
  /**
   * 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.");
    }
  }