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

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#writerIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ErrorObjListWithOpen.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Write Error Object List and Open Object to channel buffer.
 *
 * @param cb output channel buffer
 * @return length of written Error object list with open
 * @throws PcepParseException when mandatory fields are not set
 */
public int write(ChannelBuffer cb) throws PcepParseException {
    int iLenStartIndex = cb.writerIndex();
    boolean bIsErrObjListFound = false;

    //<error-obj-list> is mandatory , if not present throw exception.
    if (llerrorObjList != null) {
        ListIterator<PcepErrorObject> errObjListIterator = llerrorObjList.listIterator();
        while (errObjListIterator.hasNext()) {
            errObjListIterator.next().write(cb);
            bIsErrObjListFound = true;
        }
    }

    if (!bIsErrObjListFound) {
        throw new PcepParseException("<error-obj-list> is mandatory.");
    }

    //Open Object is optional , if present write.
    if (openObject != null) {
        openObject.write(cb);
    }

    return cb.writerIndex() - iLenStartIndex;
}
 
Example 2
Source File: CompositeChannelBuffer.java    From simple-netty-source with Apache License 2.0 6 votes vote down vote up
private void copyTo(int index, int length, int componentId, ChannelBuffer dst) {
    int dstIndex = 0;
    int i = componentId;

    while (length > 0) {
        ChannelBuffer s = components[i];
        int adjustment = indices[i];
        int localLength = Math.min(length, s.capacity() - (index - adjustment));
        s.getBytes(index - adjustment, dst, dstIndex, localLength);
        index += localLength;
        dstIndex += localLength;
        length -= localLength;
        i ++;
    }

    dst.writerIndex(dst.capacity());
}
 
Example 3
Source File: BgpEvpnRouteType2Nlri.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeLong(rd.getRouteDistinguisher());
    esi.write(cb);
    cb.writeInt(ethernetTagID);
    cb.writeByte(macAddressLength);
    cb.writeBytes(macAddress.toBytes());
    cb.writeByte(ipAddressLength);
    if (ipAddressLength > 0) {
        cb.writeBytes(ipAddress.getAddress());
    }
    mplsLabel1.write(cb);
    if (mplsLabel2 != null) {
        mplsLabel2.write(cb);
    }
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 4
Source File: BgpEvpnNlriImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public int write(ChannelBuffer cb) {
    int iLenStartIndex = cb.writerIndex();
    cb.writeByte(routeType);
    int iSpecStartIndex = cb.writerIndex();
    cb.writeByte(0);
    switch (routeType) {
        case BgpEvpnRouteType2Nlri.TYPE:
            ((BgpEvpnRouteType2Nlri) routeTypeSpec).write(cb);
            break;
        default:
            break;
    }
    cb.setByte(iSpecStartIndex,
               (short) (cb.writerIndex() - iSpecStartIndex + 1));
    return cb.writerIndex() - iLenStartIndex;
}
 
Example 5
Source File: PcepErrorMsgTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for
 * PCEP-ERROR Object, PCEP-ERROR Object, LS Object, LS Object, PCEP-ERROR Object, PCEP-ERROR Object
 * in PcepErrorMsg message.
 */
@Test
public void errorMessageTest19() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x44, // common header
            0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
            0x00, 0x00, 0x01, 0x01,
            0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
            0x00, 0x00, 0x01, 0x03,
            (byte) 0xE0, 0x10, 0x00, 0x10, // LS Object Header
            0x01, 0x00, 0x00, 0x03, // LS-ID
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x10,
            (byte) 0xE0, 0x10, 0x00, 0x10, // LS Object Header
            0x01, 0x00, 0x00, 0x03, // LS-ID
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x11,
            0x0D, 0x10, 0x00, 0x08, // PCERR Object Header
            0x00, 0x00, 0x01, 0x04, // PCERR Object Header
            0x0D, 0x10, 0x00, 0x08,
            0x00, 0x00, 0x01, 0x06};

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

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

    message = reader.readFrom(buffer);

    byte[] testErrorMsg = {0};
    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
    assertThat(message, instanceOf(PcepErrorMsg.class));
    message.writeTo(buf);
    int iReadLen = buf.writerIndex();
    testErrorMsg = new byte[iReadLen];
    buf.readBytes(testErrorMsg, 0, iReadLen);

    assertThat(testErrorMsg, is(errorMsg));
}
 
Example 6
Source File: PcepUpdateMsgExtTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case is for SRP object(SymbolicPathNameTlv), LSP object(SymbolicPathNameTlv), ERO object,
 * bandwidth object Metric object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest7() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 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, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x11, 0x00, 0x02,  0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv
            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 7
Source File: PcepReportMsgTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP Object,LSP Object,ERO Object,LSPA Object,RRO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest17() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x74,
            0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object
            0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object
            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,
            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 8
Source File: AreaIDTlv.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer c) {
    int iLenStartIndex = c.writerIndex();
    c.writeShort(TYPE);
    c.writeShort(LENGTH);
    c.writeInt(areaID);
    return c.writerIndex() - iLenStartIndex;
}
 
