use of org.batfish.datamodel.OspfIntraAreaRoute in project batfish by batfish.
the class VirtualRouter method propagateOspfIntraAreaRoute.
boolean propagateOspfIntraAreaRoute(OspfIntraAreaRoute neighborRoute, long incrementalCost, Interface neighborInterface, int adminCost, long areaNum) {
long newCost = neighborRoute.getMetric() + incrementalCost;
Ip nextHopIp = neighborInterface.getAddress().getIp();
OspfIntraAreaRoute newRoute = new OspfIntraAreaRoute(neighborRoute.getNetwork(), nextHopIp, adminCost, newCost, areaNum);
return neighborRoute.getArea() == areaNum && _ospfIntraAreaStagingRib.mergeRoute(newRoute);
}
use of org.batfish.datamodel.OspfIntraAreaRoute in project batfish by batfish.
the class VirtualRouter method initIntraAreaOspfRoutes.
/**
* Initialize Intra-area OSPF routes from the interface prefixes
*/
private void initIntraAreaOspfRoutes() {
OspfProcess proc = _vrf.getOspfProcess();
if (proc == null) {
// nothing to do
return;
}
// init intra-area routes from connected routes
// For each interface within an OSPF area and each interface prefix,
// construct a new OSPF-IA route. Put it in the IA RIB.
proc.getAreas().forEach((areaNum, area) -> {
for (String ifaceName : area.getInterfaces()) {
Interface iface = _c.getInterfaces().get(ifaceName);
if (iface.getActive()) {
Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream().map(InterfaceAddress::getPrefix).collect(Collectors.toSet());
int interfaceOspfCost = iface.getOspfCost();
for (Prefix prefix : allNetworkPrefixes) {
long cost = interfaceOspfCost;
boolean stubNetwork = iface.getOspfPassive() || iface.getOspfPointToPoint();
if (stubNetwork) {
if (proc.getMaxMetricStubNetworks() != null) {
cost = proc.getMaxMetricStubNetworks();
}
} else if (proc.getMaxMetricTransitLinks() != null) {
cost = proc.getMaxMetricTransitLinks();
}
OspfIntraAreaRoute route = new OspfIntraAreaRoute(prefix, null, RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat()), cost, areaNum);
_ospfIntraAreaRib.mergeRoute(route);
}
}
}
});
}
use of org.batfish.datamodel.OspfIntraAreaRoute in project batfish by batfish.
the class AbstractRibTest method testGetRoutesWithReplacement.
/**
* Check that getRoutes works as expected even when routes replace other routes based on
* preference
*/
@Test
public void testGetRoutesWithReplacement() {
// Use OSPF RIBs for this, as routes with better metric can replace other routes
OspfIntraAreaRib rib = new OspfIntraAreaRib(null);
Prefix prefix = Prefix.parse("1.1.1.1/32");
rib.mergeRoute(new OspfIntraAreaRoute(prefix, null, 100, 30, 1));
assertThat(rib.getRoutes(), hasSize(1));
// This new route replaces old route
OspfIntraAreaRoute newRoute = new OspfIntraAreaRoute(prefix, null, 100, 10, 1);
rib.mergeRoute(newRoute);
assertThat(rib.getRoutes(), contains(newRoute));
// Add completely new route and check that the size increases
rib.mergeRoute(new OspfIntraAreaRoute(Prefix.parse("2.2.2.2/32"), null, 100, 30, 1));
assertThat(rib.getRoutes(), hasSize(2));
}
use of org.batfish.datamodel.OspfIntraAreaRoute in project batfish by batfish.
the class VirtualRouterTest method testOSPFPassiveInterfaceRejection.
/**
* Ensure no route propagation when the interfaces are disabled or passive
*/
@Test
public void testOSPFPassiveInterfaceRejection() {
// Setup
String testRouterName = "R1";
String exportingRouterName = "R2";
String exportingRouterInterfaceName = "Ethernet1";
Map<String, Node> nodes = makeIosRouters(testRouterName, exportingRouterName);
Map<String, VirtualRouter> routers = nodes.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> e.getValue()._virtualRouters.get(Configuration.DEFAULT_VRF_NAME)));
VirtualRouter testRouter = routers.get(testRouterName);
VirtualRouter exportingRouter = routers.get(exportingRouterName);
testRouter.initRibs();
exportingRouter.initRibs();
addInterfaces(testRouter._c, exampleInterfaceAddresses);
addInterfaces(exportingRouter._c, ImmutableMap.of(exportingRouterInterfaceName, new InterfaceAddress("10.4.0.0/16")));
int adminCost = RoutingProtocol.OSPF.getDefaultAdministrativeCost(testRouter._c.getConfigurationFormat());
Prefix prefix = Prefix.parse("7.7.7.0/24");
OspfIntraAreaRoute route = new OspfIntraAreaRoute(prefix, new Ip("7.7.1.1"), adminCost, 20, 1);
exportingRouter._ospfIntraAreaRib.mergeRoute(route);
// Set interaces on router 1 to be OSPF passive
testRouter._c.getInterfaces().forEach((name, iface) -> iface.setActive(false));
// Test 1
testRouter.propagateOspfInternalRoutesFromNeighbor(testRouter._vrf.getOspfProcess(), nodes.get("R2"), testRouter._c.getInterfaces().firstEntry().getValue(), exportingRouter._c.getInterfaces().get(exportingRouterInterfaceName), adminCost);
assertThat(testRouter._ospfInterAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfInterAreaRoute.class)));
assertThat(testRouter._ospfIntraAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfIntraAreaRoute.class)));
// Flip interfaces on router 2 to be passive now
testRouter._c.getInterfaces().forEach((name, iface) -> iface.setActive(true));
exportingRouter._c.getInterfaces().forEach((name, iface) -> iface.setActive(false));
// Test 2
testRouter.propagateOspfInternalRoutesFromNeighbor(testRouter._vrf.getOspfProcess(), nodes.get("R2"), testRouter._c.getInterfaces().firstEntry().getValue(), exportingRouter._c.getInterfaces().get(exportingRouterInterfaceName), adminCost);
assertThat(testRouter._ospfInterAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfInterAreaRoute.class)));
assertThat(testRouter._ospfIntraAreaStagingRib.getRoutes(), is(emptyIterableOf(OspfIntraAreaRoute.class)));
}
use of org.batfish.datamodel.OspfIntraAreaRoute in project batfish by batfish.
the class VirtualRouter method computeInterAreaSummaries.
boolean computeInterAreaSummaries() {
OspfProcess proc = _vrf.getOspfProcess();
boolean changed = false;
// Ensure we have a running OSPF process on the VRF, otherwise bail.
if (proc == null) {
return false;
}
// Admin cost for the given protocol
int admin = RoutingProtocol.OSPF_IA.getSummaryAdministrativeCost(_c.getConfigurationFormat());
// Determine whether to use min metric by default, based on RFC1583 compatibility setting.
// Routers (at least Cisco and Juniper) default to min metric unless using RFC2328 with
// RFC1583 compatibility explicitly disabled, in which case they default to max.
boolean useMin = MoreObjects.firstNonNull(proc.getRfc1583Compatible(), true);
// Compute summaries for each area
for (Entry<Long, OspfArea> e : proc.getAreas().entrySet()) {
long areaNum = e.getKey();
OspfArea area = e.getValue();
for (Entry<Prefix, OspfAreaSummary> e2 : area.getSummaries().entrySet()) {
Prefix prefix = e2.getKey();
OspfAreaSummary summary = e2.getValue();
// Only advertised summaries can contribute
if (!summary.getAdvertised()) {
continue;
}
Long metric = summary.getMetric();
if (summary.getMetric() == null) {
// No metric was configured; compute it from any possible contributing routes.
for (OspfIntraAreaRoute contributingRoute : _ospfIntraAreaRib.getRoutes()) {
metric = computeUpdatedOspfSummaryMetric(contributingRoute, prefix, metric, areaNum, useMin);
}
for (OspfInterAreaRoute contributingRoute : _ospfInterAreaRib.getRoutes()) {
metric = computeUpdatedOspfSummaryMetric(contributingRoute, prefix, metric, areaNum, useMin);
}
}
// No routes contributed to the summary, nothing to construct
if (metric == null) {
continue;
}
// Non-null metric means we generate a new summary and put it in the RIB
OspfInterAreaRoute summaryRoute = new OspfInterAreaRoute(prefix, Ip.ZERO, admin, metric, areaNum);
if (_ospfInterAreaStagingRib.mergeRoute(summaryRoute)) {
changed = true;
}
}
}
return changed;
}
Aggregations