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

The following examples show how to use org.jboss.netty.buffer.ChannelBuffer#readBytes() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Reads from channel buffer and returns object of PcepFecObjectIPv4UnnumberedAdjacency.
 *
 * @param cb of channel buffer
 * @return object of PcepFecObjectIPv4UnnumberedAdjacency
 * @throws PcepParseException when fails to read from channel buffer
 */
public static PcepFecObjectIPv4UnnumberedAdjacency read(ChannelBuffer cb) throws PcepParseException {

    PcepObjectHeader fecObjHeader;
    int localNodeID;
    int localInterfaceID;
    int remoteNodeID;
    int remoteInterfaceID;

    fecObjHeader = PcepObjectHeader.read(cb);

    //take only FEC IPv4 Unnumbered Adjacency Object buffer.
    ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
    localNodeID = tempCb.readInt();
    localInterfaceID = tempCb.readInt();
    remoteNodeID = tempCb.readInt();
    remoteInterfaceID = tempCb.readInt();

    return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, localNodeID, localInterfaceID, remoteNodeID,
            remoteInterfaceID);
}
 
Example 2
Source Project: onos   File: BgpAttrNodeName.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Reads the LS attribute node name.
 *
 * @param cb ChannelBuffer
 * @return object of BgpAttrNodeName
 * @throws BgpParseException while parsing BgpAttrNodeName
 */
public static BgpAttrNodeName read(ChannelBuffer cb)
        throws BgpParseException {
    byte[] nodeName;

    short lsAttrLength = cb.readShort();

    if (cb.readableBytes() < lsAttrLength) {
        Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR,
                               BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
                               lsAttrLength);
    }

    nodeName = new byte[lsAttrLength];
    cb.readBytes(nodeName);
    log.debug("LS attribute node name read");
    return BgpAttrNodeName.of(nodeName);
}
 
Example 3
Source Project: onos   File: PcepErrorMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for
 * PCEP-ERROR Object, PCEP-ERROR Object
 * in PcepErrorMsg message.
 */
@Test
public void errorMessageTest9() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x14, // common header
            0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
            0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header
            0x00, 0x00, 0x01, 0x01};

    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 4
Source Project: onos   File: PcepOpenMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV
 * with P bit set in Pcep Open message.
 */
@Test
public void openMessageTest7() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set
            0x20, 0x1e, 0x78, (byte) 0xbd,
            0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY
            0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV
            (byte) 0xff, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV
    };

    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 5
Source Project: onos   File: PcepOpenMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source Project: onos   File: PcepReportMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP Object,LSP Object,ERO Object,BandWidth Object,RRO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest18() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x68,
            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,
            0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth 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 7
Source Project: onos   File: PcepRsvpUserErrorSpec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Reads the channel buffer and returns object of PcepRsvpErrorSpec.
 *
 * @param cb of type channel buffer
 * @return object of PcepRsvpErrorSpec
 * @throws PcepParseException when expected object is not received
 */
public static PcepRsvpErrorSpec read(ChannelBuffer cb) throws PcepParseException {
    PcepRsvpSpecObjHeader objHeader;
    int enterpriseNum;
    byte subOrg;
    byte errDescLen;
    short userErrorValue;
    byte[] errDesc;
    LinkedList<PcepValueType> llRsvpUserSpecSubObj = null;

    objHeader = PcepRsvpSpecObjHeader.read(cb);

    if (objHeader.getObjClassNum() != CLASS_NUM || objHeader.getObjClassType() != CLASS_TYPE) {
        throw new PcepParseException("Expected PcepRsvpUserErrorSpec object.");
    }
    enterpriseNum = cb.readInt();
    subOrg = cb.readByte();
    errDescLen = cb.readByte();
    userErrorValue = cb.readShort();
    errDesc = new byte[errDescLen];
    cb.readBytes(errDesc, 0, errDescLen);

    llRsvpUserSpecSubObj = parseErrSpecSubObj(cb);

    return new PcepRsvpUserErrorSpec(objHeader, enterpriseNum, subOrg, errDescLen, userErrorValue, errDesc,
            llRsvpUserSpecSubObj);
}
 
Example 8
Source Project: onos   File: PcepReportMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP Object,LSP Object,ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object
 * in PcRpt message.
 */
@Test
public void reportMessageTest20() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x88,
            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,
            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};

    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 9
Source Project: onos   File: AsbrSummaryLsa.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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));
        int unusedByte = channelBuffer.readByte();
        this.setMetric(channelBuffer.readUnsignedMedium());
    } catch (Exception e) {
        log.debug("Error::AsbrSummaryLsa:: {}", e.getMessage());
        throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
    }
}
 
Example 10
Source Project: onos   File: PcepOpenMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks open object with no tlv's in Pcep Open message.
 */
@Test
public void openMessageTest5() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C,
            0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage

    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 11
Source Project: onos   File: BgpEvpnNlriImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Reads from channelBuffer and parses Evpn Nlri.
 *
 * @param cb ChannelBuffer
 * @return object of BgpEvpnNlriVer4
 * @throws BgpParseException while parsing Bgp Evpn Nlri
 */
