AdjRibIns are no longer used and needed.
Change-Id: Iaa1a2268aabc2f4404f72fb78349168885f69dfc
Signed-off-by: Dana Kutenicsova <dkutenic@cisco.com>
+++ /dev/null
-/*
- * Copyright (c) 2013 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.linkstate;
-
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import java.util.List;
-import org.opendaylight.protocol.bgp.linkstate.nlri.LinkstateNlriParser;
-import org.opendaylight.protocol.bgp.parser.BGPParsingException;
-import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.ObjectType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.LinkStateAttribute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.NodeAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.PrefixAttributesCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.node.attributes._case.NodeAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.path.attribute.link.state.attribute.prefix.attributes._case.PrefixAttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.LinkstateRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.linkstate.route.Attributes1Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstate;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-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.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-final class LinkstateAdjRIBsIn extends AbstractAdjRIBs<CLinkstateDestination, LinkstateRoute, LinkstateRouteKey> {
-
- private abstract static class LinkstateRIBEntryData<A extends LinkStateAttribute> extends RIBEntryData<CLinkstateDestination, LinkstateRoute, LinkstateRouteKey> {
- private final A lsattr;
-
- protected LinkstateRIBEntryData(final Peer peer, final Attributes attributes, final A lsattr) {
- super(peer, attributes);
- this.lsattr = lsattr;
- }
-
- protected abstract LinkStateAttribute createAttributes(A lsattr);
-
- @Override
- protected final LinkstateRoute getDataObject(final CLinkstateDestination key, final LinkstateRouteKey id) {
- final LinkstateRouteBuilder builder = new LinkstateRouteBuilder();
-
- builder.setKey(id);
- builder.setIdentifier(key.getIdentifier());
- builder.setProtocolId(key.getProtocolId());
- builder.setDistinguisher(key.getDistinguisher());
- builder.setAttributes(new AttributesBuilder(getAttributes()).addAugmentation(Attributes1.class,
- new Attributes1Builder().setLinkStateAttribute(Preconditions.checkNotNull(createAttributes(this.lsattr))).build()).build());
- builder.setObjectType(Preconditions.checkNotNull(key.getObjectType()));
-
- return builder.build();
- }
-
- @Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return toStringHelper.add("lsattr", this.lsattr);
- }
- }
-
- private static final Logger LOG = LoggerFactory.getLogger(LinkstateAdjRIBsIn.class);
- private final InstanceIdentifier<LinkstateRoutes> routesBasePath;
-
- LinkstateAdjRIBsIn(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
- super(basePath);
- this.routesBasePath = basePath.builder().child((Class)LinkstateRoutes.class).build();
- }
-
- @Override
- @Deprecated
- public KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> identifierForKey(final InstanceIdentifier<Tables> basePath, final CLinkstateDestination key) {
- final ByteBuf keyBuf = Unpooled.buffer();
- LinkstateNlriParser.serializeNlri(key, keyBuf);
- return basePath.child((Class)LinkstateRoutes.class).child(LinkstateRoute.class,
- new LinkstateRouteKey(ByteArray.readAllBytes(keyBuf)));
- }
-
- @Override
- public KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> identifierForKey(final CLinkstateDestination key) {
- final ByteBuf keyBuf = Unpooled.buffer();
- LinkstateNlriParser.serializeNlri(key, keyBuf);
- return this.routesBasePath.child(LinkstateRoute.class,
- new LinkstateRouteKey(ByteArray.readAllBytes(keyBuf)));
- }
-
- private static LinkstateRIBEntryData<PrefixAttributesCase> createPrefixData(final Peer peer,
- final Attributes attributes, final LinkStateAttribute lsattr) {
- return new LinkstateRIBEntryData<PrefixAttributesCase>(peer, attributes, (PrefixAttributesCase) lsattr) {
- @Override
- protected LinkStateAttribute createAttributes(final PrefixAttributesCase lsattr) {
- final PrefixAttributesCaseBuilder b = new PrefixAttributesCaseBuilder();
- if (lsattr != null && lsattr.getPrefixAttributes() != null) {
- b.setPrefixAttributes(new PrefixAttributesBuilder(lsattr.getPrefixAttributes()).build());
- }
- return b.build();
- }
- };
- }
-
- private static LinkstateRIBEntryData<LinkAttributesCase> createLinkData(final Peer peer,
- final Attributes attributes, final LinkStateAttribute lsattr) {
- return new LinkstateRIBEntryData<LinkAttributesCase>(peer, attributes, (LinkAttributesCase) lsattr) {
- @Override
- protected LinkStateAttribute createAttributes(final LinkAttributesCase lsattr) {
- final LinkAttributesCaseBuilder b = new LinkAttributesCaseBuilder();
- if (lsattr != null && lsattr.getLinkAttributes() != null) {
- b.setLinkAttributes(new LinkAttributesBuilder(lsattr.getLinkAttributes()).build());
- }
- return b.build();
- }
- };
- }
-
- private static LinkstateRIBEntryData<NodeAttributesCase> createNodeData(final Peer peer,
- final Attributes attributes, final LinkStateAttribute lsattr) {
- return new LinkstateRIBEntryData<NodeAttributesCase>(peer, attributes, (NodeAttributesCase) lsattr) {
- @Override
- protected LinkStateAttribute createAttributes(final NodeAttributesCase lsattr) {
- final NodeAttributesCaseBuilder b = new NodeAttributesCaseBuilder();
- if (lsattr != null && lsattr.getNodeAttributes() != null) {
- b.setNodeAttributes(new NodeAttributesBuilder(lsattr.getNodeAttributes()).build());
- }
- return b.build();
- }
- };
- }
-
- @Override
- public void addRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpReachNlri nlri,
- final Attributes attributes) {
- LOG.debug("Passed nlri {}", nlri);
- final LinkstateDestination keys = ((DestinationLinkstateCase) nlri.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate();
- if (keys == null) {
- LOG.debug("No destinations present in advertized routes");
- return;
- }
- LOG.debug("Iterating over route destinations {}", keys);
- for (final CLinkstateDestination key : keys.getCLinkstateDestination()) {
- LOG.debug("Processing route key {}", key);
- LinkStateAttribute lsattr = null;
- final Attributes1 pa = attributes.getAugmentation(Attributes1.class);
- if (pa != null) {
- lsattr = pa.getLinkStateAttribute();
- }
- RIBEntryData<CLinkstateDestination, LinkstateRoute, LinkstateRouteKey> data = null;
- final ObjectType ot = key.getObjectType();
- if (ot instanceof LinkCase) {
- data = createLinkData(peer, attributes, lsattr);
- } else if (ot instanceof NodeCase) {
- data = createNodeData(peer, attributes, lsattr);
- } else if (ot instanceof PrefixCase) {
- data = createPrefixData(peer, attributes, lsattr);
- }
- super.add(trans, peer, key, data);
- }
- }
-
- @Override
- public void removeRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
- final DestinationLinkstate keys = ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) nlri.getWithdrawnRoutes().getDestinationType()).getDestinationLinkstate();
-
- for (final CLinkstateDestination key : keys.getCLinkstateDestination()) {
- super.remove(trans, peer, key);
- }
- }
-
- @Override
- public void addAdvertisement(final MpReachNlriBuilder builder, final LinkstateRoute data) {
- final CLinkstateDestinationBuilder nlri = new CLinkstateDestinationBuilder();
- nlri.setProtocolId(data.getProtocolId());
- nlri.setIdentifier(data.getIdentifier());
- final Attributes a = data.getAttributes();
- if (a != null && a.getCNextHop() != null) {
- builder.setCNextHop(a.getCNextHop());
- }
- final ObjectType type = data.getObjectType();
- nlri.setObjectType(type);
- final AdvertizedRoutes ar = builder.getAdvertizedRoutes();
- if (ar == null) {
- builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder()
- .setCLinkstateDestination(Lists.newArrayList(nlri.build())).build()).build()).build());
- } else {
- ((DestinationLinkstateCase) ar.getDestinationType()).getDestinationLinkstate().getCLinkstateDestination().add(nlri.build());
- }
- }
-
- @Override
- public void addWithdrawal(final MpUnreachNlriBuilder builder, final CLinkstateDestination id) {
- final WithdrawnRoutes wr = builder.getWithdrawnRoutes();
- if (wr == null) {
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder()
- .setCLinkstateDestination(Lists.newArrayList(id)).build()).build()).build());
- } else {
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) wr.getDestinationType())
- .getDestinationLinkstate().getCLinkstateDestination().add(id);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> routeIdentifier(final InstanceIdentifier<?> id) {
- return (KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey>)id.firstIdentifierOf(LinkstateRoute.class);
- }
-
- @Override
- public CLinkstateDestination keyForIdentifier(final KeyedInstanceIdentifier<LinkstateRoute, LinkstateRouteKey> id) {
- final LinkstateRouteKey route = id.getKey();
- List<CLinkstateDestination> dests = null;
- try {
- dests = LinkstateNlriParser.parseNlri(Unpooled.wrappedBuffer(route.getRouteKey()), false);
- } catch (final BGPParsingException e) {
- LOG.warn("Unable to parse LinkstateRoute Key {}", route, e);
- }
- if (dests == null || dests.size() != 1) {
- LOG.warn("Null or more than one LinkstateRoute Key was parsed");
- return null;
- }
- return dests.get(0);
- }
-}
import com.google.common.collect.Lists;
import java.util.List;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsFactory;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-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.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
* Activator for registering Linkstate AFI/SAFI to RIB.
public final class RIBActivator extends AbstractRIBExtensionProviderActivator {
@Override
protected List<AutoCloseable> startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) {
- return Lists.newArrayList(context.registerAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, new AdjRIBsFactory() {
- @Override
- public AdjRIBsIn<?, ?> createAdjRIBs(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
- return new LinkstateAdjRIBsIn(basePath);
- }
- }), context.registerRIBSupport(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, LinkstateRIBSupport.getInstance()));
+ return Lists.newArrayList((AutoCloseable)context.registerRIBSupport(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class, LinkstateRIBSupport.getInstance()));
}
}
final RIBActivator ribAct = new RIBActivator();
final RIBExtensionProviderContext context = new SimpleRIBExtensionProviderContext();
- assertNull(context.getAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
+ assertNull(context.getRIBSupport(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
ribAct.startRIBExtensionProvider(context);
- assertNotNull(context.getAdjRIBsInFactory(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
+ assertNotNull(context.getRIBSupport(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class));
ribAct.close();
}
+++ /dev/null
-/*
- * Copyright (c) 2014 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.linkstate;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.Lists;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.protocol.bgp.rib.RibReference;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.BGPObjectComparator;
-import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Identifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.Ipv4InterfaceIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.ProtocolId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.isis.lan.identifier.IsIsRouterIdentifierBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestination;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.destination.CLinkstateDestinationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.LinkCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.NodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.PrefixCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LinkDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.node._case.NodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.AdvertisingNodeDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.object.type.prefix._case.PrefixDescriptorsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRoute;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.linkstate.routes.linkstate.routes.LinkstateRouteBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCase;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationLinkstateCaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.rib.LocRib;
-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.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-public class LinkstateAdjRIBsInTest extends AbstractDataBrokerTest {
-
- private static final AsNumber TEST_AS_NUMBER = new AsNumber(35L);
-
- @Mock
- private RibReference rib;
-
- @Mock
- private Peer peer;
-
- @Mock
- private AdjRIBsTransaction adjRibTx;
-
- @Mock
- private RouteEncoder encoder;
-
- private LinkstateAdjRIBsIn lrib;
-
- private CLinkstateDestinationBuilder dBuilder;
-
- private final MpReachNlriBuilder builder = new MpReachNlriBuilder();
-
- private final List<CLinkstateDestination> destinations = new ArrayList<>();
-
- private final BGPObjectComparator bgpComparator = new BGPObjectComparator(TEST_AS_NUMBER);
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
- final InstanceIdentifier<Rib> iid = InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(new RibId("test-rib"))).build();
- final KeyedInstanceIdentifier<Tables, TablesKey> key = iid.child(LocRib.class).child(Tables.class, new TablesKey(LinkstateAddressFamily.class,
- LinkstateSubsequentAddressFamily.class));
-
- Mockito.doAnswer(new Answer<Void>() {
- @SuppressWarnings("unchecked")
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Object[] args = invocation.getArguments();
- final InstanceIdentifier<Route> ii = (InstanceIdentifier<Route>) args[2];
- final Route data = (Route) args[4];
- wTx.put(LogicalDatastoreType.OPERATIONAL, ii, data, true);
- return null;
- }
-
- }).when(this.adjRibTx).advertise(Mockito.<RouteEncoder>any(), Mockito.any(), Mockito.<InstanceIdentifier<Route>>any(), Mockito.<Peer>any(), Mockito.any(Route.class));
-
- Mockito.doAnswer(new Answer<Void>() {
- @SuppressWarnings("unchecked")
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Object[] args = invocation.getArguments();
- final InstanceIdentifier<Route> ii = (InstanceIdentifier<Route>) args[2];
- wTx.delete(LogicalDatastoreType.OPERATIONAL, ii);
- return null;
- }
-
- }).when(this.adjRibTx).withdraw(Mockito.<RouteEncoder>any(), Mockito.any(), Mockito.<InstanceIdentifier<Route>>any());
-
- Mockito.doAnswer(new Answer<Void>() {
- @SuppressWarnings("unchecked")
- @Override
- public Void answer(final InvocationOnMock invocation) throws Throwable {
- final Object[] args = invocation.getArguments();
- final InstanceIdentifier<Tables> basePath = (InstanceIdentifier<Tables>) args[0];
- final Boolean uptodate = (Boolean) args[1];
- final InstanceIdentifier<Attributes> aid = basePath.child(Attributes.class);
- wTx.merge(LogicalDatastoreType.OPERATIONAL, aid, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.tables.AttributesBuilder().setUptodate(uptodate).build());
- return null;
- }
- }).when(this.adjRibTx).setUptodate(Matchers.<InstanceIdentifier<Tables>>any(), Mockito.anyBoolean());
-
- Mockito.doReturn(this.bgpComparator).when(this.adjRibTx).comparator();
-
- Mockito.doReturn(iid).when(this.rib).getInstanceIdentifier();
- Mockito.doReturn("test").when(this.peer).toString();
- this.lrib = new LinkstateAdjRIBsIn(key);
-
- this.dBuilder = new CLinkstateDestinationBuilder();
-
- this.dBuilder.setProtocolId(ProtocolId.Direct);
- this.dBuilder.setIdentifier(new Identifier(new BigInteger(new byte[] { 5 })));
- }
-
- @Test
- public void testAddPrefix() {
- this.dBuilder.setObjectType(new PrefixCaseBuilder()
- .setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder().setAsNumber(TEST_AS_NUMBER).build())
- .setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("12.34.35.55/32"))).build()).build());
- this.destinations.add(this.dBuilder.build());
- this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
-
- final AttributesBuilder pa = new AttributesBuilder();
- pa.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
-
- this.lrib.addRoutes(this.adjRibTx, this.peer, this.builder.build(), pa.build());
-
- Mockito.verify(this.adjRibTx, Mockito.times(1)).advertise(Mockito.<RouteEncoder>any(), Mockito.any(), Mockito.<InstanceIdentifier<Route>>any(), Mockito.<Peer>any(), Mockito.any(Route.class));
- Mockito.verify(this.adjRibTx, Mockito.times(1)).setUptodate(Matchers.<InstanceIdentifier<Tables>>any(), Matchers.anyBoolean());
- }
-
- @Test
- public void testAddNode() {
- this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().build()).build());
- this.lrib.addRoutes(this.adjRibTx, this.peer, this.builder.build(), null);
-
- this.dBuilder.setObjectType(new NodeCaseBuilder().setNodeDescriptors(new NodeDescriptorsBuilder().setAsNumber(TEST_AS_NUMBER).setCRouterIdentifier(
- new IsisPseudonodeCaseBuilder().setIsisPseudonode(
- new IsisPseudonodeBuilder().setIsIsRouterIdentifier(
- new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).build()).build()).build()).build());
- this.destinations.add(this.dBuilder.build());
- this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
-
- final AttributesBuilder pa = new AttributesBuilder();
-
- this.lrib.addRoutes(this.adjRibTx, this.peer, this.builder.build(), pa.build());
-
- Mockito.verify(this.adjRibTx, Mockito.times(1)).advertise(Mockito.<RouteEncoder>any(), Mockito.any(), Mockito.<InstanceIdentifier<Route>>any(), Mockito.<Peer>any(), Mockito.any(Route.class));
- Mockito.verify(this.adjRibTx, Mockito.times(1)).setUptodate(Matchers.<InstanceIdentifier<Tables>>any(), Matchers.anyBoolean());
- }
-
- @Test
- public void testAddRemoveLink() {
- final LinkCaseBuilder lCase = new LinkCaseBuilder();
- lCase.setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().setAsNumber(TEST_AS_NUMBER).build());
- lCase.setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(TEST_AS_NUMBER).setCRouterIdentifier(
- new IsisPseudonodeCaseBuilder().setIsisPseudonode(
- new IsisPseudonodeBuilder().setIsIsRouterIdentifier(
- new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 1, 2, 3, 4, 5, 6 })).build()).build()).build()).build());
- lCase.setLinkDescriptors(new LinkDescriptorsBuilder().setIpv4InterfaceAddress(
- new Ipv4InterfaceIdentifier(new Ipv4Address("127.0.0.1"))).build());
- this.dBuilder.setObjectType(lCase.build());
- this.destinations.add(this.dBuilder.build());
- this.builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new DestinationLinkstateBuilder().setCLinkstateDestination(this.destinations).build()).build()).build());
-
- final AttributesBuilder pa = new AttributesBuilder();
- pa.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
-
- this.lrib.addRoutes(this.adjRibTx, this.peer, this.builder.build(), pa.build());
-
- Mockito.verify(this.adjRibTx, Mockito.times(1)).advertise(Mockito.<RouteEncoder>any(), Mockito.any(), Mockito.<InstanceIdentifier<Route>>any(), Mockito.<Peer>any(), Mockito.any(Route.class));
- Mockito.verify(this.adjRibTx, Mockito.times(1)).setUptodate(Matchers.<InstanceIdentifier<Tables>>any(), Matchers.anyBoolean());
-
- final MpUnreachNlriBuilder builder = new MpUnreachNlriBuilder();
- builder.setAfi(LinkstateAddressFamily.class);
- builder.setSafi(LinkstateSubsequentAddressFamily.class);
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
- this.destinations).build()).build()).build());
- this.lrib.removeRoutes(this.adjRibTx, this.peer, builder.build());
-
- Mockito.verify(this.adjRibTx, Mockito.times(1)).withdraw(Mockito.<RouteEncoder>any(), Mockito.any(), Matchers.<InstanceIdentifier<Route>>any());
- }
-
- @Test
- public void testAddAdvertisement() {
- final PrefixCaseBuilder pcb = new PrefixCaseBuilder();
- pcb.setAdvertisingNodeDescriptors(new AdvertisingNodeDescriptorsBuilder().build());
- pcb.setPrefixDescriptors(new PrefixDescriptorsBuilder().setIpReachabilityInformation(new IpPrefix(new Ipv4Prefix("127.0.0.1/32"))).build()).build();
- LinkstateRoute data = new LinkstateRouteBuilder().setObjectType(pcb.build()).build();
- final MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
- this.lrib.addAdvertisement(mpBuilder, data);
- final List<CLinkstateDestination> dests = ((DestinationLinkstateCase) mpBuilder.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate().getCLinkstateDestination();
-
- final NodeCaseBuilder ncb = new NodeCaseBuilder();
- ncb.setNodeDescriptors(new NodeDescriptorsBuilder().build());
- data = new LinkstateRouteBuilder().setObjectType(ncb.build()).build();
- this.lrib.addAdvertisement(mpBuilder, data);
- assertEquals(2, dests.size());
-
- final LinkCaseBuilder lcb = new LinkCaseBuilder();
- lcb.setLocalNodeDescriptors(new LocalNodeDescriptorsBuilder().build());
- lcb.setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().build());
- lcb.setLinkDescriptors(new LinkDescriptorsBuilder().build());
- data = new LinkstateRouteBuilder().setObjectType(lcb.build()).build();
- this.lrib.addAdvertisement(mpBuilder, data);
- assertEquals(3, dests.size());
- }
-
- @Test
- public void testAddWithdrawal() {
- final MpUnreachNlriBuilder paBuilder = new MpUnreachNlriBuilder().setWithdrawnRoutes(
- new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(
- Lists.newArrayList(this.dBuilder.build())).build()).build()).build());
-
- final MpUnreachNlriBuilder mpUBuilder = new MpUnreachNlriBuilder();
- this.lrib.addWithdrawal(mpUBuilder, this.dBuilder.build());
- assertEquals(paBuilder.build(), mpUBuilder.build());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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 com.google.common.base.Preconditions;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ConcurrentMap;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AdjRIBsOut;
-import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-
-/**
- * A per-peer collection of data which needs to be sent out. This class is kept lockfree
- * on purpose.
- */
-@Deprecated
-abstract class AbstractAdjRIBsOut implements AdjRIBsOut {
- private final ConcurrentMap<Object, AdjRIBOutEntry<Object, Route>> data = new ConcurrentHashMap<>();
- private final Queue<Object> queue = new ConcurrentLinkedQueue<>();
-
- /**
- * Callback invoked from RIB backend when new data becomes available. Implementations
- * are expected to be able to handle multiple notifications and perform state
- * compression as appropriate.
- */
- protected abstract void wantWrite();
-
- /**
- * Write a single PDU onto the peer. This callback is issued from {@link #process()}.
- *
- * @param pdu Update message
- * @return True if the peer is ready to accept another PDU.
- */
- protected abstract boolean writePDU(Update pdu);
-
- @Override
- public void put(final RouteEncoder ribOut, final Object key, final Route newValue) {
- AdjRIBOutEntry<Object, Route> e = data.get(key);
- if (e == null) {
- if (newValue == null) {
- // Already not advertised, nothing to do
- return;
- }
-
- e = new AdjRIBOutEntry<Object, Route>(ribOut);
- }
-
- // Make sure the new value is visible to the advertiser thread
- final DataObject oldValue = e.getAndSetCurrent(newValue);
-
- // Now read what is being currently advertised
- final DataObject advValue = e.getAdverised();
-
- if (advValue == newValue) {
- /*
- * We raced with the advertiser, which has sent out the this advertisement.
- * This means our job is done.
- */
- return;
- }
-
- if (newValue != null && AdjRIBOutEntry.isNone(advValue)) {
- /*
- * We are advertising a new value and this is not a entry: need to put
- * it into the map.
- */
- data.put(key, e);
- }
-
- if (oldValue == advValue) {
- /*
- * The old value was being advertised, so the advertiser is not aware that
- * this key needs updating. Enqueue the key, so it will see it.
- */
- queue.add(key);
- wantWrite();
- }
- }
-
- /**
- * Call this method from superclass when you are ready to process outgoing PDUs.
- */
- protected final void process() {
- boolean writable = true;
-
- while (writable) {
- final Object key = queue.poll();
- if (key == null) {
- break;
- }
-
- final AdjRIBOutEntry<Object, Route> e = data.get(key);
- if (e == null) {
- /*
- * This was a notification for a value which has already been withdrawn,
- * nothing to do, continue to next key.
- */
- continue;
- }
-
- // First read what is it that we are advertising
- final DataObject oldValue = e.getAdverised();
- Preconditions.checkState(oldValue != null, "Unexpected withdrawn entry %s for %s", e, key);
-
- // Now read what we should be advertising
- final Route newValue = e.getCurrent();
-
- if (!oldValue.equals(newValue)) {
- /*
- * The advertised value is not the same as what we want to advertise,
- * so we need to send it out.
- */
- writable = writePDU(e.getRibOut().updateMessageFor(key, newValue));
- }
-
- /*
- * Save what we are advertising. We need to store this even for withdrawals,
- * as the entry may have been picked up again.
- */
- e.setAdverised(newValue);
-
- /*
- * Ready to clean the entry. Just a tiny check first: has the new value
- * changed? If it has, we need to keep the entry, as there is an incoming
- * update.
- */
- if (newValue == null && e.getCurrent() == null) {
- data.remove(key, e);
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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 com.google.common.base.Preconditions;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
-
-@Deprecated
-final class AdjRIBOutEntry<K, V extends Route> {
- @SuppressWarnings("rawtypes")
- private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_ADV_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "advertisedValue");
- @SuppressWarnings("rawtypes")
- private static final AtomicReferenceFieldUpdater<AdjRIBOutEntry, Route> NLRIENTRY_CUR_UPDATER = AtomicReferenceFieldUpdater.newUpdater(AdjRIBOutEntry.class, Route.class, "currentValue");
-
- /*
- * Marker object for uninitialized value. Distinct from null.
- */
- private static final Route NLRIENTRY_NONE_VALUE = new Route() {
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- throw new IllegalStateException("This method should never be invoked");
- }
-
- @Override
- public Attributes getAttributes() {
- throw new IllegalStateException("This method should never be invoked");
- }
- };
-
- // Referenced via AtomicReferenceFieldUpdaters
- @SuppressWarnings("unused")
- private volatile Route currentValue = NLRIENTRY_NONE_VALUE;
- @SuppressWarnings("unused")
- private volatile Route advertisedValue = NLRIENTRY_NONE_VALUE;
- private final RouteEncoder ribOut;
-
- AdjRIBOutEntry(final RouteEncoder ribOut) {
- this.ribOut = Preconditions.checkNotNull(ribOut);
- }
-
- Route getAdverised() {
- return NLRIENTRY_ADV_UPDATER.get(this);
- }
-
- void setAdverised(final V value) {
- NLRIENTRY_ADV_UPDATER.set(this, value);
- }
-
- @SuppressWarnings("unchecked")
- V getCurrent() {
- final Route o = NLRIENTRY_CUR_UPDATER.get(this);
- Preconditions.checkState(!isNone(o), "Value cannot be NONE here");
- return (V) o;
- }
-
- Route getAndSetCurrent(final V value) {
- return NLRIENTRY_CUR_UPDATER.getAndSet(this, value);
- }
-
- RouteEncoder getRibOut() {
- return this.ribOut;
- }
-
- static boolean isNone(final Object o) {
- return NLRIENTRY_NONE_VALUE.equals(o);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2013 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 com.google.common.collect.Lists;
-import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.DestinationIpv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4Prefixes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.Ipv4Routes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4Route;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4RouteBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.routes.ipv4.routes.Ipv4RouteKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4Case;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-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.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-@Deprecated
-final class Ipv4AdjRIBsIn extends AbstractAdjRIBs<Ipv4Prefix, Ipv4Route, Ipv4RouteKey> {
- private final InstanceIdentifier<Ipv4Routes> routesBasePath;
-
- Ipv4AdjRIBsIn(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
- super(basePath);
- this.routesBasePath = basePath.builder().child((Class)Ipv4Routes.class).build();
- }
-
- @Override
- @Deprecated
- public KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> identifierForKey(final InstanceIdentifier<Tables> basePath, final Ipv4Prefix key) {
- return basePath.child((Class)Ipv4Routes.class).child(Ipv4Route.class, new Ipv4RouteKey(key));
- }
-
- @Override
- public KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> identifierForKey(final Ipv4Prefix key) {
- return this.routesBasePath.child(Ipv4Route.class, new Ipv4RouteKey(key));
- }
-
- @Override
- public void addRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpReachNlri nlri,
- final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes attributes) {
- final RIBEntryData<Ipv4Prefix, Ipv4Route, Ipv4RouteKey> data = new RIBEntryData<Ipv4Prefix, Ipv4Route, Ipv4RouteKey>(peer, attributes) {
- @Override
- protected Ipv4Route getDataObject(final Ipv4Prefix key, final Ipv4RouteKey id) {
- return new Ipv4RouteBuilder().setKey(id).setAttributes(new AttributesBuilder(attributes).build()).build();
- }
- };
-
- for (final Ipv4Prefixes id : ((DestinationIpv4Case) nlri.getAdvertizedRoutes().getDestinationType()).getDestinationIpv4().getIpv4Prefixes()) {
- super.add(trans, peer, id.getPrefix(), data);
- }
- }
-
- @Override
- public void removeRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
- for (final Ipv4Prefixes id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case) nlri.getWithdrawnRoutes().getDestinationType()).getDestinationIpv4().getIpv4Prefixes()) {
- super.remove(trans, peer, id.getPrefix());
- }
- }
-
- @Override
- public void addAdvertisement(final MpReachNlriBuilder builder, final Ipv4Route data) {
- final Attributes a = data.getAttributes();
- if (a != null && a.getCNextHop() != null) {
- builder.setCNextHop(a.getCNextHop());
- }
- final AdvertizedRoutes ar = builder.getAdvertizedRoutes();
- final Ipv4Prefixes p = new Ipv4PrefixesBuilder().setPrefix(data.getPrefix()).build();
- if (ar == null) {
- builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(Lists.newArrayList(p)).build()).build()).build());
- } else {
- ((DestinationIpv4Case) ar.getDestinationType()).getDestinationIpv4().getIpv4Prefixes().add(p);
- }
- }
-
- @Override
- public void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv4Prefix id) {
- final WithdrawnRoutes wr = builder.getWithdrawnRoutes();
- final Ipv4Prefixes p = new Ipv4PrefixesBuilder().setPrefix(id).build();
- if (wr == null) {
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
- Lists.newArrayList(p)).build()).build()).build());
- } else {
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv4Case) wr.getDestinationType()).getDestinationIpv4().getIpv4Prefixes().add(p);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> routeIdentifier(final InstanceIdentifier<?> id) {
- return (KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey>)id.firstIdentifierOf(Ipv4Route.class);
- }
-
- @Override
- public Ipv4Prefix keyForIdentifier(final KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> id) {
- return id.getKey().getPrefix();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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 com.google.common.collect.Lists;
-import org.opendaylight.protocol.bgp.rib.spi.AbstractAdjRIBs;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.DestinationIpv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6Prefixes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.Ipv6Routes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6Route;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6RouteBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.routes.ipv6.routes.Ipv6RouteKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6Case;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlri;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpUnreachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
-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.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-@Deprecated
-final class Ipv6AdjRIBsIn extends AbstractAdjRIBs<Ipv6Prefix, Ipv6Route, Ipv6RouteKey> {
- private final InstanceIdentifier<Ipv6Routes> routesBasePath;
-
- Ipv6AdjRIBsIn(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
- super(basePath);
- this.routesBasePath = basePath.builder().child((Class)Ipv6Routes.class).build();
- }
-
- @Override
- @Deprecated
- public KeyedInstanceIdentifier<Ipv6Route, Ipv6RouteKey> identifierForKey(final InstanceIdentifier<Tables> basePath, final Ipv6Prefix key) {
- return basePath.child((Class)Ipv6Routes.class).child(Ipv6Route.class, new Ipv6RouteKey(key));
- }
-
- @Override
- public KeyedInstanceIdentifier<Ipv6Route, Ipv6RouteKey> identifierForKey(final Ipv6Prefix key) {
- return this.routesBasePath.child(Ipv6Route.class, new Ipv6RouteKey(key));
- }
-
- @Override
- public void addRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpReachNlri nlri,
- final Attributes attributes) {
- final RIBEntryData<Ipv6Prefix, Ipv6Route, Ipv6RouteKey> data = new RIBEntryData<Ipv6Prefix, Ipv6Route, Ipv6RouteKey>(peer, attributes) {
- @Override
- protected Ipv6Route getDataObject(final Ipv6Prefix key, final Ipv6RouteKey id) {
- return new Ipv6RouteBuilder().setKey(id).setAttributes(new AttributesBuilder(attributes).build()).build();
- }
- };
- for (final Ipv6Prefixes id : ((DestinationIpv6Case) nlri.getAdvertizedRoutes().getDestinationType()).getDestinationIpv6().getIpv6Prefixes()) {
- super.add(trans, peer, id.getPrefix(), data);
- }
- }
-
- @Override
- public void removeRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpUnreachNlri nlri) {
- for (final Ipv6Prefixes id : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case) nlri.getWithdrawnRoutes().getDestinationType()).getDestinationIpv6().getIpv6Prefixes()) {
- super.remove(trans, peer, id.getPrefix());
- }
- }
-
- @Override
- public void addAdvertisement(final MpReachNlriBuilder builder, final Ipv6Route data) {
- final Attributes a = data.getAttributes();
- if (a != null && a.getCNextHop() != null) {
- builder.setCNextHop(a.getCNextHop());
- }
- final AdvertizedRoutes ar = builder.getAdvertizedRoutes();
- final Ipv6Prefixes p = new Ipv6PrefixesBuilder().setPrefix(data.getPrefix()).build();
- if (ar == null) {
- builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
- Lists.newArrayList(p)).build()).build()).build());
- } else {
- ((DestinationIpv6Case) ar.getDestinationType()).getDestinationIpv6().getIpv6Prefixes().add(p);
- }
- }
-
- @Override
- public void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv6Prefix id) {
- final WithdrawnRoutes wr = builder.getWithdrawnRoutes();
- final Ipv6Prefixes p = new Ipv6PrefixesBuilder().setPrefix(id).build();
- if (wr == null) {
- builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
- Lists.newArrayList(p)).build()).build()).build());
- } else {
- ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationIpv6Case) wr.getDestinationType()).getDestinationIpv6().getIpv6Prefixes().add(p);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public KeyedInstanceIdentifier<Ipv6Route, Ipv6RouteKey> routeIdentifier(final InstanceIdentifier<?> id) {
- return (KeyedInstanceIdentifier<Ipv6Route, Ipv6RouteKey>)id.firstIdentifierOf(Ipv6Route.class);
- }
-
- @Override
- public Ipv6Prefix keyForIdentifier(final KeyedInstanceIdentifier<Ipv6Route, Ipv6RouteKey> id) {
- return id.getKey().getPrefix();
- }
-}
import com.google.common.collect.Lists;
import java.util.List;
import org.opendaylight.protocol.bgp.rib.spi.AbstractRIBExtensionProviderActivator;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsFactory;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
-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.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
public final class RIBActivator extends AbstractRIBExtensionProviderActivator {
@Override
protected List<AutoCloseable> startRIBExtensionProviderImpl(final RIBExtensionProviderContext context) {
- final AdjRIBsFactory adj1 = new AdjRIBsFactory() {
- @Override
- public AdjRIBsIn<?, ?> createAdjRIBs(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
- return new Ipv4AdjRIBsIn(basePath);
- }
- };
-
- final AdjRIBsFactory adj2 = new AdjRIBsFactory() {
- @Override
- public AdjRIBsIn<?, ?> createAdjRIBs(final KeyedInstanceIdentifier<Tables, TablesKey> basePath) {
- return new Ipv6AdjRIBsIn(basePath);
- }
- };
return Lists.newArrayList(
- context.registerAdjRIBsInFactory(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, adj1),
- context.registerAdjRIBsInFactory(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, adj2),
- context.registerRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv4RIBSupport.getInstance()),
- context.registerRIBSupport(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv6RIBSupport.getInstance()));
+ (AutoCloseable)context.registerRIBSupport(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv4RIBSupport.getInstance()),
+ (AutoCloseable)context.registerRIBSupport(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class, IPv6RIBSupport.getInstance()));
}
}
+++ /dev/null
-/*
- * Copyright (c) 2014 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 com.google.common.base.Preconditions;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
-
-@Deprecated
-final class SessionRIBsOut extends AbstractAdjRIBsOut implements Runnable {
- private final AtomicBoolean scheduled = new AtomicBoolean(false);
- private final BGPSessionImpl session;
-
- SessionRIBsOut(final BGPSessionImpl session) {
- this.session = Preconditions.checkNotNull(session);
- }
-
- @Override
- protected void wantWrite() {
- if (scheduled.compareAndSet(false, true)) {
- session.schedule(this);
- }
- }
-
- @Override
- protected boolean writePDU(final Update pdu) {
- session.writeAndFlush(pdu);
- return session.isWritable();
- }
-
- @Override
- public void run() {
- process();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import com.google.common.collect.Lists;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.protocol.bgp.rib.DefaultRibReference;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsIn;
-import org.opendaylight.protocol.bgp.rib.spi.AdjRIBsTransaction;
-import org.opendaylight.protocol.bgp.rib.spi.BGPObjectComparator;
-import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
-import org.opendaylight.protocol.bgp.rib.spi.RouteEncoder;
-import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.DestinationIpv4Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.DestinationIpv6Builder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv6.prefixes.destination.ipv6.Ipv6PrefixesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv6CaseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.MpReachNlriBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.BgpRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.Route;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
-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.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-
-public class AdjacencyRIBsInTest extends AbstractDataBrokerTest {
-
- private WriteTransaction trans;
-
- private final DefaultRibReference rib = new DefaultRibReference(InstanceIdentifier.create(BgpRib.class).child(Rib.class, new RibKey(new RibId("test"))));
-
- private final RIBActivator act = new RIBActivator();
-
- private final RIBExtensionProviderContext ctx = new SimpleRIBExtensionProviderContext();
-
- private AdjRIBsIn<?, ?> a1;
-
- private RIBTables tables;
-
- private final TablesKey ipv4key = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
-
- private final TablesKey ipv6key = new TablesKey(Ipv6AddressFamily.class, UnicastSubsequentAddressFamily.class);
-
- private final TablesKey linkstateKey = new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
-
- @Mock
- AdjRIBsTransaction adjTrans4;
-
- @Mock
- AdjRIBsTransaction adjTrans6;
-
- @Mock
- AdjRIBsTransaction adjTransLS;
-
- @Mock
- Peer peer;
-
- @Mock
- KeyedInstanceIdentifier<Tables, TablesKey> id;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- this.trans = getDataBroker().newWriteOnlyTransaction();
- this.act.startRIBExtensionProvider(this.ctx);
- this.tables = new RIBTables(this.ctx);
- Mockito.doReturn(new BGPObjectComparator(new AsNumber(72L))).when(this.adjTrans4).comparator();
- Mockito.doReturn(new BGPObjectComparator(new AsNumber(72L))).when(this.adjTrans6).comparator();
- Mockito.doReturn(new BGPObjectComparator(new AsNumber(72L))).when(this.adjTransLS).comparator();
- Mockito.doReturn("test").when(this.peer).toString();
- Mockito.doNothing().when(this.adjTrans4).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
- Mockito.doNothing().when(this.adjTrans4).setUptodate(Mockito.any(InstanceIdentifier.class), Mockito.anyBoolean());
- Mockito.doNothing().when(this.adjTrans6).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
- Mockito.doNothing().when(this.adjTrans6).setUptodate(Mockito.any(InstanceIdentifier.class), Mockito.anyBoolean());
- Mockito.doNothing().when(this.adjTransLS).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
- Mockito.doNothing().when(this.adjTransLS).setUptodate(Mockito.any(InstanceIdentifier.class), Mockito.anyBoolean());
- }
-
- @Test
- public void testRIBTables() {
- this.a1 = this.tables.create(this.trans, this.rib, this.ipv4key);
- assertNotNull(this.a1);
- assertEquals(this.a1, this.tables.get(this.ipv4key));
- }
-
- @Test
- public void testAddRoutes() {
- this.a1 = this.tables.create(this.trans, this.rib, this.ipv4key);
- assertNotNull(this.a1);
- MpReachNlriBuilder mpBuilder = new MpReachNlriBuilder();
- mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
- Lists.newArrayList(new Ipv4PrefixesBuilder().setPrefix(new Ipv4Prefix("127.0.0.1/32")).build())).build()).build()).build());
- final AttributesBuilder paBuilder = new AttributesBuilder();
- this.a1.addRoutes(this.adjTrans4, this.peer, mpBuilder.build(), paBuilder.build());
- Mockito.verify(this.adjTrans4).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
-
- final AdjRIBsIn<?, ?> a2 = this.tables.create(this.trans, this.rib, this.ipv6key);
- assertNotNull(a2);
- mpBuilder = new MpReachNlriBuilder();
- mpBuilder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
- Lists.newArrayList(new Ipv6PrefixesBuilder().setPrefix(new Ipv6Prefix("2001:db8:1:2::/128")).build())).build()).build()).build());
- a2.addRoutes(this.adjTrans6, this.peer, mpBuilder.build(), paBuilder.build());
- Mockito.verify(this.adjTrans6).advertise(Mockito.any(RouteEncoder.class), Mockito.anyObject(), Mockito.any(InstanceIdentifier.class), Mockito.eq(this.peer), Mockito.any(Route.class));
-
- final AdjRIBsIn<?, ?> a3 = this.tables.create(this.trans, this.rib, this.linkstateKey);
- assertNull(a3);
- }
-
- @After
- public void tearDown() {
- this.act.close();
- }
-
-}