@Test public void testToRow() { final ImmutableMap<String, ColumnMetadata> columnMap = getColumnMetadata().stream() .collect(ImmutableMap.toImmutableMap(ColumnMetadata::getName, Function.identity())); Row row = toRow( ImmutableSet.of( new ConnectedRoute(Prefix.parse("1.1.1.0/24"), "Eth0"), new ConnectedRoute(Prefix.parse("1.1.1.0/24"), "Eth1")), "node1", "vrf", Ip.parse("1.1.1.1"), columnMap) .get(); assertThat( row, equalTo( Row.builder(columnMap) .put(COL_NODE, new Node("node1")) .put(COL_VRF, "vrf") .put(COL_IP, Ip.parse("1.1.1.1")) .put(COL_NETWORK, Prefix.parse("1.1.1.0/24")) .put(COL_NUM_ROUTES, 2) .build())); }
@VisibleForTesting static <T extends AbstractRouteDecorator> Optional<Row> toRow( Set<T> routes, String node, String vrf, Ip ip, Map<String, ColumnMetadata> columnMap) { if (routes.isEmpty()) { return Optional.empty(); } Prefix network = routes.iterator().next().getNetwork(); return Optional.of( Row.builder(columnMap) .put(COL_NODE, new Node(node)) .put(COL_VRF, vrf) .put(COL_IP, ip) .put(COL_NETWORK, network) .put(COL_NUM_ROUTES, routes.size()) .build()); }
LpmRoutesAnswerer extends Answerer { @VisibleForTesting static <T extends AbstractRouteDecorator> Optional<Row> toRow( Set<T> routes, String node, String vrf, Ip ip, Map<String, ColumnMetadata> columnMap) { if (routes.isEmpty()) { return Optional.empty(); } Prefix network = routes.iterator().next().getNetwork(); return Optional.of( Row.builder(columnMap) .put(COL_NODE, new Node(node)) .put(COL_VRF, vrf) .put(COL_IP, ip) .put(COL_NETWORK, network) .put(COL_NUM_ROUTES, routes.size()) .build()); } }
LpmRoutesAnswerer extends Answerer { @VisibleForTesting static <T extends AbstractRouteDecorator> Optional<Row> toRow( Set<T> routes, String node, String vrf, Ip ip, Map<String, ColumnMetadata> columnMap) { if (routes.isEmpty()) { return Optional.empty(); } Prefix network = routes.iterator().next().getNetwork(); return Optional.of( Row.builder(columnMap) .put(COL_NODE, new Node(node)) .put(COL_VRF, vrf) .put(COL_IP, ip) .put(COL_NETWORK, network) .put(COL_NUM_ROUTES, routes.size()) .build()); } LpmRoutesAnswerer(Question question, IBatfish batfish); }
LpmRoutesAnswerer extends Answerer { @VisibleForTesting static <T extends AbstractRouteDecorator> Optional<Row> toRow( Set<T> routes, String node, String vrf, Ip ip, Map<String, ColumnMetadata> columnMap) { if (routes.isEmpty()) { return Optional.empty(); } Prefix network = routes.iterator().next().getNetwork(); return Optional.of( Row.builder(columnMap) .put(COL_NODE, new Node(node)) .put(COL_VRF, vrf) .put(COL_IP, ip) .put(COL_NETWORK, network) .put(COL_NUM_ROUTES, routes.size()) .build()); } LpmRoutesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); }
LpmRoutesAnswerer extends Answerer { @VisibleForTesting static <T extends AbstractRouteDecorator> Optional<Row> toRow( Set<T> routes, String node, String vrf, Ip ip, Map<String, ColumnMetadata> columnMap) { if (routes.isEmpty()) { return Optional.empty(); } Prefix network = routes.iterator().next().getNetwork(); return Optional.of( Row.builder(columnMap) .put(COL_NODE, new Node(node)) .put(COL_VRF, vrf) .put(COL_IP, ip) .put(COL_NETWORK, network) .put(COL_NUM_ROUTES, routes.size()) .build()); } LpmRoutesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot);  }