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

The following are Jave code examples for showing how to use writerIndex() 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: traccar-service   File: NoranProtocolEncoder.java   Source Code and License Vote up 6 votes
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 12 + 56);

        buf.writeBytes(
                ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
        buf.writeByte(0);
        buf.writeShort(buf.capacity());
        buf.writeShort(NoranProtocolDecoder.MSG_CONTROL);
        buf.writeInt(0); // gis ip
        buf.writeShort(0); // gis port
        buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
        buf.writerIndex(buf.writerIndex() + 50 - content.length());
        buf.writeBytes(
                ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));

        return buf;
    }
 
Example 2
Project: athena   File: PcepOpenObjectVer1.java   Source Code and License Vote up 6 votes
/**
 * Returns writer index.
 *
 * @param cb of type channel buffer.
 * @return writer index
 */
protected int packOptionalTlv(ChannelBuffer cb) {
    int startIndex = cb.writerIndex();

    LinkedList<PcepValueType> llOptionalTlv = this.llOptionalTlv;
    ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
    while (listIterator.hasNext()) {
        PcepValueType tlv = listIterator.next();
        if (tlv == null) {
            log.debug("TLV is null from OptionalTlv list");
            continue;
        }

        tlv.write(cb);

        // need to take care of padding
        int pad = tlv.getLength() % 4;

        if (0 != pad) {
            pad = 4 - pad;
            for (int i = 0; i < pad; ++i) {
                cb.writeByte((byte) 0);
            }
        }
    }
    return cb.writerIndex() - startIndex;
}
 
Example 3
Project: athena   File: PcepInitiateMsgTest.java   Source Code and License Vote up 5 votes
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv)
 * objects in PcInitiate message.
 */
@Test
public void initiateMessageTest12() throws PcepParseException, PcepOutOfBoundMessageException {

    /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv).
     */
    byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x3c,
            0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv
            0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, 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
    };

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

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


    message = reader.readFrom(buffer);

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

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    message.writeTo(buf);

    testInitiateDeletionMsg = buf.array();

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

    assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg));
}
 
Example 4
Project: athena   File: PcepLabelDbVerTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeLong(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 5
Project: athena   File: BgpFsDestinationPortNum.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(FLOW_SPEC_TYPE);

    for (BgpFsOperatorValue fsOperVal : operatorValue) {
        cb.writeByte(fsOperVal.option());
        cb.writeBytes(fsOperVal.value());
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
Example 6
Project: athena   File: StatefulLspDbVerTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeLong(rawValue);
    return c.writerIndex();
}
 
Example 7
Project: athena   File: PcepUpdateMsgExtTest.java   Source Code and License Vote up 5 votes
/**
 * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object,LSPA
 * metric object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest14() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x60,
            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,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 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 8
Project: athena   File: PcepAttributeVer1.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {
    int iLenStartIndex = cb.writerIndex();
    //PCEP LSPA object is optional
    if (this.isLspaObjectSet) {
        this.lspaObject.write(cb);
    }

    //PCEP BANDWIDTH object is optional
    if (this.isBandwidthObjectSet) {
        this.bandwidthObject.write(cb);
    }

    //PCEP Metric list is optional
    if (this.isMetricListSet) {
        ListIterator<PcepMetricObject> listIterator = this.llMetricList.listIterator();
        while (listIterator.hasNext()) {
            listIterator.next().write(cb);
        }
    }

    //PCEP  IRO object is optional
    if (this.isIroObjectSet) {
        this.iroObject.write(cb);
    }
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 9
Project: athena   File: PcepReportMsgExtTest.java   Source Code and License Vote up 5 votes
/**
 * Tests PCRpt msg with Path-Setup-Type TLV as "without SR and without signalling".
 *
 * @throws PcepParseException
 * @throws PcepOutOfBoundMessageException
 */
@Test
public void reportMessageTest44() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x3C,
            0x21, 0x10, 0x00, 0x14,  0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x01, //SRP object
            0x00, 0x1c, 0x00, 0x04, // PATH-SETUP-TYPE TLV
            0x00, 0x00, 0x00, 0x02,
            0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv
            0x07, 0x10, 0x00, 0x14, //ERO object
            0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, //ERO IPv4 subobjects
            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 10
Project: athena   File: MaximumLinkBandwidthSubTlv.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(rawValue);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 11
Project: athena   File: PcepFecObjectIPv4AdjacencyVer1.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

    //Write common header
    int objLenIndex = fecObjHeader.write(cb);
    cb.writeInt(localIPv4Address);
    cb.writeInt(remoteIPv4Address);

    //Now write FEC IPv4 Adjacency Object Length
    cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
    return cb.writerIndex();
}
 
