@Test public void testBuildAcceptTrace_intranodeTraffic() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); Vrf vrf = nf.vrfBuilder().setOwner(c).build(); vrf.setFirewallSessionVrfInfo(new FirewallSessionVrfInfo(true)); Ip srcIp = Ip.parse("1.1.1.1"); Ip dstIp = Ip.parse("2.2.2.2"); int srcPort = 22; int dstPort = 40; Flow flow = Flow.builder() .setSrcIp(srcIp) .setDstIp(dstIp) .setIngressNode(c.getHostname()) .setIngressVrf(vrf.getName()) .setIpProtocol(IpProtocol.TCP) .setSrcPort(srcPort) .setDstPort(dstPort) .build(); ImmutableMap<String, Configuration> configs = ImmutableMap.of(c.getHostname(), c); String acceptingIfaceName = "acceptingIface"; TracerouteEngineImplContext ctxt = new TracerouteEngineImplContext( MockDataPlane.builder() .setForwardingAnalysis( MockForwardingAnalysis.builder() .setAcceptedIps( ImmutableMap.of( c.getHostname(), ImmutableMap.of( vrf.getName(), ImmutableMap.of(acceptingIfaceName, dstIp.toIpSpace())))) .build()) .build(), Topology.EMPTY, ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of(), false, configs); List<TraceAndReverseFlow> traces = new ArrayList<>(); FlowTracer flowTracer = new FlowTracer( ctxt, c, null, new Node(c.getHostname()), new LegacyTraceRecorder(traces::add), null, new ArrayList<>(), flow, vrf.getName(), new ArrayList<>(), new ArrayList<>(), new Stack<>(), flow, 0, 0); flowTracer.buildAcceptTrace(); TraceAndReverseFlow traceAndReverseFlow = Iterables.getOnlyElement(traces); assertThat(traceAndReverseFlow.getTrace(), hasDisposition(ACCEPTED)); assertThat(traceAndReverseFlow.getNewFirewallSessions(), empty()); }
@VisibleForTesting void buildAcceptTrace() { String acceptingInterface = _tracerouteContext .interfaceAcceptingIp(_currentNode.getName(), _vrfName, _currentFlow.getDstIp()) .orElseGet( () -> _currentConfig.getActiveInterfaces(_vrfName).keySet().iterator().next()); FirewallSessionVrfInfo firewallSessionVrfInfo = _currentConfig.getVrfs().get(_vrfName).getFirewallSessionVrfInfo(); if (_ingressInterface != null && firewallSessionVrfInfo != null) { SessionAction action = getSessionAction( firewallSessionVrfInfo.getFibLookup(), _ingressInterface, _lastHopNodeAndOutgoingInterface); @Nullable FirewallSessionTraceInfo session = buildFirewallSessionTraceInfo(action, new OriginatingSessionScope(_vrfName)); if (session != null) { _newSessions.add(session); _steps.add( new SetupSessionStep( SetupSessionStepDetail.builder() .setSessionScope(session.getSessionScope()) .setMatchCriteria(session.getMatchCriteria()) .setSessionAction(session.getAction()) .setTransformation(returnFlowDiffs(_originalFlow, _currentFlow)) .build())); } } InboundStep inboundStep = InboundStep.builder().setDetail(new InboundStepDetail(acceptingInterface)).build(); _steps.add(inboundStep); Flow returnFlow = returnFlow(_currentFlow, _currentNode.getName(), _vrfName, null); _hops.add( successHop( new Hop(_currentNode, _steps), _originalFlow, FlowDisposition.ACCEPTED, returnFlow, getHopSessionInfo(), getVisitedBreadcrumb())); _traceRecorder.recordTrace(_hops); }
FlowTracer { @VisibleForTesting void buildAcceptTrace() { String acceptingInterface = _tracerouteContext .interfaceAcceptingIp(_currentNode.getName(), _vrfName, _currentFlow.getDstIp()) .orElseGet( () -> _currentConfig.getActiveInterfaces(_vrfName).keySet().iterator().next()); FirewallSessionVrfInfo firewallSessionVrfInfo = _currentConfig.getVrfs().get(_vrfName).getFirewallSessionVrfInfo(); if (_ingressInterface != null && firewallSessionVrfInfo != null) { SessionAction action = getSessionAction( firewallSessionVrfInfo.getFibLookup(), _ingressInterface, _lastHopNodeAndOutgoingInterface); @Nullable FirewallSessionTraceInfo session = buildFirewallSessionTraceInfo(action, new OriginatingSessionScope(_vrfName)); if (session != null) { _newSessions.add(session); _steps.add( new SetupSessionStep( SetupSessionStepDetail.builder() .setSessionScope(session.getSessionScope()) .setMatchCriteria(session.getMatchCriteria()) .setSessionAction(session.getAction()) .setTransformation(returnFlowDiffs(_originalFlow, _currentFlow)) .build())); } } InboundStep inboundStep = InboundStep.builder().setDetail(new InboundStepDetail(acceptingInterface)).build(); _steps.add(inboundStep); Flow returnFlow = returnFlow(_currentFlow, _currentNode.getName(), _vrfName, null); _hops.add( successHop( new Hop(_currentNode, _steps), _originalFlow, FlowDisposition.ACCEPTED, returnFlow, getHopSessionInfo(), getVisitedBreadcrumb())); _traceRecorder.recordTrace(_hops); } }
FlowTracer { @VisibleForTesting void buildAcceptTrace() { String acceptingInterface = _tracerouteContext .interfaceAcceptingIp(_currentNode.getName(), _vrfName, _currentFlow.getDstIp()) .orElseGet( () -> _currentConfig.getActiveInterfaces(_vrfName).keySet().iterator().next()); FirewallSessionVrfInfo firewallSessionVrfInfo = _currentConfig.getVrfs().get(_vrfName).getFirewallSessionVrfInfo(); if (_ingressInterface != null && firewallSessionVrfInfo != null) { SessionAction action = getSessionAction( firewallSessionVrfInfo.getFibLookup(), _ingressInterface, _lastHopNodeAndOutgoingInterface); @Nullable FirewallSessionTraceInfo session = buildFirewallSessionTraceInfo(action, new OriginatingSessionScope(_vrfName)); if (session != null) { _newSessions.add(session); _steps.add( new SetupSessionStep( SetupSessionStepDetail.builder() .setSessionScope(session.getSessionScope()) .setMatchCriteria(session.getMatchCriteria()) .setSessionAction(session.getAction()) .setTransformation(returnFlowDiffs(_originalFlow, _currentFlow)) .build())); } } InboundStep inboundStep = InboundStep.builder().setDetail(new InboundStepDetail(acceptingInterface)).build(); _steps.add(inboundStep); Flow returnFlow = returnFlow(_currentFlow, _currentNode.getName(), _vrfName, null); _hops.add( successHop( new Hop(_currentNode, _steps), _originalFlow, FlowDisposition.ACCEPTED, returnFlow, getHopSessionInfo(), getVisitedBreadcrumb())); _traceRecorder.recordTrace(_hops); } @VisibleForTesting  FlowTracer(
      TracerouteEngineImplContext tracerouteContext,
      Configuration currentConfig,
      @Nullable String ingressInterface,
      Node currentNode,
      TraceRecorder traceRecorder,
      @Nullable NodeInterfacePair lastHopNodeAndOutgoingInterface,
      List<FirewallSessionTraceInfo> newSessions,
      Flow originalFlow,
      @Nonnull String vrfName,
      List<HopInfo> hops,
      List<Step<?>> steps,
      Stack<Breadcrumb> breadcrumbs,
      Flow currentFlow,
      int origNewSessionsSize,
      int origBreadcrumbsSize); }
