Migrate registration and lookup into RIBExtensionContexts.
Change-Id: Ia1cdfb1052abc923c79ecada0ca62c99d3ed731a
Signed-off-by: Robert Varga <rovarga@cisco.com>
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
* @param tableTypes New tables, must not be null
* @return New writer
*/
- AdjRibInWriter changeTableTypes(final RIBSupportRegistry registry, final Set<TablesKey> tableTypes) {
+ AdjRibInWriter changeTableTypes(final RIBExtensionConsumerContext registry, final Set<TablesKey> tableTypes) {
if (tableTypes.equals(tables.keySet())) {
return this;
}
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
*/
private final class TableListener implements DOMDataTreeChangeListener {
private final Map<YangInstanceIdentifier, ListenerRegistration<?>> routeListeners = new HashMap<>();
+ private final RIBExtensionConsumerContext registry;
private final DOMDataTreeChangeService service;
- private final RIBSupportRegistry registry;
- TableListener(final DOMDataTreeChangeService service, final RIBSupportRegistry registry) {
+ TableListener(final DOMDataTreeChangeService service, final RIBExtensionConsumerContext registry) {
this.registry = Preconditions.checkNotNull(registry);
this.service = Preconditions.checkNotNull(service);
}
}
break;
case WRITE:
- // FIXME: use codec to translate or refactor registry
+ // FIXME: use codec to translate
final RIBSupport ribSupport = registry.getRIBSupport(null);
- final TableRouteListener routeListener = new TableRouteListener(ribSupport, peerKey, tableKey);
+ if (ribSupport != null) {
+ final TableRouteListener routeListener = new TableRouteListener(ribSupport, peerKey, tableKey);
+ final ListenerRegistration<?> r = service.registerDataTreeChangeListener(
+ new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tc.getRootPath()), routeListener);
- final ListenerRegistration<?> r = service.registerDataTreeChangeListener(
- new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tc.getRootPath()), routeListener);
-
- routeListeners.put(tc.getRootPath(), r);
+ routeListeners.put(tc.getRootPath(), r);
+ } else {
+ LOG.warn("No RIB support for table {}, ignoring advertisements from peer %s", tableKey, peerKey);
+ }
break;
default:
// No-op
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.rib.impl;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-
-// FIXME: move to rib-spi/integrate with RIBExtension
-public interface RIBSupportRegistry {
-
- @Nullable RIBSupport getRIBSupport(@Nonnull TablesKey k);
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.spi;
+
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+
+public abstract class AbstractRIBSupportRegistration<T extends RIBSupport> extends AbstractObjectRegistration<T> implements RIBSupportRegistration<T> {
+ protected AbstractRIBSupportRegistration(final T instance) {
+ super(instance);
+ }
+}
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+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.types.rev130919.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
* not implemented.
*/
@Nullable AdjRIBsFactory getAdjRIBsInFactory(@Nonnull Class<? extends AddressFamily> afi, @Nonnull Class<? extends SubsequentAddressFamily> safi);
+
+ /**
+ * Acquire a RIB implementation factory for a AFI/SAFI combination.
+ * @param key AFI/SAFI key
+ * @return RIBSupport instance, or null if the AFI/SAFI is
+ * not implemented.
+ */
+ @Nullable RIBSupport getRIBSupport(@Nonnull TablesKey key);
+
+ /**
+ * Acquire a RIB implementation factory for a AFI/SAFI combination.
+ * @param afi Address Family Identifier
+ * @param safi Subsequent Address Family identifier
+ * @return RIBSupport instance, or null if the AFI/SAFI is
+ * not implemented.
+ */
+ @Nullable RIBSupport getRIBSupport(@Nonnull Class<? extends AddressFamily> afi, @Nonnull Class<? extends SubsequentAddressFamily> safi);
}
\ No newline at end of file
*/
AutoCloseable registerAdjRIBsInFactory(Class<? extends AddressFamily> afi, Class<? extends SubsequentAddressFamily> safi,
AdjRIBsFactory factory);
+
+ /**
+ * Register a RIBSupport instance for a particular AFI/SAFI combination.
+ *
+ * @param afi Address Family identifier
+ * @param safi Subsequent Address Family identifier
+ * @param support RIBSupport instance
+ * @return Registration handle. Call {@link RIBSupportRegistration#close()} method to remove it.
+ * @throws NullPointerException if any of the arguments is null
+ */
+ <T extends RIBSupport> RIBSupportRegistration<T> registerRIBSupport(Class<? extends AddressFamily> afi, Class<? extends SubsequentAddressFamily> safi, T support);
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.rib.spi;
+
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+
+/**
+ * A registration of a {@link RIBSupport} instance.
+ *
+ * @param <T> {@link RIBSupport} type
+ */
+public interface RIBSupportRegistration<T extends RIBSupport> extends ObjectRegistration<T> {
+ @Override
+ void close();
+}
*/
package org.opendaylight.protocol.bgp.rib.spi;
-import java.util.Map;
+import com.google.common.base.Preconditions;
import java.util.concurrent.ConcurrentHashMap;
-
+import java.util.concurrent.ConcurrentMap;
import org.opendaylight.protocol.concepts.AbstractRegistration;
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.types.rev130919.AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
public class SimpleRIBExtensionProviderContext implements RIBExtensionProviderContext {
- private final Map<TablesKey, AdjRIBsFactory> factories = new ConcurrentHashMap<>();
+ private final ConcurrentMap<TablesKey, AdjRIBsFactory> factories = new ConcurrentHashMap<>();
+ private final ConcurrentMap<TablesKey, RIBSupport> supports = new ConcurrentHashMap<>();
@Override
public final synchronized AbstractRegistration registerAdjRIBsInFactory(final Class<? extends AddressFamily> afi,
this.factories.put(key, factory);
- final Object lock = this;
return new AbstractRegistration() {
@Override
protected void removeRegistration() {
- synchronized (lock) {
+ synchronized (SimpleRIBExtensionProviderContext.this) {
SimpleRIBExtensionProviderContext.this.factories.remove(key);
}
}
final Class<? extends SubsequentAddressFamily> safi) {
return this.factories.get(new TablesKey(afi, safi));
}
+
+ @Override
+ public <T extends RIBSupport> RIBSupportRegistration<T> registerRIBSupport(final Class<? extends AddressFamily> afi,
+ final Class<? extends SubsequentAddressFamily> safi, final T support) {
+ final TablesKey key = new TablesKey(afi, safi);
+
+ final RIBSupport prev = this.supports.putIfAbsent(key, support);
+ Preconditions.checkArgument(prev == null, "AFI %s SAFI %s is already registered with %s", afi, safi, prev);
+
+ return new AbstractRIBSupportRegistration<T>(support) {
+ @Override
+ protected void removeRegistration() {
+ SimpleRIBExtensionProviderContext.this.supports.remove(key);
+ }
+ };
+ }
+
+ @Override
+ public RIBSupport getRIBSupport(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
+ return getRIBSupport(new TablesKey(afi, safi));
+ }
+
+ @Override
+ public RIBSupport getRIBSupport(final TablesKey key) {
+ return this.supports.get(Preconditions.checkNotNull(key));
+ }
}