Search in sources :

Example 6 with RestartFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags 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)

Example 7 with RestartFlags

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags in project bgpcep by opendaylight.

the class GracefulCapabilityHandler method parseCapability.

@Override
public CParameters parseCapability(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException {
    final GracefulRestartCapabilityBuilder cb = new GracefulRestartCapabilityBuilder();
    final int flagBits = (buffer.getByte(0) >> RESTART_FLAGS_SIZE);
    cb.setRestartFlags(new RestartFlags((flagBits & Byte.SIZE) != 0));
    final int timer = ((buffer.readUnsignedByte() & TIMER_TOPBITS_MASK) << Byte.SIZE) + buffer.readUnsignedByte();
    cb.setRestartTime(timer);
    final List<Tables> tables = new ArrayList<>();
    while (buffer.readableBytes() != 0) {
        final int afiVal = buffer.readShort();
        final Class<? extends AddressFamily> afi = this.afiReg.classForFamily(afiVal);
        if (afi == null) {
            LOG.debug("Ignoring GR capability for unknown address family {}", afiVal);
            buffer.skipBytes(PER_AFI_SAFI_SIZE - 2);
            continue;
        }
        final int safiVal = buffer.readUnsignedByte();
        final Class<? extends SubsequentAddressFamily> safi = this.safiReg.classForFamily(safiVal);
        if (safi == null) {
            LOG.debug("Ignoring GR capability for unknown subsequent address family {}", safiVal);
            buffer.skipBytes(1);
            continue;
        }
        final int flags = buffer.readUnsignedByte();
        tables.add(new TablesBuilder().setAfi(afi).setSafi(safi).setAfiFlags(new AfiFlags((flags & AFI_FLAG_FORWARDING_STATE) != 0)).build());
    }
    cb.setTables(tables);
    return new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(cb.build()).build()).build();
}
Also used : RestartFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags) AfiFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables.AfiFlags) ArrayList(java.util.ArrayList) CParameters1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1) TablesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.TablesBuilder) CParametersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder) CParameters1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables) GracefulRestartCapabilityBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder)

Aggregations

CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)7 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder)7 RestartFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability.RestartFlags)7 GracefulRestartCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapabilityBuilder)7 TablesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.TablesBuilder)7 Test (org.junit.Test)6 AfiFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables.AfiFlags)6 ByteBuf (io.netty.buffer.ByteBuf)5 GracefulCapabilityHandler (org.opendaylight.protocol.bgp.parser.impl.message.open.GracefulCapabilityHandler)5 ArrayList (java.util.ArrayList)2 CParameters1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1)2 Tables (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.graceful.restart.capability.Tables)2 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)1 CParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters)1 As4BytesCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder)1 GracefulRestartCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.GracefulRestartCapability)1 MultiprotocolCapability (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapability)1 MultiprotocolCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.MultiprotocolCapabilityBuilder)1 Ipv4AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily)1 Ipv6AddressFamily (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily)1