@Test public void testSetCommunities() { RoutingPolicy policy = _policyBuilder .addStatement( new SetCommunities( new CommunityExprsSet( ImmutableSet.of( new StandardCommunityHighLowExprs( new LiteralInt(30), new LiteralInt(40)), new StandardCommunityHighLowExprs( new LiteralInt(40), new LiteralInt(40)))))) .addStatement(new StaticStatement(Statements.ExitAccept)) .build(); _g = new Graph(_batfish, _batfish.getSnapshot(), true); TransferBDD tbdd = new TransferBDD(_g, _baseConfig, policy.getStatements()); TransferReturn result = tbdd.compute(ImmutableSet.of()).getReturnValue(); BDD acceptedAnnouncements = result.getSecond(); BDDRoute outAnnouncements = result.getFirst(); assertTrue(acceptedAnnouncements.isOne()); Map<CommunityVar, Set<Integer>> regexAPs = _g.getCommunityAtomicPredicates().getRegexAtomicPredicates(); Set<Integer> aps3040 = regexAPs.get(CommunityVar.from(StandardCommunity.parse("30:40"))); Set<Integer> aps4040 = regexAPs.get(CommunityVar.from(StandardCommunity.parse("40:40"))); for (int i = 0; i < _g.getCommunityAtomicPredicates().getNumAtomicPredicates(); i++) { assertEquals( aps3040.contains(i) || aps4040.contains(i) ? outAnnouncements.getFactory().one() : outAnnouncements.getFactory().zero(), outAnnouncements.getCommunityAtomicPredicates()[i]); } }
private void setCommunities( Set<CommunityVar> comms, TransferParam<BDDRoute> curP, TransferResult result) { Set<Integer> commAPs = atomicPredicatesFor(comms, _communityAtomicPredicates); BDD[] commAPBDDs = curP.getData().getCommunityAtomicPredicates(); for (int ap = 0; ap < commAPBDDs.length; ap++) { curP.indent().debug("Value: " + ap); BDD comm = commAPBDDs[ap]; BDD newValue = ite(unreachable(result), comm, commAPs.contains(ap) ? factory.one() : factory.zero()); curP.indent().debug("New Value: " + newValue); commAPBDDs[ap] = newValue; } }
TransferBDD { private void setCommunities( Set<CommunityVar> comms, TransferParam<BDDRoute> curP, TransferResult result) { Set<Integer> commAPs = atomicPredicatesFor(comms, _communityAtomicPredicates); BDD[] commAPBDDs = curP.getData().getCommunityAtomicPredicates(); for (int ap = 0; ap < commAPBDDs.length; ap++) { curP.indent().debug("Value: " + ap); BDD comm = commAPBDDs[ap]; BDD newValue = ite(unreachable(result), comm, commAPs.contains(ap) ? factory.one() : factory.zero()); curP.indent().debug("New Value: " + newValue); commAPBDDs[ap] = newValue; } } }
TransferBDD { private void setCommunities( Set<CommunityVar> comms, TransferParam<BDDRoute> curP, TransferResult result) { Set<Integer> commAPs = atomicPredicatesFor(comms, _communityAtomicPredicates); BDD[] commAPBDDs = curP.getData().getCommunityAtomicPredicates(); for (int ap = 0; ap < commAPBDDs.length; ap++) { curP.indent().debug("Value: " + ap); BDD comm = commAPBDDs[ap]; BDD newValue = ite(unreachable(result), comm, commAPs.contains(ap) ? factory.one() : factory.zero()); curP.indent().debug("New Value: " + newValue); commAPBDDs[ap] = newValue; } } TransferBDD(Graph g, Configuration conf, List<Statement> statements); }
TransferBDD { private void setCommunities( Set<CommunityVar> comms, TransferParam<BDDRoute> curP, TransferResult result) { Set<Integer> commAPs = atomicPredicatesFor(comms, _communityAtomicPredicates); BDD[] commAPBDDs = curP.getData().getCommunityAtomicPredicates(); for (int ap = 0; ap < commAPBDDs.length; ap++) { curP.indent().debug("Value: " + ap); BDD comm = commAPBDDs[ap]; BDD newValue = ite(unreachable(result), comm, commAPs.contains(ap) ? factory.one() : factory.zero()); curP.indent().debug("New Value: " + newValue); commAPBDDs[ap] = newValue; } } TransferBDD(Graph g, Configuration conf, List<Statement> statements); static BDD firstBitsEqual(BDD[] bits, Prefix p, int length); static BDD isRelevantFor(BDDRoute record, PrefixRange range); TransferResult compute(@Nullable Set<Prefix> ignoredNetworks); Map<CommunityVar, Set<Integer>> getCommunityAtomicPredicates(); Configuration getConfiguration(); Graph getGraph(); }
TransferBDD { private void setCommunities( Set<CommunityVar> comms, TransferParam<BDDRoute> curP, TransferResult result) { Set<Integer> commAPs = atomicPredicatesFor(comms, _communityAtomicPredicates); BDD[] commAPBDDs = curP.getData().getCommunityAtomicPredicates(); for (int ap = 0; ap < commAPBDDs.length; ap++) { curP.indent().debug("Value: " + ap); BDD comm = commAPBDDs[ap]; BDD newValue = ite(unreachable(result), comm, commAPs.contains(ap) ? factory.one() : factory.zero()); curP.indent().debug("New Value: " + newValue); commAPBDDs[ap] = newValue; } } TransferBDD(Graph g, Configuration conf, List<Statement> statements); static BDD firstBitsEqual(BDD[] bits, Prefix p, int length); static BDD isRelevantFor(BDDRoute record, PrefixRange range); TransferResult compute(@Nullable Set<Prefix> ignoredNetworks); Map<CommunityVar, Set<Integer>> getCommunityAtomicPredicates(); Configuration getConfiguration(); Graph getGraph();  }