use of org.batfish.datamodel.Ip in project batfish by batfish.
the class SelfNextHop method getNextHopIp.
@Override
public Ip getNextHopIp(Environment environment) {
// TODO: make work for dynamic sessions
Prefix prefix = new Prefix(environment.getPeerAddress(), Prefix.MAX_PREFIX_LENGTH);
BgpNeighbor neighbor = environment.getVrf().getBgpProcess().getNeighbors().get(prefix);
Ip localIp = neighbor.getLocalIp();
return localIp;
}
use of org.batfish.datamodel.Ip in project batfish by batfish.
the class AbstractRib method nextHopIpsByPrefix.
@Override
public final Map<Prefix, Set<Ip>> nextHopIpsByPrefix() {
Map<Prefix, Set<Ip>> map = new TreeMap<>();
for (AbstractRoute route : getRoutes()) {
Prefix prefix = route.getNetwork();
Ip nextHopIp = route.getNextHopIp();
Set<Ip> nextHopIps = map.computeIfAbsent(prefix, k -> new TreeSet<>());
nextHopIps.add(nextHopIp);
}
return map;
}
use of org.batfish.datamodel.Ip in project batfish by batfish.
the class BdpEngine method processFlows.
@Override
public SortedMap<Flow, Set<FlowTrace>> processFlows(DataPlane dataPlane, Set<Flow> flows) {
Map<Flow, Set<FlowTrace>> flowTraces = new ConcurrentHashMap<>();
BdpDataPlane dp = (BdpDataPlane) dataPlane;
flows.parallelStream().forEach(flow -> {
Set<FlowTrace> currentFlowTraces = new TreeSet<>();
flowTraces.put(flow, currentFlowTraces);
String ingressNodeName = flow.getIngressNode();
if (ingressNodeName == null) {
throw new BatfishException("Cannot construct flow trace since ingressNode is not specified");
}
Ip dstIp = flow.getDstIp();
if (dstIp == null) {
throw new BatfishException("Cannot construct flow trace since dstIp is not specified");
}
Set<Edge> visitedEdges = Collections.emptySet();
List<FlowTraceHop> hops = new ArrayList<>();
Set<String> dstIpOwners = dp._ipOwners.get(dstIp);
SortedSet<Edge> edges = new TreeSet<>();
String ingressInterfaceName = flow.getIngressInterface();
if (ingressInterfaceName != null) {
edges.add(new Edge(TRACEROUTE_INGRESS_NODE_NAME, TRACEROUTE_INGRESS_NODE_INTERFACE_NAME, ingressNodeName, ingressInterfaceName));
processCurrentNextHopInterfaceEdges(dp, TRACEROUTE_INGRESS_NODE_NAME, visitedEdges, hops, currentFlowTraces, flow, flow, dstIp, dstIpOwners, null, new TreeSet<>(), null, null, edges, false);
} else {
collectFlowTraces(dp, ingressNodeName, visitedEdges, hops, currentFlowTraces, flow, flow);
}
});
return new TreeMap<>(flowTraces);
}
use of org.batfish.datamodel.Ip in project batfish by batfish.
the class BdpEngine method computeOutputAbstractRoutes.
private SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> computeOutputAbstractRoutes(Map<String, Node> nodes, Map<Ip, String> ipOwners) {
SortedMap<String, SortedMap<String, SortedSet<AbstractRoute>>> outputRoutes = new TreeMap<>();
nodes.forEach((hostname, node) -> {
SortedMap<String, SortedSet<AbstractRoute>> routesByVrf = new TreeMap<>();
outputRoutes.put(hostname, routesByVrf);
node._virtualRouters.forEach((vrName, vr) -> {
SortedSet<AbstractRoute> routes = new TreeSet<>();
routes.addAll(vr._mainRib.getRoutes());
for (AbstractRoute route : routes) {
route.setNode(hostname);
route.setVrf(vrName);
Ip nextHopIp = route.getNextHopIp();
if (route.getProtocol() == RoutingProtocol.CONNECTED || (route.getProtocol() == RoutingProtocol.STATIC && nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) || Interface.NULL_INTERFACE_NAME.equals(route.getNextHopInterface())) {
route.setNextHop(Configuration.NODE_NONE_NAME);
}
if (!nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) {
String nextHop = ipOwners.get(nextHopIp);
if (nextHop != null) {
route.setNextHop(nextHop);
}
}
}
routesByVrf.put(vrName, routes);
});
});
return outputRoutes;
}
use of org.batfish.datamodel.Ip in project batfish by batfish.
the class BdpEngine method computeOutputRoutes.
private SortedSet<Route> computeOutputRoutes(Map<String, Node> nodes, Map<Ip, String> ipOwners) {
SortedSet<Route> outputRoutes = new TreeSet<>();
nodes.forEach((hostname, node) -> {
node._virtualRouters.forEach((vrName, vr) -> {
for (AbstractRoute route : vr._mainRib.getRoutes()) {
RouteBuilder rb = new RouteBuilder();
rb.setNode(hostname);
rb.setNetwork(route.getNetwork());
Ip nextHopIp = route.getNextHopIp();
if (route.getProtocol() == RoutingProtocol.CONNECTED || (route.getProtocol() == RoutingProtocol.STATIC && nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) || Interface.NULL_INTERFACE_NAME.equals(route.getNextHopInterface())) {
rb.setNextHop(Configuration.NODE_NONE_NAME);
}
if (!nextHopIp.equals(Route.UNSET_ROUTE_NEXT_HOP_IP)) {
rb.setNextHopIp(nextHopIp);
String nextHop = ipOwners.get(nextHopIp);
if (nextHop != null) {
rb.setNextHop(nextHop);
}
}
rb.setNextHopInterface(route.getNextHopInterface());
rb.setAdministrativeCost(route.getAdministrativeCost());
rb.setCost(route.getMetric());
rb.setProtocol(route.getProtocol());
rb.setTag(route.getTag());
rb.setVrf(vrName);
Route outputRoute = rb.build();
outputRoutes.add(outputRoute);
}
});
});
return outputRoutes;
}
Aggregations