@Test public void testAnswer() { MockSpecifierContext ctxt = MockSpecifierContext.builder().setConfigs(ImmutableMap.of("c", _c)).build(); Multiset<Row> rows = BgpPeerConfigurationAnswerer.getAnswerRows( ctxt, new NameNodeSpecifier("c"), BgpPeerConfigurationAnswerer.createTableMetadata( new BgpPeerConfigurationQuestion(null, BgpPeerPropertySpecifier.ALL)) .toColumnMap(), BgpPeerPropertySpecifier.ALL); Node node = new Node("c"); Multiset<Row> expected = HashMultiset.create(); expected.add( Row.builder() .put(COL_NODE, node) .put(COL_VRF, "v") .put(COL_REMOTE_IP, new SelfDescribingObject(Schema.IP, Ip.parse("2.2.2.2"))) .put(getColumnName(LOCAL_AS), 100L) .put(COL_LOCAL_INTERFACE, null) .put(getColumnName(REMOTE_AS), LongSpace.of(200L).toString()) .put(getColumnName(LOCAL_IP), Ip.parse("1.1.1.1")) .put(getColumnName(CONFEDERATION), 1L) .put(getColumnName(IS_PASSIVE), false) .put(getColumnName(ROUTE_REFLECTOR_CLIENT), false) .put(getColumnName(CLUSTER_ID), null) .put(getColumnName(PEER_GROUP), "g1") .put(getColumnName(IMPORT_POLICY), ImmutableSet.of("p1")) .put(getColumnName(EXPORT_POLICY), ImmutableSet.of("p2")) .put(getColumnName(SEND_COMMUNITY), false) .build()); expected.add( Row.builder() .put(COL_NODE, node) .put(COL_VRF, "v") .put(getColumnName(LOCAL_AS), 100L) .put(COL_LOCAL_INTERFACE, null) .put( COL_REMOTE_IP, new SelfDescribingObject(Schema.PREFIX, Prefix.create(Ip.parse("3.3.3.0"), 24))) .put(getColumnName(REMOTE_AS), LongSpace.of(300L).toString()) .put(getColumnName(LOCAL_IP), Ip.parse("1.1.1.2")) .put(getColumnName(CONFEDERATION), 2L) .put(getColumnName(IS_PASSIVE), true) .put(getColumnName(ROUTE_REFLECTOR_CLIENT), true) .put(getColumnName(CLUSTER_ID), Ip.parse("5.5.5.5")) .put(getColumnName(PEER_GROUP), "g2") .put(getColumnName(IMPORT_POLICY), ImmutableSet.of("p3")) .put(getColumnName(EXPORT_POLICY), ImmutableSet.of("p4")) .put(getColumnName(SEND_COMMUNITY), false) .build()); expected.add( Row.builder() .put(COL_NODE, node) .put(COL_VRF, "v") .put(getColumnName(LOCAL_AS), 100L) .put(COL_LOCAL_INTERFACE, "iface") .put(COL_REMOTE_IP, null) .put(getColumnName(REMOTE_AS), LongSpace.of(400L).toString()) .put(getColumnName(LOCAL_IP), null) .put(getColumnName(CONFEDERATION), 3L) .put(getColumnName(IS_PASSIVE), false) .put(getColumnName(ROUTE_REFLECTOR_CLIENT), true) .put(getColumnName(CLUSTER_ID), Ip.parse("6.6.6.6")) .put(getColumnName(PEER_GROUP), "g3") .put(getColumnName(IMPORT_POLICY), ImmutableSet.of("p5")) .put(getColumnName(EXPORT_POLICY), ImmutableSet.of("p6")) .put(getColumnName(SEND_COMMUNITY), false) .build()); assertThat(rows, equalTo(expected)); }
@Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpPeerConfigurationQuestion question = (BgpPeerConfigurationQuestion) _question; TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getAnswerRows( _batfish.specifierContext(snapshot), question.getNodeSpecifier(), tableMetadata.toColumnMap(), question.getPropertySpecifier()); answer.postProcessAnswer(question, propertyRows); return answer; }
BgpPeerConfigurationAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpPeerConfigurationQuestion question = (BgpPeerConfigurationQuestion) _question; TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getAnswerRows( _batfish.specifierContext(snapshot), question.getNodeSpecifier(), tableMetadata.toColumnMap(), question.getPropertySpecifier()); answer.postProcessAnswer(question, propertyRows); return answer; } }
BgpPeerConfigurationAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpPeerConfigurationQuestion question = (BgpPeerConfigurationQuestion) _question; TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getAnswerRows( _batfish.specifierContext(snapshot), question.getNodeSpecifier(), tableMetadata.toColumnMap(), question.getPropertySpecifier()); answer.postProcessAnswer(question, propertyRows); return answer; } BgpPeerConfigurationAnswerer(Question question, IBatfish batfish); }
BgpPeerConfigurationAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpPeerConfigurationQuestion question = (BgpPeerConfigurationQuestion) _question; TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getAnswerRows( _batfish.specifierContext(snapshot), question.getNodeSpecifier(), tableMetadata.toColumnMap(), question.getPropertySpecifier()); answer.postProcessAnswer(question, propertyRows); return answer; } BgpPeerConfigurationAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(
      BgpPeerPropertySpecifier propertySpecifier); @Override AnswerElement answer(NetworkSnapshot snapshot); @VisibleForTesting static Multiset<Row> getAnswerRows(
      SpecifierContext ctxt,
      NodeSpecifier nodeSpecifier,
      Map<String, ColumnMetadata> columnMetadata,
      BgpPeerPropertySpecifier propertySpecifier); static String getColumnName(String property); }
BgpPeerConfigurationAnswerer extends Answerer { @Override public AnswerElement answer(NetworkSnapshot snapshot) { BgpPeerConfigurationQuestion question = (BgpPeerConfigurationQuestion) _question; TableMetadata tableMetadata = createTableMetadata(question); TableAnswerElement answer = new TableAnswerElement(tableMetadata); Multiset<Row> propertyRows = getAnswerRows( _batfish.specifierContext(snapshot), question.getNodeSpecifier(), tableMetadata.toColumnMap(), question.getPropertySpecifier()); answer.postProcessAnswer(question, propertyRows); return answer; } BgpPeerConfigurationAnswerer(Question question, IBatfish batfish); static List<ColumnMetadata> createColumnMetadata(
      BgpPeerPropertySpecifier propertySpecifier); @Override AnswerElement answer(NetworkSnapshot snapshot); @VisibleForTesting static Multiset<Row> getAnswerRows(
      SpecifierContext ctxt,
      NodeSpecifier nodeSpecifier,
      Map<String, ColumnMetadata> columnMetadata,
      BgpPeerPropertySpecifier propertySpecifier); static String getColumnName(String property); static final String COL_NODE; static final String COL_VRF; static final String COL_LOCAL_INTERFACE; static final String COL_REMOTE_IP; }