@Test public void testDiffFlowTracesToRows() { Flow flow = Flow.builder().setIngressNode("node").setDstIp(Ip.parse("1.1.1.1")).build(); Map<Flow, List<Trace>> baseFlowTraces = ImmutableMap.of( flow, ImmutableList.of(new Trace(FlowDisposition.DENIED_OUT, ImmutableList.of()))); Map<Flow, List<Trace>> deltaFlowTraces = ImmutableMap.of( flow, ImmutableList.of(new Trace(FlowDisposition.DENIED_IN, ImmutableList.of()))); Multiset<Row> rows = diffFlowTracesToRows(baseFlowTraces, deltaFlowTraces, Integer.MAX_VALUE); assertThat( rows.iterator().next(), allOf( hasColumn( COL_FLOW, allOf(hasDstIp(Ip.parse("1.1.1.1")), hasIngressNode("node")), Schema.FLOW), hasColumn( TracerouteAnswerer.COL_BASE_TRACES, containsInAnyOrder( ImmutableList.of(TraceMatchers.hasDisposition(FlowDisposition.DENIED_OUT))), Schema.set(Schema.TRACE)), hasColumn(TracerouteAnswerer.COL_BASE_TRACE_COUNT, equalTo(1), Schema.INTEGER), hasColumn( TracerouteAnswerer.COL_DELTA_TRACES, containsInAnyOrder( ImmutableList.of(TraceMatchers.hasDisposition(FlowDisposition.DENIED_IN))), Schema.set(Schema.TRACE)), hasColumn(TracerouteAnswerer.COL_DELTA_TRACE_COUNT, equalTo(1), Schema.INTEGER))); }
public static Multiset<Row> diffFlowTracesToRows( Map<Flow, List<Trace>> baseFlowTraces, Map<Flow, List<Trace>> deltaFlowTraces, int maxTraces) { Multiset<Row> rows = LinkedHashMultiset.create(); checkArgument( baseFlowTraces.keySet().equals(deltaFlowTraces.keySet()), "Base and delta flow traces should have same flows"); for (Flow flow : baseFlowTraces.keySet()) { rows.add( Row.of( COL_FLOW, flow, TableDiff.baseColumnName(COL_TRACES), TracePruner.prune(baseFlowTraces.get(flow), maxTraces), TableDiff.baseColumnName(COL_TRACE_COUNT), baseFlowTraces.get(flow).size(), TableDiff.deltaColumnName(COL_TRACES), TracePruner.prune(deltaFlowTraces.get(flow), maxTraces), TableDiff.deltaColumnName(COL_TRACE_COUNT), deltaFlowTraces.get(flow).size())); } return rows; }
TracerouteAnswerer extends Answerer { public static Multiset<Row> diffFlowTracesToRows( Map<Flow, List<Trace>> baseFlowTraces, Map<Flow, List<Trace>> deltaFlowTraces, int maxTraces) { Multiset<Row> rows = LinkedHashMultiset.create(); checkArgument( baseFlowTraces.keySet().equals(deltaFlowTraces.keySet()), "Base and delta flow traces should have same flows"); for (Flow flow : baseFlowTraces.keySet()) { rows.add( Row.of( COL_FLOW, flow, TableDiff.baseColumnName(COL_TRACES), TracePruner.prune(baseFlowTraces.get(flow), maxTraces), TableDiff.baseColumnName(COL_TRACE_COUNT), baseFlowTraces.get(flow).size(), TableDiff.deltaColumnName(COL_TRACES), TracePruner.prune(deltaFlowTraces.get(flow), maxTraces), TableDiff.deltaColumnName(COL_TRACE_COUNT), deltaFlowTraces.get(flow).size())); } return rows; } }
TracerouteAnswerer extends Answerer { public static Multiset<Row> diffFlowTracesToRows( Map<Flow, List<Trace>> baseFlowTraces, Map<Flow, List<Trace>> deltaFlowTraces, int maxTraces) { Multiset<Row> rows = LinkedHashMultiset.create(); checkArgument( baseFlowTraces.keySet().equals(deltaFlowTraces.keySet()), "Base and delta flow traces should have same flows"); for (Flow flow : baseFlowTraces.keySet()) { rows.add( Row.of( COL_FLOW, flow, TableDiff.baseColumnName(COL_TRACES), TracePruner.prune(baseFlowTraces.get(flow), maxTraces), TableDiff.baseColumnName(COL_TRACE_COUNT), baseFlowTraces.get(flow).size(), TableDiff.deltaColumnName(COL_TRACES), TracePruner.prune(deltaFlowTraces.get(flow), maxTraces), TableDiff.deltaColumnName(COL_TRACE_COUNT), deltaFlowTraces.get(flow).size())); } return rows; } TracerouteAnswerer(Question question, IBatfish batfish); }
TracerouteAnswerer extends Answerer { public static Multiset<Row> diffFlowTracesToRows( Map<Flow, List<Trace>> baseFlowTraces, Map<Flow, List<Trace>> deltaFlowTraces, int maxTraces) { Multiset<Row> rows = LinkedHashMultiset.create(); checkArgument( baseFlowTraces.keySet().equals(deltaFlowTraces.keySet()), "Base and delta flow traces should have same flows"); for (Flow flow : baseFlowTraces.keySet()) { rows.add( Row.of( COL_FLOW, flow, TableDiff.baseColumnName(COL_TRACES), TracePruner.prune(baseFlowTraces.get(flow), maxTraces), TableDiff.baseColumnName(COL_TRACE_COUNT), baseFlowTraces.get(flow).size(), TableDiff.deltaColumnName(COL_TRACES), TracePruner.prune(deltaFlowTraces.get(flow), maxTraces), TableDiff.deltaColumnName(COL_TRACE_COUNT), deltaFlowTraces.get(flow).size())); } return rows; } TracerouteAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); @Override AnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference); static TableMetadata metadata(boolean differential); static Multiset<Row> flowTracesToRows(
      SortedMap<Flow, List<Trace>> flowTraces, int maxTraces); static Multiset<Row> diffFlowTracesToRows(
      Map<Flow, List<Trace>> baseFlowTraces,
      Map<Flow, List<Trace>> deltaFlowTraces,
      int maxTraces); }
