case RrClient:
// Client iBGP -> eBGP, propagate
return attributes;
+ default:
+ break;
}
return attributes;
}
case RrClient:
// Client iBGP -> Non-Client iBGP, reflect
return toClientAttributes(attributes);
+ default:
+ break;
}
return attributes;
}
case RrClient:
// Client iBGP -> Client iBGP, reflect
return ToInternalExportPolicy.toClientAttributes(attributes);
+ default:
+ throw new IllegalStateException("Unhandled source role " + sourceRole);
}
-
- throw new IllegalStateException("Unhandled source role " + sourceRole);
}
}
final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
if (routes instanceof MapNode) {
final YangInstanceIdentifier base = tablePath.node(ROUTES).node(routesContainerIdentifier());
- for (MapEntryNode e : ((MapNode)routes).getValue()) {
+ for (final MapEntryNode e : ((MapNode)routes).getValue()) {
function.apply(tx, base, e, attributes);
}
} else {
* @param attributes received attributes
* @return Filtered attributes, or null if the advertisement should be ignored.
*/
- abstract @Nullable ContainerNode effectiveAttributes(@Nullable ContainerNode attributes);
+ @Nullable abstract ContainerNode effectiveAttributes(@Nullable ContainerNode attributes);
}
\ No newline at end of file
}
@GuardedBy("this")
- private final void writeEpilogue(final ChannelFuture future, final Notification msg) {
+ private void writeEpilogue(final ChannelFuture future, final Notification msg) {
future.addListener(
new ChannelFutureListener() {
@Override
}
ChannelOutputLimiter getLimiter() {
- return limiter;
+ return this.limiter;
}
}
* @param state attributes of the new route
* @return true if the existing path is better, false if the new path is better
*/
- private boolean selectPath(final @Nonnull UnsignedInteger originatorId, final @Nonnull BestPathState state) {
+ private boolean selectPath(@Nonnull final UnsignedInteger originatorId, @Nonnull final BestPathState state) {
// 1. prefer path with accessible nexthop
// - we assume that all nexthops are accessible
* FIXME: for eBGP cases (when the LOCAL_PREF is missing), we should assign a policy-based preference
* before we ever get here.
*/
- if (bestState.getLocalPref() == null && state.getLocalPref() != null) {
+ if (this.bestState.getLocalPref() == null && state.getLocalPref() != null) {
return true;
}
- if (bestState.getLocalPref() != null && state.getLocalPref() == null) {
+ if (this.bestState.getLocalPref() != null && state.getLocalPref() == null) {
return false;
}
- if (state.getLocalPref() != null) {
- if (state.getLocalPref() > this.bestState.getLocalPref()) {
- return true;
- }
+ if (state.getLocalPref() != null && state.getLocalPref() > this.bestState.getLocalPref()) {
+ return true;
}
// 3. prefer learned path
private Long localPref;
private Long multiExitDisc;
private BgpOrigin origin;
- private final Long peerAs = 0L;
- private final int asPathLength = 0;
+ private static final Long peerAs = 0L;
+ private static final int asPathLength = 0;
private boolean resolved;
BestPathState(final ContainerNode attributes) {
this.attributes = Preconditions.checkNotNull(attributes);
}
+ 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("Unhandleed origin value " + originStr);
+ }
+ }
+
private void resolveValues() {
- if (resolved) {
+ if (this.resolved) {
return;
}
- final Optional<NormalizedNode<?, ?>> maybeLocalPref = NormalizedNodes.findNode(attributes, LOCAL_PREF);
+ final Optional<NormalizedNode<?, ?>> maybeLocalPref = NormalizedNodes.findNode(this.attributes, LOCAL_PREF);
if (maybeLocalPref.isPresent()) {
- localPref = (Long) ((LeafNode<?>)maybeLocalPref.get()).getValue();
+ this.localPref = (Long) ((LeafNode<?>)maybeLocalPref.get()).getValue();
} else {
- localPref = null;
+ this.localPref = null;
}
- final Optional<NormalizedNode<?, ?>> maybeMultiExitDisc = NormalizedNodes.findNode(attributes, MED);
+ final Optional<NormalizedNode<?, ?>> maybeMultiExitDisc = NormalizedNodes.findNode(this.attributes, MED);
if (maybeMultiExitDisc.isPresent()) {
- multiExitDisc = (Long) ((LeafNode<?>)maybeMultiExitDisc.get()).getValue();
+ this.multiExitDisc = (Long) ((LeafNode<?>)maybeMultiExitDisc.get()).getValue();
} else {
- multiExitDisc = null;
+ this.multiExitDisc = null;
}
- final Optional<NormalizedNode<?, ?>> maybeOrigin = NormalizedNodes.findNode(attributes, ORIGIN);
+ final Optional<NormalizedNode<?, ?>> maybeOrigin = NormalizedNodes.findNode(this.attributes, ORIGIN);
if (maybeOrigin.isPresent()) {
- final String originStr = (String) ((LeafNode<?>)maybeOrigin.get()).getValue();
- switch (originStr) {
- case "igp":
- origin = BgpOrigin.Igp;
- break;
- case "egp":
- origin = BgpOrigin.Egp;
- break;
- case "incomplete":
- origin = BgpOrigin.Incomplete;
- break;
- default:
- throw new IllegalArgumentException("Unhandleed origin value " + originStr);
- }
+ this.origin = fromString((String) ((LeafNode<?>)maybeOrigin.get()).getValue());
} else {
- origin = null;
+ this.origin = null;
}
- final Optional<NormalizedNode<?, ?>> maybeSegments = NormalizedNodes.findNode(attributes, AS_PATH);
+ final Optional<NormalizedNode<?, ?>> maybeSegments = NormalizedNodes.findNode(this.attributes, AS_PATH);
if (maybeSegments.isPresent()) {
final UnkeyedListNode segments = (UnkeyedListNode) maybeSegments.get();
// FIXME: peer AS number
// FIXME: asPathLength = countAsPath(this.bestState.getAsPath().getSegments());
- boolean haveSegment;
- for (UnkeyedListEntryNode s : segments.getValue()) {
+ final boolean haveSegment;
+ for (final UnkeyedListEntryNode s : segments.getValue()) {
}
}
}
- resolved = true;
+ this.resolved = true;
}
Long getLocalPref() {
resolveValues();
- return localPref;
+ return this.localPref;
}
Long getMultiExitDisc() {
resolveValues();
- return multiExitDisc;
+ return this.multiExitDisc;
}
BgpOrigin getOrigin() {
resolveValues();
- return origin;
+ return this.origin;
}
Long getPeerAs() {
resolveValues();
- return peerAs;
+ return this.peerAs;
}
int getAsPathLength() {
* calculations when multiple peers have changed a particular entry.
*/
final Map<RouteUpdateKey, RouteEntry> toUpdate = new HashMap<>();
- for (DataTreeCandidate tc : changes) {
+ for (final DataTreeCandidate tc : changes) {
final YangInstanceIdentifier path = tc.getRootPath();
final PathArgument routeId = path.getLastPathArgument();
final NodeIdentifierWithPredicates peerKey = IdentifierUtils.peerKey(path);
final PeerId peerId = IdentifierUtils.peerId(peerKey);
final UnsignedInteger routerId = RouterIds.routerIdForPeerId(peerId);
- RouteEntry entry = routeEntries.get(routeId);
+ RouteEntry entry = this.routeEntries.get(routeId);
if (tc.getRootNode().getDataAfter().isPresent()) {
if (entry == null) {
entry = new RouteEntry();
- routeEntries.put(routeId, entry);
+ this.routeEntries.put(routeId, entry);
}
entry.addRoute(routerId, (ContainerNode) tc.getRootNode().getDataAfter().get());
- } else if (entry != null) {
- if (entry.removeRoute(routerId)) {
- routeEntries.remove(routeId);
- entry = null;
- }
+ } else if (entry != null && entry.removeRoute(routerId)) {
+ this.routeEntries.remove(routeId);
+ entry = null;
}
toUpdate.put(new RouteUpdateKey(peerId, routeId), entry);
}
- final DOMDataWriteTransaction tx = chain.newWriteOnlyTransaction();
+ final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
// Now walk all updated entries
- for (Entry<RouteUpdateKey, RouteEntry> e : toUpdate.entrySet()) {
+ for (final Entry<RouteUpdateKey, RouteEntry> e : toUpdate.entrySet()) {
final RouteEntry entry = e.getValue();
final NormalizedNode<?, ?> value;
if (entry != null) {
- if (!entry.selectBest(ourAs)) {
+ if (!entry.selectBest(this.ourAs)) {
// Best path has not changed, no need to do anything else. Proceed to next route.
continue;
}
}
if (value != null) {
- tx.put(LogicalDatastoreType.OPERATIONAL, target.node(e.getKey().getRouteId()), value);
+ tx.put(LogicalDatastoreType.OPERATIONAL, this.target.node(e.getKey().getRouteId()), value);
} else {
- tx.delete(LogicalDatastoreType.OPERATIONAL, target.node(e.getKey().getRouteId()));
+ tx.delete(LogicalDatastoreType.OPERATIONAL, this.target.node(e.getKey().getRouteId()));
}
/*
final PeerId peerId = e.getKey().getPeerId();
final ContainerNode effectiveAttributes = peerGroup.effectiveAttributes(peerId, attributes);
- for (Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
+ for (final Entry<PeerId, YangInstanceIdentifier> pid : peerGroup.getPeers()) {
// This points to adj-rib-out for a particular peer/table combination
final YangInstanceIdentifier routeTarget = pid.getValue().node(e.getKey().getRouteId());
* @param address Router ID as a dotted-quad
* @return Router ID as an {@link UnsignedInteger}
*/
- public static UnsignedInteger routerIdForAddress(final @Nonnull String address) {
+ public static UnsignedInteger routerIdForAddress(@Nonnull final String address) {
return ROUTER_IDS.getUnchecked(address);
}
- public static UnsignedInteger routerIdForPeerId(final @Nonnull PeerId peerId) {
+ public static UnsignedInteger routerIdForPeerId(@Nonnull final PeerId peerId) {
Preconditions.checkArgument(peerId.getValue().startsWith(BGP_PREFIX), "Unhandled peer ID %s", peerId);
return BGP_ROUTER_IDS.getUnchecked(peerId);
}