@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(); } }
@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; } }
/** * 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; }
_simplified = simpleConjuncts.get(0); } else { Conjunction simple = new Conjunction(); simple.setConjuncts(simpleConjuncts); simple.setComment(getComment());
/** * 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()); }
@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())))))); } }
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()))); }
RouteMapClause rmClause = e.getValue(); String clausePolicyName = getRouteMapClausePolicyName(map, clauseNumber); Conjunction conj = new Conjunction();
If convertOspfRedistributionPolicy(OspfRedistributionPolicy policy, OspfProcess proc) { RoutingProtocol protocol = policy.getSourceProtocol(); Conjunction ospfExportConditions = new Conjunction(); if (protocol == RoutingProtocol.EIGRP) { ospfExportConditions
RoutingProtocol protocol = policy.getSourceProtocol(); Conjunction eigrpExportConditions = new Conjunction(); BooleanExpr matchExpr; if (protocol == RoutingProtocol.EIGRP) {
RouteMapClause rmClause = e.getValue(); String clausePolicyName = getRouteMapClausePolicyName(map, clauseNumber); Conjunction conj = new Conjunction();
Conjunction conj = new Conjunction(); List<BooleanExpr> subroutines = new ArrayList<>(); if (!froms.getFromAsPaths().isEmpty()) {
ripExportStatements.add(ripExportDefault); ripExportDefault.setComment("RIP export default route"); Conjunction ripExportDefaultConditions = new Conjunction(); List<Statement> ripExportDefaultStatements = ripExportDefault.getTrueStatements(); ripExportDefaultConditions.getConjuncts().add(MATCH_DEFAULT_ROUTE); If ripExportConnected = new If(); ripExportConnected.setComment("RIP export connected routes"); Conjunction ripExportConnectedConditions = new Conjunction(); ripExportConnectedConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.CONNECTED)); List<Statement> ripExportConnectedStatements = ripExportConnected.getTrueStatements(); If ripExportStatic = new If(); ripExportStatic.setComment("RIP export static routes"); Conjunction ripExportStaticConditions = new Conjunction(); ripExportStaticConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.STATIC)); List<Statement> ripExportStaticStatements = ripExportStatic.getTrueStatements(); If ripExportBgp = new If(); ripExportBgp.setComment("RIP export bgp routes"); Conjunction ripExportBgpConditions = new Conjunction(); ripExportBgpConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.BGP)); List<Statement> ripExportBgpStatements = ripExportBgp.getTrueStatements();
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));
ospfExportStatements.add(ospfExportDefault); ospfExportDefault.setComment("OSPF export default route"); Conjunction ospfExportDefaultConditions = new Conjunction(); List<Statement> ospfExportDefaultStatements = ospfExportDefault.getTrueStatements(); ospfExportDefaultConditions.getConjuncts().add(MATCH_DEFAULT_ROUTE);
Conjunction peerExportGuard = new Conjunction(); List<BooleanExpr> peerExportConditions = peerExportGuard.getConjuncts(); exportStatements.add(
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)); 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)); 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)); if (redistributeOspfPolicy != null) { BooleanExpr weInterior = BooleanExprs.TRUE; Conjunction exportOspfConditions = new Conjunction(); exportOspfConditions.setComment("Redistribute OSPF routes into BGP"); exportOspfConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.OSPF)); Conjunction exportNetworkConditions = new Conjunction(); PrefixSpace space = new PrefixSpace(); space.addPrefix(prefix);
we4.setExpr(we3); Conjunction conj = new Conjunction(); conj.setConjuncts(ImmutableList.of(we4));
originationRouteFilter.addLine(matchOutgoingPrefix); }); Conjunction conj = new Conjunction(); originationIf.setGuard(conj); conj.getConjuncts().add(new MatchProtocol(RoutingProtocol.STATIC));