@Test public void testRouterIdInference() { RoutingInstance ri = new RoutingInstance("RI"); Ip routerId = Ip.parse("9.9.9.9"); Ip loopBackIp1 = Ip.parse("1.1.1.2"); Ip loopBackIp2 = Ip.parse("1.1.1.3"); Ip ifaceIp1 = Ip.parse("1.1.1.4"); Ip ifaceIp2 = Ip.parse("1.1.1.5"); ri.setRouterId(routerId); Interface lo0 = new Interface("lo0.0"); lo0.setPrimaryAddress(ConcreteInterfaceAddress.create(loopBackIp1, Prefix.MAX_PREFIX_LENGTH)); Interface lo1 = new Interface("lo0.1"); lo1.setPrimaryAddress(ConcreteInterfaceAddress.create(loopBackIp2, Prefix.MAX_PREFIX_LENGTH)); Interface i1 = new Interface("ge-0/0/0.0"); i1.setPrimaryAddress(ConcreteInterfaceAddress.create(ifaceIp1, Prefix.MAX_PREFIX_LENGTH - 1)); Interface i2 = new Interface("ge-0/0/0.1"); i2.setPrimaryAddress(ConcreteInterfaceAddress.create(ifaceIp2, Prefix.MAX_PREFIX_LENGTH - 1)); ri.getInterfaces().put(lo0.getName(), lo0); ri.getInterfaces().put(lo1.getName(), lo1); ri.getInterfaces().put(i1.getName(), i1); ri.getInterfaces().put(i2.getName(), i2); assertThat(getRouterId(ri), equalTo(routerId)); ri.setRouterId(null); assertThat(getRouterId(ri), equalTo(loopBackIp1)); ri.getInterfaces().remove(lo0.getName()); ri.getInterfaces().remove(lo1.getName()); assertThat(getRouterId(ri), equalTo(ifaceIp1)); ri.getInterfaces().clear(); assertThat(getRouterId(ri), equalTo(Ip.ZERO)); }
@Nonnull @VisibleForTesting static Ip getRouterId(RoutingInstance routingInstance) { Ip routerId = routingInstance.getRouterId(); if (routerId != null) { return routerId; } Map<String, Interface> allInterfaces = routingInstance.getInterfaces(); Map<String, Interface> loopbackInterfaces = allInterfaces.entrySet().stream() .filter(e -> e.getKey().toLowerCase().startsWith("lo")) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Interface> routerIdCandidates = loopbackInterfaces.isEmpty() ? allInterfaces : loopbackInterfaces; return routerIdCandidates.values().stream() .filter(Interface::getActive) .map(Interface::getPrimaryAddress) .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .min(Comparator.naturalOrder()) .orElse(Ip.ZERO); }
JuniperConfiguration extends VendorConfiguration { @Nonnull @VisibleForTesting static Ip getRouterId(RoutingInstance routingInstance) { Ip routerId = routingInstance.getRouterId(); if (routerId != null) { return routerId; } Map<String, Interface> allInterfaces = routingInstance.getInterfaces(); Map<String, Interface> loopbackInterfaces = allInterfaces.entrySet().stream() .filter(e -> e.getKey().toLowerCase().startsWith("lo")) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Interface> routerIdCandidates = loopbackInterfaces.isEmpty() ? allInterfaces : loopbackInterfaces; return routerIdCandidates.values().stream() .filter(Interface::getActive) .map(Interface::getPrimaryAddress) .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .min(Comparator.naturalOrder()) .orElse(Ip.ZERO); } }
JuniperConfiguration extends VendorConfiguration { @Nonnull @VisibleForTesting static Ip getRouterId(RoutingInstance routingInstance) { Ip routerId = routingInstance.getRouterId(); if (routerId != null) { return routerId; } Map<String, Interface> allInterfaces = routingInstance.getInterfaces(); Map<String, Interface> loopbackInterfaces = allInterfaces.entrySet().stream() .filter(e -> e.getKey().toLowerCase().startsWith("lo")) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Interface> routerIdCandidates = loopbackInterfaces.isEmpty() ? allInterfaces : loopbackInterfaces; return routerIdCandidates.values().stream() .filter(Interface::getActive) .map(Interface::getPrimaryAddress) .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .min(Comparator.naturalOrder()) .orElse(Ip.ZERO); } JuniperConfiguration(); }
JuniperConfiguration extends VendorConfiguration { @Nonnull @VisibleForTesting static Ip getRouterId(RoutingInstance routingInstance) { Ip routerId = routingInstance.getRouterId(); if (routerId != null) { return routerId; } Map<String, Interface> allInterfaces = routingInstance.getInterfaces(); Map<String, Interface> loopbackInterfaces = allInterfaces.entrySet().stream() .filter(e -> e.getKey().toLowerCase().startsWith("lo")) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Interface> routerIdCandidates = loopbackInterfaces.isEmpty() ? allInterfaces : loopbackInterfaces; return routerIdCandidates.values().stream() .filter(Interface::getActive) .map(Interface::getPrimaryAddress) .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .min(Comparator.naturalOrder()) .orElse(Ip.ZERO); } JuniperConfiguration(); static @Nonnull String computeFirewallFilterTermName(
      @Nonnull String filterName, @Nonnull String termName); static @Nonnull String computeSecurityPolicyTermName(
      @Nonnull String policyName, @Nonnull String termName); @VisibleForTesting static TraceElement matchingFirewallFilter(String filename, String filterName); @VisibleForTesting static TraceElement matchingFirewallFilterTerm(
      String filename, String filterName, String termName); @VisibleForTesting static TraceElement matchingSecurityPolicyTerm(
      String filename, String policyName, String termName); static String computePeerExportPolicyName(Prefix remoteAddress); static String computeOspfExportPolicyName(String vrfName); Map<String, NodeDevice> getNodeDevices(); @Override void setVendor(ConfigurationFormat format); static String computeContributorRouteFilterListName(Prefix prefix); static String computeAggregatedRouteGenerationPolicyName(Prefix prefix); static String computeGeneratedRouteGenerationPolicyName(Prefix prefix); static String computeIsisExportPolicyName(String routingInstanceName); @Override List<Configuration> toVendorIndependentConfigurations(); static String computeLogicalSystemDefaultHostname(
      String masterHostname, String logicalSystemName); @Nonnull Map<String, LogicalSystem> getLogicalSystems(); LogicalSystem getMasterLogicalSystem(); @Override String getHostname(); @Override void setHostname(String hostname); }
