use of org.batfish.common.Pair in project batfish by batfish.
the class TransferResult method mergeChangedVariables.
// TODO: this really needs to use persistent set data types
public PList<Pair<String, Pair<Expr, Expr>>> mergeChangedVariables(TransferResult<U, T> other) {
Set<String> seen = new HashSet<>();
PList<Pair<String, Pair<Expr, Expr>>> vars = PList.empty();
for (Pair<String, Expr> cv1 : this._changedVariables) {
String s = cv1.getFirst();
Expr x = cv1.getSecond();
if (!seen.contains(s)) {
seen.add(s);
Expr e = find(other._changedVariables, s);
Pair<Expr, Expr> pair = new Pair<>(x, e);
vars = vars.plus(new Pair<>(s, pair));
}
}
for (Pair<String, Expr> cv1 : other._changedVariables) {
String s = cv1.getFirst();
Expr x = cv1.getSecond();
if (!seen.contains(s)) {
seen.add(s);
Expr e = find(this._changedVariables, s);
// preserve order
Pair<Expr, Expr> pair = new Pair<>(e, x);
vars = vars.plus(new Pair<>(s, pair));
}
}
return vars;
}
use of org.batfish.common.Pair in project batfish by batfish.
the class BDDNetwork method computeInterfacePolicies.
/*
* For each interface in the network, creates a canonical
* representation of the import and export policies on this interface.
*/
private void computeInterfacePolicies() {
for (Entry<String, Configuration> entry : _graph.getConfigurations().entrySet()) {
String router = entry.getKey();
// Skip if doesn't match the node regex
Matcher m = _nodeSpecifier.getRegex().matcher(router);
if (!m.matches()) {
continue;
}
Configuration conf = entry.getValue();
List<GraphEdge> edges = _graph.getEdgeMap().get(router);
for (GraphEdge ge : edges) {
// Import BGP policy
RoutingPolicy importBgp = _graph.findImportRoutingPolicy(router, Protocol.BGP, ge);
if (importBgp != null) {
BDDRoute rec = computeBDD(_graph, conf, importBgp, true);
_importBgpPolicies.put(ge, rec);
}
// Export BGP policy
RoutingPolicy exportBgp = _graph.findExportRoutingPolicy(router, Protocol.BGP, ge);
if (exportBgp != null) {
BDDRoute rec = computeBDD(_graph, conf, exportBgp, true);
_exportBgpPolicies.put(ge, rec);
}
IpAccessList in = ge.getStart().getIncomingFilter();
IpAccessList out = ge.getStart().getOutgoingFilter();
// Incoming ACL
if (in != null) {
BDDAcl x = BDDAcl.create(conf, in, true);
_inAcls.put(ge, x);
}
// Outgoing ACL
if (out != null) {
BDDAcl x = BDDAcl.create(conf, out, true);
_outAcls.put(ge, x);
}
}
}
for (Entry<String, List<GraphEdge>> entry : _graph.getEdgeMap().entrySet()) {
String router = entry.getKey();
// Skip if doesn't match the node regex
Matcher m = _nodeSpecifier.getRegex().matcher(router);
if (!m.matches()) {
continue;
}
List<GraphEdge> edges = entry.getValue();
Configuration conf = _graph.getConfigurations().get(router);
for (GraphEdge ge : edges) {
BDDRoute bgpIn = _importBgpPolicies.get(ge);
BDDRoute bgpOut = _exportBgpPolicies.get(ge);
BDDAcl aclIn = _inAcls.get(ge);
BDDAcl aclOut = _outAcls.get(ge);
Integer ospfCost = ge.getStart().getOspfCost();
SortedSet<Pair<Prefix, Integer>> staticPrefixes = new TreeSet<>();
SortedSet<StaticRoute> staticRoutes = conf.getDefaultVrf().getStaticRoutes();
for (StaticRoute sr : staticRoutes) {
Prefix pfx = sr.getNetwork();
Integer adminCost = sr.getAdministrativeCost();
Pair<Prefix, Integer> tup = new Pair<>(pfx, adminCost);
staticPrefixes.add(tup);
}
InterfacePolicy ipol = new InterfacePolicy(aclIn, bgpIn, null, staticPrefixes);
InterfacePolicy epol = new InterfacePolicy(aclOut, bgpOut, ospfCost, null);
_importPolicyMap.put(ge, ipol);
_exportPolicyMap.put(ge, epol);
}
}
}
use of org.batfish.common.Pair in project batfish by batfish.
the class WorkMgr method computeWorkDetails.
private WorkDetails computeWorkDetails(WorkItem workItem) {
WorkType workType = WorkType.UNKNOWN;
if (WorkItemBuilder.isParsingWorkItem(workItem)) {
workType = WorkType.PARSING;
}
if (WorkItemBuilder.isDataplaningWorkItem(workItem)) {
if (workType != WorkType.UNKNOWN) {
throw new BatfishException("Cannot do composite work. Separate PARSING and DATAPLANING.");
}
workType = WorkType.DATAPLANING;
}
if (WorkItemBuilder.isAnsweringWorkItem(workItem)) {
if (workType != WorkType.UNKNOWN) {
throw new BatfishException("Cannot do composite work. Separate ANSWER from other work.");
}
String qName = WorkItemBuilder.getQuestionName(workItem);
if (qName == null) {
throw new BatfishException("Question name not provided for ANSWER work");
}
Path qFile = getpathContainerQuestion(workItem.getContainerName(), qName);
Question question = Question.parseQuestion(qFile);
workType = question.getIndependent() ? WorkType.INDEPENDENT_ANSWERING : question.getDataPlane() ? WorkType.DATAPLANE_DEPENDENT_ANSWERING : WorkType.PARSING_DEPENDENT_ANSWERING;
}
if (WorkItemBuilder.isAnalyzingWorkItem(workItem)) {
if (workType != WorkType.UNKNOWN) {
throw new BatfishException("Cannot do composite work. Separate ANALYZE from other work.");
}
String aName = WorkItemBuilder.getAnalysisName(workItem);
if (aName == null) {
throw new BatfishException("Analysis name not provided for ANALYZE work");
}
Set<String> qNames = listAnalysisQuestions(workItem.getContainerName(), aName);
// compute the strongest dependency among the embedded questions
workType = WorkType.INDEPENDENT_ANSWERING;
for (String qName : qNames) {
Path qFile = getpathAnalysisQuestion(workItem.getContainerName(), aName, qName);
Question question = Question.parseQuestion(qFile);
if (question.getDataPlane()) {
workType = WorkType.DATAPLANE_DEPENDENT_ANSWERING;
break;
}
if (!question.getIndependent()) {
workType = WorkType.PARSING_DEPENDENT_ANSWERING;
}
}
}
Pair<Pair<String, String>, Pair<String, String>> settings = WorkItemBuilder.getBaseAndDeltaSettings(workItem);
WorkDetails details = new WorkDetails(WorkItemBuilder.getBaseTestrig(settings), WorkItemBuilder.getBaseEnvironment(settings), WorkItemBuilder.getDeltaTestrig(settings), WorkItemBuilder.getDeltaEnvironment(settings), WorkItemBuilder.isDifferential(workItem), workType);
return details;
}
use of org.batfish.common.Pair in project batfish by batfish.
the class NodJobTest method getNodJob.
private NodJob getNodJob(HeaderSpace headerSpace, Boolean srcNatted) {
StandardReachabilityQuerySynthesizer querySynthesizer = StandardReachabilityQuerySynthesizer.builder().setActions(ImmutableSet.of(ForwardingAction.ACCEPT)).setFinalNodes(ImmutableSet.of(_dstNode.getHostname())).setHeaderSpace(headerSpace).setIngressNodeVrfs(ImmutableMap.of(_srcNode.getHostname(), ImmutableSet.of(_srcVrf.getName()))).setSrcNatted(srcNatted).setTransitNodes(ImmutableSet.of()).setNonTransitNodes(ImmutableSet.of()).build();
SortedSet<Pair<String, String>> ingressNodes = ImmutableSortedSet.of(new Pair<>(_srcNode.getHostname(), _srcVrf.getName()));
return new NodJob(new Settings(), _synthesizer, querySynthesizer, ingressNodes, "tag", false);
}
use of org.batfish.common.Pair in project batfish by batfish.
the class SynthesizerInputImpl method computeEnabledAcls.
private Map<String, Map<String, IpAccessList>> computeEnabledAcls() {
if (_topologyInterfaces != null) {
return toImmutableMap(_topologyInterfaces, Entry::getKey, /* node */
topologyInterfacesEntry -> {
String hostname = topologyInterfacesEntry.getKey();
Configuration c = _configurations.get(hostname);
return topologyInterfacesEntry.getValue().stream().flatMap(ifaceName -> {
Interface i = c.getInterfaces().get(ifaceName);
ImmutableList.Builder<Pair<String, IpAccessList>> interfaceAcls = ImmutableList.builder();
IpAccessList aclIn = i.getIncomingFilter();
IpAccessList aclOut = i.getOutgoingFilter();
if (aclIn != null) {
aclIn = _ipAclListSpecializer.specialize(aclIn);
interfaceAcls.add(new Pair<>(aclIn.getName(), aclIn));
}
if (aclOut != null) {
aclOut = _ipAclListSpecializer.specialize(aclOut);
interfaceAcls.add(new Pair<>(aclOut.getName(), aclOut));
}
i.getSourceNats().forEach(sourceNat -> {
IpAccessList sourceNatAcl = sourceNat.getAcl();
if (sourceNatAcl != null) {
interfaceAcls.add(new Pair<>(sourceNatAcl.getName(), sourceNatAcl));
} else {
interfaceAcls.add(new Pair<>(DEFAULT_SOURCE_NAT_ACL.getName(), DEFAULT_SOURCE_NAT_ACL));
}
});
return interfaceAcls.build().stream();
}).collect(ImmutableSet.toImmutableSet()).stream().collect(ImmutableMap.toImmutableMap(Pair::getFirst, Pair::getSecond));
});
} else {
return _configurations.entrySet().stream().filter(e -> !_disabledNodes.contains(e.getKey())).collect(ImmutableMap.toImmutableMap(Entry::getKey, e -> {
String hostname = e.getKey();
Set<String> disabledAcls = _disabledAcls.get(hostname);
return e.getValue().getIpAccessLists().entrySet().stream().filter(e2 -> disabledAcls == null || !disabledAcls.contains(e2.getKey())).collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
}));
}
}
Aggregations