@Override public Set<String> resolve(SpecifierContext ctxt) { return _shorthandSpecifier.getMatchingNodes(ctxt); } }
/** Return the set of nodes that match this specifier */ public Set<String> getMatchingNodes(IBatfish batfish) { return getMatchingNodes(batfish.specifierContext()); }
@Override public NodesAnswerElement answer() { NodesQuestion question = (NodesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); // initRemoteBgpNeighbors(_batfish, configurations); SortedMap<String, Configuration> answerNodes = new TreeMap<>(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); for (String node : configurations.keySet()) { if (nodes.contains(node)) { answerNodes.put(node, configurations.get(node)); } } return new NodesAnswerElement(answerNodes, question.getSummary()); }
@Override public TableAnswerElement answer() { UnusedStructuresQuestion question = (UnusedStructuresQuestion) _question; // Find all the filenames that produced the queried nodes. This might have false positives if // a file produced multiple nodes, but that was already mis-handled before. Need to rewrite // this question as a TableAnswerElement. Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream() .filter(e -> includeNodes.contains(e.getKey())) .map(Entry::getValue) .collect(Collectors.toSet()); Multiset<Row> rows = LinkedHashMultiset.create(); SortedMap<String, SortedMap<String, SortedMap<String, DefinedStructureInfo>>> definedStructures = _batfish.loadConvertConfigurationAnswerElementOrReparse().getDefinedStructures(); definedStructures.entrySet().stream() .filter(e -> includeFiles.contains(e.getKey())) .forEach(e -> rows.addAll(processEntryToRows(e))); TableAnswerElement table = new TableAnswerElement(createMetadata(question)); table.postProcessAnswer(_question, rows); return table; }
@Override public TableAnswerElement answer() { UndefinedReferencesQuestion question = (UndefinedReferencesQuestion) _question; // Find all the filenames that produced the queried nodes. This might have false positives if // a file produced multiple nodes, but that was already mis-handled before. Need to rewrite // this question as a TableAnswerElement. Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Multimap<String, String> hostnameFilenameMap = _batfish.loadParseVendorConfigurationAnswerElement().getFileMap(); Set<String> includeFiles = hostnameFilenameMap.entries().stream() .filter(e -> includeNodes.contains(e.getKey())) .map(Entry::getValue) .collect(Collectors.toSet()); Multiset<Row> rows = LinkedHashMultiset.create(); SortedMap<String, SortedMap<String, SortedMap<String, SortedMap<String, SortedSet<Integer>>>>> undefinedReferences = _batfish.loadConvertConfigurationAnswerElementOrReparse().getUndefinedReferences(); undefinedReferences.entrySet().stream() .filter(e -> includeFiles.contains(e.getKey())) .forEach(e -> rows.addAll(processEntryToRows(e))); TableAnswerElement table = new TableAnswerElement(createMetadata()); table.postProcessAnswer(_question, rows); return table; }
private SortedMap<Ip, SortedSet<NodeInterfacePair>> getDuplicateIps() { UniqueIpAssignmentsQuestion question = (UniqueIpAssignmentsQuestion) _question; Set<String> nodes = question.getNodeRegex().getMatchingNodes(_batfish); Map<String, Configuration> configs = _batfish.loadConfigurations(); return nodes.stream()
@Override public InferRolesAnswerElement answer() { InferRolesQuestion question = (InferRolesQuestion) _question; InferRolesAnswerElement answerElement = new InferRolesAnswerElement(null, null); // collect relevant nodes in a list. Set<String> nodes = question.getNodeRegex().getMatchingNodes(_batfish); SortedSet<NodeRoleDimension> roleDimensions = new InferRoles(nodes, _batfish.getEnvironmentTopology(), question.getCaseSensitive()) .inferRoles(); answerElement.getRoleDimensions().addAll(roleDimensions); for (NodeRoleDimension dimension : roleDimensions) { SortedMap<String, SortedSet<String>> roleNodesMap = dimension.createRoleNodesMap(nodes); SortedSet<String> matchingNodes = new TreeSet<>(); for (SortedSet<String> nodeSet : roleNodesMap.values()) { matchingNodes.addAll(nodeSet); } answerElement.getMatchingNodesCount().put(dimension.getName(), matchingNodes.size()); } return answerElement; } }
TestFiltersQuestion question = (TestFiltersQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); FilterSpecifier filterSpecifier = question.getFilterSpecifier();
@Override public AnswerElement answer() { IpsecSessionStatusQuestion question = (IpsecSessionStatusQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); NetworkConfigurations networkConfigurations = NetworkConfigurations.of(configurations); ValueGraph<IpsecPeerConfigId, IpsecSession> ipsecTopology = IpsecUtil.initIpsecTopology(configurations); Set<String> initiatorNodes = question.getInitiatorRegex().getMatchingNodes(_batfish); Set<String> responderNodes = question.getResponderRegex().getMatchingNodes(_batfish); TableAnswerElement answerElement = new TableAnswerElement(createTableMetaData(question)); Multiset<IpsecSessionInfo> ipsecSessionInfos = rawAnswer(networkConfigurations, ipsecTopology, initiatorNodes, responderNodes); answerElement.postProcessAnswer( question, ipsecSessionInfos.stream() .filter( ipsecSessionInfo -> question.matchesStatus(ipsecSessionInfo.getIpsecSessionStatus())) .map(IpsecSessionStatusAnswerer::toRow) .collect(Collectors.toCollection(HashMultiset::create))); return answerElement; }
@Override public AnswerElement answer() { EdgesQuestion question = (EdgesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> includeNodes = question.getNodes().getMatchingNodes(_batfish); Set<String> includeRemoteNodes = question.getRemoteNodes().getMatchingNodes(_batfish); TableAnswerElement answer = new TableAnswerElement(getTableMetadata(question.getEdgeType())); Topology topology = _batfish.getEnvironmentTopology(); answer.postProcessAnswer( _question, generateRows( configurations, topology, includeNodes, includeRemoteNodes, question.getEdgeType())); return answer; }
@Override public RolesAnswerElement answer() { RolesQuestion question = (RolesQuestion) _question; // collect relevant nodes in a list. Set<String> nodes = question.getNodeRegex().getMatchingNodes(_batfish); NodeRoleDimension roleDimension = _batfish .getNodeRoleDimension(question.getRoleDimension()) .orElseThrow( () -> new BatfishException( "No role dimension found for " + question.getRoleDimension())); RolesAnswerElement answerElement = new RolesAnswerElement(roleDimension, roleDimension.createRoleNodesMap(nodes)); return answerElement; } }
SortedSetMultimap<Long, String> asns = TreeMultimap.create(); Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodeRegex().getMatchingNodes(_batfish); for (Entry<String, Configuration> e : configurations.entrySet()) { String hostname = e.getKey();
@Override public TableAnswerElement answer() { NamedStructuresQuestion question = (NamedStructuresQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createMetadata(question); Multiset<Row> propertyRows = rawAnswer(question, nodes, configurations, tableMetadata.toColumnMap()); TableAnswerElement answer = new TableAnswerElement(tableMetadata); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public AnswerElement answer() { OspfPropertiesQuestion question = (OspfPropertiesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public TableAnswerElement answer() { NodePropertiesQuestion question = (NodePropertiesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); TableAnswerElement answer = new TableAnswerElement(tableMetadata); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public AnswerElement answer() { BgpProcessConfigurationQuestion question = (BgpProcessConfigurationQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getProperties(question.getProperties(), configurations, nodes, tableMetadata.toColumnMap()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public TableAnswerElement answer() { AaaAuthenticationLoginQuestion question = (AaaAuthenticationLoginQuestion) _question; TableAnswerElement answerElement = create(question); Set<String> specifiedNodes = question.getNodes().getMatchingNodes(_batfish); SortedMap<String, Configuration> configs = _batfish.loadConfigurations(); configs.forEach( (configName, config) -> { if (specifiedNodes.contains(configName)) { Row row = null; if (config.getVendorFamily().getCisco() != null) { row = getRow(configName, config.getVendorFamily().getCisco().getLines().values()); } else if (config.getVendorFamily().getJuniper() != null) { row = getRow(configName, config.getVendorFamily().getJuniper().getLines().values()); } if (row != null) { answerElement.addRow(row); } } }); answerElement.setSummary(answerElement.computeSummary(question.getAssertion())); return answerElement; }
@Override public TableAnswerElement answer() { InterfacePropertiesQuestion question = (InterfacePropertiesQuestion) _question; Map<String, Configuration> configurations = _batfish.loadConfigurations(); Set<String> nodes = question.getNodes().getMatchingNodes(_batfish); TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getProperties( question.getProperties(), configurations, nodes, question.getInterfaces(), question.getOnlyActive(), tableMetadata.toColumnMap()); answer.postProcessAnswer(question, propertyRows); return answer; }
@Override public OutliersAnswerElement answer() { OutliersQuestion question = (OutliersQuestion) _question; _answerElement = new OutliersAnswerElement(); _configurations = _batfish.loadConfigurations(); _nodes = question.getNodeRegex().getMatchingNodes(_batfish); _verbose = question.getVerbose(); switch (question.getHypothesis()) { case SAME_DEFINITION: case SAME_NAME: SortedSet<NamedStructureOutlierSet<?>> outliers = namedStructureOutliers(question); _answerElement.setNamedStructureOutliers(outliers); break; case SAME_SERVERS: _answerElement.setServerOutliers(serverOutliers(question)); break; default: throw new BatfishException( "Unexpected outlier detection hypothesis " + question.getHypothesis()); } return _answerElement; }
@Override public CompareSameNameAnswerElement answer() { _assumeAllUnique = _batfish.debugFlagEnabled(DEBUG_FLAG_ASSUME_ALL_UNIQUE); _configurations = _batfish.loadConfigurations(); _csnQuestion = (CompareSameNameQuestion) _question; _nodes = _csnQuestion.getNodeRegex().getMatchingNodes(_batfish); _answerElement = new CompareSameNameAnswerElement(null, _nodes); add(AsPathAccessList.class, Configuration::getAsPathAccessLists); add(AuthenticationKeyChain.class, Configuration::getAuthenticationKeyChains); add(CommunityList.class, Configuration::getCommunityLists); add(IkePhase1Key.class, Configuration::getIkePhase1Keys); add(IkePhase1Policy.class, Configuration::getIkePhase1Policies); add(IkePhase1Proposal.class, Configuration::getIkePhase1Proposals); add(Interface.class, Configuration::getAllInterfaces); add(Ip6AccessList.class, Configuration::getIp6AccessLists); add(IpAccessList.class, Configuration::getIpAccessLists); add(IpsecPhase2Policy.class, Configuration::getIpsecPhase2Policies); add(IpsecPhase2Proposal.class, Configuration::getIpsecPhase2Proposals); add(IpsecPeerConfig.class, Configuration::getIpsecPeerConfigs); add(Route6FilterList.class, Configuration::getRoute6FilterLists); add(RouteFilterList.class, Configuration::getRouteFilterLists); add(RoutingPolicy.class, Configuration::getRoutingPolicies); add(Vrf.class, Configuration::getVrfs); add(Zone.class, Configuration::getZones); return _answerElement; }