JuniperConfiguration extends VendorConfiguration { @Nonnull @VisibleForTesting static Ip getRouterId(RoutingInstance routingInstance) { Ip routerId = routingInstance.getRouterId(); if (routerId != null) { return routerId; } Map<String, Interface> allInterfaces = routingInstance.getInterfaces(); Map<String, Interface> loopbackInterfaces = allInterfaces.entrySet().stream() .filter(e -> e.getKey().toLowerCase().startsWith("lo")) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); Map<String, Interface> routerIdCandidates = loopbackInterfaces.isEmpty() ? allInterfaces : loopbackInterfaces; return routerIdCandidates.values().stream() .filter(Interface::getActive) .map(Interface::getPrimaryAddress) .filter(Objects::nonNull) .map(ConcreteInterfaceAddress::getIp) .min(Comparator.naturalOrder()) .orElse(Ip.ZERO); } JuniperConfiguration(); static @Nonnull String computeFirewallFilterTermName(
      @Nonnull String filterName, @Nonnull String termName); static @Nonnull String computeSecurityPolicyTermName(
      @Nonnull String policyName, @Nonnull String termName); @VisibleForTesting static TraceElement matchingFirewallFilter(String filename, String filterName); @VisibleForTesting static TraceElement matchingFirewallFilterTerm(
      String filename, String filterName, String termName); @VisibleForTesting static TraceElement matchingSecurityPolicyTerm(
      String filename, String policyName, String termName); static String computePeerExportPolicyName(Prefix remoteAddress); static String computeOspfExportPolicyName(String vrfName); Map<String, NodeDevice> getNodeDevices(); @Override void setVendor(ConfigurationFormat format); static String computeContributorRouteFilterListName(Prefix prefix); static String computeAggregatedRouteGenerationPolicyName(Prefix prefix); static String computeGeneratedRouteGenerationPolicyName(Prefix prefix); static String computeIsisExportPolicyName(String routingInstanceName); @Override List<Configuration> toVendorIndependentConfigurations(); static String computeLogicalSystemDefaultHostname(
      String masterHostname, String logicalSystemName); @Nonnull Map<String, LogicalSystem> getLogicalSystems(); LogicalSystem getMasterLogicalSystem(); @Override String getHostname(); @Override void setHostname(String hostname); static final String ACL_NAME_COMBINED_INCOMING; static final String ACL_NAME_GLOBAL_POLICY; static final String ACL_NAME_SCREEN; static final String ACL_NAME_SCREEN_INTERFACE; static final String ACL_NAME_SCREEN_ZONE; static final String ACL_NAME_SECURITY_POLICY; @VisibleForTesting static final int DEFAULT_ISIS_COST; }