Java Code Examples for org.jboss.netty.buffer.ChannelBuffers

The following are top voted examples for showing how to use org.jboss.netty.buffer.ChannelBuffers. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: traccar-service   File: MxtProtocolDecoder.java   View source code 6 votes vote down vote up
private static void sendResponse(Channel channel, int device, long id, int crc) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
        response.writeByte(device);
        response.writeByte(MSG_ACK);
        response.writeInt((int) id);
        response.writeShort(crc);
        response.writeShort(Checksum.crc16(
                Checksum.CRC16_XMODEM, response.toByteBuffer()));

        ChannelBuffer encoded = ChannelBuffers.dynamicBuffer();
        encoded.writeByte(0x01); // header
        while (response.readable()) {
            int b = response.readByte();
            if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
                encoded.writeByte(0x10);
                b += 0x20;
            }
            encoded.writeByte(b);
        }
        encoded.writeByte(0x04); // ending
        channel.write(encoded);
    }
}
 
Example 2
Project: hadoop   File: RpcProgram.java   View source code 6 votes vote down vote up
private void sendAcceptedReply(RpcCall call, SocketAddress remoteAddress,
    AcceptState acceptState, ChannelHandlerContext ctx) {
  RpcAcceptedReply reply = RpcAcceptedReply.getInstance(call.getXid(),
      acceptState, Verifier.VERIFIER_NONE);

  XDR out = new XDR();
  reply.write(out);
  if (acceptState == AcceptState.PROG_MISMATCH) {
    out.writeInt(lowProgVersion);
    out.writeInt(highProgVersion);
  }
  ChannelBuffer b = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
      .buffer());
  RpcResponse rsp = new RpcResponse(b, remoteAddress);
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
Example 3
Project: athena   File: OspfMessageReaderTest.java   View source code 6 votes vote down vote up
/**
 * Tests readFromBuffer() method.
 */
@Test
public void testReadFromBuffer() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet1));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet2));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet3));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet4));
    ospfMessageReader.readFromBuffer(channelBuffer);

    channelBuffer = ChannelBuffers.copiedBuffer(framePacket(packet5));
    ospfMessageReader.readFromBuffer(channelBuffer);
    assertThat(ospfMessageReader, is(notNullValue()));
}
 
Example 4
Project: flume-release-1.7.0   File: TestSyslogUtils.java   View source code 6 votes vote down vote up
/**
 * Test bad event format 3: Empty priority - <>
 */
@Test
public void testExtractBadEvent3() {
  String badData1 = "<> bad bad data\n";
  SyslogUtils util = new SyslogUtils(false);
  ChannelBuffer buff = ChannelBuffers.buffer(100);
  buff.writeBytes(badData1.getBytes());
  Event e = util.extractEvent(buff);
  if (e == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers = e.getHeaders();
  Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
  Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
  Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
                      headers.get(SyslogUtils.EVENT_STATUS));
  Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
 
Example 5
Project: athena   File: PcepMessageEncoder.java   View source code 6 votes vote down vote up
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    log.debug("Sending message");
    if (!(msg instanceof List)) {
        log.debug("Invalid msg.");
        return msg;
    }

    @SuppressWarnings("unchecked")
    List<PcepMessage> msglist = (List<PcepMessage>) msg;

    ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

    for (PcepMessage pm : msglist) {
        pm.writeTo(buf);
    }

    HexDump.pcepHexDump(buf);

    return buf;
}
 
Example 6
Project: traccar-service   File: TeltonikaProtocolEncoder.java   View source code 6 votes vote down vote up
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

        buf.writeInt(0);
        buf.writeInt(content.length() + 10);
        buf.writeByte(TeltonikaProtocolDecoder.CODEC_12);
        buf.writeByte(1); // quantity
        buf.writeByte(5); // type
        buf.writeInt(content.length() + 2);
        buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
        buf.writeByte('\r');
        buf.writeByte('\n');
        buf.writeByte(1); // quantity
        buf.writeInt(Checksum.crc16(Checksum.CRC16_IBM, buf.toByteBuffer(8, buf.writerIndex() - 8)));

        return buf;
    }
 
Example 7
Project: athena   File: BgpUpdateMsgTest.java   View source code 6 votes vote down vote up
/**
 * In this test case, update message without total Path Attribute Length field is given as
 * input and expecting an exception.
 */
