@Override public BooleanExpr toBooleanExpr(JuniperConfiguration jc, Configuration c, Warnings warnings) { if (_protocol == RoutingProtocol.BGP) { return new Disjunction( new MatchProtocol(RoutingProtocol.BGP), new MatchProtocol(RoutingProtocol.IBGP)); } else { return new MatchProtocol(_protocol); } } }
@JsonCreator private static MatchProtocol create( @Nullable @JsonProperty(PROP_PROTOCOL) RoutingProtocol protocol) { checkArgument(protocol != null, "MatchProtocol missing %s", PROP_PROTOCOL); return new MatchProtocol(protocol); }
/** * Generate a {@link RoutingPolicy} for use when importing routes from pseudo-protocols (direct, * static, aggregate, generated) */ @VisibleForTesting static RoutingPolicy generateDefaultPseudoProtocolImportPolicy(@Nonnull Configuration c) { return RoutingPolicy.builder() .setOwner(c) .setName(DEFAULT_PSEUDO_PROTOCOL_IMPORT_POLICY_NAME) .setStatements( ImmutableList.of( new If( new Disjunction( new MatchProtocol(RoutingProtocol.CONNECTED), new MatchProtocol(RoutingProtocol.LOCAL), new MatchProtocol(RoutingProtocol.STATIC), new MatchProtocol(RoutingProtocol.AGGREGATE)), ImmutableList.of(Statements.ReturnTrue.toStaticStatement()), ImmutableList.of(Statements.ReturnFalse.toStaticStatement())))) .build(); }
@Override public BooleanExpr toBooleanExpr(Configuration c, CiscoConfiguration cc, Warnings w) { Disjunction d = new Disjunction(); List<BooleanExpr> disjuncts = d.getDisjuncts(); for (String protocol : _protocols) { disjuncts.add(new MatchProtocol(RoutingProtocol.fromProtocolName(protocol))); } return d.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; }
@Test public void testJavaSerialization() { MatchProtocol mp = new MatchProtocol(RoutingProtocol.STATIC); assertThat(SerializationUtils.clone(mp), equalTo(mp)); }
@Test public void testJsonSerialization() throws IOException { MatchProtocol mp = new MatchProtocol(RoutingProtocol.STATIC); assertThat(BatfishObjectMapper.clone(mp, MatchProtocol.class), equalTo(mp)); }
new Disjunction( ImmutableList.of( new MatchProtocol(RoutingProtocol.EIGRP), new MatchProtocol(RoutingProtocol.EIGRP_EX)))); } else { ospfExportConditions.getConjuncts().add(new MatchProtocol(protocol));
@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())))))); } }
@Test public void testEquals() { new EqualsTester() .addEqualityGroup( new MatchProtocol(RoutingProtocol.STATIC), new MatchProtocol(RoutingProtocol.STATIC)) .addEqualityGroup(new MatchProtocol(RoutingProtocol.BGP)) .addEqualityGroup(new Object()) .testEquals(); }
private void initDefaultBgpExportPolicy() { if (_c.getRoutingPolicies().containsKey(DEFAULT_BGP_EXPORT_POLICY_NAME)) { return; } // set up default export policy (accept bgp routes) RoutingPolicy defaultBgpExportPolicy = new RoutingPolicy(DEFAULT_BGP_EXPORT_POLICY_NAME, _c); _c.getRoutingPolicies().put(DEFAULT_BGP_EXPORT_POLICY_NAME, defaultBgpExportPolicy); If defaultBgpExportPolicyConditional = new If(); defaultBgpExportPolicy.getStatements().add(defaultBgpExportPolicyConditional); // guard Disjunction isBgp = new Disjunction(); isBgp.getDisjuncts().add(new MatchProtocol(RoutingProtocol.BGP)); isBgp.getDisjuncts().add(new MatchProtocol(RoutingProtocol.IBGP)); defaultBgpExportPolicyConditional.setGuard(isBgp); PsThenAccept.INSTANCE.applyTo( defaultBgpExportPolicyConditional.getTrueStatements(), this, _c, _w); PsThenReject.INSTANCE.applyTo( defaultBgpExportPolicyConditional.getFalseStatements(), this, _c, _w); }
new Disjunction( ImmutableList.of( new MatchProtocol(RoutingProtocol.EIGRP), new MatchProtocol(RoutingProtocol.EIGRP_EX))); matchExpr = new MatchProtocol(protocol);
/** * 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()); }
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()))); }
DestinationNetwork.instance(), new ExplicitPrefixSet(new PrefixSpace(PrefixRange.fromPrefix(prefix))))); generateAggregateConditions.add(new MatchProtocol(RoutingProtocol.AGGREGATE)); new MatchProtocol(RoutingProtocol.RIP), redistributeDefaultRoute, bgpRedistributeWithEnvironmentExpr( List<BooleanExpr> conditions = ImmutableList.of( new MatchProtocol(RoutingProtocol.STATIC), redistributeDefaultRoute, bgpRedistributeWithEnvironmentExpr( List<BooleanExpr> conditions = ImmutableList.of( new MatchProtocol(RoutingProtocol.CONNECTED), redistributeDefaultRoute, bgpRedistributeWithEnvironmentExpr( new MatchProtocol(RoutingProtocol.OSPF), redistributeDefaultRoute, bgpRedistributeWithEnvironmentExpr( new MatchPrefixSet( DestinationNetwork.instance(), new ExplicitPrefixSet(exportSpace)), new Not(new MatchProtocol(RoutingProtocol.BGP)), new Not(new MatchProtocol(RoutingProtocol.IBGP)), new Not(new MatchProtocol(RoutingProtocol.AGGREGATE)),
newProcess.getGeneratedRoutes().add(route.build()); ripExportDefaultConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.AGGREGATE)); ripExportDefaultStatements.add(Statements.ExitAccept.toStaticStatement()); ripExportDefault.setGuard(ripExportDefaultConditions); ripExportConnected.setComment("RIP export connected routes"); Conjunction ripExportConnectedConditions = new Conjunction(); ripExportConnectedConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.CONNECTED)); List<Statement> ripExportConnectedStatements = ripExportConnected.getTrueStatements(); ripExportStatic.setComment("RIP export static routes"); Conjunction ripExportStaticConditions = new Conjunction(); ripExportStaticConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.STATIC)); List<Statement> ripExportStaticStatements = ripExportStatic.getTrueStatements(); ripExportStaticConditions.getConjuncts().add(NOT_DEFAULT_ROUTE); ripExportBgp.setComment("RIP export bgp routes"); Conjunction ripExportBgpConditions = new Conjunction(); ripExportBgpConditions.getConjuncts().add(new MatchProtocol(RoutingProtocol.BGP)); List<Statement> ripExportBgpStatements = ripExportBgp.getTrueStatements(); ripExportBgpConditions.getConjuncts().add(NOT_DEFAULT_ROUTE);
ospfExportDefaultConditions .getConjuncts() .add(new MatchProtocol(RoutingProtocol.AGGREGATE));
If acceptIffEbgp = new If( new MatchProtocol(RoutingProtocol.BGP), ImmutableList.of(Statements.ExitAccept.toStaticStatement()), ImmutableList.of(Statements.ExitReject.toStaticStatement())); Conjunction conj = new Conjunction(); originationIf.setGuard(conj); conj.getConjuncts().add(new MatchProtocol(RoutingProtocol.STATIC)); conj.getConjuncts() .add(
If i = new If( new MatchProtocol(RoutingProtocol.OSPF), ImmutableList.of(Statements.ExitAccept.toStaticStatement()), pol != null
.setSystemId("invalidSystemId"); MatchProtocol mp = new MatchProtocol(RoutingProtocol.ISIS_ANY); Environment.Builder eb = Environment.builder(c).setVrf(Configuration.DEFAULT_VRF_NAME);