@Test public void testInitInterfaceCosts() { NetworkFactory nf = new NetworkFactory(); Configuration c1 = nf.configurationBuilder() .setHostname("r1") .setConfigurationFormat(ConfigurationFormat.CISCO_IOS) .build(); OspfProcess.Builder opb = nf.ospfProcessBuilder(); OspfArea.Builder oab = nf.ospfAreaBuilder().setNonStub().setNumber(0L); OspfArea area0 = oab.build(); OspfArea area1 = oab.setNumber(1L).build(); Interface.Builder ib = nf.interfaceBuilder().setOwner(c1); Interface i0 = ib.setName("eth0") .setBandwidth(1e3) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setAreaName(area0.getAreaNumber()) .build()) .build(); area0.addInterface("eth0"); Interface i1 = ib.setName("eth1") .setBandwidth(1e4) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setAreaName(area1.getAreaNumber()) .build()) .build(); area1.addInterface("eth1"); Interface i2 = ib.setName("eth2") .setBandwidth(1e5) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setAreaName(area1.getAreaNumber()) .build()) .setActive(false) .build(); area1.addInterface("eth2"); Interface i3 = ib.setName("eth3") .setBandwidth(1e6) .setOspfSettings( OspfInterfaceSettings.defaultSettingsBuilder() .setAreaName(area1.getAreaNumber()) .setPassive(true) .build()) .setActive(true) .build(); area1.addInterface("eth3"); OspfProcess proc = opb.setReferenceBandwidth(1e8) .setRouterId(Ip.ZERO) .setAreas(ImmutableSortedMap.of(0L, area0, 1L, area1)) .build(); proc.initInterfaceCosts(c1); assertThat(i0.getOspfCost(), equalTo(100000)); assertThat(i1.getOspfCost(), equalTo(10000)); assertThat(i2.getOspfCost(), nullValue()); assertThat(i3.getOspfCost(), equalTo(100)); }
public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .filter(i -> i.getOspfSettings() != null) .forEach(i -> i.getOspfSettings().setCost(computeInterfaceCost(i))); }
OspfProcess implements Serializable { public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .filter(i -> i.getOspfSettings() != null) .forEach(i -> i.getOspfSettings().setCost(computeInterfaceCost(i))); } }
OspfProcess implements Serializable { public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .filter(i -> i.getOspfSettings() != null) .forEach(i -> i.getOspfSettings().setCost(computeInterfaceCost(i))); } private  OspfProcess(
      Map<RoutingProtocol, Integer> adminCosts,
      Map<Long, OspfArea> areas,
      @Nullable String exportPolicy,
      Set<String> exportPolicySources,
      Set<GeneratedRoute> generatedRoutes,
      @Nullable Long maxMetricExternalNetworks,
      @Nullable Long maxMetricStubNetworks,
      @Nullable Long maxMetricSummaryNetworks,
      @Nullable Long maxMetricTransitLinks,
      Map<OspfNeighborConfigId, OspfNeighborConfig> ospfNeighborConfigs,
      String processId,
      Double referenceBandwidth,
      @Nullable Boolean rfc1583Compatible,
      Ip routerId,
      Integer summaryAdminCost); }
OspfProcess implements Serializable { public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .filter(i -> i.getOspfSettings() != null) .forEach(i -> i.getOspfSettings().setCost(computeInterfaceCost(i))); } private  OspfProcess(
      Map<RoutingProtocol, Integer> adminCosts,
      Map<Long, OspfArea> areas,
      @Nullable String exportPolicy,
      Set<String> exportPolicySources,
      Set<GeneratedRoute> generatedRoutes,
      @Nullable Long maxMetricExternalNetworks,
      @Nullable Long maxMetricStubNetworks,
      @Nullable Long maxMetricSummaryNetworks,
      @Nullable Long maxMetricTransitLinks,
      Map<OspfNeighborConfigId, OspfNeighborConfig> ospfNeighborConfigs,
      String processId,
      Double referenceBandwidth,
      @Nullable Boolean rfc1583Compatible,
      Ip routerId,
      Integer summaryAdminCost); static @Nonnull Builder builder(@Nullable Supplier<String> processIdGenerator); static @Nonnull Builder builder(); static Map<RoutingProtocol, Integer> computeDefaultAdminCosts(ConfigurationFormat format); int computeInterfaceCost(Interface i); @Nonnull @JsonIgnore Map<RoutingProtocol, Integer> getAdminCosts(); @Nonnull @JsonIgnore Map<Long, OspfArea> getAreas(); @JsonProperty(PROP_EXPORT_POLICY) @Nullable String getExportPolicy(); @Nonnull @JsonIgnore Set<String> getExportPolicySources(); @Nonnull @JsonIgnore Set<GeneratedRoute> getGeneratedRoutes(); @Nullable @JsonProperty(PROP_MAX_METRIC_EXTERNAL_NETWORKS) Long getMaxMetricExternalNetworks(); @Nullable @JsonProperty(PROP_MAX_METRIC_STUB_NETWORKS) Long getMaxMetricStubNetworks(); @Nullable @JsonProperty(PROP_MAX_METRIC_SUMMARY_NETWORKS) Long getMaxMetricSummaryNetworks(); @Nullable @JsonProperty(PROP_MAX_METRIC_TRANSIT_LINKS) Long getMaxMetricTransitLinks(); @JsonIgnore Map<IpLink, OspfNeighbor> getOspfNeighbors(); @JsonIgnore Map<OspfNeighborConfigId, OspfNeighborConfig> getOspfNeighborConfigs(); @Nonnull @JsonProperty(PROP_PROCESS_ID) String getProcessId(); @Nonnull @JsonProperty(PROP_REFERENCE_BANDWIDTH) Double getReferenceBandwidth(); @Nullable @JsonProperty(PROP_RFC1583) Boolean getRfc1583Compatible(); @Nonnull @JsonProperty(PROP_ROUTER_ID) Ip getRouterId(); int getSummaryAdminCost(); void initInterfaceCosts(Configuration c); @JsonIgnore boolean isAreaBorderRouter(); @JsonIgnore void setAreas(Map<Long, OspfArea> areas); void addArea(OspfArea area); @JsonIgnore void setExportPolicy(@Nullable String exportPolicy); @JsonIgnore void setExportPolicySources(SortedSet<String> exportPolicySources); @JsonIgnore void setGeneratedRoutes(SortedSet<GeneratedRoute> generatedRoutes); void addGeneratedRoute(GeneratedRoute route); @JsonIgnore void setMaxMetricExternalNetworks(@Nullable Long maxMetricExternalNetworks); @JsonIgnore void setMaxMetricStubNetworks(@Nullable Long maxMetricStubNetworks); @JsonIgnore void setMaxMetricSummaryNetworks(@Nullable Long maxMetricSummaryNetworks); @JsonIgnore void setMaxMetricTransitLinks(@Nullable Long maxMetricTransitLinks); @JsonIgnore void setOspfNeighbors(Map<IpLink, OspfNeighbor> ospfNeighbors); @JsonIgnore void setReferenceBandwidth(Double referenceBandwidth); @JsonIgnore void setRfc1583Compatible(@Nullable Boolean rfc1583Compatible); @JsonIgnore void setRouterId(@Nonnull Ip id); }
