@Override protected Iterable<Row> featureValueOf(TableAnswerElement actual) { return () -> actual.getRows().iterator(); } }
@Override protected boolean matchesSafely(TableAnswerElement item, Description mismatchDescription) { Iterator<Row> iterator = item.getRows().iterator(); Iterable<Row> rows = () -> iterator; Matcher<Iterable<? extends Row>> matcher = Matchers.containsInAnyOrder(_rowMatchers); if (!matcher.matches(rows)) { matcher.describeMismatch(rows, mismatchDescription); return false; } return true; } }
private Multiset<Row> getQuestionResults(BgpSessionCompatibilityQuestion q) { TableAnswerElement answer = (TableAnswerElement) new BgpSessionCompatibilityAnswerer(q, _batfish).answer(); return answer.getRows().getData(); } }
@Test public void testDeliveredToSubnetVSStaticRoute1() throws IOException { TableAnswerElement answer = testDeliveredToSubnetVSStaticRoute("24"); assertThat(answer.getRows().getData(), hasSize(1)); assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(1))), Schema.set(Schema.FLOW_TRACE)))); assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void testLoops() throws IOException { initNetwork(true); Set<Flow> flows = _batfish.bddLoopDetection(); assertThat(flows, Matchers.hasSize(2)); DetectLoopsAnswerer answerer = new DetectLoopsAnswerer(new DetectLoopsQuestion(TracePruner.DEFAULT_MAX_TRACES), _batfish); TableAnswerElement ae = (TableAnswerElement) answerer.answer(); // we find 2 loopy flows, but they are for the same destination, so the answerer // only reports 1. assertThat(ae.getRows(), hasSize(1)); // same result if we use the old traceroute engine _batfish.getSettings().setDebugFlags(ImmutableList.of("oldtraceroute")); ae = (TableAnswerElement) answerer.answer(); assertThat(ae.getRows(), hasSize(1)); } }
@Test public void testDispositionMultipleRouters2() throws IOException { TableAnswerElement answer = testDispositionMultipleRouters("25"); assertThat(answer.getRows().getData(), hasSize(1)); // check that packet only traverse R1 assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(1))), Schema.set(Schema.FLOW_TRACE)))); // check disposition assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void testDispositionMultiInterfaces() throws IOException { TableAnswerElement answer = testDispositionMultiInterfaces("25"); assertThat(answer.getRows().getData(), hasSize(2)); // check that packet should reach R1 assertThat( answer.getRows().getData(), everyItem( hasColumn(COL_TRACES, everyItem(hasHops(hasSize(1))), Schema.set(Schema.FLOW_TRACE)))); assertThat( answer.getRows().getData(), everyItem( hasColumn( COL_TRACES, everyItem(hasDisposition(FlowDisposition.DELIVERED_TO_SUBNET)), Schema.set(Schema.FLOW_TRACE)))); }
@Test public void resolveInterfaceTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.INTERFACE); question.setInterfaceSpecifierInput(_iface1.getName()); // only iface1 should be present (with a node specifier all nodes are included) assertThat( resolveInterface(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_INTERFACE, new NodeInterfacePair(_c1.getHostname(), _iface1.getName()))))); // nothing should match since the node specifier does not match anything question.setNodeSpecifierInput("foofoo"); assertThat( resolveInterface(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of())); }
@Test public void resolveFilterTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.FILTER); question.setFilterSpecifierInput(_filter1.getName()); // only filter1 should be present (with a node specifier all nodes are included) assertThat( resolveFilter(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_NODE, new Node(_c1.getHostname()), COL_FILTER_NAME, _filter1.getName())))); // nothing should match since the node specifier does not match anything question.setNodeSpecifierInput("foofoo"); assertThat( resolveFilter(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of())); }
@Test public void testNoLoops() throws IOException { initNetwork(false); DetectLoopsAnswerer answerer = new DetectLoopsAnswerer(new DetectLoopsQuestion(TracePruner.DEFAULT_MAX_TRACES), _batfish); TableAnswerElement ae = (TableAnswerElement) answerer.answer(); assertThat(ae.getRows(), hasSize(0)); }
@Test public void resolveNodeTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.NODE); question.setNodeSpecifierInput(_c1.getHostname()); // only c1 should be present assertThat( resolveNode(question, _context).getRows().getData(), equalTo(ImmutableMultiset.of(Row.of(COL_NODE, new Node(_c1.getHostname()))))); } }
@Test public void testHeaderSpaceConstraint2() throws IOException { Question question = new DifferentialReachabilityQuestion( new DispositionSpecifier(ImmutableSet.of(FlowDisposition.ACCEPTED)), PacketHeaderConstraints.builder().setDstIp("5.5.5.5").build(), false, false, TracePruner.DEFAULT_MAX_TRACES, PathConstraintsInput.unconstrained()); Batfish batfish = initBatfish(); TableAnswerElement answer = new DifferentialReachabilityAnswerer(question, batfish).answer(); assertThat(answer.getRows().size(), equalTo(0)); } }
@Test public void testAddValidRow() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).put("key2", null).build(); table.addRow(row); assertThat(table.getRows().getData(), contains(row)); }
@Test public void resolveLocationTest() { SpecifiersQuestion question = new SpecifiersQuestion(QueryType.LOCATION); question.setLocationSpecifierInput(_c1.getHostname()); // only c1:iface1 should be present assertThat( resolveLocation(question, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_LOCATION, new InterfaceLocation(_c1.getHostname(), _iface1.getName()).toString())))); }
@Test public void testAnswererFlow() { UndefinedReferencesAnswerer answerer = new UndefinedReferencesAnswerer(new UndefinedReferencesQuestion(), new TestBatfish()); TableAnswerElement answer = answerer.answer(); assertThat(answer.getRows(), equalTo(new Rows().add(BASIC_ROW))); }
@Test public void testAnswererFlow() { UnusedStructuresAnswerer answerer = new UnusedStructuresAnswerer(new UnusedStructuresQuestion(), new TestBatfish()); TableAnswerElement answer = answerer.answer(); assertThat(answer.getRows(), equalTo(new Rows().add(BASIC_ROW))); }
@Test public void testAnswererFlow() { FileParseStatusAnswerer answerer = new FileParseStatusAnswerer(new FileParseStatusQuestion(), new TestBatfish()); TableAnswerElement answer = answerer.answer(); assertThat( answer.getRows(), equalTo( new Rows() .add( Row.of( COL_FILENAME, "f", COL_PARSE_STATUS, ParseStatus.PASSED, COL_NODES, ImmutableList.of(new Node("h")))))); }
@Test public void resolveIpSpaceTest() { String prefix = "3.3.3.3/24"; SpecifiersQuestion questionWithIp = new SpecifiersQuestion(QueryType.LOCATION); questionWithIp.setIpSpaceSpecifierInput(prefix); // both interfacelocations should be mapped to 3.3.3.3/24 assertThat( resolveIpSpace(questionWithIp, _context).getRows().getData(), equalTo( ImmutableMultiset.of( Row.of( COL_IP_SPACE, IpWildcardSetIpSpace.builder() .including(new IpWildcard(prefix)) .build() .toString())))); }
@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 testAnswer() { ConversionStatusAnswerer answerer = new ConversionStatusAnswerer(new ConversionStatusQuestion(), new TestBatfish()); TableAnswerElement answer = answerer.answer(); assertThat( answer.getRows(), equalTo( new Rows() .add(Row.of(COL_NODE, "n1", COL_CONVERT_STATUS, ConvertStatus.PASSED)) .add(Row.of(COL_NODE, "n2", COL_CONVERT_STATUS, ConvertStatus.WARNINGS)) .add(Row.of(COL_NODE, "n3", COL_CONVERT_STATUS, ConvertStatus.FAILED)))); }