@Test public void testGetRoutesDiffNonCommonKey() { RouteRowKey routeRowKey1 = new RouteRowKey("node1", "vrf", Prefix.parse("1.1.1.1/24")); RouteRowKey routeRowKey2 = new RouteRowKey("node2", "vrf", Prefix.parse("1.1.1.2/24")); RouteRowSecondaryKey rrsk1 = new RouteRowSecondaryKey(Ip.parse("1.1.1.1"), "bgp"); RouteRowSecondaryKey rrsk2 = new RouteRowSecondaryKey(Ip.parse("1.1.1.2"), "bgp"); RouteRowAttribute rra1 = RouteRowAttribute.builder().setNextHop("node11").build(); RouteRowAttribute rra2 = RouteRowAttribute.builder().setNextHop("node22").build(); ImmutableMap.Builder<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> immutablelMapBuilderBase = ImmutableMap.builder(); ImmutableMap.Builder<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> immutablelMapBuilderRef = ImmutableMap.builder(); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> innerGroupsInBase = immutablelMapBuilderBase.put(rrsk1, ImmutableSortedSet.of(rra1)).build(); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> innerGroupsInRef = immutablelMapBuilderRef.put(rrsk2, ImmutableSortedSet.of(rra2)).build(); List<DiffRoutesOutput> diffRoutesOutputs = getRoutesDiff( ImmutableMap.of(routeRowKey1, innerGroupsInBase), ImmutableMap.of(routeRowKey2, innerGroupsInRef)); assertThat( diffRoutesOutputs, containsInAnyOrder( new DiffRoutesOutput( routeRowKey1, rrsk1, KeyPresenceStatus.ONLY_IN_SNAPSHOT, ImmutableList.of(Lists.newArrayList(rra1, null)), KeyPresenceStatus.ONLY_IN_SNAPSHOT), new DiffRoutesOutput( routeRowKey2, rrsk2, KeyPresenceStatus.ONLY_IN_REFERENCE, ImmutableList.of(Lists.newArrayList(null, rra2)), KeyPresenceStatus.ONLY_IN_REFERENCE))); }
public static List<DiffRoutesOutput> getRoutesDiff( Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase, Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef) { Set<RouteRowKey> allRouteKeys = new HashSet<>(routesInBase.keySet()); allRouteKeys.addAll(routesInRef.keySet()); List<DiffRoutesOutput> listDiffs = new ArrayList<>(); for (RouteRowKey routeRowKey : allRouteKeys) { Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> baseAttrsForRowKey = routesInBase.get(routeRowKey); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> refAttrsForRowKey = routesInRef.get(routeRowKey); if (baseAttrsForRowKey != null && refAttrsForRowKey != null) { if (!baseAttrsForRowKey.equals(refAttrsForRowKey)) { listDiffs.addAll(getDiffPerKey(routeRowKey, baseAttrsForRowKey, refAttrsForRowKey)); } } else if (baseAttrsForRowKey != null) { baseAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(routeRowAttribute, null)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_SNAPSHOT, diffMatrix, KeyPresenceStatus.ONLY_IN_SNAPSHOT)); }); } else { refAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(null, routeRowAttribute)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_REFERENCE, diffMatrix, KeyPresenceStatus.ONLY_IN_REFERENCE)); }); } } return listDiffs; }
RoutesAnswererUtil { public static List<DiffRoutesOutput> getRoutesDiff( Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase, Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef) { Set<RouteRowKey> allRouteKeys = new HashSet<>(routesInBase.keySet()); allRouteKeys.addAll(routesInRef.keySet()); List<DiffRoutesOutput> listDiffs = new ArrayList<>(); for (RouteRowKey routeRowKey : allRouteKeys) { Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> baseAttrsForRowKey = routesInBase.get(routeRowKey); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> refAttrsForRowKey = routesInRef.get(routeRowKey); if (baseAttrsForRowKey != null && refAttrsForRowKey != null) { if (!baseAttrsForRowKey.equals(refAttrsForRowKey)) { listDiffs.addAll(getDiffPerKey(routeRowKey, baseAttrsForRowKey, refAttrsForRowKey)); } } else if (baseAttrsForRowKey != null) { baseAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(routeRowAttribute, null)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_SNAPSHOT, diffMatrix, KeyPresenceStatus.ONLY_IN_SNAPSHOT)); }); } else { refAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(null, routeRowAttribute)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_REFERENCE, diffMatrix, KeyPresenceStatus.ONLY_IN_REFERENCE)); }); } } return listDiffs; } }
RoutesAnswererUtil { public static List<DiffRoutesOutput> getRoutesDiff( Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase, Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef) { Set<RouteRowKey> allRouteKeys = new HashSet<>(routesInBase.keySet()); allRouteKeys.addAll(routesInRef.keySet()); List<DiffRoutesOutput> listDiffs = new ArrayList<>(); for (RouteRowKey routeRowKey : allRouteKeys) { Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> baseAttrsForRowKey = routesInBase.get(routeRowKey); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> refAttrsForRowKey = routesInRef.get(routeRowKey); if (baseAttrsForRowKey != null && refAttrsForRowKey != null) { if (!baseAttrsForRowKey.equals(refAttrsForRowKey)) { listDiffs.addAll(getDiffPerKey(routeRowKey, baseAttrsForRowKey, refAttrsForRowKey)); } } else if (baseAttrsForRowKey != null) { baseAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(routeRowAttribute, null)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_SNAPSHOT, diffMatrix, KeyPresenceStatus.ONLY_IN_SNAPSHOT)); }); } else { refAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(null, routeRowAttribute)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_REFERENCE, diffMatrix, KeyPresenceStatus.ONLY_IN_REFERENCE)); }); } } return listDiffs; }  }
RoutesAnswererUtil { public static List<DiffRoutesOutput> getRoutesDiff( Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase, Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef) { Set<RouteRowKey> allRouteKeys = new HashSet<>(routesInBase.keySet()); allRouteKeys.addAll(routesInRef.keySet()); List<DiffRoutesOutput> listDiffs = new ArrayList<>(); for (RouteRowKey routeRowKey : allRouteKeys) { Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> baseAttrsForRowKey = routesInBase.get(routeRowKey); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> refAttrsForRowKey = routesInRef.get(routeRowKey); if (baseAttrsForRowKey != null && refAttrsForRowKey != null) { if (!baseAttrsForRowKey.equals(refAttrsForRowKey)) { listDiffs.addAll(getDiffPerKey(routeRowKey, baseAttrsForRowKey, refAttrsForRowKey)); } } else if (baseAttrsForRowKey != null) { baseAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(routeRowAttribute, null)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_SNAPSHOT, diffMatrix, KeyPresenceStatus.ONLY_IN_SNAPSHOT)); }); } else { refAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(null, routeRowAttribute)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_REFERENCE, diffMatrix, KeyPresenceStatus.ONLY_IN_REFERENCE)); }); } } return listDiffs; }  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 { public static List<DiffRoutesOutput> getRoutesDiff( Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase, Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef) { Set<RouteRowKey> allRouteKeys = new HashSet<>(routesInBase.keySet()); allRouteKeys.addAll(routesInRef.keySet()); List<DiffRoutesOutput> listDiffs = new ArrayList<>(); for (RouteRowKey routeRowKey : allRouteKeys) { Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> baseAttrsForRowKey = routesInBase.get(routeRowKey); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> refAttrsForRowKey = routesInRef.get(routeRowKey); if (baseAttrsForRowKey != null && refAttrsForRowKey != null) { if (!baseAttrsForRowKey.equals(refAttrsForRowKey)) { listDiffs.addAll(getDiffPerKey(routeRowKey, baseAttrsForRowKey, refAttrsForRowKey)); } } else if (baseAttrsForRowKey != null) { baseAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(routeRowAttribute, null)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_SNAPSHOT, diffMatrix, KeyPresenceStatus.ONLY_IN_SNAPSHOT)); }); } else { refAttrsForRowKey.forEach( (key, value) -> { List<List<RouteRowAttribute>> diffMatrix = value.stream() .map(routeRowAttribute -> Lists.newArrayList(null, routeRowAttribute)) .collect(Collectors.toList()); listDiffs.add( new DiffRoutesOutput( routeRowKey, key, KeyPresenceStatus.ONLY_IN_REFERENCE, diffMatrix, KeyPresenceStatus.ONLY_IN_REFERENCE)); }); } } return listDiffs; }  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);  }