Search in sources :

Example 6 with GracefulCapabilityHandler

use of org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler in project bgpcep by opendaylight.

the class GracefulCapabilityHandlerTest method testGracefulCapabilityHandler.

@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);
    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.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.emptyList()).build()).build()).build(), handler.parseCapability(Unpooled.wrappedBuffer(capaBytes5).slice(2, capaBytes5.length - 2)));
}
Also used : RestartFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) AfiFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables.AfiFlags) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) GracefulCapabilityHandler(org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler) ByteBuf(io.netty.buffer.ByteBuf) GracefulRestartCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder) TablesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.TablesBuilder) Test(org.junit.Test)

Aggregations

GracefulCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler)6 ByteBuf (io.netty.buffer.ByteBuf)5 Test (org.junit.Test)5 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)5 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder)5 RestartFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags)5 GracefulRestartCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder)5 AfiFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables.AfiFlags)5 TablesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.TablesBuilder)5 AddPathCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.AddPathCapabilityHandler)1 As4CapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.As4CapabilityHandler)1 BgpExtendedMessageCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.BgpExtendedMessageCapabilityHandler)1 CapabilityParameterParser (org.opendaylight.protocol.bgp.parser.impl.message.open.CapabilityParameterParser)1 MultiProtocolCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.MultiProtocolCapabilityHandler)1 RouteRefreshCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.RouteRefreshCapabilityHandler)1 AddressFamilyRegistry (org.opendaylight.protocol.bgp.parser.spi.AddressFamilyRegistry)1 SubsequentAddressFamilyRegistry (org.opendaylight.protocol.bgp.parser.spi.SubsequentAddressFamilyRegistry)1 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)1 As4BytesCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapability)1 BgpExtendedMessageCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.BgpExtendedMessageCapability)1