use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder in project bgpcep by opendaylight.
the class GracefulCapabilityHandlerTest method testRestartTimeMinValue.
@Test(expected = IllegalArgumentException.class)
public void testRestartTimeMinValue() {
final GracefulCapabilityHandler handler = new GracefulCapabilityHandler(this.ctx.getAddressFamilyRegistry(), this.ctx.getSubsequentAddressFamilyRegistry());
final GracefulRestartCapabilityBuilder capaBuilder = new GracefulRestartCapabilityBuilder();
capaBuilder.setRestartFlags(new RestartFlags(true));
capaBuilder.setRestartTime(-1);
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();
handler.serializeCapability(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setGracefulRestartCapability(capaBuilder.build()).build()).build(), buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder 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)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder in project bgpcep by opendaylight.
the class MultiProtocolCapabilityHandlerTest method noSerializationTest.
@Test
public void noSerializationTest() {
final CParameters capabilityNoAugmentation = new CParametersBuilder().addAugmentation(CParameters1.class, null).build();
final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().build()).build();
final ByteBuf bytes = Unpooled.buffer();
final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir, this.safirException);
handler.serializeCapability(capabilityNoAugmentation, bytes);
assertEquals(0, bytes.readableBytes());
handler.serializeCapability(capabilityNoMP, bytes);
assertEquals(0, bytes.readableBytes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder in project bgpcep by opendaylight.
the class MultiProtocolCapabilityHandlerTest method testCapabilityHandler.
@Test
public void testCapabilityHandler() throws BGPDocumentedException, BGPParsingException {
final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI).setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir, this.safir);
handler.serializeCapability(capabilityToSerialize, bytes);
final CParameters newCaps = handler.parseCapability(bytes);
assertEquals(capabilityToSerialize.hashCode(), newCaps.hashCode());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder in project bgpcep by opendaylight.
the class MultiProtocolCapabilityHandlerTest method testUnhandledSafi.
@Test(expected = IllegalArgumentException.class)
public void testUnhandledSafi() {
final CParameters capabilityToSerialize = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(MultiProtocolCapabilityHandlerTest.AFI).setSafi(MultiProtocolCapabilityHandlerTest.SAFI).build()).build()).build();
final ByteBuf bytes = Unpooled.buffer();
final MultiProtocolCapabilityHandler handler = new MultiProtocolCapabilityHandler(this.afir, this.safirException);
handler.serializeCapability(capabilityToSerialize, bytes);
}
Aggregations