use of org.batfish.symbolic.Protocol in project batfish by batfish.
the class DestinationClasses method buildProtocolMap.
/*
* Initialize a mapping from router to collection of protocol
*/
private Map<String, List<Protocol>> buildProtocolMap() {
// Figure out which protocols are running on which devices
Map<String, List<Protocol>> protocols = new HashMap<>();
for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
String router = entry.getKey();
Configuration conf = entry.getValue();
List<Protocol> protos = new ArrayList<>();
protocols.put(router, protos);
if (conf.getDefaultVrf().getOspfProcess() != null) {
protos.add(Protocol.OSPF);
}
if (conf.getDefaultVrf().getBgpProcess() != null) {
protos.add(Protocol.BGP);
}
if (!conf.getDefaultVrf().getStaticRoutes().isEmpty()) {
protos.add(Protocol.STATIC);
}
if (!conf.getInterfaces().isEmpty()) {
protos.add(Protocol.CONNECTED);
}
}
return protocols;
}
use of org.batfish.symbolic.Protocol 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.symbolic.Protocol 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.symbolic.Protocol 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.symbolic.Protocol in project batfish by batfish.
the class EncoderSlice method addBestVariables.
/*
* Initialize variables representing the best choice both for
* each protocol as well as for the router as a whole
*/
private void addBestVariables() {
for (Entry<String, List<Protocol>> entry : getProtocols().entrySet()) {
String router = entry.getKey();
List<Protocol> allProtos = entry.getValue();
// Overall best
for (int len = 0; len <= BITS; len++) {
String name = String.format("%d_%s%s_%s_%s_%s", _encoder.getId(), _sliceName, router, "OVERALL", "BEST", "None");
String historyName = name + "_history";
SymbolicEnum<Protocol> h = new SymbolicEnum<>(this, allProtos, historyName);
SymbolicRoute evBest = new SymbolicRoute(this, name, router, Protocol.BEST, _optimizations, h, false);
getAllSymbolicRecords().add(evBest);
_symbolicDecisions.getBestNeighbor().put(router, evBest);
}
// Best per protocol
if (!_optimizations.getSliceHasSingleProtocol().contains(router)) {
for (Protocol proto : getProtocols().get(router)) {
String name = String.format("%d_%s%s_%s_%s_%s", _encoder.getId(), _sliceName, router, proto.name(), "BEST", "None");
for (int len = 0; len <= BITS; len++) {
SymbolicRoute evBest = new SymbolicRoute(this, name, router, proto, _optimizations, null, false);
getAllSymbolicRecords().add(evBest);
_symbolicDecisions.getBestNeighborPerProtocol().put(router, proto, evBest);
}
}
}
}
}
Aggregations