Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting BGP properties on generated routes during activation #6728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
/** A generic BGP route containing the common properties among different types of BGP routes */
@ParametersAreNonnullByDefault
public abstract class BgpRoute<B extends Builder<B, R>, R extends BgpRoute<B, R>>
extends AbstractRoute {
extends AbstractRoute
implements HasReadableAsPath,
HasReadableCommunities,
HasReadableLocalPreference,
HasReadableOriginType,
HasReadableWeight {

/** Local-preference has a maximum value of u32 max. */
public static final long MAX_LOCAL_PREFERENCE = (1L << 32) - 1;
Expand All @@ -45,7 +50,12 @@ public abstract class BgpRoute<B extends Builder<B, R>, R extends BgpRoute<B, R>
/** Builder for {@link BgpRoute} */
@ParametersAreNonnullByDefault
public abstract static class Builder<B extends Builder<B, R>, R extends BgpRoute<B, R>>
extends AbstractRouteBuilder<B, R> {
extends AbstractRouteBuilder<B, R>
implements HasWritableAsPath<B, R>,
HasWritableCommunities<B, R>,
HasWritableLocalPreference<B, R>,
HasWritableOriginType<B, R>,
HasWritableWeight<B, R> {

@Nonnull protected AsPath _asPath;
// Invariant: either immutable or a local copy shielded from external mutations.
Expand Down Expand Up @@ -87,6 +97,7 @@ protected Builder() {
public abstract R build();

@Nonnull
@Override
public AsPath getAsPath() {
return _asPath;
}
Expand All @@ -99,12 +110,20 @@ public Set<Long> getClusterList() {
}

@Nonnull
public Set<Community> getCommunities() {
@Override
public CommunitySet getCommunities() {
return CommunitySet.of(_communities);
}

@Nonnull
@Override
public Set<Community> getCommunitiesAsSet() {
return _communities instanceof ImmutableSet
? _communities
: Collections.unmodifiableSet(_communities);
}

@Override
public long getLocalPreference() {
return _localPreference;
}
Expand All @@ -115,6 +134,7 @@ public Ip getOriginatorIp() {
}

@Nullable
@Override
public OriginType getOriginType() {
return _originType;
}
Expand All @@ -128,10 +148,13 @@ public RoutingProtocol getProtocol() {
@Nonnull
protected abstract B getThis();

@Override
public int getWeight() {
return _weight;
}

@Nonnull
@Override
public B setAsPath(AsPath asPath) {
_asPath = asPath;
return getThis();
Expand Down Expand Up @@ -162,12 +185,15 @@ public B addToClusterList(Long cluster) {
}

/** Overwrite communities */
@Nonnull
@Override
public B setCommunities(CommunitySet communities) {
_communities = communities.getCommunities();
return getThis();
}

/** Overwrite communities */
// TODO: remove in favor of setCommunities(CommunitySet)
public B setCommunities(Collection<? extends Community> communities) {
if (communities instanceof ImmutableSet) {
@SuppressWarnings("unchecked") // cannot be mutated, cast to superclass is safe.
Expand Down Expand Up @@ -206,6 +232,8 @@ public B removeCommunities(Set<Community> communities) {
return getThis();
}

@Nonnull
@Override
public B setLocalPreference(long localPreference) {
_localPreference = localPreference;
return getThis();
Expand All @@ -216,6 +244,8 @@ public B setOriginatorIp(Ip originatorIp) {
return getThis();
}

@Nonnull
@Override
public B setOriginType(OriginType originType) {
_originType = originType;
return getThis();
Expand All @@ -241,6 +271,8 @@ public B setSrcProtocol(@Nullable RoutingProtocol srcProtocol) {
return getThis();
}

@Nonnull
@Override
public B setWeight(int weight) {
_weight = weight;
return getThis();
Expand Down Expand Up @@ -327,6 +359,7 @@ protected BgpRoute(

@Nonnull
@JsonProperty(PROP_AS_PATH)
@Override
public AsPath getAsPath() {
return _asPath;
}
Expand All @@ -336,10 +369,19 @@ public AsPath getAsPath() {
}

/** Return the set of all community attributes */
public @Nonnull CommunitySet getCommunities() {
@Nonnull
@Override
public final CommunitySet getCommunities() {
return _communities;
}

/** Return the set of all community attributes */
@Nonnull
@Override
public final Set<Community> getCommunitiesAsSet() {
return _communities.getCommunities();
}

/** Return only standard community attributes */
@Nonnull
@JsonIgnore
Expand All @@ -355,6 +397,7 @@ public Set<ExtendedCommunity> getExtendedCommunities() {
}

@JsonProperty(PROP_LOCAL_PREFERENCE)
@Override
public long getLocalPreference() {
return _localPreference;
}
Expand All @@ -374,6 +417,7 @@ public Ip getOriginatorIp() {

@Nonnull
@JsonProperty(PROP_ORIGIN_TYPE)
@Override
public OriginType getOriginType() {
return _originType;
}
Expand Down Expand Up @@ -404,6 +448,7 @@ public RoutingProtocol getSrcProtocol() {
}

@JsonProperty(PROP_WEIGHT)
@Override
public int getWeight() {
return _weight;
}
Expand Down