use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class AbstractionBuilder method createAbstractConfig.
/*
* Creates a new Configuration from an old one for an abstract router
* by copying the old configuration, but removing any concrete interfaces,
* neighbors etc that do not correpond to any abstract neighbors.
*/
private Configuration createAbstractConfig(Set<String> abstractRouters, Configuration conf) {
Configuration abstractConf = new Configuration(conf.getHostname(), conf.getConfigurationFormat());
abstractConf.setDnsServers(conf.getDnsServers());
abstractConf.setDnsSourceInterface(conf.getDnsSourceInterface());
abstractConf.setDomainName(conf.getDomainName());
abstractConf.setAuthenticationKeyChains(conf.getAuthenticationKeyChains());
abstractConf.setIkeGateways(conf.getIkeGateways());
abstractConf.setDefaultCrossZoneAction(conf.getDefaultCrossZoneAction());
abstractConf.setIkePolicies(conf.getIkePolicies());
abstractConf.setIkeProposals(conf.getIkeProposals());
abstractConf.setDefaultInboundAction(conf.getDefaultInboundAction());
abstractConf.setIpAccessLists(conf.getIpAccessLists());
abstractConf.setIp6AccessLists(conf.getIp6AccessLists());
abstractConf.setRouteFilterLists(conf.getRouteFilterLists());
abstractConf.setRoute6FilterLists(conf.getRoute6FilterLists());
abstractConf.setIpsecPolicies(conf.getIpsecPolicies());
abstractConf.setIpsecProposals(conf.getIpsecProposals());
abstractConf.setIpsecVpns(conf.getIpsecVpns());
abstractConf.setLoggingServers(conf.getLoggingServers());
abstractConf.setLoggingSourceInterface(conf.getLoggingSourceInterface());
abstractConf.setNormalVlanRange(conf.getNormalVlanRange());
abstractConf.setNtpServers(conf.getNtpServers());
abstractConf.setNtpSourceInterface(conf.getNtpSourceInterface());
abstractConf.setRoles(conf.getRoles());
abstractConf.setSnmpSourceInterface(conf.getSnmpSourceInterface());
abstractConf.setSnmpTrapServers(conf.getSnmpTrapServers());
abstractConf.setTacacsServers(conf.getTacacsServers());
abstractConf.setTacacsSourceInterface(conf.getTacacsSourceInterface());
abstractConf.setVendorFamily(conf.getVendorFamily());
abstractConf.setZones(conf.getZones());
abstractConf.setCommunityLists(conf.getCommunityLists());
abstractConf.setRoutingPolicies(conf.getRoutingPolicies());
abstractConf.setRoute6FilterLists(conf.getRoute6FilterLists());
SortedSet<Interface> toRetain = new TreeSet<>();
SortedSet<IpLink> ipNeighbors = new TreeSet<>();
SortedSet<BgpNeighbor> bgpNeighbors = new TreeSet<>();
List<GraphEdge> edges = _graph.getEdgeMap().get(conf.getName());
for (GraphEdge ge : edges) {
boolean leavesNetwork = (ge.getPeer() == null);
if (leavesNetwork || (abstractRouters.contains(ge.getRouter()) && abstractRouters.contains(ge.getPeer()))) {
toRetain.add(ge.getStart());
Ip start = ge.getStart().getAddress().getIp();
if (!leavesNetwork) {
Ip end = ge.getEnd().getAddress().getIp();
ipNeighbors.add(new IpLink(start, end));
}
BgpNeighbor n = _graph.getEbgpNeighbors().get(ge);
if (n != null) {
bgpNeighbors.add(n);
}
}
}
// Update interfaces
NavigableMap<String, Interface> abstractInterfaces = new TreeMap<>();
for (Entry<String, Interface> entry : conf.getInterfaces().entrySet()) {
String name = entry.getKey();
Interface iface = entry.getValue();
if (toRetain.contains(iface)) {
abstractInterfaces.put(name, iface);
}
}
abstractConf.setInterfaces(abstractInterfaces);
// Update VRFs
Map<String, Vrf> abstractVrfs = new HashMap<>();
for (Entry<String, Vrf> entry : conf.getVrfs().entrySet()) {
String name = entry.getKey();
Vrf vrf = entry.getValue();
Vrf abstractVrf = new Vrf(name);
abstractVrf.setStaticRoutes(vrf.getStaticRoutes());
abstractVrf.setIsisProcess(vrf.getIsisProcess());
abstractVrf.setRipProcess(vrf.getRipProcess());
abstractVrf.setSnmpServer(vrf.getSnmpServer());
NavigableMap<String, Interface> abstractVrfInterfaces = new TreeMap<>();
for (Entry<String, Interface> entry2 : vrf.getInterfaces().entrySet()) {
String iname = entry2.getKey();
Interface iface = entry2.getValue();
if (toRetain.contains(iface)) {
abstractVrfInterfaces.put(iname, iface);
}
}
abstractVrf.setInterfaces(abstractVrfInterfaces);
abstractVrf.setInterfaceNames(new TreeSet<>(abstractVrfInterfaces.keySet()));
OspfProcess ospf = vrf.getOspfProcess();
if (ospf != null) {
OspfProcess abstractOspf = new OspfProcess();
abstractOspf.setAreas(ospf.getAreas());
abstractOspf.setExportPolicy(ospf.getExportPolicy());
abstractOspf.setReferenceBandwidth(ospf.getReferenceBandwidth());
abstractOspf.setRouterId(ospf.getRouterId());
// Copy over neighbors
Map<IpLink, OspfNeighbor> abstractNeighbors = new HashMap<>();
if (ospf.getOspfNeighbors() != null) {
for (Entry<IpLink, OspfNeighbor> entry2 : ospf.getOspfNeighbors().entrySet()) {
IpLink link = entry2.getKey();
OspfNeighbor neighbor = entry2.getValue();
if (ipNeighbors.contains(link)) {
abstractNeighbors.put(link, neighbor);
}
}
}
abstractOspf.setOspfNeighbors(abstractNeighbors);
abstractVrf.setOspfProcess(abstractOspf);
}
BgpProcess bgp = vrf.getBgpProcess();
if (bgp != null) {
BgpProcess abstractBgp = new BgpProcess();
abstractBgp.setMultipathEbgp(bgp.getMultipathEbgp());
abstractBgp.setMultipathIbgp(bgp.getMultipathIbgp());
abstractBgp.setRouterId(bgp.getRouterId());
abstractBgp.setOriginationSpace(bgp.getOriginationSpace());
// TODO: set bgp neighbors accordingly
// Copy over neighbors
SortedMap<Prefix, BgpNeighbor> abstractBgpNeighbors = new TreeMap<>();
if (bgp.getNeighbors() != null) {
for (Entry<Prefix, BgpNeighbor> entry2 : bgp.getNeighbors().entrySet()) {
Prefix prefix = entry2.getKey();
BgpNeighbor neighbor = entry2.getValue();
if (bgpNeighbors.contains(neighbor)) {
abstractBgpNeighbors.put(prefix, neighbor);
}
}
}
abstractBgp.setNeighbors(abstractBgpNeighbors);
abstractVrf.setBgpProcess(abstractBgp);
}
abstractVrfs.put(name, abstractVrf);
}
abstractConf.setVrfs(abstractVrfs);
return abstractConf;
}
use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class JuniperConfiguration method createOspfProcess.
private OspfProcess createOspfProcess(RoutingInstance routingInstance) {
OspfProcess newProc = new OspfProcess();
String vrfName = routingInstance.getName();
// export policies
String ospfExportPolicyName = "~OSPF_EXPORT_POLICY:" + vrfName + "~";
RoutingPolicy ospfExportPolicy = new RoutingPolicy(ospfExportPolicyName, _c);
_c.getRoutingPolicies().put(ospfExportPolicyName, ospfExportPolicy);
newProc.setExportPolicy(ospfExportPolicyName);
If ospfExportPolicyConditional = new If();
// TODO: set default metric-type for special cases based on ospf process
// setttings
ospfExportPolicy.getStatements().add(new SetOspfMetricType(OspfMetricType.E2));
ospfExportPolicy.getStatements().add(ospfExportPolicyConditional);
Disjunction matchSomeExportPolicy = new Disjunction();
ospfExportPolicyConditional.setGuard(matchSomeExportPolicy);
ospfExportPolicyConditional.getTrueStatements().add(Statements.ExitAccept.toStaticStatement());
ospfExportPolicyConditional.getFalseStatements().add(Statements.ExitReject.toStaticStatement());
routingInstance.getOspfExportPolicies().forEach((exportPolicyName, exportPolicyLine) -> {
PolicyStatement exportPolicy = _policyStatements.get(exportPolicyName);
if (exportPolicy == null) {
undefined(JuniperStructureType.POLICY_STATEMENT, exportPolicyName, JuniperStructureUsage.OSPF_EXPORT_POLICY, exportPolicyLine);
} else {
setPolicyStatementReferent(exportPolicyName, routingInstance.getOspfExportPolicies(), "OSPF export policies");
CallExpr callPolicy = new CallExpr(exportPolicyName);
matchSomeExportPolicy.getDisjuncts().add(callPolicy);
}
});
// areas
Map<Long, OspfArea> newAreas = newProc.getAreas();
newAreas.putAll(routingInstance.getOspfAreas());
// place interfaces into areas
for (Entry<String, Interface> e : routingInstance.getInterfaces().entrySet()) {
String name = e.getKey();
Interface iface = e.getValue();
placeInterfaceIntoArea(newAreas, name, iface, vrfName);
}
newProc.setRouterId(routingInstance.getRouterId());
newProc.setReferenceBandwidth(routingInstance.getOspfReferenceBandwidth());
return newProc;
}
use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class CiscoGrammarTest method testOspfMaxMetric.
@Test
public void testOspfMaxMetric() throws IOException {
String testrigName = "ospf-max-metric";
String iosMaxMetricName = "ios-max-metric";
String iosMaxMetricCustomName = "ios-max-metric-custom";
String iosMaxMetricOnStartupName = "ios-max-metric-on-startup";
List<String> configurationNames = ImmutableList.of(iosMaxMetricName, iosMaxMetricCustomName, iosMaxMetricOnStartupName);
Batfish batfish = BatfishTestUtils.getBatfishFromTestrigText(TestrigText.builder().setConfigurationText(TESTRIGS_PREFIX + testrigName, configurationNames).build(), _folder);
Map<String, Configuration> configurations = batfish.loadConfigurations();
Configuration iosMaxMetric = configurations.get(iosMaxMetricName);
Configuration iosMaxMetricCustom = configurations.get(iosMaxMetricCustomName);
Configuration iosMaxMetricOnStartup = configurations.get(iosMaxMetricOnStartupName);
OspfProcess proc = iosMaxMetric.getDefaultVrf().getOspfProcess();
OspfProcess procCustom = iosMaxMetricCustom.getDefaultVrf().getOspfProcess();
OspfProcess procOnStartup = iosMaxMetricOnStartup.getDefaultVrf().getOspfProcess();
long expectedMaxMetricRouterLsa = org.batfish.representation.cisco.OspfProcess.MAX_METRIC_ROUTER_LSA;
long expectedMaxMetricStub = org.batfish.representation.cisco.OspfProcess.MAX_METRIC_ROUTER_LSA;
long expectedMaxMetricExternal = org.batfish.representation.cisco.OspfProcess.DEFAULT_MAX_METRIC_EXTERNAL_LSA;
long expectedMaxMetricSummary = org.batfish.representation.cisco.OspfProcess.DEFAULT_MAX_METRIC_SUMMARY_LSA;
long expectedCustomMaxMetricExternal = 12345L;
long expectedCustomMaxMetricSummary = 23456L;
assertThat(proc.getMaxMetricTransitLinks(), equalTo(expectedMaxMetricRouterLsa));
assertThat(proc.getMaxMetricStubNetworks(), equalTo(expectedMaxMetricStub));
assertThat(proc.getMaxMetricExternalNetworks(), equalTo(expectedMaxMetricExternal));
assertThat(proc.getMaxMetricSummaryNetworks(), equalTo(expectedMaxMetricSummary));
assertThat(procCustom.getMaxMetricTransitLinks(), equalTo(expectedMaxMetricRouterLsa));
assertThat(procCustom.getMaxMetricStubNetworks(), equalTo(expectedMaxMetricStub));
assertThat(procCustom.getMaxMetricExternalNetworks(), equalTo(expectedCustomMaxMetricExternal));
assertThat(procCustom.getMaxMetricSummaryNetworks(), equalTo(expectedCustomMaxMetricSummary));
assertThat(procOnStartup.getMaxMetricTransitLinks(), is(nullValue()));
assertThat(procOnStartup.getMaxMetricStubNetworks(), is(nullValue()));
assertThat(procOnStartup.getMaxMetricExternalNetworks(), is(nullValue()));
assertThat(procOnStartup.getMaxMetricSummaryNetworks(), is(nullValue()));
}
use of org.batfish.datamodel.OspfProcess 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;
}
use of org.batfish.datamodel.OspfProcess in project batfish by batfish.
the class VirtualRouter method propagateOspfExternalRoutes.
public boolean propagateOspfExternalRoutes(Map<String, Node> nodes, Topology topology) {
boolean changed = false;
String node = _c.getHostname();
OspfProcess proc = _vrf.getOspfProcess();
if (proc != null) {
int admin = 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);
String neighborInterfaceName = edge.getInt2();
OspfArea area = connectingInterface.getOspfArea();
Configuration nc = neighbor._c;
Interface neighborInterface = nc.getInterfaces().get(neighborInterfaceName);
String neighborVrfName = neighborInterface.getVrfName();
VirtualRouter neighborVirtualRouter = nodes.get(neighborName)._virtualRouters.get(neighborVrfName);
OspfArea neighborArea = neighborInterface.getOspfArea();
if (connectingInterface.getOspfEnabled() && !connectingInterface.getOspfPassive() && neighborInterface.getOspfEnabled() && !neighborInterface.getOspfPassive() && area != null && neighborArea != null && area.getName().equals(neighborArea.getName())) {
/*
* We have an ospf neighbor relationship on this edge. So we
* should add all ospf external type 1(2) routes from this
* neighbor into our ospf external type 1(2) staging rib. For
* type 1, the cost of the route increases each time. For type 2,
* the cost remains constant, but we must keep track of cost to
* advertiser as a tie-breaker.
*/
long connectingInterfaceCost = connectingInterface.getOspfCost();
long incrementalCost = proc.getMaxMetricTransitLinks() != null ? proc.getMaxMetricTransitLinks() : connectingInterfaceCost;
for (OspfExternalType1Route neighborRoute : neighborVirtualRouter._prevOspfExternalType1Rib.getRoutes()) {
long oldArea = neighborRoute.getArea();
long connectionArea = area.getName();
long newArea;
long baseMetric = neighborRoute.getMetric();
long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
newArea = connectionArea;
if (oldArea != OspfRoute.NO_AREA) {
Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
if (connectionArea != oldArea) {
if (connectionArea != 0L && oldArea != 0L) {
continue;
}
if (maxMetricSummaryNetworks != null) {
baseMetric = maxMetricSummaryNetworks + neighborRoute.getLsaMetric();
baseCostToAdvertiser = maxMetricSummaryNetworks;
}
}
}
long newMetric = baseMetric + incrementalCost;
long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
OspfExternalType1Route newRoute = new OspfExternalType1Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, newMetric, neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
if (_ospfExternalType1StagingRib.mergeRoute(newRoute)) {
changed = true;
}
}
for (OspfExternalType2Route neighborRoute : neighborVirtualRouter._prevOspfExternalType2Rib.getRoutes()) {
long oldArea = neighborRoute.getArea();
long connectionArea = area.getName();
long newArea;
long baseCostToAdvertiser = neighborRoute.getCostToAdvertiser();
if (oldArea == OspfRoute.NO_AREA) {
newArea = connectionArea;
} else {
newArea = oldArea;
Long maxMetricSummaryNetworks = neighborVirtualRouter._vrf.getOspfProcess().getMaxMetricSummaryNetworks();
if (connectionArea != oldArea && maxMetricSummaryNetworks != null) {
baseCostToAdvertiser = maxMetricSummaryNetworks;
}
}
long newCostToAdvertiser = baseCostToAdvertiser + incrementalCost;
OspfExternalType2Route newRoute = new OspfExternalType2Route(neighborRoute.getNetwork(), neighborInterface.getAddress().getIp(), admin, neighborRoute.getMetric(), neighborRoute.getLsaMetric(), newArea, newCostToAdvertiser, neighborRoute.getAdvertiser());
if (_ospfExternalType2StagingRib.mergeRoute(newRoute)) {
changed = true;
}
}
}
}
}
return changed;
}
Aggregations