public int computeInterfaceCost(Interface i) { return computeInterfaceCost(_referenceBandwidth, i); }
/** Initialize interface costs for all interfaces that belong to this process */ public void initInterfaceCosts(Configuration c) { _areas.values().stream() .flatMap(a -> a.getInterfaces().stream()) .map(interfaceName -> c.getAllInterfaces().get(interfaceName)) .filter(Interface::getActive) .forEach(i -> i.setOspfCost(computeInterfaceCost(i))); }
@Test public void testComputeInterfaceCost() { Interface.Builder ib = Interface.builder() .setName("eth0") .setBandwidth(1e3) .setOwner(new Configuration("r1", ConfigurationFormat.CISCO_IOS)); Interface i = ib.build(); // Round up to 1 int cost = OspfProcess.computeInterfaceCost(1.0, i); assertThat(cost, equalTo(1)); cost = OspfProcess.computeInterfaceCost(1e6, i); assertThat(cost, equalTo(1000)); _thrown.expectMessage("Interface eth0 on r1 is missing bandwidth"); _thrown.expect(IllegalStateException.class); OspfProcess.computeInterfaceCost(1e6, ib.setBandwidth(null).build()); }
OspfProcess proc = _vrf.getOspfProcess(); if (proc != null && _active) { iface.setOspfCost(proc.computeInterfaceCost(iface));