List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:org.opendaylight.protocol.bgp.parser.spi.UtilsTest.java
License:Open Source License
@Test public void testMultiprotocolCapabilitiesUtil() throws BGPParsingException { final byte[] bytes = new byte[] { 0, 1, 0, 1 }; final ByteBuf bytesBuf = Unpooled.copiedBuffer(bytes); final BgpTableType parsedAfiSafi = MultiprotocolCapabilitiesUtil .parseMPAfiSafi(bytesBuf, this.afiReg, this.safiReg).get(); assertEquals(Ipv4AddressFamily.class, parsedAfiSafi.getAfi()); assertEquals(UnicastSubsequentAddressFamily.class, parsedAfiSafi.getSafi()); final ByteBuf serializedAfiSafi = Unpooled.buffer(4); MultiprotocolCapabilitiesUtil.serializeMPAfiSafi(this.afiReg, this.safiReg, Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, serializedAfiSafi); assertArrayEquals(bytes, serializedAfiSafi.array()); }
From source file:org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry.java
License:Open Source License
private static byte[] serializeAs4BytesCapability(final As4BytesCapability as4Capability) { final ByteBuf buffer = Unpooled .buffer(1 /*CODE*/ + 1 /*LENGTH*/ + Integer.SIZE / Byte.SIZE /*4 byte value*/); final As4CapabilityHandler serializer = new As4CapabilityHandler(); serializer.serializeCapability(new CParametersBuilder().setAs4BytesCapability(as4Capability).build(), buffer);//from ww w . j ava2 s .co m return buffer.array(); }
From source file:org.opendaylight.protocol.bmp.spi.parser.PeerDistinguisherUtilTest.java
License:Open Source License
@Test public void testPeerDistingisherType0() { final DistinguisherBuilder dBuilder = new DistinguisherBuilder(); dBuilder.setDistinguisherType(DistinguisherType.Type0); dBuilder.setDistinguisher(ASN + ":" + ISP_NUMBER_FOUR_BYTES); assertEquals(dBuilder.build(),//w ww . j av a 2s . c om PeerDistinguisherUtil.parsePeerDistingisher(Unpooled.wrappedBuffer(DISTINGUISHER_TYPE0))); final ByteBuf buffer = Unpooled.buffer(DISTINGUISHER_TYPE0.length); PeerDistinguisherUtil.serializePeerDistinguisher(dBuilder.build(), buffer); Assert.assertArrayEquals(DISTINGUISHER_TYPE0, buffer.array()); }
From source file:org.opendaylight.protocol.bmp.spi.parser.PeerDistinguisherUtilTest.java
License:Open Source License
@Test public void testPeerDistingisherType1() { final DistinguisherBuilder dBuilder = new DistinguisherBuilder(); dBuilder.setDistinguisherType(DistinguisherType.Type1); dBuilder.setDistinguisher(IPV4_ADDRESS + ":" + ISP_NUMBER); assertEquals(dBuilder.build(),//from www . j a v a2 s.c o m PeerDistinguisherUtil.parsePeerDistingisher(Unpooled.wrappedBuffer(DISTINGUISHER_TYPE1))); final ByteBuf buffer = Unpooled.buffer(DISTINGUISHER_TYPE1.length); PeerDistinguisherUtil.serializePeerDistinguisher(dBuilder.build(), buffer); Assert.assertArrayEquals(DISTINGUISHER_TYPE1, buffer.array()); }
From source file:org.opendaylight.protocol.bmp.spi.parser.PeerDistinguisherUtilTest.java
License:Open Source License
@Test public void testPeerDistingisherType2() { final DistinguisherBuilder dBuilder = new DistinguisherBuilder(); dBuilder.setDistinguisherType(DistinguisherType.Type2); dBuilder.setDistinguisher(ASN_FOUR_BYTES + ":" + ISP_NUMBER); assertEquals(dBuilder.build(),/* w w w . j a va2 s. c o m*/ PeerDistinguisherUtil.parsePeerDistingisher(Unpooled.wrappedBuffer(DISTINGUISHER_TYPE2))); final ByteBuf buffer = Unpooled.buffer(DISTINGUISHER_TYPE2.length); PeerDistinguisherUtil.serializePeerDistinguisher(dBuilder.build(), buffer); Assert.assertArrayEquals(DISTINGUISHER_TYPE2, buffer.array()); }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testOpenObjectWithTLV() throws PCEPDeserializerException, IOException { try (SyncOptimizationsActivator a = new SyncOptimizationsActivator()) { a.start(this.ctx); final SyncOptimizationsOpenObjectParser parser = new SyncOptimizationsOpenObjectParser( this.ctx.getTlvHandlerRegistry(), this.ctx.getVendorInformationTlvRegistry()); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPOpenObject1.bin")); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder(); builder.setProcessingRule(false); builder.setIgnore(false);/* www . j a v a2s. co m*/ builder.setVersion(new ProtocolVersion((short) 1)); builder.setKeepalive((short) 30); builder.setDeadTimer((short) 120); builder.setSessionId((short) 1); final Stateful tlv1 = new StatefulBuilder().setLspUpdateCapability(Boolean.TRUE) .addAugmentation(Stateful1.class, new Stateful1Builder().build()).build(); final Tlvs1Builder statBuilder = new Tlvs1Builder(); statBuilder.setStateful(tlv1); final Tlvs3Builder syncOptBuilder = new Tlvs3Builder(); syncOptBuilder.setLspDbVersion( new LspDbVersionBuilder().setLspDbVersionValue(new BigInteger(DB_VERSION)).build()); syncOptBuilder .setSpeakerEntityId(new SpeakerEntityIdBuilder().setSpeakerEntityIdValue(SPEAKER_ID).build()); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder() .addAugmentation(Tlvs1.class, statBuilder.build()) .addAugmentation(Tlvs3.class, syncOptBuilder.build()).build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testLspObjectWithTLV() throws IOException, PCEPDeserializerException { try (StatefulActivator a = new StatefulActivator(); SyncOptimizationsActivator a2 = new SyncOptimizationsActivator()) { a.start(this.ctx); a2.start(this.ctx); final SyncOptimizationsLspObjectParser parser = new SyncOptimizationsLspObjectParser( this.ctx.getTlvHandlerRegistry(), this.ctx.getVendorInformationTlvRegistry()); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspObject1WithTLV.bin")); final LspBuilder builder = new LspBuilder(); builder.setProcessingRule(true); builder.setIgnore(true);/*from w ww . j ava2 s .c o m*/ builder.setAdministrative(true); builder.setDelegate(false); builder.setRemove(true); builder.setSync(false); builder.addAugmentation(Lsp1.class, new Lsp1Builder().setCreate(false).build()); builder.setOperational(OperationalStatus.GoingDown); builder.setPlspId(new PlspId(0x12345L)); final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build(); final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName( "Med".getBytes())) .build(); final LspDbVersion lspDbVersion = new LspDbVersionBuilder() .setLspDbVersionValue(new BigInteger(DB_VERSION)).build(); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder() .setLspErrorCode(tlv1).setSymbolicPathName(tlv2) .addAugmentation( org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs1Builder() .setLspDbVersion(lspDbVersion).build()) .build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); } }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testStateful07LspObjectWithTlv() throws IOException, PCEPDeserializerException { final Stateful07LspObjectParser parser = new Stateful07LspObjectParser(this.tlvRegistry, this.viTlvRegistry); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspObject2WithTLV.bin")); final LspBuilder builder = new LspBuilder(); builder.setProcessingRule(true);//from w w w . j a v a 2s. co m builder.setIgnore(true); builder.setAdministrative(true); builder.setDelegate(false); builder.setRemove(true); builder.setSync(false); builder.setOperational(OperationalStatus.GoingDown); builder.setPlspId(new PlspId(0x12345L)); final LspErrorCode tlv1 = new LspErrorCodeBuilder().setErrorCode(627610883L).build(); final SymbolicPathName tlv2 = new SymbolicPathNameBuilder().setPathName( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName( "Med".getBytes())) .build(); final Ipv4Builder afi = new Ipv4Builder(); afi.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))); afi.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })))); afi.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }))); final LspIdentifiers tlv3 = new LspIdentifiersBuilder() .setAddressFamily(new Ipv4CaseBuilder().setIpv4(afi.build()).build()).setLspId(new LspId(65535L)) .setTunnelId(new TunnelId(4660)).build(); final RsvpErrorBuilder rsvpBuilder = new RsvpErrorBuilder(); rsvpBuilder.setNode(new IpAddress(Ipv4Util.addressForByteBuf( Unpooled.wrappedBuffer(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 })))); rsvpBuilder.setFlags( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.ErrorSpec.Flags( false, true)); rsvpBuilder.setCode((short) 146); rsvpBuilder.setValue(5634); final RsvpErrorSpec tlv4 = new RsvpErrorSpecBuilder() .setErrorType(new RsvpCaseBuilder().setRsvpError(rsvpBuilder.build()).build()).build(); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder() .setLspErrorCode(tlv1).setSymbolicPathName(tlv2).setLspIdentifiers(tlv3) .setRsvpErrorSpec(tlv4).build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testLspaObject() throws IOException, PCEPDeserializerException { final Stateful07LspaObjectParser parser = new Stateful07LspaObjectParser(this.tlvRegistry, this.viTlvRegistry); final LspaBuilder builder = new LspaBuilder(); final ByteBuf result = Unpooled .wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin")); final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName( new byte[] { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d, (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65 })) .build();/* w w w . j a v a 2 s . co m*/ builder.setIgnore(false); builder.setProcessingRule(false); builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L)); builder.setIncludeAny(new AttributeFilter(0x1A025CC7L)); builder.setIncludeAll(new AttributeFilter(0x2BB66532L)); builder.setHoldPriority((short) 0x02); builder.setSetupPriority((short) 0x03); builder.setLocalProtectionDesired(true); builder.setTlvs( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder() .addAugmentation(Tlvs2.class, new Tlvs2Builder().setSymbolicPathName(tlv).build()).build()); // Tlvs container does not contain toString final Object o = parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4)); assertEquals(tlv, ((Lspa) o).getTlvs().getAugmentation(Tlvs2.class).getSymbolicPathName()); // assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result, // 4))); final ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); }
From source file:org.opendaylight.protocol.pcep.ietf.PCEPObjectParserTest.java
License:Open Source License
@Test public void testSrpObject() throws IOException, PCEPDeserializerException { final CInitiated00SrpObjectParser parser = new CInitiated00SrpObjectParser(this.tlvRegistry, this.viTlvRegistry); final ByteBuf result = Unpooled.wrappedBuffer(new byte[] { (byte) 0x21, (byte) 0x10, (byte) 0x00, (byte) 0x0c, 0, 0, 0, (byte) 0x01, 0, 0, 0, (byte) 0x01 }); final SrpBuilder builder = new SrpBuilder(); builder.setProcessingRule(false);//from www . j a va2 s . com builder.setIgnore(false); builder.setOperationId(new SrpIdNumber(1L)); builder.addAugmentation(Srp1.class, new Srp1Builder().setRemove(true).build()); builder.setTlvs(new TlvsBuilder().build()); assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false), result.slice(4, result.readableBytes() - 4))); final ByteBuf buf = Unpooled.buffer(); parser.serializeObject(builder.build(), buf); assertArrayEquals(result.array(), ByteArray.getAllBytes(buf)); }