use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class DestinationClasses method buildPrefixTrie.
private void buildPrefixTrie(Map<String, List<Protocol>> protoMap, List<Prefix> dstIps, List<Prefix> notDstIps, PrefixTrieMap pt) {
// Populate prefix trie
for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
String router = entry.getKey();
Configuration conf = entry.getValue();
for (Protocol proto : protoMap.get(router)) {
Set<Prefix> destinations = new HashSet<>();
if (!proto.isStatic()) {
destinations = Graph.getOriginatedNetworks(conf, proto);
}
// Add all destinations to the prefix trie relevant to this slice
for (Prefix p : destinations) {
if (PrefixUtils.overlap(p, dstIps) && !PrefixUtils.overlap(p, notDstIps)) {
Set<Prefix> toAdd = new HashSet<>();
for (Prefix pfx : dstIps) {
if (p.equals(pfx)) {
toAdd.add(p);
} else if (pfx.containsPrefix(p)) {
toAdd.add(p);
} else if (p.containsPrefix(pfx)) {
toAdd.add(pfx);
}
}
for (Prefix prefix : toAdd) {
pt.add(prefix, router);
}
}
}
}
}
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class MrvConfiguration method toVendorIndependentConfiguration.
@Override
public Configuration toVendorIndependentConfiguration() throws VendorConversionException {
_c = new Configuration(_hostname, _vendor);
_c.setDefaultCrossZoneAction(LineAction.ACCEPT);
_c.setDefaultInboundAction(LineAction.ACCEPT);
return _c;
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class EncoderSlice method initOriginatedPrefixes.
private void initOriginatedPrefixes() {
for (Entry<String, Configuration> entry : getGraph().getConfigurations().entrySet()) {
String router = entry.getKey();
Configuration conf = entry.getValue();
for (Protocol proto : _optimizations.getProtocols().get(router)) {
Set<Prefix> prefixes = Graph.getOriginatedNetworks(conf, proto);
_originatedNetworks.put(router, proto, prefixes);
}
}
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class EncoderSlice method addBestPerProtocolConstraints.
/*
* Constrains each protocol-best record similarly to the overall
* best record. It will be better than all choices and equal to
* at least one of them.
*/
private void addBestPerProtocolConstraints() {
for (Entry<String, Configuration> entry : getGraph().getConfigurations().entrySet()) {
String router = entry.getKey();
Configuration conf = entry.getValue();
for (Protocol proto : getProtocols().get(router)) {
SymbolicRoute bestVars = _symbolicDecisions.getBestVars(_optimizations, router, proto);
assert (bestVars != null);
BoolExpr acc = null;
BoolExpr somePermitted = null;
for (LogicalEdge e : collectAllImportLogicalEdges(router, conf, proto)) {
SymbolicRoute vars = correctVars(e);
if (somePermitted == null) {
somePermitted = vars.getPermitted();
} else {
somePermitted = mkOr(somePermitted, vars.getPermitted());
}
BoolExpr v = mkAnd(vars.getPermitted(), equal(conf, proto, bestVars, vars, e, true));
if (acc == null) {
acc = v;
} else {
acc = mkOr(acc, v);
}
add(mkImplies(vars.getPermitted(), greaterOrEqual(conf, proto, bestVars, vars, e)));
}
if (acc != null) {
add(mkEq(somePermitted, bestVars.getPermitted()));
add(mkImplies(somePermitted, acc));
}
}
}
}
use of org.batfish.datamodel.Configuration in project batfish by batfish.
the class EncoderSlice method addBestOverallConstraints.
/*
* Constraints that specify that the best choice is
* better than all alternatives, and is at least one of the choices:
*
* (1) if no options are valid, then best is not valid
* (2) if some option is valid, then we have the following:
*
* (best <= best_prot1) and ... and (best <= best_protn)
* (best = best_prot1) or ... or (best = best_protn)
*/
private void addBestOverallConstraints() {
for (Entry<String, Configuration> entry : getGraph().getConfigurations().entrySet()) {
String router = entry.getKey();
Configuration conf = entry.getValue();
// These constraints will be added at the protocol-level when a single protocol
if (!_optimizations.getSliceHasSingleProtocol().contains(router)) {
boolean someProto = false;
BoolExpr acc = null;
BoolExpr somePermitted = null;
SymbolicRoute best = _symbolicDecisions.getBestNeighbor().get(router);
for (Protocol proto : getProtocols().get(router)) {
someProto = true;
SymbolicRoute bestVars = _symbolicDecisions.getBestVars(_optimizations, router, proto);
assert (bestVars != null);
if (somePermitted == null) {
somePermitted = bestVars.getPermitted();
} else {
somePermitted = mkOr(somePermitted, bestVars.getPermitted());
}
BoolExpr val = mkAnd(bestVars.getPermitted(), equal(conf, proto, best, bestVars, null, true));
if (acc == null) {
acc = val;
} else {
acc = mkOr(acc, val);
}
add(mkImplies(bestVars.getPermitted(), greaterOrEqual(conf, proto, best, bestVars, null)));
}
if (someProto) {
if (acc != null) {
add(mkEq(somePermitted, best.getPermitted()));
add(mkImplies(somePermitted, acc));
}
} else {
add(mkNot(best.getPermitted()));
}
}
}
}
Aggregations