}
/**
- * Create a Add Path PathArgument Key(prefix+pathId)
+ * Create a Add Path PathArgument Key(prefix+pathId).
*
- * @param pathId Path Id value
- * @param routeId Route Id value
- * @param routeQname route QName provided per each RibSupport
- * @param pathidQname Path Id QName provided per each RibSupport
+ * @param pathId Path Id value
+ * @param routeId Route Id value
+ * @param routeQname route QName provided per each RibSupport
+ * @param pathidQname Path Id QName provided per each RibSupport
* @param routeKeyQname Prefix QName provided per each RibSupport
* @return Route Key Nid
*/
- public static PathArgument createNidKey(final long pathId, final PathArgument routeId, final QName routeQname, final QName pathidQname,
- final QName routeKeyQname) {
- return createNodeIdentifierWithPredicates(routeQname, pathidQname, pathId, routeKeyQname, getObjectKey(routeId, routeKeyQname));
+ public static NodeIdentifierWithPredicates createNidKey(final long pathId, final PathArgument routeId,
+ final QName routeQname, final QName pathidQname, final QName routeKeyQname) {
+ return createNodeIdentifierWithPredicates(routeQname, pathidQname, pathId, routeKeyQname,
+ getObjectKey(routeId, routeKeyQname));
}
/**
- * Get route key object ( prefgit stat ix / key-value/ .. )
+ * Get route key object ( prefgit stat ix / key-value/ .. ).
*
* @param routeId PathArgument containing the key
* @param routeKeyQname routeKey Qname
return (((NodeIdentifierWithPredicates) routeId).getKeyValues()).get(routeKeyQname);
}
- public static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname, final QName pathidQname, final Object pathId,
- final QName routeKeyQname, final Object keyObject) {
+ public static NodeIdentifierWithPredicates createNodeIdentifierWithPredicates(final QName routeQname,
+ final QName pathidQname, final Object pathId, final QName routeKeyQname, final Object keyObject) {
final ImmutableMap<QName, Object> keyValues = ImmutableMap.of(pathidQname, pathId, routeKeyQname, keyObject);
return new NodeIdentifierWithPredicates(routeQname, keyValues);
}
/**
- * Build Path Id
+ * Build Path Id.
*
* @param routesCont route container
* @param pathIdNii path Id node Identifier
* @return PathId or null in case is not the container
*/
- public static PathId buildPathId(final DataContainerNode<? extends PathArgument> routesCont, final NodeIdentifier pathIdNii) {
+ public static PathId buildPathId(final DataContainerNode<? extends PathArgument> routesCont,
+ final NodeIdentifier pathIdNii) {
final Long pathIdVal = PathIdUtil.extractPathId(routesCont, pathIdNii);
return pathIdVal == null ? null : new PathId(pathIdVal);
}
/**
- * Build Route Key for supporting mp
- * Key is composed by 2 elements (route-key + path Id)
+ * Build Route Key for supporting mp.
+ * Key is composed by 2 elements (route-key + path Id).
*
* @param routeQname route Qname
* @param routeKeyQname route key Qname
* @param pathIdQname path Id Qname
* @param routeKeyValue route key value
- * @param maybePathIdLeaf path id container, it might me supported or not, in that case default 0 value will be assigned
+ * @param maybePathIdLeaf path id container, it might me supported or not, in that case default 0 value will
+ * be assigned
* @return Route Key Nid
*/
- public static NodeIdentifierWithPredicates createNidKey(final QName routeQname, final QName routeKeyQname, final QName pathIdQname,
- final Object routeKeyValue, final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf) {
+ public static NodeIdentifierWithPredicates createNidKey(final QName routeQname, final QName routeKeyQname,
+ final QName pathIdQname, final Object routeKeyValue,
+ final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf) {
// FIXME: a cache here would mean we instantiate the same identifier for each route making comparison quicker.
final Object pathId = maybePathIdLeaf.isPresent() ? (maybePathIdLeaf.get()).getValue() : NON_PATH_ID;
return createNodeIdentifierWithPredicates(routeQname, pathIdQname, pathId, routeKeyQname, routeKeyValue);
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <configuration>
+ <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.mode;
+
+import java.util.List;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.as.path.Segments;
+
+public final class BesthPathStateUtil {
+ BesthPathStateUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static AsNumber getPeerAs(final List<Segments> segments) {
+ if (segments.isEmpty()) {
+ return new AsNumber(0L);
+ }
+ for (final Segments seg : segments) {
+ if (seg.getAsSequence() != null && !seg.getAsSequence().isEmpty()) {
+ return segments.get(0).getAsSequence().get(0);
+ }
+ }
+ return new AsNumber(0L);
+ }
+}
public interface BestPath {
/**
+ * RouterId.
*
* @return the routerId (UnsignedInteger)
*/
UnsignedInteger getRouterId();
/**
+ * PeerId.
*
* @return the routerId (UnsignedInteger) converted to a PeerId
*/
PeerId getPeerId();
/**
+ * Attributes.
*
* @return the path attributes
*/
ContainerNode getAttributes();
/**
+ * PathId.
*
* @return pathId
*/
*/
package org.opendaylight.protocol.bgp.mode.api;
+import javax.annotation.Nonnull;
+
public interface PathSelectionMode extends AutoCloseable {
/**
- * Create a RouteEntry
+ * Create a RouteEntry.
+ *
* @param isComplex true if is complex
* @return ComplexRouteEntry if is complex otherwise a SimpleRouteEntry
*/
- RouteEntry createRouteEntry(boolean isComplex);
+ @Nonnull RouteEntry createRouteEntry(boolean isComplex);
}
*/
public interface RouteEntry {
/**
- * Remove route
+ * Remove route.
*
- * @param routerId router ID in unsigned integer format from an Ipv4Address
+ * @param routerId router ID in unsigned integer format from an Ipv4Address
* @param remotePathId remote path Id received
* @return return true if it was the last route on entry
*/
boolean removeRoute(UnsignedInteger routerId, Long remotePathId);
/**
- * Create value
+ * Create value.
*
* @param routeId router ID pathArgument
- * @param path BestPath
+ * @param path BestPath
* @return MapEntryNode
*/
+ @Deprecated
MapEntryNode createValue(PathArgument routeId, BestPath path);
/**
- * Indicates whether best has changed
+ * Indicates whether best has changed.
*
* @param localAs The local autonomous system number
* @return return true if it has changed
boolean selectBest(long localAs);
/**
- * @param routerId router ID in unsigned integer format from an Ipv4Address
+ * Add Route.
+ *
+ * @param routerId router ID in unsigned integer format from an Ipv4Address
* @param remotePathId remote path Id received
- * @param attrII route Attributes Identifier
- * @param data route Data change
+ * @param attrII route Attributes Identifier
+ * @param data route Data change
* @return returns the offset
*/
int addRoute(UnsignedInteger routerId, Long remotePathId, NodeIdentifier attrII, NormalizedNode<?, ?> data);
/**
- * Update LocRibOut and AdjRibsOut by removing stale best path and writing new best
+ * Update LocRibOut and AdjRibsOut by removing stale best path and writing new best.
*
- * @param localTK local Table Key
- * @param peerPT peer export policy
+ * @param localTK local Table Key
+ * @param peerPT peer export policy
* @param locRibTarget YII local rib
- * @param ribSupport rib support
- * @param tx DOM transaction
- * @param routeIdPA router ID pathArgument
+ * @param ribSupport rib support
+ * @param tx DOM transaction
+ * @param routeIdPA router ID pathArgument
*/
- void updateRoute(TablesKey localTK, ExportPolicyPeerTracker peerPT, YangInstanceIdentifier locRibTarget, RIBSupport ribSupport,
- DOMDataWriteTransaction tx, PathArgument routeIdPA);
+ void updateRoute(TablesKey localTK, ExportPolicyPeerTracker peerPT, YangInstanceIdentifier locRibTarget,
+ RIBSupport ribSupport, DOMDataWriteTransaction tx, PathArgument routeIdPA);
/**
- * Write Route on LocRibOut and AdjRibsOut
- * @param peerId destination peerId
- * @param routeId router ID path Argument
- * @param rootPath YII root path
- * @param peerGroup PeerExportGroup
- * @param localTK local Table Key
+ * Write Route on LocRibOut and AdjRibsOut.
+ *
+ * @param peerId destination peerId
+ * @param routeId router ID path Argument
+ * @param rootPath YII root path
+ * @param peerGroup PeerExportGroup
+ * @param localTK local Table Key
* @param ribSupport rib support
- * @param tx DOM transaction
+ * @param tx DOM transaction
*/
- void writeRoute(PeerId peerId, PathArgument routeId, YangInstanceIdentifier rootPath, PeerExportGroup peerGroup, TablesKey localTK,
- ExportPolicyPeerTracker peerPT, RIBSupport ribSupport, DOMDataWriteTransaction tx);
+ void writeRoute(PeerId peerId, PathArgument routeId, YangInstanceIdentifier rootPath, PeerExportGroup peerGroup,
+ TablesKey localTK, ExportPolicyPeerTracker peerPT, RIBSupport ribSupport, DOMDataWriteTransaction tx);
}
\ No newline at end of file
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.annotation.concurrent.NotThreadSafe;
+import org.opendaylight.protocol.bgp.mode.BesthPathStateUtil;
import org.opendaylight.protocol.bgp.mode.api.BestPathState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.AsPath;
private final NodeIdentifier asSeqNid;
NamespaceSpecificIds(final QName namespace) {
- NodeIdentifier container = new NodeIdentifier(QName.create(namespace, AsPath.QNAME.getLocalName().intern()));
+ NodeIdentifier container = new NodeIdentifier(QName.create(namespace,
+ AsPath.QNAME.getLocalName().intern()));
NodeIdentifier leaf = new NodeIdentifier(QName.create(namespace, "segments").intern());
this.asPath = ImmutableList.of(container, leaf);
}
private static final Logger LOG = LoggerFactory.getLogger(BestPathStateImpl.class);
- private static final Cache<QNameModule, NamespaceSpecificIds> PATH_CACHE = CacheBuilder.newBuilder().weakKeys().weakValues().build();
+ private static final Cache<QNameModule, NamespaceSpecificIds> PATH_CACHE = CacheBuilder.newBuilder()
+ .weakKeys().weakValues().build();
private long peerAs = 0L;
private int asPathLength = 0;
public BestPathStateImpl(final ContainerNode attributes) {
final NamespaceSpecificIds col;
try {
- col = PATH_CACHE.get(attributes.getNodeType().getModule(), () -> new NamespaceSpecificIds(attributes.getNodeType()));
+ col = PATH_CACHE.get(attributes.getNodeType().getModule(),
+ () -> new NamespaceSpecificIds(attributes.getNodeType()));
} catch (final ExecutionException e) {
LOG.error("Error creating namespace-specific attributes collection.", e);
throw new IllegalStateException("Error creating namespace-specific attributes collection.", e);
private static BgpOrigin fromString(final String originStr) {
switch (originStr) {
- case "igp":
- return BgpOrigin.Igp;
- case "egp":
- return BgpOrigin.Egp;
- case "incomplete":
- return BgpOrigin.Incomplete;
- default:
- throw new IllegalArgumentException("Unhandled origin value " + originStr);
+ case "igp":
+ return BgpOrigin.Igp;
+ case "egp":
+ return BgpOrigin.Egp;
+ case "incomplete":
+ return BgpOrigin.Incomplete;
+ default:
+ throw new IllegalArgumentException("Unhandled origin value " + originStr);
}
}
return;
}
- final Optional<NormalizedNode<?, ?>> maybeLocalPref = NormalizedNodes.findNode(this.attributes, this.ids.getLocPref());
+ final Optional<NormalizedNode<?, ?>> maybeLocalPref
+ = NormalizedNodes.findNode(this.attributes, this.ids.getLocPref());
if (maybeLocalPref.isPresent()) {
this.localPref = (Long) maybeLocalPref.get().getValue();
} else {
this.localPref = null;
}
- final Optional<NormalizedNode<?, ?>> maybeMultiExitDisc = NormalizedNodes.findNode(this.attributes, this.ids.getMed());
+ final Optional<NormalizedNode<?, ?>> maybeMultiExitDisc
+ = NormalizedNodes.findNode(this.attributes, this.ids.getMed());
if (maybeMultiExitDisc.isPresent()) {
this.multiExitDisc = (Long) maybeMultiExitDisc.get().getValue();
} else {
this.multiExitDisc = null;
}
- final Optional<NormalizedNode<?, ?>> maybeOrigin = NormalizedNodes.findNode(this.attributes, this.ids.getOrig());
+ final Optional<NormalizedNode<?, ?>> maybeOrigin
+ = NormalizedNodes.findNode(this.attributes, this.ids.getOrig());
if (maybeOrigin.isPresent()) {
this.origin = fromString((String) maybeOrigin.get().getValue());
} else {
this.origin = null;
}
- final Optional<NormalizedNode<?, ?>> maybeSegments = NormalizedNodes.findNode(this.attributes, this.ids.getAsPath());
+ final Optional<NormalizedNode<?, ?>> maybeSegments
+ = NormalizedNodes.findNode(this.attributes, this.ids.getAsPath());
if (maybeSegments.isPresent()) {
final UnkeyedListNode segments = (UnkeyedListNode) maybeSegments.get();
final List<Segments> segs = extractSegments(segments);
if (!segs.isEmpty()) {
- this.peerAs = getPeerAs(segs).getValue();
+ this.peerAs = BesthPathStateUtil.getPeerAs(segs).getValue();
this.asPathLength = countAsPath(segs);
}
}
return count;
}
- private static AsNumber getPeerAs(final List<Segments> segments) {
- if (segments.isEmpty()) {
- return new AsNumber(0L);
- }
- for (final Segments seg : segments) {
- if (seg.getAsSequence() != null && !seg.getAsSequence().isEmpty()) {
- return segments.get(0).getAsSequence().get(0);
- }
- }
- return new AsNumber(0L);
- }
+
public List<Segments> extractSegments(final UnkeyedListNode segments) {
// list segments
final List<Segments> extracted = new ArrayList<>();
for (final UnkeyedListEntryNode segment : segments.getValue()) {
final SegmentsBuilder sb = new SegmentsBuilder();
- // We are expecting that segment contains either as-sequence or as-set, so just one of them will be set, other would be null
- sb.setAsSequence(extractAsList(segment, this.ids.getAsSeq())).setAsSet(extractAsList(segment, this.ids.getAsSet()));
+ // We are expecting that segment contains either as-sequence or as-set,
+ // so just one of them will be set, other would be null
+ sb.setAsSequence(extractAsList(segment, this.ids.getAsSeq()))
+ .setAsSet(extractAsList(segment, this.ids.getAsSet()));
extracted.add(sb.build());
}
return extracted;
return offset;
}
- protected int addRoute(final RouteKey key, final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
+ protected int addRoute(final RouteKey key, final NodeIdentifier attributesIdentifier,
+ final NormalizedNode<?, ?> data) {
LOG.trace("Find {} in {}", attributesIdentifier, data);
- final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(data, attributesIdentifier).orNull();
+ final ContainerNode advertisedAttrs
+ = (ContainerNode) NormalizedNodes.findNode(data, attributesIdentifier).orNull();
return addRoute(key, advertisedAttrs);
}
/**
- * Remove route
+ * Remove route.
*
* @param key RouteKey of removed route
* @param offset Offset of removed route
this.values = this.offsets.removeValue(this.values, offset);
this.pathsId = this.offsets.removeValue(this.pathsId, offset);
this.offsets = this.offsets.without(key);
- if(this.removedPaths == null) {
+ if (this.removedPaths == null) {
this.removedPaths = new ArrayList<>();
}
this.removedPaths.add(new RemovedPath(key, pathId));
}
@Override
- public void updateRoute(final TablesKey localTK, final ExportPolicyPeerTracker peerPT, final YangInstanceIdentifier locRibTarget,
- final RIBSupport ribSupport, final DOMDataWriteTransaction tx, final PathArgument routeIdPA) {
- if(this.bestPathRemoved != null) {
+ public void updateRoute(final TablesKey localTK, final ExportPolicyPeerTracker peerPT,
+ final YangInstanceIdentifier locRibTarget, final RIBSupport ribSupport, final DOMDataWriteTransaction tx,
+ final PathArgument routeIdPA) {
+ if (this.bestPathRemoved != null) {
this.bestPathRemoved.forEach(path -> {
final PathArgument routeIdAddPath = ribSupport.getRouteIdAddPath(path.getPathId(), routeIdPA);
- final YangInstanceIdentifier pathAddPathTarget = ribSupport.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdAddPath);
+ final YangInstanceIdentifier pathAddPathTarget = ribSupport
+ .routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdAddPath);
fillLocRib(pathAddPathTarget, null, tx);
});
this.bestPathRemoved = null;
}
- if(this.removedPaths != null) {
+ if (this.removedPaths != null) {
this.removedPaths.forEach(removedPath -> {
final PathArgument routeIdAddPath = ribSupport.getRouteIdAddPath(removedPath.getPathId(), routeIdPA);
- fillAdjRibsOut(true, null, null, null, routeIdPA, routeIdAddPath, RouterIds.createPeerId(removedPath.getRouteId()),
- peerPT, localTK, ribSupport, tx);
+ fillAdjRibsOut(true, null, null, null, routeIdPA, routeIdAddPath,
+ RouterIds.createPeerId(removedPath.getRouteId()), peerPT, localTK, ribSupport, tx);
});
this.removedPaths = null;
}
- if(this.newBestPathToBeAdvertised != null) {
- this.newBestPathToBeAdvertised.forEach(path -> addPathToDataStore(path, isFirstBestPath(this.bestPath.indexOf(path)), routeIdPA,
- locRibTarget, ribSupport, peerPT, localTK, tx));
+ if (this.newBestPathToBeAdvertised != null) {
+ this.newBestPathToBeAdvertised.forEach(path -> addPathToDataStore(path,
+ isFirstBestPath(this.bestPath.indexOf(path)), routeIdPA, locRibTarget, ribSupport, peerPT,
+ localTK, tx));
this.newBestPathToBeAdvertised = null;
}
}
@Override
- public void writeRoute(final PeerId destPeer, final PathArgument routeId, final YangInstanceIdentifier rootPath, final PeerExportGroup peerGroup,
- final TablesKey localTK, final ExportPolicyPeerTracker peerPT, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
+ public void writeRoute(final PeerId destPeer, final PathArgument routeId, final YangInstanceIdentifier rootPath,
+ final PeerExportGroup peerGroup, final TablesKey localTK, final ExportPolicyPeerTracker peerPT,
+ final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
final boolean destPeerSupAddPath = peerPT.isAddPathSupportedByPeer(destPeer);
- if(this.bestPath != null) {
+ if (this.bestPath != null) {
final PeerRole destPeerRole = getRoutePeerIdRole(peerPT, destPeer);
- this.bestPath.stream().filter(path -> filterRoutes(path.getPeerId(), destPeer, peerPT, localTK, destPeerRole) &&
- peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath(this.bestPath.indexOf(path))))
- .forEach(path -> writeRoutePath(destPeer, routeId, peerPT, peerGroup, destPeerSupAddPath, path, rootPath, localTK, ribSup, tx));
+ this.bestPath.stream().filter(path -> filterRoutes(path.getPeerId(), destPeer, peerPT, localTK,
+ destPeerRole) && peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath,
+ isFirstBestPath(this.bestPath.indexOf(path)))).forEach(path -> writeRoutePath(destPeer, routeId,
+ peerPT, peerGroup, destPeerSupAddPath, path, rootPath, localTK, ribSup, tx));
}
}
private void writeRoutePath(final PeerId destPeer, final PathArgument routeId, final ExportPolicyPeerTracker peerPT,
- final PeerExportGroup peerGroup, final boolean destPeerSupAddPath,
- final BestPath path, final YangInstanceIdentifier rootPath, final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
+ final PeerExportGroup peerGroup, final boolean destPeerSupAddPath, final BestPath path,
+ final YangInstanceIdentifier rootPath, final TablesKey localTK, final RIBSupport ribSup,
+ final DOMDataWriteTransaction tx) {
final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeId);
- final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(getRoutePeerIdRole(peerPT,path.getPeerId()), path.getAttributes());
+ final ContainerNode effectiveAttributes = peerGroup
+ .effectiveAttributes(getRoutePeerIdRole(peerPT,path.getPeerId()), path.getAttributes());
if (destPeerSupAddPath) {
- writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK), effectiveAttributes, createValue(routeIdAddPath, path), ribSup, tx);
+ writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK), effectiveAttributes,
+ createValue(routeIdAddPath, path), ribSup, tx);
} else {
- writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeId, localTK), effectiveAttributes, createValue(routeId, path), ribSup, tx);
+ writeRoute(destPeer, getAdjRibOutYII(ribSup, rootPath, routeId, localTK), effectiveAttributes,
+ createValue(routeId, path), ribSup, tx);
}
}
- private void addPathToDataStore(final BestPath path, final boolean isFirstBestPath, final PathArgument routeIdPA, final YangInstanceIdentifier locRibTarget,
- final RIBSupport ribSup, final ExportPolicyPeerTracker peerPT, final TablesKey localTK, final DOMDataWriteTransaction tx) {
+ private void addPathToDataStore(final BestPath path, final boolean isFirstBestPath, final PathArgument routeIdPA,
+ final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup, final ExportPolicyPeerTracker peerPT,
+ final TablesKey localTK, final DOMDataWriteTransaction tx) {
final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
- final YangInstanceIdentifier pathAddPathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdAddPath);
+ final YangInstanceIdentifier pathAddPathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER),
+ routeIdAddPath);
final MapEntryNode addPathValue = createValue(routeIdAddPath, path);
final MapEntryNode value = createValue(routeIdPA, path);
LOG.trace("Selected best value {}", addPathValue);
fillLocRib(pathAddPathTarget, addPathValue, tx);
- fillAdjRibsOut(isFirstBestPath, path.getAttributes(), value, addPathValue, routeIdPA, routeIdAddPath, path.getPeerId(), peerPT, localTK,
+ fillAdjRibsOut(isFirstBestPath, path.getAttributes(), value, addPathValue, routeIdPA, routeIdAddPath,
+ path.getPeerId(), peerPT, localTK,
ribSup, tx);
}
- private void fillAdjRibsOut(final boolean isFirstBestPath, final ContainerNode attributes, final NormalizedNode<?, ?> value, final MapEntryNode addPathValue,
- final PathArgument routeId, final PathArgument routeIdAddPath, final PeerId routePeerId, final ExportPolicyPeerTracker peerPT, final TablesKey
- localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
+ private void fillAdjRibsOut(final boolean isFirstBestPath, final ContainerNode attributes,
+ final NormalizedNode<?, ?> value, final MapEntryNode addPathValue, final PathArgument routeId,
+ final PathArgument routeIdAddPath, final PeerId routePeerId, final ExportPolicyPeerTracker peerPT,
+ final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
/*
* We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
* expose from which client a particular route was learned from in the local RIB, and have
for (final PeerRole role : PeerRole.values()) {
final PeerExportGroup peerGroup = peerPT.getPeerGroup(role);
if (peerGroup != null) {
- final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(getRoutePeerIdRole(peerPT, routePeerId), attributes);
+ final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(getRoutePeerIdRole(peerPT,
+ routePeerId), attributes);
peerGroup.forEach((destPeer, rootPath) -> {
final boolean destPeerSupAddPath = peerPT.isAddPathSupportedByPeer(destPeer);
- if (filterRoutes(routePeerId, destPeer, peerPT, localTK, role) &&
- peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
+ if (filterRoutes(routePeerId, destPeer, peerPT, localTK, role)
+ && peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
if (destPeerSupAddPath) {
- update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK), effectiveAttributes,
- addPathValue, ribSup, tx);
- } else if(!this.oldNonAddPathBestPathTheSame){
- update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeId, localTK), effectiveAttributes, value, ribSup, tx);
+ update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeIdAddPath, localTK),
+ effectiveAttributes, addPathValue, ribSup, tx);
+ } else if (!this.oldNonAddPathBestPathTheSame) {
+ update(destPeer, getAdjRibOutYII(ribSup, rootPath, routeId, localTK),
+ effectiveAttributes, value, ribSup, tx);
}
}
});
}
/**
- * Process best path selection
+ * Process best path selection.
*
* @param localAs The local autonomous system number
* @param keyList List of RouteKey
protected boolean isBestPathNew(final List<AddPathBestPath> newBestPathList) {
this.oldNonAddPathBestPathTheSame = isNonAddPathBestPathTheSame(newBestPathList);
filterRemovedPaths(newBestPathList);
- if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty() || newBestPathList != null && !newBestPathList.equals(this.bestPath)) {
+ if (this.bestPathRemoved != null && !this.bestPathRemoved.isEmpty() || newBestPathList != null
+ && !newBestPathList.equals(this.bestPath)) {
this.newBestPathToBeAdvertised = new ArrayList<>(newBestPathList);
- if(this.bestPath != null) {
+ if (this.bestPath != null) {
this.newBestPathToBeAdvertised.removeAll(this.bestPath);
}
this.bestPath = newBestPathList;
}
private boolean isNonAddPathBestPathTheSame(final List<AddPathBestPath> newBestPathList) {
- return !(isEmptyOrNull(this.bestPath) || isEmptyOrNull(newBestPathList)) &&
- this.bestPath.get(0).equals(newBestPathList.get(0));
+ return !(isEmptyOrNull(this.bestPath) || isEmptyOrNull(newBestPathList))
+ && this.bestPath.get(0).equals(newBestPathList.get(0));
}
private static boolean isEmptyOrNull(final List<AddPathBestPath> pathList) {
}
private void filterRemovedPaths(final List<AddPathBestPath> newBestPathList) {
- if(this.bestPath == null) {
+ if (this.bestPath == null) {
return;
}
this.bestPathRemoved = new ArrayList<>(this.bestPath);
this.bestPath.forEach(oldBest -> {
final Optional<AddPathBestPath> present = newBestPathList.stream()
- .filter(newBest -> newBest.getPathId() == oldBest.getPathId() && newBest.getRouteKey() == oldBest.getRouteKey()).findAny();
+ .filter(newBest -> newBest.getPathId() == oldBest.getPathId()
+ && newBest.getRouteKey() == oldBest.getRouteKey()).findAny();
present.ifPresent(addPathBestPath -> this.bestPathRemoved.remove(oldBest));
});
}
private final int offsetPosition;
private final long pathId;
- public AddPathBestPath(@Nonnull final BestPathState state, @Nonnull final RouteKey key, final int offsetPosition, final Long pathId) {
+ public AddPathBestPath(@Nonnull final BestPathState state, @Nonnull final RouteKey key, final int offsetPosition,
+ final Long pathId) {
super(state);
this.routeKey = requireNonNull(key);
this.offsetPosition = offsetPosition;
return false;
}
/*
- We don't check offset position since it will change as new path is added, and we want to be able to use List comparison between old
- bestpath list and new best path list.
+ We don't check offset position since it will change as new path is added, and we want to be able
+ to use List comparison between old bestpath list and new best path list.
*/
if (!this.state.equals(other.state)) {
return false;
}
@Override
- public final UnsignedInteger getRouterId() {
+ public UnsignedInteger getRouterId() {
return this.routeKey.getRouteId();
}
@Override
- public final PeerId getPeerId() {
+ public PeerId getPeerId() {
return RouterIds.createPeerId(this.routeKey.getRouteId());
}
}
public AddPathBestPath result() {
- return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey, this.bestOffsetPosition, this.bestPathId);
+ return this.bestRouteKey == null ? null : new AddPathBestPath(this.bestState, this.bestRouteKey,
+ this.bestOffsetPosition, this.bestPathId);
}
}
* array members and array management features.
*/
public final class OffsetMap {
- static final OffsetMap EMPTY = new OffsetMap(Collections.emptySet());
private static final Logger LOG = LoggerFactory.getLogger(OffsetMap.class);
private static final String NEGATIVEOFFSET = "Invalid negative offset %s";
private static final String INVALIDOFFSET = "Invalid offset %s for %s router IDs";
- private static final LoadingCache<Set<RouteKey>, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder().weakValues().build(
- new CacheLoader<Set<RouteKey>, OffsetMap>() {
- @Override
- public OffsetMap load(@Nonnull final Set<RouteKey> key) throws Exception {
- return new OffsetMap(key);
- }
- });
+ private static final LoadingCache<Set<RouteKey>, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder().weakValues()
+ .build(new CacheLoader<Set<RouteKey>, OffsetMap>() {
+ @Override
+ public OffsetMap load(@Nonnull final Set<RouteKey> key) {
+ return new OffsetMap(key);
+ }
+ });
private static final Comparator<RouteKey> COMPARATOR = RouteKey::compareTo;
+ static final OffsetMap EMPTY = new OffsetMap(Collections.emptySet());
+
private final RouteKey[] routeKeys;
private OffsetMap(final Set<RouteKey> routerIds) {
public RouteKey(final UnsignedInteger routerId, final Long remotePathId) {
this.routerId = routerId;
- this.remotePathId = remotePathId == null ? 0 : remotePathId;
+ this.remotePathId = remotePathId != null ? remotePathId : 0;
}
private Long getExternalPathId() {
@Override
public int compareTo(@Nonnull final RouteKey otherRouteKey) {
final int routeIdCompareTo = this.routerId.compareTo(otherRouteKey.getRouteId());
- return routeIdCompareTo == 0 ? this.remotePathId.compareTo(otherRouteKey.getExternalPathId()) : routeIdCompareTo;
+ return routeIdCompareTo == 0 ? this.remotePathId.compareTo(otherRouteKey.getExternalPathId())
+ : routeIdCompareTo;
}
}
requireNonNull(key.getRouteId(), "Router ID may not be null");
if (attributes != null) {
final BestPathState state = new BestPathStateImpl(attributes);
- final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset, this.offsets.getValue(this.pathsId, offset));
+ final AddPathBestPath bestPath = new AddPathBestPath(state, key, offset,
+ this.offsets.getValue(this.pathsId, offset));
newBestPathList.add(bestPath);
}
}
import org.opendaylight.protocol.bgp.mode.impl.add.OffsetMap;
import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
import org.opendaylight.protocol.bgp.mode.spi.RouteEntryUtil;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
}
@Override
- public MapEntryNode createValue(final YangInstanceIdentifier.PathArgument routeId, final BestPath path) {
+ public MapEntryNode createValue(final PathArgument routeId, final BestPath path) {
final OffsetMap map = getOffsets();
final MapEntryNode mapValues = map.getValue(this.values, map.offsetOf(((AddPathBestPath) path).getRouteKey()));
return RouteEntryUtil.createComplexRouteValue(routeId, path, mapValues);
}
@Override
- public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final YangInstanceIdentifier.NodeIdentifier attII, final NormalizedNode<?, ?> data) {
+ public int addRoute(final UnsignedInteger routerId, final Long remotePathId,
+ final NodeIdentifier attII, final NormalizedNode<?, ?> data) {
final OffsetMap oldMap = getOffsets();
final int offset = addRoute(new RouteKey(routerId, remotePathId), attII, data);
final OffsetMap newMap = getOffsets();
}
@Override
- public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attII, final NormalizedNode<?, ?> data) {
+ public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attII,
+ final NormalizedNode<?, ?> data) {
return addRoute(new RouteKey(routerId, remotePathId), attII, data);
}
}
import org.opendaylight.protocol.bgp.mode.impl.add.RouteKey;
abstract class AbstractNPathsRouteEntry extends AddPathAbstractRouteEntry {
- private final long nBestPaths;
+ private final long npaths;
- AbstractNPathsRouteEntry(final Long nBestPaths) {
- this.nBestPaths = nBestPaths;
+ AbstractNPathsRouteEntry(final Long npaths) {
+ this.npaths = npaths;
}
@Override
public final boolean selectBest(final long localAs) {
final List<AddPathBestPath> newBestPathList = new ArrayList<>();
final List<RouteKey> keyList = this.offsets.getRouteKeysList();
- final long maxSearch = this.nBestPaths < this.offsets.size() && this.nBestPaths != 0 ? this.nBestPaths : this.offsets.size();
+ final long maxSearch = this.npaths < this.offsets.size()
+ && this.npaths != 0 ? this.npaths : this.offsets.size();
for (long i = 0; i < maxSearch; ++i) {
final AddPathBestPath newBest = selectBest(localAs, keyList);
newBestPathList.add(newBest);
import org.opendaylight.protocol.bgp.mode.api.RouteEntry;
public class AddPathBestNPathSelection implements PathSelectionMode {
- private final Long nBestPaths;
+ private final Long npaths;
- public AddPathBestNPathSelection(final Long nBestPaths) {
- this.nBestPaths = nBestPaths;
+ public AddPathBestNPathSelection(final Long npaths) {
+ this.npaths = npaths;
}
@Override
}
public Long getNBestPaths() {
- return this.nBestPaths;
+ return this.npaths;
}
}
\ No newline at end of file
private static final MapEntryNode[] EMPTY_VALUES = new MapEntryNode[0];
private MapEntryNode[] values = EMPTY_VALUES;
- public ComplexRouteEntry(final Long nBestPaths) {
- super(nBestPaths);
+ ComplexRouteEntry(final Long npaths) {
+ super(npaths);
}
@Override
}
@Override
- public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
+ public int addRoute(final UnsignedInteger routerId, final Long remotePathId,
+ final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
final OffsetMap oldMap = getOffsets();
final int offset = addRoute(new RouteKey(routerId, remotePathId), attributesIdentifier, data);
final OffsetMap newMap = getOffsets();
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class SimpleRouteEntry extends AbstractNPathsRouteEntry {
- public SimpleRouteEntry(final Long nBestPaths) {
- super(nBestPaths);
+ SimpleRouteEntry(final Long npaths) {
+ super(npaths);
}
@Override
}
@Override
- public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
+ public int addRoute(final UnsignedInteger routerId, final Long remotePathId,
+ final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
return addRoute(new RouteKey(routerId, remotePathId), attributesIdentifier, data);
}
}
\ No newline at end of file
private BaseBestPath bestPath;
private BaseBestPath removedBestPath;
- private int addRoute(final UnsignedInteger routerId, final ContainerNode attributes) {
- int offset = this.offsets.offsetOf(routerId);
- if (offset < 0) {
- final OffsetMap newOffsets = this.offsets.with(routerId);
- offset = newOffsets.offsetOf(routerId);
-
- this.values = newOffsets.expand(this.offsets, this.values, offset);
- this.offsets = newOffsets;
- }
-
- this.offsets.setValue(this.values, offset, attributes);
- LOG.trace("Added route from {} attributes {}", routerId, attributes);
- return offset;
- }
-
/**
- * Remove route
+ * Remove route.
*
* @param routerId router ID in unsigned integer
- * @param offset of removed route
+ * @param offset of removed route
* @return true if its the last route
*/
protected final boolean removeRoute(final UnsignedInteger routerId, final int offset) {
final BaseBestPath newBestPath = selector.result();
final boolean modified = newBestPath == null || !newBestPath.equals(this.bestPath);
if (modified) {
- if(this.offsets.isEmpty()) {
+ if (this.offsets.isEmpty()) {
this.removedBestPath = this.bestPath;
}
LOG.trace("Previous best {}, current best {}", this.bestPath, newBestPath);
}
@Override
- public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
+ public int addRoute(final UnsignedInteger routerId, final Long remotePathId,
+ final NodeIdentifier attributesIdentifier, final NormalizedNode<?, ?> data) {
LOG.trace("Find {} in {}", attributesIdentifier, data);
- final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes.findNode(data, attributesIdentifier).orNull();
- return addRoute(routerId, advertisedAttrs);
+ final ContainerNode advertisedAttrs = (ContainerNode) NormalizedNodes
+ .findNode(data, attributesIdentifier).orNull();
+ int offset = this.offsets.offsetOf(routerId);
+ if (offset < 0) {
+ final OffsetMap newOffsets = this.offsets.with(routerId);
+ offset = newOffsets.offsetOf(routerId);
+
+ this.values = newOffsets.expand(this.offsets, this.values, offset);
+ this.offsets = newOffsets;
+ }
+
+ this.offsets.setValue(this.values, offset, advertisedAttrs);
+ LOG.trace("Added route from {} attributes {}", routerId, advertisedAttrs);
+ return offset;
}
@Override
- public void updateRoute(final TablesKey localTK, final ExportPolicyPeerTracker peerPT, final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup,
- final DOMDataWriteTransaction tx, final PathArgument routeIdPA) {
+ public void updateRoute(final TablesKey localTK, final ExportPolicyPeerTracker peerPT,
+ final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup,
+ final DOMDataWriteTransaction tx, final PathArgument routeIdPA) {
if (this.removedBestPath != null) {
removePathFromDataStore(this.removedBestPath, routeIdPA, locRibTarget, peerPT, localTK, ribSup, tx);
this.removedBestPath = null;
}
@Override
- public void writeRoute(final PeerId destPeer, final PathArgument routeId, final YangInstanceIdentifier rootPath, final PeerExportGroup peerGroup,
- final TablesKey localTK, final ExportPolicyPeerTracker peerPT, final RIBSupport ribSupport, final DOMDataWriteTransaction tx) {
+ public void writeRoute(final PeerId destPeer, final PathArgument routeId, final YangInstanceIdentifier rootPath,
+ final PeerExportGroup peerGroup, final TablesKey localTK, final ExportPolicyPeerTracker peerPT,
+ final RIBSupport ribSupport, final DOMDataWriteTransaction tx) {
if (this.bestPath != null) {
final BaseBestPath path = this.bestPath;
final PeerRole destPeerRole = getRoutePeerIdRole(peerPT, destPeer);
if (filterRoutes(path.getPeerId(), destPeer, peerPT, localTK, destPeerRole)) {
- final ContainerNode effAttrib = peerGroup.effectiveAttributes(getRoutePeerIdRole(peerPT,path.getPeerId()), path.getAttributes());
+ final ContainerNode effAttrib = peerGroup.effectiveAttributes(
+ getRoutePeerIdRole(peerPT, path.getPeerId()), path.getAttributes());
writeRoute(destPeer, getAdjRibOutYII(ribSupport, rootPath, routeId, localTK), effAttrib,
- createValue(routeId, path), ribSupport, tx);
+ createValue(routeId, path), ribSupport, tx);
}
}
}
- private void removePathFromDataStore(final BestPath path, final PathArgument routeIdPA, final YangInstanceIdentifier locRibTarget,
- final ExportPolicyPeerTracker peerPT, final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
+ private void removePathFromDataStore(final BestPath path, final PathArgument routeIdPA,
+ final YangInstanceIdentifier locRibTarget, final ExportPolicyPeerTracker peerPT,
+ final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
LOG.trace("Best Path removed {}", path);
final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
final YangInstanceIdentifier pathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdPA);
fillAdjRibsOut(null, null, routeIdPA, path.getPeerId(), peerPT, localTK, ribSup, tx);
}
- private void addPathToDataStore(final BestPath path, final PathArgument routeIdPA, final YangInstanceIdentifier locRibTarget,
- final RIBSupport ribSup, final ExportPolicyPeerTracker peerPT, final TablesKey localTK, final DOMDataWriteTransaction tx) {
+ private void addPathToDataStore(final BestPath path, final PathArgument routeIdPA,
+ final YangInstanceIdentifier locRibTarget, final RIBSupport ribSup, final ExportPolicyPeerTracker peerPT,
+ final TablesKey localTK, final DOMDataWriteTransaction tx) {
final PathArgument routeIdAddPath = ribSup.getRouteIdAddPath(path.getPathId(), routeIdPA);
final YangInstanceIdentifier pathTarget = ribSup.routePath(locRibTarget.node(ROUTES_IDENTIFIER), routeIdPA);
final NormalizedNode<?, ?> value = createValue(routeIdPA, path);
addPathValue = createValue(routeIdAddPath, path);
LOG.trace("Selected best value {}", addPathValue);
}
- fillLocRib(pathAddPathTarget == null ? pathTarget : pathAddPathTarget, addPathValue == null ? value : addPathValue, tx);
+ fillLocRib(pathAddPathTarget == null ? pathTarget : pathAddPathTarget,
+ addPathValue == null ? value : addPathValue, tx);
fillAdjRibsOut(path.getAttributes(), value, routeIdPA, path.getPeerId(), peerPT, localTK, ribSup, tx);
}
@VisibleForTesting
private void fillAdjRibsOut(final ContainerNode attributes, final NormalizedNode<?, ?> value,
- final PathArgument routeId, final PeerId routePeerId, final ExportPolicyPeerTracker peerPT,
- final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
+ final PathArgument routeId, final PeerId routePeerId, final ExportPolicyPeerTracker peerPT,
+ final TablesKey localTK, final RIBSupport ribSup, final DOMDataWriteTransaction tx) {
/*
* We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
* expose from which client a particular route was learned from in the local RIB, and have
final PeerExportGroup peerGroup = peerPT.getPeerGroup(role);
if (peerGroup != null) {
final ContainerNode effAttrib = peerGroup.effectiveAttributes(getRoutePeerIdRole(peerPT, routePeerId),
- attributes);
+ attributes);
peerGroup.forEach((destPeer, rootPath) -> {
if (!filterRoutes(routePeerId, destPeer, peerPT, localTK, getRoutePeerIdRole(peerPT, destPeer))) {
return;
private MapEntryNode[] values = EMPTY_VALUES;
@Override
- public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attrII, final NormalizedNode<?, ?> data) {
+ public int addRoute(final UnsignedInteger routerId, final Long remotePathId, final NodeIdentifier attrII,
+ final NormalizedNode<?, ?> data) {
final OffsetMap oldMap = getOffsets();
final int offset = super.addRoute(routerId, remotePathId, attrII, data);
final OffsetMap newMap = getOffsets();
* array members and array management features.
*/
final class OffsetMap {
- static final OffsetMap EMPTY = new OffsetMap(Collections.emptySet());
private static final Logger LOG = LoggerFactory.getLogger(OffsetMap.class);
private static final String NEGATIVEOFFSET = "Invalid negative offset %s";
private static final String INVALIDOFFSET = "Invalid offset %s for %s router IDs";
- private static final LoadingCache<Set<UnsignedInteger>, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder().weakValues().build(
- new CacheLoader<Set<UnsignedInteger>, OffsetMap>() {
- @Override
- public OffsetMap load(@Nonnull final Set<UnsignedInteger> key) throws Exception {
- return new OffsetMap(key);
- }
- });
+ private static final LoadingCache<Set<UnsignedInteger>, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder()
+ .weakValues().build(new CacheLoader<Set<UnsignedInteger>, OffsetMap>() {
+ @Override
+ public OffsetMap load(@Nonnull final Set<UnsignedInteger> key) {
+ return new OffsetMap(key);
+ }
+ });
private static final Comparator<UnsignedInteger> COMPARATOR = UnsignedInteger::compareTo;
+ static final OffsetMap EMPTY = new OffsetMap(Collections.emptySet());
private final UnsignedInteger[] routeKeys;
private OffsetMap(final Set<UnsignedInteger> routerIds) {
this.state = requireNonNull(state);
}
- protected abstract MoreObjects.ToStringHelper addToStringAttributes(final MoreObjects.ToStringHelper toStringHelper);
+ protected abstract MoreObjects.ToStringHelper addToStringAttributes(MoreObjects.ToStringHelper toStringHelper);
@VisibleForTesting
public final BestPathState getState() {
public class AbstractBestPathSelector {
private static final Collection<YangInstanceIdentifier.PathArgument> ORIGINATOR_ID = ImmutableList.of(new
- YangInstanceIdentifier.NodeIdentifier(OriginatorId.QNAME), new YangInstanceIdentifier.NodeIdentifier(QName.create(OriginatorId.QNAME, "originator")));
+ YangInstanceIdentifier.NodeIdentifier(OriginatorId.QNAME),
+ new YangInstanceIdentifier.NodeIdentifier(QName.create(OriginatorId.QNAME, "originator")));
private final Long ourAs;
protected UnsignedInteger bestOriginatorId = null;
protected static boolean filterRoutes(final PeerId rootPeer, final PeerId destPeer,
final ExportPolicyPeerTracker peerPT, final TablesKey localTK, final PeerRole destPeerRole) {
- return !rootPeer.equals(destPeer) && isTableSupportedAndReady(destPeer, peerPT, localTK) && !PeerRole.Internal.equals(destPeerRole);
+ return !rootPeer.equals(destPeer) && isTableSupportedAndReady(destPeer, peerPT, localTK)
+ && !PeerRole.Internal.equals(destPeerRole);
}
- private static boolean isTableSupportedAndReady(final PeerId destPeer, final ExportPolicyPeerTracker peerPT, final TablesKey localTK) {
+ private static boolean isTableSupportedAndReady(final PeerId destPeer, final ExportPolicyPeerTracker peerPT,
+ final TablesKey localTK) {
if (!peerPT.isTableSupported(destPeer) || !peerPT.isTableStructureInitialized(destPeer)) {
LOG.trace("Route rejected, peer {} does not support this table type {}", destPeer, localTK);
return false;
protected static YangInstanceIdentifier getAdjRibOutYII(final RIBSupport ribSup,
final YangInstanceIdentifier rootPath, final PathArgument routeId, final TablesKey localTK) {
- return ribSup.routePath(rootPath.node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(localTK))
- .node(ROUTES_IDENTIFIER), routeId);
+ return ribSup.routePath(rootPath.node(AdjRibOut.QNAME).node(Tables.QNAME)
+ .node(RibSupportUtils.toYangTablesKey(localTK)).node(ROUTES_IDENTIFIER), routeId);
}
protected PeerRole getRoutePeerIdRole(final ExportPolicyPeerTracker peerPT, final PeerId routePeerId) {
return b.build();
}
- public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path, final MapEntryNode mapValues) {
- final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = Builders.mapEntryBuilder();
+ public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path,
+ final MapEntryNode mapValues) {
+ final DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder
+ = Builders.mapEntryBuilder();
mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) routeId);
mapEntryBuilder.addChild(path.getAttributes());
mapValues.getValue().forEach(mapEntryBuilder::addChild);
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
public abstract class AbstractRouteEntryTest {
protected static final long REMOTE_PATH_ID = 1;
protected static final PeerId PEER_ID = new PeerId("bgp://42.42.42.42");
- protected static final YangInstanceIdentifier PEER_YII2 = YangInstanceIdentifier.of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test", "2015-03-05", "peer2"));
+ protected static final YangInstanceIdentifier PEER_YII2 = YangInstanceIdentifier
+ .of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test",
+ "2015-03-05", "peer2"));
protected static final long AS = 64444;
protected static final UnsignedInteger ROUTER_ID = UnsignedInteger.ONE;
- protected static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- protected static final YangInstanceIdentifier LOC_RIB_TARGET = YangInstanceIdentifier.create(YangInstanceIdentifier.of(BgpRib.QNAME)
- .node(LocRib.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).getPathArguments());
+ protected static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class,
+ UnicastSubsequentAddressFamily.class);
+ protected static final YangInstanceIdentifier LOC_RIB_TARGET =
+ YangInstanceIdentifier.create(YangInstanceIdentifier.of(BgpRib.QNAME).node(LocRib.QNAME)
+ .node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).getPathArguments());
private static final long PATH_ID = 1;
private static final PeerId PEER_ID2 = new PeerId("bgp://43.43.43.43");
private static final String PREFIX = "1.2.3.4/32";
private static final String PREFIX2 = "2.2.2.2/32";
- private static final YangInstanceIdentifier PEER_YII = YangInstanceIdentifier.of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test", "2015-03-05", "peer1"));
+ private static final YangInstanceIdentifier PEER_YII
+ = YangInstanceIdentifier.of(QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet:test",
+ "2015-03-05", "peer1"));
private static final NodeIdentifier ROUTES_IDENTIFIER = new NodeIdentifier(Routes.QNAME);
- private static final NodeIdentifier ORIGIN_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, Origin.QNAME.getLocalName()).intern());
- private static final NodeIdentifier ORIGIN_VALUE_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, "value").intern());
- private static final NodeIdentifier AS_PATH_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, AsPath.QNAME.getLocalName()).intern());
- private static final NodeIdentifier ATOMIC_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, AtomicAggregate.QNAME.getLocalName()));
+ private static final NodeIdentifier ORIGIN_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ Origin.QNAME.getLocalName()).intern());
+ private static final NodeIdentifier ORIGIN_VALUE_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ "value").intern());
+ private static final NodeIdentifier AS_PATH_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ AsPath.QNAME.getLocalName()).intern());
+ private static final NodeIdentifier ATOMIC_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ AtomicAggregate.QNAME.getLocalName()));
private static final QName Q_NAME = BindingReflections.findQName(Ipv4Routes.class).intern();
- private static final NodeIdentifier ROUTE_ATTRIBUTES_IDENTIFIER = new NodeIdentifier(QName.create(Q_NAME, Attributes.QNAME.getLocalName().intern()));
- private static final QName PREFIX_QNAME = QName.create(Ipv4Route.QNAME, "prefix").intern();
- protected static final NodeIdentifierWithPredicates ROUTE_ID_PA = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PREFIX_QNAME, PREFIX));
+ private static final NodeIdentifier ROUTE_ATTRIBUTES_IDENTIFIER
+ = new NodeIdentifier(QName.create(Q_NAME, Attributes.QNAME.getLocalName().intern()));
+ private static final QName PREFIX_QNAME
+ = QName.create(Ipv4Route.QNAME, "prefix").intern();
+ protected static final NodeIdentifierWithPredicates ROUTE_ID_PA
+ = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PREFIX_QNAME, PREFIX));
private static final QName PATHID_QNAME = QName.create(Ipv4Route.QNAME, "path-id").intern();
- protected static final NodeIdentifierWithPredicates ROUTE_ID_PA_ADD_PATH = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, ImmutableMap.of(PATHID_QNAME, PATH_ID, PREFIX_QNAME, PREFIX2));
+ protected static final NodeIdentifierWithPredicates ROUTE_ID_PA_ADD_PATH
+ = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+ ImmutableMap.of(PATHID_QNAME, PATH_ID, PREFIX_QNAME, PREFIX2));
@Mock
protected RIBSupport ribSupport;
@Mock
protected ExportPolicyPeerTracker peerPT;
@Mock
protected PeerExportGroup peg;
- protected List<YangInstanceIdentifier> yIIChanges;
+ protected List<YangInstanceIdentifier> yiichanges;
protected NormalizedNode<?, ?> attributes;
protected YangInstanceIdentifier routePaYii;
protected YangInstanceIdentifier routePaAddPathYii;
protected void setUp() {
MockitoAnnotations.initMocks(this);
- this.yIIChanges = new ArrayList<>();
+ this.yiichanges = new ArrayList<>();
this.attributes = createAttr();
this.locRibTargetYii = LOC_RIB_TARGET.node(ROUTES_IDENTIFIER);
- this.locRibOutTargetYii = PEER_YII.node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
+ this.locRibOutTargetYii = PEER_YII.node(AdjRibOut.QNAME).node(Tables.QNAME)
+ .node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
this.routePaYii = this.locRibTargetYii.node(ROUTE_ID_PA);
this.routePaAddPathYii = this.locRibTargetYii.node(ROUTE_ID_PA_ADD_PATH);
this.routeRiboutYii = this.locRibOutTargetYii.node(ROUTE_ID_PA);
this.routeAddRiboutYii = this.locRibOutTargetYii.node(ROUTE_ID_PA_ADD_PATH);
this.routeRiboutAttYii = this.locRibOutTargetYii.node(ROUTE_ID_PA).node(ATTRS_EXTENSION_Q);
this.routeAddRiboutAttYii = this.locRibOutTargetYii.node(ROUTE_ID_PA_ADD_PATH).node(ATTRS_EXTENSION_Q);
- this.locRibOutTargetYiiPeer2 = PEER_YII2.node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
+ this.locRibOutTargetYiiPeer2 = PEER_YII2.node(AdjRibOut.QNAME).node(Tables.QNAME)
+ .node(RibSupportUtils.toYangTablesKey(TABLES_KEY)).node(ROUTES_IDENTIFIER);
this.routeRiboutYiiPeer2 = this.locRibOutTargetYiiPeer2.node(ROUTE_ID_PA);
this.routeRiboutAttYiiPeer2 = this.locRibOutTargetYiiPeer2.node(ROUTE_ID_PA).node(ATTRS_EXTENSION_Q);
this.routeAddRiboutYiiPeer2 = this.locRibOutTargetYiiPeer2.node(ROUTE_ID_PA_ADD_PATH);
private void mockTransactionChain() {
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
- this.yIIChanges.add((YangInstanceIdentifier) args[1]);
+ this.yiichanges.add((YangInstanceIdentifier) args[1]);
return args[1];
- }).when(this.tx).put(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ }).when(this.tx)
+ .put(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
if (this.routePaYii.equals(args[1])) {
- this.yIIChanges.remove(this.routePaYii);
+ this.yiichanges.remove(this.routePaYii);
} else if (this.routePaAddPathYii.equals(args[1])) {
- this.yIIChanges.remove(this.routePaAddPathYii);
+ this.yiichanges.remove(this.routePaAddPathYii);
} else if (this.routeRiboutYii.equals(args[1])) {
- this.yIIChanges.remove(this.routeRiboutYii);
- this.yIIChanges.remove(this.routeAddRiboutAttYii);
+ this.yiichanges.remove(this.routeRiboutYii);
+ this.yiichanges.remove(this.routeAddRiboutAttYii);
} else if (this.routeAddRiboutYii.equals(args[1])) {
- this.yIIChanges.remove(this.routeAddRiboutYii);
- this.yIIChanges.remove(this.routeAddRiboutAttYii);
+ this.yiichanges.remove(this.routeAddRiboutYii);
+ this.yiichanges.remove(this.routeAddRiboutAttYii);
}
return args[1];
}).when(this.tx).delete(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class));
private void mockRibSupport() {
doReturn(ROUTE_ATTRIBUTES_IDENTIFIER).when(this.ribSupport).routeAttributesIdentifier();
- doReturn(ROUTE_ID_PA_ADD_PATH).when(this.ribSupport).getRouteIdAddPath(any(Long.class), eq(ROUTE_ID_PA_ADD_PATH));
+ doReturn(ROUTE_ID_PA_ADD_PATH).when(this.ribSupport)
+ .getRouteIdAddPath(any(Long.class), eq(ROUTE_ID_PA_ADD_PATH));
doReturn(null).when(this.ribSupport).getRouteIdAddPath(any(Long.class), eq(ROUTE_ID_PA));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
}
private static NormalizedNode<?, ?> createAttr() {
- final ContainerNode attributes = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(ATTRS_EXTENSION_Q))
+ final ContainerNode attributes = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(ATTRS_EXTENSION_Q))
.addChild(Builders.containerBuilder().withNodeIdentifier(ORIGIN_NID)
- .addChild(Builders.leafBuilder().withNodeIdentifier(ORIGIN_VALUE_NID).withValue("igp").build()).build())
+ .addChild(Builders.leafBuilder().withNodeIdentifier(ORIGIN_VALUE_NID)
+ .withValue("igp").build()).build())
.addChild(Builders.containerBuilder().withNodeIdentifier(AS_PATH_NID)
.addChild(Builders.unkeyedListBuilder().withNodeIdentifier(SEGMENTS_NID).build()).build())
.addChild(Builders.containerBuilder().withNodeIdentifier(ATOMIC_NID).build()).build();
return ImmutableContainerNodeBuilder.create().withNodeIdentifier(ROUTE_ATTRIBUTES_IDENTIFIER)
.withChild(attributes).build();
}
+
+ protected Map<YangInstanceIdentifier, Long> collectInfo() {
+ return this.yiichanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ }
}
import static org.junit.Assert.assertTrue;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.mode.impl.AbstractRouteEntryTest;
}
private void testAddRouteSelectBestAndWriteOnDS() {
- this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
+ this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport
+ .routeAttributesIdentifier(), this.attributes);
assertFalse(this.testBARE.isEmpty());
assertTrue(this.testBARE.selectBest(AS));
/** Add AddPath Route **/
- this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA_ADD_PATH);
- Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport,
+ this.tx, ROUTE_ID_PA_ADD_PATH);
+ final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(3, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
}
private void testRemoveRoute() {
- Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(3, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
assertTrue(this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID));
assertTrue(this.testBARE.selectBest(AS));
- this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA_ADD_PATH);
- yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport,
+ this.tx, ROUTE_ID_PA_ADD_PATH);
+ yiiCount = collectInfo();
assertEquals(0, yiiCount.size());
assertFalse(yiiCount.containsKey(this.routePaAddPathYii));
assertFalse(yiiCount.containsKey(this.routeAddRiboutYii));
import static org.junit.Assert.assertTrue;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.mode.impl.AbstractRouteEntryTest;
}
private void testWriteEmptyBestPath() {
- this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, this.tx);
- assertEquals(0, this.yIIChanges.size());
+ this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport,
+ this.tx);
+ assertEquals(0, this.yiichanges.size());
}
private void testAddRouteSelectBestAndWriteOnDS() {
- this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(), this.attributes);
+ this.testBARE.addRoute(ROUTER_ID, REMOTE_PATH_ID, this.ribSupport.routeAttributesIdentifier(),
+ this.attributes);
assertFalse(this.testBARE.isEmpty());
assertTrue(this.testBARE.selectBest(AS));
/** Add AddPath Route **/
- this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA_ADD_PATH);
- Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx,
+ ROUTE_ID_PA_ADD_PATH);
+ final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(3, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
}
private void testInitializePeerWithExistentRoute() {
- assertEquals(3, this.yIIChanges.size());
- this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA_ADD_PATH, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, this.tx);
- assertEquals(5, this.yIIChanges.size());
- final Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream()
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ assertEquals(3, this.yiichanges.size());
+ this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA_ADD_PATH, PEER_YII2, this.peg, TABLES_KEY, this.peerPT,
+ this.ribSupport, this.tx);
+ assertEquals(5, this.yiichanges.size());
+ final Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2));
assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2));
}
private void testRemoveRoute() {
- Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(5, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
assertTrue(this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID));
assertTrue(this.testBARE.selectBest(AS));
- this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA_ADD_PATH);
- yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx,
+ ROUTE_ID_PA_ADD_PATH);
+ yiiCount = collectInfo();
assertEquals(2, yiiCount.size());
assertFalse(yiiCount.containsKey(this.routePaAddPathYii));
assertFalse(yiiCount.containsKey(this.routeAddRiboutYii));
@Before
public void setUp() throws Exception {
final BasePathSelector selector = new BasePathSelector(20L);
- selector.processPath(BasePathSelectorTest.ROUTER_ID2, BasePathSelectorTest.createStateFromPrefMedOriginASPath().build());
+ selector.processPath(BasePathSelectorTest.ROUTER_ID2,
+ BasePathSelectorTest.createStateFromPrefMedOriginASPath().build());
this.baseBestPath = selector.result();
this.baseBestPathCopy = selector.result();
}
@Test
public void testHashCodeAndEqual() throws Exception {
- assertTrue(this.baseBestPath.equals(this.baseBestPathCopy) && this.baseBestPathCopy.equals(this.baseBestPath));
+ assertTrue(this.baseBestPath.equals(this.baseBestPathCopy)
+ && this.baseBestPathCopy.equals(this.baseBestPath));
assertTrue(this.baseBestPath.hashCode() == this.baseBestPathCopy.hashCode());
assertTrue(this.baseBestPath.getPathId() == PATH_ID);
}
public class BasePathSelectorTest {
- public static final QName ATTRS_EXTENSION_Q = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet", "2017-12-07", "attributes");
+ public static final QName ATTRS_EXTENSION_Q = QName.create("urn:opendaylight:params:xml:ns:yang:bgp-inet",
+ "2017-12-07", "attributes");
public static final QName AS_NUMBER_Q = QName.create(ATTRS_EXTENSION_Q, "as-number");
- public static final NodeIdentifier SEGMENTS_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, Segments.QNAME.getLocalName()));
- public static final NodeIdentifier SEQ_LEAFLIST_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, "as-sequence"));
- public static final UnkeyedListEntryNode SEQ_SEGMENT = Builders.unkeyedListEntryBuilder().withNodeIdentifier(SEGMENTS_NID)
- .addChild(Builders.orderedLeafSetBuilder().withNodeIdentifier(SEQ_LEAFLIST_NID)
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 1L)).withValue(1L).build())
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 2L)).withValue(2L).build())
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 3L)).withValue(3L).build())
- .build()).build();
- private static final NodeIdentifier SET_LEAFLIST_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q, "as-set"));
- public static final UnkeyedListEntryNode SET_SEGMENT = Builders.unkeyedListEntryBuilder().withNodeIdentifier(SEGMENTS_NID)
- .addChild(Builders.leafSetBuilder().withNodeIdentifier(SET_LEAFLIST_NID)
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 10L)).withValue(10L).build())
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 11L)).withValue(11L).build())
- .build()).build();
- private static final UnkeyedListEntryNode SEQ_SEGMENT2 = Builders.unkeyedListEntryBuilder().withNodeIdentifier(SEGMENTS_NID)
- .addChild(Builders.orderedLeafSetBuilder().withNodeIdentifier(SEQ_LEAFLIST_NID)
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 20L)).withValue(20L).build())
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 2L)).withValue(2L).build())
- .addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 3L)).withValue(3L).build())
- .build()).build();
+ public static final NodeIdentifier SEGMENTS_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ Segments.QNAME.getLocalName()));
+ public static final NodeIdentifier SEQ_LEAFLIST_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ "as-sequence"));
+ public static final UnkeyedListEntryNode SEQ_SEGMENT = Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(SEGMENTS_NID).addChild(Builders.orderedLeafSetBuilder()
+ .withNodeIdentifier(SEQ_LEAFLIST_NID)
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 1L)).withValue(1L).build())
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 2L)).withValue(2L).build())
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 3L)).withValue(3L).build())
+ .build()).build();
+ private static final NodeIdentifier SET_LEAFLIST_NID = new NodeIdentifier(QName.create(ATTRS_EXTENSION_Q,
+ "as-set"));
+ public static final UnkeyedListEntryNode SET_SEGMENT = Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(SEGMENTS_NID).addChild(Builders.leafSetBuilder().withNodeIdentifier(SET_LEAFLIST_NID)
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 10L)).withValue(10L).build())
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 11L)).withValue(11L).build())
+ .build()).build();
+ private static final UnkeyedListEntryNode SEQ_SEGMENT2 = Builders.unkeyedListEntryBuilder()
+ .withNodeIdentifier(SEGMENTS_NID).addChild(Builders.orderedLeafSetBuilder()
+ .withNodeIdentifier(SEQ_LEAFLIST_NID)
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 20L)).withValue(20L).build())
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 2L)).withValue(2L).build())
+ .addChild(Builders.leafSetEntryBuilder()
+ .withNodeIdentifier(new NodeWithValue<>(AS_NUMBER_Q, 3L)).withValue(3L).build())
+ .build()).build();
private static final QName LOCAL_PREF_Q_NAME = QName.create(ATTRS_EXTENSION_Q, "local-pref");
private static final QName MULTI_EXIT_DISC_Q_NAME = QName.create(ATTRS_EXTENSION_Q, "multi-exit-disc");
private static final QName ORIGIN_Q_NAME = QName.create(ATTRS_EXTENSION_Q, "origin");
private static final QName AS_PATH_Q_NAME = QName.create(ATTRS_EXTENSION_Q, "as-path");
- private final UnsignedInteger ROUTER_ID = RouterIds.routerIdForAddress("127.0.0.1");
+ private static final UnsignedInteger ROUTER_ID = RouterIds.routerIdForAddress("127.0.0.1");
static final UnsignedInteger ROUTER_ID2 = RouterIds.routerIdForPeerId(new PeerId("bgp://127.0.0.1"));
- private final UnsignedInteger ROUTER_ID3 = RouterIds.routerIdForPeerId(new PeerId("bgp://127.0.0.2"));
+ private static final UnsignedInteger ROUTER_ID3 = RouterIds.routerIdForPeerId(new PeerId("bgp://127.0.0.2"));
private final BasePathSelector selector = new BasePathSelector(20L);
private final BestPathStateImpl state = new BestPathStateImpl(createStateFromPrefMedOriginASPath().build());
- private final BaseBestPath originBestPath = new BaseBestPath(this.ROUTER_ID, this.state);
+ private final BaseBestPath originBestPath = new BaseBestPath(ROUTER_ID, this.state);
@Test
public void testBestPathForEquality() {
@Test
public void testBestPathWithHigherLocalPref() {
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder = createContBuilder(ATTRS_EXTENSION_Q);
this.selector.processPath(ROUTER_ID2, createStateFromPrefMedOrigin()); // local-pref 123
BaseBestPath processedPath = this.selector.result();
assertEquals(123L, processedPath.getState().getLocalPref().longValue());
processedPath = this.selector.result();
assertEquals(321L, processedPath.getState().getLocalPref().longValue());
+ DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder =
+ createContBuilder(ATTRS_EXTENSION_Q);
addLowerLocalRef(dataContBuilder); // prefer path with higher LOCAL_PREF
this.selector.processPath(ROUTER_ID2, dataContBuilder.build());
processedPath = this.selector.result();
@Test
public void testBestPathSelectionOptions() {
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder = createStateFromPrefMedOriginASPath();
+ DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder
+ = createStateFromPrefMedOriginASPath();
this.selector.processPath(ROUTER_ID2, dataContBuilder.build());
BaseBestPath processedPath = this.selector.result();
assertEquals(1, processedPath.getState().getOrigin().getIntValue());
@Test
public void testBestPathForNonEquality() {
- this.selector.processPath(this.ROUTER_ID3, createStateFromPrefMedOrigin());
+ this.selector.processPath(ROUTER_ID3, createStateFromPrefMedOrigin());
final BaseBestPath processedPath = this.selector.result();
assertNotEquals(this.originBestPath.getPeerId(), processedPath.getPeerId());
}
private static ContainerNode createStateFromPrefMedOrigin() {
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder = createContBuilder(ATTRS_EXTENSION_Q);
+ DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder
+ = createContBuilder(ATTRS_EXTENSION_Q);
addLowerLocalRef(dataContBuilder);
addLowerMultiExitDisc(dataContBuilder);
addIgpOrigin(dataContBuilder);
}
static DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> createStateFromPrefMedOriginASPath() {
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder = createContBuilder(ATTRS_EXTENSION_Q);
+ DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder
+ = createContBuilder(ATTRS_EXTENSION_Q);
addHigherLocalRef(dataContBuilder);
addHigherMultiExitDisc(dataContBuilder);
addEgpOrigin(dataContBuilder);
return dataContBuilder;
}
- private static void addLowerLocalRef(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
- dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME).addChild(createValueBuilder(123L, LOCAL_PREF_Q_NAME, "pref").build()).build());
+ private static void addLowerLocalRef(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
+ dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME)
+ .addChild(createValueBuilder(123L, LOCAL_PREF_Q_NAME, "pref").build()).build());
}
- private static void addHigherLocalRef(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
- dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME).addChild(createValueBuilder(321L, LOCAL_PREF_Q_NAME, "pref").build()).build());
+ private static void addHigherLocalRef(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
+ dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME)
+ .addChild(createValueBuilder(321L, LOCAL_PREF_Q_NAME, "pref").build()).build());
}
- private static void addLowerMultiExitDisc(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
- dataContBuilder.addChild(createContBuilder(MULTI_EXIT_DISC_Q_NAME).addChild(createValueBuilder(1234L, MULTI_EXIT_DISC_Q_NAME, "med").build()).build());
+ private static void addLowerMultiExitDisc(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
+ dataContBuilder.addChild(createContBuilder(MULTI_EXIT_DISC_Q_NAME)
+ .addChild(createValueBuilder(1234L, MULTI_EXIT_DISC_Q_NAME, "med").build()).build());
}
- private static void addHigherMultiExitDisc(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
- dataContBuilder.addChild(createContBuilder(MULTI_EXIT_DISC_Q_NAME).addChild(createValueBuilder(4321L, MULTI_EXIT_DISC_Q_NAME, "med").build()).build());
+ private static void addHigherMultiExitDisc(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
+ dataContBuilder.addChild(createContBuilder(MULTI_EXIT_DISC_Q_NAME)
+ .addChild(createValueBuilder(4321L, MULTI_EXIT_DISC_Q_NAME, "med").build()).build());
}
- private static void addIgpOrigin(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
- dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME).addChild(createValueBuilder("igp", ORIGIN_Q_NAME, "value").build()).build());
+ private static void addIgpOrigin(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
+ dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME)
+ .addChild(createValueBuilder("igp", ORIGIN_Q_NAME, "value").build()).build());
}
- private static void addEgpOrigin(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
- dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME).addChild(createValueBuilder("egp", ORIGIN_Q_NAME, "value").build()).build());
+ private static void addEgpOrigin(
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder) {
+ dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME)
+ .addChild(createValueBuilder("egp", ORIGIN_Q_NAME, "value").build()).build());
}
- private static void addAsPath(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder, final UnkeyedListEntryNode segment) {
- final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> asPathContBuilder = ImmutableContainerNodeSchemaAwareBuilder.create();
+ private static void addAsPath(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder,
+ final UnkeyedListEntryNode segment) {
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> asPathContBuilder
+ = ImmutableContainerNodeSchemaAwareBuilder.create();
asPathContBuilder.withNodeIdentifier(new NodeIdentifier(AS_PATH_Q_NAME));
- final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> segments = ImmutableUnkeyedListNodeBuilder.create();
+ final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> segments
+ = ImmutableUnkeyedListNodeBuilder.create();
segments.withNodeIdentifier(SEGMENTS_NID);
segments.addChild(segment);
asPathContBuilder.addChild(segments.build());
return ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(new NodeIdentifier(qname));
}
- private static <T> ImmutableLeafNodeBuilder<T> createValueBuilder(final T value, final QName qname, final String localName) {
+ private static <T> ImmutableLeafNodeBuilder<T> createValueBuilder(final T value, final QName qname,
+ final String localName) {
final ImmutableLeafNodeBuilder<T> valueBuilder = new ImmutableLeafNodeBuilder<>();
valueBuilder.withNodeIdentifier(new NodeIdentifier(QName.create(qname, localName))).withValue(value);
return valueBuilder;
sequences.add(new AsNumber(2L));
sequences.add(new AsNumber(3L));
final List<Segments> expected = new ArrayList<>();
- expected.add(new SegmentsBuilder().setAsSet(Lists.newArrayList(new AsNumber(11L), new AsNumber(10L))).build());
+ expected.add(new SegmentsBuilder()
+ .setAsSet(Lists.newArrayList(new AsNumber(11L), new AsNumber(10L))).build());
expected.add(new SegmentsBuilder().setAsSequence(sequences).build());
// test
final List<Segments> actual = this.state.extractSegments(builder.build());
@Test(expected = IllegalArgumentException.class)
public void testBgpOrigin() {
- DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder = createContBuilder(ATTRS_EXTENSION_Q);
- final ContainerNode containerIncom = dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME).addChild(createValueBuilder("incomplete", ORIGIN_Q_NAME, "value").build()).build()).build();
- this.selector.processPath(this.ROUTER_ID3, containerIncom);
+ DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> dataContBuilder
+ = createContBuilder(ATTRS_EXTENSION_Q);
+ final ContainerNode containerIncom = dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME)
+ .addChild(createValueBuilder("incomplete", ORIGIN_Q_NAME, "value")
+ .build()).build()).build();
+ this.selector.processPath(ROUTER_ID3, containerIncom);
final BaseBestPath processedPathIncom = this.selector.result();
assertEquals(BgpOrigin.Incomplete, processedPathIncom.getState().getOrigin());
- final ContainerNode containerException = dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME).addChild(createValueBuilder("LOL", ORIGIN_Q_NAME, "value").build()).build()).build();
- this.selector.processPath(this.ROUTER_ID3, containerException);
+ final ContainerNode containerException = dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME)
+ .addChild(createValueBuilder("LOL", ORIGIN_Q_NAME, "value").build()).build()).build();
+ this.selector.processPath(ROUTER_ID3, containerException);
final BaseBestPath processedPathException = this.selector.result();
processedPathException.getState().getOrigin();
}
import static org.junit.Assert.assertFalse;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.mode.impl.AbstractRouteEntryTest;
}
private void testRemoveRoute() {
- Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(8, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaYii));
this.testBARE.removeRoute(ROUTER_ID, REMOTE_PATH_ID);
this.testBARE.selectBest(AS);
this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA);
- yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ yiiCount = collectInfo();
assertFalse(yiiCount.containsKey(this.routePaYii));
assertFalse(yiiCount.containsKey(this.routeAddRiboutAttYii));
}
private void testInitializePeerWithExistentRoute() {
- this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, this.tx);
- assertEquals(8, this.yIIChanges.size());
- final Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream()
- .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport,
+ this.tx);
+ assertEquals(8, this.yiichanges.size());
+ Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(1, (long) yiiCount.get(this.routeRiboutYiiPeer2));
assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYiiPeer2));
}
assertFalse(this.testBARE.getOffsets().isEmpty());
this.testBARE.selectBest(AS);
this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA);
- Map<YangInstanceIdentifier, Long> yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ Map<YangInstanceIdentifier, Long> yiiCount = collectInfo();
assertEquals(3, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaYii));
assertEquals(1, (long) yiiCount.get(this.routeRiboutYii));
assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYii));
- this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx, ROUTE_ID_PA_ADD_PATH);
- yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+ this.testBARE.updateRoute(TABLES_KEY, this.peerPT, LOC_RIB_TARGET, this.ribSupport, this.tx,
+ ROUTE_ID_PA_ADD_PATH);
+ yiiCount = collectInfo();
assertEquals(6, yiiCount.size());
assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii));
assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii));
}
private void testWriteEmptyBestPath() {
- this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport, this.tx);
- assertEquals(0, this.yIIChanges.size());
+ this.testBARE.writeRoute(PEER_ID, ROUTE_ID_PA, PEER_YII2, this.peg, TABLES_KEY, this.peerPT, this.ribSupport,
+ this.tx);
+ assertEquals(0, this.yiichanges.size());
}
}
final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
final Collection<DataTreeCandidateNode> modifiedRoutes = this.ribSupport.changedRoutes(child);
for (final DataTreeCandidateNode route : modifiedRoutes) {
- final PathArgument routeId = this.ribSupport.createRouteKeyPathArgument(route.getIdentifier());
+ final NodeIdentifierWithPredicates routeId = (NodeIdentifierWithPredicates)
+ this.ribSupport.createRouteKeyPathArgument(route.getIdentifier());
RouteEntry entry = this.routeEntries.get(routeId);
final Optional<NormalizedNode<?, ?>> maybeData = route.getDataAfter();
final Optional<NormalizedNode<?, ?>> maybeDataBefore = route.getDataBefore();
import static java.util.Objects.requireNonNull;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerId;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
/**
* Combined key formed as a concatenation of source peer and route identifiers.
*/
final class RouteUpdateKey {
private final PeerId peerId;
- private final PathArgument routeId;
+ private final NodeIdentifierWithPredicates routeId;
- RouteUpdateKey(final PeerId peerId, final PathArgument routeId) {
+ RouteUpdateKey(final PeerId peerId, final NodeIdentifierWithPredicates routeId) {
this.peerId = requireNonNull(peerId);
this.routeId = requireNonNull(routeId);
}
return this.peerId;
}
- PathArgument getRouteId() {
+ NodeIdentifierWithPredicates getRouteId() {
return this.routeId;
}
* @param peerId of peer
* @return Role of peer
*/
- @Nullable
+ @Nonnull
PeerRole getRole(@Nonnull YangInstanceIdentifier peerId);
/**
import static org.junit.Assert.assertNull;
import static org.opendaylight.protocol.bgp.parser.spi.PathIdUtil.NON_PATH_ID;
+import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev171207.ipv4.routes.ipv4.routes.Ipv4Route;
public class AddPathRibSupportTest {
- private static final NodeIdentifier QNAME = new NodeIdentifier(QName.create("test").intern());
+ private static final String PREFIX = "1.2.3.4/32";
+ private static final String ROUTE_KEY = "prefix";
+ private static final NodeIdentifierWithPredicates QNAME
+ = new NodeIdentifierWithPredicates(Ipv4Route.QNAME,
+ ImmutableMap.of(QName.create(Ipv4Route.QNAME, ROUTE_KEY).intern(), PREFIX));
@Test
public void defaultAddPathRibSupport() {