use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class BGPSessionStateImpl method advertizeCapabilities.
@Override
public synchronized void advertizeCapabilities(final int newHoldTimerValue, final SocketAddress newRemoteAddress, final SocketAddress localAddress, final Set<BgpTableType> tableTypes, final List<BgpParameters> bgpParameters) {
if (bgpParameters != null) {
for (final BgpParameters parameters : bgpParameters) {
for (final OptionalCapabilities optionalCapabilities : parameters.nonnullOptionalCapabilities()) {
final CParameters cParam = optionalCapabilities.getCParameters();
final CParameters1 capabilities = cParam.augmentation(CParameters1.class);
if (capabilities != null) {
final MultiprotocolCapability mc = capabilities.getMultiprotocolCapability();
if (mc != null) {
this.multiProtocolCapability = true;
}
if (capabilities.getGracefulRestartCapability() != null) {
this.gracefulRestartCapability = true;
}
if (capabilities.getAddPathCapability() != null) {
this.addPathCapability = true;
}
if (capabilities.getRouteRefreshCapability() != null) {
this.routerRefreshCapability = true;
}
}
if (cParam.getAs4BytesCapability() != null) {
this.asn32Capability = true;
}
}
}
}
this.holdTimerValue = newHoldTimerValue;
this.remoteAddress = StrictBGPPeerRegistry.getIpAddress(newRemoteAddress);
this.remotePort = new PortNumber(Uint16.valueOf(((InetSocketAddress) newRemoteAddress).getPort()));
this.localPort = new PortNumber(Uint16.valueOf(((InetSocketAddress) localAddress).getPort()));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class GracefulRestartUtilTest method getLlGracefulCapabilityTest.
@Test
public void getLlGracefulCapabilityTest() {
final Set<BgpPeerUtil.LlGracefulRestartDTO> llGracefulRestartDTOs = new HashSet<>();
llGracefulRestartDTOs.add(new BgpPeerUtil.LlGracefulRestartDTO(IPV4_KEY, STALE_TIME, true));
llGracefulRestartDTOs.add(new BgpPeerUtil.LlGracefulRestartDTO(IPV6_KEY, STALE_TIME, false));
CParameters capability = GracefulRestartUtil.getLlGracefulCapability(llGracefulRestartDTOs);
final CParameters1 params = capability.augmentation(CParameters1.class);
assertNotNull(params);
final LlGracefulRestartCapability llGracefulCapability = params.getLlGracefulRestartCapability();
assertNotNull(llGracefulCapability);
final var tables = llGracefulCapability.getTables();
assertNotNull(tables);
assertEquals(2, tables.size());
assertEquals(STALE_TIME, tables.values().iterator().next().getLongLivedStaleTime().getValue().intValue());
tables.values().forEach(table -> {
assertTrue(isSameKey(IPV4_KEY, table.key()) && table.getAfiFlags().getForwardingState() || isSameKey(IPV6_KEY, table.key()) && !table.getAfiFlags().getForwardingState());
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class GracefulRestartUtilTest method getGracefulCapabilityTest.
@Test
public void getGracefulCapabilityTest() {
final Map<TablesKey, Boolean> gracefulMap = new HashMap<>();
gracefulMap.put(IPV4_KEY, true);
gracefulMap.put(IPV6_KEY, false);
CParameters capability = GracefulRestartUtil.getGracefulCapability(gracefulMap, RESTART_TIME, RESTARTING);
final CParameters1 params = capability.augmentation(CParameters1.class);
assertNotNull(params);
final GracefulRestartCapability gracefulCapability = params.getGracefulRestartCapability();
assertNotNull(gracefulCapability);
assertTrue(gracefulCapability.getRestartFlags().getRestartState());
assertEquals(RESTART_TIME, gracefulCapability.getRestartTime().intValue());
final var tables = gracefulCapability.getTables();
assertNotNull(tables);
assertEquals(2, tables.size());
tables.values().forEach(table -> {
assertTrue(isSameKey(IPV4_KEY, table.key()) && table.getAfiFlags().getForwardingState() || isSameKey(IPV6_KEY, table.key()) && !table.getAfiFlags().getForwardingState());
});
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters in project bgpcep by opendaylight.
the class EventBusRegistration method sendMessage.
private static void sendMessage(final BGPSessionListener listener, final Notification message) {
if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
listener.onSessionTerminated(null, new BGPTerminationReason(BGPError.CEASE));
} else if (message instanceof Open) {
final Set<BgpTableType> tts = new HashSet<>();
final List<AddressFamilies> addPathCapabilitiesList = new ArrayList<>();
for (final BgpParameters param : ((Open) message).getBgpParameters()) {
for (final OptionalCapabilities capa : param.getOptionalCapabilities()) {
final CParameters cParam = capa.getCParameters();
final CParameters1 aug = cParam.augmentation(CParameters1.class);
if (aug == null) {
continue;
}
if (aug.getMultiprotocolCapability() != null) {
final MultiprotocolCapability p = aug.getMultiprotocolCapability();
LOG.debug("Adding open parameter {}", p);
final BgpTableType type = new BgpTableTypeImpl(p.getAfi(), p.getSafi());
tts.add(type);
} else if (aug.getAddPathCapability() != null) {
final AddPathCapability addPathCap = aug.getAddPathCapability();
addPathCapabilitiesList.addAll(addPathCap.getAddressFamilies());
}
}
}
listener.onSessionUp(new MockBGPSession(tts, addPathCapabilitiesList));
} else if (!(message instanceof Keepalive)) {
try {
listener.onMessage(new MockBGPSession(), message);
} catch (BGPDocumentedException e) {
LOG.warn("Exception encountered while handling message", e);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParameters 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();
}
}
Aggregations