List of usage examples for io.netty.buffer ByteBuf array
public abstract byte[] array();
From source file:org.opendaylight.protocol.bgp.parser.impl.message.update.extended.communities.OpaqueEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final OpaqueEcHandler handler = new OpaqueEcHandler(); final OpaqueExtendedCommunityCase expected = new OpaqueExtendedCommunityCaseBuilder() .setOpaqueExtendedCommunity( new OpaqueExtendedCommunityBuilder().setValue(new byte[] { 21, 45, 5, 4, 3, 1 }).build()) .build();/*from ww w .j a va2 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.RouteOriginAsTwoOctetEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final RouteOriginAsTwoOctetEcHandler handler = new RouteOriginAsTwoOctetEcHandler(); final RouteOriginExtendedCommunityCase expected = new RouteOriginExtendedCommunityCaseBuilder() .setRouteOriginExtendedCommunity( new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(24L)) .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build()) .build();/*from ww w . j a va 2s .c om*/ 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.RouteOriginIpv4EcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final RouteOriginIpv4EcHandler handler = new RouteOriginIpv4EcHandler(); final RouteOriginIpv4Case expected = new RouteOriginIpv4CaseBuilder() .setRouteOriginIpv4(new RouteOriginIpv4Builder() .setGlobalAdministrator(new Ipv4Address("12.51.2.5")).setLocalAdministrator(5421).build()) .build();//www . jav a 2s .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.RouteTargetAsTwoOctetEcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final RouteTargetAsTwoOctetEcHandler handler = new RouteTargetAsTwoOctetEcHandler(); final RouteTargetExtendedCommunityCase expected = new RouteTargetExtendedCommunityCaseBuilder() .setRouteTargetExtendedCommunity( new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(new ShortAsNumber(35L)) .setLocalAdministrator(new byte[] { 4, 2, 8, 7 }).build()) .build();/* w w w. j a v a 2s .co 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.RouteTargetIpv4EcHandlerTest.java
License:Open Source License
@Test public void testHandler() throws BGPDocumentedException, BGPParsingException { final RouteTargetIpv4EcHandler handler = new RouteTargetIpv4EcHandler(); final RouteTargetIpv4Case expected = new RouteTargetIpv4CaseBuilder() .setRouteTargetIpv4(new RouteTargetIpv4Builder() .setGlobalAdministrator(new Ipv4Address("12.51.2.5")).setLocalAdministrator(5421).build()) .build();/*from w w w . j a v a2s .co 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.ParserTest.java
License:Open Source License
@Test public void testNotificationMsg() throws BGPParsingException, BGPDocumentedException { Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()) .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }) .build();//from w w w . j a v a2s. com final ByteBuf bytes = Unpooled.buffer(); ParserTest.reg.serializeMessage(notMsg, bytes); assertArrayEquals(notificationBMsg, ByteArray.subByte(bytes.array(), 0, bytes.writerIndex())); Notification m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes)); assertTrue(m instanceof Notify); assertEquals(BGPError.OPT_PARAM_NOT_SUPPORTED, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode())); assertArrayEquals(new byte[] { 4, 9 }, ((Notify) m).getData()); notMsg = new NotifyBuilder().setErrorCode(BGPError.CONNECTION_NOT_SYNC.getCode()) .setErrorSubcode(BGPError.CONNECTION_NOT_SYNC.getSubcode()).build(); bytes.clear(); ParserTest.reg.serializeMessage(notMsg, bytes); m = ParserTest.reg.parseMessage(Unpooled.copiedBuffer(bytes)); assertTrue(m instanceof Notify); assertEquals(BGPError.CONNECTION_NOT_SYNC, BGPError.forValue(((Notify) m).getErrorCode(), ((Notify) m).getErrorSubcode())); assertNull(((Notify) m).getData()); }
From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleRegistryTest.java
License:Open Source License
@Test public void testMpReachParser() throws BGPParsingException { final NlriRegistry nlriReg = this.ctx.getNlriRegistry(); final byte[] mpReachBytes = { 0x00, 0x01, 0x01, 0x04, 0x7f, 0x00, 0x00, 0x01, 0x00 }; final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class) .setSafi(UnicastSubsequentAddressFamily.class) .setCNextHop(new Ipv4NextHopCaseBuilder() .setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.0.0.1")).build()) .build())/*from w w w .j a va 2s. c o m*/ .build(); final ByteBuf buffer = Unpooled.buffer(mpReachBytes.length); nlriReg.serializeMpReach(mpReach, buffer); assertArrayEquals(mpReachBytes, buffer.array()); assertEquals(mpReach, nlriReg.parseMpReach(Unpooled.wrappedBuffer(mpReachBytes), CONSTRAINT)); verify(this.activator.nlriParser, times(1)).parseNlri(Mockito.any(ByteBuf.class), Mockito.any(MpReachNlriBuilder.class), Mockito.any()); }
From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleRegistryTest.java
License:Open Source License
@Test public void testMpReachWithZeroNextHop() throws BGPParsingException { final NlriRegistry nlriReg = this.ctx.getNlriRegistry(); final byte[] mpReachBytes = { 0x00, 0x01, 0x01, 0x00, 0x00 }; final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class) .setSafi(UnicastSubsequentAddressFamily.class).build(); final ByteBuf buffer = Unpooled.buffer(mpReachBytes.length); nlriReg.serializeMpReach(mpReach, buffer); assertArrayEquals(mpReachBytes, buffer.array()); assertEquals(mpReach, nlriReg.parseMpReach(Unpooled.wrappedBuffer(mpReachBytes), CONSTRAINT)); }
From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleRegistryTest.java
License:Open Source License
@Test public void testMpReachIpv6() throws BGPParsingException { final NlriRegistry nlriReg = this.ctx.getNlriRegistry(); final byte[] mpReachBytes = { 0x00, 0x02, 0x01, 0x00, 0x00 }; final MpReachNlri mpReach = new MpReachNlriBuilder().setAfi(Ipv6AddressFamily.class) .setSafi(UnicastSubsequentAddressFamily.class).build(); final ByteBuf buffer = Unpooled.buffer(mpReachBytes.length); nlriReg.serializeMpReach(mpReach, buffer); assertArrayEquals(mpReachBytes, buffer.array()); assertEquals(mpReach, nlriReg.parseMpReach(Unpooled.wrappedBuffer(mpReachBytes), CONSTRAINT)); }
From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleRegistryTest.java
License:Open Source License
@Test public void testMpUnReachParser() throws BGPParsingException { final NlriRegistry nlriReg = this.ctx.getNlriRegistry(); final byte[] mpUnreachBytes = { 0x00, 0x01, 0x01 }; final MpUnreachNlri mpUnreach = new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class) .setSafi(UnicastSubsequentAddressFamily.class).build(); final ByteBuf buffer = Unpooled.buffer(mpUnreachBytes.length); nlriReg.serializeMpUnReach(mpUnreach, buffer); assertArrayEquals(mpUnreachBytes, buffer.array()); assertEquals(mpUnreach, nlriReg.parseMpUnreach(Unpooled.wrappedBuffer(mpUnreachBytes), CONSTRAINT)); verify(this.activator.nlriParser, times(1)).parseNlri(Mockito.any(ByteBuf.class), Mockito.any(MpUnreachNlriBuilder.class), Mockito.any()); }