@Test public void testEvaluateFibLookupOutgoingInterfaceIsOneOf() { Prefix dstPrefix = _flow.getDstIp().toPrefix(); Ip nextVrIp = Ip.parse("5.5.5.5"); String srcIface = "Eth0"; String vrfName = "vrf"; String nextVrfName = "nextVrf"; String vrfIface = "vrfIface"; String nextVrfIface = "nextVrfIface"; ConnectedRoute fakeRoute = new ConnectedRoute(dstPrefix, vrfIface); Map<String, Fib> fibs = ImmutableMap.of( vrfName, MockFib.builder() .setFibEntries( ImmutableMap.of( _flow.getDstIp(), ImmutableSet.of( new FibEntry( new FibForward(Ip.MAX, vrfIface), ImmutableList.of(fakeRoute))), nextVrIp, ImmutableSet.of( new FibEntry( new FibNextVrf(nextVrfName), ImmutableList.of(fakeRoute))))) .build(), nextVrfName, MockFib.builder() .setFibEntries( ImmutableMap.of( _flow.getDstIp(), ImmutableSet.of( new FibEntry( new FibForward(Ip.MAX, nextVrfIface), ImmutableList.of(fakeRoute))), nextVrIp, ImmutableSet.of( new FibEntry( new FibForward(Ip.MAX, nextVrfIface), ImmutableList.of(fakeRoute))))) .build()); Action trueAction = new FibLookup(new LiteralVrfName("finalVrf")); Return trueReturn = new Return(trueAction); Action defaultAction = Drop.instance(); { FlowResult r = FlowEvaluator.evaluate( _flow, srcIface, vrfName, singletonPolicy( new If( new FibLookupOutgoingInterfaceIsOneOf( IngressInterfaceVrf.instance(), ImmutableSet.of(vrfIface)), Collections.singletonList(trueReturn))), ImmutableMap.of(), ImmutableMap.of(), fibs); assertThat(r.getAction(), equalTo(trueAction)); } { FlowResult r = FlowEvaluator.evaluate( _flow, srcIface, vrfName, singletonPolicy( new If( new FibLookupOutgoingInterfaceIsOneOf( IngressInterfaceVrf.instance(), ImmutableSet.of("NoMatchIface")), Collections.singletonList(trueReturn))), ImmutableMap.of(), ImmutableMap.of(), fibs); assertThat(r.getAction(), equalTo(defaultAction)); } { FlowResult r = FlowEvaluator.evaluate( _flow, srcIface, vrfName, singletonPolicy( new If( new FibLookupOutgoingInterfaceIsOneOf( new LiteralVrfName(nextVrfName), ImmutableSet.of(nextVrfIface)), Collections.singletonList(trueReturn))), ImmutableMap.of(), ImmutableMap.of(), fibs); assertThat(r.getAction(), equalTo(trueAction)); } { Flow flow = _flow.toBuilder().setDstIp(nextVrIp).build(); FlowResult r = FlowEvaluator.evaluate( flow, srcIface, vrfName, singletonPolicy( new If( new FibLookupOutgoingInterfaceIsOneOf( IngressInterfaceVrf.instance(), ImmutableSet.of(nextVrfIface)), Collections.singletonList(trueReturn))), ImmutableMap.of(), ImmutableMap.of(), fibs); assertThat(r.getAction(), equalTo(trueAction)); } }
private FlowResult evaluate(PacketPolicy policy) { Action action = policy.getStatements().stream() .map(_stmtEvaluator::visit) .filter(Objects::nonNull) .findFirst() .orElse(policy.getDefaultAction().getAction()); return new FlowResult(getTransformedFlow(), action); }
FlowEvaluator { private FlowResult evaluate(PacketPolicy policy) { Action action = policy.getStatements().stream() .map(_stmtEvaluator::visit) .filter(Objects::nonNull) .findFirst() .orElse(policy.getDefaultAction().getAction()); return new FlowResult(getTransformedFlow(), action); } }
FlowEvaluator { private FlowResult evaluate(PacketPolicy policy) { Action action = policy.getStatements().stream() .map(_stmtEvaluator::visit) .filter(Objects::nonNull) .findFirst() .orElse(policy.getDefaultAction().getAction()); return new FlowResult(getTransformedFlow(), action); } private  FlowEvaluator(
      Flow originalFlow,
      String srcInterface,
      String srcInterfaceVrf,
      Map<String, IpAccessList> availableAcls,
      Map<String, IpSpace> namedIpSpaces,
      Map<String, Fib> fibs); }
FlowEvaluator { private FlowResult evaluate(PacketPolicy policy) { Action action = policy.getStatements().stream() .map(_stmtEvaluator::visit) .filter(Objects::nonNull) .findFirst() .orElse(policy.getDefaultAction().getAction()); return new FlowResult(getTransformedFlow(), action); } private  FlowEvaluator(
      Flow originalFlow,
      String srcInterface,
      String srcInterfaceVrf,
      Map<String, IpAccessList> availableAcls,
      Map<String, IpSpace> namedIpSpaces,
      Map<String, Fib> fibs); static FlowResult evaluate(
      Flow f,
      String srcInterface,
      String srcInterfaceVrf,
      PacketPolicy policy,
      Map<String, IpAccessList> availableAcls,
      Map<String, IpSpace> namedIpSpaces,
      Map<String, Fib> fibs); }
FlowEvaluator { private FlowResult evaluate(PacketPolicy policy) { Action action = policy.getStatements().stream() .map(_stmtEvaluator::visit) .filter(Objects::nonNull) .findFirst() .orElse(policy.getDefaultAction().getAction()); return new FlowResult(getTransformedFlow(), action); } private  FlowEvaluator(
      Flow originalFlow,
      String srcInterface,
      String srcInterfaceVrf,
      Map<String, IpAccessList> availableAcls,
      Map<String, IpSpace> namedIpSpaces,
      Map<String, Fib> fibs); static FlowResult evaluate(
      Flow f,
      String srcInterface,
      String srcInterfaceVrf,
      PacketPolicy policy,
      Map<String, IpAccessList> availableAcls,
      Map<String, IpSpace> namedIpSpaces,
      Map<String, Fib> fibs);  }