Search in sources :

Example 31 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class Encoder method initSlices.

/*
   * Initialize each encoding slice.
   * For iBGP, we also add reachability information for each pair of neighbors,
   * to determine if messages sent to/from a neighbor will arrive.
   */
private void initSlices(HeaderSpace h, Graph g) {
    if (g.getIbgpNeighbors().isEmpty() || !_modelIgp) {
        _slices.put(MAIN_SLICE_NAME, new EncoderSlice(this, h, g, ""));
    } else {
        _slices.put(MAIN_SLICE_NAME, new EncoderSlice(this, h, g, MAIN_SLICE_NAME));
    }
    if (_modelIgp) {
        SortedSet<Pair<String, Ip>> ibgpRouters = new TreeSet<>();
        for (Entry<GraphEdge, BgpNeighbor> entry : g.getIbgpNeighbors().entrySet()) {
            GraphEdge ge = entry.getKey();
            BgpNeighbor n = entry.getValue();
            String router = ge.getRouter();
            Ip ip = n.getLocalIp();
            Pair<String, Ip> pair = new Pair<>(router, ip);
            // Add one slice per (router, source ip) pair
            if (!ibgpRouters.contains(pair)) {
                ibgpRouters.add(pair);
                // Create a control plane slice only for this ip
                HeaderSpace hs = new HeaderSpace();
                // Make sure messages are sent to this destination IP
                SortedSet<IpWildcard> ips = new TreeSet<>();
                ips.add(new IpWildcard(n.getLocalIp()));
                hs.setDstIps(ips);
                // Make sure messages use TCP port 179
                SortedSet<SubRange> dstPorts = new TreeSet<>();
                dstPorts.add(new SubRange(179, 179));
                hs.setDstPorts(dstPorts);
                // Make sure messages use the TCP protocol
                SortedSet<IpProtocol> protocols = new TreeSet<>();
                protocols.add(IpProtocol.TCP);
                hs.setIpProtocols(protocols);
                // TODO: create domains once
                Graph gNew = new Graph(g.getBatfish(), null, g.getDomain(router));
                String sliceName = "SLICE-" + router + "_";
                EncoderSlice slice = new EncoderSlice(this, hs, gNew, sliceName);
                _slices.put(sliceName, slice);
                PropertyAdder pa = new PropertyAdder(slice);
                Map<String, BoolExpr> reachVars = pa.instrumentReachability(router);
                _sliceReachability.put(router, reachVars);
            }
        }
    }
}
Also used : BoolExpr(com.microsoft.z3.BoolExpr) Ip(org.batfish.datamodel.Ip) HeaderSpace(org.batfish.datamodel.HeaderSpace) BgpNeighbor(org.batfish.datamodel.BgpNeighbor) IpWildcard(org.batfish.datamodel.IpWildcard) Graph(org.batfish.symbolic.Graph) TreeSet(java.util.TreeSet) IpProtocol(org.batfish.datamodel.IpProtocol) SubRange(org.batfish.datamodel.SubRange) GraphEdge(org.batfish.symbolic.GraphEdge) Pair(org.batfish.common.Pair)

Example 32 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class EncoderSlice method computeWildcardMatch.

/*
   * Convert a set of wildcards and a packet field to a symbolic boolean expression
   */
private BoolExpr computeWildcardMatch(Set<IpWildcard> wcs, BitVecExpr field) {
    BoolExpr acc = mkFalse();
    for (IpWildcard wc : wcs) {
        ipWildCardBound(field, wc);
        acc = mkOr(acc, ipWildCardBound(field, wc));
    }
    return (BoolExpr) acc.simplify();
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) BoolExpr(com.microsoft.z3.BoolExpr)

Example 33 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class DestinationClasses method createHeaderSpace.

/*
   * Convert a collection of prefixes over destination IP in to a headerspace
   */
private HeaderSpace createHeaderSpace(List<Prefix> prefixes) {
    HeaderSpace h = new HeaderSpace();
    h.setDstIps(prefixes.stream().map(IpWildcard::new).collect(Collectors.toSet()));
    return h;
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) HeaderSpace(org.batfish.datamodel.HeaderSpace)

Example 34 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class FwFromSourceAddressExcept method applyTo.

@Override
public void applyTo(IpAccessListLine line, JuniperConfiguration jc, Warnings w, Configuration c) {
    IpWildcard wildcard = new IpWildcard(_prefix);
    line.setNotSrcIps(Iterables.concat(line.getNotSrcIps(), Collections.singleton(wildcard)));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard)

Example 35 with IpWildcard

use of org.batfish.datamodel.IpWildcard in project batfish by batfish.

the class FwFromSourcePrefixList method applyTo.

@Override
public void applyTo(IpAccessListLine line, JuniperConfiguration jc, Warnings w, Configuration c) {
    PrefixList pl = jc.getPrefixLists().get(_name);
    if (pl != null) {
        pl.getReferers().put(this, "firewall from source-prefix-list");
        if (pl.getIpv6()) {
            return;
        }
        RouteFilterList sourcePrefixList = c.getRouteFilterLists().get(_name);
        List<IpWildcard> wildcards = sourcePrefixList.getMatchingIps();
        line.setSrcIps(Iterables.concat(line.getSrcIps(), wildcards));
    } else {
        w.redFlag("Reference to undefined source prefix-list: \"" + _name + "\"");
    }
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) RouteFilterList(org.batfish.datamodel.RouteFilterList)

Aggregations

IpWildcard (org.batfish.datamodel.IpWildcard)63 Test (org.junit.Test)38 Ip (org.batfish.datamodel.Ip)18 IpAccessListLine (org.batfish.datamodel.IpAccessListLine)17 SubRange (org.batfish.datamodel.SubRange)16 HeaderSpace (org.batfish.datamodel.HeaderSpace)12 Prefix (org.batfish.datamodel.Prefix)9 LinkedList (java.util.LinkedList)8 Configuration (org.batfish.datamodel.Configuration)8 Context (com.microsoft.z3.Context)7 Interface (org.batfish.datamodel.Interface)7 IpAccessList (org.batfish.datamodel.IpAccessList)6 IpProtocol (org.batfish.datamodel.IpProtocol)6 BoolExpr (com.microsoft.z3.BoolExpr)5 TreeSet (java.util.TreeSet)5 BatfishException (org.batfish.common.BatfishException)5 RouteFilterList (org.batfish.datamodel.RouteFilterList)5 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)4 Status (com.microsoft.z3.Status)4 Map (java.util.Map)4