Java Code Examples for org.jboss.netty.buffer.ChannelBuffer.readBytes()

The following are Jave code examples for showing how to use readBytes() of the org.jboss.netty.buffer.ChannelBuffer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: NioSmtpClient   File: ChunkingExtension.java   Source Code and License Vote up 6 votes
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  if (e.getMessage() instanceof ChannelBuffer) {
    ChannelBuffer buffer = (ChannelBuffer) e.getMessage();

    int bytesToRead = Math.min(currentChunkSize - bytesRead, buffer.readableBytes());
    buffer.readBytes(getMailEnvelope().getMessageOutputStream(), bytesToRead);
    bytesRead += bytesToRead;

    if (bytesRead == currentChunkSize) {
      stopCapturingData();
    }

    return;
  }

  super.messageReceived(ctx, e);
}
 
Example 2
Project: athena   File: PcepUpdateMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv,
 * StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject) objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest9() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58,
            0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x00, 0x11, 0x00, 0x02,  0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x00, 0x11, 0x00, 0x02,  0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x01, 0x04, 0x00 };

    byte[] testupdateMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepUpdateMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testupdateMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testupdateMsg = new byte[readLen];
    buf.readBytes(testupdateMsg, 0, readLen);

    assertThat(testupdateMsg, is(updateMsg));
}
 
Example 3
Project: athena   File: BgpHeader.java   Source Code and License Vote up 5 votes
/**
 * Read from channel buffer and Returns BGP header.
 *
 * @param cb ChannelBuffer
 * @return object of BGPHeader
 */
public static BgpHeader read(ChannelBuffer cb) {

    byte[] marker = new byte[MARKER_LENGTH];
    byte type;
    short length;
    cb.readBytes(marker, 0, MARKER_LENGTH);
    length = cb.readShort();
    type = cb.readByte();
    return new BgpHeader(marker, length, type);
}
 
Example 4
Project: athena   File: PcepUpdateMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks for SRP, LSP,
 * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest32() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54,
            0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x20, 0x10, 0x00, 0x8, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x01, 0x04, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00,
            0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object

    byte[] testupdateMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepUpdateMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testupdateMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testupdateMsg = new byte[readLen];
    buf.readBytes(testupdateMsg, 0, readLen);

    assertThat(testupdateMsg, is(updateMsg));
}
 
Example 5
Project: athena   File: AreaAddressTlv.java   Source Code and License Vote up 5 votes
@Override
public void readFrom(ChannelBuffer channelBuffer) {
    while (channelBuffer.readableBytes() > 0) {
        int addressLength = channelBuffer.readByte();
        byte[] addressbytes = new byte[addressLength];
        channelBuffer.readBytes(addressbytes, 0, addressLength);
        String areaAddress = IsisUtil.areaAddres(addressbytes);
        this.areaAddress.add(areaAddress);
    }
}
 
Example 6
Project: athena   File: PcepReportMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv )
 * ERO Object,LSPA Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest26() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x58,
            0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object
            0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv
            0x07, 0x10, 0x00, 0x14, //ERO Object
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA Object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    byte[] testReportMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(reportMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepReportMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);

    int readLen = buf.writerIndex();
    testReportMsg = new byte[readLen];
    buf.readBytes(testReportMsg, 0, readLen);

    assertThat(testReportMsg, is(reportMsg));
}
 
Example 7
Project: athena   File: PcepReportMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv)
 * ERO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest27() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x44,
            0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object
            0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv
            0x07, 0x10, 0x00, 0x14, //ERO Object
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00};

    byte[] testReportMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(reportMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepReportMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);

    int readLen = buf.writerIndex();
    testReportMsg = new byte[readLen];
    buf.readBytes(testReportMsg, 0, readLen);

    assertThat(testReportMsg, is(reportMsg));
}
 
Example 8
Project: athena   File: PcepUpdateMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv),
 * ERO (IPv4SubObject, IPv4SubObject),Metric objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest18() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x4c,
            0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x01, 0x04, 0x00,
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object

    byte[] testupdateMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(updateMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepUpdateMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testupdateMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testupdateMsg = new byte[readLen];
    buf.readBytes(testupdateMsg, 0, readLen);

    assertThat(testupdateMsg, is(updateMsg));
}
 