Example 12
Project: athena   File: PcepRsvpObjectHeader.java   Source Code and License Vote up 5 votes
/**
 * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
 *
 * @param cb of type channel buffer
 * @return object length index in channel buffer
 */
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeShort((short) 0);
    cb.writeByte(this.objClassNum);
    cb.writeByte(this.objClassType);
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 13
Project: athena   File: BgpFsPacketLength.java   Source Code and License Vote up 5 votes
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();

    cb.writeByte(FLOW_SPEC_TYPE);

    for (BgpFsOperatorValue fsOperVal : operatorValue) {
        cb.writeByte(fsOperVal.option());
        cb.writeBytes(fsOperVal.value());
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
Example 14
Project: athena   File: PcepErrorMsgVer1.java   Source Code and License Vote up 5 votes
@Override
public void write(ChannelBuffer cb, PcepErrorMsgVer1 message) throws PcepParseException {
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type 0xC
    cb.writeByte(MSG_TYPE.getType());
    // length is length of variable message, will be updated at the end
    // Store the position of message
    // length in buffer
    int msgLenIndex = cb.writerIndex();
    cb.writeShort(0);
    ErrorObjListWithOpen errObjListWithOpen = message.getErrorObjListWithOpen();
    PcepErrorInfo errInfo = message.getPcepErrorInfo();

    // write ( <error-obj-list> [<Open>] ) if exists.
    // otherwise write <error> [<error-list>]

    if ((errObjListWithOpen != null)
            && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
        errObjListWithOpen.write(cb);
    } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) {
        errInfo.write(cb);
    } else {
        throw new PcepParseException("Empty PCEP-ERROR message.");
    }
    // PcepErrorMessage message length field
    int length = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) length);
}
 
Example 15
Project: athena   File: PcepInitiateMsgVer1.java   Source Code and License Vote up 4 votes
@Override
public void write(ChannelBuffer cb, PcepInitiateMsgVer1 message) throws PcepParseException {

    boolean isDelLspRequest = false;
    int startIndex = cb.writerIndex();
    // first 3 bits set to version
    cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
    // message type 0xC
    cb.writeByte(MSG_TYPE.getType());
    // length is length of variable message, will be updated at the end
    // Store the position of message
    // length in buffer
    int msgLenIndex = cb.writerIndex();
    cb.writeShort(0);

    ListIterator<PcInitiatedLspRequest> listIterator = message.llPcInitiatedLspRequestList.listIterator();

    while (listIterator.hasNext()) {

        PcInitiatedLspRequest listReq = listIterator.next();

        //Srp Object is mandatory
        PcepSrpObject srpObj = listReq.getSrpObject();
        if (srpObj != null) {
            isDelLspRequest = srpObj.getRFlag();
            srpObj.write(cb);
        } else {
            throw new PcepParseException("SRP Object is mandatory for PcInitiate message.");
        }

        //LSP Object is mandatory
        PcepLspObject lspObj = listReq.getLspObject();
        if (lspObj != null) {
            lspObj.write(cb);
        } else {
            throw new PcepParseException("LSP Object is mandatory for PcInitiate message.");
        }

        /* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects
         * so if R bit is not set then we should read for Ero and EndPoint objects also.
         */

        if (!isDelLspRequest) {

            //EndPoints object is mandatory
            PcepEndPointsObject endPointObj = listReq.getEndPointsObject();
            if (endPointObj != null) {
                endPointObj.write(cb);
            } else {
                throw new PcepParseException("End points Object is mandatory for PcInitiate message.");
            }

            //Ero object is mandatory
            PcepEroObject eroObj = listReq.getEroObject();
            if (eroObj != null) {
                eroObj.write(cb);
            } else {
                throw new PcepParseException("ERO Object is mandatory for PcInitiate message.");
            }

            //PcepAttribute is optional
            PcepAttribute pcepAttribute = listReq.getPcepAttribute();
            if (pcepAttribute != null) {
                pcepAttribute.write(cb);
            }
        }
    }

    // PCInitiate message length field
    int length = cb.writerIndex() - startIndex;
    cb.setShort(msgLenIndex, (short) length);
}
 
Example 16
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,Metric-list,RRO Object
 * SRP Object,LSP Object(symbolic path tlv),ERO Object,Metric-list,RRO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest30() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0xE4,
            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,
            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,
            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 17
Project: athena   File: PcepLabelUpdateMsgTest.java   Source Code and License Vote up 4 votes
/**
 * This test case checks for
 * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LABEL, FEC.
 * in PcepLabelUpdate message.
 */
@Test
public void labelUpdateMessageTest6() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] labelUpdate = new byte[]{0x20, (byte) 0xE2, 0x00, 0x50, // common header
            0x21, 0x10, 0x00, 0x0C, // SRP Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x10,
            0x20, 0x10, 0x00, 0x08, // LSP Object Header
            0x00, 0x01, 0x00, 0x00,
            (byte) 0xE1, 0x10, 0x00, 0x0C, // LABEL Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x44, 0x00, 0x00,
            (byte) 0xE1, 0x10, 0x00, 0x0C, // LABEL Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x44, 0x00, 0x00,
            0x21, 0x10, 0x00, 0x0C, // SRP Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x12,
            (byte) 0xE1, 0x10, 0x00, 0x0C, // LABEL Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x44, 0x00, 0x00,
            (byte) 0xE2, 0x10, 0x00, 0x08, // FEC Object Header
            0x0A, 0x0A, 0x0D, 0x0D};

    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(labelUpdate);

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

    message = reader.readFrom(buffer);

    byte[] testLabelUpdateMsg = {0};
    assertThat(message, instanceOf(PcepLabelUpdateMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);

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

    assertThat(testLabelUpdateMsg, is(labelUpdate));
}
 
