use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.LlGracefulRestartCapabilityBuilder 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.LlGracefulRestartCapabilityBuilder 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.LlGracefulRestartCapabilityBuilder in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandlerTest method testRecvdUnsupportedSafi.
@Test
public void testRecvdUnsupportedSafi() {
final byte[] capaBytes = { // header
(byte) 0x47, (byte) 0x15, // Ipv4 Unicast, afiFlags = false, timer = 10
(byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0a, // Unsupported safi, afiFlags = true, timer = 160
(byte) 0x00, (byte) 0x01, (byte) 0x85, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0xa0, // Ipv6 Unicast afiFlags = false, 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();
LlGracefulCapabilityHandler handler1 = new LlGracefulCapabilityHandler(afir, safir);
assertEquals(cParameters, handler1.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.LlGracefulRestartCapabilityBuilder in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandlerTest method testUnsupportedAfi.
@Test(expected = IllegalArgumentException.class)
public void testUnsupportedAfi() {
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder().setTables(BindingMap.of(new TablesBuilder().setAfi(AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setAfiFlags(new Tables.AfiFlags(Boolean.FALSE)).setLongLivedStaleTime(TEN).build())).build();
final CParameters cParameters = new CParametersBuilder().addAugmentation(new CParameters1Builder().setLlGracefulRestartCapability(capability).build()).build();
final ByteBuf buffer = Unpooled.buffer();
this.handler.serializeCapability(cParameters, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.LlGracefulRestartCapabilityBuilder in project bgpcep by opendaylight.
the class LlGracefulCapabilityHandlerTest method testUnsupportedSafi.
@Test(expected = IllegalArgumentException.class)
public void testUnsupportedSafi() {
final LlGracefulRestartCapability capability = new LlGracefulRestartCapabilityBuilder().setTables(BindingMap.of(new TablesBuilder().setAfi(Ipv4AddressFamily.class).setSafi(SubsequentAddressFamily.class).setAfiFlags(new Tables.AfiFlags(Boolean.FALSE)).setLongLivedStaleTime(TEN).build())).build();
final CParameters cParameters = new CParametersBuilder().addAugmentation(new CParameters1Builder().setLlGracefulRestartCapability(capability).build()).build();
final ByteBuf buffer = Unpooled.buffer();
this.handler.serializeCapability(cParameters, buffer);
}
Aggregations