use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.
the class DestinationClasses method buildHeaderSpaceEcs.
private void buildHeaderSpaceEcs(Map<Set<String>, List<Prefix>> destinationMap) {
destinationMap.forEach((devices, prefixes) -> {
HeaderSpace h = createHeaderSpace(prefixes);
if (_headerspace != null) {
copyAllButDestinationIp(h, _headerspace);
}
_headerspaceMap.put(devices, new Tuple<>(h, new Tuple<>(prefixes, false)));
});
}
use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.
the class DestinationClasses method createHeaderSpace.
/*
* Convert a collection of prefixes over destination IP in to a headerspace
*/
private HeaderSpace createHeaderSpace(List<Prefix> prefixes) {
HeaderSpace h = new HeaderSpace();
h.setDstIps(prefixes.stream().map(IpWildcard::new).collect(Collectors.toSet()));
return h;
}
use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.
the class NetworkSlice method allSlices.
public static ArrayList<Supplier<NetworkSlice>> allSlices(DestinationClasses dcs, int fails) {
BDDNetwork network = BDDNetwork.create(dcs.getGraph());
ArrayList<Supplier<NetworkSlice>> classes = new ArrayList<>();
for (Entry<Set<String>, Tuple<HeaderSpace, Tuple<List<Prefix>, Boolean>>> entry : dcs.getHeaderspaceMap().entrySet()) {
Set<String> devices = entry.getKey();
HeaderSpace headerspace = entry.getValue().getFirst();
List<Prefix> prefixes = entry.getValue().getSecond().getFirst();
Boolean isDefaultCase = entry.getValue().getSecond().getSecond();
Supplier<NetworkSlice> sup = () -> AbstractionBuilder.createGraph(dcs, network, devices, headerspace, prefixes, fails, isDefaultCase);
classes.add(sup);
}
return classes;
}
use of org.batfish.datamodel.HeaderSpace in project batfish by batfish.
the class NodJobTest method testNotNattedUnsat.
/**
* Test that traffic originating from 3.0.0.1 that is expected NOT to be NATed returns UNSAT when
* we constrain to only allow NATed results.
*/
@Test
public void testNotNattedUnsat() {
HeaderSpace headerSpace = new HeaderSpace();
headerSpace.setSrcIps(ImmutableList.of(new IpWildcard("3.0.0.1")));
NodJob nodJob = getNodJob(headerSpace, true);
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 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