use of org.batfish.datamodel.HeaderSpace 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 org.batfish.datamodel.HeaderSpace 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 org.batfish.datamodel.HeaderSpace 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 org.batfish.datamodel.HeaderSpace in project batfish by batfish.
the class BatfishCompressionTest method testCompressionFibs_simpleNetwork.
/**
* Test that compression doesn't change the fibs for this network.
*/
@Test
public void testCompressionFibs_simpleNetwork() throws IOException {
DataPlane origDataPlane = getDataPlane(simpleNetwork());
SortedMap<String, Configuration> compressedConfigs = compressNetwork(simpleNetwork(), new HeaderSpace());
DataPlane compressedDataPlane = getDataPlane(compressedConfigs);
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> origRibs = origDataPlane.getRibs();
SortedMap<String, SortedMap<String, GenericRib<AbstractRoute>>> compressedRibs = compressedDataPlane.getRibs();
compressedRibs.forEach((hostname, compressedRibsByVrf) -> compressedRibsByVrf.forEach((vrf, compressedRib) -> {
GenericRib<AbstractRoute> origRib = origRibs.get(hostname).get(vrf);
Set<AbstractRoute> origRoutes = origRib.getRoutes();
Set<AbstractRoute> compressedRoutes = compressedRib.getRoutes();
for (AbstractRoute route : compressedRoutes) {
/* Every compressed route should appear in original RIB */
assertThat(origRoutes, hasItem(route));
}
}));
compressedConfigs.values().forEach(BatfishCompressionTest::assertIsCompressedConfig);
/* No nodes should be missing */
assertThat(origRibs.keySet(), equalTo(compressedRibs.keySet()));
}
use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.
the class Batfish method computeCompressedDataPlane.
private CompressDataPlaneResult computeCompressedDataPlane(HeaderSpace headerSpace) {
// Since compression mutates the configurations, we must clone them before that happens.
// A simple way to do this is to create a deep clone of each entry using Java serialization.
_logger.info("Computing compressed dataplane");
Map<String, Configuration> clonedConfigs = loadConfigurations().entrySet().parallelStream().collect(toMap(Entry::getKey, entry -> SerializationUtils.clone(entry.getValue())));
Map<String, Configuration> configs = new BatfishCompressor(this, clonedConfigs).compress(headerSpace);
Topology topo = CommonUtil.synthesizeTopology(configs);
DataPlanePlugin dataPlanePlugin = getDataPlanePlugin();
ComputeDataPlaneResult result = dataPlanePlugin.computeDataPlane(false, configs, topo);
_storage.storeCompressedConfigurations(configs, _testrigSettings.getName());
return new CompressDataPlaneResult(configs, result._dataPlane, result._answerElement);
}
Aggregations