@Override public void applyTo( List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) { statements.add(new SetCommunity(new LiteralCommunitySet(_communities))); }
@Override public void visitLiteralCommunitySet(LiteralCommunitySet literalCommunitySet) { literalCommunitySet.getCommunities().stream() .map(CommunityVarConverter::toCommunityVar) .forEach(_builder::add); }
@Override public void applyTo( List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) { statements.add(new AddCommunity(new LiteralCommunitySet(_communities))); }
@JsonCreator private static @Nonnull LiteralCommunitySet create( @JsonProperty(PROP_COMMUNITIES) SortedSet<Long> communities) { return new LiteralCommunitySet(firstNonNull(communities, ImmutableSortedSet.of())); }
@Test public void testMatchedCommunities() { LiteralCommunitySet l = new LiteralCommunitySet(ImmutableSet.of(1L, 3L)); Set<Long> communityCandidates = ImmutableSet.of(1L, 2L); assertThat(l, matchedCommunities(null, communityCandidates, ImmutableSet.of(1L))); } }
@Test public void testAsLiteralCommunities() { LiteralCommunitySet l = new LiteralCommunitySet(ImmutableSet.of(1L, 2L)); assertThat(l, asLiteralCommunities(null, equalTo(ImmutableSet.of(1L, 2L)))); }
_name, _name, _name)); statements.add(new AddCommunity(new LiteralCommunitySet(literalCommunities)));
@Test public void testMatchAnyCommunity() { LiteralCommunitySet l = new LiteralCommunitySet(ImmutableSet.of(1L, 3L)); Set<Long> communityCandidates = ImmutableSet.of(1L, 2L); assertThat(l, matchAnyCommunity(null, communityCandidates)); }
@Test public void testEquals() { new EqualsTester() .addEqualityGroup( new LiteralCommunitySet(ImmutableSet.of(1L, 2L)), new LiteralCommunitySet(ImmutableSet.of(2L, 1L))) .addEqualityGroup(new LiteralCommunitySet(ImmutableSet.of(2L))) .testEquals(); }
_name, _name, _name)); statements.add(new SetCommunity(new LiteralCommunitySet(literalCommunities)));
/** * For each static route in the given {@link RoutingInstance} that has at least one community set, * creates an {@link If} that matches that route (specifically, matches static routes with that * route's destination network), and sets communities for matching exported routes. */ @Nonnull private static List<If> getStaticRouteCommunitySetters(@Nonnull RoutingInstance ri) { MatchProtocol matchStatic = new MatchProtocol(RoutingProtocol.STATIC); return ri.getRibs().get(RoutingInformationBase.RIB_IPV4_UNICAST).getStaticRoutes().values() .stream() .filter(route -> !route.getCommunities().isEmpty()) .map( route -> { // Create matcher that matches routes that share this route's destination network PrefixExpr destNetworkMatcher = DestinationNetwork.instance(); PrefixSetExpr destNetwork = new ExplicitPrefixSet(new PrefixSpace(PrefixRange.fromPrefix(route.getPrefix()))); MatchPrefixSet networkMatcher = new MatchPrefixSet(destNetworkMatcher, destNetwork); // When a matching static route is exported, set its communities return new If( new Conjunction(ImmutableList.of(matchStatic, networkMatcher)), ImmutableList.of( new SetCommunity(new LiteralCommunitySet(route.getCommunities())))); }) .collect(ImmutableList.toImmutableList()); }
@Test public void testMatchCommunities() { Set<Long> matchingCommunitySetCandidate1 = ImmutableSet.of(1L, 2L); Set<Long> matchingCommunitySetCandidate2 = ImmutableSet.of(1L); Set<Long> nonMatchingCommunitySetCandidate = ImmutableSet.of(2L); LiteralCommunitySet l = new LiteralCommunitySet(ImmutableSet.of(1L, 3L)); assertThat(l, matchCommunities(null, matchingCommunitySetCandidate1)); assertThat(l, matchCommunities(null, matchingCommunitySetCandidate2)); assertThat(l, not(matchCommunities(null, nonMatchingCommunitySetCandidate))); }
@Test public void testMatchCommunity() { LiteralCommunitySet l = new LiteralCommunitySet(ImmutableSet.of(1L, 3L)); assertThat(l, matchCommunity(null, 1L)); assertThat(l, not(matchCommunity(null, 2L))); }