Search in sources :

Example 86 with Context

use of com.google.cloud.dialogflow.v2.Context 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)

Example 87 with Context

use of com.google.cloud.dialogflow.v2.Context in project batfish by batfish.

the class NodJobTest method testNattedSat.

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

use of com.google.cloud.dialogflow.v2.Context in project batfish by batfish.

the class Z3ContextJob method mkFixedpoint.

protected Fixedpoint mkFixedpoint(NodProgram program, boolean printAnswer) {
    Context ctx = program.getNodContext().getContext();
    Params p = ctx.mkParams();
    p.add("timeout", _settings.getZ3timeout());
    p.add("fixedpoint.engine", "datalog");
    p.add("fixedpoint.datalog.default_relation", "doc");
    p.add("fixedpoint.print_answer", printAnswer);
    Fixedpoint fix = ctx.mkFixedpoint();
    fix.setParameters(p);
    for (FuncDecl relationDeclaration : program.getNodContext().getRelationDeclarations().values()) {
        fix.registerRelation(relationDeclaration);
    }
    for (BoolExpr rule : program.getRules()) {
        fix.addRule(rule, null);
    }
    return fix;
}
Also used : Context(com.microsoft.z3.Context) BoolExpr(com.microsoft.z3.BoolExpr) Fixedpoint(com.microsoft.z3.Fixedpoint) Params(com.microsoft.z3.Params) FuncDecl(com.microsoft.z3.FuncDecl)

Example 89 with Context

use of com.google.cloud.dialogflow.v2.Context in project batfish by batfish.

the class BoolExprTransformer method visitTransformationRuleStatement.

@Override
public BoolExpr visitTransformationRuleStatement(TransformationRuleStatement transformationRuleStatement) {
    Context ctx = _nodContext.getContext();
    ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(transformationRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
    transformationRuleStatement.getPreconditionPreTransformationStates().stream().map(preconditionPreTransformationState -> toBoolExpr(preconditionPreTransformationState, _input, _nodContext)).forEach(preconditions::add);
    transformationRuleStatement.getPreconditionPostTransformationStates().stream().map(preconditionPostTransformationState -> (BoolExpr) toBoolExpr(preconditionPostTransformationState, _input, _nodContext).substitute(_from, _to)).forEach(preconditions::add);
    return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), (BoolExpr) toBoolExpr(transformationRuleStatement.getPostconditionTransformationState(), _input, _nodContext).substitute(_from, _to));
}
Also used : Context(com.microsoft.z3.Context) NodContext(org.batfish.z3.NodContext) Statement(org.batfish.z3.expr.Statement) Arrays(java.util.Arrays) PrefixMatchExpr(org.batfish.z3.expr.PrefixMatchExpr) TransformationHeaderField(org.batfish.z3.TransformationHeaderField) OrExpr(org.batfish.z3.expr.OrExpr) TrueExpr(org.batfish.z3.expr.TrueExpr) Context(com.microsoft.z3.Context) SynthesizerInput(org.batfish.z3.SynthesizerInput) TransformationRuleStatement(org.batfish.z3.expr.TransformationRuleStatement) GenericStatementVisitor(org.batfish.z3.expr.GenericStatementVisitor) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) BoolExpr(com.microsoft.z3.BoolExpr) StateExpr(org.batfish.z3.expr.StateExpr) HeaderSpaceMatchExpr(org.batfish.z3.expr.HeaderSpaceMatchExpr) Parameterizer(org.batfish.z3.state.visitors.Parameterizer) IfExpr(org.batfish.z3.expr.IfExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) FalseExpr(org.batfish.z3.expr.FalseExpr) ImmutableMap(com.google.common.collect.ImmutableMap) IpSpaceMatchExpr(org.batfish.z3.expr.IpSpaceMatchExpr) IfThenElse(org.batfish.z3.expr.IfThenElse) Set(java.util.Set) NotExpr(org.batfish.z3.expr.NotExpr) Comment(org.batfish.z3.expr.Comment) BasicRuleStatement(org.batfish.z3.expr.BasicRuleStatement) SaneExpr(org.batfish.z3.expr.SaneExpr) AndExpr(org.batfish.z3.expr.AndExpr) NodContext(org.batfish.z3.NodContext) CurrentIsOriginalExpr(org.batfish.z3.expr.CurrentIsOriginalExpr) EqExpr(org.batfish.z3.expr.EqExpr) Expr(com.microsoft.z3.Expr) QueryStatement(org.batfish.z3.expr.QueryStatement) RangeMatchExpr(org.batfish.z3.expr.RangeMatchExpr) Type(org.batfish.z3.state.StateParameter.Type) BoolExpr(com.microsoft.z3.BoolExpr) ImmutableList(com.google.common.collect.ImmutableList)

Example 90 with Context

use of com.google.cloud.dialogflow.v2.Context in project bmoth by hhu-stups.

the class MachineTranslatorTest method init.

@Before
public void init() {
    String machine = "MACHINE SimpleMachine\n";
    machine += "VARIABLES x\n";
    machine += "INVARIANT x : INTEGER &\n";
    machine += "\tx**2 = x*x \n";
    machine += "INITIALISATION x := -3\n";
    machine += "OPERATIONS\n";
    machine += "\tIncX = SELECT x < 50 THEN x := x+1 END\n";
    machine += "END";
    translator = new MachineToZ3Translator(parseMachine(machine), new Context());
}
Also used : Context(com.microsoft.z3.Context) MachineToZ3Translator(de.bmoth.backend.z3.MachineToZ3Translator) Before(org.junit.Before)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)39 CoreException (org.eclipse.core.runtime.CoreException)34 Context (org.osate.aadl2.Context)31 BoolExpr (com.microsoft.z3.BoolExpr)25 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)18 Test (org.junit.Test)18 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 List (java.util.List)16 Map (java.util.Map)15 Solver (com.microsoft.z3.Solver)13 File (java.io.File)13 IOException (java.io.IOException)11 IPath (org.eclipse.core.runtime.IPath)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11 Feature (org.osate.aadl2.Feature)11 FileNotFoundException (java.io.FileNotFoundException)10