@Test public void testGetRoutesDiffCommonKey() { RouteRowKey routeRowKey = new RouteRowKey("node", "vrf", Prefix.parse("2.2.2.2/24")); RouteRowSecondaryKey rrsk1 = new RouteRowSecondaryKey(Ip.parse("1.1.1.1"), "bgp"); RouteRowSecondaryKey rrsk2 = new RouteRowSecondaryKey(Ip.parse("1.1.1.2"), "bgp"); RouteRowSecondaryKey rrsk3 = new RouteRowSecondaryKey(Ip.parse("1.1.1.3"), "bgp"); RouteRowSecondaryKey rrsk4 = new RouteRowSecondaryKey(Ip.parse("1.1.1.4"), "bgp"); RouteRowAttribute rra1 = RouteRowAttribute.builder().setNextHop("node1").build(); RouteRowAttribute rra2 = RouteRowAttribute.builder().setNextHop("node2").build(); RouteRowAttribute rra3 = RouteRowAttribute.builder().setNextHop("node3").build(); RouteRowAttribute rra4 = RouteRowAttribute.builder().setNextHop("node4").build(); RouteRowAttribute rra5 = RouteRowAttribute.builder().setNextHop("node5").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)) .put(rrsk2, ImmutableSortedSet.of(rra1, rra2)) .put(rrsk3, ImmutableSortedSet.of(rra4)) .build(); Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>> innerGroupsInRef = immutablelMapBuilderRef .put(rrsk1, ImmutableSortedSet.of(rra2)) .put(rrsk2, ImmutableSortedSet.of(rra1, rra3)) .put(rrsk4, ImmutableSortedSet.of(rra5)) .build(); List<DiffRoutesOutput> diffRoutesOutputs = getRoutesDiff( ImmutableMap.of(routeRowKey, innerGroupsInBase), ImmutableMap.of(routeRowKey, innerGroupsInRef)); assertThat( diffRoutesOutputs, containsInAnyOrder( new DiffRoutesOutput( routeRowKey, rrsk1, KeyPresenceStatus.IN_BOTH, ImmutableList.of(Lists.newArrayList(rra1, rra2)), KeyPresenceStatus.IN_BOTH), new DiffRoutesOutput( routeRowKey, rrsk2, KeyPresenceStatus.IN_BOTH, ImmutableList.of( Lists.newArrayList(rra1, rra1), Lists.newArrayList(rra2, null), Lists.newArrayList(null, rra3)), KeyPresenceStatus.IN_BOTH), new DiffRoutesOutput( routeRowKey, rrsk3, KeyPresenceStatus.ONLY_IN_SNAPSHOT, ImmutableList.of(Lists.newArrayList(rra4, null)), KeyPresenceStatus.IN_BOTH), new DiffRoutesOutput( routeRowKey, rrsk4, KeyPresenceStatus.ONLY_IN_REFERENCE, ImmutableList.of(Lists.newArrayList(null, rra5)), KeyPresenceStatus.IN_BOTH))); }
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);  }