@Test public void testBgpRibRouteColumnsValue() { Ip ip = Ip.parse("1.1.1.1"); Prefix prefix = ip.toPrefix(); Ip bgpUnnumIp = Ip.parse("169.254.0.1"); Bgpv4Route.Builder rb = Bgpv4Route.builder() .setNetwork(prefix) .setOriginType(OriginType.IGP) .setCommunities(ImmutableSortedSet.of(StandardCommunity.of(65537L))) .setProtocol(RoutingProtocol.BGP) .setOriginatorIp(Ip.parse("1.1.1.2")) .setAsPath(AsPath.ofSingletonAsSets(ImmutableList.of(1L, 2L))); Bgpv4Route standardRoute = rb.setNextHopIp(ip).build(); Bgpv4Route unnumRoute = rb.setNextHopIp(bgpUnnumIp).setNextHopInterface("iface").build(); Table<String, String, Set<Bgpv4Route>> bgpRouteTable = HashBasedTable.create(); bgpRouteTable.put("node", "vrf", ImmutableSet.of(standardRoute, unnumRoute)); Multiset<Row> rows = getBgpRibRoutes( bgpRouteTable, RibProtocol.BGP, ImmutableSet.of("node"), null, RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER, ".*"); Matcher<Row> commonMatcher = allOf( hasColumn(COL_NODE, new Node("node"), Schema.NODE), hasColumn(COL_VRF_NAME, "vrf", Schema.STRING), hasColumn(COL_NETWORK, prefix, Schema.PREFIX), hasColumn(COL_PROTOCOL, "bgp", Schema.STRING), hasColumn(COL_AS_PATH, "1 2", Schema.STRING), hasColumn(COL_METRIC, 0, Schema.INTEGER), hasColumn(COL_LOCAL_PREF, 0L, Schema.LONG), hasColumn(COL_COMMUNITIES, ImmutableList.of("1:1"), Schema.list(Schema.STRING)), hasColumn(COL_ORIGIN_PROTOCOL, nullValue(), Schema.STRING), hasColumn(COL_TAG, nullValue(), Schema.INTEGER), hasColumn(COL_ORIGINATOR_ID, Ip.parse("1.1.1.2"), Schema.IP), hasColumn(COL_CLUSTER_LIST, nullValue(), Schema.list(Schema.LONG))); assertThat( rows, containsInAnyOrder( allOf( commonMatcher, hasColumn(COL_NEXT_HOP_IP, ip, Schema.IP), hasColumn(COL_NEXT_HOP_INTERFACE, "dynamic", Schema.STRING)), allOf( commonMatcher, hasColumn(COL_NEXT_HOP_IP, nullValue(), Schema.IP), hasColumn(COL_NEXT_HOP_INTERFACE, "iface", Schema.STRING)))); }
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);  }