@Test(expected = BgpParseException.class)
public void bgpUpdateMessageTest29() throws BgpParseException {
    byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, //marker
            0x00, 0x16, 0x02, 0x00, 0x01, 0x00};

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

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();

    message = reader.readFrom(buffer, bgpHeader);

    assertThat(message, instanceOf(BgpUpdateMsg.class));
}
 
Example 8
Project: traccar-service   File: NoranProtocolEncoder.java   View source code 6 votes vote down vote up
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 9
Project: athena   File: OpaqueLsa11Test.java   View source code 6 votes vote down vote up
/**
 * Tests readFrom()  method.
 */
@Test
public void testReadFrom() throws Exception {
    opqueHeader = new OpaqueLsaHeader();
    opqueHeader.setLsType(11);
    opqueHeader.setLsPacketLen(48);
    opqueHeader.setLsCheckSum(10);
    opqueHeader.setAge(4);
    opqueHeader.setOpaqueId(1);
    opqueHeader.setOpaqueType(11);
    opqueHeader.setLsSequenceNo(250);
    opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
    opqueHeader.setOptions(2);
    opaqueLsa11 = new OpaqueLsa11(opqueHeader);
    channelBuffer = ChannelBuffers.copiedBuffer(packet);
    opaqueLsa11.readFrom(channelBuffer);
    assertThat(opaqueLsa11, is(notNullValue()));
}
 
Example 10
Project: athena   File: OpaqueLsa10Test.java   View source code 6 votes vote down vote up
/**
 * Tests getLsaBodyAsByteArray() method.
 */
@Test(expected = Exception.class)
public void testGetLsaBodyAsByteArray2() throws Exception {
    opqueHeader = new OpaqueLsaHeader();
    opqueHeader.setLsType(10);
    opqueHeader.setLsPacketLen(48);
    opqueHeader.setLsCheckSum(10);
    opqueHeader.setAge(4);
    opqueHeader.setOpaqueId(1);
    opqueHeader.setOpaqueType(10);
    opqueHeader.setLsSequenceNo(250);
    opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165"));
    opqueHeader.setOptions(2);
    opaqueLsa10 = new OpaqueLsa10(opqueHeader);
    linkTlv = new LinkTlv(new TlvHeader());
    opaqueLsa10.addValue(linkTlv);
    channelBuffer = ChannelBuffers.copiedBuffer(packet);
    opaqueLsa10.readFrom(channelBuffer);
    result = opaqueLsa10.getLsaBodyAsByteArray();
    assertThat(result, is(notNullValue()));
}
 
Example 11
Project: athena   File: BgpOpenMsgTest.java   View source code 6 votes vote down vote up
/**
 * In this test case, Invalid version is given as input and expecting
 * an exception.
 */
@Test(expected = BgpParseException.class)
public void openMessageTest5() throws BgpParseException {

    // OPEN Message with invalid version number.
    byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, 0x00, 0x1d, 0x01, 0X05,
            (byte) 0xfe, 0x09, 0x00, (byte) 0xb4,
            (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f,
            0x00};

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

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();
    message = reader.readFrom(buffer, bgpHeader);

    assertThat(message, instanceOf(BgpOpenMsg.class));
}
 
Example 12
Project: athena   File: IpExtendedReachabilityTlvTest.java   View source code 6 votes vote down vote up
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(tlv);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
    channelBuffer = ChannelBuffers.copiedBuffer(tlv1);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
    channelBuffer = ChannelBuffers.copiedBuffer(tlv2);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
    channelBuffer = ChannelBuffers.copiedBuffer(tlv3);
    ipExtendedReachabilityTlv.readFrom(channelBuffer);
    assertThat(ipExtendedReachabilityTlv.metric(), is(0));
}
 
Example 13
Project: athena   File: ExternalLsaTest.java   View source code 6 votes vote down vote up
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    ospfExternalDestination = new OspfExternalDestination();
    ospfExternalDestination.setExternalRouterTag(2);
    ospfExternalDestination.setMetric(100);
    ospfExternalDestination.setType1orType2Metric(true);
    externalLsa.addExternalDestination(ospfExternalDestination);
    ospfExternalDestination1 = new OspfExternalDestination();
    ospfExternalDestination.setExternalRouterTag(3);
    ospfExternalDestination.setMetric(50);
    ospfExternalDestination.setType1orType2Metric(true);
    externalLsa.addExternalDestination(ospfExternalDestination1);
    ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
    inputByteArray = createByteForNetworkLsa();
    lsaHeader = createLsaHeader();
    externalLsa = new ExternalLsa(lsaHeader);
    channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
    externalLsa.readFrom(channelBuffer);
    assertThat(externalLsa, is(notNullValue()));
}
 
