package org.opendaylight.protocol.bgp.rib.impl;
import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-import java.util.Map.Entry;
-import java.util.Set;
import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.RIBSupport;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.ClusterId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.OriginatorId;
+import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContext;
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.message.rev130919.path.attributes.Aggregator;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AsPath;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Communities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.ExtendedCommunities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.LocalPref;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.MultiExitDisc;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Origin;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.Attributes;
-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.BgpAggregator;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Community;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ExtendedCommunity;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
/**
* A context for a single RIB table instance. It is always bound to a particular {@link AdjRibInWriter}.
*/
@NotThreadSafe
final class TableContext {
- private static final ContainerNode EMPTY_TABLE_ATTRIBUTES = ImmutableNodes.containerNode(Attributes.QNAME);
- private static final ContainerNode EMPTY_ROUTE_ATTRIBUTES = ImmutableNodes.containerNode(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.route.Attributes.QNAME);
- private static final Set<Class<? extends DataObject>> ATTRIBUTE_CACHEABLES;
-
- static {
- final Builder<Class<? extends DataObject>> acb = ImmutableSet.builder();
- acb.add(Aggregator.class);
- acb.add(BgpAggregator.class);
- acb.add(AsPath.class);
- acb.add(ClusterId.class);
- acb.add(Community.class);
- acb.add(Communities.class);
- acb.add(ExtendedCommunity.class);
- acb.add(ExtendedCommunities.class);
- acb.add(LocalPref.class);
- acb.add(MultiExitDisc.class);
- acb.add(Origin.class);
- acb.add(OriginatorId.class);
- ATTRIBUTE_CACHEABLES = acb.build();
- }
-
private final YangInstanceIdentifier tableId;
- private final RIBSupport tableSupport;
- private final Object attributeCodec;
- private final Object nlriCodec;
+ private final RIBSupportContext tableSupport;
- TableContext(final RIBSupport tableSupport, final YangInstanceIdentifier tableId) {
+ TableContext(final RIBSupportContext tableSupport, final YangInstanceIdentifier tableId) {
this.tableSupport = Preconditions.checkNotNull(tableSupport);
this.tableId = Preconditions.checkNotNull(tableId);
-
- final Builder<Class<? extends DataObject>> acb = ImmutableSet.builder();
- acb.addAll(ATTRIBUTE_CACHEABLES);
- acb.addAll(tableSupport.cacheableAttributeObjects());
-
- // FIXME: new Codec.create(acb.build(), tableSupport.cacheableNlriObjects());
- this.attributeCodec = null;
-
- // FIXME: new Codec.create(tableSupport.cacheableNlriObjects());
- this.nlriCodec = null;
}
YangInstanceIdentifier getTableId() {
return this.tableId;
}
- static void clearTable(final DOMDataWriteTransaction tx, final RIBSupport tableSupport, final YangInstanceIdentifier tableId) {
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> tb = ImmutableNodes.mapEntryBuilder();
- tb.withNodeIdentifier((NodeIdentifierWithPredicates)tableId.getLastPathArgument());
- tb.withChild(EMPTY_TABLE_ATTRIBUTES);
-
- // tableId is keyed, but that fact is not directly visible from YangInstanceIdentifier, see BUG-2796
- final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) tableId.getLastPathArgument();
- for (final Entry<QName, Object> e : tableKey.getKeyValues().entrySet()) {
- tb.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue()));
- }
-
- final ChoiceNode routes = tableSupport.emptyRoutes();
- Verify.verifyNotNull(routes, "Null empty routes in %s", tableSupport);
- Verify.verify(Routes.QNAME.equals(routes.getNodeType()), "Empty routes have unexpected identifier %s, expected %s", routes.getNodeType(), Routes.QNAME);
-
- tx.put(LogicalDatastoreType.OPERATIONAL, tableId, tb.withChild(routes).build());
- }
void clearTable(final DOMDataWriteTransaction tx) {
- clearTable(tx, this.tableSupport, this.tableId);
+ tableSupport.clearTable(tx, this.tableId);
}
void removeTable(final DOMDataWriteTransaction tx) {
tx.delete(LogicalDatastoreType.OPERATIONAL, this.tableId);
}
- void writeRoutes(final Object codecFactory, final DOMDataWriteTransaction tx, final MpReachNlri nlri, final PathAttributes attributes) {
-
- // FIXME: run the decoder process
- final ContainerNode domNlri = (ContainerNode) this.nlriCodec;
-
- // FIXME: run the decoder process
- final ContainerNode domAttributes = (ContainerNode) this.attributeCodec;
-
- // FIXME : causes ApplicationPeerTest to fail, uncomment, when codecs are ready
- //final ContainerNode routeAttributes = Builders.containerBuilder(EMPTY_ROUTE_ATTRIBUTES).withValue(domAttributes.getValue()).build();
-
- //this.tableSupport.putRoutes(tx, this.tableId, domNlri, routeAttributes);
+ void writeRoutes(final DOMDataWriteTransaction tx, final MpReachNlri nlri, final PathAttributes attributes) {
+ this.tableSupport.writeRoutes(tx,tableId,nlri,attributes);
}
- void removeRoutes(final Object object, final DOMDataWriteTransaction tx, final MpUnreachNlri nlri) {
- // FIXME: run the decoder process
- final ContainerNode domNlri = (ContainerNode) this.nlriCodec;
- // FIXME : causes ApplicationPeerTest to fail, uncomment, when codecs are ready
- // this.tableSupport.deleteRoutes(tx, this.tableId, domNlri);
+ void removeRoutes(final DOMDataWriteTransaction tx, final MpUnreachNlri nlri) {
+ this.tableSupport.deleteRoutes(tx, this.tableId,nlri);
}
}