*/
package org.opendaylight.protocol.bgp.rib.impl;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
+import org.opendaylight.protocol.bgp.rib.impl.spi.CodecsRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.Peer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Routes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
import org.opendaylight.yangtools.binding.data.codec.api.BindingCodecTreeFactory;
import org.opendaylight.yangtools.sal.binding.generator.impl.GeneratedClassLoadingStrategy;
@ThreadSafe
public final class RIBImpl extends DefaultRibReference implements AutoCloseable, RIB, TransactionChainListener, SchemaContextListener {
private static final Logger LOG = LoggerFactory.getLogger(RIBImpl.class);
- private static final QName RIB_ID_QNAME = QName.cachedReference(QName.create(Rib.QNAME, "id"));
- private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME);
+ @VisibleForTesting
+ public static final QName RIB_ID_QNAME = QName.cachedReference(QName.create(Rib.QNAME, "id"));
+ @VisibleForTesting
+ public static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes.QNAME);
private final ReconnectStrategyFactory tcpStrategyFactory;
private final ReconnectStrategyFactory sessionStrategyFactory;
private final RIBExtensionConsumerContext extensions;
private final YangInstanceIdentifier yangRibId;
private final RIBSupportContextRegistryImpl ribContextRegistry;
+ private final CodecsRegistryImpl codecsRegistry;
private final EffectiveRibInWriter efWriter;
private final DOMDataBrokerExtension service;
+ private final List<LocRibWriter> locRibs = new ArrayList<>();
public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final Ipv4Address clusterId, final RIBExtensionConsumerContext extensions,
final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory, final BindingCodecTreeFactory codecFactory,
this.dataBroker = dps;
this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
this.extensions = Preconditions.checkNotNull(extensions);
- this.ribContextRegistry = RIBSupportContextRegistryImpl.create(extensions, codecFactory, classStrategy);
+ this.codecsRegistry = CodecsRegistryImpl.create(codecFactory, classStrategy);
+ this.ribContextRegistry = RIBSupportContextRegistryImpl.create(extensions, this.codecsRegistry);
this.yangRibId = YangInstanceIdentifier.builder().node(BgpRib.QNAME).node(Rib.QNAME).nodeWithKey(Rib.QNAME, RIB_ID_QNAME, ribId.getValue()).build();
LOG.debug("Instantiating RIB table {} at {}", ribId, this.yangRibId);
final DOMDataBrokerExtension domDatatreeChangeService = this.domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
this.service = domDatatreeChangeService;
- this.efWriter = EffectiveRibInWriter.create(getService(), this.createPeerChain(this), getYangRibId(), pd, this.ribContextRegistry);
+ this.efWriter = EffectiveRibInWriter.create(getService(), createPeerChain(this), getYangRibId(), pd, this.ribContextRegistry);
LOG.debug("Effective RIB created.");
for (final BgpTableType t : this.localTables) {
} catch (final TransactionCommitFailedException e1) {
LOG.error("Failed to initiate LocRIB for key {}", key, e1);
}
-
- // FIXME: do not lose the writer so we clean it up on shutdown
- LocRibWriter.create(this.ribContextRegistry, key, this.createPeerChain(this), getYangRibId(), this.localAs, getService(), pd);
+ this.locRibs.add(LocRibWriter.create(this.ribContextRegistry, key, createPeerChain(this), getYangRibId(), this.localAs, getService(), pd));
}
@Override
t.submit().get();
this.domChain.close();
this.efWriter.close();
+ for (final LocRibWriter locRib : this.locRibs) {
+ try {
+ locRib.close();
+ } catch (final Exception e) {
+ LOG.warn("Could not close LocalRib reference: {}", locRib, e);
+ }
+ }
}
@Override
getInstanceIdentifier().child(LocRib.class).child(Tables.class, key)).checkedGet();
if (tableMaybe.isPresent()) {
final Tables table = tableMaybe.get();
- if (table.getRoutes() instanceof Ipv4RoutesCase) {
- final Ipv4RoutesCase routesCase = (Ipv4RoutesCase) table.getRoutes();
- if (routesCase.getIpv4Routes() != null && routesCase.getIpv4Routes().getIpv4Route() != null) {
- return routesCase.getIpv4Routes().getIpv4Route().size();
- }
- } else if (table.getRoutes() instanceof Ipv6RoutesCase) {
- final Ipv6RoutesCase routesCase = (Ipv6RoutesCase) table.getRoutes();
- if (routesCase.getIpv6Routes() != null && routesCase.getIpv6Routes().getIpv6Route() != null) {
- return routesCase.getIpv6Routes().getIpv6Route().size();
- }
- }
+ return countIpRoutes(table.getRoutes());
}
} catch (final ReadFailedException e) {
LOG.debug("Failed to read tables", e);
return 0;
}
+ private int countIpRoutes(final Routes routes) {
+ if (routes instanceof Ipv4RoutesCase) {
+ final Ipv4RoutesCase routesCase = (Ipv4RoutesCase) routes;
+ if (routesCase.getIpv4Routes() != null && routesCase.getIpv4Routes().getIpv4Route() != null) {
+ return routesCase.getIpv4Routes().getIpv4Route().size();
+ }
+ } else if (routes instanceof Ipv6RoutesCase) {
+ final Ipv6RoutesCase routesCase = (Ipv6RoutesCase) routes;
+ if (routesCase.getIpv6Routes() != null && routesCase.getIpv6Routes().getIpv6Route() != null) {
+ return routesCase.getIpv6Routes().getIpv6Route().size();
+ }
+ }
+ return 0;
+ }
+
public Set<TablesKey> getLocalTablesKeys() {
return this.localTablesKeys;
}
@Override
public void onGlobalContextUpdated(final SchemaContext context) {
- this.ribContextRegistry.onSchemaContextUpdated(context);
+ this.codecsRegistry.onSchemaContextUpdated(context);
+ }
+
+ @Override
+ public CodecsRegistry getCodecsRegistry() {
+ return this.codecsRegistry;
}
}