@Test public void testOutputAPrefix() { RoutingPolicy policy = _policyBuilder.addStatement(new StaticStatement(Statements.ExitAccept)).build(); PrefixRange prefixRange = PrefixRange.fromPrefix(Prefix.parse("1.1.1.1/32")); SearchRoutePoliciesQuestion question = new SearchRoutePoliciesQuestion( EMPTY_CONSTRAINTS, BgpRouteConstraints.builder().setPrefix(new PrefixSpace(prefixRange)).build(), HOSTNAME, policy.getName(), Action.PERMIT); SearchRoutePoliciesAnswerer answerer = new SearchRoutePoliciesAnswerer(question, _batfish); TableAnswerElement answer = (TableAnswerElement) answerer.answer(_batfish.getSnapshot()); BgpRoute inputRoute = BgpRoute.builder() .setNetwork(Prefix.parse("1.1.1.1/32")) .setOriginatorIp(Ip.ZERO) .setOriginType(OriginType.IGP) .setProtocol(RoutingProtocol.BGP) .build(); BgpRouteDiffs diff = new BgpRouteDiffs(ImmutableSet.of()); assertThat( answer.getRows().getData(), Matchers.contains( allOf( hasColumn(COL_NODE, equalTo(new Node(HOSTNAME)), Schema.NODE), hasColumn(COL_POLICY_NAME, equalTo(policy.getName()), Schema.STRING), hasColumn(COL_ACTION, equalTo(PERMIT.toString()), Schema.STRING), hasColumn(COL_INPUT_ROUTE, equalTo(inputRoute), Schema.BGP_ROUTE), hasColumn(COL_OUTPUT_ROUTE, equalTo(inputRoute), Schema.BGP_ROUTE), hasColumn(COL_DIFF, equalTo(diff), Schema.BGP_ROUTE_DIFFS)))); }
@Override public AnswerElement answer(NetworkSnapshot snapshot) { SpecifierContext context = _batfish.specifierContext(snapshot); Multiset<Row> rows = _nodeSpecifier.resolve(context).stream() .flatMap(node -> searchPoliciesForNode(node, _policySpecifier.resolve(node, context))) .map(SearchRoutePoliciesAnswerer::toRow) .collect(ImmutableMultiset.toImmutableMultiset()); TableAnswerElement answerElement = new TableAnswerElement(metadata()); answerElement.postProcessAnswer(_question, rows); return answerElement; }
SearchRoutePoliciesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { SpecifierContext context = _batfish.specifierContext(snapshot); Multiset<Row> rows = _nodeSpecifier.resolve(context).stream() .flatMap(node -> searchPoliciesForNode(node, _policySpecifier.resolve(node, context))) .map(SearchRoutePoliciesAnswerer::toRow) .collect(ImmutableMultiset.toImmutableMultiset()); TableAnswerElement answerElement = new TableAnswerElement(metadata()); answerElement.postProcessAnswer(_question, rows); return answerElement; } }
SearchRoutePoliciesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { SpecifierContext context = _batfish.specifierContext(snapshot); Multiset<Row> rows = _nodeSpecifier.resolve(context).stream() .flatMap(node -> searchPoliciesForNode(node, _policySpecifier.resolve(node, context))) .map(SearchRoutePoliciesAnswerer::toRow) .collect(ImmutableMultiset.toImmutableMultiset()); TableAnswerElement answerElement = new TableAnswerElement(metadata()); answerElement.postProcessAnswer(_question, rows); return answerElement; } SearchRoutePoliciesAnswerer(SearchRoutePoliciesQuestion question, IBatfish batfish); }
SearchRoutePoliciesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { SpecifierContext context = _batfish.specifierContext(snapshot); Multiset<Row> rows = _nodeSpecifier.resolve(context).stream() .flatMap(node -> searchPoliciesForNode(node, _policySpecifier.resolve(node, context))) .map(SearchRoutePoliciesAnswerer::toRow) .collect(ImmutableMultiset.toImmutableMultiset()); TableAnswerElement answerElement = new TableAnswerElement(metadata()); answerElement.postProcessAnswer(_question, rows); return answerElement; } SearchRoutePoliciesAnswerer(SearchRoutePoliciesQuestion question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata metadata(); }
SearchRoutePoliciesAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { SpecifierContext context = _batfish.specifierContext(snapshot); Multiset<Row> rows = _nodeSpecifier.resolve(context).stream() .flatMap(node -> searchPoliciesForNode(node, _policySpecifier.resolve(node, context))) .map(SearchRoutePoliciesAnswerer::toRow) .collect(ImmutableMultiset.toImmutableMultiset()); TableAnswerElement answerElement = new TableAnswerElement(metadata()); answerElement.postProcessAnswer(_question, rows); return answerElement; } SearchRoutePoliciesAnswerer(SearchRoutePoliciesQuestion question, IBatfish batfish); @Override AnswerElement answer(NetworkSnapshot snapshot); static TableMetadata metadata(); static final String COL_NODE; static final String COL_POLICY_NAME; static final String COL_INPUT_ROUTE; static final String COL_ACTION; static final String COL_OUTPUT_ROUTE; static final String COL_DIFF; }