Example 14
Project: traccar-service   File: EelinkProtocolEncoder.java   View source code 6 votes vote down vote up
private ChannelBuffer encodeContent(String content) {

        ChannelBuffer buf = ChannelBuffers.dynamicBuffer();

        buf.writeByte(0x67);
        buf.writeByte(0x67);
        buf.writeByte(EelinkProtocolDecoder.MSG_DOWNLINK);
        buf.writeShort(2 + 1 + 4 + content.length()); // length
        buf.writeShort(0); // index

        buf.writeByte(0x01); // command
        buf.writeInt(0); // server id
        buf.writeBytes(content.getBytes(StandardCharsets.UTF_8));

        return buf;
    }
 
Example 15
Project: athena   File: PcepUpdateMsgExtTest.java   View source code 5 votes vote down vote up
/**
 * This test case is for SRP object, LSP object(StatefulLspDbVerTlv), ERO object,LSPA
 * metric object in PcepUpdate message.
 */
@Test
public void pcepUpdateMsgTest17() throws PcepParseException, PcepOutOfBoundMessageException {
    byte[] updateMsg = new byte[] {0x20, 0x0b, 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,
            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 16
Project: athena   File: PcepInitiateMsgExtTest.java   View source code 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 17
Project: athena   File: PcepReportMsgTest.java   View source code 5 votes vote down vote up
/**
 * 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 18
Project: athena   File: PcepInitiateMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv)
 * objects in PcInitiate message.
 */
@Test
public void initiateMessageTest14() throws PcepParseException, PcepOutOfBoundMessageException {

    /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv).
     */
    byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x34,
            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, 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};

    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 19
Project: athena   File: OspfUtilTest.java   View source code 5 votes vote down vote up
/**
 * Tests readLsaHeader() method.
 */
@Test
public void testReadLsaHeader() throws Exception {
    byte[] header = {0, 10, 2, 1, 7, 7, 7, 7, 7, 7, 7, 7, -128, 0, 0, 2, 46, -126, 0,
            48, 0, 0, 0, 2, 1, 1, 1, 1, 10, 10, 10, 7, 1, 0, 0, 10, 10, 10, 10, 0, -1, -1, -1,
            0, 3, 0, 0, 10, 0, 10, 66, 10, 1, 0, 0, 1, 7, 7, 7, 7, -128, 0, 0, 1, -64, 79, 0,
            116, 0, 1, 0, 4, 0, 0, 0, 0, 0, 2, 0, 84, 0, 1, 0, 1, 1, 0, 0, 0, 0, 2, 0, 4, 10,
            10, 10, 0, 0, 5, 0, 4, 0, 0, 0, 0, 0, 6, 0, 4, 73, -104, -106, -128, 0, 7, 0, 4, 73,
            -104, -106, -128, 0, 8, 0, 32, 73, -104, -106, -128, 73, -104, -106, -128, 73, -104, -106,
            -128, 73, -104, -106, -128, 73, -104, -106, -128, 73, -104, -106, -128, 73, -104, -106, -128,
            73, -104, -106, -128, 0, 9, 0, 4, 0, 0, 0, 0};
    channelBuffer = ChannelBuffers.copiedBuffer(header);
    lsaHeader = OspfUtil.readLsaHeader(channelBuffer);
    assertThat(lsaHeader, is(notNullValue()));
}
 
Example 20
Project: athena   File: MetricOfInternalReachabilityTest.java   View source code 5 votes vote down vote up
/**
 * Tests asBytes() method.
 */
@Test
public void testAsBytes() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(internalReachability);
    reachability.readFrom(channelBuffer);
    result3 = reachability.asBytes();
    assertThat(result3, is(notNullValue()));
}
 
Example 21
Project: athena   File: BgpUpdateMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks update message with withdrawn routes.
 */
