use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables.AfiFlags in project bgpcep by opendaylight.
the class GracefulCapabilityHandlerTest method testUnhandledAfi.
@Test(expected = IllegalArgumentException.class)
public void testUnhandledAfi() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(), this.ctx.getSubsequentAddressFamilyRegistry());
final GracefulRestartCapabilityBuilder capaBuilder = new GracefulRestartCapabilityBuilder();
capaBuilder.setRestartFlags(new RestartFlags(true));
capaBuilder.setRestartTime(Uint16.valueOf(50));
final TablesBuilder tablesBuilder = new TablesBuilder();
tablesBuilder.setAfiFlags(new AfiFlags(true));
tablesBuilder.setAfi(AddressFamily.class);
tablesBuilder.setSafi(UnicastSubsequentAddressFamily.class);
capaBuilder.setTables(BindingMap.of(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer();
handler.serializeCapability(new CParametersBuilder().addAugmentation(new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables.AfiFlags in project bgpcep by opendaylight.
the class GracefulCapabilityHandlerTest method testUnhandledSafi.
@Test(expected = IllegalArgumentException.class)
public void testUnhandledSafi() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(), this.ctx.getSubsequentAddressFamilyRegistry());
final GracefulRestartCapabilityBuilder capaBuilder = new GracefulRestartCapabilityBuilder();
capaBuilder.setRestartFlags(new RestartFlags(true));
capaBuilder.setRestartTime(Uint16.valueOf(50));
final TablesBuilder tablesBuilder = new TablesBuilder();
tablesBuilder.setAfiFlags(new AfiFlags(true));
tablesBuilder.setAfi(Ipv4AddressFamily.class);
tablesBuilder.setSafi(SubsequentAddressFamily.class);
capaBuilder.setTables(BindingMap.of(tablesBuilder.build()));
final ByteBuf buffer = Unpooled.buffer();
handler.serializeCapability(new CParametersBuilder().addAugmentation(new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables.AfiFlags in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandlerTest method testLongLivedGracefulCapabilityHandler.
@Test
public void testLongLivedGracefulCapabilityHandler() throws BGPParsingException, BGPDocumentedException {
final byte[] capaBytes = { // header
(byte) 0x47, (byte) 0x0e, // Ipv4 Unicast, afiFlags = false, timer = 10
(byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // Ipv6 Unicast, afiFlags = true, timer = 160
(byte) 0x00, (byte) 0x02, (byte) 0x01, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0xa0 };
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder().setTables(BindingMap.ordered(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAfiFlags(new Tables.AfiFlags(Boolean.FALSE)).setLongLivedStaleTime(TEN).build(), new TablesBuilder().setAfi(Ipv6AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAfiFlags(new Tables.AfiFlags(Boolean.TRUE)).setLongLivedStaleTime(new Uint24(Uint32.valueOf(160))).build())).build();
final CParameters cParameters = new CParametersBuilder().addAugmentation(new CParameters1Builder().setLlGracefulRestartCapability(capability).build()).build();
final ByteBuf buffer = Unpooled.buffer(capaBytes.length);
this.handler.serializeCapability(cParameters, buffer);
assertArrayEquals(capaBytes, buffer.array());
assertEquals(cParameters, this.handler.parseCapability(Unpooled.wrappedBuffer(capaBytes).slice(2, capaBytes.length - 2)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables.AfiFlags in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandler method parseCapability.
@Override
public CParameters parseCapability(final ByteBuf buffer) {
final BindingMap.Builder<TablesKey, Tables> tables = BindingMap.builder();
while (buffer.isReadable()) {
final short 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_TABLE_SIZE - 2);
continue;
}
final byte safival = buffer.readByte();
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(PER_TABLE_SIZE - 3);
continue;
}
final byte afiFlags = buffer.readByte();
final int staleTime = buffer.readUnsignedMedium();
final Tables table = new TablesBuilder().setAfi(afi).setSafi(safi).setAfiFlags(new Tables.AfiFlags(afiFlags == AFI_FLAG_FORWARDING_STATE)).setLongLivedStaleTime(new Uint24(Uint32.valueOf(staleTime))).build();
tables.add(table);
}
return new CParametersBuilder().addAugmentation(new CParameters1Builder().setLlGracefulRestartCapability(new LlGracefulRestartCapabilityBuilder().setTables(tables.build()).build()).build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.graceful.restart.capability.Tables.AfiFlags 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(Uint16.valueOf(timer));
final BindingMap.Builder<TablesKey, Tables> tables = BindingMap.builder();
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.build());
return new CParametersBuilder().addAugmentation(new CParameters1Builder().setGracefulRestartCapability(cb.build()).build()).build();
}
Aggregations