use of org.batfish.datamodel.Interface 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;
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class VirtualRouter method initConnectedRib.
/**
* Initialize the connected RIB -- a RIB containing connected routes (i.e., direct connections to
* neighbors).
*/
@VisibleForTesting
void initConnectedRib() {
// Look at all connected interfaces
for (Interface i : _vrf.getInterfaces().values()) {
if (i.getActive()) {
// Create a route for each interface prefix
for (InterfaceAddress ifaceAddress : i.getAllAddresses()) {
Prefix prefix = ifaceAddress.getPrefix();
ConnectedRoute cr = new ConnectedRoute(prefix, i.getName());
_connectedRib.mergeRoute(cr);
}
}
}
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class BdpEngine method processCurrentNextHopInterfaceEdges.
private boolean processCurrentNextHopInterfaceEdges(BdpDataPlane dp, String currentNodeName, Set<Edge> visitedEdges, List<FlowTraceHop> hopsSoFar, Set<FlowTrace> flowTraces, Flow originalFlow, Flow transformedFlow, Ip dstIp, Set<String> dstIpOwners, @Nullable String nextHopInterfaceName, SortedSet<String> routesForThisNextHopInterface, @Nullable Ip finalNextHopIp, @Nullable NodeInterfacePair nextHopInterface, SortedSet<Edge> edges, boolean arp) {
boolean continueToNextNextHopInterface = false;
int unreachableNeighbors = 0;
int potentialNeighbors = 0;
for (Edge edge : edges) {
if (!edge.getNode1().equals(currentNodeName)) {
continue;
}
potentialNeighbors++;
List<FlowTraceHop> newHops = new ArrayList<>(hopsSoFar);
Set<Edge> newVisitedEdges = new LinkedHashSet<>(visitedEdges);
FlowTraceHop newHop = new FlowTraceHop(edge, routesForThisNextHopInterface, hopFlow(originalFlow, transformedFlow));
newVisitedEdges.add(edge);
newHops.add(newHop);
/*
* Check to see whether neighbor would refrain from sending ARP reply
* (NEIGHBOR_UNREACHABLE)
*
* This occurs if:
*
* - Using interface-only route
*
* AND
*
* - Neighbor does not own arpIp
*
* AND EITHER
*
* -- Neighbor not using proxy-arp
*
* - OR
*
* -- Subnet of neighbor's receiving-interface contains arpIp
*/
if (arp) {
Ip arpIp;
Set<String> arpIpOwners;
if (finalNextHopIp == null) {
arpIp = dstIp;
arpIpOwners = dstIpOwners;
} else {
arpIp = finalNextHopIp;
arpIpOwners = dp._ipOwners.get(arpIp);
}
// using interface-only route
String node2 = edge.getNode2();
if (arpIpOwners == null || !arpIpOwners.contains(node2)) {
// neighbor does not own arpIp
String int2Name = edge.getInt2();
Interface int2 = dp._nodes.get(node2)._c.getInterfaces().get(int2Name);
boolean neighborUnreachable = false;
Boolean proxyArp = int2.getProxyArp();
if (proxyArp == null || !proxyArp) {
// TODO: proxyArp probably shouldn't be null
neighborUnreachable = true;
} else {
for (InterfaceAddress address : int2.getAllAddresses()) {
if (address.getPrefix().containsIp(arpIp)) {
neighborUnreachable = true;
break;
}
}
}
if (neighborUnreachable) {
unreachableNeighbors++;
continue;
}
}
}
if (visitedEdges.contains(edge)) {
FlowTrace trace = new FlowTrace(FlowDisposition.LOOP, newHops, FlowDisposition.LOOP.toString());
flowTraces.add(trace);
potentialNeighbors--;
continue;
}
String nextNodeName = edge.getNode2();
// now check output filter and input filter
if (nextHopInterfaceName != null) {
IpAccessList outFilter = dp._nodes.get(currentNodeName)._c.getInterfaces().get(nextHopInterfaceName).getOutgoingFilter();
if (outFilter != null) {
FlowDisposition disposition = FlowDisposition.DENIED_OUT;
boolean denied = flowTraceDeniedHelper(flowTraces, originalFlow, transformedFlow, newHops, outFilter, disposition);
if (denied) {
potentialNeighbors--;
continue;
}
}
}
IpAccessList inFilter = dp._nodes.get(nextNodeName)._c.getInterfaces().get(edge.getInt2()).getIncomingFilter();
if (inFilter != null) {
FlowDisposition disposition = FlowDisposition.DENIED_IN;
boolean denied = flowTraceDeniedHelper(flowTraces, originalFlow, transformedFlow, newHops, inFilter, disposition);
if (denied) {
potentialNeighbors--;
continue;
}
}
// recurse
collectFlowTraces(dp, nextNodeName, newVisitedEdges, newHops, flowTraces, originalFlow, transformedFlow);
}
if (arp && unreachableNeighbors > 0 && unreachableNeighbors == potentialNeighbors) {
FlowTrace trace = neighborUnreachableTrace(hopsSoFar, nextHopInterface, routesForThisNextHopInterface, originalFlow, transformedFlow);
flowTraces.add(trace);
continueToNextNextHopInterface = true;
}
return continueToNextNextHopInterface;
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class InterfacesSpecifierTest method matchesName.
@Test
public void matchesName() {
InterfacesSpecifier specifier = new InterfacesSpecifier("name:Loopback.*");
Interface loopbackInterface = new Interface("Loopback0");
Interface nonLoopbackInterface = new Interface("Ethetnet0/0");
assertThat(specifier.matches(loopbackInterface), equalTo(true));
assertThat(specifier.matches(nonLoopbackInterface), equalTo(false));
}
use of org.batfish.datamodel.Interface in project batfish by batfish.
the class Batfish method initRemoteRipNeighbors.
@Override
public void initRemoteRipNeighbors(Map<String, Configuration> configurations, Map<Ip, Set<String>> ipOwners, Topology topology) {
for (Entry<String, Configuration> e : configurations.entrySet()) {
String hostname = e.getKey();
Configuration c = e.getValue();
for (Entry<String, Vrf> e2 : c.getVrfs().entrySet()) {
Vrf vrf = e2.getValue();
RipProcess proc = vrf.getRipProcess();
if (proc != null) {
proc.setRipNeighbors(new TreeMap<>());
String vrfName = e2.getKey();
for (String ifaceName : proc.getInterfaces()) {
Interface iface = vrf.getInterfaces().get("ifaceName");
SortedSet<Edge> ifaceEdges = topology.getInterfaceEdges().get(new NodeInterfacePair(hostname, ifaceName));
boolean hasNeighbor = false;
Ip localIp = iface.getAddress().getIp();
if (ifaceEdges != null) {
for (Edge edge : ifaceEdges) {
if (edge.getNode1().equals(hostname)) {
String remoteHostname = edge.getNode2();
String remoteIfaceName = edge.getInt2();
Configuration remoteNode = configurations.get(remoteHostname);
Interface remoteIface = remoteNode.getInterfaces().get(remoteIfaceName);
Vrf remoteVrf = remoteIface.getVrf();
String remoteVrfName = remoteVrf.getName();
RipProcess remoteProc = remoteVrf.getRipProcess();
if (remoteProc != null) {
if (remoteProc.getRipNeighbors() == null) {
remoteProc.setRipNeighbors(new TreeMap<>());
}
if (remoteProc.getInterfaces().contains(remoteIfaceName)) {
Ip remoteIp = remoteIface.getAddress().getIp();
Pair<Ip, Ip> localKey = new Pair<>(localIp, remoteIp);
RipNeighbor neighbor = proc.getRipNeighbors().get(localKey);
if (neighbor == null) {
hasNeighbor = true;
// initialize local neighbor
neighbor = new RipNeighbor(localKey);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getRipNeighbors().put(localKey, neighbor);
// initialize remote neighbor
Pair<Ip, Ip> remoteKey = new Pair<>(remoteIp, localIp);
RipNeighbor remoteNeighbor = new RipNeighbor(remoteKey);
remoteNeighbor.setVrf(remoteVrfName);
remoteNeighbor.setOwner(remoteNode);
remoteNeighbor.setInterface(remoteIface);
remoteProc.getRipNeighbors().put(remoteKey, remoteNeighbor);
// link neighbors
neighbor.setRemoteRipNeighbor(remoteNeighbor);
remoteNeighbor.setRemoteRipNeighbor(neighbor);
}
}
}
}
}
}
if (!hasNeighbor) {
Pair<Ip, Ip> key = new Pair<>(localIp, Ip.ZERO);
RipNeighbor neighbor = new RipNeighbor(key);
neighbor.setVrf(vrfName);
neighbor.setOwner(c);
neighbor.setInterface(iface);
proc.getRipNeighbors().put(key, neighbor);
}
}
}
}
}
}
Aggregations