Search in sources :

Example 66 with Context

use of com.microsoft.z3.Context in project batfish by batfish.

the class AbstractNodJob method call.

@Override
public final NodJobResult call() {
    long startTime = System.currentTimeMillis();
    try (Context ctx = new Context()) {
        SmtInput smtInput = computeSmtInput(startTime, ctx);
        Map<OriginateVrf, Map<String, Long>> originateVrfConstraints = getOriginateVrfConstraints(ctx, smtInput);
        Set<Flow> flows = getFlows(originateVrfConstraints);
        return new NodJobResult(startTime, _logger.getHistory(), flows);
    } catch (Z3Exception e) {
        return new NodJobResult(startTime, _logger.getHistory(), new BatfishException("Error running NoD on concatenated data plane", e));
    }
}
Also used : Context(com.microsoft.z3.Context) BatfishException(org.batfish.common.BatfishException) OriginateVrf(org.batfish.z3.state.OriginateVrf) Z3Exception(com.microsoft.z3.Z3Exception) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Flow(org.batfish.datamodel.Flow)

Example 67 with Context

use of com.microsoft.z3.Context in project batfish by batfish.

the class BoolExprTransformerTest method setup.

@Before
public void setup() {
    _stateExpr = Accept.INSTANCE;
    _transformationStateExpr = new PreOutEdgePostNat("host1", "interface1", "host2", "interface2");
    _ctx = new Context();
    _input = MockSynthesizerInput.builder().build();
    _nodContext = new NodContext(_ctx, ReachabilityProgram.builder().setInput(_input).setRules(of(new BasicRuleStatement(_stateExpr), new TransformationRuleStatement(_transformationStateExpr))).build());
}
Also used : NodContext(org.batfish.z3.NodContext) Context(com.microsoft.z3.Context) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) NodContext(org.batfish.z3.NodContext) PreOutEdgePostNat(org.batfish.z3.state.PreOutEdgePostNat) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) Before(org.junit.Before)

Example 68 with Context

use of com.microsoft.z3.Context in project batfish by batfish.

the class NodJobTest method testNotNattedSat.

/**
 * Test that traffic originating from 3.0.0.1 that is expected NOT to be NATed returns SAT when we
 * constrain to only allow NOT-NATed results.
 */
@Test
public void testNotNattedSat() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
    NodJob nodJob = getNodJob(headerSpace, false);
    Context z3Context = new Context();
    Status status = nodJob.computeNodSat(System.currentTimeMillis(), z3Context);
    assertThat(status, equalTo(Status.SATISFIABLE));
}
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 69 with Context

use of com.microsoft.z3.Context in project batfish by batfish.

the class NodJobTest method testNattedUnsat.

/**
 * Test that traffic originating from 3.0.0.0 that is expected to be NATed returns UNSAT when we
 * constrain to only allow NOT-NATed results.
 */
@Test
public void testNattedUnsat() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.0")));
    NodJob nodJob = getNodJob(headerSpace, false);
    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 70 with Context

use of com.microsoft.z3.Context in project batfish by batfish.

the class NodJobTest method testNatted.

/**
 * Test that traffic originating from 3.0.0.0 is NATed
 */
@Test
public void testNatted() {
    HeaderSpace headerSpace = new HeaderSpace();
    headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.0")));
    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);
    // Only one OriginateVrf choice, so this must be 0
    assertThat(fieldConstraints, hasEntry(OriginateVrfInstrumentation.ORIGINATE_VRF_FIELD_NAME, new Long(0)));
    assertThat(fieldConstraints, hasEntry(BasicHeaderField.ORIG_SRC_IP.getName(), new Ip("3.0.0.0").asLong()));
    assertThat(fieldConstraints, hasEntry(equalTo(BasicHeaderField.SRC_IP.getName()), not(equalTo(new Ip("3.0.0.0").asLong()))));
    assertThat(fieldConstraints, hasEntry(BasicHeaderField.SRC_IP.getName(), new Ip("1.0.0.10").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(), notNullValue());
        assertThat(hop.getTransformedFlow().getSrcIp(), equalTo(new Ip("1.0.0.10")));
    });
}
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

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)34 BoolExpr (com.microsoft.z3.BoolExpr)31 Test (org.junit.Test)24 List (java.util.List)21 Event (dartagnan.program.Event)19 MemEvent (dartagnan.program.MemEvent)19 Program (dartagnan.program.Program)19 IOException (java.io.IOException)19 Set (java.util.Set)19 Collectors (java.util.stream.Collectors)19 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 Local (dartagnan.program.Local)16 HashMap (java.util.HashMap)16 Map (java.util.Map)15 Solver (com.microsoft.z3.Solver)14 Init (dartagnan.program.Init)14 File (java.io.File)14