use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class VirtualRouter method propagateOspfInternalRoutes.
/**
* Propagate OSPF internal routes from every valid OSPF neighbor
*
* @param nodes mapping of node names to instances.
* @param topology network topology
* @return true if new routes have been added to the staging RIB
*/
boolean propagateOspfInternalRoutes(Map<String, Node> nodes, Topology topology) {
OspfProcess proc = _vrf.getOspfProcess();
if (proc == null) {
// nothing to do
return false;
}
boolean changed = false;
String node = _c.getHostname();
// Default OSPF admin cost for constructing new routes
int adminCost = RoutingProtocol.OSPF.getDefaultAdministrativeCost(_c.getConfigurationFormat());
SortedSet<Edge> edges = topology.getNodeEdges().get(node);
if (edges == null) {
// there are no edges, so OSPF won't produce anything
return false;
}
for (Edge edge : edges) {
if (!edge.getNode1().equals(node)) {
continue;
}
String connectingInterfaceName = edge.getInt1();
Interface connectingInterface = _vrf.getInterfaces().get(connectingInterfaceName);
if (connectingInterface == null) {
// wrong vrf, so skip
continue;
}
String neighborName = edge.getNode2();
Node neighbor = nodes.get(neighborName);
Interface neighborInterface = neighbor._c.getInterfaces().get(edge.getInt2());
changed |= propagateOspfInternalRoutesFromNeighbor(proc, neighbor, connectingInterface, neighborInterface, adminCost);
}
return changed;
}
use of org.batfish.datamodel.OspfProcess 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.OspfProcess in project batfish by batfish.
the class Graph method initAreaIds.
/*
* Initialize each routers set of area IDs for OSPF
*/
private void initAreaIds() {
for (Entry<String, Configuration> entry : _configurations.entrySet()) {
String router = entry.getKey();
Configuration conf = entry.getValue();
Set<Long> areaIds = new HashSet<>();
OspfProcess p = conf.getDefaultVrf().getOspfProcess();
if (p != null) {
p.getAreas().forEach((id, area) -> areaIds.add(id));
}
_areaIds.put(router, areaIds);
}
}
use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class Graph method getOriginatedNetworks.
/*
* Collects and returns all originated prefixes for the given
* router as well as the protocol. Static routes and connected
* routes are treated as originating the prefix.
*/
public static Set<Prefix> getOriginatedNetworks(Configuration conf, Protocol proto) {
Set<Prefix> acc = new HashSet<>();
if (proto.isOspf()) {
OspfProcess ospf = conf.getDefaultVrf().getOspfProcess();
for (OspfArea area : ospf.getAreas().values()) {
for (String ifaceName : area.getInterfaces()) {
Interface iface = conf.getInterfaces().get(ifaceName);
if (iface.getActive() && iface.getOspfEnabled()) {
acc.add(iface.getAddress().getPrefix());
}
}
}
return acc;
}
if (proto.isBgp()) {
RoutingPolicy defaultPol = findCommonRoutingPolicy(conf, Protocol.BGP);
if (defaultPol != null) {
AstVisitor v = new AstVisitor();
v.visit(conf, defaultPol.getStatements(), stmt -> {
}, expr -> {
if (expr instanceof Conjunction) {
Conjunction c = (Conjunction) expr;
if (c.getConjuncts().size() >= 2) {
BooleanExpr be1 = c.getConjuncts().get(0);
BooleanExpr be2 = c.getConjuncts().get(1);
if (be1 instanceof MatchPrefixSet && be2 instanceof Not) {
MatchPrefixSet mps = (MatchPrefixSet) be1;
Not n = (Not) be2;
if (n.getExpr() instanceof MatchProtocol) {
MatchProtocol mp = (MatchProtocol) n.getExpr();
if (mp.getProtocol() == RoutingProtocol.BGP) {
PrefixSetExpr e = mps.getPrefixSet();
if (e instanceof ExplicitPrefixSet) {
ExplicitPrefixSet eps = (ExplicitPrefixSet) e;
Set<PrefixRange> ranges = eps.getPrefixSpace().getPrefixRanges();
for (PrefixRange r : ranges) {
acc.add(r.getPrefix());
}
}
}
}
}
}
}
});
}
return acc;
}
if (proto.isConnected()) {
for (Interface iface : conf.getInterfaces().values()) {
InterfaceAddress address = iface.getAddress();
if (address != null) {
acc.add(address.getPrefix());
}
}
return acc;
}
if (proto.isStatic()) {
for (StaticRoute sr : conf.getDefaultVrf().getStaticRoutes()) {
if (sr.getNetwork() != null) {
acc.add(sr.getNetwork());
}
}
return acc;
}
throw new BatfishException("ERROR: getOriginatedNetworks: " + proto.name());
}
use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class Graph method findExportRoutingPolicy.
/*
* Find the export routing policy for a given edge
*/
@Nullable
public RoutingPolicy findExportRoutingPolicy(String router, Protocol proto, GraphEdge ge) {
Configuration conf = _configurations.get(router);
if (proto.isConnected()) {
return null;
}
if (proto.isStatic()) {
return null;
}
if (proto.isOspf()) {
OspfProcess p = conf.getDefaultVrf().getOspfProcess();
if (p == null) {
return null;
}
String exp = p.getExportPolicy();
return conf.getRoutingPolicies().get(exp);
}
if (proto.isBgp()) {
BgpNeighbor n = findBgpNeighbor(ge);
// if no neighbor (e.g., loopback), or no export policy
if (n == null || n.getExportPolicy() == null) {
return null;
}
return conf.getRoutingPolicies().get(n.getExportPolicy());
}
throw new BatfishException("TODO: findExportRoutingPolicy for " + proto.name());
}
Aggregations