FlowTracer { @VisibleForTesting void buildAcceptTrace() { String acceptingInterface = _tracerouteContext .interfaceAcceptingIp(_currentNode.getName(), _vrfName, _currentFlow.getDstIp()) .orElseGet( () -> _currentConfig.getActiveInterfaces(_vrfName).keySet().iterator().next()); FirewallSessionVrfInfo firewallSessionVrfInfo = _currentConfig.getVrfs().get(_vrfName).getFirewallSessionVrfInfo(); if (_ingressInterface != null && firewallSessionVrfInfo != null) { SessionAction action = getSessionAction( firewallSessionVrfInfo.getFibLookup(), _ingressInterface, _lastHopNodeAndOutgoingInterface); @Nullable FirewallSessionTraceInfo session = buildFirewallSessionTraceInfo(action, new OriginatingSessionScope(_vrfName)); if (session != null) { _newSessions.add(session); _steps.add( new SetupSessionStep( SetupSessionStepDetail.builder() .setSessionScope(session.getSessionScope()) .setMatchCriteria(session.getMatchCriteria()) .setSessionAction(session.getAction()) .setTransformation(returnFlowDiffs(_originalFlow, _currentFlow)) .build())); } } InboundStep inboundStep = InboundStep.builder().setDetail(new InboundStepDetail(acceptingInterface)).build(); _steps.add(inboundStep); Flow returnFlow = returnFlow(_currentFlow, _currentNode.getName(), _vrfName, null); _hops.add( successHop( new Hop(_currentNode, _steps), _originalFlow, FlowDisposition.ACCEPTED, returnFlow, getHopSessionInfo(), getVisitedBreadcrumb())); _traceRecorder.recordTrace(_hops); } @VisibleForTesting  FlowTracer(
      TracerouteEngineImplContext tracerouteContext,
      Configuration currentConfig,
      @Nullable String ingressInterface,
      Node currentNode,
      TraceRecorder traceRecorder,
      @Nullable NodeInterfacePair lastHopNodeAndOutgoingInterface,
      List<FirewallSessionTraceInfo> newSessions,
      Flow originalFlow,
      @Nonnull String vrfName,
      List<HopInfo> hops,
      List<Step<?>> steps,
      Stack<Breadcrumb> breadcrumbs,
      Flow currentFlow,
      int origNewSessionsSize,
      int origBreadcrumbsSize);  }
