@Test public void returnFlow() { Ip ip1 = Ip.parse("1.1.1.1"); int port1 = 1111; Ip ip2 = Ip.parse("2.2.2.2"); int port2 = 2222; String node1 = "node1"; String vrf1 = "vrf1"; String iface1 = "iface1"; Flow forwardFlow = Flow.builder() .setSrcIp(ip1) .setSrcPort(port1) .setDstIp(ip2) .setDstPort(port2) .setIngressNode(node1) .setIngressVrf(vrf1) .setIngressInterface(iface1) .build(); String node2 = "node2"; String vrf2 = "vrf2"; String iface2 = "iface2"; assertThat( TracerouteUtils.returnFlow(forwardFlow, node2, vrf2, null), equalTo( Flow.builder() .setSrcIp(ip2) .setSrcPort(port2) .setDstIp(ip1) .setDstPort(port1) .setIngressNode(node2) .setIngressVrf(vrf2) .build())); assertThat( TracerouteUtils.returnFlow(forwardFlow, node2, null, iface2), equalTo( Flow.builder() .setSrcIp(ip2) .setSrcPort(port2) .setDstIp(ip1) .setDstPort(port1) .setIngressNode(node2) .setIngressInterface(iface2) .build())); }
static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .setTcpFlags(getTcpFlagsForReverse(forwardFlow.getTcpFlags())) .build(); }
TracerouteUtils { static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .setTcpFlags(getTcpFlagsForReverse(forwardFlow.getTcpFlags())) .build(); } }
TracerouteUtils { static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .setTcpFlags(getTcpFlagsForReverse(forwardFlow.getTcpFlags())) .build(); }  }
TracerouteUtils { static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .setTcpFlags(getTcpFlagsForReverse(forwardFlow.getTcpFlags())) .build(); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow); }
TracerouteUtils { static Flow returnFlow( Flow forwardFlow, String returnIngressNode, @Nullable String returnIngressVrf, @Nullable String returnIngressIface) { checkArgument( returnIngressVrf == null ^ returnIngressIface == null, "Either returnIngressVrf or returnIngressIface required, but not both"); return forwardFlow .toBuilder() .setDstIp(forwardFlow.getSrcIp()) .setDstPort(forwardFlow.getSrcPort()) .setSrcIp(forwardFlow.getDstIp()) .setSrcPort(forwardFlow.getDstPort()) .setIngressNode(returnIngressNode) .setIngressVrf(returnIngressVrf) .setIngressInterface(returnIngressIface) .setTcpFlags(getTcpFlagsForReverse(forwardFlow.getTcpFlags())) .build(); }  static TransformationStep transformationStep(
      TransformationType type, Flow inputFlow, Flow transformedFlow);  }