@Test public void testNodeAcceptEdges() { BDD sessionHeaders = PKT.getDstIp().value(10L); BDD srcFwI1 = _fwSrcMgr.getSourceInterfaceBDD(FW_I1); BDD validSrc = _fwSrcMgr.isValidValue(); BDD lastHop1 = _lastHopMgr.getLastHopOutgoingInterfaceBdd(SOURCE1, SOURCE1_IFACE, FW, FW_I1); BDD noLastHop = _lastHopMgr.getNoLastHopOutgoingInterfaceBdd(FW, FW_I1); BDDFirewallSessionTraceInfo sessionInfo = new BDDFirewallSessionTraceInfo( FW, ImmutableSet.of(FW_I1), Accept.INSTANCE, sessionHeaders, IDENTITY); assertThat( nodeAcceptEdges(sessionInfo), contains( edge( new PreInInterface(FW, FW_I1), new NodeAccept(FW), allOf( mapsForward(srcFwI1, sessionHeaders), mapsForward(srcFwI1.and(noLastHop), sessionHeaders), mapsForward(srcFwI1.and(lastHop1), sessionHeaders), mapsBackward(ONE, validSrc.and(sessionHeaders)))))); _fwI1.setFirewallSessionInterfaceInfo( new FirewallSessionInterfaceInfo(false, ImmutableList.of(FW_I1), PERMIT_TCP, null)); assertThat( nodeAcceptEdges(sessionInfo), contains( edge( new PreInInterface(FW, FW_I1), new NodeAccept(FW), allOf( mapsForward(srcFwI1, sessionHeaders.and(_permitTcpBdd)), mapsForward(srcFwI1.and(noLastHop), sessionHeaders.and(_permitTcpBdd)), mapsForward(srcFwI1.and(lastHop1), sessionHeaders.and(_permitTcpBdd)), mapsBackward(ONE, validSrc.and(sessionHeaders).and(_permitTcpBdd)))))); _fwI1.setFirewallSessionInterfaceInfo(null); { BDD poolBdd = PKT.getSrcIp().value(10L); Transition nat = Transitions.eraseAndSet(PKT.getSrcIp(), poolBdd); BDDFirewallSessionTraceInfo natSessionInfo = new BDDFirewallSessionTraceInfo( FW, ImmutableSet.of(FW_I1), Accept.INSTANCE, sessionHeaders, nat); assertThat( nodeAcceptEdges(natSessionInfo), contains( edge( new PreInInterface(FW, FW_I1), new NodeAccept(FW), allOf( mapsForward(srcFwI1, sessionHeaders.and(poolBdd)), mapsForward(srcFwI1.and(noLastHop), sessionHeaders.and(poolBdd)), mapsForward(srcFwI1.and(lastHop1), sessionHeaders.and(poolBdd)), mapsBackward(ONE, validSrc.and(sessionHeaders)), mapsBackward(poolBdd.not(), ZERO))))); } }
@VisibleForTesting Stream<Edge> nodeAcceptEdges(BDDFirewallSessionTraceInfo sessionInfo) { SessionAction action = sessionInfo.getAction(); checkArgument( action instanceof Accept, "Unsupported session action for PreInInterface->NodeAccept edge: %s", action); String hostname = sessionInfo.getHostname(); BDDSourceManager srcMgr = _srcMgrs.get(hostname); BDDOutgoingOriginalFlowFilterManager outgoingOriginalFlowFilterMgr = _outgoingOriginalFlowFilterMgrs.get(hostname); StateExpr postState = new NodeAccept(hostname); return sessionInfo .getSessionScope() .accept( new SessionScopeVisitor<Stream<Edge>>() { @Override public Stream<Edge> visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return incomingSessionScope.getIncomingInterfaces().stream() .map( inIface -> { StateExpr preState = new PreInInterface(hostname, inIface); BDD inAclBdd = getIncomingSessionFilterBdd(hostname, inIface); Transition transition = compose( constraint(sessionInfo.getSessionFlows().and(inAclBdd)), sessionInfo.getTransformation(), removeNodeSpecificConstraints( hostname, _lastHopMgr, outgoingOriginalFlowFilterMgr, srcMgr)); if (transition == Zero.INSTANCE) { return null; } return new Edge(preState, postState, transition); }) .filter(Objects::nonNull); } @Override public Stream<Edge> visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { throw new BatfishException( String.format( "Unexpected SessionScope: Originating from VRF %s", originatingSessionScope.getOriginatingVrf())); } }); }
SessionInstrumentation { @VisibleForTesting Stream<Edge> nodeAcceptEdges(BDDFirewallSessionTraceInfo sessionInfo) { SessionAction action = sessionInfo.getAction(); checkArgument( action instanceof Accept, "Unsupported session action for PreInInterface->NodeAccept edge: %s", action); String hostname = sessionInfo.getHostname(); BDDSourceManager srcMgr = _srcMgrs.get(hostname); BDDOutgoingOriginalFlowFilterManager outgoingOriginalFlowFilterMgr = _outgoingOriginalFlowFilterMgrs.get(hostname); StateExpr postState = new NodeAccept(hostname); return sessionInfo .getSessionScope() .accept( new SessionScopeVisitor<Stream<Edge>>() { @Override public Stream<Edge> visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return incomingSessionScope.getIncomingInterfaces().stream() .map( inIface -> { StateExpr preState = new PreInInterface(hostname, inIface); BDD inAclBdd = getIncomingSessionFilterBdd(hostname, inIface); Transition transition = compose( constraint(sessionInfo.getSessionFlows().and(inAclBdd)), sessionInfo.getTransformation(), removeNodeSpecificConstraints( hostname, _lastHopMgr, outgoingOriginalFlowFilterMgr, srcMgr)); if (transition == Zero.INSTANCE) { return null; } return new Edge(preState, postState, transition); }) .filter(Objects::nonNull); } @Override public Stream<Edge> visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { throw new BatfishException( String.format( "Unexpected SessionScope: Originating from VRF %s", originatingSessionScope.getOriginatingVrf())); } }); } }
SessionInstrumentation { @VisibleForTesting Stream<Edge> nodeAcceptEdges(BDDFirewallSessionTraceInfo sessionInfo) { SessionAction action = sessionInfo.getAction(); checkArgument( action instanceof Accept, "Unsupported session action for PreInInterface->NodeAccept edge: %s", action); String hostname = sessionInfo.getHostname(); BDDSourceManager srcMgr = _srcMgrs.get(hostname); BDDOutgoingOriginalFlowFilterManager outgoingOriginalFlowFilterMgr = _outgoingOriginalFlowFilterMgrs.get(hostname); StateExpr postState = new NodeAccept(hostname); return sessionInfo .getSessionScope() .accept( new SessionScopeVisitor<Stream<Edge>>() { @Override public Stream<Edge> visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return incomingSessionScope.getIncomingInterfaces().stream() .map( inIface -> { StateExpr preState = new PreInInterface(hostname, inIface); BDD inAclBdd = getIncomingSessionFilterBdd(hostname, inIface); Transition transition = compose( constraint(sessionInfo.getSessionFlows().and(inAclBdd)), sessionInfo.getTransformation(), removeNodeSpecificConstraints( hostname, _lastHopMgr, outgoingOriginalFlowFilterMgr, srcMgr)); if (transition == Zero.INSTANCE) { return null; } return new Edge(preState, postState, transition); }) .filter(Objects::nonNull); } @Override public Stream<Edge> visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { throw new BatfishException( String.format( "Unexpected SessionScope: Originating from VRF %s", originatingSessionScope.getOriginatingVrf())); } }); } @VisibleForTesting  SessionInstrumentation(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      Map<String, BDDSourceManager> srcMgrs,
      LastHopOutgoingInterfaceManager lastHopMgr,
      Map<String, BDDOutgoingOriginalFlowFilterManager> outgoingOriginalFlowFilterMgrs,
      @Nullable Map<String, Map<String, Supplier<BDD>>> filterBdds); }
