@Override public AnswerElement answer() { SpecifiersQuestion question = (SpecifiersQuestion) _question; SpecifierContext context = _batfish.specifierContext(); switch (question.getQueryType()) { case FILTER: return resolveFilter(question, context); case INTERFACE: return resolveInterface(question, context); case IP_SPACE: return resolveIpSpace(question, context); case IP_SPACE_OF_LOCATION: return resolveIpSpaceOfLocation(question, context); case LOCATION: return resolveLocation(question, context); case NODE: return resolveNode(question, context); default: throw new IllegalArgumentException("Unhandled query type: " + question.getQueryType()); } }
@Test public void resolveIpSpaceOfLocationTest() { SpecifiersQuestion questionWithLocation = new SpecifiersQuestion(QueryType.IP_SPACE_OF_LOCATION); questionWithLocation.setLocationSpecifierInput(_c1.getHostname()); // only c1:iface1 should be present assertThat( resolveIpSpaceOfLocation(questionWithLocation, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName())) .toString(), COL_IP_SPACE, _iface1.getAddress().getIp().toIpSpace().toString())))); }
@Test public void resolveIpSpaceOfLocationTestDefault() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.IP_SPACE); assertThat( resolveIpSpaceOfLocation(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c1.getHostname(), _iface1.getName())) .toString(), COL_IP_SPACE, _iface1.getAddress().getIp().toIpSpace().toString()), Row.of( COL_LOCATIONS, ImmutableSet.of(new InterfaceLocation(_c2.getHostname(), _iface2.getName())) .toString(), COL_IP_SPACE, _iface2.getAddress().getIp().toIpSpace().toString())))); }