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());
});
}
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));
}
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;
}
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));
}
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());
}
Aggregations