TracerouteAnswerer extends Answerer { public static Multiset<Row> diffFlowTracesToRows( Map<Flow, List<Trace>> baseFlowTraces, Map<Flow, List<Trace>> deltaFlowTraces, int maxTraces) { Multiset<Row> rows = LinkedHashMultiset.create(); checkArgument( baseFlowTraces.keySet().equals(deltaFlowTraces.keySet()), "Base and delta flow traces should have same flows"); for (Flow flow : baseFlowTraces.keySet()) { rows.add( Row.of( COL_FLOW, flow, TableDiff.baseColumnName(COL_TRACES), TracePruner.prune(baseFlowTraces.get(flow), maxTraces), TableDiff.baseColumnName(COL_TRACE_COUNT), baseFlowTraces.get(flow).size(), TableDiff.deltaColumnName(COL_TRACES), TracePruner.prune(deltaFlowTraces.get(flow), maxTraces), TableDiff.deltaColumnName(COL_TRACE_COUNT), deltaFlowTraces.get(flow).size())); } return rows; } TracerouteAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); @Override AnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference); static TableMetadata metadata(boolean differential); static Multiset<Row> flowTracesToRows(
      SortedMap<Flow, List<Trace>> flowTraces, int maxTraces); static Multiset<Row> diffFlowTracesToRows(
      Map<Flow, List<Trace>> baseFlowTraces,
      Map<Flow, List<Trace>> deltaFlowTraces,
      int maxTraces); static final String COL_FLOW; static final String COL_TRACES; static final String COL_TRACE_COUNT; static final String COL_BASE_TRACES; static final String COL_DELTA_TRACES; static final String COL_BASE_TRACE_COUNT; static final String COL_DELTA_TRACE_COUNT; }