@Override public CommunitySetExpr toCommunitySetExpr(CiscoConfiguration cc, Configuration c, Warnings w) { return new NamedCommunitySet(_name); } }
@Override public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) { return new MatchCommunitySet(new NamedCommunitySet(_name)); } }
@JsonCreator private static NamedCommunitySet create(@JsonProperty(PROP_NAME) String name) { return new NamedCommunitySet(requireNonNull(name)); }
@Override public void applyTo( List<Statement> statements, CiscoConfiguration cc, Configuration c, Warnings w) { CommunityList list = c.getCommunityLists().get(_listName); if (list != null) { statements.add(new DeleteCommunity(new NamedCommunitySet(_listName))); } }
@Override public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) { Disjunction d = new Disjunction(); List<BooleanExpr> disjuncts = d.getDisjuncts(); for (String listName : _listNames) { CommunityList list = c.getCommunityLists().get(listName); if (list != null) { disjuncts.add(new MatchCommunitySet(new NamedCommunitySet(listName))); } } return d.simplify(); } }
@Override public void applyTo( List<Statement> statements, JuniperConfiguration juniperVendorConfiguration, Configuration c, Warnings warnings) { CommunityList namedList = _configuration.getMasterLogicalSystem().getCommunityLists().get(_name); if (namedList == null) { warnings.redFlag("Reference to undefined community: \"" + _name + "\""); } else { org.batfish.datamodel.CommunityList list = c.getCommunityLists().get(_name); if (list == null) { throw new VendorConversionException("missing community list: \"" + _name + "\""); } statements.add(new DeleteCommunity(new NamedCommunitySet(_name))); } }
@Test public void testMatchedCommunities() { NamedCommunitySet expr = new NamedCommunitySet(COMMUNITY_LIST_NAME); Set<Long> communityCandidates = ImmutableSet.of(1L, 2L); assertThat(expr, matchedCommunities(_env, communityCandidates, ImmutableSet.of(1L))); } }
statements.add( new SetCommunity( new org.batfish.datamodel.routing_policy.expr.NamedCommunitySet( communityListName))); } else { statements.add( new AddCommunity( new org.batfish.datamodel.routing_policy.expr.NamedCommunitySet( communityListName)));
statements.add( new AddCommunity( new org.batfish.datamodel.routing_policy.expr.NamedCommunitySet( communityListName))));
@Test public void testAsLiteralCommunities() { long val = 1L; NamedCommunitySet expr = new NamedCommunitySet(COMMUNITY_LIST_NAME); assertThat(expr, asLiteralCommunities(_env, equalTo(ImmutableSet.of(val)))); }
@Test public void testMatchAnyCommunity() { NamedCommunitySet expr = new NamedCommunitySet(COMMUNITY_LIST_NAME); Set<Long> communityCandidates = ImmutableSet.of(1L, 2L); assertThat(expr, matchAnyCommunity(_env, communityCandidates)); }
@Test public void testEquals() { new EqualsTester() .addEqualityGroup( new NamedCommunitySet(COMMUNITY_LIST_NAME), new NamedCommunitySet(COMMUNITY_LIST_NAME)) .addEqualityGroup(new NamedCommunitySet("other")) .testEquals(); }
@Test public void testMatchCommunity() { NamedCommunitySet expr = new NamedCommunitySet(COMMUNITY_LIST_NAME); assertThat(expr, matchCommunity(_env, 1L)); assertThat(expr, not(matchCommunity(_env, 2L))); }
@Test public void testMatchCommunities() { Set<Long> matchingCommunitySetCandidate1 = ImmutableSet.of(1L, 2L); Set<Long> matchingCommunitySetCandidate2 = ImmutableSet.of(1L); Set<Long> nonMatchingCommunitySetCandidate = ImmutableSet.of(2L); NamedCommunitySet expr = new NamedCommunitySet(COMMUNITY_LIST_NAME); assertThat(expr, matchCommunities(_env, matchingCommunitySetCandidate1)); assertThat(expr, matchCommunities(_env, matchingCommunitySetCandidate2)); assertThat(expr, not(matchCommunities(_env, nonMatchingCommunitySetCandidate))); }