use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1 in project bgpcep by opendaylight.
the class BGPSessionImpl method findSingleCapability.
private static <T extends ChildOf<MpCapabilities>> Optional<T> findSingleCapability(final List<BgpParameters> bgpParameters, final String name, final Function<CParameters1, T> extractor) {
final List<T> found = new ArrayList<>(1);
for (BgpParameters bgpParams : bgpParameters) {
for (OptionalCapabilities optCapability : bgpParams.nonnullOptionalCapabilities()) {
final CParameters cparam = optCapability.getCParameters();
if (cparam != null) {
final CParameters1 augment = cparam.augmentation(CParameters1.class);
if (augment != null) {
final T capa = extractor.apply(augment);
if (capa != null) {
found.add(capa);
}
}
}
}
}
final Set<T> set = ImmutableSet.copyOf(found);
switch(set.size()) {
case 0:
LOG.debug("{} capability not advertised.", name);
return Optional.empty();
case 1:
return Optional.of(found.get(0));
default:
LOG.warn("Multiple instances of {} capability advertised: {}, ignoring.", name, set);
return Optional.empty();
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1 in project bgpcep by opendaylight.
the class GracefulCapabilityHandler method serializeCapability.
@Override
public void serializeCapability(final CParameters capability, final ByteBuf byteAggregator) {
final CParameters1 aug = capability.augmentation(CParameters1.class);
if (aug == null) {
return;
}
final GracefulRestartCapability grace = aug.getGracefulRestartCapability();
if (grace != null) {
final ByteBuf bytes = serializeCapability(grace);
CapabilityUtil.formatCapability(CODE, bytes, byteAggregator);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1 in project bgpcep by opendaylight.
the class AddPathCapabilityHandlerTest method noSerializationTest.
@Test
public void noSerializationTest() {
final CParameters capabilityNoAugmentation = new CParametersBuilder().removeAugmentation(CParameters1.class).build();
final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(new CParameters1Builder().build()).build();
final ByteBuf bytes = Unpooled.buffer();
final AddPathCapabilityHandler handler = new AddPathCapabilityHandler(this.afiRegistry, 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.rev180329.CParameters1 in project bgpcep by opendaylight.
the class OpenTest method testSerializeOpen.
@Test
public void testSerializeOpen() throws BGPDocumentedException {
final Open open = new OpenBuilder().setBgpIdentifier(new Ipv4AddressNoZone("127.0.0.1")).setMyAsNumber(Uint16.valueOf(30)).setHoldTimer(Uint16.valueOf(3)).setVersion(new ProtocolVersion(Uint8.valueOf(4))).setBgpParameters(List.of(new BgpParametersBuilder().setOptionalCapabilities(List.of(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(new AsNumber(Uint32.valueOf(1000))).build()).addAugmentation(new CParameters1Builder().setGracefulRestartCapability(new GracefulRestartCapabilityBuilder().setRestartFlags(new GracefulRestartCapability.RestartFlags(false)).setRestartTime(Uint16.ZERO).setTables(Map.of()).build()).build()).build()).build())).build())).build();
final ByteBuf msg = Unpooled.buffer();
new BGPOpenMessageParser(registry).serializeMessage(open, msg);
final byte[] temp = ByteArray.cutBytes(ByteArray.getAllBytes(msg), 19);
final Open openResult = new BGPOpenMessageParser(registry).parseMessageBody(Unpooled.copiedBuffer(temp), temp.length, null);
assertEquals(open.getBgpIdentifier(), openResult.getBgpIdentifier());
assertEquals(open.getHoldTimer(), openResult.getHoldTimer());
assertEquals(open.getMyAsNumber(), openResult.getMyAsNumber());
boolean grace = false;
if (openResult.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability() != null) {
grace = true;
}
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().getAs4BytesCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 0 : 1).getCParameters().getAs4BytesCapability());
assertEquals(open.getBgpParameters().get(0).getOptionalCapabilities().get(0).getCParameters().augmentation(CParameters1.class).getGracefulRestartCapability(), openResult.getBgpParameters().get(0).getOptionalCapabilities().get(grace ? 1 : 0).getCParameters().augmentation(CParameters1.class).getGracefulRestartCapability());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1 in project bgpcep by opendaylight.
the class MultiProtocolCapabilityHandlerTest method noSerializationTest.
@Test
public void noSerializationTest() {
final CParameters capabilityNoAugmentation = new CParametersBuilder().removeAugmentation(CParameters1.class).build();
final CParameters capabilityNoMP = new CParametersBuilder().addAugmentation(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());
}
Aggregations