@Test
public void bgpUpdateMessageTest05() throws BgpParseException {
    byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
            (byte) 0xff, (byte) 0xff, 0x00, 0x1b, 0x02, 0x00, 0x04, 0x18, 0x0a, 0x01, 0x01, 0x00, 0x00};

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

    BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader();
    BgpMessage message;
    BgpHeader bgpHeader = new BgpHeader();

    message = reader.readFrom(buffer, bgpHeader);

    assertThat(message, instanceOf(BgpUpdateMsg.class));
    BgpUpdateMsg other = (BgpUpdateMsg) message;

    assertThat(other.getHeader().getMarker(), is(MARKER));
    assertThat(other.getHeader().getType(), is(UPDATE_MSG_TYPE));
    assertThat(other.getHeader().getLength(), is((short) 27));

    ListIterator<IpPrefix> listIterator1 = other.withdrawnRoutes().listIterator();
    byte[] prefix = new byte[] {0x0a, 0x01, 0x01, 0x00};

    IpPrefix testPrefixValue = listIterator1.next();
    assertThat(testPrefixValue.prefixLength(), is((int) 24));
    assertThat(testPrefixValue.address().toOctets(), is(prefix));
}
 
Example 22
Project: athena   File: HostNameTlvTest.java   View source code 5 votes vote down vote up
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(tlv);
    hostNameTlv.readFrom(channelBuffer);
    assertThat(hostNameTlv.hostName(), is(hostName));
}
 
Example 23
Project: athena   File: SummaryLsaTest.java   View source code 5 votes vote down vote up
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    inputByteArray = createByteForNetworkLsa();
    lsaHeader = createLsaHeader();
    summaryLsa = new SummaryLsa(lsaHeader);
    channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
    summaryLsa.readFrom(channelBuffer);
    assertThat(summaryLsa, is(notNullValue()));
}
 
Example 24
Project: athena   File: PcepUpdateMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv),
 * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest23() 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, //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 25
Project: athena   File: PcepUpdateMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv,
 * StatefulLspErrorCodeTlv), ERO (IPv4SubObject) objects in PcUpd message.
 */
@Test
public void pcepUpdateMsgTest8() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x50,
            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, 0x0c, 0x01, 0x08, 0x11, 0x01, //ERO object
            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 26
Project: athena   File: IsisNeighborTlvTest.java   View source code 5 votes vote down vote up
/**
 * Tests asBytes() getter method.
 */
@Test
public void testAsBytes() throws Exception {
    channelBuffer = ChannelBuffers.copiedBuffer(tlv);
    isisNeighborTlv.readFrom(channelBuffer);
    result = isisNeighborTlv.asBytes();
    assertThat(result, is(notNullValue()));
}
 
Example 27
Project: athena   File: PcepInitiateMsgExtTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv),
 * END-POINTS, ERO, LSPA OBJECT objects in PcInitiate message.
 */
