@Test public void testGetBgpRoutesCommunities() { Ip ip = Ip.parse("1.1.1.1"); Table<String, String, Set<Bgpv4Route>> bgpRouteTable = HashBasedTable.create(); bgpRouteTable.put( "node", "vrf", ImmutableSet.of( new Builder() .setNetwork(ip.toPrefix()) .setOriginType(OriginType.IGP) .setOriginatorIp(ip) .setReceivedFromIp(ip) .setCommunities(ImmutableSortedSet.of(StandardCommunity.of(65537L))) .setProtocol(RoutingProtocol.BGP) .build())); Multiset<Row> rows = getBgpRibRoutes( bgpRouteTable, RibProtocol.BGP, ImmutableSet.of("node"), null, RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER, ".*"); assertThat( rows.iterator().next().get(COL_COMMUNITIES, Schema.list(Schema.STRING)), equalTo(ImmutableList.of("1:1"))); }
static Multiset<Row> getBgpRibRoutes( Table<String, String, Set<Bgpv4Route>> bgpRoutes, RibProtocol ribProtocol, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(ribProtocol).toColumnMap(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); matchingNodes.forEach( hostname -> bgpRoutes .row(hostname) .forEach( (vrfName, routes) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { routes.stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec .getProtocols() .contains(route.getProtocol())) .forEach( route -> rows.add( bgpRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); return rows; }
RoutesAnswererUtil { static Multiset<Row> getBgpRibRoutes( Table<String, String, Set<Bgpv4Route>> bgpRoutes, RibProtocol ribProtocol, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(ribProtocol).toColumnMap(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); matchingNodes.forEach( hostname -> bgpRoutes .row(hostname) .forEach( (vrfName, routes) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { routes.stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec .getProtocols() .contains(route.getProtocol())) .forEach( route -> rows.add( bgpRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); return rows; } }
RoutesAnswererUtil { static Multiset<Row> getBgpRibRoutes( Table<String, String, Set<Bgpv4Route>> bgpRoutes, RibProtocol ribProtocol, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(ribProtocol).toColumnMap(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); matchingNodes.forEach( hostname -> bgpRoutes .row(hostname) .forEach( (vrfName, routes) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { routes.stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec .getProtocols() .contains(route.getProtocol())) .forEach( route -> rows.add( bgpRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); return rows; }  }
RoutesAnswererUtil { static Multiset<Row> getBgpRibRoutes( Table<String, String, Set<Bgpv4Route>> bgpRoutes, RibProtocol ribProtocol, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(ribProtocol).toColumnMap(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); matchingNodes.forEach( hostname -> bgpRoutes .row(hostname) .forEach( (vrfName, routes) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { routes.stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec .getProtocols() .contains(route.getProtocol())) .forEach( route -> rows.add( bgpRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); 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 Multiset<Row> getBgpRibRoutes( Table<String, String, Set<Bgpv4Route>> bgpRoutes, RibProtocol ribProtocol, Set<String> matchingNodes, @Nullable Prefix network, RoutingProtocolSpecifier protocolSpec, String vrfRegex) { Multiset<Row> rows = HashMultiset.create(); Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(ribProtocol).toColumnMap(); Pattern compiledVrfRegex = Pattern.compile(vrfRegex); matchingNodes.forEach( hostname -> bgpRoutes .row(hostname) .forEach( (vrfName, routes) -> { if (compiledVrfRegex.matcher(vrfName).matches()) { routes.stream() .filter( route -> (network == null || network.equals(route.getNetwork())) && protocolSpec .getProtocols() .contains(route.getProtocol())) .forEach( route -> rows.add( bgpRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); 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);  }