OspfProcess implements Serializable { public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .filter(i -> i.getOspfSettings() != null) .forEach(i -> i.getOspfSettings().setCost(computeInterfaceCost(i))); } private  OspfProcess(
      Map<RoutingProtocol, Integer> adminCosts,
      Map<Long, OspfArea> areas,
      @Nullable String exportPolicy,
      Set<String> exportPolicySources,
      Set<GeneratedRoute> generatedRoutes,
      @Nullable Long maxMetricExternalNetworks,
      @Nullable Long maxMetricStubNetworks,
      @Nullable Long maxMetricSummaryNetworks,
      @Nullable Long maxMetricTransitLinks,
      Map<OspfNeighborConfigId, OspfNeighborConfig> ospfNeighborConfigs,
      String processId,
      Double referenceBandwidth,
      @Nullable Boolean rfc1583Compatible,
      Ip routerId,
      Integer summaryAdminCost); static @Nonnull Builder builder(@Nullable Supplier<String> processIdGenerator); static @Nonnull Builder builder(); static Map<RoutingProtocol, Integer> computeDefaultAdminCosts(ConfigurationFormat format); int computeInterfaceCost(Interface i); @Nonnull @JsonIgnore Map<RoutingProtocol, Integer> getAdminCosts(); @Nonnull @JsonIgnore Map<Long, OspfArea> getAreas(); @JsonProperty(PROP_EXPORT_POLICY) @Nullable String getExportPolicy(); @Nonnull @JsonIgnore Set<String> getExportPolicySources(); @Nonnull @JsonIgnore Set<GeneratedRoute> getGeneratedRoutes(); @Nullable @JsonProperty(PROP_MAX_METRIC_EXTERNAL_NETWORKS) Long getMaxMetricExternalNetworks(); @Nullable @JsonProperty(PROP_MAX_METRIC_STUB_NETWORKS) Long getMaxMetricStubNetworks(); @Nullable @JsonProperty(PROP_MAX_METRIC_SUMMARY_NETWORKS) Long getMaxMetricSummaryNetworks(); @Nullable @JsonProperty(PROP_MAX_METRIC_TRANSIT_LINKS) Long getMaxMetricTransitLinks(); @JsonIgnore Map<IpLink, OspfNeighbor> getOspfNeighbors(); @JsonIgnore Map<OspfNeighborConfigId, OspfNeighborConfig> getOspfNeighborConfigs(); @Nonnull @JsonProperty(PROP_PROCESS_ID) String getProcessId(); @Nonnull @JsonProperty(PROP_REFERENCE_BANDWIDTH) Double getReferenceBandwidth(); @Nullable @JsonProperty(PROP_RFC1583) Boolean getRfc1583Compatible(); @Nonnull @JsonProperty(PROP_ROUTER_ID) Ip getRouterId(); int getSummaryAdminCost(); void initInterfaceCosts(Configuration c); @JsonIgnore boolean isAreaBorderRouter(); @JsonIgnore void setAreas(Map<Long, OspfArea> areas); void addArea(OspfArea area); @JsonIgnore void setExportPolicy(@Nullable String exportPolicy); @JsonIgnore void setExportPolicySources(SortedSet<String> exportPolicySources); @JsonIgnore void setGeneratedRoutes(SortedSet<GeneratedRoute> generatedRoutes); void addGeneratedRoute(GeneratedRoute route); @JsonIgnore void setMaxMetricExternalNetworks(@Nullable Long maxMetricExternalNetworks); @JsonIgnore void setMaxMetricStubNetworks(@Nullable Long maxMetricStubNetworks); @JsonIgnore void setMaxMetricSummaryNetworks(@Nullable Long maxMetricSummaryNetworks); @JsonIgnore void setMaxMetricTransitLinks(@Nullable Long maxMetricTransitLinks); @JsonIgnore void setOspfNeighbors(Map<IpLink, OspfNeighbor> ospfNeighbors); @JsonIgnore void setReferenceBandwidth(Double referenceBandwidth); @JsonIgnore void setRfc1583Compatible(@Nullable Boolean rfc1583Compatible); @JsonIgnore void setRouterId(@Nonnull Ip id); static final EnumSet<RoutingProtocol> REQUIRES_ADMIN; }