@Override public CommunitySetExpr toCommunitySetExpr(CiscoConfiguration cc, Configuration c, Warnings w) { return new NamedCommunitySet(_name); } }
@Override public SortedSet<Long> matchedCommunities( Environment environment, Set<Long> communityCandidates) { return resolve(environment).matchedCommunities(environment, communityCandidates); }
@Override public void visitNamedCommunitySet(NamedCommunitySet namedCommunitySet) { visitCommunityList(_configuration.getCommunityLists().get(namedCommunitySet.getName())); }
private BoolExpr matchCommunitySet(Configuration conf, CommunitySetExpr e, SymbolicRoute other) { if (e instanceof CommunityList) { Set<CommunityVar> comms = collectCommunityVars(conf, e); BoolExpr acc = _enc.mkTrue(); for (CommunityVar comm : comms) { BoolExpr c = other.getCommunities().get(comm); if (c == null) { throw new BatfishException("matchCommunitySet: should not be null"); } acc = _enc.mkAnd(acc, c); } return acc; } if (e instanceof NamedCommunitySet) { NamedCommunitySet x = (NamedCommunitySet) e; CommunityList cl = conf.getCommunityLists().get(x.getName()); return matchCommunityList(cl, other); } throw new BatfishException("TODO: match community set"); }
@Override public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) { return new MatchCommunitySet(new NamedCommunitySet(_name)); } }
@Override public boolean matchCommunities(Environment environment, Set<Long> communitySetCandidate) { return resolve(environment).matchCommunities(environment, communitySetCandidate); }
private BDD matchCommunitySet( TransferParam<BDDRoute> p, Configuration conf, CommunitySetExpr e, BDDRoute other) { if (e instanceof CommunityList) { Set<CommunityVar> comms = ((CommunityList) e) .getLines().stream() .map(line -> toCommunityVar(line.getMatchCondition())) .collect(Collectors.toSet()); BDD acc = factory.one(); for (CommunityVar comm : comms) { p.debug("Inline Community Set: " + comm); BDD c = other.getCommunities().get(comm); if (c == null) { throw new BatfishException("matchCommunitySet: should not be null"); } acc = acc.and(c); } return acc; } if (e instanceof NamedCommunitySet) { p.debug("Named"); NamedCommunitySet x = (NamedCommunitySet) e; CommunityList cl = conf.getCommunityLists().get(x.getName()); p.debug("Named Community Set: " + cl.getName()); return matchCommunityList(p, cl, other); } throw new BatfishException("TODO: match community set"); }
@JsonCreator private static NamedCommunitySet create(@JsonProperty(PROP_NAME) String name) { return new NamedCommunitySet(requireNonNull(name)); }
@Override public SortedSet<Long> asLiteralCommunities(Environment environment) { return resolve(environment).asLiteralCommunities(environment); }
@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 boolean matchAnyCommunity(Environment environment, Set<Long> communityCandidates) { return resolve(environment).matchAnyCommunity(environment, communityCandidates); }
@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)));
@Test public void testAsLiteralCommunities() { long val = 1L; NamedCommunitySet expr = new NamedCommunitySet(COMMUNITY_LIST_NAME); assertThat(expr, asLiteralCommunities(_env, equalTo(ImmutableSet.of(val)))); }
statements.add( new AddCommunity( new org.batfish.datamodel.routing_policy.expr.NamedCommunitySet( communityListName))));
@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 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))); }