FlowTracer { @VisibleForTesting void buildAcceptTrace() { String acceptingInterface = _tracerouteContext .interfaceAcceptingIp(_currentNode.getName(), _vrfName, _currentFlow.getDstIp()) .orElseGet( () -> _currentConfig.getActiveInterfaces(_vrfName).keySet().iterator().next()); FirewallSessionVrfInfo firewallSessionVrfInfo = _currentConfig.getVrfs().get(_vrfName).getFirewallSessionVrfInfo(); if (_ingressInterface != null && firewallSessionVrfInfo != null) { SessionAction action = getSessionAction( firewallSessionVrfInfo.getFibLookup(), _ingressInterface, _lastHopNodeAndOutgoingInterface); @Nullable FirewallSessionTraceInfo session = buildFirewallSessionTraceInfo(action, new OriginatingSessionScope(_vrfName)); if (session != null) { _newSessions.add(session); _steps.add( new SetupSessionStep( SetupSessionStepDetail.builder() .setSessionScope(session.getSessionScope()) .setMatchCriteria(session.getMatchCriteria()) .setSessionAction(session.getAction()) .setTransformation(returnFlowDiffs(_originalFlow, _currentFlow)) .build())); } } InboundStep inboundStep = InboundStep.builder().setDetail(new InboundStepDetail(acceptingInterface)).build(); _steps.add(inboundStep); Flow returnFlow = returnFlow(_currentFlow, _currentNode.getName(), _vrfName, null); _hops.add( successHop( new Hop(_currentNode, _steps), _originalFlow, FlowDisposition.ACCEPTED, returnFlow, getHopSessionInfo(), getVisitedBreadcrumb())); _traceRecorder.recordTrace(_hops); } @VisibleForTesting  FlowTracer(
      TracerouteEngineImplContext tracerouteContext,
      Configuration currentConfig,
      @Nullable String ingressInterface,
      Node currentNode,
      TraceRecorder traceRecorder,
      @Nullable NodeInterfacePair lastHopNodeAndOutgoingInterface,
      List<FirewallSessionTraceInfo> newSessions,
      Flow originalFlow,
      @Nonnull String vrfName,
      List<HopInfo> hops,
      List<Step<?>> steps,
      Stack<Breadcrumb> breadcrumbs,
      Flow currentFlow,
      int origNewSessionsSize,
      int origBreadcrumbsSize);   }