Search in sources :

Example 6 with Ip

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;
}
Also used : BgpNeighbor(org.batfish.datamodel.BgpNeighbor) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix)

Example 7 with Ip

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;
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) ImmutableSet(com.google.common.collect.ImmutableSet) SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Ip(org.batfish.datamodel.Ip) Prefix(org.batfish.datamodel.Prefix) TreeMap(java.util.TreeMap)

Example 8 with Ip

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);
}
Also used : BatfishException(org.batfish.common.BatfishException) SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Ip(org.batfish.datamodel.Ip) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Flow(org.batfish.datamodel.Flow) FlowTraceHop(org.batfish.datamodel.FlowTraceHop) TreeSet(java.util.TreeSet) FlowTrace(org.batfish.datamodel.FlowTrace) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Edge(org.batfish.datamodel.Edge)

Example 9 with Ip

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;
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) TreeSet(java.util.TreeSet) SortedMap(java.util.SortedMap) Ip(org.batfish.datamodel.Ip) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet)

Example 10 with Ip

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;
}
Also used : AbstractRoute(org.batfish.datamodel.AbstractRoute) RouteBuilder(org.batfish.datamodel.RouteBuilder) TreeSet(java.util.TreeSet) Ip(org.batfish.datamodel.Ip) AbstractRoute(org.batfish.datamodel.AbstractRoute) Route(org.batfish.datamodel.Route)

Aggregations

Ip (org.batfish.datamodel.Ip)163 Prefix (org.batfish.datamodel.Prefix)52 Configuration (org.batfish.datamodel.Configuration)43 Test (org.junit.Test)37 InterfaceAddress (org.batfish.datamodel.InterfaceAddress)36 Interface (org.batfish.datamodel.Interface)30 RoutePolicyNextHopIp (org.batfish.representation.cisco.RoutePolicyNextHopIp)30 TreeSet (java.util.TreeSet)23 BatfishException (org.batfish.common.BatfishException)23 Vrf (org.batfish.datamodel.Vrf)23 IpWildcard (org.batfish.datamodel.IpWildcard)20 SortedSet (java.util.SortedSet)19 BgpNeighbor (org.batfish.datamodel.BgpNeighbor)18 BgpProcess (org.batfish.datamodel.BgpProcess)18 FwThenNextIp (org.batfish.representation.juniper.FwThenNextIp)18 PsThenNextHopIp (org.batfish.representation.juniper.PsThenNextHopIp)18 ArrayList (java.util.ArrayList)16 Set (java.util.Set)16 Flow (org.batfish.datamodel.Flow)16 IpAccessList (org.batfish.datamodel.IpAccessList)16