List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:org.opendaylight.bgp.concepts.RouteDistinguisherUtilTest.java
License:Open Source License
@Test public void testAs2BRouteDistinguisher() { final RouteDistinguisher expected = createRouteDistinguisher(0, ADMIN, ASSIGNED_NUMBER); final RouteDistinguisher parsed = RouteDistinguisherUtil .parseRouteDistinguisher(Unpooled.copiedBuffer(AS_2B_BYTES)); assertEquals(expected.getRdTwoOctetAs(), parsed.getRdTwoOctetAs()); final ByteBuf byteAggregator = Unpooled.buffer(AS_2B_BYTES.length); RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator); assertArrayEquals(AS_2B_BYTES, byteAggregator.array()); assertEquals("0" + SEPARATOR + ADMIN + SEPARATOR + ASSIGNED_NUMBER, parsed.getRdTwoOctetAs().getValue()); }
From source file:org.opendaylight.bgp.concepts.RouteDistinguisherUtilTest.java
License:Open Source License
@Test public void testIpv4RouteDistinguisher() { final RouteDistinguisher expected = createRouteDistinguisher(1, IP_ADDRESS, IP_PORT); final RouteDistinguisher parsed = RouteDistinguisherUtil .parseRouteDistinguisher(Unpooled.copiedBuffer(IP_BYTES)); assertEquals(expected.getRdIpv4(), parsed.getRdIpv4()); final ByteBuf byteAggregator = Unpooled.buffer(IP_BYTES.length); RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator); assertArrayEquals(IP_BYTES, byteAggregator.array()); assertEquals(IP_ADDRESS + SEPARATOR + IP_PORT, parsed.getRdIpv4().getValue()); }
From source file:org.opendaylight.bgp.concepts.RouteDistinguisherUtilTest.java
License:Open Source License
@Test public void testAs4BRouteDistinguisher() { final RouteDistinguisher expected = createRouteDistinguisher(2, ADMIN, ASSIGNED_NUMBER); final RouteDistinguisher parsed = RouteDistinguisherUtil .parseRouteDistinguisher(Unpooled.copiedBuffer(AS_4B_BYTES)); assertEquals(expected.getRdAs(), parsed.getRdAs()); final ByteBuf byteAggregator = Unpooled.buffer(AS_4B_BYTES.length); RouteDistinguisherUtil.serializeRouteDistinquisher(expected, byteAggregator); assertArrayEquals(AS_4B_BYTES, byteAggregator.array()); assertEquals(ADMIN + SEPARATOR + ASSIGNED_NUMBER, parsed.getRdAs().getValue()); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.EOMFramingMechanismEncoderTest.java
License:Open Source License
@Test public void testEncode() throws Exception { final byte[] content = new byte[50]; final ByteBuf source = Unpooled.wrappedBuffer(content); final ByteBuf destination = Unpooled.buffer(); new EOMFramingMechanismEncoder().encode(null, source, destination); assertEquals(Unpooled.wrappedBuffer(source.array(), NetconfMessageConstants.END_OF_MESSAGE), destination); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXIHandlersTest.java
License:Open Source License
@Test public void testEncodeDecode() throws Exception { final ByteBuf buffer = Unpooled.buffer(); netconfMessageToEXIEncoder.encode(null, msg, buffer); final int exiLength = msgAsExi.length; // array from buffer is cca 256 n length, compare only subarray assertArrayEquals(msgAsExi, Arrays.copyOfRange(buffer.array(), 0, exiLength)); // assert all other bytes in buffer be 0 for (int i = exiLength; i < buffer.array().length; i++) { assertEquals((byte) 0, buffer.array()[i]); }/*from ww w. ja v a 2 s .com*/ final List<Object> out = Lists.newArrayList(); netconfEXIToMessageDecoder.decode(null, buffer, out); XMLUnit.compareXML(msg.getDocument(), ((NetconfMessage) out.get(0)).getDocument()); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfHelloMessageToXMLEncoderTest.java
License:Open Source License
@Test public void testEncode() throws Exception { final NetconfMessage msg = new NetconfHelloMessage( XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"), NetconfHelloMessageAdditionalHeader.fromString("[tomas;10.0.0.0:10000;tcp;client;]")); final ByteBuf destination = Unpooled.buffer(); new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, destination); final String encoded = new String(destination.array()); assertThat(encoded, containsString("[tomas;10.0.0.0:10000;tcp;client;]")); assertThat(encoded, containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>")); }
From source file:org.opendaylight.controller.netconf.nettyutil.handler.NetconfHelloMessageToXMLEncoderTest.java
License:Open Source License
@Test public void testEncodeNoHeader() throws Exception { final NetconfMessage msg = new NetconfHelloMessage( XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>")); final ByteBuf destination = Unpooled.buffer(); new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, destination); final String encoded = new String(destination.array()); assertThat(encoded, not(containsString("[tomas;10.0.0.0:10000;tcp;client;]"))); assertThat(encoded, containsString("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>")); }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.FSExtendedCommunitiesTest.java
License:Open Source License
@Test public void testTrafficRateSerializer() throws BGPDocumentedException, BGPParsingException { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCase trafficRate = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.route.attributes.extended.communities.extended.community.TrafficRateExtendedCommunityCaseBuilder() .setTrafficRateExtendedCommunity( new TrafficRateExtendedCommunityBuilder().setInformativeAs(new ShortAsNumber(72L)) .setLocalAdministrator(new Bandwidth(new byte[] { 0, 1, 2, 3 })).build()) .build();//from w w w . ja va2 s . co m final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficRate) .setTransitive(true).build(); final ByteBuf output = Unpooled.buffer(TRAFFIC_RATE.length); registry.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(TRAFFIC_RATE, output.array()); }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.FSExtendedCommunitiesTest.java
License:Open Source License
@Test public void testTrafficActionSerializer() throws BGPDocumentedException, BGPParsingException { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.route.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCase trafficAction = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.route.attributes.extended.communities.extended.community.TrafficActionExtendedCommunityCaseBuilder() .setTrafficActionExtendedCommunity( new TrafficActionExtendedCommunityBuilder().setSample(true).setTerminalAction(true).build()) .build();/*w w w. j a v a 2 s .co m*/ final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficAction) .setTransitive(true).build(); final ByteBuf output = Unpooled.buffer(TRAFFIC_ACTION.length); registry.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(TRAFFIC_ACTION, output.array()); }
From source file:org.opendaylight.protocol.bgp.flowspec.extended.communities.FSExtendedCommunitiesTest.java
License:Open Source License
@Test public void testTrafficMarkingSerializer() throws BGPDocumentedException, BGPParsingException { final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.route.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCase trafficMarking = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.bgp.rib.route.attributes.extended.communities.extended.community.TrafficMarkingExtendedCommunityCaseBuilder() .setTrafficMarkingExtendedCommunity(new TrafficMarkingExtendedCommunityBuilder() .setGlobalAdministrator(new Dscp((short) 63)).build()) .build();/* w ww.j av a2s. co m*/ final ExtendedCommunities expected = new ExtendedCommunitiesBuilder().setExtendedCommunity(trafficMarking) .setTransitive(true).build(); final ByteBuf output = Unpooled.buffer(TRAFFIC_MARKING.length); registry.serializeExtendedCommunity(expected, output); Assert.assertArrayEquals(TRAFFIC_MARKING, output.array()); }