@Test public void testReturnFlowDiffs() { Ip dst1 = Ip.parse("1.1.1.1"); Ip src1 = Ip.parse("2.2.2.2"); Ip dst2 = Ip.parse("3.3.3.3"); Ip src2 = Ip.parse("4.4.4.4"); Flow origForward = Flow.builder().setIngressNode("ingressNode").setDstIp(dst1).setSrcIp(src1).build(); Flow newForwardDst = origForward.toBuilder().setDstIp(dst2).build(); Flow newForwardSrc = origForward.toBuilder().setSrcIp(src2).build(); Flow newForwardDstAndSrc = newForwardDst.toBuilder().setSrcIp(src2).build(); assertThat(returnFlowDiffs(null, origForward), empty()); assertThat(returnFlowDiffs(origForward, null), empty()); assertThat(returnFlowDiffs(origForward, origForward), empty()); FlowDiff returnDstDiff = new FlowDiff(PROP_DST_IP, src2.toString(), src1.toString()); FlowDiff returnSrcDiff = new FlowDiff(PROP_SRC_IP, dst2.toString(), dst1.toString()); assertThat(returnFlowDiffs(origForward, newForwardDst), contains(returnSrcDiff)); assertThat(returnFlowDiffs(origForward, newForwardSrc), contains(returnDstDiff)); assertThat( returnFlowDiffs(origForward, newForwardDstAndSrc), containsInAnyOrder(returnSrcDiff, returnDstDiff)); }
public static SortedSet<FlowDiff> returnFlowDiffs( @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow) { if (origForwardFlow == null || transformedForwardFlow == null || origForwardFlow.equals(transformedForwardFlow)) { return ImmutableSortedSet.of(); } checkArgument( origForwardFlow .toBuilder() .setDstIp(transformedForwardFlow.getDstIp()) .setSrcIp(transformedForwardFlow.getSrcIp()) .setDstPort(transformedForwardFlow.getDstPort()) .setSrcPort(transformedForwardFlow.getSrcPort()) .build() .equals(transformedForwardFlow), "returnFlowDiffs only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( transformedForwardFlow.getDstIp(), transformedForwardFlow.getSrcIp(), transformedForwardFlow.getDstPort(), transformedForwardFlow.getSrcPort(), origForwardFlow.getDstIp(), origForwardFlow.getSrcIp(), origForwardFlow.getDstPort(), origForwardFlow.getSrcPort()); }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> returnFlowDiffs( @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow) { if (origForwardFlow == null || transformedForwardFlow == null || origForwardFlow.equals(transformedForwardFlow)) { return ImmutableSortedSet.of(); } checkArgument( origForwardFlow .toBuilder() .setDstIp(transformedForwardFlow.getDstIp()) .setSrcIp(transformedForwardFlow.getSrcIp()) .setDstPort(transformedForwardFlow.getDstPort()) .setSrcPort(transformedForwardFlow.getSrcPort()) .build() .equals(transformedForwardFlow), "returnFlowDiffs only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( transformedForwardFlow.getDstIp(), transformedForwardFlow.getSrcIp(), transformedForwardFlow.getDstPort(), transformedForwardFlow.getSrcPort(), origForwardFlow.getDstIp(), origForwardFlow.getSrcIp(), origForwardFlow.getDstPort(), origForwardFlow.getSrcPort()); } }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> returnFlowDiffs( @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow) { if (origForwardFlow == null || transformedForwardFlow == null || origForwardFlow.equals(transformedForwardFlow)) { return ImmutableSortedSet.of(); } checkArgument( origForwardFlow .toBuilder() .setDstIp(transformedForwardFlow.getDstIp()) .setSrcIp(transformedForwardFlow.getSrcIp()) .setDstPort(transformedForwardFlow.getDstPort()) .setSrcPort(transformedForwardFlow.getSrcPort()) .build() .equals(transformedForwardFlow), "returnFlowDiffs only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( transformedForwardFlow.getDstIp(), transformedForwardFlow.getSrcIp(), transformedForwardFlow.getDstPort(), transformedForwardFlow.getSrcPort(), origForwardFlow.getDstIp(), origForwardFlow.getSrcIp(), origForwardFlow.getDstPort(), origForwardFlow.getSrcPort()); } @VisibleForTesting  FlowDiff(String fieldName, String oldValue, String newValue); }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> returnFlowDiffs( @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow) { if (origForwardFlow == null || transformedForwardFlow == null || origForwardFlow.equals(transformedForwardFlow)) { return ImmutableSortedSet.of(); } checkArgument( origForwardFlow .toBuilder() .setDstIp(transformedForwardFlow.getDstIp()) .setSrcIp(transformedForwardFlow.getSrcIp()) .setDstPort(transformedForwardFlow.getDstPort()) .setSrcPort(transformedForwardFlow.getSrcPort()) .build() .equals(transformedForwardFlow), "returnFlowDiffs only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( transformedForwardFlow.getDstIp(), transformedForwardFlow.getSrcIp(), transformedForwardFlow.getDstPort(), transformedForwardFlow.getSrcPort(), origForwardFlow.getDstIp(), origForwardFlow.getSrcIp(), origForwardFlow.getDstPort(), origForwardFlow.getSrcPort()); } @VisibleForTesting  FlowDiff(String fieldName, String oldValue, String newValue); @Override boolean equals(Object o); static FlowDiff flowDiff(IpField ipField, Ip oldValue, Ip newValue); static FlowDiff flowDiff(PortField portField, int oldValue, int newValue); @JsonProperty(PROP_FIELD_NAME) String getFieldName(); @JsonProperty(PROP_OLD_VALUE) String getOldValue(); @Override int hashCode(); @JsonProperty(PROP_NEW_VALUE) String getNewValue(); static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2); static SortedSet<FlowDiff> returnFlowDiffs(
      @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow); @JsonIgnore @Nullable PortField getPortField(); @JsonIgnore @Nullable IpField getIpField(); @Override int compareTo(FlowDiff o); }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> returnFlowDiffs( @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow) { if (origForwardFlow == null || transformedForwardFlow == null || origForwardFlow.equals(transformedForwardFlow)) { return ImmutableSortedSet.of(); } checkArgument( origForwardFlow .toBuilder() .setDstIp(transformedForwardFlow.getDstIp()) .setSrcIp(transformedForwardFlow.getSrcIp()) .setDstPort(transformedForwardFlow.getDstPort()) .setSrcPort(transformedForwardFlow.getSrcPort()) .build() .equals(transformedForwardFlow), "returnFlowDiffs only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( transformedForwardFlow.getDstIp(), transformedForwardFlow.getSrcIp(), transformedForwardFlow.getDstPort(), transformedForwardFlow.getSrcPort(), origForwardFlow.getDstIp(), origForwardFlow.getSrcIp(), origForwardFlow.getDstPort(), origForwardFlow.getSrcPort()); } @VisibleForTesting  FlowDiff(String fieldName, String oldValue, String newValue); @Override boolean equals(Object o); static FlowDiff flowDiff(IpField ipField, Ip oldValue, Ip newValue); static FlowDiff flowDiff(PortField portField, int oldValue, int newValue); @JsonProperty(PROP_FIELD_NAME) String getFieldName(); @JsonProperty(PROP_OLD_VALUE) String getOldValue(); @Override int hashCode(); @JsonProperty(PROP_NEW_VALUE) String getNewValue(); static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2); static SortedSet<FlowDiff> returnFlowDiffs(
      @Nullable Flow origForwardFlow, @Nullable Flow transformedForwardFlow); @JsonIgnore @Nullable PortField getPortField(); @JsonIgnore @Nullable IpField getIpField(); @Override int compareTo(FlowDiff o);  }