use of org.batfish.datamodel.FlowTrace in project batfish by batfish.
the class CounterExample method buildFlowHistory.
/*
* Creates a trace-based example of what happens
* to a packet (e.g., why it is not reachable).
*/
FlowHistory buildFlowHistory(String testrigName, Collection<String> sourceRouters, Encoder enc, Map<String, Boolean> reach) {
FlowHistory fh = new FlowHistory();
for (String source : sourceRouters) {
Boolean sourceVar = reach.get(source);
if (!sourceVar) {
Tuple<Flow, FlowTrace> tup = buildFlowTrace(enc, source);
SortedSet<Edge> failedLinks = buildFailedLinks(enc);
SortedSet<BgpAdvertisement> envRoutes = buildEnvRoutingTable(enc);
Environment baseEnv = new Environment("BASE", testrigName, failedLinks, null, null, null, null, envRoutes);
fh.addFlowTrace(tup.getFirst(), "BASE", baseEnv, tup.getSecond());
}
}
return fh;
}
use of org.batfish.datamodel.FlowTrace 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());
});
}
Aggregations