use of org.batfish.datamodel.ForwardingAction in project batfish by batfish.
the class Batfish method singleReachability.
private AnswerElement singleReachability(ReachabilitySettings reachabilitySettings, ReachabilityQuerySynthesizer.Builder<?, ?> builder) {
Settings settings = getSettings();
String tag = getFlowTag(_testrigSettings);
Set<ForwardingAction> actions = reachabilitySettings.getActions();
boolean useCompression = reachabilitySettings.getUseCompression();
// specialized compression
/*
CompressDataPlaneResult compressionResult =
useCompression ? computeCompressedDataPlane(headerSpace) : null;
Map<String, Configuration> configurations =
useCompression ? compressionResult._compressedConfigs : loadConfigurations();
DataPlane dataPlane = useCompression ? compressionResult._compressedDataPlane : loadDataPlane();
*/
// general compression
Snapshot snapshot = getSnapshot();
Map<String, Configuration> configurations = useCompression ? loadCompressedConfigurations(snapshot) : loadConfigurations(snapshot);
DataPlane dataPlane = loadDataPlane(useCompression);
if (configurations == null) {
throw new BatfishException("error loading configurations");
}
if (dataPlane == null) {
throw new BatfishException("error loading data plane");
}
Set<String> activeIngressNodes;
Set<String> activeFinalNodes;
HeaderSpace headerSpace;
Set<String> transitNodes;
Set<String> nonTransitNodes;
int maxChunkSize;
try {
activeIngressNodes = reachabilitySettings.computeActiveIngressNodes(configurations);
activeFinalNodes = reachabilitySettings.computeActiveFinalNodes(configurations);
headerSpace = reachabilitySettings.getHeaderSpace();
transitNodes = reachabilitySettings.computeActiveTransitNodes(configurations);
nonTransitNodes = reachabilitySettings.computeActiveNonTransitNodes(configurations);
maxChunkSize = reachabilitySettings.getMaxChunkSize();
reachabilitySettings.validateTransitNodes(configurations);
} catch (InvalidReachabilitySettingsException e) {
return e.getInvalidSettingsAnswer();
}
List<Pair<String, String>> originateNodeVrfs = activeIngressNodes.stream().flatMap(ingressNode -> configurations.get(ingressNode).getVrfs().keySet().stream().map(ingressVrf -> new Pair<>(ingressNode, ingressVrf))).collect(Collectors.toList());
int chunkSize = Math.max(1, Math.min(maxChunkSize, originateNodeVrfs.size() / _settings.getAvailableThreads()));
// partition originateNodeVrfs into chunks
List<List<Pair<String, String>>> originateNodeVrfChunks = Lists.partition(originateNodeVrfs, chunkSize);
Synthesizer dataPlaneSynthesizer = synthesizeDataPlane(configurations, dataPlane, loadForwardingAnalysis(configurations, dataPlane), headerSpace, reachabilitySettings.getSpecialize());
// build query jobs
List<NodJob> jobs = originateNodeVrfChunks.stream().map(ImmutableSortedSet::copyOf).map(nodeVrfs -> {
SortedMap<String, Set<String>> vrfsByNode = new TreeMap<>();
nodeVrfs.forEach(nodeVrf -> {
String node = nodeVrf.getFirst();
String vrf = nodeVrf.getSecond();
vrfsByNode.computeIfAbsent(node, key -> new TreeSet<>());
vrfsByNode.get(node).add(vrf);
});
ReachabilityQuerySynthesizer query = builder.setActions(actions).setHeaderSpace(headerSpace).setFinalNodes(activeFinalNodes).setIngressNodeVrfs(vrfsByNode).setTransitNodes(transitNodes).setNonTransitNodes(nonTransitNodes).setSrcNatted(reachabilitySettings.getSrcNatted()).build();
return new NodJob(settings, dataPlaneSynthesizer, query, nodeVrfs, tag, reachabilitySettings.getSpecialize());
}).collect(Collectors.toList());
// run jobs and get resulting flows
Set<Flow> flows = computeNodOutput(jobs);
getDataPlanePlugin().processFlows(flows, loadDataPlane());
AnswerElement answerElement = getHistory();
return answerElement;
}
use of org.batfish.datamodel.ForwardingAction in project batfish by batfish.
the class StandardReachabilityQuerySynthesizer method computeFinalActions.
/**
* Create query condition for action at final node(s)
*/
private List<StateExpr> computeFinalActions() {
ImmutableList.Builder<StateExpr> finalActionsBuilder = ImmutableList.builder();
for (ForwardingAction action : _actions) {
switch(action) {
case ACCEPT:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr accept = new NodeAccept(finalNode);
finalActionsBuilder.add(accept);
}
} else {
finalActionsBuilder.add(Accept.INSTANCE);
}
break;
case DEBUG:
finalActionsBuilder.add(Debug.INSTANCE);
break;
case DROP:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeDrop(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(Drop.INSTANCE);
}
break;
case DROP_ACL:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeDropAcl(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(DropAcl.INSTANCE);
}
break;
case DROP_ACL_IN:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeDropAclIn(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(DropAclIn.INSTANCE);
}
break;
case DROP_ACL_OUT:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeDropAclOut(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(DropAclOut.INSTANCE);
}
break;
case DROP_NO_ROUTE:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeDropNoRoute(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(DropNoRoute.INSTANCE);
}
break;
case DROP_NULL_ROUTE:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeDropNullRoute(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(DropNullRoute.INSTANCE);
}
break;
case NEIGHBOR_UNREACHABLE_OR_EXITS_NETWORK:
if (_finalNodes.size() > 0) {
for (String finalNode : _finalNodes) {
StateExpr drop = new NodeNeighborUnreachable(finalNode);
finalActionsBuilder.add(drop);
}
} else {
finalActionsBuilder.add(NeighborUnreachable.INSTANCE);
}
break;
case FORWARD:
default:
throw new BatfishException("unsupported action");
}
}
return finalActionsBuilder.build();
}
Aggregations