List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testMonitoringObject() throws PCEPDeserializerException { final byte[] monitoringBytes = { /* object header */ 0x13, 0x10, 0x00, 0x0C,/*from w ww . ja va2 s.co m*/ /* flags */ 0x00, 0x00, 0x00, 0x01, /* monitoring-id=16 */ 0x00, 0x00, 0x00, 0x10 }; final PCEPMonitoringObjectParser parser = new PCEPMonitoringObjectParser(this.tlvRegistry, this.viTlvRegistry); final Monitoring monitoring = new MonitoringBuilder().setMonitoringId(16L) .setFlags(new Flags(false, false, true, false, false)) .setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.monitoring.TlvsBuilder() .build()) .build(); final ByteBuf result = Unpooled.wrappedBuffer(monitoringBytes); assertEquals(monitoring, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(monitoringBytes.length); parser.serializeObject(monitoring, buf); assertArrayEquals(monitoringBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testPccIdReqIPv4Object() throws PCEPDeserializerException { final byte[] pccIdReqBytes = { /* object header */ 0x14, 0x10, 0x00, 0x08,// ww w.j a v a 2s . c om /* ipv4 address */ 0x7f, 0x00, 0x00, 0x01 }; final PCEPPccIdReqIPv4ObjectParser parser = new PCEPPccIdReqIPv4ObjectParser(); final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))) .build(); final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes); assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length); parser.serializeObject(pccIdReq, buf); assertArrayEquals(pccIdReqBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testPccIdReqIPv6Object() throws PCEPDeserializerException { final byte[] pccIdReqBytes = { /* object header */ 0x14, 0x20, 0x00, 0x14,//from w ww.j av a 2 s .com /* ipv6 address */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; final PCEPPccIdReqIPv6ObjectParser parser = new PCEPPccIdReqIPv6ObjectParser(); final PccIdReq pccIdReq = new PccIdReqBuilder().setIpAddress(new IpAddress(new Ipv6Address("::1"))).build(); final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes); assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length); parser.serializeObject(pccIdReq, buf); assertArrayEquals(pccIdReqBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testPceIdIPv4Object() throws PCEPDeserializerException { final byte[] pccIdReqBytes = { /* object header */ 0x19, 0x10, 0x00, 0x08,//from ww w .j a v a 2 s . com /* ipv4 address */ 0x7f, 0x00, 0x00, 0x01 }; final PCEPPceIdIPv4ObjectParser parser = new PCEPPceIdIPv4ObjectParser(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pceId = new PceIdBuilder() .setIpAddress(new IpAddress(new Ipv4Address("127.0.0.1"))).build(); final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes); assertEquals(pceId, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length); parser.serializeObject(pceId, buf); assertArrayEquals(pccIdReqBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testPceIdIPv6Object() throws PCEPDeserializerException { final byte[] pccIdReqBytes = { /* object header */ 0x19, 0x20, 0x00, 0x14,//from w w w.j a v a 2s. co m /* ipv6 header */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; final PCEPPceIdIPv6ObjectParser parser = new PCEPPceIdIPv6ObjectParser(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pce.id.object.PceId pccIdReq = new PceIdBuilder() .setIpAddress(new IpAddress(new Ipv6Address("::1"))).build(); final ByteBuf result = Unpooled.wrappedBuffer(pccIdReqBytes); assertEquals(pccIdReq, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(pccIdReqBytes.length); parser.serializeObject(pccIdReq, buf); assertArrayEquals(pccIdReqBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testProcTimeObject() throws PCEPDeserializerException { final byte[] proctimeBytes = { /* object header */ 0x1A, 0x10, 0x00, 0x1C,//w w w . j a v a2s . c o m /* E flag */ 0x00, 0x00, 0x00, 0x01, /* current proc. time */ 0x00, 0x00, 0x00, 0x01, /* min proc. time */ 0x00, 0x00, 0x00, 0x02, /* max proc time */ 0x00, 0x00, 0x00, 0x03, /* average proc time */ 0x00, 0x00, 0x00, 0x04, /* variance proc time */ 0x00, 0x00, 0x00, 0x05, }; final PCEPProcTimeObjectParser parser = new PCEPProcTimeObjectParser(); final ProcTime procTime = new ProcTimeBuilder().setEstimated(true).setAverageProcTime(4L) .setCurrentProcTime(1L).setMaxProcTime(3L).setMinProcTime(2L).setVarianceProcTime(5L).build(); final ByteBuf result = Unpooled.wrappedBuffer(proctimeBytes); assertEquals(procTime, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(proctimeBytes.length); parser.serializeObject(procTime, buf); assertArrayEquals(proctimeBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPObjectParserTest.java
License:Open Source License
@Test public void testOverloadObject() throws PCEPDeserializerException { final byte[] overloadBytes = { /* object header */ 0x1B, 0x10, 0x00, 0x08,//from w w w . j a v a 2 s. com /* overload duration */ 0x00, 0x00, 0x00, 0x78 }; final PCEPOverloadObjectParser parser = new PCEPOverloadObjectParser(); final Overload overload = new OverloadBuilder().setDuration(120).build(); final ByteBuf result = Unpooled.wrappedBuffer(overloadBytes); assertEquals(overload, parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(overloadBytes.length); parser.serializeObject(overload, buf); assertArrayEquals(overloadBytes, buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java
License:Open Source License
@Test public void testOpenMsg() throws IOException, PCEPDeserializerException { final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenMessage1.bin")); final PCEPOpenMessageParser parser = new PCEPOpenMessageParser(this.ctx.getObjectHandlerRegistry()); final OpenMessageBuilder builder = new OpenMessageBuilder(); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder b = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder(); b.setProcessingRule(false);/*from w w w. j a v a 2 s. c o m*/ b.setIgnore(false); b.setVersion(new ProtocolVersion((short) 1)); b.setKeepalive((short) 30); b.setDeadTimer((short) 120); b.setSessionId((short) 1); b.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder() .build()); builder.setOpen(b.build()); assertEquals(new OpenBuilder().setOpenMessage(builder.build()).build(), parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(new OpenBuilder().setOpenMessage(builder.build()).build(), buf); assertArrayEquals(result.array(), buf.array()); try { parser.serializeMessage(new OpenBuilder().setOpenMessage(new OpenMessageBuilder().build()).build(), null); fail(); } catch (final IllegalArgumentException e) { assertEquals("Open Object must be present in Open Message.", e.getMessage()); } }
From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java
License:Open Source License
@Test public void testKeepAliveMsg() throws IOException, PCEPDeserializerException { final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { 32, 2, 0, 4 }); final PCEPKeepAliveMessageParser parser = new PCEPKeepAliveMessageParser(this.objectRegistry); final KeepaliveBuilder builder = new KeepaliveBuilder() .setKeepaliveMessage(new KeepaliveMessageBuilder().build()); assertEquals(builder.build(),/*from w ww. j av a2s.c om*/ parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(builder.build(), buf); assertArrayEquals(result.array(), buf.array()); }
From source file:org.opendaylight.protocol.pcep.impl.PCEPValidatorTest.java
License:Open Source License
@Test public void testStartTLSMsg() throws Exception { final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { 32, 20, 0, 4 }); final PCEPStartTLSMessageParser parser = new PCEPStartTLSMessageParser(this.objectRegistry); final StarttlsBuilder builder = new StarttlsBuilder() .setStartTlsMessage(new StartTlsMessageBuilder().build()); assertEquals(builder.build(),/* w w w . j av a 2 s.c o m*/ parser.parseMessage(result.slice(4, result.readableBytes() - 4), Collections.<Message>emptyList())); final ByteBuf buf = Unpooled.buffer(result.readableBytes()); parser.serializeMessage(builder.build(), buf); assertArrayEquals(result.array(), buf.array()); }