use of com.google.cloud.dialogflow.v2.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());
}
use of com.google.cloud.dialogflow.v2.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));
}
use of com.google.cloud.dialogflow.v2.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));
}
use of com.google.cloud.dialogflow.v2.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")));
});
}
use of com.google.cloud.dialogflow.v2.Context in project batfish by batfish.
the class BoolExprTransformer method visitBasicRuleStatement.
@Override
public BoolExpr visitBasicRuleStatement(BasicRuleStatement basicRuleStatement) {
Context ctx = _nodContext.getContext();
ImmutableList.Builder<BoolExpr> preconditions = ImmutableList.<BoolExpr>builder().add(toBoolExpr(basicRuleStatement.getPreconditionStateIndependentConstraints(), _input, _nodContext));
basicRuleStatement.getPreconditionStates().stream().map(preconditionState -> toBoolExpr(preconditionState, _input, _nodContext)).forEach(preconditions::add);
return ctx.mkImplies(ctx.mkAnd(preconditions.build().stream().toArray(BoolExpr[]::new)), toBoolExpr(basicRuleStatement.getPostconditionState(), _input, _nodContext));
}
Aggregations