List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:org.opendaylight.protocol.bgp.labeled.unicast.BgpPrefixSidTlvsTest.java
License:Open Source License
@Test public void testOriginatorParser() { final OriginatorSrgbTlvParser parser = new OriginatorSrgbTlvParser(); final List<SrgbValue> list = new ArrayList<SrgbValue>(); final Srgb srgb1 = new Srgb(1L); final Srgb srgb2 = new Srgb(2L); list.add(new SrgbValueBuilder().setBase(srgb1).setRange(srgb2).build()); list.add(new SrgbValueBuilder().setBase(srgb2).setRange(srgb1).build()); final LuOriginatorSrgbTlv tlv = new LuOriginatorSrgbTlvBuilder().setSrgbValue(list).build(); final ByteBuf serialized = Unpooled.buffer(14); parser.serializeBgpPrefixSidTlv(tlv, serialized); final byte[] expected = new byte[] { 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 2, 0, 0, 1 }; assertArrayEquals(expected, serialized.array()); final LuOriginatorSrgbTlv parsed = parser.parseBgpPrefixSidTlv(serialized); assertEquals(tlv.getSrgbValue().size(), parsed.getSrgbValue().size()); assertTrue(tlv.getSrgbValue().get(0).getBase().equals(srgb1)); assertTrue(tlv.getSrgbValue().get(0).getRange().equals(srgb2)); assertTrue(tlv.getSrgbValue().get(1).getBase().equals(srgb2)); assertTrue(tlv.getSrgbValue().get(1).getRange().equals(srgb1)); assertEquals(3, parser.getType());// ww w . j av a 2s. c om }
From source file:org.opendaylight.protocol.bgp.parser.impl.AddPathCapabilityHandlerTest.java
License:Open Source License
@Test public void testCapabilityHandler() throws BGPDocumentedException, BGPParsingException { final List<AddressFamilies> family = new ArrayList<AddressFamilies>(); family.add(new AddressFamiliesBuilder().setAfi(this.afi).setSafi(this.safi) .setSendReceive(SendReceive.forValue(1)).build()); final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder() .setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(family).build()) .build())//from w ww .ja va2 s.c om .build(); final ByteBuf bytes = Unpooled.buffer(6); final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, this.safiRegistry); handler.serializeCapability(capabilityToSerialize, bytes); assertArrayEquals(this.serializedBytes, bytes.array()); final CParameters newCaps = handler.parseCapability(this.parseCorrectBytes); assertEquals(capabilityToSerialize.hashCode(), newCaps.hashCode()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.BgpExtendedMessageCapabilityHandlerTest.java
License:Open Source License
@Test public void testBgpExtendedMessageCapabilityHandler() throws BGPDocumentedException, BGPParsingException { final BgpExtendedMessageCapabilityHandler handler = new BgpExtendedMessageCapabilityHandler(); final byte[] bgpExeBytes = { (byte) 0x06, (byte) 0x00 }; final ByteBuf buffer = Unpooled.buffer(bgpExeBytes.length); handler.serializeCapability(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY, buffer); Assert.assertArrayEquals(bgpExeBytes, buffer.array()); Assert.assertEquals(handler.parseCapability(Unpooled.wrappedBuffer(bgpExeBytes)), BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY); final byte[] bgpExeBytes2 = { (byte) 0x40, (byte) 0x06 }; buffer.clear();/*w w w .java 2 s . c o m*/ handler.serializeCapability(BgpExtendedMessageUtil.EXTENDED_MESSAGE_CAPABILITY, buffer); Assert.assertNotSame(bgpExeBytes2, buffer.array()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.GracefulCapabilityHandlerTest.java
License:Open Source License
@Test public void testGracefulCapabilityHandler() throws BGPDocumentedException, BGPParsingException { final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(), this.ctx.getSubsequentAddressFamilyRegistry()); final byte[] capaBytes = { (byte) 0x40, (byte) 0x06, (byte) 0x81, (byte) 0xf4, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x80 }; final GracefulRestartCapabilityBuilder capaBuilder = new GracefulRestartCapabilityBuilder(); capaBuilder.setRestartFlags(new RestartFlags(true)); capaBuilder.setRestartTime(500);/*from w w w .j av a 2 s. co m*/ final TablesBuilder tablesBuilder = new TablesBuilder(); tablesBuilder.setAfiFlags(new AfiFlags(true)); tablesBuilder.setAfi(Ipv4AddressFamily.class); tablesBuilder.setSafi(UnicastSubsequentAddressFamily.class); capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build())); final ByteBuf buffer = Unpooled.buffer(capaBytes.length); handler.serializeCapability(new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), buffer); Assert.assertArrayEquals(capaBytes, buffer.array()); Assert.assertEquals( new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), handler.parseCapability(Unpooled.wrappedBuffer(capaBytes).slice(2, capaBytes.length - 2))); final byte[] capaBytes2 = { (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00 }; capaBuilder.setRestartFlags(new RestartFlags(false)); capaBuilder.setRestartTime(0); tablesBuilder.setAfiFlags(new AfiFlags(false)); capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build())); buffer.clear(); handler.serializeCapability(new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), buffer); Assert.assertArrayEquals(capaBytes2, buffer.array()); Assert.assertEquals( new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), handler.parseCapability(Unpooled.wrappedBuffer(capaBytes2).slice(2, capaBytes2.length - 2))); capaBuilder.setRestartFlags(null); tablesBuilder.setAfiFlags(null); capaBuilder.setRestartTime(null); capaBuilder.setTables(Lists.newArrayList(tablesBuilder.build())); buffer.clear(); handler.serializeCapability(new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), buffer); Assert.assertArrayEquals(capaBytes2, buffer.array()); final byte[] capaBytes3 = { (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; capaBuilder.setRestartFlags(new RestartFlags(false)); capaBuilder.setRestartTime(0); capaBuilder.setTables(Collections.<Tables>emptyList()); Assert.assertEquals( new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), handler.parseCapability(Unpooled.wrappedBuffer(capaBytes3).slice(2, capaBytes3.length - 2))); final byte[] capaBytes4 = { (byte) 0x40, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00 }; Assert.assertEquals( new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()) .build(), handler.parseCapability(Unpooled.wrappedBuffer(capaBytes4).slice(2, capaBytes4.length - 2))); final byte[] capaBytes5 = { (byte) 0x40, (byte) 0x02, (byte) 0x00, (byte) 0x00 }; final ByteBuf b = Unpooled.buffer(capaBytes5.length); handler.serializeCapability(new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder() .setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().build()).build()) .build(), b); Assert.assertArrayEquals(capaBytes5, b.array()); Assert.assertEquals( new CParametersBuilder() .addAugmentation(CParameters1.class, new CParameters1Builder() .setGracefulRestartCapability(new GracefulRestartCapabilityBuilder() .setRestartFlags(new RestartFlags(Boolean.FALSE)).setRestartTime(0) .setTables(Collections.<Tables>emptyList()).build()) .build()) .build(), handler.parseCapability(Unpooled.wrappedBuffer(capaBytes5).slice(2, capaBytes5.length - 2))); }
From source file:org.opendaylight.protocol.bgp.parser.impl.Ipv4NlriParserTest.java
License:Open Source License
@Test public void serializeAttributeTest() throws UnsupportedEncodingException { final ByteBuf outputBytes = Unpooled.buffer(); this.parser.serializeAttribute(this.nlri, outputBytes); assertArrayEquals(this.inputBytes.array(), outputBytes.array()); this.parser.serializeAttribute(this.nlriWrong, outputBytes); assertFalse(Arrays.equals(this.inputBytes.array(), outputBytes.array())); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.AsTwoOctetSpecificEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final AsTwoOctetSpecificEcHandler handler = new AsTwoOctetSpecificEcHandler(); final AsSpecificExtendedCommunityCase expected = new AsSpecificExtendedCommunityCaseBuilder() .setAsSpecificExtendedCommunity( new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(54L)) .setLocalAdministrator(new byte[] { 0, 0, 1, 76 }).build()) .build();//from ww w .j a va 2 s.c o m final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT)); Assert.assertEquals(expected, exComm); final ByteBuf output = Unpooled.buffer(INPUT.length); handler.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(INPUT, output.array()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.Generic4OctASEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final As4GenericSpecExtendedCommunityCase expected = new As4GenericSpecExtendedCommunityCaseBuilder() .setAs4GenericSpecExtendedCommunity( new As4GenericSpecExtendedCommunityBuilder().setAs4SpecificCommon(AS_COMMON).build()) .build();/*from w w w . ja v a2s . c om*/ final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT)); Assert.assertEquals(expected, exComm); final ByteBuf output = Unpooled.buffer(INPUT.length); this.handler.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(INPUT, output.array()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteOrigin4OctectASEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final As4RouteOriginExtendedCommunityCase expected = new As4RouteOriginExtendedCommunityCaseBuilder() .setAs4RouteOriginExtendedCommunity( new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(AS_COMMON).build()) .build();//from w w w . ja va2 s .c o m final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT)); Assert.assertEquals(expected, exComm); final ByteBuf output = Unpooled.buffer(INPUT.length); this.handler.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(INPUT, output.array()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.four.octect.as.specific.RouteTarget4OctectASEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final As4RouteTargetExtendedCommunityCase expected = new As4RouteTargetExtendedCommunityCaseBuilder() .setAs4RouteTargetExtendedCommunity( new As4RouteTargetExtendedCommunityBuilder().setAs4SpecificCommon(AS_COMMON).build()) .build();/*from ww w. j av a2s . c om*/ final ExtendedCommunity exComm = this.handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT)); Assert.assertEquals(expected, exComm); final ByteBuf output = Unpooled.buffer(INPUT.length); this.handler.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(INPUT, output.array()); }
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.Ipv4SpecificEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final Ipv4SpecificEcHandler handler = new Ipv4SpecificEcHandler(); final Inet4SpecificExtendedCommunityCase expected = new Inet4SpecificExtendedCommunityCaseBuilder() .setInet4SpecificExtendedCommunity(new Inet4SpecificExtendedCommunityBuilder() .setGlobalAdministrator(new Ipv4Address("12.51.2.5")) .setLocalAdministrator(new byte[] { 21, 45 }).build()) .build();//from w w w. j a v a 2 s.c o m final ExtendedCommunity exComm = handler.parseExtendedCommunity(Unpooled.copiedBuffer(INPUT)); Assert.assertEquals(expected, exComm); final ByteBuf output = Unpooled.buffer(INPUT.length); handler.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(INPUT, output.array()); }