@Test public void testEvpnRibRouteColumns() { Ip ip = Ip.parse("1.1.1.1"); Prefix prefix = ip.toPrefix(); EvpnType3Route.Builder rb = EvpnType3Route.builder() .setVniIp(ip) .setRouteDistinguisher(RouteDistinguisher.from(ip, 1)) .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))); EvpnType3Route standardRoute = rb.setNextHopIp(ip).build(); Table<String, String, Set<EvpnRoute<?, ?>>> evpnRouteTable = HashBasedTable.create(); evpnRouteTable.put("node", "vrf", ImmutableSet.of(standardRoute)); Multiset<Row> rows = getEvpnRoutes( evpnRouteTable, RibProtocol.EVPN, ImmutableSet.of("node"), null, RoutingProtocolSpecifier.ALL_PROTOCOLS_SPECIFIER, ".*"); assertThat( rows, contains( allOf( hasColumn(COL_NODE, new Node("node"), Schema.NODE), hasColumn(COL_VRF_NAME, "vrf", Schema.STRING), hasColumn(COL_NETWORK, prefix, Schema.PREFIX), hasColumn( COL_ROUTE_DISTINGUISHER, RouteDistinguisher.from(ip, 1).toString(), Schema.STRING), 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_NEXT_HOP_IP, ip, Schema.IP), hasColumn(COL_NEXT_HOP_INTERFACE, "dynamic", Schema.STRING)))); }
static Multiset<Row> getEvpnRoutes( Table<String, String, Set<EvpnRoute<?, ?>>> evpnRoutes, 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 -> evpnRoutes .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( evpnRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); return rows; }
RoutesAnswererUtil { static Multiset<Row> getEvpnRoutes( Table<String, String, Set<EvpnRoute<?, ?>>> evpnRoutes, 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 -> evpnRoutes .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( evpnRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); return rows; } }
RoutesAnswererUtil { static Multiset<Row> getEvpnRoutes( Table<String, String, Set<EvpnRoute<?, ?>>> evpnRoutes, 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 -> evpnRoutes .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( evpnRouteToRow( hostname, vrfName, route, columnMetadataMap))); } })); return rows; }  }
RoutesAnswererUtil { static Multiset<Row> getEvpnRoutes( Table<String, String, Set<EvpnRoute<?, ?>>> evpnRoutes, 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 -> evpnRoutes .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( evpnRouteToRow( 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> getEvpnRoutes( Table<String, String, Set<EvpnRoute<?, ?>>> evpnRoutes, 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 -> evpnRoutes .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( evpnRouteToRow( 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);  }