SessionInstrumentation { @VisibleForTesting Stream<Edge> nodeAcceptEdges(BDDFirewallSessionTraceInfo sessionInfo) { SessionAction action = sessionInfo.getAction(); checkArgument( action instanceof Accept, "Unsupported session action for PreInInterface->NodeAccept edge: %s", action); String hostname = sessionInfo.getHostname(); BDDSourceManager srcMgr = _srcMgrs.get(hostname); BDDOutgoingOriginalFlowFilterManager outgoingOriginalFlowFilterMgr = _outgoingOriginalFlowFilterMgrs.get(hostname); StateExpr postState = new NodeAccept(hostname); return sessionInfo .getSessionScope() .accept( new SessionScopeVisitor<Stream<Edge>>() { @Override public Stream<Edge> visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return incomingSessionScope.getIncomingInterfaces().stream() .map( inIface -> { StateExpr preState = new PreInInterface(hostname, inIface); BDD inAclBdd = getIncomingSessionFilterBdd(hostname, inIface); Transition transition = compose( constraint(sessionInfo.getSessionFlows().and(inAclBdd)), sessionInfo.getTransformation(), removeNodeSpecificConstraints( hostname, _lastHopMgr, outgoingOriginalFlowFilterMgr, srcMgr)); if (transition == Zero.INSTANCE) { return null; } return new Edge(preState, postState, transition); }) .filter(Objects::nonNull); } @Override public Stream<Edge> visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { throw new BatfishException( String.format( "Unexpected SessionScope: Originating from VRF %s", originatingSessionScope.getOriginatingVrf())); } }); } @VisibleForTesting  SessionInstrumentation(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      Map<String, BDDSourceManager> srcMgrs,
      LastHopOutgoingInterfaceManager lastHopMgr,
      Map<String, BDDOutgoingOriginalFlowFilterManager> outgoingOriginalFlowFilterMgrs,
      @Nullable Map<String, Map<String, Supplier<BDD>>> filterBdds); static Stream<Edge> sessionInstrumentation(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      Map<String, BDDSourceManager> srcMgrs,
      LastHopOutgoingInterfaceManager lastHopMgr,
      Map<String, BDDOutgoingOriginalFlowFilterManager> outgoingOriginalFlowFilterMgrs,
      Map<String, Map<String, Supplier<BDD>>> filterBdds,
      Stream<Edge> originalEdges,
      Map<String, List<BDDFirewallSessionTraceInfo>> initializedSessions,
      BDDFibGenerator bddFibGenerator); }
