use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters 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.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters 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.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters 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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class RouteRefreshCapabilityHandlerTest method testRRCapHandler.
@Test
public void testRRCapHandler() throws BGPDocumentedException, BGPParsingException {
final CParameters expectedParams = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setRouteRefreshCapability(new RouteRefreshCapabilityBuilder().build()).build()).build();
assertEquals(expectedParams, HANDLER.parseCapability(Unpooled.copiedBuffer(OK_BYTES)));
assertEquals(expectedParams, HANDLER.parseCapability(Unpooled.copiedBuffer(WRONG_BYTES)));
final ByteBuf byteAggregator = Unpooled.buffer(2);
HANDLER.serializeCapability(expectedParams, byteAggregator);
assertEquals(Unpooled.copiedBuffer(CAP_BYTES), byteAggregator);
final CParameters missingCap = new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setRouteRefreshCapability(null).build()).build();
final ByteBuf byteAggregator2 = Unpooled.buffer(0);
HANDLER.serializeCapability(missingCap, byteAggregator2);
assertEquals(Unpooled.copiedBuffer(new byte[] {}), byteAggregator2);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class CapabilityParameterParser method serializeOptionalCapability.
private void serializeOptionalCapability(final OptionalCapabilities optionalCapa, final ByteBuf byteAggregator) {
if (optionalCapa.getCParameters() != null) {
final CParameters cap = optionalCapa.getCParameters();
final ByteBuf bytes = Unpooled.buffer();
this.reg.serializeCapability(cap, bytes);
Preconditions.checkArgument(bytes != null, "Unhandled capability class %s", cap.getImplementedInterface());
if (LOG.isTraceEnabled()) {
LOG.trace("BGP capability serialized to: {}", ByteBufUtil.hexDump(bytes));
}
byteAggregator.writeBytes(bytes);
}
}
Aggregations