Example 9
Project: athena   File: ExternalLsa.java   Source Code and License Vote up 5 votes
/**
 * Reads from channel buffer and populate instance.
 *
 * @param channelBuffer channelBuffer instance
 * @throws OspfParseException might throws exception while parsing buffer
 */
public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {

    try {
        byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
        channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
        this.setNetworkMask(Ip4Address.valueOf(tempByteArray));

        while (channelBuffer.readableBytes() >= OspfUtil.EXTERNAL_DESTINATION_LENGTH) {
            OspfExternalDestination externalDestination = new OspfExternalDestination();

            //E Bit - use to find type1 or type2
            int eIsSet = channelBuffer.readByte();
            if (eIsSet != 0) {
                externalDestination.setType1orType2Metric(true);
            } else {
                externalDestination.setType1orType2Metric(false);
            }
            externalDestination.setMetric(channelBuffer.readUnsignedMedium());
            tempByteArray = new byte[OspfUtil.FOUR_BYTES];
            channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
            externalDestination.setForwardingAddress(Ip4Address.valueOf(tempByteArray));
            externalDestination.setExternalRouterTag(channelBuffer.readInt());

            this.addExternalDestination(externalDestination);
        }
    } catch (Exception e) {
        log.debug("Error::ExternalLSA:: {}", e.getMessage());
        throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
    }
}
 
Example 10
Project: athena   File: AdjacencyStateTlv.java   Source Code and License Vote up 5 votes
@Override
public void readFrom(ChannelBuffer channelBuffer) {
    this.setAdjacencyType(channelBuffer.readByte());
    this.setLocalCircuitId(channelBuffer.readInt());
    if (channelBuffer.readableBytes() > 0) {
        byte[] tempByteArray = new byte[IsisUtil.ID_SIX_BYTES];
        channelBuffer.readBytes(tempByteArray, 0, IsisUtil.ID_SIX_BYTES);
        this.setNeighborSystemId(IsisUtil.systemId(tempByteArray));
        this.setNeighborLocalCircuitId(channelBuffer.readInt());
    }
}
 
Example 11
Project: athena   File: PcepOpenMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks open object with LSR id encoded.
 */
@Test
public void openMessageTest16() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, // common header
            0x01, 0x10, 0x00, 0x14, // common object header
            0x20, 0x05, 0x1E, 0x01, // OPEN object
            (byte) 0xFF, 0x05, 0x00, 0x08, // Node attribute TLV
            0x00, 0x11, 0x00, 0x04,  // PCEP-LS-IPv4-ROUTER-ID sub tlv
            0x02, 0x02, 0x02, 0x02
    };

    byte[] testOpenMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepOpenMsg.class));

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testOpenMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testOpenMsg = new byte[readLen];
    buf.readBytes(testOpenMsg, 0, readLen);
    assertThat(testOpenMsg, is(openMsg));

}
 
Example 12
Project: athena   File: PcepIroObjectVer1.java   Source Code and License Vote up 5 votes
/**
 * 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);
}
 
Example 13
Project: athena   File: PcepOpenMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV
 * in Pcep Open message.
 */
@Test
public void openMessageTest10() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header
            0x01, 0x10, 0x00, 0x18, // common object header
            0x20, 0x05, 0x1E, 0x01, // OPEN object
            0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY
            0x00, 0x00, 0x00, 0x05,
            0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV
            0x00, 0x00, 0x00, 0x00};

    byte[] testOpenMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(openMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepOpenMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);
    testOpenMsg = buf.array();

    int readLen = buf.writerIndex() - 0;
    testOpenMsg = new byte[readLen];
    buf.readBytes(testOpenMsg, 0, readLen);

    assertThat(testOpenMsg, is(openMsg));

}
 
Example 14
Project: athena   File: OspfMessageReader.java   Source Code and License Vote up 5 votes
/**
 * Gets the OSPF packet Header.
 *
 * @param channelBuffer channel buffer instance.
 * @return Ospf Header instance.
 */