Example 18
Project: athena   File: WideCommunityParameter.java   Source Code and License Vote up 4 votes
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    WideCommunity.encodeWideCommunityTlv(c, parameterTlv());
    return c.writerIndex() - iLenStartIndex;
}
 
Example 19
Project: athena   File: PcepReportMsgTest.java   Source Code and License Vote up 4 votes
/**
 * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv )
 * ERO Object,LSPA Object,RRO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest25() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x8c,
            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,
            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 20
Project: athena   File: PcepLSReportMsgTest.java   Source Code and License Vote up 4 votes
/**
 * This test case checks for
 * LS Object (Routing Universe TLV,Local Node Descriptors TLV(AutonomousSystemSubTlv, BGPLSidentifierSubTlv
 * OSPFareaIDsubTlv, IgpRouterIdSubTlv), RemoteNodeDescriptorsTLV(AutonomousSystemSubTlv, BGPLSidentifierSubTlv
 * OSPFareaIDsubTlv, IgpRouterIdSubTlv), LinkDescriptorsTLV(LinkLocalRemoteIdentifiersSubTlv
 * IPv4InterfaceAddressSubTlv, IPv4NeighborAddressSubTlv))
 * in PcLSRpt message.
 */
@Test
public void lsReportMessageTest18() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] lsReportMsg = new byte[]{0x20, (byte) 0xE0, 0x00, (byte) 0xC4, // common header
            (byte) 0xE0, 0x10, 0x00, (byte) 0xC0, // LS Object Header
            0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, // LS-ID
            (byte) 0xFF, 0x01, 0x00, 0x08, // Routing Universe TLV
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x01,
            (byte) 0xFF, 0x02, 0x00, 0x24, // Local Node Descriptors TLV
            0x00, 0x01, 0x00, 0x04, //AutonomousSystemSubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x02, 0x00, 0x04, //BGPLSidentifierSubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x03, 0x00, 0x04, //OSPFareaIDsubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x04, 0x00, 0x08, //IgpRouterIdSubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x00, 0x00, 0x11,
            (byte) 0xFF, 0x03, 0x00, 0x24, //RemoteNodeDescriptorsTLV
            0x00, 0x01, 0x00, 0x04, //AutonomousSystemSubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x02, 0x00, 0x04, //BGPLSidentifierSubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x03, 0x00, 0x04, //OSPFareaIDsubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x04, 0x00, 0x08, //IgpRouterIdSubTlv
            0x00, 0x00, 0x00, 0x11,
            0x00, 0x00, 0x00, 0x11,
            (byte) 0xFF, 0x04, 0x00, 0x1C, //LinkDescriptorsTLV
            0x00, 0x06, 0x00, 0x08, //LinkLocalRemoteIdentifiersSubTlv
            0x01, 0x11, 0x00, 0x09,
            0x01, 0x21, 0x00, 0x09,
            0x00, 0x07, 0x00, 0x04, //IPv4InterfaceAddressSubTlv
            0x01, 0x01, 0x01, 0x01,
            0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressSubTlv
            0x01, 0x011, 0x01, 0x10,
            (byte) 0xFF, 0x05, 0x00, 0x30, //NodeAttributesTlv
            0x00, 0x0D, 0x00, 0x01, //NodeFlagBitsSubTlv
            (byte) 0x90, 0x00, 0x00, 0x00,
            0x00, 0x0E, 0x00, 0x04, //OpaqueNodePropertiesSubTlv
            0x01, 0x011, 0x01, 0x10,
            0x00, 0x0F, 0x00, 0x08, //NodeNameSubTlv
            0x08, 0x00, 0x01, 0x09,
            0x08, 0x00, 0x01, 0x09,
            0x00, 0x10, 0x00, 0x08, //ISISAreaIdentifierSubTlv
            0x20, 0x01, 0x22, 0x01,
            0x20, 0x01, 0x22, 0x01,
            0x00, 0x11, 0x00, 0x04, //IPv4RouterIdOfLocalNodeSubTlv
            0x00, 0x01, 0x01, 0x02
    };

    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(lsReportMsg);

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

    message = reader.readFrom(buffer);

    byte[] testReportMsg = {0};
    assertThat(message, instanceOf(PcepLSReportMsg.class));
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    message.writeTo(buf);

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

    assertThat(testReportMsg, is(lsReportMsg));
}