Search in sources :

Example 16 with HeaderSpace

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

the class DestinationClasses method buildHeaderSpaceEcs.

private void buildHeaderSpaceEcs(Map<Set<String>, List<Prefix>> destinationMap) {
    destinationMap.forEach((devices, prefixes) -> {
        HeaderSpace h = createHeaderSpace(prefixes);
        if (_headerspace != null) {
            copyAllButDestinationIp(h, _headerspace);
        }
        _headerspaceMap.put(devices, new Tuple<>(h, new Tuple<>(prefixes, false)));
    });
}
Also used : HeaderSpace(org.batfish.datamodel.HeaderSpace) Tuple(org.batfish.symbolic.utils.Tuple)

Example 17 with HeaderSpace

use of org.batfish.datamodel.HeaderSpace 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 18 with HeaderSpace

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

the class NetworkSlice method allSlices.

public static ArrayList<Supplier<NetworkSlice>> allSlices(DestinationClasses dcs, int fails) {
    BDDNetwork network = BDDNetwork.create(dcs.getGraph());
    ArrayList<Supplier<NetworkSlice>> classes = new ArrayList<>();
    for (Entry<Set<String>, Tuple<HeaderSpace, Tuple<List<Prefix>, Boolean>>> entry : dcs.getHeaderspaceMap().entrySet()) {
        Set<String> devices = entry.getKey();
        HeaderSpace headerspace = entry.getValue().getFirst();
        List<Prefix> prefixes = entry.getValue().getSecond().getFirst();
        Boolean isDefaultCase = entry.getValue().getSecond().getSecond();
        Supplier<NetworkSlice> sup = () -> AbstractionBuilder.createGraph(dcs, network, devices, headerspace, prefixes, fails, isDefaultCase);
        classes.add(sup);
    }
    return classes;
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) BDDNetwork(org.batfish.symbolic.bdd.BDDNetwork) HeaderSpace(org.batfish.datamodel.HeaderSpace) Prefix(org.batfish.datamodel.Prefix) Supplier(java.util.function.Supplier) List(java.util.List) ArrayList(java.util.ArrayList) Tuple(org.batfish.symbolic.utils.Tuple)

Example 19 with HeaderSpace

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

the class NodJobTest method testNotNattedUnsat.

/**
 * Test that traffic originating from 3.0.0.1 that is expected NOT to be NATed returns UNSAT when
 * we constrain to only allow NATed results.
 */
@Test
public void testNotNattedUnsat() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
    NodJob nodJob = getNodJob(headerSpace, true);
    Context z3Context = new Context();
    Status status = nodJob.computeNodSat(System.currentTimeMillis(), z3Context);
    assertThat(status, equalTo(Status.UNSATISFIABLE));
}
Also used : IpWildcard(org.batfish.datamodel.IpWildcard) Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) HeaderSpace(org.batfish.datamodel.HeaderSpace) Test(org.junit.Test)

Example 20 with HeaderSpace

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

the class NodJobTest method testNotNatted.

/**
 * Test that traffic originating from 3.0.0.1 is not NATed
 */
@Test
public void testNotNatted() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
    NodJob nodJob = getNodJob(headerSpace);
    Context z3Context = new Context();
    SmtInput smtInput = nodJob.computeSmtInput(System.currentTimeMillis(), z3Context);
    Map<OriginateVrf, Map<String, Long>> fieldConstraintsByOriginateVrf = nodJob.getOriginateVrfConstraints(z3Context, smtInput);
    assertThat(fieldConstraintsByOriginateVrf.entrySet(), hasSize(1));
    assertThat(fieldConstraintsByOriginateVrf, hasKey(_originateVrf));
    Map<String, Long> fieldConstraints = fieldConstraintsByOriginateVrf.get(_originateVrf);
    assertThat(fieldConstraints, hasEntry(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME, new Long(0)));
    assertThat(smtInput._variablesAsConsts, hasKey("SRC_IP"));
    assertThat(fieldConstraints, hasKey(BasicHeaderField.SRC_IP.getName()));
    assertThat(fieldConstraints, hasEntry(BasicHeaderField.ORIG_SRC_IP.getName(), new Ip("3.0.0.1").asLong()));
    assertThat(fieldConstraints, hasEntry(BasicHeaderField.SRC_IP.getName(), new Ip("3.0.0.1").asLong()));
    Set<Flow> flows = nodJob.getFlows(fieldConstraintsByOriginateVrf);
    _bdpDataPlanePlugin.processFlows(flows, _dataPlane);
    List<FlowTrace> flowTraces = _bdpDataPlanePlugin.getHistoryFlowTraces(_dataPlane);
    flowTraces.forEach(trace -> {
        assertThat(trace.getNotes(), is("ACCEPTED"));
        List<FlowTraceHop> hops = trace.getHops();
        assertThat(hops, hasSize(1));
        FlowTraceHop hop = hops.get(0);
        assertThat(hop.getTransformedFlow(), nullValue());
    });
}
Also used : Context(com.microsoft.z3.Context) Ip(org.batfish.datamodel.Ip) HeaderSpace(org.batfish.datamodel.HeaderSpace) OriginateVrf(org.batfish.z3.state.OriginateVrf) Flow(org.batfish.datamodel.Flow) IpWildcard(org.batfish.datamodel.IpWildcard) FlowTraceHop(org.batfish.datamodel.FlowTraceHop) FlowTrace(org.batfish.datamodel.FlowTrace) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Test(org.junit.Test)

Aggregations

HeaderSpace (org.batfish.datamodel.HeaderSpace)22 IpWildcard (org.batfish.datamodel.IpWildcard)12 Test (org.junit.Test)8 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)7 Map (java.util.Map)7 SortedMap (java.util.SortedMap)7 Configuration (org.batfish.datamodel.Configuration)7 Ip (org.batfish.datamodel.Ip)7 Context (com.microsoft.z3.Context)6 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 Pair (org.batfish.common.Pair)6 DataPlane (org.batfish.datamodel.DataPlane)6 Flow (org.batfish.datamodel.Flow)6 Topology (org.batfish.datamodel.Topology)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 IOException (java.io.IOException)5 TreeMap (java.util.TreeMap)5 IBatfish (org.batfish.common.plugin.IBatfish)5