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.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;
builder.setProtocolId(key.getProtocolId());
builder.setDistinguisher(key.getDistinguisher());
builder.setAttributes(new AttributesBuilder(getPathAttributes()).addAugmentation(Attributes1.class,
- new Attributes1Builder().setAttributeType(Preconditions.checkNotNull(createAttributes(this.lsattr))).build()).build());
+ new Attributes1Builder().setAttributeType(Preconditions.checkNotNull(createAttributes(this.lsattr))).build()).build());
builder.setObjectType(Preconditions.checkNotNull(createObject(key)));
return builder.build();
final ByteBuf keyBuf = Unpooled.buffer();
LinkstateNlriParser.serializeNlri(key, keyBuf);
return basePath.child(LinkstateRoutes.class).child(LinkstateRoute.class,
- new LinkstateRouteKey(ByteArray.readAllBytes(keyBuf)));
+ new LinkstateRouteKey(ByteArray.readAllBytes(keyBuf)));
}
@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.update.PathAttributes attributes) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes attributes) {
LOG.debug("Passed nlri {}", nlri);
final LinkstateDestination keys = ((DestinationLinkstateCase) nlri.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate();
if (keys == null) {
}
@Override
- protected void addAdvertisement(final MpReachNlriBuilder builder, final LinkstateRoute data) {
+ public void addAdvertisement(final MpReachNlriBuilder builder, final LinkstateRoute data) {
final CLinkstateDestinationBuilder nlri = new CLinkstateDestinationBuilder();
-
+ nlri.setProtocolId(data.getProtocolId());
+ nlri.setIdentifier(data.getIdentifier());
final ObjectType type = data.getObjectType();
if (type instanceof PrefixCase) {
final PrefixCase prefix = (PrefixCase) type;
}
@Override
- protected void addWithdrawal(final MpUnreachNlriBuilder builder, final CLinkstateDestination id) {
+ 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.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder()
- .setCLinkstateDestination(Lists.newArrayList(id)).build()).build()).build());
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.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.rev131125.update.path.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 dests.get(0);
+ }
}
* @return {@link CLinkstateDestination}
* @throws BGPParsingException if parsing was unsuccessful
*/
- private List<CLinkstateDestination> parseNlri(final ByteBuf nlri) throws BGPParsingException {
+ public static List<CLinkstateDestination> parseNlri(final ByteBuf nlri, final boolean isVpn) throws BGPParsingException {
if (!nlri.isReadable()) {
return null;
}
// length means total length of the tlvs including route distinguisher not including the type field
final int length = nlri.readUnsignedShort();
RouteDistinguisher distinguisher = null;
- if (this.isVpn) {
+ if (isVpn) {
// this parses route distinguisher
distinguisher = new RouteDistinguisher(BigInteger.valueOf(nlri.readLong()));
builder.setDistinguisher(distinguisher);
}
nlri.skipBytes(locallength);
builder.setLocalNodeDescriptors((LocalNodeDescriptors) localDescriptor);
- final int restLength = length - (this.isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
+ final int restLength = length - (isVpn ? ROUTE_DISTINGUISHER_LENGTH : 0) - PROTOCOL_ID_LENGTH - IDENTIFIER_LENGTH
- TYPE_LENGTH - LENGTH_SIZE - locallength;
LOG.trace("Restlength {}", restLength);
final ByteBuf rest = nlri.slice(nlri.readerIndex(), restLength);
if (!nlri.isReadable()) {
return;
}
- final List<CLinkstateDestination> dst = parseNlri(nlri);
+ final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev131125.update.path.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate(
if (!nlri.isReadable()) {
return;
}
- final List<CLinkstateDestination> dst = parseNlri(nlri);
+ final List<CLinkstateDestination> dst = parseNlri(nlri, this.isVpn);
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
new DestinationLinkstateCaseBuilder().setDestinationLinkstate(
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;
@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.update.PathAttributes attributes) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes attributes) {
final RIBEntryData<Ipv4Prefix, Ipv4Route, Ipv4RouteKey> data = new RIBEntryData<Ipv4Prefix, Ipv4Route, Ipv4RouteKey>(peer, attributes) {
@Override
protected Ipv4Route getDataObject(final Ipv4Prefix key, final Ipv4RouteKey id) {
}
@Override
- protected void addAdvertisement(final MpReachNlriBuilder builder, final Ipv4Route data) {
+ public void addAdvertisement(final MpReachNlriBuilder builder, final Ipv4Route data) {
final AdvertizedRoutes ar = builder.getAdvertizedRoutes();
if (ar == null) {
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
- Lists.newArrayList(data.getPrefix())).build()).build()).build());
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
+ Lists.newArrayList(data.getPrefix())).build()).build()).build());
} else {
((DestinationIpv4) ar.getDestinationType()).getIpv4Prefixes().add(data.getPrefix());
}
}
@Override
- protected void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv4Prefix id) {
+ public void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv4Prefix id) {
final WithdrawnRoutes wr = builder.getWithdrawnRoutes();
if (wr == null) {
builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
- Lists.newArrayList(id)).build()).build()).build());
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder().setIpv4Prefixes(
+ Lists.newArrayList(id)).build()).build()).build());
} else {
((DestinationIpv4Case) wr.getDestinationType()).getDestinationIpv4().getIpv4Prefixes().add(id);
}
}
+
+ @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();
+ }
}
import com.google.common.base.Preconditions;
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;
@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.update.PathAttributes attributes) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes attributes) {
final RIBEntryData<Ipv6Prefix, Ipv6Route, Ipv6RouteKey> data = new RIBEntryData<Ipv6Prefix, Ipv6Route, Ipv6RouteKey>(peer, attributes) {
@Override
protected Ipv6Route getDataObject(final Ipv6Prefix key, final Ipv6RouteKey id) {
}
@Override
- protected void addAdvertisement(final MpReachNlriBuilder builder, final Ipv6Route data) {
+ public void addAdvertisement(final MpReachNlriBuilder builder, final Ipv6Route data) {
final AdvertizedRoutes ar = builder.getAdvertizedRoutes();
if (ar == null) {
builder.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
- Lists.newArrayList(data.getPrefix())).build()).build()).build());
+ new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
+ Lists.newArrayList(data.getPrefix())).build()).build()).build());
} else {
((DestinationIpv6) ar.getDestinationType()).getIpv6Prefixes().add(data.getPrefix());
}
}
@Override
- protected void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv6Prefix id) {
+ public void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv6Prefix id) {
final WithdrawnRoutes wr = builder.getWithdrawnRoutes();
if (wr == null) {
builder.setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType(
- new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
- Lists.newArrayList(id)).build()).build()).build());
+ new DestinationIpv6CaseBuilder().setDestinationIpv6(new DestinationIpv6Builder().setIpv6Prefixes(
+ Lists.newArrayList(id)).build()).build()).build());
} else {
((DestinationIpv6Case) wr.getDestinationType()).getDestinationIpv6().getIpv6Prefixes().add(id);
}
}
+
+ @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.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.LinkedBlockingQueue;
import javax.annotation.concurrent.ThreadSafe;
-
import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
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.BgpRibBuilder;
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.RibBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.bgp.rib.RibKey;
});
public RIBImpl(final RibId ribId, final AsNumber localAs, final Ipv4Address localBgpId, final RIBExtensionConsumerContext extensions,
- final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory,
- final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final List<BgpTableType> localTables) {
+ final BGPDispatcher dispatcher, final ReconnectStrategyFactory tcpStrategyFactory,
+ final ReconnectStrategyFactory sessionStrategyFactory, final DataBroker dps, final List<BgpTableType> localTables) {
super(InstanceIdentifier.builder(BgpRib.class).child(Rib.class, new RibKey(Preconditions.checkNotNull(ribId))).toInstance());
this.chain = dps.createTransactionChain(this);
this.localAs = Preconditions.checkNotNull(localAs);
LOG.debug("Instantiating RIB table {} at {}", ribId, getInstanceIdentifier());
- final ReadWriteTransaction trans = chain.newReadWriteTransaction();
+ final ReadWriteTransaction trans = this.chain.newReadWriteTransaction();
Optional<Rib> o;
try {
o = trans.read(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier()).get();
// put empty BgpRib if not exists
trans.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(BgpRib.class).build(), new BgpRibBuilder().build());
trans.put(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier(), new RibBuilder().setKey(new RibKey(ribId)).setId(ribId).setLocRib(
- new LocRibBuilder().setTables(Collections.<Tables> emptyList()).build()).build());
+ new LocRibBuilder().setTables(Collections.<Tables> emptyList()).build()).build());
- for (BgpTableType t : localTables) {
+ for (final BgpTableType t : localTables) {
final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
if (this.tables.create(trans, this, key) == null) {
LOG.debug("Did not create local table for unhandled table type {}", t);
@Override
public synchronized void updateTables(final Peer peer, final Update message) {
- final AdjRIBsTransactionImpl trans = new AdjRIBsTransactionImpl(ribOuts, this.comparator, this.chain.newWriteOnlyTransaction());
+ final AdjRIBsTransactionImpl trans = new AdjRIBsTransactionImpl(this.ribOuts, this.comparator, this.chain.newWriteOnlyTransaction());
if (!EOR.equals(message)) {
final WithdrawnRoutes wr = message.getWithdrawnRoutes();
if (wr != null) {
final AdjRIBsIn<?, ?> ari = this.tables.get(IPV4_UNICAST_TABLE);
if (ari != null) {
+ /*
+ * create MPUnreach for the routes to be handled in the same way as linkstate routes
+ */
ari.removeRoutes(
- trans,
- peer,
- new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setWithdrawnRoutes(
- new WithdrawnRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(
- new DestinationIpv4Builder().setIpv4Prefixes(wr.getWithdrawnRoutes()).build()).build()).build()).build());
+ trans,
+ peer,
+ new MpUnreachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setWithdrawnRoutes(
+ new WithdrawnRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(
+ new DestinationIpv4Builder().setIpv4Prefixes(wr.getWithdrawnRoutes()).build()).build()).build()).build());
} else {
LOG.debug("Not removing objects from unhandled IPv4 Unicast");
}
if (ar != null) {
final AdjRIBsIn<?, ?> ari = this.tables.get(IPV4_UNICAST_TABLE);
if (ari != null) {
+ /*
+ * create MPReach for the routes to be handled in the same way as linkstate routes
+ */
final MpReachNlriBuilder b = new MpReachNlriBuilder().setAfi(Ipv4AddressFamily.class).setSafi(
- UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(
- new AdvertizedRoutesBuilder().setDestinationType(
- new DestinationIpv4CaseBuilder().setDestinationIpv4(
- new DestinationIpv4Builder().setIpv4Prefixes(ar.getNlri()).build()).build()).build());
+ UnicastSubsequentAddressFamily.class).setAdvertizedRoutes(
+ new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(
+ new DestinationIpv4Builder().setIpv4Prefixes(ar.getNlri()).build()).build()).build());
if (attrs != null) {
b.setCNextHop(attrs.getCNextHop());
}
public synchronized void clearTable(final Peer peer, final TablesKey key) {
final AdjRIBsIn<?, ?> ari = this.tables.get(key);
if (ari != null) {
- final AdjRIBsTransactionImpl trans = new AdjRIBsTransactionImpl(ribOuts, comparator, this.chain.newWriteOnlyTransaction());
+ final AdjRIBsTransactionImpl trans = new AdjRIBsTransactionImpl(this.ribOuts, this.comparator, this.chain.newWriteOnlyTransaction());
ari.clear(trans, peer);
Futures.addCallback(trans.commit(), new FutureCallback<Void>() {
return toStringHelper;
}
+ @SuppressWarnings("unchecked")
+ protected <K, V extends Route> AdjRIBsIn<K, V> getTable(final TablesKey key) {
+ return (AdjRIBsIn<K, V>) this.tables.get(key);
+ }
+
@Override
public void close() throws InterruptedException, ExecutionException {
final WriteTransaction t = this.chain.newWriteOnlyTransaction();
t.delete(LogicalDatastoreType.OPERATIONAL, getInstanceIdentifier());
t.submit().get();
- chain.close();
+ this.chain.close();
}
@Override
final AdjRIBsOutRegistration reg = new AdjRIBsOutRegistration(aro) {
@Override
protected void removeRegistration() {
- ribOuts.remove(peer, aro);
+ RIBImpl.this.ribOuts.remove(peer, aro);
}
};
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Preconditions;
-
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
-
import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
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.Update;
return this.name;
}
+ /**
+ * Based on given comparator, finds a new best candidate for initial route.
+ *
+ * @param comparator
+ * @param initial
+ * @return
+ */
private RIBEntryData<I, D, K> findCandidate(final BGPObjectComparator comparator, final RIBEntryData<I, D, K> initial) {
RIBEntryData<I, D, K> newState = initial;
for (final RIBEntryData<I, D, K> s : this.candidates.values()) {
return newState;
}
+ /**
+ * Advertize newly elected best candidate to datastore.
+ *
+ * @param transaction
+ * @param candidate
+ */
private void electCandidate(final AdjRIBsTransaction transaction, final RIBEntryData<I, D, K> candidate) {
LOG.trace("Electing state {} to supersede {}", candidate, this.currentState);
}
}
+ /**
+ * Removes RIBEntry from database. If we are removing best path, elect another candidate (using BPS).
+ * If there are no other candidates, remove the path completely.
+ * @param transaction
+ * @param peer
+ * @return true if the list of the candidates for this path is empty
+ */
synchronized boolean removeState(final AdjRIBsTransaction transaction, final Peer peer) {
final RIBEntryData<I, D, K> data = this.candidates.remove(peer);
LOG.trace("Removed data {}", data);
*/
protected abstract KeyedInstanceIdentifier<D, K> identifierForKey(InstanceIdentifier<Tables> basePath, I id);
- /**
- * Transform an advertised data object into the corresponding NLRI in MP_REACH attribute.
- *
- * @param data Data object
- * @param builder MP_REACH attribute builder
- */
- protected abstract void addAdvertisement(MpReachNlriBuilder builder, D data);
+ public void addWith(final MpUnreachNlriBuilder builder, final InstanceIdentifier<?> key) {
+ this.addWithdrawal(builder, keyForIdentifier(this.routeIdentifier(key)));
+ }
/**
* Transform a withdrawn identifier into a the corresponding NLRI in MP_UNREACH attribute.
*/
protected abstract void addWithdrawal(MpUnreachNlriBuilder builder, I id);
+ /**
+ * Creates router identifier out of instance identifier
+ * @param id instance identifier
+ * @return router identifier
+ */
+ public abstract @Nullable KeyedInstanceIdentifier<D, K> routeIdentifier(InstanceIdentifier<?> id);
+
+ /**
+ * Craates route key out of instance identifier
+ * @param id instance identifier
+ * @return route key
+ */
+ public abstract I keyForIdentifier(KeyedInstanceIdentifier<D, K> id);
+
/**
* Common backend for {@link AdjRIBsIn#addRoutes()} implementations.
+ * If a new route is added, check first for its existence in Map of entries.
+ * If the route is already there, change it's state. Then check for peer in
+ * Map of peers, if it's not there, add it.
*
* @param trans Transaction context
* @param peer Originating peer
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.message.rev130919.update.PathAttributes;
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.MpReachNlriBuilder;
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.Route;
public interface AdjRIBsIn<K, V extends Route> {
- void addRoutes(AdjRIBsTransaction trans, Peer peer, MpReachNlri nlri, PathAttributes attributes);
- void removeRoutes(AdjRIBsTransaction trans, Peer peer, MpUnreachNlri nlri);
+ /**
+ * Adds routes to this adjacency rib.
+ * @param trans data-store transaction
+ * @param peer advertising peer
+ * @param nlri routes
+ * @param attributes route attributes
+ */
+ void addRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpReachNlri nlri, final PathAttributes attributes);
- void clear(AdjRIBsTransaction trans, Peer peer);
+ /**
+ * Removes routes from this adjacency rib.
+ * @param trans data-store transaction
+ * @param peer advertising peer
+ * @param nlri routes
+ */
+ void removeRoutes(final AdjRIBsTransaction trans, final Peer peer, final MpUnreachNlri nlri);
- void markUptodate(AdjRIBsTransaction trans, Peer peer);
+ /**
+ * Clears adjacency rib tables.
+ * @param trans data-store transaction
+ * @param peer advertising peer
+ */
+ void clear(final AdjRIBsTransaction trans, final Peer peer);
+ /**
+ * Marks true or false the state of this adjacency rib.
+ * @param trans data-store transaction
+ * @param peer advertising peer
+ */
+ void markUptodate(final AdjRIBsTransaction trans, final Peer peer);
+
+ /**
+ * Transform an advertised data object into the corresponding NLRI in MP_REACH attribute.
+ * @param builder MP_REACH attribute builder
+ * @param data Data object
+ */
+ void addAdvertisement(final MpReachNlriBuilder builder, final V data);
+
+ /**
+ * Creates end-of-rib message for this adjacency rib.
+ * @return BGP Update message
+ */
Update endOfRib();
}
@Test
public void testCompare() {
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr1),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr2)) < 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr2)) < 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr2),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr1)) > 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr1)) > 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr2),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr3)) < 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr3)) < 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr3),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr2)) > 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr2)) > 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr3),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr4)) < 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr4)) < 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr4),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr3)) > 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr3)) > 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr4),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr5)) < 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr5)) < 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr5),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr4)) > 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr4)) > 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr5),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr6)) < 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr6)) < 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr6),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr5)) > 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr5)) > 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr6),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr7)) < 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr7)) < 0);
assertTrue(this.comparator.compare(new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr7),
- new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr6)) > 0);
+ new TestIpv4AdjRIBsIn.TestIpv4RIBEntryData(this.peer, this.attr6)) > 0);
}
@Test
@Override
protected Ipv4Route getDataObject(final Ipv4Prefix key, final Ipv4RouteKey id) {
- return new Ipv4RouteBuilder().setKey(id).setAttributes(new AttributesBuilder(attributes).build()).build();
+ return new Ipv4RouteBuilder().setKey(id).setAttributes(new AttributesBuilder(this.attributes).build()).build();
}
}
@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.update.PathAttributes attributes) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributes attributes) {
return;
}
}
@Override
- protected void addAdvertisement(final MpReachNlriBuilder builder, final Ipv4Route data) {
- // TODO Auto-generated method stub
+ public void addAdvertisement(final MpReachNlriBuilder builder, final Ipv4Route data) {
+ // no-op
}
@Override
- protected void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv4Prefix id) {
- // TODO Auto-generated method stub
+ public void addWithdrawal(final MpUnreachNlriBuilder builder, final Ipv4Prefix id) {
+ // no-op
+ }
+
+ @Override
+ public KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> routeIdentifier(final InstanceIdentifier<?> id) {
+ return null;
+ }
+
+ @Override
+ public Ipv4Prefix keyForIdentifier(final KeyedInstanceIdentifier<Ipv4Route, Ipv4RouteKey> id) {
+ return null;
}
}
}