@Override public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) { Conjunction conj = new Conjunction(); for (String conjunct : _conjuncts) { PolicyStatement conjunctPs = jc.getMasterLogicalSystem().getPolicyStatements().get(conjunct); if (conjunctPs != null) { conj.getConjuncts().add(new CallExpr(conjunct)); } else { warnings.redFlag("Reference to undefined policy conjunct: \"" + conjunct + "\""); } } return conj; } }
_simplified = simpleConjuncts.get(0); } else { Conjunction simple = new Conjunction(); simple.setConjuncts(simpleConjuncts); simple.setComment(getComment()); _simplified = simple; simple._simplified = _simplified;
@Override public BooleanExpr toBooleanExpr(CiscoConfiguration cc, Configuration c, Warnings w) { Conjunction conj = new Conjunction(); BooleanExpr left = _left.toBooleanExpr(cc, c, w); BooleanExpr right = _right.toBooleanExpr(cc, c, w); List<BooleanExpr> conjuncts = conj.getConjuncts(); conjuncts.add(left); conjuncts.add(right); return conj.simplify(); } }
/** * Create a filter that only allows traffic for those prefixes if it came from outside. EXTERNAL = * (protocol is bgp or ibgp) and (the AS path is not an internal path) MATCH = destination matches * the prefixTrie GUARD = EXTERNAL or MATCH (only allow this traffic through) */ @Nonnull private BooleanExpr matchExternalTraffic() { List<AsPathSetElem> elements = new ArrayList<>(); elements.add(new RegexAsPathSetElem(_internalRegex)); ExplicitAsPathSet expr = new ExplicitAsPathSet(elements); MatchAsPath matchPath = new MatchAsPath(expr); MatchProtocol mpBgp = new MatchProtocol(RoutingProtocol.BGP); MatchProtocol mpIbgp = new MatchProtocol(RoutingProtocol.IBGP); Disjunction d = new Disjunction(); List<BooleanExpr> disjuncts = new ArrayList<>(); disjuncts.add(mpBgp); disjuncts.add(mpIbgp); d.setDisjuncts(disjuncts); Not n = new Not(matchPath); Conjunction c = new Conjunction(); List<BooleanExpr> conjuncts = new ArrayList<>(); conjuncts.add(d); conjuncts.add(n); c.setConjuncts(conjuncts); return c; }
exportConditions.add(new Conjunction(generateAggregateConditions)); if (redistributeRipPolicy != null) { BooleanExpr weInterior = BooleanExprs.TRUE; Conjunction exportRipConditions = new Conjunction(); exportRipConditions.setComment("Redistribute RIP routes into BGP"); exportRipConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.RIP)); String mapName = redistributeRipPolicy.getRouteMap(); if (mapName != null) { exportRipConditions.getConjuncts().add(we); exportConditions.add(exportRipConditions); if (redistributeStaticPolicy != null) { BooleanExpr weInterior = BooleanExprs.TRUE; Conjunction exportStaticConditions = new Conjunction(); exportStaticConditions.setComment("Redistribute static routes into BGP"); exportStaticConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.STATIC)); String mapName = redistributeStaticPolicy.getRouteMap(); if (mapName != null) { exportStaticConditions.getConjuncts().add(we); exportConditions.add(exportStaticConditions); if (redistributeConnectedPolicy != null) { BooleanExpr weInterior = BooleanExprs.TRUE; Conjunction exportConnectedConditions = new Conjunction(); exportConnectedConditions.setComment("Redistribute connected routes into BGP"); exportConnectedConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.CONNECTED));
exportConditions.add(new Conjunction(generateAggregateConditions)); bgpRedistributeWithEnvironmentExpr( map == null ? BooleanExprs.TRUE : new CallExpr(routeMap), OriginType.INCOMPLETE)); Conjunction rip = new Conjunction(conditions); rip.setComment("Redistribute RIP routes into BGP"); exportConditions.add(rip); bgpRedistributeWithEnvironmentExpr( map == null ? BooleanExprs.TRUE : new CallExpr(routeMap), OriginType.INCOMPLETE)); Conjunction staticRedist = new Conjunction(conditions); staticRedist.setComment("Redistribute static routes into BGP"); exportConditions.add(staticRedist); bgpRedistributeWithEnvironmentExpr( map == null ? BooleanExprs.TRUE : new CallExpr(routeMap), OriginType.INCOMPLETE)); Conjunction connected = new Conjunction(conditions); connected.setComment("Redistribute connected routes into BGP"); exportConditions.add(connected); bgpRedistributeWithEnvironmentExpr( map == null ? BooleanExprs.TRUE : new CallExpr(routeMap), OriginType.INCOMPLETE)); Conjunction ospf = new Conjunction(conditions); ospf.setComment("Redistribute OSPF routes into BGP"); exportConditions.add(ospf); OriginType.IGP)); newBgpProcess.addToOriginationSpace(exportSpace); exportConditions.add(new Conjunction(exportNetworkConditions));
/** * 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()); }
if (expr instanceof Conjunction) { Conjunction c = (Conjunction) expr; if (c.getConjuncts().size() >= 2) { BooleanExpr be1 = c.getConjuncts().get(0); BooleanExpr be2 = c.getConjuncts().get(1); if (be1 instanceof MatchPrefixSet && be2 instanceof Not) { MatchPrefixSet mps = (MatchPrefixSet) be1;
@Override public String toString() { return toStringHelper().add(PROP_CONJUNCTS, _conjuncts).toString(); } }
we4.setExpr(we3); Conjunction conj = new Conjunction(); conj.setConjuncts(ImmutableList.of(we4));
@Override public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) { Interface iface = c.getAllInterfaces().get(_name); if (iface == null) { // No such interface, won't match anything return BooleanExprs.FALSE; } // Convert to conjunction of connected protocol and matching at least one of the interface // prefixes return new Conjunction( ImmutableList.of( new MatchProtocol(RoutingProtocol.CONNECTED), new MatchPrefixSet( DestinationNetwork.instance(), new ExplicitPrefixSet( new PrefixSpace( c.getAllInterfaces().get(_name).getAllAddresses().stream() .map(InterfaceAddress::getPrefix) .map(PrefixRange::fromPrefix) .collect(ImmutableSet.toImmutableSet())))))); } }
if (e instanceof Conjunction) { Conjunction c = (Conjunction) e; for (BooleanExpr be : c.getConjuncts()) { visit(conf, be, fs, fe);
If convertOspfRedistributionPolicy(OspfRedistributionPolicy policy, OspfProcess proc) { RoutingProtocol protocol = policy.getSourceProtocol(); Conjunction ospfExportConditions = new Conjunction(); if (protocol == RoutingProtocol.EIGRP) { ospfExportConditions .getConjuncts() .add( new Disjunction( new MatchProtocol(RoutingProtocol.EIGRP_EX)))); } else { ospfExportConditions.getConjuncts().add(new MatchProtocol(protocol)); ospfExportConditions.getConjuncts().add(NOT_DEFAULT_ROUTE); ospfExportConditions.getConjuncts().add(RouteIsClassful.instance()); RouteMap exportRouteMap = _routeMaps.get(exportRouteMapName); if (exportRouteMap != null) { ospfExportConditions.getConjuncts().add(new CallExpr(exportRouteMapName));
private RoutingPolicy toRoutingPolicy(RouteMap routeMap) { String name = routeMap.getName(); RoutingPolicy routingPolicy = new RoutingPolicy(name, _c); List<Statement> statements = routingPolicy.getStatements(); for (Entry<Integer, RouteMapRule> e : routeMap.getRules().entrySet()) { String ruleName = Integer.toString(e.getKey()); RouteMapRule rule = e.getValue(); If ifStatement = new If(); List<Statement> trueStatements = ifStatement.getTrueStatements(); ifStatement.setComment(ruleName); Conjunction conj = new Conjunction(); for (RouteMapMatch match : rule.getMatches()) { conj.getConjuncts().add(match.toBooleanExpr(this, _c, _w)); } ifStatement.setGuard(conj.simplify()); switch (rule.getAction()) { case PERMIT: trueStatements.add(Statements.ExitAccept.toStaticStatement()); break; case DENY: trueStatements.add(Statements.ExitReject.toStaticStatement()); break; default: throw new BatfishException("Invalid action"); } statements.add(ifStatement); } statements.add(Statements.ExitReject.toStaticStatement()); return routingPolicy; }
private void applyLocalRoutePolicy(RoutingInstance routingInstance, RoutingPolicy targetPolicy) { boolean lan = routingInstance.getExportLocalRoutesLan(); boolean ptp = routingInstance.getExportLocalRoutesPointToPoint(); if (lan && ptp) { // All local routes are allowed, so no need for filter return; } BooleanExpr matchProtocol = new MatchProtocol(RoutingProtocol.LOCAL); BooleanExpr match; if (!lan && !ptp) { // No need to check length, since all local routes will be rejected match = matchProtocol; } else { SubRange rejectedLength = !lan ? new SubRange(0, Prefix.MAX_PREFIX_LENGTH - 2) : new SubRange(Prefix.MAX_PREFIX_LENGTH - 1, Prefix.MAX_PREFIX_LENGTH - 1); match = new Conjunction( ImmutableList.of( matchProtocol, new MatchLocalRouteSourcePrefixLength(rejectedLength))); } targetPolicy .getStatements() .add(new If(match, ImmutableList.of(Statements.ExitReject.toStaticStatement()))); }
BoolExpr acc = _enc.mkTrue(); TransferResult<BoolExpr, BoolExpr> result = new TransferResult<>(); for (BooleanExpr be : c.getConjuncts()) { TransferResult<BoolExpr, BoolExpr> r = compute(be, pCur.indent()); result = result.addChangedVariables(r);
RouteMapClause rmClause = e.getValue(); String clausePolicyName = getRouteMapClausePolicyName(map, clauseNumber); Conjunction conj = new Conjunction(); matchIpOrPrefix.getDisjuncts().add(matchExpr); } else { conj.getConjuncts().add(matchExpr); conj.getConjuncts().add(matchIpOrPrefix);
Conjunction conj = new Conjunction(); List<BooleanExpr> subroutines = new ArrayList<>(); if (!froms.getFromAsPaths().isEmpty()) { conj.getConjuncts().add(new Disjunction(toBooleanExprs(froms.getFromAsPaths()))); conj.getConjuncts().add(froms.getFromColor().toBooleanExpr(this, _c, _w)); conj.getConjuncts().add(new Disjunction(toBooleanExprs(froms.getFromCommunities()))); conj.getConjuncts().add(froms.getFromFamily().toBooleanExpr(this, _c, _w)); conj.getConjuncts().add(new Disjunction(toBooleanExprs(froms.getFromInterfaces()))); conj.getConjuncts().add(froms.getFromLocalPreference().toBooleanExpr(this, _c, _w)); conj.getConjuncts().add(froms.getFromMetric().toBooleanExpr(this, _c, _w)); .addAll(toBooleanExprs(froms.getFromPrefixListFilterOrLongers())); prefixListDisjunction.getDisjuncts().addAll(toBooleanExprs(froms.getFromRouteFilters())); conj.getConjuncts().add(prefixListDisjunction); conj.getConjuncts().add(new Disjunction(toBooleanExprs(froms.getFromProtocols()))); conj.getConjuncts().add(new Disjunction(toBooleanExprs(froms.getFromTags()))); conj.getConjuncts().add(chain); return conj.simplify();
BDD acc = factory.one(); TransferResult<TransferReturn, BDD> result = new TransferResult<>(); for (BooleanExpr be : c.getConjuncts()) { TransferResult<TransferReturn, BDD> r = compute(be, p.indent()); acc = acc.and(r.getReturnValue().getSecond());
RoutingProtocol protocol = policy.getSourceProtocol(); Conjunction eigrpExportConditions = new Conjunction(); BooleanExpr matchExpr; if (protocol == RoutingProtocol.EIGRP) { return null; eigrpExportConditions.getConjuncts().add(new MatchProcessAsn(otherAsn)); } else { matchExpr = new MatchProtocol(protocol); eigrpExportConditions.getConjuncts().add(matchExpr); RouteMap exportRouteMap = oldConfig.getRouteMaps().get(exportRouteMapName); if (exportRouteMap != null) { eigrpExportConditions.getConjuncts().add(new CallExpr(exportRouteMapName));