From 00656d6a42614fc6b750f8eefdcce70ac70be29e Mon Sep 17 00:00:00 2001 From: "Claudio D. Gasparini" Date: Tue, 9 Jan 2018 12:51:34 +0100 Subject: [PATCH] Fix findbug and checkstyle issues Change-Id: Ia8fef246d76af79c9557f7cecf7cbd2740249ab9 Signed-off-by: Claudio D. Gasparini --- .../protocol/bgp/parser/spi/PathIdUtil.java | 40 ++--- bgp/path-selection-mode/pom.xml | 7 + .../protocol/bgp/mode/BesthPathStateUtil.java | 30 ++++ .../protocol/bgp/mode/api/BestPath.java | 4 + .../bgp/mode/api/PathSelectionMode.java | 7 +- .../protocol/bgp/mode/api/RouteEntry.java | 54 +++---- .../bgp/mode/impl/BestPathStateImpl.java | 58 +++---- .../impl/add/AddPathAbstractRouteEntry.java | 111 ++++++++------ .../bgp/mode/impl/add/AddPathBestPath.java | 11 +- .../bgp/mode/impl/add/AddPathSelector.java | 3 +- .../protocol/bgp/mode/impl/add/OffsetMap.java | 17 ++- .../protocol/bgp/mode/impl/add/RouteKey.java | 5 +- .../all/paths/AbstractAllPathsRouteEntry.java | 3 +- .../impl/add/all/paths/ComplexRouteEntry.java | 8 +- .../impl/add/all/paths/SimpleRouteEntry.java | 3 +- .../add/n/paths/AbstractNPathsRouteEntry.java | 9 +- .../n/paths/AddPathBestNPathSelection.java | 8 +- .../impl/add/n/paths/ComplexRouteEntry.java | 7 +- .../impl/add/n/paths/SimpleRouteEntry.java | 7 +- .../impl/base/BaseAbstractRouteEntry.java | 74 ++++----- .../mode/impl/base/BaseComplexRouteEntry.java | 3 +- .../bgp/mode/impl/base/OffsetMap.java | 16 +- .../bgp/mode/spi/AbstractBestPath.java | 2 +- .../mode/spi/AbstractBestPathSelector.java | 3 +- .../bgp/mode/spi/AbstractRouteEntry.java | 10 +- .../protocol/bgp/mode/spi/RouteEntryUtil.java | 6 +- .../bgp/mode/impl/AbstractRouteEntryTest.java | 83 +++++++---- .../add/all/paths/SimpleRouteEntryTest.java | 17 ++- .../add/n/paths/SimpleRouteEntryTest.java | 32 ++-- .../bgp/mode/impl/base/BaseBestPathTest.java | 6 +- .../mode/impl/base/BasePathSelectorTest.java | 141 +++++++++++------- .../mode/impl/base/BaseRouteEntryTest.java | 26 ++-- .../protocol/bgp/rib/impl/LocRibWriter.java | 3 +- .../protocol/bgp/rib/impl/RouteUpdateKey.java | 8 +- .../bgp/rib/spi/ExportPolicyPeerTracker.java | 2 +- .../bgp/rib/spi/AddPathRibSupportTest.java | 10 +- 36 files changed, 502 insertions(+), 332 deletions(-) create mode 100644 bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/BesthPathStateUtil.java diff --git a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java index cca87d6bc7..9fe8c32044 100644 --- a/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java +++ b/bgp/parser-spi/src/main/java/org/opendaylight/protocol/bgp/parser/spi/PathIdUtil.java @@ -70,22 +70,23 @@ public final class PathIdUtil { } /** - * 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 @@ -95,37 +96,40 @@ public final class PathIdUtil { 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 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 routesCont, final NodeIdentifier pathIdNii) { + public static PathId buildPathId(final DataContainerNode 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> maybePathIdLeaf) { + public static NodeIdentifierWithPredicates createNidKey(final QName routeQname, final QName routeKeyQname, + final QName pathIdQname, final Object routeKeyValue, + final Optional> 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); diff --git a/bgp/path-selection-mode/pom.xml b/bgp/path-selection-mode/pom.xml index 4971ae38ab..1661b50613 100644 --- a/bgp/path-selection-mode/pom.xml +++ b/bgp/path-selection-mode/pom.xml @@ -95,6 +95,13 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + org.apache.felix maven-bundle-plugin diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/BesthPathStateUtil.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/BesthPathStateUtil.java new file mode 100644 index 0000000000..b7625ab075 --- /dev/null +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/BesthPathStateUtil.java @@ -0,0 +1,30 @@ +/* + * 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) { + 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); + } +} diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/BestPath.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/BestPath.java index 01b483b2d3..22916a85c8 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/BestPath.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/BestPath.java @@ -15,24 +15,28 @@ import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; 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 */ diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/PathSelectionMode.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/PathSelectionMode.java index b1ee6a1d1a..97e408a3ba 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/PathSelectionMode.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/PathSelectionMode.java @@ -7,11 +7,14 @@ */ 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); } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java index 9ef78754b6..7535b7407a 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/api/RouteEntry.java @@ -30,25 +30,26 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; */ 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 @@ -56,37 +57,40 @@ public interface RouteEntry { 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 diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BestPathStateImpl.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BestPathStateImpl.java index 114988016c..3a3159f0b0 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BestPathStateImpl.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/BestPathStateImpl.java @@ -20,6 +20,7 @@ import java.util.Collection; 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; @@ -54,7 +55,8 @@ public final class BestPathStateImpl implements BestPathState { 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); @@ -100,7 +102,8 @@ public final class BestPathStateImpl implements BestPathState { } private static final Logger LOG = LoggerFactory.getLogger(BestPathStateImpl.class); - private static final Cache PATH_CACHE = CacheBuilder.newBuilder().weakKeys().weakValues().build(); + private static final Cache PATH_CACHE = CacheBuilder.newBuilder() + .weakKeys().weakValues().build(); private long peerAs = 0L; private int asPathLength = 0; @@ -115,7 +118,8 @@ public final class BestPathStateImpl implements BestPathState { 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); @@ -128,14 +132,14 @@ public final class BestPathStateImpl implements BestPathState { 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); } } @@ -144,33 +148,37 @@ public final class BestPathStateImpl implements BestPathState { return; } - final Optional> maybeLocalPref = NormalizedNodes.findNode(this.attributes, this.ids.getLocPref()); + final Optional> maybeLocalPref + = NormalizedNodes.findNode(this.attributes, this.ids.getLocPref()); if (maybeLocalPref.isPresent()) { this.localPref = (Long) maybeLocalPref.get().getValue(); } else { this.localPref = null; } - final Optional> maybeMultiExitDisc = NormalizedNodes.findNode(this.attributes, this.ids.getMed()); + final Optional> maybeMultiExitDisc + = NormalizedNodes.findNode(this.attributes, this.ids.getMed()); if (maybeMultiExitDisc.isPresent()) { this.multiExitDisc = (Long) maybeMultiExitDisc.get().getValue(); } else { this.multiExitDisc = null; } - final Optional> maybeOrigin = NormalizedNodes.findNode(this.attributes, this.ids.getOrig()); + final Optional> maybeOrigin + = NormalizedNodes.findNode(this.attributes, this.ids.getOrig()); if (maybeOrigin.isPresent()) { this.origin = fromString((String) maybeOrigin.get().getValue()); } else { this.origin = null; } - final Optional> maybeSegments = NormalizedNodes.findNode(this.attributes, this.ids.getAsPath()); + final Optional> maybeSegments + = NormalizedNodes.findNode(this.attributes, this.ids.getAsPath()); if (maybeSegments.isPresent()) { final UnkeyedListNode segments = (UnkeyedListNode) maybeSegments.get(); final List segs = extractSegments(segments); if (!segs.isEmpty()) { - this.peerAs = getPeerAs(segs).getValue(); + this.peerAs = BesthPathStateUtil.getPeerAs(segs).getValue(); this.asPathLength = countAsPath(segs); } } @@ -222,25 +230,17 @@ public final class BestPathStateImpl implements BestPathState { return count; } - private static AsNumber getPeerAs(final List 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 extractSegments(final UnkeyedListNode segments) { // list segments final List 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; diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java index 6609e556b2..0f156347a2 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathAbstractRouteEntry.java @@ -89,14 +89,16 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { 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 @@ -107,7 +109,7 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { 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)); @@ -115,71 +117,84 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { } @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 @@ -192,16 +207,18 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { 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); } } }); @@ -227,7 +244,7 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { } /** - * Process best path selection + * Process best path selection. * * @param localAs The local autonomous system number * @param keyList List of RouteKey @@ -255,9 +272,10 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { protected boolean isBestPathNew(final List 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; @@ -268,8 +286,8 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { } private boolean isNonAddPathBestPathTheSame(final List 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 pathList) { @@ -277,13 +295,14 @@ public abstract class AddPathAbstractRouteEntry extends AbstractRouteEntry { } private void filterRemovedPaths(final List newBestPathList) { - if(this.bestPath == null) { + if (this.bestPath == null) { return; } this.bestPathRemoved = new ArrayList<>(this.bestPath); this.bestPath.forEach(oldBest -> { final Optional 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)); }); } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathBestPath.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathBestPath.java index e1981247b7..13f6f4796f 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathBestPath.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathBestPath.java @@ -22,7 +22,8 @@ public final class AddPathBestPath extends AbstractBestPath { 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; @@ -64,8 +65,8 @@ public final class AddPathBestPath extends AbstractBestPath { 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; @@ -75,12 +76,12 @@ public final class AddPathBestPath extends AbstractBestPath { } @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()); } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathSelector.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathSelector.java index 9dbe31b069..380e905804 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathSelector.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/AddPathSelector.java @@ -52,6 +52,7 @@ public final class AddPathSelector extends AbstractBestPathSelector { } 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); } } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/OffsetMap.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/OffsetMap.java index ae57d35147..9887dd3bd6 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/OffsetMap.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/OffsetMap.java @@ -32,18 +32,19 @@ import org.slf4j.LoggerFactory; * 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, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder().weakValues().build( - new CacheLoader, OffsetMap>() { - @Override - public OffsetMap load(@Nonnull final Set key) throws Exception { - return new OffsetMap(key); - } - }); + private static final LoadingCache, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder().weakValues() + .build(new CacheLoader, OffsetMap>() { + @Override + public OffsetMap load(@Nonnull final Set key) { + return new OffsetMap(key); + } + }); private static final Comparator COMPARATOR = RouteKey::compareTo; + static final OffsetMap EMPTY = new OffsetMap(Collections.emptySet()); + private final RouteKey[] routeKeys; private OffsetMap(final Set routerIds) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/RouteKey.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/RouteKey.java index 9e1211c6b9..faf54d9d1d 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/RouteKey.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/RouteKey.java @@ -17,7 +17,7 @@ public final class RouteKey implements Comparable { 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() { @@ -65,6 +65,7 @@ public final class RouteKey implements Comparable { @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; } } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java index bba334b246..775f7f5635 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/AbstractAllPathsRouteEntry.java @@ -38,7 +38,8 @@ abstract class AbstractAllPathsRouteEntry extends AddPathAbstractRouteEntry { 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); } } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java index 2ec4f43a90..2c829c4ad9 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/ComplexRouteEntry.java @@ -14,7 +14,8 @@ import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath; 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; @@ -32,14 +33,15 @@ final class ComplexRouteEntry extends AbstractAllPathsRouteEntry { } @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(); diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java index 20d02c2c14..4d01b8bba9 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntry.java @@ -30,7 +30,8 @@ final class SimpleRouteEntry extends AbstractAllPathsRouteEntry { } @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); } } diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AbstractNPathsRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AbstractNPathsRouteEntry.java index 0fda7d7b6e..57a9d90c9c 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AbstractNPathsRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AbstractNPathsRouteEntry.java @@ -16,17 +16,18 @@ import org.opendaylight.protocol.bgp.mode.impl.add.AddPathBestPath; 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 newBestPathList = new ArrayList<>(); final List 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); diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AddPathBestNPathSelection.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AddPathBestNPathSelection.java index 29eed92f9d..6b9f5dbf49 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AddPathBestNPathSelection.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/AddPathBestNPathSelection.java @@ -12,10 +12,10 @@ import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode; 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 @@ -29,6 +29,6 @@ public class AddPathBestNPathSelection implements PathSelectionMode { } public Long getNBestPaths() { - return this.nBestPaths; + return this.npaths; } } \ No newline at end of file diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java index 3d7b7abf4f..747496abd3 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/ComplexRouteEntry.java @@ -22,8 +22,8 @@ final class ComplexRouteEntry extends AbstractNPathsRouteEntry { 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 @@ -43,7 +43,8 @@ final class ComplexRouteEntry extends AbstractNPathsRouteEntry { } @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(); diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java index b9107240db..673baa4875 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntry.java @@ -17,8 +17,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; 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 @@ -33,7 +33,8 @@ final class SimpleRouteEntry extends AbstractNPathsRouteEntry { } @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 diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java index 088fa60faf..12aa4a60a2 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseAbstractRouteEntry.java @@ -37,26 +37,11 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { 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) { @@ -84,7 +69,7 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { 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); @@ -94,15 +79,29 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { } @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; @@ -113,21 +112,24 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { } @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); @@ -139,8 +141,9 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { 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); @@ -153,7 +156,8 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { 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); } @@ -163,8 +167,8 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { @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 @@ -178,7 +182,7 @@ abstract class BaseAbstractRouteEntry extends AbstractRouteEntry { 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; diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java index 04c22444aa..4195a5c6e1 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseComplexRouteEntry.java @@ -20,7 +20,8 @@ final class BaseComplexRouteEntry extends BaseAbstractRouteEntry { 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(); diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/OffsetMap.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/OffsetMap.java index a07a0c29a1..6ae03377b7 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/OffsetMap.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/impl/base/OffsetMap.java @@ -31,18 +31,18 @@ import org.slf4j.LoggerFactory; * 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, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder().weakValues().build( - new CacheLoader, OffsetMap>() { - @Override - public OffsetMap load(@Nonnull final Set key) throws Exception { - return new OffsetMap(key); - } - }); + private static final LoadingCache, OffsetMap> OFFSETMAPS = CacheBuilder.newBuilder() + .weakValues().build(new CacheLoader, OffsetMap>() { + @Override + public OffsetMap load(@Nonnull final Set key) { + return new OffsetMap(key); + } + }); private static final Comparator COMPARATOR = UnsignedInteger::compareTo; + static final OffsetMap EMPTY = new OffsetMap(Collections.emptySet()); private final UnsignedInteger[] routeKeys; private OffsetMap(final Set routerIds) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPath.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPath.java index b601802444..42fc10d460 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPath.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPath.java @@ -23,7 +23,7 @@ public abstract class AbstractBestPath implements BestPath { 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() { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPathSelector.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPathSelector.java index 03dc3dc8db..05fae4d2d3 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPathSelector.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractBestPathSelector.java @@ -25,7 +25,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes; public class AbstractBestPathSelector { private static final Collection 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; diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java index 87428f01e0..ec58b69229 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/AbstractRouteEntry.java @@ -72,10 +72,12 @@ public abstract class AbstractRouteEntry implements RouteEntry { 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; @@ -85,8 +87,8 @@ public abstract class AbstractRouteEntry implements RouteEntry { 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) { diff --git a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java index 1e40ed1cfe..2753d9d6e2 100644 --- a/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java +++ b/bgp/path-selection-mode/src/main/java/org/opendaylight/protocol/bgp/mode/spi/RouteEntryUtil.java @@ -27,8 +27,10 @@ public final class RouteEntryUtil { return b.build(); } - public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path, final MapEntryNode mapValues) { - final DataContainerNodeAttrBuilder mapEntryBuilder = Builders.mapEntryBuilder(); + public static MapEntryNode createComplexRouteValue(final PathArgument routeId, final BestPath path, + final MapEntryNode mapValues) { + final DataContainerNodeAttrBuilder mapEntryBuilder + = Builders.mapEntryBuilder(); mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) routeId); mapEntryBuilder.addChild(path.getAttributes()); mapValues.getValue().forEach(mapEntryBuilder::addChild); diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java index 20965c1d07..d128436e93 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/AbstractRouteEntryTest.java @@ -23,6 +23,8 @@ import java.util.List; 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; @@ -62,28 +64,43 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableCo 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 @@ -92,7 +109,7 @@ public abstract class AbstractRouteEntryTest { protected ExportPolicyPeerTracker peerPT; @Mock protected PeerExportGroup peg; - protected List yIIChanges; + protected List yiichanges; protected NormalizedNode attributes; protected YangInstanceIdentifier routePaYii; protected YangInstanceIdentifier routePaAddPathYii; @@ -111,17 +128,19 @@ public abstract class AbstractRouteEntryTest { 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); @@ -134,22 +153,23 @@ public abstract class AbstractRouteEntryTest { 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)); @@ -201,7 +221,8 @@ public abstract class AbstractRouteEntryTest { 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(); @@ -230,13 +251,19 @@ public abstract class AbstractRouteEntryTest { } 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 collectInfo() { + return this.yiichanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + } } diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java index 1680f268bb..4f8f4af71c 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/all/paths/SimpleRouteEntryTest.java @@ -12,8 +12,6 @@ import static org.junit.Assert.assertFalse; 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; @@ -35,12 +33,14 @@ public final class SimpleRouteEntryTest extends 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 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 yiiCount = collectInfo(); assertEquals(3, yiiCount.size()); assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii)); @@ -48,13 +48,14 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { } private void testRemoveRoute() { - Map yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + Map 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)); diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java index 8a9892e2b8..e941a17dd9 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/add/n/paths/SimpleRouteEntryTest.java @@ -12,8 +12,6 @@ import static org.junit.Assert.assertFalse; 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; @@ -45,17 +43,20 @@ public final class SimpleRouteEntryTest extends 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 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 yiiCount = collectInfo(); assertEquals(3, yiiCount.size()); assertEquals(1, (long) yiiCount.get(this.routePaAddPathYii)); assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYii)); @@ -68,23 +69,24 @@ public final class SimpleRouteEntryTest extends AbstractRouteEntryTest { } 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 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 yiiCount = collectInfo(); assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2)); assertEquals(1, (long) yiiCount.get(this.routeAddRiboutYiiPeer2)); } private void testRemoveRoute() { - Map yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + Map 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)); diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPathTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPathTest.java index 5a209239fc..878f84d2ce 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPathTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseBestPathTest.java @@ -26,7 +26,8 @@ public class BaseBestPathTest { @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(); } @@ -48,7 +49,8 @@ public class BaseBestPathTest { @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); } diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectorTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectorTest.java index 6f6f955f5b..c17ede0b89 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectorTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BasePathSelectorTest.java @@ -38,38 +38,52 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUn 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() { @@ -86,7 +100,6 @@ public class BasePathSelectorTest { @Test public void testBestPathWithHigherLocalPref() { - DataContainerNodeAttrBuilder 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()); @@ -95,6 +108,8 @@ public class BasePathSelectorTest { processedPath = this.selector.result(); assertEquals(321L, processedPath.getState().getLocalPref().longValue()); + DataContainerNodeAttrBuilder dataContBuilder = + createContBuilder(ATTRS_EXTENSION_Q); addLowerLocalRef(dataContBuilder); // prefer path with higher LOCAL_PREF this.selector.processPath(ROUTER_ID2, dataContBuilder.build()); processedPath = this.selector.result(); @@ -103,7 +118,8 @@ public class BasePathSelectorTest { @Test public void testBestPathSelectionOptions() { - DataContainerNodeAttrBuilder dataContBuilder = createStateFromPrefMedOriginASPath(); + DataContainerNodeAttrBuilder dataContBuilder + = createStateFromPrefMedOriginASPath(); this.selector.processPath(ROUTER_ID2, dataContBuilder.build()); BaseBestPath processedPath = this.selector.result(); assertEquals(1, processedPath.getState().getOrigin().getIntValue()); @@ -143,7 +159,7 @@ public class BasePathSelectorTest { @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()); @@ -155,7 +171,8 @@ public class BasePathSelectorTest { } private static ContainerNode createStateFromPrefMedOrigin() { - DataContainerNodeAttrBuilder dataContBuilder = createContBuilder(ATTRS_EXTENSION_Q); + DataContainerNodeAttrBuilder dataContBuilder + = createContBuilder(ATTRS_EXTENSION_Q); addLowerLocalRef(dataContBuilder); addLowerMultiExitDisc(dataContBuilder); addIgpOrigin(dataContBuilder); @@ -163,7 +180,8 @@ public class BasePathSelectorTest { } static DataContainerNodeAttrBuilder createStateFromPrefMedOriginASPath() { - DataContainerNodeAttrBuilder dataContBuilder = createContBuilder(ATTRS_EXTENSION_Q); + DataContainerNodeAttrBuilder dataContBuilder + = createContBuilder(ATTRS_EXTENSION_Q); addHigherLocalRef(dataContBuilder); addHigherMultiExitDisc(dataContBuilder); addEgpOrigin(dataContBuilder); @@ -171,35 +189,50 @@ public class BasePathSelectorTest { return dataContBuilder; } - private static void addLowerLocalRef(final DataContainerNodeAttrBuilder dataContBuilder) { - dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME).addChild(createValueBuilder(123L, LOCAL_PREF_Q_NAME, "pref").build()).build()); + private static void addLowerLocalRef( + final DataContainerNodeAttrBuilder dataContBuilder) { + dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME) + .addChild(createValueBuilder(123L, LOCAL_PREF_Q_NAME, "pref").build()).build()); } - private static void addHigherLocalRef(final DataContainerNodeAttrBuilder dataContBuilder) { - dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME).addChild(createValueBuilder(321L, LOCAL_PREF_Q_NAME, "pref").build()).build()); + private static void addHigherLocalRef( + final DataContainerNodeAttrBuilder dataContBuilder) { + dataContBuilder.addChild(createContBuilder(LOCAL_PREF_Q_NAME) + .addChild(createValueBuilder(321L, LOCAL_PREF_Q_NAME, "pref").build()).build()); } - private static void addLowerMultiExitDisc(final DataContainerNodeAttrBuilder 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 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 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 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 dataContBuilder) { - dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME).addChild(createValueBuilder("igp", ORIGIN_Q_NAME, "value").build()).build()); + private static void addIgpOrigin( + final DataContainerNodeAttrBuilder dataContBuilder) { + dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME) + .addChild(createValueBuilder("igp", ORIGIN_Q_NAME, "value").build()).build()); } - private static void addEgpOrigin(final DataContainerNodeAttrBuilder dataContBuilder) { - dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME).addChild(createValueBuilder("egp", ORIGIN_Q_NAME, "value").build()).build()); + private static void addEgpOrigin( + final DataContainerNodeAttrBuilder dataContBuilder) { + dataContBuilder.addChild(createContBuilder(ORIGIN_Q_NAME) + .addChild(createValueBuilder("egp", ORIGIN_Q_NAME, "value").build()).build()); } - private static void addAsPath(final DataContainerNodeAttrBuilder dataContBuilder, final UnkeyedListEntryNode segment) { - final DataContainerNodeAttrBuilder asPathContBuilder = ImmutableContainerNodeSchemaAwareBuilder.create(); + private static void addAsPath(final DataContainerNodeAttrBuilder dataContBuilder, + final UnkeyedListEntryNode segment) { + final DataContainerNodeAttrBuilder asPathContBuilder + = ImmutableContainerNodeSchemaAwareBuilder.create(); asPathContBuilder.withNodeIdentifier(new NodeIdentifier(AS_PATH_Q_NAME)); - final CollectionNodeBuilder segments = ImmutableUnkeyedListNodeBuilder.create(); + final CollectionNodeBuilder segments + = ImmutableUnkeyedListNodeBuilder.create(); segments.withNodeIdentifier(SEGMENTS_NID); segments.addChild(segment); asPathContBuilder.addChild(segments.build()); @@ -211,7 +244,8 @@ public class BasePathSelectorTest { return ImmutableContainerNodeSchemaAwareBuilder.create().withNodeIdentifier(new NodeIdentifier(qname)); } - private static ImmutableLeafNodeBuilder createValueBuilder(final T value, final QName qname, final String localName) { + private static ImmutableLeafNodeBuilder createValueBuilder(final T value, final QName qname, + final String localName) { final ImmutableLeafNodeBuilder valueBuilder = new ImmutableLeafNodeBuilder<>(); valueBuilder.withNodeIdentifier(new NodeIdentifier(QName.create(qname, localName))).withValue(value); return valueBuilder; @@ -231,7 +265,8 @@ public class BasePathSelectorTest { sequences.add(new AsNumber(2L)); sequences.add(new AsNumber(3L)); final List 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 actual = this.state.extractSegments(builder.build()); @@ -243,14 +278,18 @@ public class BasePathSelectorTest { @Test(expected = IllegalArgumentException.class) public void testBgpOrigin() { - DataContainerNodeAttrBuilder 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 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(); } diff --git a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java index bc66b4c755..3accb42d03 100644 --- a/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java +++ b/bgp/path-selection-mode/src/test/java/org/opendaylight/protocol/bgp/mode/impl/base/BaseRouteEntryTest.java @@ -12,8 +12,6 @@ import static org.junit.Assert.assertEquals; 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; @@ -39,22 +37,22 @@ public class BaseRouteEntryTest extends AbstractRouteEntryTest { } private void testRemoveRoute() { - Map yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + Map 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 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 yiiCount = collectInfo(); assertEquals(1, (long) yiiCount.get(this.routeRiboutYiiPeer2)); assertEquals(1, (long) yiiCount.get(this.routeRiboutAttYiiPeer2)); } @@ -70,13 +68,14 @@ public class BaseRouteEntryTest extends AbstractRouteEntryTest { 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 yiiCount = this.yIIChanges.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); + Map 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)); @@ -84,7 +83,8 @@ public class BaseRouteEntryTest extends 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()); } } diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java index 9cc65baf83..03b58fc5bf 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/LocRibWriter.java @@ -234,7 +234,8 @@ final class LocRibWriter implements AutoCloseable, TotalPrefixesCounter, TotalPa final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId); final Collection 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> maybeData = route.getDataAfter(); final Optional> maybeDataBefore = route.getDataBefore(); diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteUpdateKey.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteUpdateKey.java index c3693bda79..f76750b247 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteUpdateKey.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/RouteUpdateKey.java @@ -10,7 +10,7 @@ package org.opendaylight.protocol.bgp.rib.impl; 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. @@ -18,9 +18,9 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum */ 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); } @@ -29,7 +29,7 @@ final class RouteUpdateKey { return this.peerId; } - PathArgument getRouteId() { + NodeIdentifierWithPredicates getRouteId() { return this.routeId; } diff --git a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ExportPolicyPeerTracker.java b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ExportPolicyPeerTracker.java index ab5e487554..f750bb8630 100644 --- a/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ExportPolicyPeerTracker.java +++ b/bgp/rib-spi/src/main/java/org/opendaylight/protocol/bgp/rib/spi/ExportPolicyPeerTracker.java @@ -59,7 +59,7 @@ public interface ExportPolicyPeerTracker { * @param peerId of peer * @return Role of peer */ - @Nullable + @Nonnull PeerRole getRole(@Nonnull YangInstanceIdentifier peerId); /** diff --git a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java index fa8dc0248a..f91d13953f 100644 --- a/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java +++ b/bgp/rib-spi/src/test/java/org/opendaylight/protocol/bgp/rib/spi/AddPathRibSupportTest.java @@ -11,13 +11,19 @@ import static org.junit.Assert.assertEquals; 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() { -- 2.36.6