@Test public void testWithCallExprs() { ConjunctionChain conjunctionChain = new ConjunctionChain( ImmutableList.of(new CallExpr(P1.getName()), new CallExpr(P2.getName()))); NavigableMap<String, RoutingPolicy> policiesMap = ImmutableSortedMap.of( P1.getName(), P1, P2.getName(), P2, DEFAULT_POLICY.getName(), DEFAULT_POLICY); StaticRoute.Builder srb = StaticRoute.builder().setAdmin(5).setMetric(10L); Environment environment = buildEnvironment( policiesMap, DEFAULT_POLICY.getName(), srb.setTag(1L).setNetwork(NETWORK_1).build()); Result result = conjunctionChain.evaluate(environment); assertThat(environment.getOutputRoute().getMetric(), equalTo(10L)); assertThat(result, equalTo(new Result(true, false, false, false))); environment = buildEnvironment( policiesMap, DEFAULT_POLICY.getName(), srb.setTag(2L).setNetwork(NETWORK_1).build()); result = conjunctionChain.evaluate(environment); assertThat(environment.getOutputRoute().getMetric(), equalTo(10L)); assertThat(result, equalTo(new Result(false, false, false, false))); environment = buildEnvironment( policiesMap, DEFAULT_POLICY.getName(), srb.setTag(1L).setNetwork(NETWORK_2).build()); result = conjunctionChain.evaluate(environment); assertThat(environment.getOutputRoute().getMetric(), equalTo(10L)); assertThat(result, equalTo(new Result(false, false, false, false))); environment = buildEnvironment( policiesMap, DEFAULT_POLICY.getName(), srb.setTag(3L).setNetwork(NETWORK_3).build()); result = conjunctionChain.evaluate(environment); assertThat(environment.getOutputRoute().getMetric(), equalTo(500L)); assertThat(result, equalTo(new Result(false, false, true, false))); }
@Override public Result evaluate(Environment environment) { Result subroutineResult = Result.builder().setFallThrough(true).build(); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { return subroutineResult.toBuilder().setReturn(false).build(); } } if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } }
ConjunctionChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { Result subroutineResult = Result.builder().setFallThrough(true).build(); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { return subroutineResult.toBuilder().setReturn(false).build(); } } if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } }
ConjunctionChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { Result subroutineResult = Result.builder().setFallThrough(true).build(); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { return subroutineResult.toBuilder().setReturn(false).build(); } } if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } ConjunctionChain(List<BooleanExpr> subroutines); }
ConjunctionChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { Result subroutineResult = Result.builder().setFallThrough(true).build(); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { return subroutineResult.toBuilder().setReturn(false).build(); } } if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } ConjunctionChain(List<BooleanExpr> subroutines); @Override T accept(BooleanExprVisitor<T, U> visitor, U arg); @Override Set<String> collectSources(
      Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w); @Override Result evaluate(Environment environment); @Nonnull @JsonProperty(PROP_SUBROUTINES) List<BooleanExpr> getSubroutines(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); }
ConjunctionChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { Result subroutineResult = Result.builder().setFallThrough(true).build(); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { return subroutineResult.toBuilder().setReturn(false).build(); } } if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } ConjunctionChain(List<BooleanExpr> subroutines); @Override T accept(BooleanExprVisitor<T, U> visitor, U arg); @Override Set<String> collectSources(
      Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w); @Override Result evaluate(Environment environment); @Nonnull @JsonProperty(PROP_SUBROUTINES) List<BooleanExpr> getSubroutines(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString();  }