Example 9
Source File: PcepOpenObjectVer1.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

    //write common header
    int objLenIndex = openObjHeader.write(cb);

    if (objLenIndex <= 0) {
        throw new PcepParseException("Unable to write Open object header.");
    }

    cb.writeByte((byte) (OPEN_OBJECT_VERSION << PcepMessageVer1.SHIFT_FLAG));
    cb.writeByte(this.keepAliveTime);
    cb.writeByte(this.deadTime);
    cb.writeByte(this.sessionId);

    //Pack optional TLV
    packOptionalTlv(cb);

    //now write OPEN Object Length
    int length = cb.writerIndex() - objStartIndex;
    cb.setShort(objLenIndex, (short) length);
    //will be helpful during print().
    this.openObjHeader.setObjLen((short) length);

    return length;
}
 
Example 10
Source File: BgpOpenMsgVer4.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * returns length of capability tlvs.
 *
 * @param cb of type channel buffer
 * @param message of type BGPOpenMsgVer4
 * @return capParaLen of open message
 */
protected int packCapabilityTlv(ChannelBuffer cb, BgpOpenMsgVer4 message) {
    int startIndex = cb.writerIndex();
    int capParaLen = 0;
    int capParaLenIndex = 0;

    LinkedList<BgpValueType> capabilityTlv = message.capabilityTlv;
    ListIterator<BgpValueType> listIterator = capabilityTlv.listIterator();

    if (listIterator.hasNext()) {
        // Set optional parameter type as 2
        cb.writeByte(OPT_PARA_TYPE_CAPABILITY);

        // Store the index of capability parameter length and update length at the end
        capParaLenIndex = cb.writerIndex();

        // Set capability parameter length as 0
        cb.writeByte(0);

        // Update the startIndex to know the length of capability tlv
        startIndex = cb.writerIndex();
    }

    while (listIterator.hasNext()) {
        BgpValueType tlv = listIterator.next();
        if (tlv == null) {
            log.debug("Warning: TLV is null from CapabilityTlv list");
            continue;
        }
        tlv.write(cb);
    }

    capParaLen = cb.writerIndex() - startIndex;

    if (capParaLen != 0) {
        // Update capability parameter length
        cb.setByte(capParaLenIndex, (byte) capParaLen);
    }
    return capParaLen;
}
 
Example 11
Source File: PcepUpdateMsgTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP,
 * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest30() 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, 0x08, 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 12
Source File: PcepUpdateMsgExtTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object,
 * LSPA, Bandwidth object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest2() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x68,
            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, //LSP 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 13
Source File: PcepUpdateMsgTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv),
 * ERO (IPv4SubObject, IPv4SubObject),LSPA objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest17() 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, 0x1c, 0x00, 0x00, 0x10, 0x05, //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 };

    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 14
Source File: PcepInitiateMsgExtTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP ( StatefulLspDbVerTlv), END-POINTS,
 * ERO, LSPA OBJECT objects in PcInitiate message.
 */
@Test
public void initiateMessageTest36() throws PcepParseException, PcepOutOfBoundMessageException {

    // SRP, LSP ( StatefulLspDbVerTlv), END-POINTS,
    // ERO, LSPA OBJECT.
    //
    byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x58,
            0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object
            0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
            0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object
            0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00,
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 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 15
Source File: PcepFecObjectIPv4Ver1.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

    int objStartIndex = cb.writerIndex();

    //write common header
    int objLenIndex = fecObjHeader.write(cb);
    cb.writeInt(nodeID);

    //now write FEC IPv4 Object Length
    cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
    return cb.writerIndex();
}
 
Example 16
Source File: PcepUpdateMsgTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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 17
Source File: PcepUpdateMsgTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv,
 * SymbolicPathNameTlv, StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject),
 * LSPA, Bandwidth, Metric objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest28() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x80,
            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,
            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 18
Source File: PcepLSObjectVer1.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public int write(ChannelBuffer cb) throws PcepParseException {

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

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

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

    //write Flag
    cb.writeShort(0);

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

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

    //write LSId
    cb.writeLong(lsId);

    // Add optional TLV
    packOptionalTlv(cb);

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

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

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

    return cb.writerIndex();
}
 
Example 19
Source File: PcepLSReportMsgTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * 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), NodeAttributesTlv(OpaqueNodePropertiesSubTlv
 * ISISAreaIdentifierSubTlv, IPv4RouterIdOfLocalNodeSubTlv))
 * in PcLSRpt message.
 */
@Test
public void lsReportMessageTest21() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] lsReportMsg = new byte[]{0x20, (byte) 0xE0, 0x00, (byte) 0xB0, // common header
            (byte) 0xE0, 0x10, 0x00, (byte) 0xAC, // 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, 0x1C, //NodeAttributesTlv
            0x00, 0x0E, 0x00, 0x04, //OpaqueNodePropertiesSubTlv
            0x01, 0x011, 0x01, 0x10,
            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));
}
 
Example 20
Source File: PcepInitiateMsgExtTest.java    From onos with Apache License 2.0 4 votes vote down vote up
/**
 * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv,
 * SymbolicPathNameTlv, StatefulLspDbVerTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT
 * objects in PcInitiate message.
 */
@Test
public void initiateMessageTest9() throws PcepParseException, PcepOutOfBoundMessageException {

    // SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv),
    // END-POINTS, ERO, LSPA, BANDWIDTH OBJECT.
    //
    byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x84,
            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, 0x30, 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, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
            0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object
            0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 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

    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));
}