@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); } } }
if (expr instanceof MatchProtocol) { MatchProtocol mp = (MatchProtocol) expr; RoutingProtocol other = mp.getProtocol(); Protocol otherP = Protocol.fromRoutingProtocol(other); if (otherP != null && otherP != p) {
MatchProtocol mp = new MatchProtocol(RoutingProtocol.ISIS_ANY); Environment.Builder eb = Environment.builder(c).setVrf(Configuration.DEFAULT_VRF_NAME); mp.evaluate( eb.setOriginalRoute( rb.setProtocol(RoutingProtocol.ISIS_L1).setLevel(IsisLevel.LEVEL_1).build()) assertThat( "Matches ISIS_L2", mp.evaluate( eb.setOriginalRoute( rb.setProtocol(RoutingProtocol.ISIS_L2).setLevel(IsisLevel.LEVEL_2).build()) assertThat( "Matches ISIS_EL1", mp.evaluate( eb.setOriginalRoute( rb.setProtocol(RoutingProtocol.ISIS_EL1) assertThat( "Matches ISIS_EL2", mp.evaluate( eb.setOriginalRoute( rb.setProtocol(RoutingProtocol.ISIS_EL2) "Does not match ISIS_ANY", not( mp.evaluate( eb.setOriginalRoute(
@JsonCreator private static MatchProtocol create( @Nullable @JsonProperty(PROP_PROTOCOL) RoutingProtocol protocol) { checkArgument(protocol != null, "MatchProtocol missing %s", PROP_PROTOCOL); return new MatchProtocol(protocol); }
if (n.getExpr() instanceof MatchProtocol) { MatchProtocol mp = (MatchProtocol) n.getExpr(); if (mp.getProtocol() == RoutingProtocol.BGP) { PrefixSetExpr e = mps.getPrefixSet(); if (e instanceof ExplicitPrefixSet) {
/** * 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(); }
Protocol proto = Protocol.fromRoutingProtocol(mp.getProtocol()); if (proto == null) { pCur.debug("MatchProtocol(" + mp.getProtocol().protocolName() + "): false"); return fromExpr(_enc.mkFalse()); pCur.debug("MatchProtocol(" + mp.getProtocol().protocolName() + "): " + protoMatch); return fromExpr(protoMatch); pCur.debug("MatchProtocol(" + mp.getProtocol().protocolName() + "): " + protoMatch); return fromExpr(protoMatch);
@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(); } }
Protocol proto = Protocol.fromRoutingProtocol(mp.getProtocol()); if (proto == null) { p.debug("MatchProtocol(" + mp.getProtocol().protocolName() + "): false"); TransferReturn ret = new TransferReturn(p.getData(), factory.zero()); return fromExpr(ret); p.debug("MatchProtocol(" + mp.getProtocol().protocolName() + "): " + protoMatch); TransferReturn ret = new TransferReturn(p.getData(), protoMatch); return fromExpr(ret);
/** * 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)),