private OspfPacketHeader getOspfHeader(ChannelBuffer channelBuffer) throws Exception {
    OspfPacketHeader ospfPacketHeader = new OspfPacketHeader();

    // Determine OSPF version & Packet Type
    int version = channelBuffer.readByte(); //byte 1 is ospf version
    int packetType = channelBuffer.readByte(); //byte 2 is ospf packet type

    // byte 3 & 4 combine is packet length.
    int packetLength = channelBuffer.readShort();

    byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
    channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
    Ip4Address routerId = Ip4Address.valueOf(tempByteArray);

    tempByteArray = new byte[OspfUtil.FOUR_BYTES];
    channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
    Ip4Address areaId = Ip4Address.valueOf(tempByteArray);

    int checkSum = channelBuffer.readUnsignedShort();
    int auType = channelBuffer.readUnsignedShort();
    int authentication = (int) channelBuffer.readLong();

    ospfPacketHeader.setOspfVer(version);
    ospfPacketHeader.setOspftype(packetType);
    ospfPacketHeader.setOspfPacLength(packetLength);
    ospfPacketHeader.setRouterId(routerId);
    ospfPacketHeader.setAreaId(areaId);
    ospfPacketHeader.setChecksum(checkSum);
    ospfPacketHeader.setAuthType(auType);
    ospfPacketHeader.setAuthentication(authentication);

    return ospfPacketHeader;
}
 
Example 15
Project: traccar-service   File: MegastekFrameDecoder.java   Source Code and License Vote up 5 votes
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 10) {
        return null;
    }

    if (Character.isDigit(buf.getByte(buf.readerIndex()))) {
        int length = 4 + Integer.parseInt(buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII));
        if (buf.readableBytes() >= length) {
            return buf.readBytes(length);
        }
    } else {
        while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') {
            buf.skipBytes(1);
        }
        int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
        if (delimiter == -1) {
            delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!');
        }
        if (delimiter != -1) {
            ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex());
            buf.skipBytes(1);
            return result;
        }
    }

    return null;
}
 
Example 16
Project: athena   File: LocalNodeDescriptorsTlv.java   Source Code and License Vote up 4 votes
/**
 * Reads the channel buffer and returns object of AutonomousSystemTlv.
 *
 * @param c input channel buffer
 * @param hLength length of subtlvs.
 * @return object of AutonomousSystemTlv
 * @throws PcepParseException if mandatory fields are missing
 */
public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {

    // Node Descriptor Sub-TLVs (variable)
    List<PcepValueType> llNodeDescriptorSubTLVs = new LinkedList<>();

    ChannelBuffer tempCb = c.readBytes(hLength);

    while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {

        PcepValueType tlv;
        short hType = tempCb.readShort();
        int iValue = 0;
        short length = tempCb.readShort();

        switch (hType) {

        case AutonomousSystemSubTlv.TYPE:
            iValue = tempCb.readInt();
            tlv = new AutonomousSystemSubTlv(iValue);
            break;
        case BgpLsIdentifierSubTlv.TYPE:
            iValue = tempCb.readInt();
            tlv = new BgpLsIdentifierSubTlv(iValue);
            break;
        case OspfAreaIdSubTlv.TYPE:
            iValue = tempCb.readInt();
            tlv = new OspfAreaIdSubTlv(iValue);
            break;
        case IgpRouterIdSubTlv.TYPE:
            tlv = IgpRouterIdSubTlv.read(tempCb, length);
            break;

        default:
            throw new PcepParseException("Unsupported Sub TLV type :" + hType);
        }

        // Check for the padding
        int pad = length % 4;
        if (0 < pad) {
            pad = 4 - pad;
            if (pad <= tempCb.readableBytes()) {
                tempCb.skipBytes(pad);
            }
        }

        llNodeDescriptorSubTLVs.add(tlv);
    }

    if (0 < tempCb.readableBytes()) {
        throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
    }
    return new LocalNodeDescriptorsTlv(llNodeDescriptorSubTLVs);
}
 
Example 17
Project: athena   File: PcepInitiateMsgTest.java   Source Code and License Vote up 4 votes
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv,
 * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO objects
 * in PcInitiate message.
 */
