@Test public void testFullAnswerPipelineAndNumResults() { NetworkFactory nf = new NetworkFactory(); Configuration c = nf.configurationBuilder().setConfigurationFormat(ConfigurationFormat.CISCO_IOS).build(); Vrf vrf = nf.vrfBuilder().setOwner(c).build(); SortedMap<String, SortedMap<String, GenericRib<AnnotatedRoute<AbstractRoute>>>> ribs = ImmutableSortedMap.of( c.getHostname(), ImmutableSortedMap.of( vrf.getName(), new MockRib<>( ImmutableSet.of( new AnnotatedRoute<>( StaticRoute.builder() .setAdministrativeCost(1) .setNetwork(Prefix.parse("1.1.1.1/32")) .setNextHopInterface("Null") .build(), vrf.getName()))))); NetworkConfigurations nc = NetworkConfigurations.of(ImmutableMap.of(c.getHostname(), c)); MockBatfish batfish = new MockBatfish(nc, MockDataPlane.builder().setRibs(ribs).build()); AnswerElement el = new RoutesAnswerer(new RoutesQuestion(), batfish).answer(batfish.getSnapshot()); assert el.getSummary() != null; assertThat(el.getSummary().getNumResults(), equalTo(1)); batfish = new MockBatfish(nc, MockDataPlane.builder().setRibs(ImmutableSortedMap.of()).build()); el = new RoutesAnswerer(new RoutesQuestion(), batfish).answer(batfish.getSnapshot()); assert el.getSummary() != null; assertThat(el.getSummary().getNumResults(), equalTo(0)); }
@Override public AnswerElement answer(NetworkSnapshot snapshot) { RoutesQuestion question = (RoutesQuestion) _question; TableAnswerElement answer = new TableAnswerElement(getTableMetadata(question.getRib())); DataPlane dp = _batfish.loadDataPlane(snapshot); Set<String> matchingNodes = question.getNodeSpecifier().resolve(_batfish.specifierContext(snapshot)); Prefix network = question.getNetwork(); RoutingProtocolSpecifier protocolSpec = question.getRoutingProtocolSpecifier(); String vrfRegex = question.getVrfs(); Map<Ip, Set<String>> ipOwners = computeIpNodeOwners(_batfish.loadConfigurations(snapshot), true); Multiset<Row> rows; switch (question.getRib()) { case BGP: rows = getBgpRibRoutes( dp.getBgpRoutes(), RibProtocol.BGP, matchingNodes, network, protocolSpec, vrfRegex); break; case EVPN: rows = getEvpnRoutes( dp.getEvpnRoutes(), RibProtocol.EVPN, matchingNodes, network, protocolSpec, vrfRegex); break; case MAIN: default: rows = getMainRibRoutes( dp.getRibs(), matchingNodes, network, protocolSpec, vrfRegex, ipOwners); } answer.postProcessAnswer(_question, rows); return answer; }
RoutesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { RoutesQuestion question = (RoutesQuestion) _question; TableAnswerElement answer = new TableAnswerElement(getTableMetadata(question.getRib())); DataPlane dp = _batfish.loadDataPlane(snapshot); Set<String> matchingNodes = question.getNodeSpecifier().resolve(_batfish.specifierContext(snapshot)); Prefix network = question.getNetwork(); RoutingProtocolSpecifier protocolSpec = question.getRoutingProtocolSpecifier(); String vrfRegex = question.getVrfs(); Map<Ip, Set<String>> ipOwners = computeIpNodeOwners(_batfish.loadConfigurations(snapshot), true); Multiset<Row> rows; switch (question.getRib()) { case BGP: rows = getBgpRibRoutes( dp.getBgpRoutes(), RibProtocol.BGP, matchingNodes, network, protocolSpec, vrfRegex); break; case EVPN: rows = getEvpnRoutes( dp.getEvpnRoutes(), RibProtocol.EVPN, matchingNodes, network, protocolSpec, vrfRegex); break; case MAIN: default: rows = getMainRibRoutes( dp.getRibs(), matchingNodes, network, protocolSpec, vrfRegex, ipOwners); } answer.postProcessAnswer(_question, rows); return answer; } }
RoutesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { RoutesQuestion question = (RoutesQuestion) _question; TableAnswerElement answer = new TableAnswerElement(getTableMetadata(question.getRib())); DataPlane dp = _batfish.loadDataPlane(snapshot); Set<String> matchingNodes = question.getNodeSpecifier().resolve(_batfish.specifierContext(snapshot)); Prefix network = question.getNetwork(); RoutingProtocolSpecifier protocolSpec = question.getRoutingProtocolSpecifier(); String vrfRegex = question.getVrfs(); Map<Ip, Set<String>> ipOwners = computeIpNodeOwners(_batfish.loadConfigurations(snapshot), true); Multiset<Row> rows; switch (question.getRib()) { case BGP: rows = getBgpRibRoutes( dp.getBgpRoutes(), RibProtocol.BGP, matchingNodes, network, protocolSpec, vrfRegex); break; case EVPN: rows = getEvpnRoutes( dp.getEvpnRoutes(), RibProtocol.EVPN, matchingNodes, network, protocolSpec, vrfRegex); break; case MAIN: default: rows = getMainRibRoutes( dp.getRibs(), matchingNodes, network, protocolSpec, vrfRegex, ipOwners); } answer.postProcessAnswer(_question, rows); return answer; } RoutesAnswerer(Question question, IBatfish batfish); }
RoutesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { RoutesQuestion question = (RoutesQuestion) _question; TableAnswerElement answer = new TableAnswerElement(getTableMetadata(question.getRib())); DataPlane dp = _batfish.loadDataPlane(snapshot); Set<String> matchingNodes = question.getNodeSpecifier().resolve(_batfish.specifierContext(snapshot)); Prefix network = question.getNetwork(); RoutingProtocolSpecifier protocolSpec = question.getRoutingProtocolSpecifier(); String vrfRegex = question.getVrfs(); Map<Ip, Set<String>> ipOwners = computeIpNodeOwners(_batfish.loadConfigurations(snapshot), true); Multiset<Row> rows; switch (question.getRib()) { case BGP: rows = getBgpRibRoutes( dp.getBgpRoutes(), RibProtocol.BGP, matchingNodes, network, protocolSpec, vrfRegex); break; case EVPN: rows = getEvpnRoutes( dp.getEvpnRoutes(), RibProtocol.EVPN, matchingNodes, network, protocolSpec, vrfRegex); break; case MAIN: default: rows = getMainRibRoutes( dp.getRibs(), matchingNodes, network, protocolSpec, vrfRegex, ipOwners); } answer.postProcessAnswer(_question, rows); return answer; } RoutesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); @Override AnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference); }
RoutesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { RoutesQuestion question = (RoutesQuestion) _question; TableAnswerElement answer = new TableAnswerElement(getTableMetadata(question.getRib())); DataPlane dp = _batfish.loadDataPlane(snapshot); Set<String> matchingNodes = question.getNodeSpecifier().resolve(_batfish.specifierContext(snapshot)); Prefix network = question.getNetwork(); RoutingProtocolSpecifier protocolSpec = question.getRoutingProtocolSpecifier(); String vrfRegex = question.getVrfs(); Map<Ip, Set<String>> ipOwners = computeIpNodeOwners(_batfish.loadConfigurations(snapshot), true); Multiset<Row> rows; switch (question.getRib()) { case BGP: rows = getBgpRibRoutes( dp.getBgpRoutes(), RibProtocol.BGP, matchingNodes, network, protocolSpec, vrfRegex); break; case EVPN: rows = getEvpnRoutes( dp.getEvpnRoutes(), RibProtocol.EVPN, matchingNodes, network, protocolSpec, vrfRegex); break; case MAIN: default: rows = getMainRibRoutes( dp.getRibs(), matchingNodes, network, protocolSpec, vrfRegex, ipOwners); } answer.postProcessAnswer(_question, rows); return answer; } RoutesAnswerer(Question question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); @Override AnswerElement answerDiff(NetworkSnapshot snapshot, NetworkSnapshot reference);  }