public static BgpEvpnNlriImpl read(ChannelBuffer cb)
        throws BgpParseException {

    BgpEvpnNlriData routeNlri = null;

    if (cb.readableBytes() > 0) {
        ChannelBuffer tempBuf = cb.copy();
        byte type = cb.readByte();
        byte length = cb.readByte();
        if (cb.readableBytes() < length) {
            throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
                                        BgpErrorType.OPTIONAL_ATTRIBUTE_ERROR,
                                        tempBuf.readBytes(cb.readableBytes()
                                                                  + TYPE_AND_LEN));
        }
        ChannelBuffer tempCb = cb.readBytes(length);
        switch (type) {
            case BgpEvpnRouteType2Nlri.TYPE:
                routeNlri = BgpEvpnRouteType2Nlri.read(tempCb);
                break;
            default:
                log.info("Discarding, EVPN route type {}", type);
                throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR,
                                            BgpErrorType.MISSING_WELLKNOWN_ATTRIBUTE, null);
                //        break;
        }
        return new BgpEvpnNlriImpl(type, routeNlri);
    } else {
        return new BgpEvpnNlriImpl();
    }

}
 
Example 12
Source Project: onos   File: IsisNeighborTlv.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(ChannelBuffer channelBuffer) {
    while (channelBuffer.readableBytes() >= 6) {
        byte[] addressbytes = new byte[IsisUtil.SIX_BYTES];
        channelBuffer.readBytes(addressbytes, 0, IsisUtil.SIX_BYTES);
        this.neighbor.add(MacAddress.valueOf(addressbytes));
    }
}
 
Example 13
Source Project: onos   File: PcepUpdateMsgExtTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case is for SRP object(SymbolicPathNameTlv), LSP object(StatefulLspErrorCodeTlv), ERO object,
 * bandwidth object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest30() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48,
            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, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object
            0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
            0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object
            0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01,
            0x01, 0x01, 0x04, 0x00,
            0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth 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 14
Source Project: onos   File: PcepReportMsgTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This test case checks for SRP Object, LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv
 * StatefulLspErrorCodeTlv) ERO Object, LSPA Object, Metric-list.
 * in PcRpt message.
 */
@Test
public void reportMessageTest6() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x6c,
            0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object
            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, 0x04, //ERO Object
            0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LSPA Object
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, //Metric object
            0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object
    };

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

    // SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv,
    // StatefulLspErrorCodeTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT.
    //
    byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x8c,
            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, 0x38, 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,
            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, 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};

    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 16
Source Project: onos   File: PcepInitiateMsgExtTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv),
 * END-POINTS, ERO, LSPA BANDWIDTH OBJECT objects in PcInitiate message.
 */
@Test
public void initiateMessageTest25() throws PcepParseException, PcepOutOfBoundMessageException {

    // SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA BANDWIDTH OBJECT.
    //
    byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x60,
            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, 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,
            0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object
            0x07, 0x10, 0x00, 0x04, //ERO object
            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));
}
 
Example 17
Source Project: onos   File: PcepLSReportMsgTest.java    License: 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(BGPLSidentifierSubTlv
 * OSPFareaIDsubTlv, IgpRouterIdSubTlv))
 * in PcLSRpt message.
 */
@Test
public void lsReportMessageTest10() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] lsReportMsg = new byte[]{0x20, (byte) 0xE0, 0x00, 0x68, // common header
            (byte) 0xE0, 0x10, 0x00, 0x64, // 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, 0x1C, //RemoteNodeDescriptorsTLV
            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
    };

    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 18
Source Project: onos   File: PcepLabelUpdateMsgTest.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This test case checks for
 * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LSP, LABEL
 * in PcepLabelUpdate message.
 */
@Test
public void labelUpdateMessageTest4() 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, 0x66, 0x00, 0x00,
            (byte) 0xE1, 0x10, 0x00, 0x0C, // LABEL Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x68, 0x00, 0x00,
            0x21, 0x10, 0x00, 0x0C, // SRP Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x11,
            0x20, 0x10, 0x00, 0x08, // LSP Object Header
            0x00, 0x02, 0x00, 0x00,
            (byte) 0xE1, 0x10, 0x00, 0x0C, // LABEL Object Header
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x44, 0x00, 0x00};

    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 19
Source Project: onos   File: PcepLSReportMsgTest.java    License: 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(
 * IPv4InterfaceAddressSubTlv, IPv4NeighborAddressSubTlv))
 * in PcLSRpt message.
 */
@Test
public void lsReportMessageTest15() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] lsReportMsg = new byte[]{0x20, (byte) 0xE0, 0x00, (byte) 0x84, // common header
            (byte) 0xE0, 0x10, 0x00, (byte) 0x80, // 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, 0x10, //LinkDescriptorsTLV
            0x00, 0x07, 0x00, 0x04, //IPv4InterfaceAddressSubTlv
            0x01, 0x01, 0x01, 0x01,
            0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressSubTlv
            0x01, 0x011, 0x01, 0x10
    };

    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 Project: onos   File: Validation.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Convert byte array to MacAddress.
 *
 * @param length of MacAddress
 * @param cb channelBuffer
 * @return macAddress
 */
public static MacAddress toMacAddress(int length, ChannelBuffer cb) {
    byte[] address = new byte[length];
    cb.readBytes(address, 0, length);
    MacAddress macAddress = MacAddress.valueOf(address);
    return macAddress;
}