SessionInstrumentation { @VisibleForTesting Stream<Edge> nodeAcceptEdges(BDDFirewallSessionTraceInfo sessionInfo) { SessionAction action = sessionInfo.getAction(); checkArgument( action instanceof Accept, "Unsupported session action for PreInInterface->NodeAccept edge: %s", action); String hostname = sessionInfo.getHostname(); BDDSourceManager srcMgr = _srcMgrs.get(hostname); BDDOutgoingOriginalFlowFilterManager outgoingOriginalFlowFilterMgr = _outgoingOriginalFlowFilterMgrs.get(hostname); StateExpr postState = new NodeAccept(hostname); return sessionInfo .getSessionScope() .accept( new SessionScopeVisitor<Stream<Edge>>() { @Override public Stream<Edge> visitIncomingSessionScope( IncomingSessionScope incomingSessionScope) { return incomingSessionScope.getIncomingInterfaces().stream() .map( inIface -> { StateExpr preState = new PreInInterface(hostname, inIface); BDD inAclBdd = getIncomingSessionFilterBdd(hostname, inIface); Transition transition = compose( constraint(sessionInfo.getSessionFlows().and(inAclBdd)), sessionInfo.getTransformation(), removeNodeSpecificConstraints( hostname, _lastHopMgr, outgoingOriginalFlowFilterMgr, srcMgr)); if (transition == Zero.INSTANCE) { return null; } return new Edge(preState, postState, transition); }) .filter(Objects::nonNull); } @Override public Stream<Edge> visitOriginatingSessionScope( OriginatingSessionScope originatingSessionScope) { throw new BatfishException( String.format( "Unexpected SessionScope: Originating from VRF %s", originatingSessionScope.getOriginatingVrf())); } }); } @VisibleForTesting  SessionInstrumentation(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      Map<String, BDDSourceManager> srcMgrs,
      LastHopOutgoingInterfaceManager lastHopMgr,
      Map<String, BDDOutgoingOriginalFlowFilterManager> outgoingOriginalFlowFilterMgrs,
      @Nullable Map<String, Map<String, Supplier<BDD>>> filterBdds); static Stream<Edge> sessionInstrumentation(
      BDDPacket bddPacket,
      Map<String, Configuration> configs,
      Map<String, BDDSourceManager> srcMgrs,
      LastHopOutgoingInterfaceManager lastHopMgr,
      Map<String, BDDOutgoingOriginalFlowFilterManager> outgoingOriginalFlowFilterMgrs,
      Map<String, Map<String, Supplier<BDD>>> filterBdds,
      Stream<Edge> originalEdges,
      Map<String, List<BDDFirewallSessionTraceInfo>> initializedSessions,
      BDDFibGenerator bddFibGenerator);  }