@Test public void testMainRibColumnsValue() { SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> ribs = ImmutableSortedMap.of( "n1", ImmutableSortedMap.of( Configuration.DEFAULT_VRF_NAME, new MockRib<>( ImmutableSet.of( OspfExternalType2Route.builder() .setNetwork(Prefix.parse("1.1.1.0/24")) .setNextHopIp(Ip.parse("1.1.1.2")) .setAdmin(10) .setMetric(2L << 34) .setLsaMetric(2) .setCostToAdvertiser(2) .setArea(1L) .setAdvertiser("n2") .setOspfMetricType(OspfMetricType.E2) .setTag(2L << 35) .build())))); Multiset<Row> actual = getMainRibRoutes( ribs, ImmutableSet.of("n1"), null, RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER, ".*", null); assertThat( actual, contains( allOf( hasColumn(COL_NODE, new Node("n1"), Schema.NODE), hasColumn(COL_VRF_NAME, Configuration.DEFAULT_VRF_NAME, Schema.STRING), hasColumn(COL_NETWORK, Prefix.parse("1.1.1.0/24"), Schema.PREFIX), hasColumn(COL_NEXT_HOP_IP, Ip.parse("1.1.1.2"), Schema.IP), hasColumn(COL_NEXT_HOP_INTERFACE, "dynamic", Schema.STRING), hasColumn(COL_NEXT_HOP, nullValue(), Schema.STRING), hasColumn(COL_PROTOCOL, "ospfE2", Schema.STRING), hasColumn(COL_TAG, equalTo(2L << 35), Schema.LONG), hasColumn(COL_ADMIN_DISTANCE, equalTo(10), Schema.INTEGER), hasColumn(COL_METRIC, equalTo(2L << 34), Schema.LONG)))); }
static <T extends AbstractRouteDecorator> Multiset<Row> getMainRibRoutes( SortedMap<String, SortedMap<String, GenericRib<T>>> ribs, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex, @Nullable Map<Ip, Set<String>> ipOwners) { Multiset<Row> rows = HashMultiset.create(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(RibProtocol.MAIN).toColumnMap(); ribs.forEach( (node, vrfMap) -> { if (matchingNodes.contains(node)) { vrfMap.forEach( (vrfName, rib) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { rib.getRoutes().stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec.getProtocols().contains(route.getProtocol())) .forEach( route -> rows.add( abstractRouteToRow( node, vrfName, route, columnMetadataMap, ipOwners))); } }); } }); return rows; }
RoutesAnswererUtil { static <T extends AbstractRouteDecorator> Multiset<Row> getMainRibRoutes( SortedMap<String, SortedMap<String, GenericRib<T>>> ribs, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex, @Nullable Map<Ip, Set<String>> ipOwners) { Multiset<Row> rows = HashMultiset.create(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(RibProtocol.MAIN).toColumnMap(); ribs.forEach( (node, vrfMap) -> { if (matchingNodes.contains(node)) { vrfMap.forEach( (vrfName, rib) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { rib.getRoutes().stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec.getProtocols().contains(route.getProtocol())) .forEach( route -> rows.add( abstractRouteToRow( node, vrfName, route, columnMetadataMap, ipOwners))); } }); } }); return rows; } }
RoutesAnswererUtil { static <T extends AbstractRouteDecorator> Multiset<Row> getMainRibRoutes( SortedMap<String, SortedMap<String, GenericRib<T>>> ribs, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex, @Nullable Map<Ip, Set<String>> ipOwners) { Multiset<Row> rows = HashMultiset.create(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(RibProtocol.MAIN).toColumnMap(); ribs.forEach( (node, vrfMap) -> { if (matchingNodes.contains(node)) { vrfMap.forEach( (vrfName, rib) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { rib.getRoutes().stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec.getProtocols().contains(route.getProtocol())) .forEach( route -> rows.add( abstractRouteToRow( node, vrfName, route, columnMetadataMap, ipOwners))); } }); } }); return rows; }  }
RoutesAnswererUtil { static <T extends AbstractRouteDecorator> Multiset<Row> getMainRibRoutes( SortedMap<String, SortedMap<String, GenericRib<T>>> ribs, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex, @Nullable Map<Ip, Set<String>> ipOwners) { Multiset<Row> rows = HashMultiset.create(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(RibProtocol.MAIN).toColumnMap(); ribs.forEach( (node, vrfMap) -> { if (matchingNodes.contains(node)) { vrfMap.forEach( (vrfName, rib) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { rib.getRoutes().stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec.getProtocols().contains(route.getProtocol())) .forEach( route -> rows.add( abstractRouteToRow( node, vrfName, route, columnMetadataMap, ipOwners))); } }); } }); return rows; }  static Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> groupRoutes(
          SortedMap<String, SortedMap<String, GenericRib<T>>> ribs,
          Set<String> matchingNodes,
          @Nullable Prefix network,
          String vrfRegex,
          RoutingProtocolSpecifier protocolSpec,
          @Nullable Map<Ip, Set<String>> ipOwners); static List<DiffRoutesOutput> getRoutesDiff(
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase,
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef); }
RoutesAnswererUtil { static <T extends AbstractRouteDecorator> Multiset<Row> getMainRibRoutes( SortedMap<String, SortedMap<String, GenericRib<T>>> ribs, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex, @Nullable Map<Ip, Set<String>> ipOwners) { Multiset<Row> rows = HashMultiset.create(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(RibProtocol.MAIN).toColumnMap(); ribs.forEach( (node, vrfMap) -> { if (matchingNodes.contains(node)) { vrfMap.forEach( (vrfName, rib) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { rib.getRoutes().stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec.getProtocols().contains(route.getProtocol())) .forEach( route -> rows.add( abstractRouteToRow( node, vrfName, route, columnMetadataMap, ipOwners))); } }); } }); return rows; }  static Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> groupRoutes(
          SortedMap<String, SortedMap<String, GenericRib<T>>> ribs,
          Set<String> matchingNodes,
          @Nullable Prefix network,
          String vrfRegex,
          RoutingProtocolSpecifier protocolSpec,
          @Nullable Map<Ip, Set<String>> ipOwners); static List<DiffRoutesOutput> getRoutesDiff(
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase,
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef);  }