Skip to content

Commit

Permalink
identify and ignore (for now) the common idiom of (InputCommunities -…
Browse files Browse the repository at this point in the history
… Exp) in the translation of a community set expression
  • Loading branch information
millstein committed Mar 30, 2021
1 parent 02c5d99 commit cfe022b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ public Set<CommunityVar> visitCommunityExprsSet(
@Override
public Set<CommunityVar> visitCommunitySetDifference(
CommunitySetDifference communitySetDifference, Configuration arg) {
throw new UnsupportedOperationException("Community set differences are not supported");
if (communitySetDifference.getInitial().equals(InputCommunities.instance())) {
// a common pattern is to remove specific input communities (e.g. all standard ones)
// before adding new ones.
// TODO: handle this idiom properly rather than just ignoring it
return ImmutableSet.of();
} else {
throw new UnsupportedOperationException("Community set differences are not supported");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
import org.batfish.datamodel.ConfigurationFormat;
import org.batfish.datamodel.NetworkFactory;
import org.batfish.datamodel.bgp.community.StandardCommunity;
import org.batfish.datamodel.routing_policy.communities.AllStandardCommunities;
import org.batfish.datamodel.routing_policy.communities.CommunityExprsSet;
import org.batfish.datamodel.routing_policy.communities.CommunitySet;
import org.batfish.datamodel.routing_policy.communities.CommunitySetDifference;
import org.batfish.datamodel.routing_policy.communities.CommunitySetExprReference;
import org.batfish.datamodel.routing_policy.communities.CommunitySetReference;
import org.batfish.datamodel.routing_policy.communities.CommunitySetUnion;
import org.batfish.datamodel.routing_policy.communities.InputCommunities;
import org.batfish.datamodel.routing_policy.communities.LiteralCommunitySet;
import org.batfish.datamodel.routing_policy.communities.StandardCommunityHighLowExprs;
import org.batfish.datamodel.routing_policy.expr.LiteralInt;
Expand Down Expand Up @@ -55,6 +58,16 @@ public void testVisitCommunityExprsSet() {
assertEquals(ImmutableSet.of(cvar1, cvar2), result);
}

@Test
public void testVisitCommunitySetDifference() {
CommunitySetDifference csd =
new CommunitySetDifference(InputCommunities.instance(), AllStandardCommunities.instance());

Set<CommunityVar> result = _varCollector.visitCommunitySetDifference(csd, _baseConfig);

assertEquals(ImmutableSet.of(), result);
}

@Test
public void testVisitCommunitySetExprReference() {
String name = "name";
Expand Down

0 comments on commit cfe022b

Please sign in to comment.