@Test
public void initiateMessageTest29() throws PcepParseException, PcepOutOfBoundMessageException {

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

    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 28
Project: flume-release-1.7.0   File: TestSyslogUtils.java   View source code 5 votes vote down vote up
@Test
public void testGoodEventBadEvent() {
  String badData1 = "hi guys! <10F> bad bad data\n";
  String priority = "<10>";
  String goodData1 = "Good good good data\n";
  SyslogUtils util = new SyslogUtils(false);
  ChannelBuffer buff = ChannelBuffers.buffer(100);
  buff.writeBytes((priority + goodData1).getBytes());
  buff.writeBytes(badData1.getBytes());

  Event e2 = util.extractEvent(buff);
  if (e2 == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers2 = e2.getHeaders();
  Assert.assertEquals("1", headers2.get(SyslogUtils.SYSLOG_FACILITY));
  Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
  Assert.assertEquals(null,
                      headers2.get(SyslogUtils.EVENT_STATUS));
  Assert.assertEquals(priority + goodData1.trim(),
                      new String(e2.getBody()).trim());

  Event e = util.extractEvent(buff);

  if (e == null) {
    throw new NullPointerException("Event is null");
  }
  Map<String, String> headers = e.getHeaders();
  Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
  Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
  Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
                      headers.get(SyslogUtils.EVENT_STATUS));
  Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
 
Example 29
Project: athena   File: PcepErrorMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks for
 * LS Object, PCEP-ERROR Object
 * in PcepErrorMsg message.
 */
@Test
public void errorMessageTest11() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x1C, // common header
            (byte) 0xE0, 0x13, 0x00, 0x10, // LS Object Header
            0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // LS-ID
            0x00, 0x00, 0x00, 0x10,
            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 30
Project: athena   File: MaximumReservableBandwidthTest.java   View source code 5 votes vote down vote up
/**
 * Tests readFrom() method.
 */
@Test
public void testReadFrom() throws Exception {
    header = new TlvHeader();
    header.setTlvType(6);
    header.setTlvLength(4);
    channelBuffer = ChannelBuffers.copiedBuffer(packet);
    maximumReservableBandwidth = new MaximumReservableBandwidth(header);
    maximumReservableBandwidth.readFrom(channelBuffer);
    assertThat(maximumReservableBandwidth, is(notNullValue()));
}
 
Example 31
Project: Elasticsearch   File: ESHttpResponseEncoder.java   View source code 5 votes vote down vote up
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    Object retVal = super.encode(ctx, channel, msg);
    if (retVal instanceof CompositeChannelBuffer) {
        CompositeChannelBuffer ccb = (CompositeChannelBuffer) retVal;
        if (ccb.useGathering() != NettyUtils.DEFAULT_GATHERING) {
            List<ChannelBuffer> decompose = ccb.decompose(ccb.readerIndex(), ccb.readableBytes());
            return ChannelBuffers.wrappedBuffer(NettyUtils.DEFAULT_GATHERING,
                    decompose.toArray(new ChannelBuffer[decompose.size()]));
        }
    }
    return retVal;
}
 
Example 32
Project: opentsdb-rpc-kafka   File: KafkaHttpRpcPlugin.java   View source code 5 votes vote down vote up
/**
 * Handles printing stats per namespace. Aggregated stats are included with 
 * the main tsdb /api/stats call. Users can filter by namespace if they want. 
 * @param query The HTTP query to parse and respond to.
 */
private void handlePerNamespaceStats(final HttpRpcPluginQuery query) {
  synchronized (tsdb) {
    if (KafkaRpcPlugin.KAFKA_RPC_REFERENCE == null) {
      throw new BadRequestException(HttpResponseStatus.CONFLICT, 
          "Consumers have not started yet");
    }
    
    final String filter = query.getQueryStringParam("namespace");
    final Map<String, Map<String, AtomicLong>> counters = 
        KafkaRpcPlugin.KAFKA_RPC_REFERENCE.getNamespaceCounters();
    final long ts = System.currentTimeMillis() / 1000;
    
    // TSD format for ingest
    final List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (final Entry<String, Map<String, AtomicLong>> counter : 
      counters.entrySet()) {
      
      for (final Entry<String, AtomicLong> metric : counter.getValue().entrySet()) {
        if (filter != null && !filter.isEmpty() && 
            !filter.toLowerCase().equals(metric.getKey().toLowerCase())) {
          continue;
        }
        
        final Map<String, Object> entry = new HashMap<String, Object>(4);
        entry.put("metric", "KafkaRpcPlugin.perNamespace." + counter.getKey());
        entry.put("timestamp", ts);
        entry.put("value", metric.getValue().get());
        final Map<String, String> tags = new HashMap<String, String>(2);
        tags.put("host", KafkaRpcPlugin.KAFKA_RPC_REFERENCE.getHost());
        tags.put("namespace", metric.getKey());
        entry.put("tags", tags);
        results.add(entry);
      }
    }
    query.sendBuffer(HttpResponseStatus.OK,
        ChannelBuffers.wrappedBuffer(JSON.serializeToBytes(results)),
        "application/json");
  }
}
 
Example 33
Project: hadoop   File: RpcProgram.java   View source code 5 votes vote down vote up
protected static void sendRejectedReply(RpcCall call,
    SocketAddress remoteAddress, ChannelHandlerContext ctx) {
  XDR out = new XDR();
  RpcDeniedReply reply = new RpcDeniedReply(call.getXid(),
      RpcReply.ReplyState.MSG_DENIED,
      RpcDeniedReply.RejectState.AUTH_ERROR, new VerifierNone());
  reply.write(out);
  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap()
      .buffer());
  RpcResponse rsp = new RpcResponse(buf, remoteAddress);
  RpcUtil.sendRpcResponse(ctx, rsp);
}
 