@Test
public void initiateMessageTest3() throws PcepParseException, PcepOutOfBoundMessageException {

    /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv,
     * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO.
     */
    byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x64,
            0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv
            (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01,
            (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20,
            0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv
            0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv
            0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object
            0x07, 0x10, 0x00, 0x14, //ERO object
            0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00,
            0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00};

    byte[] testInitiateCreationMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(initiateCreationMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepInitiateMsg.class));

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    message.writeTo(buf);
    testInitiateCreationMsg = buf.array();

    int iReadLen = buf.writerIndex();
    testInitiateCreationMsg = new byte[iReadLen];
    buf.readBytes(testInitiateCreationMsg, 0, iReadLen);

    assertThat(testInitiateCreationMsg, is(initiateCreationMsg));
}
 
Example 18
Project: athena   File: PcepReportMsgTest.java   Source Code and License Vote up 4 votes
/**
 * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object
 * BandWidth Object,Metric-list,RRO Object,SRP Object,LSP Object(symbolic path tlv)
 * ERO Object,LSPA Object,Metric-list,RRO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest32() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x01, (byte) 0x14,
            0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object
            0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x07, 0x10, 0x00, 0x14, //ERO Object
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object
            0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
            0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
            0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00,
            0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object
            0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            0x07, 0x10, 0x00, 0x14, //ERO Object
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00,
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object
            0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06,
            0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
            0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01,
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00};

    byte[] testReportMsg = {0};
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(reportMsg);

    PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
    PcepMessage message = null;

    message = reader.readFrom(buffer);

    assertThat(message, instanceOf(PcepReportMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);

    int readLen = buf.writerIndex();
    testReportMsg = new byte[readLen];
    buf.readBytes(testReportMsg, 0, readLen);

    assertThat(testReportMsg, is(reportMsg));
}
 
Example 19
Project: athena   File: BgpPrefixLSIdentifier.java   Source Code and License Vote up 4 votes
/**
 * Parse list of prefix descriptors.
 *
 * @param cb ChannelBuffer
 * @return list of prefix descriptors
 * @throws BgpParseException while parsing list of prefix descriptors
 */
public static List<BgpValueType> parsePrefixDescriptors(ChannelBuffer cb) throws BgpParseException {
    LinkedList<BgpValueType> prefixDescriptor = new LinkedList<>();
    BgpValueType tlv = null;
    boolean isIpReachInfo = false;
    ChannelBuffer tempCb;
    int count = 0;

    while (cb.readableBytes() > 0) {
        ChannelBuffer tempBuf = cb.copy();
        short type = cb.readShort();
        short length = cb.readShort();
        if (cb.readableBytes() < length) {
            //length + 4 implies data contains type, length and value
            throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                    tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN));
        }
        tempCb = cb.readBytes(length);
        switch (type) {
        case OspfRouteTypeTlv.TYPE:
            tlv = OspfRouteTypeTlv.read(tempCb);
            break;
        case IPReachabilityInformationTlv.TYPE:
            tlv = IPReachabilityInformationTlv.read(tempCb, length);
            isIpReachInfo = true;
            break;
        case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY:
            tlv = BgpAttrNodeMultiTopologyId.read(tempCb);
            count = count + 1;
            if (count > 1) {
                //length + 4 implies data contains type, length and value
                throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
                       BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + TYPE_AND_LEN));
            }
            break;
        default:
            UnSupportedAttribute.skipBytes(tempCb, length);
        }
        prefixDescriptor.add(tlv);
    }

    if (!isIpReachInfo) {
        throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                null);
    }
    return prefixDescriptor;
}
 
Example 20
Project: athena   File: PcepNaiIpv6NodeId.java   Source Code and License Vote up 2 votes
/**
 * Reads from the channel buffer and returns object of PcepNAIIpv6NodeId.
 *
 * @param cb of type channel buffer.
 * @return object of PcepNAIIpv6NodeId
 */
public static PcepNaiIpv6NodeId read(ChannelBuffer cb) {
    byte[] ipv6NodeId = new byte[IPV6_LEN];
    cb.readBytes(ipv6NodeId, 0, IPV6_LEN);
    return new PcepNaiIpv6NodeId(ipv6NodeId);
}