@Override protected Map<IpLink, OspfNeighbor> featureValueOf(OspfProcess actual) { return actual.getOspfNeighbors(); } }
/** Return an OSPF builder. Pre-defines required fields (e.g., reference bandwidth) */ public OspfProcess.Builder ospfProcessBuilder() { return OspfProcess.builder(this).setReferenceBandwidth(1e8); }
@Override protected Map<Long, OspfArea> featureValueOf(OspfProcess actual) { return actual.getAreas(); } }
if (ospf != null) { OspfProcess abstractOspf = OspfProcess.builder().setReferenceBandwidth(ospf.getReferenceBandwidth()).build(); abstractOspf.setAreas(ospf.getAreas()); abstractOspf.setExportPolicy(ospf.getExportPolicy()); abstractOspf.setRouterId(ospf.getRouterId()); if (ospf.getOspfNeighbors() != null) { for (Entry<IpLink, OspfNeighbor> entry2 : ospf.getOspfNeighbors().entrySet()) { IpLink link = entry2.getKey(); OspfNeighbor neighbor = entry2.getValue(); abstractOspf.setOspfNeighbors(abstractNeighbors); abstractVrf.setOspfProcess(abstractOspf);
private org.batfish.datamodel.ospf.OspfProcess toOspfProcess( OspfProcess proc, String vrfName, Configuration c, CiscoConfiguration oldConfig) { org.batfish.datamodel.ospf.OspfProcess newProcess = org.batfish.datamodel.ospf.OspfProcess.builder() .setReferenceBandwidth(proc.getReferenceBandwidth()) .build(); newProcess.setMaxMetricTransitLinks(OspfProcess.MAX_METRIC_ROUTER_LSA); if (proc.getMaxMetricIncludeStub()) { newProcess.setMaxMetricStubNetworks(OspfProcess.MAX_METRIC_ROUTER_LSA); newProcess.setMaxMetricExternalNetworks(proc.getMaxMetricExternalLsa()); newProcess.setMaxMetricSummaryNetworks(proc.getMaxMetricSummaryLsa()); newProcess.setProcessId(proc.getName()); newProcess.setRfc1583Compatible(proc.getRfc1583Compatible()); newProcess.setAreas(toImmutableSortedMap(areas, Entry::getKey, e -> e.getValue().build())); .getAreas() .values() .forEach( c.getRoutingPolicies().put(ospfExportPolicyName, ospfExportPolicy); List<Statement> ospfExportStatements = ospfExportPolicy.getStatements(); newProcess.setExportPolicy(ospfExportPolicyName); route.setAdmin(MAX_ADMINISTRATIVE_COST); route.setGenerationPolicy(defaultOriginateMapName);
private OspfProcess createOspfProcess(RoutingInstance routingInstance) { OspfProcess newProc = OspfProcess.builder() .setReferenceBandwidth(routingInstance.getOspfReferenceBandwidth()) .build(); applyLocalRoutePolicy(routingInstance, ospfExportPolicy); _c.getRoutingPolicies().put(ospfExportPolicyName, ospfExportPolicy); newProc.setExportPolicy(ospfExportPolicyName); If ospfExportPolicyConditional = new If(); newProc.setAreas( newAreaBuilders.entrySet().stream() .collect( .getAreas() .values() .forEach( .setOspfArea(area))); newProc.setRouterId(getOspfRouterId(routingInstance)); return newProc;
OspfProcess proc = vrf.getOspfProcess(); if (proc != null) { proc.setOspfNeighbors(new TreeMap<>()); String vrfName = e2.getKey(); for (Entry<Long, OspfArea> e3 : proc.getAreas().entrySet()) { long areaNum = e3.getKey(); OspfArea area = e3.getValue(); OspfProcess remoteProc = remoteVrf.getOspfProcess(); if (remoteProc != null) { if (remoteProc.getOspfNeighbors() == null) { remoteProc.setOspfNeighbors(new TreeMap<>()); OspfArea remoteArea = remoteProc.getAreas().get(areaNum); if (remoteArea != null && remoteArea.getInterfaces().contains(remoteIfaceName)) { Ip remoteIp = remoteIface.getAddress().getIp(); IpLink localKey = new IpLink(localIp, remoteIp); OspfNeighbor neighbor = proc.getOspfNeighbors().get(localKey); if (neighbor == null) { hasNeighbor = true; neighbor.setOwner(c); neighbor.setInterface(iface); proc.getOspfNeighbors().put(localKey, neighbor); remoteNeighbor.setOwner(remoteNode); remoteNeighbor.setInterface(remoteIface); remoteProc.getOspfNeighbors().put(remoteKey, remoteNeighbor);
@Test public void getProperties() { OspfProcess ospf1 = OspfProcess.builder().setReferenceBandwidth(1e8).build(); ospf1.setExportPolicy("my-policy"); ospf1.setReferenceBandwidth(42.0); ospf1.setProcessId("uber-proc");
@Nullable public static RoutingPolicy findCommonRoutingPolicy(Configuration conf, Protocol proto) { if (proto.isOspf()) { String exp = conf.getDefaultVrf().getOspfProcess().getExportPolicy(); return conf.getRoutingPolicies().get(exp); } if (proto.isBgp()) { for (Map.Entry<String, RoutingPolicy> entry : conf.getRoutingPolicies().entrySet()) { String name = entry.getKey(); if (name.contains(BGP_COMMON_FILTER_LIST_NAME)) { return entry.getValue(); } } return null; } if (proto.isStatic()) { return null; } if (proto.isConnected()) { return null; } throw new BatfishException("TODO: findCommonRoutingPolicy for " + proto.name()); }
proc.getAreas() .forEach( (areaNum, area) -> { boolean stubNetwork = iface.getOspfPassive() || iface.getOspfPointToPoint(); if (stubNetwork) { if (proc.getMaxMetricStubNetworks() != null) { cost = proc.getMaxMetricStubNetworks(); } else if (proc.getMaxMetricTransitLinks() != null) { cost = proc.getMaxMetricTransitLinks();
if (!neighborProc.isAreaBorderRouter()) { return false; neighborProc.getAreas().get(neighborRouteAreaNum).getSummaryFilter(); boolean hasSummaryFilter = neighborSummaryFilterName != null; boolean allowed = !hasSummaryFilter;
public void computeRoutingPolicySources(Warnings w) { for (String rpName : _routingPolicies.keySet()) { computeRoutingPolicySources(rpName, w); } for (Vrf vrf : _vrfs.values()) { BgpProcess bgpProcess = vrf.getBgpProcess(); if (bgpProcess != null) { for (BgpPeerConfig neighbor : Iterables.concat( bgpProcess.getActiveNeighbors().values(), bgpProcess.getPassiveNeighbors().values())) { neighbor.setExportPolicySources(getRoutingPolicySources(neighbor.getExportPolicy())); neighbor.setImportPolicySources(getRoutingPolicySources(neighbor.getImportPolicy())); } } OspfProcess ospfProcess = vrf.getOspfProcess(); if (ospfProcess != null) { ospfProcess.setExportPolicySources(getRoutingPolicySources(ospfProcess.getExportPolicy())); } for (GeneratedRoute gr : vrf.getGeneratedRoutes()) { gr.setAttributePolicySources(getRoutingPolicySources(gr.getAttributePolicy())); gr.setGenerationPolicySources(getRoutingPolicySources(gr.getGenerationPolicy())); } } }
boolean useMin = firstNonNull(proc.getRfc1583Compatible(), Boolean.TRUE); for (Entry<Long, OspfArea> e : proc.getAreas().entrySet()) { long areaNum = e.getKey(); OspfArea area = e.getValue();
RoutingPolicy ospfExportPolicy = c.getRoutingPolicies().computeIfAbsent(ospfExportPolicyName, n -> new RoutingPolicy(n, c)); ospfProcess.setExportPolicy(ospfExportPolicyName); ospfExportPolicy .getStatements() ospfProcess.getExportPolicySources(), containsInAnyOrder(ospfExportPolicyName, ospfExportSubPolicyName));
public int computeInterfaceCost(Interface i) { return computeInterfaceCost(_referenceBandwidth, i); }
private void postProcessOspfCosts(Map<String, Configuration> configurations) { configurations .values() .forEach( c -> c.getVrfs() .values() .forEach( vrf -> { // Compute OSPF interface costs where they are missing OspfProcess proc = vrf.getOspfProcess(); if (proc != null) { proc.initInterfaceCosts(c); } })); }
@Override protected Ip featureValueOf(OspfProcess actual) { return actual.getRouterId(); } }
@Override protected Double featureValueOf(OspfProcess actual) { return actual.getReferenceBandwidth(); } }
@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()) { BgpPeerConfig 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()); }
/** 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))); }