Example 34
Project: https-github.com-apache-zookeeper   File: ClientCnxnSocketNetty.java   View source code 5 votes vote down vote up
private void sendPkt(Packet p) {
    // Assuming the packet will be sent out successfully. Because if it fails,
    // the channel will close and clean up queues.
    p.createBB();
    updateLastSend();
    sentCount++;
    channel.write(ChannelBuffers.wrappedBuffer(p.bb));
}
 
Example 35
Project: hadoop   File: RpcUtil.java   View source code 5 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
    ChannelBuffer buf) {

  if (buf.readableBytes() < 4)
    return null;

  buf.markReaderIndex();

  byte[] fragmentHeader = new byte[4];
  buf.readBytes(fragmentHeader);
  int length = XDR.fragmentSize(fragmentHeader);
  boolean isLast = XDR.isLastFragment(fragmentHeader);

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

  ChannelBuffer newFragment = buf.readSlice(length);
  if (currentFrame == null) {
    currentFrame = newFragment;
  } else {
    currentFrame = ChannelBuffers.wrappedBuffer(currentFrame, newFragment);
  }

  if (isLast) {
    ChannelBuffer completeFrame = currentFrame;
    currentFrame = null;
    return completeFrame;
  } else {
    return null;
  }
}
 
Example 36
Project: athena   File: NetworkLsaTest.java   View source code 5 votes vote down vote up
/**
 * Tests readFrom() method.
 */
@Test(expected = Exception.class)
public void testReadFrom1() throws Exception {
    byte[] temp = {0, 0, 0};
    inputByteArray = temp;
    lsaHeader = createLsaHeader();
    networkLsa = new NetworkLsa(lsaHeader);
    channelBuffer = ChannelBuffers.copiedBuffer(inputByteArray);
    networkLsa.readFrom(channelBuffer);
    assertThat(networkLsa, is(notNullValue()));
}
 
Example 37
Project: athena   File: PcepLSReportMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks for  LS Object (Routing Universe TLV)
 * in PcLSRpt message.
 */
@Test
public void lsReportMessageTest3() throws PcepParseException, PcepOutOfBoundMessageException {

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

    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 38
Project: traccar-service   File: ObdDongleProtocolDecoder.java   View source code 5 votes vote down vote up
private static void sendResponse(Channel channel, int type, int index, String imei, ChannelBuffer content) {
    if (channel != null) {
        ChannelBuffer response = ChannelBuffers.dynamicBuffer();
        response.writeShort(0x5555); // header
        response.writeShort(index);
        response.writeBytes(imei.getBytes(StandardCharsets.US_ASCII));
        response.writeByte(type);
        response.writeShort(content.readableBytes());
        response.writeBytes(content);
        response.writeByte(0); // checksum
        response.writeShort(0xAAAA);
        channel.write(response);
    }
}
 
Example 39
Project: astrobee_android   File: MainActivity.java   View source code 5 votes vote down vote up
@SuppressWarnings("unused")
protected final void onNewData(final ByteBuffer data) {
    if (!mExposureSet) {
        mUiHandler.post(new Runnable() {
            @Override
            public void run() {
                if (mExposureSet)
                    return;
                setExposure();
                mExposureSet = true;
            }
        });
    }

    if (mPublisher == null)
        return;
    if (!mPublisher.hasSubscribers())
        return;

    data.order(ByteOrder.nativeOrder());
    data.rewind();

    if (mChannelBuffer == null) {
        mChannelBuffer = ChannelBuffers.wrappedBuffer(data);
    }

    mChannelBuffer.setIndex(0, mChannelBuffer.capacity());

    mCloud.getHeader().setStamp(mConnectedNode.getCurrentTime());
    mCloud.getHeader().setSeq(mSeqNum.incrementAndGet());
    mCloud.setData(mChannelBuffer);

    mPublisher.publish(mCloud);
}
 
Example 40
Project: athena   File: PcepOpenMsgTest.java   View source code 5 votes vote down vote up
/**
 * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV
 * with I bit set in Pcep Open message.
 */
@Test
public void openMessageTest6() throws PcepParseException, PcepOutOfBoundMessageException {

    byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit 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));

}