use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class VirtualRouter method isOspfInterAreaFromInterAreaPropagationAllowed.
private static boolean isOspfInterAreaFromInterAreaPropagationAllowed(long areaNum, Node neighbor, OspfInternalRoute neighborRoute, OspfArea neighborArea) {
long neighborRouteAreaNum = neighborRoute.getArea();
// May only propagate to or from area 0
if (areaNum != neighborRouteAreaNum && areaNum != 0L && neighborRouteAreaNum != 0L) {
return false;
}
Prefix neighborRouteNetwork = neighborRoute.getNetwork();
String neighborSummaryFilterName = neighborArea.getSummaryFilter();
boolean hasSummaryFilter = neighborSummaryFilterName != null;
boolean allowed = !hasSummaryFilter;
// If there is a summary filter, run the route through it
if (hasSummaryFilter) {
RouteFilterList neighborSummaryFilter = neighbor._c.getRouteFilterLists().get(neighborSummaryFilterName);
allowed = neighborSummaryFilter.permits(neighborRouteNetwork);
}
return allowed;
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class VirtualRouter method computeUpdatedOspfSummaryMetric.
/**
* Decides whether the current OSPF summary route metric needs to be changed based on the given
* route's metric.
*
* <p>Routes from the same area or outside of areaPrefix have no effect on the summary metric.
*
* @param route The route in question, whose metric is considered
* @param areaPrefix The Ip prefix of the OSPF area
* @param currentMetric The current summary metric for the area
* @param areaNum Area number.
* @param useMin Whether to use the older RFC 1583 computation, which takes the minimum of metrics
* as opposed to the newer RFC 2328, which uses the maximum
* @return the newly computed summary metric.
*/
@Nullable
static Long computeUpdatedOspfSummaryMetric(OspfInternalRoute route, Prefix areaPrefix, @Nullable Long currentMetric, long areaNum, boolean useMin) {
Prefix contributingRoutePrefix = route.getNetwork();
// Only update metric for different areas and if the area prefix contains the route prefix
if (areaNum == route.getArea() || !areaPrefix.containsPrefix(contributingRoutePrefix)) {
return currentMetric;
}
long contributingRouteMetric = route.getMetric();
// Definitely update if we have no previous metric
if (currentMetric == null) {
return contributingRouteMetric;
}
// RFC1583 compatibility explicitly disabled, in which case they default to max.
if (useMin) {
return Math.min(currentMetric, contributingRouteMetric);
}
return Math.max(currentMetric, contributingRouteMetric);
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class VirtualRouter method initBaseRipRoutes.
/**
* Initialize RIP routes from the interface prefixes
*/
@VisibleForTesting
void initBaseRipRoutes() {
if (_vrf.getRipProcess() == null) {
// nothing to do
return;
}
// init internal routes from connected routes
for (String ifaceName : _vrf.getRipProcess().getInterfaces()) {
Interface iface = _vrf.getInterfaces().get(ifaceName);
if (iface.getActive()) {
Set<Prefix> allNetworkPrefixes = iface.getAllAddresses().stream().map(InterfaceAddress::getPrefix).collect(Collectors.toSet());
long cost = RipProcess.DEFAULT_RIP_COST;
for (Prefix prefix : allNetworkPrefixes) {
RipInternalRoute route = new RipInternalRoute(prefix, null, RoutingProtocol.RIP.getDefaultAdministrativeCost(_c.getConfigurationFormat()), cost);
_ripInternalRib.mergeRoute(route);
}
}
}
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class VirtualRouter method activateStaticRoutes.
/**
* Re-activate static routes at the beginning of an iteration. Directly adds a static route to the
* main RIB if the route's next-hop-ip matches routes from the previous iterations.
*/
boolean activateStaticRoutes() {
boolean changed = false;
for (StaticRoute sr : _staticRib.getRoutes()) {
// See if we had (in the previous RIB) any routes matching this route's next hop IP
Set<AbstractRoute> matchingRoutes = _prevMainRib.longestPrefixMatch(sr.getNextHopIp());
Prefix staticRoutePrefix = sr.getNetwork();
for (AbstractRoute matchingRoute : matchingRoutes) {
Prefix matchingRoutePrefix = matchingRoute.getNetwork();
// contain this static route's prefix
if (!matchingRoutePrefix.containsPrefix(staticRoutePrefix)) {
changed |= _mainRib.mergeRoute(sr);
// break out of the inner loop but continue processing static routes
break;
}
}
}
return changed;
}
use of org.batfish.datamodel.Prefix in project batfish by batfish.
the class VirtualRouter method isOspfInterAreaFromIntraAreaPropagationAllowed.
private static boolean isOspfInterAreaFromIntraAreaPropagationAllowed(long areaNum, Node neighbor, OspfInternalRoute neighborRoute, OspfArea neighborArea) {
long neighborRouteAreaNum = neighborRoute.getArea();
// May only propagate to or from area 0
if (areaNum == neighborRouteAreaNum || (areaNum != 0L && neighborRouteAreaNum != 0L)) {
return false;
}
Prefix neighborRouteNetwork = neighborRoute.getNetwork();
String neighborSummaryFilterName = neighborArea.getSummaryFilter();
boolean hasSummaryFilter = neighborSummaryFilterName != null;
boolean allowed = !hasSummaryFilter;
// If there is a summary filter, run the route through it
if (hasSummaryFilter) {
RouteFilterList neighborSummaryFilter = neighbor._c.getRouteFilterLists().get(neighborSummaryFilterName);
allowed = neighborSummaryFilter.permits(neighborRouteNetwork);
}
return allowed;
}
Aggregations