@Test public void testSessionTransformation() { Ip srcIp1 = Ip.parse("1.1.1.1"); Ip dstIp1 = Ip.parse("2.2.2.2"); int srcPort1 = 10001; int dstPort1 = 10002; Ip srcIp2 = Ip.parse("3.3.3.3"); Ip dstIp2 = Ip.parse("4.4.4.4"); int srcPort2 = 10003; int dstPort2 = 10004; Flow inputFlow = Flow.builder() .setIngressNode("inNode") .setIngressInterface("inInterf") .setDstIp(dstIp1) .setSrcIp(srcIp1) .setDstPort(dstPort1) .setSrcPort(srcPort1) .setIpProtocol(IpProtocol.TCP) .build(); Flow currentFlow = Flow.builder() .setIngressNode("inNode") .setIngressInterface("inInterf") .setDstIp(dstIp2) .setSrcIp(srcIp2) .setDstPort(dstPort2) .setSrcPort(srcPort2) .setIpProtocol(IpProtocol.TCP) .build(); Transformation transformation = TracerouteUtils.sessionTransformation(inputFlow, currentFlow); assertThat( transformation, equalTo( new Transformation( AclLineMatchExprs.TRUE, ImmutableList.of( assignSourceIp(dstIp1, dstIp1), assignSourcePort(dstPort1, dstPort1), assignDestinationIp(srcIp1, srcIp1), assignDestinationPort(srcPort1, srcPort1)), null, null))); }
@Nullable static Transformation sessionTransformation(Flow inputFlow, Flow currentFlow) { ImmutableList.Builder<org.batfish.datamodel.transformation.TransformationStep> transformationStepsBuilder = ImmutableList.builder(); Ip origDstIp = inputFlow.getDstIp(); if (!origDstIp.equals(currentFlow.getDstIp())) { transformationStepsBuilder.add(assignSourceIp(origDstIp, origDstIp)); } @Nullable Integer origDstPort = inputFlow.getDstPort(); if (origDstPort != null && !origDstPort.equals(currentFlow.getDstPort())) { transformationStepsBuilder.add(assignSourcePort(origDstPort, origDstPort)); } Ip origSrcIp = inputFlow.getSrcIp(); if (!origSrcIp.equals(currentFlow.getSrcIp())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp( origSrcIp, origSrcIp)); } @Nullable Integer origSrcPort = inputFlow.getSrcPort(); if (origSrcPort != null && !origSrcPort.equals(currentFlow.getSrcPort())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationPort( origSrcPort, origSrcPort)); } List<org.batfish.datamodel.transformation.TransformationStep> transformationSteps = transformationStepsBuilder.build(); return transformationSteps.isEmpty() ? null : always().apply(transformationSteps).build(); }
TracerouteUtils { @Nullable static Transformation sessionTransformation(Flow inputFlow, Flow currentFlow) { ImmutableList.Builder<org.batfish.datamodel.transformation.TransformationStep> transformationStepsBuilder = ImmutableList.builder(); Ip origDstIp = inputFlow.getDstIp(); if (!origDstIp.equals(currentFlow.getDstIp())) { transformationStepsBuilder.add(assignSourceIp(origDstIp, origDstIp)); } @Nullable Integer origDstPort = inputFlow.getDstPort(); if (origDstPort != null && !origDstPort.equals(currentFlow.getDstPort())) { transformationStepsBuilder.add(assignSourcePort(origDstPort, origDstPort)); } Ip origSrcIp = inputFlow.getSrcIp(); if (!origSrcIp.equals(currentFlow.getSrcIp())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp( origSrcIp, origSrcIp)); } @Nullable Integer origSrcPort = inputFlow.getSrcPort(); if (origSrcPort != null && !origSrcPort.equals(currentFlow.getSrcPort())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationPort( origSrcPort, origSrcPort)); } List<org.batfish.datamodel.transformation.TransformationStep> transformationSteps = transformationStepsBuilder.build(); return transformationSteps.isEmpty() ? null : always().apply(transformationSteps).build(); } }
TracerouteUtils { @Nullable static Transformation sessionTransformation(Flow inputFlow, Flow currentFlow) { ImmutableList.Builder<org.batfish.datamodel.transformation.TransformationStep> transformationStepsBuilder = ImmutableList.builder(); Ip origDstIp = inputFlow.getDstIp(); if (!origDstIp.equals(currentFlow.getDstIp())) { transformationStepsBuilder.add(assignSourceIp(origDstIp, origDstIp)); } @Nullable Integer origDstPort = inputFlow.getDstPort(); if (origDstPort != null && !origDstPort.equals(currentFlow.getDstPort())) { transformationStepsBuilder.add(assignSourcePort(origDstPort, origDstPort)); } Ip origSrcIp = inputFlow.getSrcIp(); if (!origSrcIp.equals(currentFlow.getSrcIp())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp( origSrcIp, origSrcIp)); } @Nullable Integer origSrcPort = inputFlow.getSrcPort(); if (origSrcPort != null && !origSrcPort.equals(currentFlow.getSrcPort())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationPort( origSrcPort, origSrcPort)); } List<org.batfish.datamodel.transformation.TransformationStep> transformationSteps = transformationStepsBuilder.build(); return transformationSteps.isEmpty() ? null : always().apply(transformationSteps).build(); }  }
TracerouteUtils { @Nullable static Transformation sessionTransformation(Flow inputFlow, Flow currentFlow) { ImmutableList.Builder<org.batfish.datamodel.transformation.TransformationStep> transformationStepsBuilder = ImmutableList.builder(); Ip origDstIp = inputFlow.getDstIp(); if (!origDstIp.equals(currentFlow.getDstIp())) { transformationStepsBuilder.add(assignSourceIp(origDstIp, origDstIp)); } @Nullable Integer origDstPort = inputFlow.getDstPort(); if (origDstPort != null && !origDstPort.equals(currentFlow.getDstPort())) { transformationStepsBuilder.add(assignSourcePort(origDstPort, origDstPort)); } Ip origSrcIp = inputFlow.getSrcIp(); if (!origSrcIp.equals(currentFlow.getSrcIp())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp( origSrcIp, origSrcIp)); } @Nullable Integer origSrcPort = inputFlow.getSrcPort(); if (origSrcPort != null && !origSrcPort.equals(currentFlow.getSrcPort())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationPort( origSrcPort, origSrcPort)); } List<org.batfish.datamodel.transformation.TransformationStep> transformationSteps = transformationStepsBuilder.build(); return transformationSteps.isEmpty() ? null : always().apply(transformationSteps).build(); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow); }
TracerouteUtils { @Nullable static Transformation sessionTransformation(Flow inputFlow, Flow currentFlow) { ImmutableList.Builder<org.batfish.datamodel.transformation.TransformationStep> transformationStepsBuilder = ImmutableList.builder(); Ip origDstIp = inputFlow.getDstIp(); if (!origDstIp.equals(currentFlow.getDstIp())) { transformationStepsBuilder.add(assignSourceIp(origDstIp, origDstIp)); } @Nullable Integer origDstPort = inputFlow.getDstPort(); if (origDstPort != null && !origDstPort.equals(currentFlow.getDstPort())) { transformationStepsBuilder.add(assignSourcePort(origDstPort, origDstPort)); } Ip origSrcIp = inputFlow.getSrcIp(); if (!origSrcIp.equals(currentFlow.getSrcIp())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationIp( origSrcIp, origSrcIp)); } @Nullable Integer origSrcPort = inputFlow.getSrcPort(); if (origSrcPort != null && !origSrcPort.equals(currentFlow.getSrcPort())) { transformationStepsBuilder.add( org.batfish.datamodel.transformation.TransformationStep.assignDestinationPort( origSrcPort, origSrcPort)); } List<org.batfish.datamodel.transformation.TransformationStep> transformationSteps = transformationStepsBuilder.build(); return transformationSteps.isEmpty() ? null : always().apply(transformationSteps).build(); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow);  }