org.jboss.netty.buffer.ChannelBuffers Java Examples
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffers.
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: BgpUpdateMsgTest.java From onos with Apache License 2.0 | 6 votes |
/** * In this test case, Invalid message type is given as input and expecting * an exception. */ @Test(expected = BgpParseException.class) public void bgpUpdateMessageTest04() 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, 0x17, 0x06, 0x00, 0x00, 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)); }
Example #2
Source File: BasicFactoryTest.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
public void testCreateAndParse() throws MessageParseException { BasicFactory factory = BasicFactory.getInstance(); OFMessage m = factory.getMessage(OFType.HELLO); m.setVersion((byte) 1); m.setType(OFType.ECHO_REQUEST); m.setLength(U16.t(8)); m.setXid(0xdeadbeef); ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); ChannelBuffer bb2 = ChannelBuffers.dynamicBuffer(); m.writeTo(bb); bb2.writeBytes(bb, bb.readableBytes()-1); TestCase.assertNull(factory.parseMessage(bb2)); bb2.writeByte(bb.readByte()); List<OFMessage> message = factory.parseMessage(bb2); TestCase.assertNotNull(message); TestCase.assertEquals(message.size(), 1); TestCase.assertTrue(message.get(0).getType() == OFType.ECHO_REQUEST); }
Example #3
Source File: OpaqueLsa9Test.java From onos with Apache License 2.0 | 6 votes |
/** * Tests readFrom() method. */ @Test public void testReadFrom() throws Exception { opqueHeader = new OpaqueLsaHeader(); opqueHeader.setLsType(1); opqueHeader.setLsPacketLen(48); opqueHeader.setLsCheckSum(10); opqueHeader.setAge(4); opqueHeader.setOpaqueId(9); opqueHeader.setOpaqueType(9); opqueHeader.setLsSequenceNo(250); opqueHeader.setAdvertisingRouter(Ip4Address.valueOf("100.226.165.165")); opqueHeader.setOptions(2); opaqueLsa9 = new OpaqueLsa9(opqueHeader); channelBuffer = ChannelBuffers.copiedBuffer(packet); opaqueLsa9.readFrom(channelBuffer); assertThat(opaqueLsa9, is(notNullValue())); }
Example #4
Source File: TaskMessage.java From jstorm with Apache License 2.0 | 6 votes |
/** * create a buffer containing the encoding of this batch */ @Override public ChannelBuffer buffer() throws Exception { int payloadLen = 0; if (_message != null) payloadLen = _message.length; int totalLen = 8 + payloadLen; ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(totalLen)); bout.writeShort(_type); if (_task > Short.MAX_VALUE) throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE); bout.writeShort((short) _task); bout.writeInt(payloadLen); if (payloadLen > 0) bout.write(_message); bout.close(); return bout.buffer(); }
Example #5
Source File: EventClient.java From hadoop-arch-book with Apache License 2.0 | 6 votes |
public Action submitUserEvent(UserEvent userEvent) throws Exception { Channel channel = channelStateEvent.getChannel(); if (channel.isWritable()) { String json = userEvent.getJSONObject().toString(); ChannelBuffer m = ChannelBuffers.wrappedBuffer(Bytes.toBytes(json)); LOG.info("EventClient:sending " + json); channel.write(m); } else { throw new RuntimeException("Channel is not writable"); } synchronized (this) { long startTime = System.currentTimeMillis(); LOG.info("-- EventClient:Waiting for response " + startTime); this.wait(); LOG.info("-- EventClient:Got response " + (System.currentTimeMillis() - startTime)); } LOG.info("EventClient:action " + action.alert); return action; }
Example #6
Source File: TestDelegationTokenRemoteFetcher.java From hadoop with Apache License 2.0 | 6 votes |
@Override public void handle(Channel channel, Token<DelegationTokenIdentifier> token, String serviceUrl) throws IOException { Assert.assertEquals(testToken, token); Credentials creds = new Credentials(); creds.addToken(new Text(serviceUrl), token); DataOutputBuffer out = new DataOutputBuffer(); creds.write(out); int fileLength = out.getData().length; ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength); cbuffer.writeBytes(out.getData()); HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(fileLength)); response.setContent(cbuffer); channel.write(response).addListener(ChannelFutureListener.CLOSE); }
Example #7
Source File: MemcachedBinaryResponseEncoder.java From fqueue with Apache License 2.0 | 6 votes |
public ChannelBuffer constructHeader(MemcachedBinaryCommandDecoder.BinaryCommand bcmd, ChannelBuffer extrasBuffer, ChannelBuffer keyBuffer, ChannelBuffer valueBuffer, short responseCode, int opaqueValue, long casUnique) { // take the ResponseMessage and turn it into a binary payload. ChannelBuffer header = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 24); header.writeByte((byte)0x81); // magic header.writeByte(bcmd.code); // opcode short keyLength = (short) (keyBuffer != null ? keyBuffer.capacity() :0); header.writeShort(keyLength); int extrasLength = extrasBuffer != null ? extrasBuffer.capacity() : 0; header.writeByte((byte) extrasLength); // extra length = flags + expiry header.writeByte((byte)0); // data type unused header.writeShort(responseCode); // status code int dataLength = valueBuffer != null ? valueBuffer.capacity() : 0; header.writeInt(dataLength + keyLength + extrasLength); // data length header.writeInt(opaqueValue); // opaque header.writeLong(casUnique); return header; }
Example #8
Source File: IsisMessageReaderTest.java From onos with Apache License 2.0 | 6 votes |
/** * Tests readFromBuffer() method. */ @Test public void testReadFromBuffer() throws Exception { channelBuffer = ChannelBuffers.copiedBuffer(helloP2P); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(P2PHelloPdu.class))); channelBuffer = ChannelBuffers.copiedBuffer(helloL1L2); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(L1L2HelloPdu.class))); byte[] tlv1 = Bytes.concat(l1Lsp, (IsisUtil.getPaddingTlvs(l1Lsp.length))); channelBuffer = ChannelBuffers.copiedBuffer(tlv1); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(LsPdu.class))); tlv1 = Bytes.concat(csnp, (IsisUtil.getPaddingTlvs(csnp.length))); channelBuffer = ChannelBuffers.copiedBuffer(tlv1); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(Csnp.class))); tlv1 = Bytes.concat(psnp, (IsisUtil.getPaddingTlvs(psnp.length))); channelBuffer = ChannelBuffers.copiedBuffer(tlv1); message = reader.readFromBuffer(channelBuffer); assertThat(message, is(instanceOf(Psnp.class))); }
Example #9
Source File: BgpUpdateMsg2Test.java From onos with Apache License 2.0 | 6 votes |
/** * This test case checks the changes made in. * LinkStateAttributes (For Link State Attribute Type 1173 i.e. Extended Administrative Group) * as bug fix for bug 8036 */ @Test public void bgpUpdateMessage2Test4() 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, (byte) 0x01, (byte) 0x19, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x90, (byte) 0x0e, (byte) 0x00, (byte) 0x6e, (byte) 0x40, (byte) 0x04, (byte) 0x47, (byte) 0x10, (byte) 0x20, (byte) 0x01, (byte) 0x05, (byte) 0xb0, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x54, (byte) 0x00, (byte) 0xff, (byte) 0xfe, (byte) 0xb8, (byte) 0x35, (byte) 0x2b, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x55, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xe9, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2b, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1b, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0xd5, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0x70, (byte) 0x70, (byte) 0x70, (byte) 0xd4, (byte) 0x40, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x40, (byte) 0x05, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x64, (byte) 0x80, (byte) 0x1d, (byte) 0x7f, (byte) 0x04, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc0, (byte) 0xa8, (byte) 0x07, (byte) 0xca, (byte) 0x04, (byte) 0x06, (byte) 0x00, (byte) 0x04, (byte) 0xc0, (byte) 0xa8, (byte) 0x07, (byte) 0xc9, (byte) 0x04, (byte) 0x40, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x41, (byte) 0x00, (byte) 0x04, (byte) 0x49, (byte) 0xb7, (byte) 0x1b, (byte) 0x00, (byte) 0x04, (byte) 0x42, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x43, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x44, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, (byte) 0x04, (byte) 0x47, (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a, //------------ BGP-LS ATTR_EXTNDED_ADMNSTRATIVE_GRP Attribute------------------------------------------ (byte) 0x04, (byte) 0x95, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 //----------------------------------------------------------------------------------------------------- }; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(updateMsg); BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); BgpMessage message = null; BgpHeader bgpHeader = new BgpHeader(); message = reader.readFrom(buffer, bgpHeader); assertThat(message, instanceOf(BgpUpdateMsg.class)); BgpUpdateMsg receivedMsg = (BgpUpdateMsg) message; List<BgpValueType> pathAttr = receivedMsg.bgpPathAttributes().pathAttributes(); ListIterator<BgpValueType> iterator = pathAttr.listIterator(); while (iterator.hasNext()) { BgpValueType attr = iterator.next(); if (attr instanceof LinkStateAttributes) { assertThat(((LinkStateAttributes) attr).linkStateAttributes().size(), is(9)); } } }
Example #10
Source File: TestSyslogUtils.java From mt-flume with Apache License 2.0 | 6 votes |
public void checkHeader(String msg1, String stamp1, String format1, String host1, String data1) throws ParseException { SyslogUtils util = new SyslogUtils(false); ChannelBuffer buff = ChannelBuffers.buffer(200); buff.writeBytes(msg1.getBytes()); Event e = util.extractEvent(buff); if(e == null){ throw new NullPointerException("Event is null"); } Map<String, String> headers2 = e.getHeaders(); if (stamp1 == null) { Assert.assertFalse(headers2.containsKey("timestamp")); } else { SimpleDateFormat formater = new SimpleDateFormat(format1); Assert.assertEquals(String.valueOf(formater.parse(stamp1).getTime()), headers2.get("timestamp")); } if (host1 == null) { Assert.assertFalse(headers2.containsKey("host")); } else { String host2 = headers2.get("host"); Assert.assertEquals(host2,host1); } Assert.assertEquals(data1, new String(e.getBody())); }
Example #11
Source File: OFActionTunnelDstIPTest.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
private void testAll(OFActionTunnelDstIP tip) { assertEquals(OFActionType.VENDOR, tip.getType()); assertEquals(2, tip.getSubtype()); assertEquals(16, tip.getLength()); assertEquals(0x005c16c7, tip.getVendor()); tip.setTunnelDstIP(24); assertEquals(24, tip.getTunnelDstIP()); // Test wire format int ip = IPv4.toIPv4Address("17.33.49.65"); tip.setTunnelDstIP(ip); ChannelBuffer buf = ChannelBuffers.buffer(32); tip.writeTo(buf); ChannelBuffer buf2 = buf.copy(); assertEquals(16, buf.readableBytes()); byte fromBuffer[] = new byte[16]; buf.readBytes(fromBuffer); assertArrayEquals(expectedWireFormat1, fromBuffer); OFActionTunnelDstIP act2 = new OFActionTunnelDstIP(); act2.readFrom(buf2); assertEquals(tip, act2); }
Example #12
Source File: PcepReportMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv) * ERO Object * in PcRpt message. */ @Test public void reportMessageTest27() throws PcepParseException, PcepOutOfBoundMessageException { byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x44, 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv 0x07, 0x10, 0x00, 0x14, //ERO Object 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; byte[] testReportMsg = {0}; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(reportMsg); PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); PcepMessage message = null; message = reader.readFrom(buffer); assertThat(message, instanceOf(PcepReportMsg.class)); ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); message.writeTo(buf); int readLen = buf.writerIndex(); testReportMsg = new byte[readLen]; buf.readBytes(testReportMsg, 0, readLen); assertThat(testReportMsg, is(reportMsg)); }
Example #13
Source File: BgpUpdateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * In this test case, Invalid AFI is given as input and expecting * an exception. */ @Test(expected = BgpParseException.class) public void bgpUpdateMessageTest16() 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, 0x60, 0x02, 0x00, 0x00, //withdrawn len 0x00, 0x49, //path attribute len (byte) 0xff, 0x01, 0x01, 0x00, //origin 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med (byte) 0x80, 0x0e, 0x34, 0x40, 0x06, 0x47, //mpreach with safi = 71 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop 0x00, //reserved 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; 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 #14
Source File: PcepUpdateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * 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 #15
Source File: Message.java From usergrid with Apache License 2.0 | 5 votes |
public ChannelBuffer encode( ChannelBuffer buffer ) { if ( buffer == null ) { buffer = ChannelBuffers.buffer( ByteOrder.LITTLE_ENDIAN, messageLength ); } buffer.writeInt( messageLength ); buffer.writeInt( requestID ); buffer.writeInt( responseTo ); buffer.writeInt( opCode ); return buffer; }
Example #16
Source File: PcepReportMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for SRP Object,LSP Object, ERO Object,RRO Object * in PcRpt message. */ @Test public void reportMessageTest12() throws PcepParseException, PcepOutOfBoundMessageException { byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x60, 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, 0x1f, 0x04, 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 #17
Source File: IsisNeighborTlvTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests readFrom() method. */ @Test public void testReadFrom() throws Exception { channelBuffer = ChannelBuffers.copiedBuffer(tlv); isisNeighborTlv.readFrom(channelBuffer); assertThat(isisNeighborTlv.neighbor().size(), is(1)); }
Example #18
Source File: ShuffleHandler.java From big-c with Apache License 2.0 | 5 votes |
protected void sendError(ChannelHandlerContext ctx, String message, HttpResponseStatus status) { HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status); response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8"); // Put shuffle version into http header response.setHeader(ShuffleHeader.HTTP_HEADER_NAME, ShuffleHeader.DEFAULT_HTTP_HEADER_NAME); response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION, ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION); response.setContent( ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8)); // Close the connection as soon as the error message is sent. ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE); }
Example #19
Source File: NettyTransport.java From Elasticsearch with Apache License 2.0 | 5 votes |
protected void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { if (!lifecycle.started()) { // ignore return; } if (isCloseConnectionException(e.getCause())) { logger.trace("close connection exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel()); // close the channel, which will cause a node to be disconnected if relevant ctx.getChannel().close(); disconnectFromNodeChannel(ctx.getChannel(), e.getCause()); } else if (isConnectException(e.getCause())) { logger.trace("connect exception caught on transport layer [{}]", e.getCause(), ctx.getChannel()); // close the channel as safe measure, which will cause a node to be disconnected if relevant ctx.getChannel().close(); disconnectFromNodeChannel(ctx.getChannel(), e.getCause()); } else if (e.getCause() instanceof CancelledKeyException) { logger.trace("cancelled key exception caught on transport layer [{}], disconnecting from relevant node", e.getCause(), ctx.getChannel()); // close the channel as safe measure, which will cause a node to be disconnected if relevant ctx.getChannel().close(); disconnectFromNodeChannel(ctx.getChannel(), e.getCause()); } else if (e.getCause() instanceof SizeHeaderFrameDecoder.HttpOnTransportException) { // in case we are able to return data, serialize the exception content and sent it back to the client if (ctx.getChannel().isOpen()) { ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(e.getCause().getMessage().getBytes(Charsets.UTF_8)); ChannelFuture channelFuture = ctx.getChannel().write(buffer); channelFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { future.getChannel().close(); } }); } } else { logger.warn("exception caught on transport layer [{}], closing connection", e.getCause(), ctx.getChannel()); // close the channel, which will cause a node to be disconnected if relevant ctx.getChannel().close(); disconnectFromNodeChannel(ctx.getChannel(), e.getCause()); } }
Example #20
Source File: PcepUpdateMsgExtTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case is for SRP object, LSP object(StatefulLspErrorCodeTlv), ERO object,bandwidth object * Metric object in PcepUpdate message. */ @Test public void pcepUpdateMsgTest4() throws PcepParseException, PcepOutOfBoundMessageException { byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object 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 #21
Source File: PcepLabelUpdateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for * <pce-label-map> SRP, LABEL, FEC Object. * in PcepLabelUpdate message. */ @Test public void labelUpdateMessageTest3() throws PcepParseException, PcepOutOfBoundMessageException { byte[] labelUpdate = new byte[]{0x20, (byte) 0xE2, 0x00, 0x24, // common header 0x21, 0x10, 0x00, 0x0C, // SRP Object Header 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, (byte) 0xE1, 0x10, 0x00, 0x0C, // LABEL Object Header 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, (byte) 0xE2, 0x10, 0x00, 0x08, // FEC Object Header 0x0A, 0x0A, 0x0B, 0x0B}; 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 #22
Source File: PcepOpenMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV * with P & I bits set and invalid session id in Pcep Open message. */ @Test public void openMessageTest9() throws PcepParseException, PcepOutOfBoundMessageException { byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set 0x20, 0x1e, 0x78, 0x00, //invalid sessionID 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 #23
Source File: PcepInitiateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, StatefulRsvpErrorSpecTlv) * objects in PcInitiate message. */ @Test public void initiateMessageTest10() throws PcepParseException, PcepOutOfBoundMessageException { /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, StatefulRsvpErrorSpecTlv). */ byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x44, 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, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08 //StatefulLspErrorCodeTlv }; 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 #24
Source File: DefaultIsisInterfaceTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests processCsnPduMessage() method. */ @Test(expected = Exception.class) public void testProcessCsnPduMessage() throws Exception { ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); csnp = new Csnp(isisHeader); csnp.readFrom(channelBuffer); csnp.setSourceMac(macAddress1); csnp.setIsisPduType(IsisPduType.L2CSNP.value()); isisMessage = csnp; defaultIsisInterface.processIsisMessage(isisMessage, isisLsdb, channel); assertThat(defaultIsisInterface, is(notNullValue())); }
Example #25
Source File: CsnpTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests readFrom() method. */ @Test public void testReadFrom() throws Exception { channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); csnp.readFrom(channelBuffer); assertThat(csnp, is(notNullValue())); }
Example #26
Source File: OspfInterfaceChannelHandlerTest.java From onos with Apache License 2.0 | 5 votes |
/** * Utility for test method. */ private DdPacket createDdPacket() throws OspfParseException { byte[] ddPacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126}; DdPacket ddPacket1 = new DdPacket(); ChannelBuffer buf = ChannelBuffers.buffer(ddPacket.length); buf.writeBytes(ddPacket); ddPacket1.readFrom(buf); return ddPacket1; }
Example #27
Source File: PcepReportMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for SRP Object, LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv * StatefulLspErrorCodeTlv) ERO Object, IRO object * in PcRpt message. */ @Test public void reportMessageTest5() throws PcepParseException, PcepOutOfBoundMessageException { byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x50, 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object //LSP Object 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv 0x07, 0x10, 0x00, 0x14, //ERO Object 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; byte[] testReportMsg = {0}; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(reportMsg); PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); PcepMessage message = null; message = reader.readFrom(buffer); assertThat(message, instanceOf(PcepReportMsg.class)); ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); message.writeTo(buf); int readLen = buf.writerIndex(); testReportMsg = new byte[readLen]; buf.readBytes(testReportMsg, 0, readLen); assertThat(testReportMsg, is(reportMsg)); }
Example #28
Source File: AdministrativeGroupTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests readFrom() method. */ @Test public void testReadFrom() throws Exception { tlvHeader = new TlvHeader(); tlvHeader.setTlvType(9); tlvHeader.setTlvLength(4); administrativeGroup = new AdministrativeGroup(tlvHeader); channelBuffer = ChannelBuffers.copiedBuffer(packet); administrativeGroup.readFrom(channelBuffer); assertThat(administrativeGroup.administrativeGroup(), is(notNullValue())); }
Example #29
Source File: CsnpTest.java From onos with Apache License 2.0 | 5 votes |
/** * Tests completeSequenceNumberPduBody() method. */ @Test public void testCompleteSequenceNumberPduBody() throws Exception { channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); csnp.readFrom(channelBuffer); result = csnp.completeSequenceNumberPduBody(); assertThat(result, is(notNullValue())); }
Example #30
Source File: OFPortConfigTest.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
public void testWriteRead() throws Exception { OFPortMod msg = (OFPortMod) messageFactory .getMessage(OFType.PORT_MOD); msg.setHardwareAddress(new byte[6]); msg.portNumber = 1; ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); bb.clear(); msg.writeTo(bb); msg.readFrom(bb); TestCase.assertEquals(OFType.PORT_MOD, msg.getType()); TestCase.assertEquals(1, msg.getPortNumber()); }