@Test public void testFlowDiffs() { 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 orig = Flow.builder().setIngressNode("ingressNode").setDstIp(dst1).setSrcIp(src1).build(); Flow newDst = orig.toBuilder().setDstIp(dst2).build(); Flow newSrc = orig.toBuilder().setSrcIp(src2).build(); Flow newDstAndSrc = newDst.toBuilder().setSrcIp(src2).build(); assertThat(flowDiffs(null, orig), empty()); assertThat(flowDiffs(orig, null), empty()); assertThat(flowDiffs(orig, orig), empty()); FlowDiff dstDiff = new FlowDiff(PROP_DST_IP, dst1.toString(), dst2.toString()); FlowDiff srcDiff = new FlowDiff(PROP_SRC_IP, src1.toString(), src2.toString()); assertThat(flowDiffs(orig, newDst), contains(dstDiff)); assertThat(flowDiffs(orig, newSrc), contains(srcDiff)); assertThat(flowDiffs(orig, newDstAndSrc), containsInAnyOrder(dstDiff, srcDiff)); }
public static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2) { if (flow1 == null || flow2 == null || flow1.equals(flow2)) { return ImmutableSortedSet.of(); } checkArgument( flow1 .toBuilder() .setDstIp(flow2.getDstIp()) .setSrcIp(flow2.getSrcIp()) .setDstPort(flow2.getDstPort()) .setSrcPort(flow2.getSrcPort()) .build() .equals(flow2), "flowDiff only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( flow1.getSrcIp(), flow1.getDstIp(), flow1.getSrcPort(), flow1.getDstPort(), flow2.getSrcIp(), flow2.getDstIp(), flow2.getSrcPort(), flow2.getDstPort()); }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2) { if (flow1 == null || flow2 == null || flow1.equals(flow2)) { return ImmutableSortedSet.of(); } checkArgument( flow1 .toBuilder() .setDstIp(flow2.getDstIp()) .setSrcIp(flow2.getSrcIp()) .setDstPort(flow2.getDstPort()) .setSrcPort(flow2.getSrcPort()) .build() .equals(flow2), "flowDiff only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( flow1.getSrcIp(), flow1.getDstIp(), flow1.getSrcPort(), flow1.getDstPort(), flow2.getSrcIp(), flow2.getDstIp(), flow2.getSrcPort(), flow2.getDstPort()); } }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2) { if (flow1 == null || flow2 == null || flow1.equals(flow2)) { return ImmutableSortedSet.of(); } checkArgument( flow1 .toBuilder() .setDstIp(flow2.getDstIp()) .setSrcIp(flow2.getSrcIp()) .setDstPort(flow2.getDstPort()) .setSrcPort(flow2.getSrcPort()) .build() .equals(flow2), "flowDiff only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( flow1.getSrcIp(), flow1.getDstIp(), flow1.getSrcPort(), flow1.getDstPort(), flow2.getSrcIp(), flow2.getDstIp(), flow2.getSrcPort(), flow2.getDstPort()); } @VisibleForTesting  FlowDiff(String fieldName, String oldValue, String newValue); }
FlowDiff implements Comparable<FlowDiff> { public static SortedSet<FlowDiff> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2) { if (flow1 == null || flow2 == null || flow1.equals(flow2)) { return ImmutableSortedSet.of(); } checkArgument( flow1 .toBuilder() .setDstIp(flow2.getDstIp()) .setSrcIp(flow2.getSrcIp()) .setDstPort(flow2.getDstPort()) .setSrcPort(flow2.getSrcPort()) .build() .equals(flow2), "flowDiff only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( flow1.getSrcIp(), flow1.getDstIp(), flow1.getSrcPort(), flow1.getDstPort(), flow2.getSrcIp(), flow2.getDstIp(), flow2.getSrcPort(), flow2.getDstPort()); } @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> flowDiffs(@Nullable Flow flow1, @Nullable Flow flow2) { if (flow1 == null || flow2 == null || flow1.equals(flow2)) { return ImmutableSortedSet.of(); } checkArgument( flow1 .toBuilder() .setDstIp(flow2.getDstIp()) .setSrcIp(flow2.getSrcIp()) .setDstPort(flow2.getDstPort()) .setSrcPort(flow2.getSrcPort()) .build() .equals(flow2), "flowDiff only supports differences of src/dst Ip and src/dst Port"); return getFlowDiffs( flow1.getSrcIp(), flow1.getDstIp(), flow1.getSrcPort(), flow1.getDstPort(), flow2.getSrcIp(), flow2.getDstIp(), flow2.getSrcPort(), flow2.getDstPort()); } @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);  }